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