]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/libsupc++/tinfo.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / libsupc++ / tinfo.h
1 // RTTI support internals for -*- C++ -*-
2 // Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2004
3 // Free Software Foundation
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 #include "typeinfo"
32 #include <cstddef>
33
34 // Class declarations shared between the typeinfo implementation files.
35
36 #include <cxxabi.h>
37
38 namespace __cxxabiv1 {
39
40 inline bool __pbase_type_info::
41 __pointer_catch (const __pbase_type_info *thrown_type,
42                  void **thr_obj,
43                  unsigned outer) const
44 {
45   return __pointee->__do_catch (thrown_type->__pointee, thr_obj, outer + 2);
46 }
47
48 namespace {
49
50 using namespace std;
51 using namespace abi;
52
53 // Initial part of a vtable, this structure is used with offsetof, so we don't
54 // have to keep alignments consistent manually.
55 struct vtable_prefix 
56 {
57   // Offset to most derived object.
58   ptrdiff_t whole_object;
59
60   // Additional padding if necessary.
61 #ifdef _GLIBCXX_VTABLE_PADDING
62   ptrdiff_t padding1;               
63 #endif
64
65   // Pointer to most derived type_info.
66   const __class_type_info *whole_type;  
67
68   // Additional padding if necessary.
69 #ifdef _GLIBCXX_VTABLE_PADDING
70   ptrdiff_t padding2;               
71 #endif
72
73   // What a class's vptr points to.
74   const void *origin;               
75 };
76
77 template <typename T>
78 inline const T *
79 adjust_pointer (const void *base, ptrdiff_t offset)
80 {
81   return reinterpret_cast <const T *>
82     (reinterpret_cast <const char *> (base) + offset);
83 }
84
85 // ADDR is a pointer to an object.  Convert it to a pointer to a base,
86 // using OFFSET. IS_VIRTUAL is true, if we are getting a virtual base.
87 inline void const *
88 convert_to_base (void const *addr, bool is_virtual, ptrdiff_t offset)
89 {
90   if (is_virtual)
91     {
92       const void *vtable = *static_cast <const void *const *> (addr);
93       
94       offset = *adjust_pointer<ptrdiff_t> (vtable, offset);
95     }
96
97   return adjust_pointer<void> (addr, offset);
98 }
99
100 // some predicate functions for __class_type_info::__sub_kind
101 inline bool contained_p (__class_type_info::__sub_kind access_path)
102 {
103   return access_path >= __class_type_info::__contained_mask;
104 }
105 inline bool public_p (__class_type_info::__sub_kind access_path)
106 {
107   return access_path & __class_type_info::__contained_public_mask;
108 }
109 inline bool virtual_p (__class_type_info::__sub_kind access_path)
110 {
111   return (access_path & __class_type_info::__contained_virtual_mask);
112 }
113 inline bool contained_public_p (__class_type_info::__sub_kind access_path)
114 {
115   return ((access_path & __class_type_info::__contained_public)
116           == __class_type_info::__contained_public);
117 }
118 inline bool contained_nonpublic_p (__class_type_info::__sub_kind access_path)
119 {
120   return ((access_path & __class_type_info::__contained_public)
121           == __class_type_info::__contained_mask);
122 }
123 inline bool contained_nonvirtual_p (__class_type_info::__sub_kind access_path)
124 {
125   return ((access_path & (__class_type_info::__contained_mask
126                           | __class_type_info::__contained_virtual_mask))
127           == __class_type_info::__contained_mask);
128 }
129
130 static const __class_type_info *const nonvirtual_base_type =
131     static_cast <const __class_type_info *> (0) + 1;
132
133 } // namespace
134
135 // __upcast_result is used to hold information during traversal of a class
136 // hierarchy when catch matching.
137 struct __class_type_info::__upcast_result
138 {
139   const void *dst_ptr;        // pointer to caught object
140   __sub_kind part2dst;        // path from current base to target
141   int src_details;            // hints about the source type hierarchy
142   const __class_type_info *base_type; // where we found the target,
143                               // if in vbase the __class_type_info of vbase
144                               // if a non-virtual base then 1
145                               // else NULL
146   __upcast_result (int d)
147     :dst_ptr (NULL), part2dst (__unknown), src_details (d), base_type (NULL)
148     {}
149 };
150
151 // __dyncast_result is used to hold information during traversal of a class
152 // hierarchy when dynamic casting.
153 struct __class_type_info::__dyncast_result
154 {
155   const void *dst_ptr;        // pointer to target object or NULL
156   __sub_kind whole2dst;       // path from most derived object to target
157   __sub_kind whole2src;       // path from most derived object to sub object
158   __sub_kind dst2src;         // path from target to sub object
159   int whole_details;          // details of the whole class hierarchy
160   
161   __dyncast_result (int details_ = __vmi_class_type_info::__flags_unknown_mask)
162     :dst_ptr (NULL), whole2dst (__unknown),
163      whole2src (__unknown), dst2src (__unknown),
164      whole_details (details_)
165     {}
166
167 protected:
168   __dyncast_result(const __dyncast_result&);
169   
170   __dyncast_result&
171   operator=(const __dyncast_result&);
172 };
173
174 inline __class_type_info::__sub_kind __class_type_info::
175 __find_public_src (ptrdiff_t src2dst,
176                    const void *obj_ptr,
177                    const __class_type_info *src_type,
178                    const void *src_ptr) const
179 {
180   if (src2dst >= 0)
181     return adjust_pointer <void> (obj_ptr, src2dst) == src_ptr
182             ? __contained_public : __not_contained;
183   if (src2dst == -2)
184     return __not_contained;
185   return __do_find_public_src (src2dst, obj_ptr, src_type, src_ptr);
186 }
187
188 }