17
17
#include < goto-checker/bmc_util.h>
18
18
#include < goto-checker/report_util.h>
19
19
20
- #include < util/xml.h>
21
20
#include < util/json.h>
21
+ #include < util/xml.h>
22
22
23
- #include < solvers/sat/satcheck.h>
24
23
#include < solvers/prop/literal_expr.h>
24
+ #include < solvers/sat/satcheck.h>
25
25
26
- #include < goto-symex/build_goto_trace.h>
27
- #include < goto-programs/xml_goto_trace.h>
28
26
#include < goto-programs/json_goto_trace.h>
27
+ #include < goto-programs/xml_goto_trace.h>
28
+ #include < goto-symex/build_goto_trace.h>
29
29
30
30
void bmc_all_propertiest::goal_covered (const cover_goalst::goalt &)
31
31
{
32
32
for (auto &g : goal_map)
33
33
{
34
34
// failed already?
35
- if (g.second .status == goalt::statust::FAILURE)
35
+ if (g.second .status == goalt::statust::FAILURE)
36
36
continue ;
37
37
38
38
// check whether failed
39
39
for (auto &c : g.second .instances )
40
40
{
41
- literalt cond= c->cond_literal ;
41
+ literalt cond = c->cond_literal ;
42
42
43
43
if (solver.l_get (cond).is_false ())
44
44
{
45
- g.second .status = goalt::statust::FAILURE;
45
+ g.second .status = goalt::statust::FAILURE;
46
46
build_goto_trace (bmc.equation , c, solver, bmc.ns , g.second .goto_trace );
47
47
break ;
48
48
}
@@ -56,7 +56,7 @@ safety_checkert::resultt bmc_all_propertiest::operator()()
56
56
57
57
solver.set_message_handler (get_message_handler ());
58
58
59
- auto solver_start= std::chrono::steady_clock::now ();
59
+ auto solver_start = std::chrono::steady_clock::now ();
60
60
61
61
convert_symex_target_equation (
62
62
bmc.equation , bmc.prop_conv , get_message_handler ());
@@ -67,13 +67,13 @@ safety_checkert::resultt bmc_all_propertiest::operator()()
67
67
forall_goto_functions (f_it, goto_functions)
68
68
forall_goto_program_instructions (i_it, f_it->second .body )
69
69
if (i_it->is_assert ())
70
- goal_map[i_it->source_location .get_property_id ()]= goalt (*i_it);
70
+ goal_map[i_it->source_location .get_property_id ()] = goalt (*i_it);
71
71
72
72
// get the conditions for these goals from formula
73
73
// collect all 'instances' of the properties
74
- for (symex_target_equationt::SSA_stepst::iterator
75
- it= bmc.equation .SSA_steps .begin ();
76
- it!= bmc.equation .SSA_steps .end ();
74
+ for (symex_target_equationt::SSA_stepst::iterator it =
75
+ bmc.equation .SSA_steps .begin ();
76
+ it != bmc.equation .SSA_steps .end ();
77
77
it++)
78
78
{
79
79
if (it->is_assert ())
@@ -104,28 +104,28 @@ safety_checkert::resultt bmc_all_propertiest::operator()()
104
104
{
105
105
// Our goal is to falsify a property, i.e., we will
106
106
// add the negation of the property as goal.
107
- literalt p= !solver.convert (g.second .as_expr ());
107
+ literalt p = !solver.convert (g.second .as_expr ());
108
108
cover_goals.add (p);
109
109
}
110
110
111
111
status () << " Running " << solver.decision_procedure_text () << eom;
112
112
113
- bool error= false ;
113
+ bool error = false ;
114
114
115
- decision_proceduret::resultt result= cover_goals ();
115
+ decision_proceduret::resultt result = cover_goals ();
116
116
117
- if (result== decision_proceduret::resultt::D_ERROR)
117
+ if (result == decision_proceduret::resultt::D_ERROR)
118
118
{
119
- error= true ;
119
+ error = true ;
120
120
for (auto &g : goal_map)
121
- if (g.second .status == goalt::statust::UNKNOWN)
122
- g.second .status = goalt::statust::ERROR;
121
+ if (g.second .status == goalt::statust::UNKNOWN)
122
+ g.second .status = goalt::statust::ERROR;
123
123
}
124
124
else
125
125
{
126
126
for (auto &g : goal_map)
127
- if (g.second .status == goalt::statust::UNKNOWN)
128
- g.second .status = goalt::statust::SUCCESS;
127
+ if (g.second .status == goalt::statust::UNKNOWN)
128
+ g.second .status = goalt::statust::SUCCESS;
129
129
}
130
130
131
131
{
@@ -143,155 +143,156 @@ safety_checkert::resultt bmc_all_propertiest::operator()()
143
143
if (error)
144
144
return safety_checkert::resultt::ERROR;
145
145
146
- bool safe= (cover_goals.number_covered ()== 0 );
146
+ bool safe = (cover_goals.number_covered () == 0 );
147
147
148
148
if (safe)
149
149
report_success (bmc.ui_message_handler ); // legacy, might go away
150
150
else
151
151
report_failure (bmc.ui_message_handler ); // legacy, might go away
152
152
153
- return safe?safety_checkert::resultt::SAFE:safety_checkert::resultt::UNSAFE;
153
+ return safe ? safety_checkert::resultt::SAFE
154
+ : safety_checkert::resultt::UNSAFE;
154
155
}
155
156
156
157
void bmc_all_propertiest::report (const cover_goalst &cover_goals)
157
158
{
158
159
switch (bmc.ui_message_handler .get_ui ())
159
160
{
160
161
case ui_message_handlert::uit::PLAIN:
162
+ {
163
+ result () << " \n ** Results:" << eom;
164
+
165
+ // collect goals in a vector
166
+ std::vector<goal_mapt::const_iterator> goals;
167
+
168
+ for (auto g_it = goal_map.begin (); g_it != goal_map.end (); g_it++)
169
+ goals.push_back (g_it);
170
+
171
+ // now determine an ordering for those goals:
172
+ // 1. alphabetical ordering of file name
173
+ // 2. numerical ordering of line number
174
+ // 3. alphabetical ordering of goal ID
175
+ std::sort (
176
+ goals.begin (),
177
+ goals.end (),
178
+ [](goal_mapt::const_iterator git1, goal_mapt::const_iterator git2) {
179
+ const auto &g1 = git1->second .source_location ;
180
+ const auto &g2 = git2->second .source_location ;
181
+ if (g1.get_file () != g2.get_file ())
182
+ return id2string (g1.get_file ()) < id2string (g2.get_file ());
183
+ else if (!g1.get_line ().empty () && !g2.get_line ().empty ())
184
+ return std::stoul (id2string (g1.get_line ())) <
185
+ std::stoul (id2string (g2.get_line ()));
186
+ else
187
+ return id2string (git1->first ) < id2string (git2->first );
188
+ });
189
+
190
+ // now show in the order we have determined
191
+
192
+ irep_idt previous_function;
193
+ irep_idt current_file;
194
+ for (const auto &g : goals)
161
195
{
162
- result () << " \n ** Results:" << eom;
163
-
164
- // collect goals in a vector
165
- std::vector<goal_mapt::const_iterator> goals;
166
-
167
- for (auto g_it = goal_map.begin (); g_it != goal_map.end (); g_it++)
168
- goals.push_back (g_it);
169
-
170
- // now determine an ordering for those goals:
171
- // 1. alphabetical ordering of file name
172
- // 2. numerical ordering of line number
173
- // 3. alphabetical ordering of goal ID
174
- std::sort (
175
- goals.begin (),
176
- goals.end (),
177
- [](goal_mapt::const_iterator git1, goal_mapt::const_iterator git2) {
178
- const auto &g1 = git1->second .source_location ;
179
- const auto &g2 = git2->second .source_location ;
180
- if (g1.get_file () != g2.get_file ())
181
- return id2string (g1.get_file ()) < id2string (g2.get_file ());
182
- else if (!g1.get_line ().empty () && !g2.get_line ().empty ())
183
- return std::stoul (id2string (g1.get_line ())) <
184
- std::stoul (id2string (g2.get_line ()));
185
- else
186
- return id2string (git1->first ) < id2string (git2->first );
187
- });
188
-
189
- // now show in the order we have determined
190
-
191
- irep_idt previous_function;
192
- irep_idt current_file;
193
- for (const auto &g : goals)
194
- {
195
- const auto &l = g->second .source_location ;
196
+ const auto &l = g->second .source_location ;
196
197
197
- if (l.get_function () != previous_function)
198
+ if (l.get_function () != previous_function)
199
+ {
200
+ if (!previous_function.empty ())
201
+ result () << ' \n ' ;
202
+ previous_function = l.get_function ();
203
+ if (!previous_function.empty ())
198
204
{
199
- if (!previous_function.empty ())
200
- result () << ' \n ' ;
201
- previous_function = l.get_function ();
202
- if (!previous_function.empty ())
203
- {
204
- current_file = l.get_file ();
205
- if (!current_file.empty ())
206
- result () << current_file << ' ' ;
207
- if (!l.get_function ().empty ())
208
- result () << " function " << l.get_function ();
209
- result () << eom;
210
- }
205
+ current_file = l.get_file ();
206
+ if (!current_file.empty ())
207
+ result () << current_file << ' ' ;
208
+ if (!l.get_function ().empty ())
209
+ result () << " function " << l.get_function ();
210
+ result () << eom;
211
211
}
212
+ }
212
213
213
- result () << faint << ' [' << g->first << " ] " << reset;
214
-
215
- if (l.get_file () != current_file)
216
- result () << " file " << l.get_file () << ' ' ;
214
+ result () << faint << ' [' << g->first << " ] " << reset;
217
215
218
- if (!l. get_line (). empty () )
219
- result () << " line " << l.get_line () << ' ' ;
216
+ if (l. get_file () != current_file )
217
+ result () << " file " << l.get_file () << ' ' ;
220
218
221
- result () << g->second .description << " : " ;
219
+ if (!l.get_line ().empty ())
220
+ result () << " line " << l.get_line () << ' ' ;
222
221
223
- if (g->second .status == goalt::statust::SUCCESS)
224
- result () << green;
225
- else
226
- result () << red;
222
+ result () << g->second .description << " : " ;
227
223
228
- result () << g->second .status_string () << reset << eom;
229
- }
224
+ if (g->second .status == goalt::statust::SUCCESS)
225
+ result () << green;
226
+ else
227
+ result () << red;
230
228
231
- if (bmc.options .get_bool_option (" trace" ))
232
- {
233
- for (const auto &g : goal_map)
234
- if (g.second .status ==goalt::statust::FAILURE)
235
- {
236
- result () << " \n " << " Trace for " << g.first << " :" << " \n " ;
237
- show_goto_trace (
238
- result (), bmc.ns , g.second .goto_trace , bmc.trace_options ());
239
- result () << eom;
240
- }
241
- }
229
+ result () << g->second .status_string () << reset << eom;
230
+ }
242
231
243
- status () << " \n ** " << cover_goals.number_covered ()
244
- << " of " << cover_goals.size () << " failed ("
245
- << cover_goals.iterations () << " iteration"
246
- << (cover_goals.iterations ()==1 ?" " :" s" )
247
- << " )" << eom;
232
+ if (bmc.options .get_bool_option (" trace" ))
233
+ {
234
+ for (const auto &g : goal_map)
235
+ if (g.second .status == goalt::statust::FAILURE)
236
+ {
237
+ result () << " \n "
238
+ << " Trace for " << g.first << " :"
239
+ << " \n " ;
240
+ show_goto_trace (
241
+ result (), bmc.ns , g.second .goto_trace , bmc.trace_options ());
242
+ result () << eom;
243
+ }
248
244
}
249
- break ;
245
+
246
+ status () << " \n ** " << cover_goals.number_covered () << " of "
247
+ << cover_goals.size () << " failed (" << cover_goals.iterations ()
248
+ << " iteration" << (cover_goals.iterations () == 1 ? " " : " s" )
249
+ << " )" << eom;
250
+ }
251
+ break ;
250
252
251
253
case ui_message_handlert::uit::XML_UI:
254
+ {
255
+ for (const auto &g : goal_map)
252
256
{
253
- for (const auto &g : goal_map)
254
- {
255
- xmlt xml_result (
256
- " result" ,
257
- {{" property" , id2string (g.first )},
258
- {" status" , g.second .status_string ()}},
259
- {});
257
+ xmlt xml_result (
258
+ " result" ,
259
+ {{" property" , id2string (g.first )},
260
+ {" status" , g.second .status_string ()}},
261
+ {});
260
262
261
- if (g.second .status == goalt::statust::FAILURE)
262
- convert (bmc.ns , g.second .goto_trace , xml_result.new_element ());
263
+ if (g.second .status == goalt::statust::FAILURE)
264
+ convert (bmc.ns , g.second .goto_trace , xml_result.new_element ());
263
265
264
- result () << xml_result;
265
- }
266
- break ;
266
+ result () << xml_result;
267
267
}
268
+ break ;
269
+ }
268
270
269
- case ui_message_handlert::uit::JSON_UI:
271
+ case ui_message_handlert::uit::JSON_UI:
272
+ {
273
+ if (result ().tellp () > 0 )
274
+ result () << eom; // force end of previous message
275
+ json_stream_objectt &json_result =
276
+ bmc.ui_message_handler .get_json_stream ().push_back_stream_object ();
277
+ json_stream_arrayt &result_array =
278
+ json_result.push_back_stream_array (" result" );
279
+
280
+ for (const auto &g : goal_map)
270
281
{
271
- if (result ().tellp () > 0 )
272
- result () << eom; // force end of previous message
273
- json_stream_objectt &json_result =
274
- bmc.ui_message_handler .get_json_stream ().push_back_stream_object ();
275
- json_stream_arrayt &result_array =
276
- json_result.push_back_stream_array (" result" );
282
+ json_stream_objectt &result = result_array.push_back_stream_object ();
283
+ result[" property" ] = json_stringt (g.first );
284
+ result[" description" ] = json_stringt (g.second .description );
285
+ result[" status" ] = json_stringt (g.second .status_string ());
277
286
278
- for ( const auto &g : goal_map )
287
+ if (g. second . status == goalt::statust::FAILURE )
279
288
{
280
- json_stream_objectt &result = result_array.push_back_stream_object ();
281
- result[" property" ] = json_stringt (g.first );
282
- result[" description" ] = json_stringt (g.second .description );
283
- result[" status" ]=json_stringt (g.second .status_string ());
284
-
285
- if (g.second .status ==goalt::statust::FAILURE)
286
- {
287
- json_stream_arrayt &json_trace =
288
- result.push_back_stream_array (" trace" );
289
- convert<json_stream_arrayt>(
290
- bmc.ns , g.second .goto_trace , json_trace, bmc.trace_options ());
291
- }
289
+ json_stream_arrayt &json_trace = result.push_back_stream_array (" trace" );
290
+ convert<json_stream_arrayt>(
291
+ bmc.ns , g.second .goto_trace , json_trace, bmc.trace_options ());
292
292
}
293
293
}
294
- break ;
294
+ }
295
+ break ;
295
296
}
296
297
}
297
298
0 commit comments