Skip to content

Commit ce2680b

Browse files
authored
Merge pull request #6419 from tautschnig/nonconst-cleanup
Remove goto_programt::instructiont::type_nonconst
2 parents 07895ef + f6fa03c commit ce2680b

File tree

3 files changed

+20
-28
lines changed

3 files changed

+20
-28
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: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,20 @@ 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() =
101+
// take copies as references into irepconverter are not stable
102+
codet code =
103103
static_cast<const codet &>(irepconverter.reference_convert(in));
104-
instruction.source_location_nonconst() =
105-
static_cast<const source_locationt &>(
106-
irepconverter.reference_convert(in));
107-
instruction.type_nonconst() =
104+
source_locationt source_location = static_cast<const source_locationt &>(
105+
irepconverter.reference_convert(in));
106+
goto_program_instruction_typet instruction_type =
108107
(goto_program_instruction_typet)irepconverter.read_gb_word(in);
109-
instruction.guard =
108+
exprt guard =
110109
static_cast<const exprt &>(irepconverter.reference_convert(in));
110+
111+
goto_programt::instructiont instruction{
112+
code, source_location, instruction_type, guard, {}};
113+
111114
instruction.target_number = irepconverter.read_gb_word(in);
112115
if(instruction.is_target() &&
113116
rev_target_map.insert(
@@ -131,6 +134,8 @@ static bool read_bin_goto_object(
131134
// The above info is also held in the goto_functiont object, and could
132135
// be stored in the binary.
133136
}
137+
138+
itarget->swap(instruction);
134139
}
135140

136141
// Resolve targets

unit/goto-programs/structured_trace_util.cpp

Lines changed: 6 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,20 @@ 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+
auto back_edge = std::prev(instructions.end());
55+
back_edge->location_number = 2;
56+
loop_head->incoming_edges.insert(back_edge);
6057
// 3: no_location
6158
goto_programt::instructiont no_location;
6259
no_location.location_number = 3;
6360
instructions.push_back(no_location);
6461
// 4: no_file
6562
add_instruction(no_file_location, instructions);
6663

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

0 commit comments

Comments
 (0)