Skip to content

Commit cd12c87

Browse files
committed
Remove goto_programt::instructiont::type_nonconst
Use of this method was never advised, and the remaining two uses can be rewritten to use more appropriate (and modern) APIs.
1 parent 6351d3a commit cd12c87

File tree

3 files changed

+15
-30
lines changed

3 files changed

+15
-30
lines changed

src/goto-programs/goto_program.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,9 @@ class goto_programt
345345
return _type;
346346
}
347347

348-
/// Set the kind of the instruction.
349-
/// This method is best avoided to prevent mal-formed instructions.
350-
/// Consider using the goto_programt::make_X methods instead.
351-
goto_program_instruction_typet &type_nonconst()
352-
{
353-
return _type;
354-
}
355-
356348
protected:
357-
// Use type() and type_nonconst() to access.
349+
// Use type() to access. To prevent malformed instructions, no non-const
350+
// access method is provided.
358351
goto_program_instruction_typet _type;
359352

360353
public:

src/goto-programs/read_bin_goto_object.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,15 @@ static bool read_bin_goto_object(
9797
for(std::size_t ins_index = 0; ins_index < ins_count; ++ins_index)
9898
{
9999
goto_programt::targett itarget = f.body.add_instruction();
100-
goto_programt::instructiont &instruction=*itarget;
101100

102-
instruction.code_nonconst() =
103-
static_cast<const codet &>(irepconverter.reference_convert(in));
104-
instruction.source_location_nonconst() =
101+
goto_programt::instructiont instruction{
102+
static_cast<const codet &>(irepconverter.reference_convert(in)),
105103
static_cast<const source_locationt &>(
106-
irepconverter.reference_convert(in));
107-
instruction.type_nonconst() =
108-
(goto_program_instruction_typet)irepconverter.read_gb_word(in);
109-
instruction.guard =
110-
static_cast<const exprt &>(irepconverter.reference_convert(in));
104+
irepconverter.reference_convert(in)),
105+
(goto_program_instruction_typet)irepconverter.read_gb_word(in),
106+
static_cast<const exprt &>(irepconverter.reference_convert(in)),
107+
{}};
108+
111109
instruction.target_number = irepconverter.read_gb_word(in);
112110
if(instruction.is_target() &&
113111
rev_target_map.insert(
@@ -131,6 +129,8 @@ static bool read_bin_goto_object(
131129
// The above info is also held in the goto_functiont object, and could
132130
// be stored in the binary.
133131
}
132+
133+
itarget->swap(instruction);
134134
}
135135

136136
// Resolve targets

unit/goto-programs/structured_trace_util.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ Author: Diffblue
1010
#include <goto-programs/goto_trace.h>
1111
#include <goto-programs/structured_trace_util.h>
1212

13-
void link_edges(goto_programt::targett source, goto_programt::targett target)
14-
{
15-
source->targets.push_back(target);
16-
target->incoming_edges.insert(source);
17-
}
18-
1913
source_locationt simple_location(const std::string &file, unsigned line)
2014
{
2115
source_locationt location;
@@ -53,20 +47,18 @@ TEST_CASE("structured_trace_util", "[core][util][trace]")
5347
// 0 # normal_location
5448
add_instruction(basic_location, instructions);
5549
// 1 # loop_head
56-
add_instruction(loop_head_location, instructions);
50+
auto loop_head = add_instruction(loop_head_location, instructions);
5751
// 2: goto 1 # back_edge
58-
const auto back_edge = add_instruction(back_edge_location, instructions);
59-
back_edge->type_nonconst() = GOTO;
52+
instructions.emplace_back(
53+
goto_programt::make_goto(loop_head, back_edge_location));
54+
loop_head->incoming_edges.insert(--instructions.end());
6055
// 3: no_location
6156
goto_programt::instructiont no_location;
6257
no_location.location_number = 3;
6358
instructions.push_back(no_location);
6459
// 4: no_file
6560
add_instruction(no_file_location, instructions);
6661

67-
link_edges(
68-
std::next(instructions.begin(), 2), std::next(instructions.begin(), 1));
69-
7062
SECTION("location-only steps")
7163
{
7264
goto_trace_stept step;

0 commit comments

Comments
 (0)