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