9
9
// / \file
10
10
// / Replace Java Nondet expressions
11
11
12
- #include " goto-programs/replace_java_nondet.h"
13
- #include " goto-programs/goto_convert.h"
14
- #include " goto-programs/goto_model.h"
15
- #include " goto-programs/remove_skip.h"
12
+ #include " replace_java_nondet.h"
16
13
17
- #include " util/irep_ids.h"
14
+ #include < goto-programs/goto_convert.h>
15
+ #include < goto-programs/goto_model.h>
16
+ #include < goto-programs/remove_skip.h>
18
17
19
18
#include < algorithm>
20
19
#include < regex>
24
23
class nondet_instruction_infot final
25
24
{
26
25
public:
27
- enum class is_nondett :bool { FALSE , TRUE };
28
- enum class is_nullablet :bool { FALSE , TRUE };
26
+ enum class is_nondett : bool
27
+ {
28
+ FALSE ,
29
+ TRUE
30
+ };
31
+ enum class is_nullablet : bool
32
+ {
33
+ FALSE ,
34
+ TRUE
35
+ };
29
36
30
- nondet_instruction_infot ():
31
- is_nondet (is_nondett::FALSE ),
32
- is_nullable (is_nullablet::FALSE )
37
+ nondet_instruction_infot ()
38
+ : is_nondet(is_nondett::FALSE ), is_nullable(is_nullablet::FALSE )
33
39
{
34
40
}
35
41
36
- explicit nondet_instruction_infot (is_nullablet is_nullable):
37
- is_nondet(is_nondett::TRUE ),
38
- is_nullable(is_nullable)
42
+ explicit nondet_instruction_infot (is_nullablet is_nullable)
43
+ : is_nondet(is_nondett::TRUE ), is_nullable(is_nullable)
39
44
{
40
45
}
41
46
42
- is_nondett get_instruction_type () const { return is_nondet; }
43
- is_nullablet get_nullable_type () const { return is_nullable; }
47
+ is_nondett get_instruction_type () const
48
+ {
49
+ return is_nondet;
50
+ }
51
+ is_nullablet get_nullable_type () const
52
+ {
53
+ return is_nullable;
54
+ }
44
55
45
56
private:
46
57
is_nondett is_nondet;
@@ -52,11 +63,11 @@ class nondet_instruction_infot final
52
63
// / \return A structure detailing whether the function call appears to be one of
53
64
// / our nondet library methods, and if so, whether or not it allows null
54
65
// / results.
55
- static nondet_instruction_infot is_nondet_returning_object (
56
- const code_function_callt &function_call)
66
+ static nondet_instruction_infot
67
+ is_nondet_returning_object ( const code_function_callt &function_call)
57
68
{
58
- const auto &function_symbol= to_symbol_expr (function_call.function ());
59
- const auto function_name= id2string (function_symbol.get_identifier ());
69
+ const auto &function_symbol = to_symbol_expr (function_call.function ());
70
+ const auto function_name = id2string (function_symbol.get_identifier ());
60
71
const std::regex reg (
61
72
R"( .*org\.cprover\.CProver\.nondet)"
62
73
R"( (?:Boolean|Byte|Char|Short|Int|Long|Float|Double|With(out)?Null.*))" );
@@ -74,51 +85,51 @@ static nondet_instruction_infot is_nondet_returning_object(
74
85
// / recognised nondet library methods, and return some information about it.
75
86
// / \param instr: A goto-program instruction to check.
76
87
// / \return A structure detailing the properties of the nondet method.
77
- static nondet_instruction_infot get_nondet_instruction_info (
78
- const goto_programt::const_targett &instr)
88
+ static nondet_instruction_infot
89
+ get_nondet_instruction_info ( const goto_programt::const_targett &instr)
79
90
{
80
- if (!(instr->is_function_call () && instr->code .id ()== ID_code))
91
+ if (!(instr->is_function_call () && instr->code .id () == ID_code))
81
92
{
82
93
return nondet_instruction_infot ();
83
94
}
84
- const auto &code= to_code (instr->code );
85
- if (code.get_statement ()!= ID_function_call)
95
+ const auto &code = to_code (instr->code );
96
+ if (code.get_statement () != ID_function_call)
86
97
{
87
98
return nondet_instruction_infot ();
88
99
}
89
- const auto &function_call= to_code_function_call (code);
100
+ const auto &function_call = to_code_function_call (code);
90
101
return is_nondet_returning_object (function_call);
91
102
}
92
103
93
104
// / Return whether the expression is a symbol with the specified identifier.
94
105
// / \param expr: The expression which may be a symbol.
95
106
// / \param identifier: Some identifier.
96
107
// / \return True if the expression is a symbol with the specified identifier.
97
- static bool is_symbol_with_id (const exprt& expr, const irep_idt& identifier)
108
+ static bool is_symbol_with_id (const exprt & expr, const irep_idt & identifier)
98
109
{
99
- return expr.id ()== ID_symbol &&
100
- to_symbol_expr (expr).get_identifier ()== identifier;
110
+ return expr.id () == ID_symbol &&
111
+ to_symbol_expr (expr).get_identifier () == identifier;
101
112
}
102
113
103
114
// / Return whether the expression is a typecast with the specified identifier.
104
115
// / \param expr: The expression which may be a typecast.
105
116
// / \param identifier: Some identifier.
106
117
// / \return True if the expression is a typecast with one operand, and the
107
118
// / typecast's identifier matches the specified identifier.
108
- static bool is_typecast_with_id (const exprt& expr, const irep_idt& identifier)
119
+ static bool is_typecast_with_id (const exprt & expr, const irep_idt & identifier)
109
120
{
110
- if (!(expr.id ()== ID_typecast && expr.operands ().size ()== 1 ))
121
+ if (!(expr.id () == ID_typecast && expr.operands ().size () == 1 ))
111
122
{
112
123
return false ;
113
124
}
114
- const auto &typecast= to_typecast_expr (expr);
115
- if (!(typecast.op ().id ()== ID_symbol && !typecast.op ().has_operands ()))
125
+ const auto &typecast = to_typecast_expr (expr);
126
+ if (!(typecast.op ().id () == ID_symbol && !typecast.op ().has_operands ()))
116
127
{
117
128
return false ;
118
129
}
119
- const auto &op_symbol= to_symbol_expr (typecast.op ());
130
+ const auto &op_symbol = to_symbol_expr (typecast.op ());
120
131
// Return whether the typecast has the expected operand
121
- return op_symbol.get_identifier ()== identifier;
132
+ return op_symbol.get_identifier () == identifier;
122
133
}
123
134
124
135
// / Return whether the instruction is an assignment, and the rhs is a symbol or
@@ -136,7 +147,7 @@ static bool is_assignment_from(
136
147
{
137
148
return false ;
138
149
}
139
- const auto &rhs= to_code_assign (instr.code ).rhs ();
150
+ const auto &rhs = to_code_assign (instr.code ).rhs ();
140
151
return is_symbol_with_id (rhs, identifier) ||
141
152
is_typecast_with_id (rhs, identifier);
142
153
}
@@ -165,10 +176,11 @@ static goto_programt::targett check_and_replace_target(
165
176
const goto_programt::targett &target)
166
177
{
167
178
// Check whether this is a nondet library method, and return if not
168
- const auto instr_info=get_nondet_instruction_info (target);
169
- const auto next_instr=std::next (target);
170
- if (instr_info.get_instruction_type ()==
171
- nondet_instruction_infot::is_nondett::FALSE )
179
+ const auto instr_info = get_nondet_instruction_info (target);
180
+ const auto next_instr = std::next (target);
181
+ if (
182
+ instr_info.get_instruction_type () ==
183
+ nondet_instruction_infot::is_nondett::FALSE )
172
184
{
173
185
return next_instr;
174
186
}
@@ -227,8 +239,8 @@ static goto_programt::targett check_and_replace_target(
227
239
228
240
// Assume that the LHS of *this* assignment is the actual nondet variable
229
241
const auto &code_assign = to_code_assign (assignment_instruction->code );
230
- const auto nondet_var= code_assign.lhs ();
231
- const auto source_loc= target->source_location ;
242
+ const auto nondet_var = code_assign.lhs ();
243
+ const auto source_loc = target->source_location ;
232
244
233
245
// Erase from the nondet function call to the assignment
234
246
const auto after_matching_assignment = std::next (assignment_instruction);
@@ -239,20 +251,19 @@ static goto_programt::targett check_and_replace_target(
239
251
std::for_each (
240
252
target,
241
253
after_matching_assignment,
242
- [](goto_programt::instructiont &instr)
243
- {
254
+ [](goto_programt::instructiont &instr) { // NOLINT (*)
244
255
instr.make_skip ();
245
256
});
246
257
247
- const auto inserted= goto_program.insert_before (after_matching_assignment);
258
+ const auto inserted = goto_program.insert_before (after_matching_assignment);
248
259
inserted->make_assignment ();
249
260
side_effect_expr_nondett inserted_expr (nondet_var.type ());
250
261
inserted_expr.set_nullable (
251
- instr_info.get_nullable_type ()==
262
+ instr_info.get_nullable_type () ==
252
263
nondet_instruction_infot::is_nullablet::TRUE );
253
- inserted->code = code_assignt (nondet_var, inserted_expr);
254
- inserted->code .add_source_location ()= source_loc;
255
- inserted->source_location = source_loc;
264
+ inserted->code = code_assignt (nondet_var, inserted_expr);
265
+ inserted->code .add_source_location () = source_loc;
266
+ inserted->source_location = source_loc;
256
267
257
268
goto_program.update ();
258
269
@@ -265,13 +276,12 @@ static goto_programt::targett check_and_replace_target(
265
276
// / \param goto_program: The goto program to modify.
266
277
static void replace_java_nondet (goto_programt &goto_program)
267
278
{
268
- for (auto instruction_iterator= goto_program.instructions .begin (),
269
- end= goto_program.instructions .end ();
270
- instruction_iterator!= end;)
279
+ for (auto instruction_iterator = goto_program.instructions .begin (),
280
+ end = goto_program.instructions .end ();
281
+ instruction_iterator != end;)
271
282
{
272
- instruction_iterator=check_and_replace_target (
273
- goto_program,
274
- instruction_iterator);
283
+ instruction_iterator =
284
+ check_and_replace_target (goto_program, instruction_iterator);
275
285
}
276
286
}
277
287
0 commit comments