1 /*****************************************************************************/
5 /* Error handling for the cc65 C compiler */
9 /* (C) 1998-2004 Ullrich von Bassewitz */
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", 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 PPWarning (const char* Format, ...)
100 /* Print warning message. For use within the preprocessor. */
103 va_start (ap, Format);
104 IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
110 static void IntError (const char* Filename, unsigned LineNo, const char* Msg, va_list ap)
111 /* Print an error message - internal function*/
113 fprintf (stderr, "%s(%u): Error: ", Filename, LineNo);
114 vfprintf (stderr, Msg, ap);
115 fprintf (stderr, "\n");
118 Print (stderr, 1, "Input: %.*s\n", SB_GetLen (Line), SB_GetConstBuf (Line));
121 if (ErrorCount > 10) {
122 Fatal ("Too many errors");
128 void Error (const char* Format, ...)
129 /* Print an error message */
132 va_start (ap, Format);
133 IntError (GetInputName (CurTok.LI), GetInputLine (CurTok.LI), Format, ap);
139 void PPError (const char* Format, ...)
140 /* Print an error message. For use within the preprocessor. */
143 va_start (ap, Format);
144 IntError (GetCurrentFile(), GetCurrentLine(), Format, ap);
150 void Fatal (const char* Format, ...)
151 /* Print a message about a fatal error and die */
155 const char* FileName;
158 FileName = GetInputName (CurTok.LI);
159 LineNum = GetInputLine (CurTok.LI);
161 FileName = GetCurrentFile ();
162 LineNum = GetCurrentLine ();
165 fprintf (stderr, "%s(%u): Fatal: ", FileName, LineNum);
167 va_start (ap, Format);
168 vfprintf (stderr, Format, ap);
170 fprintf (stderr, "\n");
173 Print (stderr, 1, "Input: %.*s\n", SB_GetLen (Line), SB_GetConstBuf (Line));
180 void Internal (const char* Format, ...)
181 /* Print a message about an internal compiler error and die. */
185 const char* FileName;
188 FileName = GetInputName (CurTok.LI);
189 LineNum = GetInputLine (CurTok.LI);
191 FileName = GetCurrentFile ();
192 LineNum = GetCurrentLine ();
195 fprintf (stderr, "%s(%u): Internal compiler error:\n",
198 va_start (ap, Format);
199 vfprintf (stderr, Format, ap);
203 fprintf (stderr, "\nInput: %.*s\n", SB_GetLen (Line), SB_GetConstBuf (Line));
206 /* Use abort to create a core dump */
212 void ErrorReport (void)
213 /* Report errors (called at end of compile) */
215 Print (stdout, 1, "%u errors, %u warnings\n", ErrorCount, WarningCount);