typeinfo.h revision 232922
1/*
2 * Copyright 2010-2011 PathScale, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 *    this list of conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 *    this list of conditions and the following disclaimer in the documentation
12 *    and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
15 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <stddef.h>
28#include "abi_namespace.h"
29#include "typeinfo"
30
31namespace ABI_NAMESPACE
32{
33	/**
34	 * Primitive type info, for intrinsic types.
35	 */
36	struct __fundamental_type_info : public std::type_info
37	{
38		virtual ~__fundamental_type_info();
39	};
40	/**
41	 * Type info for arrays.
42	 */
43	struct __array_type_info : public std::type_info
44	{
45		virtual ~__array_type_info();
46	};
47	/**
48	 * Type info for functions.
49	 */
50	struct __function_type_info : public std::type_info
51	{
52		virtual ~__function_type_info();
53	};
54	/**
55	 * Type info for enums.
56	 */
57	struct __enum_type_info : public std::type_info
58	{
59		virtual ~__enum_type_info();
60	};
61
62	/**
63	 * Base class for class type info.  Used only for tentative definitions.
64	 */
65	struct __class_type_info : public std::type_info
66	{
67		virtual ~__class_type_info();
68		/**
69		 * Function implementing dynamic casts.
70		 */
71		virtual void *cast_to(void *obj,
72		                      const struct __class_type_info *other) const;
73		/**
74		 * Function returning whether a cast from this type to another type is
75		 * possible.
76		 */
77		virtual bool can_cast_to(const struct __class_type_info *other) const;
78	};
79
80	/**
81	 * Single-inheritance class type info.  This is used for classes containing
82	 * a single non-virtual base class at offset 0.
83	 */
84	struct __si_class_type_info : public __class_type_info
85	{
86		virtual ~__si_class_type_info();
87		const __class_type_info *__base_type;
88		virtual void *cast_to(void *obj, const struct __class_type_info *other) const;
89        virtual bool can_cast_to(const struct __class_type_info *other) const;
90	};
91
92	/**
93	 * Type info for base classes.  Classes with multiple bases store an array
94	 * of these, one for each superclass.
95	 */
96	struct __base_class_type_info
97	{
98		const __class_type_info *__base_type;
99		private:
100			/**
101			 * The high __offset_shift bits of this store the (signed) offset
102			 * of the base class.  The low bits store flags from
103			 * __offset_flags_masks.
104			 */
105			long __offset_flags;
106			/**
107			 * Flags used in the low bits of __offset_flags.
108			 */
109			enum __offset_flags_masks
110			{
111				/** This base class is virtual. */
112				__virtual_mask = 0x1,
113				/** This base class is public. */
114				__public_mask = 0x2,
115				/** The number of bits reserved for flags. */
116				__offset_shift = 8
117			};
118		public:
119			/**
120			 * Returns the offset of the base class.
121			 */
122			long offset() const
123			{
124				return __offset_flags >> __offset_shift;
125			}
126			/**
127			 * Returns the flags.
128			 */
129			long flags() const
130			{
131				return __offset_flags & ((1 << __offset_shift) - 1);
132			}
133			/**
134			 * Returns whether this is a public base class.
135			 */
136			bool isPublic() const { return flags() & __public_mask; }
137			/**
138			 * Returns whether this is a virtual base class.
139			 */
140			bool isVirtual() const { return flags() & __virtual_mask; }
141	};
142
143	/**
144	 * Type info for classes with virtual bases or multiple superclasses.
145	 */
146	struct __vmi_class_type_info : public __class_type_info
147	{
148		virtual ~__vmi_class_type_info();
149		/** Flags describing this class.  Contains values from __flags_masks. */
150		unsigned int __flags;
151		/** The number of base classes. */
152		unsigned int __base_count;
153		/**
154		 * Array of base classes - this actually has __base_count elements, not
155		 * 1.
156		 */
157		__base_class_type_info __base_info[1];
158
159		/**
160		 * Flags used in the __flags field.
161		 */
162		enum __flags_masks
163		{
164			/** The class has non-diamond repeated inheritance. */
165			__non_diamond_repeat_mask = 0x1,
166			/** The class is diamond shaped. */
167			__diamond_shaped_mask = 0x2
168		};
169		virtual void *cast_to(void *obj, const struct __class_type_info *other) const;
170        virtual bool can_cast_to(const struct __class_type_info *other) const;
171	};
172
173	/**
174	 * Base class used for both pointer and pointer-to-member type info.
175	 */
176	struct __pbase_type_info : public std::type_info
177	{
178		virtual ~__pbase_type_info();
179		/**
180		 * Flags.  Values from __masks.
181		 */
182		unsigned int __flags;
183		/**
184		 * The type info for the pointee.
185		 */
186		const std::type_info *__pointee;
187
188		/**
189		 * Masks used for qualifiers on the pointer.
190		 */
191		enum __masks
192		{
193			/** Pointer has const qualifier. */
194			__const_mask = 0x1,
195			/** Pointer has volatile qualifier. */
196			__volatile_mask = 0x2,
197			/** Pointer has restrict qualifier. */
198			__restrict_mask = 0x4,
199			/** Pointer points to an incomplete type. */
200			__incomplete_mask = 0x8,
201			/** Pointer is a pointer to a member of an incomplete class. */
202			__incomplete_class_mask = 0x10
203		};
204	};
205
206	/**
207	 * Pointer type info.
208	 */
209	struct __pointer_type_info : public __pbase_type_info
210	{
211		virtual ~__pointer_type_info();
212	};
213
214	/**
215	 * Pointer to member type info.
216	 */
217	struct __pointer_to_member_type_info : public __pbase_type_info
218	{
219		virtual ~__pointer_to_member_type_info();
220		/**
221		 * Pointer to the class containing this member.
222		 */
223		const __class_type_info *__context;
224	};
225
226}
227