introduce internal "mask" expression node to avoid mixed-type overloading of "/"

This commit is contained in:
Vern Paxson 2023-09-26 14:39:26 -07:00
parent b53a025b1e
commit 434a7e059d
6 changed files with 55 additions and 13 deletions

View file

@ -253,6 +253,7 @@ bool Expr::IsFieldAssignable(const Expr* e) const
case EXPR_SUB:
case EXPR_TIMES:
case EXPR_DIVIDE:
case EXPR_MASK:
case EXPR_MOD:
case EXPR_AND:
case EXPR_OR:
@ -1091,20 +1092,24 @@ ExprPtr DivideExpr::Duplicate()
bool DivideExpr::WillTransform(Reducer* c) const
{
return GetType()->Tag() != TYPE_SUBNET && op2->IsOne();
return op2->IsOne();
}
ExprPtr DivideExpr::Reduce(Reducer* c, StmtPtr& red_stmt)
{
if ( GetType()->Tag() != TYPE_SUBNET )
{
if ( op2->IsOne() )
return op1->ReduceToSingleton(c, red_stmt);
}
if ( op2->IsOne() )
return op1->ReduceToSingleton(c, red_stmt);
return BinaryExpr::Reduce(c, red_stmt);
}
ExprPtr MaskExpr::Duplicate()
{
auto op1_d = op1->Duplicate();
auto op2_d = op2->Duplicate();
return SetSucc(new MaskExpr(op1_d, op2_d));
}
ExprPtr ModExpr::Duplicate()
{
auto op1_d = op1->Duplicate();