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