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 first. 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 /** Returns an @e implementation-defined byte string; this is not 78 * portable between compilers! */ 79 const char* name() const 80 { return __name; } 81 82#if !__GXX_MERGED_TYPEINFO_NAMES 83 bool before(const type_info& __arg) const; 84 85 // In old abi, or when weak symbols are not supported, there can 86 // be multiple instances of a type_info object for one 87 // type. Uniqueness must use the _name value, not object address. 88 bool operator==(const type_info& __arg) const; 89#else 90 /** Returns true if @c *this precedes @c __arg in the implementation's 91 * collation order. */ 92 // In new abi we can rely on type_info's NTBS being unique, 93 // and therefore address comparisons are sufficient. 94 bool before(const type_info& __arg) const 95 { return __name < __arg.__name; } 96 97 bool operator==(const type_info& __arg) const 98 { return __name == __arg.__name; } 99#endif 100 bool operator!=(const type_info& __arg) const 101 { return !operator==(__arg); } 102 103 // Try and catch a thrown type. Store an adjusted pointer to the 104 // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then 105 // THR_OBJ points to the thrown object. If THR_TYPE is a pointer 106 // type, then THR_OBJ is the pointer itself. OUTER indicates the 107 // number of outer pointers, and whether they were const 108 // qualified. 109 virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj, 110 unsigned __outer) const; 111 112 // Internally used during catch matching 113 virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target, 114 void **__obj_ptr) const; 115 116 // Return true if this is a pointer type of some kind 117 virtual bool __is_pointer_p() const; 118 119 // Return true if this is a function type 120 virtual bool __is_function_p() const; 121 122 protected: 123 const char *__name; 124 125 explicit type_info(const char *__n): __name(__n) { } 126 127 private: 128 /// Assigning type_info is not supported. 129 type_info& operator=(const type_info&); 130 type_info(const type_info&); 131 }; 132 133 /** 134 * @brief Thrown during incorrect typecasting. 135 * 136 * If you attempt an invalid @c dynamic_cast expression, an instance of 137 * this class (or something derived from this class) is thrown. */ 138 class bad_cast : public exception 139 { 140 public: 141 bad_cast() throw() { } 142 143 // This declaration is not useless: 144 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 145 virtual ~bad_cast() throw(); 146 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 157 // This declaration is not useless: 158 // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 159 virtual ~bad_typeid() throw(); 160 161 // See comment in eh_exception.cc. 162 virtual const char* what() const throw(); 163 }; 164} // namespace std 165 166#pragma GCC visibility pop 167 168} // extern "C++" 169#endif 170