Skip to content

Commit 9e90719

Browse files
committed
Make ui_message_handlert parameterizable in the underlying message handler
1 parent 94faf89 commit 9e90719

11 files changed

+60
-39
lines changed

src/goto-cc/armcc_mode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Author: CM Wintersteiger, 2006
2121

2222
#include <iostream>
2323

24-
#include <util/message.h>
2524
#include <util/prefix.h>
2625
#include <util/config.h>
2726

@@ -36,7 +35,8 @@ int armcc_modet::doit()
3635
return EX_OK;
3736
}
3837

39-
compilet compiler(cmdline, message_handler, cmdline.isset("diag_error="));
38+
ui_message_handlert ui_message(message_handler);
39+
compilet compiler(cmdline, ui_message, cmdline.isset("diag_error="));
4040

4141
#if 0
4242
bool act_as_ld=

src/goto-cc/as_mode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Author: Michael Tautschnig
2424
#include <cstring>
2525

2626
#include <util/config.h>
27-
#include <util/cout_message.h>
2827
#include <util/get_base_name.h>
2928
#include <util/run.h>
3029
#include <util/tempdir.h>
@@ -122,7 +121,8 @@ int as_modet::doit()
122121
config.set(cmdline);
123122

124123
// determine actions to be undertaken
125-
compilet compiler(cmdline, message_handler, cmdline.isset("fatal-warnings"));
124+
ui_message_handlert ui_message(message_handler);
125+
compilet compiler(cmdline, ui_message, cmdline.isset("fatal-warnings"));
126126

127127
if(cmdline.isset('b')) // as86 only
128128
{

src/goto-cc/cw_mode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Author: CM Wintersteiger, 2006
2121

2222
#include <iostream>
2323

24-
#include <util/message.h>
2524
#include <util/prefix.h>
2625
#include <util/config.h>
2726

@@ -36,7 +35,8 @@ int cw_modet::doit()
3635
return EX_OK;
3736
}
3837

39-
compilet compiler(cmdline, message_handler, cmdline.isset("Werror"));
38+
ui_message_handlert ui_message(message_handler);
39+
compilet compiler(cmdline, ui_message, cmdline.isset("Werror"));
4040

4141
#if 0
4242
bool act_as_ld=

src/goto-cc/gcc_mode.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ int gcc_modet::doit()
361361
}
362362
}
363363

364+
ui_message_handlert ui_message(gcc_message_handler);
364365
compilet compiler(cmdline,
365-
gcc_message_handler,
366+
ui_message,
366367
cmdline.isset("Werror") &&
367368
cmdline.isset("Wextra") &&
368369
!cmdline.isset("Wno-error"));

src/goto-cc/ld_mode.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ int ld_modet::doit()
9191
eval_verbosity(
9292
cmdline.get_value("verbosity"), messaget::M_ERROR, gcc_message_handler);
9393

94-
compilet compiler(cmdline, gcc_message_handler, false);
94+
ui_message_handlert ui_message(gcc_message_handler);
95+
compilet compiler(cmdline, ui_message, false);
9596

9697
// determine actions to be undertaken
9798
compiler.mode = compilet::LINK_LIBRARY;

src/goto-cc/ms_cl_mode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Author: CM Wintersteiger, 2006
2424
#include <util/config.h>
2525
#include <util/file_util.h>
2626
#include <util/get_base_name.h>
27-
#include <util/message.h>
2827
#include <util/prefix.h>
2928

3029
#include "compile.h"
@@ -49,7 +48,8 @@ int ms_cl_modet::doit()
4948
return EX_OK;
5049
}
5150

52-
compilet compiler(cmdline, message_handler, cmdline.isset("WX"));
51+
ui_message_handlert ui_message(message_handler);
52+
compilet compiler(cmdline, ui_message, cmdline.isset("WX"));
5353

5454
#if 0
5555
bool act_as_ld=

src/goto-cc/ms_link_mode.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ int ms_link_modet::doit()
3333
eval_verbosity(
3434
cmdline.get_value("verbosity"), messaget::M_ERROR, message_handler);
3535

36-
compilet compiler(cmdline, message_handler, false);
36+
ui_message_handlert ui_message(message_handler);
37+
compilet compiler(cmdline, ui_message, false);
3738

3839
// determine actions to be undertaken
3940
compiler.mode = compilet::LINK_LIBRARY;

src/util/cout_message.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Author: Daniel Kroening, [email protected]
1010
#ifndef CPROVER_UTIL_COUT_MESSAGE_H
1111
#define CPROVER_UTIL_COUT_MESSAGE_H
1212

13-
#include "ui_message.h"
13+
#include "message.h"
1414

1515
class cout_message_handlert:public stream_message_handlert
1616
{
@@ -26,7 +26,7 @@ class cerr_message_handlert:public stream_message_handlert
2626
cerr_message_handlert();
2727
};
2828

29-
class console_message_handlert:public ui_message_handlert
29+
class console_message_handlert : public message_handlert
3030
{
3131
public:
3232
// level 4 and upwards go to cout, level 1-3 to cerr
@@ -49,7 +49,7 @@ class console_message_handlert:public ui_message_handlert
4949
const bool always_flush;
5050
};
5151

52-
class gcc_message_handlert:public ui_message_handlert
52+
class gcc_message_handlert : public message_handlert
5353
{
5454
public:
5555
// aims to imitate the messages gcc prints

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)