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