Skip to content

Commit 905e5ed

Browse files
committed
Add a CL-specific message handler
console_message_handlert does not print source lines, which we do in GCC mode and should also be doing in CL mode.
1 parent e7508bf commit 905e5ed

File tree

7 files changed

+102
-8
lines changed

7 files changed

+102
-8
lines changed

regression/ansi-c/const1/const-array.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
const-array.c
33
^.*: .* is constant$
44
^ array\[1\] = 2;$

regression/ansi-c/const1/const-member.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
const-member.c
33

44
^.*: .* is constant$

src/goto-cc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SRC = armcc_cmdline.cpp \
44
as_cmdline.cpp \
55
as_mode.cpp \
66
bcc_cmdline.cpp \
7+
cl_message_handler.cpp \
78
compile.cpp \
89
cw_mode.cpp \
910
gcc_cmdline.cpp \

src/goto-cc/cl_message_handler.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
#include <iostream>
15+
#include <sstream>
16+
17+
void cl_message_handlert::print(
18+
unsigned level,
19+
const std::string &message,
20+
const source_locationt &location)
21+
{
22+
if(verbosity < level || location == source_locationt())
23+
{
24+
console_message_handlert::print(level, message);
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+
34+
if(level == messaget::M_ERROR)
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 _WIN32
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+
formatted_message << '\n' << source_line;
59+
}
60+
}
61+
62+
console_message_handlert::print(level, formatted_message.str());
63+
}

src/goto-cc/cl_message_handler.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*******************************************************************\
2+
3+
Module: Print messages like CL.exe does
4+
5+
Author: Michael Tautschnig
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_GOTO_CC_CL_MESSAGE_HANDLER_H
10+
#define CPROVER_GOTO_CC_CL_MESSAGE_HANDLER_H
11+
12+
#include <util/cout_message.h>
13+
14+
class cl_message_handlert : public console_message_handlert
15+
{
16+
public:
17+
void print(unsigned, const xmlt &) override
18+
{
19+
}
20+
21+
void print(unsigned, const jsont &) override
22+
{
23+
}
24+
25+
// aims to imitate the messages CL prints
26+
void print(
27+
unsigned level,
28+
const std::string &message,
29+
const source_locationt &location) override;
30+
};
31+
32+
#endif // CPROVER_GOTO_CC_CL_MESSAGE_HANDLER_H

src/goto-cc/ms_cl_mode.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ Date: June 2006
1414
#ifndef CPROVER_GOTO_CC_MS_CL_MODE_H
1515
#define CPROVER_GOTO_CC_MS_CL_MODE_H
1616

17-
#include <util/cout_message.h>
18-
17+
#include "cl_message_handler.h"
1918
#include "goto_cc_mode.h"
2019
#include "ms_cl_cmdline.h"
2120

@@ -35,7 +34,7 @@ class ms_cl_modet:public goto_cc_modet
3534

3635
protected:
3736
ms_cl_cmdlinet &cmdline;
38-
console_message_handlert message_handler;
37+
cl_message_handlert message_handler;
3938
};
4039

4140
#endif // CPROVER_GOTO_CC_MS_CL_MODE_H

src/goto-cc/ms_link_mode.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ Date: July 2018
1414
#ifndef CPROVER_GOTO_CC_MS_LINK_MODE_H
1515
#define CPROVER_GOTO_CC_MS_LINK_MODE_H
1616

17+
#include "cl_message_handler.h"
1718
#include "compile.h"
1819
#include "goto_cc_mode.h"
1920

20-
#include <util/cout_message.h>
21-
2221
class ms_link_modet : public goto_cc_modet
2322
{
2423
public:
@@ -28,7 +27,7 @@ class ms_link_modet : public goto_cc_modet
2827
explicit ms_link_modet(goto_cc_cmdlinet &);
2928

3029
protected:
31-
console_message_handlert message_handler;
30+
cl_message_handlert message_handler;
3231
};
3332

3433
#endif // CPROVER_GOTO_CC_MS_LINK_MODE_H

0 commit comments

Comments
 (0)