Skip to content

Commit da5d4d1

Browse files
author
Daniel Kroening
authored
Merge pull request #3166 from diffblue/mstream-manipulators
mstreamt manipulators are now static
2 parents fe7e385 + 90b04e3 commit da5d4d1

File tree

5 files changed

+67
-53
lines changed

5 files changed

+67
-53
lines changed

src/cbmc/all_properties.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ void bmc_all_propertiest::report(const cover_goalst &cover_goals)
164164
<< goal_pair.second.description << ": ";
165165

166166
if(goal_pair.second.status == goalt::statust::SUCCESS)
167-
result() << green();
167+
result() << green;
168168
else
169-
result() << red();
169+
result() << red;
170170

171-
result() << goal_pair.second.status_string() << reset() << eom;
171+
result() << goal_pair.second.status_string() << reset << eom;
172172
}
173173

174174
if(bmc.options.get_bool_option("trace"))

src/cbmc/bmc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ bmct::run_decision_procedure(prop_convt &prop_conv)
153153

154154
void bmct::report_success()
155155
{
156-
result() << bold() << "VERIFICATION SUCCESSFUL" << reset() << eom;
156+
result() << bold << "VERIFICATION SUCCESSFUL" << reset << eom;
157157

158158
switch(ui_message_handler.get_ui())
159159
{
@@ -180,7 +180,7 @@ void bmct::report_success()
180180

181181
void bmct::report_failure()
182182
{
183-
result() << bold() << "VERIFICATION FAILED" << reset() << eom;
183+
result() << bold << "VERIFICATION FAILED" << reset << eom;
184184

185185
switch(ui_message_handler.get_ui())
186186
{

src/goto-analyzer/static_verifier.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,22 @@ bool static_verifier(
232232

233233
if(e.is_true())
234234
{
235-
m.result() << m.green() << "Success" << m.reset();
235+
m.result() << m.green << "Success" << m.reset;
236236
pass++;
237237
}
238238
else if(e.is_false())
239239
{
240-
m.result() << m.red() << "Failure" << m.reset() << " (if reachable)";
240+
m.result() << m.red << "Failure" << m.reset << " (if reachable)";
241241
fail++;
242242
}
243243
else if(domain.is_bottom())
244244
{
245-
m.result() << m.green() << "Success" << m.reset() << " (unreachable)";
245+
m.result() << m.green << "Success" << m.reset << " (unreachable)";
246246
pass++;
247247
}
248248
else
249249
{
250-
m.result() << m.yellow() << "Unknown" << m.reset();
250+
m.result() << m.yellow << "Unknown" << m.reset;
251251
unknown++;
252252
}
253253

@@ -258,11 +258,11 @@ bool static_verifier(
258258
}
259259
}
260260

261-
m.status() << m.bold() << "Summary: "
261+
m.status() << m.bold << "Summary: "
262262
<< pass << " pass, "
263263
<< fail << " fail if reachable, "
264264
<< unknown << " unknown"
265-
<< m.reset() << messaget::eom;
265+
<< m.reset << messaget::eom;
266266

267267
return false;
268268
}

src/util/message.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ messaget::~messaget()
6868
{
6969
}
7070

71+
// Visual studio requires this (empty) static object
72+
messaget::eomt messaget::eom;
73+
74+
const messaget::commandt messaget::reset(0);
75+
const messaget::commandt messaget::bold(1);
76+
const messaget::commandt messaget::faint(2);
77+
const messaget::commandt messaget::italic(3);
78+
const messaget::commandt messaget::underline(4);
79+
const messaget::commandt messaget::red(31);
80+
const messaget::commandt messaget::green(32);
81+
const messaget::commandt messaget::yellow(33);
82+
const messaget::commandt messaget::blue(34);
83+
7184
/// Parse a (user-)provided string as a verbosity level and set it as the
7285
/// verbosity of dest.
7386
/// \param user_input Input string; if empty, the default verbosity is used.

src/util/message.h

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,6 @@ class messaget
240240
return *this;
241241
}
242242

243-
// for feeding in manipulator functions such as eom
244-
mstreamt &operator << (mstreamt &(*func)(mstreamt &))
245-
{
246-
return func(*this);
247-
}
248-
249243
private:
250244
void assign_from(const mstreamt &other)
251245
{
@@ -257,9 +251,15 @@ class messaget
257251
friend class messaget;
258252
};
259253

260-
// Feeding 'eom' into the stream triggers
261-
// the printing of the message
262-
static mstreamt &eom(mstreamt &m)
254+
// Feeding 'eom' into the stream triggers the printing of the message
255+
// This is implemented as an I/O manipulator (compare to STL's endl).
256+
class eomt
257+
{
258+
};
259+
260+
static eomt eom;
261+
262+
friend mstreamt &operator<<(mstreamt &m, eomt)
263263
{
264264
if(m.message.message_handler)
265265
{
@@ -275,58 +275,59 @@ class messaget
275275
return m;
276276
}
277277

278-
// in lieu of std::endl
279-
static mstreamt &endl(mstreamt &m)
278+
// This is an I/O manipulator (compare to STL's set_precision).
279+
class commandt
280280
{
281-
static_cast<std::ostream &>(m) << std::endl;
282-
return m;
281+
public:
282+
explicit commandt(unsigned _command) : command(_command)
283+
{
284+
}
285+
286+
unsigned command;
287+
};
288+
289+
/// feed a command into an mstreamt
290+
friend mstreamt &operator<<(mstreamt &m, const commandt &c)
291+
{
292+
if(m.message.message_handler)
293+
return m << m.message.message_handler->command(c.command);
294+
else
295+
return m;
283296
}
284297

285298
/// \brief Create an ECMA-48 SGR (Select Graphic Rendition) command.
286-
std::string command(unsigned c) const
299+
static commandt command(unsigned c)
287300
{
288-
if(message_handler)
289-
return message_handler->command(c);
290-
else
291-
return std::string();
301+
return commandt(c);
292302
}
293303

294304
/// return to default formatting,
295305
/// as defined by the terminal
296-
std::string reset() const
297-
{
298-
return command(0);
299-
}
306+
static const commandt reset;
300307

301308
/// render text with red foreground color
302-
std::string red() const
303-
{
304-
return command(31);
305-
}
309+
static const commandt red;
306310

307311
/// render text with green foreground color
308-
std::string green() const
309-
{
310-
return command(32);
311-
}
312+
static const commandt green;
312313

313314
/// render text with yellow foreground color
314-
std::string yellow() const
315-
{
316-
return command(33);
317-
}
315+
static const commandt yellow;
318316

319317
/// render text with blue foreground color
320-
std::string blue() const
321-
{
322-
return command(34);
323-
}
318+
static const commandt blue;
324319

325320
/// render text with bold font
326-
std::string bold() const
327-
{
328-
return command(1);
329-
}
321+
static const commandt bold;
322+
323+
/// render text with faint font
324+
static const commandt faint;
325+
326+
/// render italic text
327+
static const commandt italic;
328+
329+
/// render underlined text
330+
static const commandt underline;
330331

331332
mstreamt &get_mstream(unsigned message_level) const
332333
{

0 commit comments

Comments
 (0)