mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Trigger constructor (and factoring) to support lower-level constructions
This commit is contained in:
parent
a16a25efbd
commit
b1e95d68e0
2 changed files with 45 additions and 28 deletions
|
@ -98,15 +98,44 @@ protected:
|
||||||
double time;
|
double time;
|
||||||
};
|
};
|
||||||
|
|
||||||
Trigger::Trigger(Expr* arg_cond, Stmt* arg_body,
|
Trigger::Trigger(const Expr* cond, Stmt* body, Stmt* timeout_stmts,
|
||||||
Stmt* arg_timeout_stmts,
|
Expr* timeout_expr, Frame* frame,
|
||||||
Expr* arg_timeout, Frame* arg_frame,
|
bool is_return, const Location* location)
|
||||||
bool arg_is_return, const Location* arg_location)
|
{
|
||||||
|
timeout_value = -1;
|
||||||
|
|
||||||
|
if ( timeout_expr )
|
||||||
|
{
|
||||||
|
ValPtr timeout_val;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
timeout_val = timeout_expr->Eval(frame);
|
||||||
|
}
|
||||||
|
catch ( InterpreterException& )
|
||||||
|
{ /* Already reported */ }
|
||||||
|
|
||||||
|
timeout_value = timeout_val->AsInterval();
|
||||||
|
}
|
||||||
|
|
||||||
|
Init(cond, body, timeout_stmts, frame, is_return, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
Trigger::Trigger(const Expr* cond, Stmt* body, Stmt* timeout_stmts,
|
||||||
|
double timeout, Frame* frame,
|
||||||
|
bool is_return, const Location* location)
|
||||||
|
{
|
||||||
|
timeout_value = timeout;
|
||||||
|
Init(cond, body, timeout_stmts, frame, is_return, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Trigger::Init(const Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts,
|
||||||
|
Frame* arg_frame, bool arg_is_return,
|
||||||
|
const Location* arg_location)
|
||||||
{
|
{
|
||||||
cond = arg_cond;
|
cond = arg_cond;
|
||||||
body = arg_body;
|
body = arg_body;
|
||||||
timeout_stmts = arg_timeout_stmts;
|
timeout_stmts = arg_timeout_stmts;
|
||||||
timeout = arg_timeout;
|
|
||||||
frame = arg_frame->Clone();
|
frame = arg_frame->Clone();
|
||||||
timer = nullptr;
|
timer = nullptr;
|
||||||
delayed = false;
|
delayed = false;
|
||||||
|
@ -114,7 +143,6 @@ Trigger::Trigger(Expr* arg_cond, Stmt* arg_body,
|
||||||
attached = nullptr;
|
attached = nullptr;
|
||||||
is_return = arg_is_return;
|
is_return = arg_is_return;
|
||||||
location = arg_location;
|
location = arg_location;
|
||||||
timeout_value = -1;
|
|
||||||
|
|
||||||
DBG_LOG(DBG_NOTIFIERS, "%s: instantiating", Name());
|
DBG_LOG(DBG_NOTIFIERS, "%s: instantiating", Name());
|
||||||
|
|
||||||
|
@ -132,23 +160,6 @@ Trigger::Trigger(Expr* arg_cond, Stmt* arg_body,
|
||||||
arg_frame->SetDelayed();
|
arg_frame->SetDelayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
ValPtr timeout_val;
|
|
||||||
|
|
||||||
if ( arg_timeout )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
timeout_val = arg_timeout->Eval(arg_frame);
|
|
||||||
}
|
|
||||||
catch ( InterpreterException& )
|
|
||||||
{ /* Already reported */ }
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( timeout_val )
|
|
||||||
{
|
|
||||||
timeout_value = timeout_val->AsInterval();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure we don't get deleted if somebody calls a method like
|
// Make sure we don't get deleted if somebody calls a method like
|
||||||
// Timeout() while evaluating the trigger.
|
// Timeout() while evaluating the trigger.
|
||||||
Ref(this);
|
Ref(this);
|
||||||
|
@ -198,7 +209,7 @@ Trigger::~Trigger()
|
||||||
// point.
|
// point.
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trigger::Init(std::vector<ValPtr> index_expr_results)
|
void Trigger::ReInit(std::vector<ValPtr> index_expr_results)
|
||||||
{
|
{
|
||||||
assert(! disabled);
|
assert(! disabled);
|
||||||
UnregisterAll();
|
UnregisterAll();
|
||||||
|
@ -276,7 +287,7 @@ bool Trigger::Eval()
|
||||||
// Not true. Perhaps next time...
|
// Not true. Perhaps next time...
|
||||||
DBG_LOG(DBG_NOTIFIERS, "%s: trigger condition is false", Name());
|
DBG_LOG(DBG_NOTIFIERS, "%s: trigger condition is false", Name());
|
||||||
Unref(f);
|
Unref(f);
|
||||||
Init(std::move(index_expr_results));
|
ReInit(std::move(index_expr_results));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,9 @@ public:
|
||||||
// instantiation. Note that if the condition is already true, the
|
// instantiation. Note that if the condition is already true, the
|
||||||
// statements are executed immediately and the object is deleted
|
// statements are executed immediately and the object is deleted
|
||||||
// right away.
|
// right away.
|
||||||
Trigger(Expr* cond, Stmt* body, Stmt* timeout_stmts, Expr* timeout,
|
Trigger(const Expr* cond, Stmt* body, Stmt* timeout_stmts, Expr* timeout,
|
||||||
|
Frame* f, bool is_return, const Location* loc);
|
||||||
|
Trigger(const Expr* cond, Stmt* body, Stmt* timeout_stmts, double timeout,
|
||||||
Frame* f, bool is_return, const Location* loc);
|
Frame* f, bool is_return, const Location* loc);
|
||||||
~Trigger() override;
|
~Trigger() override;
|
||||||
|
|
||||||
|
@ -95,12 +97,16 @@ private:
|
||||||
friend class TriggerTraversalCallback;
|
friend class TriggerTraversalCallback;
|
||||||
friend class TriggerTimer;
|
friend class TriggerTimer;
|
||||||
|
|
||||||
void Init(std::vector<IntrusivePtr<Val>> index_expr_results);
|
void Init(const Expr* cond, Stmt* body, Stmt* timeout_stmts, Frame* frame,
|
||||||
|
bool is_return, const Location* location);
|
||||||
|
|
||||||
|
void ReInit(std::vector<IntrusivePtr<Val>> index_expr_results);
|
||||||
|
|
||||||
void Register(ID* id);
|
void Register(ID* id);
|
||||||
void Register(Val* val);
|
void Register(Val* val);
|
||||||
void UnregisterAll();
|
void UnregisterAll();
|
||||||
|
|
||||||
Expr* cond;
|
const Expr* cond;
|
||||||
Stmt* body;
|
Stmt* body;
|
||||||
Stmt* timeout_stmts;
|
Stmt* timeout_stmts;
|
||||||
Expr* timeout;
|
Expr* timeout;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue