Skip to content

Commit 705729d

Browse files
committed
Move gcc_message_handlert to goto-cc folder
The only use is within goto-cc, there is no need to define this in util/.
1 parent 2be3344 commit 705729d

File tree

11 files changed

+146
-126
lines changed

11 files changed

+146
-126
lines changed

src/goto-cc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SRC = armcc_cmdline.cpp \
77
compile.cpp \
88
cw_mode.cpp \
99
gcc_cmdline.cpp \
10+
gcc_message_handler.cpp \
1011
gcc_mode.cpp \
1112
gcc_version.cpp \
1213
goto_cc_cmdline.cpp \

src/goto-cc/armcc_mode.h

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

17-
#include <util/cout_message.h>
18-
19-
#include "goto_cc_mode.h"
2017
#include "armcc_cmdline.h"
18+
#include "gcc_message_handler.h"
19+
#include "goto_cc_mode.h"
2120

2221
class armcc_modet:public goto_cc_modet
2322
{

src/goto-cc/as_mode.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Author: Michael Tautschnig
2424
#include <cstring>
2525

2626
#include <util/config.h>
27-
#include <util/cout_message.h>
2827
#include <util/get_base_name.h>
2928
#include <util/run.h>
3029
#include <util/tempdir.h>

src/goto-cc/as_mode.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ Date: July 2016
1414
#ifndef CPROVER_GOTO_CC_AS_MODE_H
1515
#define CPROVER_GOTO_CC_AS_MODE_H
1616

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

2120
class as_modet:public goto_cc_modet

src/goto-cc/gcc_message_handler.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*******************************************************************\
2+
3+
Module:
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include "gcc_message_handler.h"
10+
11+
#include <util/unicode.h>
12+
13+
#include <fstream>
14+
#include <iostream>
15+
16+
void gcc_message_handlert::print(
17+
unsigned level,
18+
const std::string &message,
19+
const source_locationt &location)
20+
{
21+
message_handlert::print(level, message);
22+
23+
if(verbosity >= level)
24+
{
25+
// gcc appears to send everything to cerr
26+
auto &out = std::cerr;
27+
28+
const irep_idt file = location.get_file();
29+
const irep_idt line = location.get_line();
30+
const irep_idt column = location.get_column();
31+
const irep_idt function = location.get_function();
32+
33+
if(!function.empty())
34+
{
35+
if(!file.empty())
36+
out << string(messaget::bold) << file << ':' << string(messaget::reset)
37+
<< ' ';
38+
out << "In function " << string(messaget::bold) << '\'' << function
39+
<< '\'' << string(messaget::reset) << ":\n";
40+
}
41+
42+
if(!line.empty())
43+
{
44+
out << string(messaget::bold);
45+
46+
if(!file.empty())
47+
out << file << ':';
48+
49+
out << line << ':';
50+
51+
if(column.empty())
52+
out << "1: ";
53+
else
54+
out << column << ": ";
55+
56+
if(level == messaget::M_ERROR)
57+
out << string(messaget::red) << "error: ";
58+
else if(level == messaget::M_WARNING)
59+
out << string(messaget::bright_magenta) << "warning: ";
60+
61+
out << string(messaget::reset);
62+
}
63+
64+
out << message << '\n';
65+
66+
const auto file_name = location.full_path();
67+
if(file_name.has_value() && !line.empty())
68+
{
69+
#ifdef _WIN32
70+
std::ifstream in(widen(file_name.value()));
71+
#else
72+
std::ifstream in(file_name.value());
73+
#endif
74+
if(in)
75+
{
76+
const auto line_number = std::stoull(id2string(line));
77+
std::string source_line;
78+
for(std::size_t l = 0; l < line_number; l++)
79+
std::getline(in, source_line);
80+
81+
if(in)
82+
out << ' ' << source_line << '\n'; // gcc adds a space, clang doesn't
83+
}
84+
}
85+
86+
out << std::flush;
87+
}
88+
}
89+
90+
void gcc_message_handlert::print(
91+
unsigned level,
92+
const std::string &message)
93+
{
94+
message_handlert::print(level, message);
95+
96+
// gcc appears to send everything to cerr
97+
if(verbosity>=level)
98+
std::cerr << message << '\n' << std::flush;
99+
}

src/goto-cc/gcc_message_handler.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*******************************************************************\
2+
3+
Module:
4+
5+
Author: Daniel Kroening, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#ifndef CPROVER_GOTO_CC_GCC_MESSAGE_HANDLER_H
10+
#define CPROVER_GOTO_CC_GCC_MESSAGE_HANDLER_H
11+
12+
#include <util/cout_message.h>
13+
14+
class gcc_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 gcc prints
26+
void print(unsigned level, const std::string &message) override;
27+
28+
void print(
29+
unsigned level,
30+
const std::string &message,
31+
const source_locationt &location) override;
32+
33+
private:
34+
/// feed a command into a string
35+
std::string string(const messaget::commandt &c) const
36+
{
37+
return command(c.command);
38+
}
39+
};
40+
41+
#endif // CPROVER_GOTO_CC_GCC_MESSAGE_HANDLER_H

src/goto-cc/gcc_mode.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ Date: June 2006
1515
#define CPROVER_GOTO_CC_GCC_MODE_H
1616

1717
#include "compile.h"
18+
#include "gcc_message_handler.h"
1819
#include "gcc_version.h"
1920
#include "goto_cc_mode.h"
2021

21-
#include <util/cout_message.h>
22-
2322
#include <set>
2423

2524
class gcc_modet:public goto_cc_modet

src/goto-cc/ld_mode.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ Date: June 2006
1515
#define CPROVER_GOTO_CC_LD_MODE_H
1616

1717
#include "compile.h"
18+
#include "gcc_message_handler.h"
1819
#include "goto_cc_mode.h"
1920

20-
#include <util/cout_message.h>
21-
2221
#include <set>
2322

2423
class ld_modet : public goto_cc_modet

src/goto-cc/linker_script_merge.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include <functional>
99

10-
#include <util/cout_message.h>
1110
#include <util/json.h>
1211

1312
#include "compile.h"

src/util/cout_message.cpp

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Author: Daniel Kroening, [email protected]
88

99
#include "cout_message.h"
1010

11-
#include <fstream>
1211
#include <iostream>
1312

1413
#ifdef _WIN32
@@ -139,88 +138,3 @@ void console_message_handlert::flush(unsigned level)
139138
else
140139
std::cerr << std::flush;
141140
}
142-
143-
void gcc_message_handlert::print(
144-
unsigned level,
145-
const std::string &message,
146-
const source_locationt &location)
147-
{
148-
message_handlert::print(level, message);
149-
150-
if(verbosity >= level)
151-
{
152-
// gcc appears to send everything to cerr
153-
auto &out = std::cerr;
154-
155-
const irep_idt file = location.get_file();
156-
const irep_idt line = location.get_line();
157-
const irep_idt column = location.get_column();
158-
const irep_idt function = location.get_function();
159-
160-
if(!function.empty())
161-
{
162-
if(!file.empty())
163-
out << string(messaget::bold) << file << ':' << string(messaget::reset)
164-
<< ' ';
165-
out << "In function " << string(messaget::bold) << '\'' << function
166-
<< '\'' << string(messaget::reset) << ":\n";
167-
}
168-
169-
if(!line.empty())
170-
{
171-
out << string(messaget::bold);
172-
173-
if(!file.empty())
174-
out << file << ':';
175-
176-
out << line << ':';
177-
178-
if(column.empty())
179-
out << "1: ";
180-
else
181-
out << column << ": ";
182-
183-
if(level == messaget::M_ERROR)
184-
out << string(messaget::red) << "error: ";
185-
else if(level == messaget::M_WARNING)
186-
out << string(messaget::bright_magenta) << "warning: ";
187-
188-
out << string(messaget::reset);
189-
}
190-
191-
out << message << '\n';
192-
193-
const auto file_name = location.full_path();
194-
if(file_name.has_value() && !line.empty())
195-
{
196-
#ifdef _WIN32
197-
std::ifstream in(widen(file_name.value()));
198-
#else
199-
std::ifstream in(file_name.value());
200-
#endif
201-
if(in)
202-
{
203-
const auto line_number = std::stoull(id2string(line));
204-
std::string source_line;
205-
for(std::size_t l = 0; l < line_number; l++)
206-
std::getline(in, source_line);
207-
208-
if(in)
209-
out << ' ' << source_line << '\n'; // gcc adds a space, clang doesn't
210-
}
211-
}
212-
213-
out << std::flush;
214-
}
215-
}
216-
217-
void gcc_message_handlert::print(
218-
unsigned level,
219-
const std::string &message)
220-
{
221-
message_handlert::print(level, message);
222-
223-
// gcc appears to send everything to cerr
224-
if(verbosity>=level)
225-
std::cerr << message << '\n' << std::flush;
226-
}

src/util/cout_message.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,33 +62,4 @@ class console_message_handlert : public message_handlert
6262
bool use_SGR;
6363
};
6464

65-
class gcc_message_handlert : public console_message_handlert
66-
{
67-
public:
68-
void print(unsigned, const xmlt &) override
69-
{
70-
}
71-
72-
void print(unsigned, const jsont &) override
73-
{
74-
}
75-
76-
// aims to imitate the messages gcc prints
77-
virtual void print(
78-
unsigned level,
79-
const std::string &message) override;
80-
81-
virtual void print(
82-
unsigned level,
83-
const std::string &message,
84-
const source_locationt &location) override;
85-
86-
private:
87-
/// feed a command into a string
88-
std::string string(const messaget::commandt &c) const
89-
{
90-
return command(c.command);
91-
}
92-
};
93-
9465
#endif // CPROVER_UTIL_COUT_MESSAGE_H

0 commit comments

Comments
 (0)