/*1* Copyright 2010-2011 PathScale, Inc. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions are met:5*6* 1. Redistributions of source code must retain the above copyright notice,7* this list of conditions and the following disclaimer.8*9* 2. Redistributions in binary form must reproduce the above copyright notice,10* this list of conditions and the following disclaimer in the documentation11* and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS14* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,15* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR16* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR17* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,18* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,19* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;20* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,21* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF23* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#include <stddef.h>27#include "abi_namespace.h"2829namespace ABI_NAMESPACE30{31struct __class_type_info;32}33namespace std34{35/**36* Standard type info class. The layout of this class is specified by the37* ABI. The layout of the vtable is not, but is intended to be38* compatible with the GNU ABI.39*40* Unlike the GNU version, the vtable layout is considered semi-private.41*/42class type_info43{44public:45/**46* Virtual destructor. This class must have one virtual function to47* ensure that it has a vtable.48*/49virtual ~type_info();50bool operator==(const type_info &) const;51bool operator!=(const type_info &) const;52bool before(const type_info &) const;53const char* name() const;54type_info();55private:56type_info(const type_info& rhs);57type_info& operator= (const type_info& rhs);58const char *__type_name;59/*60* The following functions are in this order to match the61* vtable layout of libsupc++. This allows libcxxrt to be used62* with libraries that depend on this.63*64* These functions are in the public headers for libstdc++, so65* we have to assume that someone will probably call them and66* expect them to work. Their names must also match the names used in67* libsupc++, so that code linking against this library can subclass68* type_info and correctly fill in the values in the vtables.69*/70public:71/**72* Returns true if this is some pointer type, false otherwise.73*/74virtual bool __is_pointer_p() const { return false; }75/**76* Returns true if this is some function type, false otherwise.77*/78virtual bool __is_function_p() const { return false; }79/**80* Catch function. Allows external libraries to implement81* their own basic types. This is used, for example, in the82* GNUstep Objective-C runtime to allow Objective-C types to be83* caught in G++ catch blocks.84*85* The outer parameter indicates the number of outer pointers86* in the high bits. The low bit indicates whether the87* pointers are const qualified.88*/89virtual bool __do_catch(const type_info *thrown_type,90void **thrown_object,91unsigned outer) const;92/**93* Performs an upcast. This is used in exception handling to94* cast from subclasses to superclasses. If the upcast is95* possible, it returns true and adjusts the pointer. If the96* upcast is not possible, it returns false and does not adjust97* the pointer.98*/99virtual bool __do_upcast(100const ABI_NAMESPACE::__class_type_info *target,101void **thrown_object) const102{103return false;104}105};106}107108109namespace ABI_NAMESPACE110{111/**112* Primitive type info, for intrinsic types.113*/114struct __fundamental_type_info : public std::type_info115{116virtual ~__fundamental_type_info();117};118/**119* Type info for arrays.120*/121struct __array_type_info : public std::type_info122{123virtual ~__array_type_info();124};125/**126* Type info for functions.127*/128struct __function_type_info : public std::type_info129{130virtual ~__function_type_info();131virtual bool __is_function_p() const { return true; }132};133/**134* Type info for enums.135*/136struct __enum_type_info : public std::type_info137{138virtual ~__enum_type_info();139};140141/**142* Base class for class type info. Used only for tentative definitions.143*/144struct __class_type_info : public std::type_info145{146virtual ~__class_type_info();147/**148* Function implementing dynamic casts.149*/150virtual void *cast_to(void *obj, const struct __class_type_info *other) const;151virtual bool __do_upcast(const __class_type_info *target,152void **thrown_object) const153{154return this == target;155}156};157158/**159* Single-inheritance class type info. This is used for classes containing160* a single non-virtual base class at offset 0.161*/162struct __si_class_type_info : public __class_type_info163{164virtual ~__si_class_type_info();165const __class_type_info *__base_type;166virtual bool __do_upcast(167const ABI_NAMESPACE::__class_type_info *target,168void **thrown_object) const;169virtual void *cast_to(void *obj, const struct __class_type_info *other) const;170};171172/**173* Type info for base classes. Classes with multiple bases store an array174* of these, one for each superclass.175*/176struct __base_class_type_info177{178const __class_type_info *__base_type;179private:180/**181* The high __offset_shift bits of this store the (signed) offset182* of the base class. The low bits store flags from183* __offset_flags_masks.184*/185long __offset_flags;186/**187* Flags used in the low bits of __offset_flags.188*/189enum __offset_flags_masks190{191/** This base class is virtual. */192__virtual_mask = 0x1,193/** This base class is public. */194__public_mask = 0x2,195/** The number of bits reserved for flags. */196__offset_shift = 8197};198public:199/**200* Returns the offset of the base class.201*/202long offset() const203{204return __offset_flags >> __offset_shift;205}206/**207* Returns the flags.208*/209long flags() const210{211return __offset_flags & ((1 << __offset_shift) - 1);212}213/**214* Returns whether this is a public base class.215*/216bool isPublic() const { return flags() & __public_mask; }217/**218* Returns whether this is a virtual base class.219*/220bool isVirtual() const { return flags() & __virtual_mask; }221};222223/**224* Type info for classes with virtual bases or multiple superclasses.225*/226struct __vmi_class_type_info : public __class_type_info227{228virtual ~__vmi_class_type_info();229/** Flags describing this class. Contains values from __flags_masks. */230unsigned int __flags;231/** The number of base classes. */232unsigned int __base_count;233/**234* Array of base classes - this actually has __base_count elements, not235* 1.236*/237__base_class_type_info __base_info[1];238239/**240* Flags used in the __flags field.241*/242enum __flags_masks243{244/** The class has non-diamond repeated inheritance. */245__non_diamond_repeat_mask = 0x1,246/** The class is diamond shaped. */247__diamond_shaped_mask = 0x2248};249virtual bool __do_upcast(250const ABI_NAMESPACE::__class_type_info *target,251void **thrown_object) const;252virtual void *cast_to(void *obj, const struct __class_type_info *other) const;253};254255/**256* Base class used for both pointer and pointer-to-member type info.257*/258struct __pbase_type_info : public std::type_info259{260virtual ~__pbase_type_info();261/**262* Flags. Values from __masks.263*/264unsigned int __flags;265/**266* The type info for the pointee.267*/268const std::type_info *__pointee;269270/**271* Masks used for qualifiers on the pointer.272*/273enum __masks274{275/** Pointer has const qualifier. */276__const_mask = 0x1,277/** Pointer has volatile qualifier. */278__volatile_mask = 0x2,279/** Pointer has restrict qualifier. */280__restrict_mask = 0x4,281/** Pointer points to an incomplete type. */282__incomplete_mask = 0x8,283/** Pointer is a pointer to a member of an incomplete class. */284__incomplete_class_mask = 0x10285};286virtual bool __do_catch(const type_info *thrown_type,287void **thrown_object,288unsigned outer) const;289};290291/**292* Pointer type info.293*/294struct __pointer_type_info : public __pbase_type_info295{296virtual ~__pointer_type_info();297virtual bool __is_pointer_p() const { return true; }298};299300/**301* Pointer to member type info.302*/303struct __pointer_to_member_type_info : public __pbase_type_info304{305virtual ~__pointer_to_member_type_info();306/**307* Pointer to the class containing this member.308*/309const __class_type_info *__context;310};311312}313314315