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