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  int,
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!="")
30  dest+=' ';
31  dest+="file "+id2string(file);
32  }
33  if(!line.empty())
34  {
35  if(dest!="")
36  dest+=' ';
37  dest+="line "+id2string(line);
38  }
39  if(!column.empty())
40  {
41  if(dest!="")
42  dest+=' ';
43  dest+="column "+id2string(column);
44  }
45  if(!function.empty())
46  {
47  if(dest!="")
48  dest+=' ';
49  dest+="function "+id2string(function);
50  }
51 
52  if(dest!="")
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 
79  const std::string &user_input,
80  const message_levelt default_verbosity,
81  message_handlert &dest)
82 {
83  unsigned v = default_verbosity;
84 
85  if(!user_input.empty())
86  {
87  v = unsafe_string2unsigned(user_input);
88 
89  if(v > messaget::M_DEBUG)
90  {
91  dest.print(
93  "verbosity value " + user_input + " out of range, using debug-level (" +
94  std::to_string(messaget::M_DEBUG) + ") verbosity",
95  -1,
97 
99  }
100  }
101 
102  dest.set_verbosity(v);
103 
104  return v;
105 }
106 
114  mstreamt &mstream,
115  const std::function<void(mstreamt &)> &output_generator) const
116 {
117  if(
118  message_handler &&
120  {
121  output_generator(mstream);
122  }
123 }
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
virtual ~messaget()
Definition: message.cpp:68
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:78
const irep_idt & get_column() const
unsigned get_verbosity() const
Definition: message.h:66
const irep_idt & get_line() const
message_levelt
Definition: message.h:137
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
const irep_idt & get_file() const
std::string to_string(const string_constraintt &expr)
Used for debug printing.
std::vector< unsigned > message_count
Definition: message.h:78
void conditional_output(mstreamt &mstream, const std::function< void(mstreamt &)> &output_generator) const
Generate output to mstream using output_generator if the configured verbosity is at least as high as ...
Definition: message.cpp:113
void set_verbosity(unsigned _verbosity)
Definition: message.h:65
mstreamt mstream
Definition: message.h:343
message_handlert * message_handler
Definition: message.h:342
unsigned message_level
Definition: message.h:212
bool empty() const
Definition: dstring.h:73
virtual void print(unsigned level, const std::string &message)=0
Definition: message.cpp:59
Definition: kdev_t.h:19