Use 'ao-dbg' instead of 's51' to communicate with TeleMetrum
[fw/sdcc] / src / SDCCerr.c
1 /*
2  * SDCCerr - Standard error handler
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU Library General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include "SDCCerr.h"
23
24 #define USE_STDOUT_FOR_ERRORS   0
25
26 #if USE_STDOUT_FOR_ERRORS
27 #define DEFAULT_ERROR_OUT       stdout
28 #else
29 #define DEFAULT_ERROR_OUT       stderr
30 #endif
31
32 struct SDCCERRG _SDCCERRG; 
33
34 extern char *filename;
35 extern int lineno;
36 extern int fatalError;
37
38 /* Currently the errIndex field must match the position of the 
39  * entry in the array. It is only included in order to make 
40  * human error lookup easier.
41  */
42 struct
43 {
44     int                 errIndex;
45     ERROR_LOG_LEVEL     errType;
46     const char          *errText;
47 } ErrTab [] =
48 {
49 { E_DUPLICATE, ERROR_LEVEL_ERROR,
50    "Duplicate symbol '%s', symbol IGNORED" },
51 { E_SYNTAX_ERROR, ERROR_LEVEL_ERROR,
52    "Syntax error, declaration ignored at '%s'" },
53 { E_CONST_EXPECTED, ERROR_LEVEL_ERROR,
54     "Initializer element is not constant" },
55 { E_OUT_OF_MEM, ERROR_LEVEL_ERROR,
56    "'malloc' failed file '%s' for size %ld" },
57 { E_FILE_OPEN_ERR, ERROR_LEVEL_ERROR,
58    "'fopen' failed on file '%s'" },
59 { E_INVALID_OCLASS, ERROR_LEVEL_ERROR,
60    "Internal Error Oclass invalid '%s'" },
61 { E_CANNOT_ALLOC, ERROR_LEVEL_ERROR,
62    "Cannot allocate variable '%s'." },
63 { E_OLD_STYLE, ERROR_LEVEL_ERROR,
64    "Old style C declaration. IGNORED '%s'" },
65 { E_STACK_OUT, ERROR_LEVEL_ERROR,
66    "Out of stack Space. '%s' not allocated" },
67 { E_INTERNAL_ERROR, ERROR_LEVEL_ERROR,
68    "FATAL Compiler Internal Error in file '%s' line number '%d' : %s \n"
69    "Contact Author with source code" },
70 { E_LVALUE_REQUIRED, ERROR_LEVEL_ERROR,
71    "'lvalue' required for '%s' operation." },
72 { E_TMPFILE_FAILED, ERROR_LEVEL_ERROR,
73    "Creation of temp file failed" },
74 { E_FUNCTION_EXPECTED, ERROR_LEVEL_ERROR,
75    "called object is not a function" },
76 { E_USING_ERROR, ERROR_LEVEL_ERROR,
77    "'using', 'interrupt' or 'reentrant' must follow a function definiton.'%s'" },
78 { E_SFR_INIT, ERROR_LEVEL_ERROR,
79    "Absolute address & initial value both cannot be specified for\n"
80    " a 'sfr','sbit' storage class, initial value ignored '%s'" },
81 { W_INIT_IGNORED, ERROR_LEVEL_WARNING,
82    "Variable in the storage class cannot be initialized.'%s'" },
83 { E_AUTO_ASSUMED, ERROR_LEVEL_ERROR,
84    "variable '%s' must be static to have storage class in reentrant function" },
85 { E_AUTO_ABSA, ERROR_LEVEL_ERROR,
86    "absolute address not allowed for automatic var '%s' in reentrant function " },
87 { W_INIT_WRONG, ERROR_LEVEL_WARNING,
88    "Initializer different levels of indirections" },
89 { E_FUNC_REDEF, ERROR_LEVEL_ERROR,
90    "Function name '%s' redefined " },
91 { E_ID_UNDEF, ERROR_LEVEL_ERROR,
92    "Undefined identifier '%s'" },
93 { W_STACK_OVERFLOW, ERROR_LEVEL_WARNING,
94    "stack exceeds 256 bytes for function '%s'" },
95 { E_NEED_ARRAY_PTR, ERROR_LEVEL_ERROR,
96    "Array or pointer required for '%s' operation " },
97 { E_IDX_NOT_INT, ERROR_LEVEL_ERROR,
98    "Array index not an integer" },
99 { W_IDX_OUT_OF_BOUNDS, ERROR_LEVEL_WARNING,
100    "index %i is outside of the array bounds (array size is %i)" },
101 { E_STRUCT_UNION, ERROR_LEVEL_ERROR,
102    "Structure/Union expected left of '.%s'" },
103 { E_NOT_MEMBER, ERROR_LEVEL_ERROR,
104    "'%s' not a structure/union member" },
105 { E_PTR_REQD, ERROR_LEVEL_ERROR,
106    "Pointer required" },
107 { E_UNARY_OP, ERROR_LEVEL_ERROR,
108    "'unary %c': illegal operand" },
109 { E_CONV_ERR, ERROR_LEVEL_ERROR,
110    "conversion error: integral promotion failed" },
111 { E_INT_REQD, ERROR_LEVEL_ERROR,
112    "type must be INT for bit field definition" },
113 { E_BITFLD_SIZE, ERROR_LEVEL_ERROR,
114    "bit field size cannot be greater than int (%d bits)" },
115 { W_TRUNCATION, ERROR_LEVEL_WARNING,
116    "high order truncation might occur" },
117 { E_CODE_WRITE, ERROR_LEVEL_ERROR,
118    "Attempt to assign value to a constant variable (%s)" },
119 { E_LVALUE_CONST, ERROR_LEVEL_ERROR,
120    "Lvalue specifies constant object" },
121 { E_ILLEGAL_ADDR, ERROR_LEVEL_ERROR,
122    "'&' illegal operand , %s" },
123 { E_CAST_ILLEGAL, ERROR_LEVEL_ERROR,
124    "illegal cast (cast cannot be aggregate)" },
125 { E_MULT_INTEGRAL, ERROR_LEVEL_ERROR,
126    "'*' bad operand" },
127 { E_ARG_ERROR, ERROR_LEVEL_ERROR,
128    "Argument count error, argument ignored" },
129 { E_ARG_COUNT, ERROR_LEVEL_ERROR,
130    "Function was expecting more arguments" },
131 { E_FUNC_EXPECTED, ERROR_LEVEL_ERROR,
132    "Function name expected '%s'. ANSI style declaration REQUIRED" },
133 { E_PLUS_INVALID, ERROR_LEVEL_ERROR,
134    "invalid operand '%s'" },
135 { E_PTR_PLUS_PTR, ERROR_LEVEL_ERROR,
136    "pointer + pointer invalid" },
137 { E_SHIFT_OP_INVALID, ERROR_LEVEL_ERROR,
138    "invalid operand for shift operator" },
139 { E_COMPARE_OP, ERROR_LEVEL_ERROR,
140    "compare operand cannot be struct/union" },
141 { E_BITWISE_OP, ERROR_LEVEL_ERROR,
142    "operand invalid for bitwise operation" },
143 { E_ANDOR_OP, ERROR_LEVEL_ERROR,
144    "Invalid operand for '&&' or '||'" },
145 { E_TYPE_MISMATCH, ERROR_LEVEL_ERROR,
146    "indirections to different types %s %s " },
147 { E_AGGR_ASSIGN, ERROR_LEVEL_ERROR,
148    "cannot assign values to aggregates" },
149 { E_ARRAY_DIRECT, ERROR_LEVEL_ERROR,
150    "bit Arrays can be accessed by literal index only" },
151 { E_BIT_ARRAY, ERROR_LEVEL_ERROR,
152    "Array or Pointer to bit|sbit|sfr not allowed.'%s'" },
153 { E_DUPLICATE_TYPEDEF, ERROR_LEVEL_ERROR,
154    "typedef/enum '%s' duplicate. Previous definiton Ignored" },
155 { E_ARG_TYPE, ERROR_LEVEL_ERROR,
156    "Actual Argument type different from declaration %d" },
157 { E_RET_VALUE, ERROR_LEVEL_ERROR,
158    "Function return value mismatch" },
159 { E_FUNC_AGGR, ERROR_LEVEL_ERROR,
160    "Function cannot return aggregate. Func body ignored" },
161 { E_FUNC_DEF, ERROR_LEVEL_ERROR,
162    "ANSI Style declaration needed" },
163 { E_DUPLICATE_LABEL, ERROR_LEVEL_ERROR,
164    "Duplicate label '%s'" },
165 { E_LABEL_UNDEF, ERROR_LEVEL_ERROR,
166    "Label undefined '%s'" },
167 { E_FUNC_VOID, ERROR_LEVEL_ERROR,
168    "void function returning value" },
169 { W_VOID_FUNC, ERROR_LEVEL_WARNING,
170    "function '%s' must return value" },
171 { W_RETURN_MISMATCH, ERROR_LEVEL_WARNING,
172    "function return value mismatch" },
173 { E_CASE_CONTEXT, ERROR_LEVEL_ERROR,
174    "'case/default' found without 'switch'. Statement ignored" },
175 { E_CASE_CONSTANT, ERROR_LEVEL_ERROR,
176    "'case' expression not constant. Statement ignored" },
177 { E_BREAK_CONTEXT, ERROR_LEVEL_ERROR,
178    "'break/continue' statement out of context" },
179 { E_SWITCH_AGGR, ERROR_LEVEL_ERROR,
180    "nonintegral used in switch expression" },
181 { E_FUNC_BODY, ERROR_LEVEL_ERROR,
182    "function '%s' already has body" },
183 { E_UNKNOWN_SIZE, ERROR_LEVEL_ERROR,
184    "attempt to allocate variable of unknown size '%s'" },
185 { E_AUTO_AGGR_INIT, ERROR_LEVEL_ERROR,
186    "aggregate 'auto' variable '%s' cannot be initialized" },
187 { E_INIT_COUNT, ERROR_LEVEL_ERROR,
188    "too many initializers" },
189 { E_INIT_STRUCT, ERROR_LEVEL_ERROR,
190    "struct/union/array '%s': initialization needs curly braces" },
191 { E_INIT_NON_ADDR, ERROR_LEVEL_ERROR,
192    "non-address initialization expression" },
193 { E_INT_DEFINED, ERROR_LEVEL_ERROR,
194    "interrupt no '%d' already has a service routine '%s'" },
195 { E_INT_ARGS, ERROR_LEVEL_ERROR,
196    "interrupt routine cannot have arguments, arguments ingored" },
197 { E_INCLUDE_MISSING, ERROR_LEVEL_ERROR,
198    "critical compiler #include file missing.            " },
199 { E_NO_MAIN, ERROR_LEVEL_ERROR,
200    "function 'main' undefined" },
201 { E_EXTERN_INIT, ERROR_LEVEL_ERROR,
202    "'extern' variable '%s' cannot be initialised        " },
203 { E_PRE_PROC_FAILED, ERROR_LEVEL_ERROR,
204    "Pre-Processor %s" },
205 { E_DUP_FAILED, ERROR_LEVEL_ERROR,
206    "_dup call failed" },
207 { E_INCOMPAT_TYPES, ERROR_LEVEL_ERROR,
208    "incompatible types" },
209 { W_LOOP_ELIMINATE, ERROR_LEVEL_WARNING,
210    "'while' loop with 'zero' constant. Loop eliminated" },
211 { W_NO_SIDE_EFFECTS, ERROR_LEVEL_WARNING,
212    "%s expression has NO side effects. Expr eliminated" },
213 { W_CONST_TOO_LARGE, ERROR_LEVEL_PEDANTIC,
214    "constant value '%s', out of range." },
215 { W_BAD_COMPARE, ERROR_LEVEL_WARNING,
216    "comparison will either, ALWAYs succeed or ALWAYs fail" },
217 { E_TERMINATING, ERROR_LEVEL_ERROR,
218    "Compiler Terminating , contact author with source" },
219 { W_LOCAL_NOINIT, ERROR_LEVEL_WARNING,
220    "'auto' variable '%s' may be used before initialization" },
221 { W_NO_REFERENCE, ERROR_LEVEL_WARNING,
222    "in function %s unreferenced %s : '%s'" },
223 { E_OP_UNKNOWN_SIZE, ERROR_LEVEL_ERROR,
224    "unknown size for operand" },
225 { W_LONG_UNSUPPORTED, ERROR_LEVEL_WARNING,
226    "'%s' 'long' not supported , declared as 'int'." },
227 { E_LITERAL_GENERIC, ERROR_LEVEL_ERROR,
228     //"illegal cast of LITERAL value to 'generic' pointer: assuming 'xdata' pointer" },
229     "illegal cast of LITERAL value to 'generic' pointer" },
230 { E_SFR_ADDR_RANGE, ERROR_LEVEL_ERROR,
231    "%s '%s' address out of range" },
232 { E_BITVAR_STORAGE, ERROR_LEVEL_ERROR,
233    "storage class CANNOT be specified for bit variable '%s'" },
234 { E_EXTERN_MISMATCH, ERROR_LEVEL_ERROR,
235    "extern definition for '%s' mismatches with declaration." },
236 { E_NONRENT_ARGS, ERROR_LEVEL_ERROR,
237    "Functions called via pointers must be 'reentrant' to take this many arguments" },
238 { W_DOUBLE_UNSUPPORTED, ERROR_LEVEL_WARNING,
239    "type 'double' not supported assuming 'float'" },
240 { W_COMP_RANGE, ERROR_LEVEL_WARNING,
241    "comparison is always %s due to limited range of data type" },
242 { W_FUNC_NO_RETURN, ERROR_LEVEL_WARNING,
243    "no 'return' statement found for function '%s'" },
244 { W_PRE_PROC_WARNING, ERROR_LEVEL_WARNING,
245    "Pre-Processor %s" },
246 { W_STRUCT_AS_ARG, ERROR_LEVEL_WARNING,
247    "structure '%s' passed as function argument changed to pointer" },
248 { E_PREV_DEF_CONFLICT, ERROR_LEVEL_ERROR,
249    "conflict with previous definition of '%s' for attribute '%s'" },
250 { E_CODE_NO_INIT, ERROR_LEVEL_ERROR,
251    "variable '%s' declared in code space must have initialiser" },
252 { E_OPS_INTEGRAL, ERROR_LEVEL_ERROR,
253    "operands not integral for assignment operation" },
254 { E_TOO_MANY_PARMS, ERROR_LEVEL_ERROR,
255    "too many parameters " },
256 { E_TOO_FEW_PARMS, ERROR_LEVEL_ERROR,
257    "too few parameters" },
258 { E_FUNC_NO_CODE, ERROR_LEVEL_ERROR,
259    "code not generated for '%s' due to previous errors" },
260 { E_TYPE_MISMATCH_PARM, ERROR_LEVEL_ERROR,
261    "type mismatch for parameter number %d" },
262 { E_INVALID_FLOAT_CONST, ERROR_LEVEL_ERROR,
263    "invalid float constant '%s'" },
264 { E_INVALID_OP, ERROR_LEVEL_ERROR,
265    "invalid operand for '%s' operation" },
266 { E_SWITCH_NON_INTEGER, ERROR_LEVEL_ERROR,
267    "switch value not an integer" },
268 { E_CASE_NON_INTEGER, ERROR_LEVEL_ERROR,
269    "case label not an integer" },
270 { W_FUNC_TOO_LARGE, ERROR_LEVEL_WARNING,
271    "function '%s' too large for global optimization" },
272 { W_CONTROL_FLOW, ERROR_LEVEL_PEDANTIC,
273    "conditional flow changed by optimizer: so said EVELYN the modified DOG" },
274 { W_PTR_TYPE_INVALID, ERROR_LEVEL_WARNING,
275    "invalid type specifier for pointer type; specifier ignored" },
276 { W_IMPLICIT_FUNC, ERROR_LEVEL_WARNING,
277    "function '%s' implicit declaration" },
278 { W_CONTINUE, ERROR_LEVEL_WARNING,
279    "%s" },
280 { I_EXTENDED_STACK_SPILS, ERROR_LEVEL_INFO,
281    "extended stack by %d bytes for compiler temp(s) :in function  '%s': %s " },
282 { W_UNKNOWN_PRAGMA, ERROR_LEVEL_WARNING,
283    "unknown or unsupported #pragma directive '%s'" },
284 { W_SHIFT_CHANGED, ERROR_LEVEL_PEDANTIC,
285    "%s shifting more than size of object changed to zero" },
286 { W_UNKNOWN_OPTION, ERROR_LEVEL_WARNING,
287    "unknown compiler option '%s' ignored" },
288 { W_UNSUPP_OPTION, ERROR_LEVEL_WARNING,
289    "option '%s' no longer supported  '%s' " },
290 { W_UNKNOWN_FEXT, ERROR_LEVEL_WARNING,
291    "don't know what to do with file '%s'. file extension unsupported" },
292 { W_TOO_MANY_SRC, ERROR_LEVEL_WARNING,
293    "cannot compile more than one source file. file '%s' ignored" },
294 { I_CYCLOMATIC, ERROR_LEVEL_INFO,
295    "function '%s', # edges %d , # nodes %d , cyclomatic complexity %d" },
296 { E_DIVIDE_BY_ZERO, ERROR_LEVEL_ERROR,
297    "dividing by ZERO" },
298 { E_FUNC_BIT, ERROR_LEVEL_ERROR,
299    "function cannot return 'bit'" },
300 { E_CAST_ZERO, ERROR_LEVEL_ERROR,
301    "casting from to type 'void' is illegal" },
302 { W_CONST_RANGE, ERROR_LEVEL_WARNING,
303    "constant is out of range %s" },
304 { W_CODE_UNREACH, ERROR_LEVEL_PEDANTIC,
305    "unreachable code" },
306 { E_NONPTR2_GENPTR, ERROR_LEVEL_ERROR,
307    "non-pointer type cast to generic pointer" },
308 { W_POSSBUG, ERROR_LEVEL_WARNING,
309    "possible code generation error at line %d,\n"
310    " send source to sandeep.dutta@usa.net" },
311 { E_INCOMPAT_PTYPES, ERROR_LEVEL_ERROR,
312    "pointer types incompatible " },
313 { W_UNKNOWN_MODEL, ERROR_LEVEL_WARNING,
314    "unknown memory model at %s : %d" },
315 { E_UNKNOWN_TARGET, ERROR_LEVEL_ERROR,
316    "cannot generate code for target '%s'" },
317 { W_INDIR_BANKED, ERROR_LEVEL_WARNING,
318    "Indirect call to a banked function not implemented." },
319 { W_UNSUPPORTED_MODEL, ERROR_LEVEL_WARNING,
320    "Model '%s' not supported for %s, ignored." },
321 { W_BANKED_WITH_NONBANKED, ERROR_LEVEL_WARNING,
322    "Both banked and nonbanked attributes used.  nonbanked wins." },
323 { W_BANKED_WITH_STATIC, ERROR_LEVEL_WARNING,
324    "Both banked and static used.  static wins." },
325 { W_INT_TO_GEN_PTR_CAST, ERROR_LEVEL_WARNING,
326    "converting integer type to generic pointer: assuming XDATA" },
327 { W_ESC_SEQ_OOR_FOR_CHAR, ERROR_LEVEL_WARNING,
328    "escape sequence out of range for char." },
329 { E_INVALID_HEX, ERROR_LEVEL_ERROR,
330    "\\x used with no following hex digits." },
331 { W_FUNCPTR_IN_USING_ISR, ERROR_LEVEL_WARNING,
332    "call via function pointer in ISR using non-zero register bank.\n"
333    "            Cannot determine which register bank to save." },
334 { E_NO_SUCH_BANK, ERROR_LEVEL_ERROR,
335    "called function uses unknown register bank %d." },
336 { E_TWO_OR_MORE_DATA_TYPES, ERROR_LEVEL_ERROR,
337     "two or more data types in declaration for '%s'" },
338 { E_LONG_OR_SHORT_INVALID, ERROR_LEVEL_ERROR,
339     "long or short specified for %s '%s'" },
340 { E_SIGNED_OR_UNSIGNED_INVALID, ERROR_LEVEL_ERROR,
341     "signed or unsigned specified for %s '%s'" },
342 { E_LONG_AND_SHORT_INVALID, ERROR_LEVEL_ERROR,
343     "both long and short specified for %s '%s'" },
344 { E_SIGNED_AND_UNSIGNED_INVALID, ERROR_LEVEL_ERROR,
345     "both signed and unsigned specified for %s '%s'" },
346 { E_TWO_OR_MORE_STORAGE_CLASSES, ERROR_LEVEL_ERROR,
347     "two or more storage classes in declaration for '%s'" },
348 { W_EXCESS_INITIALIZERS, ERROR_LEVEL_WARNING,
349     "excess elements in %s initializer after '%s'" },
350 { E_ARGUMENT_MISSING, ERROR_LEVEL_ERROR,
351    "Option %s requires an argument." },
352 { W_STRAY_BACKSLASH, ERROR_LEVEL_WARNING,
353     "stray '\\' at column %d" },
354 { W_NEWLINE_IN_STRING, ERROR_LEVEL_WARNING,
355     "newline in string constant" },
356 { E_CANNOT_USE_GENERIC_POINTER, ERROR_LEVEL_ERROR,
357     "cannot use generic pointer %s to initialize %s" },
358 { W_EXCESS_SHORT_OPTIONS, ERROR_LEVEL_WARNING,
359     "Only one short option can be specified at a time.  Rest of %s ignored." },
360 { E_VOID_VALUE_USED, ERROR_LEVEL_ERROR,
361     "void value not ignored as it ought to be" },
362 { W_INTEGRAL2PTR_NOCAST, ERROR_LEVEL_WARNING,
363     "converting integral to pointer without a cast" },
364 { W_PTR2INTEGRAL_NOCAST, ERROR_LEVEL_WARNING,
365     "converting pointer to integral without a cast" },
366 { W_SYMBOL_NAME_TOO_LONG, ERROR_LEVEL_WARNING,
367     "symbol name too long, truncated to %d chars" },
368 { W_CAST_STRUCT_PTR,ERROR_LEVEL_WARNING,
369           "cast of struct %s * to struct %s * " },
370 { W_LIT_OVERFLOW, ERROR_LEVEL_WARNING,
371     "overflow in implicit constant conversion" },
372 { E_PARAM_NAME_OMITTED, ERROR_LEVEL_ERROR,
373     "in function %s: name omitted for parameter %d" },
374 { W_NO_FILE_ARG_IN_C1, ERROR_LEVEL_WARNING,
375     "only standard input is compiled in c1 mode. file '%s' ignored" },
376 { E_NEED_OPT_O_IN_C1, ERROR_LEVEL_ERROR,
377     "must specify assembler file name with -o in c1 mode" },
378 { W_ILLEGAL_OPT_COMBINATION, ERROR_LEVEL_WARNING,
379     "illegal combination of options (--c1mode, -E, -S -c)" },
380 { E_DUPLICATE_MEMBER, ERROR_LEVEL_ERROR,
381     "duplicate %s member '%s'" },
382 { E_STACK_VIOLATION, ERROR_LEVEL_ERROR,
383     "'%s' internal stack %s" },
384 { W_INT_OVL, ERROR_LEVEL_PEDANTIC,
385     "integer overflow in expression" },
386 { W_USELESS_DECL, ERROR_LEVEL_WARNING,
387     "useless declaration (possible use of keyword as variable name)" },
388 { E_INT_BAD_INTNO, ERROR_LEVEL_ERROR,
389     "interrupt number '%u' is not valid" },
390 { W_BITFLD_NAMED, ERROR_LEVEL_WARNING,
391     "ignoring declarator of 0 length bitfield" },
392 { E_FUNC_ATTR, ERROR_LEVEL_ERROR,
393     "function attribute following non-function declaration"},
394 { W_SAVE_RESTORE, ERROR_LEVEL_PEDANTIC,
395     "unmatched #pragma save and #pragma restore" },
396 { E_INVALID_CRITICAL, ERROR_LEVEL_ERROR,
397     "not allowed in a critical section" },
398 { E_NOT_ALLOWED, ERROR_LEVEL_ERROR,
399     "%s not allowed here" },
400 { E_BAD_TAG, ERROR_LEVEL_ERROR,
401     "'%s' is not a %s tag" },
402 { E_ENUM_NON_INTEGER, ERROR_LEVEL_ERROR,
403    "enumeration constant not an integer" },
404 { W_DEPRECATED_PRAGMA, ERROR_LEVEL_WARNING,
405    "pragma %s is deprecated, please see documentation for details" },
406 { E_SIZEOF_INCOMPLETE_TYPE, ERROR_LEVEL_ERROR,
407    "sizeof applied to an incomplete type" },
408 { E_PREVIOUS_DEF, ERROR_LEVEL_ERROR,
409    "previously defined here" },
410 { W_SIZEOF_VOID, ERROR_LEVEL_WARNING,
411    "size of void is zero" },
412 { W_POSSBUG2, ERROR_LEVEL_WARNING,
413    "possible code generation error at %s line %d,\n"
414    " please report problem and send source code at SDCC-USER list on SF.Net"},
415 { W_COMPLEMENT, ERROR_LEVEL_WARNING,
416    "using ~ on bit/bool/unsigned char variables can give unexpected results due to promotion to int" },
417 { E_SHADOWREGS_NO_ISR, ERROR_LEVEL_ERROR,
418    "ISR function attribute 'shadowregs' following non-ISR function '%s'" },
419 { W_SFR_ABSRANGE, ERROR_LEVEL_WARNING,
420    "absolute address for sfr '%s' probably out of range." },
421 { E_BANKED_WITH_CALLEESAVES, ERROR_LEVEL_ERROR,
422    "Both banked and callee-saves cannot be used together." },
423 { W_INVALID_INT_CONST, ERROR_LEVEL_WARNING,
424    "integer constant '%s' out of range, truncated to %.0lf." },
425 { W_CMP_SU_CHAR, ERROR_LEVEL_PEDANTIC,
426    "comparison of 'signed char' with 'unsigned char' requires promotion to int" },
427 { W_INVALID_FLEXARRAY, ERROR_LEVEL_WARNING,
428    "invalid use of structure with flexible array member" },
429 { W_C89_NO_FLEXARRAY, ERROR_LEVEL_PEDANTIC,
430    "ISO C90 does not support flexible array members" },
431 { E_FLEXARRAY_NOTATEND, ERROR_LEVEL_ERROR,
432    "flexible array member not at end of struct" },
433 { E_FLEXARRAY_INEMPTYSTRCT, ERROR_LEVEL_ERROR,
434    "flexible array in otherwise empty struct" },
435 { W_EMPTY_SOURCE_FILE, ERROR_LEVEL_WARNING,
436    "ISO C forbids an empty source file" },
437 { W_BAD_PRAGMA_ARGUMENTS, ERROR_LEVEL_WARNING,
438    "#pragma %s: bad argument(s); pragma ignored" },
439 { E_BAD_RESTRICT, ERROR_LEVEL_ERROR,
440    "Only pointers may be qualified with 'restrict'" },
441 { E_BAD_INLINE, ERROR_LEVEL_ERROR,
442    "Only functions may be qualified with 'inline'" },
443 { E_BAD_INT_ARGUMENT, ERROR_LEVEL_ERROR,
444    "Bad integer argument for option %s" },
445 { E_NEGATIVE_ARRAY_SIZE, ERROR_LEVEL_ERROR,
446    "Size of array '%s' is negative" },
447 };
448
449 /*
450 -------------------------------------------------------------------------------
451 SetErrorOut - Set the error output file
452
453 -------------------------------------------------------------------------------
454 */
455
456 FILE *SetErrorOut(FILE *NewErrorOut)
457 {
458     _SDCCERRG.out = NewErrorOut ;
459
460     return NewErrorOut ;
461 }
462
463 void setErrorLogLevel (ERROR_LOG_LEVEL level)
464 {
465     _SDCCERRG.logLevel = level;
466 }
467
468 /*
469 -------------------------------------------------------------------------------
470 vwerror - Output a standard error message with variable number of arguments
471
472 -------------------------------------------------------------------------------
473 */
474
475 void vwerror (int errNum, va_list marker)
476 {
477     if (_SDCCERRG.out == NULL) {
478         _SDCCERRG.out = DEFAULT_ERROR_OUT;
479     }
480
481     if (ErrTab[errNum].errIndex != errNum) {
482         fprintf(_SDCCERRG.out, 
483                 "Internal error: error table entry for %d inconsistent.", errNum);
484     }
485
486     if ((ErrTab[errNum].errType >= _SDCCERRG.logLevel) && (!_SDCCERRG.disabled[errNum])) {
487         if ( ErrTab[errNum].errType == ERROR_LEVEL_ERROR || _SDCCERRG.werror )
488             fatalError++ ;
489   
490         if ( filename && lineno ) {
491             if(_SDCCERRG.style)
492                 fprintf(_SDCCERRG.out, "%s(%d) : ",filename,lineno);
493             else
494                 fprintf(_SDCCERRG.out, "%s:%d: ",filename,lineno);
495         } else if (lineno) {
496             fprintf(_SDCCERRG.out, "at %d: ", lineno);
497         } else {
498             fprintf(_SDCCERRG.out, "-:0: ");
499         }
500
501         switch(ErrTab[errNum].errType)
502         {
503             case ERROR_LEVEL_ERROR:
504                 fprintf(_SDCCERRG.out, "error %d: ", errNum);
505                 break;
506             case ERROR_LEVEL_WARNING:
507             case ERROR_LEVEL_PEDANTIC:
508                 if (_SDCCERRG.werror)
509                     fprintf(_SDCCERRG.out, "error %d: ", errNum);
510                 else
511                     fprintf(_SDCCERRG.out, "warning %d: ", errNum);
512                 break;
513             case ERROR_LEVEL_INFO:
514                 fprintf(_SDCCERRG.out, "info %d: ", errNum);
515                 break;
516             default:
517                 break;                  
518         }
519     
520         vfprintf(_SDCCERRG.out, ErrTab[errNum].errText,marker);
521         fprintf(_SDCCERRG.out, "\n");
522     } else {
523         /* Below the logging level, drop. */
524     }
525 }
526 /*
527 -------------------------------------------------------------------------------
528 werror - Output a standard error message with variable number of arguments
529
530 -------------------------------------------------------------------------------
531 */
532
533 void werror (int errNum, ...)
534 {
535     va_list marker;
536     va_start(marker,errNum);
537     vwerror(errNum, marker);
538     va_end(marker);
539 }
540
541 /*
542 -------------------------------------------------------------------------------
543 werrorfl - Output a standard error message with variable number of arguments.
544            Use a specified filename and line number instead of the default.
545
546 -------------------------------------------------------------------------------
547 */
548
549 void werrorfl (char *newFilename, int newLineno, int errNum, ...)
550 {
551     char *oldFilename = filename;
552     int oldLineno = lineno;
553     va_list marker;
554
555     filename = newFilename;
556     lineno = newLineno;
557
558     va_start(marker,errNum);
559     vwerror(errNum, marker);
560     va_end(marker);
561
562     filename = oldFilename;
563     lineno = oldLineno;
564 }
565
566
567 /*
568 -------------------------------------------------------------------------------
569 fatal - Output a standard error message with variable number of arguments and
570         call exit()
571 -------------------------------------------------------------------------------
572 */
573 void fatal (int exitCode, int errNum, ...)
574 {
575     va_list marker;
576     va_start(marker,errNum);
577     vwerror(errNum, marker);
578     va_end(marker);
579
580     exit(exitCode);
581 }
582
583 /*
584 -------------------------------------------------------------------------------
585 style - Change the output error style to MSVC
586 -------------------------------------------------------------------------------
587 */
588
589 void MSVC_style (int style)
590 {
591     _SDCCERRG.style = style;
592 }
593
594 /*
595 -------------------------------------------------------------------------------
596 disabled - Disable output of specified warning
597 -------------------------------------------------------------------------------
598 */
599
600 void setWarningDisabled (int errNum)
601 {
602     if ((errNum < MAX_ERROR_WARNING) && (ErrTab[errNum].errType <= ERROR_LEVEL_WARNING))
603         _SDCCERRG.disabled[errNum] = 1;
604 }
605
606 /*
607 -------------------------------------------------------------------------------
608 Set the flag to treat warnings as errors
609 -------------------------------------------------------------------------------
610 */
611
612 void setWError (int flag)
613 {
614     _SDCCERRG.werror = flag;
615 }