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