mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
fixes for doing "script validation" to check for ZAM compile-ability
This commit is contained in:
parent
cae5d30c62
commit
2c5b5bb41f
3 changed files with 20 additions and 12 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,12 @@ class Stmt;
|
|||
void script_validation();
|
||||
|
||||
/**
|
||||
* Returns true if the given script statement (body) is valid.
|
||||
* Returns true if the given script statement (body) is valid. The
|
||||
* second argument indicates whether the statement is the body of a hook.
|
||||
*
|
||||
* Unlike script_validation(), does not report any errors, just returns
|
||||
* whether they are present.
|
||||
*/
|
||||
bool script_is_valid(const Stmt* s);
|
||||
bool script_is_valid(const Stmt* s, bool is_in_hook);
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@ bool is_ZAM_compilable(const ProfileFunc* pf, const char** reason)
|
|||
}
|
||||
|
||||
auto b = pf->ProfiledBody();
|
||||
if ( b && ! script_is_valid(b) )
|
||||
auto is_hook = pf->ProfiledFunc()->Flavor() == FUNC_FLAVOR_HOOK;
|
||||
if ( b && ! script_is_valid(b, is_hook) )
|
||||
{
|
||||
if ( reason )
|
||||
*reason = "invalid script body";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue