]> git.sur5r.net Git - cc65/blob - src/cc65/error.c
Removed error numbers in favour of literal error messages. The error numbers
[cc65] / src / cc65 / error.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  error.c                                  */
4 /*                                                                           */
5 /*                  Error handling for the cc65 C compiler                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2000 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdarg.h>
39
40 #include "global.h"
41 #include "input.h"
42 #include "scanner.h"
43 #include "stmt.h"
44 #include "error.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54 /* Count of errors/warnings */
55 unsigned ErrorCount     = 0;
56 unsigned WarningCount   = 0;
57
58
59
60 /*****************************************************************************/
61 /*                                   Code                                    */
62 /*****************************************************************************/
63
64
65
66 static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
67 /* Print warning message - internal function. */
68 {
69     if (!NoWarn) {
70         fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
71         vfprintf (stderr, Msg, ap);
72         fprintf (stderr, "\n");
73
74         if (Verbose) {
75             fprintf (stderr, "Line: %s\n", line);
76         }
77         ++WarningCount;
78     }
79 }
80
81
82
83 void Warning (const char* Format, ...)
84 /* Print warning message. */
85 {
86     va_list ap;
87     va_start (ap, Format);
88     IntWarning (GetCurrentFile(), curpos, Format, ap);
89     va_end (ap);
90 }
91
92
93
94 void PPWarning (const char* Format, ...)
95 /* Print warning message. For use within the preprocessor. */
96 {
97     va_list ap;
98     va_start (ap, Format);
99     IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
100     va_end (ap);
101 }
102
103
104
105 static void IntError (const char* Filename, unsigned Line, const char* Msg, va_list ap)
106 /* Print an error message - internal function*/
107 {
108     fprintf (stderr, "%s(%u): Error: ", Filename, Line);
109     vfprintf (stderr, Msg, ap);
110     fprintf (stderr, "\n");
111
112     if (Verbose) {
113         fprintf (stderr, "Line: %s\n", line);
114     }
115     ++ErrorCount;
116     if (ErrorCount > 10) {
117         Fatal ("Too many errors");
118     }
119 }
120
121
122
123 void Error (const char* Format, ...)
124 /* Print an error message */
125 {
126     va_list ap;
127     va_start (ap, Format);
128     IntError (GetCurrentFile(), curpos, Format, ap);
129     va_end (ap);
130 }
131
132
133
134 void PPError (const char* Format, ...)
135 /* Print an error message. For use within the preprocessor.  */
136 {
137     va_list ap;
138     va_start (ap, Format);
139     IntError (GetCurrentFile(), GetCurrentLine(), Format, ap);
140     va_end (ap);
141 }
142
143
144
145 void Fatal (const char* Format, ...)
146 /* Print a message about a fatal error and die */
147 {
148     va_list ap;
149
150     fprintf (stderr, "%s(%u): Fatal: ", GetCurrentFile(), curpos);
151
152     va_start (ap, Format);
153     vfprintf (stderr, Format, ap);
154     va_end (ap);
155     fprintf (stderr, "\n");
156
157     if (Verbose) {
158         fprintf (stderr, "Line: %s\n", line);
159     }
160     exit (EXIT_FAILURE);
161 }
162
163
164
165 void Internal (char* Format, ...)
166 /* Print a message about an internal compiler error and die. */
167 {
168     va_list ap;
169
170     fprintf (stderr, "%s(%u): Internal compiler error:\n",
171              GetCurrentFile(), curpos);
172
173     va_start (ap, Format);
174     vfprintf (stderr, Format, ap);
175     va_end (ap);
176     fprintf (stderr, "\nLine: %s\n", line);
177
178     /* Use abort to create a core dump */
179     abort ();
180 }
181
182
183
184 void ErrorReport (void)
185 /* Report errors (called at end of compile) */
186 {
187     if (ErrorCount == 0 && Verbose) {
188         printf ("No errors.\n");
189     }
190 }
191
192
193
194