Tell us at least the linenumber
[fw/sdcc] / src / SDCCerr.c
1 /* SDCCerr.c - error handling routines */
2
3 #include "common.h"
4
5 #define USE_STDOUT_FOR_ERRORS           0
6
7 #if USE_STDOUT_FOR_ERRORS
8 #define ERRSINK         stdout
9 #else
10 #define ERRSINK         stderr
11 #endif
12
13 #define ERROR           0
14 #define WARNING         1
15
16 struct  {
17         int             errType ;
18         char    *errText ;
19 } ErrTab [] =
20 {
21 {  ERROR  ,"error *** Duplicate symbol '%s', symbol IGNORED\n"                },
22 { ERROR  ,"error *** Syntax Error Declaration ingonerd\n"                             },
23 { ERROR  ,"error *** Constant Expected Found Variable\n"                          },
24 { ERROR  ,"error *** 'malloc' failed file '%s' for size %ld\n"                },
25 { ERROR  ,"error *** 'fopen' failed on file '%s'\n"                                   },
26 { ERROR  ,"error *** Internal Error Oclass invalid '%s'\n"                            },
27 { ERROR  ,"error *** Cannot allocate variable '%s'.\n"                        },
28 { ERROR  ,"error *** Old style C declaration. IGNORED '%s'\n"                 },
29 { ERROR  ,"error *** Out of stack Space. '%s' not allocted\n"                 },
30 { ERROR  ,"error *** FATAL Compiler Internal Error in file '%s' line number '%d' : %s \nContact Author with source code\n" },
31 { ERROR  ,"error *** 'lvalue' required for '%s' operation .\n"                },
32 { ERROR  ,"error *** Creation of temp file failed\n"                          },
33 { ERROR  ,"error *** Function expected here '%s'\n"                                   },
34 { ERROR  ,"error *** 'using', 'interrupt' or 'reentrant' must follow a function definiton .'%s'\n"},
35 { ERROR  ,"error *** Absolute address & initial value both cannot be specified for\n a 'sfr','sbit' storage class, initial value ignored '%s'\n"  },
36 { WARNING,"warning *** Variable in the storage class cannot be initialized.'%s'\n"},
37 { WARNING,"warning *** storage class not allowed for automatic variable '%s' in reentrant function\n"   },
38 { ERROR  ,"error *** absolute address not allowed for automatic var '%s' in reentrant function \n"            },
39 { WARNING,"warning *** Initializer different levels of indirections\n"        },
40 { ERROR  ,"error *** Function name '%s' redefined \n"                         },
41 { ERROR  ,"error *** Undefined identifier '%s'\n"                                 },
42 { WARNING,"warning *** stack exceeds 256 bytes for function '%s'\n"},
43 { ERROR  ,"error *** Array or pointer required for '%s' operation \n"         },
44 { ERROR  ,"error *** Array index not an integer\n"                                },
45 { ERROR  ,"error *** Array bound Exceeded, assuming zero\n"                           },
46 { ERROR  ,"error *** Structure/Union expected left of '.%s'\n"                    },
47 { ERROR  ,"error *** '%s' not a structure/union member\n"                         },
48 { ERROR  ,"error *** Pointer required\n"                                              },
49 { ERROR  ,"error *** 'unary %c': illegal operand\n"                                   },
50 { ERROR  ,"error *** convertion error: integral promotion failed\n"                   },
51 { ERROR  ,"error *** type must be INT for bit field definition\n"                     },
52 { ERROR  ,"error *** bit field size greater than 16 . assuming 16\n"              },
53 { WARNING,"warning *** high order truncation might occur\n"                           },
54 { ERROR  ,"error *** Attempt to assign value to a constant variable %s\n"         },
55 { ERROR  ,"error *** Lvalue specifies constant object\n"                          },
56 { ERROR  ,"error *** '&' illegal operand , %s\n"                                  },
57 { ERROR  ,"error *** illegal cast (cast cannot be aggregate)\n"                   },
58 { ERROR  ,"error *** '*' bad operand\n"                                           },
59 { ERROR  ,"error *** Argument count error, argument ignored\n"                    },
60 { ERROR  ,"error *** Function was expecting more arguments\n"                     },
61 { ERROR  ,"error *** Function name expected '%s'.ANSI style declaration REQUIRED\n"},
62 { ERROR  ,"error *** invalid operand '%s'\n"                                          },
63 { ERROR  ,"error *** pointer + pointer invalid\n"                                     },
64 { ERROR  ,"error *** invalid operand for shift operator\n"                            },
65 { ERROR  ,"error *** compare operand cannot be struct/union\n"                },
66 { ERROR  ,"error *** operand invalid for bitwise operation\n"                 },
67 { ERROR  ,"error *** Invalid operand for '&&' or '||'\n"                              },
68 { WARNING,"warning *** indirections to different types %s %s \n"                      },
69 { ERROR  ,"error *** cannot assign values to aggregates\n"                            },
70 { ERROR  ,"error *** bit Arrays can be accessed by literal index only\n"              },
71 { ERROR  ,"error *** Array or Pointer to bit|sbit|sfr not allowed.'%s'\n"             },
72 { ERROR  ,"error *** typedef/enum '%s' duplicate.Previous definiton Ignored\n"    },
73 { ERROR  ,"error *** Actual Argument type different from declaration %d\n"            },
74 { ERROR  ,"error *** Function return value mismatch\n"                        },
75 { ERROR  ,"error *** Function cannot return aggregate. Func body ignored\n"           },
76 { ERROR  ,"error *** ANSI Style declaration needed\n"                         },
77 { ERROR  ,"error *** Label name redefined '%s'\n"                                     },
78 { ERROR  ,"error *** Label undefined '%s'\n"                                  },
79 { ERROR  ,"error *** void function returning value\n"                         },
80 { ERROR  ,"error *** function '%s' must return value\n"                       },
81 { WARNING,"warning *** function return value mismatch\n"                              },
82 { ERROR  ,"error *** 'case/default' found without 'switch'.statement ignored\n"   },
83 { ERROR  ,"error *** 'case' expression not constant. statement ignored\n"             },
84 { ERROR  ,"error *** 'break/continue' statement out of context\n"                     },
85 { ERROR  ,"error *** nonintegral used in switch expression\n"                 },
86 { ERROR  ,"error *** function '%s' already has body\n"                        },
87 { ERROR  ,"error *** attempt to allocate variable of unknown size '%s'\n"             },
88 { ERROR  ,"error *** aggregate 'auto' variable '%s' cannot be initialized\n"      },
89 { ERROR  ,"error *** too many initializers\n"                                 },
90 { ERROR  ,"error *** struct/union/array '%s' :initialization needs curly braces\n"},
91 { ERROR  ,"error *** non-address initialization expression\n"                 },
92 { ERROR  ,"error *** interrupt no '%d' already has a service routine '%s'\n"          },
93 { ERROR  ,"error *** interrupt routine cannot have arguments, arguments ingored\n"},
94 { ERROR  ,"error *** critical compiler #include file missing.           \n"   },
95 { ERROR  ,"error *** function 'main' undefined\n"                                 },
96 { ERROR  ,"error *** 'extern' variable '%s' cannot be initialised       \n"           },
97 { ERROR  ,"error *** Pre-Processor %s\n"                                              },
98 { ERROR  ,"error *** _dup call failed\n"                                          },
99 { WARNING,"warning *** pointer being cast to incompatible type \n"                        },
100 { WARNING,"warning *** 'while' loop with 'zero' constant.loop eliminated\n"           },
101 { WARNING,"warning *** %s expression has NO side effects.expr eliminated\n"           },
102 { WARNING,"warning *** constant value '%s', out of range.\n"                  },
103 { WARNING,"warning *** comparison will either, ALWAYs succeed or ALWAYs fail\n"   },
104 { ERROR  ,"error *** Compiler Terminating , contact author with source\n"             },
105 { WARNING,"warning *** 'auto' variable '%s' may be used before initialization at %s(%d)\n"      },
106 { WARNING,"warning *** in function %s unreferenced %s : '%s'\n"                       },
107 { ERROR  ,"error *** unknown size for operand\n"                                      },
108 { WARNING,"warning *** '%s' 'long' not supported , declared as 'int' .\n"             },
109 { WARNING,"warning *** LITERAL value being cast to '_generic' pointer\n"              },
110 { ERROR  ,"error *** %s '%s' address out of range\n"                                  },
111 { ERROR  ,"error *** storage class CANNOT be specified for bit variable '%s'\n"    },
112 { WARNING,"warning *** extern definition for '%s' mismatches with declaration.\n"  },
113 { WARNING,"warning *** Functions called via pointers must be 'reentrant' to take arguments\n"   },
114 { WARNING,"warning *** type 'double' not supported assuming 'float'\n"                },
115 { WARNING,"warning *** if-statement condition always false.if-statement not generated\n"},
116 { WARNING,"warning *** no 'return' statement found for function '%s'\n"       },
117 { WARNING,"warning *** Pre-Processor %s\n"                                            },
118 { WARNING,"warning *** structure '%s' passed as function argument changed to pointer\n"},
119 { ERROR  ,"error *** conflict with previous definition of '%s' for attribute '%s'\n" },
120 { ERROR  ,"error *** variable '%s' declared in code space must have initialiser\n" },
121 { ERROR  ,"error *** operands not integral for assignment operation\n"            },
122 { ERROR  ,"error *** too many parameters \n"                                      },
123 { ERROR  ,"error *** to few parameters\n"                                         },
124 { ERROR  ,"error *** code not generated for '%s' due to previous errors\n"},
125 { WARNING,"warning *** type mismatch for parameter number %d\n"},
126 { ERROR  ,"error *** invalid float constant '%s'\n"},
127 { ERROR  ,"error *** invalid operand for '%s' operation\n"},
128 { ERROR  ,"error *** switch value not an integer\n"},
129 { ERROR  ,"error *** case label not an integer\n"},
130 { WARNING,"warning *** function '%s' too large for global optimization\n"},
131 { WARNING,"warning *** conditional flow changed by optimizer '%s(%d)':so said EVELYN the modified DOG\n"},
132 { WARNING,"warning *** invalid type specifier for pointer type specifier ignored\n"},
133 { WARNING,"warning *** function '%s' implicit declaration\n"},
134 { WARNING,"warning *** %s"},
135 { WARNING,"info *** %s extended by %d bytes for compiler temp(s) :in function  '%s': %s \n"},
136 { WARNING,"warning *** unknown or unsupported #pragma directive '%s'\n"},
137 { WARNING,"warning *** %s shifting more than size of object changed to zero\n"},
138 { WARNING,"warning *** unknown compiler option '%s' ignored\n"},
139 { WARNING,"warning *** option '%s' no longer supported  '%s' \n"},
140 { WARNING,"warning *** don't know what to do with file '%s'. file extension unsupported\n"},
141 { WARNING,"warning *** cannot compile more than one source file . file '%s' ignored\n"},
142 { WARNING,"info *** function '%s', # edges %d , # nodes %d , cyclomatic complexity %d\n"},
143 { ERROR  ,"error *** dividing by ZERO\n"},
144 { ERROR  ,"error *** function cannot return 'bit'\n"},
145 { ERROR  ,"error *** casting from to type 'void' is illegal\n"},
146 { WARNING,"warning *** constant is out of range %s\n" },
147 { WARNING,"warning *** unreachable code %s(%d)\n"},
148 { WARNING,"warning *** non-pointer type cast to _generic pointer\n"},
149 { WARNING,"warning *** possible code generation error at line %d,\n send source to sandeep.dutta@usa.net\n"},
150 { WARNING,"warning *** pointer types incompatible \n" },
151 { WARNING,"warning *** unknown memory model at %s : %d\n" },
152 { ERROR  ,"error   *** cannot generate code for target '%s'\n"},
153 { WARNING,"warning *** Indirect call to a banked function not implemented.\n"},
154 { WARNING,"warning *** Model '%s' not supported for %s, ignored.\n"},
155 { WARNING,"warning *** Both banked and nonbanked attributes used.  nonbanked wins.\n"},
156 { WARNING,"warning *** Both banked and static used.  static wins.\n"},
157 { WARNING,"warning *** converting integer type to generic pointer: assuming XDATA\n"}
158 };
159
160 void    vwerror (int errNum, va_list marker)
161 {
162     if ( ErrTab[errNum].errType== ERROR )
163         fatalError++ ;
164     
165     if ( filename && lineno ) {
166         fprintf(ERRSINK, "%s(%d):",filename,lineno);
167     } else {
168         fprintf(ERRSINK, "at %d:",lineno);
169     }
170     vfprintf(ERRSINK, ErrTab[errNum].errText,marker);
171 }
172
173 /****************************************************************************/
174 /* werror - writes an error to the listing file & to standarderr            */
175 /****************************************************************************/
176 void    werror (int errNum, ... )
177 {
178     va_list     marker;
179     va_start(marker,errNum);
180     vwerror(errNum, marker);
181     va_end( marker );
182 }
183