mirror of
https://github.com/zeek/zeek.git
synced 2025-10-08 17:48:21 +00:00
simple AST optimization for ?: operator
This commit is contained in:
parent
fb101f7b0e
commit
ed3c87d253
1 changed files with 13 additions and 0 deletions
|
@ -1427,6 +1427,19 @@ ExprPtr CondExpr::Reduce(Reducer* c, StmtPtr& red_stmt)
|
|||
return op2;
|
||||
}
|
||||
|
||||
if ( op2->IsConst() && op3->IsConst() && GetType()->Tag() == TYPE_BOOL )
|
||||
{
|
||||
auto op2_t = op2->IsOne();
|
||||
ASSERT(op2_t != op3->IsOne());
|
||||
|
||||
if ( op2_t )
|
||||
// This is "var ? T : F", which can be replaced by var.
|
||||
return op1;
|
||||
|
||||
// Instead we have "var ? F : T".
|
||||
return make_intrusive<NotExpr>(op1);
|
||||
}
|
||||
|
||||
if ( c->Optimizing() )
|
||||
return ThisPtr();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue