fixes for doing "script validation" to check for ZAM compile-ability

This commit is contained in:
Vern Paxson 2023-06-14 17:39:47 -07:00
parent cae5d30c62
commit 2c5b5bb41f
3 changed files with 20 additions and 12 deletions

View file

@ -22,11 +22,11 @@ public:
stmt_depths[stmt->Tag()] += 1;
if ( stmt->Tag() == STMT_BREAK && ! BreakStmtIsValid() )
Error(stmt, "break statement used outside of for, while or "
"switch statement and not within a hook.");
Report(stmt, "break statement used outside of for, while or "
"switch statement and not within a hook.");
if ( stmt->Tag() == STMT_NEXT && ! NextStmtIsValid() )
Error(stmt, "next statement used outside of for or while statement.");
Report(stmt, "next statement used outside of for or while statement.");
return TC_CONTINUE;
}
@ -63,6 +63,8 @@ public:
return TC_CONTINUE;
}
void SetHookDepth(int hd) { hook_depth = hd; }
bool IsValid() const { return valid_script; }
private:
@ -84,11 +86,7 @@ private:
void Report(const Stmt* stmt, const char* msg)
{
if ( report )
{
zeek::reporter->PushLocation(stmt->GetLocationInfo());
zeek::reporter->Warning("%s", msg);
zeek::reporter->PopLocation();
}
Error(stmt, msg);
valid_script = false;
}
@ -105,10 +103,15 @@ void script_validation()
traverse_all(&bn_cb);
}
bool script_is_valid(const Stmt* stmt)
bool script_is_valid(const Stmt* stmt, bool is_in_hook)
{
BreakNextScriptValidation bn_cb(false);
if ( is_in_hook )
bn_cb.SetHookDepth(1);
stmt->Traverse(&bn_cb);
return bn_cb.IsValid();
}