1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 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
7 ///////////////////////////////////////////////////////////////////////////////
9 #include "CompilerError.hh"
10 #include "../common/memory.h"
11 #include "../common/path.h"
20 # include <sys/wait.h>
23 unsigned verb_level
=0x0007; /* default value */
25 const char *argv0
; /* the programname :) */
27 void fatal_error(const char *filename
, int lineno
, const char *fmt
, ...)
31 va_start(parameters
, fmt
);
32 Common::Location
loc(filename
, lineno
);
33 Common::Error_Context::report_error(&loc
, fmt
, parameters
);
36 fprintf(stderr
, "FATAL ERROR: %s: In line %d of %s: ",
37 argv0
, lineno
, filename
);
38 va_start(parameters
, fmt
);
39 vfprintf(stderr
, fmt
, parameters
);
47 void ERROR(const char *fmt
, ...)
49 fprintf(stderr
, "%s: error: ", argv0
);
51 va_start(parameters
, fmt
);
52 vfprintf(stderr
, fmt
, parameters
);
56 Common::Error_Context::increment_error_count();
59 void WARNING(const char *fmt
, ...)
61 if(!(verb_level
& 2)) return;
62 fprintf(stderr
, "%s: warning: ", argv0
);
64 va_start(parameters
, fmt
);
65 vfprintf(stderr
, fmt
, parameters
);
69 Common::Error_Context::increment_warning_count();
72 void NOTSUPP(const char *fmt
, ...)
74 if(!(verb_level
& 1)) return;
75 fprintf(stderr
, "%s: warning: not supported: ", argv0
);
77 va_start(parameters
, fmt
);
78 vfprintf(stderr
, fmt
, parameters
);
82 Common::Error_Context::increment_warning_count();
85 void NOTIFY(const char *fmt
, ...)
87 if(!(verb_level
& 4)) return;
88 fprintf(stderr
, "Notify: ");
90 va_start(parameters
, fmt
);
91 vfprintf(stderr
, fmt
, parameters
);
97 void DEBUG(unsigned level
, const char *fmt
, ...)
99 if((level
>7?7:level
)>((verb_level
>>3)&0x07)) return;
100 fprintf(stderr
, "%*sDebug: ", level
, "");
102 va_start(parameters
, fmt
);
103 vfprintf(stderr
, fmt
, parameters
);
109 unsigned int get_error_count(void)
111 return Common::Error_Context::get_error_count();
114 unsigned int get_warning_count(void)
116 return Common::Error_Context::get_warning_count();
119 void path_error(const char *fmt
, ...)
123 char *err_msg
= mprintf_va_list(fmt
, ap
);
125 ERROR("%s", err_msg
);
131 unsigned int Error_Context::error_count
= 0, Error_Context::warning_count
= 0;
132 unsigned int Error_Context::max_errors
= (unsigned)-1;
134 bool Error_Context::chain_printed
= false;
136 Error_Context
*Error_Context::head
= 0, *Error_Context::tail
= 0;
138 void Error_Context::print_context(FILE *fp
)
141 for (Error_Context
*ptr
= head
; ptr
; ptr
= ptr
->next
) {
142 if (ptr
->is_restorer
) FATAL_ERROR("Error_Context::print()");
143 else if (!ptr
->str
) continue;
144 else if (!ptr
->is_printed
) {
145 for (int i
= 0; i
< level
; i
++) putc(' ', fp
);
146 if (ptr
->location
) ptr
->location
->print_location(fp
);
147 if (gcc_compat
) fputs("note: ", fp
); // CDT ignores "note"
150 ptr
->is_printed
= true;
154 for (int i
= 0; i
< level
; i
++) putc(' ', fp
);
155 chain_printed
= true;
158 Error_Context::Error_Context(size_t n_keep
)
159 : prev(0), next(0), location(0), str(0), is_printed(false),
160 is_restorer(true), outer_printed(false)
162 Error_Context
*begin
= head
;
163 for (size_t i
= 0; i
< n_keep
; i
++) {
174 // partial backup (only elements before begin are kept)
183 outer_printed
= chain_printed
;
184 chain_printed
= false;
187 Error_Context::Error_Context(const Location
*p_location
)
188 : prev(0), next(0), location(p_location
), str(0), is_printed(false),
189 is_restorer(false), outer_printed(false)
191 if (!head
) head
= this;
192 if (tail
) tail
->next
= this;
198 Error_Context::Error_Context(const Location
*p_location
,
199 const char *p_fmt
, ...)
200 : prev(0), next(0), location(p_location
), str(0), is_printed(false),
201 is_restorer(false), outer_printed(false)
204 va_start(args
, p_fmt
);
205 str
= mprintf_va_list(p_fmt
, args
);
208 if (!head
) head
= this;
209 if (tail
) tail
->next
= this;
215 Error_Context::~Error_Context()
219 for (Error_Context
*ptr
= next
; ptr
; ptr
= ptr
->next
)
220 ptr
->is_printed
= false;
221 } else chain_printed
= outer_printed
;
223 // partial restoration
236 if (tail
!= this) FATAL_ERROR("Error_Context::~Error_Context()");
237 if (prev
) prev
->next
= 0;
243 void Error_Context::set_message(const char *p_fmt
, ...)
245 if (is_restorer
) FATAL_ERROR("Error_Context::set_message()");
248 va_start(args
, p_fmt
);
249 str
= mprintf_va_list(p_fmt
, args
);
254 void Error_Context::report_error(const Location
*loc
, const char *fmt
,
257 if (!suppress_context
) print_context(stderr
);
258 Location my_location
;
259 if (tail
!= 0 && loc
&& loc
->get_filename() == 0) {
260 // borrow location information from the innermost context
261 my_location
.set_location( *(tail
->location
) );
264 if (loc
) loc
->print_location(stderr
);
265 fputs("error: ", stderr
);
266 vfprintf(stderr
, fmt
, args
);
269 increment_error_count();
272 void Error_Context::report_warning(const Location
*loc
, const char *fmt
,
275 if(!(verb_level
& 2)) return;
276 if (!suppress_context
) print_context(stderr
);
277 if (loc
) loc
->print_location(stderr
);
278 fputs("warning: ", stderr
);
279 vfprintf(stderr
, fmt
, args
);
282 increment_warning_count();
285 void Error_Context::report_note(const Location
*loc
, const char *fmt
,
288 if (!suppress_context
) print_context(stderr
);
289 if (loc
) loc
->print_location(stderr
);
290 fputs("note: ", stderr
);
291 vfprintf(stderr
, fmt
, args
);
296 void Error_Context::increment_error_count()
298 if (++error_count
>= max_errors
) {
299 fputs("Maximum number of errors reached, aborting.\n", stderr
);
305 void Error_Context::increment_warning_count()
310 void Error_Context::print_error_statistics()
312 if (error_count
== 0) {
313 if (warning_count
== 0) NOTIFY("No errors or warnings were detected.");
314 else NOTIFY("No errors and %u warning%s were detected.",
315 warning_count
, warning_count
> 1 ? "s" : "");
317 if (warning_count
== 0) NOTIFY("%u error%s and no warnings were "
318 "detected.", error_count
, error_count
> 1 ? "s" : "");
319 else NOTIFY("%u error%s and %u warning%s were detected.",
320 error_count
, error_count
> 1 ? "s" : "",
321 warning_count
, warning_count
> 1 ? "s" : "");
325 } // namespace Common
This page took 0.043121 seconds and 5 git commands to generate.