Stmt: use class IntrusivePtr

This commit is contained in:
Max Kellermann 2020-02-27 10:19:15 +01:00
parent 50ae129c57
commit 46397de5c0
6 changed files with 176 additions and 218 deletions

View file

@ -387,7 +387,7 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
try
{
result = body.stmts->Exec(f, flow);
result = body.stmts->Exec(f, flow).release();
}
catch ( InterpreterException& e )

View file

@ -130,11 +130,9 @@ void Stmt::AccessStats(ODesc* d) const
}
}
ExprListStmt::ExprListStmt(BroStmtTag t, ListExpr* arg_l)
: Stmt(t)
ExprListStmt::ExprListStmt(BroStmtTag t, IntrusivePtr<ListExpr> arg_l)
: Stmt(t), l(std::move(arg_l))
{
l = arg_l;
const expr_list& e = l->Exprs();
for ( const auto& expr : e )
{
@ -143,23 +141,20 @@ ExprListStmt::ExprListStmt(BroStmtTag t, ListExpr* arg_l)
Error("value of type void illegal");
}
SetLocationInfo(arg_l->GetLocationInfo());
SetLocationInfo(l->GetLocationInfo());
}
ExprListStmt::~ExprListStmt()
{
Unref(l);
}
ExprListStmt::~ExprListStmt() = default;
Val* ExprListStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> ExprListStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
last_access = network_time;
flow = FLOW_NEXT;
val_list* vals = eval_list(f, l);
val_list* vals = eval_list(f, l.get());
if ( vals )
{
Val* result = DoExec(vals, flow);
auto result = DoExec(vals, flow);
delete_vals(vals);
return result;
}
@ -212,7 +207,7 @@ static IntrusivePtr<EnumVal> lookup_enum_val(const char* module_name, const char
return rval;
}
static Val* print_log(val_list* vals)
static IntrusivePtr<Val> print_log(val_list* vals)
{
auto plval = lookup_enum_val("Log", "PRINTLOG");
auto record = make_intrusive<RecordVal>(internal_type("Log::PrintLogInfo")->AsRecordType());
@ -231,7 +226,7 @@ static Val* print_log(val_list* vals)
return nullptr;
}
Val* PrintStmt::DoExec(val_list* vals, stmt_flow_type& /* flow */) const
IntrusivePtr<Val> PrintStmt::DoExec(val_list* vals, stmt_flow_type& /* flow */) const
{
RegisterAccess();
@ -294,29 +289,23 @@ Val* PrintStmt::DoExec(val_list* vals, stmt_flow_type& /* flow */) const
return 0;
}
ExprStmt::ExprStmt(Expr* arg_e) : Stmt(STMT_EXPR)
ExprStmt::ExprStmt(IntrusivePtr<Expr> arg_e) : Stmt(STMT_EXPR), e(std::move(arg_e))
{
e = arg_e;
if ( e && e->IsPure() )
Warn("expression value ignored");
SetLocationInfo(arg_e->GetLocationInfo());
SetLocationInfo(e->GetLocationInfo());
}
ExprStmt::ExprStmt(BroStmtTag t, Expr* arg_e) : Stmt(t)
ExprStmt::ExprStmt(BroStmtTag t, IntrusivePtr<Expr> arg_e) : Stmt(t), e(std::move(arg_e))
{
e = arg_e;
if ( e )
SetLocationInfo(e->GetLocationInfo());
}
ExprStmt::~ExprStmt()
{
Unref(e);
}
ExprStmt::~ExprStmt() = default;
Val* ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
@ -329,7 +318,7 @@ Val* ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const
return 0;
}
Val* ExprStmt::DoExec(Frame* /* f */, Val* /* v */, stmt_flow_type& /* flow */) const
IntrusivePtr<Val> ExprStmt::DoExec(Frame* /* f */, Val* /* v */, stmt_flow_type& /* flow */) const
{
return 0;
}
@ -375,29 +364,23 @@ TraversalCode ExprStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
IfStmt::IfStmt(Expr* test, Stmt* arg_s1, Stmt* arg_s2) : ExprStmt(STMT_IF, test)
IfStmt::IfStmt(IntrusivePtr<Expr> test, IntrusivePtr<Stmt> arg_s1, IntrusivePtr<Stmt> arg_s2)
: ExprStmt(STMT_IF, std::move(test)), s1(std::move(arg_s1)), s2(std::move(arg_s2))
{
s1 = arg_s1;
s2 = arg_s2;
if ( ! e->IsError() && ! IsBool(e->Type()->Tag()) )
e->Error("conditional in test must be boolean");
const Location* loc1 = arg_s1->GetLocationInfo();
const Location* loc2 = arg_s2->GetLocationInfo();
const Location* loc1 = s1->GetLocationInfo();
const Location* loc2 = s2->GetLocationInfo();
SetLocationInfo(loc1, loc2);
}
IfStmt::~IfStmt()
{
Unref(s1);
Unref(s2);
}
IfStmt::~IfStmt() = default;
Val* IfStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
IntrusivePtr<Val> IfStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
{
// Treat 0 as false, but don't require 1 for true.
Stmt* do_stmt = v->IsZero() ? s2 : s1;
Stmt* do_stmt = v->IsZero() ? s2.get() : s1.get();
f->SetNextStmt(do_stmt);
@ -405,9 +388,9 @@ Val* IfStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
{ // ### Abort or something
}
Val* result = do_stmt->Exec(f, flow);
auto result = do_stmt->Exec(f, flow);
if ( ! post_execute_stmt(do_stmt, f, result, &flow) )
if ( ! post_execute_stmt(do_stmt, f, result.get(), &flow) )
{ // ### Abort or something
}
@ -479,8 +462,8 @@ static BroStmtTag get_last_stmt_tag(const Stmt* stmt)
return get_last_stmt_tag(stmts->Stmts()[len - 1]);
}
Case::Case(ListExpr* arg_expr_cases, id_list* arg_type_cases, Stmt* arg_s)
: expr_cases(arg_expr_cases), type_cases(arg_type_cases), s(arg_s)
Case::Case(IntrusivePtr<ListExpr> arg_expr_cases, id_list* arg_type_cases, IntrusivePtr<Stmt> arg_s)
: expr_cases(std::move(arg_expr_cases)), type_cases(arg_type_cases), s(std::move(arg_s))
{
BroStmtTag t = get_last_stmt_tag(Body());
@ -490,9 +473,6 @@ Case::Case(ListExpr* arg_expr_cases, id_list* arg_type_cases, Stmt* arg_s)
Case::~Case()
{
Unref(expr_cases);
Unref(s);
for ( const auto& id : *type_cases )
Unref(id);
@ -605,8 +585,8 @@ void SwitchStmt::Init()
case_label_value_map.SetDeleteFunc(int_del_func);
}
SwitchStmt::SwitchStmt(Expr* index, case_list* arg_cases) :
ExprStmt(STMT_SWITCH, index), cases(arg_cases), default_case_idx(-1)
SwitchStmt::SwitchStmt(IntrusivePtr<Expr> index, case_list* arg_cases) :
ExprStmt(STMT_SWITCH, std::move(index)), cases(arg_cases), default_case_idx(-1)
{
Init();
@ -628,7 +608,7 @@ SwitchStmt::SwitchStmt(Expr* index, case_list* arg_cases) :
if ( ! le->Type()->AsTypeList()->AllMatch(e->Type(), false) )
{
le->Error("case expression type differs from switch type", e);
le->Error("case expression type differs from switch type", e.get());
continue;
}
@ -816,9 +796,9 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
return std::make_pair(label_idx, label_id);
}
Val* SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
IntrusivePtr<Val> SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
{
Val* rval = 0;
IntrusivePtr<Val> rval;
auto m = FindCaseLabelMatch(v);
int matching_label_idx = m.first;
@ -901,7 +881,7 @@ TraversalCode SwitchStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
AddStmt::AddStmt(Expr* arg_e) : ExprStmt(STMT_ADD, arg_e)
AddStmt::AddStmt(IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_ADD, std::move(arg_e))
{
if ( ! e->CanAdd() )
Error("illegal add statement");
@ -912,7 +892,7 @@ int AddStmt::IsPure() const
return 0;
}
Val* AddStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> AddStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
@ -934,7 +914,7 @@ TraversalCode AddStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
DelStmt::DelStmt(Expr* arg_e) : ExprStmt(STMT_DELETE, arg_e)
DelStmt::DelStmt(IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e))
{
if ( e->IsError() )
return;
@ -948,7 +928,7 @@ int DelStmt::IsPure() const
return 0;
}
Val* DelStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> DelStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
@ -969,12 +949,11 @@ TraversalCode DelStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
EventStmt::EventStmt(EventExpr* arg_e) : ExprStmt(STMT_EVENT, arg_e)
EventStmt::EventStmt(IntrusivePtr<EventExpr> arg_e) : ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e))
{
event_expr = arg_e;
}
Val* EventStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> EventStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
val_list* args = eval_list(f, event_expr->Args());
@ -1003,19 +982,15 @@ TraversalCode EventStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
WhileStmt::WhileStmt(Expr* arg_loop_condition, Stmt* arg_body)
: loop_condition(arg_loop_condition), body(arg_body)
WhileStmt::WhileStmt(IntrusivePtr<Expr> arg_loop_condition, IntrusivePtr<Stmt> arg_body)
: loop_condition(std::move(arg_loop_condition)), body(std::move(arg_body))
{
if ( ! loop_condition->IsError() &&
! IsBool(loop_condition->Type()->Tag()) )
loop_condition->Error("while conditional must be boolean");
}
WhileStmt::~WhileStmt()
{
Unref(loop_condition);
Unref(body);
}
WhileStmt::~WhileStmt() = default;
int WhileStmt::IsPure() const
{
@ -1056,11 +1031,11 @@ TraversalCode WhileStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
Val* WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
Val* rval = 0;
IntrusivePtr<Val> rval;
for ( ; ; )
{
@ -1085,8 +1060,8 @@ Val* WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const
return rval;
}
ForStmt::ForStmt(id_list* arg_loop_vars, Expr* loop_expr)
: ExprStmt(STMT_FOR, loop_expr)
ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
: ExprStmt(STMT_FOR, std::move(loop_expr))
{
loop_vars = arg_loop_vars;
body = 0;
@ -1163,10 +1138,10 @@ ForStmt::ForStmt(id_list* arg_loop_vars, Expr* loop_expr)
e->Error("target to iterate over must be a table, set, vector, or string");
}
ForStmt::ForStmt(id_list* arg_loop_vars, Expr* loop_expr, ID* val_var)
: ForStmt(arg_loop_vars, loop_expr)
ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr, IntrusivePtr<ID> val_var)
: ForStmt(arg_loop_vars, std::move(loop_expr))
{
value_var = val_var;
value_var = std::move(val_var);
if ( e->Type()->IsTable() )
{
@ -1180,7 +1155,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, Expr* loop_expr, ID* val_var)
}
else
{
add_local({NewRef{}, value_var}, {NewRef{}, yield_type}, INIT_NONE,
add_local(value_var, {NewRef{}, yield_type}, INIT_NONE,
0, 0, VAR_REGULAR);
}
}
@ -1193,14 +1168,11 @@ ForStmt::~ForStmt()
for ( const auto& var : *loop_vars )
Unref(var);
delete loop_vars;
Unref(value_var);
Unref(body);
}
Val* ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
IntrusivePtr<Val> ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
{
Val* ret = 0;
IntrusivePtr<Val> ret;
if ( v->Type()->Tag() == TYPE_TABLE )
{
@ -1219,7 +1191,7 @@ Val* ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
delete k;
if ( value_var )
f->SetElement(value_var, current_tev->Value()->Ref());
f->SetElement(value_var.get(), current_tev->Value()->Ref());
for ( int i = 0; i < ind_lv->Length(); i++ )
f->SetElement((*loop_vars)[i], ind_lv->Index(i)->Ref());
@ -1349,7 +1321,7 @@ TraversalCode ForStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
Val* NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
IntrusivePtr<Val> NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_LOOP;
@ -1376,7 +1348,7 @@ TraversalCode NextStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
Val* BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
IntrusivePtr<Val> BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_BREAK;
@ -1403,7 +1375,7 @@ TraversalCode BreakStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
Val* FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
IntrusivePtr<Val> FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_FALLTHROUGH;
@ -1430,7 +1402,7 @@ TraversalCode FallthroughStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
ReturnStmt::ReturnStmt(Expr* arg_e) : ExprStmt(STMT_RETURN, arg_e)
ReturnStmt::ReturnStmt(IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_RETURN, std::move(arg_e))
{
Scope* s = current_scope();
@ -1465,16 +1437,20 @@ ReturnStmt::ReturnStmt(Expr* arg_e) : ExprStmt(STMT_RETURN, arg_e)
}
else
(void) check_and_promote_expr(e, yt);
{
Expr *e_ = e.release();
(void) check_and_promote_expr(e_, yt);
e = {AdoptRef{}, e_};
}
}
Val* ReturnStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> ReturnStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_RETURN;
if ( e )
return e->Eval(f).release();
return e->Eval(f);
else
return 0;
}
@ -1507,7 +1483,7 @@ StmtList::~StmtList()
Unref(stmt);
}
Val* StmtList::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> StmtList::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
@ -1520,9 +1496,9 @@ Val* StmtList::Exec(Frame* f, stmt_flow_type& flow) const
{ // ### Abort or something
}
Val* result = stmt->Exec(f, flow);
auto result = stmt->Exec(f, flow);
if ( ! post_execute_stmt(stmt, f, result, &flow) )
if ( ! post_execute_stmt(stmt, f, result.get(), &flow) )
{ // ### Abort or something
}
@ -1586,7 +1562,7 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
Val* EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
@ -1603,9 +1579,9 @@ Val* EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const
{ // ### Abort or something
}
Val* result = stmt->Exec(f, flow);
auto result = stmt->Exec(f, flow);
if ( ! post_execute_stmt(stmt, f, result, &flow) )
if ( ! post_execute_stmt(stmt, f, result.get(), &flow) )
{ // ### Abort or something
}
}
@ -1659,7 +1635,7 @@ InitStmt::~InitStmt()
delete inits;
}
Val* InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
@ -1723,7 +1699,7 @@ TraversalCode InitStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
Val* NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
IntrusivePtr<Val> NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
@ -1752,17 +1728,13 @@ TraversalCode NullStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc);
}
WhenStmt::WhenStmt(Expr* arg_cond, Stmt* arg_s1, Stmt* arg_s2,
Expr* arg_timeout, bool arg_is_return)
: Stmt(STMT_WHEN)
WhenStmt::WhenStmt(IntrusivePtr<Expr> arg_cond, IntrusivePtr<Stmt> arg_s1, IntrusivePtr<Stmt> arg_s2,
IntrusivePtr<Expr> arg_timeout, bool arg_is_return)
: Stmt(STMT_WHEN), cond(std::move(arg_cond)), s1(std::move(arg_s1)), s2(std::move(arg_s2)), timeout(std::move(arg_timeout))
{
assert(arg_cond);
assert(arg_s1);
assert(cond);
assert(s1);
cond = arg_cond;
s1 = arg_s1;
s2 = arg_s2;
timeout = arg_timeout;
is_return = arg_is_return;
if ( ! cond->IsError() && ! IsBool(cond->Type()->Tag()) )
@ -1779,27 +1751,15 @@ WhenStmt::WhenStmt(Expr* arg_cond, Stmt* arg_s1, Stmt* arg_s2,
}
}
WhenStmt::~WhenStmt()
{
Unref(cond);
Unref(s1);
Unref(s2);
}
WhenStmt::~WhenStmt() = default;
Val* WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const
IntrusivePtr<Val> WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const
{
RegisterAccess();
flow = FLOW_NEXT;
::Ref(cond);
::Ref(s1);
if ( s2 )
::Ref(s2);
if ( timeout )
::Ref(timeout);
// The new trigger object will take care of its own deletion.
new trigger::Trigger(cond, s1, s2, timeout, f, is_return, location);
new trigger::Trigger(IntrusivePtr{cond}.release(), IntrusivePtr{s1}.release(), IntrusivePtr{s2}.release(), IntrusivePtr{timeout}.release(), f, is_return, location);
return 0;
}

View file

@ -26,7 +26,7 @@ public:
~Stmt() override;
virtual Val* Exec(Frame* f, stmt_flow_type& flow) const = 0;
virtual IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const = 0;
Stmt* Ref() { ::Ref(this); return this; }
@ -85,104 +85,105 @@ protected:
class ExprListStmt : public Stmt {
public:
const ListExpr* ExprList() const { return l; }
const ListExpr* ExprList() const { return l.get(); }
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
ExprListStmt(BroStmtTag t, ListExpr* arg_l);
ExprListStmt(BroStmtTag t, IntrusivePtr<ListExpr> arg_l);
~ExprListStmt() override;
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
virtual Val* DoExec(val_list* vals, stmt_flow_type& flow) const = 0;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
virtual IntrusivePtr<Val> DoExec(val_list* vals, stmt_flow_type& flow) const = 0;
void Describe(ODesc* d) const override;
void PrintVals(ODesc* d, val_list* vals, int offset) const;
ListExpr* l;
IntrusivePtr<ListExpr> l;
};
class PrintStmt : public ExprListStmt {
public:
explicit PrintStmt(ListExpr* l) : ExprListStmt(STMT_PRINT, l) { }
template<typename L>
explicit PrintStmt(L &&l) : ExprListStmt(STMT_PRINT, std::forward<L>(l)) { }
protected:
Val* DoExec(val_list* vals, stmt_flow_type& flow) const override;
IntrusivePtr<Val> DoExec(val_list* vals, stmt_flow_type& flow) const override;
};
class ExprStmt : public Stmt {
public:
explicit ExprStmt(Expr* e);
explicit ExprStmt(IntrusivePtr<Expr> e);
~ExprStmt() override;
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
const Expr* StmtExpr() const { return e; }
const Expr* StmtExpr() const { return e.get(); }
void Describe(ODesc* d) const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
ExprStmt(BroStmtTag t, Expr* e);
ExprStmt(BroStmtTag t, IntrusivePtr<Expr> e);
virtual Val* DoExec(Frame* f, Val* v, stmt_flow_type& flow) const;
virtual IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const;
int IsPure() const override;
Expr* e;
IntrusivePtr<Expr> e;
};
class IfStmt : public ExprStmt {
public:
IfStmt(Expr* test, Stmt* s1, Stmt* s2);
IfStmt(IntrusivePtr<Expr> test, IntrusivePtr<Stmt> s1, IntrusivePtr<Stmt> s2);
~IfStmt() override;
const Stmt* TrueBranch() const { return s1; }
const Stmt* FalseBranch() const { return s2; }
const Stmt* TrueBranch() const { return s1.get(); }
const Stmt* FalseBranch() const { return s2.get(); }
void Describe(ODesc* d) const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
Val* DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
int IsPure() const override;
Stmt* s1;
Stmt* s2;
IntrusivePtr<Stmt> s1;
IntrusivePtr<Stmt> s2;
};
class Case : public BroObj {
public:
Case(ListExpr* c, id_list* types, Stmt* arg_s);
Case(IntrusivePtr<ListExpr> c, id_list* types, IntrusivePtr<Stmt> arg_s);
~Case() override;
const ListExpr* ExprCases() const { return expr_cases; }
ListExpr* ExprCases() { return expr_cases; }
const ListExpr* ExprCases() const { return expr_cases.get(); }
ListExpr* ExprCases() { return expr_cases.get(); }
const id_list* TypeCases() const { return type_cases; }
id_list* TypeCases() { return type_cases; }
const Stmt* Body() const { return s; }
Stmt* Body() { return s; }
const Stmt* Body() const { return s.get(); }
Stmt* Body() { return s.get(); }
void Describe(ODesc* d) const override;
TraversalCode Traverse(TraversalCallback* cb) const;
protected:
ListExpr* expr_cases;
IntrusivePtr<ListExpr> expr_cases;
id_list* type_cases;
Stmt* s;
IntrusivePtr<Stmt> s;
};
typedef PList<Case> case_list;
class SwitchStmt : public ExprStmt {
public:
SwitchStmt(Expr* index, case_list* cases);
SwitchStmt(IntrusivePtr<Expr> index, case_list* cases);
~SwitchStmt() override;
const case_list* Cases() const { return cases; }
@ -192,7 +193,7 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
Val* DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
int IsPure() const override;
// Initialize composite hash and case label map.
@ -223,40 +224,40 @@ protected:
class AddStmt : public ExprStmt {
public:
explicit AddStmt(Expr* e);
explicit AddStmt(IntrusivePtr<Expr> e);
int IsPure() const override;
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
};
class DelStmt : public ExprStmt {
public:
explicit DelStmt(Expr* e);
explicit DelStmt(IntrusivePtr<Expr> e);
int IsPure() const override;
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
};
class EventStmt : public ExprStmt {
public:
explicit EventStmt(EventExpr* e);
explicit EventStmt(IntrusivePtr<EventExpr> e);
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
EventExpr* event_expr;
IntrusivePtr<EventExpr> event_expr;
};
class WhileStmt : public Stmt {
public:
WhileStmt(Expr* loop_condition, Stmt* body);
WhileStmt(IntrusivePtr<Expr> loop_condition, IntrusivePtr<Stmt> body);
~WhileStmt() override;
int IsPure() const override;
@ -266,24 +267,24 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
Expr* loop_condition;
Stmt* body;
IntrusivePtr<Expr> loop_condition;
IntrusivePtr<Stmt> body;
};
class ForStmt : public ExprStmt {
public:
ForStmt(id_list* loop_vars, Expr* loop_expr);
ForStmt(id_list* loop_vars, IntrusivePtr<Expr> loop_expr);
// Special constructor for key value for loop.
ForStmt(id_list* loop_vars, Expr* loop_expr, ID* val_var);
ForStmt(id_list* loop_vars, IntrusivePtr<Expr> loop_expr, IntrusivePtr<ID> val_var);
~ForStmt() override;
void AddBody(Stmt* arg_body) { body = arg_body; }
void AddBody(IntrusivePtr<Stmt> arg_body) { body = std::move(arg_body); }
const id_list* LoopVar() const { return loop_vars; }
const Expr* LoopExpr() const { return e; }
const Stmt* LoopBody() const { return body; }
const Expr* LoopExpr() const { return e.get(); }
const Stmt* LoopBody() const { return body.get(); }
int IsPure() const override;
@ -292,20 +293,20 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
Val* DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
id_list* loop_vars;
Stmt* body;
IntrusivePtr<Stmt> body;
// Stores the value variable being used for a key value for loop.
// Always set to nullptr unless special constructor is called.
ID* value_var = nullptr;
IntrusivePtr<ID> value_var;
};
class NextStmt : public Stmt {
public:
NextStmt() : Stmt(STMT_NEXT) { }
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override;
void Describe(ODesc* d) const override;
@ -319,7 +320,7 @@ class BreakStmt : public Stmt {
public:
BreakStmt() : Stmt(STMT_BREAK) { }
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override;
void Describe(ODesc* d) const override;
@ -333,7 +334,7 @@ class FallthroughStmt : public Stmt {
public:
FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { }
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override;
void Describe(ODesc* d) const override;
@ -345,9 +346,9 @@ protected:
class ReturnStmt : public ExprStmt {
public:
explicit ReturnStmt(Expr* e);
explicit ReturnStmt(IntrusivePtr<Expr> e);
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
void Describe(ODesc* d) const override;
};
@ -357,7 +358,7 @@ public:
StmtList();
~StmtList() override;
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
const stmt_list& Stmts() const { return stmts; }
stmt_list& Stmts() { return stmts; }
@ -377,7 +378,7 @@ public:
EventBodyList() : StmtList()
{ topmost = false; tag = STMT_EVENT_BODY_LIST; }
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
void Describe(ODesc* d) const override;
@ -395,7 +396,7 @@ public:
~InitStmt() override;
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
const id_list* Inits() const { return inits; }
@ -411,7 +412,7 @@ class NullStmt : public Stmt {
public:
NullStmt() : Stmt(STMT_NULL) { }
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override;
void Describe(ODesc* d) const override;
@ -422,25 +423,25 @@ public:
class WhenStmt : public Stmt {
public:
// s2 is null if no timeout block given.
WhenStmt(Expr* cond, Stmt* s1, Stmt* s2, Expr* timeout, bool is_return);
WhenStmt(IntrusivePtr<Expr> cond, IntrusivePtr<Stmt> s1, IntrusivePtr<Stmt> s2, IntrusivePtr<Expr> timeout, bool is_return);
~WhenStmt() override;
Val* Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
int IsPure() const override;
const Expr* Cond() const { return cond; }
const Stmt* Body() const { return s1; }
const Expr* TimeoutExpr() const { return timeout; }
const Stmt* TimeoutBody() const { return s2; }
const Expr* Cond() const { return cond.get(); }
const Stmt* Body() const { return s1.get(); }
const Expr* TimeoutExpr() const { return timeout.get(); }
const Stmt* TimeoutBody() const { return s2.get(); }
void Describe(ODesc* d) const override;
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
Expr* cond;
Stmt* s1;
Stmt* s2;
Expr* timeout;
IntrusivePtr<Expr> cond;
IntrusivePtr<Stmt> s1;
IntrusivePtr<Stmt> s2;
IntrusivePtr<Expr> timeout;
bool is_return;
};

View file

@ -303,7 +303,7 @@ bool Trigger::Eval()
try
{
v = {AdoptRef{}, body->Exec(f, flow)};
v = body->Exec(f, flow);
}
catch ( InterpreterException& e )
{ /* Already reported. */ }
@ -346,12 +346,12 @@ void Trigger::Timeout()
if ( timeout_stmts )
{
stmt_flow_type flow;
Frame* f = frame->Clone();
Val* v = 0;
IntrusivePtr<Frame> f{AdoptRef{}, frame->Clone()};
IntrusivePtr<Val> v;
try
{
v = timeout_stmts->Exec(f, flow);
v = timeout_stmts->Exec(f.get(), flow);
}
catch ( InterpreterException& e )
{ /* Already reported. */ }
@ -368,13 +368,10 @@ void Trigger::Timeout()
DBG_LOG(DBG_NOTIFIERS, "%s: trigger has parent %s, caching timeout result", Name(), pname);
delete [] pname;
#endif
trigger->Cache(frame->GetCall(), v);
trigger->Cache(frame->GetCall(), v.get());
trigger->Release();
frame->ClearTrigger();
}
Unref(v);
Unref(f);
}
Disable();

View file

@ -237,7 +237,7 @@ IntrusivePtr<Stmt> add_local(IntrusivePtr<ID> id, IntrusivePtr<BroType> t, init_
auto name_expr = make_intrusive<NameExpr>(id, dt == VAR_CONST);
auto stmt =
make_intrusive<ExprStmt>(new AssignExpr(std::move(name_expr), std::move(init), 0, 0,
make_intrusive<ExprStmt>(make_intrusive<AssignExpr>(std::move(name_expr), std::move(init), 0, nullptr,
id->Attrs() ? id->Attrs()->Attrs() : 0 ));
stmt->SetLocationInfo(&location);

View file

@ -1395,7 +1395,7 @@ stmt:
| TOK_PRINT expr_list ';' opt_no_test
{
set_location(@1, @3);
$$ = new PrintStmt($2);
$$ = new PrintStmt(IntrusivePtr{AdoptRef{}, $2});
if ( ! $4 )
brofiler.AddStmt($$);
}
@ -1403,7 +1403,7 @@ stmt:
| TOK_EVENT event ';' opt_no_test
{
set_location(@1, @3);
$$ = new EventStmt($2);
$$ = new EventStmt({AdoptRef{}, $2});
if ( ! $4 )
brofiler.AddStmt($$);
}
@ -1411,29 +1411,29 @@ stmt:
| TOK_IF '(' expr ')' stmt
{
set_location(@1, @4);
$$ = new IfStmt($3, $5, new NullStmt());
$$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive<NullStmt>());
}
| TOK_IF '(' expr ')' stmt TOK_ELSE stmt
{
set_location(@1, @4);
$$ = new IfStmt($3, $5, $7);
$$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7});
}
| TOK_SWITCH expr '{' case_list '}'
{
set_location(@1, @2);
$$ = new SwitchStmt($2, $4);
$$ = new SwitchStmt({AdoptRef{}, $2}, $4);
}
| for_head stmt
{
$1->AsForStmt()->AddBody($2);
$1->AsForStmt()->AddBody({AdoptRef{}, $2});
}
| TOK_WHILE '(' expr ')' stmt
{
$$ = new WhileStmt($3, $5);
$$ = new WhileStmt({AdoptRef{}, $3}, {AdoptRef{}, $5});
}
| TOK_NEXT ';' opt_no_test
@ -1471,7 +1471,7 @@ stmt:
| TOK_RETURN expr ';' opt_no_test
{
set_location(@1, @2);
$$ = new ReturnStmt($2);
$$ = new ReturnStmt({AdoptRef{}, $2});
if ( ! $4 )
brofiler.AddStmt($$);
}
@ -1479,7 +1479,7 @@ stmt:
| TOK_ADD expr ';' opt_no_test
{
set_location(@1, @3);
$$ = new AddStmt($2);
$$ = new AddStmt({AdoptRef{}, $2});
if ( ! $4 )
brofiler.AddStmt($$);
}
@ -1487,7 +1487,7 @@ stmt:
| TOK_DELETE expr ';' opt_no_test
{
set_location(@1, @3);
$$ = new DelStmt($2);
$$ = new DelStmt({AdoptRef{}, $2});
if ( ! $4 )
brofiler.AddStmt($$);
}
@ -1511,13 +1511,13 @@ stmt:
| TOK_WHEN '(' expr ')' stmt
{
set_location(@3, @5);
$$ = new WhenStmt($3, $5, 0, 0, false);
$$ = new WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, nullptr, nullptr, false);
}
| TOK_WHEN '(' expr ')' stmt TOK_TIMEOUT expr '{' opt_no_test_block stmt_list '}'
{
set_location(@3, @9);
$$ = new WhenStmt($3, $5, $10, $7, false);
$$ = new WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $10}, {AdoptRef{}, $7}, false);
if ( $9 )
brofiler.DecIgnoreDepth();
}
@ -1526,13 +1526,13 @@ stmt:
| TOK_RETURN TOK_WHEN '(' expr ')' stmt
{
set_location(@4, @6);
$$ = new WhenStmt($4, $6, 0, 0, true);
$$ = new WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, nullptr, nullptr, true);
}
| TOK_RETURN TOK_WHEN '(' expr ')' stmt TOK_TIMEOUT expr '{' opt_no_test_block stmt_list '}'
{
set_location(@4, @10);
$$ = new WhenStmt($4, $6, $11, $8, true);
$$ = new WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, {AdoptRef{}, $11}, {AdoptRef{}, $8}, true);
if ( $10 )
brofiler.DecIgnoreDepth();
}
@ -1540,7 +1540,7 @@ stmt:
| index_slice '=' expr ';' opt_no_test
{
set_location(@1, @4);
$$ = new ExprStmt(get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $3}, in_init).release());
$$ = new ExprStmt(get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $3}, in_init));
if ( ! $5 )
brofiler.AddStmt($$);
@ -1549,7 +1549,7 @@ stmt:
| expr ';' opt_no_test
{
set_location(@1, @2);
$$ = new ExprStmt($1);
$$ = new ExprStmt({AdoptRef{}, $1});
if ( ! $3 )
brofiler.AddStmt($$);
}
@ -1605,13 +1605,13 @@ case_list:
case:
TOK_CASE expr_list ':' stmt_list
{ $$ = new Case($2, 0, $4); }
{ $$ = new Case({AdoptRef{}, $2}, 0, {AdoptRef{}, $4}); }
|
TOK_CASE case_type_list ':' stmt_list
{ $$ = new Case(0, $2, $4); }
{ $$ = new Case(nullptr, $2, {AdoptRef{}, $4}); }
|
TOK_DEFAULT ':' stmt_list
{ $$ = new Case(0, 0, $3); }
{ $$ = new Case(nullptr, 0, {AdoptRef{}, $3}); }
;
case_type_list:
@ -1675,12 +1675,12 @@ for_head:
id_list* loop_vars = new id_list;
loop_vars->push_back(loop_var.release());
$$ = new ForStmt(loop_vars, $5);
$$ = new ForStmt(loop_vars, {AdoptRef{}, $5});
}
|
TOK_FOR '(' '[' local_id_list ']' TOK_IN expr ')'
{
$$ = new ForStmt($4, $7);
$$ = new ForStmt($4, {AdoptRef{}, $7});
}
|
TOK_FOR '(' TOK_ID ',' TOK_ID TOK_IN expr ')'
@ -1713,7 +1713,7 @@ for_head:
id_list* loop_vars = new id_list;
loop_vars->push_back(key_var.release());
$$ = new ForStmt(loop_vars, $7, val_var.release());
$$ = new ForStmt(loop_vars, {AdoptRef{}, $7}, std::move(val_var));
}
|
TOK_FOR '(' '[' local_id_list ']' ',' TOK_ID TOK_IN expr ')'
@ -1732,7 +1732,7 @@ for_head:
else
val_var = install_ID($7, module, false, false);
$$ = new ForStmt($4, $9, val_var.release());
$$ = new ForStmt($4, {AdoptRef{}, $9}, std::move(val_var));
}
;