mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
some code simplifications and streamlining
This commit is contained in:
parent
18c77ddc2c
commit
79c53c9ed6
11 changed files with 23 additions and 27 deletions
12
src/Expr.cc
12
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<RefExpr>(IntrusivePtr{NewRef{}, this});
|
||||
return make_intrusive<RefExpr>(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<RefExpr>(IntrusivePtr{NewRef{}, this});
|
||||
return make_intrusive<RefExpr>(ThisPtr());
|
||||
}
|
||||
|
||||
ValPtr IndexExpr::Eval(Frame* f) const
|
||||
|
@ -3113,7 +3113,7 @@ FieldExpr::~FieldExpr()
|
|||
|
||||
ExprPtr FieldExpr::MakeLvalue()
|
||||
{
|
||||
return make_intrusive<RefExpr>(IntrusivePtr{NewRef{}, this});
|
||||
return make_intrusive<RefExpr>(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<RefExpr>(IntrusivePtr{NewRef{}, this});
|
||||
return make_intrusive<RefExpr>(ThisPtr());
|
||||
}
|
||||
|
||||
void ListExpr::Assign(Frame* f, ValPtr v)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ public:
|
|||
// into a StmtPtr.
|
||||
virtual StmtPtr SetSucc(Stmt* succ)
|
||||
{
|
||||
succ->SetOriginal({NewRef{}, this});
|
||||
succ->SetOriginal(ThisPtr());
|
||||
return {AdoptRef{}, succ};
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -491,24 +491,19 @@ static void analyze_scripts_for_ZAM(std::unique_ptr<ProfileFuncs>& pfs)
|
|||
// since it won't be consulted in that case.
|
||||
std::unordered_set<Func*> 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -787,10 +787,10 @@ StmtPtr StmtList::DoReduce(Reducer* c)
|
|||
bool StmtList::ReduceStmt(int& s_i, std::vector<StmtPtr>& 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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace zeek::detail
|
|||
|
||||
const ZAMStmt ZAMCompiler::CompileStmt(const Stmt* s)
|
||||
{
|
||||
SetCurrStmt(s);
|
||||
curr_stmt = const_cast<Stmt*>(s)->ThisPtr();
|
||||
|
||||
switch ( s->Tag() )
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -14,7 +14,7 @@ using ValVec = std::vector<ValPtr>;
|
|||
|
||||
// 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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue