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 /* Error messages sorted by ErrTypes */
55 static char* ErrMsg [ERR_COUNT-1] = {
67 "Identifier expected",
70 "Incompatible pointer types",
71 "Too many arguments in function call",
72 "Too few arguments in function call",
73 "Duplicate macro parameter: %s",
74 "Variable identifier expected",
75 "Integer expression expected",
76 "Constant expression expected",
78 "Redefinition of `%s'",
79 "Conflicting types for `%s'",
80 "String literal expected",
82 "Function must return a value",
83 "Function cannot return a value",
84 "Unexpected `continue'",
85 "Undefined symbol: `%s'",
86 "Undefined label: `%s'",
87 "Too many local variables",
88 "Too many initializers",
89 "Cannot initialize incomplete type",
91 "Operation not allowed with this type of argument",
93 "Struct/union has no field named `%s'",
94 "Struct pointer expected",
96 "Expression expected",
97 "Preprocessor expression expected",
99 "Illegal function call",
100 "Illegal indirection",
103 "Illegal character constant",
105 "Illegal type qualifier",
106 "Illegal storage class",
108 "Illegal segment name: `%s'",
110 "Modulo operation with zero",
112 "Symbol is already different kind",
113 "Too many lexical levels",
114 "Parameter name omitted",
115 "Old style function decl used as prototype",
116 "Declaration for parameter `%s' but no such parameter",
117 "Cannot take address of a register variable",
118 "Illegal size of data type",
119 "__fastcall__ is not allowed for C functions",
120 "Variable has unknown size",
121 "Unknown identifier: `%s'",
122 "Duplicate qualifier: `%s'",
123 "Assignment to const",
124 "Pointer types differ in type qualifiers",
129 /* Count of errors/warnings */
130 unsigned ErrorCount = 0;
131 unsigned WarningCount = 0;
135 /*****************************************************************************/
137 /*****************************************************************************/
141 static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
142 /* Print warning message - internal function. */
145 fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
146 vfprintf (stderr, Msg, ap);
147 fprintf (stderr, "\n");
150 fprintf (stderr, "Line: %s\n", line);
158 void Warning (const char* Format, ...)
159 /* Print warning message. */
162 va_start (ap, Format);
163 IntWarning (GetCurrentFile(), curpos, Format, ap);
169 void PPWarning (const char* Format, ...)
170 /* Print warning message. For use within the preprocessor. */
173 va_start (ap, Format);
174 IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
180 static void IntError (const char* Filename, unsigned Line, const char* Msg, va_list ap)
181 /* Print an error message - internal function*/
183 fprintf (stderr, "%s(%u): Error: ", Filename, Line);
184 vfprintf (stderr, Msg, ap);
185 fprintf (stderr, "\n");
188 fprintf (stderr, "Line: %s\n", line);
191 if (ErrorCount > 10) {
192 Fatal ("Too many errors");
198 void Error (unsigned ErrNum, ...)
199 /* Print an error message */
202 va_start (ap, ErrNum);
203 IntError (GetCurrentFile(), curpos, ErrMsg [ErrNum-1], ap);
209 void MError (const char* Format, ...)
210 /* Print an error message */
213 va_start (ap, Format);
214 IntError (GetCurrentFile(), curpos, Format, ap);
220 void PPError (const char* Format, ...)
221 /* Print an error message. For use within the preprocessor. */
224 va_start (ap, Format);
225 IntError (GetCurrentFile(), GetCurrentLine(), Format, ap);
231 void Fatal (const char* Format, ...)
232 /* Print a message about a fatal error and die */
236 fprintf (stderr, "%s(%u): Fatal: ", GetCurrentFile(), curpos);
238 va_start (ap, Format);
239 vfprintf (stderr, Format, ap);
241 fprintf (stderr, "\n");
244 fprintf (stderr, "Line: %s\n", line);
251 void Internal (char* Format, ...)
252 /* Print a message about an internal compiler error and die. */
256 fprintf (stderr, "%s(%u): Internal compiler error:\n",
257 GetCurrentFile(), curpos);
259 va_start (ap, Format);
260 vfprintf (stderr, Format, ap);
262 fprintf (stderr, "\nLine: %s\n", line);
264 /* Use abort to create a core dump */
270 void ErrorReport (void)
271 /* Report errors (called at end of compile) */
273 if (ErrorCount == 0 && Verbose) {
274 printf ("No errors.\n");