]> git.sur5r.net Git - cc65/blob - src/cc65/error.c
Moved verbose output to a shared module in the common/ directory.
[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 /* common */
41 #include "print.h"
42
43 /* cc65 */
44 #include "global.h"
45 #include "input.h"
46 #include "scanner.h"
47 #include "stmt.h"
48 #include "error.h"
49
50
51
52 /*****************************************************************************/
53 /*                                   Data                                    */
54 /*****************************************************************************/
55
56
57
58 /* Count of errors/warnings */
59 unsigned ErrorCount     = 0;
60 unsigned WarningCount   = 0;
61
62
63
64 /*****************************************************************************/
65 /*                                   Code                                    */
66 /*****************************************************************************/
67
68
69
70 static void IntWarning (const char* Filename, unsigned Line, const char* Msg, va_list ap)
71 /* Print warning message - internal function. */
72 {
73     if (!NoWarn) {
74         fprintf (stderr, "%s(%u): Warning: ", Filename, Line);
75         vfprintf (stderr, Msg, ap);
76         fprintf (stderr, "\n");
77
78         Print (stderr, 1, "Line: %s\n", line);
79         ++WarningCount;
80     }
81 }
82
83
84
85 void Warning (const char* Format, ...)
86 /* Print warning message. */
87 {
88     va_list ap;
89     va_start (ap, Format);
90     IntWarning (GetCurrentFile(), curpos, Format, ap);
91     va_end (ap);
92 }
93
94
95
96 void PPWarning (const char* Format, ...)
97 /* Print warning message. For use within the preprocessor. */
98 {
99     va_list ap;
100     va_start (ap, Format);
101     IntWarning (GetCurrentFile(), GetCurrentLine(), Format, ap);
102     va_end (ap);
103 }
104
105
106
107 static void IntError (const char* Filename, unsigned Line, const char* Msg, va_list ap)
108 /* Print an error message - internal function*/
109 {
110     fprintf (stderr, "%s(%u): Error: ", Filename, Line);
111     vfprintf (stderr, Msg, ap);
112     fprintf (stderr, "\n");
113
114     Print (stderr, 1, "Line: %s\n", line);
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     Print (stderr, 1, "Line: %s\n", line);
158     exit (EXIT_FAILURE);
159 }
160
161
162
163 void Internal (char* Format, ...)
164 /* Print a message about an internal compiler error and die. */
165 {
166     va_list ap;
167
168     fprintf (stderr, "%s(%u): Internal compiler error:\n",
169              GetCurrentFile(), curpos);
170
171     va_start (ap, Format);
172     vfprintf (stderr, Format, ap);
173     va_end (ap);
174     fprintf (stderr, "\nLine: %s\n", line);
175
176     /* Use abort to create a core dump */
177     abort ();
178 }
179
180
181
182 void ErrorReport (void)
183 /* Report errors (called at end of compile) */
184 {
185     if (ErrorCount == 0 && Verbosity > 0) {
186         printf ("No errors.\n");
187     }
188 }
189
190
191
192