1 |
17 |
jlechner |
// RTTI support for -*- C++ -*-
|
2 |
|
|
// Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002
|
3 |
|
|
// Free Software Foundation
|
4 |
|
|
//
|
5 |
|
|
// This file is part of GCC.
|
6 |
|
|
//
|
7 |
|
|
// GCC 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 |
|
|
// GCC 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 GCC; see the file COPYING. If not, write to
|
19 |
|
|
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
20 |
|
|
// Boston, MA 02110-1301, 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 |
|
|
|
31 |
|
|
/** @file typeinfo
|
32 |
|
|
* This header provides RTTI support.
|
33 |
|
|
*/
|
34 |
|
|
|
35 |
|
|
#ifndef _TYPEINFO
|
36 |
|
|
#define _TYPEINFO
|
37 |
|
|
|
38 |
|
|
#include
|
39 |
|
|
|
40 |
|
|
#pragma GCC visibility push(default)
|
41 |
|
|
|
42 |
|
|
extern "C++" {
|
43 |
|
|
|
44 |
|
|
namespace __cxxabiv1
|
45 |
|
|
{
|
46 |
|
|
class __class_type_info;
|
47 |
|
|
} // namespace __cxxabiv1
|
48 |
|
|
|
49 |
|
|
#ifndef __GXX_MERGED_TYPEINFO_NAMES
|
50 |
|
|
#if !__GXX_WEAK__
|
51 |
|
|
// If weak symbols are not supported, typeinfo names are not merged.
|
52 |
|
|
#define __GXX_MERGED_TYPEINFO_NAMES 0
|
53 |
|
|
#else
|
54 |
|
|
// On platforms that support weak symbols, typeinfo names are merged.
|
55 |
|
|
#define __GXX_MERGED_TYPEINFO_NAMES 1
|
56 |
|
|
#endif
|
57 |
|
|
#endif
|
58 |
|
|
|
59 |
|
|
namespace std
|
60 |
|
|
{
|
61 |
|
|
/**
|
62 |
|
|
* @brief Part of RTTI.
|
63 |
|
|
*
|
64 |
|
|
* The @c type_info class describes type information generated by
|
65 |
|
|
* an implementation.
|
66 |
|
|
*/
|
67 |
|
|
class type_info
|
68 |
|
|
{
|
69 |
|
|
public:
|
70 |
|
|
/** Destructor. Being the first non-inline virtual function, this
|
71 |
|
|
* controls in which translation unit the vtable is emitted. The
|
72 |
|
|
* compiler makes use of that information to know where to emit
|
73 |
|
|
* the runtime-mandated type_info structures in the new-abi. */
|
74 |
|
|
virtual ~type_info();
|
75 |
|
|
|
76 |
|
|
private:
|
77 |
|
|
/// Assigning type_info is not supported. Made private.
|
78 |
|
|
type_info& operator=(const type_info&);
|
79 |
|
|
type_info(const type_info&);
|
80 |
|
|
|
81 |
|
|
protected:
|
82 |
|
|
const char *__name;
|
83 |
|
|
|
84 |
|
|
protected:
|
85 |
|
|
explicit type_info(const char *__n): __name(__n) { }
|
86 |
|
|
|
87 |
|
|
public:
|
88 |
|
|
// the public interface
|
89 |
|
|
/** Returns an @e implementation-defined byte string; this is not
|
90 |
|
|
* portable between compilers! */
|
91 |
|
|
const char* name() const
|
92 |
|
|
{ return __name; }
|
93 |
|
|
|
94 |
|
|
#if !__GXX_MERGED_TYPEINFO_NAMES
|
95 |
|
|
bool before(const type_info& __arg) const;
|
96 |
|
|
// In old abi, or when weak symbols are not supported, there can
|
97 |
|
|
// be multiple instances of a type_info object for one
|
98 |
|
|
// type. Uniqueness must use the _name value, not object address.
|
99 |
|
|
bool operator==(const type_info& __arg) const;
|
100 |
|
|
#else
|
101 |
|
|
/** Returns true if @c *this precedes @c __arg in the implementation's
|
102 |
|
|
* collation order. */
|
103 |
|
|
// In new abi we can rely on type_info's NTBS being unique,
|
104 |
|
|
// and therefore address comparisons are sufficient.
|
105 |
|
|
bool before(const type_info& __arg) const
|
106 |
|
|
{ return __name < __arg.__name; }
|
107 |
|
|
bool operator==(const type_info& __arg) const
|
108 |
|
|
{ return __name == __arg.__name; }
|
109 |
|
|
#endif
|
110 |
|
|
bool operator!=(const type_info& __arg) const
|
111 |
|
|
{ return !operator==(__arg); }
|
112 |
|
|
|
113 |
|
|
// the internal interface
|
114 |
|
|
public:
|
115 |
|
|
// return true if this is a pointer type of some kind
|
116 |
|
|
virtual bool __is_pointer_p() const;
|
117 |
|
|
// return true if this is a function type
|
118 |
|
|
virtual bool __is_function_p() const;
|
119 |
|
|
|
120 |
|
|
// Try and catch a thrown type. Store an adjusted pointer to the
|
121 |
|
|
// caught type in THR_OBJ. If THR_TYPE is not a pointer type, then
|
122 |
|
|
// THR_OBJ points to the thrown object. If THR_TYPE is a pointer
|
123 |
|
|
// type, then THR_OBJ is the pointer itself. OUTER indicates the
|
124 |
|
|
// number of outer pointers, and whether they were const
|
125 |
|
|
// qualified.
|
126 |
|
|
virtual bool __do_catch(const type_info *__thr_type, void **__thr_obj,
|
127 |
|
|
unsigned __outer) const;
|
128 |
|
|
|
129 |
|
|
// internally used during catch matching
|
130 |
|
|
virtual bool __do_upcast(const __cxxabiv1::__class_type_info *__target,
|
131 |
|
|
void **__obj_ptr) const;
|
132 |
|
|
};
|
133 |
|
|
|
134 |
|
|
/**
|
135 |
|
|
* @brief Thrown during incorrect typecasting.
|
136 |
|
|
*
|
137 |
|
|
* If you attempt an invalid @c dynamic_cast expression, an instance of
|
138 |
|
|
* this class (or something derived from this class) is thrown. */
|
139 |
|
|
class bad_cast : public exception
|
140 |
|
|
{
|
141 |
|
|
public:
|
142 |
|
|
bad_cast() throw() { }
|
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 |
|
|
|
148 |
|
|
/** If you use a NULL pointer in a @c typeid expression, this is thrown. */
|
149 |
|
|
class bad_typeid : public exception
|
150 |
|
|
{
|
151 |
|
|
public:
|
152 |
|
|
bad_typeid () throw() { }
|
153 |
|
|
// This declaration is not useless:
|
154 |
|
|
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
|
155 |
|
|
virtual ~bad_typeid() throw();
|
156 |
|
|
};
|
157 |
|
|
} // namespace std
|
158 |
|
|
|
159 |
|
|
#pragma GCC visibility pop
|
160 |
|
|
|
161 |
|
|
} // extern "C++"
|
162 |
|
|
#endif
|