mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 20:48:21 +00:00
Merge remote-tracking branch 'origin/topic/vern/CPP-cond'
* origin/topic/vern/CPP-cond: fix btest comment to more accurately describe the test clang-format issue btests for erroneous script conditionals avoid compiling-to-C++ for functions potentially influenced by conditionals track the use of conditionals in functions and files AST profiles track the associated function/body/expression
This commit is contained in:
commit
6a7bbd5268
14 changed files with 170 additions and 55 deletions
|
@ -6,6 +6,8 @@
|
|||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "zeek/script_opt/StmtOptInfo.h"
|
||||
|
||||
namespace zeek::detail
|
||||
{
|
||||
|
||||
|
@ -50,6 +52,14 @@ bool is_CPP_compilable(const ProfileFunc* pf, const char** reason)
|
|||
return false;
|
||||
}
|
||||
|
||||
auto body = pf->ProfiledBody();
|
||||
if ( body && ! body->GetOptInfo()->is_free_of_conditionals )
|
||||
{
|
||||
if ( reason )
|
||||
*reason = "body may be affected by @if conditional";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,12 +60,23 @@ p_hash_type script_specific_hash(const StmtPtr& body, p_hash_type generic_hash)
|
|||
|
||||
ProfileFunc::ProfileFunc(const Func* func, const StmtPtr& body, bool _abs_rec_fields)
|
||||
{
|
||||
profiled_func = func;
|
||||
profiled_body = body.get();
|
||||
abs_rec_fields = _abs_rec_fields;
|
||||
Profile(func->GetType().get(), body);
|
||||
}
|
||||
|
||||
ProfileFunc::ProfileFunc(const Stmt* s, bool _abs_rec_fields)
|
||||
{
|
||||
profiled_body = s;
|
||||
abs_rec_fields = _abs_rec_fields;
|
||||
s->Traverse(this);
|
||||
}
|
||||
|
||||
ProfileFunc::ProfileFunc(const Expr* e, bool _abs_rec_fields)
|
||||
{
|
||||
profiled_expr = e;
|
||||
|
||||
abs_rec_fields = _abs_rec_fields;
|
||||
|
||||
if ( e->Tag() == EXPR_LAMBDA )
|
||||
|
@ -84,12 +95,6 @@ ProfileFunc::ProfileFunc(const Expr* e, bool _abs_rec_fields)
|
|||
e->Traverse(this);
|
||||
}
|
||||
|
||||
ProfileFunc::ProfileFunc(const Stmt* s, bool _abs_rec_fields)
|
||||
{
|
||||
abs_rec_fields = _abs_rec_fields;
|
||||
s->Traverse(this);
|
||||
}
|
||||
|
||||
void ProfileFunc::Profile(const FuncType* ft, const StmtPtr& body)
|
||||
{
|
||||
num_params = ft->Params()->NumFields();
|
||||
|
|
|
@ -100,6 +100,12 @@ public:
|
|||
ProfileFunc(const Stmt* body, bool abs_rec_fields = false);
|
||||
ProfileFunc(const Expr* func, bool abs_rec_fields = false);
|
||||
|
||||
// Returns the function, body, or expression profiled. Each can be
|
||||
// null depending on the constructor used.
|
||||
const Func* ProfiledFunc() const { return profiled_func; }
|
||||
const Stmt* ProfiledBody() const { return profiled_body; }
|
||||
const Expr* ProfiledExpr() const { return profiled_expr; }
|
||||
|
||||
// See the comments for the associated member variables for each
|
||||
// of these accessors.
|
||||
const std::unordered_set<const ID*>& Globals() const { return globals; }
|
||||
|
@ -157,6 +163,12 @@ protected:
|
|||
// Take note of an assignment to an identifier.
|
||||
void TrackAssignment(const ID* id);
|
||||
|
||||
// The function, body, or expression profiled. Can be null
|
||||
// depending on which constructor was used.
|
||||
const Func* profiled_func = nullptr;
|
||||
const Stmt* profiled_body = nullptr;
|
||||
const Expr* profiled_expr = nullptr;
|
||||
|
||||
// Globals seen in the function.
|
||||
//
|
||||
// Does *not* include globals solely seen as the function being
|
||||
|
|
|
@ -22,6 +22,10 @@ public:
|
|||
// True if we observe that there is a branch out of the statement
|
||||
// to just beyond its extent, such as due to a "break".
|
||||
bool contains_branch_beyond = false;
|
||||
|
||||
// Whether this statement is free of the possible influence
|
||||
// of conditional code.
|
||||
bool is_free_of_conditionals = true;
|
||||
};
|
||||
|
||||
} // namespace zeek::detail
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue