35class DoStaticAssert :
public Transform,
public ResolutionContext {
37 bool removeStatement =
false;
40 explicit DoStaticAssert(
TypeMap *typeMap) : typeMap(typeMap) {
42 setName(
"DoStaticAssert");
44 const IR::Node *postorder(IR::MethodCallExpression *method)
override {
47 if (ef->method->name == staticAssertMethodName) {
48 auto subst = ef->substitution;
49 auto params = subst.getParametersInOrder();
50 if (!params->moveNext()) {
51 ::P4::warning(ErrorType::WARN_INVALID,
"static_assert with no arguments: %1%",
55 auto param = params->getCurrent();
57 auto arg = subst.lookup(param);
59 if (
auto bl = arg->expression->to<IR::BoolLiteral>()) {
61 std::string_view message =
"static_assert failed";
62 if (params->moveNext()) {
63 param = params->getCurrent();
65 auto msg = subst.lookup(param);
67 if (
const auto *sl = msg->expression->to<IR::StringLiteral>()) {
71 ::P4::error(ErrorType::ERR_EXPECTED,
"%1%: %2%", method, message);
74 if (getContext()->node->is<IR::MethodCallStatement>()) {
75 removeStatement =
true;
78 return new IR::BoolLiteral(method->srcInfo,
true);
81 "Could not evaluate static_assert to a constant: %1%", arg);
89 const IR::Node *postorder(IR::MethodCallStatement *statement)
override {
90 if (removeStatement) {
91 removeStatement =
false;
static MethodInstance * resolve(const IR::MethodCallExpression *mce, const DeclarationLookup *refMap, TypeMap *typeMap, bool useExpressionType=false, const Visitor::Context *ctxt=nullptr, bool incomplete=false)
Definition methodInstance.cpp:27
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
void warning(const char *format, Args &&...args)
Report a warning with the given message.
Definition lib/error.h:128
void error(const char *format, Args &&...args)
Report an error with the given message.
Definition lib/error.h:58