typeinfo.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. #include <typeinfo>
  27. #include "abi_namespace.h"
  28. namespace ABI_NAMESPACE
  29. {
  30. /**
  31. * Primitive type info, for intrinsic types.
  32. */
  33. struct __fundamental_type_info : public std::type_info
  34. {
  35. virtual ~__fundamental_type_info();
  36. };
  37. /**
  38. * Type info for arrays.
  39. */
  40. struct __array_type_info : public std::type_info
  41. {
  42. virtual ~__array_type_info();
  43. };
  44. /**
  45. * Type info for functions.
  46. */
  47. struct __function_type_info : public std::type_info
  48. {
  49. virtual ~__function_type_info();
  50. virtual bool __is_function_p() const { return true; }
  51. };
  52. /**
  53. * Type info for enums.
  54. */
  55. struct __enum_type_info : public std::type_info
  56. {
  57. virtual ~__enum_type_info();
  58. };
  59. /**
  60. * Base class for class type info. Used only for tentative definitions.
  61. */
  62. struct __class_type_info : public std::type_info
  63. {
  64. virtual ~__class_type_info();
  65. /**
  66. * Function implementing dynamic casts.
  67. */
  68. virtual void *cast_to(void *obj, const struct __class_type_info *other) const;
  69. virtual bool __do_upcast(const ABI_NAMESPACE::
  70. __class_type_info *target,
  71. void **thrown_object) const
  72. {
  73. return this == target;
  74. }
  75. };
  76. /**
  77. * Single-inheritance class type info. This is used for classes containing
  78. * a single non-virtual base class at offset 0.
  79. */
  80. struct __si_class_type_info : public __class_type_info
  81. {
  82. virtual ~__si_class_type_info();
  83. const __class_type_info *__base_type;
  84. virtual bool __do_upcast(
  85. const __cxxabiv1::__class_type_info *target,
  86. void **thrown_object) const;
  87. virtual void *cast_to(void *obj, const struct __class_type_info *other) const;
  88. };
  89. /**
  90. * Type info for base classes. Classes with multiple bases store an array
  91. * of these, one for each superclass.
  92. */
  93. struct __base_class_type_info
  94. {
  95. const __class_type_info *__base_type;
  96. private:
  97. /**
  98. * The high __offset_shift bits of this store the (signed) offset
  99. * of the base class. The low bits store flags from
  100. * __offset_flags_masks.
  101. */
  102. long __offset_flags;
  103. /**
  104. * Flags used in the low bits of __offset_flags.
  105. */
  106. enum __offset_flags_masks
  107. {
  108. /** This base class is virtual. */
  109. __virtual_mask = 0x1,
  110. /** This base class is public. */
  111. __public_mask = 0x2,
  112. /** The number of bits reserved for flags. */
  113. __offset_shift = 8
  114. };
  115. public:
  116. /**
  117. * Returns the offset of the base class.
  118. */
  119. long offset() const
  120. {
  121. return __offset_flags >> __offset_shift;
  122. }
  123. /**
  124. * Returns the flags.
  125. */
  126. long flags() const
  127. {
  128. return __offset_flags & ((1 << __offset_shift) - 1);
  129. }
  130. /**
  131. * Returns whether this is a public base class.
  132. */
  133. bool isPublic() const { return flags() & __public_mask; }
  134. /**
  135. * Returns whether this is a virtual base class.
  136. */
  137. bool isVirtual() const { return flags() & __virtual_mask; }
  138. };
  139. /**
  140. * Type info for classes with virtual bases or multiple superclasses.
  141. */
  142. struct __vmi_class_type_info : public __class_type_info
  143. {
  144. virtual ~__vmi_class_type_info();
  145. /** Flags describing this class. Contains values from __flags_masks. */
  146. unsigned int __flags;
  147. /** The number of base classes. */
  148. unsigned int __base_count;
  149. /**
  150. * Array of base classes - this actually has __base_count elements, not
  151. * 1.
  152. */
  153. __base_class_type_info __base_info[1];
  154. /**
  155. * Flags used in the __flags field.
  156. */
  157. enum __flags_masks
  158. {
  159. /** The class has non-diamond repeated inheritance. */
  160. __non_diamond_repeat_mask = 0x1,
  161. /** The class is diamond shaped. */
  162. __diamond_shaped_mask = 0x2
  163. };
  164. virtual bool __do_upcast(
  165. const __cxxabiv1::__class_type_info *target,
  166. void **thrown_object) const;
  167. virtual void *cast_to(void *obj, const struct __class_type_info *other) const;
  168. };
  169. /**
  170. * Base class used for both pointer and pointer-to-member type info.
  171. */
  172. struct __pbase_type_info : public std::type_info
  173. {
  174. virtual ~__pbase_type_info();
  175. /**
  176. * Flags. Values from __masks.
  177. */
  178. unsigned int __flags;
  179. /**
  180. * The type info for the pointee.
  181. */
  182. const std::type_info *__pointee;
  183. /**
  184. * Masks used for qualifiers on the pointer.
  185. */
  186. enum __masks
  187. {
  188. /** Pointer has const qualifier. */
  189. __const_mask = 0x1,
  190. /** Pointer has volatile qualifier. */
  191. __volatile_mask = 0x2,
  192. /** Pointer has restrict qualifier. */
  193. __restrict_mask = 0x4,
  194. /** Pointer points to an incomplete type. */
  195. __incomplete_mask = 0x8,
  196. /** Pointer is a pointer to a member of an incomplete class. */
  197. __incomplete_class_mask = 0x10
  198. };
  199. virtual bool __is_pointer_p() const { return true; }
  200. virtual bool __do_catch(const type_info *thrown_type,
  201. void **thrown_object,
  202. unsigned outer) const;
  203. };
  204. /**
  205. * Pointer type info.
  206. */
  207. struct __pointer_type_info : public __pbase_type_info
  208. {
  209. virtual ~__pointer_type_info();
  210. };
  211. /**
  212. * Pointer to member type info.
  213. */
  214. struct __pointer_to_member_type_info : public __pbase_type_info
  215. {
  216. virtual ~__pointer_to_member_type_info();
  217. /**
  218. * Pointer to the class containing this member.
  219. */
  220. const __class_type_info *__context;
  221. };
  222. }