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 "json.h"
13 #include "string2int.h"
14 
16  unsigned level,
17  const std::string &message,
18  const source_locationt &location)
19 {
20  std::string dest;
21 
22  const irep_idt &file=location.get_file();
23  const irep_idt &line=location.get_line();
24  const irep_idt &column=location.get_column();
25  const irep_idt &function=location.get_function();
26 
27  if(!file.empty())
28  {
29  if(!dest.empty())
30  dest+=' ';
31  dest+="file "+id2string(file);
32  }
33  if(!line.empty())
34  {
35  if(!dest.empty())
36  dest+=' ';
37  dest+="line "+id2string(line);
38  }
39  if(!column.empty())
40  {
41  if(!dest.empty())
42  dest+=' ';
43  dest+="column "+id2string(column);
44  }
45  if(!function.empty())
46  {
47  if(!dest.empty())
48  dest+=' ';
49  dest+="function "+id2string(function);
50  }
51 
52  if(!dest.empty())
53  dest+=": ";
54  dest+=message;
55 
56  print(level, dest);
57 }
58 
60  unsigned level,
61  const std::string &)
62 {
63  if(level>=message_count.size())
64  message_count.resize(level+1, 0);
65  ++message_count[level];
66 }
67 
69 {
70 }
71 
72 // Visual studio requires this (empty) static object
74 
92 
100  const std::string &user_input,
101  const message_levelt default_verbosity,
102  message_handlert &dest)
103 {
104  unsigned v = default_verbosity;
105 
106  if(!user_input.empty())
107  {
108  v = unsafe_string2unsigned(user_input);
109 
110  if(v > messaget::M_DEBUG)
111  {
112  dest.print(
114  "verbosity value " + user_input + " out of range, using debug-level (" +
115  std::to_string(messaget::M_DEBUG) + ") verbosity",
116  source_locationt());
117 
118  v = messaget::M_DEBUG;
119  }
120  }
121 
122  dest.set_verbosity(v);
123 
124  return v;
125 }
126 
134  mstreamt &message_stream,
135  const std::function<void(mstreamt &)> &output_generator) const
136 {
137  if(
138  message_handler &&
139  message_handler->get_verbosity() >= message_stream.message_level)
140  {
141  output_generator(mstream);
142  }
143 }
144 
146 {
147  if(this->tellp() > 0)
148  *this << eom; // force end of previous message
150  {
152  }
153  return *this;
154 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
source_locationt::get_function
const irep_idt & get_function() const
Definition: source_location.h:56
messaget::reset
static const commandt reset
return to default formatting, as defined by the terminal
Definition: message.h:329
message_handlert::get_verbosity
unsigned get_verbosity() const
Definition: message.h:51
data
Definition: kdev_t.h:24
file
Definition: kdev_t.h:19
source_locationt::get_column
const irep_idt & get_column() const
Definition: source_location.h:51
messaget::bright_red
static const commandt bright_red
render text with bright red foreground color
Definition: message.h:350
to_string
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Definition: string_constraint.cpp:55
messaget::eom
static eomt eom
Definition: message.h:283
messaget::italic
static const commandt italic
render italic text
Definition: message.h:374
source_locationt::get_line
const irep_idt & get_line() const
Definition: source_location.h:46
messaget::mstreamt::operator<<
mstreamt & operator<<(const xmlt &data)
Definition: message.h:246
message_handlert::print
virtual void print(unsigned level, const std::string &message)=0
Definition: message.cpp:59
json_objectt
Definition: json.h:298
messaget::bright_magenta
static const commandt bright_magenta
render text with bright magenta foreground color
Definition: message.h:362
message
static const char * message(const static_verifier_resultt::statust &status)
Makes a status message string from a status.
Definition: static_verifier.cpp:74
string2int.h
message.h
messaget::bright_yellow
static const commandt bright_yellow
render text with bright yellow foreground color
Definition: message.h:356
messaget::green
static const commandt green
render text with green foreground color
Definition: message.h:335
messaget::faint
static const commandt faint
render text with faint font
Definition: message.h:371
messaget::bold
static const commandt bold
render text with bold font
Definition: message.h:368
messaget::yellow
static const commandt yellow
render text with yellow foreground color
Definition: message.h:338
id2string
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
message_handlert
Definition: message.h:27
dstringt::empty
bool empty() const
Definition: dstring.h:88
messaget::eomt
Definition: message.h:280
messaget::mstreamt::message
messaget & message
Definition: message.h:243
source_locationt
Definition: source_location.h:20
message_handlert::set_verbosity
void set_verbosity(unsigned _verbosity)
Definition: message.h:50
message_handlert::message_count
std::vector< std::size_t > message_count
Definition: message.h:70
messaget::message_handler
message_handlert * message_handler
Definition: message.h:425
messaget::M_WARNING
@ M_WARNING
Definition: message.h:167
messaget::red
static const commandt red
render text with red foreground color
Definition: message.h:332
messaget::message_levelt
message_levelt
Definition: message.h:166
messaget::conditional_output
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:133
unsafe_string2unsigned
unsigned unsafe_string2unsigned(const std::string &str, int base)
Definition: string2int.cpp:38
json.h
messaget::~messaget
virtual ~messaget()
Definition: message.cpp:68
source_locationt::get_file
const irep_idt & get_file() const
Definition: source_location.h:36
messaget::underline
static const commandt underline
render underlined text
Definition: message.h:377
messaget::mstreamt
Definition: message.h:221
messaget::cyan
static const commandt cyan
render text with cyan foreground color
Definition: message.h:347
messaget::M_DEBUG
@ M_DEBUG
Definition: message.h:168
messaget::mstream
mstreamt mstream
Definition: message.h:426
messaget::bright_green
static const commandt bright_green
render text with bright green foreground color
Definition: message.h:353
messaget::eval_verbosity
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:99
messaget::mstreamt::message_level
unsigned message_level
Definition: message.h:242
messaget::magenta
static const commandt magenta
render text with magenta foreground color
Definition: message.h:344
messaget::bright_cyan
static const commandt bright_cyan
render text with bright cyan foreground color
Definition: message.h:365
messaget::bright_blue
static const commandt bright_blue
render text with bright blue foreground color
Definition: message.h:359
messaget::commandt
Definition: message.h:303
messaget::blue
static const commandt blue
render text with blue foreground color
Definition: message.h:341