diff --git a/backends/p4tools/p4tools.def b/backends/p4tools/p4tools.def index 062a7db451b..205c7b4dc22 100644 --- a/backends/p4tools/p4tools.def +++ b/backends/p4tools/p4tools.def @@ -30,7 +30,7 @@ class StateVariable : Expression { isSemanticallyLess { if (static_cast(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(a_); return compare(ref, a.ref) < 0; } @@ -137,7 +137,7 @@ class SymbolicVariable : Expression { isSemanticallyLess { if (static_cast(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(a_); return label < a.label; /* ignore type */ } @@ -226,7 +226,7 @@ public: isSemanticallyLess { if (static_cast(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(a_); return label < a.label; /* ignore type */ } diff --git a/ir/base.def b/ir/base.def index 58e7a3ef94a..1b4452f74fd 100644 --- a/ir/base.def +++ b/ir/base.def @@ -230,7 +230,7 @@ class AnnotationToken { dbprint { out << text; } isSemanticallyLess { if (static_cast(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(a_); return IR::isSemanticallyLess(token_type, a.token_type) || IR::isSemanticallyLess(text, a.text) diff --git a/ir/expression.def b/ir/expression.def index 4dbcbdfbe95..f39491876f2 100644 --- a/ir/expression.def +++ b/ir/expression.def @@ -254,7 +254,7 @@ class Constant : Literal { visit_children { v.visit(type, "type"); } isSemanticallyLess { if (static_cast(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(a_); return value < a.value; /* ignore base */ diff --git a/ir/node.h b/ir/node.h index e1ae698ec8e..a3a8df5924f 100644 --- a/ir/node.h +++ b/ir/node.h @@ -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; } diff --git a/ir/type.def b/ir/type.def index c181906178f..ad81c4513dc 100644 --- a/ir/type.def +++ b/ir/type.def @@ -89,7 +89,7 @@ class Type_Any : Type, ITypeVar { isSemanticallyLess { if (static_cast(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 */ } } @@ -240,7 +240,7 @@ class Type_InfInt : Type, ITypeVar { isSemanticallyLess { if (static_cast(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; } } diff --git a/ir/v1.def b/ir/v1.def index 75f05390793..f756a3a49fa 100644 --- a/ir/v1.def +++ b/ir/v1.def @@ -247,7 +247,7 @@ class CalculatedField : IAnnotated { v.visit(annotations, "annotations"); } isSemanticallyLess { if (static_cast(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(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); }) diff --git a/test/gtest/semantically_less_test.cpp b/test/gtest/semantically_less_test.cpp index eb75ee96ee3..c8e82fc8c2e 100644 --- a/test/gtest/semantically_less_test.cpp +++ b/test/gtest/semantically_less_test.cpp @@ -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); @@ -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) { @@ -190,8 +190,8 @@ TEST(OperatorLess, ConstantVectors) { auto *p5 = new IR::IndexedVector(new IR::Constant(t, 0)); auto *p6 = new IR::IndexedVector(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); diff --git a/tools/ir-generator/methods.cpp b/tools/ir-generator/methods.cpp index 3e5126b62eb..71065f11422 100644 --- a/tools/ir-generator/methods.cpp +++ b/tools/ir-generator/methods.cpp @@ -137,8 +137,8 @@ const ordered_map IrMethod::Generate = { << "if (static_cast(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) @@ -174,8 +174,7 @@ const ordered_map 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; }