Skip to content

Commit 60892e0

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 60892e0

File tree

9 files changed

+38
-27
lines changed

9 files changed

+38
-27
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/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/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/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-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)