@@ -145,68 +145,72 @@ void gcc_message_handlert::print(
145
145
const std::string &message,
146
146
const source_locationt &location)
147
147
{
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);
154
149
155
- if (!function. empty () )
150
+ if (verbosity >= level )
156
151
{
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;
165
154
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 ();
169
159
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
+ }
172
168
173
- dest+=id2string (line)+" :" ;
169
+ if (!line.empty ())
170
+ {
171
+ out << string (messaget::bold );
174
172
175
- if (column.empty ())
176
- dest+=" 1: " ;
177
- else
178
- dest+=id2string (column)+" : " ;
173
+ if (!file.empty ())
174
+ out << file << ' :' ;
179
175
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 << ' :' ;
184
177
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: " ;
187
187
188
- dest+=message;
188
+ out << string (messaget::reset);
189
+ }
189
190
190
- print (level, dest) ;
191
+ out << message << ' \n ' ;
191
192
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
+ {
195
196
#ifdef _WIN32
196
- std::ifstream in (widen (file_name.value ()));
197
+ std::ifstream in (widen (file_name.value ()));
197
198
#else
198
- std::ifstream in (file_name.value ());
199
+ std::ifstream in (file_name.value ());
199
200
#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
-
207
201
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
+ }
209
211
}
212
+
213
+ out << std::flush;
210
214
}
211
215
}
212
216
0 commit comments