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",
89 "Identifier expected",
92 "Incompatible pointer types",
93 "Too many arguments in function call",
94 "Too few arguments in function call",
95 "Macro argument count mismatch",
96 "Duplicate macro parameter: %s",
97 "Variable identifier expected",
98 "Integer expression expected",
99 "Constant expression expected",
101 "`\"' or `<' expected",
102 "Missing terminator or name too long",
103 "Include file `%s' not found",
104 "Cannot open include file `%s': %s",
105 "Invalid #error directive",
107 "Unexpected `#endif'",
108 "Unexpected `#else'",
110 "Compiler directive expected",
111 "Redefinition of `%s'",
112 "Conflicting types for `%s'",
113 "String literal expected",
115 "Function must return a value",
116 "Function cannot return a value",
117 "Unexpected `continue'",
118 "Undefined symbol: `%s'",
119 "Undefined label: `%s'",
120 "Include nesting too deep",
121 "Too many local variables",
122 "Too many initializers",
123 "Cannot initialize incomplete type",
125 "Operation not allowed with this type of argument",
127 "Struct/union has no field named `%s'",
128 "Struct pointer expected",
130 "Expression expected",
131 "Preprocessor expression expected",
133 "Illegal function call",
134 "Illegal indirection",
136 "Illegal macro call",
138 "Illegal character constant",
140 "Illegal type qualifier",
141 "Illegal storage class",
143 "Illegal segment name: `%s'",
145 "Modulo operation with zero",
147 "Symbol is already different kind",
148 "Too many lexical levels",
149 "Parameter name omitted",
150 "Old style function decl used as prototype",
151 "Declaration for parameter `%s' but no such parameter",
152 "Cannot take address of a register variable",
153 "Illegal size of data type",
154 "__fastcall__ is not allowed for C functions",
155 "Variable has unknown size",
156 "Unknown identifier: `%s'",
157 "Duplicate qualifier: `%s'",
158 "Assignment to const",
159 "Pointer types differ in type qualifiers",
164 static char* FatMsg [FAT_COUNT-1] = {
166 "Cannot open output file: %s",
167 "Cannot write to output file (disk full?)",
168 "Cannot open input file: %s",
172 "Out of string space",
173 "Too many case labels",
178 /* Count of errors/warnings */
179 unsigned ErrorCount = 0;
180 unsigned WarningCount = 0;
184 /*****************************************************************************/
186 /*****************************************************************************/
190 void Warning (unsigned WarnNum, ...)
191 /* Print warning message. */
196 fprintf (stderr, "%s(%u): Warning #%u: ",
197 GetCurrentFile(), curpos, WarnNum);
199 va_start (ap, WarnNum);
200 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
202 fprintf (stderr, "\n");
205 fprintf (stderr, "Line: %s\n", line);
213 void PPWarning (unsigned WarnNum, ...)
214 /* Print warning message. For use within the preprocessor. */
219 fprintf (stderr, "%s(%u): Warning #%u: ",
220 GetCurrentFile(), GetCurrentLine(), WarnNum);
222 va_start (ap, WarnNum);
223 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
225 fprintf (stderr, "\n");
232 void Error (unsigned ErrNum, ...)
233 /* Print an error message */
237 fprintf (stderr, "%s(%u): Error #%u: ",
238 GetCurrentFile(), curpos, ErrNum);
240 va_start (ap, ErrNum);
241 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
243 fprintf (stderr, "\n");
246 fprintf (stderr, "Line: %s\n", line);
249 if (ErrorCount > 10) {
250 Fatal (FAT_TOO_MANY_ERRORS);
256 void PPError (unsigned ErrNum, ...)
257 /* Print an error message. For use within the preprocessor. */
261 fprintf (stderr, "%s(%u): Error #%u: ",
262 GetCurrentFile(), GetCurrentLine(), ErrNum);
264 va_start (ap, ErrNum);
265 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
267 fprintf (stderr, "\n");
270 if (ErrorCount > 10) {
271 Fatal (FAT_TOO_MANY_ERRORS);
277 void Fatal (unsigned FatNum, ...)
278 /* Print a message about a fatal error and die */
282 fprintf (stderr, "%s(%u): Fatal #%u: ",
283 GetCurrentFile(), curpos, FatNum);
285 va_start (ap, FatNum);
286 vfprintf (stderr, FatMsg [FatNum-1], ap);
288 fprintf (stderr, "\n");
291 fprintf (stderr, "Line: %s\n", line);
298 void Internal (char* Format, ...)
299 /* Print a message about an internal compiler error and die. */
303 fprintf (stderr, "%s(%u): Internal compiler error:\n",
304 GetCurrentFile(), curpos);
306 va_start (ap, Format);
307 vfprintf (stderr, Format, ap);
309 fprintf (stderr, "\nLine: %s\n", line);
311 /* Use abort to create a core dump */
317 void ErrorReport (void)
318 /* Report errors (called at end of compile) */
320 if (ErrorCount == 0 && Verbose) {
321 printf ("No errors.\n");