1 /*****************************************************************************/
5 /* Error handling for the cc65 C compiler */
9 /* (C) 1998-2009, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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 /*****************************************************************************/
53 /*****************************************************************************/
55 /*****************************************************************************/
59 /* Count of errors/warnings */
60 unsigned ErrorCount = 0;
61 unsigned WarningCount = 0;
65 /*****************************************************************************/
67 /*****************************************************************************/
71 static void IntWarning (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
72 /* Print warning message - internal function. */
74 if (!IS_Get (&WarnDisable)) {
75 fprintf (stderr, "%s(%u): Warning: ", Filename, LineNo);
76 vfprintf (stderr, Msg, ap);
77 fprintf (stderr, "\n");
80 Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
88 void Warning (const char* Format, ...)
89 /* Print warning message. */
92 va_start (ap, Format);
93 IntWarning (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
99 void LIWarning (const LineInfo* LI, const char* Format, ...)
100 /* Print a warning message with the line info given explicitly */
103 va_start (ap, Format);
104 IntWarning (GetInputName (LI), GetInputLine (LI), Format, ap);
110 void PPWarning (const char* Format, ...)
111 /* Print warning message. For use within the preprocessor. */
114 va_start (ap, Format);
115 IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
121 static void IntError (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
122 /* Print an error message - internal function*/
124 fprintf (stderr, "%s(%u): Error: ", Filename, LineNo);
125 vfprintf (stderr, Msg, ap);
126 fprintf (stderr, "\n");
129 Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
132 if (ErrorCount > 10) {
133 Fatal ("Too many errors");
139 void Error (const char* Format, ...)
140 /* Print an error message */
143 va_start (ap, Format);
144 IntError (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
150 void LIError (const LineInfo* LI, const char* Format, ...)
151 /* Print an error message with the line info given explicitly */
154 va_start (ap, Format);
155 IntError (GetInputName (LI), GetInputLine (LI), Format, ap);
161 void PPError (const char* Format, ...)
162 /* Print an error message. For use within the preprocessor. */
165 va_start (ap, Format);
166 IntError (GetCurrentFile(), GetCurrentLine(), Format, ap);
172 void Fatal (const char* Format, ...)
173 /* Print a message about a fatal error and die */
177 const char* FileName;
180 FileName = GetInputName (CurTok.LI);
181 LineNum = GetInputLine (CurTok.LI);
183 FileName = GetCurrentFile ();
184 LineNum = GetCurrentLine ();
187 fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
189 va_start (ap, Format);
190 vfprintf (stderr, Format, ap);
192 fprintf (stderr, "\n");
195 Print (stderr, 1, "Input: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
202 void Internal (const char* Format, ...)
203 /* Print a message about an internal compiler error and die. */
207 const char* FileName;
210 FileName = GetInputName (CurTok.LI);
211 LineNum = GetInputLine (CurTok.LI);
213 FileName = GetCurrentFile ();
214 LineNum = GetCurrentLine ();
217 fprintf (stderr, "%s(%u): Internal compiler error:\n",
220 va_start (ap, Format);
221 vfprintf (stderr, Format, ap);
223 fprintf (stderr, "\n");
226 fprintf (stderr, "\nInput: %.*s\n", (int) SB_GetLen (Line), SB_GetConstBuf (Line));
229 /* Use abort to create a core dump */
235 void ErrorReport (void)
236 /* Report errors (called at end of compile) */
238 Print (stdout, 1, "%u errors, %u warnings\n", ErrorCount, WarningCount);