cprover
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 "string2int.h"
13 
15  unsigned level,
16  const std::string &message,
17  const source_locationt &location)
18 {
19  std::string dest;
20 
21  const irep_idt &file=location.get_file();
22  const irep_idt &line=location.get_line();
23  const irep_idt &column=location.get_column();
24  const irep_idt &function=location.get_function();
25 
26  if(!file.empty())
27  {
28  if(dest!="")
29  dest+=' ';
30  dest+="file "+id2string(file);
31  }
32  if(!line.empty())
33  {
34  if(dest!="")
35  dest+=' ';
36  dest+="line "+id2string(line);
37  }
38  if(!column.empty())
39  {
40  if(dest!="")
41  dest+=' ';
42  dest+="column "+id2string(column);
43  }
44  if(!function.empty())
45  {
46  if(dest!="")
47  dest+=' ';
48  dest+="function "+id2string(function);
49  }
50 
51  if(dest!="")
52  dest+=": ";
53  dest+=message;
54 
55  print(level, dest);
56 }
57 
59  unsigned level,
60  const std::string &)
61 {
62  if(level>=message_count.size())
63  message_count.resize(level+1, 0);
64  ++message_count[level];
65 }
66 
68 {
69 }
70 
71 // Visual studio requires this (empty) static object
73 
91 
99  const std::string &user_input,
100  const message_levelt default_verbosity,
101  message_handlert &dest)
102 {
103  unsigned v = default_verbosity;
104 
105  if(!user_input.empty())
106  {
107  v = unsafe_string2unsigned(user_input);
108 
109  if(v > messaget::M_DEBUG)
110  {
111  dest.print(
113  "verbosity value " + user_input + " out of range, using debug-level (" +
114  std::to_string(messaget::M_DEBUG) + ") verbosity",
115  source_locationt());
116 
117  v = messaget::M_DEBUG;
118  }
119  }
120 
121  dest.set_verbosity(v);
122 
123  return v;
124 }
125 
133  mstreamt &message_stream,
134  const std::function<void(mstreamt &)> &output_generator) const
135 {
136  if(
137  message_handler &&
138  message_handler->get_verbosity() >= message_stream.message_level)
139  {
140  output_generator(mstream);
141  }
142 }
static const commandt bright_magenta
render text with bright magenta foreground color
Definition: message.h:363
static const commandt bright_yellow
render text with bright yellow foreground color
Definition: message.h:357
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
static const commandt bold
render text with bold font
Definition: message.h:369
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
virtual ~messaget()
Definition: message.cpp:67
static const commandt blue
render text with blue foreground color
Definition: message.h:342
unsigned unsafe_string2unsigned(const std::string &str, int base)
Definition: string2int.cpp:69
const irep_idt & get_function() const
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:98
static const commandt bright_red
render text with bright red foreground color
Definition: message.h:351
static const commandt bright_blue
render text with bright blue foreground color
Definition: message.h:360
static const commandt reset
return to default formatting, as defined by the terminal
Definition: message.h:330
const irep_idt & get_column() const
unsigned get_verbosity() const
Definition: message.h:49
static const commandt underline
render underlined text
Definition: message.h:378
static const commandt magenta
render text with magenta foreground color
Definition: message.h:345
const irep_idt & get_line() const
static const commandt red
render text with red foreground color
Definition: message.h:333
message_levelt
Definition: message.h:158
static const commandt bright_cyan
render text with bright cyan foreground color
Definition: message.h:366
static const commandt bright_green
render text with bright green foreground color
Definition: message.h:354
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:35
static const commandt faint
render text with faint font
Definition: message.h:372
static eomt eom
Definition: message.h:284
const irep_idt & get_file() const
std::vector< std::size_t > message_count
Definition: message.h:68
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:132
void set_verbosity(unsigned _verbosity)
Definition: message.h:48
static const commandt green
render text with green foreground color
Definition: message.h:336
mstreamt mstream
Definition: message.h:427
static const commandt cyan
render text with cyan foreground color
Definition: message.h:348
message_handlert * message_handler
Definition: message.h:426
unsigned message_level
Definition: message.h:234
bool empty() const
Definition: dstring.h:75
static const commandt yellow
render text with yellow foreground color
Definition: message.h:339
static const commandt italic
render italic text
Definition: message.h:375
virtual void print(unsigned level, const std::string &message)=0
Definition: message.cpp:58
Definition: kdev_t.h:19