37 : refMap(refMap), typeMap(typeMap), removeStatement(
false) {
40 setName(
"DoStaticAssert");
42 const IR::Node *postorder(IR::MethodCallExpression *method)
override {
45 if (ef->method->name ==
"static_assert") {
46 auto subst = ef->substitution;
47 auto params = subst.getParametersInOrder();
48 if (!params->moveNext()) {
49 ::warning(ErrorType::WARN_INVALID,
"static_assert with no arguments: %1%",
53 auto param = params->getCurrent();
55 auto arg = subst.lookup(param);
57 if (
auto bl = arg->expression->to<IR::BoolLiteral>()) {
59 cstring message =
"static_assert failed";
60 if (params->moveNext()) {
61 param = params->getCurrent();
63 auto msg = subst.lookup(param);
65 if (
auto sl = msg->expression->to<IR::StringLiteral>()) {
69 ::error(ErrorType::ERR_EXPECTED,
"%1%: %2%", method, message);
72 if (getContext()->node->is<IR::MethodCallStatement>()) {
73 removeStatement =
true;
76 return new IR::BoolLiteral(method->srcInfo,
true);
78 ::error(ErrorType::ERR_UNEXPECTED,
79 "Could not evaluate static_assert to a constant: %1%", arg);
87 const IR::Node *postorder(IR::MethodCallStatement *statement)
override {
88 if (removeStatement) {
89 removeStatement =
false;
static MethodInstance * resolve(const IR::MethodCallExpression *mce, DeclarationLookup *refMap, TypeMap *typeMap, bool useExpressionType=false, const Visitor::Context *ctxt=nullptr, bool incomplete=false)
Definition methodInstance.cpp:26