mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Adjust some Reducer ref-counting and IntrusivePtr usage
This commit is contained in:
parent
7ce4351ed0
commit
b4cf393475
4 changed files with 12 additions and 12 deletions
|
@ -369,7 +369,7 @@ ExprPtr NameExpr::Reduce(Reducer* c, StmtPtr& red_stmt)
|
||||||
return TransformMe(make_intrusive<ConstExpr>(v), c, red_stmt);
|
return TransformMe(make_intrusive<ConstExpr>(v), c, red_stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
return c->UpdateName(this)->ThisPtr();
|
return c->UpdateName({NewRef{}, this});
|
||||||
}
|
}
|
||||||
|
|
||||||
ValPtr NameExpr::FoldVal() const
|
ValPtr NameExpr::FoldVal() const
|
||||||
|
|
|
@ -33,15 +33,12 @@ ExprPtr Reducer::GenTemporaryExpr(const TypePtr& t, ExprPtr rhs)
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
NameExpr* Reducer::UpdateName(NameExpr* n)
|
NameExprPtr Reducer::UpdateName(NameExprPtr n)
|
||||||
{
|
{
|
||||||
if ( NameIsReduced(n) )
|
if ( NameIsReduced(n.get()) )
|
||||||
{
|
|
||||||
Ref(n);
|
|
||||||
return n;
|
return n;
|
||||||
}
|
|
||||||
|
|
||||||
return new NameExpr(FindNewLocal(n));
|
return make_intrusive<NameExpr>(FindNewLocal(n.get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Reducer::NameIsReduced(const NameExpr* n) const
|
bool Reducer::NameIsReduced(const NameExpr* n) const
|
||||||
|
@ -58,9 +55,12 @@ void Reducer::UpdateIDs(IDPList* ids)
|
||||||
IDPtr id = {NewRef{}, (*ids)[i]};
|
IDPtr id = {NewRef{}, (*ids)[i]};
|
||||||
|
|
||||||
if ( ! ID_IsReduced(id) )
|
if ( ! ID_IsReduced(id) )
|
||||||
|
{
|
||||||
|
Unref((*ids)[i]);
|
||||||
(*ids)[i] = UpdateID(id).release();
|
(*ids)[i] = UpdateID(id).release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Reducer::UpdateIDs(std::vector<IDPtr>& ids)
|
void Reducer::UpdateIDs(std::vector<IDPtr>& ids)
|
||||||
{
|
{
|
||||||
|
@ -198,7 +198,7 @@ TempVar* Reducer::FindTemporary(const ID* id) const
|
||||||
return tmp->second;
|
return tmp->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
Stmt* Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, Stmt* succ_stmt)
|
StmtPtr Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, Stmt* succ_stmt)
|
||||||
{
|
{
|
||||||
// First check for tmp=rhs.
|
// First check for tmp=rhs.
|
||||||
auto lhs_id = lhs->Id();
|
auto lhs_id = lhs->Id();
|
||||||
|
@ -254,7 +254,7 @@ Stmt* Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, Stmt* succ_stmt)
|
||||||
nullptr, nullptr, false);
|
nullptr, nullptr, false);
|
||||||
TrackExprReplacement(rhs.get(), merge_e.get());
|
TrackExprReplacement(rhs.get(), merge_e.get());
|
||||||
|
|
||||||
return new ExprStmt(merge_e);
|
return make_intrusive<ExprStmt>(merge_e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reducer::TrackExprReplacement(const Expr* orig, const Expr* e)
|
void Reducer::TrackExprReplacement(const Expr* orig, const Expr* e)
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
|
|
||||||
ExprPtr GenTemporaryExpr(const TypePtr& t, ExprPtr rhs);
|
ExprPtr GenTemporaryExpr(const TypePtr& t, ExprPtr rhs);
|
||||||
|
|
||||||
NameExpr* UpdateName(NameExpr* n);
|
NameExprPtr UpdateName(NameExprPtr n);
|
||||||
bool NameIsReduced(const NameExpr* n) const;
|
bool NameIsReduced(const NameExpr* n) const;
|
||||||
|
|
||||||
void UpdateIDs(IDPList* ids);
|
void UpdateIDs(IDPList* ids);
|
||||||
|
@ -105,7 +105,7 @@ public:
|
||||||
// Given an lhs=rhs statement followed by succ_stmt, returns
|
// Given an lhs=rhs statement followed by succ_stmt, returns
|
||||||
// a (new) merge of the two if they're of the form tmp=rhs, var=tmp;
|
// a (new) merge of the two if they're of the form tmp=rhs, var=tmp;
|
||||||
// otherwise, nil.
|
// otherwise, nil.
|
||||||
Stmt* MergeStmts(const NameExpr* lhs, ExprPtr rhs, Stmt* succ_stmt);
|
StmtPtr MergeStmts(const NameExpr* lhs, ExprPtr rhs, Stmt* succ_stmt);
|
||||||
|
|
||||||
// The following two methods will, in the future, update expressions
|
// The following two methods will, in the future, update expressions
|
||||||
// with optimized versions. They are distinct because the first
|
// with optimized versions. They are distinct because the first
|
||||||
|
|
|
@ -845,7 +845,7 @@ bool StmtList::ReduceStmt(int& s_i, StmtPList* f_stmts, Reducer* c)
|
||||||
auto merge = c->MergeStmts(var, rhs, s_i_succ);
|
auto merge = c->MergeStmts(var, rhs, s_i_succ);
|
||||||
if ( merge )
|
if ( merge )
|
||||||
{
|
{
|
||||||
f_stmts->append(merge);
|
f_stmts->append(merge.release());
|
||||||
|
|
||||||
// Skip both this statement and the next,
|
// Skip both this statement and the next,
|
||||||
// now that we've substituted the merge.
|
// now that we've substituted the merge.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue