Skip to content

Commit 2ab3b9c

Browse files
committed
Activate JSON streaming when printing goto-traces
1 parent 54bae24 commit 2ab3b9c

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

src/cbmc/all_properties.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -206,24 +206,26 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
206206

207207
case ui_message_handlert::uit::JSON_UI:
208208
{
209-
json_objectt json_result;
210-
json_arrayt &result_array=json_result["result"].make_array();
209+
json_stream_objectt &json_result =
210+
result().json_stream().push_back_stream_object();
211+
json_stream_arrayt &result_array =
212+
json_result.push_back_stream_array("result");
211213

212214
for(const auto &g : goal_map)
213215
{
214-
json_objectt &result=result_array.push_back().make_object();
216+
json_stream_objectt &result = result_array.push_back_stream_object();
215217
result["property"]=json_stringt(id2string(g.first));
216218
result["description"]=json_stringt(id2string(g.second.description));
217219
result["status"]=json_stringt(g.second.status_string());
218220

219221
if(g.second.status==goalt::statust::FAILURE)
220222
{
221-
jsont &json_trace=result["trace"];
222-
convert(bmc.ns, g.second.goto_trace, json_trace, bmc.trace_options());
223+
json_stream_arrayt &json_trace =
224+
result.push_back_stream_array("trace");
225+
convert<json_stream_arrayt>(
226+
bmc.ns, g.second.goto_trace, json_trace, bmc.trace_options());
223227
}
224228
}
225-
226-
result() << json_result;
227229
}
228230
break;
229231
}

src/cbmc/bmc.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Author: Daniel Kroening, [email protected]
2424
#include <util/memory_info.h>
2525
#include <util/message.h>
2626
#include <util/json.h>
27+
#include <util/json_stream.h>
2728
#include <util/cprover_prefix.h>
2829

2930
#include <langapi/mode.h>
@@ -86,18 +87,17 @@ void bmct::error_trace()
8687

8788
case ui_message_handlert::uit::JSON_UI:
8889
{
89-
json_objectt json;
90-
json_arrayt &result_array=json["results"].make_array();
91-
json_objectt &json_result=result_array.push_back().make_object();
90+
json_stream_objectt &json_result =
91+
status().json_stream().push_back_stream_object();
9292
const goto_trace_stept &step=goto_trace.steps.back();
9393
json_result["property"]=
9494
json_stringt(id2string(step.pc->source_location.get_property_id()));
9595
json_result["description"]=
9696
json_stringt(id2string(step.pc->source_location.get_comment()));
9797
json_result["status"]=json_stringt("failed");
98-
jsont &json_trace=json_result["trace"];
99-
convert(ns, goto_trace, json_trace, trace_options());
100-
status() << json_result;
98+
json_stream_arrayt &json_trace =
99+
json_result.push_back_stream_array("trace");
100+
convert<json_stream_arrayt>(ns, goto_trace, json_trace, trace_options());
101101
}
102102
break;
103103
}

src/cbmc/bmc_cover.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected]
1717
#include <util/xml.h>
1818
#include <util/xml_expr.h>
1919
#include <util/json.h>
20+
#include <util/json_stream.h>
2021
#include <util/json_expr.h>
2122

2223
#include <solvers/prop/cover_goals.h>
@@ -346,19 +347,19 @@ bool bmc_covert::operator()()
346347

347348
case ui_message_handlert::uit::JSON_UI:
348349
{
349-
json_objectt json_result;
350-
json_arrayt &goals_array=json_result["goals"].make_array();
350+
json_stream_objectt &json_result =
351+
status().json_stream().push_back_stream_object();
351352
for(const auto &goal_pair : goal_map)
352353
{
353354
const goalt &goal=goal_pair.second;
354355

355-
json_objectt &result=goals_array.push_back().make_object();
356-
result["status"]=json_stringt(goal.satisfied?"satisfied":"failed");
357-
result["goal"]=json_stringt(id2string(goal_pair.first));
358-
result["description"]=json_stringt(goal.description);
356+
json_result["status"] =
357+
json_stringt(goal.satisfied ? "satisfied" : "failed");
358+
json_result["goal"] = json_stringt(id2string(goal_pair.first));
359+
json_result["description"] = json_stringt(goal.description);
359360

360361
if(goal.source_location.is_not_nil())
361-
result["sourceLocation"]=json(goal.source_location);
362+
json_result["sourceLocation"] = json(goal.source_location);
362363
}
363364
json_result["totalGoals"]=json_numbert(std::to_string(goal_map.size()));
364365
json_result["goalsCovered"]=json_numbert(std::to_string(goals_covered));
@@ -369,12 +370,12 @@ bool bmc_covert::operator()()
369370
json_objectt &result=tests_array.push_back().make_object();
370371
if(bmc.options.get_bool_option("trace"))
371372
{
372-
jsont &json_trace=result["trace"];
373+
json_arrayt &json_trace = json_result["trace"].make_array();
373374
convert(bmc.ns, test.goto_trace, json_trace, bmc.trace_options());
374375
}
375376
else
376377
{
377-
json_arrayt &json_test=result["inputs"].make_array();
378+
json_arrayt &json_test = json_result["inputs"].make_array();
378379

379380
for(const auto &step : test.goto_trace.steps)
380381
{
@@ -396,7 +397,6 @@ bool bmc_covert::operator()()
396397
}
397398
}
398399

399-
result() << json_result;
400400
break;
401401
}
402402
}

src/goto-programs/interpreter.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Author: Daniel Kroening, [email protected]
2929
#include <json/json_parser.h>
3030

3131
#include "interpreter_class.h"
32+
#include "json_goto_trace.h"
3233
#include "remove_returns.h"
3334

3435
const std::size_t interpretert::npos=std::numeric_limits<size_t>::max();
@@ -151,8 +152,8 @@ void interpretert::command()
151152
}
152153
else if(ch=='j')
153154
{
154-
jsont json_steps;
155-
convert(ns, steps, json_steps);
155+
json_arrayt json_steps;
156+
convert<json_arrayt>(ns, steps, json_steps);
156157
ch=tolower(command[1]);
157158
if(ch==' ')
158159
{

0 commit comments

Comments
 (0)