* configure.ac: Set ABI_TWEAKS_SRCDIR.
[official-gcc.git] / libstdc++-v3 / libsupc++ / cxxabi.h
blobf1f74e7fcd9ac1cf1bffdc0650f28e2f990dbf94
1 // new abi support -*- C++ -*-
3 // Copyright (C) 2000, 2002, 2003, 2004 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, 59 Temple Place - Suite 330,
20 // Boston, MA 02111-1307, 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 #ifndef _CXXABI_H
43 #define _CXXABI_H 1
45 #include <stddef.h>
46 #include <bits/cxxabi_tweaks.h>
48 #ifdef __cplusplus
49 namespace __cxxabiv1
51 extern "C"
53 #endif
55 // Allocate array.
56 void*
57 __cxa_vec_new(size_t __element_count, size_t __element_size,
58 size_t __padding_size, void (*__constructor) (void*),
59 void (*__destructor) (void*));
61 void*
62 __cxa_vec_new2(size_t __element_count, size_t __element_size,
63 size_t __padding_size, void (*__constructor) (void*),
64 void (*__destructor) (void*), void *(*__alloc) (size_t),
65 void (*__dealloc) (void*));
67 void*
68 __cxa_vec_new3(size_t __element_count, size_t __element_size,
69 size_t __padding_size, void (*__constructor) (void*),
70 void (*__destructor) (void*), void *(*__alloc) (size_t),
71 void (*__dealloc) (void*, size_t));
73 // Construct array.
74 void
75 __cxa_vec_ctor(void* __array_address, size_t __element_count,
76 size_t __element_size, void (*__constructor) (void*),
77 void (*__destructor) (void*));
79 void
80 __cxa_vec_cctor(void* dest_array, void* src_array, size_t element_count,
81 size_t element_size, void (*constructor) (void*, void*),
82 void (*destructor) (void*));
84 // Destruct array.
85 void
86 __cxa_vec_dtor(void* __array_address, size_t __element_count,
87 size_t __element_size, void (*__destructor) (void*));
89 void
90 __cxa_vec_cleanup(void* __array_address, size_t __element_count,
91 size_t __element_size, void (*__destructor) (void*));
93 // Destruct and release array.
94 void
95 __cxa_vec_delete(void* __array_address, size_t __element_size,
96 size_t __padding_size, void (*__destructor) (void*));
98 void
99 __cxa_vec_delete2(void* __array_address, size_t __element_size,
100 size_t __padding_size, void (*__destructor) (void*),
101 void (*__dealloc) (void*));
103 void
104 __cxa_vec_delete3(void* __array_address, size_t __element_size,
105 size_t __padding_size, void (*__destructor) (void*),
106 void (*__dealloc) (void*, size_t));
108 int
109 __cxa_guard_acquire(__guard*);
111 void
112 __cxa_guard_release(__guard*);
114 void
115 __cxa_guard_abort(__guard*);
117 // Pure virtual functions.
118 void
119 __cxa_pure_virtual(void);
121 // Exception handling.
122 void
123 __cxa_bad_cast();
125 void
126 __cxa_bad_typeid();
128 // DSO destruction.
130 __cxa_atexit(void (*)(void*), void*, void*);
133 __cxa_finalize(void*);
135 // Demangling routines.
136 char*
137 __cxa_demangle(const char* __mangled_name, char* __output_buffer,
138 size_t* __length, int* __status);
139 #ifdef __cplusplus
141 } // namespace __cxxabiv1
142 #endif
144 #ifdef __cplusplus
146 #include <typeinfo>
148 namespace __cxxabiv1
150 // Type information for int, float etc.
151 class __fundamental_type_info : public std::type_info
153 public:
154 explicit
155 __fundamental_type_info(const char* __n) : std::type_info(__n) { }
157 virtual
158 ~__fundamental_type_info();
161 // Type information for array objects.
162 class __array_type_info : public std::type_info
164 public:
165 explicit
166 __array_type_info(const char* __n) : std::type_info(__n) { }
168 virtual
169 ~__array_type_info();
172 // Type information for functions (both member and non-member).
173 class __function_type_info : public std::type_info
175 public:
176 explicit
177 __function_type_info(const char* __n) : std::type_info(__n) { }
179 virtual
180 ~__function_type_info();
182 protected:
183 // Implementation defined member function.
184 virtual bool
185 __is_function_p() const;
188 // Type information for enumerations.
189 class __enum_type_info : public std::type_info
191 public:
192 explicit
193 __enum_type_info(const char* __n) : std::type_info(__n) { }
195 virtual
196 ~__enum_type_info();
199 // Common type information for simple pointers and pointers to member.
200 class __pbase_type_info : public std::type_info
202 public:
203 unsigned int __flags; // Qualification of the target object.
204 const std::type_info* __pointee; // Type of pointed to object.
206 explicit
207 __pbase_type_info(const char* __n, int __quals,
208 const std::type_info* __type)
209 : std::type_info(__n), __flags(__quals), __pointee(__type)
212 virtual
213 ~__pbase_type_info();
215 // Implementation defined type.
216 enum __masks
218 __const_mask = 0x1,
219 __volatile_mask = 0x2,
220 __restrict_mask = 0x4,
221 __incomplete_mask = 0x8,
222 __incomplete_class_mask = 0x10
225 protected:
226 __pbase_type_info(const __pbase_type_info&);
228 __pbase_type_info&
229 operator=(const __pbase_type_info&);
231 // Implementation defined member functions.
232 virtual bool
233 __do_catch(const std::type_info* __thr_type, void** __thr_obj,
234 unsigned int __outer) const;
236 inline virtual bool
237 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
238 unsigned __outer) const;
241 // Type information for simple pointers.
242 class __pointer_type_info : public __pbase_type_info
244 public:
245 explicit
246 __pointer_type_info(const char* __n, int __quals,
247 const std::type_info* __type)
248 : __pbase_type_info (__n, __quals, __type) { }
251 virtual
252 ~__pointer_type_info();
254 protected:
255 // Implementation defined member functions.
256 virtual bool
257 __is_pointer_p() const;
259 virtual bool
260 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
261 unsigned __outer) const;
264 class __class_type_info;
266 // Type information for a pointer to member variable.
267 class __pointer_to_member_type_info : public __pbase_type_info
269 public:
270 __class_type_info* __context; // Class of the member.
272 explicit
273 __pointer_to_member_type_info(const char* __n, int __quals,
274 const std::type_info* __type,
275 __class_type_info* __klass)
276 : __pbase_type_info(__n, __quals, __type), __context(__klass) { }
278 virtual
279 ~__pointer_to_member_type_info();
281 protected:
282 __pointer_to_member_type_info(const __pointer_to_member_type_info&);
284 __pointer_to_member_type_info&
285 operator=(const __pointer_to_member_type_info&);
287 // Implementation defined member function.
288 virtual bool
289 __pointer_catch(const __pbase_type_info* __thr_type, void** __thr_obj,
290 unsigned __outer) const;
293 // Helper class for __vmi_class_type.
294 class __base_class_type_info
296 public:
297 const __class_type_info* __base_type; // Base class type.
298 long __offset_flags; // Offset and info.
300 enum __offset_flags_masks
302 __virtual_mask = 0x1,
303 __public_mask = 0x2,
304 __hwm_bit = 2,
305 __offset_shift = 8 // Bits to shift offset.
308 // Implementation defined member functions.
309 bool
310 __is_virtual_p() const
311 { return __offset_flags & __virtual_mask; }
313 bool
314 __is_public_p() const
315 { return __offset_flags & __public_mask; }
317 ptrdiff_t
318 __offset() const
320 // This shift, being of a signed type, is implementation
321 // defined. GCC implements such shifts as arithmetic, which is
322 // what we want.
323 return static_cast<ptrdiff_t>(__offset_flags) >> __offset_shift;
327 // Type information for a class.
328 class __class_type_info : public std::type_info
330 public:
331 explicit
332 __class_type_info (const char *__n) : type_info(__n) { }
334 virtual
335 ~__class_type_info ();
337 // Implementation defined types.
338 // The type sub_kind tells us about how a base object is contained
339 // within a derived object. We often do this lazily, hence the
340 // UNKNOWN value. At other times we may use NOT_CONTAINED to mean
341 // not publicly contained.
342 enum __sub_kind
344 // We have no idea.
345 __unknown = 0,
347 // Not contained within us (in some circumstances this might
348 // mean not contained publicly)
349 __not_contained,
351 // Contained ambiguously.
352 __contained_ambig,
354 // Via a virtual path.
355 __contained_virtual_mask = __base_class_type_info::__virtual_mask,
357 // Via a public path.
358 __contained_public_mask = __base_class_type_info::__public_mask,
360 // Contained within us.
361 __contained_mask = 1 << __base_class_type_info::__hwm_bit,
363 __contained_private = __contained_mask,
364 __contained_public = __contained_mask | __contained_public_mask
367 struct __upcast_result;
368 struct __dyncast_result;
370 protected:
371 // Implementation defined member functions.
372 virtual bool
373 __do_upcast(const __class_type_info* __dst_type, void**__obj_ptr) const;
375 virtual bool
376 __do_catch(const type_info* __thr_type, void** __thr_obj,
377 unsigned __outer) const;
379 public:
380 // Helper for upcast. See if DST is us, or one of our bases.
381 // Return false if not found, true if found.
382 virtual bool
383 __do_upcast(const __class_type_info* __dst, const void* __obj,
384 __upcast_result& __restrict __result) const;
386 // Indicate whether SRC_PTR of type SRC_TYPE is contained publicly
387 // within OBJ_PTR. OBJ_PTR points to a base object of our type,
388 // which is the destination type. SRC2DST indicates how SRC
389 // objects might be contained within this type. If SRC_PTR is one
390 // of our SRC_TYPE bases, indicate the virtuality. Returns
391 // not_contained for non containment or private containment.
392 inline __sub_kind
393 __find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
394 const __class_type_info* __src_type,
395 const void* __src_ptr) const;
397 // Helper for dynamic cast. ACCESS_PATH gives the access from the
398 // most derived object to this base. DST_TYPE indicates the
399 // desired type we want. OBJ_PTR points to a base of our type
400 // within the complete object. SRC_TYPE indicates the static type
401 // started from and SRC_PTR points to that base within the most
402 // derived object. Fill in RESULT with what we find. Return true
403 // if we have located an ambiguous match.
404 virtual bool
405 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
406 const __class_type_info* __dst_type, const void* __obj_ptr,
407 const __class_type_info* __src_type, const void* __src_ptr,
408 __dyncast_result& __result) const;
410 // Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE
411 // bases are inherited by the type started from -- which is not
412 // necessarily the current type. The current type will be a base
413 // of the destination type. OBJ_PTR points to the current base.
414 virtual __sub_kind
415 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
416 const __class_type_info* __src_type,
417 const void* __src_ptr) const;
420 // Type information for a class with a single non-virtual base.
421 class __si_class_type_info : public __class_type_info
423 public:
424 const __class_type_info* __base_type;
426 explicit
427 __si_class_type_info(const char *__n, const __class_type_info *__base)
428 : __class_type_info(__n), __base_type(__base) { }
430 virtual
431 ~__si_class_type_info();
433 protected:
434 __si_class_type_info(const __si_class_type_info&);
436 __si_class_type_info&
437 operator=(const __si_class_type_info&);
439 // Implementation defined member functions.
440 virtual bool
441 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
442 const __class_type_info* __dst_type, const void* __obj_ptr,
443 const __class_type_info* __src_type, const void* __src_ptr,
444 __dyncast_result& __result) const;
446 virtual __sub_kind
447 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
448 const __class_type_info* __src_type,
449 const void* __sub_ptr) const;
451 virtual bool
452 __do_upcast(const __class_type_info*__dst, const void*__obj,
453 __upcast_result& __restrict __result) const;
456 // Type information for a class with multiple and/or virtual bases.
457 class __vmi_class_type_info : public __class_type_info
459 public:
460 unsigned int __flags; // Details about the class hierarchy.
461 unsigned int __base_count; // Dumber of direct bases.
463 // The array of bases uses the trailing array struct hack so this
464 // class is not constructable with a normal constructor. It is
465 // internally generated by the compiler.
466 __base_class_type_info __base_info[1]; // Array of bases.
468 explicit
469 __vmi_class_type_info(const char* __n, int ___flags)
470 : __class_type_info(__n), __flags(___flags), __base_count(0) { }
472 virtual
473 ~__vmi_class_type_info();
475 // Implementation defined types.
476 enum __flags_masks
478 __non_diamond_repeat_mask = 0x1, // Distinct instance of repeated base.
479 __diamond_shaped_mask = 0x2, // Diamond shaped multiple inheritance.
480 __flags_unknown_mask = 0x10
483 protected:
484 // Implementation defined member functions.
485 virtual bool
486 __do_dyncast(ptrdiff_t __src2dst, __sub_kind __access_path,
487 const __class_type_info* __dst_type, const void* __obj_ptr,
488 const __class_type_info* __src_type, const void* __src_ptr,
489 __dyncast_result& __result) const;
491 virtual __sub_kind
492 __do_find_public_src(ptrdiff_t __src2dst, const void* __obj_ptr,
493 const __class_type_info* __src_type,
494 const void* __src_ptr) const;
496 virtual bool
497 __do_upcast(const __class_type_info* __dst, const void* __obj,
498 __upcast_result& __restrict __result) const;
501 // Dynamic cast runtime.
502 // src2dst has the following possible values
503 // >-1: src_type is a unique public non-virtual base of dst_type
504 // dst_ptr + src2dst == src_ptr
505 // -1: unspecified relationship
506 // -2: src_type is not a public base of dst_type
507 // -3: src_type is a multiple public non-virtual base of dst_type
508 extern "C" void*
509 __dynamic_cast(const void* __src_ptr, // Starting object.
510 const __class_type_info* __src_type, // Static type of object.
511 const __class_type_info* __dst_type, // Desired target type.
512 ptrdiff_t __src2dst); // How src and dst are related.
515 // Returns the type_info for the currently handled exception [15.3/8], or
516 // null if there is none.
517 extern "C" std::type_info*
518 __cxa_current_exception_type();
519 } // namespace __cxxabiv1
521 // User programs should use the alias `abi'.
522 namespace abi = __cxxabiv1;
524 #endif // __cplusplus
526 #endif // __CXXABI_H