Skip to content

Commit 775d1bb

Browse files
committed
Activate JSON streaming when printing goto-traces
1 parent a55cd66 commit 775d1bb

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

src/cbmc/all_properties.cpp

Lines changed: 9 additions & 7 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 10 additions & 10 deletions
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>
@@ -348,19 +349,19 @@ bool bmc_covert::operator()()
348349

349350
case ui_message_handlert::uit::JSON_UI:
350351
{
351-
json_objectt json_result;
352-
json_arrayt &goals_array=json_result["goals"].make_array();
352+
json_stream_objectt &json_result =
353+
status().json_stream().push_back_stream_object();
353354
for(const auto &goal_pair : goal_map)
354355
{
355356
const goalt &goal=goal_pair.second;
356357

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

362363
if(goal.source_location.is_not_nil())
363-
result["sourceLocation"]=json(goal.source_location);
364+
json_result["sourceLocation"] = json(goal.source_location);
364365
}
365366
json_result["totalGoals"]=json_numbert(std::to_string(goal_map.size()));
366367
json_result["goalsCovered"]=json_numbert(std::to_string(goals_covered));
@@ -371,12 +372,12 @@ bool bmc_covert::operator()()
371372
json_objectt &result=tests_array.push_back().make_object();
372373
if(bmc.options.get_bool_option("trace"))
373374
{
374-
jsont &json_trace=result["trace"];
375+
json_arrayt &json_trace = json_result["trace"].make_array();
375376
convert(bmc.ns, test.goto_trace, json_trace, bmc.trace_options());
376377
}
377378
else
378379
{
379-
json_arrayt &json_test=result["inputs"].make_array();
380+
json_arrayt &json_test = json_result["inputs"].make_array();
380381

381382
for(const auto &step : test.goto_trace.steps)
382383
{
@@ -398,7 +399,6 @@ bool bmc_covert::operator()()
398399
}
399400
}
400401

401-
result() << json_result;
402402
break;
403403
}
404404
}

src/goto-programs/interpreter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Author: Daniel Kroening, [email protected]
2828
#include <json/json_parser.h>
2929

3030
#include "interpreter_class.h"
31+
#include "json_goto_trace.h"
3132
#include "remove_returns.h"
3233

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

0 commit comments

Comments
 (0)