Skip to content

Commit 8121569

Browse files
committed
introduce instructiont::assign_lhs() and assign_rhs()
This mirrors the change in #5861 by replacing the use of code_assignt by directly returning the lhs and rhs expressions. The client code is simplified.
1 parent 99741b3 commit 8121569

9 files changed

+77
-67
lines changed

src/analyses/constant_propagator.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,8 @@ void constant_propagator_domaint::transform(
164164
}
165165
else if(from->is_assign())
166166
{
167-
const auto &assignment = from->get_assign();
168-
const exprt &lhs=assignment.lhs();
169-
const exprt &rhs=assignment.rhs();
167+
const exprt &lhs = from->assign_lhs();
168+
const exprt &rhs = from->assign_rhs();
170169
assign_rec(values, lhs, rhs, ns, cp, true);
171170
}
172171
else if(from->is_assume())

src/goto-programs/goto_program.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,9 @@ std::list<exprt> expressions_read(
299299
}
300300

301301
case ASSIGN:
302-
{
303-
const code_assignt &assignment = instruction.get_assign();
304-
dest.push_back(assignment.rhs());
305-
parse_lhs_read(assignment.lhs(), dest);
302+
dest.push_back(instruction.assign_rhs());
303+
parse_lhs_read(instruction.assign_lhs(), dest);
306304
break;
307-
}
308305

309306
case CATCH:
310307
case THROW:
@@ -343,7 +340,7 @@ std::list<exprt> expressions_written(
343340
break;
344341

345342
case ASSIGN:
346-
dest.push_back(instruction.get_assign().lhs());
343+
dest.push_back(instruction.assign_lhs());
347344
break;
348345

349346
case CATCH:
@@ -935,15 +932,12 @@ void goto_programt::instructiont::transform(
935932

936933
case ASSIGN:
937934
{
938-
auto new_assign_lhs = f(get_assign().lhs());
939-
auto new_assign_rhs = f(get_assign().rhs());
940-
if(new_assign_lhs.has_value() || new_assign_rhs.has_value())
941-
{
942-
auto new_assignment = get_assign();
943-
new_assignment.lhs() = new_assign_lhs.value_or(new_assignment.lhs());
944-
new_assignment.rhs() = new_assign_rhs.value_or(new_assignment.rhs());
945-
set_assign(new_assignment);
946-
}
935+
auto new_assign_lhs = f(assign_lhs());
936+
auto new_assign_rhs = f(assign_rhs());
937+
if(new_assign_lhs.has_value())
938+
assign_lhs() = new_assign_lhs.value();
939+
if(new_assign_rhs.has_value())
940+
assign_rhs() = new_assign_rhs.value();
947941
}
948942
break;
949943

@@ -1032,8 +1026,8 @@ void goto_programt::instructiont::apply(
10321026
break;
10331027

10341028
case ASSIGN:
1035-
f(get_assign().lhs());
1036-
f(get_assign().rhs());
1029+
f(assign_lhs());
1030+
f(assign_rhs());
10371031
break;
10381032

10391033
case DECL:

src/goto-programs/goto_program.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,44 @@ class goto_programt
183183
codet code;
184184

185185
/// Get the assignment for ASSIGN
186-
const code_assignt &get_assign() const
186+
DEPRECATED(SINCE(2021, 2, 24, "Use dead_symbol instead"))
187+
const code_assignt &get_assignX() const
187188
{
188189
PRECONDITION(is_assign());
189190
return to_code_assign(code);
190191
}
191192

193+
/// Get the lhs of the assignment for ASSIGN
194+
const exprt &assign_lhs() const
195+
{
196+
PRECONDITION(is_assign());
197+
return to_code_assign(code).lhs();
198+
}
199+
200+
/// Get the lhs of the assignment for ASSIGN
201+
exprt &assign_lhs()
202+
{
203+
PRECONDITION(is_assign());
204+
return to_code_assign(code).lhs();
205+
}
206+
207+
/// Get the rhs of the assignment for ASSIGN
208+
const exprt &assign_rhs() const
209+
{
210+
PRECONDITION(is_assign());
211+
return to_code_assign(code).rhs();
212+
}
213+
214+
/// Get the rhs of the assignment for ASSIGN
215+
exprt &assign_rhs()
216+
{
217+
PRECONDITION(is_assign());
218+
return to_code_assign(code).rhs();
219+
}
220+
192221
/// Set the assignment for ASSIGN
193-
void set_assign(code_assignt c)
222+
DEPRECATED(SINCE(2021, 2, 24, "Use dead_symbol instead"))
223+
void set_assignX(code_assignt c)
194224
{
195225
PRECONDITION(is_assign());
196226
code = std::move(c);

src/goto-programs/graphml_witness.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ static bool filter_out(
229229
goto_tracet::stepst::const_iterator &it)
230230
{
231231
if(
232-
it->hidden && (!it->pc->is_assign() ||
233-
it->pc->get_assign().rhs().id() != ID_side_effect ||
234-
it->pc->get_assign().rhs().get(ID_statement) != ID_nondet))
232+
it->hidden &&
233+
(!it->pc->is_assign() || it->pc->assign_rhs().id() != ID_side_effect ||
234+
it->pc->assign_rhs().get(ID_statement) != ID_nondet))
235235
return true;
236236

237237
if(!it->is_assignment() && !it->is_goto() && !it->is_assert())

src/goto-programs/mm_io.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ void mm_io(
4545

4646
if(it->is_assign())
4747
{
48-
auto a = it->get_assign();
49-
collect_deref_expr(a.rhs(), deref_expr_r);
48+
auto &a_lhs = it->assign_lhs();
49+
auto &a_rhs = it->assign_rhs();
50+
collect_deref_expr(a_rhs, deref_expr_r);
5051

5152
if(mm_io_r.is_not_nil())
5253
{
@@ -59,8 +60,7 @@ void mm_io(
5960
irep_idt identifier=to_symbol_expr(mm_io_r).get_identifier();
6061
auto return_value = return_value_symbol(identifier, ns);
6162
if_exprt if_expr(integer_address(d.pointer()), return_value, d);
62-
if(!replace_expr(d, if_expr, a.rhs()))
63-
it->set_assign(a);
63+
replace_expr(d, if_expr, a_rhs);
6464

6565
const typet &pt=ct.parameters()[0].type();
6666
const typet &st=ct.parameters()[1].type();
@@ -78,9 +78,9 @@ void mm_io(
7878

7979
if(mm_io_w.is_not_nil())
8080
{
81-
if(a.lhs().id()==ID_dereference)
81+
if(a_lhs.id() == ID_dereference)
8282
{
83-
const dereference_exprt &d=to_dereference_expr(a.lhs());
83+
const dereference_exprt &d = to_dereference_expr(a_lhs);
8484
source_locationt source_location=it->source_location;
8585
const code_typet &ct=to_code_type(mm_io_w.type());
8686
const typet &pt=ct.parameters()[0].type();
@@ -92,7 +92,7 @@ void mm_io(
9292
mm_io_w,
9393
{typecast_exprt(d.pointer(), pt),
9494
typecast_exprt(size_opt.value(), st),
95-
typecast_exprt(a.rhs(), vt)});
95+
typecast_exprt(a_rhs, vt)});
9696
goto_function.body.insert_before_swap(it);
9797
*it = goto_programt::make_function_call(fc, source_location);
9898
it++;

src/goto-programs/remove_returns.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,13 @@ bool remove_returnst::restore_returns(
310310
{
311311
if(instruction.is_assign())
312312
{
313-
const auto &assign = instruction.get_assign();
314-
315-
if(assign.lhs().id()!=ID_symbol ||
316-
to_symbol_expr(assign.lhs()).get_identifier()!=rv_name_id)
313+
if(
314+
instruction.assign_lhs().id() != ID_symbol ||
315+
to_symbol_expr(instruction.assign_lhs()).get_identifier() != rv_name_id)
317316
continue;
318317

319318
// replace "fkt#return_value=x;" by "return x;"
320-
const exprt rhs = assign.rhs();
319+
const exprt rhs = instruction.assign_rhs();
321320
instruction = goto_programt::make_return(
322321
code_returnt(rhs), instruction.source_location);
323322
did_something = true;
@@ -360,14 +359,12 @@ void remove_returnst::undo_function_calls(
360359
if(!next->is_assign())
361360
continue;
362361

363-
const code_assignt &assign = next->get_assign();
364-
365362
const auto rv_symbol = return_value_symbol(function_id, ns);
366-
if(assign.rhs() != rv_symbol)
363+
if(next->assign_rhs() != rv_symbol)
367364
continue;
368365

369366
// restore the previous assignment
370-
function_call.lhs()=assign.lhs();
367+
function_call.lhs() = next->assign_lhs();
371368

372369
i_it->set_function_call(function_call);
373370

src/goto-programs/restrict_function_pointers.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,15 @@ function_pointer_restrictionst::get_by_name_restriction(
413413

414414
const goto_programt::const_targett it = std::prev(location);
415415

416-
const code_assignt &assign = it->get_assign();
417-
418416
INVARIANT(
419-
to_symbol_expr(assign.lhs()).get_identifier() ==
417+
to_symbol_expr(it->assign_lhs()).get_identifier() ==
420418
function_pointer_call_site.get_identifier(),
421419
"called function pointer must have been assigned at the previous location");
422420

423-
if(!can_cast_expr<symbol_exprt>(assign.rhs()))
421+
if(!can_cast_expr<symbol_exprt>(it->assign_rhs()))
424422
return {};
425423

426-
const auto &rhs = to_symbol_expr(assign.rhs());
424+
const auto &rhs = to_symbol_expr(it->assign_rhs());
427425

428426
const auto restriction = by_name_restrictions.find(rhs.get_identifier());
429427

src/goto-programs/slice_global_inits.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ void slice_global_inits(goto_modelt &goto_model)
9393
{
9494
if(!*seen_it && instruction.is_assign())
9595
{
96-
const code_assignt &code_assign = instruction.get_assign();
97-
const irep_idt id = to_symbol_expr(code_assign.lhs()).get_identifier();
96+
const irep_idt id =
97+
to_symbol_expr(instruction.assign_lhs()).get_identifier();
9898

9999
// if we are to keep the left-hand side, then we also need to keep all
100100
// symbols occurring in the right-hand side
@@ -103,7 +103,7 @@ void slice_global_inits(goto_modelt &goto_model)
103103
symbols_to_keep.find(id) != symbols_to_keep.end())
104104
{
105105
fixed_point_reached = false;
106-
find_symbols(code_assign.rhs(), symbols_to_keep, true, false);
106+
find_symbols(instruction.assign_rhs(), symbols_to_keep, true, false);
107107
*seen_it = true;
108108
}
109109
}
@@ -119,8 +119,8 @@ void slice_global_inits(goto_modelt &goto_model)
119119
{
120120
if(instruction.is_assign())
121121
{
122-
const code_assignt &code_assign = instruction.get_assign();
123-
const symbol_exprt &symbol_expr=to_symbol_expr(code_assign.lhs());
122+
const symbol_exprt &symbol_expr =
123+
to_symbol_expr(instruction.assign_lhs());
124124
const irep_idt id=symbol_expr.get_identifier();
125125

126126
if(

src/goto-programs/string_abstraction.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,8 @@ goto_programt::targett string_abstractiont::abstract_assign(
498498
goto_programt::targett target)
499499
{
500500
{
501-
code_assignt assign = target->get_assign();
502-
503-
exprt &lhs = assign.lhs();
504-
exprt &rhs = assign.rhs();
501+
exprt &lhs = target->assign_lhs();
502+
exprt &rhs = target->assign_rhs();
505503

506504
if(has_string_macros(lhs))
507505
{
@@ -511,11 +509,9 @@ goto_programt::targett string_abstractiont::abstract_assign(
511509

512510
if(has_string_macros(rhs))
513511
replace_string_macros(rhs, false, target->source_location);
514-
515-
target->set_assign(assign);
516512
}
517513

518-
const typet &type = target->get_assign().lhs().type();
514+
const typet &type = target->assign_lhs().type();
519515

520516
if(type.id() == ID_pointer)
521517
return abstract_pointer_assign(dest, target);
@@ -1066,11 +1062,9 @@ goto_programt::targett string_abstractiont::abstract_pointer_assign(
10661062
goto_programt &dest,
10671063
const goto_programt::targett target)
10681064
{
1069-
const code_assignt &assign = target->get_assign();
1070-
1071-
const exprt &lhs = assign.lhs();
1072-
const exprt rhs = assign.rhs();
1073-
const exprt *rhsp = &(assign.rhs());
1065+
const exprt &lhs = target->assign_lhs();
1066+
const exprt rhs = target->assign_rhs();
1067+
const exprt *rhsp = &(target->assign_rhs());
10741068

10751069
while(rhsp->id()==ID_typecast)
10761070
rhsp = &(to_typecast_expr(*rhsp).op());
@@ -1108,10 +1102,8 @@ goto_programt::targett string_abstractiont::abstract_char_assign(
11081102
goto_programt &dest,
11091103
goto_programt::targett target)
11101104
{
1111-
const code_assignt &assign = target->get_assign();
1112-
1113-
const exprt &lhs = assign.lhs();
1114-
const exprt *rhsp = &(assign.rhs());
1105+
const exprt &lhs = target->assign_lhs();
1106+
const exprt *rhsp = &(target->assign_rhs());
11151107

11161108
while(rhsp->id()==ID_typecast)
11171109
rhsp = &(to_typecast_expr(*rhsp).op());

0 commit comments

Comments
 (0)