1 // Methods for type_info for -*- C++ -*- Run Time Type Identification.
3 // Copyright (C) 1994, 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation
6 // This file is part of GCC.
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)
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.
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.
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.
34 #include "new" // for placement new
36 // We can't rely on having stdlib.h if we're freestanding.
37 extern "C" void abort ();
41 #if !__GXX_TYPEINFO_EQUALITY_INLINE
44 type_info::before (const type_info
&arg
) const
46 #if __GXX_MERGED_TYPEINFO_NAMES
47 return name () < arg
.name ();
49 return __builtin_strcmp (name (), arg
.name ()) < 0;
57 namespace __cxxabiv1
{
61 // This has special meaning to the compiler, and will cause it
62 // to emit the type_info structures for the fundamental types which are
63 // mandated to exist in the runtime.
64 __fundamental_type_info::
65 ~__fundamental_type_info ()
72 __function_type_info::
73 ~__function_type_info ()
85 ~__pointer_type_info ()
88 __pointer_to_member_type_info::
89 ~__pointer_to_member_type_info ()
92 bool __pointer_type_info::
93 __is_pointer_p () const
98 bool __function_type_info::
99 __is_function_p () const
104 bool __pbase_type_info::
105 __do_catch (const type_info
*thr_type
,
107 unsigned outer
) const
109 if (*this == *thr_type
)
110 return true; // same type
111 if (typeid (*this) != typeid (*thr_type
))
112 return false; // not both same kind of pointers
115 // We're not the same and our outer pointers are not all const qualified
116 // Therefore there must at least be a qualification conversion involved
117 // But for that to be valid, our outer pointers must be const qualified.
120 const __pbase_type_info
*thrown_type
=
121 static_cast <const __pbase_type_info
*> (thr_type
);
123 if (thrown_type
->__flags
& ~__flags
)
124 // We're less qualified.
127 if (!(__flags
& __const_mask
))
130 return __pointer_catch (thrown_type
, thr_obj
, outer
);
133 inline bool __pbase_type_info::
134 __pointer_catch (const __pbase_type_info
*thrown_type
,
136 unsigned outer
) const
138 return __pointee
->__do_catch (thrown_type
->__pointee
, thr_obj
, outer
+ 2);
141 bool __pointer_type_info::
142 __pointer_catch (const __pbase_type_info
*thrown_type
,
144 unsigned outer
) const
146 if (outer
< 2 && *__pointee
== typeid (void))
148 // conversion to void
149 return !thrown_type
->__pointee
->__is_function_p ();
152 return __pbase_type_info::__pointer_catch (thrown_type
, thr_obj
, outer
);
155 bool __pointer_to_member_type_info::
156 __pointer_catch (const __pbase_type_info
*thr_type
,
158 unsigned outer
) const
160 // This static cast is always valid, as our caller will have determined that
161 // thr_type is really a __pointer_to_member_type_info.
162 const __pointer_to_member_type_info
*thrown_type
=
163 static_cast <const __pointer_to_member_type_info
*> (thr_type
);
165 if (*__context
!= *thrown_type
->__context
)
166 return false; // not pointers to member of same class
168 return __pbase_type_info::__pointer_catch (thrown_type
, thr_obj
, outer
);