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#ifdef _MSC_VER
12# include <util/unicode.h>
13#endif
14
15#include <fstream>
16
18 unsigned level,
19 const std::string &message,
20 const source_locationt &location)
21{
22 if(verbosity < level || location == source_locationt())
23 {
25 return;
26 }
27
28 std::ostringstream formatted_message;
29
30 const irep_idt file = location.get_file();
31 const std::string &line = id2string(location.get_line());
32 formatted_message << file << '(' << line << "): ";
33
35 formatted_message << "error: ";
36 else if(level == messaget::M_WARNING)
37 formatted_message << "warning: ";
38
39 formatted_message << message;
40
41 const auto full_path = location.full_path();
42
43 if(full_path.has_value() && !line.empty())
44 {
45#ifdef _MSC_VER
46 std::ifstream in(widen(full_path.value()));
47#else
48 std::ifstream in(full_path.value());
49#endif
50 if(in)
51 {
52 const auto line_number = std::stoull(line);
53 std::string source_line;
54 for(std::size_t l = 0; l < line_number; l++)
55 std::getline(in, source_line);
56
57 if(in)
58 {
59 formatted_message << '\n';
60 formatted_message << file << '(' << line << "): " << source_line;
61 }
62 }
63 }
64
66}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:564
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:37
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
std::wstring widen(const char *s)
Definition unicode.cpp:49