diff --git a/src/Expr.cc b/src/Expr.cc index 9d411c4702..8cae1a0d86 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -254,7 +254,7 @@ ExprPtr Expr::MakeLvalue() if ( ! IsError() ) ExprError("can't be assigned to"); - return {NewRef{}, this}; + return ThisPtr(); } bool Expr::InvertSense() @@ -539,7 +539,7 @@ ExprPtr NameExpr::MakeLvalue() if ( id->IsOption() && ! in_const_init ) ExprError("option is not a modifiable lvalue"); - return make_intrusive(IntrusivePtr{NewRef{}, this}); + return make_intrusive(ThisPtr()); } void NameExpr::Assign(Frame* f, ValPtr v) @@ -2492,7 +2492,7 @@ RefExpr::RefExpr(ExprPtr arg_op) : UnaryExpr(EXPR_REF, std::move(arg_op)) ExprPtr RefExpr::MakeLvalue() { - return {NewRef{}, this}; + return ThisPtr(); } void RefExpr::Assign(Frame* f, ValPtr v) @@ -2876,7 +2876,7 @@ ExprPtr IndexExpr::MakeLvalue() if ( IsString(op1->GetType()->Tag()) ) ExprError("cannot assign to string index expression"); - return make_intrusive(IntrusivePtr{NewRef{}, this}); + return make_intrusive(ThisPtr()); } ValPtr IndexExpr::Eval(Frame* f) const @@ -3113,7 +3113,7 @@ FieldExpr::~FieldExpr() ExprPtr FieldExpr::MakeLvalue() { - return make_intrusive(IntrusivePtr{NewRef{}, this}); + return make_intrusive(ThisPtr()); } bool FieldExpr::CanDel() const @@ -5130,7 +5130,7 @@ ExprPtr ListExpr::MakeLvalue() if ( expr->Tag() != EXPR_NAME ) ExprError("can only assign to list of identifiers"); - return make_intrusive(IntrusivePtr{NewRef{}, this}); + return make_intrusive(ThisPtr()); } void ListExpr::Assign(Frame* f, ValPtr v) diff --git a/src/Stmt.cc b/src/Stmt.cc index 0979b19139..5acacbc1f9 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -206,6 +206,9 @@ bool Stmt::IsPure() const void Stmt::Describe(ODesc* d) const { + // The following is a handy add-on when doing AST debugging. + // d->Add(util::fmt("%p: ", this)); + StmtDescribe(d); } diff --git a/src/StmtBase.h b/src/StmtBase.h index 17188e0ce1..d8ba87a045 100644 --- a/src/StmtBase.h +++ b/src/StmtBase.h @@ -165,7 +165,7 @@ public: // into a StmtPtr. virtual StmtPtr SetSucc(Stmt* succ) { - succ->SetOriginal({NewRef{}, this}); + succ->SetOriginal(ThisPtr()); return {AdoptRef{}, succ}; } diff --git a/src/script_opt/IDOptInfo.cc b/src/script_opt/IDOptInfo.cc index 744e126988..b60e707692 100644 --- a/src/script_opt/IDOptInfo.cc +++ b/src/script_opt/IDOptInfo.cc @@ -141,7 +141,7 @@ void IDOptInfo::DefinedAfter(const Stmt* s, const ExprPtr& e, // This needs to come after filling out the confluence // blocks, since they'll create their own (earlier) regions. usage_regions.emplace_back(s, true, stmt_num); - usage_regions.back().SetDefExpr(e); + usage_regions.back().SetDefExpr(std::move(e)); if ( tracing ) DumpBlocks(); diff --git a/src/script_opt/ScriptOpt.cc b/src/script_opt/ScriptOpt.cc index 67284107a1..7e59834408 100644 --- a/src/script_opt/ScriptOpt.cc +++ b/src/script_opt/ScriptOpt.cc @@ -491,24 +491,19 @@ static void analyze_scripts_for_ZAM(std::unique_ptr& pfs) // since it won't be consulted in that case. std::unordered_set func_used_indirectly; - if ( global_stmts ) - func_used_indirectly.insert(global_stmts.get()); - if ( inl ) { + if ( global_stmts ) + func_used_indirectly.insert(global_stmts.get()); + for ( auto& g : pfs->Globals() ) { if ( g->GetType()->Tag() != TYPE_FUNC ) continue; auto v = g->GetVal(); - if ( ! v ) - continue; - - auto func = v->AsFunc(); - - if ( inl->WasInlined(func) ) - func_used_indirectly.insert(func); + if ( v ) + func_used_indirectly.insert(v->AsFunc()); } } diff --git a/src/script_opt/Stmt.cc b/src/script_opt/Stmt.cc index 7cefdc63a2..e6084138c0 100644 --- a/src/script_opt/Stmt.cc +++ b/src/script_opt/Stmt.cc @@ -787,10 +787,10 @@ StmtPtr StmtList::DoReduce(Reducer* c) bool StmtList::ReduceStmt(int& s_i, std::vector& f_stmts, Reducer* c) { bool did_change = false; - auto stmt = stmts[s_i]; - auto old_stmt = stmt; + auto& stmt_i = stmts[s_i]; + auto old_stmt = stmt_i.get(); - stmt = stmt->Reduce(c); + auto stmt = stmt_i->Reduce(c); if ( stmt != old_stmt ) did_change = true; diff --git a/src/script_opt/ZAM/Compile.h b/src/script_opt/ZAM/Compile.h index b990a1e9a5..4c645b6f63 100644 --- a/src/script_opt/ZAM/Compile.h +++ b/src/script_opt/ZAM/Compile.h @@ -124,8 +124,6 @@ private: const ZAMStmt CompileStmt(const StmtPtr& body) { return CompileStmt(body.get()); } const ZAMStmt CompileStmt(const Stmt* body); - void SetCurrStmt(const Stmt* stmt) { curr_stmt = stmt; } - const ZAMStmt CompilePrint(const PrintStmt* ps); const ZAMStmt CompileExpr(const ExprStmt* es); const ZAMStmt CompileIf(const IfStmt* is); diff --git a/src/script_opt/ZAM/Stmt.cc b/src/script_opt/ZAM/Stmt.cc index 1054b959fc..4f7c332724 100644 --- a/src/script_opt/ZAM/Stmt.cc +++ b/src/script_opt/ZAM/Stmt.cc @@ -13,7 +13,7 @@ namespace zeek::detail const ZAMStmt ZAMCompiler::CompileStmt(const Stmt* s) { - SetCurrStmt(s); + curr_stmt = const_cast(s)->ThisPtr(); switch ( s->Tag() ) { diff --git a/src/script_opt/ZAM/Support.cc b/src/script_opt/ZAM/Support.cc index 73518a1f47..15dd6ff472 100644 --- a/src/script_opt/ZAM/Support.cc +++ b/src/script_opt/ZAM/Support.cc @@ -13,7 +13,7 @@ namespace zeek::detail { -const Stmt* curr_stmt; +StmtPtr curr_stmt; TypePtr log_ID_enum_type; TypePtr any_base_type; bool ZAM_error = false; diff --git a/src/script_opt/ZAM/Support.h b/src/script_opt/ZAM/Support.h index 84c3114e74..fdc88121cc 100644 --- a/src/script_opt/ZAM/Support.h +++ b/src/script_opt/ZAM/Support.h @@ -14,7 +14,7 @@ using ValVec = std::vector; // The (reduced) statement currently being compiled. Used for both // tracking "use" and "reaching" definitions, and for error messages. -extern const Stmt* curr_stmt; +extern StmtPtr curr_stmt; // True if a function with the given profile can be compiled to ZAM. // If not, returns the reason in *reason, if non-nil. diff --git a/src/script_opt/ZAM/ZInst.h b/src/script_opt/ZAM/ZInst.h index 90df08e884..8eff6f2ca5 100644 --- a/src/script_opt/ZAM/ZInst.h +++ b/src/script_opt/ZAM/ZInst.h @@ -306,7 +306,7 @@ public: int num_labels = 0; // Used for debugging. Transformed into the ZInst "loc" field. - const Stmt* stmt = curr_stmt; + StmtPtr stmt = curr_stmt; private: // Initialize 'c' from the given ConstExpr.