00001 // RTTI support for -*- C++ -*- 00002 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 00003 // 2003, 2004, 2005, 2006, 2007, 2009 00004 // Free Software Foundation 00005 // 00006 // This file is part of GCC. 00007 // 00008 // GCC is free software; you can redistribute it and/or modify 00009 // it under the terms of the GNU General Public License as published by 00010 // the Free Software Foundation; either version 3, or (at your option) 00011 // any later version. 00012 // 00013 // GCC is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // Under Section 7 of GPL version 3, you are granted additional 00019 // permissions described in the GCC Runtime Library Exception, version 00020 // 3.1, as published by the Free Software Foundation. 00021 00022 // You should have received a copy of the GNU General Public License and 00023 // a copy of the GCC Runtime Library Exception along with this program; 00024 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00025 // <http://www.gnu.org/licenses/>. 00026 00027 /** @file typeinfo 00028 * This is a Standard C++ Library header. 00029 */ 00030 00031 #ifndef _TYPEINFO 00032 #define _TYPEINFO 00033 00034 #include <exception> 00035 00036 #pragma GCC visibility push(default) 00037 00038 extern "C++" { 00039 00040 namespace __cxxabiv1 00041 { 00042 class __class_type_info; 00043 } // namespace __cxxabiv1 00044 00045 // Determine whether typeinfo names for the same type are merged (in which 00046 // case comparison can just compare pointers) or not (in which case 00047 // strings must be compared and g++.dg/abi/local1.C will fail), and 00048 // whether comparison is to be implemented inline or not. By default we 00049 // use inline pointer comparison if weak symbols are available, and 00050 // out-of-line strcmp if not. Out-of-line pointer comparison is used 00051 // where the object files are to be portable to multiple systems, some of 00052 // which may not be able to use pointer comparison, but the particular 00053 // system for which libstdc++ is being built can use pointer comparison; 00054 // in particular for most ARM EABI systems, where the ABI specifies 00055 // out-of-line comparison. Inline strcmp is not currently supported. The 00056 // compiler's target configuration can override the defaults by defining 00057 // __GXX_TYPEINFO_EQUALITY_INLINE to 1 or 0 to indicate whether or not 00058 // comparison is inline, and __GXX_MERGED_TYPEINFO_NAMES to 1 or 0 to 00059 // indicate whether or not pointer comparison can be used. 00060 00061 #ifndef __GXX_MERGED_TYPEINFO_NAMES 00062 #if !__GXX_WEAK__ 00063 // If weak symbols are not supported, typeinfo names are not merged. 00064 #define __GXX_MERGED_TYPEINFO_NAMES 0 00065 #else 00066 // On platforms that support weak symbols, typeinfo names are merged. 00067 #define __GXX_MERGED_TYPEINFO_NAMES 1 00068 #endif 00069 #endif 00070 00071 // By default follow the same rules as for __GXX_MERGED_TYPEINFO_NAMES. 00072 #ifndef __GXX_TYPEINFO_EQUALITY_INLINE 00073 #if !__GXX_WEAK__ 00074 #define __GXX_TYPEINFO_EQUALITY_INLINE 0 00075 #else 00076 #define __GXX_TYPEINFO_EQUALITY_INLINE 1 00077 #endif 00078 #endif 00079 00080 namespace std 00081 { 00082 /** 00083 * @brief Part of RTTI. 00084 * 00085 * The @c type_info class describes type information generated by 00086 * an implementation. 00087 */ 00088 class type_info 00089 { 00090 public: 00091 /** Destructor first. Being the first non-inline virtual function, this 00092 * controls in which translation unit the vtable is emitted. The 00093 * compiler makes use of that information to know where to emit 00094 * the runtime-mandated type_info structures in the new-abi. */ 00095 virtual ~type_info(); 00096 00097 /** Returns an @e implementation-defined byte string; this is not 00098 * portable between compilers! */ 00099 const char* name() const 00100 { return __name; } 00101 00102 #if !__GXX_TYPEINFO_EQUALITY_INLINE 00103 bool before(const type_info& __arg) const; 00104 00105 // In old abi, or when weak symbols are not supported, there can 00106 // be multiple instances of a type_info object for one 00107 // type. Uniqueness must use the _name value, not object address. 00108 bool operator==(const type_info& __arg) const; 00109 #else 00110 #if !__GXX_MERGED_TYPEINFO_NAMES 00111 #error "Inline implementation of type_info comparision requires merging of type_info objects" 00112 #endif 00113 /** Returns true if @c *this precedes @c __arg in the implementation's 00114 * collation order. */ 00115 // In new abi we can rely on type_info's NTBS being unique, 00116 // and therefore address comparisons are sufficient. 00117 bool before(const type_info& __arg) const 00118 { return __name < __arg.__name; } 00119 00120 bool operator==(const type_info& __arg) const 00121 { return __name == __arg.__name; } 00122 #endif 00123 bool operator!=(const type_info& __arg) const 00124 { return !operator==(__arg); } 00125 00126 // Return true if this is a pointer type of some kind 00127 virtual bool __is_pointer_p() const; 00128 00129 // Return true if this is a function type 00130 virtual bool __is_function_p() const; 00131 00132 // Try and catch a thrown type. Store an adjusted pointer to the 00133 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then 00134 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer 00135 // type, then THR_OBJ is the pointer itself. OUTER indicates the 00136 // number of outer pointers, and whether they were const 00137 // qualified. 00138 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj, 00139 unsigned __outer) const; 00140 00141 // Internally used during catch matching 00142 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target, 00143 void **__obj_ptr) const; 00144 00145 protected: 00146 const char *__name; 00147 00148 explicit type_info(const char *__n): __name(__n) { } 00149 00150 private: 00151 /// Assigning type_info is not supported. 00152 type_info& operator=(const type_info&); 00153 type_info(const type_info&); 00154 }; 00155 00156 /** 00157 * @brief Thrown during incorrect typecasting. 00158 * @ingroup exceptions 00159 * 00160 * If you attempt an invalid @c dynamic_cast expression, an instance of 00161 * this class (or something derived from this class) is thrown. */ 00162 class bad_cast : public exception 00163 { 00164 public: 00165 bad_cast() throw() { } 00166 00167 // This declaration is not useless: 00168 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00169 virtual ~bad_cast() throw(); 00170 00171 // See comment in eh_exception.cc. 00172 virtual const char* what() const throw(); 00173 }; 00174 00175 /** 00176 * @brief Thrown when a NULL pointer in a @c typeid expression is used. 00177 * @ingroup exceptions 00178 */ 00179 class bad_typeid : public exception 00180 { 00181 public: 00182 bad_typeid () throw() { } 00183 00184 // This declaration is not useless: 00185 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00186 virtual ~bad_typeid() throw(); 00187 00188 // See comment in eh_exception.cc. 00189 virtual const char* what() const throw(); 00190 }; 00191 } // namespace std 00192 00193 #pragma GCC visibility pop 00194 00195 } // extern "C++" 00196 #endif