annotate gcc/cp/search.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Breadth-first and depth-first routines for
kono
parents:
diff changeset
2 searching multiple-inheritance lattice for GNU C++.
kono
parents:
diff changeset
3 Copyright (C) 1987-2017 Free Software Foundation, Inc.
kono
parents:
diff changeset
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 This file is part of GCC.
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
10 the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
11 any later version.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
16 GNU General Public License for more details.
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
19 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
20 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 /* High-level class interface. */
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #include "config.h"
kono
parents:
diff changeset
25 #include "system.h"
kono
parents:
diff changeset
26 #include "coretypes.h"
kono
parents:
diff changeset
27 #include "cp-tree.h"
kono
parents:
diff changeset
28 #include "intl.h"
kono
parents:
diff changeset
29 #include "toplev.h"
kono
parents:
diff changeset
30 #include "spellcheck-tree.h"
kono
parents:
diff changeset
31 #include "stringpool.h"
kono
parents:
diff changeset
32 #include "attribs.h"
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 static int is_subobject_of_p (tree, tree);
kono
parents:
diff changeset
35 static tree dfs_lookup_base (tree, void *);
kono
parents:
diff changeset
36 static tree dfs_dcast_hint_pre (tree, void *);
kono
parents:
diff changeset
37 static tree dfs_dcast_hint_post (tree, void *);
kono
parents:
diff changeset
38 static tree dfs_debug_mark (tree, void *);
kono
parents:
diff changeset
39 static int check_hidden_convs (tree, int, int, tree, tree, tree);
kono
parents:
diff changeset
40 static tree split_conversions (tree, tree, tree, tree);
kono
parents:
diff changeset
41 static int lookup_conversions_r (tree, int, int, tree, tree, tree *);
kono
parents:
diff changeset
42 static int look_for_overrides_r (tree, tree);
kono
parents:
diff changeset
43 static tree lookup_field_r (tree, void *);
kono
parents:
diff changeset
44 static tree dfs_accessible_post (tree, void *);
kono
parents:
diff changeset
45 static tree dfs_walk_once_accessible (tree, bool,
kono
parents:
diff changeset
46 tree (*pre_fn) (tree, void *),
kono
parents:
diff changeset
47 tree (*post_fn) (tree, void *),
kono
parents:
diff changeset
48 void *data);
kono
parents:
diff changeset
49 static tree dfs_access_in_type (tree, void *);
kono
parents:
diff changeset
50 static access_kind access_in_type (tree, tree);
kono
parents:
diff changeset
51 static tree dfs_get_pure_virtuals (tree, void *);
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 /* Data for lookup_base and its workers. */
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 struct lookup_base_data_s
kono
parents:
diff changeset
57 {
kono
parents:
diff changeset
58 tree t; /* type being searched. */
kono
parents:
diff changeset
59 tree base; /* The base type we're looking for. */
kono
parents:
diff changeset
60 tree binfo; /* Found binfo. */
kono
parents:
diff changeset
61 bool via_virtual; /* Found via a virtual path. */
kono
parents:
diff changeset
62 bool ambiguous; /* Found multiply ambiguous */
kono
parents:
diff changeset
63 bool repeated_base; /* Whether there are repeated bases in the
kono
parents:
diff changeset
64 hierarchy. */
kono
parents:
diff changeset
65 bool want_any; /* Whether we want any matching binfo. */
kono
parents:
diff changeset
66 };
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 /* Worker function for lookup_base. See if we've found the desired
kono
parents:
diff changeset
69 base and update DATA_ (a pointer to LOOKUP_BASE_DATA_S). */
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 static tree
kono
parents:
diff changeset
72 dfs_lookup_base (tree binfo, void *data_)
kono
parents:
diff changeset
73 {
kono
parents:
diff changeset
74 struct lookup_base_data_s *data = (struct lookup_base_data_s *) data_;
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->base))
kono
parents:
diff changeset
77 {
kono
parents:
diff changeset
78 if (!data->binfo)
kono
parents:
diff changeset
79 {
kono
parents:
diff changeset
80 data->binfo = binfo;
kono
parents:
diff changeset
81 data->via_virtual
kono
parents:
diff changeset
82 = binfo_via_virtual (data->binfo, data->t) != NULL_TREE;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 if (!data->repeated_base)
kono
parents:
diff changeset
85 /* If there are no repeated bases, we can stop now. */
kono
parents:
diff changeset
86 return binfo;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 if (data->want_any && !data->via_virtual)
kono
parents:
diff changeset
89 /* If this is a non-virtual base, then we can't do
kono
parents:
diff changeset
90 better. */
kono
parents:
diff changeset
91 return binfo;
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 return dfs_skip_bases;
kono
parents:
diff changeset
94 }
kono
parents:
diff changeset
95 else
kono
parents:
diff changeset
96 {
kono
parents:
diff changeset
97 gcc_assert (binfo != data->binfo);
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 /* We've found more than one matching binfo. */
kono
parents:
diff changeset
100 if (!data->want_any)
kono
parents:
diff changeset
101 {
kono
parents:
diff changeset
102 /* This is immediately ambiguous. */
kono
parents:
diff changeset
103 data->binfo = NULL_TREE;
kono
parents:
diff changeset
104 data->ambiguous = true;
kono
parents:
diff changeset
105 return error_mark_node;
kono
parents:
diff changeset
106 }
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 /* Prefer one via a non-virtual path. */
kono
parents:
diff changeset
109 if (!binfo_via_virtual (binfo, data->t))
kono
parents:
diff changeset
110 {
kono
parents:
diff changeset
111 data->binfo = binfo;
kono
parents:
diff changeset
112 data->via_virtual = false;
kono
parents:
diff changeset
113 return binfo;
kono
parents:
diff changeset
114 }
kono
parents:
diff changeset
115
kono
parents:
diff changeset
116 /* There must be repeated bases, otherwise we'd have stopped
kono
parents:
diff changeset
117 on the first base we found. */
kono
parents:
diff changeset
118 return dfs_skip_bases;
kono
parents:
diff changeset
119 }
kono
parents:
diff changeset
120 }
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 return NULL_TREE;
kono
parents:
diff changeset
123 }
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 /* Returns true if type BASE is accessible in T. (BASE is known to be
kono
parents:
diff changeset
126 a (possibly non-proper) base class of T.) If CONSIDER_LOCAL_P is
kono
parents:
diff changeset
127 true, consider any special access of the current scope, or access
kono
parents:
diff changeset
128 bestowed by friendship. */
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 bool
kono
parents:
diff changeset
131 accessible_base_p (tree t, tree base, bool consider_local_p)
kono
parents:
diff changeset
132 {
kono
parents:
diff changeset
133 tree decl;
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 /* [class.access.base]
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 A base class is said to be accessible if an invented public
kono
parents:
diff changeset
138 member of the base class is accessible.
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 If BASE is a non-proper base, this condition is trivially
kono
parents:
diff changeset
141 true. */
kono
parents:
diff changeset
142 if (same_type_p (t, base))
kono
parents:
diff changeset
143 return true;
kono
parents:
diff changeset
144 /* Rather than inventing a public member, we use the implicit
kono
parents:
diff changeset
145 public typedef created in the scope of every class. */
kono
parents:
diff changeset
146 decl = TYPE_FIELDS (base);
kono
parents:
diff changeset
147 while (!DECL_SELF_REFERENCE_P (decl))
kono
parents:
diff changeset
148 decl = DECL_CHAIN (decl);
kono
parents:
diff changeset
149 while (ANON_AGGR_TYPE_P (t))
kono
parents:
diff changeset
150 t = TYPE_CONTEXT (t);
kono
parents:
diff changeset
151 return accessible_p (t, decl, consider_local_p);
kono
parents:
diff changeset
152 }
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 /* Lookup BASE in the hierarchy dominated by T. Do access checking as
kono
parents:
diff changeset
155 ACCESS specifies. Return the binfo we discover. If KIND_PTR is
kono
parents:
diff changeset
156 non-NULL, fill with information about what kind of base we
kono
parents:
diff changeset
157 discovered.
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 If the base is inaccessible, or ambiguous, then error_mark_node is
kono
parents:
diff changeset
160 returned. If the tf_error bit of COMPLAIN is not set, no error
kono
parents:
diff changeset
161 is issued. */
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 tree
kono
parents:
diff changeset
164 lookup_base (tree t, tree base, base_access access,
kono
parents:
diff changeset
165 base_kind *kind_ptr, tsubst_flags_t complain)
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 tree binfo;
kono
parents:
diff changeset
168 tree t_binfo;
kono
parents:
diff changeset
169 base_kind bk;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 /* "Nothing" is definitely not derived from Base. */
kono
parents:
diff changeset
172 if (t == NULL_TREE)
kono
parents:
diff changeset
173 {
kono
parents:
diff changeset
174 if (kind_ptr)
kono
parents:
diff changeset
175 *kind_ptr = bk_not_base;
kono
parents:
diff changeset
176 return NULL_TREE;
kono
parents:
diff changeset
177 }
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 if (t == error_mark_node || base == error_mark_node)
kono
parents:
diff changeset
180 {
kono
parents:
diff changeset
181 if (kind_ptr)
kono
parents:
diff changeset
182 *kind_ptr = bk_not_base;
kono
parents:
diff changeset
183 return error_mark_node;
kono
parents:
diff changeset
184 }
kono
parents:
diff changeset
185 gcc_assert (TYPE_P (base));
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 if (!TYPE_P (t))
kono
parents:
diff changeset
188 {
kono
parents:
diff changeset
189 t_binfo = t;
kono
parents:
diff changeset
190 t = BINFO_TYPE (t);
kono
parents:
diff changeset
191 }
kono
parents:
diff changeset
192 else
kono
parents:
diff changeset
193 {
kono
parents:
diff changeset
194 t = complete_type (TYPE_MAIN_VARIANT (t));
kono
parents:
diff changeset
195 t_binfo = TYPE_BINFO (t);
kono
parents:
diff changeset
196 }
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 base = TYPE_MAIN_VARIANT (base);
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 /* If BASE is incomplete, it can't be a base of T--and instantiating it
kono
parents:
diff changeset
201 might cause an error. */
kono
parents:
diff changeset
202 if (t_binfo && CLASS_TYPE_P (base) && COMPLETE_OR_OPEN_TYPE_P (base))
kono
parents:
diff changeset
203 {
kono
parents:
diff changeset
204 struct lookup_base_data_s data;
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 data.t = t;
kono
parents:
diff changeset
207 data.base = base;
kono
parents:
diff changeset
208 data.binfo = NULL_TREE;
kono
parents:
diff changeset
209 data.ambiguous = data.via_virtual = false;
kono
parents:
diff changeset
210 data.repeated_base = CLASSTYPE_REPEATED_BASE_P (t);
kono
parents:
diff changeset
211 data.want_any = access == ba_any;
kono
parents:
diff changeset
212
kono
parents:
diff changeset
213 dfs_walk_once (t_binfo, dfs_lookup_base, NULL, &data);
kono
parents:
diff changeset
214 binfo = data.binfo;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 if (!binfo)
kono
parents:
diff changeset
217 bk = data.ambiguous ? bk_ambig : bk_not_base;
kono
parents:
diff changeset
218 else if (binfo == t_binfo)
kono
parents:
diff changeset
219 bk = bk_same_type;
kono
parents:
diff changeset
220 else if (data.via_virtual)
kono
parents:
diff changeset
221 bk = bk_via_virtual;
kono
parents:
diff changeset
222 else
kono
parents:
diff changeset
223 bk = bk_proper_base;
kono
parents:
diff changeset
224 }
kono
parents:
diff changeset
225 else
kono
parents:
diff changeset
226 {
kono
parents:
diff changeset
227 binfo = NULL_TREE;
kono
parents:
diff changeset
228 bk = bk_not_base;
kono
parents:
diff changeset
229 }
kono
parents:
diff changeset
230
kono
parents:
diff changeset
231 /* Check that the base is unambiguous and accessible. */
kono
parents:
diff changeset
232 if (access != ba_any)
kono
parents:
diff changeset
233 switch (bk)
kono
parents:
diff changeset
234 {
kono
parents:
diff changeset
235 case bk_not_base:
kono
parents:
diff changeset
236 break;
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 case bk_ambig:
kono
parents:
diff changeset
239 if (complain & tf_error)
kono
parents:
diff changeset
240 error ("%qT is an ambiguous base of %qT", base, t);
kono
parents:
diff changeset
241 binfo = error_mark_node;
kono
parents:
diff changeset
242 break;
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 default:
kono
parents:
diff changeset
245 if ((access & ba_check_bit)
kono
parents:
diff changeset
246 /* If BASE is incomplete, then BASE and TYPE are probably
kono
parents:
diff changeset
247 the same, in which case BASE is accessible. If they
kono
parents:
diff changeset
248 are not the same, then TYPE is invalid. In that case,
kono
parents:
diff changeset
249 there's no need to issue another error here, and
kono
parents:
diff changeset
250 there's no implicit typedef to use in the code that
kono
parents:
diff changeset
251 follows, so we skip the check. */
kono
parents:
diff changeset
252 && COMPLETE_TYPE_P (base)
kono
parents:
diff changeset
253 && !accessible_base_p (t, base, !(access & ba_ignore_scope)))
kono
parents:
diff changeset
254 {
kono
parents:
diff changeset
255 if (complain & tf_error)
kono
parents:
diff changeset
256 error ("%qT is an inaccessible base of %qT", base, t);
kono
parents:
diff changeset
257 binfo = error_mark_node;
kono
parents:
diff changeset
258 bk = bk_inaccessible;
kono
parents:
diff changeset
259 }
kono
parents:
diff changeset
260 break;
kono
parents:
diff changeset
261 }
kono
parents:
diff changeset
262
kono
parents:
diff changeset
263 if (kind_ptr)
kono
parents:
diff changeset
264 *kind_ptr = bk;
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 return binfo;
kono
parents:
diff changeset
267 }
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 /* Data for dcast_base_hint walker. */
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 struct dcast_data_s
kono
parents:
diff changeset
272 {
kono
parents:
diff changeset
273 tree subtype; /* The base type we're looking for. */
kono
parents:
diff changeset
274 int virt_depth; /* Number of virtual bases encountered from most
kono
parents:
diff changeset
275 derived. */
kono
parents:
diff changeset
276 tree offset; /* Best hint offset discovered so far. */
kono
parents:
diff changeset
277 bool repeated_base; /* Whether there are repeated bases in the
kono
parents:
diff changeset
278 hierarchy. */
kono
parents:
diff changeset
279 };
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 /* Worker for dcast_base_hint. Search for the base type being cast
kono
parents:
diff changeset
282 from. */
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 static tree
kono
parents:
diff changeset
285 dfs_dcast_hint_pre (tree binfo, void *data_)
kono
parents:
diff changeset
286 {
kono
parents:
diff changeset
287 struct dcast_data_s *data = (struct dcast_data_s *) data_;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
290 data->virt_depth++;
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), data->subtype))
kono
parents:
diff changeset
293 {
kono
parents:
diff changeset
294 if (data->virt_depth)
kono
parents:
diff changeset
295 {
kono
parents:
diff changeset
296 data->offset = ssize_int (-1);
kono
parents:
diff changeset
297 return data->offset;
kono
parents:
diff changeset
298 }
kono
parents:
diff changeset
299 if (data->offset)
kono
parents:
diff changeset
300 data->offset = ssize_int (-3);
kono
parents:
diff changeset
301 else
kono
parents:
diff changeset
302 data->offset = BINFO_OFFSET (binfo);
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 return data->repeated_base ? dfs_skip_bases : data->offset;
kono
parents:
diff changeset
305 }
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 return NULL_TREE;
kono
parents:
diff changeset
308 }
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 /* Worker for dcast_base_hint. Track the virtual depth. */
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 static tree
kono
parents:
diff changeset
313 dfs_dcast_hint_post (tree binfo, void *data_)
kono
parents:
diff changeset
314 {
kono
parents:
diff changeset
315 struct dcast_data_s *data = (struct dcast_data_s *) data_;
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
318 data->virt_depth--;
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 return NULL_TREE;
kono
parents:
diff changeset
321 }
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
kono
parents:
diff changeset
324 started from is related to the required TARGET type, in order to optimize
kono
parents:
diff changeset
325 the inheritance graph search. This information is independent of the
kono
parents:
diff changeset
326 current context, and ignores private paths, hence get_base_distance is
kono
parents:
diff changeset
327 inappropriate. Return a TREE specifying the base offset, BOFF.
kono
parents:
diff changeset
328 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
kono
parents:
diff changeset
329 and there are no public virtual SUBTYPE bases.
kono
parents:
diff changeset
330 BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
kono
parents:
diff changeset
331 BOFF == -2, SUBTYPE is not a public base.
kono
parents:
diff changeset
332 BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 tree
kono
parents:
diff changeset
335 dcast_base_hint (tree subtype, tree target)
kono
parents:
diff changeset
336 {
kono
parents:
diff changeset
337 struct dcast_data_s data;
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 data.subtype = subtype;
kono
parents:
diff changeset
340 data.virt_depth = 0;
kono
parents:
diff changeset
341 data.offset = NULL_TREE;
kono
parents:
diff changeset
342 data.repeated_base = CLASSTYPE_REPEATED_BASE_P (target);
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 dfs_walk_once_accessible (TYPE_BINFO (target), /*friends=*/false,
kono
parents:
diff changeset
345 dfs_dcast_hint_pre, dfs_dcast_hint_post, &data);
kono
parents:
diff changeset
346 return data.offset ? data.offset : ssize_int (-2);
kono
parents:
diff changeset
347 }
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 /* Search for a member with name NAME in a multiple inheritance
kono
parents:
diff changeset
350 lattice specified by TYPE. If it does not exist, return NULL_TREE.
kono
parents:
diff changeset
351 If the member is ambiguously referenced, return `error_mark_node'.
kono
parents:
diff changeset
352 Otherwise, return a DECL with the indicated name. If WANT_TYPE is
kono
parents:
diff changeset
353 true, type declarations are preferred. */
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 /* Return the FUNCTION_DECL, RECORD_TYPE, UNION_TYPE, or
kono
parents:
diff changeset
356 NAMESPACE_DECL corresponding to the innermost non-block scope. */
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 tree
kono
parents:
diff changeset
359 current_scope (void)
kono
parents:
diff changeset
360 {
kono
parents:
diff changeset
361 /* There are a number of cases we need to be aware of here:
kono
parents:
diff changeset
362 current_class_type current_function_decl
kono
parents:
diff changeset
363 global NULL NULL
kono
parents:
diff changeset
364 fn-local NULL SET
kono
parents:
diff changeset
365 class-local SET NULL
kono
parents:
diff changeset
366 class->fn SET SET
kono
parents:
diff changeset
367 fn->class SET SET
kono
parents:
diff changeset
368
kono
parents:
diff changeset
369 Those last two make life interesting. If we're in a function which is
kono
parents:
diff changeset
370 itself inside a class, we need decls to go into the fn's decls (our
kono
parents:
diff changeset
371 second case below). But if we're in a class and the class itself is
kono
parents:
diff changeset
372 inside a function, we need decls to go into the decls for the class. To
kono
parents:
diff changeset
373 achieve this last goal, we must see if, when both current_class_ptr and
kono
parents:
diff changeset
374 current_function_decl are set, the class was declared inside that
kono
parents:
diff changeset
375 function. If so, we know to put the decls into the class's scope. */
kono
parents:
diff changeset
376 if (current_function_decl && current_class_type
kono
parents:
diff changeset
377 && ((DECL_FUNCTION_MEMBER_P (current_function_decl)
kono
parents:
diff changeset
378 && same_type_p (DECL_CONTEXT (current_function_decl),
kono
parents:
diff changeset
379 current_class_type))
kono
parents:
diff changeset
380 || (DECL_FRIEND_CONTEXT (current_function_decl)
kono
parents:
diff changeset
381 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
kono
parents:
diff changeset
382 current_class_type))))
kono
parents:
diff changeset
383 return current_function_decl;
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 if (current_class_type)
kono
parents:
diff changeset
386 return current_class_type;
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 if (current_function_decl)
kono
parents:
diff changeset
389 return current_function_decl;
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 return current_namespace;
kono
parents:
diff changeset
392 }
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 /* Returns nonzero if we are currently in a function scope. Note
kono
parents:
diff changeset
395 that this function returns zero if we are within a local class, but
kono
parents:
diff changeset
396 not within a member function body of the local class. */
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 int
kono
parents:
diff changeset
399 at_function_scope_p (void)
kono
parents:
diff changeset
400 {
kono
parents:
diff changeset
401 tree cs = current_scope ();
kono
parents:
diff changeset
402 /* Also check cfun to make sure that we're really compiling
kono
parents:
diff changeset
403 this function (as opposed to having set current_function_decl
kono
parents:
diff changeset
404 for access checking or some such). */
kono
parents:
diff changeset
405 return (cs && TREE_CODE (cs) == FUNCTION_DECL
kono
parents:
diff changeset
406 && cfun && cfun->decl == current_function_decl);
kono
parents:
diff changeset
407 }
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 /* Returns true if the innermost active scope is a class scope. */
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 bool
kono
parents:
diff changeset
412 at_class_scope_p (void)
kono
parents:
diff changeset
413 {
kono
parents:
diff changeset
414 tree cs = current_scope ();
kono
parents:
diff changeset
415 return cs && TYPE_P (cs);
kono
parents:
diff changeset
416 }
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 /* Returns true if the innermost active scope is a namespace scope. */
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 bool
kono
parents:
diff changeset
421 at_namespace_scope_p (void)
kono
parents:
diff changeset
422 {
kono
parents:
diff changeset
423 tree cs = current_scope ();
kono
parents:
diff changeset
424 return cs && TREE_CODE (cs) == NAMESPACE_DECL;
kono
parents:
diff changeset
425 }
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 /* Return the scope of DECL, as appropriate when doing name-lookup. */
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 tree
kono
parents:
diff changeset
430 context_for_name_lookup (tree decl)
kono
parents:
diff changeset
431 {
kono
parents:
diff changeset
432 /* [class.union]
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 For the purposes of name lookup, after the anonymous union
kono
parents:
diff changeset
435 definition, the members of the anonymous union are considered to
kono
parents:
diff changeset
436 have been defined in the scope in which the anonymous union is
kono
parents:
diff changeset
437 declared. */
kono
parents:
diff changeset
438 tree context = DECL_CONTEXT (decl);
kono
parents:
diff changeset
439
kono
parents:
diff changeset
440 while (context && TYPE_P (context)
kono
parents:
diff changeset
441 && (ANON_AGGR_TYPE_P (context) || UNSCOPED_ENUM_P (context)))
kono
parents:
diff changeset
442 context = TYPE_CONTEXT (context);
kono
parents:
diff changeset
443 if (!context)
kono
parents:
diff changeset
444 context = global_namespace;
kono
parents:
diff changeset
445
kono
parents:
diff changeset
446 return context;
kono
parents:
diff changeset
447 }
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 /* Returns true iff DECL is declared in TYPE. */
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 static bool
kono
parents:
diff changeset
452 member_declared_in_type (tree decl, tree type)
kono
parents:
diff changeset
453 {
kono
parents:
diff changeset
454 /* A normal declaration obviously counts. */
kono
parents:
diff changeset
455 if (context_for_name_lookup (decl) == type)
kono
parents:
diff changeset
456 return true;
kono
parents:
diff changeset
457 /* So does a using or access declaration. */
kono
parents:
diff changeset
458 if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl)
kono
parents:
diff changeset
459 && purpose_member (type, DECL_ACCESS (decl)))
kono
parents:
diff changeset
460 return true;
kono
parents:
diff changeset
461 return false;
kono
parents:
diff changeset
462 }
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 /* The accessibility routines use BINFO_ACCESS for scratch space
kono
parents:
diff changeset
465 during the computation of the accessibility of some declaration. */
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 /* Avoid walking up past a declaration of the member. */
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 static tree
kono
parents:
diff changeset
470 dfs_access_in_type_pre (tree binfo, void *data)
kono
parents:
diff changeset
471 {
kono
parents:
diff changeset
472 tree decl = (tree) data;
kono
parents:
diff changeset
473 tree type = BINFO_TYPE (binfo);
kono
parents:
diff changeset
474 if (member_declared_in_type (decl, type))
kono
parents:
diff changeset
475 return dfs_skip_bases;
kono
parents:
diff changeset
476 return NULL_TREE;
kono
parents:
diff changeset
477 }
kono
parents:
diff changeset
478
kono
parents:
diff changeset
479 #define BINFO_ACCESS(NODE) \
kono
parents:
diff changeset
480 ((access_kind) ((TREE_PUBLIC (NODE) << 1) | TREE_PRIVATE (NODE)))
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 /* Set the access associated with NODE to ACCESS. */
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 #define SET_BINFO_ACCESS(NODE, ACCESS) \
kono
parents:
diff changeset
485 ((TREE_PUBLIC (NODE) = ((ACCESS) & 2) != 0), \
kono
parents:
diff changeset
486 (TREE_PRIVATE (NODE) = ((ACCESS) & 1) != 0))
kono
parents:
diff changeset
487
kono
parents:
diff changeset
488 /* Called from access_in_type via dfs_walk. Calculate the access to
kono
parents:
diff changeset
489 DATA (which is really a DECL) in BINFO. */
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491 static tree
kono
parents:
diff changeset
492 dfs_access_in_type (tree binfo, void *data)
kono
parents:
diff changeset
493 {
kono
parents:
diff changeset
494 tree decl = (tree) data;
kono
parents:
diff changeset
495 tree type = BINFO_TYPE (binfo);
kono
parents:
diff changeset
496 access_kind access = ak_none;
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 if (context_for_name_lookup (decl) == type)
kono
parents:
diff changeset
499 {
kono
parents:
diff changeset
500 /* If we have descended to the scope of DECL, just note the
kono
parents:
diff changeset
501 appropriate access. */
kono
parents:
diff changeset
502 if (TREE_PRIVATE (decl))
kono
parents:
diff changeset
503 access = ak_private;
kono
parents:
diff changeset
504 else if (TREE_PROTECTED (decl))
kono
parents:
diff changeset
505 access = ak_protected;
kono
parents:
diff changeset
506 else
kono
parents:
diff changeset
507 access = ak_public;
kono
parents:
diff changeset
508 }
kono
parents:
diff changeset
509 else
kono
parents:
diff changeset
510 {
kono
parents:
diff changeset
511 /* First, check for an access-declaration that gives us more
kono
parents:
diff changeset
512 access to the DECL. */
kono
parents:
diff changeset
513 if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl))
kono
parents:
diff changeset
514 {
kono
parents:
diff changeset
515 tree decl_access = purpose_member (type, DECL_ACCESS (decl));
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 if (decl_access)
kono
parents:
diff changeset
518 {
kono
parents:
diff changeset
519 decl_access = TREE_VALUE (decl_access);
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 if (decl_access == access_public_node)
kono
parents:
diff changeset
522 access = ak_public;
kono
parents:
diff changeset
523 else if (decl_access == access_protected_node)
kono
parents:
diff changeset
524 access = ak_protected;
kono
parents:
diff changeset
525 else if (decl_access == access_private_node)
kono
parents:
diff changeset
526 access = ak_private;
kono
parents:
diff changeset
527 else
kono
parents:
diff changeset
528 gcc_unreachable ();
kono
parents:
diff changeset
529 }
kono
parents:
diff changeset
530 }
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 if (!access)
kono
parents:
diff changeset
533 {
kono
parents:
diff changeset
534 int i;
kono
parents:
diff changeset
535 tree base_binfo;
kono
parents:
diff changeset
536 vec<tree, va_gc> *accesses;
kono
parents:
diff changeset
537
kono
parents:
diff changeset
538 /* Otherwise, scan our baseclasses, and pick the most favorable
kono
parents:
diff changeset
539 access. */
kono
parents:
diff changeset
540 accesses = BINFO_BASE_ACCESSES (binfo);
kono
parents:
diff changeset
541 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
542 {
kono
parents:
diff changeset
543 tree base_access = (*accesses)[i];
kono
parents:
diff changeset
544 access_kind base_access_now = BINFO_ACCESS (base_binfo);
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 if (base_access_now == ak_none || base_access_now == ak_private)
kono
parents:
diff changeset
547 /* If it was not accessible in the base, or only
kono
parents:
diff changeset
548 accessible as a private member, we can't access it
kono
parents:
diff changeset
549 all. */
kono
parents:
diff changeset
550 base_access_now = ak_none;
kono
parents:
diff changeset
551 else if (base_access == access_protected_node)
kono
parents:
diff changeset
552 /* Public and protected members in the base become
kono
parents:
diff changeset
553 protected here. */
kono
parents:
diff changeset
554 base_access_now = ak_protected;
kono
parents:
diff changeset
555 else if (base_access == access_private_node)
kono
parents:
diff changeset
556 /* Public and protected members in the base become
kono
parents:
diff changeset
557 private here. */
kono
parents:
diff changeset
558 base_access_now = ak_private;
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 /* See if the new access, via this base, gives more
kono
parents:
diff changeset
561 access than our previous best access. */
kono
parents:
diff changeset
562 if (base_access_now != ak_none
kono
parents:
diff changeset
563 && (access == ak_none || base_access_now < access))
kono
parents:
diff changeset
564 {
kono
parents:
diff changeset
565 access = base_access_now;
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 /* If the new access is public, we can't do better. */
kono
parents:
diff changeset
568 if (access == ak_public)
kono
parents:
diff changeset
569 break;
kono
parents:
diff changeset
570 }
kono
parents:
diff changeset
571 }
kono
parents:
diff changeset
572 }
kono
parents:
diff changeset
573 }
kono
parents:
diff changeset
574
kono
parents:
diff changeset
575 /* Note the access to DECL in TYPE. */
kono
parents:
diff changeset
576 SET_BINFO_ACCESS (binfo, access);
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 return NULL_TREE;
kono
parents:
diff changeset
579 }
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 /* Return the access to DECL in TYPE. */
kono
parents:
diff changeset
582
kono
parents:
diff changeset
583 static access_kind
kono
parents:
diff changeset
584 access_in_type (tree type, tree decl)
kono
parents:
diff changeset
585 {
kono
parents:
diff changeset
586 tree binfo = TYPE_BINFO (type);
kono
parents:
diff changeset
587
kono
parents:
diff changeset
588 /* We must take into account
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 [class.paths]
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 If a name can be reached by several paths through a multiple
kono
parents:
diff changeset
593 inheritance graph, the access is that of the path that gives
kono
parents:
diff changeset
594 most access.
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 The algorithm we use is to make a post-order depth-first traversal
kono
parents:
diff changeset
597 of the base-class hierarchy. As we come up the tree, we annotate
kono
parents:
diff changeset
598 each node with the most lenient access. */
kono
parents:
diff changeset
599 dfs_walk_once (binfo, dfs_access_in_type_pre, dfs_access_in_type, decl);
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 return BINFO_ACCESS (binfo);
kono
parents:
diff changeset
602 }
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 /* Returns nonzero if it is OK to access DECL named in TYPE through an object
kono
parents:
diff changeset
605 of OTYPE in the context of DERIVED. */
kono
parents:
diff changeset
606
kono
parents:
diff changeset
607 static int
kono
parents:
diff changeset
608 protected_accessible_p (tree decl, tree derived, tree type, tree otype)
kono
parents:
diff changeset
609 {
kono
parents:
diff changeset
610 /* We're checking this clause from [class.access.base]
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 m as a member of N is protected, and the reference occurs in a
kono
parents:
diff changeset
613 member or friend of class N, or in a member or friend of a
kono
parents:
diff changeset
614 class P derived from N, where m as a member of P is public, private
kono
parents:
diff changeset
615 or protected.
kono
parents:
diff changeset
616
kono
parents:
diff changeset
617 Here DERIVED is a possible P, DECL is m and TYPE is N. */
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 /* If DERIVED isn't derived from N, then it can't be a P. */
kono
parents:
diff changeset
620 if (!DERIVED_FROM_P (type, derived))
kono
parents:
diff changeset
621 return 0;
kono
parents:
diff changeset
622
kono
parents:
diff changeset
623 /* [class.protected]
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 When a friend or a member function of a derived class references
kono
parents:
diff changeset
626 a protected nonstatic member of a base class, an access check
kono
parents:
diff changeset
627 applies in addition to those described earlier in clause
kono
parents:
diff changeset
628 _class.access_) Except when forming a pointer to member
kono
parents:
diff changeset
629 (_expr.unary.op_), the access must be through a pointer to,
kono
parents:
diff changeset
630 reference to, or object of the derived class itself (or any class
kono
parents:
diff changeset
631 derived from that class) (_expr.ref_). If the access is to form
kono
parents:
diff changeset
632 a pointer to member, the nested-name-specifier shall name the
kono
parents:
diff changeset
633 derived class (or any class derived from that class). */
kono
parents:
diff changeset
634 if (DECL_NONSTATIC_MEMBER_P (decl)
kono
parents:
diff changeset
635 && !DERIVED_FROM_P (derived, otype))
kono
parents:
diff changeset
636 return 0;
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 return 1;
kono
parents:
diff changeset
639 }
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 /* Returns nonzero if SCOPE is a type or a friend of a type which would be able
kono
parents:
diff changeset
642 to access DECL through TYPE. OTYPE is the type of the object. */
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644 static int
kono
parents:
diff changeset
645 friend_accessible_p (tree scope, tree decl, tree type, tree otype)
kono
parents:
diff changeset
646 {
kono
parents:
diff changeset
647 /* We're checking this clause from [class.access.base]
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 m as a member of N is protected, and the reference occurs in a
kono
parents:
diff changeset
650 member or friend of class N, or in a member or friend of a
kono
parents:
diff changeset
651 class P derived from N, where m as a member of P is public, private
kono
parents:
diff changeset
652 or protected.
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 Here DECL is m and TYPE is N. SCOPE is the current context,
kono
parents:
diff changeset
655 and we check all its possible Ps. */
kono
parents:
diff changeset
656 tree befriending_classes;
kono
parents:
diff changeset
657 tree t;
kono
parents:
diff changeset
658
kono
parents:
diff changeset
659 if (!scope)
kono
parents:
diff changeset
660 return 0;
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 if (is_global_friend (scope))
kono
parents:
diff changeset
663 return 1;
kono
parents:
diff changeset
664
kono
parents:
diff changeset
665 /* Is SCOPE itself a suitable P? */
kono
parents:
diff changeset
666 if (TYPE_P (scope) && protected_accessible_p (decl, scope, type, otype))
kono
parents:
diff changeset
667 return 1;
kono
parents:
diff changeset
668
kono
parents:
diff changeset
669 if (DECL_DECLARES_FUNCTION_P (scope))
kono
parents:
diff changeset
670 befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
kono
parents:
diff changeset
671 else if (TYPE_P (scope))
kono
parents:
diff changeset
672 befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
kono
parents:
diff changeset
673 else
kono
parents:
diff changeset
674 return 0;
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 for (t = befriending_classes; t; t = TREE_CHAIN (t))
kono
parents:
diff changeset
677 if (protected_accessible_p (decl, TREE_VALUE (t), type, otype))
kono
parents:
diff changeset
678 return 1;
kono
parents:
diff changeset
679
kono
parents:
diff changeset
680 /* Nested classes have the same access as their enclosing types, as
kono
parents:
diff changeset
681 per DR 45 (this is a change from C++98). */
kono
parents:
diff changeset
682 if (TYPE_P (scope))
kono
parents:
diff changeset
683 if (friend_accessible_p (TYPE_CONTEXT (scope), decl, type, otype))
kono
parents:
diff changeset
684 return 1;
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 if (DECL_DECLARES_FUNCTION_P (scope))
kono
parents:
diff changeset
687 {
kono
parents:
diff changeset
688 /* Perhaps this SCOPE is a member of a class which is a
kono
parents:
diff changeset
689 friend. */
kono
parents:
diff changeset
690 if (DECL_CLASS_SCOPE_P (scope)
kono
parents:
diff changeset
691 && friend_accessible_p (DECL_CONTEXT (scope), decl, type, otype))
kono
parents:
diff changeset
692 return 1;
kono
parents:
diff changeset
693 }
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 /* Maybe scope's template is a friend. */
kono
parents:
diff changeset
696 if (tree tinfo = get_template_info (scope))
kono
parents:
diff changeset
697 {
kono
parents:
diff changeset
698 tree tmpl = TI_TEMPLATE (tinfo);
kono
parents:
diff changeset
699 if (DECL_CLASS_TEMPLATE_P (tmpl))
kono
parents:
diff changeset
700 tmpl = TREE_TYPE (tmpl);
kono
parents:
diff changeset
701 else
kono
parents:
diff changeset
702 tmpl = DECL_TEMPLATE_RESULT (tmpl);
kono
parents:
diff changeset
703 if (tmpl != scope)
kono
parents:
diff changeset
704 {
kono
parents:
diff changeset
705 /* Increment processing_template_decl to make sure that
kono
parents:
diff changeset
706 dependent_type_p works correctly. */
kono
parents:
diff changeset
707 ++processing_template_decl;
kono
parents:
diff changeset
708 int ret = friend_accessible_p (tmpl, decl, type, otype);
kono
parents:
diff changeset
709 --processing_template_decl;
kono
parents:
diff changeset
710 if (ret)
kono
parents:
diff changeset
711 return 1;
kono
parents:
diff changeset
712 }
kono
parents:
diff changeset
713 }
kono
parents:
diff changeset
714
kono
parents:
diff changeset
715 /* If is_friend is true, we should have found a befriending class. */
kono
parents:
diff changeset
716 gcc_checking_assert (!is_friend (type, scope));
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 return 0;
kono
parents:
diff changeset
719 }
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 struct dfs_accessible_data
kono
parents:
diff changeset
722 {
kono
parents:
diff changeset
723 tree decl;
kono
parents:
diff changeset
724 tree object_type;
kono
parents:
diff changeset
725 };
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 /* Avoid walking up past a declaration of the member. */
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 static tree
kono
parents:
diff changeset
730 dfs_accessible_pre (tree binfo, void *data)
kono
parents:
diff changeset
731 {
kono
parents:
diff changeset
732 dfs_accessible_data *d = (dfs_accessible_data *)data;
kono
parents:
diff changeset
733 tree type = BINFO_TYPE (binfo);
kono
parents:
diff changeset
734 if (member_declared_in_type (d->decl, type))
kono
parents:
diff changeset
735 return dfs_skip_bases;
kono
parents:
diff changeset
736 return NULL_TREE;
kono
parents:
diff changeset
737 }
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 /* Called via dfs_walk_once_accessible from accessible_p */
kono
parents:
diff changeset
740
kono
parents:
diff changeset
741 static tree
kono
parents:
diff changeset
742 dfs_accessible_post (tree binfo, void *data)
kono
parents:
diff changeset
743 {
kono
parents:
diff changeset
744 /* access_in_type already set BINFO_ACCESS for us. */
kono
parents:
diff changeset
745 access_kind access = BINFO_ACCESS (binfo);
kono
parents:
diff changeset
746 tree N = BINFO_TYPE (binfo);
kono
parents:
diff changeset
747 dfs_accessible_data *d = (dfs_accessible_data *)data;
kono
parents:
diff changeset
748 tree decl = d->decl;
kono
parents:
diff changeset
749 tree scope = current_nonlambda_scope ();
kono
parents:
diff changeset
750
kono
parents:
diff changeset
751 /* A member m is accessible at the point R when named in class N if */
kono
parents:
diff changeset
752 switch (access)
kono
parents:
diff changeset
753 {
kono
parents:
diff changeset
754 case ak_none:
kono
parents:
diff changeset
755 return NULL_TREE;
kono
parents:
diff changeset
756
kono
parents:
diff changeset
757 case ak_public:
kono
parents:
diff changeset
758 /* m as a member of N is public, or */
kono
parents:
diff changeset
759 return binfo;
kono
parents:
diff changeset
760
kono
parents:
diff changeset
761 case ak_private:
kono
parents:
diff changeset
762 {
kono
parents:
diff changeset
763 /* m as a member of N is private, and R occurs in a member or friend of
kono
parents:
diff changeset
764 class N, or */
kono
parents:
diff changeset
765 if (scope && TREE_CODE (scope) != NAMESPACE_DECL
kono
parents:
diff changeset
766 && is_friend (N, scope))
kono
parents:
diff changeset
767 return binfo;
kono
parents:
diff changeset
768 return NULL_TREE;
kono
parents:
diff changeset
769 }
kono
parents:
diff changeset
770
kono
parents:
diff changeset
771 case ak_protected:
kono
parents:
diff changeset
772 {
kono
parents:
diff changeset
773 /* m as a member of N is protected, and R occurs in a member or friend
kono
parents:
diff changeset
774 of class N, or in a member or friend of a class P derived from N,
kono
parents:
diff changeset
775 where m as a member of P is public, private, or protected */
kono
parents:
diff changeset
776 if (friend_accessible_p (scope, decl, N, d->object_type))
kono
parents:
diff changeset
777 return binfo;
kono
parents:
diff changeset
778 return NULL_TREE;
kono
parents:
diff changeset
779 }
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 default:
kono
parents:
diff changeset
782 gcc_unreachable ();
kono
parents:
diff changeset
783 }
kono
parents:
diff changeset
784 }
kono
parents:
diff changeset
785
kono
parents:
diff changeset
786 /* Like accessible_p below, but within a template returns true iff DECL is
kono
parents:
diff changeset
787 accessible in TYPE to all possible instantiations of the template. */
kono
parents:
diff changeset
788
kono
parents:
diff changeset
789 int
kono
parents:
diff changeset
790 accessible_in_template_p (tree type, tree decl)
kono
parents:
diff changeset
791 {
kono
parents:
diff changeset
792 int save_ptd = processing_template_decl;
kono
parents:
diff changeset
793 processing_template_decl = 0;
kono
parents:
diff changeset
794 int val = accessible_p (type, decl, false);
kono
parents:
diff changeset
795 processing_template_decl = save_ptd;
kono
parents:
diff changeset
796 return val;
kono
parents:
diff changeset
797 }
kono
parents:
diff changeset
798
kono
parents:
diff changeset
799 /* DECL is a declaration from a base class of TYPE, which was the
kono
parents:
diff changeset
800 class used to name DECL. Return nonzero if, in the current
kono
parents:
diff changeset
801 context, DECL is accessible. If TYPE is actually a BINFO node,
kono
parents:
diff changeset
802 then we can tell in what context the access is occurring by looking
kono
parents:
diff changeset
803 at the most derived class along the path indicated by BINFO. If
kono
parents:
diff changeset
804 CONSIDER_LOCAL is true, do consider special access the current
kono
parents:
diff changeset
805 scope or friendship thereof we might have. */
kono
parents:
diff changeset
806
kono
parents:
diff changeset
807 int
kono
parents:
diff changeset
808 accessible_p (tree type, tree decl, bool consider_local_p)
kono
parents:
diff changeset
809 {
kono
parents:
diff changeset
810 tree binfo;
kono
parents:
diff changeset
811 access_kind access;
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 /* If this declaration is in a block or namespace scope, there's no
kono
parents:
diff changeset
814 access control. */
kono
parents:
diff changeset
815 if (!TYPE_P (context_for_name_lookup (decl)))
kono
parents:
diff changeset
816 return 1;
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 /* There is no need to perform access checks inside a thunk. */
kono
parents:
diff changeset
819 if (current_function_decl && DECL_THUNK_P (current_function_decl))
kono
parents:
diff changeset
820 return 1;
kono
parents:
diff changeset
821
kono
parents:
diff changeset
822 /* In a template declaration, we cannot be sure whether the
kono
parents:
diff changeset
823 particular specialization that is instantiated will be a friend
kono
parents:
diff changeset
824 or not. Therefore, all access checks are deferred until
kono
parents:
diff changeset
825 instantiation. However, PROCESSING_TEMPLATE_DECL is set in the
kono
parents:
diff changeset
826 parameter list for a template (because we may see dependent types
kono
parents:
diff changeset
827 in default arguments for template parameters), and access
kono
parents:
diff changeset
828 checking should be performed in the outermost parameter list. */
kono
parents:
diff changeset
829 if (processing_template_decl
kono
parents:
diff changeset
830 && !expanding_concept ()
kono
parents:
diff changeset
831 && (!processing_template_parmlist || processing_template_decl > 1))
kono
parents:
diff changeset
832 return 1;
kono
parents:
diff changeset
833
kono
parents:
diff changeset
834 tree otype = NULL_TREE;
kono
parents:
diff changeset
835 if (!TYPE_P (type))
kono
parents:
diff changeset
836 {
kono
parents:
diff changeset
837 /* When accessing a non-static member, the most derived type in the
kono
parents:
diff changeset
838 binfo chain is the type of the object; remember that type for
kono
parents:
diff changeset
839 protected_accessible_p. */
kono
parents:
diff changeset
840 for (tree b = type; b; b = BINFO_INHERITANCE_CHAIN (b))
kono
parents:
diff changeset
841 otype = BINFO_TYPE (b);
kono
parents:
diff changeset
842 type = BINFO_TYPE (type);
kono
parents:
diff changeset
843 }
kono
parents:
diff changeset
844 else
kono
parents:
diff changeset
845 otype = type;
kono
parents:
diff changeset
846
kono
parents:
diff changeset
847 /* [class.access.base]
kono
parents:
diff changeset
848
kono
parents:
diff changeset
849 A member m is accessible when named in class N if
kono
parents:
diff changeset
850
kono
parents:
diff changeset
851 --m as a member of N is public, or
kono
parents:
diff changeset
852
kono
parents:
diff changeset
853 --m as a member of N is private, and the reference occurs in a
kono
parents:
diff changeset
854 member or friend of class N, or
kono
parents:
diff changeset
855
kono
parents:
diff changeset
856 --m as a member of N is protected, and the reference occurs in a
kono
parents:
diff changeset
857 member or friend of class N, or in a member or friend of a
kono
parents:
diff changeset
858 class P derived from N, where m as a member of P is public, private or
kono
parents:
diff changeset
859 protected, or
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 --there exists a base class B of N that is accessible at the point
kono
parents:
diff changeset
862 of reference, and m is accessible when named in class B.
kono
parents:
diff changeset
863
kono
parents:
diff changeset
864 We walk the base class hierarchy, checking these conditions. */
kono
parents:
diff changeset
865
kono
parents:
diff changeset
866 /* We walk using TYPE_BINFO (type) because access_in_type will set
kono
parents:
diff changeset
867 BINFO_ACCESS on it and its bases. */
kono
parents:
diff changeset
868 binfo = TYPE_BINFO (type);
kono
parents:
diff changeset
869
kono
parents:
diff changeset
870 /* Compute the accessibility of DECL in the class hierarchy
kono
parents:
diff changeset
871 dominated by type. */
kono
parents:
diff changeset
872 access = access_in_type (type, decl);
kono
parents:
diff changeset
873 if (access == ak_public)
kono
parents:
diff changeset
874 return 1;
kono
parents:
diff changeset
875
kono
parents:
diff changeset
876 /* If we aren't considering the point of reference, only the first bullet
kono
parents:
diff changeset
877 applies. */
kono
parents:
diff changeset
878 if (!consider_local_p)
kono
parents:
diff changeset
879 return 0;
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 dfs_accessible_data d = { decl, otype };
kono
parents:
diff changeset
882
kono
parents:
diff changeset
883 /* Walk the hierarchy again, looking for a base class that allows
kono
parents:
diff changeset
884 access. */
kono
parents:
diff changeset
885 return dfs_walk_once_accessible (binfo, /*friends=*/true,
kono
parents:
diff changeset
886 dfs_accessible_pre,
kono
parents:
diff changeset
887 dfs_accessible_post, &d)
kono
parents:
diff changeset
888 != NULL_TREE;
kono
parents:
diff changeset
889 }
kono
parents:
diff changeset
890
kono
parents:
diff changeset
891 struct lookup_field_info {
kono
parents:
diff changeset
892 /* The type in which we're looking. */
kono
parents:
diff changeset
893 tree type;
kono
parents:
diff changeset
894 /* The name of the field for which we're looking. */
kono
parents:
diff changeset
895 tree name;
kono
parents:
diff changeset
896 /* If non-NULL, the current result of the lookup. */
kono
parents:
diff changeset
897 tree rval;
kono
parents:
diff changeset
898 /* The path to RVAL. */
kono
parents:
diff changeset
899 tree rval_binfo;
kono
parents:
diff changeset
900 /* If non-NULL, the lookup was ambiguous, and this is a list of the
kono
parents:
diff changeset
901 candidates. */
kono
parents:
diff changeset
902 tree ambiguous;
kono
parents:
diff changeset
903 /* If nonzero, we are looking for types, not data members. */
kono
parents:
diff changeset
904 int want_type;
kono
parents:
diff changeset
905 /* If something went wrong, a message indicating what. */
kono
parents:
diff changeset
906 const char *errstr;
kono
parents:
diff changeset
907 };
kono
parents:
diff changeset
908
kono
parents:
diff changeset
909 /* Nonzero for a class member means that it is shared between all objects
kono
parents:
diff changeset
910 of that class.
kono
parents:
diff changeset
911
kono
parents:
diff changeset
912 [class.member.lookup]:If the resulting set of declarations are not all
kono
parents:
diff changeset
913 from sub-objects of the same type, or the set has a nonstatic member
kono
parents:
diff changeset
914 and includes members from distinct sub-objects, there is an ambiguity
kono
parents:
diff changeset
915 and the program is ill-formed.
kono
parents:
diff changeset
916
kono
parents:
diff changeset
917 This function checks that T contains no nonstatic members. */
kono
parents:
diff changeset
918
kono
parents:
diff changeset
919 int
kono
parents:
diff changeset
920 shared_member_p (tree t)
kono
parents:
diff changeset
921 {
kono
parents:
diff changeset
922 if (VAR_P (t) || TREE_CODE (t) == TYPE_DECL \
kono
parents:
diff changeset
923 || TREE_CODE (t) == CONST_DECL)
kono
parents:
diff changeset
924 return 1;
kono
parents:
diff changeset
925 if (is_overloaded_fn (t))
kono
parents:
diff changeset
926 {
kono
parents:
diff changeset
927 for (ovl_iterator iter (get_fns (t)); iter; ++iter)
kono
parents:
diff changeset
928 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (*iter))
kono
parents:
diff changeset
929 return 0;
kono
parents:
diff changeset
930 return 1;
kono
parents:
diff changeset
931 }
kono
parents:
diff changeset
932 return 0;
kono
parents:
diff changeset
933 }
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 /* Routine to see if the sub-object denoted by the binfo PARENT can be
kono
parents:
diff changeset
936 found as a base class and sub-object of the object denoted by
kono
parents:
diff changeset
937 BINFO. */
kono
parents:
diff changeset
938
kono
parents:
diff changeset
939 static int
kono
parents:
diff changeset
940 is_subobject_of_p (tree parent, tree binfo)
kono
parents:
diff changeset
941 {
kono
parents:
diff changeset
942 tree probe;
kono
parents:
diff changeset
943
kono
parents:
diff changeset
944 for (probe = parent; probe; probe = BINFO_INHERITANCE_CHAIN (probe))
kono
parents:
diff changeset
945 {
kono
parents:
diff changeset
946 if (probe == binfo)
kono
parents:
diff changeset
947 return 1;
kono
parents:
diff changeset
948 if (BINFO_VIRTUAL_P (probe))
kono
parents:
diff changeset
949 return (binfo_for_vbase (BINFO_TYPE (probe), BINFO_TYPE (binfo))
kono
parents:
diff changeset
950 != NULL_TREE);
kono
parents:
diff changeset
951 }
kono
parents:
diff changeset
952 return 0;
kono
parents:
diff changeset
953 }
kono
parents:
diff changeset
954
kono
parents:
diff changeset
955 /* DATA is really a struct lookup_field_info. Look for a field with
kono
parents:
diff changeset
956 the name indicated there in BINFO. If this function returns a
kono
parents:
diff changeset
957 non-NULL value it is the result of the lookup. Called from
kono
parents:
diff changeset
958 lookup_field via breadth_first_search. */
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 static tree
kono
parents:
diff changeset
961 lookup_field_r (tree binfo, void *data)
kono
parents:
diff changeset
962 {
kono
parents:
diff changeset
963 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
kono
parents:
diff changeset
964 tree type = BINFO_TYPE (binfo);
kono
parents:
diff changeset
965 tree nval = NULL_TREE;
kono
parents:
diff changeset
966
kono
parents:
diff changeset
967 /* If this is a dependent base, don't look in it. */
kono
parents:
diff changeset
968 if (BINFO_DEPENDENT_BASE_P (binfo))
kono
parents:
diff changeset
969 return NULL_TREE;
kono
parents:
diff changeset
970
kono
parents:
diff changeset
971 /* If this base class is hidden by the best-known value so far, we
kono
parents:
diff changeset
972 don't need to look. */
kono
parents:
diff changeset
973 if (lfi->rval_binfo && BINFO_INHERITANCE_CHAIN (binfo) == lfi->rval_binfo
kono
parents:
diff changeset
974 && !BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
975 return dfs_skip_bases;
kono
parents:
diff changeset
976
kono
parents:
diff changeset
977 nval = get_class_binding (type, lfi->name, lfi->want_type);
kono
parents:
diff changeset
978
kono
parents:
diff changeset
979 /* If we're looking up a type (as with an elaborated type specifier)
kono
parents:
diff changeset
980 we ignore all non-types we find. */
kono
parents:
diff changeset
981 if (lfi->want_type && nval && !DECL_DECLARES_TYPE_P (nval))
kono
parents:
diff changeset
982 {
kono
parents:
diff changeset
983 nval = NULL_TREE;
kono
parents:
diff changeset
984 if (CLASSTYPE_NESTED_UTDS (type))
kono
parents:
diff changeset
985 if (binding_entry e = binding_table_find (CLASSTYPE_NESTED_UTDS (type),
kono
parents:
diff changeset
986 lfi->name))
kono
parents:
diff changeset
987 nval = TYPE_MAIN_DECL (e->type);
kono
parents:
diff changeset
988 }
kono
parents:
diff changeset
989
kono
parents:
diff changeset
990 /* If there is no declaration with the indicated name in this type,
kono
parents:
diff changeset
991 then there's nothing to do. */
kono
parents:
diff changeset
992 if (!nval)
kono
parents:
diff changeset
993 goto done;
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 /* If the lookup already found a match, and the new value doesn't
kono
parents:
diff changeset
996 hide the old one, we might have an ambiguity. */
kono
parents:
diff changeset
997 if (lfi->rval_binfo
kono
parents:
diff changeset
998 && !is_subobject_of_p (lfi->rval_binfo, binfo))
kono
parents:
diff changeset
999
kono
parents:
diff changeset
1000 {
kono
parents:
diff changeset
1001 if (nval == lfi->rval && shared_member_p (nval))
kono
parents:
diff changeset
1002 /* The two things are really the same. */
kono
parents:
diff changeset
1003 ;
kono
parents:
diff changeset
1004 else if (is_subobject_of_p (binfo, lfi->rval_binfo))
kono
parents:
diff changeset
1005 /* The previous value hides the new one. */
kono
parents:
diff changeset
1006 ;
kono
parents:
diff changeset
1007 else
kono
parents:
diff changeset
1008 {
kono
parents:
diff changeset
1009 /* We have a real ambiguity. We keep a chain of all the
kono
parents:
diff changeset
1010 candidates. */
kono
parents:
diff changeset
1011 if (!lfi->ambiguous && lfi->rval)
kono
parents:
diff changeset
1012 {
kono
parents:
diff changeset
1013 /* This is the first time we noticed an ambiguity. Add
kono
parents:
diff changeset
1014 what we previously thought was a reasonable candidate
kono
parents:
diff changeset
1015 to the list. */
kono
parents:
diff changeset
1016 lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
kono
parents:
diff changeset
1017 TREE_TYPE (lfi->ambiguous) = error_mark_node;
kono
parents:
diff changeset
1018 }
kono
parents:
diff changeset
1019
kono
parents:
diff changeset
1020 /* Add the new value. */
kono
parents:
diff changeset
1021 lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
kono
parents:
diff changeset
1022 TREE_TYPE (lfi->ambiguous) = error_mark_node;
kono
parents:
diff changeset
1023 lfi->errstr = G_("request for member %qD is ambiguous");
kono
parents:
diff changeset
1024 }
kono
parents:
diff changeset
1025 }
kono
parents:
diff changeset
1026 else
kono
parents:
diff changeset
1027 {
kono
parents:
diff changeset
1028 lfi->rval = nval;
kono
parents:
diff changeset
1029 lfi->rval_binfo = binfo;
kono
parents:
diff changeset
1030 }
kono
parents:
diff changeset
1031
kono
parents:
diff changeset
1032 done:
kono
parents:
diff changeset
1033 /* Don't look for constructors or destructors in base classes. */
kono
parents:
diff changeset
1034 if (IDENTIFIER_CDTOR_P (lfi->name))
kono
parents:
diff changeset
1035 return dfs_skip_bases;
kono
parents:
diff changeset
1036 return NULL_TREE;
kono
parents:
diff changeset
1037 }
kono
parents:
diff changeset
1038
kono
parents:
diff changeset
1039 /* Return a "baselink" with BASELINK_BINFO, BASELINK_ACCESS_BINFO,
kono
parents:
diff changeset
1040 BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
kono
parents:
diff changeset
1041 FUNCTIONS, and OPTYPE respectively. */
kono
parents:
diff changeset
1042
kono
parents:
diff changeset
1043 tree
kono
parents:
diff changeset
1044 build_baselink (tree binfo, tree access_binfo, tree functions, tree optype)
kono
parents:
diff changeset
1045 {
kono
parents:
diff changeset
1046 tree baselink;
kono
parents:
diff changeset
1047
kono
parents:
diff changeset
1048 gcc_assert (TREE_CODE (functions) == FUNCTION_DECL
kono
parents:
diff changeset
1049 || TREE_CODE (functions) == TEMPLATE_DECL
kono
parents:
diff changeset
1050 || TREE_CODE (functions) == TEMPLATE_ID_EXPR
kono
parents:
diff changeset
1051 || TREE_CODE (functions) == OVERLOAD);
kono
parents:
diff changeset
1052 gcc_assert (!optype || TYPE_P (optype));
kono
parents:
diff changeset
1053 gcc_assert (TREE_TYPE (functions));
kono
parents:
diff changeset
1054
kono
parents:
diff changeset
1055 baselink = make_node (BASELINK);
kono
parents:
diff changeset
1056 TREE_TYPE (baselink) = TREE_TYPE (functions);
kono
parents:
diff changeset
1057 BASELINK_BINFO (baselink) = binfo;
kono
parents:
diff changeset
1058 BASELINK_ACCESS_BINFO (baselink) = access_binfo;
kono
parents:
diff changeset
1059 BASELINK_FUNCTIONS (baselink) = functions;
kono
parents:
diff changeset
1060 BASELINK_OPTYPE (baselink) = optype;
kono
parents:
diff changeset
1061
kono
parents:
diff changeset
1062 return baselink;
kono
parents:
diff changeset
1063 }
kono
parents:
diff changeset
1064
kono
parents:
diff changeset
1065 /* Look for a member named NAME in an inheritance lattice dominated by
kono
parents:
diff changeset
1066 XBASETYPE. If PROTECT is 0 or two, we do not check access. If it
kono
parents:
diff changeset
1067 is 1, we enforce accessibility. If PROTECT is zero, then, for an
kono
parents:
diff changeset
1068 ambiguous lookup, we return NULL. If PROTECT is 1, we issue error
kono
parents:
diff changeset
1069 messages about inaccessible or ambiguous lookup. If PROTECT is 2,
kono
parents:
diff changeset
1070 we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
kono
parents:
diff changeset
1071 TREE_VALUEs are the list of ambiguous candidates.
kono
parents:
diff changeset
1072
kono
parents:
diff changeset
1073 WANT_TYPE is 1 when we should only return TYPE_DECLs.
kono
parents:
diff changeset
1074
kono
parents:
diff changeset
1075 If nothing can be found return NULL_TREE and do not issue an error.
kono
parents:
diff changeset
1076
kono
parents:
diff changeset
1077 If non-NULL, failure information is written back to AFI. */
kono
parents:
diff changeset
1078
kono
parents:
diff changeset
1079 tree
kono
parents:
diff changeset
1080 lookup_member (tree xbasetype, tree name, int protect, bool want_type,
kono
parents:
diff changeset
1081 tsubst_flags_t complain, access_failure_info *afi)
kono
parents:
diff changeset
1082 {
kono
parents:
diff changeset
1083 tree rval, rval_binfo = NULL_TREE;
kono
parents:
diff changeset
1084 tree type = NULL_TREE, basetype_path = NULL_TREE;
kono
parents:
diff changeset
1085 struct lookup_field_info lfi;
kono
parents:
diff changeset
1086
kono
parents:
diff changeset
1087 /* rval_binfo is the binfo associated with the found member, note,
kono
parents:
diff changeset
1088 this can be set with useful information, even when rval is not
kono
parents:
diff changeset
1089 set, because it must deal with ALL members, not just non-function
kono
parents:
diff changeset
1090 members. It is used for ambiguity checking and the hidden
kono
parents:
diff changeset
1091 checks. Whereas rval is only set if a proper (not hidden)
kono
parents:
diff changeset
1092 non-function member is found. */
kono
parents:
diff changeset
1093
kono
parents:
diff changeset
1094 const char *errstr = 0;
kono
parents:
diff changeset
1095
kono
parents:
diff changeset
1096 if (name == error_mark_node
kono
parents:
diff changeset
1097 || xbasetype == NULL_TREE
kono
parents:
diff changeset
1098 || xbasetype == error_mark_node)
kono
parents:
diff changeset
1099 return NULL_TREE;
kono
parents:
diff changeset
1100
kono
parents:
diff changeset
1101 gcc_assert (identifier_p (name));
kono
parents:
diff changeset
1102
kono
parents:
diff changeset
1103 if (TREE_CODE (xbasetype) == TREE_BINFO)
kono
parents:
diff changeset
1104 {
kono
parents:
diff changeset
1105 type = BINFO_TYPE (xbasetype);
kono
parents:
diff changeset
1106 basetype_path = xbasetype;
kono
parents:
diff changeset
1107 }
kono
parents:
diff changeset
1108 else
kono
parents:
diff changeset
1109 {
kono
parents:
diff changeset
1110 if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype)))
kono
parents:
diff changeset
1111 return NULL_TREE;
kono
parents:
diff changeset
1112 type = xbasetype;
kono
parents:
diff changeset
1113 xbasetype = NULL_TREE;
kono
parents:
diff changeset
1114 }
kono
parents:
diff changeset
1115
kono
parents:
diff changeset
1116 type = complete_type (type);
kono
parents:
diff changeset
1117
kono
parents:
diff changeset
1118 /* Make sure we're looking for a member of the current instantiation in the
kono
parents:
diff changeset
1119 right partial specialization. */
kono
parents:
diff changeset
1120 if (flag_concepts && dependent_type_p (type))
kono
parents:
diff changeset
1121 if (tree t = currently_open_class (type))
kono
parents:
diff changeset
1122 type = t;
kono
parents:
diff changeset
1123
kono
parents:
diff changeset
1124 if (!basetype_path)
kono
parents:
diff changeset
1125 basetype_path = TYPE_BINFO (type);
kono
parents:
diff changeset
1126
kono
parents:
diff changeset
1127 if (!basetype_path)
kono
parents:
diff changeset
1128 return NULL_TREE;
kono
parents:
diff changeset
1129
kono
parents:
diff changeset
1130 memset (&lfi, 0, sizeof (lfi));
kono
parents:
diff changeset
1131 lfi.type = type;
kono
parents:
diff changeset
1132 lfi.name = name;
kono
parents:
diff changeset
1133 lfi.want_type = want_type;
kono
parents:
diff changeset
1134 dfs_walk_all (basetype_path, &lookup_field_r, NULL, &lfi);
kono
parents:
diff changeset
1135 rval = lfi.rval;
kono
parents:
diff changeset
1136 rval_binfo = lfi.rval_binfo;
kono
parents:
diff changeset
1137 if (rval_binfo)
kono
parents:
diff changeset
1138 type = BINFO_TYPE (rval_binfo);
kono
parents:
diff changeset
1139 errstr = lfi.errstr;
kono
parents:
diff changeset
1140
kono
parents:
diff changeset
1141 /* If we are not interested in ambiguities, don't report them;
kono
parents:
diff changeset
1142 just return NULL_TREE. */
kono
parents:
diff changeset
1143 if (!protect && lfi.ambiguous)
kono
parents:
diff changeset
1144 return NULL_TREE;
kono
parents:
diff changeset
1145
kono
parents:
diff changeset
1146 if (protect == 2)
kono
parents:
diff changeset
1147 {
kono
parents:
diff changeset
1148 if (lfi.ambiguous)
kono
parents:
diff changeset
1149 return lfi.ambiguous;
kono
parents:
diff changeset
1150 else
kono
parents:
diff changeset
1151 protect = 0;
kono
parents:
diff changeset
1152 }
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 /* [class.access]
kono
parents:
diff changeset
1155
kono
parents:
diff changeset
1156 In the case of overloaded function names, access control is
kono
parents:
diff changeset
1157 applied to the function selected by overloaded resolution.
kono
parents:
diff changeset
1158
kono
parents:
diff changeset
1159 We cannot check here, even if RVAL is only a single non-static
kono
parents:
diff changeset
1160 member function, since we do not know what the "this" pointer
kono
parents:
diff changeset
1161 will be. For:
kono
parents:
diff changeset
1162
kono
parents:
diff changeset
1163 class A { protected: void f(); };
kono
parents:
diff changeset
1164 class B : public A {
kono
parents:
diff changeset
1165 void g(A *p) {
kono
parents:
diff changeset
1166 f(); // OK
kono
parents:
diff changeset
1167 p->f(); // Not OK.
kono
parents:
diff changeset
1168 }
kono
parents:
diff changeset
1169 };
kono
parents:
diff changeset
1170
kono
parents:
diff changeset
1171 only the first call to "f" is valid. However, if the function is
kono
parents:
diff changeset
1172 static, we can check. */
kono
parents:
diff changeset
1173 if (rval && protect
kono
parents:
diff changeset
1174 && !really_overloaded_fn (rval))
kono
parents:
diff changeset
1175 {
kono
parents:
diff changeset
1176 tree decl = is_overloaded_fn (rval) ? get_first_fn (rval) : rval;
kono
parents:
diff changeset
1177 if (!DECL_NONSTATIC_MEMBER_FUNCTION_P (decl)
kono
parents:
diff changeset
1178 && !perform_or_defer_access_check (basetype_path, decl, decl,
kono
parents:
diff changeset
1179 complain, afi))
kono
parents:
diff changeset
1180 rval = error_mark_node;
kono
parents:
diff changeset
1181 }
kono
parents:
diff changeset
1182
kono
parents:
diff changeset
1183 if (errstr && protect)
kono
parents:
diff changeset
1184 {
kono
parents:
diff changeset
1185 if (complain & tf_error)
kono
parents:
diff changeset
1186 {
kono
parents:
diff changeset
1187 error (errstr, name, type);
kono
parents:
diff changeset
1188 if (lfi.ambiguous)
kono
parents:
diff changeset
1189 print_candidates (lfi.ambiguous);
kono
parents:
diff changeset
1190 }
kono
parents:
diff changeset
1191 rval = error_mark_node;
kono
parents:
diff changeset
1192 }
kono
parents:
diff changeset
1193
kono
parents:
diff changeset
1194 if (rval && is_overloaded_fn (rval))
kono
parents:
diff changeset
1195 rval = build_baselink (rval_binfo, basetype_path, rval,
kono
parents:
diff changeset
1196 (IDENTIFIER_CONV_OP_P (name)
kono
parents:
diff changeset
1197 ? TREE_TYPE (name): NULL_TREE));
kono
parents:
diff changeset
1198 return rval;
kono
parents:
diff changeset
1199 }
kono
parents:
diff changeset
1200
kono
parents:
diff changeset
1201 /* Helper class for lookup_member_fuzzy. */
kono
parents:
diff changeset
1202
kono
parents:
diff changeset
1203 class lookup_field_fuzzy_info
kono
parents:
diff changeset
1204 {
kono
parents:
diff changeset
1205 public:
kono
parents:
diff changeset
1206 lookup_field_fuzzy_info (bool want_type_p) :
kono
parents:
diff changeset
1207 m_want_type_p (want_type_p), m_candidates () {}
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 void fuzzy_lookup_field (tree type);
kono
parents:
diff changeset
1210
kono
parents:
diff changeset
1211 /* If true, we are looking for types, not data members. */
kono
parents:
diff changeset
1212 bool m_want_type_p;
kono
parents:
diff changeset
1213 /* The result: a vec of identifiers. */
kono
parents:
diff changeset
1214 auto_vec<tree> m_candidates;
kono
parents:
diff changeset
1215 };
kono
parents:
diff changeset
1216
kono
parents:
diff changeset
1217 /* Locate all fields within TYPE, append them to m_candidates. */
kono
parents:
diff changeset
1218
kono
parents:
diff changeset
1219 void
kono
parents:
diff changeset
1220 lookup_field_fuzzy_info::fuzzy_lookup_field (tree type)
kono
parents:
diff changeset
1221 {
kono
parents:
diff changeset
1222 if (!CLASS_TYPE_P (type))
kono
parents:
diff changeset
1223 return;
kono
parents:
diff changeset
1224
kono
parents:
diff changeset
1225 for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
kono
parents:
diff changeset
1226 {
kono
parents:
diff changeset
1227 if (!m_want_type_p || DECL_DECLARES_TYPE_P (field))
kono
parents:
diff changeset
1228 if (DECL_NAME (field))
kono
parents:
diff changeset
1229 m_candidates.safe_push (DECL_NAME (field));
kono
parents:
diff changeset
1230 }
kono
parents:
diff changeset
1231 }
kono
parents:
diff changeset
1232
kono
parents:
diff changeset
1233
kono
parents:
diff changeset
1234 /* Helper function for lookup_member_fuzzy, called via dfs_walk_all
kono
parents:
diff changeset
1235 DATA is really a lookup_field_fuzzy_info. Look for a field with
kono
parents:
diff changeset
1236 the name indicated there in BINFO. Gathers pertinent identifiers into
kono
parents:
diff changeset
1237 m_candidates. */
kono
parents:
diff changeset
1238
kono
parents:
diff changeset
1239 static tree
kono
parents:
diff changeset
1240 lookup_field_fuzzy_r (tree binfo, void *data)
kono
parents:
diff changeset
1241 {
kono
parents:
diff changeset
1242 lookup_field_fuzzy_info *lffi = (lookup_field_fuzzy_info *) data;
kono
parents:
diff changeset
1243 tree type = BINFO_TYPE (binfo);
kono
parents:
diff changeset
1244
kono
parents:
diff changeset
1245 lffi->fuzzy_lookup_field (type);
kono
parents:
diff changeset
1246
kono
parents:
diff changeset
1247 return NULL_TREE;
kono
parents:
diff changeset
1248 }
kono
parents:
diff changeset
1249
kono
parents:
diff changeset
1250 /* Like lookup_member, but try to find the closest match for NAME,
kono
parents:
diff changeset
1251 rather than an exact match, and return an identifier (or NULL_TREE).
kono
parents:
diff changeset
1252 Do not complain. */
kono
parents:
diff changeset
1253
kono
parents:
diff changeset
1254 tree
kono
parents:
diff changeset
1255 lookup_member_fuzzy (tree xbasetype, tree name, bool want_type_p)
kono
parents:
diff changeset
1256 {
kono
parents:
diff changeset
1257 tree type = NULL_TREE, basetype_path = NULL_TREE;
kono
parents:
diff changeset
1258 struct lookup_field_fuzzy_info lffi (want_type_p);
kono
parents:
diff changeset
1259
kono
parents:
diff changeset
1260 /* rval_binfo is the binfo associated with the found member, note,
kono
parents:
diff changeset
1261 this can be set with useful information, even when rval is not
kono
parents:
diff changeset
1262 set, because it must deal with ALL members, not just non-function
kono
parents:
diff changeset
1263 members. It is used for ambiguity checking and the hidden
kono
parents:
diff changeset
1264 checks. Whereas rval is only set if a proper (not hidden)
kono
parents:
diff changeset
1265 non-function member is found. */
kono
parents:
diff changeset
1266
kono
parents:
diff changeset
1267 if (name == error_mark_node
kono
parents:
diff changeset
1268 || xbasetype == NULL_TREE
kono
parents:
diff changeset
1269 || xbasetype == error_mark_node)
kono
parents:
diff changeset
1270 return NULL_TREE;
kono
parents:
diff changeset
1271
kono
parents:
diff changeset
1272 gcc_assert (identifier_p (name));
kono
parents:
diff changeset
1273
kono
parents:
diff changeset
1274 if (TREE_CODE (xbasetype) == TREE_BINFO)
kono
parents:
diff changeset
1275 {
kono
parents:
diff changeset
1276 type = BINFO_TYPE (xbasetype);
kono
parents:
diff changeset
1277 basetype_path = xbasetype;
kono
parents:
diff changeset
1278 }
kono
parents:
diff changeset
1279 else
kono
parents:
diff changeset
1280 {
kono
parents:
diff changeset
1281 if (!RECORD_OR_UNION_CODE_P (TREE_CODE (xbasetype)))
kono
parents:
diff changeset
1282 return NULL_TREE;
kono
parents:
diff changeset
1283 type = xbasetype;
kono
parents:
diff changeset
1284 xbasetype = NULL_TREE;
kono
parents:
diff changeset
1285 }
kono
parents:
diff changeset
1286
kono
parents:
diff changeset
1287 type = complete_type (type);
kono
parents:
diff changeset
1288
kono
parents:
diff changeset
1289 /* Make sure we're looking for a member of the current instantiation in the
kono
parents:
diff changeset
1290 right partial specialization. */
kono
parents:
diff changeset
1291 if (flag_concepts && dependent_type_p (type))
kono
parents:
diff changeset
1292 type = currently_open_class (type);
kono
parents:
diff changeset
1293
kono
parents:
diff changeset
1294 if (!basetype_path)
kono
parents:
diff changeset
1295 basetype_path = TYPE_BINFO (type);
kono
parents:
diff changeset
1296
kono
parents:
diff changeset
1297 if (!basetype_path)
kono
parents:
diff changeset
1298 return NULL_TREE;
kono
parents:
diff changeset
1299
kono
parents:
diff changeset
1300 /* Populate lffi.m_candidates. */
kono
parents:
diff changeset
1301 dfs_walk_all (basetype_path, &lookup_field_fuzzy_r, NULL, &lffi);
kono
parents:
diff changeset
1302
kono
parents:
diff changeset
1303 return find_closest_identifier (name, &lffi.m_candidates);
kono
parents:
diff changeset
1304 }
kono
parents:
diff changeset
1305
kono
parents:
diff changeset
1306 /* Like lookup_member, except that if we find a function member we
kono
parents:
diff changeset
1307 return NULL_TREE. */
kono
parents:
diff changeset
1308
kono
parents:
diff changeset
1309 tree
kono
parents:
diff changeset
1310 lookup_field (tree xbasetype, tree name, int protect, bool want_type)
kono
parents:
diff changeset
1311 {
kono
parents:
diff changeset
1312 tree rval = lookup_member (xbasetype, name, protect, want_type,
kono
parents:
diff changeset
1313 tf_warning_or_error);
kono
parents:
diff changeset
1314
kono
parents:
diff changeset
1315 /* Ignore functions, but propagate the ambiguity list. */
kono
parents:
diff changeset
1316 if (!error_operand_p (rval)
kono
parents:
diff changeset
1317 && (rval && BASELINK_P (rval)))
kono
parents:
diff changeset
1318 return NULL_TREE;
kono
parents:
diff changeset
1319
kono
parents:
diff changeset
1320 return rval;
kono
parents:
diff changeset
1321 }
kono
parents:
diff changeset
1322
kono
parents:
diff changeset
1323 /* Like lookup_member, except that if we find a non-function member we
kono
parents:
diff changeset
1324 return NULL_TREE. */
kono
parents:
diff changeset
1325
kono
parents:
diff changeset
1326 tree
kono
parents:
diff changeset
1327 lookup_fnfields (tree xbasetype, tree name, int protect)
kono
parents:
diff changeset
1328 {
kono
parents:
diff changeset
1329 tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/false,
kono
parents:
diff changeset
1330 tf_warning_or_error);
kono
parents:
diff changeset
1331
kono
parents:
diff changeset
1332 /* Ignore non-functions, but propagate the ambiguity list. */
kono
parents:
diff changeset
1333 if (!error_operand_p (rval)
kono
parents:
diff changeset
1334 && (rval && !BASELINK_P (rval)))
kono
parents:
diff changeset
1335 return NULL_TREE;
kono
parents:
diff changeset
1336
kono
parents:
diff changeset
1337 return rval;
kono
parents:
diff changeset
1338 }
kono
parents:
diff changeset
1339
kono
parents:
diff changeset
1340 /* DECL is the result of a qualified name lookup. QUALIFYING_SCOPE is
kono
parents:
diff changeset
1341 the class or namespace used to qualify the name. CONTEXT_CLASS is
kono
parents:
diff changeset
1342 the class corresponding to the object in which DECL will be used.
kono
parents:
diff changeset
1343 Return a possibly modified version of DECL that takes into account
kono
parents:
diff changeset
1344 the CONTEXT_CLASS.
kono
parents:
diff changeset
1345
kono
parents:
diff changeset
1346 In particular, consider an expression like `B::m' in the context of
kono
parents:
diff changeset
1347 a derived class `D'. If `B::m' has been resolved to a BASELINK,
kono
parents:
diff changeset
1348 then the most derived class indicated by the BASELINK_BINFO will be
kono
parents:
diff changeset
1349 `B', not `D'. This function makes that adjustment. */
kono
parents:
diff changeset
1350
kono
parents:
diff changeset
1351 tree
kono
parents:
diff changeset
1352 adjust_result_of_qualified_name_lookup (tree decl,
kono
parents:
diff changeset
1353 tree qualifying_scope,
kono
parents:
diff changeset
1354 tree context_class)
kono
parents:
diff changeset
1355 {
kono
parents:
diff changeset
1356 if (context_class && context_class != error_mark_node
kono
parents:
diff changeset
1357 && CLASS_TYPE_P (context_class)
kono
parents:
diff changeset
1358 && CLASS_TYPE_P (qualifying_scope)
kono
parents:
diff changeset
1359 && DERIVED_FROM_P (qualifying_scope, context_class)
kono
parents:
diff changeset
1360 && BASELINK_P (decl))
kono
parents:
diff changeset
1361 {
kono
parents:
diff changeset
1362 tree base;
kono
parents:
diff changeset
1363
kono
parents:
diff changeset
1364 /* Look for the QUALIFYING_SCOPE as a base of the CONTEXT_CLASS.
kono
parents:
diff changeset
1365 Because we do not yet know which function will be chosen by
kono
parents:
diff changeset
1366 overload resolution, we cannot yet check either accessibility
kono
parents:
diff changeset
1367 or ambiguity -- in either case, the choice of a static member
kono
parents:
diff changeset
1368 function might make the usage valid. */
kono
parents:
diff changeset
1369 base = lookup_base (context_class, qualifying_scope,
kono
parents:
diff changeset
1370 ba_unique, NULL, tf_none);
kono
parents:
diff changeset
1371 if (base && base != error_mark_node)
kono
parents:
diff changeset
1372 {
kono
parents:
diff changeset
1373 BASELINK_ACCESS_BINFO (decl) = base;
kono
parents:
diff changeset
1374 tree decl_binfo
kono
parents:
diff changeset
1375 = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
kono
parents:
diff changeset
1376 ba_unique, NULL, tf_none);
kono
parents:
diff changeset
1377 if (decl_binfo && decl_binfo != error_mark_node)
kono
parents:
diff changeset
1378 BASELINK_BINFO (decl) = decl_binfo;
kono
parents:
diff changeset
1379 }
kono
parents:
diff changeset
1380 }
kono
parents:
diff changeset
1381
kono
parents:
diff changeset
1382 if (BASELINK_P (decl))
kono
parents:
diff changeset
1383 BASELINK_QUALIFIED_P (decl) = true;
kono
parents:
diff changeset
1384
kono
parents:
diff changeset
1385 return decl;
kono
parents:
diff changeset
1386 }
kono
parents:
diff changeset
1387
kono
parents:
diff changeset
1388
kono
parents:
diff changeset
1389 /* Walk the class hierarchy within BINFO, in a depth-first traversal.
kono
parents:
diff changeset
1390 PRE_FN is called in preorder, while POST_FN is called in postorder.
kono
parents:
diff changeset
1391 If PRE_FN returns DFS_SKIP_BASES, child binfos will not be
kono
parents:
diff changeset
1392 walked. If PRE_FN or POST_FN returns a different non-NULL value,
kono
parents:
diff changeset
1393 that value is immediately returned and the walk is terminated. One
kono
parents:
diff changeset
1394 of PRE_FN and POST_FN can be NULL. At each node, PRE_FN and
kono
parents:
diff changeset
1395 POST_FN are passed the binfo to examine and the caller's DATA
kono
parents:
diff changeset
1396 value. All paths are walked, thus virtual and morally virtual
kono
parents:
diff changeset
1397 binfos can be multiply walked. */
kono
parents:
diff changeset
1398
kono
parents:
diff changeset
1399 tree
kono
parents:
diff changeset
1400 dfs_walk_all (tree binfo, tree (*pre_fn) (tree, void *),
kono
parents:
diff changeset
1401 tree (*post_fn) (tree, void *), void *data)
kono
parents:
diff changeset
1402 {
kono
parents:
diff changeset
1403 tree rval;
kono
parents:
diff changeset
1404 unsigned ix;
kono
parents:
diff changeset
1405 tree base_binfo;
kono
parents:
diff changeset
1406
kono
parents:
diff changeset
1407 /* Call the pre-order walking function. */
kono
parents:
diff changeset
1408 if (pre_fn)
kono
parents:
diff changeset
1409 {
kono
parents:
diff changeset
1410 rval = pre_fn (binfo, data);
kono
parents:
diff changeset
1411 if (rval)
kono
parents:
diff changeset
1412 {
kono
parents:
diff changeset
1413 if (rval == dfs_skip_bases)
kono
parents:
diff changeset
1414 goto skip_bases;
kono
parents:
diff changeset
1415 return rval;
kono
parents:
diff changeset
1416 }
kono
parents:
diff changeset
1417 }
kono
parents:
diff changeset
1418
kono
parents:
diff changeset
1419 /* Find the next child binfo to walk. */
kono
parents:
diff changeset
1420 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
kono
parents:
diff changeset
1421 {
kono
parents:
diff changeset
1422 rval = dfs_walk_all (base_binfo, pre_fn, post_fn, data);
kono
parents:
diff changeset
1423 if (rval)
kono
parents:
diff changeset
1424 return rval;
kono
parents:
diff changeset
1425 }
kono
parents:
diff changeset
1426
kono
parents:
diff changeset
1427 skip_bases:
kono
parents:
diff changeset
1428 /* Call the post-order walking function. */
kono
parents:
diff changeset
1429 if (post_fn)
kono
parents:
diff changeset
1430 {
kono
parents:
diff changeset
1431 rval = post_fn (binfo, data);
kono
parents:
diff changeset
1432 gcc_assert (rval != dfs_skip_bases);
kono
parents:
diff changeset
1433 return rval;
kono
parents:
diff changeset
1434 }
kono
parents:
diff changeset
1435
kono
parents:
diff changeset
1436 return NULL_TREE;
kono
parents:
diff changeset
1437 }
kono
parents:
diff changeset
1438
kono
parents:
diff changeset
1439 /* Worker for dfs_walk_once. This behaves as dfs_walk_all, except
kono
parents:
diff changeset
1440 that binfos are walked at most once. */
kono
parents:
diff changeset
1441
kono
parents:
diff changeset
1442 static tree
kono
parents:
diff changeset
1443 dfs_walk_once_r (tree binfo, tree (*pre_fn) (tree, void *),
kono
parents:
diff changeset
1444 tree (*post_fn) (tree, void *), hash_set<tree> *pset,
kono
parents:
diff changeset
1445 void *data)
kono
parents:
diff changeset
1446 {
kono
parents:
diff changeset
1447 tree rval;
kono
parents:
diff changeset
1448 unsigned ix;
kono
parents:
diff changeset
1449 tree base_binfo;
kono
parents:
diff changeset
1450
kono
parents:
diff changeset
1451 /* Call the pre-order walking function. */
kono
parents:
diff changeset
1452 if (pre_fn)
kono
parents:
diff changeset
1453 {
kono
parents:
diff changeset
1454 rval = pre_fn (binfo, data);
kono
parents:
diff changeset
1455 if (rval)
kono
parents:
diff changeset
1456 {
kono
parents:
diff changeset
1457 if (rval == dfs_skip_bases)
kono
parents:
diff changeset
1458 goto skip_bases;
kono
parents:
diff changeset
1459
kono
parents:
diff changeset
1460 return rval;
kono
parents:
diff changeset
1461 }
kono
parents:
diff changeset
1462 }
kono
parents:
diff changeset
1463
kono
parents:
diff changeset
1464 /* Find the next child binfo to walk. */
kono
parents:
diff changeset
1465 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
kono
parents:
diff changeset
1466 {
kono
parents:
diff changeset
1467 if (BINFO_VIRTUAL_P (base_binfo))
kono
parents:
diff changeset
1468 if (pset->add (base_binfo))
kono
parents:
diff changeset
1469 continue;
kono
parents:
diff changeset
1470
kono
parents:
diff changeset
1471 rval = dfs_walk_once_r (base_binfo, pre_fn, post_fn, pset, data);
kono
parents:
diff changeset
1472 if (rval)
kono
parents:
diff changeset
1473 return rval;
kono
parents:
diff changeset
1474 }
kono
parents:
diff changeset
1475
kono
parents:
diff changeset
1476 skip_bases:
kono
parents:
diff changeset
1477 /* Call the post-order walking function. */
kono
parents:
diff changeset
1478 if (post_fn)
kono
parents:
diff changeset
1479 {
kono
parents:
diff changeset
1480 rval = post_fn (binfo, data);
kono
parents:
diff changeset
1481 gcc_assert (rval != dfs_skip_bases);
kono
parents:
diff changeset
1482 return rval;
kono
parents:
diff changeset
1483 }
kono
parents:
diff changeset
1484
kono
parents:
diff changeset
1485 return NULL_TREE;
kono
parents:
diff changeset
1486 }
kono
parents:
diff changeset
1487
kono
parents:
diff changeset
1488 /* Like dfs_walk_all, except that binfos are not multiply walked. For
kono
parents:
diff changeset
1489 non-diamond shaped hierarchies this is the same as dfs_walk_all.
kono
parents:
diff changeset
1490 For diamond shaped hierarchies we must mark the virtual bases, to
kono
parents:
diff changeset
1491 avoid multiple walks. */
kono
parents:
diff changeset
1492
kono
parents:
diff changeset
1493 tree
kono
parents:
diff changeset
1494 dfs_walk_once (tree binfo, tree (*pre_fn) (tree, void *),
kono
parents:
diff changeset
1495 tree (*post_fn) (tree, void *), void *data)
kono
parents:
diff changeset
1496 {
kono
parents:
diff changeset
1497 static int active = 0; /* We must not be called recursively. */
kono
parents:
diff changeset
1498 tree rval;
kono
parents:
diff changeset
1499
kono
parents:
diff changeset
1500 gcc_assert (pre_fn || post_fn);
kono
parents:
diff changeset
1501 gcc_assert (!active);
kono
parents:
diff changeset
1502 active++;
kono
parents:
diff changeset
1503
kono
parents:
diff changeset
1504 if (!CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
kono
parents:
diff changeset
1505 /* We are not diamond shaped, and therefore cannot encounter the
kono
parents:
diff changeset
1506 same binfo twice. */
kono
parents:
diff changeset
1507 rval = dfs_walk_all (binfo, pre_fn, post_fn, data);
kono
parents:
diff changeset
1508 else
kono
parents:
diff changeset
1509 {
kono
parents:
diff changeset
1510 hash_set<tree> pset;
kono
parents:
diff changeset
1511 rval = dfs_walk_once_r (binfo, pre_fn, post_fn, &pset, data);
kono
parents:
diff changeset
1512 }
kono
parents:
diff changeset
1513
kono
parents:
diff changeset
1514 active--;
kono
parents:
diff changeset
1515
kono
parents:
diff changeset
1516 return rval;
kono
parents:
diff changeset
1517 }
kono
parents:
diff changeset
1518
kono
parents:
diff changeset
1519 /* Worker function for dfs_walk_once_accessible. Behaves like
kono
parents:
diff changeset
1520 dfs_walk_once_r, except (a) FRIENDS_P is true if special
kono
parents:
diff changeset
1521 access given by the current context should be considered, (b) ONCE
kono
parents:
diff changeset
1522 indicates whether bases should be marked during traversal. */
kono
parents:
diff changeset
1523
kono
parents:
diff changeset
1524 static tree
kono
parents:
diff changeset
1525 dfs_walk_once_accessible_r (tree binfo, bool friends_p, hash_set<tree> *pset,
kono
parents:
diff changeset
1526 tree (*pre_fn) (tree, void *),
kono
parents:
diff changeset
1527 tree (*post_fn) (tree, void *), void *data)
kono
parents:
diff changeset
1528 {
kono
parents:
diff changeset
1529 tree rval = NULL_TREE;
kono
parents:
diff changeset
1530 unsigned ix;
kono
parents:
diff changeset
1531 tree base_binfo;
kono
parents:
diff changeset
1532
kono
parents:
diff changeset
1533 /* Call the pre-order walking function. */
kono
parents:
diff changeset
1534 if (pre_fn)
kono
parents:
diff changeset
1535 {
kono
parents:
diff changeset
1536 rval = pre_fn (binfo, data);
kono
parents:
diff changeset
1537 if (rval)
kono
parents:
diff changeset
1538 {
kono
parents:
diff changeset
1539 if (rval == dfs_skip_bases)
kono
parents:
diff changeset
1540 goto skip_bases;
kono
parents:
diff changeset
1541
kono
parents:
diff changeset
1542 return rval;
kono
parents:
diff changeset
1543 }
kono
parents:
diff changeset
1544 }
kono
parents:
diff changeset
1545
kono
parents:
diff changeset
1546 /* Find the next child binfo to walk. */
kono
parents:
diff changeset
1547 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
kono
parents:
diff changeset
1548 {
kono
parents:
diff changeset
1549 bool mark = pset && BINFO_VIRTUAL_P (base_binfo);
kono
parents:
diff changeset
1550
kono
parents:
diff changeset
1551 if (mark && pset->contains (base_binfo))
kono
parents:
diff changeset
1552 continue;
kono
parents:
diff changeset
1553
kono
parents:
diff changeset
1554 /* If the base is inherited via private or protected
kono
parents:
diff changeset
1555 inheritance, then we can't see it, unless we are a friend of
kono
parents:
diff changeset
1556 the current binfo. */
kono
parents:
diff changeset
1557 if (BINFO_BASE_ACCESS (binfo, ix) != access_public_node)
kono
parents:
diff changeset
1558 {
kono
parents:
diff changeset
1559 tree scope;
kono
parents:
diff changeset
1560 if (!friends_p)
kono
parents:
diff changeset
1561 continue;
kono
parents:
diff changeset
1562 scope = current_scope ();
kono
parents:
diff changeset
1563 if (!scope
kono
parents:
diff changeset
1564 || TREE_CODE (scope) == NAMESPACE_DECL
kono
parents:
diff changeset
1565 || !is_friend (BINFO_TYPE (binfo), scope))
kono
parents:
diff changeset
1566 continue;
kono
parents:
diff changeset
1567 }
kono
parents:
diff changeset
1568
kono
parents:
diff changeset
1569 if (mark)
kono
parents:
diff changeset
1570 pset->add (base_binfo);
kono
parents:
diff changeset
1571
kono
parents:
diff changeset
1572 rval = dfs_walk_once_accessible_r (base_binfo, friends_p, pset,
kono
parents:
diff changeset
1573 pre_fn, post_fn, data);
kono
parents:
diff changeset
1574 if (rval)
kono
parents:
diff changeset
1575 return rval;
kono
parents:
diff changeset
1576 }
kono
parents:
diff changeset
1577
kono
parents:
diff changeset
1578 skip_bases:
kono
parents:
diff changeset
1579 /* Call the post-order walking function. */
kono
parents:
diff changeset
1580 if (post_fn)
kono
parents:
diff changeset
1581 {
kono
parents:
diff changeset
1582 rval = post_fn (binfo, data);
kono
parents:
diff changeset
1583 gcc_assert (rval != dfs_skip_bases);
kono
parents:
diff changeset
1584 return rval;
kono
parents:
diff changeset
1585 }
kono
parents:
diff changeset
1586
kono
parents:
diff changeset
1587 return NULL_TREE;
kono
parents:
diff changeset
1588 }
kono
parents:
diff changeset
1589
kono
parents:
diff changeset
1590 /* Like dfs_walk_once except that only accessible bases are walked.
kono
parents:
diff changeset
1591 FRIENDS_P indicates whether friendship of the local context
kono
parents:
diff changeset
1592 should be considered when determining accessibility. */
kono
parents:
diff changeset
1593
kono
parents:
diff changeset
1594 static tree
kono
parents:
diff changeset
1595 dfs_walk_once_accessible (tree binfo, bool friends_p,
kono
parents:
diff changeset
1596 tree (*pre_fn) (tree, void *),
kono
parents:
diff changeset
1597 tree (*post_fn) (tree, void *), void *data)
kono
parents:
diff changeset
1598 {
kono
parents:
diff changeset
1599 hash_set<tree> *pset = NULL;
kono
parents:
diff changeset
1600 if (CLASSTYPE_DIAMOND_SHAPED_P (BINFO_TYPE (binfo)))
kono
parents:
diff changeset
1601 pset = new hash_set<tree>;
kono
parents:
diff changeset
1602 tree rval = dfs_walk_once_accessible_r (binfo, friends_p, pset,
kono
parents:
diff changeset
1603 pre_fn, post_fn, data);
kono
parents:
diff changeset
1604
kono
parents:
diff changeset
1605 if (pset)
kono
parents:
diff changeset
1606 delete pset;
kono
parents:
diff changeset
1607 return rval;
kono
parents:
diff changeset
1608 }
kono
parents:
diff changeset
1609
kono
parents:
diff changeset
1610 /* Return true iff the code of T is CODE, and it has compatible
kono
parents:
diff changeset
1611 type with TYPE. */
kono
parents:
diff changeset
1612
kono
parents:
diff changeset
1613 static bool
kono
parents:
diff changeset
1614 matches_code_and_type_p (tree t, enum tree_code code, tree type)
kono
parents:
diff changeset
1615 {
kono
parents:
diff changeset
1616 if (TREE_CODE (t) != code)
kono
parents:
diff changeset
1617 return false;
kono
parents:
diff changeset
1618 if (!cxx_types_compatible_p (TREE_TYPE (t), type))
kono
parents:
diff changeset
1619 return false;
kono
parents:
diff changeset
1620 return true;
kono
parents:
diff changeset
1621 }
kono
parents:
diff changeset
1622
kono
parents:
diff changeset
1623 /* Subroutine of direct_accessor_p and reference_accessor_p.
kono
parents:
diff changeset
1624 Determine if COMPONENT_REF is a simple field lookup of this->FIELD_DECL.
kono
parents:
diff changeset
1625 We expect a tree of the form:
kono
parents:
diff changeset
1626 <component_ref:
kono
parents:
diff changeset
1627 <indirect_ref:S>
kono
parents:
diff changeset
1628 <nop_expr:P*
kono
parents:
diff changeset
1629 <parm_decl (this)>
kono
parents:
diff changeset
1630 <field_decl (FIELD_DECL)>>>. */
kono
parents:
diff changeset
1631
kono
parents:
diff changeset
1632 static bool
kono
parents:
diff changeset
1633 field_access_p (tree component_ref, tree field_decl, tree field_type)
kono
parents:
diff changeset
1634 {
kono
parents:
diff changeset
1635 if (!matches_code_and_type_p (component_ref, COMPONENT_REF, field_type))
kono
parents:
diff changeset
1636 return false;
kono
parents:
diff changeset
1637
kono
parents:
diff changeset
1638 tree indirect_ref = TREE_OPERAND (component_ref, 0);
kono
parents:
diff changeset
1639 if (TREE_CODE (indirect_ref) != INDIRECT_REF)
kono
parents:
diff changeset
1640 return false;
kono
parents:
diff changeset
1641
kono
parents:
diff changeset
1642 tree ptr = STRIP_NOPS (TREE_OPERAND (indirect_ref, 0));
kono
parents:
diff changeset
1643 if (!is_this_parameter (ptr))
kono
parents:
diff changeset
1644 return false;
kono
parents:
diff changeset
1645
kono
parents:
diff changeset
1646 /* Must access the correct field. */
kono
parents:
diff changeset
1647 if (TREE_OPERAND (component_ref, 1) != field_decl)
kono
parents:
diff changeset
1648 return false;
kono
parents:
diff changeset
1649 return true;
kono
parents:
diff changeset
1650 }
kono
parents:
diff changeset
1651
kono
parents:
diff changeset
1652 /* Subroutine of field_accessor_p.
kono
parents:
diff changeset
1653
kono
parents:
diff changeset
1654 Assuming that INIT_EXPR has already had its code and type checked,
kono
parents:
diff changeset
1655 determine if it is a simple accessor for FIELD_DECL
kono
parents:
diff changeset
1656 (of type FIELD_TYPE).
kono
parents:
diff changeset
1657
kono
parents:
diff changeset
1658 Specifically, a simple accessor within struct S of the form:
kono
parents:
diff changeset
1659 T get_field () { return m_field; }
kono
parents:
diff changeset
1660 should have a DECL_SAVED_TREE of the form:
kono
parents:
diff changeset
1661 <return_expr
kono
parents:
diff changeset
1662 <init_expr:T
kono
parents:
diff changeset
1663 <result_decl:T
kono
parents:
diff changeset
1664 <nop_expr:T
kono
parents:
diff changeset
1665 <component_ref:
kono
parents:
diff changeset
1666 <indirect_ref:S>
kono
parents:
diff changeset
1667 <nop_expr:P*
kono
parents:
diff changeset
1668 <parm_decl (this)>
kono
parents:
diff changeset
1669 <field_decl (FIELD_DECL)>>>. */
kono
parents:
diff changeset
1670
kono
parents:
diff changeset
1671 static bool
kono
parents:
diff changeset
1672 direct_accessor_p (tree init_expr, tree field_decl, tree field_type)
kono
parents:
diff changeset
1673 {
kono
parents:
diff changeset
1674 tree result_decl = TREE_OPERAND (init_expr, 0);
kono
parents:
diff changeset
1675 if (!matches_code_and_type_p (result_decl, RESULT_DECL, field_type))
kono
parents:
diff changeset
1676 return false;
kono
parents:
diff changeset
1677
kono
parents:
diff changeset
1678 tree component_ref = STRIP_NOPS (TREE_OPERAND (init_expr, 1));
kono
parents:
diff changeset
1679 if (!field_access_p (component_ref, field_decl, field_type))
kono
parents:
diff changeset
1680 return false;
kono
parents:
diff changeset
1681
kono
parents:
diff changeset
1682 return true;
kono
parents:
diff changeset
1683 }
kono
parents:
diff changeset
1684
kono
parents:
diff changeset
1685 /* Subroutine of field_accessor_p.
kono
parents:
diff changeset
1686
kono
parents:
diff changeset
1687 Assuming that INIT_EXPR has already had its code and type checked,
kono
parents:
diff changeset
1688 determine if it is a "reference" accessor for FIELD_DECL
kono
parents:
diff changeset
1689 (of type FIELD_REFERENCE_TYPE).
kono
parents:
diff changeset
1690
kono
parents:
diff changeset
1691 Specifically, a simple accessor within struct S of the form:
kono
parents:
diff changeset
1692 T& get_field () { return m_field; }
kono
parents:
diff changeset
1693 should have a DECL_SAVED_TREE of the form:
kono
parents:
diff changeset
1694 <return_expr
kono
parents:
diff changeset
1695 <init_expr:T&
kono
parents:
diff changeset
1696 <result_decl:T&
kono
parents:
diff changeset
1697 <nop_expr: T&
kono
parents:
diff changeset
1698 <addr_expr: T*
kono
parents:
diff changeset
1699 <component_ref:T
kono
parents:
diff changeset
1700 <indirect_ref:S
kono
parents:
diff changeset
1701 <nop_expr
kono
parents:
diff changeset
1702 <parm_decl (this)>>
kono
parents:
diff changeset
1703 <field (FIELD_DECL)>>>>>>. */
kono
parents:
diff changeset
1704 static bool
kono
parents:
diff changeset
1705 reference_accessor_p (tree init_expr, tree field_decl, tree field_type,
kono
parents:
diff changeset
1706 tree field_reference_type)
kono
parents:
diff changeset
1707 {
kono
parents:
diff changeset
1708 tree result_decl = TREE_OPERAND (init_expr, 0);
kono
parents:
diff changeset
1709 if (!matches_code_and_type_p (result_decl, RESULT_DECL, field_reference_type))
kono
parents:
diff changeset
1710 return false;
kono
parents:
diff changeset
1711
kono
parents:
diff changeset
1712 tree field_pointer_type = build_pointer_type (field_type);
kono
parents:
diff changeset
1713 tree addr_expr = STRIP_NOPS (TREE_OPERAND (init_expr, 1));
kono
parents:
diff changeset
1714 if (!matches_code_and_type_p (addr_expr, ADDR_EXPR, field_pointer_type))
kono
parents:
diff changeset
1715 return false;
kono
parents:
diff changeset
1716
kono
parents:
diff changeset
1717 tree component_ref = STRIP_NOPS (TREE_OPERAND (addr_expr, 0));
kono
parents:
diff changeset
1718
kono
parents:
diff changeset
1719 if (!field_access_p (component_ref, field_decl, field_type))
kono
parents:
diff changeset
1720 return false;
kono
parents:
diff changeset
1721
kono
parents:
diff changeset
1722 return true;
kono
parents:
diff changeset
1723 }
kono
parents:
diff changeset
1724
kono
parents:
diff changeset
1725 /* Return true if FN is an accessor method for FIELD_DECL.
kono
parents:
diff changeset
1726 i.e. a method of the form { return FIELD; }, with no
kono
parents:
diff changeset
1727 conversions.
kono
parents:
diff changeset
1728
kono
parents:
diff changeset
1729 If CONST_P, then additionally require that FN be a const
kono
parents:
diff changeset
1730 method. */
kono
parents:
diff changeset
1731
kono
parents:
diff changeset
1732 static bool
kono
parents:
diff changeset
1733 field_accessor_p (tree fn, tree field_decl, bool const_p)
kono
parents:
diff changeset
1734 {
kono
parents:
diff changeset
1735 if (TREE_CODE (fn) != FUNCTION_DECL)
kono
parents:
diff changeset
1736 return false;
kono
parents:
diff changeset
1737
kono
parents:
diff changeset
1738 /* We don't yet support looking up static data, just fields. */
kono
parents:
diff changeset
1739 if (TREE_CODE (field_decl) != FIELD_DECL)
kono
parents:
diff changeset
1740 return false;
kono
parents:
diff changeset
1741
kono
parents:
diff changeset
1742 tree fntype = TREE_TYPE (fn);
kono
parents:
diff changeset
1743 if (TREE_CODE (fntype) != METHOD_TYPE)
kono
parents:
diff changeset
1744 return false;
kono
parents:
diff changeset
1745
kono
parents:
diff changeset
1746 /* If the field is accessed via a const "this" argument, verify
kono
parents:
diff changeset
1747 that the "this" parameter is const. */
kono
parents:
diff changeset
1748 if (const_p)
kono
parents:
diff changeset
1749 {
kono
parents:
diff changeset
1750 tree this_type = type_of_this_parm (fntype);
kono
parents:
diff changeset
1751 if (!TYPE_READONLY (this_type))
kono
parents:
diff changeset
1752 return false;
kono
parents:
diff changeset
1753 }
kono
parents:
diff changeset
1754
kono
parents:
diff changeset
1755 tree saved_tree = DECL_SAVED_TREE (fn);
kono
parents:
diff changeset
1756
kono
parents:
diff changeset
1757 if (saved_tree == NULL_TREE)
kono
parents:
diff changeset
1758 return false;
kono
parents:
diff changeset
1759
kono
parents:
diff changeset
1760 if (TREE_CODE (saved_tree) != RETURN_EXPR)
kono
parents:
diff changeset
1761 return false;
kono
parents:
diff changeset
1762
kono
parents:
diff changeset
1763 tree init_expr = TREE_OPERAND (saved_tree, 0);
kono
parents:
diff changeset
1764 if (TREE_CODE (init_expr) != INIT_EXPR)
kono
parents:
diff changeset
1765 return false;
kono
parents:
diff changeset
1766
kono
parents:
diff changeset
1767 /* Determine if this is a simple accessor within struct S of the form:
kono
parents:
diff changeset
1768 T get_field () { return m_field; }. */
kono
parents:
diff changeset
1769 tree field_type = TREE_TYPE (field_decl);
kono
parents:
diff changeset
1770 if (cxx_types_compatible_p (TREE_TYPE (init_expr), field_type))
kono
parents:
diff changeset
1771 return direct_accessor_p (init_expr, field_decl, field_type);
kono
parents:
diff changeset
1772
kono
parents:
diff changeset
1773 /* Failing that, determine if it is an accessor of the form:
kono
parents:
diff changeset
1774 T& get_field () { return m_field; }. */
kono
parents:
diff changeset
1775 tree field_reference_type = cp_build_reference_type (field_type, false);
kono
parents:
diff changeset
1776 if (cxx_types_compatible_p (TREE_TYPE (init_expr), field_reference_type))
kono
parents:
diff changeset
1777 return reference_accessor_p (init_expr, field_decl, field_type,
kono
parents:
diff changeset
1778 field_reference_type);
kono
parents:
diff changeset
1779
kono
parents:
diff changeset
1780 return false;
kono
parents:
diff changeset
1781 }
kono
parents:
diff changeset
1782
kono
parents:
diff changeset
1783 /* Callback data for dfs_locate_field_accessor_pre. */
kono
parents:
diff changeset
1784
kono
parents:
diff changeset
1785 struct locate_field_data
kono
parents:
diff changeset
1786 {
kono
parents:
diff changeset
1787 locate_field_data (tree field_decl_, bool const_p_)
kono
parents:
diff changeset
1788 : field_decl (field_decl_), const_p (const_p_) {}
kono
parents:
diff changeset
1789
kono
parents:
diff changeset
1790 tree field_decl;
kono
parents:
diff changeset
1791 bool const_p;
kono
parents:
diff changeset
1792 };
kono
parents:
diff changeset
1793
kono
parents:
diff changeset
1794 /* Return a FUNCTION_DECL that is an "accessor" method for DATA, a FIELD_DECL,
kono
parents:
diff changeset
1795 callable via binfo, if one exists, otherwise return NULL_TREE.
kono
parents:
diff changeset
1796
kono
parents:
diff changeset
1797 Callback for dfs_walk_once_accessible for use within
kono
parents:
diff changeset
1798 locate_field_accessor. */
kono
parents:
diff changeset
1799
kono
parents:
diff changeset
1800 static tree
kono
parents:
diff changeset
1801 dfs_locate_field_accessor_pre (tree binfo, void *data)
kono
parents:
diff changeset
1802 {
kono
parents:
diff changeset
1803 locate_field_data *lfd = (locate_field_data *)data;
kono
parents:
diff changeset
1804 tree type = BINFO_TYPE (binfo);
kono
parents:
diff changeset
1805
kono
parents:
diff changeset
1806 vec<tree, va_gc> *member_vec;
kono
parents:
diff changeset
1807 tree fn;
kono
parents:
diff changeset
1808 size_t i;
kono
parents:
diff changeset
1809
kono
parents:
diff changeset
1810 if (!CLASS_TYPE_P (type))
kono
parents:
diff changeset
1811 return NULL_TREE;
kono
parents:
diff changeset
1812
kono
parents:
diff changeset
1813 member_vec = CLASSTYPE_MEMBER_VEC (type);
kono
parents:
diff changeset
1814 if (!member_vec)
kono
parents:
diff changeset
1815 return NULL_TREE;
kono
parents:
diff changeset
1816
kono
parents:
diff changeset
1817 for (i = 0; vec_safe_iterate (member_vec, i, &fn); ++i)
kono
parents:
diff changeset
1818 if (fn)
kono
parents:
diff changeset
1819 if (field_accessor_p (fn, lfd->field_decl, lfd->const_p))
kono
parents:
diff changeset
1820 return fn;
kono
parents:
diff changeset
1821
kono
parents:
diff changeset
1822 return NULL_TREE;
kono
parents:
diff changeset
1823 }
kono
parents:
diff changeset
1824
kono
parents:
diff changeset
1825 /* Return a FUNCTION_DECL that is an "accessor" method for FIELD_DECL,
kono
parents:
diff changeset
1826 callable via BASETYPE_PATH, if one exists, otherwise return NULL_TREE. */
kono
parents:
diff changeset
1827
kono
parents:
diff changeset
1828 tree
kono
parents:
diff changeset
1829 locate_field_accessor (tree basetype_path, tree field_decl, bool const_p)
kono
parents:
diff changeset
1830 {
kono
parents:
diff changeset
1831 if (TREE_CODE (basetype_path) != TREE_BINFO)
kono
parents:
diff changeset
1832 return NULL_TREE;
kono
parents:
diff changeset
1833
kono
parents:
diff changeset
1834 /* Walk the hierarchy, looking for a method of some base class that allows
kono
parents:
diff changeset
1835 access to the field. */
kono
parents:
diff changeset
1836 locate_field_data lfd (field_decl, const_p);
kono
parents:
diff changeset
1837 return dfs_walk_once_accessible (basetype_path, /*friends=*/true,
kono
parents:
diff changeset
1838 dfs_locate_field_accessor_pre,
kono
parents:
diff changeset
1839 NULL, &lfd);
kono
parents:
diff changeset
1840 }
kono
parents:
diff changeset
1841
kono
parents:
diff changeset
1842 /* Check that virtual overrider OVERRIDER is acceptable for base function
kono
parents:
diff changeset
1843 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
kono
parents:
diff changeset
1844
kono
parents:
diff changeset
1845 static int
kono
parents:
diff changeset
1846 check_final_overrider (tree overrider, tree basefn)
kono
parents:
diff changeset
1847 {
kono
parents:
diff changeset
1848 tree over_type = TREE_TYPE (overrider);
kono
parents:
diff changeset
1849 tree base_type = TREE_TYPE (basefn);
kono
parents:
diff changeset
1850 tree over_return = fndecl_declared_return_type (overrider);
kono
parents:
diff changeset
1851 tree base_return = fndecl_declared_return_type (basefn);
kono
parents:
diff changeset
1852 tree over_throw, base_throw;
kono
parents:
diff changeset
1853
kono
parents:
diff changeset
1854 int fail = 0;
kono
parents:
diff changeset
1855
kono
parents:
diff changeset
1856 if (DECL_INVALID_OVERRIDER_P (overrider))
kono
parents:
diff changeset
1857 return 0;
kono
parents:
diff changeset
1858
kono
parents:
diff changeset
1859 if (same_type_p (base_return, over_return))
kono
parents:
diff changeset
1860 /* OK */;
kono
parents:
diff changeset
1861 else if ((CLASS_TYPE_P (over_return) && CLASS_TYPE_P (base_return))
kono
parents:
diff changeset
1862 || (TREE_CODE (base_return) == TREE_CODE (over_return)
kono
parents:
diff changeset
1863 && POINTER_TYPE_P (base_return)))
kono
parents:
diff changeset
1864 {
kono
parents:
diff changeset
1865 /* Potentially covariant. */
kono
parents:
diff changeset
1866 unsigned base_quals, over_quals;
kono
parents:
diff changeset
1867
kono
parents:
diff changeset
1868 fail = !POINTER_TYPE_P (base_return);
kono
parents:
diff changeset
1869 if (!fail)
kono
parents:
diff changeset
1870 {
kono
parents:
diff changeset
1871 fail = cp_type_quals (base_return) != cp_type_quals (over_return);
kono
parents:
diff changeset
1872
kono
parents:
diff changeset
1873 base_return = TREE_TYPE (base_return);
kono
parents:
diff changeset
1874 over_return = TREE_TYPE (over_return);
kono
parents:
diff changeset
1875 }
kono
parents:
diff changeset
1876 base_quals = cp_type_quals (base_return);
kono
parents:
diff changeset
1877 over_quals = cp_type_quals (over_return);
kono
parents:
diff changeset
1878
kono
parents:
diff changeset
1879 if ((base_quals & over_quals) != over_quals)
kono
parents:
diff changeset
1880 fail = 1;
kono
parents:
diff changeset
1881
kono
parents:
diff changeset
1882 if (CLASS_TYPE_P (base_return) && CLASS_TYPE_P (over_return))
kono
parents:
diff changeset
1883 {
kono
parents:
diff changeset
1884 /* Strictly speaking, the standard requires the return type to be
kono
parents:
diff changeset
1885 complete even if it only differs in cv-quals, but that seems
kono
parents:
diff changeset
1886 like a bug in the wording. */
kono
parents:
diff changeset
1887 if (!same_type_ignoring_top_level_qualifiers_p (base_return,
kono
parents:
diff changeset
1888 over_return))
kono
parents:
diff changeset
1889 {
kono
parents:
diff changeset
1890 tree binfo = lookup_base (over_return, base_return,
kono
parents:
diff changeset
1891 ba_check, NULL, tf_none);
kono
parents:
diff changeset
1892
kono
parents:
diff changeset
1893 if (!binfo || binfo == error_mark_node)
kono
parents:
diff changeset
1894 fail = 1;
kono
parents:
diff changeset
1895 }
kono
parents:
diff changeset
1896 }
kono
parents:
diff changeset
1897 else if (can_convert_standard (TREE_TYPE (base_type),
kono
parents:
diff changeset
1898 TREE_TYPE (over_type),
kono
parents:
diff changeset
1899 tf_warning_or_error))
kono
parents:
diff changeset
1900 /* GNU extension, allow trivial pointer conversions such as
kono
parents:
diff changeset
1901 converting to void *, or qualification conversion. */
kono
parents:
diff changeset
1902 {
kono
parents:
diff changeset
1903 if (pedwarn (DECL_SOURCE_LOCATION (overrider), 0,
kono
parents:
diff changeset
1904 "invalid covariant return type for %q#D", overrider))
kono
parents:
diff changeset
1905 inform (DECL_SOURCE_LOCATION (basefn),
kono
parents:
diff changeset
1906 " overriding %q#D", basefn);
kono
parents:
diff changeset
1907 }
kono
parents:
diff changeset
1908 else
kono
parents:
diff changeset
1909 fail = 2;
kono
parents:
diff changeset
1910 }
kono
parents:
diff changeset
1911 else
kono
parents:
diff changeset
1912 fail = 2;
kono
parents:
diff changeset
1913 if (!fail)
kono
parents:
diff changeset
1914 /* OK */;
kono
parents:
diff changeset
1915 else
kono
parents:
diff changeset
1916 {
kono
parents:
diff changeset
1917 if (fail == 1)
kono
parents:
diff changeset
1918 {
kono
parents:
diff changeset
1919 error ("invalid covariant return type for %q+#D", overrider);
kono
parents:
diff changeset
1920 error (" overriding %q+#D", basefn);
kono
parents:
diff changeset
1921 }
kono
parents:
diff changeset
1922 else
kono
parents:
diff changeset
1923 {
kono
parents:
diff changeset
1924 error ("conflicting return type specified for %q+#D", overrider);
kono
parents:
diff changeset
1925 error (" overriding %q+#D", basefn);
kono
parents:
diff changeset
1926 }
kono
parents:
diff changeset
1927 DECL_INVALID_OVERRIDER_P (overrider) = 1;
kono
parents:
diff changeset
1928 return 0;
kono
parents:
diff changeset
1929 }
kono
parents:
diff changeset
1930
kono
parents:
diff changeset
1931 /* Check throw specifier is at least as strict. */
kono
parents:
diff changeset
1932 maybe_instantiate_noexcept (basefn);
kono
parents:
diff changeset
1933 maybe_instantiate_noexcept (overrider);
kono
parents:
diff changeset
1934 base_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (basefn));
kono
parents:
diff changeset
1935 over_throw = TYPE_RAISES_EXCEPTIONS (TREE_TYPE (overrider));
kono
parents:
diff changeset
1936
kono
parents:
diff changeset
1937 if (!comp_except_specs (base_throw, over_throw, ce_derived))
kono
parents:
diff changeset
1938 {
kono
parents:
diff changeset
1939 error ("looser throw specifier for %q+#F", overrider);
kono
parents:
diff changeset
1940 error (" overriding %q+#F", basefn);
kono
parents:
diff changeset
1941 DECL_INVALID_OVERRIDER_P (overrider) = 1;
kono
parents:
diff changeset
1942 return 0;
kono
parents:
diff changeset
1943 }
kono
parents:
diff changeset
1944
kono
parents:
diff changeset
1945 /* Check for conflicting type attributes. But leave transaction_safe for
kono
parents:
diff changeset
1946 set_one_vmethod_tm_attributes. */
kono
parents:
diff changeset
1947 if (!comp_type_attributes (over_type, base_type)
kono
parents:
diff changeset
1948 && !tx_safe_fn_type_p (base_type)
kono
parents:
diff changeset
1949 && !tx_safe_fn_type_p (over_type))
kono
parents:
diff changeset
1950 {
kono
parents:
diff changeset
1951 error ("conflicting type attributes specified for %q+#D", overrider);
kono
parents:
diff changeset
1952 error (" overriding %q+#D", basefn);
kono
parents:
diff changeset
1953 DECL_INVALID_OVERRIDER_P (overrider) = 1;
kono
parents:
diff changeset
1954 return 0;
kono
parents:
diff changeset
1955 }
kono
parents:
diff changeset
1956
kono
parents:
diff changeset
1957 /* A function declared transaction_safe_dynamic that overrides a function
kono
parents:
diff changeset
1958 declared transaction_safe (but not transaction_safe_dynamic) is
kono
parents:
diff changeset
1959 ill-formed. */
kono
parents:
diff changeset
1960 if (tx_safe_fn_type_p (base_type)
kono
parents:
diff changeset
1961 && lookup_attribute ("transaction_safe_dynamic",
kono
parents:
diff changeset
1962 DECL_ATTRIBUTES (overrider))
kono
parents:
diff changeset
1963 && !lookup_attribute ("transaction_safe_dynamic",
kono
parents:
diff changeset
1964 DECL_ATTRIBUTES (basefn)))
kono
parents:
diff changeset
1965 {
kono
parents:
diff changeset
1966 error_at (DECL_SOURCE_LOCATION (overrider),
kono
parents:
diff changeset
1967 "%qD declared %<transaction_safe_dynamic%>", overrider);
kono
parents:
diff changeset
1968 inform (DECL_SOURCE_LOCATION (basefn),
kono
parents:
diff changeset
1969 "overriding %qD declared %<transaction_safe%>", basefn);
kono
parents:
diff changeset
1970 }
kono
parents:
diff changeset
1971
kono
parents:
diff changeset
1972 if (DECL_DELETED_FN (basefn) != DECL_DELETED_FN (overrider))
kono
parents:
diff changeset
1973 {
kono
parents:
diff changeset
1974 if (DECL_DELETED_FN (overrider))
kono
parents:
diff changeset
1975 {
kono
parents:
diff changeset
1976 error ("deleted function %q+D", overrider);
kono
parents:
diff changeset
1977 error ("overriding non-deleted function %q+D", basefn);
kono
parents:
diff changeset
1978 maybe_explain_implicit_delete (overrider);
kono
parents:
diff changeset
1979 }
kono
parents:
diff changeset
1980 else
kono
parents:
diff changeset
1981 {
kono
parents:
diff changeset
1982 error ("non-deleted function %q+D", overrider);
kono
parents:
diff changeset
1983 error ("overriding deleted function %q+D", basefn);
kono
parents:
diff changeset
1984 }
kono
parents:
diff changeset
1985 return 0;
kono
parents:
diff changeset
1986 }
kono
parents:
diff changeset
1987 if (DECL_FINAL_P (basefn))
kono
parents:
diff changeset
1988 {
kono
parents:
diff changeset
1989 error ("virtual function %q+D", overrider);
kono
parents:
diff changeset
1990 error ("overriding final function %q+D", basefn);
kono
parents:
diff changeset
1991 return 0;
kono
parents:
diff changeset
1992 }
kono
parents:
diff changeset
1993 return 1;
kono
parents:
diff changeset
1994 }
kono
parents:
diff changeset
1995
kono
parents:
diff changeset
1996 /* Given a class TYPE, and a function decl FNDECL, look for
kono
parents:
diff changeset
1997 virtual functions in TYPE's hierarchy which FNDECL overrides.
kono
parents:
diff changeset
1998 We do not look in TYPE itself, only its bases.
kono
parents:
diff changeset
1999
kono
parents:
diff changeset
2000 Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
kono
parents:
diff changeset
2001 find that it overrides anything.
kono
parents:
diff changeset
2002
kono
parents:
diff changeset
2003 We check that every function which is overridden, is correctly
kono
parents:
diff changeset
2004 overridden. */
kono
parents:
diff changeset
2005
kono
parents:
diff changeset
2006 int
kono
parents:
diff changeset
2007 look_for_overrides (tree type, tree fndecl)
kono
parents:
diff changeset
2008 {
kono
parents:
diff changeset
2009 tree binfo = TYPE_BINFO (type);
kono
parents:
diff changeset
2010 tree base_binfo;
kono
parents:
diff changeset
2011 int ix;
kono
parents:
diff changeset
2012 int found = 0;
kono
parents:
diff changeset
2013
kono
parents:
diff changeset
2014 /* A constructor for a class T does not override a function T
kono
parents:
diff changeset
2015 in a base class. */
kono
parents:
diff changeset
2016 if (DECL_CONSTRUCTOR_P (fndecl))
kono
parents:
diff changeset
2017 return 0;
kono
parents:
diff changeset
2018
kono
parents:
diff changeset
2019 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
kono
parents:
diff changeset
2020 {
kono
parents:
diff changeset
2021 tree basetype = BINFO_TYPE (base_binfo);
kono
parents:
diff changeset
2022
kono
parents:
diff changeset
2023 if (TYPE_POLYMORPHIC_P (basetype))
kono
parents:
diff changeset
2024 found += look_for_overrides_r (basetype, fndecl);
kono
parents:
diff changeset
2025 }
kono
parents:
diff changeset
2026 return found;
kono
parents:
diff changeset
2027 }
kono
parents:
diff changeset
2028
kono
parents:
diff changeset
2029 /* Look in TYPE for virtual functions with the same signature as
kono
parents:
diff changeset
2030 FNDECL. */
kono
parents:
diff changeset
2031
kono
parents:
diff changeset
2032 tree
kono
parents:
diff changeset
2033 look_for_overrides_here (tree type, tree fndecl)
kono
parents:
diff changeset
2034 {
kono
parents:
diff changeset
2035 tree ovl = get_class_binding (type, DECL_NAME (fndecl));
kono
parents:
diff changeset
2036
kono
parents:
diff changeset
2037 for (ovl_iterator iter (ovl); iter; ++iter)
kono
parents:
diff changeset
2038 {
kono
parents:
diff changeset
2039 tree fn = *iter;
kono
parents:
diff changeset
2040
kono
parents:
diff changeset
2041 if (!DECL_VIRTUAL_P (fn))
kono
parents:
diff changeset
2042 /* Not a virtual. */;
kono
parents:
diff changeset
2043 else if (DECL_CONTEXT (fn) != type)
kono
parents:
diff changeset
2044 /* Introduced with a using declaration. */;
kono
parents:
diff changeset
2045 else if (DECL_STATIC_FUNCTION_P (fndecl))
kono
parents:
diff changeset
2046 {
kono
parents:
diff changeset
2047 tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
kono
parents:
diff changeset
2048 tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
kono
parents:
diff changeset
2049 if (compparms (TREE_CHAIN (btypes), dtypes))
kono
parents:
diff changeset
2050 return fn;
kono
parents:
diff changeset
2051 }
kono
parents:
diff changeset
2052 else if (same_signature_p (fndecl, fn))
kono
parents:
diff changeset
2053 return fn;
kono
parents:
diff changeset
2054 }
kono
parents:
diff changeset
2055
kono
parents:
diff changeset
2056 return NULL_TREE;
kono
parents:
diff changeset
2057 }
kono
parents:
diff changeset
2058
kono
parents:
diff changeset
2059 /* Look in TYPE for virtual functions overridden by FNDECL. Check both
kono
parents:
diff changeset
2060 TYPE itself and its bases. */
kono
parents:
diff changeset
2061
kono
parents:
diff changeset
2062 static int
kono
parents:
diff changeset
2063 look_for_overrides_r (tree type, tree fndecl)
kono
parents:
diff changeset
2064 {
kono
parents:
diff changeset
2065 tree fn = look_for_overrides_here (type, fndecl);
kono
parents:
diff changeset
2066 if (fn)
kono
parents:
diff changeset
2067 {
kono
parents:
diff changeset
2068 if (DECL_STATIC_FUNCTION_P (fndecl))
kono
parents:
diff changeset
2069 {
kono
parents:
diff changeset
2070 /* A static member function cannot match an inherited
kono
parents:
diff changeset
2071 virtual member function. */
kono
parents:
diff changeset
2072 error ("%q+#D cannot be declared", fndecl);
kono
parents:
diff changeset
2073 error (" since %q+#D declared in base class", fn);
kono
parents:
diff changeset
2074 }
kono
parents:
diff changeset
2075 else
kono
parents:
diff changeset
2076 {
kono
parents:
diff changeset
2077 /* It's definitely virtual, even if not explicitly set. */
kono
parents:
diff changeset
2078 DECL_VIRTUAL_P (fndecl) = 1;
kono
parents:
diff changeset
2079 check_final_overrider (fndecl, fn);
kono
parents:
diff changeset
2080 }
kono
parents:
diff changeset
2081 return 1;
kono
parents:
diff changeset
2082 }
kono
parents:
diff changeset
2083
kono
parents:
diff changeset
2084 /* We failed to find one declared in this class. Look in its bases. */
kono
parents:
diff changeset
2085 return look_for_overrides (type, fndecl);
kono
parents:
diff changeset
2086 }
kono
parents:
diff changeset
2087
kono
parents:
diff changeset
2088 /* Called via dfs_walk from dfs_get_pure_virtuals. */
kono
parents:
diff changeset
2089
kono
parents:
diff changeset
2090 static tree
kono
parents:
diff changeset
2091 dfs_get_pure_virtuals (tree binfo, void *data)
kono
parents:
diff changeset
2092 {
kono
parents:
diff changeset
2093 tree type = (tree) data;
kono
parents:
diff changeset
2094
kono
parents:
diff changeset
2095 /* We're not interested in primary base classes; the derived class
kono
parents:
diff changeset
2096 of which they are a primary base will contain the information we
kono
parents:
diff changeset
2097 need. */
kono
parents:
diff changeset
2098 if (!BINFO_PRIMARY_P (binfo))
kono
parents:
diff changeset
2099 {
kono
parents:
diff changeset
2100 tree virtuals;
kono
parents:
diff changeset
2101
kono
parents:
diff changeset
2102 for (virtuals = BINFO_VIRTUALS (binfo);
kono
parents:
diff changeset
2103 virtuals;
kono
parents:
diff changeset
2104 virtuals = TREE_CHAIN (virtuals))
kono
parents:
diff changeset
2105 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
kono
parents:
diff changeset
2106 vec_safe_push (CLASSTYPE_PURE_VIRTUALS (type), BV_FN (virtuals));
kono
parents:
diff changeset
2107 }
kono
parents:
diff changeset
2108
kono
parents:
diff changeset
2109 return NULL_TREE;
kono
parents:
diff changeset
2110 }
kono
parents:
diff changeset
2111
kono
parents:
diff changeset
2112 /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
kono
parents:
diff changeset
2113
kono
parents:
diff changeset
2114 void
kono
parents:
diff changeset
2115 get_pure_virtuals (tree type)
kono
parents:
diff changeset
2116 {
kono
parents:
diff changeset
2117 /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
kono
parents:
diff changeset
2118 is going to be overridden. */
kono
parents:
diff changeset
2119 CLASSTYPE_PURE_VIRTUALS (type) = NULL;
kono
parents:
diff changeset
2120 /* Now, run through all the bases which are not primary bases, and
kono
parents:
diff changeset
2121 collect the pure virtual functions. We look at the vtable in
kono
parents:
diff changeset
2122 each class to determine what pure virtual functions are present.
kono
parents:
diff changeset
2123 (A primary base is not interesting because the derived class of
kono
parents:
diff changeset
2124 which it is a primary base will contain vtable entries for the
kono
parents:
diff changeset
2125 pure virtuals in the base class. */
kono
parents:
diff changeset
2126 dfs_walk_once (TYPE_BINFO (type), NULL, dfs_get_pure_virtuals, type);
kono
parents:
diff changeset
2127 }
kono
parents:
diff changeset
2128
kono
parents:
diff changeset
2129 /* Debug info for C++ classes can get very large; try to avoid
kono
parents:
diff changeset
2130 emitting it everywhere.
kono
parents:
diff changeset
2131
kono
parents:
diff changeset
2132 Note that this optimization wins even when the target supports
kono
parents:
diff changeset
2133 BINCL (if only slightly), and reduces the amount of work for the
kono
parents:
diff changeset
2134 linker. */
kono
parents:
diff changeset
2135
kono
parents:
diff changeset
2136 void
kono
parents:
diff changeset
2137 maybe_suppress_debug_info (tree t)
kono
parents:
diff changeset
2138 {
kono
parents:
diff changeset
2139 if (write_symbols == NO_DEBUG)
kono
parents:
diff changeset
2140 return;
kono
parents:
diff changeset
2141
kono
parents:
diff changeset
2142 /* We might have set this earlier in cp_finish_decl. */
kono
parents:
diff changeset
2143 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
kono
parents:
diff changeset
2144
kono
parents:
diff changeset
2145 /* Always emit the information for each class every time. */
kono
parents:
diff changeset
2146 if (flag_emit_class_debug_always)
kono
parents:
diff changeset
2147 return;
kono
parents:
diff changeset
2148
kono
parents:
diff changeset
2149 /* If we already know how we're handling this class, handle debug info
kono
parents:
diff changeset
2150 the same way. */
kono
parents:
diff changeset
2151 if (CLASSTYPE_INTERFACE_KNOWN (t))
kono
parents:
diff changeset
2152 {
kono
parents:
diff changeset
2153 if (CLASSTYPE_INTERFACE_ONLY (t))
kono
parents:
diff changeset
2154 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
kono
parents:
diff changeset
2155 /* else don't set it. */
kono
parents:
diff changeset
2156 }
kono
parents:
diff changeset
2157 /* If the class has a vtable, write out the debug info along with
kono
parents:
diff changeset
2158 the vtable. */
kono
parents:
diff changeset
2159 else if (TYPE_CONTAINS_VPTR_P (t))
kono
parents:
diff changeset
2160 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
kono
parents:
diff changeset
2161
kono
parents:
diff changeset
2162 /* Otherwise, just emit the debug info normally. */
kono
parents:
diff changeset
2163 }
kono
parents:
diff changeset
2164
kono
parents:
diff changeset
2165 /* Note that we want debugging information for a base class of a class
kono
parents:
diff changeset
2166 whose vtable is being emitted. Normally, this would happen because
kono
parents:
diff changeset
2167 calling the constructor for a derived class implies calling the
kono
parents:
diff changeset
2168 constructors for all bases, which involve initializing the
kono
parents:
diff changeset
2169 appropriate vptr with the vtable for the base class; but in the
kono
parents:
diff changeset
2170 presence of optimization, this initialization may be optimized
kono
parents:
diff changeset
2171 away, so we tell finish_vtable_vardecl that we want the debugging
kono
parents:
diff changeset
2172 information anyway. */
kono
parents:
diff changeset
2173
kono
parents:
diff changeset
2174 static tree
kono
parents:
diff changeset
2175 dfs_debug_mark (tree binfo, void * /*data*/)
kono
parents:
diff changeset
2176 {
kono
parents:
diff changeset
2177 tree t = BINFO_TYPE (binfo);
kono
parents:
diff changeset
2178
kono
parents:
diff changeset
2179 if (CLASSTYPE_DEBUG_REQUESTED (t))
kono
parents:
diff changeset
2180 return dfs_skip_bases;
kono
parents:
diff changeset
2181
kono
parents:
diff changeset
2182 CLASSTYPE_DEBUG_REQUESTED (t) = 1;
kono
parents:
diff changeset
2183
kono
parents:
diff changeset
2184 return NULL_TREE;
kono
parents:
diff changeset
2185 }
kono
parents:
diff changeset
2186
kono
parents:
diff changeset
2187 /* Write out the debugging information for TYPE, whose vtable is being
kono
parents:
diff changeset
2188 emitted. Also walk through our bases and note that we want to
kono
parents:
diff changeset
2189 write out information for them. This avoids the problem of not
kono
parents:
diff changeset
2190 writing any debug info for intermediate basetypes whose
kono
parents:
diff changeset
2191 constructors, and thus the references to their vtables, and thus
kono
parents:
diff changeset
2192 the vtables themselves, were optimized away. */
kono
parents:
diff changeset
2193
kono
parents:
diff changeset
2194 void
kono
parents:
diff changeset
2195 note_debug_info_needed (tree type)
kono
parents:
diff changeset
2196 {
kono
parents:
diff changeset
2197 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
kono
parents:
diff changeset
2198 {
kono
parents:
diff changeset
2199 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)) = 0;
kono
parents:
diff changeset
2200 rest_of_type_compilation (type, namespace_bindings_p ());
kono
parents:
diff changeset
2201 }
kono
parents:
diff changeset
2202
kono
parents:
diff changeset
2203 dfs_walk_all (TYPE_BINFO (type), dfs_debug_mark, NULL, 0);
kono
parents:
diff changeset
2204 }
kono
parents:
diff changeset
2205
kono
parents:
diff changeset
2206 /* Helper for lookup_conversions_r. TO_TYPE is the type converted to
kono
parents:
diff changeset
2207 by a conversion op in base BINFO. VIRTUAL_DEPTH is nonzero if
kono
parents:
diff changeset
2208 BINFO is morally virtual, and VIRTUALNESS is nonzero if virtual
kono
parents:
diff changeset
2209 bases have been encountered already in the tree walk. PARENT_CONVS
kono
parents:
diff changeset
2210 is the list of lists of conversion functions that could hide CONV
kono
parents:
diff changeset
2211 and OTHER_CONVS is the list of lists of conversion functions that
kono
parents:
diff changeset
2212 could hide or be hidden by CONV, should virtualness be involved in
kono
parents:
diff changeset
2213 the hierarchy. Merely checking the conversion op's name is not
kono
parents:
diff changeset
2214 enough because two conversion operators to the same type can have
kono
parents:
diff changeset
2215 different names. Return nonzero if we are visible. */
kono
parents:
diff changeset
2216
kono
parents:
diff changeset
2217 static int
kono
parents:
diff changeset
2218 check_hidden_convs (tree binfo, int virtual_depth, int virtualness,
kono
parents:
diff changeset
2219 tree to_type, tree parent_convs, tree other_convs)
kono
parents:
diff changeset
2220 {
kono
parents:
diff changeset
2221 tree level, probe;
kono
parents:
diff changeset
2222
kono
parents:
diff changeset
2223 /* See if we are hidden by a parent conversion. */
kono
parents:
diff changeset
2224 for (level = parent_convs; level; level = TREE_CHAIN (level))
kono
parents:
diff changeset
2225 for (probe = TREE_VALUE (level); probe; probe = TREE_CHAIN (probe))
kono
parents:
diff changeset
2226 if (same_type_p (to_type, TREE_TYPE (probe)))
kono
parents:
diff changeset
2227 return 0;
kono
parents:
diff changeset
2228
kono
parents:
diff changeset
2229 if (virtual_depth || virtualness)
kono
parents:
diff changeset
2230 {
kono
parents:
diff changeset
2231 /* In a virtual hierarchy, we could be hidden, or could hide a
kono
parents:
diff changeset
2232 conversion function on the other_convs list. */
kono
parents:
diff changeset
2233 for (level = other_convs; level; level = TREE_CHAIN (level))
kono
parents:
diff changeset
2234 {
kono
parents:
diff changeset
2235 int we_hide_them;
kono
parents:
diff changeset
2236 int they_hide_us;
kono
parents:
diff changeset
2237 tree *prev, other;
kono
parents:
diff changeset
2238
kono
parents:
diff changeset
2239 if (!(virtual_depth || TREE_STATIC (level)))
kono
parents:
diff changeset
2240 /* Neither is morally virtual, so cannot hide each other. */
kono
parents:
diff changeset
2241 continue;
kono
parents:
diff changeset
2242
kono
parents:
diff changeset
2243 if (!TREE_VALUE (level))
kono
parents:
diff changeset
2244 /* They evaporated away already. */
kono
parents:
diff changeset
2245 continue;
kono
parents:
diff changeset
2246
kono
parents:
diff changeset
2247 they_hide_us = (virtual_depth
kono
parents:
diff changeset
2248 && original_binfo (binfo, TREE_PURPOSE (level)));
kono
parents:
diff changeset
2249 we_hide_them = (!they_hide_us && TREE_STATIC (level)
kono
parents:
diff changeset
2250 && original_binfo (TREE_PURPOSE (level), binfo));
kono
parents:
diff changeset
2251
kono
parents:
diff changeset
2252 if (!(we_hide_them || they_hide_us))
kono
parents:
diff changeset
2253 /* Neither is within the other, so no hiding can occur. */
kono
parents:
diff changeset
2254 continue;
kono
parents:
diff changeset
2255
kono
parents:
diff changeset
2256 for (prev = &TREE_VALUE (level), other = *prev; other;)
kono
parents:
diff changeset
2257 {
kono
parents:
diff changeset
2258 if (same_type_p (to_type, TREE_TYPE (other)))
kono
parents:
diff changeset
2259 {
kono
parents:
diff changeset
2260 if (they_hide_us)
kono
parents:
diff changeset
2261 /* We are hidden. */
kono
parents:
diff changeset
2262 return 0;
kono
parents:
diff changeset
2263
kono
parents:
diff changeset
2264 if (we_hide_them)
kono
parents:
diff changeset
2265 {
kono
parents:
diff changeset
2266 /* We hide the other one. */
kono
parents:
diff changeset
2267 other = TREE_CHAIN (other);
kono
parents:
diff changeset
2268 *prev = other;
kono
parents:
diff changeset
2269 continue;
kono
parents:
diff changeset
2270 }
kono
parents:
diff changeset
2271 }
kono
parents:
diff changeset
2272 prev = &TREE_CHAIN (other);
kono
parents:
diff changeset
2273 other = *prev;
kono
parents:
diff changeset
2274 }
kono
parents:
diff changeset
2275 }
kono
parents:
diff changeset
2276 }
kono
parents:
diff changeset
2277 return 1;
kono
parents:
diff changeset
2278 }
kono
parents:
diff changeset
2279
kono
parents:
diff changeset
2280 /* Helper for lookup_conversions_r. PARENT_CONVS is a list of lists
kono
parents:
diff changeset
2281 of conversion functions, the first slot will be for the current
kono
parents:
diff changeset
2282 binfo, if MY_CONVS is non-NULL. CHILD_CONVS is the list of lists
kono
parents:
diff changeset
2283 of conversion functions from children of the current binfo,
kono
parents:
diff changeset
2284 concatenated with conversions from elsewhere in the hierarchy --
kono
parents:
diff changeset
2285 that list begins with OTHER_CONVS. Return a single list of lists
kono
parents:
diff changeset
2286 containing only conversions from the current binfo and its
kono
parents:
diff changeset
2287 children. */
kono
parents:
diff changeset
2288
kono
parents:
diff changeset
2289 static tree
kono
parents:
diff changeset
2290 split_conversions (tree my_convs, tree parent_convs,
kono
parents:
diff changeset
2291 tree child_convs, tree other_convs)
kono
parents:
diff changeset
2292 {
kono
parents:
diff changeset
2293 tree t;
kono
parents:
diff changeset
2294 tree prev;
kono
parents:
diff changeset
2295
kono
parents:
diff changeset
2296 /* Remove the original other_convs portion from child_convs. */
kono
parents:
diff changeset
2297 for (prev = NULL, t = child_convs;
kono
parents:
diff changeset
2298 t != other_convs; prev = t, t = TREE_CHAIN (t))
kono
parents:
diff changeset
2299 continue;
kono
parents:
diff changeset
2300
kono
parents:
diff changeset
2301 if (prev)
kono
parents:
diff changeset
2302 TREE_CHAIN (prev) = NULL_TREE;
kono
parents:
diff changeset
2303 else
kono
parents:
diff changeset
2304 child_convs = NULL_TREE;
kono
parents:
diff changeset
2305
kono
parents:
diff changeset
2306 /* Attach the child convs to any we had at this level. */
kono
parents:
diff changeset
2307 if (my_convs)
kono
parents:
diff changeset
2308 {
kono
parents:
diff changeset
2309 my_convs = parent_convs;
kono
parents:
diff changeset
2310 TREE_CHAIN (my_convs) = child_convs;
kono
parents:
diff changeset
2311 }
kono
parents:
diff changeset
2312 else
kono
parents:
diff changeset
2313 my_convs = child_convs;
kono
parents:
diff changeset
2314
kono
parents:
diff changeset
2315 return my_convs;
kono
parents:
diff changeset
2316 }
kono
parents:
diff changeset
2317
kono
parents:
diff changeset
2318 /* Worker for lookup_conversions. Lookup conversion functions in
kono
parents:
diff changeset
2319 BINFO and its children. VIRTUAL_DEPTH is nonzero, if BINFO is in a
kono
parents:
diff changeset
2320 morally virtual base, and VIRTUALNESS is nonzero, if we've
kono
parents:
diff changeset
2321 encountered virtual bases already in the tree walk. PARENT_CONVS
kono
parents:
diff changeset
2322 is a list of conversions within parent binfos. OTHER_CONVS are
kono
parents:
diff changeset
2323 conversions found elsewhere in the tree. Return the conversions
kono
parents:
diff changeset
2324 found within this portion of the graph in CONVS. Return nonzero if
kono
parents:
diff changeset
2325 we encountered virtualness. We keep template and non-template
kono
parents:
diff changeset
2326 conversions separate, to avoid unnecessary type comparisons.
kono
parents:
diff changeset
2327
kono
parents:
diff changeset
2328 The located conversion functions are held in lists of lists. The
kono
parents:
diff changeset
2329 TREE_VALUE of the outer list is the list of conversion functions
kono
parents:
diff changeset
2330 found in a particular binfo. The TREE_PURPOSE of both the outer
kono
parents:
diff changeset
2331 and inner lists is the binfo at which those conversions were
kono
parents:
diff changeset
2332 found. TREE_STATIC is set for those lists within of morally
kono
parents:
diff changeset
2333 virtual binfos. The TREE_VALUE of the inner list is the conversion
kono
parents:
diff changeset
2334 function or overload itself. The TREE_TYPE of each inner list node
kono
parents:
diff changeset
2335 is the converted-to type. */
kono
parents:
diff changeset
2336
kono
parents:
diff changeset
2337 static int
kono
parents:
diff changeset
2338 lookup_conversions_r (tree binfo, int virtual_depth, int virtualness,
kono
parents:
diff changeset
2339 tree parent_convs, tree other_convs, tree *convs)
kono
parents:
diff changeset
2340 {
kono
parents:
diff changeset
2341 int my_virtualness = 0;
kono
parents:
diff changeset
2342 tree my_convs = NULL_TREE;
kono
parents:
diff changeset
2343 tree child_convs = NULL_TREE;
kono
parents:
diff changeset
2344
kono
parents:
diff changeset
2345 /* If we have no conversion operators, then don't look. */
kono
parents:
diff changeset
2346 if (!TYPE_HAS_CONVERSION (BINFO_TYPE (binfo)))
kono
parents:
diff changeset
2347 {
kono
parents:
diff changeset
2348 *convs = NULL_TREE;
kono
parents:
diff changeset
2349
kono
parents:
diff changeset
2350 return 0;
kono
parents:
diff changeset
2351 }
kono
parents:
diff changeset
2352
kono
parents:
diff changeset
2353 if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
2354 virtual_depth++;
kono
parents:
diff changeset
2355
kono
parents:
diff changeset
2356 /* First, locate the unhidden ones at this level. */
kono
parents:
diff changeset
2357 if (tree conv = get_class_binding (BINFO_TYPE (binfo), conv_op_identifier))
kono
parents:
diff changeset
2358 for (ovl_iterator iter (conv); iter; ++iter)
kono
parents:
diff changeset
2359 {
kono
parents:
diff changeset
2360 tree fn = *iter;
kono
parents:
diff changeset
2361 tree type = DECL_CONV_FN_TYPE (fn);
kono
parents:
diff changeset
2362
kono
parents:
diff changeset
2363 if (TREE_CODE (fn) != TEMPLATE_DECL && type_uses_auto (type))
kono
parents:
diff changeset
2364 {
kono
parents:
diff changeset
2365 mark_used (fn);
kono
parents:
diff changeset
2366 type = DECL_CONV_FN_TYPE (fn);
kono
parents:
diff changeset
2367 }
kono
parents:
diff changeset
2368
kono
parents:
diff changeset
2369 if (check_hidden_convs (binfo, virtual_depth, virtualness,
kono
parents:
diff changeset
2370 type, parent_convs, other_convs))
kono
parents:
diff changeset
2371 {
kono
parents:
diff changeset
2372 my_convs = tree_cons (binfo, fn, my_convs);
kono
parents:
diff changeset
2373 TREE_TYPE (my_convs) = type;
kono
parents:
diff changeset
2374 if (virtual_depth)
kono
parents:
diff changeset
2375 {
kono
parents:
diff changeset
2376 TREE_STATIC (my_convs) = 1;
kono
parents:
diff changeset
2377 my_virtualness = 1;
kono
parents:
diff changeset
2378 }
kono
parents:
diff changeset
2379 }
kono
parents:
diff changeset
2380 }
kono
parents:
diff changeset
2381
kono
parents:
diff changeset
2382 if (my_convs)
kono
parents:
diff changeset
2383 {
kono
parents:
diff changeset
2384 parent_convs = tree_cons (binfo, my_convs, parent_convs);
kono
parents:
diff changeset
2385 if (virtual_depth)
kono
parents:
diff changeset
2386 TREE_STATIC (parent_convs) = 1;
kono
parents:
diff changeset
2387 }
kono
parents:
diff changeset
2388
kono
parents:
diff changeset
2389 child_convs = other_convs;
kono
parents:
diff changeset
2390
kono
parents:
diff changeset
2391 /* Now iterate over each base, looking for more conversions. */
kono
parents:
diff changeset
2392 unsigned i;
kono
parents:
diff changeset
2393 tree base_binfo;
kono
parents:
diff changeset
2394 for (i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
kono
parents:
diff changeset
2395 {
kono
parents:
diff changeset
2396 tree base_convs;
kono
parents:
diff changeset
2397 unsigned base_virtualness;
kono
parents:
diff changeset
2398
kono
parents:
diff changeset
2399 base_virtualness = lookup_conversions_r (base_binfo,
kono
parents:
diff changeset
2400 virtual_depth, virtualness,
kono
parents:
diff changeset
2401 parent_convs, child_convs,
kono
parents:
diff changeset
2402 &base_convs);
kono
parents:
diff changeset
2403 if (base_virtualness)
kono
parents:
diff changeset
2404 my_virtualness = virtualness = 1;
kono
parents:
diff changeset
2405 child_convs = chainon (base_convs, child_convs);
kono
parents:
diff changeset
2406 }
kono
parents:
diff changeset
2407
kono
parents:
diff changeset
2408 *convs = split_conversions (my_convs, parent_convs,
kono
parents:
diff changeset
2409 child_convs, other_convs);
kono
parents:
diff changeset
2410
kono
parents:
diff changeset
2411 return my_virtualness;
kono
parents:
diff changeset
2412 }
kono
parents:
diff changeset
2413
kono
parents:
diff changeset
2414 /* Return a TREE_LIST containing all the non-hidden user-defined
kono
parents:
diff changeset
2415 conversion functions for TYPE (and its base-classes). The
kono
parents:
diff changeset
2416 TREE_VALUE of each node is the FUNCTION_DECL of the conversion
kono
parents:
diff changeset
2417 function. The TREE_PURPOSE is the BINFO from which the conversion
kono
parents:
diff changeset
2418 functions in this node were selected. This function is effectively
kono
parents:
diff changeset
2419 performing a set of member lookups as lookup_fnfield does, but
kono
parents:
diff changeset
2420 using the type being converted to as the unique key, rather than the
kono
parents:
diff changeset
2421 field name. */
kono
parents:
diff changeset
2422
kono
parents:
diff changeset
2423 tree
kono
parents:
diff changeset
2424 lookup_conversions (tree type)
kono
parents:
diff changeset
2425 {
kono
parents:
diff changeset
2426 tree convs;
kono
parents:
diff changeset
2427
kono
parents:
diff changeset
2428 complete_type (type);
kono
parents:
diff changeset
2429 if (!CLASS_TYPE_P (type) || !TYPE_BINFO (type))
kono
parents:
diff changeset
2430 return NULL_TREE;
kono
parents:
diff changeset
2431
kono
parents:
diff changeset
2432 lookup_conversions_r (TYPE_BINFO (type), 0, 0, NULL_TREE, NULL_TREE, &convs);
kono
parents:
diff changeset
2433
kono
parents:
diff changeset
2434 tree list = NULL_TREE;
kono
parents:
diff changeset
2435
kono
parents:
diff changeset
2436 /* Flatten the list-of-lists */
kono
parents:
diff changeset
2437 for (; convs; convs = TREE_CHAIN (convs))
kono
parents:
diff changeset
2438 {
kono
parents:
diff changeset
2439 tree probe, next;
kono
parents:
diff changeset
2440
kono
parents:
diff changeset
2441 for (probe = TREE_VALUE (convs); probe; probe = next)
kono
parents:
diff changeset
2442 {
kono
parents:
diff changeset
2443 next = TREE_CHAIN (probe);
kono
parents:
diff changeset
2444
kono
parents:
diff changeset
2445 TREE_CHAIN (probe) = list;
kono
parents:
diff changeset
2446 list = probe;
kono
parents:
diff changeset
2447 }
kono
parents:
diff changeset
2448 }
kono
parents:
diff changeset
2449
kono
parents:
diff changeset
2450 return list;
kono
parents:
diff changeset
2451 }
kono
parents:
diff changeset
2452
kono
parents:
diff changeset
2453 /* Returns the binfo of the first direct or indirect virtual base derived
kono
parents:
diff changeset
2454 from BINFO, or NULL if binfo is not via virtual. */
kono
parents:
diff changeset
2455
kono
parents:
diff changeset
2456 tree
kono
parents:
diff changeset
2457 binfo_from_vbase (tree binfo)
kono
parents:
diff changeset
2458 {
kono
parents:
diff changeset
2459 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
kono
parents:
diff changeset
2460 {
kono
parents:
diff changeset
2461 if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
2462 return binfo;
kono
parents:
diff changeset
2463 }
kono
parents:
diff changeset
2464 return NULL_TREE;
kono
parents:
diff changeset
2465 }
kono
parents:
diff changeset
2466
kono
parents:
diff changeset
2467 /* Returns the binfo of the first direct or indirect virtual base derived
kono
parents:
diff changeset
2468 from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
kono
parents:
diff changeset
2469 via virtual. */
kono
parents:
diff changeset
2470
kono
parents:
diff changeset
2471 tree
kono
parents:
diff changeset
2472 binfo_via_virtual (tree binfo, tree limit)
kono
parents:
diff changeset
2473 {
kono
parents:
diff changeset
2474 if (limit && !CLASSTYPE_VBASECLASSES (limit))
kono
parents:
diff changeset
2475 /* LIMIT has no virtual bases, so BINFO cannot be via one. */
kono
parents:
diff changeset
2476 return NULL_TREE;
kono
parents:
diff changeset
2477
kono
parents:
diff changeset
2478 for (; binfo && !SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), limit);
kono
parents:
diff changeset
2479 binfo = BINFO_INHERITANCE_CHAIN (binfo))
kono
parents:
diff changeset
2480 {
kono
parents:
diff changeset
2481 if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
2482 return binfo;
kono
parents:
diff changeset
2483 }
kono
parents:
diff changeset
2484 return NULL_TREE;
kono
parents:
diff changeset
2485 }
kono
parents:
diff changeset
2486
kono
parents:
diff changeset
2487 /* BINFO is for a base class in some hierarchy. Return true iff it is a
kono
parents:
diff changeset
2488 direct base. */
kono
parents:
diff changeset
2489
kono
parents:
diff changeset
2490 bool
kono
parents:
diff changeset
2491 binfo_direct_p (tree binfo)
kono
parents:
diff changeset
2492 {
kono
parents:
diff changeset
2493 tree d_binfo = BINFO_INHERITANCE_CHAIN (binfo);
kono
parents:
diff changeset
2494 if (BINFO_INHERITANCE_CHAIN (d_binfo))
kono
parents:
diff changeset
2495 /* A second inheritance chain means indirect. */
kono
parents:
diff changeset
2496 return false;
kono
parents:
diff changeset
2497 if (!BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
2498 /* Non-virtual, so only one inheritance chain means direct. */
kono
parents:
diff changeset
2499 return true;
kono
parents:
diff changeset
2500 /* A virtual base looks like a direct base, so we need to look through the
kono
parents:
diff changeset
2501 direct bases to see if it's there. */
kono
parents:
diff changeset
2502 tree b_binfo;
kono
parents:
diff changeset
2503 for (int i = 0; BINFO_BASE_ITERATE (d_binfo, i, b_binfo); ++i)
kono
parents:
diff changeset
2504 if (b_binfo == binfo)
kono
parents:
diff changeset
2505 return true;
kono
parents:
diff changeset
2506 return false;
kono
parents:
diff changeset
2507 }
kono
parents:
diff changeset
2508
kono
parents:
diff changeset
2509 /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
kono
parents:
diff changeset
2510 Find the equivalent binfo within whatever graph HERE is located.
kono
parents:
diff changeset
2511 This is the inverse of original_binfo. */
kono
parents:
diff changeset
2512
kono
parents:
diff changeset
2513 tree
kono
parents:
diff changeset
2514 copied_binfo (tree binfo, tree here)
kono
parents:
diff changeset
2515 {
kono
parents:
diff changeset
2516 tree result = NULL_TREE;
kono
parents:
diff changeset
2517
kono
parents:
diff changeset
2518 if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
2519 {
kono
parents:
diff changeset
2520 tree t;
kono
parents:
diff changeset
2521
kono
parents:
diff changeset
2522 for (t = here; BINFO_INHERITANCE_CHAIN (t);
kono
parents:
diff changeset
2523 t = BINFO_INHERITANCE_CHAIN (t))
kono
parents:
diff changeset
2524 continue;
kono
parents:
diff changeset
2525
kono
parents:
diff changeset
2526 result = binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (t));
kono
parents:
diff changeset
2527 }
kono
parents:
diff changeset
2528 else if (BINFO_INHERITANCE_CHAIN (binfo))
kono
parents:
diff changeset
2529 {
kono
parents:
diff changeset
2530 tree cbinfo;
kono
parents:
diff changeset
2531 tree base_binfo;
kono
parents:
diff changeset
2532 int ix;
kono
parents:
diff changeset
2533
kono
parents:
diff changeset
2534 cbinfo = copied_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
kono
parents:
diff changeset
2535 for (ix = 0; BINFO_BASE_ITERATE (cbinfo, ix, base_binfo); ix++)
kono
parents:
diff changeset
2536 if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo), BINFO_TYPE (binfo)))
kono
parents:
diff changeset
2537 {
kono
parents:
diff changeset
2538 result = base_binfo;
kono
parents:
diff changeset
2539 break;
kono
parents:
diff changeset
2540 }
kono
parents:
diff changeset
2541 }
kono
parents:
diff changeset
2542 else
kono
parents:
diff changeset
2543 {
kono
parents:
diff changeset
2544 gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (here), BINFO_TYPE (binfo)));
kono
parents:
diff changeset
2545 result = here;
kono
parents:
diff changeset
2546 }
kono
parents:
diff changeset
2547
kono
parents:
diff changeset
2548 gcc_assert (result);
kono
parents:
diff changeset
2549 return result;
kono
parents:
diff changeset
2550 }
kono
parents:
diff changeset
2551
kono
parents:
diff changeset
2552 tree
kono
parents:
diff changeset
2553 binfo_for_vbase (tree base, tree t)
kono
parents:
diff changeset
2554 {
kono
parents:
diff changeset
2555 unsigned ix;
kono
parents:
diff changeset
2556 tree binfo;
kono
parents:
diff changeset
2557 vec<tree, va_gc> *vbases;
kono
parents:
diff changeset
2558
kono
parents:
diff changeset
2559 for (vbases = CLASSTYPE_VBASECLASSES (t), ix = 0;
kono
parents:
diff changeset
2560 vec_safe_iterate (vbases, ix, &binfo); ix++)
kono
parents:
diff changeset
2561 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), base))
kono
parents:
diff changeset
2562 return binfo;
kono
parents:
diff changeset
2563 return NULL;
kono
parents:
diff changeset
2564 }
kono
parents:
diff changeset
2565
kono
parents:
diff changeset
2566 /* BINFO is some base binfo of HERE, within some other
kono
parents:
diff changeset
2567 hierarchy. Return the equivalent binfo, but in the hierarchy
kono
parents:
diff changeset
2568 dominated by HERE. This is the inverse of copied_binfo. If BINFO
kono
parents:
diff changeset
2569 is not a base binfo of HERE, returns NULL_TREE. */
kono
parents:
diff changeset
2570
kono
parents:
diff changeset
2571 tree
kono
parents:
diff changeset
2572 original_binfo (tree binfo, tree here)
kono
parents:
diff changeset
2573 {
kono
parents:
diff changeset
2574 tree result = NULL;
kono
parents:
diff changeset
2575
kono
parents:
diff changeset
2576 if (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), BINFO_TYPE (here)))
kono
parents:
diff changeset
2577 result = here;
kono
parents:
diff changeset
2578 else if (BINFO_VIRTUAL_P (binfo))
kono
parents:
diff changeset
2579 result = (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here))
kono
parents:
diff changeset
2580 ? binfo_for_vbase (BINFO_TYPE (binfo), BINFO_TYPE (here))
kono
parents:
diff changeset
2581 : NULL_TREE);
kono
parents:
diff changeset
2582 else if (BINFO_INHERITANCE_CHAIN (binfo))
kono
parents:
diff changeset
2583 {
kono
parents:
diff changeset
2584 tree base_binfos;
kono
parents:
diff changeset
2585
kono
parents:
diff changeset
2586 base_binfos = original_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
kono
parents:
diff changeset
2587 if (base_binfos)
kono
parents:
diff changeset
2588 {
kono
parents:
diff changeset
2589 int ix;
kono
parents:
diff changeset
2590 tree base_binfo;
kono
parents:
diff changeset
2591
kono
parents:
diff changeset
2592 for (ix = 0; (base_binfo = BINFO_BASE_BINFO (base_binfos, ix)); ix++)
kono
parents:
diff changeset
2593 if (SAME_BINFO_TYPE_P (BINFO_TYPE (base_binfo),
kono
parents:
diff changeset
2594 BINFO_TYPE (binfo)))
kono
parents:
diff changeset
2595 {
kono
parents:
diff changeset
2596 result = base_binfo;
kono
parents:
diff changeset
2597 break;
kono
parents:
diff changeset
2598 }
kono
parents:
diff changeset
2599 }
kono
parents:
diff changeset
2600 }
kono
parents:
diff changeset
2601
kono
parents:
diff changeset
2602 return result;
kono
parents:
diff changeset
2603 }
kono
parents:
diff changeset
2604
kono
parents:
diff changeset
2605 /* True iff TYPE has any dependent bases (and therefore we can't say
kono
parents:
diff changeset
2606 definitively that another class is not a base of an instantiation of
kono
parents:
diff changeset
2607 TYPE). */
kono
parents:
diff changeset
2608
kono
parents:
diff changeset
2609 bool
kono
parents:
diff changeset
2610 any_dependent_bases_p (tree type)
kono
parents:
diff changeset
2611 {
kono
parents:
diff changeset
2612 if (!type || !CLASS_TYPE_P (type) || !processing_template_decl)
kono
parents:
diff changeset
2613 return false;
kono
parents:
diff changeset
2614
kono
parents:
diff changeset
2615 unsigned i;
kono
parents:
diff changeset
2616 tree base_binfo;
kono
parents:
diff changeset
2617 FOR_EACH_VEC_SAFE_ELT (BINFO_BASE_BINFOS (TYPE_BINFO (type)), i, base_binfo)
kono
parents:
diff changeset
2618 if (BINFO_DEPENDENT_BASE_P (base_binfo))
kono
parents:
diff changeset
2619 return true;
kono
parents:
diff changeset
2620
kono
parents:
diff changeset
2621 return false;
kono
parents:
diff changeset
2622 }