mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
fixes for script optimization of coerce-to-any expressions
This commit is contained in:
parent
cfb068a922
commit
e93db75f78
3 changed files with 22 additions and 1 deletions
|
@ -1642,6 +1642,9 @@ class CoerceToAnyExpr : public UnaryExpr {
|
||||||
public:
|
public:
|
||||||
CoerceToAnyExpr(ExprPtr op);
|
CoerceToAnyExpr(ExprPtr op);
|
||||||
|
|
||||||
|
bool IsReduced(Reducer* c) const override;
|
||||||
|
ExprPtr Reduce(Reducer* c, StmtPtr& red_stmt) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ValPtr Fold(Val* v) const override;
|
ValPtr Fold(Val* v) const override;
|
||||||
|
|
||||||
|
|
|
@ -1849,7 +1849,8 @@ void WhenInfo::Build(StmtPtr ws) {
|
||||||
auto else_branch = timeout_s ? timeout_s : empty;
|
auto else_branch = timeout_s ? timeout_s : empty;
|
||||||
|
|
||||||
auto do_bodies = make_intrusive<IfStmt>(two_test, s, else_branch);
|
auto do_bodies = make_intrusive<IfStmt>(two_test, s, else_branch);
|
||||||
auto dummy_return = make_intrusive<ReturnStmt>(true_const);
|
auto any_true_const = make_intrusive<CoerceToAnyExpr>(true_const);
|
||||||
|
auto dummy_return = make_intrusive<ReturnStmt>(any_true_const);
|
||||||
|
|
||||||
auto shebang = make_intrusive<StmtList>(do_test, do_bodies, dummy_return);
|
auto shebang = make_intrusive<StmtList>(do_test, do_bodies, dummy_return);
|
||||||
|
|
||||||
|
|
|
@ -3109,6 +3109,23 @@ CoerceToAnyExpr::CoerceToAnyExpr(ExprPtr arg_op) : UnaryExpr(EXPR_TO_ANY_COERCE,
|
||||||
type = base_type(TYPE_ANY);
|
type = base_type(TYPE_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CoerceToAnyExpr::IsReduced(Reducer* c) const { return HasReducedOps(c); }
|
||||||
|
|
||||||
|
ExprPtr CoerceToAnyExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
|
||||||
|
if ( c->Optimizing() )
|
||||||
|
op = c->UpdateExpr(op);
|
||||||
|
|
||||||
|
red_stmt = nullptr;
|
||||||
|
|
||||||
|
if ( ! op->IsSingleton(c) )
|
||||||
|
op = op->ReduceToSingleton(c, red_stmt);
|
||||||
|
|
||||||
|
if ( c->Optimizing() )
|
||||||
|
return ThisPtr();
|
||||||
|
else
|
||||||
|
return AssignToTemporary(c, red_stmt);
|
||||||
|
}
|
||||||
|
|
||||||
ValPtr CoerceToAnyExpr::Fold(Val* v) const { return {NewRef{}, v}; }
|
ValPtr CoerceToAnyExpr::Fold(Val* v) const { return {NewRef{}, v}; }
|
||||||
|
|
||||||
ExprPtr CoerceToAnyExpr::Duplicate() { return SetSucc(new CoerceToAnyExpr(op->Duplicate())); }
|
ExprPtr CoerceToAnyExpr::Duplicate() { return SetSucc(new CoerceToAnyExpr(op->Duplicate())); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue