Skip to content

Commit f6d8eb3

Browse files
Replace #ifdef by template parameter in symex_assign
In assign_array. This requires fixing some error in one of the branch since the compiler was not looking at it before.
1 parent d7a812a commit f6d8eb3

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

src/goto-symex/symex_assign.cpp

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void symex_assignt::assign_rec(
8080
assign_symbol(to_ssa_expr(lhs), full_lhs, rhs, guard);
8181
}
8282
else if(lhs.id() == ID_index)
83-
assign_array(to_index_expr(lhs), full_lhs, rhs, guard);
83+
assign_array<use_update()>(to_index_expr(lhs), full_lhs, rhs, guard);
8484
else if(lhs.id()==ID_member)
8585
{
8686
const typet &type = to_member_expr(lhs).struct_op().type();
@@ -464,6 +464,7 @@ void symex_assignt::assign_typecast(
464464
assign_rec(lhs.op(), new_full_lhs, rhs_typecasted, guard);
465465
}
466466

467+
template <bool use_update>
467468
void symex_assignt::assign_array(
468469
const index_exprt &lhs,
469470
const exprt &full_lhs,
@@ -476,34 +477,26 @@ void symex_assignt::assign_array(
476477

477478
PRECONDITION(lhs_index_type.id() == ID_array);
478479

479-
#ifdef USE_UPDATE
480-
481-
// turn
482-
// a[i]=e
483-
// into
484-
// a'==UPDATE(a, [i], e)
485-
486-
update_exprt new_rhs(lhs_index_type);
487-
new_rhs.old()=lhs_array;
488-
new_rhs.designator().push_back(index_designatort(lhs_index));
489-
new_rhs.new_value()=rhs;
490-
491-
exprt new_full_lhs=add_to_lhs(full_lhs, lhs);
492-
493-
symex_assign_rec(
494-
state, lhs_array, new_full_lhs, new_rhs, guard, assignment_type);
495-
496-
#else
497-
// turn
498-
// a[i]=e
499-
// into
500-
// a'==a WITH [i:=e]
501-
502-
const with_exprt new_rhs{lhs_array, lhs_index, rhs};
503-
const exprt new_full_lhs = add_to_lhs(full_lhs, lhs);
504-
505-
assign_rec(lhs_array, new_full_lhs, new_rhs, guard);
506-
#endif
480+
if(use_update)
481+
{
482+
// turn
483+
// a[i]=e
484+
// into
485+
// a'==UPDATE(a, [i], e)
486+
const update_exprt new_rhs{lhs_array, index_designatort(lhs_index), rhs};
487+
const exprt new_full_lhs = add_to_lhs(full_lhs, lhs);
488+
assign_rec(lhs_array, new_full_lhs, new_rhs, guard);
489+
}
490+
else
491+
{
492+
// turn
493+
// a[i]=e
494+
// into
495+
// a'==a WITH [i:=e]
496+
const with_exprt new_rhs{lhs_array, lhs_index, rhs};
497+
const exprt new_full_lhs = add_to_lhs(full_lhs, lhs);
498+
assign_rec(lhs_array, new_full_lhs, new_rhs, guard);
499+
}
507500
}
508501

509502
void symex_assignt::assign_struct_member(

src/goto-symex/symex_assign.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class symex_assignt
7373
const exprt &rhs,
7474
const exprt::operandst &guard);
7575

76+
/// \tparam use_update: use update_exprt instead of with_exprt when building
77+
/// expressions that modify components of an array or a struct
78+
template <bool use_update>
7679
void assign_array(
7780
const index_exprt &lhs,
7881
const exprt &full_lhs,

0 commit comments

Comments
 (0)