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