Skip to content

Commit 6f721cc

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Rewrite of case_guard
1 parent b22474f commit 6f721cc

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/goto-programs/goto_convert.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,27 +1153,28 @@ exprt goto_convertt::case_guard(
11531153
const exprt &value,
11541154
const exprt::operandst &case_op)
11551155
{
1156-
exprt dest=exprt(ID_or, bool_typet());
1157-
dest.reserve_operands(case_op.size());
1156+
PRECONDITION(!case_op.empty());
11581157

1159-
forall_expr(it, case_op)
1158+
if(case_op.size() == 1)
1159+
return equal_exprt(value, case_op.at(0));
1160+
else
11601161
{
1161-
equal_exprt eq_expr;
1162-
eq_expr.lhs()=value;
1163-
eq_expr.rhs()=*it;
1164-
dest.move_to_operands(eq_expr);
1165-
}
1162+
exprt dest = exprt(ID_or, bool_typet());
1163+
dest.reserve_operands(case_op.size());
11661164

1167-
CHECK_RETURN(!dest.operands().empty());
1165+
forall_expr(it, case_op)
1166+
{
1167+
equal_exprt eq_expr;
1168+
eq_expr.lhs() = value;
1169+
eq_expr.rhs() = *it;
1170+
dest.move_to_operands(eq_expr);
1171+
}
1172+
INVARIANT(
1173+
case_op.size() == dest.operands().size(),
1174+
"case guard conversion should preserve the number of cases");
11681175

1169-
if(dest.operands().size()==1)
1170-
{
1171-
exprt tmp;
1172-
tmp.swap(dest.op0());
1173-
dest.swap(tmp);
1176+
return dest;
11741177
}
1175-
1176-
return dest;
11771178
}
11781179

11791180
void goto_convertt::convert_switch(

0 commit comments

Comments
 (0)