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 "Macro redefinition is not identical",
98 "Variable identifier expected",
99 "Integer expression expected",
100 "Constant expression expected",
102 "`\"' or `<' expected",
103 "Missing terminator or name too long",
104 "Include file `%s' not found",
105 "Cannot open include file `%s': %s",
106 "Invalid #error directive",
108 "Unexpected `#endif'",
109 "Unexpected `#else'",
111 "Compiler directive expected",
112 "Redefinition of `%s'",
113 "Conflicting types for `%s'",
114 "String literal expected",
116 "Function must return a value",
117 "Function cannot return a value",
118 "Unexpected `continue'",
119 "Undefined symbol: `%s'",
120 "Undefined label: `%s'",
121 "Include nesting too deep",
122 "Too many local variables",
123 "Too many initializers",
124 "Cannot initialize incomplete type",
126 "Operation not allowed with this type of argument",
128 "Struct/union has no field named `%s'",
129 "Struct pointer expected",
131 "Expression expected",
132 "Preprocessor expression expected",
134 "Illegal function call",
135 "Illegal indirection",
137 "Illegal macro call",
139 "Illegal character constant",
141 "Illegal type qualifier",
142 "Illegal storage class",
144 "Illegal segment name: `%s'",
146 "Modulo operation with zero",
148 "Symbol is already different kind",
149 "Too many lexical levels",
150 "Parameter name omitted",
151 "Old style function decl used as prototype",
152 "Declaration for parameter `%s' but no such parameter",
153 "Cannot take address of a register variable",
154 "Illegal size of data type",
155 "__fastcall__ is not allowed for C functions",
156 "Variable has unknown size",
157 "Unknown identifier: `%s'",
158 "Duplicate qualifier: `%s'",
159 "Assignment to const",
160 "Pointer types differ in type qualifiers",
165 static char* FatMsg [FAT_COUNT-1] = {
167 "Cannot open output file: %s",
168 "Cannot write to output file (disk full?)",
169 "Cannot open input file: %s",
173 "Out of string space",
174 "Too many case labels",
179 /* Count of errors/warnings */
180 unsigned ErrorCount = 0;
181 unsigned WarningCount = 0;
185 /*****************************************************************************/
187 /*****************************************************************************/
191 void Warning (unsigned WarnNum, ...)
192 /* Print warning message. */
197 fprintf (stderr, "%s(%u): Warning #%u: ",
198 GetCurrentFile(), curpos, WarnNum);
200 va_start (ap, WarnNum);
201 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
203 fprintf (stderr, "\n");
206 fprintf (stderr, "Line: %s\n", line);
214 void PPWarning (unsigned WarnNum, ...)
215 /* Print warning message. For use within the preprocessor. */
220 fprintf (stderr, "%s(%u): Warning #%u: ",
221 GetCurrentFile(), GetCurrentLine(), WarnNum);
223 va_start (ap, WarnNum);
224 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
226 fprintf (stderr, "\n");
233 void Error (unsigned ErrNum, ...)
234 /* Print an error message */
238 fprintf (stderr, "%s(%u): Error #%u: ",
239 GetCurrentFile(), curpos, ErrNum);
241 va_start (ap, ErrNum);
242 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
244 fprintf (stderr, "\n");
247 fprintf (stderr, "Line: %s\n", line);
250 if (ErrorCount > 10) {
251 Fatal (FAT_TOO_MANY_ERRORS);
257 void PPError (unsigned ErrNum, ...)
258 /* Print an error message. For use within the preprocessor. */
262 fprintf (stderr, "%s(%u): Error #%u: ",
263 GetCurrentFile(), GetCurrentLine(), ErrNum);
265 va_start (ap, ErrNum);
266 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
268 fprintf (stderr, "\n");
271 if (ErrorCount > 10) {
272 Fatal (FAT_TOO_MANY_ERRORS);
278 void Fatal (unsigned FatNum, ...)
279 /* Print a message about a fatal error and die */
283 fprintf (stderr, "%s(%u): Fatal #%u: ",
284 GetCurrentFile(), curpos, FatNum);
286 va_start (ap, FatNum);
287 vfprintf (stderr, FatMsg [FatNum-1], ap);
289 fprintf (stderr, "\n");
292 fprintf (stderr, "Line: %s\n", line);
299 void Internal (char* Format, ...)
300 /* Print a message about an internal compiler error and die. */
304 fprintf (stderr, "%s(%u): Internal compiler error:\n",
305 GetCurrentFile(), curpos);
307 va_start (ap, Format);
308 vfprintf (stderr, Format, ap);
310 fprintf (stderr, "\nLine: %s\n", line);
312 /* Use abort to create a core dump */
318 void ErrorReport (void)
319 /* Report errors (called at end of compile) */
321 if (ErrorCount == 0 && Verbose) {
322 printf ("No errors.\n");