* libsupc++/cxxabi-internal.h: Remove, to be replaced by...
[official-gcc.git] / libstdc++-v3 / libsupc++ / cxxabi.h
blob7f0307834d358860d35ca6c80a4fad44a46edefc
1 // new abi support -*- C++ -*-
3 // Copyright (C) 2000, 2002, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
4 //
5 // This file is part of GCC.
6 //
7 // GCC 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 // GCC 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 GCC; see the file COPYING. If not, write to
19 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 // Boston, MA 02110-1301, USA.
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.
31 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com>
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.
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. */
42 /** @file cxxabi.h
43 * The header provides an interface to the C++ ABI.
46 #ifndef _CXXABI_H
47 #define _CXXABI_H 1
49 #pragma GCC visibility push(default)
51 #include <stddef.h>
52 #include <bits/cxxabi_tweaks.h>
53 #include <cxxabi-forced.h>
55 #ifdef __cplusplus
56 namespace __cxxabiv1
58 extern "C"
60 #endif
62 typedef __cxa_cdtor_return_type (*__cxa_cdtor_type)(void *);
64 // Allocate array.
65 void*
66 __cxa_vec_new(size_t __element_count, size_t __element_size,
67 size_t __padding_size, __cxa_cdtor_type constructor,
68 __cxa_cdtor_type destructor);
70 void*
71 __cxa_vec_new2(size_t __element_count, size_t __element_size,
72 size_t __padding_size, __cxa_cdtor_type constructor,
73 __cxa_cdtor_type destructor, void *(*__alloc) (size_t),
74 void (*__dealloc) (void*));
76 void*
77 __cxa_vec_new3(size_t __element_count, size_t __element_size,
78 size_t __padding_size, __cxa_cdtor_type constructor,
79 __cxa_cdtor_type destructor, void *(*__alloc) (size_t),
80 void (*__dealloc) (void*, size_t));
82 // Construct array.
83 __cxa_vec_ctor_return_type
84 __cxa_vec_ctor(void* __array_address, size_t __element_count,
85 size_t __element_size, __cxa_cdtor_type constructor,
86 __cxa_cdtor_type destructor);
88 __cxa_vec_ctor_return_type
89 __cxa_vec_cctor(void* dest_array, void* src_array, size_t element_count,
90 size_t element_size,
91 __cxa_cdtor_return_type (*constructor) (void*, void*),
92 __cxa_cdtor_type destructor);
94 // Destruct array.
95 void
96 __cxa_vec_dtor(void* __array_address, size_t __element_count,
97 size_t __element_size, __cxa_cdtor_type destructor);
99 void
100 __cxa_vec_cleanup(void* __array_address, size_t __element_count,
101 size_t __element_size, __cxa_cdtor_type destructor);
103 // Destruct and release array.
104 void
105 __cxa_vec_delete(void* __array_address, size_t __element_size,
106 size_t __padding_size, __cxa_cdtor_type destructor);
108 void
109 __cxa_vec_delete2(void* __array_address, size_t __element_size,
110 size_t __padding_size, __cxa_cdtor_type destructor,
111 void (*__dealloc) (void*));
113 void
114 __cxa_vec_delete3(void* __array_address, size_t __element_size,
115 size_t __padding_size, __cxa_cdtor_type destructor,
116 void (*__dealloc) (void*, size_t));
118 int
119 __cxa_guard_acquire(__guard*);
121 void
122 __cxa_guard_release(__guard*);
124 void
125 __cxa_guard_abort(__guard*);
127 // Pure virtual functions.
128 void
129 __cxa_pure_virtual(void);
131 // Exception handling.
132 void
133 __cxa_bad_cast();
135 void
136 __cxa_bad_typeid();
138 // DSO destruction.
140 __cxa_atexit(void (*)(void*), void*, void*)
141 #ifdef __cplusplus
142 throw ()
143 #endif
147 __cxa_finalize(void*);
149 // Demangling routines.
150 char*
151 __cxa_demangle(const char* __mangled_name, char* __output_buffer,
152 size_t* __length, int* __status);
153 #ifdef __cplusplus
155 } // namespace __cxxabiv1
156 #endif
158 #ifdef __cplusplus
160 #include <typeinfo>
162 namespace __cxxabiv1
164 // Type information for int, float etc.
165 class __fundamental_type_info : public std::type_info
167 public:
168 explicit
169 __fundamental_type_info(const char* __n) : std::type_info(__n) { }
171 virtual
172 ~__fundamental_type_info();
175 // Type information for array objects.
176 class __array_type_info : public std::type_info
178 public:
179 explicit
180 __array_type_info(const char* __n) : std::type_info(__n) { }
182 virtual
183 ~__array_type_info();
186 // Type information for functions (both member and non-member).
187 class __function_type_info : public std::type_info
189 public:
190 explicit
191 __function_type_info(const char* __n) : std::type_info(__n) { }
193 virtual
194 ~__function_type_info();
196 protected:
197 // Implementation defined member function.
198 virtual bool
199 __is_function_p() const;
202 // Type information for enumerations.
203 class __enum_type_info : public std::type_info
205 public:
206 explicit
207 __enum_type_info(const char* __n) : std::type_info(__n) { }
209 virtual
210 ~__enum_type_info();
213 // Common type information for simple pointers and pointers to member.
214 class __pbase_type_info : public std::type_info
216 public:
217 unsigned int __flags; // Qualification of the target object.
218 const std::type_info* __pointee; // Type of pointed to object.
220 explicit
221 __pbase_type_info(const char* __n, int __quals,
222 const std::type_info* __type)
223 : std::type_info(__n), __flags(__quals), __pointee(__type)
226 virtual
227 ~__pbase_type_info();
229 // Implementation defined type.
230 enum __masks
232 __const_mask = 0x1,
233 __volatile_mask = 0x2,
234 __restrict_mask = 0x4,
235 __incomplete_mask = 0x8,
236 __incomplete_class_mask = 0x10
239 protected:
240 __pbase_type_info(const __pbase_type_info&);
242 __pbase_type_info&
243 operator=(const __pbase_type_info&);
245 // Implementation defined member functions.
246 virtual bool
247 __do_catch(const std::type_info* __thr_type, void** __thr_obj,
248 unsigned int __outer) const;
250 inline virtual bool
251 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
252 unsigned __outer) const;
255 // Type information for simple pointers.
256 class __pointer_type_info : public __pbase_type_info
258 public:
259 explicit
260 __pointer_type_info(const char* __n, int __quals,
261 const std::type_info* __type)
262 : __pbase_type_info (__n, __quals, __type) { }
265 virtual
266 ~__pointer_type_info();
268 protected:
269 // Implementation defined member functions.
270 virtual bool
271 __is_pointer_p() const;
273 virtual bool
274 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
275 unsigned __outer) const;
278 class __class_type_info;
280 // Type information for a pointer to member variable.
281 class __pointer_to_member_type_info : public __pbase_type_info
283 public:
284 __class_type_info* __context; // Class of the member.
286 explicit
287 __pointer_to_member_type_info(const char* __n, int __quals,
288 const std::type_info* __type,
289 __class_type_info* __klass)
290 : __pbase_type_info(__n, __quals, __type), __context(__klass) { }
292 virtual
293 ~__pointer_to_member_type_info();
295 protected:
296 __pointer_to_member_type_info(const __pointer_to_member_type_info&);
298 __pointer_to_member_type_info&
299 operator=(const __pointer_to_member_type_info&);
301 // Implementation defined member function.
302 virtual bool
303 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
304 unsigned __outer) const;
307 // Helper class for __vmi_class_type.
308 class __base_class_type_info
310 public:
311 const __class_type_info* __base_type; // Base class type.
312 long __offset_flags; // Offset and info.
314 enum __offset_flags_masks
316 __virtual_mask = 0x1,
317 __public_mask = 0x2,
318 __hwm_bit = 2,
319 __offset_shift = 8 // Bits to shift offset.
322 // Implementation defined member functions.
323 bool
324 __is_virtual_p() const
325 { return __offset_flags & __virtual_mask; }
327 bool
328 __is_public_p() const
329 { return __offset_flags & __public_mask; }
331 ptrdiff_t
332 __offset() const
334 // This shift, being of a signed type, is implementation
335 // defined. GCC implements such shifts as arithmetic, which is
336 // what we want.
337 return static_cast<ptrdiff_t>(__offset_flags) >> __offset_shift;
341 // Type information for a class.
342 class __class_type_info : public std::type_info
344 public:
345 explicit
346 __class_type_info (const char *__n) : type_info(__n) { }
348 virtual
349 ~__class_type_info ();
351 // Implementation defined types.
352 // The type sub_kind tells us about how a base object is contained
353 // within a derived object. We often do this lazily, hence the
354 // UNKNOWN value. At other times we may use NOT_CONTAINED to mean
355 // not publicly contained.
356 enum __sub_kind
358 // We have no idea.
359 __unknown = 0,
361 // Not contained within us (in some circumstances this might
362 // mean not contained publicly)
363 __not_contained,
365 // Contained ambiguously.
366 __contained_ambig,
368 // Via a virtual path.
369 __contained_virtual_mask = __base_class_type_info::__virtual_mask,
371 // Via a public path.
372 __contained_public_mask = __base_class_type_info::__public_mask,
374 // Contained within us.
375 __contained_mask = 1 << __base_class_type_info::__hwm_bit,
377 __contained_private = __contained_mask,
378 __contained_public = __contained_mask | __contained_public_mask
381 struct __upcast_result;
382 struct __dyncast_result;
384 protected:
385 // Implementation defined member functions.
386 virtual bool
387 __do_upcast(const __class_type_info* __dst_type, void**__obj_ptr) const;
389 virtual bool
390 __do_catch(const type_info* __thr_type, void** __thr_obj,
391 unsigned __outer) const;
393 public:
394 // Helper for upcast. See if DST is us, or one of our bases.
395 // Return false if not found, true if found.
396 virtual bool
397 __do_upcast(const __class_type_info* __dst, const void* __obj,
398 __upcast_result& __restrict __result) const;
400 // Indicate whether SRC_PTR of type SRC_TYPE is contained publicly
401 // within OBJ_PTR. OBJ_PTR points to a base object of our type,
402 // which is the destination type. SRC2DST indicates how SRC
403 // objects might be contained within this type. If SRC_PTR is one
404 // of our SRC_TYPE bases, indicate the virtuality. Returns
405 // not_contained for non containment or private containment.
406 inline __sub_kind
407 __find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
408 const __class_type_info* __src_type,
409 const void* __src_ptr) const;
411 // Helper for dynamic cast. ACCESS_PATH gives the access from the
412 // most derived object to this base. DST_TYPE indicates the
413 // desired type we want. OBJ_PTR points to a base of our type
414 // within the complete object. SRC_TYPE indicates the static type
415 // started from and SRC_PTR points to that base within the most
416 // derived object. Fill in RESULT with what we find. Return true
417 // if we have located an ambiguous match.
418 virtual bool
419 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
420 const __class_type_info* __dst_type, const void* __obj_ptr,
421 const __class_type_info* __src_type, const void* __src_ptr,
422 __dyncast_result& __result) const;
424 // Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE
425 // bases are inherited by the type started from -- which is not
426 // necessarily the current type. The current type will be a base
427 // of the destination type. OBJ_PTR points to the current base.
428 virtual __sub_kind
429 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
430 const __class_type_info* __src_type,
431 const void* __src_ptr) const;
434 // Type information for a class with a single non-virtual base.
435 class __si_class_type_info : public __class_type_info
437 public:
438 const __class_type_info* __base_type;
440 explicit
441 __si_class_type_info(const char *__n, const __class_type_info *__base)
442 : __class_type_info(__n), __base_type(__base) { }
444 virtual
445 ~__si_class_type_info();
447 protected:
448 __si_class_type_info(const __si_class_type_info&);
450 __si_class_type_info&
451 operator=(const __si_class_type_info&);
453 // Implementation defined member functions.
454 virtual bool
455 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
456 const __class_type_info* __dst_type, const void* __obj_ptr,
457 const __class_type_info* __src_type, const void* __src_ptr,
458 __dyncast_result& __result) const;
460 virtual __sub_kind
461 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
462 const __class_type_info* __src_type,
463 const void* __sub_ptr) const;
465 virtual bool
466 __do_upcast(const __class_type_info*__dst, const void*__obj,
467 __upcast_result& __restrict __result) const;
470 // Type information for a class with multiple and/or virtual bases.
471 class __vmi_class_type_info : public __class_type_info
473 public:
474 unsigned int __flags; // Details about the class hierarchy.
475 unsigned int __base_count; // Number of direct bases.
477 // The array of bases uses the trailing array struct hack so this
478 // class is not constructable with a normal constructor. It is
479 // internally generated by the compiler.
480 __base_class_type_info __base_info[1]; // Array of bases.
482 explicit
483 __vmi_class_type_info(const char* __n, int ___flags)
484 : __class_type_info(__n), __flags(___flags), __base_count(0) { }
486 virtual
487 ~__vmi_class_type_info();
489 // Implementation defined types.
490 enum __flags_masks
492 __non_diamond_repeat_mask = 0x1, // Distinct instance of repeated base.
493 __diamond_shaped_mask = 0x2, // Diamond shaped multiple inheritance.
494 __flags_unknown_mask = 0x10
497 protected:
498 // Implementation defined member functions.
499 virtual bool
500 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
501 const __class_type_info* __dst_type, const void* __obj_ptr,
502 const __class_type_info* __src_type, const void* __src_ptr,
503 __dyncast_result& __result) const;
505 virtual __sub_kind
506 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
507 const __class_type_info* __src_type,
508 const void* __src_ptr) const;
510 virtual bool
511 __do_upcast(const __class_type_info* __dst, const void* __obj,
512 __upcast_result& __restrict __result) const;
515 // Dynamic cast runtime.
516 // src2dst has the following possible values
517 // >-1: src_type is a unique public non-virtual base of dst_type
518 // dst_ptr + src2dst == src_ptr
519 // -1: unspecified relationship
520 // -2: src_type is not a public base of dst_type
521 // -3: src_type is a multiple public non-virtual base of dst_type
522 extern "C" void*
523 __dynamic_cast(const void* __src_ptr, // Starting object.
524 const __class_type_info* __src_type, // Static type of object.
525 const __class_type_info* __dst_type, // Desired target type.
526 ptrdiff_t __src2dst); // How src and dst are related.
529 // Returns the type_info for the currently handled exception [15.3/8], or
530 // null if there is none.
531 extern "C" std::type_info*
532 __cxa_current_exception_type();
534 // A magic placeholder class that can be caught by reference
535 // to recognize foreign exceptions.
536 class __foreign_exception
538 virtual ~__foreign_exception() throw();
539 virtual void __pure_dummy() = 0; // prevent catch by value
542 } // namespace __cxxabiv1
544 // User programs should use the alias `abi'.
545 namespace abi = __cxxabiv1;
547 #endif // __cplusplus
549 #pragma GCC visibility pop
551 #endif // __CXXABI_H