cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
cl_message_handler.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Print messages like CL.exe does
4
5
Author: Michael Tautschnig
6
7
\*******************************************************************/
8
9
#include "
cl_message_handler.h
"
10
11
#include <
util/unicode.h
>
12
13
#include <fstream>
14
15
void
cl_message_handlert::print
(
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
if
(level ==
messaget::M_WARNING
&&
warnings_are_errors
)
29
formatted_message <<
"error: warning treated as error\n"
;
30
31
const
irep_idt
file
= location.
get_file
();
32
const
std::string &line =
id2string
(location.
get_line
());
33
formatted_message <<
file
<<
'('
<< line <<
"): "
;
34
35
if
(level ==
messaget::M_ERROR
)
36
formatted_message <<
"error: "
;
37
else
if
(level ==
messaget::M_WARNING
)
38
formatted_message <<
"warning: "
;
39
40
formatted_message << message;
41
42
const
auto
full_path = location.
full_path
();
43
44
if
(full_path.has_value() && !line.empty())
45
{
46
std::ifstream in(
widen_if_needed
(full_path.value()));
47
48
if
(in)
49
{
50
const
auto
line_number = std::stoull(line);
51
std::string source_line;
52
for
(std::size_t l = 0; l < line_number; l++)
53
std::getline(in, source_line);
54
55
if
(in)
56
{
57
formatted_message <<
'\n'
;
58
formatted_message <<
file
<<
'('
<< line <<
"): "
<< source_line;
59
}
60
}
61
}
62
63
console_message_handlert::print
(level, formatted_message.str());
64
}
cl_message_handler.h
cl_message_handlert::warnings_are_errors
bool warnings_are_errors
Definition
cl_message_handler.h:41
cl_message_handlert::print
void print(unsigned, const xmlt &) override
Definition
cl_message_handler.h:17
console_message_handlert::print
void print(unsigned, const xmlt &) override
Definition
cout_message.h:32
message_handlert::verbosity
unsigned verbosity
Definition
message.h:71
messaget::M_ERROR
@ M_ERROR
Definition
message.h:169
messaget::M_WARNING
@ M_WARNING
Definition
message.h:169
source_locationt
Definition
source_location.h:20
source_locationt::get_file
const irep_idt & get_file() const
Definition
source_location.h:36
source_locationt::get_line
const irep_idt & get_line() const
Definition
source_location.h:46
source_locationt::full_path
std::optional< std::string > full_path() const
Get a path to the file, including working directory.
Definition
source_location.cpp:88
id2string
const std::string & id2string(const irep_idt &d)
Definition
irep.h:44
file
Definition
kdev_t.h:19
unicode.h
widen_if_needed
#define widen_if_needed(s)
Definition
unicode.h:28
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
goto-cc
cl_message_handler.cpp
Generated by
1.17.0