Skip to content

Commit

Permalink
Replace node_type_name with typeId.
Browse files Browse the repository at this point in the history
  • Loading branch information
fruffy committed Mar 27, 2024
1 parent a3b38b4 commit 9f41b51
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 21 deletions.
6 changes: 3 additions & 3 deletions backends/p4tools/p4tools.def
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class StateVariable : Expression {

isSemanticallyLess {
if (static_cast<const Node *>(this) == &a_) return false;
if (node_type_name() != a_.node_type_name()) return node_type_name() < a_.node_type_name();
if (typeId() != a_.typeId()) return typeId() < a_.typeId();
auto &a = static_cast<const StateVariable &>(a_);
return compare(ref, a.ref) < 0;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ class SymbolicVariable : Expression {

isSemanticallyLess {
if (static_cast<const Node *>(this) == &a_) return false;
if (node_type_name() != a_.node_type_name()) return node_type_name() < a_.node_type_name();
if (typeId() != a_.typeId()) return typeId() < a_.typeId();
auto &a = static_cast<const SymbolicVariable &>(a_);
return label < a.label; /* ignore type */
}
Expand Down Expand Up @@ -226,7 +226,7 @@ public:

isSemanticallyLess {
if (static_cast<const Node *>(this) == &a_) return false;
if (node_type_name() != a_.node_type_name()) return node_type_name() < a_.node_type_name();
if (typeId() != a_.typeId()) return typeId() < a_.typeId();
auto &a = static_cast<const ConcolicVariable &>(a_);
return label < a.label; /* ignore type */
}
Expand Down
2 changes: 1 addition & 1 deletion ir/base.def
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class AnnotationToken {
dbprint { out << text; }
isSemanticallyLess {
if (static_cast<const Node *>(this) == &a_) return false;
if (node_type_name() != a_.node_type_name()) return node_type_name() < a_.node_type_name();
if (typeId() != a_.typeId()) return typeId() < a_.typeId();
auto &a = static_cast<const AnnotationToken &>(a_);
return IR::isSemanticallyLess(token_type, a.token_type)
|| IR::isSemanticallyLess(text, a.text)
Expand Down
2 changes: 1 addition & 1 deletion ir/expression.def
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class Constant : Literal {
visit_children { v.visit(type, "type"); }
isSemanticallyLess {
if (static_cast<const Node *>(this) == &a_) return false;
if (node_type_name() != a_.node_type_name()) return node_type_name() < a_.node_type_name();
if (typeId() != a_.typeId()) return typeId() < a_.typeId();
if (Literal::isSemanticallyLess(a_)) return true;
auto &a = static_cast<const Constant &>(a_);
return value < a.value; /* ignore base */
Expand Down
6 changes: 3 additions & 3 deletions ir/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ class Node : public virtual INode {
virtual bool operator==(const Node &a) const { return this->typeId() == a.typeId(); }
/* 'equiv' does a deep-equals comparison, comparing all non-pointer fields and recursing
* though all Node subclass pointers to compare them with 'equiv' as well. */
virtual bool equiv(const Node &a) const { return this->typeId() == a.typeId(); }
virtual bool isSemanticallyLess(const Node &a) const {
return node_type_name() < a.node_type_name();
[[nodiscard]] virtual bool equiv(const Node &a) const { return this->typeId() == a.typeId(); }
[[nodiscard]] virtual bool isSemanticallyLess(const Node &a) const {
return this->typeId() < a.typeId();
}
#define DEFINE_OPEQ_FUNC(CLASS, BASE) \
virtual bool operator==(const CLASS &) const { return false; }
Expand Down
4 changes: 2 additions & 2 deletions ir/type.def
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Type_Any : Type, ITypeVar {
isSemanticallyLess {
if (static_cast<const Node *>(this) == &a_) return false;
if (Type::isSemanticallyLess(a_)) return true;
return node_type_name() < a_.node_type_name(); /* ignore declid */
return typeId() < a_.typeId(); /* ignore declid */
}
}

Expand Down Expand Up @@ -240,7 +240,7 @@ class Type_InfInt : Type, ITypeVar {
isSemanticallyLess {
if (static_cast<const Node *>(this) == &a_) return false;
if (Type::isSemanticallyLess(a_)) return true;
return node_type_name() < a_.node_type_name(); /* ignore declid */
return typeId() < a_.typeId(); /* ignore declid */
}
const Type* getP4Type() const override { return this; }
}
Expand Down
2 changes: 1 addition & 1 deletion ir/v1.def
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class CalculatedField : IAnnotated {
v.visit(annotations, "annotations"); }
isSemanticallyLess {
if (static_cast<const Node *>(this) == &a_) return false;
if (node_type_name() != a_.node_type_name()) return node_type_name() < a_.node_type_name();
if (typeId() != a_.typeId()) return typeId() < a_.typeId();
auto &a = static_cast<const CalculatedField &>(a_);
return (field != nullptr ? a.field != nullptr ? field->isSemanticallyLess(*a.field) : false : a.field != nullptr)
|| std::lexicographical_compare(specs.begin(), specs.end(), a.specs.begin(), a.specs.end(), [](const update_or_verify &a, const update_or_verify &b) { return a.isSemanticallyLess(b); })
Expand Down
12 changes: 6 additions & 6 deletions test/gtest/semantically_less_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ TEST(OperatorLess, Types) {
CHECK_EQUALITY_FOR_P4C_TYPE(a, c);

auto *d = new IR::Type_Boolean();
CHECK_LESS_FOR_P4C_TYPE(a, d);
CHECK_GREATER_FOR_P4C_TYPE(d, a);
CHECK_LESS_FOR_P4C_TYPE(d, a);
CHECK_GREATER_FOR_P4C_TYPE(a, d);

auto *e = new IR::Type_InfInt();
CHECK_LESS_FOR_P4C_TYPE(a, e);
Expand Down Expand Up @@ -153,8 +153,8 @@ TEST(OperatorLess, MixedConstants) {

CHECK_LESS_FOR_P4C_EXPRESSION(d, a);
CHECK_GREATER_FOR_P4C_EXPRESSION(a, d);
CHECK_LESS_FOR_P4C_EXPRESSION(d, b);
CHECK_GREATER_FOR_P4C_EXPRESSION(b, d);
CHECK_LESS_FOR_P4C_EXPRESSION(b, d);
CHECK_GREATER_FOR_P4C_EXPRESSION(d, b);
}

TEST(OperatorLess, ConstantVectors) {
Expand Down Expand Up @@ -190,8 +190,8 @@ TEST(OperatorLess, ConstantVectors) {
auto *p5 = new IR::IndexedVector<IR::Node>(new IR::Constant(t, 0));
auto *p6 = new IR::IndexedVector<IR::Node>(new IR::StringLiteral(new IR::Type_String(), "a"));

CHECK_LESS_FOR_P4C_NODE_VECTOR(p4, p5);
CHECK_GREATER_FOR_P4C_NODE_VECTOR(p5, p4);
CHECK_LESS_FOR_P4C_NODE_VECTOR(p5, p4);
CHECK_GREATER_FOR_P4C_NODE_VECTOR(p4, p5);
CHECK_LESS_FOR_P4C_NODE_VECTOR(p4, p6);
CHECK_GREATER_FOR_P4C_NODE_VECTOR(p6, p4);
CHECK_LESS_FOR_P4C_NODE_VECTOR(p5, p6);
Expand Down
7 changes: 3 additions & 4 deletions tools/ir-generator/methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ const ordered_map<cstring, IrMethod::info_t> IrMethod::Generate = {
<< "if (static_cast<const Node *>(this) == &a_) return false;\n";
if (auto parent = cl->getParent()) {
buf << cl->indent << cl->indent
<< "if (node_type_name() != a_.node_type_name()) "
"return node_type_name() < a_.node_type_name();\n";
<< "if (typeId() != a_.typeId()) "
"return typeId() < a_.typeId();\n";
if (parent->name != "Node") {
buf << cl->indent << cl->indent << "if ("
<< parent->qualified_name(cl->containedIn)
Expand Down Expand Up @@ -174,8 +174,7 @@ const ordered_map<cstring, IrMethod::info_t> IrMethod::Generate = {
}
}
if (first) { // no fields?
buf << cl->indent << cl->indent
<< "return node_type_name() < a_.node_type_name()";
buf << cl->indent << cl->indent << "return typeId() < a_.typeId()";
}
buf << ";" << std::endl;
}
Expand Down

0 comments on commit 9f41b51

Please sign in to comment.