annotate gcc/cp/search.c @ 136:4627f235cf2a

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