Skip to content

Commit c830360

Browse files
committed
introduce instructiont::decl_symbol()
This addresses the issue of the ambiguous dual-use of code_declt in both the C front-end and the goto-program API by replacing the use of code_declt by directly returning the symbol_exprt. The client code is simplified.
1 parent a4c81ef commit c830360

21 files changed

+57
-63
lines changed

jbmc/src/java_bytecode/remove_exceptions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,7 @@ void remove_exceptionst::instrument_exceptions(
512512
{
513513
if(instr_it->is_decl())
514514
{
515-
code_declt decl = instr_it->get_decl();
516-
locals.push_back(decl.symbol());
515+
locals.push_back(instr_it->decl_symbol());
517516
}
518517
// Is it a handler push/pop or catch landing-pad?
519518
else if(instr_it->type==CATCH)

src/analyses/constant_propagator.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ void constant_propagator_domaint::transform(
158158

159159
if(from->is_decl())
160160
{
161-
const auto &code_decl = from->get_decl();
162-
const symbol_exprt &symbol = code_decl.symbol();
161+
const symbol_exprt &symbol = from->decl_symbol();
163162
values.set_to_top(symbol);
164163
}
165164
else if(from->is_assign())

src/analyses/custom_bitvector_analysis.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ void custom_bitvector_domaint::transform(
294294

295295
case DECL:
296296
{
297-
const code_declt &code_decl=to_code_decl(instruction.code);
298-
assign_lhs(code_decl.symbol(), vectorst());
297+
const auto &decl_symbol = instruction.decl_symbol();
298+
assign_lhs(decl_symbol, vectorst());
299299

300300
// is it a pointer?
301-
if(code_decl.symbol().type().id()==ID_pointer)
302-
assign_lhs(dereference_exprt(code_decl.symbol()), vectorst());
301+
if(decl_symbol.type().id() == ID_pointer)
302+
assign_lhs(dereference_exprt(decl_symbol), vectorst());
303303
}
304304
break;
305305

src/analyses/escape_analysis.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,8 @@ void escape_domaint::transform(
202202
break;
203203

204204
case DECL:
205-
{
206-
const code_declt &code_decl=to_code_decl(instruction.code);
207-
aliases.isolate(code_decl.get_identifier());
208-
assign_lhs_cleanup(code_decl.symbol(), std::set<irep_idt>());
209-
}
205+
aliases.isolate(instruction.decl_symbol().get_identifier());
206+
assign_lhs_cleanup(instruction.decl_symbol(), std::set<irep_idt>());
210207
break;
211208

212209
case DEAD:

src/analyses/global_may_alias.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ void global_may_alias_domaint::transform(
120120
}
121121

122122
case DECL:
123-
{
124-
const code_declt &code_decl = to_code_decl(instruction.code);
125-
aliases.isolate(code_decl.get_identifier());
123+
aliases.isolate(instruction.decl_symbol().get_identifier());
126124
break;
127-
}
128125

129126
case DEAD:
130127
{

src/analyses/goto_rw.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,9 @@ void goto_rw(
822822
break;
823823

824824
case DECL:
825+
rw_set.get_objects_rec(function, target, target->decl_symbol().type());
825826
rw_set.get_objects_rec(
826-
function, target, to_code_decl(target->code).symbol().type());
827-
rw_set.get_objects_rec(
828-
function,
829-
target,
830-
rw_range_sett::get_modet::LHS_W,
831-
to_code_decl(target->code).symbol());
827+
function, target, rw_range_sett::get_modet::LHS_W, target->decl_symbol());
832828
break;
833829

834830
case FUNCTION_CALL:

src/analyses/interval_domain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ void interval_domaint::transform(
7171
switch(instruction.type)
7272
{
7373
case DECL:
74-
havoc_rec(to_code_decl(instruction.code).symbol());
74+
havoc_rec(instruction.decl_symbol());
7575
break;
7676

7777
case DEAD:

src/analyses/local_bitvector_analysis.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,12 @@ void local_bitvector_analysist::build()
282282
}
283283

284284
case DECL:
285-
{
286-
const code_declt &code_decl = to_code_decl(instruction.code);
287285
assign_lhs(
288-
code_decl.symbol(),
286+
instruction.decl_symbol(),
289287
exprt(ID_uninitialized),
290288
loc_info_src,
291289
loc_info_dest);
292290
break;
293-
}
294291

295292
case DEAD:
296293
{

src/analyses/local_may_alias.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,9 @@ void local_may_aliast::build(const goto_functiont &goto_function)
383383
}
384384

385385
case DECL:
386-
{
387-
const code_declt &code_decl = to_code_decl(instruction.code);
388-
assign_lhs(code_decl.symbol(), nil_exprt(), loc_info_src, loc_info_dest);
386+
assign_lhs(
387+
instruction.decl_symbol(), nil_exprt(), loc_info_src, loc_info_dest);
389388
break;
390-
}
391389

392390
case DEAD:
393391
{

src/analyses/locals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void localst::build(const goto_functiont &goto_function)
2020
for(const auto &instruction : goto_function.body.instructions)
2121
{
2222
if(instruction.is_decl())
23-
locals.insert(instruction.get_decl().get_identifier());
23+
locals.insert(instruction.decl_symbol().get_identifier());
2424
}
2525

2626
locals.insert(

src/analyses/uninitialized_domain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void uninitialized_domaint::transform(
3333

3434
if(from->is_decl())
3535
{
36-
const irep_idt &identifier = to_code_decl(from->code).get_identifier();
36+
const irep_idt &identifier = from->decl_symbol().get_identifier();
3737
const symbolt &symbol = ns.lookup(identifier);
3838

3939
if(!symbol.is_static_lifetime)

src/analyses/variable-sensitivity/variable_sensitivity_domain.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ void variable_sensitivity_domaint::transform(
4646
abstract_object_pointert top_object =
4747
abstract_state
4848
.abstract_object_factory(
49-
to_code_decl(instruction.code).symbol().type(), ns, true, false)
49+
instruction.decl_symbol().type(), ns, true, false)
5050
->update_location_context(write_location, true);
51-
abstract_state.assign(
52-
to_code_decl(instruction.code).symbol(), top_object, ns);
51+
abstract_state.assign(instruction.decl_symbol(), top_object, ns);
5352
}
5453
// We now store top.
5554
break;

src/goto-diff/change_impact.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void full_slicert::operator()(
7979
jumps.push_back(instruction_node_index);
8080
else if(instruction->is_decl())
8181
{
82-
const auto &s=to_code_decl(instruction->code).symbol();
82+
const auto &s=instruction->decl_symbol();
8383
decl_dead[s.get_identifier()].push(instruction_node_index);
8484
}
8585
else if(instruction->is_dead())

src/goto-instrument/code_contracts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ bool code_contractst::add_pointer_checks(const std::string &function_name)
669669
{
670670
if(instruction_iterator->is_decl())
671671
{
672-
freely_assignable_exprs.insert(instruction_iterator->get_decl().symbol());
672+
freely_assignable_exprs.insert(instruction_iterator->decl_symbol());
673673
}
674674
else if(instruction_iterator->is_assign())
675675
{

src/goto-instrument/full_slicer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void full_slicert::operator()(
285285
jumps.push_back(instruction_node_index);
286286
else if(instruction->is_decl())
287287
{
288-
const auto &s = to_code_decl(instruction->code).symbol();
288+
const auto &s = instruction->decl_symbol();
289289
decl_dead[s.get_identifier()].push(instruction_node_index);
290290
}
291291
else if(instruction->is_dead())

src/goto-instrument/goto_program2code.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ goto_programt::const_targett goto_program2codet::convert_decl(
450450
goto_programt::const_targett upper_bound,
451451
code_blockt &dest)
452452
{
453-
code_declt d = target->get_decl();
453+
code_declt d = code_declt{target->decl_symbol()};
454454
symbol_exprt &symbol = d.symbol();
455455

456456
goto_programt::const_targett next=target;

src/goto-instrument/uninitialized.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ void uninitializedt::add_assertions(
109109
// if we track it, add declaration and assignment
110110
// for tracking variable!
111111

112-
const irep_idt &identifier=
113-
to_code_decl(instruction.code).get_identifier();
112+
const irep_idt &identifier = instruction.decl_symbol().get_identifier();
114113

115114
if(tracking.find(identifier)!=tracking.end())
116115
{

src/goto-programs/goto_program.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ void goto_programt::get_decl_identifiers(
240240
DATA_INVARIANT(
241241
instruction.code.operands().size() == 1,
242242
"declaration statement expects one operand");
243-
const symbol_exprt &symbol_expr = to_symbol_expr(instruction.code.op0());
244-
decl_identifiers.insert(symbol_expr.get_identifier());
243+
decl_identifiers.insert(instruction.decl_symbol().get_identifier());
245244
}
246245
}
247246
}
@@ -871,9 +870,9 @@ void goto_programt::instructiont::validate(
871870
source_location);
872871
DATA_CHECK_WITH_DIAGNOSTICS(
873872
vm,
874-
!ns.lookup(get_decl().get_identifier(), table_symbol),
873+
!ns.lookup(decl_symbol().get_identifier(), table_symbol),
875874
"declared symbols should be known",
876-
id2string(get_decl().get_identifier()),
875+
id2string(decl_symbol().get_identifier()),
877876
source_location);
878877
break;
879878
case DEAD:
@@ -954,13 +953,9 @@ void goto_programt::instructiont::transform(
954953

955954
case DECL:
956955
{
957-
auto new_symbol = f(get_decl().symbol());
956+
auto new_symbol = f(decl_symbol());
958957
if(new_symbol.has_value())
959-
{
960-
auto new_decl = get_decl();
961-
new_decl.symbol() = to_symbol_expr(*new_symbol);
962-
set_decl(new_decl);
963-
}
958+
decl_symbol() = to_symbol_expr(*new_symbol);
964959
}
965960
break;
966961

@@ -1046,7 +1041,7 @@ void goto_programt::instructiont::apply(
10461041
break;
10471042

10481043
case DECL:
1049-
f(get_decl().symbol());
1044+
f(decl_symbol());
10501045
break;
10511046

10521047
case DEAD:

src/goto-programs/goto_program.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Daniel Kroening, [email protected]
1818
#include <sstream>
1919
#include <string>
2020

21+
#include <util/deprecate.h>
2122
#include <util/invariant.h>
2223
#include <util/namespace.h>
2324
#include <util/source_location.h>
@@ -196,6 +197,7 @@ class goto_programt
196197
}
197198

198199
/// Get the declaration for DECL
200+
DEPRECATED(SINCE(2021, 2, 24, "Use decl_symbol instead"))
199201
const code_declt &get_decl() const
200202
{
201203
PRECONDITION(is_decl());
@@ -206,7 +208,30 @@ class goto_programt
206208
return decl;
207209
}
208210

211+
/// Get the declared symbol for DECL
212+
const symbol_exprt &decl_symbol() const
213+
{
214+
PRECONDITION(is_decl());
215+
auto &decl = expr_checked_cast<code_declt>(code);
216+
INVARIANT(
217+
!decl.initial_value(),
218+
"code_declt in goto program may not contain initialization.");
219+
return decl.symbol();
220+
}
221+
222+
/// Get the declared symbol for DECL
223+
symbol_exprt &decl_symbol()
224+
{
225+
PRECONDITION(is_decl());
226+
auto &decl = expr_checked_cast<code_declt>(code);
227+
INVARIANT(
228+
!decl.initial_value(),
229+
"code_declt in goto program may not contain initialization.");
230+
return decl.symbol();
231+
}
232+
209233
/// Set the declaration for DECL
234+
DEPRECATED(SINCE(2021, 2, 24, "Use decl_symbol instead"))
210235
void set_decl(code_declt c)
211236
{
212237
PRECONDITION(is_decl());

src/goto-programs/string_abstraction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void string_abstractiont::declare_define_locals(goto_programt &dest)
251251
// same name may exist several times due to inlining, make sure the first
252252
// declaration is used
253253
available_decls.insert(
254-
std::make_pair(it->get_decl().get_identifier(), it));
254+
std::make_pair(it->decl_symbol().get_identifier(), it));
255255

256256
// declare (and, if necessary, define) locals
257257
for(const auto &l : locals)

src/goto-symex/symex_decl.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,7 @@ Author: Daniel Kroening, [email protected]
1616
void goto_symext::symex_decl(statet &state)
1717
{
1818
const goto_programt::instructiont &instruction=*state.source.pc;
19-
20-
const auto &code = instruction.get_decl();
21-
22-
// two-operand decl not supported here
23-
// we handle the decl with only one operand
24-
PRECONDITION(code.operands().size() == 1);
25-
26-
symex_decl(state, code.symbol());
19+
symex_decl(state, instruction.decl_symbol());
2720
}
2821

2922
void goto_symext::symex_decl(statet &state, const symbol_exprt &expr)

0 commit comments

Comments
 (0)