]>
Commit | Line | Data |
---|---|---|
e2c09482 BK |
1 | // new abi support -*- C++ -*- |
2 | ||
3 | // Copyright (C) 2000 Free Software Foundation, Inc. | |
4 | // | |
6305f20a BK |
5 | // This file is part of GNU CC. |
6 | // | |
7 | // GNU CC is free software; you can redistribute it and/or modify | |
8 | // it under the terms of the GNU General Public License as published by | |
9 | // the Free Software Foundation; either version 2, or (at your option) | |
10 | // any later version. | |
11 | // | |
12 | // GNU CC is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | // | |
17 | // You should have received a copy of the GNU General Public License | |
18 | // along with GNU CC; see the file COPYING. If not, write to | |
19 | // the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | // Boston, MA 02111-1307, USA. | |
21 | ||
22 | // As a special exception, you may use this file as part of a free software | |
23 | // library without restriction. Specifically, if other files instantiate | |
24 | // templates or use macros or inline functions from this file, or you compile | |
25 | // this file and link it with other files to produce an executable, this | |
26 | // file does not by itself cause the resulting executable to be covered by | |
27 | // the GNU General Public License. This exception does not however | |
28 | // invalidate any other reasons why the executable file might be covered by | |
29 | // the GNU General Public License. | |
30 | ||
e2c09482 BK |
31 | // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com> |
32 | ||
6305f20a BK |
33 | /* This file declares the new abi entry points into the runtime. It is not |
34 | normally necessary for user programs to include this header, or use the | |
35 | entry points directly. However, this header is available should that be | |
36 | needed. | |
37 | ||
38 | Some of the entry points are intended for both C and C++, thus this header | |
39 | is includable from both C and C++. Though the C++ specific parts are not | |
40 | available in C, naturally enough. */ | |
41 | ||
42 | #ifndef __CXXABI_H | |
43 | #define __CXXABI_H 1 | |
44 | ||
6305f20a BK |
45 | #ifdef __cplusplus |
46 | ||
47 | // We use the compiler builtins __SIZE_TYPE__ and __PTRDIFF_TYPE__ instead of | |
48 | // std::size_t and std::ptrdiff_t respectively. This makes us independant of | |
49 | // the conformance level of <cstddef> and whether -fhonor-std was supplied. | |
50 | // <cstddef> is not currently available during compiler building anyway. | |
51 | // Including <stddef.h> would be wrong, as that would rudely place size_t in | |
52 | // the global namespace. | |
53 | ||
54 | #include <typeinfo> | |
55 | ||
56 | namespace __cxxabiv1 | |
57 | { | |
58 | ||
59 | /* type information for int, float etc */ | |
60 | class __fundamental_type_info | |
61 | : public std::type_info | |
62 | { | |
63 | public: | |
64 | virtual ~__fundamental_type_info (); | |
65 | public: | |
66 | explicit __fundamental_type_info (const char *__n) | |
67 | : std::type_info (__n) | |
68 | { } | |
69 | }; | |
70 | ||
71 | /* type information for array objects */ | |
72 | class __array_type_info | |
73 | : public std::type_info | |
74 | { | |
75 | /* abi defined member functions */ | |
76 | protected: | |
77 | virtual ~__array_type_info (); | |
78 | public: | |
79 | explicit __array_type_info (const char *__n) | |
80 | : std::type_info (__n) | |
81 | { } | |
82 | }; | |
83 | ||
84 | /* type information for functions (both member and non-member) */ | |
85 | class __function_type_info | |
86 | : public std::type_info | |
87 | { | |
88 | /* abi defined member functions */ | |
89 | public: | |
90 | virtual ~__function_type_info (); | |
91 | public: | |
92 | explicit __function_type_info (const char *__n) | |
93 | : std::type_info (__n) | |
94 | { } | |
95 | ||
96 | /* implementation defined member functions */ | |
97 | protected: | |
98 | virtual bool __is_function_p () const; | |
99 | }; | |
100 | ||
101 | /* type information for enumerations */ | |
102 | class __enum_type_info | |
103 | : public std::type_info | |
104 | { | |
105 | /* abi defined member functions */ | |
106 | public: | |
107 | virtual ~__enum_type_info (); | |
108 | public: | |
109 | explicit __enum_type_info (const char *__n) | |
110 | : std::type_info (__n) | |
111 | { } | |
112 | }; | |
113 | ||
114 | /* common type information for simple pointers and pointers to member */ | |
115 | class __pbase_type_info | |
116 | : public std::type_info | |
117 | { | |
118 | /* abi defined member variables */ | |
119 | public: | |
120 | unsigned int __qualifier_flags; /* qualification of the target object */ | |
121 | const std::type_info *__pointee; /* type of pointed to object */ | |
122 | ||
123 | /* abi defined member functions */ | |
124 | public: | |
125 | virtual ~__pbase_type_info (); | |
126 | public: | |
127 | explicit __pbase_type_info (const char *__n, | |
128 | int __quals, | |
129 | const std::type_info *__type) | |
130 | : std::type_info (__n), __qualifier_flags (__quals), __pointee (__type) | |
131 | { } | |
132 | ||
133 | /* implementation defined types */ | |
134 | public: | |
135 | enum __qualifier_masks { | |
136 | __const_mask = 0x1, | |
137 | __volatile_mask = 0x2, | |
138 | __restrict_mask = 0x4, | |
139 | __incomplete_mask = 0x8, | |
140 | __incomplete_class_mask = 0x10 | |
141 | }; | |
142 | ||
143 | /* implementation defined member functions */ | |
144 | protected: | |
145 | virtual bool __do_catch (const std::type_info *__thr_type, | |
146 | void **__thr_obj, | |
147 | unsigned __outer) const; | |
148 | protected: | |
149 | inline virtual bool __pointer_catch (const __pbase_type_info *__thr_type, | |
150 | void **__thr_obj, | |
151 | unsigned __outer) const; | |
152 | }; | |
153 | ||
154 | /* type information for simple pointers */ | |
155 | class __pointer_type_info | |
156 | : public __pbase_type_info | |
157 | { | |
158 | /* abi defined member functions */ | |
159 | public: | |
160 | virtual ~__pointer_type_info (); | |
161 | public: | |
162 | explicit __pointer_type_info (const char *__n, | |
163 | int __quals, | |
164 | const std::type_info *__type) | |
165 | : __pbase_type_info (__n, __quals, __type) | |
166 | { } | |
167 | ||
168 | /* implementation defined member functions */ | |
169 | protected: | |
170 | virtual bool __is_pointer_p () const; | |
171 | ||
172 | protected: | |
173 | virtual bool __pointer_catch (const __pbase_type_info *__thr_type, | |
174 | void **__thr_obj, | |
175 | unsigned __outer) const; | |
176 | }; | |
177 | ||
178 | /* type information for a pointer to member variable */ | |
179 | class __pointer_to_member_type_info | |
180 | : public __pbase_type_info | |
181 | { | |
182 | /* abi defined member variables */ | |
183 | public: | |
184 | __class_type_info *__context_class; /* class of the member */ | |
185 | ||
186 | /* abi defined member functions */ | |
187 | public: | |
188 | virtual ~__pointer_to_member_type_info (); | |
189 | public: | |
190 | explicit __pointer_to_member_type_info (const char *__n, | |
191 | int __quals, | |
192 | const std::type_info *__type, | |
193 | __class_type_info *__klass) | |
194 | : __pbase_type_info (__n, __quals, __type), __context_class (__klass) | |
195 | { } | |
196 | ||
197 | /* implementation defined member functions */ | |
198 | protected: | |
199 | virtual bool __pointer_catch (const __pbase_type_info *__thr_type, | |
200 | void **__thr_obj, | |
201 | unsigned __outer) const; | |
202 | }; | |
203 | ||
204 | class __class_type_info; | |
205 | ||
206 | /* helper class for __vmi_class_type */ | |
207 | class __base_class_info | |
208 | { | |
209 | /* abi defined member variables */ | |
210 | public: | |
211 | const __class_type_info *__base; /* base class type */ | |
212 | long __offset_flags; /* offset and info */ | |
213 | ||
214 | /* implementation defined types */ | |
215 | public: | |
216 | enum __offset_flags_masks { | |
217 | __virtual_mask = 0x1, | |
218 | __public_mask = 0x2, | |
219 | hwm_bit = 2, | |
220 | offset_shift = 8 /* bits to shift offset by */ | |
221 | }; | |
222 | ||
223 | /* implementation defined member functions */ | |
224 | public: | |
225 | bool __is_virtual_p () const | |
226 | { return __offset_flags & __virtual_mask; } | |
227 | bool __is_public_p () const | |
228 | { return __offset_flags & __public_mask; } | |
229 | __PTRDIFF_TYPE__ __offset () const | |
230 | { | |
231 | // This shift, being of a signed type, is implementation defined. GCC | |
232 | // implements such shifts as arithmetic, which is what we want. | |
233 | return static_cast<__PTRDIFF_TYPE__> (__offset_flags) >> offset_shift; | |
234 | } | |
235 | }; | |
236 | ||
237 | /* type information for a class */ | |
238 | class __class_type_info | |
239 | : public std::type_info | |
240 | { | |
241 | /* abi defined member functions */ | |
242 | public: | |
243 | virtual ~__class_type_info (); | |
244 | public: | |
245 | explicit __class_type_info (const char *__n) | |
246 | : type_info (__n) | |
247 | { } | |
248 | ||
249 | /* implementation defined types */ | |
250 | public: | |
251 | /* sub_kind tells us about how a base object is contained within a derived | |
252 | object. We often do this lazily, hence the UNKNOWN value. At other times | |
253 | we may use NOT_CONTAINED to mean not publicly contained. */ | |
254 | enum __sub_kind | |
255 | { | |
256 | __unknown = 0, /* we have no idea */ | |
257 | __not_contained, /* not contained within us (in some */ | |
258 | /* circumstances this might mean not contained */ | |
259 | /* publicly) */ | |
260 | __contained_ambig, /* contained ambiguously */ | |
261 | ||
262 | __contained_virtual_mask = __base_class_info::__virtual_mask, /* via a virtual path */ | |
263 | __contained_public_mask = __base_class_info::__public_mask, /* via a public path */ | |
264 | __contained_mask = 1 << __base_class_info::hwm_bit, /* contained within us */ | |
265 | ||
266 | __contained_private = __contained_mask, | |
267 | __contained_public = __contained_mask | __contained_public_mask | |
268 | }; | |
269 | ||
270 | public: | |
271 | struct __upcast_result; | |
272 | struct __dyncast_result; | |
273 | ||
274 | /* implementation defined member functions */ | |
275 | protected: | |
276 | virtual bool __do_upcast (const __class_type_info *__dst_type, void **__obj_ptr) const; | |
277 | ||
278 | protected: | |
279 | virtual bool __do_catch (const type_info *__thr_type, void **__thr_obj, | |
280 | unsigned __outer) const; | |
281 | ||
282 | ||
283 | public: | |
284 | /* Helper for upcast. See if DST is us, or one of our bases. */ | |
285 | /* Return false if not found, true if found. */ | |
286 | virtual bool __do_upcast (const __class_type_info *__dst, | |
287 | const void *__obj, | |
288 | __upcast_result &__restrict __result) const; | |
289 | ||
290 | public: | |
291 | /* Indicate whether SRC_PTR of type SRC_TYPE is contained publicly within | |
292 | OBJ_PTR. OBJ_PTR points to a base object of our type, which is the | |
293 | destination type. SRC2DST indicates how SRC objects might be contained | |
294 | within this type. If SRC_PTR is one of our SRC_TYPE bases, indicate the | |
295 | virtuality. Returns not_contained for non containment or private | |
296 | containment. */ | |
297 | inline __sub_kind __find_public_src (__PTRDIFF_TYPE__ __src2dst, | |
298 | const void *__obj_ptr, | |
299 | const __class_type_info *__src_type, | |
300 | const void *__src_ptr) const; | |
301 | ||
302 | public: | |
303 | /* dynamic cast helper. ACCESS_PATH gives the access from the most derived | |
304 | object to this base. DST_TYPE indicates the desired type we want. OBJ_PTR | |
305 | points to a base of our type within the complete object. SRC_TYPE | |
306 | indicates the static type started from and SRC_PTR points to that base | |
307 | within the most derived object. Fill in RESULT with what we find. Return | |
308 | true if we have located an ambiguous match. */ | |
309 | virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst, | |
310 | __sub_kind __access_path, | |
311 | const __class_type_info *__dst_type, | |
312 | const void *__obj_ptr, | |
313 | const __class_type_info *__src_type, | |
314 | const void *__src_ptr, | |
315 | __dyncast_result &__result) const; | |
316 | public: | |
317 | /* Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE bases are | |
318 | inherited by the type started from -- which is not necessarily the | |
319 | current type. The current type will be a base of the destination type. | |
320 | OBJ_PTR points to the current base. */ | |
321 | virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst, | |
322 | const void *__obj_ptr, | |
323 | const __class_type_info *__src_type, | |
324 | const void *__src_ptr) const; | |
325 | }; | |
326 | ||
327 | /* type information for a class with a single non-virtual base */ | |
328 | class __si_class_type_info | |
329 | : public __class_type_info | |
330 | { | |
331 | /* abi defined member variables */ | |
332 | public: | |
333 | const __class_type_info *__base_type; | |
334 | ||
335 | /* abi defined member functions */ | |
336 | public: | |
337 | virtual ~__si_class_type_info (); | |
338 | public: | |
339 | explicit __si_class_type_info (const char *__n, | |
340 | const __class_type_info *__base) | |
341 | : __class_type_info (__n), __base_type (__base) | |
342 | { } | |
343 | ||
344 | /* implementation defined member functions */ | |
345 | protected: | |
346 | virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst, | |
347 | __sub_kind __access_path, | |
348 | const __class_type_info *__dst_type, | |
349 | const void *__obj_ptr, | |
350 | const __class_type_info *__src_type, | |
351 | const void *__src_ptr, | |
352 | __dyncast_result &__result) const; | |
353 | virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst, | |
354 | const void *__obj_ptr, | |
355 | const __class_type_info *__src_type, | |
356 | const void *__sub_ptr) const; | |
357 | virtual bool __do_upcast (const __class_type_info *__dst, | |
358 | const void *__obj, | |
359 | __upcast_result &__restrict __result) const; | |
360 | }; | |
361 | ||
362 | /* type information for a class with multiple and/or virtual bases */ | |
363 | class __vmi_class_type_info : public __class_type_info { | |
364 | /* abi defined member variables */ | |
365 | public: | |
366 | unsigned int __flags; /* details about the class heirarchy */ | |
367 | unsigned int __base_count; /* number of direct bases */ | |
368 | __base_class_info const __base_info[1]; /* array of bases */ | |
369 | /* The array of bases uses the trailing array struct hack | |
370 | so this class is not constructable with a normal constructor. It is | |
371 | internally generated by the compiler. */ | |
372 | ||
373 | /* abi defined member functions */ | |
374 | public: | |
375 | virtual ~__vmi_class_type_info (); | |
376 | public: | |
377 | explicit __vmi_class_type_info (const char *__n, | |
378 | int ___flags) | |
379 | : __class_type_info (__n), __flags (___flags), __base_count (0) | |
380 | { } | |
381 | ||
382 | /* implementation defined types */ | |
383 | public: | |
384 | enum __flags_masks { | |
385 | __non_diamond_repeat_mask = 0x1, /* distinct instance of repeated base */ | |
386 | __diamond_shaped_mask = 0x2, /* diamond shaped multiple inheritance */ | |
387 | non_public_base_mask = 0x4, /* has non-public direct or indirect base */ | |
388 | public_base_mask = 0x8, /* has public base (direct) */ | |
389 | ||
390 | __flags_unknown_mask = 0x10 | |
391 | }; | |
392 | ||
393 | /* implementation defined member functions */ | |
394 | protected: | |
395 | virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst, | |
396 | __sub_kind __access_path, | |
397 | const __class_type_info *__dst_type, | |
398 | const void *__obj_ptr, | |
399 | const __class_type_info *__src_type, | |
400 | const void *__src_ptr, | |
401 | __dyncast_result &__result) const; | |
402 | virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst, | |
403 | const void *__obj_ptr, | |
404 | const __class_type_info *__src_type, | |
405 | const void *__src_ptr) const; | |
406 | virtual bool __do_upcast (const __class_type_info *__dst, | |
407 | const void *__obj, | |
408 | __upcast_result &__restrict __result) const; | |
409 | }; | |
410 | ||
411 | /* dynamic cast runtime */ | |
412 | extern "C" | |
413 | void *__dynamic_cast (const void *__src_ptr, /* object started from */ | |
414 | const __class_type_info *__src_type, /* static type of object */ | |
415 | const __class_type_info *__dst_type, /* desired target type */ | |
416 | __PTRDIFF_TYPE__ __src2dst); /* how src and dst are related */ | |
417 | ||
418 | /* src2dst has the following possible values | |
419 | >= 0: src_type is a unique public non-virtual base of dst_type | |
420 | dst_ptr + src2dst == src_ptr | |
421 | -1: unspecified relationship | |
422 | -2: src_type is not a public base of dst_type | |
423 | -3: src_type is a multiple public non-virtual base of dst_type */ | |
424 | ||
425 | /* array ctor/dtor routines */ | |
426 | ||
427 | /* allocate and construct array */ | |
428 | extern "C" | |
429 | void *__cxa_vec_new (__SIZE_TYPE__ __element_count, | |
430 | __SIZE_TYPE__ __element_size, | |
431 | __SIZE_TYPE__ __padding_size, | |
432 | void (*__constructor) (void *), | |
433 | void (*__destructor) (void *)); | |
434 | ||
435 | extern "C" | |
436 | void *__cxa_vec_new2 (__SIZE_TYPE__ __element_count, | |
437 | __SIZE_TYPE__ __element_size, | |
438 | __SIZE_TYPE__ __padding_size, | |
439 | void (*__constructor) (void *), | |
440 | void (*__destructor) (void *), | |
441 | void *(*__alloc) (__SIZE_TYPE__), | |
442 | void (*__dealloc) (void *)); | |
443 | ||
444 | extern "C" | |
445 | void *__cxa_vec_new3 (__SIZE_TYPE__ __element_count, | |
446 | __SIZE_TYPE__ __element_size, | |
447 | __SIZE_TYPE__ __padding_size, | |
448 | void (*__constructor) (void *), | |
449 | void (*__destructor) (void *), | |
450 | void *(*__alloc) (__SIZE_TYPE__), | |
451 | void (*__dealloc) (void *, __SIZE_TYPE__)); | |
452 | ||
453 | /* construct array */ | |
454 | extern "C" | |
455 | void __cxa_vec_ctor (void *__array_address, | |
456 | __SIZE_TYPE__ __element_count, | |
457 | __SIZE_TYPE__ __element_size, | |
458 | void (*__constructor) (void *), | |
459 | void (*__destructor) (void *)); | |
460 | ||
461 | extern "C" | |
462 | void __cxa_vec_cctor (void *dest_array, | |
463 | void *src_array, | |
464 | __SIZE_TYPE__ element_count, | |
465 | __SIZE_TYPE__ element_size, | |
466 | void (*constructor) (void *, void *), | |
467 | void (*destructor) (void *)); | |
468 | ||
469 | /* destruct array */ | |
470 | extern "C" | |
471 | void __cxa_vec_dtor (void *__array_address, | |
472 | __SIZE_TYPE__ __element_count, | |
473 | __SIZE_TYPE__ __element_size, | |
474 | void (*__destructor) (void *)); | |
475 | ||
f8c02bc5 JM |
476 | /* destruct array */ |
477 | extern "C" | |
478 | void __cxa_vec_cleanup (void *__array_address, | |
479 | __SIZE_TYPE__ __element_count, | |
480 | __SIZE_TYPE__ __element_size, | |
481 | void (*__destructor) (void *)); | |
482 | ||
6305f20a BK |
483 | /* destruct and release array */ |
484 | extern "C" | |
485 | void __cxa_vec_delete (void *__array_address, | |
486 | __SIZE_TYPE__ __element_size, | |
487 | __SIZE_TYPE__ __padding_size, | |
488 | void (*__destructor) (void *)); | |
489 | ||
490 | extern "C" | |
491 | void __cxa_vec_delete2 (void *__array_address, | |
492 | __SIZE_TYPE__ __element_size, | |
493 | __SIZE_TYPE__ __padding_size, | |
494 | void (*__destructor) (void *), | |
495 | void (*__dealloc) (void *)); | |
496 | ||
497 | extern "C" | |
498 | void __cxa_vec_delete3 (void *__array_address, | |
499 | __SIZE_TYPE__ __element_size, | |
500 | __SIZE_TYPE__ __padding_size, | |
501 | void (*__destructor) (void *), | |
502 | void (*__dealloc) (void *, __SIZE_TYPE__)); | |
503 | ||
504 | /* demangling routines */ | |
505 | ||
506 | extern "C" | |
507 | char *__cxa_demangle (const char *__mangled_name, | |
508 | char *__output_buffer, | |
509 | __SIZE_TYPE__ *__length, | |
510 | int *__status); | |
511 | ||
512 | } /* namespace __cxxabiv1 */ | |
513 | ||
514 | /* User programs should use the alias `abi'. */ | |
515 | namespace abi = __cxxabiv1; | |
516 | ||
517 | #else | |
518 | #endif /* __cplusplus */ | |
519 | ||
520 | ||
521 | #endif /* __CXXABI_H */ |