Skip to content

Commit 0c8b108

Browse files
Make ui_message_handlert parameterizable in the underlying message handler
1 parent 2518473 commit 0c8b108

File tree

3 files changed

+43
-25
lines changed

3 files changed

+43
-25
lines changed

src/util/ui_message.cpp

+32-16
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,14 @@ Author: Daniel Kroening, [email protected]
1919
#include "cout_message.h"
2020
#include "cmdline.h"
2121

22-
ui_message_handlert::ui_message_handlert()
23-
: _ui(uit::PLAIN),
24-
always_flush(false),
25-
time(timestampert::make(timestampert::clockt::NONE)),
26-
out(std::cout),
27-
json_stream(nullptr)
28-
{
29-
}
30-
3122
ui_message_handlert::ui_message_handlert(
23+
message_handlert *message_handler,
3224
uit __ui,
3325
const std::string &program,
3426
bool always_flush,
3527
timestampert::clockt clock_type)
36-
: _ui(__ui),
28+
: message_handler(message_handler),
29+
_ui(__ui),
3730
always_flush(always_flush),
3831
time(timestampert::make(clock_type)),
3932
out(std::cout),
@@ -73,6 +66,7 @@ ui_message_handlert::ui_message_handlert(
7366
const class cmdlinet &cmdline,
7467
const std::string &program)
7568
: ui_message_handlert(
69+
nullptr,
7670
cmdline.isset("xml-ui") ? uit::XML_UI : cmdline.isset("json-ui")
7771
? uit::JSON_UI
7872
: uit::PLAIN,
@@ -88,6 +82,12 @@ ui_message_handlert::ui_message_handlert(
8882
{
8983
}
9084

85+
ui_message_handlert::ui_message_handlert(message_handlert &message_handler)
86+
: ui_message_handlert(
87+
&message_handler, uit::PLAIN, "", false, timestampert::clockt::NONE)
88+
{
89+
}
90+
9191
ui_message_handlert::~ui_message_handlert()
9292
{
9393
switch(get_ui())
@@ -129,13 +129,22 @@ void ui_message_handlert::print(
129129
{
130130
case uit::PLAIN:
131131
{
132-
console_message_handlert console_message_handler(always_flush);
133132
std::stringstream ss;
134133
const std::string timestamp = time->stamp();
135134
ss << timestamp << (timestamp.empty() ? "" : " ") << message;
136-
console_message_handler.print(level, ss.str());
137-
if(always_flush)
138-
console_message_handler.flush(level);
135+
if(message_handler)
136+
{
137+
message_handler->print(level, ss.str());
138+
if(always_flush)
139+
message_handler->flush(level);
140+
}
141+
else
142+
{
143+
console_message_handlert msg(always_flush);
144+
msg.print(level, ss.str());
145+
if(always_flush)
146+
msg.flush(level);
147+
}
139148
}
140149
break;
141150

@@ -298,8 +307,15 @@ void ui_message_handlert::flush(unsigned level)
298307
{
299308
case uit::PLAIN:
300309
{
301-
console_message_handlert console_message_handler(always_flush);
302-
console_message_handler.flush(level);
310+
if(message_handler)
311+
{
312+
message_handler->flush(level);
313+
}
314+
else
315+
{
316+
console_message_handlert msg(always_flush);
317+
msg.flush(level);
318+
}
303319
}
304320
break;
305321

src/util/ui_message.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,9 @@ class ui_message_handlert : public message_handlert
2121
public:
2222
enum class uit { PLAIN, XML_UI, JSON_UI };
2323

24-
ui_message_handlert(
25-
uit,
26-
const std::string &program,
27-
const bool always_flush,
28-
timestampert::clockt clock_type);
29-
3024
ui_message_handlert(const class cmdlinet &, const std::string &program);
3125

32-
/// Default constructor; implementation is in .cpp file
33-
ui_message_handlert();
26+
explicit ui_message_handlert(message_handlert &);
3427

3528
virtual ~ui_message_handlert();
3629

@@ -48,12 +41,20 @@ class ui_message_handlert : public message_handlert
4841
}
4942

5043
protected:
44+
message_handlert *message_handler;
5145
uit _ui;
5246
const bool always_flush;
5347
std::unique_ptr<const timestampert> time;
5448
std::ostream &out;
5549
std::unique_ptr<json_stream_arrayt> json_stream;
5650

51+
ui_message_handlert(
52+
message_handlert *,
53+
uit,
54+
const std::string &program,
55+
const bool always_flush,
56+
timestampert::clockt clock_type);
57+
5758
virtual void print(
5859
unsigned level,
5960
const std::string &message) override;

unit/analyses/ai/ai_simplify_lhs.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/// Unit tests for ai_domain_baset::ai_simplify_lhs
1111

1212
#include <testing-utils/catch.hpp>
13+
#include <testing-utils/message.h>
1314

1415
#include <analyses/ai.h>
1516

@@ -64,7 +65,7 @@ bool constant_simplification_mockt::ai_simplify(
6465
SCENARIO("ai_domain_baset::ai_simplify_lhs",
6566
"[core][analyses][ai][ai_simplify_lhs]")
6667
{
67-
ui_message_handlert message_handler;
68+
ui_message_handlert message_handler(null_message_handler);
6869
ansi_c_languaget language;
6970
language.set_message_handler(message_handler);
7071

0 commit comments

Comments
 (0)