Skip to content

Commit 2518473

Browse files
tautschnigpeterschrammel
authored andcommitted
Restrict get_json_stream to ui_message_handler
... now that we properly pass around ui_message_handlert we can clean up the JSON stream handling as well.
1 parent 49920a4 commit 2518473

File tree

7 files changed

+16
-28
lines changed

7 files changed

+16
-28
lines changed

src/cbmc/all_properties.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,10 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
202202

203203
case ui_message_handlert::uit::JSON_UI:
204204
{
205+
if(result().tellp() > 0)
206+
result() << eom; // force end of previous message
205207
json_stream_objectt &json_result =
206-
result().json_stream().push_back_stream_object();
208+
bmc.ui_message_handler.get_json_stream().push_back_stream_object();
207209
json_stream_arrayt &result_array =
208210
json_result.push_back_stream_array("result");
209211

src/cbmc/bmc.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ void bmct::error_trace()
7272

7373
case ui_message_handlert::uit::JSON_UI:
7474
{
75+
if(status().tellp() > 0)
76+
status() << eom; // force end of previous message
7577
json_stream_objectt &json_result =
76-
status().json_stream().push_back_stream_object();
78+
ui_message_handler.get_json_stream().push_back_stream_object();
7779
const goto_trace_stept &step=goto_trace.steps.back();
7880
json_result["property"] =
7981
json_stringt(step.pc->source_location.get_property_id());

src/cbmc/bmc_cover.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ bool bmc_covert::operator()()
341341

342342
case ui_message_handlert::uit::JSON_UI:
343343
{
344+
if(status().tellp() > 0)
345+
status() << eom; // force end of previous message
344346
json_stream_objectt &json_result =
345-
status().json_stream().push_back_stream_object();
347+
bmc.ui_message_handler.get_json_stream().push_back_stream_object();
346348
for(const auto &goal_pair : goal_map)
347349
{
348350
const goalt &goal=goal_pair.second;

src/goto-programs/class_hierarchy.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ void show_class_hierarchy(
273273
msg.result() << messaget::eom;
274274
break;
275275
case ui_message_handlert::uit::JSON_UI:
276-
hierarchy.output(msg.result().json_stream(), children_only);
276+
if(msg.result().tellp() > 0)
277+
msg.result() << messaget::eom; // force end of previous message
278+
hierarchy.output(message_handler.get_json_stream(), children_only);
277279
break;
278280
case ui_message_handlert::uit::XML_UI:
279281
UNIMPLEMENTED;

src/util/message.h

+1-16
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ Author: Daniel Kroening, [email protected]
1818
#include "invariant.h"
1919
#include "json.h"
2020
#include "source_location.h"
21-
#include "xml.h"
2221

23-
class json_stream_arrayt;
22+
class xmlt;
2423

2524
class message_handlert
2625
{
@@ -36,12 +35,6 @@ class message_handlert
3635
// no-op by default
3736
}
3837

39-
/// Return the underlying JSON stream
40-
virtual json_stream_arrayt &get_json_stream()
41-
{
42-
UNREACHABLE;
43-
}
44-
4538
virtual void print(unsigned level, const jsont &json)
4639
{
4740
// no-op by default
@@ -246,14 +239,6 @@ class messaget
246239
return func(*this);
247240
}
248241

249-
/// Returns a reference to the top-level JSON array stream
250-
json_stream_arrayt &json_stream()
251-
{
252-
if(this->tellp() > 0)
253-
*this << eom; // force end of previous message
254-
return message.message_handler->get_json_stream();
255-
}
256-
257242
private:
258243
void assign_from(const mstreamt &other)
259244
{

src/util/ui_message.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,8 @@ ui_message_handlert::ui_message_handlert(
6161

6262
case uit::JSON_UI:
6363
{
64-
if(!json_stream)
65-
{
66-
json_stream =
67-
std::unique_ptr<json_stream_arrayt>(new json_stream_arrayt(out));
68-
}
69-
70-
INVARIANT(json_stream, "JSON stream must be initialized before use");
64+
json_stream =
65+
std::unique_ptr<json_stream_arrayt>(new json_stream_arrayt(out));
7166
json_stream->push_back().make_object()["program"] = json_stringt(program);
7267
}
7368
break;

src/util/ui_message.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ui_message_handlert : public message_handlert
4141

4242
virtual void flush(unsigned level) override;
4343

44-
json_stream_arrayt &get_json_stream() override
44+
json_stream_arrayt &get_json_stream()
4545
{
4646
PRECONDITION(json_stream!=nullptr);
4747
return *json_stream;

0 commit comments

Comments
 (0)