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 "Symbol `%s' defined more than once",
111 "String literal expected",
113 "Function must return a value",
114 "Function cannot return a value",
115 "Unexpected `continue'",
116 "Undefined symbol: `%s'",
117 "Undefined label: `%s'",
118 "Include nesting too deep",
119 "Too many local variables",
120 "Too many initializers",
121 "Cannot initialize incomplete type",
123 "Operation not allowed on these types",
125 "Struct/union has no field named `%s'",
126 "Struct pointer expected",
128 "Expression expected",
129 "Preprocessor expression expected",
131 "Illegal function call",
132 "Illegal indirection",
134 "Illegal macro call",
136 "Illegal character constant",
138 "Illegal type qualifier",
139 "Illegal storage class",
140 "Illegal segment name: `%s'",
142 "Modulo operation with zero",
144 "Symbol is already different kind",
145 "Too many lexical levels",
146 "Parameter name omitted",
147 "Old style function decl used as prototype",
148 "Declaration for parameter `%s' but no such parameter",
149 "Cannot take address of a register variable",
150 "Illegal size of data type",
151 "__fastcall__ is not allowed for C functions",
152 "Variable has unknown size",
153 "Unknown identifier: `%s'",
154 "Duplicate qualifier: `%s'",
155 "Assignment to const",
160 static char* FatMsg [FAT_COUNT-1] = {
162 "Cannot open output file: %s",
163 "Cannot write to output file (disk full?)",
164 "Cannot open input file: %s",
168 "Out of string space",
169 "Too many case labels",
174 /* Count of errors/warnings */
175 unsigned ErrorCount = 0;
176 unsigned WarningCount = 0;
180 /*****************************************************************************/
182 /*****************************************************************************/
186 void Warning (unsigned WarnNum, ...)
187 /* Print warning message. */
192 fprintf (stderr, "%s(%u): Warning #%u: ",
193 GetCurrentFile(), curpos, WarnNum);
195 va_start (ap, WarnNum);
196 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
198 fprintf (stderr, "\n");
201 fprintf (stderr, "Line: %s\n", line);
209 void PPWarning (unsigned WarnNum, ...)
210 /* Print warning message. For use within the preprocessor. */
215 fprintf (stderr, "%s(%u): Warning #%u: ",
216 GetCurrentFile(), GetCurrentLine(), WarnNum);
218 va_start (ap, WarnNum);
219 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
221 fprintf (stderr, "\n");
228 void Error (unsigned ErrNum, ...)
229 /* Print an error message */
233 fprintf (stderr, "%s(%u): Error #%u: ",
234 GetCurrentFile(), curpos, ErrNum);
236 va_start (ap, ErrNum);
237 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
239 fprintf (stderr, "\n");
242 fprintf (stderr, "Line: %s\n", line);
245 if (ErrorCount > 10) {
246 Fatal (FAT_TOO_MANY_ERRORS);
252 void PPError (unsigned ErrNum, ...)
253 /* Print an error message. For use within the preprocessor. */
257 fprintf (stderr, "%s(%u): Error #%u: ",
258 GetCurrentFile(), GetCurrentLine(), ErrNum);
260 va_start (ap, ErrNum);
261 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
263 fprintf (stderr, "\n");
266 if (ErrorCount > 10) {
267 Fatal (FAT_TOO_MANY_ERRORS);
273 void Fatal (unsigned FatNum, ...)
274 /* Print a message about a fatal error and die */
278 fprintf (stderr, "%s(%u): Fatal #%u: ",
279 GetCurrentFile(), curpos, FatNum);
281 va_start (ap, FatNum);
282 vfprintf (stderr, FatMsg [FatNum-1], ap);
284 fprintf (stderr, "\n");
287 fprintf (stderr, "Line: %s\n", line);
294 void Internal (char* Format, ...)
295 /* Print a message about an internal compiler error and die. */
299 fprintf (stderr, "%s(%u): Internal compiler error:\n",
300 GetCurrentFile(), curpos);
302 va_start (ap, Format);
303 vfprintf (stderr, Format, ap);
305 fprintf (stderr, "\nLine: %s\n", line);
307 /* Use abort to create a core dump */
313 void ErrorReport (void)
314 /* Report errors (called at end of compile) */
316 if (ErrorCount == 0 && Verbose) {
317 printf ("No errors.\n");