Skip to content

Commit 43fffdf

Browse files
Replace #ifdef by template parameter in symex_assign
In assign_struct_member. This requires fixing some problems in one of the branchs, as the compiler was not looking at it before.
1 parent f6d8eb3 commit 43fffdf

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

src/goto-symex/symex_assign.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ void symex_assignt::assign_rec(
8585
{
8686
const typet &type = to_member_expr(lhs).struct_op().type();
8787
if(type.id() == ID_struct || type.id() == ID_struct_tag)
88-
assign_struct_member(to_member_expr(lhs), full_lhs, rhs, guard);
88+
{
89+
assign_struct_member<use_update()>(
90+
to_member_expr(lhs), full_lhs, rhs, guard);
91+
}
8992
else if(type.id() == ID_union || type.id() == ID_union_tag)
9093
{
9194
// should have been replaced by byte_extract
@@ -499,6 +502,7 @@ void symex_assignt::assign_array(
499502
}
500503
}
501504

505+
template <bool use_update>
502506
void symex_assignt::assign_struct_member(
503507
const member_exprt &lhs,
504508
const exprt &full_lhs,
@@ -534,35 +538,30 @@ void symex_assignt::assign_struct_member(
534538

535539
const irep_idt &component_name=lhs.get_component_name();
536540

537-
#ifdef USE_UPDATE
538-
539-
// turn
540-
// a.c=e
541-
// into
542-
// a'==UPDATE(a, .c, e)
543-
544-
update_exprt new_rhs(lhs_struct.type());
545-
new_rhs.old()=lhs_struct;
546-
new_rhs.designator().push_back(member_designatort(component_name));
547-
new_rhs.new_value()=rhs;
548-
549-
exprt new_full_lhs=add_to_lhs(full_lhs, lhs);
550-
551-
symex_assign_rec(
552-
state, lhs_struct, new_full_lhs, new_rhs, guard, assignment_type);
553-
554-
#else
555-
// turn
556-
// a.c=e
557-
// into
558-
// a'==a WITH [c:=e]
541+
if(use_update)
542+
{
543+
// turn
544+
// a.c=e
545+
// into
546+
// a'==UPDATE(a, .c, e)
547+
const update_exprt new_rhs{
548+
lhs_struct, member_designatort(component_name), rhs};
549+
const exprt new_full_lhs = add_to_lhs(full_lhs, lhs);
550+
assign_rec(lhs_struct, new_full_lhs, new_rhs, guard);
551+
}
552+
else
553+
{
554+
// turn
555+
// a.c=e
556+
// into
557+
// a'==a WITH [c:=e]
559558

560-
with_exprt new_rhs(lhs_struct, exprt(ID_member_name), rhs);
561-
new_rhs.where().set(ID_component_name, component_name);
559+
with_exprt new_rhs(lhs_struct, exprt(ID_member_name), rhs);
560+
new_rhs.where().set(ID_component_name, component_name);
562561

563-
exprt new_full_lhs=add_to_lhs(full_lhs, lhs);
564-
assign_rec(lhs_struct, new_full_lhs, new_rhs, guard);
565-
#endif
562+
exprt new_full_lhs = add_to_lhs(full_lhs, lhs);
563+
assign_rec(lhs_struct, new_full_lhs, new_rhs, guard);
564+
}
566565
}
567566

568567
void symex_assignt::assign_if(

src/goto-symex/symex_assign.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class symex_assignt
8282
const exprt &rhs,
8383
exprt::operandst &guard);
8484

85+
/// \tparam use_update: use update_exprt instead of with_exprt when building
86+
/// expressions that modify components of an array or a struct
87+
template <bool use_update>
8588
void assign_struct_member(
8689
const member_exprt &lhs,
8790
const exprt &full_lhs,

0 commit comments

Comments
 (0)