cprover
Loading...
Searching...
No Matches
cl_message_handler.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Print messages like CL.exe does
4
5Author: Michael Tautschnig
6
7\*******************************************************************/
8
10
11#include <util/unicode.h>
12
13#include <fstream>
14
16 unsigned level,
17 const std::string &message,
18 const source_locationt &location)
19{
20 if(verbosity < level || location == source_locationt())
21 {
22 console_message_handlert::print(level, message);
23 return;
24 }
25
26 std::ostringstream formatted_message;
27
28 const irep_idt file = location.get_file();
29 const std::string &line = id2string(location.get_line());
30 formatted_message << file << '(' << line << "): ";
31
32 if(level == messaget::M_ERROR)
33 formatted_message << "error: ";
34 else if(level == messaget::M_WARNING)
35 formatted_message << "warning: ";
36
37 formatted_message << message;
38
39 const auto full_path = location.full_path();
40
41 if(full_path.has_value() && !line.empty())
42 {
43 std::ifstream in(widen_if_needed(full_path.value()));
44
45 if(in)
46 {
47 const auto line_number = std::stoull(line);
48 std::string source_line;
49 for(std::size_t l = 0; l < line_number; l++)
50 std::getline(in, source_line);
51
52 if(in)
53 {
54 formatted_message << '\n';
55 formatted_message << file << '(' << line << "): " << source_line;
56 }
57 }
58 }
59
61}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:563
void print(unsigned, const xmlt &) override
void print(unsigned, const xmlt &) override
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:39
unsigned verbosity
Definition message.h:72
@ M_ERROR
Definition message.h:170
@ M_WARNING
Definition message.h:170
optionalt< std::string > full_path() const
Get a path to the file, including working directory.
const irep_idt & get_file() const
const irep_idt & get_line() const
const std::string & id2string(const irep_idt &d)
Definition irep.h:47
Definition kdev_t.h:19
#define widen_if_needed(s)
Definition unicode.h:28