Skip to content

Commit 0323ed0

Browse files
Merge pull request #1349 from peterschrammel/cleanup/use-preformatted-output
Make message streams accept XML and JSON data
2 parents 6cb2f90 + e957025 commit 0323ed0

13 files changed

+175
-154
lines changed

src/analyses/natural_loops.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ Author: Georg Weissenbacher, [email protected]
1111

1212
#include "natural_loops.h"
1313

14-
#include <iostream>
15-
16-
void show_natural_loops(const goto_modelt &goto_model)
14+
void show_natural_loops(
15+
const goto_modelt &goto_model,
16+
std::ostream &out)
1717
{
1818
forall_goto_functions(it, goto_model.goto_functions)
1919
{
20-
std::cout << "*** " << it->first << '\n';
20+
out << "*** " << it->first << '\n';
2121

2222
natural_loopst natural_loops;
2323
natural_loops(it->second.body);
24-
natural_loops.output(std::cout);
24+
natural_loops.output(out);
2525

26-
std::cout << '\n';
26+
out << '\n';
2727
}
2828
}

src/analyses/natural_loops.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ class natural_loopst:
6969
typedef natural_loops_templatet<goto_programt, goto_programt::targett>
7070
natural_loops_mutablet;
7171

72-
void show_natural_loops(const goto_modelt &);
72+
void show_natural_loops(
73+
const goto_modelt &,
74+
std::ostream &out);
7375

7476
/// Finds all back-edges and computes the natural loops
7577
#ifdef DEBUG

src/cbmc/all_properties.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "all_properties_class.h"
1313

14-
#include <iostream>
15-
1614
#include <util/time_stopping.h>
1715
#include <util/xml.h>
1816
#include <util/json.h>
@@ -163,10 +161,10 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
163161
{
164162
case ui_message_handlert::uit::PLAIN:
165163
{
166-
status() << "\n** Results:" << eom;
164+
result() << "\n** Results:" << eom;
167165

168166
for(const auto &goal_pair : goal_map)
169-
status() << "[" << goal_pair.first << "] "
167+
result() << "[" << goal_pair.first << "] "
170168
<< goal_pair.second.description << ": "
171169
<< goal_pair.second.status_string()
172170
<< eom;
@@ -176,10 +174,11 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
176174
for(const auto &g : goal_map)
177175
if(g.second.status==goalt::statust::FAILURE)
178176
{
179-
std::cout << "\n" << "Trace for " << g.first << ":" << "\n";
180-
show_goto_trace(std::cout, bmc.ns, g.second.goto_trace);
177+
result() << "\n" << "Trace for " << g.first << ":" << "\n";
178+
show_goto_trace(result(), bmc.ns, g.second.goto_trace);
181179
}
182180
}
181+
result() << eom;
183182

184183
status() << "\n** " << cover_goals.number_covered()
185184
<< " of " << cover_goals.size() << " failed ("
@@ -200,7 +199,7 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
200199
if(g.second.status==goalt::statust::FAILURE)
201200
convert(bmc.ns, g.second.goto_trace, xml_result.new_element());
202201

203-
std::cout << xml_result << "\n";
202+
result() << xml_result;
204203
}
205204
break;
206205
}
@@ -224,7 +223,7 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
224223
}
225224
}
226225

227-
std::cout << ",\n" << json_result;
226+
result() << json_result;
228227
}
229228
break;
230229
}

src/cbmc/bmc.cpp

+16-18
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,33 @@ void bmct::error_trace()
5555
switch(ui)
5656
{
5757
case ui_message_handlert::uit::PLAIN:
58-
status() << "Counterexample:" << eom;
59-
show_goto_trace(status(), ns, goto_trace);
60-
status() << eom;
58+
result() << "Counterexample:" << eom;
59+
show_goto_trace(result(), ns, goto_trace);
60+
result() << eom;
6161
break;
6262

6363
case ui_message_handlert::uit::XML_UI:
6464
{
6565
xmlt xml;
6666
convert(ns, goto_trace, xml);
67-
status() << preformatted_output << xml << eom;
67+
status() << xml;
6868
}
6969
break;
7070

7171
case ui_message_handlert::uit::JSON_UI:
7272
{
73-
json_objectt json_result;
74-
json_arrayt &result_array=json_result["results"].make_array();
75-
json_objectt &result=result_array.push_back().make_object();
73+
json_objectt json;
74+
json_arrayt &result_array=json["results"].make_array();
75+
json_objectt &json_result=result_array.push_back().make_object();
7676
const goto_trace_stept &step=goto_trace.steps.back();
77-
result["property"]=
77+
json_result["property"]=
7878
json_stringt(id2string(step.pc->source_location.get_property_id()));
79-
result["description"]=
79+
json_result["description"]=
8080
json_stringt(id2string(step.pc->source_location.get_comment()));
81-
result["status"]=json_stringt("failed");
82-
jsont &json_trace=result["trace"];
81+
json_result["status"]=json_stringt("failed");
82+
jsont &json_trace=json_result["trace"];
8383
convert(ns, goto_trace, json_trace);
84-
status() << preformatted_output << json_result << eom;
84+
status() << json_result;
8585
}
8686
break;
8787
}
@@ -173,16 +173,15 @@ void bmct::report_success()
173173
{
174174
xmlt xml("cprover-status");
175175
xml.data="SUCCESS";
176-
std::cout << xml;
177-
std::cout << "\n";
176+
result() << xml;
178177
}
179178
break;
180179

181180
case ui_message_handlert::uit::JSON_UI:
182181
{
183182
json_objectt json_result;
184183
json_result["cProverStatus"]=json_stringt("success");
185-
std::cout << ",\n" << json_result;
184+
result() << json_result;
186185
}
187186
break;
188187
}
@@ -201,16 +200,15 @@ void bmct::report_failure()
201200
{
202201
xmlt xml("cprover-status");
203202
xml.data="FAILURE";
204-
std::cout << xml;
205-
std::cout << "\n";
203+
result() << xml;
206204
}
207205
break;
208206

209207
case ui_message_handlert::uit::JSON_UI:
210208
{
211209
json_objectt json_result;
212210
json_result["cProverStatus"]=json_stringt("failure");
213-
std::cout << ",\n" << json_result;
211+
result() << json_result;
214212
}
215213
break;
216214
}

src/cbmc/bmc_cover.cpp

+15-21
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "bmc.h"
1313

14-
#include <iostream>
15-
1614
#include <util/time_stopping.h>
1715
#include <util/xml.h>
1816
#include <util/xml_expr.h>
@@ -185,10 +183,6 @@ void bmc_covert::satisfying_assignment()
185183
goto_trace.steps.erase(++s_it1, goto_trace.steps.end());
186184
break;
187185
}
188-
189-
#if 0
190-
show_goto_trace(std::cout, bmc.ns, test.goto_trace);
191-
#endif
192186
}
193187

194188
bool bmc_covert::operator()()
@@ -221,8 +215,6 @@ bool bmc_covert::operator()()
221215

222216
bmc.do_conversion();
223217

224-
// bmc.equation.output(std::cout);
225-
226218
// get the conditions for these goals from formula
227219
// collect all 'instances' of the goals
228220
for(auto it = bmc.equation.SSA_steps.begin();
@@ -278,26 +270,25 @@ bool bmc_covert::operator()()
278270
{
279271
case ui_message_handlert::uit::PLAIN:
280272
{
281-
status() << "\n** coverage results:" << eom;
273+
result() << "\n** coverage results:" << eom;
282274

283275
for(const auto &g : goal_map)
284276
{
285277
const goalt &goal=g.second;
286278

287-
status() << "[" << g.first << "]";
279+
result() << "[" << g.first << "]";
288280

289281
if(goal.source_location.is_not_nil())
290-
status() << ' ' << goal.source_location;
282+
result() << ' ' << goal.source_location;
291283

292284
if(!goal.description.empty())
293-
status() << ' ' << goal.description;
285+
result() << ' ' << goal.description;
294286

295-
status() << ": " << (goal.satisfied?"SATISFIED":"FAILED")
296-
<< eom;
287+
result() << ": " << (goal.satisfied?"SATISFIED":"FAILED")
288+
<< '\n';
297289
}
298290

299-
status() << '\n';
300-
291+
result() << eom;
301292
break;
302293
}
303294

@@ -315,7 +306,7 @@ bool bmc_covert::operator()()
315306
if(goal.source_location.is_not_nil())
316307
xml_result.new_element()=xml(goal.source_location);
317308

318-
std::cout << xml_result << "\n";
309+
result() << xml_result;
319310
}
320311

321312
for(const auto &test : tests)
@@ -348,7 +339,7 @@ bool bmc_covert::operator()()
348339
xml_goal.set_attribute("id", id2string(goal_id));
349340
}
350341

351-
std::cout << xml_result << "\n";
342+
result() << xml_result;
352343
}
353344
break;
354345
}
@@ -404,7 +395,8 @@ bool bmc_covert::operator()()
404395
goal_refs.push_back(json_stringt(id2string(goal_id)));
405396
}
406397
}
407-
std::cout << ",\n" << json_result;
398+
399+
result() << json_result;
408400
break;
409401
}
410402
}
@@ -422,10 +414,12 @@ bool bmc_covert::operator()()
422414

423415
if(bmc.ui==ui_message_handlert::uit::PLAIN)
424416
{
425-
std::cout << "Test suite:" << '\n';
417+
result() << "Test suite:" << '\n';
426418

427419
for(const auto &test : tests)
428-
std::cout << get_test(test.goto_trace) << '\n';
420+
result() << get_test(test.goto_trace) << '\n';
421+
422+
result() << eom;
429423
}
430424

431425
return false;

src/cbmc/fault_localization.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ safety_checkert::resultt fault_localizationt::stop_on_fail()
301301
xmlt dest("fault-localization");
302302
xmlt xml_diagnosis=report_xml(ID_nil);
303303
dest.new_element().swap(xml_diagnosis);
304-
status() << preformatted_output << dest << eom;
304+
status() << dest;
305305
break;
306306
}
307307
case ui_message_handlert::uit::JSON_UI:
@@ -379,7 +379,7 @@ void fault_localizationt::report(
379379
xmlt xml_diagnosis=report_xml(goal_pair.first);
380380
dest.new_element().swap(xml_diagnosis);
381381
}
382-
status() << preformatted_output << dest << eom;
382+
status() << dest;
383383
}
384384
break;
385385
case ui_message_handlert::uit::JSON_UI:

src/goto-instrument/goto_instrument_parse_options.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ int goto_instrument_parse_optionst::doit()
554554

555555
if(cmdline.isset("show-natural-loops"))
556556
{
557-
show_natural_loops(goto_model);
557+
show_natural_loops(goto_model, std::cout);
558558
return 0;
559559
}
560560

src/util/cout_message.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ cerr_message_handlert::cerr_message_handlert():
3131

3232
void console_message_handlert::print(
3333
unsigned level,
34-
const std::string &message,
35-
bool preformatted)
34+
const std::string &message)
3635
{
37-
message_handlert::print(level, message, preformatted);
36+
message_handlert::print(level, message);
3837

3938
if(verbosity<level)
4039
return;
@@ -102,8 +101,7 @@ void gcc_message_handlert::print(
102101
unsigned level,
103102
const std::string &message,
104103
int sequence_number,
105-
const source_locationt &location,
106-
bool preformatted)
104+
const source_locationt &location)
107105
{
108106
const irep_idt file=location.get_file();
109107
const irep_idt line=location.get_line();
@@ -141,15 +139,14 @@ void gcc_message_handlert::print(
141139

142140
dest+=message;
143141

144-
print(level, dest, preformatted);
142+
print(level, dest);
145143
}
146144

147145
void gcc_message_handlert::print(
148146
unsigned level,
149-
const std::string &message,
150-
bool preformatted)
147+
const std::string &message)
151148
{
152-
message_handlert::print(level, message, preformatted);
149+
message_handlert::print(level, message);
153150

154151
// gcc appears to send everything to cerr
155152
if(verbosity>=level)

src/util/cout_message.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class console_message_handlert:public ui_message_handlert
3232
// level 4 and upwards go to cout, level 1-3 to cerr
3333
virtual void print(
3434
unsigned level,
35-
const std::string &message,
36-
bool preformatted) override;
35+
const std::string &message) override;
3736

3837
virtual void flush(unsigned level) override;
3938
};
@@ -44,15 +43,13 @@ class gcc_message_handlert:public ui_message_handlert
4443
// aims to imitate the messages gcc prints
4544
virtual void print(
4645
unsigned level,
47-
const std::string &message,
48-
bool preformatted) override;
46+
const std::string &message) override;
4947

5048
virtual void print(
5149
unsigned level,
5250
const std::string &message,
5351
int sequence_number,
54-
const source_locationt &location,
55-
bool preformatted) override;
52+
const source_locationt &location) override;
5653
};
5754

5855
#endif // CPROVER_UTIL_COUT_MESSAGE_H

0 commit comments

Comments
 (0)