1 /*****************************************************************************/
5 /* Error handling for the cc65 C compiler */
9 /* (C) 1998 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 /*****************************************************************************/
49 /*****************************************************************************/
51 /*****************************************************************************/
55 static char* WarnMsg [WARN_COUNT-1] = {
57 "Condition is never true",
58 "Condition is always true",
59 "Converting pointer to integer without a cast",
60 "Converting integer to pointer without a cast",
61 "Function call without a prototype",
64 "Function must be extern",
65 "Parameter `%s' is never used",
66 "`%s' is defined but never used",
68 "`/*' found inside a comment",
69 "Useless declaration",
74 /* Error messages sorted by ErrTypes */
75 static char* ErrMsg [ERR_COUNT-1] = {
76 "Invalid character (%u)",
78 "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 "Open failure on include file `%s'",
105 "Invalid #error directive",
107 "Unexpected `#endif'",
108 "Unexpected `#else'",
110 "Compiler directive expected",
111 "Symbol `%s' defined more than once",
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 on these types",
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 storage class",
141 "Modulo operation with zero",
143 "Symbol is already different kind",
144 "Too many lexical levels",
145 "Parameter name omitted",
146 "Old style function decl used as prototype",
147 "Declaration for parameter `%s' but no such parameter",
148 "Cannot take address of a register variable",
149 "Illegal size of data type",
150 "__fastcall__ is not allowed for C functions",
151 "Variable has unknown size",
152 "Unknown identifier: `%s'",
157 static char* FatMsg [FAT_COUNT-1] = {
159 "Cannot open output file: %s",
160 "Cannot write to output file (disk full?)",
161 "Cannot open input file: %s",
165 "Out of string space",
166 "Too many case labels",
171 /* Count of errors/warnings */
172 unsigned ErrorCount = 0;
173 unsigned WarningCount = 0;
177 /*****************************************************************************/
179 /*****************************************************************************/
183 void Warning (unsigned WarnNum, ...)
184 /* Print warning message. */
189 fprintf (stderr, "%s(%u): Warning #%u: ",
190 GetCurrentFile(), curpos, WarnNum);
192 va_start (ap, WarnNum);
193 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
195 fprintf (stderr, "\n");
198 fprintf (stderr, "Line: %s\n", line);
206 void PPWarning (unsigned WarnNum, ...)
207 /* Print warning message. For use within the preprocessor. */
212 fprintf (stderr, "%s(%u): Warning #%u: ",
213 GetCurrentFile(), GetCurrentLine(), WarnNum);
215 va_start (ap, WarnNum);
216 vfprintf (stderr, WarnMsg [WarnNum-1], ap);
218 fprintf (stderr, "\n");
225 void Error (unsigned ErrNum, ...)
226 /* Print an error message */
230 fprintf (stderr, "%s(%u): Error #%u: ",
231 GetCurrentFile(), curpos, ErrNum);
233 va_start (ap, ErrNum);
234 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
236 fprintf (stderr, "\n");
239 fprintf (stderr, "Line: %s\n", line);
242 if (ErrorCount > 10) {
243 Fatal (FAT_TOO_MANY_ERRORS);
249 void PPError (unsigned ErrNum, ...)
250 /* Print an error message. For use within the preprocessor. */
254 fprintf (stderr, "%s(%u): Error #%u: ",
255 GetCurrentFile(), GetCurrentLine(), ErrNum);
257 va_start (ap, ErrNum);
258 vfprintf (stderr, ErrMsg [ErrNum-1], ap);
260 fprintf (stderr, "\n");
263 if (ErrorCount > 10) {
264 Fatal (FAT_TOO_MANY_ERRORS);
270 void Fatal (unsigned FatNum, ...)
271 /* Print a message about a fatal error and die */
275 fprintf (stderr, "%s(%u): Fatal #%u: ",
276 GetCurrentFile(), curpos, FatNum);
278 va_start (ap, FatNum);
279 vfprintf (stderr, FatMsg [FatNum-1], ap);
281 fprintf (stderr, "\n");
284 fprintf (stderr, "Line: %s\n", line);
291 void Internal (char* Format, ...)
292 /* Print a message about an internal compiler error and die. */
296 fprintf (stderr, "%s(%u): Internal compiler error:\n",
297 GetCurrentFile(), curpos);
299 va_start (ap, Format);
300 vfprintf (stderr, Format, ap);
302 fprintf (stderr, "\nLine: %s\n", line);
304 /* Use abort to create a core dump */
310 void ErrorReport (void)
311 /* Report errors (called at end of compile) */
313 if (ErrorCount == 0 && Verbose) {
314 printf ("No errors.\n");