OSDN Git Service

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