@@ -1120,39 +1120,34 @@ simplify_exprt::resultt<> simplify_exprt::simplify_unary_plus(const exprt &expr)
11201120}
11211121
11221122simplify_exprt::resultt<>
1123- simplify_exprt::simplify_unary_minus (const exprt &expr)
1123+ simplify_exprt::simplify_unary_minus (const unary_minus_exprt &expr)
11241124{
1125- if (expr.operands ().size ()!=1 )
1126- return unchanged (expr);
1127-
11281125 if (!is_number (expr.type ()))
11291126 return unchanged (expr);
11301127
1131- const exprt &operand = expr.op0 ();
1128+ const exprt &operand = expr.op ();
11321129
11331130 if (expr.type ()!=operand.type ())
11341131 return unchanged (expr);
11351132
11361133 if (operand.id ()==ID_unary_minus)
11371134 {
11381135 // cancel out "-(-x)" to "x"
1139- if (operand.operands ().size ()!=1 )
1140- return unchanged (expr);
1141-
1142- if (!is_number (operand.op0 ().type ()))
1136+ if (!is_number (to_unary_minus_expr (operand).op ().type ()))
11431137 return unchanged (expr);
11441138
1145- return expr. op0 (). op0 ();
1139+ return to_unary_minus_expr (operand). op ();
11461140 }
11471141 else if (operand.id ()==ID_constant)
11481142 {
11491143 const irep_idt &type_id=expr.type ().id ();
1144+ const auto &constant_expr = to_constant_expr (operand);
11501145
11511146 if (type_id==ID_integer ||
11521147 type_id==ID_signedbv ||
11531148 type_id==ID_unsignedbv)
11541149 {
1155- const auto int_value = numeric_cast<mp_integer>(expr. op0 () );
1150+ const auto int_value = numeric_cast<mp_integer>(constant_expr );
11561151
11571152 if (!int_value.has_value ())
11581153 return unchanged (expr);
@@ -1162,20 +1157,20 @@ simplify_exprt::simplify_unary_minus(const exprt &expr)
11621157 else if (type_id==ID_rational)
11631158 {
11641159 rationalt r;
1165- if (to_rational (expr. op0 () , r))
1160+ if (to_rational (constant_expr , r))
11661161 return unchanged (expr);
11671162
11681163 return from_rational (-r);
11691164 }
11701165 else if (type_id==ID_fixedbv)
11711166 {
1172- fixedbvt f (to_constant_expr (expr. op0 ()) );
1167+ fixedbvt f (constant_expr );
11731168 f.negate ();
11741169 return f.to_expr ();
11751170 }
11761171 else if (type_id==ID_floatbv)
11771172 {
1178- ieee_floatt f (to_constant_expr (expr. op0 ()) );
1173+ ieee_floatt f (constant_expr );
11791174 f.negate ();
11801175 return f.to_expr ();
11811176 }
0 commit comments