mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 02:28:21 +00:00
Change "when" statements that don't require closures to use new implementation.
Provide hooks for script optimization access to "when" statements. Regularize treatment of naming and timeouts for Triggers.
This commit is contained in:
parent
5eb37e4c78
commit
48f1e4df42
4 changed files with 183 additions and 129 deletions
43
src/Stmt.h
43
src/Stmt.h
|
@ -547,6 +547,10 @@ public:
|
|||
// Takes ownership of the CaptureList, which if nil signifies
|
||||
// old-style frame semantics.
|
||||
WhenInfo(ExprPtr _cond, FuncType::CaptureList* _cl, bool _is_return);
|
||||
|
||||
// Constructor used by script optimization to create a stub.
|
||||
WhenInfo(bool _is_return);
|
||||
|
||||
~WhenInfo() { delete cl; }
|
||||
|
||||
void AddBody(StmtPtr _s) { s = std::move(_s); }
|
||||
|
@ -559,11 +563,18 @@ public:
|
|||
|
||||
// Complete construction of the associated internals, including
|
||||
// the (complex) lambda used to access the different elements of
|
||||
// the statement.
|
||||
void Build(StmtPtr ws);
|
||||
// the statement. The optional argument is only for generating
|
||||
// error messages.
|
||||
void Build(StmtPtr ws = nullptr);
|
||||
|
||||
// Instantiate a new instance.
|
||||
// This is available after a call to Build().
|
||||
const LambdaExprPtr& Lambda() const { return lambda; }
|
||||
|
||||
// Instantiate a new instance, either by evaluating the associated
|
||||
// lambda, or directly using the given function value (for compiled
|
||||
// code).
|
||||
void Instantiate(Frame* f);
|
||||
void Instantiate(ValPtr func);
|
||||
|
||||
// For old-style semantics, the following simply return the
|
||||
// individual "when" components. For capture semantics, however,
|
||||
|
@ -572,15 +583,15 @@ public:
|
|||
ExprPtr Cond();
|
||||
StmtPtr WhenBody();
|
||||
|
||||
ExprPtr TimeoutExpr() { return timeout; }
|
||||
ExprPtr TimeoutExpr() const { return timeout; }
|
||||
double TimeoutVal(Frame* f);
|
||||
|
||||
StmtPtr TimeoutStmt();
|
||||
|
||||
FuncType::CaptureList* Captures() { return cl; }
|
||||
|
||||
bool IsReturn() const { return is_return; }
|
||||
|
||||
const LambdaExprPtr& Lambda() const { return lambda; }
|
||||
|
||||
// The locals and globals used in the conditional expression
|
||||
// (other than newly introduced locals), necessary for registering
|
||||
// the associated triggers for when their values change.
|
||||
|
@ -588,6 +599,15 @@ public:
|
|||
const IDSet& WhenExprGlobals() const { return when_expr_globals; }
|
||||
|
||||
private:
|
||||
// True if the "when" statement corresponds to old-style deprecated
|
||||
// semantics (no captures, but needing captures). Also generates
|
||||
// the corresponding deprecation warnings, which are associated
|
||||
// with "ws".
|
||||
bool IsDeprecatedSemantics(StmtPtr ws);
|
||||
|
||||
// Build those elements we'll need for invoking our lambda.
|
||||
void BuildInvokeElems();
|
||||
|
||||
ExprPtr cond;
|
||||
StmtPtr s;
|
||||
ExprPtr timeout;
|
||||
|
@ -599,8 +619,9 @@ private:
|
|||
// The name of parameter passed ot the lambda.
|
||||
std::string lambda_param_id;
|
||||
|
||||
// The expression for constructing the lambda.
|
||||
// The expression for constructing the lambda, and its type.
|
||||
LambdaExprPtr lambda;
|
||||
FuncTypePtr lambda_ft;
|
||||
|
||||
// The current instance of the lambda. Created by Instantiate(),
|
||||
// for immediate use via calls to Cond() etc.
|
||||
|
@ -612,9 +633,17 @@ private:
|
|||
ListExprPtr invoke_s;
|
||||
ListExprPtr invoke_timeout;
|
||||
|
||||
// Helper expressions for calling the lambda / testing within it.
|
||||
ConstExprPtr one_const;
|
||||
ConstExprPtr two_const;
|
||||
ConstExprPtr three_const;
|
||||
|
||||
IDSet when_expr_locals;
|
||||
IDSet when_expr_globals;
|
||||
|
||||
// Locals introduced via "local" in the "when" clause itself.
|
||||
IDSet when_new_locals;
|
||||
|
||||
// Used for identifying deprecated instances. Holds all of the local
|
||||
// variables in the scope prior to parsing the "when" statement.
|
||||
std::map<std::string, IDPtr, std::less<>> prior_vars;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue