CBMC
message.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 
10 #include "message.h"
11 
12 #include "json.h"
13 #include "string2int.h"
14 #include "structured_data.h"
15 
17  unsigned level,
18  const std::string &message,
19  const source_locationt &location)
20 {
21  std::string dest;
22 
23  const irep_idt &file=location.get_file();
24  const irep_idt &line=location.get_line();
25  const irep_idt &column=location.get_column();
26  const irep_idt &function=location.get_function();
27 
28  if(!file.empty())
29  {
30  if(!dest.empty())
31  dest+=' ';
32  dest+="file "+id2string(file);
33  }
34  if(!line.empty())
35  {
36  if(!dest.empty())
37  dest+=' ';
38  dest+="line "+id2string(line);
39  }
40  if(!column.empty())
41  {
42  if(!dest.empty())
43  dest+=' ';
44  dest+="column "+id2string(column);
45  }
46  if(!function.empty())
47  {
48  if(!dest.empty())
49  dest+=' ';
50  dest+="function "+id2string(function);
51  }
52 
53  if(!dest.empty())
54  dest+=": ";
55  dest+=message;
56 
57  print(level, dest);
58 }
59 
61  unsigned level,
62  const std::string &)
63 {
64  if(level>=message_count.size())
65  message_count.resize(level+1, 0);
66  ++message_count[level];
67 }
68 void message_handlert::print(unsigned level, const structured_datat &data)
69 {
70  // default to just printing out the data in a format
71  print(level, to_pretty(data));
72 }
73 
75 {
76 }
77 
78 // Visual studio requires this (empty) static object
80 
98 
106  const std::string &user_input,
107  const message_levelt default_verbosity,
108  message_handlert &dest)
109 {
110  unsigned v = default_verbosity;
111 
112  if(!user_input.empty())
113  {
114  v = unsafe_string2unsigned(user_input);
115 
116  if(v > messaget::M_DEBUG)
117  {
118  dest.print(
120  "verbosity value " + user_input + " out of range, using debug-level (" +
121  std::to_string(messaget::M_DEBUG) + ") verbosity",
122  source_locationt());
123 
124  v = messaget::M_DEBUG;
125  }
126  }
127 
128  dest.set_verbosity(v);
129 
130  return v;
131 }
132 
140  mstreamt &message_stream,
141  const std::function<void(mstreamt &)> &output_generator) const
142 {
143  if(
144  message_handler &&
145  message_handler->get_verbosity() >= message_stream.message_level)
146  {
147  output_generator(mstream);
148  }
149 }
150 
152 {
153  if(this->tellp() > 0)
154  *this << eom; // force end of previous message
156  {
158  }
159  return *this;
160 }
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
bool empty() const
Definition: dstring.h:89
void set_verbosity(unsigned _verbosity)
Definition: message.h:53
virtual void print(unsigned level, const std::string &message)=0
Definition: message.cpp:60
std::vector< std::size_t > message_count
Definition: message.h:73
unsigned get_verbosity() const
Definition: message.h:54
messaget & message
Definition: message.h:246
unsigned message_level
Definition: message.h:245
mstreamt & operator<<(const xmlt &data)
Definition: message.h:249
static const commandt yellow
render text with yellow foreground color
Definition: message.h:352
static const commandt bright_magenta
render text with bright magenta foreground color
Definition: message.h:376
static unsigned eval_verbosity(const std::string &user_input, const message_levelt default_verbosity, message_handlert &dest)
Parse a (user-)provided string as a verbosity level and set it as the verbosity of dest.
Definition: message.cpp:105
message_handlert * message_handler
Definition: message.h:439
static const commandt magenta
render text with magenta foreground color
Definition: message.h:358
static const commandt reset
return to default formatting, as defined by the terminal
Definition: message.h:343
static const commandt green
render text with green foreground color
Definition: message.h:349
static const commandt faint
render text with faint font
Definition: message.h:385
static const commandt bold
render text with bold font
Definition: message.h:382
static const commandt bright_red
render text with bright red foreground color
Definition: message.h:364
static const commandt underline
render underlined text
Definition: message.h:391
void conditional_output(mstreamt &mstream, const std::function< void(mstreamt &)> &output_generator) const
Generate output to message_stream using output_generator if the configured verbosity is at least as h...
Definition: message.cpp:139
static const commandt bright_cyan
render text with bright cyan foreground color
Definition: message.h:379
static const commandt bright_yellow
render text with bright yellow foreground color
Definition: message.h:370
virtual ~messaget()
Definition: message.cpp:74
message_levelt
Definition: message.h:169
@ M_DEBUG
Definition: message.h:171
@ M_WARNING
Definition: message.h:170
static const commandt bright_blue
render text with bright blue foreground color
Definition: message.h:373
static const commandt italic
render italic text
Definition: message.h:388
static const commandt red
render text with red foreground color
Definition: message.h:346
mstreamt mstream
Definition: message.h:440
static eomt eom
Definition: message.h:297
static const commandt cyan
render text with cyan foreground color
Definition: message.h:361
static const commandt bright_green
render text with bright green foreground color
Definition: message.h:367
static const commandt blue
render text with blue foreground color
Definition: message.h:355
const irep_idt & get_function() const
const irep_idt & get_column() const
const irep_idt & get_line() const
const irep_idt & get_file() const
A way of representing nested key/value data.
const std::string & id2string(const irep_idt &d)
Definition: irep.h:40
unsigned unsafe_string2unsigned(const std::string &str, int base)
Definition: string2int.cpp:35
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
std::string to_pretty(const structured_datat &data)
Convert the structured_data into plain text.