]> git.sur5r.net Git - cc65/blob - src/ca65/error.h
c7bd9d86c97c0e964f6164837b5c0d08a30927f8
[cc65] / src / ca65 / error.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  error.h                                  */
4 /*                                                                           */
5 /*                Error handling for the ca65 macroassembler                 */
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 #ifndef ERROR_H
37 #define ERROR_H
38
39
40
41 #include "scanner.h"
42
43
44
45 /*****************************************************************************/
46 /*                                   Data                                    */
47 /*****************************************************************************/
48
49
50
51 /* Warning numbers */
52 enum Warnings {
53     WARN_NONE,                          /* No warning */
54     WARN_MASK_ERROR,
55     WARN_SYM_NOT_REFERENCED,
56     WARN_IMPORT_NOT_REFERENCED,
57     WARN_CANNOT_TRACK_STATUS,
58     WARN_USER,
59     WARN_COUNT                          /* Warning count */
60 };
61
62 /* Error numbers */
63 enum Errors {
64     ERR_NONE,                           /* No error */
65     ERR_NOT_IMPLEMENTED,                /* Command/operation not implemented */
66     ERR_CANNOT_OPEN_INCLUDE,
67     ERR_INCLUDE_NESTING,
68     ERR_INVALID_CHAR,
69     ERR_HEX_DIGIT_EXPECTED,
70     ERR_DIGIT_EXPECTED,
71     ERR_01_EXPECTED,
72     ERR_NUM_OVERFLOW,
73     ERR_PSEUDO_EXPECTED,
74     ERR_TOO_MANY_CHARS,
75     ERR_COLON_EXPECTED,
76     ERR_LPAREN_EXPECTED,
77     ERR_RPAREN_EXPECTED,
78     ERR_RBRACK_EXPECTED,
79     ERR_COMMA_EXPECTED,
80     ERR_ONOFF_EXPECTED,
81     ERR_Y_EXPECTED,
82     ERR_X_EXPECTED,
83     ERR_INTCON_EXPECTED,
84     ERR_STRCON_EXPECTED,
85     ERR_CHARCON_EXPECTED,
86     ERR_CONSTEXPR_EXPECTED,
87     ERR_IDENT_EXPECTED,
88     ERR_ENDMACRO_EXPECTED,
89     ERR_OPTION_KEY_EXPECTED,
90     ERR_816_MODE_ONLY,
91     ERR_USER,
92     ERR_STRING_TOO_LONG,
93     ERR_NEWLINE_IN_STRING,
94     ERR_ILLEGAL_CHARCON,
95     ERR_ILLEGAL_ADDR_MODE,
96     ERR_ILLEGAL_LOCALSTART,
97     ERR_ILLEGAL_LOCAL_USE,
98     ERR_ILLEGAL_SEGMENT,
99     ERR_ILLEGAL_SEG_ATTR,
100     ERR_ILLEGAL_MACPACK,
101     ERR_ILLEGAL_FEATURE,
102     ERR_SYNTAX,
103     ERR_SYM_ALREADY_DEFINED,
104     ERR_SYM_UNDEFINED,
105     ERR_SYM_ALREADY_IMPORT,
106     ERR_SYM_ALREADY_EXPORT,
107     ERR_EXPORT_UNDEFINED,
108     ERR_EXPORT_MUST_BE_CONST,
109     ERR_IF_NESTING,
110     ERR_UNEXPECTED_EOF,
111     ERR_UNEXPECTED_EOL,
112     ERR_UNEXPECTED,
113     ERR_DIV_BY_ZERO,
114     ERR_MOD_BY_ZERO,
115     ERR_RANGE,
116     ERR_TOO_MANY_PARAMS,
117     ERR_MACRO_PARAM_EXPECTED,
118     ERR_CIRCULAR_REFERENCE,
119     ERR_SYM_REDECL_MISMATCH,
120     ERR_ALIGN,
121     ERR_DUPLICATE_ELSE,
122     ERR_OPEN_IF,
123     ERR_OPEN_PROC,
124     ERR_SEG_ATTR_MISMATCH,
125     ERR_CPU_NOT_SUPPORTED,
126     ERR_COUNTER_UNDERFLOW,
127     ERR_UNDEFINED_LABEL,
128     ERR_OPEN_STMT,
129     ERR_COUNT                           /* Error count */
130 };
131
132 /* Fatal errors */
133 enum Fatals {
134     FAT_NONE,
135     FAT_MAX_INPUT_FILES,
136     FAT_OUT_OF_MEMORY,
137     FAT_TOO_MANY_SEGMENTS,
138     FAT_STRING_TOO_LONG,
139     FAT_CANNOT_OPEN_INPUT,
140     FAT_CANNOT_STAT_INPUT,
141     FAT_CANNOT_OPEN_OUTPUT,
142     FAT_CANNOT_WRITE_OUTPUT,
143     FAT_CANNOT_OPEN_LISTING,
144     FAT_CANNOT_WRITE_LISTING,
145     FAT_CANNOT_READ_LISTING,
146     FAT_NESTING,
147     FAT_TOO_MANY_SYMBOLS,
148     FAT_COUNT                           /* Fatal error count */
149 };
150
151
152
153 /* Warning levels */
154 extern unsigned         WarnLevel;
155
156 /* Messages for internal compiler errors */
157 extern const char _MsgCheckFailed [];
158 extern const char _MsgPrecondition [];
159 extern const char _MsgFail [];
160
161 /* Statistics */
162 extern unsigned ErrorCount;
163 extern unsigned WarningCount;
164
165
166
167 /*****************************************************************************/
168 /*                                   Code                                    */
169 /*****************************************************************************/
170
171
172
173 void Warning (unsigned WarnNum, ...);
174 /* Print warning message. */
175
176 void PWarning (const FilePos* Pos, unsigned WarnNum, ...);
177 /* Print warning message giving an explicit file and position. */
178
179 void Error (unsigned ErrNum, ...);
180 /* Print an error message */
181
182 void PError (const FilePos* Pos, unsigned ErrNum, ...);
183 /* Print an error message giving an explicit file and position. */
184
185 void ErrorSkip (unsigned ErrNum, ...);
186 /* Print an error message and skip the rest of the line */
187
188 void Fatal (unsigned FatNum, ...);
189 /* Print a message about a fatal error and die */
190
191 void Internal (const char* Format, ...);
192 /* Print a message about an internal compiler error and die. */
193
194 #define CHECK(c)                                                        \
195     if (!(c))                                                           \
196         Internal (_MsgCheckFailed, #c, c, __FILE__, __LINE__)
197
198 #define PRECONDITION(c)                                                 \
199     if (!(c))                                                           \
200         Internal (_MsgPrecondition, #c, c, __FILE__, __LINE__)
201
202 #define FAIL(s)                                                         \
203     Internal (_MsgFail, s, __FILE__, __LINE__)
204
205
206
207 /* End of error.h */
208
209 #endif
210
211
212
213