Skip to content

Commit ac7c605

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 c5a0e7c commit ac7c605

File tree

11 files changed

+138
-126
lines changed

11 files changed

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

src/goto-cc/gcc_message_handler.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
// aims to imitate the messages gcc prints
18+
virtual void print(
19+
unsigned level,
20+
const std::string &message) override;
21+
22+
virtual void print(
23+
unsigned level,
24+
const std::string &message,
25+
const source_locationt &location) override;
26+
27+
private:
28+
/// feed a command into a string
29+
std::string string(const messaget::commandt &c) const
30+
{
31+
return command(c.command);
32+
}
33+
};
34+
35+
#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)