1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
13 ******************************************************************************/
15 #include "CompilerError.hh"
16 #include "../common/memory.h"
17 #include "../common/path.h"
26 # include <sys/wait.h>
29 unsigned verb_level
=0x0007; /* default value */
31 const char *argv0
; /* the programname :) */
33 void fatal_error(const char *filename
, int lineno
, const char *fmt
, ...)
37 va_start(parameters
, fmt
);
38 Common::Location
loc(filename
, lineno
);
39 Common::Error_Context::report_error(&loc
, fmt
, parameters
);
42 fprintf(stderr
, "FATAL ERROR: %s: In line %d of %s: ",
43 argv0
, lineno
, filename
);
44 va_start(parameters
, fmt
);
45 vfprintf(stderr
, fmt
, parameters
);
53 void ERROR(const char *fmt
, ...)
55 fprintf(stderr
, "%s: error: ", argv0
);
57 va_start(parameters
, fmt
);
58 vfprintf(stderr
, fmt
, parameters
);
62 Common::Error_Context::increment_error_count();
65 void WARNING(const char *fmt
, ...)
67 if(!(verb_level
& 2)) return;
68 fprintf(stderr
, "%s: warning: ", argv0
);
70 va_start(parameters
, fmt
);
71 vfprintf(stderr
, fmt
, parameters
);
75 Common::Error_Context::increment_warning_count();
78 void NOTSUPP(const char *fmt
, ...)
80 if(!(verb_level
& 1)) return;
81 fprintf(stderr
, "%s: warning: not supported: ", argv0
);
83 va_start(parameters
, fmt
);
84 vfprintf(stderr
, fmt
, parameters
);
88 Common::Error_Context::increment_warning_count();
91 void NOTIFY(const char *fmt
, ...)
93 if(!(verb_level
& 4)) return;
94 fprintf(stderr
, "Notify: ");
96 va_start(parameters
, fmt
);
97 vfprintf(stderr
, fmt
, parameters
);
103 void DEBUG(unsigned level
, const char *fmt
, ...)
105 if((level
>7?7:level
)>((verb_level
>>3)&0x07)) return;
106 fprintf(stderr
, "%*sDebug: ", level
, "");
108 va_start(parameters
, fmt
);
109 vfprintf(stderr
, fmt
, parameters
);
115 unsigned int get_error_count(void)
117 return Common::Error_Context::get_error_count();
120 unsigned int get_warning_count(void)
122 return Common::Error_Context::get_warning_count();
125 void path_error(const char *fmt
, ...)
129 char *err_msg
= mprintf_va_list(fmt
, ap
);
131 ERROR("%s", err_msg
);
137 unsigned int Error_Context::error_count
= 0, Error_Context::warning_count
= 0;
138 unsigned int Error_Context::max_errors
= (unsigned)-1;
140 bool Error_Context::chain_printed
= false;
142 Error_Context
*Error_Context::head
= 0, *Error_Context::tail
= 0;
144 void Error_Context::print_context(FILE *fp
)
147 for (Error_Context
*ptr
= head
; ptr
; ptr
= ptr
->next
) {
148 if (ptr
->is_restorer
) FATAL_ERROR("Error_Context::print()");
149 else if (!ptr
->str
) continue;
150 else if (!ptr
->is_printed
) {
151 for (int i
= 0; i
< level
; i
++) putc(' ', fp
);
152 if (ptr
->location
) ptr
->location
->print_location(fp
);
153 if (gcc_compat
) fputs("note: ", fp
); // CDT ignores "note"
156 ptr
->is_printed
= true;
160 for (int i
= 0; i
< level
; i
++) putc(' ', fp
);
161 chain_printed
= true;
164 Error_Context::Error_Context(size_t n_keep
)
165 : prev(0), next(0), location(0), str(0), is_printed(false),
166 is_restorer(true), outer_printed(false)
168 Error_Context
*begin
= head
;
169 for (size_t i
= 0; i
< n_keep
; i
++) {
180 // partial backup (only elements before begin are kept)
189 outer_printed
= chain_printed
;
190 chain_printed
= false;
193 Error_Context::Error_Context(const Location
*p_location
)
194 : prev(0), next(0), location(p_location
), str(0), is_printed(false),
195 is_restorer(false), outer_printed(false)
197 if (!head
) head
= this;
198 if (tail
) tail
->next
= this;
204 Error_Context::Error_Context(const Location
*p_location
,
205 const char *p_fmt
, ...)
206 : prev(0), next(0), location(p_location
), str(0), is_printed(false),
207 is_restorer(false), outer_printed(false)
210 va_start(args
, p_fmt
);
211 str
= mprintf_va_list(p_fmt
, args
);
214 if (!head
) head
= this;
215 if (tail
) tail
->next
= this;
221 Error_Context::~Error_Context()
225 for (Error_Context
*ptr
= next
; ptr
; ptr
= ptr
->next
)
226 ptr
->is_printed
= false;
227 } else chain_printed
= outer_printed
;
229 // partial restoration
242 if (tail
!= this) FATAL_ERROR("Error_Context::~Error_Context()");
243 if (prev
) prev
->next
= 0;
249 void Error_Context::set_message(const char *p_fmt
, ...)
251 if (is_restorer
) FATAL_ERROR("Error_Context::set_message()");
254 va_start(args
, p_fmt
);
255 str
= mprintf_va_list(p_fmt
, args
);
260 void Error_Context::report_error(const Location
*loc
, const char *fmt
,
263 if (!suppress_context
) print_context(stderr
);
264 Location my_location
;
265 if (tail
!= 0 && loc
&& loc
->get_filename() == 0) {
266 // borrow location information from the innermost context
267 my_location
.set_location( *(tail
->location
) );
270 if (loc
) loc
->print_location(stderr
);
271 fputs("error: ", stderr
);
272 vfprintf(stderr
, fmt
, args
);
275 increment_error_count();
278 void Error_Context::report_warning(const Location
*loc
, const char *fmt
,
281 if(!(verb_level
& 2)) return;
282 if (!suppress_context
) print_context(stderr
);
283 if (loc
) loc
->print_location(stderr
);
284 fputs("warning: ", stderr
);
285 vfprintf(stderr
, fmt
, args
);
288 increment_warning_count();
291 void Error_Context::report_note(const Location
*loc
, const char *fmt
,
294 if (!suppress_context
) print_context(stderr
);
295 if (loc
) loc
->print_location(stderr
);
296 fputs("note: ", stderr
);
297 vfprintf(stderr
, fmt
, args
);
302 void Error_Context::increment_error_count()
304 if (++error_count
>= max_errors
) {
305 fputs("Maximum number of errors reached, aborting.\n", stderr
);
311 void Error_Context::increment_warning_count()
316 void Error_Context::print_error_statistics()
318 if (error_count
== 0) {
319 if (warning_count
== 0) NOTIFY("No errors or warnings were detected.");
320 else NOTIFY("No errors and %u warning%s were detected.",
321 warning_count
, warning_count
> 1 ? "s" : "");
323 if (warning_count
== 0) NOTIFY("%u error%s and no warnings were "
324 "detected.", error_count
, error_count
> 1 ? "s" : "");
325 else NOTIFY("%u error%s and %u warning%s were detected.",
326 error_count
, error_count
> 1 ? "s" : "",
327 warning_count
, warning_count
> 1 ? "s" : "");
331 } // namespace Common
This page took 0.038901 seconds and 5 git commands to generate.