1 // new abi support -*- C++ -*-
3 // Copyright (C) 2000 Free Software Foundation, Inc.
5 // This file is part of GNU CC.
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)
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.
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.
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
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. */
45 #if defined(__cplusplus) && (!defined(__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100)
46 /* These structures only make sense when targeting the new abi, catch a
47 bonehead error early rather than let the user get very confused. */
48 #error "Not targetting the new abi, supply -fnew-abi"
53 // We use the compiler builtins __SIZE_TYPE__ and __PTRDIFF_TYPE__ instead of
54 // std::size_t and std::ptrdiff_t respectively. This makes us independant of
55 // the conformance level of <cstddef> and whether -fhonor-std was supplied.
56 // <cstddef> is not currently available during compiler building anyway.
57 // Including <stddef.h> would be wrong, as that would rudely place size_t in
58 // the global namespace.
65 /* type information for int, float etc */
66 class __fundamental_type_info
67 : public std::type_info
70 virtual ~__fundamental_type_info ();
72 explicit __fundamental_type_info (const char *__n)
73 : std::type_info (__n)
77 /* type information for array objects */
78 class __array_type_info
79 : public std::type_info
81 /* abi defined member functions */
83 virtual ~__array_type_info ();
85 explicit __array_type_info (const char *__n)
86 : std::type_info (__n)
90 /* type information for functions (both member and non-member) */
91 class __function_type_info
92 : public std::type_info
94 /* abi defined member functions */
96 virtual ~__function_type_info ();
98 explicit __function_type_info (const char *__n)
99 : std::type_info (__n)
102 /* implementation defined member functions */
104 virtual bool __is_function_p () const;
107 /* type information for enumerations */
108 class __enum_type_info
109 : public std::type_info
111 /* abi defined member functions */
113 virtual ~__enum_type_info ();
115 explicit __enum_type_info (const char *__n)
116 : std::type_info (__n)
120 /* common type information for simple pointers and pointers to member */
121 class __pbase_type_info
122 : public std::type_info
124 /* abi defined member variables */
126 unsigned int __qualifier_flags; /* qualification of the target object */
127 const std::type_info *__pointee; /* type of pointed to object */
129 /* abi defined member functions */
131 virtual ~__pbase_type_info ();
133 explicit __pbase_type_info (const char *__n,
135 const std::type_info *__type)
136 : std::type_info (__n), __qualifier_flags (__quals), __pointee (__type)
139 /* implementation defined types */
141 enum __qualifier_masks {
143 __volatile_mask = 0x2,
144 __restrict_mask = 0x4,
145 __incomplete_mask = 0x8,
146 __incomplete_class_mask = 0x10
149 /* implementation defined member functions */
151 virtual bool __do_catch (const std::type_info *__thr_type,
153 unsigned __outer) const;
155 inline virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
157 unsigned __outer) const;
160 /* type information for simple pointers */
161 class __pointer_type_info
162 : public __pbase_type_info
164 /* abi defined member functions */
166 virtual ~__pointer_type_info ();
168 explicit __pointer_type_info (const char *__n,
170 const std::type_info *__type)
171 : __pbase_type_info (__n, __quals, __type)
174 /* implementation defined member functions */
176 virtual bool __is_pointer_p () const;
179 virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
181 unsigned __outer) const;
184 /* type information for a pointer to member variable */
185 class __pointer_to_member_type_info
186 : public __pbase_type_info
188 /* abi defined member variables */
190 __class_type_info *__context_class; /* class of the member */
192 /* abi defined member functions */
194 virtual ~__pointer_to_member_type_info ();
196 explicit __pointer_to_member_type_info (const char *__n,
198 const std::type_info *__type,
199 __class_type_info *__klass)
200 : __pbase_type_info (__n, __quals, __type), __context_class (__klass)
203 /* implementation defined member functions */
205 virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
207 unsigned __outer) const;
210 class __class_type_info;
212 /* helper class for __vmi_class_type */
213 class __base_class_info
215 /* abi defined member variables */
217 const __class_type_info *__base; /* base class type */
218 long __offset_flags; /* offset and info */
220 /* implementation defined types */
222 enum __offset_flags_masks {
223 __virtual_mask = 0x1,
226 offset_shift = 8 /* bits to shift offset by */
229 /* implementation defined member functions */
231 bool __is_virtual_p () const
232 { return __offset_flags & __virtual_mask; }
233 bool __is_public_p () const
234 { return __offset_flags & __public_mask; }
235 __PTRDIFF_TYPE__ __offset () const
237 // This shift, being of a signed type, is implementation defined. GCC
238 // implements such shifts as arithmetic, which is what we want.
239 return static_cast<__PTRDIFF_TYPE__> (__offset_flags) >> offset_shift;
243 /* type information for a class */
244 class __class_type_info
245 : public std::type_info
247 /* abi defined member functions */
249 virtual ~__class_type_info ();
251 explicit __class_type_info (const char *__n)
255 /* implementation defined types */
257 /* sub_kind tells us about how a base object is contained within a derived
258 object. We often do this lazily, hence the UNKNOWN value. At other times
259 we may use NOT_CONTAINED to mean not publicly contained. */
262 __unknown = 0, /* we have no idea */
263 __not_contained, /* not contained within us (in some */
264 /* circumstances this might mean not contained */
266 __contained_ambig, /* contained ambiguously */
268 __contained_virtual_mask = __base_class_info::__virtual_mask, /* via a virtual path */
269 __contained_public_mask = __base_class_info::__public_mask, /* via a public path */
270 __contained_mask = 1 << __base_class_info::hwm_bit, /* contained within us */
272 __contained_private = __contained_mask,
273 __contained_public = __contained_mask | __contained_public_mask
277 struct __upcast_result;
278 struct __dyncast_result;
280 /* implementation defined member functions */
282 virtual bool __do_upcast (const __class_type_info *__dst_type, void **__obj_ptr) const;
285 virtual bool __do_catch (const type_info *__thr_type, void **__thr_obj,
286 unsigned __outer) const;
290 /* Helper for upcast. See if DST is us, or one of our bases. */
291 /* Return false if not found, true if found. */
292 virtual bool __do_upcast (const __class_type_info *__dst,
294 __upcast_result &__restrict __result) const;
297 /* Indicate whether SRC_PTR of type SRC_TYPE is contained publicly within
298 OBJ_PTR. OBJ_PTR points to a base object of our type, which is the
299 destination type. SRC2DST indicates how SRC objects might be contained
300 within this type. If SRC_PTR is one of our SRC_TYPE bases, indicate the
301 virtuality. Returns not_contained for non containment or private
303 inline __sub_kind __find_public_src (__PTRDIFF_TYPE__ __src2dst,
304 const void *__obj_ptr,
305 const __class_type_info *__src_type,
306 const void *__src_ptr) const;
309 /* dynamic cast helper. ACCESS_PATH gives the access from the most derived
310 object to this base. DST_TYPE indicates the desired type we want. OBJ_PTR
311 points to a base of our type within the complete object. SRC_TYPE
312 indicates the static type started from and SRC_PTR points to that base
313 within the most derived object. Fill in RESULT with what we find. Return
314 true if we have located an ambiguous match. */
315 virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst,
316 __sub_kind __access_path,
317 const __class_type_info *__dst_type,
318 const void *__obj_ptr,
319 const __class_type_info *__src_type,
320 const void *__src_ptr,
321 __dyncast_result &__result) const;
323 /* Helper for find_public_subobj. SRC2DST indicates how SRC_TYPE bases are
324 inherited by the type started from -- which is not necessarily the
325 current type. The current type will be a base of the destination type.
326 OBJ_PTR points to the current base. */
327 virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst,
328 const void *__obj_ptr,
329 const __class_type_info *__src_type,
330 const void *__src_ptr) const;
333 /* type information for a class with a single non-virtual base */
334 class __si_class_type_info
335 : public __class_type_info
337 /* abi defined member variables */
339 const __class_type_info *__base_type;
341 /* abi defined member functions */
343 virtual ~__si_class_type_info ();
345 explicit __si_class_type_info (const char *__n,
346 const __class_type_info *__base)
347 : __class_type_info (__n), __base_type (__base)
350 /* implementation defined member functions */
352 virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst,
353 __sub_kind __access_path,
354 const __class_type_info *__dst_type,
355 const void *__obj_ptr,
356 const __class_type_info *__src_type,
357 const void *__src_ptr,
358 __dyncast_result &__result) const;
359 virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst,
360 const void *__obj_ptr,
361 const __class_type_info *__src_type,
362 const void *__sub_ptr) const;
363 virtual bool __do_upcast (const __class_type_info *__dst,
365 __upcast_result &__restrict __result) const;
368 /* type information for a class with multiple and/or virtual bases */
369 class __vmi_class_type_info : public __class_type_info {
370 /* abi defined member variables */
372 unsigned int __flags; /* details about the class heirarchy */
373 unsigned int __base_count; /* number of direct bases */
374 __base_class_info const __base_info[1]; /* array of bases */
375 /* The array of bases uses the trailing array struct hack
376 so this class is not constructable with a normal constructor. It is
377 internally generated by the compiler. */
379 /* abi defined member functions */
381 virtual ~__vmi_class_type_info ();
383 explicit __vmi_class_type_info (const char *__n,
385 : __class_type_info (__n), __flags (___flags), __base_count (0)
388 /* implementation defined types */
391 __non_diamond_repeat_mask = 0x1, /* distinct instance of repeated base */
392 __diamond_shaped_mask = 0x2, /* diamond shaped multiple inheritance */
393 non_public_base_mask = 0x4, /* has non-public direct or indirect base */
394 public_base_mask = 0x8, /* has public base (direct) */
396 __flags_unknown_mask = 0x10
399 /* implementation defined member functions */
401 virtual bool __do_dyncast (__PTRDIFF_TYPE__ __src2dst,
402 __sub_kind __access_path,
403 const __class_type_info *__dst_type,
404 const void *__obj_ptr,
405 const __class_type_info *__src_type,
406 const void *__src_ptr,
407 __dyncast_result &__result) const;
408 virtual __sub_kind __do_find_public_src (__PTRDIFF_TYPE__ __src2dst,
409 const void *__obj_ptr,
410 const __class_type_info *__src_type,
411 const void *__src_ptr) const;
412 virtual bool __do_upcast (const __class_type_info *__dst,
414 __upcast_result &__restrict __result) const;
417 /* dynamic cast runtime */
419 void *__dynamic_cast (const void *__src_ptr, /* object started from */
420 const __class_type_info *__src_type, /* static type of object */
421 const __class_type_info *__dst_type, /* desired target type */
422 __PTRDIFF_TYPE__ __src2dst); /* how src and dst are related */
424 /* src2dst has the following possible values
425 >= 0: src_type is a unique public non-virtual base of dst_type
426 dst_ptr + src2dst == src_ptr
427 -1: unspecified relationship
428 -2: src_type is not a public base of dst_type
429 -3: src_type is a multiple public non-virtual base of dst_type */
431 /* array ctor/dtor routines */
433 /* allocate and construct array */
435 void *__cxa_vec_new (__SIZE_TYPE__ __element_count,
436 __SIZE_TYPE__ __element_size,
437 __SIZE_TYPE__ __padding_size,
438 void (*__constructor) (void *),
439 void (*__destructor) (void *));
442 void *__cxa_vec_new2 (__SIZE_TYPE__ __element_count,
443 __SIZE_TYPE__ __element_size,
444 __SIZE_TYPE__ __padding_size,
445 void (*__constructor) (void *),
446 void (*__destructor) (void *),
447 void *(*__alloc) (__SIZE_TYPE__),
448 void (*__dealloc) (void *));
451 void *__cxa_vec_new3 (__SIZE_TYPE__ __element_count,
452 __SIZE_TYPE__ __element_size,
453 __SIZE_TYPE__ __padding_size,
454 void (*__constructor) (void *),
455 void (*__destructor) (void *),
456 void *(*__alloc) (__SIZE_TYPE__),
457 void (*__dealloc) (void *, __SIZE_TYPE__));
459 /* construct array */
461 void __cxa_vec_ctor (void *__array_address,
462 __SIZE_TYPE__ __element_count,
463 __SIZE_TYPE__ __element_size,
464 void (*__constructor) (void *),
465 void (*__destructor) (void *));
468 void __cxa_vec_cctor (void *dest_array,
470 __SIZE_TYPE__ element_count,
471 __SIZE_TYPE__ element_size,
472 void (*constructor) (void *, void *),
473 void (*destructor) (void *));
477 void __cxa_vec_dtor (void *__array_address,
478 __SIZE_TYPE__ __element_count,
479 __SIZE_TYPE__ __element_size,
480 void (*__destructor) (void *));
482 /* destruct and release array */
484 void __cxa_vec_delete (void *__array_address,
485 __SIZE_TYPE__ __element_size,
486 __SIZE_TYPE__ __padding_size,
487 void (*__destructor) (void *));
490 void __cxa_vec_delete2 (void *__array_address,
491 __SIZE_TYPE__ __element_size,
492 __SIZE_TYPE__ __padding_size,
493 void (*__destructor) (void *),
494 void (*__dealloc) (void *));
497 void __cxa_vec_delete3 (void *__array_address,
498 __SIZE_TYPE__ __element_size,
499 __SIZE_TYPE__ __padding_size,
500 void (*__destructor) (void *),
501 void (*__dealloc) (void *, __SIZE_TYPE__));
503 /* demangling routines */
506 char *__cxa_demangle (const char *__mangled_name,
507 char *__output_buffer,
508 __SIZE_TYPE__ *__length,
511 } /* namespace __cxxabiv1 */
513 /* User programs should use the alias `abi'. */
514 namespace abi = __cxxabiv1;
517 #endif /* __cplusplus */
520 #endif /* __CXXABI_H */