1 |
424 |
jeremybenn |
// RTTI support for -*- C++ -*-
|
2 |
|
|
// Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
3 |
|
|
// 2003, 2004, 2005, 2006, 2007, 2009, 2010
|
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 3, 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 |
|
|
// Under Section 7 of GPL version 3, you are granted additional
|
19 |
|
|
// permissions described in the GCC Runtime Library Exception, version
|
20 |
|
|
// 3.1, as published by the Free Software Foundation.
|
21 |
|
|
|
22 |
|
|
// You should have received a copy of the GNU General Public License and
|
23 |
|
|
// a copy of the GCC Runtime Library Exception along with this program;
|
24 |
|
|
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
25 |
|
|
// .
|
26 |
|
|
|
27 |
|
|
/** @file typeinfo
|
28 |
|
|
* This is a Standard C++ Library header.
|
29 |
|
|
*/
|
30 |
|
|
|
31 |
|
|
#ifndef _TYPEINFO
|
32 |
|
|
#define _TYPEINFO
|
33 |
|
|
|
34 |
|
|
#pragma GCC system_header
|
35 |
|
|
|
36 |
|
|
#include
|
37 |
|
|
|
38 |
|
|
#pragma GCC visibility push(default)
|
39 |
|
|
|
40 |
|
|
extern "C++" {
|
41 |
|
|
|
42 |
|
|
namespace __cxxabiv1
|
43 |
|
|
{
|
44 |
|
|
class __class_type_info;
|
45 |
|
|
} // namespace __cxxabiv1
|
46 |
|
|
|
47 |
|
|
// Determine whether typeinfo names for the same type are merged (in which
|
48 |
|
|
// case comparison can just compare pointers) or not (in which case strings
|
49 |
|
|
// must be compared), and whether comparison is to be implemented inline or
|
50 |
|
|
// not. We used to do inline pointer comparison by default if weak symbols
|
51 |
|
|
// are available, but even with weak symbols sometimes names are not merged
|
52 |
|
|
// when objects are loaded with RTLD_LOCAL, so now we always use strcmp by
|
53 |
|
|
// default. For ABI compatibility, we do the strcmp inline if weak symbols
|
54 |
|
|
// are available, and out-of-line if not. Out-of-line pointer comparison
|
55 |
|
|
// is used where the object files are to be portable to multiple systems,
|
56 |
|
|
// some of which may not be able to use pointer comparison, but the
|
57 |
|
|
// particular system for which libstdc++ is being built can use pointer
|
58 |
|
|
// comparison; in particular for most ARM EABI systems, where the ABI
|
59 |
|
|
// specifies out-of-line comparison. The compiler's target configuration
|
60 |
|
|
// can override the defaults by defining __GXX_TYPEINFO_EQUALITY_INLINE to
|
61 |
|
|
// 1 or 0 to indicate whether or not comparison is inline, and
|
62 |
|
|
// __GXX_MERGED_TYPEINFO_NAMES to 1 or 0 to indicate whether or not pointer
|
63 |
|
|
// comparison can be used.
|
64 |
|
|
|
65 |
|
|
#ifndef __GXX_MERGED_TYPEINFO_NAMES
|
66 |
|
|
// By default, typeinfo names are not merged.
|
67 |
|
|
#define __GXX_MERGED_TYPEINFO_NAMES 0
|
68 |
|
|
#endif
|
69 |
|
|
|
70 |
|
|
// By default follow the old inline rules to avoid ABI changes.
|
71 |
|
|
#ifndef __GXX_TYPEINFO_EQUALITY_INLINE
|
72 |
|
|
#if !__GXX_WEAK__
|
73 |
|
|
#define __GXX_TYPEINFO_EQUALITY_INLINE 0
|
74 |
|
|
#else
|
75 |
|
|
#define __GXX_TYPEINFO_EQUALITY_INLINE 1
|
76 |
|
|
#endif
|
77 |
|
|
#endif
|
78 |
|
|
|
79 |
|
|
namespace std
|
80 |
|
|
{
|
81 |
|
|
/**
|
82 |
|
|
* @brief Part of RTTI.
|
83 |
|
|
*
|
84 |
|
|
* The @c type_info class describes type information generated by
|
85 |
|
|
* an implementation.
|
86 |
|
|
*/
|
87 |
|
|
class type_info
|
88 |
|
|
{
|
89 |
|
|
public:
|
90 |
|
|
/** Destructor first. Being the first non-inline virtual function, this
|
91 |
|
|
* controls in which translation unit the vtable is emitted. The
|
92 |
|
|
* compiler makes use of that information to know where to emit
|
93 |
|
|
* the runtime-mandated type_info structures in the new-abi. */
|
94 |
|
|
virtual ~type_info();
|
95 |
|
|
|
96 |
|
|
/** Returns an @e implementation-defined byte string; this is not
|
97 |
|
|
* portable between compilers! */
|
98 |
|
|
const char* name() const
|
99 |
|
|
{ return __name[0] == '*' ? __name + 1 : __name; }
|
100 |
|
|
|
101 |
|
|
#if !__GXX_TYPEINFO_EQUALITY_INLINE
|
102 |
|
|
// In old abi, or when weak symbols are not supported, there can
|
103 |
|
|
// be multiple instances of a type_info object for one
|
104 |
|
|
// type. Uniqueness must use the _name value, not object address.
|
105 |
|
|
bool before(const type_info& __arg) const;
|
106 |
|
|
bool operator==(const type_info& __arg) const;
|
107 |
|
|
#else
|
108 |
|
|
#if !__GXX_MERGED_TYPEINFO_NAMES
|
109 |
|
|
/** Returns true if @c *this precedes @c __arg in the implementation's
|
110 |
|
|
* collation order. */
|
111 |
|
|
// Even with the new abi, on systems that support dlopen
|
112 |
|
|
// we can run into cases where type_info names aren't merged,
|
113 |
|
|
// so we still need to do string comparison.
|
114 |
|
|
bool before(const type_info& __arg) const
|
115 |
|
|
{ return (__name[0] == '*' && __arg.__name[0] == '*')
|
116 |
|
|
? __name < __arg.__name
|
117 |
|
|
: __builtin_strcmp (__name, __arg.__name) < 0; }
|
118 |
|
|
|
119 |
|
|
bool operator==(const type_info& __arg) const
|
120 |
|
|
{
|
121 |
|
|
return ((__name == __arg.__name)
|
122 |
|
|
|| (__name[0] != '*' &&
|
123 |
|
|
__builtin_strcmp (__name, __arg.__name) == 0));
|
124 |
|
|
}
|
125 |
|
|
#else
|
126 |
|
|
// On some targets we can rely on type_info's NTBS being unique,
|
127 |
|
|
// and therefore address comparisons are sufficient.
|
128 |
|
|
bool before(const type_info& __arg) const
|
129 |
|
|
{ return __name < __arg.__name; }
|
130 |
|
|
|
131 |
|
|
bool operator==(const type_info& __arg) const
|
132 |
|
|
{ return __name == __arg.__name; }
|
133 |
|
|
#endif
|
134 |
|
|
#endif
|
135 |
|
|
bool operator!=(const type_info& __arg) const
|
136 |
|
|
{ return !operator==(__arg); }
|
137 |
|
|
|
138 |
|
|
// Return true if this is a pointer type of some kind
|
139 |
|
|
virtual bool __is_pointer_p() const;
|
140 |
|
|
|
141 |
|
|
// Return true if this is a function type
|
142 |
|
|
virtual bool __is_function_p() const;
|
143 |
|
|
|
144 |
|
|
// Try and catch a thrown type. Store an adjusted pointer to the
|
145 |
|
|
// caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
|
146 |
|
|
// THR_OBJ points to the thrown object. If THR_TYPE is a pointer
|
147 |
|
|
// type, then THR_OBJ is the pointer itself. OUTER indicates the
|
148 |
|
|
// number of outer pointers, and whether they were const
|
149 |
|
|
// qualified.
|
150 |
|
|
virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
|
151 |
|
|
unsigned __outer) const;
|
152 |
|
|
|
153 |
|
|
// Internally used during catch matching
|
154 |
|
|
virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
|
155 |
|
|
void **__obj_ptr) const;
|
156 |
|
|
|
157 |
|
|
protected:
|
158 |
|
|
const char *__name;
|
159 |
|
|
|
160 |
|
|
explicit type_info(const char *__n): __name(__n) { }
|
161 |
|
|
|
162 |
|
|
private:
|
163 |
|
|
/// Assigning type_info is not supported.
|
164 |
|
|
type_info& operator=(const type_info&);
|
165 |
|
|
type_info(const type_info&);
|
166 |
|
|
};
|
167 |
|
|
|
168 |
|
|
/**
|
169 |
|
|
* @brief Thrown during incorrect typecasting.
|
170 |
|
|
* @ingroup exceptions
|
171 |
|
|
*
|
172 |
|
|
* If you attempt an invalid @c dynamic_cast expression, an instance of
|
173 |
|
|
* this class (or something derived from this class) is thrown. */
|
174 |
|
|
class bad_cast : public exception
|
175 |
|
|
{
|
176 |
|
|
public:
|
177 |
|
|
bad_cast() throw() { }
|
178 |
|
|
|
179 |
|
|
// This declaration is not useless:
|
180 |
|
|
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
|
181 |
|
|
virtual ~bad_cast() throw();
|
182 |
|
|
|
183 |
|
|
// See comment in eh_exception.cc.
|
184 |
|
|
virtual const char* what() const throw();
|
185 |
|
|
};
|
186 |
|
|
|
187 |
|
|
/**
|
188 |
|
|
* @brief Thrown when a NULL pointer in a @c typeid expression is used.
|
189 |
|
|
* @ingroup exceptions
|
190 |
|
|
*/
|
191 |
|
|
class bad_typeid : public exception
|
192 |
|
|
{
|
193 |
|
|
public:
|
194 |
|
|
bad_typeid () throw() { }
|
195 |
|
|
|
196 |
|
|
// This declaration is not useless:
|
197 |
|
|
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
|
198 |
|
|
virtual ~bad_typeid() throw();
|
199 |
|
|
|
200 |
|
|
// See comment in eh_exception.cc.
|
201 |
|
|
virtual const char* what() const throw();
|
202 |
|
|
};
|
203 |
|
|
} // namespace std
|
204 |
|
|
|
205 |
|
|
#pragma GCC visibility pop
|
206 |
|
|
|
207 |
|
|
} // extern "C++"
|
208 |
|
|
#endif
|