/
exceptions.h
307 lines (273 loc) · 9.25 KB
/
exceptions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/* exceptions.h
* Copyright (C) 2001-2010, Parrot Foundation.
* SVN Info
* $Id$
* Overview:
* define the internal interpreter exceptions
* Data Structure and Algorithms:
* History:
* Notes:
* References:
*/
#ifndef PARROT_EXCEPTIONS_H_GUARD
#define PARROT_EXCEPTIONS_H_GUARD
#include "parrot/compiler.h"
/* Prototypes */
/* Exception Types
* the first types are real exceptions and have Python exception
* names.
*/
/* &gen_from_enum(except_types.pasm) */
typedef enum {
EXCEPTION_BAD_BUFFER_SIZE,
EXCEPTION_MISSING_ENCODING_NAME,
EXCEPTION_INVALID_STRING_REPRESENTATION,
EXCEPTION_ICU_ERROR,
EXCEPTION_UNIMPLEMENTED,
EXCEPTION_NULL_REG_ACCESS,
EXCEPTION_NO_REG_FRAMES,
EXCEPTION_SUBSTR_OUT_OF_STRING,
EXCEPTION_ORD_OUT_OF_STRING,
EXCEPTION_MALFORMED_UTF8,
EXCEPTION_MALFORMED_UTF16,
EXCEPTION_MALFORMED_UTF32,
EXCEPTION_INVALID_CHARACTER,
EXCEPTION_INVALID_CHARTYPE,
EXCEPTION_INVALID_ENCODING,
EXCEPTION_INVALID_CHARCLASS,
EXCEPTION_NEG_REPEAT,
EXCEPTION_NEG_SUBSTR,
EXCEPTION_NEG_SLEEP,
EXCEPTION_NEG_CHOP,
EXCEPTION_INVALID_OPERATION,
EXCEPTION_ARG_OP_NOT_HANDLED,
EXCEPTION_KEY_NOT_FOUND,
EXCEPTION_JIT_UNAVAILABLE,
EXCEPTION_EXEC_UNAVAILABLE,
EXCEPTION_INTERP_ERROR,
EXCEPTION_PARROT_USAGE_ERROR,
EXCEPTION_PIO_ERROR,
EXCEPTION_PARROT_POINTER_ERROR,
EXCEPTION_DIV_BY_ZERO,
EXCEPTION_PIO_NOT_IMPLEMENTED,
EXCEPTION_ALLOCATION_ERROR,
EXCEPTION_INTERNAL_PANIC,
EXCEPTION_OUT_OF_BOUNDS,
EXCEPTION_JIT_ERROR,
EXCEPTION_EXEC_ERROR,
EXCEPTION_ILL_INHERIT,
EXCEPTION_NO_PREV_CS,
EXCEPTION_NO_CLASS,
EXCEPTION_LEX_NOT_FOUND,
EXCEPTION_PAD_NOT_FOUND,
EXCEPTION_ATTRIB_NOT_FOUND,
EXCEPTION_GLOBAL_NOT_FOUND,
EXCEPTION_EXTERNAL_ERROR,
EXCEPTION_METHOD_NOT_FOUND,
EXCEPTION_VTABLE_NOT_FOUND,
EXCEPTION_WRITE_TO_CONSTCLASS,
EXCEPTION_NOSPAWN,
EXCEPTION_INTERNAL_NOT_IMPLEMENTED,
EXCEPTION_ERR_OVERFLOW,
EXCEPTION_LOSSY_CONVERSION,
EXCEPTION_ROLE_COMPOSITION_METHOD_CONFLICT,
EXCEPTION_UNEXPECTED_NULL,
EXCEPTION_LIBRARY_ERROR,
EXCEPTION_LIBRARY_NOT_LOADED,
EXCEPTION_SYNTAX_ERROR,
EXCEPTION_MALFORMED_PACKFILE,
CONTROL_RETURN,
CONTROL_OK,
CONTROL_BREAK,
CONTROL_CONTINUE,
CONTROL_ERROR,
CONTROL_TAKE,
CONTROL_LEAVE,
CONTROL_EXIT,
CONTROL_LOOP_NEXT,
CONTROL_LOOP_LAST,
CONTROL_LOOP_REDO
} exception_type_enum;
/* &end_gen */
/* &gen_from_enum(except_severity.pasm) subst(s/(\w+)/uc($1)/e) */
typedef enum {
EXCEPT_normal = 0,
EXCEPT_warning = 1,
EXCEPT_error = 2,
EXCEPT_severe = 3,
EXCEPT_fatal = 4,
EXCEPT_doomed = 5,
EXCEPT_exit = 6
} exception_severity;
/* &end_gen */
/* HEADERIZER BEGIN: src/exceptions.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void do_panic(
NULLOK_INTERP,
ARGIN_NULLOK(const char *message),
ARGIN_NULLOK(const char *file),
unsigned int line);
PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void exit_fatal(int exitcode, ARGIN(const char *format), ...)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_DOES_NOT_RETURN_WHEN_FALSE
void Parrot_assert(
INTVAL condition,
ARGIN(const char *condition_string),
ARGIN(const char *file),
unsigned int line)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void Parrot_confess(
ARGIN(const char *cond),
ARGIN(const char *file),
unsigned int line)
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
void Parrot_ex_add_c_handler(PARROT_INTERP, ARGIN(Parrot_runloop *jp))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
PMC * Parrot_ex_build_exception(PARROT_INTERP,
INTVAL severity,
long error,
ARGIN_NULLOK(STRING *msg))
__attribute__nonnull__(1);
PARROT_EXPORT
void Parrot_ex_mark_unhandled(PARROT_INTERP, ARGIN(PMC *exception))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void Parrot_ex_rethrow_from_c(PARROT_INTERP, ARGIN(PMC *exception))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
opcode_t * Parrot_ex_rethrow_from_op(PARROT_INTERP, ARGIN(PMC *exception))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void Parrot_ex_throw_from_c(PARROT_INTERP, ARGIN(PMC *exception))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_DOES_NOT_RETURN
PARROT_COLD
void Parrot_ex_throw_from_c_args(PARROT_INTERP,
SHIM(void *ret_addr),
int exitcode,
ARGIN(const char *format),
...)
__attribute__nonnull__(1)
__attribute__nonnull__(4);
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
opcode_t * Parrot_ex_throw_from_op(PARROT_INTERP,
ARGIN(PMC *exception),
ARGIN_NULLOK(void *dest))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_EXPORT
PARROT_CAN_RETURN_NULL
opcode_t * Parrot_ex_throw_from_op_args(PARROT_INTERP,
ARGIN_NULLOK(void *dest),
int ex_type,
ARGIN(const char *format),
...)
__attribute__nonnull__(1)
__attribute__nonnull__(4);
PARROT_DOES_NOT_RETURN
PARROT_COLD
void die_from_exception(PARROT_INTERP, ARGIN(PMC *exception))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
void Parrot_print_backtrace(void);
#define ASSERT_ARGS_do_panic __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
#define ASSERT_ARGS_exit_fatal __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(format))
#define ASSERT_ARGS_Parrot_assert __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(condition_string) \
, PARROT_ASSERT_ARG(file))
#define ASSERT_ARGS_Parrot_confess __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(cond) \
, PARROT_ASSERT_ARG(file))
#define ASSERT_ARGS_Parrot_ex_add_c_handler __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(jp))
#define ASSERT_ARGS_Parrot_ex_build_exception __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
#define ASSERT_ARGS_Parrot_ex_mark_unhandled __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(exception))
#define ASSERT_ARGS_Parrot_ex_rethrow_from_c __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(exception))
#define ASSERT_ARGS_Parrot_ex_rethrow_from_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(exception))
#define ASSERT_ARGS_Parrot_ex_throw_from_c __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(exception))
#define ASSERT_ARGS_Parrot_ex_throw_from_c_args __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(format))
#define ASSERT_ARGS_Parrot_ex_throw_from_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(exception))
#define ASSERT_ARGS_Parrot_ex_throw_from_op_args __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(format))
#define ASSERT_ARGS_die_from_exception __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(exception))
#define ASSERT_ARGS_Parrot_print_backtrace __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/exceptions.c */
#define PANIC(interp, message) do_panic((interp), (message), __FILE__, __LINE__)
/* having a modified version of PARROT_ASSERT which resolves as an integer
* rvalue lets us put ASSERT_ARGS() at the top of the list of local variables.
* Thus, we can catch bad pointers before any of the local initialization
* logic is run. And it always returns 0, so headerizer can chain them in
* ASSERT_ARGS_* macros like:
* int _ASSERT_ARGS = PARROT_ASSERT_ARG(a) || PARROT_ASSERT_ARG(b) || ...
*/
#ifdef NDEBUG
# define PARROT_ASSERT(x) /*@-noeffect@*/((void)0)/*@=noeffect@*/
# define PARROT_ASSERT_ARG(x) (0)
# define PARROT_FAILURE(x) /*@-noeffect@*/((void)0)/*@=noeffect@*/
# define PARROT_ASSERT_MSG(x, s) /*@-noeffect@*/((void)0)/*@=noeffect@*/
# define ASSERT_ARGS(a)
#else
# define PARROT_ASSERT(x) (x) ? ((void)0) : Parrot_confess(#x, __FILE__, __LINE__)
# define PARROT_ASSERT_ARG(x) ((x) ? (0) : (Parrot_confess(#x, __FILE__, __LINE__), 0))
# define PARROT_FAILURE(x) Parrot_confess((x), __FILE__, __LINE__)
# define PARROT_ASSERT_MSG(x, s) ((x) ? (0) : (Parrot_confess(s, __FILE__, __LINE__), 0))
# ifdef __GNUC__
# define ASSERT_ARGS(a) ASSERT_ARGS_ ## a ;
# else
# define ASSERT_ARGS(a)
# endif /* __GNUC__ */
#endif /* NDEBUG */
#endif /* PARROT_EXCEPTIONS_H_GUARD */
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/