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