Skip to content

Commit 58bafea

Browse files
Daniel KroeningPetr Bauch
Daniel Kroening
authored and
Petr Bauch
committed
gcc_message_handlert: use stream directly
1 parent 1c83869 commit 58bafea

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

src/util/cout_message.cpp

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -145,68 +145,72 @@ void gcc_message_handlert::print(
145145
const std::string &message,
146146
const source_locationt &location)
147147
{
148-
const irep_idt file=location.get_file();
149-
const irep_idt line=location.get_line();
150-
const irep_idt column=location.get_column();
151-
const irep_idt function=location.get_function();
152-
153-
std::string dest;
148+
message_handlert::print(level, message);
154149

155-
if(!function.empty())
150+
if(verbosity >= level)
156151
{
157-
if(!file.empty())
158-
dest += string(messaget::bold) + id2string(file) + ":" +
159-
string(messaget::reset);
160-
if(dest!="")
161-
dest+=' ';
162-
dest += "In function " + string(messaget::bold) + '\'' +
163-
id2string(function) + '\'' + string(messaget::reset) + ":\n";
164-
}
152+
// gcc appears to send everything to cerr
153+
auto &out = std::cerr;
165154

166-
if(!line.empty())
167-
{
168-
dest += string(messaget::bold);
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();
169159

170-
if(!file.empty())
171-
dest+=id2string(file)+":";
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+
}
172168

173-
dest+=id2string(line)+":";
169+
if(!line.empty())
170+
{
171+
out << string(messaget::bold);
174172

175-
if(column.empty())
176-
dest+="1: ";
177-
else
178-
dest+=id2string(column)+": ";
173+
if(!file.empty())
174+
out << file << ':';
179175

180-
if(level==messaget::M_ERROR)
181-
dest += string(messaget::red) + "error: ";
182-
else if(level==messaget::M_WARNING)
183-
dest += string(messaget::bright_magenta) + "warning: ";
176+
out << line << ':';
184177

185-
dest += string(messaget::reset);
186-
}
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: ";
187187

188-
dest+=message;
188+
out << string(messaget::reset);
189+
}
189190

190-
print(level, dest);
191+
out << message << '\n';
191192

192-
const auto file_name = location.full_path();
193-
if(file_name.has_value() && !line.empty())
194-
{
193+
const auto file_name = location.full_path();
194+
if(file_name.has_value() && !line.empty())
195+
{
195196
#ifdef _WIN32
196-
std::ifstream in(widen(file_name.value()));
197+
std::ifstream in(widen(file_name.value()));
197198
#else
198-
std::ifstream in(file_name.value());
199+
std::ifstream in(file_name.value());
199200
#endif
200-
if(in)
201-
{
202-
const auto line_number = std::stoull(id2string(line));
203-
std::string line;
204-
for(std::size_t l = 0; l < line_number; l++)
205-
std::getline(in, line);
206-
207201
if(in)
208-
print(level, " " + line); // gcc adds a space, clang doesn't
202+
{
203+
const auto line_number = std::stoull(id2string(line));
204+
std::string line;
205+
for(std::size_t l = 0; l < line_number; l++)
206+
std::getline(in, line);
207+
208+
if(in)
209+
out << ' ' << line << '\n'; // gcc adds a space, clang doesn't
210+
}
209211
}
212+
213+
out << std::flush;
210214
}
211215
}
212216

0 commit comments

Comments
 (0)