1 // Methods for type_info for -*- C++ -*- Run Time Type Identification.
2 // Copyright (C) 1994, 1996, 1998, 1999 Free Software Foundation
4 // This file is part of GNU CC.
6 // GNU CC is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // GNU CC is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with GNU CC; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330,
19 // Boston, MA 02111-1307, USA.
21 // As a special exception, if you link this library with other files,
22 // some of which are compiled with GCC, to produce an executable,
23 // this library does not by itself cause the resulting executable
24 // to be covered by the GNU General Public License.
25 // This exception does not however invalidate any other reasons why
26 // the executable file might be covered by the GNU General Public License.
28 #pragma implementation "typeinfo"
32 #include "new" // for placement new
34 // This file contains the minimal working set necessary to link with code
35 // that uses virtual functions and -frtti but does not actually use RTTI
42 // We can't rely on common symbols being shared between shared objects.
44 operator== (const std::type_info
& arg
) const
46 return (&arg
== this) || (strcmp (name (), arg
.name ()) == 0);
50 __rtti_class (void *addr
, const char *name
,
51 const __class_type_info::base_info
*bl
, size_t bn
)
52 { new (addr
) __class_type_info (name
, bl
, bn
); }
55 __rtti_si (void *addr
, const char *n
, const std::type_info
*ti
)
57 new (addr
) __si_type_info
58 (n
, static_cast <const __user_type_info
&> (*ti
));
62 __rtti_user (void *addr
, const char *name
)
63 { new (addr
) __user_type_info (name
); }
65 // dynamic_cast helper methods.
66 // Returns 1 if the cast succeeds, 0 otherwise. Stores the adjusted value
69 int __user_type_info::
70 dcast (const type_info
& to
, int, void *addr
, void **valp
,
71 const type_info
*, void *) const
78 dcast (const type_info
& to
, int require_public
, void *addr
, void **valp
,
79 const type_info
*sub
, void *subptr
) const
86 return base
.dcast (to
, require_public
, addr
, valp
, sub
, subptr
);
89 int __class_type_info::
90 dcast (const type_info
& desired
, int is_public
, void *objptr
, void **valp
,
91 const type_info
*sub
, void *subptr
) const
101 for (size_t i
= 0; i
< n_bases
; i
++)
103 if (is_public
&& base_list
[i
].access
!= PUBLIC
)
110 p
= (char *)objptr
+ base_list
[i
].offset
;
111 if (base_list
[i
].is_virtual
)
115 /* Preserve null pointer. */
118 if (base_list
[i
].base
->dcast (desired
, is_public
, p
, &p
, sub
, subptr
))
129 // Perhaps we're downcasting from *sub to desired; see if
130 // subptr is a subobject of exactly one of {match_found,p}.
132 const __user_type_info
&d
=
133 static_cast <const __user_type_info
&> (desired
);
136 d
.dcast (*sub
, 1, match
, &os
);
138 d
.dcast (*sub
, 1, p
, &ns
);
141 // Both have the same subobject, so we can't disambiguate;
142 // i.e. subptr is a virtual base.
144 else if (os
== subptr
)
146 else if (ns
== subptr
)
153 // We're not downcasting, so we can't disambiguate.