Skip to content

Commit e3a9157

Browse files
committed
Add lift_cond
This is just like lift_if, but for cond_exprt
1 parent 2dddea3 commit e3a9157

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/util/expr_util.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,24 @@ if_exprt lift_if(const exprt &src, std::size_t operand_number)
216216
return result;
217217
}
218218

219+
cond_exprt lift_cond(const exprt &src, std::size_t operand_number)
220+
{
221+
PRECONDITION(operand_number < src.operands().size());
222+
PRECONDITION(src.operands()[operand_number].id() == ID_cond);
223+
224+
const cond_exprt cond_expr = to_cond_expr(src.operands()[operand_number]);
225+
cond_exprt result({}, src.type(), cond_expr.is_exclusive());
226+
227+
for(std::size_t i = 0; i < cond_expr.get_n_cases(); ++i)
228+
{
229+
exprt new_value = src;
230+
new_value.operands()[operand_number] = cond_expr.value(i);
231+
result.add_case(cond_expr.condition(i), new_value);
232+
}
233+
234+
return result;
235+
}
236+
219237
const exprt &skip_typecast(const exprt &expr)
220238
{
221239
if(expr.id()!=ID_typecast)

src/util/expr_util.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class symbol_exprt;
2626
class update_exprt;
2727
class with_exprt;
2828
class if_exprt;
29+
class cond_exprt;
2930
class symbolt;
3031
class typet;
3132
class namespacet;
@@ -74,6 +75,9 @@ bool has_subtype(const typet &, const irep_idt &id, const namespacet &);
7475
/// lift up an if_exprt one level
7576
if_exprt lift_if(const exprt &, std::size_t operand_number);
7677

78+
/// lift up an cond_exprt one level
79+
cond_exprt lift_cond(const exprt &, std::size_t operand_number);
80+
7781
/// find the expression nested inside typecasts, if any
7882
const exprt &skip_typecast(const exprt &expr);
7983

0 commit comments

Comments
 (0)