typeinfo.h revision 227825
1227825Stheraven#include <stddef.h> 2227825Stheraven#include "abi_namespace.h" 3227825Stheraven#include "typeinfo" 4227825Stheraven 5227825Stheravennamespace ABI_NAMESPACE 6227825Stheraven{ 7227825Stheraven /** 8227825Stheraven * Primitive type info, for intrinsic types. 9227825Stheraven */ 10227825Stheraven struct __fundamental_type_info : public std::type_info 11227825Stheraven { 12227825Stheraven virtual ~__fundamental_type_info(); 13227825Stheraven }; 14227825Stheraven /** 15227825Stheraven * Type info for arrays. 16227825Stheraven */ 17227825Stheraven struct __array_type_info : public std::type_info 18227825Stheraven { 19227825Stheraven virtual ~__array_type_info(); 20227825Stheraven }; 21227825Stheraven /** 22227825Stheraven * Type info for functions. 23227825Stheraven */ 24227825Stheraven struct __function_type_info : public std::type_info 25227825Stheraven { 26227825Stheraven virtual ~__function_type_info(); 27227825Stheraven }; 28227825Stheraven /** 29227825Stheraven * Type info for enums. 30227825Stheraven */ 31227825Stheraven struct __enum_type_info : public std::type_info 32227825Stheraven { 33227825Stheraven virtual ~__enum_type_info(); 34227825Stheraven }; 35227825Stheraven 36227825Stheraven /** 37227825Stheraven * Base class for class type info. Used only for tentative definitions. 38227825Stheraven */ 39227825Stheraven struct __class_type_info : public std::type_info 40227825Stheraven { 41227825Stheraven virtual ~__class_type_info(); 42227825Stheraven /** 43227825Stheraven * Function implementing dynamic casts. 44227825Stheraven */ 45227825Stheraven virtual void *cast_to(void *obj, 46227825Stheraven const struct __class_type_info *other) const; 47227825Stheraven /** 48227825Stheraven * Function returning whether a cast from this type to another type is 49227825Stheraven * possible. 50227825Stheraven */ 51227825Stheraven virtual bool can_cast_to(const struct __class_type_info *other) const; 52227825Stheraven }; 53227825Stheraven 54227825Stheraven /** 55227825Stheraven * Single-inheritance class type info. This is used for classes containing 56227825Stheraven * a single non-virtual base class at offset 0. 57227825Stheraven */ 58227825Stheraven struct __si_class_type_info : public __class_type_info 59227825Stheraven { 60227825Stheraven virtual ~__si_class_type_info(); 61227825Stheraven const __class_type_info *__base_type; 62227825Stheraven virtual void *cast_to(void *obj, const struct __class_type_info *other) const; 63227825Stheraven virtual bool can_cast_to(const struct __class_type_info *other) const; 64227825Stheraven }; 65227825Stheraven 66227825Stheraven /** 67227825Stheraven * Type info for base classes. Classes with multiple bases store an array 68227825Stheraven * of these, one for each superclass. 69227825Stheraven */ 70227825Stheraven struct __base_class_type_info 71227825Stheraven { 72227825Stheraven const __class_type_info *__base_type; 73227825Stheraven private: 74227825Stheraven /** 75227825Stheraven * The high __offset_shift bits of this store the (signed) offset 76227825Stheraven * of the base class. The low bits store flags from 77227825Stheraven * __offset_flags_masks. 78227825Stheraven */ 79227825Stheraven long __offset_flags; 80227825Stheraven /** 81227825Stheraven * Flags used in the low bits of __offset_flags. 82227825Stheraven */ 83227825Stheraven enum __offset_flags_masks 84227825Stheraven { 85227825Stheraven /** This base class is virtual. */ 86227825Stheraven __virtual_mask = 0x1, 87227825Stheraven /** This base class is public. */ 88227825Stheraven __public_mask = 0x2, 89227825Stheraven /** The number of bits reserved for flags. */ 90227825Stheraven __offset_shift = 8 91227825Stheraven }; 92227825Stheraven public: 93227825Stheraven /** 94227825Stheraven * Returns the offset of the base class. 95227825Stheraven */ 96227825Stheraven long offset() const 97227825Stheraven { 98227825Stheraven return __offset_flags >> __offset_shift; 99227825Stheraven } 100227825Stheraven /** 101227825Stheraven * Returns the flags. 102227825Stheraven */ 103227825Stheraven long flags() const 104227825Stheraven { 105227825Stheraven return __offset_flags & ((1 << __offset_shift) - 1); 106227825Stheraven } 107227825Stheraven /** 108227825Stheraven * Returns whether this is a public base class. 109227825Stheraven */ 110227825Stheraven bool isPublic() const { return flags() & __public_mask; } 111227825Stheraven /** 112227825Stheraven * Returns whether this is a virtual base class. 113227825Stheraven */ 114227825Stheraven bool isVirtual() const { return flags() & __virtual_mask; } 115227825Stheraven }; 116227825Stheraven 117227825Stheraven /** 118227825Stheraven * Type info for classes with virtual bases or multiple superclasses. 119227825Stheraven */ 120227825Stheraven struct __vmi_class_type_info : public __class_type_info 121227825Stheraven { 122227825Stheraven virtual ~__vmi_class_type_info(); 123227825Stheraven /** Flags describing this class. Contains values from __flags_masks. */ 124227825Stheraven unsigned int __flags; 125227825Stheraven /** The number of base classes. */ 126227825Stheraven unsigned int __base_count; 127227825Stheraven /** 128227825Stheraven * Array of base classes - this actually has __base_count elements, not 129227825Stheraven * 1. 130227825Stheraven */ 131227825Stheraven __base_class_type_info __base_info[1]; 132227825Stheraven 133227825Stheraven /** 134227825Stheraven * Flags used in the __flags field. 135227825Stheraven */ 136227825Stheraven enum __flags_masks 137227825Stheraven { 138227825Stheraven /** The class has non-diamond repeated inheritance. */ 139227825Stheraven __non_diamond_repeat_mask = 0x1, 140227825Stheraven /** The class is diamond shaped. */ 141227825Stheraven __diamond_shaped_mask = 0x2 142227825Stheraven }; 143227825Stheraven virtual void *cast_to(void *obj, const struct __class_type_info *other) const; 144227825Stheraven virtual bool can_cast_to(const struct __class_type_info *other) const; 145227825Stheraven }; 146227825Stheraven 147227825Stheraven /** 148227825Stheraven * Base class used for both pointer and pointer-to-member type info. 149227825Stheraven */ 150227825Stheraven struct __pbase_type_info : public std::type_info 151227825Stheraven { 152227825Stheraven virtual ~__pbase_type_info(); 153227825Stheraven /** 154227825Stheraven * Flags. Values from __masks. 155227825Stheraven */ 156227825Stheraven unsigned int __flags; 157227825Stheraven /** 158227825Stheraven * The type info for the pointee. 159227825Stheraven */ 160227825Stheraven const std::type_info *__pointee; 161227825Stheraven 162227825Stheraven /** 163227825Stheraven * Masks used for qualifiers on the pointer. 164227825Stheraven */ 165227825Stheraven enum __masks 166227825Stheraven { 167227825Stheraven /** Pointer has const qualifier. */ 168227825Stheraven __const_mask = 0x1, 169227825Stheraven /** Pointer has volatile qualifier. */ 170227825Stheraven __volatile_mask = 0x2, 171227825Stheraven /** Pointer has restrict qualifier. */ 172227825Stheraven __restrict_mask = 0x4, 173227825Stheraven /** Pointer points to an incomplete type. */ 174227825Stheraven __incomplete_mask = 0x8, 175227825Stheraven /** Pointer is a pointer to a member of an incomplete class. */ 176227825Stheraven __incomplete_class_mask = 0x10 177227825Stheraven }; 178227825Stheraven }; 179227825Stheraven 180227825Stheraven /** 181227825Stheraven * Pointer type info. 182227825Stheraven */ 183227825Stheraven struct __pointer_type_info : public __pbase_type_info 184227825Stheraven { 185227825Stheraven virtual ~__pointer_type_info(); 186227825Stheraven }; 187227825Stheraven 188227825Stheraven /** 189227825Stheraven * Pointer to member type info. 190227825Stheraven */ 191227825Stheraven struct __pointer_to_member_type_info : public __pbase_type_info 192227825Stheraven { 193227825Stheraven virtual ~__pointer_to_member_type_info(); 194227825Stheraven /** 195227825Stheraven * Pointer to the class containing this member. 196227825Stheraven */ 197227825Stheraven const __class_type_info *__context; 198227825Stheraven }; 199227825Stheraven 200227825Stheraven} 201