1 /*****************************************************************************/
5 /* Error handling for the cc65 C compiler */
9 /* (C) 1998-2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
48 /*****************************************************************************/
50 /*****************************************************************************/
54 static char* WarnMsg [WARN_COUNT-1] = {
56 "Condition is never true",
57 "Condition is always true",
58 "Converting pointer to integer without a cast",
59 "Converting integer to pointer without a cast",
60 "Function call without a prototype",
63 "Function must be extern",
64 "Parameter `%s' is never used",
65 "`%s' is defined but never used",
67 "`/*' found inside a comment",
68 "Useless declaration",
73 /* Error messages sorted by ErrTypes */
74 static char* ErrMsg [ERR_COUNT-1] = {
75 "Invalid character (%u)",
77 "End-of-file reached in comment starting at line %u",
88 "Identifier expected",
91 "Incompatible pointer types",
92 "Too many arguments in function call",
93 "Too few arguments in function call",
94 "Macro argument count mismatch",
95 "Duplicate macro parameter: %s",
96 "Variable identifier expected",
97 "Integer expression expected",
98 "Constant expression expected",
100 "`\"' or `<' expected",
101 "Missing terminator or name too long",
102 "Include file `%s' not found",
103 "Cannot open include file `%s': %s",
104 "Invalid #error directive",
106 "Unexpected `#endif'",
107 "Unexpected `#else'",
109 "Compiler directive expected",
110 "Redefinition of `%s'",
111 "Conflicting types for `%s'",
112 "String literal expected",
114 "Function must return a value",
115 "Function cannot return a value",
116 "Unexpected `continue'",
117 "Undefined symbol: `%s'",
118 "Undefined label: `%s'",
119 "Include nesting too deep",
120 "Too many local variables",
121 "Too many initializers",
122 "Cannot initialize incomplete type",
124 "Operation not allowed with this type of argument",
126 "Struct/union has no field named `%s'",
127 "Struct pointer expected",
129 "Expression expected",
130 "Preprocessor expression expected",
132 "Illegal function call",
133 "Illegal indirection",
135 "Illegal macro call",
137 "Illegal character constant",
139 "Illegal type qualifier",
140 "Illegal storage class",
141 "Illegal segment name: `%s'",
143 "Modulo operation with zero",
145 "Symbol is already different kind",
146 "Too many lexical levels",
147 "Parameter name omitted",
148 "Old style function decl used as prototype",
149 "Declaration for parameter `%s' but no such parameter",
150 "Cannot take address of a register variable",
151 "Illegal size of data type",
152 "__fastcall__ is not allowed for C functions",
153 "Variable has unknown size",
154 "Unknown identifier: `%s'",
155 "Duplicate qualifier: `%s'",
156 "Assignment to const",
157 "Pointer types differ in type qualifiers",
162 static char* FatMsg [FAT_COUNT-1] = {
164 "Cannot open output file: %s",
165 "Cannot write to output file (disk full?)",
166 "Cannot open input file: %s",
170 "Out of string space",
171 "Too many case labels",
176 /* Count of errors/warnings */
177 unsigned ErrorCount = 0;
178 unsigned WarningCount = 0;
182 /*****************************************************************************/
184 /*****************************************************************************/
188 void Warning (unsigned WarnNum, ...)
189 /* Print warning message. */
194 fprintf (stderr, "%s(%u): Warning #%u: ",
195 GetCurrentFile(), curpos, WarnNum);
197 va_start (ap, WarnNum);
198 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
200 fprintf (stderr, "\n");
203 fprintf (stderr, "Line: %s\n", line);
211 void PPWarning (unsigned WarnNum, ...)
212 /* Print warning message. For use within the preprocessor. */
217 fprintf (stderr, "%s(%u): Warning #%u: ",
218 GetCurrentFile(), GetCurrentLine(), WarnNum);
220 va_start (ap, WarnNum);
221 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
223 fprintf (stderr, "\n");
230 void Error (unsigned ErrNum, ...)
231 /* Print an error message */
235 fprintf (stderr, "%s(%u): Error #%u: ",
236 GetCurrentFile(), curpos, ErrNum);
238 va_start (ap, ErrNum);
239 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
241 fprintf (stderr, "\n");
244 fprintf (stderr, "Line: %s\n", line);
247 if (ErrorCount > 10) {
248 Fatal (FAT_TOO_MANY_ERRORS);
254 void PPError (unsigned ErrNum, ...)
255 /* Print an error message. For use within the preprocessor. */
259 fprintf (stderr, "%s(%u): Error #%u: ",
260 GetCurrentFile(), GetCurrentLine(), ErrNum);
262 va_start (ap, ErrNum);
263 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
265 fprintf (stderr, "\n");
268 if (ErrorCount > 10) {
269 Fatal (FAT_TOO_MANY_ERRORS);
275 void Fatal (unsigned FatNum, ...)
276 /* Print a message about a fatal error and die */
280 fprintf (stderr, "%s(%u): Fatal #%u: ",
281 GetCurrentFile(), curpos, FatNum);
283 va_start (ap, FatNum);
284 vfprintf (stderr, FatMsg [FatNum-1], ap);
286 fprintf (stderr, "\n");
289 fprintf (stderr, "Line: %s\n", line);
296 void Internal (char* Format, ...)
297 /* Print a message about an internal compiler error and die. */
301 fprintf (stderr, "%s(%u): Internal compiler error:\n",
302 GetCurrentFile(), curpos);
304 va_start (ap, Format);
305 vfprintf (stderr, Format, ap);
307 fprintf (stderr, "\nLine: %s\n", line);
309 /* Use abort to create a core dump */
315 void ErrorReport (void)
316 /* Report errors (called at end of compile) */
318 if (ErrorCount == 0 && Verbose) {
319 printf ("No errors.\n");