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