typeinfo revision 169691
1// RTTI support for -*- C++ -*- 2// Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 3// 2003, 2004, 2005, 2006, 2007 4// Free Software Foundation 5// 6// This file is part of GCC. 7// 8// GCC is free software; you can redistribute it and/or modify 9// it under the terms of the GNU General Public License as published by 10// the Free Software Foundation; either version 2, or (at your option) 11// any later version. 12// 13// GCC is distributed in the hope that it will be useful, 14// but WITHOUT ANY WARRANTY; without even the implied warranty of 15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16// GNU General Public License for more details. 17// 18// You should have received a copy of the GNU General Public License 19// along with GCC; see the file COPYING. If not, write to 20// the Free Software Foundation, 51 Franklin Street, Fifth Floor, 21// Boston, MA 02110-1301, USA. 22 23// As a special exception, you may use this file as part of a free software 24// library without restriction. Specifically, if other files instantiate 25// templates or use macros or inline functions from this file, or you compile 26// this file and link it with other files to produce an executable, this 27// file does not by itself cause the resulting executable to be covered by 28// the GNU General Public License. This exception does not however 29// invalidate any other reasons why the executable file might be covered by 30// the GNU General Public License. 31 32/** @file typeinfo 33 * This is a Standard C++ Library header. 34 */ 35 36#ifndef _TYPEINFO 37#define _TYPEINFO 38 39#include <exception> 40 41#pragma GCC visibility push(default) 42 43extern "C++" { 44 45namespace __cxxabiv1 46{ 47 class __class_type_info; 48} // namespace __cxxabiv1 49 50#ifndef __GXX_MERGED_TYPEINFO_NAMES 51 #if !__GXX_WEAK__ 52 // If weak symbols are not supported, typeinfo names are not merged. 53 #define __GXX_MERGED_TYPEINFO_NAMES 0 54 #else 55 // On platforms that support weak symbols, typeinfo names are merged. 56 #define __GXX_MERGED_TYPEINFO_NAMES 1 57 #endif 58#endif 59 60namespace std 61{ 62 /** 63 * @brief Part of RTTI. 64 * 65 * The @c type_info class describes type information generated by 66 * an implementation. 67 */ 68 class type_info 69 { 70 public: 71 /** Destructor. Being the first non-inline virtual function, this 72 * controls in which translation unit the vtable is emitted. The 73 * compiler makes use of that information to know where to emit 74 * the runtime-mandated type_info structures in the new-abi. */ 75 virtual ~type_info(); 76 77 private: 78 /// Assigning type_info is not supported. Made private. 79 type_info& operator=(const type_info&); 80 type_info(const type_info&); 81 82 protected: 83 const char *__name; 84 85 protected: 86 explicit type_info(const char *__n): __name(__n) { } 87 88 public: 89 // the public interface 90 /** Returns an @e implementation-defined byte string; this is not 91 * portable between compilers! */ 92 const char* name() const 93 { return __name; } 94 95#if !__GXX_MERGED_TYPEINFO_NAMES 96 bool before(const type_info& __arg) const; 97 // In old abi, or when weak symbols are not supported, there can 98 // be multiple instances of a type_info object for one 99 // type. Uniqueness must use the _name value, not object address. 100 bool operator==(const type_info& __arg) const; 101#else 102 /** Returns true if @c *this precedes @c __arg in the implementation's 103 * collation order. */ 104 // In new abi we can rely on type_info's NTBS being unique, 105 // and therefore address comparisons are sufficient. 106 bool before(const type_info& __arg) const 107 { return __name < __arg.__name; } 108 bool operator==(const type_info& __arg) const 109 { return __name == __arg.__name; } 110#endif 111 bool operator!=(const type_info& __arg) const 112 { return !operator==(__arg); } 113 114 // the internal interface 115 public: 116 // return true if this is a pointer type of some kind 117 virtual bool __is_pointer_p() const; 118 // return true if this is a function type 119 virtual bool __is_function_p() const; 120 121 // Try and catch a thrown type. Store an adjusted pointer to the 122 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then 123 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer 124 // type, then THR_OBJ is the pointer itself. OUTER indicates the 125 // number of outer pointers, and whether they were const 126 // qualified. 127 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj, 128 unsigned __outer) const; 129 130 // internally used during catch matching 131 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target, 132 void **__obj_ptr) const; 133 }; 134 135 /** 136 * @brief Thrown during incorrect typecasting. 137 * 138 * If you attempt an invalid @c dynamic_cast expression, an instance of 139 * this class (or something derived from this class) is thrown. */ 140 class bad_cast : public exception 141 { 142 public: 143 bad_cast() throw() { } 144 // This declaration is not useless: 145 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 146 virtual ~bad_cast() throw(); 147 // See comment in eh_exception.cc. 148 virtual const char* what() const throw(); 149 }; 150 151 /** If you use a NULL pointer in a @c typeid expression, this is thrown. */ 152 class bad_typeid : public exception 153 { 154 public: 155 bad_typeid () throw() { } 156 // This declaration is not useless: 157 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 158 virtual ~bad_typeid() throw(); 159 // See comment in eh_exception.cc. 160 virtual const char* what() const throw(); 161 }; 162} // namespace std 163 164#pragma GCC visibility pop 165 166} // extern "C++" 167#endif 168