OSDN Git Service

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