OSDN Git Service

2001-02-15 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / libsupc++ / cxxabi.h
1 // new abi support -*- C++ -*-
2   
3 // Copyright (C) 2000 Free Software Foundation, Inc.
4 //
5 // This file is part of GNU CC.
6 //
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)
10 // any later version.
11 // 
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.
16 // 
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.
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 #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"
49 #endif
50
51 #ifdef __cplusplus
52
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.
59
60 #include <typeinfo>
61
62 namespace __cxxabiv1
63 {
64
65 /* type information for int, float etc */
66 class __fundamental_type_info
67   : public std::type_info
68 {
69 public:
70   virtual ~__fundamental_type_info ();
71 public:
72   explicit __fundamental_type_info (const char *__n)
73     : std::type_info (__n)
74     { }
75 };
76
77 /* type information for array objects */
78 class __array_type_info
79   : public std::type_info
80 {
81 /* abi defined member functions */
82 protected:
83   virtual ~__array_type_info ();
84 public:
85   explicit __array_type_info (const char *__n)
86     : std::type_info (__n)
87     { }
88 };
89
90 /* type information for functions (both member and non-member) */
91 class __function_type_info
92   : public std::type_info
93 {
94 /* abi defined member functions */
95 public:
96   virtual ~__function_type_info ();
97 public:
98   explicit __function_type_info (const char *__n)
99     : std::type_info (__n)
100     { }
101   
102 /* implementation defined member functions */
103 protected:
104   virtual bool __is_function_p () const;
105 };
106
107 /* type information for enumerations */
108 class __enum_type_info
109   : public std::type_info
110 {
111 /* abi defined member functions */
112 public:
113   virtual ~__enum_type_info ();
114 public:
115   explicit __enum_type_info (const char *__n)
116     : std::type_info (__n)
117     { }
118 };
119
120 /* common type information for simple pointers and pointers to member */
121 class __pbase_type_info
122   : public std::type_info
123 {
124 /* abi defined member variables */
125 public:
126   unsigned int __qualifier_flags; /* qualification of the target object */
127   const std::type_info *__pointee;   /* type of pointed to object */
128
129 /* abi defined member functions */
130 public:
131   virtual ~__pbase_type_info ();
132 public:
133   explicit __pbase_type_info (const char *__n,
134                                 int __quals,
135                                 const std::type_info *__type)
136     : std::type_info (__n), __qualifier_flags (__quals), __pointee (__type)
137     { }
138
139 /* implementation defined types */
140 public:
141   enum __qualifier_masks {
142     __const_mask = 0x1,
143     __volatile_mask = 0x2,
144     __restrict_mask = 0x4,
145     __incomplete_mask = 0x8,
146     __incomplete_class_mask = 0x10
147   };
148
149 /* implementation defined member functions */
150 protected:
151   virtual bool __do_catch (const std::type_info *__thr_type,
152                            void **__thr_obj,
153                            unsigned __outer) const;
154 protected:
155   inline virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
156                                        void **__thr_obj,
157                                        unsigned __outer) const;
158 };
159
160 /* type information for simple pointers */
161 class __pointer_type_info
162   : public __pbase_type_info
163 {
164 /* abi defined member functions */
165 public:
166   virtual ~__pointer_type_info ();
167 public:
168   explicit __pointer_type_info (const char *__n,
169                                 int __quals,
170                                 const std::type_info *__type)
171     : __pbase_type_info (__n, __quals, __type)
172     { }
173
174 /* implementation defined member functions */
175 protected:
176   virtual bool __is_pointer_p () const;
177
178 protected:
179   virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
180                                 void **__thr_obj,
181                                 unsigned __outer) const;
182 };
183
184 /* type information for a pointer to member variable */
185 class __pointer_to_member_type_info
186   : public __pbase_type_info
187 {
188 /* abi defined member variables */
189 public:
190   __class_type_info *__context_class;   /* class of the member */
191
192 /* abi defined member functions */
193 public:
194   virtual ~__pointer_to_member_type_info ();
195 public:
196   explicit __pointer_to_member_type_info (const char *__n,
197                                           int __quals,
198                                           const std::type_info *__type,
199                                           __class_type_info *__klass)
200     : __pbase_type_info (__n, __quals, __type), __context_class (__klass)
201     { }
202
203 /* implementation defined member functions */
204 protected:
205   virtual bool __pointer_catch (const __pbase_type_info *__thr_type,
206                                 void **__thr_obj,
207                                 unsigned __outer) const;
208 };
209
210 class __class_type_info;
211
212 /* helper class for __vmi_class_type */
213 class __base_class_info
214 {
215 /* abi defined member variables */
216 public:
217   const __class_type_info *__base;    /* base class type */
218   long __offset_flags;            /* offset and info */
219
220 /* implementation defined types */
221 public:
222   enum __offset_flags_masks {
223     __virtual_mask = 0x1,
224     __public_mask = 0x2,
225     hwm_bit = 2,
226     offset_shift = 8          /* bits to shift offset by */
227   };
228   
229 /* implementation defined member functions */
230 public:
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
236     { 
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;
240     }
241 };
242
243 /* type information for a class */
244 class __class_type_info
245   : public std::type_info
246 {
247 /* abi defined member functions */
248 public:
249   virtual ~__class_type_info ();
250 public:
251   explicit __class_type_info (const char *__n)
252     : type_info (__n)
253     { }
254
255 /* implementation defined types */
256 public:
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. */
260   enum __sub_kind
261   {
262     __unknown = 0,              /* we have no idea */
263     __not_contained,            /* not contained within us (in some */
264                                 /* circumstances this might mean not contained */
265                                 /* publicly) */
266     __contained_ambig,          /* contained ambiguously */
267     
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 */
271     
272     __contained_private = __contained_mask,
273     __contained_public = __contained_mask | __contained_public_mask
274   };
275
276 public:  
277   struct __upcast_result;
278   struct __dyncast_result;
279
280 /* implementation defined member functions */
281 protected:
282   virtual bool __do_upcast (const __class_type_info *__dst_type, void **__obj_ptr) const;
283
284 protected:
285   virtual bool __do_catch (const type_info *__thr_type, void **__thr_obj,
286                            unsigned __outer) const;
287
288
289 public:
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,
293                             const void *__obj,
294                             __upcast_result &__restrict __result) const;
295
296 public:
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
302      containment. */
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;
307
308 public:
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;
322 public:
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;
331 };
332
333 /* type information for a class with a single non-virtual base */
334 class __si_class_type_info
335   : public __class_type_info
336 {
337 /* abi defined member variables */
338 public:
339   const __class_type_info *__base_type;
340
341 /* abi defined member functions */
342 public:
343   virtual ~__si_class_type_info ();
344 public:
345   explicit __si_class_type_info (const char *__n,
346                                  const __class_type_info *__base)
347     : __class_type_info (__n), __base_type (__base)
348     { }
349
350 /* implementation defined member functions */
351 protected:
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,
364                             const void *__obj,
365                             __upcast_result &__restrict __result) const;
366 };
367
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 */
371 public:
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. */
378
379 /* abi defined member functions */
380 public:
381   virtual ~__vmi_class_type_info ();
382 public:
383   explicit __vmi_class_type_info (const char *__n,
384                                   int ___flags)
385     : __class_type_info (__n), __flags (___flags), __base_count (0)
386     { }
387
388 /* implementation defined types */
389 public:
390   enum __flags_masks {
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) */
395     
396     __flags_unknown_mask = 0x10
397   };
398
399 /* implementation defined member functions */
400 protected:
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,
413                             const void *__obj,
414                             __upcast_result &__restrict __result) const;
415 };
416
417 /* dynamic cast runtime */
418 extern "C"
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 */
423
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 */
430
431 /* array ctor/dtor routines */
432
433 /* allocate and construct array */
434 extern "C"
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 *));
440
441 extern "C"
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 *));
449
450 extern "C"
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__));
458
459 /* construct array */
460 extern "C"
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 *));
466
467 extern "C"
468 void __cxa_vec_cctor (void *dest_array,
469                       void *src_array,
470                       __SIZE_TYPE__ element_count,
471                       __SIZE_TYPE__ element_size,
472                       void (*constructor) (void *, void *),
473                       void (*destructor) (void *));
474  
475 /* destruct array */
476 extern "C"
477 void __cxa_vec_dtor (void *__array_address,
478                      __SIZE_TYPE__ __element_count,
479                      __SIZE_TYPE__ __element_size,
480                      void (*__destructor) (void *));
481
482 /* destruct and release array */
483 extern "C"
484 void __cxa_vec_delete (void *__array_address,
485                        __SIZE_TYPE__ __element_size,
486                        __SIZE_TYPE__ __padding_size,
487                        void (*__destructor) (void *));
488
489 extern "C"
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 *));
495                   
496 extern "C"
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__));
502                   
503 /* demangling routines */
504
505 extern "C" 
506 char *__cxa_demangle (const char *__mangled_name,
507                       char *__output_buffer,
508                       __SIZE_TYPE__ *__length,
509                       int *__status);
510
511 } /* namespace __cxxabiv1 */
512
513 /* User programs should use the alias `abi'. */
514 namespace abi = __cxxabiv1;
515
516 #else
517 #endif /* __cplusplus */
518
519
520 #endif /* __CXXABI_H */