Skip to content

Commit 5ea209d

Browse files
Extract and document a fix_type function
This makes the code of rename clearer. The documentation of fix type clarifies what the extracted piece of code is trying to achieve. And this piece of code becomes more reusable, in particular if we want several versions of rename (in particular it would make sense to have one for each level).
1 parent 08c1dfa commit 5ea209d

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/goto-symex/goto_symex_state.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,25 @@ static void set_l2_indices(
284284
ssa_expr.set_level_2(level2.current_count(ssa_expr.get_identifier()));
285285
}
286286

287+
/// Fixes the type of `with_exprt`s and `if_exprt`s according to their operands.
288+
/// When the type of the operands of a `with_exprt` or `if_exprt` have been
289+
/// renamed they could end up being different from that of the expression. We
290+
/// fix that by propagating the type of its operands to \p expr.
291+
static void fix_type(exprt &expr)
292+
{
293+
if(expr.id() == ID_with)
294+
expr.type() = to_with_expr(expr).old().type();
295+
else if(expr.id() == ID_if)
296+
{
297+
DATA_INVARIANT(
298+
to_if_expr(expr).true_case().type() ==
299+
to_if_expr(expr).false_case().type(),
300+
"true case of to_if_expr should be of same type "
301+
"as false case");
302+
expr.type() = to_if_expr(expr).true_case().type();
303+
}
304+
}
305+
287306
void goto_symex_statet::rename(
288307
exprt &expr,
289308
const namespacet &ns,
@@ -367,18 +386,7 @@ void goto_symex_statet::rename(
367386
Forall_operands(it, expr)
368387
rename(*it, ns, level);
369388

370-
// some fixes
371-
if(expr.id()==ID_with)
372-
expr.type()=to_with_expr(expr).old().type();
373-
else if(expr.id()==ID_if)
374-
{
375-
DATA_INVARIANT(
376-
to_if_expr(expr).true_case().type() ==
377-
to_if_expr(expr).false_case().type(),
378-
"true case of to_if_expr should be of same type "
379-
"as false case");
380-
expr.type()=to_if_expr(expr).true_case().type();
381-
}
389+
fix_type(expr);
382390
}
383391
}
384392

0 commit comments

Comments
 (0)