00001 // RTTI support for -*- C++ -*- 00002 // Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002 00003 // Free Software Foundation 00004 // 00005 // This file is part of GCC. 00006 // 00007 // GCC is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 // 00012 // GCC is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GCC; see the file COPYING. If not, write to 00019 // the Free Software Foundation, 51 Franklin Street, Fifth Floor, 00020 // Boston, MA 02110-1301, USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 /** @file typeinfo 00032 * This header provides RTTI support. 00033 */ 00034 00035 #ifndef _TYPEINFO 00036 #define _TYPEINFO 00037 00038 #include <exception> 00039 00040 #pragma GCC visibility push(default) 00041 00042 extern "C++" { 00043 00044 namespace __cxxabiv1 00045 { 00046 class __class_type_info; 00047 } // namespace __cxxabiv1 00048 00049 #ifndef __GXX_MERGED_TYPEINFO_NAMES 00050 #if !__GXX_WEAK__ 00051 // If weak symbols are not supported, typeinfo names are not merged. 00052 #define __GXX_MERGED_TYPEINFO_NAMES 0 00053 #else 00054 // On platforms that support weak symbols, typeinfo names are merged. 00055 #define __GXX_MERGED_TYPEINFO_NAMES 1 00056 #endif 00057 #endif 00058 00059 namespace std 00060 { 00061 /** 00062 * @brief Part of RTTI. 00063 * 00064 * The @c type_info class describes type information generated by 00065 * an implementation. 00066 */ 00067 class type_info 00068 { 00069 public: 00070 /** Destructor. Being the first non-inline virtual function, this 00071 * controls in which translation unit the vtable is emitted. The 00072 * compiler makes use of that information to know where to emit 00073 * the runtime-mandated type_info structures in the new-abi. */ 00074 virtual ~type_info(); 00075 00076 private: 00077 /// Assigning type_info is not supported. Made private. 00078 type_info& operator=(const type_info&); 00079 type_info(const type_info&); 00080 00081 protected: 00082 const char *__name; 00083 00084 protected: 00085 explicit type_info(const char *__n): __name(__n) { } 00086 00087 public: 00088 // the public interface 00089 /** Returns an @e implementation-defined byte string; this is not 00090 * portable between compilers! */ 00091 const char* name() const 00092 { return __name; } 00093 00094 #if !__GXX_MERGED_TYPEINFO_NAMES 00095 bool before(const type_info& __arg) const; 00096 // In old abi, or when weak symbols are not supported, there can 00097 // be multiple instances of a type_info object for one 00098 // type. Uniqueness must use the _name value, not object address. 00099 bool operator==(const type_info& __arg) const; 00100 #else 00101 /** Returns true if @c *this precedes @c __arg in the implementation's 00102 * collation order. */ 00103 // In new abi we can rely on type_info's NTBS being unique, 00104 // and therefore address comparisons are sufficient. 00105 bool before(const type_info& __arg) const 00106 { return __name < __arg.__name; } 00107 bool operator==(const type_info& __arg) const 00108 { return __name == __arg.__name; } 00109 #endif 00110 bool operator!=(const type_info& __arg) const 00111 { return !operator==(__arg); } 00112 00113 // the internal interface 00114 public: 00115 // return true if this is a pointer type of some kind 00116 virtual bool __is_pointer_p() const; 00117 // return true if this is a function type 00118 virtual bool __is_function_p() const; 00119 00120 // Try and catch a thrown type. Store an adjusted pointer to the 00121 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then 00122 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer 00123 // type, then THR_OBJ is the pointer itself. OUTER indicates the 00124 // number of outer pointers, and whether they were const 00125 // qualified. 00126 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj, 00127 unsigned __outer) const; 00128 00129 // internally used during catch matching 00130 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target, 00131 void **__obj_ptr) const; 00132 }; 00133 00134 /** 00135 * @brief Thrown during incorrect typecasting. 00136 * 00137 * If you attempt an invalid @c dynamic_cast expression, an instance of 00138 * this class (or something derived from this class) is thrown. */ 00139 class bad_cast : public exception 00140 { 00141 public: 00142 bad_cast() throw() { } 00143 // This declaration is not useless: 00144 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00145 virtual ~bad_cast() throw(); 00146 }; 00147 00148 /** If you use a NULL pointer in a @c typeid expression, this is thrown. */ 00149 class bad_typeid : public exception 00150 { 00151 public: 00152 bad_typeid () throw() { } 00153 // This declaration is not useless: 00154 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 00155 virtual ~bad_typeid() throw(); 00156 }; 00157 } // namespace std 00158 00159 #pragma GCC visibility pop 00160 00161 } // extern "C++" 00162 #endif