]>
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 | // |
6305f20a BK |
5 | // This file is part of GNU CC. |
6 | // | |
7 | // GNU CC is free software; you can redistribute it and/or modify | |
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 | // | |
12 | // GNU CC is distributed in the hope that it will be useful, | |
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 | |
18 | // along with GNU CC; see the file COPYING. If not, write to | |
19 | // the Free Software Foundation, 59 Temple Place - Suite 330, | |
20 | // Boston, MA 02111-1307, USA. | |
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 PE |
31 | /** @file typeinfo |
32 | * This header provides RTTI support. | |
33 | */ | |
34 | ||
6305f20a BK |
35 | #ifndef __TYPEINFO__ |
36 | #define __TYPEINFO__ | |
37 | ||
6305f20a BK |
38 | #include <exception> |
39 | ||
40 | extern "C++" { | |
41 | ||
6305f20a BK |
42 | namespace __cxxabiv1 |
43 | { | |
44 | class __class_type_info; | |
45 | } // namespace __cxxabiv1 | |
6305f20a | 46 | |
94083e5d MM |
47 | #if !__GXX_WEAK__ |
48 | // If weak symbols are not supported, typeinfo names are not merged. | |
0f0b2faf MM |
49 | #define __GXX_MERGED_TYPEINFO_NAMES 0 |
50 | #else | |
94083e5d | 51 | // On platforms that support weak symbols, typeinfo names are merged. |
0f0b2faf MM |
52 | #define __GXX_MERGED_TYPEINFO_NAMES 1 |
53 | #endif | |
54 | ||
d34786e3 BK |
55 | namespace std |
56 | { | |
669f7a03 PE |
57 | /** The @c type_info class describes type information generated by |
58 | * an implementation. | |
59 | * @brief Used in RTTI. */ | |
d34786e3 BK |
60 | class type_info |
61 | { | |
62 | public: | |
669f7a03 PE |
63 | /** Destructor. Being the first non-inline virtual function, this |
64 | * controls in which translation unit the vtable is emitted. The | |
65 | * compiler makes use of that information to know where to emit | |
66 | * the runtime-mandated type_info structures in the new-abi. */ | |
d34786e3 BK |
67 | virtual ~type_info(); |
68 | ||
69 | private: | |
669f7a03 | 70 | /// Assigning type_info is not supported. Made private. |
d34786e3 BK |
71 | type_info& operator=(const type_info&); |
72 | type_info(const type_info&); | |
73 | ||
74 | protected: | |
75 | const char *__name; | |
76 | ||
77 | protected: | |
78 | explicit type_info(const char *__n): __name(__n) { } | |
79 | ||
80 | public: | |
81 | // the public interface | |
77cd227e | 82 | /** Returns an @e implementation-defined byte string; this is not |
669f7a03 | 83 | * portable between compilers! */ |
d34786e3 | 84 | const char* name() const |
6305f20a | 85 | { return __name; } |
6305f20a | 86 | |
0f0b2faf | 87 | #if !__GXX_MERGED_TYPEINFO_NAMES |
d3a193e3 | 88 | bool before(const type_info& __arg) const; |
0f0b2faf MM |
89 | // In old abi, or when weak symbols are not supported, there can |
90 | // be multiple instances of a type_info object for one | |
91 | // type. Uniqueness must use the _name value, not object address. | |
92 | bool operator==(const type_info& __arg) const; | |
6305f20a | 93 | #else |
c5504edb | 94 | /** Returns true if @c *this precedes @c __arg in the implementation's |
669f7a03 | 95 | * collation order. */ |
d34786e3 BK |
96 | // In new abi we can rely on type_info's NTBS being unique, |
97 | // and therefore address comparisons are sufficient. | |
98 | bool before(const type_info& __arg) const | |
6305f20a | 99 | { return __name < __arg.__name; } |
d34786e3 | 100 | bool operator==(const type_info& __arg) const |
6305f20a | 101 | { return __name == __arg.__name; } |
0f0b2faf | 102 | #endif |
d34786e3 BK |
103 | bool operator!=(const type_info& __arg) const |
104 | { return !operator==(__arg); } | |
d34786e3 BK |
105 | |
106 | // the internal interface | |
d34786e3 BK |
107 | public: |
108 | // return true if this is a pointer type of some kind | |
109 | virtual bool __is_pointer_p() const; | |
110 | // return true if this is a function type | |
111 | virtual bool __is_function_p() const; | |
112 | ||
113 | // Try and catch a thrown type. Store an adjusted pointer to the | |
114 | // caught type in THR_OBJ. If THR_TYPE is not a pointer type, then | |
115 | // THR_OBJ points to the thrown object. If THR_TYPE is a pointer | |
116 | // type, then THR_OBJ is the pointer itself. OUTER indicates the | |
117 | // number of outer pointers, and whether they were const | |
118 | // qualified. | |
119 | virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj, | |
120 | unsigned __outer) const; | |
121 | ||
122 | // internally used during catch matching | |
123 | virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target, | |
124 | void **__obj_ptr) const; | |
d34786e3 BK |
125 | }; |
126 | ||
669f7a03 PE |
127 | /** If you attempt an invalid @c dynamic_cast expression, an instance of |
128 | * this class (or something derived from this class) is thrown. */ | |
d34786e3 BK |
129 | class bad_cast : public exception |
130 | { | |
131 | public: | |
132 | bad_cast() throw() { } | |
e05cd3dd PC |
133 | // This declaration is not useless: |
134 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 | |
d66ae36a | 135 | virtual ~bad_cast() throw(); |
d34786e3 BK |
136 | }; |
137 | ||
669f7a03 | 138 | /** If you use a NULL pointer in a @c typeid expression, this is thrown. */ |
d34786e3 BK |
139 | class bad_typeid : public exception |
140 | { | |
141 | public: | |
142 | bad_typeid () throw() { } | |
e05cd3dd PC |
143 | // This declaration is not useless: |
144 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 | |
d66ae36a | 145 | virtual ~bad_typeid() throw(); |
d34786e3 | 146 | }; |
6305f20a BK |
147 | } // namespace std |
148 | ||
149 | } // extern "C++" | |
150 | #endif |