]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/search.c
a87ba5f602982f8e4bf8de4e582b51e2b1f0d55a
[gcc.git] / gcc / cp / search.c
1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
13
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24 /* High-level class interface. */
25
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "tm.h"
30 #include "tree.h"
31 #include "cp-tree.h"
32 #include "obstack.h"
33 #include "flags.h"
34 #include "rtl.h"
35 #include "output.h"
36 #include "toplev.h"
37 #include "stack.h"
38
39 /* Obstack used for remembering decision points of breadth-first. */
40
41 static struct obstack search_obstack;
42
43 /* Methods for pushing and popping objects to and from obstacks. */
44
45 struct stack_level *
46 push_stack_level (obstack, tp, size)
47 struct obstack *obstack;
48 char *tp; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
49 int size;
50 {
51 struct stack_level *stack;
52 obstack_grow (obstack, tp, size);
53 stack = (struct stack_level *) ((char*)obstack_next_free (obstack) - size);
54 obstack_finish (obstack);
55 stack->obstack = obstack;
56 stack->first = (tree *) obstack_base (obstack);
57 stack->limit = obstack_room (obstack) / sizeof (tree *);
58 return stack;
59 }
60
61 struct stack_level *
62 pop_stack_level (stack)
63 struct stack_level *stack;
64 {
65 struct stack_level *tem = stack;
66 struct obstack *obstack = tem->obstack;
67 stack = tem->prev;
68 obstack_free (obstack, tem);
69 return stack;
70 }
71
72 #define search_level stack_level
73 static struct search_level *search_stack;
74
75 struct vbase_info
76 {
77 /* The class dominating the hierarchy. */
78 tree type;
79 /* A pointer to a complete object of the indicated TYPE. */
80 tree decl_ptr;
81 tree inits;
82 };
83
84 static tree lookup_field_1 (tree, tree);
85 static int is_subobject_of_p (tree, tree, tree);
86 static int is_subobject_of_p_1 (tree, tree, tree);
87 static tree dfs_check_overlap (tree, void *);
88 static tree dfs_no_overlap_yet (tree, void *);
89 static base_kind lookup_base_r (tree, tree, base_access,
90 bool, bool, bool, tree *);
91 static int dynamic_cast_base_recurse (tree, tree, bool, tree *);
92 static tree marked_pushdecls_p (tree, void *);
93 static tree unmarked_pushdecls_p (tree, void *);
94 static tree dfs_debug_unmarkedp (tree, void *);
95 static tree dfs_debug_mark (tree, void *);
96 static tree dfs_get_vbase_types (tree, void *);
97 static tree dfs_push_type_decls (tree, void *);
98 static tree dfs_push_decls (tree, void *);
99 static tree dfs_unuse_fields (tree, void *);
100 static tree add_conversions (tree, void *);
101 static int look_for_overrides_r (tree, tree);
102 static struct search_level *push_search_level (struct stack_level *,
103 struct obstack *);
104 static struct search_level *pop_search_level (struct stack_level *);
105 static tree bfs_walk (tree, tree (*) (tree, void *),
106 tree (*) (tree, void *), void *);
107 static tree lookup_field_queue_p (tree, void *);
108 static int shared_member_p (tree);
109 static tree lookup_field_r (tree, void *);
110 static tree canonical_binfo (tree);
111 static tree shared_marked_p (tree, void *);
112 static tree shared_unmarked_p (tree, void *);
113 static int dependent_base_p (tree);
114 static tree dfs_accessible_queue_p (tree, void *);
115 static tree dfs_accessible_p (tree, void *);
116 static tree dfs_access_in_type (tree, void *);
117 static access_kind access_in_type (tree, tree);
118 static tree dfs_canonical_queue (tree, void *);
119 static tree dfs_assert_unmarked_p (tree, void *);
120 static void assert_canonical_unmarked (tree);
121 static int protected_accessible_p (tree, tree, tree);
122 static int friend_accessible_p (tree, tree, tree);
123 static void setup_class_bindings (tree, int);
124 static int template_self_reference_p (tree, tree);
125 static tree dfs_find_vbase_instance (tree, void *);
126 static tree dfs_get_pure_virtuals (tree, void *);
127 static tree dfs_build_inheritance_graph_order (tree, void *);
128
129 /* Allocate a level of searching. */
130
131 static struct search_level *
132 push_search_level (struct stack_level *stack, struct obstack *obstack)
133 {
134 struct search_level tem;
135
136 tem.prev = stack;
137 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
138 }
139
140 /* Discard a level of search allocation. */
141
142 static struct search_level *
143 pop_search_level (struct stack_level *obstack)
144 {
145 register struct search_level *stack = pop_stack_level (obstack);
146
147 return stack;
148 }
149 \f
150 /* Variables for gathering statistics. */
151 #ifdef GATHER_STATISTICS
152 static int n_fields_searched;
153 static int n_calls_lookup_field, n_calls_lookup_field_1;
154 static int n_calls_lookup_fnfields, n_calls_lookup_fnfields_1;
155 static int n_calls_get_base_type;
156 static int n_outer_fields_searched;
157 static int n_contexts_saved;
158 #endif /* GATHER_STATISTICS */
159
160 \f
161 /* Worker for lookup_base. BINFO is the binfo we are searching at,
162 BASE is the RECORD_TYPE we are searching for. ACCESS is the
163 required access checks. WITHIN_CURRENT_SCOPE, IS_NON_PUBLIC and
164 IS_VIRTUAL indicate how BINFO was reached from the start of the
165 search. WITHIN_CURRENT_SCOPE is true if we met the current scope,
166 or friend thereof (this allows us to determine whether a protected
167 base is accessible or not). IS_NON_PUBLIC indicates whether BINFO
168 is accessible and IS_VIRTUAL indicates if it is morally virtual.
169
170 If BINFO is of the required type, then *BINFO_PTR is examined to
171 compare with any other instance of BASE we might have already
172 discovered. *BINFO_PTR is initialized and a base_kind return value
173 indicates what kind of base was located.
174
175 Otherwise BINFO's bases are searched. */
176
177 static base_kind
178 lookup_base_r (tree binfo, tree base, base_access access,
179 bool within_current_scope,
180 bool is_non_public, /* inside a non-public part */
181 bool is_virtual, /* inside a virtual part */
182 tree *binfo_ptr)
183 {
184 int i;
185 tree bases;
186 base_kind found = bk_not_base;
187
188 if (access == ba_check
189 && !within_current_scope
190 && is_friend (BINFO_TYPE (binfo), current_scope ()))
191 {
192 /* Do not clear is_non_public here. If A is a private base of B, A
193 is not allowed to convert a B* to an A*. */
194 within_current_scope = 1;
195 }
196
197 if (same_type_p (BINFO_TYPE (binfo), base))
198 {
199 /* We have found a base. Check against what we have found
200 already. */
201 found = bk_same_type;
202 if (is_virtual)
203 found = bk_via_virtual;
204 if (is_non_public)
205 found = bk_inaccessible;
206
207 if (!*binfo_ptr)
208 *binfo_ptr = binfo;
209 else if (!is_virtual || !tree_int_cst_equal (BINFO_OFFSET (binfo),
210 BINFO_OFFSET (*binfo_ptr)))
211 {
212 if (access != ba_any)
213 *binfo_ptr = NULL;
214 else if (!is_virtual)
215 /* Prefer a non-virtual base. */
216 *binfo_ptr = binfo;
217 found = bk_ambig;
218 }
219
220 return found;
221 }
222
223 bases = BINFO_BASETYPES (binfo);
224 if (!bases)
225 return bk_not_base;
226
227 for (i = TREE_VEC_LENGTH (bases); i--;)
228 {
229 tree base_binfo = TREE_VEC_ELT (bases, i);
230 int this_non_public = is_non_public;
231 int this_virtual = is_virtual;
232 base_kind bk;
233
234 if (access <= ba_ignore)
235 ; /* no change */
236 else if (TREE_VIA_PUBLIC (base_binfo))
237 ; /* no change */
238 else if (access == ba_not_special)
239 this_non_public = 1;
240 else if (TREE_VIA_PROTECTED (base_binfo) && within_current_scope)
241 ; /* no change */
242 else if (is_friend (BINFO_TYPE (binfo), current_scope ()))
243 ; /* no change */
244 else
245 this_non_public = 1;
246
247 if (TREE_VIA_VIRTUAL (base_binfo))
248 this_virtual = 1;
249
250 bk = lookup_base_r (base_binfo, base,
251 access, within_current_scope,
252 this_non_public, this_virtual,
253 binfo_ptr);
254
255 switch (bk)
256 {
257 case bk_ambig:
258 if (access != ba_any)
259 return bk;
260 found = bk;
261 break;
262
263 case bk_inaccessible:
264 if (found == bk_not_base)
265 found = bk;
266 my_friendly_assert (found == bk_via_virtual
267 || found == bk_inaccessible, 20010723);
268
269 break;
270
271 case bk_same_type:
272 bk = bk_proper_base;
273 /* FALLTHROUGH */
274 case bk_proper_base:
275 my_friendly_assert (found == bk_not_base, 20010723);
276 found = bk;
277 break;
278
279 case bk_via_virtual:
280 if (found != bk_ambig)
281 found = bk;
282 break;
283
284 case bk_not_base:
285 break;
286 }
287 }
288 return found;
289 }
290
291 /* Lookup BASE in the hierarchy dominated by T. Do access checking as
292 ACCESS specifies. Return the binfo we discover (which might not be
293 canonical). If KIND_PTR is non-NULL, fill with information about
294 what kind of base we discovered.
295
296 If the base is inaccessible, or ambiguous, and the ba_quiet bit is
297 not set in ACCESS, then an error is issued and error_mark_node is
298 returned. If the ba_quiet bit is set, then no error is issued and
299 NULL_TREE is returned. */
300
301 tree
302 lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
303 {
304 tree binfo = NULL; /* The binfo we've found so far. */
305 tree t_binfo = NULL;
306 base_kind bk;
307
308 if (t == error_mark_node || base == error_mark_node)
309 {
310 if (kind_ptr)
311 *kind_ptr = bk_not_base;
312 return error_mark_node;
313 }
314 my_friendly_assert (TYPE_P (base), 20011127);
315
316 if (!TYPE_P (t))
317 {
318 t_binfo = t;
319 t = BINFO_TYPE (t);
320 }
321 else
322 t_binfo = TYPE_BINFO (t);
323
324 /* Ensure that the types are instantiated. */
325 t = complete_type (TYPE_MAIN_VARIANT (t));
326 base = complete_type (TYPE_MAIN_VARIANT (base));
327
328 bk = lookup_base_r (t_binfo, base, access & ~ba_quiet,
329 0, 0, 0, &binfo);
330
331 switch (bk)
332 {
333 case bk_inaccessible:
334 binfo = NULL_TREE;
335 if (!(access & ba_quiet))
336 {
337 error ("`%T' is an inaccessible base of `%T'", base, t);
338 binfo = error_mark_node;
339 }
340 break;
341 case bk_ambig:
342 if (access != ba_any)
343 {
344 binfo = NULL_TREE;
345 if (!(access & ba_quiet))
346 {
347 error ("`%T' is an ambiguous base of `%T'", base, t);
348 binfo = error_mark_node;
349 }
350 }
351 break;
352 default:;
353 }
354
355 if (kind_ptr)
356 *kind_ptr = bk;
357
358 return binfo;
359 }
360
361 /* Worker function for get_dynamic_cast_base_type. */
362
363 static int
364 dynamic_cast_base_recurse (tree subtype, tree binfo, bool is_via_virtual,
365 tree *offset_ptr)
366 {
367 tree binfos;
368 int i, n_baselinks;
369 int worst = -2;
370
371 if (BINFO_TYPE (binfo) == subtype)
372 {
373 if (is_via_virtual)
374 return -1;
375 else
376 {
377 *offset_ptr = BINFO_OFFSET (binfo);
378 return 0;
379 }
380 }
381
382 binfos = BINFO_BASETYPES (binfo);
383 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
384 for (i = 0; i < n_baselinks; i++)
385 {
386 tree base_binfo = TREE_VEC_ELT (binfos, i);
387 int rval;
388
389 if (!TREE_VIA_PUBLIC (base_binfo))
390 continue;
391 rval = dynamic_cast_base_recurse
392 (subtype, base_binfo,
393 is_via_virtual || TREE_VIA_VIRTUAL (base_binfo), offset_ptr);
394 if (worst == -2)
395 worst = rval;
396 else if (rval >= 0)
397 worst = worst >= 0 ? -3 : worst;
398 else if (rval == -1)
399 worst = -1;
400 else if (rval == -3 && worst != -1)
401 worst = -3;
402 }
403 return worst;
404 }
405
406 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
407 started from is related to the required TARGET type, in order to optimize
408 the inheritance graph search. This information is independent of the
409 current context, and ignores private paths, hence get_base_distance is
410 inappropriate. Return a TREE specifying the base offset, BOFF.
411 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
412 and there are no public virtual SUBTYPE bases.
413 BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
414 BOFF == -2, SUBTYPE is not a public base.
415 BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
416
417 tree
418 get_dynamic_cast_base_type (tree subtype, tree target)
419 {
420 tree offset = NULL_TREE;
421 int boff = dynamic_cast_base_recurse (subtype, TYPE_BINFO (target),
422 false, &offset);
423
424 if (!boff)
425 return offset;
426 offset = build_int_2 (boff, -1);
427 TREE_TYPE (offset) = ssizetype;
428 return offset;
429 }
430
431 /* Search for a member with name NAME in a multiple inheritance lattice
432 specified by TYPE. If it does not exist, return NULL_TREE.
433 If the member is ambiguously referenced, return `error_mark_node'.
434 Otherwise, return the FIELD_DECL. */
435
436 /* Do a 1-level search for NAME as a member of TYPE. The caller must
437 figure out whether it can access this field. (Since it is only one
438 level, this is reasonable.) */
439
440 static tree
441 lookup_field_1 (tree type, tree name)
442 {
443 register tree field;
444
445 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
446 || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
447 || TREE_CODE (type) == TYPENAME_TYPE)
448 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM and
449 BOUND_TEMPLATE_TEMPLATE_PARM are not fields at all;
450 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
451 the code often worked even when we treated the index as a list
452 of fields!)
453 The TYPE_FIELDS of TYPENAME_TYPE is its TYPENAME_TYPE_FULLNAME. */
454 return NULL_TREE;
455
456 if (TYPE_NAME (type)
457 && DECL_LANG_SPECIFIC (TYPE_NAME (type))
458 && DECL_SORTED_FIELDS (TYPE_NAME (type)))
459 {
460 tree *fields = &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type)), 0);
461 int lo = 0, hi = TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type)));
462 int i;
463
464 while (lo < hi)
465 {
466 i = (lo + hi) / 2;
467
468 #ifdef GATHER_STATISTICS
469 n_fields_searched++;
470 #endif /* GATHER_STATISTICS */
471
472 if (DECL_NAME (fields[i]) > name)
473 hi = i;
474 else if (DECL_NAME (fields[i]) < name)
475 lo = i + 1;
476 else
477 {
478 /* We might have a nested class and a field with the
479 same name; we sorted them appropriately via
480 field_decl_cmp, so just look for the last field with
481 this name. */
482 while (i + 1 < hi
483 && DECL_NAME (fields[i+1]) == name)
484 ++i;
485 return fields[i];
486 }
487 }
488 return NULL_TREE;
489 }
490
491 field = TYPE_FIELDS (type);
492
493 #ifdef GATHER_STATISTICS
494 n_calls_lookup_field_1++;
495 #endif /* GATHER_STATISTICS */
496 while (field)
497 {
498 #ifdef GATHER_STATISTICS
499 n_fields_searched++;
500 #endif /* GATHER_STATISTICS */
501 my_friendly_assert (DECL_P (field), 0);
502 if (DECL_NAME (field) == NULL_TREE
503 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
504 {
505 tree temp = lookup_field_1 (TREE_TYPE (field), name);
506 if (temp)
507 return temp;
508 }
509 if (TREE_CODE (field) == USING_DECL)
510 /* For now, we're just treating member using declarations as
511 old ARM-style access declarations. Thus, there's no reason
512 to return a USING_DECL, and the rest of the compiler can't
513 handle it. Once the class is defined, these are purged
514 from TYPE_FIELDS anyhow; see handle_using_decl. */
515 ;
516 else if (DECL_NAME (field) == name)
517 return field;
518 field = TREE_CHAIN (field);
519 }
520 /* Not found. */
521 if (name == vptr_identifier)
522 {
523 /* Give the user what s/he thinks s/he wants. */
524 if (TYPE_POLYMORPHIC_P (type))
525 return TYPE_VFIELD (type);
526 }
527 return NULL_TREE;
528 }
529
530 /* There are a number of cases we need to be aware of here:
531 current_class_type current_function_decl
532 global NULL NULL
533 fn-local NULL SET
534 class-local SET NULL
535 class->fn SET SET
536 fn->class SET SET
537
538 Those last two make life interesting. If we're in a function which is
539 itself inside a class, we need decls to go into the fn's decls (our
540 second case below). But if we're in a class and the class itself is
541 inside a function, we need decls to go into the decls for the class. To
542 achieve this last goal, we must see if, when both current_class_ptr and
543 current_function_decl are set, the class was declared inside that
544 function. If so, we know to put the decls into the class's scope. */
545
546 tree
547 current_scope ()
548 {
549 if (current_function_decl == NULL_TREE)
550 return current_class_type;
551 if (current_class_type == NULL_TREE)
552 return current_function_decl;
553 if ((DECL_FUNCTION_MEMBER_P (current_function_decl)
554 && same_type_p (DECL_CONTEXT (current_function_decl),
555 current_class_type))
556 || (DECL_FRIEND_CONTEXT (current_function_decl)
557 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
558 current_class_type)))
559 return current_function_decl;
560
561 return current_class_type;
562 }
563
564 /* Returns nonzero if we are currently in a function scope. Note
565 that this function returns zero if we are within a local class, but
566 not within a member function body of the local class. */
567
568 int
569 at_function_scope_p ()
570 {
571 tree cs = current_scope ();
572 return cs && TREE_CODE (cs) == FUNCTION_DECL;
573 }
574
575 /* Returns true if the innermost active scope is a class scope. */
576
577 bool
578 at_class_scope_p ()
579 {
580 tree cs = current_scope ();
581 return cs && TYPE_P (cs);
582 }
583
584 /* Return the scope of DECL, as appropriate when doing name-lookup. */
585
586 tree
587 context_for_name_lookup (tree decl)
588 {
589 /* [class.union]
590
591 For the purposes of name lookup, after the anonymous union
592 definition, the members of the anonymous union are considered to
593 have been defined in the scope in which the anonymous union is
594 declared. */
595 tree context = DECL_CONTEXT (decl);
596
597 while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context))
598 context = TYPE_CONTEXT (context);
599 if (!context)
600 context = global_namespace;
601
602 return context;
603 }
604
605 /* Return a canonical BINFO if BINFO is a virtual base, or just BINFO
606 otherwise. */
607
608 static tree
609 canonical_binfo (tree binfo)
610 {
611 return (TREE_VIA_VIRTUAL (binfo)
612 ? TYPE_BINFO (BINFO_TYPE (binfo)) : binfo);
613 }
614
615 /* A queue function that simply ensures that we walk into the
616 canonical versions of virtual bases. */
617
618 static tree
619 dfs_canonical_queue (tree binfo, void *data ATTRIBUTE_UNUSED)
620 {
621 return canonical_binfo (binfo);
622 }
623
624 /* Called via dfs_walk from assert_canonical_unmarked. */
625
626 static tree
627 dfs_assert_unmarked_p (tree binfo, void *data ATTRIBUTE_UNUSED)
628 {
629 my_friendly_assert (!BINFO_MARKED (binfo), 0);
630 return NULL_TREE;
631 }
632
633 /* Asserts that all the nodes below BINFO (using the canonical
634 versions of virtual bases) are unmarked. */
635
636 static void
637 assert_canonical_unmarked (tree binfo)
638 {
639 dfs_walk (binfo, dfs_assert_unmarked_p, dfs_canonical_queue, 0);
640 }
641
642 /* If BINFO is marked, return a canonical version of BINFO.
643 Otherwise, return NULL_TREE. */
644
645 static tree
646 shared_marked_p (tree binfo, void *data)
647 {
648 binfo = canonical_binfo (binfo);
649 return markedp (binfo, data);
650 }
651
652 /* If BINFO is not marked, return a canonical version of BINFO.
653 Otherwise, return NULL_TREE. */
654
655 static tree
656 shared_unmarked_p (tree binfo, void *data)
657 {
658 binfo = canonical_binfo (binfo);
659 return unmarkedp (binfo, data);
660 }
661
662 /* The accessibility routines use BINFO_ACCESS for scratch space
663 during the computation of the accssibility of some declaration. */
664
665 #define BINFO_ACCESS(NODE) \
666 ((access_kind) ((TREE_LANG_FLAG_1 (NODE) << 1) | TREE_LANG_FLAG_6 (NODE)))
667
668 /* Set the access associated with NODE to ACCESS. */
669
670 #define SET_BINFO_ACCESS(NODE, ACCESS) \
671 ((TREE_LANG_FLAG_1 (NODE) = ((ACCESS) & 2) != 0), \
672 (TREE_LANG_FLAG_6 (NODE) = ((ACCESS) & 1) != 0))
673
674 /* Called from access_in_type via dfs_walk. Calculate the access to
675 DATA (which is really a DECL) in BINFO. */
676
677 static tree
678 dfs_access_in_type (tree binfo, void *data)
679 {
680 tree decl = (tree) data;
681 tree type = BINFO_TYPE (binfo);
682 access_kind access = ak_none;
683
684 if (context_for_name_lookup (decl) == type)
685 {
686 /* If we have desceneded to the scope of DECL, just note the
687 appropriate access. */
688 if (TREE_PRIVATE (decl))
689 access = ak_private;
690 else if (TREE_PROTECTED (decl))
691 access = ak_protected;
692 else
693 access = ak_public;
694 }
695 else
696 {
697 /* First, check for an access-declaration that gives us more
698 access to the DECL. The CONST_DECL for an enumeration
699 constant will not have DECL_LANG_SPECIFIC, and thus no
700 DECL_ACCESS. */
701 if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl))
702 {
703 tree decl_access = purpose_member (type, DECL_ACCESS (decl));
704 if (decl_access)
705 access = ((access_kind)
706 TREE_INT_CST_LOW (TREE_VALUE (decl_access)));
707 }
708
709 if (!access)
710 {
711 int i;
712 int n_baselinks;
713 tree binfos;
714
715 /* Otherwise, scan our baseclasses, and pick the most favorable
716 access. */
717 binfos = BINFO_BASETYPES (binfo);
718 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
719 for (i = 0; i < n_baselinks; ++i)
720 {
721 tree base_binfo = TREE_VEC_ELT (binfos, i);
722 access_kind base_access
723 = BINFO_ACCESS (canonical_binfo (base_binfo));
724
725 if (base_access == ak_none || base_access == ak_private)
726 /* If it was not accessible in the base, or only
727 accessible as a private member, we can't access it
728 all. */
729 base_access = ak_none;
730 else if (TREE_VIA_PROTECTED (base_binfo))
731 /* Public and protected members in the base are
732 protected here. */
733 base_access = ak_protected;
734 else if (!TREE_VIA_PUBLIC (base_binfo))
735 /* Public and protected members in the base are
736 private here. */
737 base_access = ak_private;
738
739 /* See if the new access, via this base, gives more
740 access than our previous best access. */
741 if (base_access != ak_none
742 && (base_access == ak_public
743 || (base_access == ak_protected
744 && access != ak_public)
745 || (base_access == ak_private
746 && access == ak_none)))
747 {
748 access = base_access;
749
750 /* If the new access is public, we can't do better. */
751 if (access == ak_public)
752 break;
753 }
754 }
755 }
756 }
757
758 /* Note the access to DECL in TYPE. */
759 SET_BINFO_ACCESS (binfo, access);
760
761 /* Mark TYPE as visited so that if we reach it again we do not
762 duplicate our efforts here. */
763 SET_BINFO_MARKED (binfo);
764
765 return NULL_TREE;
766 }
767
768 /* Return the access to DECL in TYPE. */
769
770 static access_kind
771 access_in_type (tree type, tree decl)
772 {
773 tree binfo = TYPE_BINFO (type);
774
775 /* We must take into account
776
777 [class.paths]
778
779 If a name can be reached by several paths through a multiple
780 inheritance graph, the access is that of the path that gives
781 most access.
782
783 The algorithm we use is to make a post-order depth-first traversal
784 of the base-class hierarchy. As we come up the tree, we annotate
785 each node with the most lenient access. */
786 dfs_walk_real (binfo, 0, dfs_access_in_type, shared_unmarked_p, decl);
787 dfs_walk (binfo, dfs_unmark, shared_marked_p, 0);
788 assert_canonical_unmarked (binfo);
789
790 return BINFO_ACCESS (binfo);
791 }
792
793 /* Called from dfs_accessible_p via dfs_walk. */
794
795 static tree
796 dfs_accessible_queue_p (tree binfo, void *data ATTRIBUTE_UNUSED)
797 {
798 if (BINFO_MARKED (binfo))
799 return NULL_TREE;
800
801 /* If this class is inherited via private or protected inheritance,
802 then we can't see it, unless we are a friend of the subclass. */
803 if (!TREE_VIA_PUBLIC (binfo)
804 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo)),
805 current_scope ()))
806 return NULL_TREE;
807
808 return canonical_binfo (binfo);
809 }
810
811 /* Called from dfs_accessible_p via dfs_walk. */
812
813 static tree
814 dfs_accessible_p (tree binfo, void *data)
815 {
816 int protected_ok = data != 0;
817 access_kind access;
818
819 SET_BINFO_MARKED (binfo);
820 access = BINFO_ACCESS (binfo);
821 if (access == ak_public || (access == ak_protected && protected_ok))
822 return binfo;
823 else if (access != ak_none
824 && is_friend (BINFO_TYPE (binfo), current_scope ()))
825 return binfo;
826
827 return NULL_TREE;
828 }
829
830 /* Returns nonzero if it is OK to access DECL through an object
831 indiated by BINFO in the context of DERIVED. */
832
833 static int
834 protected_accessible_p (tree decl, tree derived, tree binfo)
835 {
836 access_kind access;
837
838 /* We're checking this clause from [class.access.base]
839
840 m as a member of N is protected, and the reference occurs in a
841 member or friend of class N, or in a member or friend of a
842 class P derived from N, where m as a member of P is private or
843 protected.
844
845 Here DERIVED is a possible P and DECL is m. accessible_p will
846 iterate over various values of N, but the access to m in DERIVED
847 does not change.
848
849 Note that I believe that the passage above is wrong, and should read
850 "...is private or protected or public"; otherwise you get bizarre results
851 whereby a public using-decl can prevent you from accessing a protected
852 member of a base. (jason 2000/02/28) */
853
854 /* If DERIVED isn't derived from m's class, then it can't be a P. */
855 if (!DERIVED_FROM_P (context_for_name_lookup (decl), derived))
856 return 0;
857
858 access = access_in_type (derived, decl);
859
860 /* If m is inaccessible in DERIVED, then it's not a P. */
861 if (access == ak_none)
862 return 0;
863
864 /* [class.protected]
865
866 When a friend or a member function of a derived class references
867 a protected nonstatic member of a base class, an access check
868 applies in addition to those described earlier in clause
869 _class.access_) Except when forming a pointer to member
870 (_expr.unary.op_), the access must be through a pointer to,
871 reference to, or object of the derived class itself (or any class
872 derived from that class) (_expr.ref_). If the access is to form
873 a pointer to member, the nested-name-specifier shall name the
874 derived class (or any class derived from that class). */
875 if (DECL_NONSTATIC_MEMBER_P (decl))
876 {
877 /* We can tell through what the reference is occurring by
878 chasing BINFO up to the root. */
879 tree t = binfo;
880 while (BINFO_INHERITANCE_CHAIN (t))
881 t = BINFO_INHERITANCE_CHAIN (t);
882
883 if (!DERIVED_FROM_P (derived, BINFO_TYPE (t)))
884 return 0;
885 }
886
887 return 1;
888 }
889
890 /* Returns nonzero if SCOPE is a friend of a type which would be able
891 to access DECL through the object indicated by BINFO. */
892
893 static int
894 friend_accessible_p (tree scope, tree decl, tree binfo)
895 {
896 tree befriending_classes;
897 tree t;
898
899 if (!scope)
900 return 0;
901
902 if (TREE_CODE (scope) == FUNCTION_DECL
903 || DECL_FUNCTION_TEMPLATE_P (scope))
904 befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
905 else if (TYPE_P (scope))
906 befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
907 else
908 return 0;
909
910 for (t = befriending_classes; t; t = TREE_CHAIN (t))
911 if (protected_accessible_p (decl, TREE_VALUE (t), binfo))
912 return 1;
913
914 /* Nested classes are implicitly friends of their enclosing types, as
915 per core issue 45 (this is a change from the standard). */
916 if (TYPE_P (scope))
917 for (t = TYPE_CONTEXT (scope); t && TYPE_P (t); t = TYPE_CONTEXT (t))
918 if (protected_accessible_p (decl, t, binfo))
919 return 1;
920
921 if (TREE_CODE (scope) == FUNCTION_DECL
922 || DECL_FUNCTION_TEMPLATE_P (scope))
923 {
924 /* Perhaps this SCOPE is a member of a class which is a
925 friend. */
926 if (DECL_CLASS_SCOPE_P (decl)
927 && friend_accessible_p (DECL_CONTEXT (scope), decl, binfo))
928 return 1;
929
930 /* Or an instantiation of something which is a friend. */
931 if (DECL_TEMPLATE_INFO (scope))
932 return friend_accessible_p (DECL_TI_TEMPLATE (scope), decl, binfo);
933 }
934 else if (CLASSTYPE_TEMPLATE_INFO (scope))
935 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope), decl, binfo);
936
937 return 0;
938 }
939
940 /* DECL is a declaration from a base class of TYPE, which was the
941 class used to name DECL. Return nonzero if, in the current
942 context, DECL is accessible. If TYPE is actually a BINFO node,
943 then we can tell in what context the access is occurring by looking
944 at the most derived class along the path indicated by BINFO. */
945
946 int
947 accessible_p (tree type, tree decl)
948 {
949 tree binfo;
950 tree t;
951
952 /* Nonzero if it's OK to access DECL if it has protected
953 accessibility in TYPE. */
954 int protected_ok = 0;
955
956 /* If we're not checking access, everything is accessible. */
957 if (!scope_chain->check_access)
958 return 1;
959
960 /* If this declaration is in a block or namespace scope, there's no
961 access control. */
962 if (!TYPE_P (context_for_name_lookup (decl)))
963 return 1;
964
965 if (!TYPE_P (type))
966 {
967 binfo = type;
968 type = BINFO_TYPE (type);
969 }
970 else
971 binfo = TYPE_BINFO (type);
972
973 /* [class.access.base]
974
975 A member m is accessible when named in class N if
976
977 --m as a member of N is public, or
978
979 --m as a member of N is private, and the reference occurs in a
980 member or friend of class N, or
981
982 --m as a member of N is protected, and the reference occurs in a
983 member or friend of class N, or in a member or friend of a
984 class P derived from N, where m as a member of P is private or
985 protected, or
986
987 --there exists a base class B of N that is accessible at the point
988 of reference, and m is accessible when named in class B.
989
990 We walk the base class hierarchy, checking these conditions. */
991
992 /* Figure out where the reference is occurring. Check to see if
993 DECL is private or protected in this scope, since that will
994 determine whether protected access is allowed. */
995 if (current_class_type)
996 protected_ok = protected_accessible_p (decl, current_class_type, binfo);
997
998 /* Now, loop through the classes of which we are a friend. */
999 if (!protected_ok)
1000 protected_ok = friend_accessible_p (current_scope (), decl, binfo);
1001
1002 /* Standardize the binfo that access_in_type will use. We don't
1003 need to know what path was chosen from this point onwards. */
1004 binfo = TYPE_BINFO (type);
1005
1006 /* Compute the accessibility of DECL in the class hierarchy
1007 dominated by type. */
1008 access_in_type (type, decl);
1009 /* Walk the hierarchy again, looking for a base class that allows
1010 access. */
1011 t = dfs_walk (binfo, dfs_accessible_p,
1012 dfs_accessible_queue_p,
1013 protected_ok ? &protected_ok : 0);
1014 /* Clear any mark bits. Note that we have to walk the whole tree
1015 here, since we have aborted the previous walk from some point
1016 deep in the tree. */
1017 dfs_walk (binfo, dfs_unmark, dfs_canonical_queue, 0);
1018 assert_canonical_unmarked (binfo);
1019
1020 return t != NULL_TREE;
1021 }
1022
1023 /* Recursive helper funciton for is_subobject_of_p; see that routine
1024 for documentation of the parameters. */
1025
1026 static int
1027 is_subobject_of_p_1 (tree parent, tree binfo, tree most_derived)
1028 {
1029 tree binfos;
1030 int i, n_baselinks;
1031
1032 if (parent == binfo)
1033 return 1;
1034
1035 binfos = BINFO_BASETYPES (binfo);
1036 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1037
1038 /* Iterate through the base types. */
1039 for (i = 0; i < n_baselinks; i++)
1040 {
1041 tree base_binfo = TREE_VEC_ELT (binfos, i);
1042 tree base_type;
1043
1044 base_type = TREE_TYPE (base_binfo);
1045 if (!CLASS_TYPE_P (base_type))
1046 /* If we see a TEMPLATE_TYPE_PARM, or some such, as a base
1047 class there's no way to descend into it. */
1048 continue;
1049
1050 /* Avoid walking into the same virtual base more than once. */
1051 if (TREE_VIA_VIRTUAL (base_binfo))
1052 {
1053 if (CLASSTYPE_MARKED4 (base_type))
1054 continue;
1055 SET_CLASSTYPE_MARKED4 (base_type);
1056 base_binfo = binfo_for_vbase (base_type, most_derived);
1057 }
1058
1059 if (is_subobject_of_p_1 (parent, base_binfo, most_derived))
1060 return 1;
1061 }
1062 return 0;
1063 }
1064
1065 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1066 found as a base class and sub-object of the object denoted by
1067 BINFO. MOST_DERIVED is the most derived type of the hierarchy being
1068 searched. */
1069
1070 static int
1071 is_subobject_of_p (tree parent, tree binfo, tree most_derived)
1072 {
1073 int result;
1074 tree vbase;
1075
1076 result = is_subobject_of_p_1 (parent, binfo, most_derived);
1077 /* Clear the mark bits on virtual bases. */
1078 for (vbase = CLASSTYPE_VBASECLASSES (most_derived);
1079 vbase;
1080 vbase = TREE_CHAIN (vbase))
1081 CLEAR_CLASSTYPE_MARKED4 (TREE_TYPE (TREE_VALUE (vbase)));
1082
1083 return result;
1084 }
1085
1086 struct lookup_field_info {
1087 /* The type in which we're looking. */
1088 tree type;
1089 /* The name of the field for which we're looking. */
1090 tree name;
1091 /* If non-NULL, the current result of the lookup. */
1092 tree rval;
1093 /* The path to RVAL. */
1094 tree rval_binfo;
1095 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1096 candidates. */
1097 tree ambiguous;
1098 /* If nonzero, we are looking for types, not data members. */
1099 int want_type;
1100 /* If nonzero, RVAL was found by looking through a dependent base. */
1101 int from_dep_base_p;
1102 /* If something went wrong, a message indicating what. */
1103 const char *errstr;
1104 };
1105
1106 /* Returns nonzero if BINFO is not hidden by the value found by the
1107 lookup so far. If BINFO is hidden, then there's no need to look in
1108 it. DATA is really a struct lookup_field_info. Called from
1109 lookup_field via breadth_first_search. */
1110
1111 static tree
1112 lookup_field_queue_p (tree binfo, void *data)
1113 {
1114 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1115
1116 /* Don't look for constructors or destructors in base classes. */
1117 if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
1118 return NULL_TREE;
1119
1120 /* If this base class is hidden by the best-known value so far, we
1121 don't need to look. */
1122 binfo = CANONICAL_BINFO (binfo, lfi->type);
1123 if (!lfi->from_dep_base_p && lfi->rval_binfo
1124 && is_subobject_of_p (binfo, lfi->rval_binfo, lfi->type))
1125 return NULL_TREE;
1126
1127 return binfo;
1128 }
1129
1130 /* Within the scope of a template class, you can refer to the to the
1131 current specialization with the name of the template itself. For
1132 example:
1133
1134 template <typename T> struct S { S* sp; }
1135
1136 Returns nonzero if DECL is such a declaration in a class TYPE. */
1137
1138 static int
1139 template_self_reference_p (tree type, tree decl)
1140 {
1141 return (CLASSTYPE_USE_TEMPLATE (type)
1142 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))
1143 && TREE_CODE (decl) == TYPE_DECL
1144 && DECL_ARTIFICIAL (decl)
1145 && DECL_NAME (decl) == constructor_name (type));
1146 }
1147
1148
1149 /* Nonzero for a class member means that it is shared between all objects
1150 of that class.
1151
1152 [class.member.lookup]:If the resulting set of declarations are not all
1153 from sub-objects of the same type, or the set has a nonstatic member
1154 and includes members from distinct sub-objects, there is an ambiguity
1155 and the program is ill-formed.
1156
1157 This function checks that T contains no nonstatic members. */
1158
1159 static int
1160 shared_member_p (tree t)
1161 {
1162 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == TYPE_DECL \
1163 || TREE_CODE (t) == CONST_DECL)
1164 return 1;
1165 if (is_overloaded_fn (t))
1166 {
1167 for (; t; t = OVL_NEXT (t))
1168 {
1169 tree fn = OVL_CURRENT (t);
1170 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1171 return 0;
1172 }
1173 return 1;
1174 }
1175 return 0;
1176 }
1177
1178 /* DATA is really a struct lookup_field_info. Look for a field with
1179 the name indicated there in BINFO. If this function returns a
1180 non-NULL value it is the result of the lookup. Called from
1181 lookup_field via breadth_first_search. */
1182
1183 static tree
1184 lookup_field_r (tree binfo, void *data)
1185 {
1186 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1187 tree type = BINFO_TYPE (binfo);
1188 tree nval = NULL_TREE;
1189 int from_dep_base_p;
1190
1191 /* First, look for a function. There can't be a function and a data
1192 member with the same name, and if there's a function and a type
1193 with the same name, the type is hidden by the function. */
1194 if (!lfi->want_type)
1195 {
1196 int idx = lookup_fnfields_1 (type, lfi->name);
1197 if (idx >= 0)
1198 nval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1199 }
1200
1201 if (!nval)
1202 /* Look for a data member or type. */
1203 nval = lookup_field_1 (type, lfi->name);
1204
1205 /* If there is no declaration with the indicated name in this type,
1206 then there's nothing to do. */
1207 if (!nval)
1208 return NULL_TREE;
1209
1210 /* If we're looking up a type (as with an elaborated type specifier)
1211 we ignore all non-types we find. */
1212 if (lfi->want_type && TREE_CODE (nval) != TYPE_DECL
1213 && !DECL_CLASS_TEMPLATE_P (nval))
1214 {
1215 if (lfi->name == TYPE_IDENTIFIER (type))
1216 {
1217 /* If the aggregate has no user defined constructors, we allow
1218 it to have fields with the same name as the enclosing type.
1219 If we are looking for that name, find the corresponding
1220 TYPE_DECL. */
1221 for (nval = TREE_CHAIN (nval); nval; nval = TREE_CHAIN (nval))
1222 if (DECL_NAME (nval) == lfi->name
1223 && TREE_CODE (nval) == TYPE_DECL)
1224 break;
1225 }
1226 else
1227 nval = NULL_TREE;
1228 if (!nval)
1229 {
1230 nval = purpose_member (lfi->name, CLASSTYPE_TAGS (type));
1231 if (nval)
1232 nval = TYPE_MAIN_DECL (TREE_VALUE (nval));
1233 else
1234 return NULL_TREE;
1235 }
1236 }
1237
1238 /* You must name a template base class with a template-id. */
1239 if (!same_type_p (type, lfi->type)
1240 && template_self_reference_p (type, nval))
1241 return NULL_TREE;
1242
1243 from_dep_base_p = dependent_base_p (binfo);
1244 if (lfi->from_dep_base_p && !from_dep_base_p)
1245 {
1246 /* If the new declaration is not found via a dependent base, and
1247 the old one was, then we must prefer the new one. We weren't
1248 really supposed to be able to find the old one, so we don't
1249 want to be affected by a specialization. Consider:
1250
1251 struct B { typedef int I; };
1252 template <typename T> struct D1 : virtual public B {};
1253 template <typename T> struct D :
1254 public D1, virtual pubic B { I i; };
1255
1256 The `I' in `D<T>' is unambigousuly `B::I', regardless of how
1257 D1 is specialized. */
1258 lfi->from_dep_base_p = 0;
1259 lfi->rval = NULL_TREE;
1260 lfi->rval_binfo = NULL_TREE;
1261 lfi->ambiguous = NULL_TREE;
1262 lfi->errstr = 0;
1263 }
1264 else if (lfi->rval_binfo && !lfi->from_dep_base_p && from_dep_base_p)
1265 /* Similarly, if the old declaration was not found via a dependent
1266 base, and the new one is, ignore the new one. */
1267 return NULL_TREE;
1268
1269 /* If the lookup already found a match, and the new value doesn't
1270 hide the old one, we might have an ambiguity. */
1271 if (lfi->rval_binfo && !is_subobject_of_p (lfi->rval_binfo, binfo, lfi->type))
1272 {
1273 if (nval == lfi->rval && shared_member_p (nval))
1274 /* The two things are really the same. */
1275 ;
1276 else if (is_subobject_of_p (binfo, lfi->rval_binfo, lfi->type))
1277 /* The previous value hides the new one. */
1278 ;
1279 else
1280 {
1281 /* We have a real ambiguity. We keep a chain of all the
1282 candidates. */
1283 if (!lfi->ambiguous && lfi->rval)
1284 {
1285 /* This is the first time we noticed an ambiguity. Add
1286 what we previously thought was a reasonable candidate
1287 to the list. */
1288 lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
1289 TREE_TYPE (lfi->ambiguous) = error_mark_node;
1290 }
1291
1292 /* Add the new value. */
1293 lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
1294 TREE_TYPE (lfi->ambiguous) = error_mark_node;
1295 lfi->errstr = "request for member `%D' is ambiguous";
1296 }
1297 }
1298 else
1299 {
1300 if (from_dep_base_p && TREE_CODE (nval) == TYPE_DECL
1301 /* We need to return a member template class so we can
1302 define partial specializations. Is there a better
1303 way? */
1304 && !DECL_CLASS_TEMPLATE_P (nval))
1305 /* The thing we're looking for isn't a type, so the implicit
1306 typename extension doesn't apply, so we just pretend we
1307 didn't find anything. */
1308 return NULL_TREE;
1309
1310 lfi->rval = nval;
1311 lfi->from_dep_base_p = from_dep_base_p;
1312 lfi->rval_binfo = binfo;
1313 }
1314
1315 return NULL_TREE;
1316 }
1317
1318 /* Return a "baselink" which BASELINK_BINFO, BASELINK_ACCESS_BINFO,
1319 BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
1320 FUNCTIONS, and OPTYPE respectively. */
1321
1322 tree
1323 build_baselink (tree binfo, tree access_binfo, tree functions, tree optype)
1324 {
1325 tree baselink;
1326
1327 my_friendly_assert (TREE_CODE (functions) == FUNCTION_DECL
1328 || TREE_CODE (functions) == TEMPLATE_DECL
1329 || TREE_CODE (functions) == TEMPLATE_ID_EXPR
1330 || TREE_CODE (functions) == OVERLOAD,
1331 20020730);
1332 my_friendly_assert (!optype || TYPE_P (optype), 20020730);
1333 my_friendly_assert (TREE_TYPE (functions), 20020805);
1334
1335 baselink = make_node (BASELINK);
1336 TREE_TYPE (baselink) = TREE_TYPE (functions);
1337 BASELINK_BINFO (baselink) = binfo;
1338 BASELINK_ACCESS_BINFO (baselink) = access_binfo;
1339 BASELINK_FUNCTIONS (baselink) = functions;
1340 BASELINK_OPTYPE (baselink) = optype;
1341
1342 return baselink;
1343 }
1344
1345 /* Look for a member named NAME in an inheritance lattice dominated by
1346 XBASETYPE. If PROTECT is 0 or two, we do not check access. If it
1347 is 1, we enforce accessibility. If PROTECT is zero, then, for an
1348 ambiguous lookup, we return NULL. If PROTECT is 1, we issue error
1349 messages about inaccessible or ambiguous lookup. If PROTECT is 2,
1350 we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
1351 TREE_VALUEs are the list of ambiguous candidates.
1352
1353 WANT_TYPE is 1 when we should only return TYPE_DECLs.
1354
1355 If nothing can be found return NULL_TREE and do not issue an error. */
1356
1357 tree
1358 lookup_member (tree xbasetype, tree name, int protect, bool want_type)
1359 {
1360 tree rval, rval_binfo = NULL_TREE;
1361 tree type = NULL_TREE, basetype_path = NULL_TREE;
1362 struct lookup_field_info lfi;
1363
1364 /* rval_binfo is the binfo associated with the found member, note,
1365 this can be set with useful information, even when rval is not
1366 set, because it must deal with ALL members, not just non-function
1367 members. It is used for ambiguity checking and the hidden
1368 checks. Whereas rval is only set if a proper (not hidden)
1369 non-function member is found. */
1370
1371 const char *errstr = 0;
1372
1373 if (xbasetype == current_class_type && TYPE_BEING_DEFINED (xbasetype)
1374 && IDENTIFIER_CLASS_VALUE (name))
1375 {
1376 tree field = IDENTIFIER_CLASS_VALUE (name);
1377 if (TREE_CODE (field) != FUNCTION_DECL
1378 && ! (want_type && TREE_CODE (field) != TYPE_DECL))
1379 /* We're in the scope of this class, and the value has already
1380 been looked up. Just return the cached value. */
1381 return field;
1382 }
1383
1384 if (TREE_CODE (xbasetype) == TREE_VEC)
1385 {
1386 type = BINFO_TYPE (xbasetype);
1387 basetype_path = xbasetype;
1388 }
1389 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)))
1390 {
1391 type = xbasetype;
1392 basetype_path = TYPE_BINFO (type);
1393 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path) == NULL_TREE,
1394 980827);
1395 }
1396 else
1397 abort ();
1398
1399 complete_type (type);
1400
1401 #ifdef GATHER_STATISTICS
1402 n_calls_lookup_field++;
1403 #endif /* GATHER_STATISTICS */
1404
1405 memset ((PTR) &lfi, 0, sizeof (lfi));
1406 lfi.type = type;
1407 lfi.name = name;
1408 lfi.want_type = want_type;
1409 bfs_walk (basetype_path, &lookup_field_r, &lookup_field_queue_p, &lfi);
1410 rval = lfi.rval;
1411 rval_binfo = lfi.rval_binfo;
1412 if (rval_binfo)
1413 type = BINFO_TYPE (rval_binfo);
1414 errstr = lfi.errstr;
1415
1416 /* If we are not interested in ambiguities, don't report them;
1417 just return NULL_TREE. */
1418 if (!protect && lfi.ambiguous)
1419 return NULL_TREE;
1420
1421 if (protect == 2)
1422 {
1423 if (lfi.ambiguous)
1424 return lfi.ambiguous;
1425 else
1426 protect = 0;
1427 }
1428
1429 /* [class.access]
1430
1431 In the case of overloaded function names, access control is
1432 applied to the function selected by overloaded resolution. */
1433 if (rval && protect && !is_overloaded_fn (rval)
1434 && !enforce_access (xbasetype, rval))
1435 return error_mark_node;
1436
1437 if (errstr && protect)
1438 {
1439 error (errstr, name, type);
1440 if (lfi.ambiguous)
1441 print_candidates (lfi.ambiguous);
1442 rval = error_mark_node;
1443 }
1444
1445 /* If the thing we found was found via the implicit typename
1446 extension, build the typename type. */
1447 if (rval && lfi.from_dep_base_p && !DECL_CLASS_TEMPLATE_P (rval))
1448 abort ();
1449
1450 if (rval && is_overloaded_fn (rval))
1451 rval = build_baselink (rval_binfo, basetype_path, rval,
1452 (IDENTIFIER_TYPENAME_P (name)
1453 ? TREE_TYPE (name): NULL_TREE));
1454 return rval;
1455 }
1456
1457 /* Like lookup_member, except that if we find a function member we
1458 return NULL_TREE. */
1459
1460 tree
1461 lookup_field (tree xbasetype, tree name, int protect, bool want_type)
1462 {
1463 tree rval = lookup_member (xbasetype, name, protect, want_type);
1464
1465 /* Ignore functions. */
1466 if (rval && BASELINK_P (rval))
1467 return NULL_TREE;
1468
1469 return rval;
1470 }
1471
1472 /* Like lookup_member, except that if we find a non-function member we
1473 return NULL_TREE. */
1474
1475 tree
1476 lookup_fnfields (tree xbasetype, tree name, int protect)
1477 {
1478 tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/false);
1479
1480 /* Ignore non-functions. */
1481 if (rval && !BASELINK_P (rval))
1482 return NULL_TREE;
1483
1484 return rval;
1485 }
1486
1487 /* TYPE is a class type. Return the index of the fields within
1488 the method vector with name NAME, or -1 is no such field exists. */
1489
1490 int
1491 lookup_fnfields_1 (tree type, tree name)
1492 {
1493 tree method_vec = (CLASS_TYPE_P (type)
1494 ? CLASSTYPE_METHOD_VEC (type)
1495 : NULL_TREE);
1496
1497 if (method_vec != 0)
1498 {
1499 register int i;
1500 register tree *methods = &TREE_VEC_ELT (method_vec, 0);
1501 int len = TREE_VEC_LENGTH (method_vec);
1502 tree tmp;
1503
1504 #ifdef GATHER_STATISTICS
1505 n_calls_lookup_fnfields_1++;
1506 #endif /* GATHER_STATISTICS */
1507
1508 /* Constructors are first... */
1509 if (name == ctor_identifier)
1510 return (methods[CLASSTYPE_CONSTRUCTOR_SLOT]
1511 ? CLASSTYPE_CONSTRUCTOR_SLOT : -1);
1512 /* and destructors are second. */
1513 if (name == dtor_identifier)
1514 return (methods[CLASSTYPE_DESTRUCTOR_SLOT]
1515 ? CLASSTYPE_DESTRUCTOR_SLOT : -1);
1516
1517 for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
1518 i < len && methods[i];
1519 ++i)
1520 {
1521 #ifdef GATHER_STATISTICS
1522 n_outer_fields_searched++;
1523 #endif /* GATHER_STATISTICS */
1524
1525 tmp = OVL_CURRENT (methods[i]);
1526 if (DECL_NAME (tmp) == name)
1527 return i;
1528
1529 /* If the type is complete and we're past the conversion ops,
1530 switch to binary search. */
1531 if (! DECL_CONV_FN_P (tmp)
1532 && COMPLETE_TYPE_P (type))
1533 {
1534 int lo = i + 1, hi = len;
1535
1536 while (lo < hi)
1537 {
1538 i = (lo + hi) / 2;
1539
1540 #ifdef GATHER_STATISTICS
1541 n_outer_fields_searched++;
1542 #endif /* GATHER_STATISTICS */
1543
1544 tmp = DECL_NAME (OVL_CURRENT (methods[i]));
1545
1546 if (tmp > name)
1547 hi = i;
1548 else if (tmp < name)
1549 lo = i + 1;
1550 else
1551 return i;
1552 }
1553 break;
1554 }
1555 }
1556
1557 /* If we didn't find it, it might have been a template
1558 conversion operator to a templated type. If there are any,
1559 such template conversion operators will all be overloaded on
1560 the first conversion slot. (Note that we don't look for this
1561 case above so that we will always find specializations
1562 first.) */
1563 if (IDENTIFIER_TYPENAME_P (name))
1564 {
1565 i = CLASSTYPE_FIRST_CONVERSION_SLOT;
1566 if (i < len && methods[i])
1567 {
1568 tmp = OVL_CURRENT (methods[i]);
1569 if (TREE_CODE (tmp) == TEMPLATE_DECL
1570 && DECL_TEMPLATE_CONV_FN_P (tmp))
1571 return i;
1572 }
1573 }
1574 }
1575
1576 return -1;
1577 }
1578
1579 /* DECL is the result of a qualified name lookup. QUALIFYING_SCOPE is
1580 the class or namespace used to qualify the name. CONTEXT_CLASS is
1581 the class corresponding to the object in which DECL will be used.
1582 Return a possibly modified version of DECL that takes into account
1583 the CONTEXT_CLASS.
1584
1585 In particular, consider an expression like `B::m' in the context of
1586 a derived class `D'. If `B::m' has been resolved to a BASELINK,
1587 then the most derived class indicated by the BASELINK_BINFO will be
1588 `B', not `D'. This function makes that adjustment. */
1589
1590 tree
1591 adjust_result_of_qualified_name_lookup (tree decl,
1592 tree qualifying_scope,
1593 tree context_class)
1594 {
1595 if (context_class && CLASS_TYPE_P (qualifying_scope)
1596 && DERIVED_FROM_P (qualifying_scope, context_class)
1597 && BASELINK_P (decl))
1598 {
1599 tree base;
1600
1601 my_friendly_assert (CLASS_TYPE_P (context_class), 20020808);
1602
1603 /* Look for the QUALIFYING_SCOPE as a base of the
1604 CONTEXT_CLASS. If QUALIFYING_SCOPE is ambiguous, we cannot
1605 be sure yet than an error has occurred; perhaps the function
1606 chosen by overload resolution will be static. */
1607 base = lookup_base (context_class, qualifying_scope,
1608 ba_ignore | ba_quiet, NULL);
1609 if (base)
1610 {
1611 BASELINK_ACCESS_BINFO (decl) = base;
1612 BASELINK_BINFO (decl)
1613 = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
1614 ba_ignore | ba_quiet,
1615 NULL);
1616 }
1617 }
1618
1619 return decl;
1620 }
1621
1622 \f
1623 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1624 type in the hierarchy, in a breadth-first preorder traversal.
1625 If it ever returns a non-NULL value, that value is immediately
1626 returned and the walk is terminated. At each node, FN is passed a
1627 BINFO indicating the path from the curently visited base-class to
1628 TYPE. Before each base-class is walked QFN is called. If the
1629 value returned is nonzero, the base-class is walked; otherwise it
1630 is not. If QFN is NULL, it is treated as a function which always
1631 returns 1. Both FN and QFN are passed the DATA whenever they are
1632 called. */
1633
1634 static tree
1635 bfs_walk (tree binfo, tree (*fn) (tree, void *),
1636 tree (*qfn) (tree, void *), void *data)
1637 {
1638 size_t head;
1639 size_t tail;
1640 tree rval = NULL_TREE;
1641 /* An array of the base classes of BINFO. These will be built up in
1642 breadth-first order, except where QFN prunes the search. */
1643 varray_type bfs_bases;
1644
1645 /* Start with enough room for ten base classes. That will be enough
1646 for most hierarchies. */
1647 VARRAY_TREE_INIT (bfs_bases, 10, "search_stack");
1648
1649 /* Put the first type into the stack. */
1650 VARRAY_TREE (bfs_bases, 0) = binfo;
1651 tail = 1;
1652
1653 for (head = 0; head < tail; ++head)
1654 {
1655 int i;
1656 int n_baselinks;
1657 tree binfos;
1658
1659 /* Pull the next type out of the queue. */
1660 binfo = VARRAY_TREE (bfs_bases, head);
1661
1662 /* If this is the one we're looking for, we're done. */
1663 rval = (*fn) (binfo, data);
1664 if (rval)
1665 break;
1666
1667 /* Queue up the base types. */
1668 binfos = BINFO_BASETYPES (binfo);
1669 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos): 0;
1670 for (i = 0; i < n_baselinks; i++)
1671 {
1672 tree base_binfo = TREE_VEC_ELT (binfos, i);
1673
1674 if (qfn)
1675 base_binfo = (*qfn) (base_binfo, data);
1676
1677 if (base_binfo)
1678 {
1679 if (tail == VARRAY_SIZE (bfs_bases))
1680 VARRAY_GROW (bfs_bases, 2 * VARRAY_SIZE (bfs_bases));
1681 VARRAY_TREE (bfs_bases, tail) = base_binfo;
1682 ++tail;
1683 }
1684 }
1685 }
1686
1687 return rval;
1688 }
1689
1690 /* Exactly like bfs_walk, except that a depth-first traversal is
1691 performed, and PREFN is called in preorder, while POSTFN is called
1692 in postorder. */
1693
1694 tree
1695 dfs_walk_real (tree binfo,
1696 tree (*prefn) (tree, void *), tree (*postfn) (tree, void *),
1697 tree (*qfn) (tree, void *), void *data)
1698 {
1699 int i;
1700 int n_baselinks;
1701 tree binfos;
1702 tree rval = NULL_TREE;
1703
1704 /* Call the pre-order walking function. */
1705 if (prefn)
1706 {
1707 rval = (*prefn) (binfo, data);
1708 if (rval)
1709 return rval;
1710 }
1711
1712 /* Process the basetypes. */
1713 binfos = BINFO_BASETYPES (binfo);
1714 n_baselinks = BINFO_N_BASETYPES (binfo);
1715 for (i = 0; i < n_baselinks; i++)
1716 {
1717 tree base_binfo = TREE_VEC_ELT (binfos, i);
1718
1719 if (qfn)
1720 base_binfo = (*qfn) (base_binfo, data);
1721
1722 if (base_binfo)
1723 {
1724 rval = dfs_walk_real (base_binfo, prefn, postfn, qfn, data);
1725 if (rval)
1726 return rval;
1727 }
1728 }
1729
1730 /* Call the post-order walking function. */
1731 if (postfn)
1732 rval = (*postfn) (binfo, data);
1733
1734 return rval;
1735 }
1736
1737 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1738 performed. */
1739
1740 tree
1741 dfs_walk (tree binfo, tree (*fn) (tree, void *),
1742 tree (*qfn) (tree, void *), void *data)
1743 {
1744 return dfs_walk_real (binfo, 0, fn, qfn, data);
1745 }
1746
1747 /* Check that virtual overrider OVERRIDER is acceptable for base function
1748 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1749
1750 int
1751 check_final_overrider (tree overrider, tree basefn)
1752 {
1753 tree over_type = TREE_TYPE (overrider);
1754 tree base_type = TREE_TYPE (basefn);
1755 tree over_return = TREE_TYPE (over_type);
1756 tree base_return = TREE_TYPE (base_type);
1757 tree over_throw = TYPE_RAISES_EXCEPTIONS (over_type);
1758 tree base_throw = TYPE_RAISES_EXCEPTIONS (base_type);
1759 int fail = 0;
1760
1761 if (same_type_p (base_return, over_return))
1762 /* OK */;
1763 else if ((CLASS_TYPE_P (over_return) && CLASS_TYPE_P (base_return))
1764 || (TREE_CODE (base_return) == TREE_CODE (over_return)
1765 && POINTER_TYPE_P (base_return)))
1766 {
1767 /* Potentially covariant. */
1768 unsigned base_quals, over_quals;
1769
1770 fail = !POINTER_TYPE_P (base_return);
1771 if (!fail)
1772 {
1773 fail = cp_type_quals (base_return) != cp_type_quals (over_return);
1774
1775 base_return = TREE_TYPE (base_return);
1776 over_return = TREE_TYPE (over_return);
1777 }
1778 base_quals = cp_type_quals (base_return);
1779 over_quals = cp_type_quals (over_return);
1780
1781 if ((base_quals & over_quals) != over_quals)
1782 fail = 1;
1783
1784 if (CLASS_TYPE_P (base_return) && CLASS_TYPE_P (over_return))
1785 {
1786 tree binfo = lookup_base (over_return, base_return,
1787 ba_check | ba_quiet, NULL);
1788
1789 if (!binfo)
1790 fail = 1;
1791 }
1792 else if (!pedantic
1793 && can_convert (TREE_TYPE (base_type), TREE_TYPE (over_type)))
1794 /* GNU extension, allow trivial pointer conversions such as
1795 converting to void *, or qualification conversion. */
1796 {
1797 /* can_convert will permit user defined conversion from a
1798 (reference to) class type. We must reject them. */
1799 over_return = TREE_TYPE (over_type);
1800 if (TREE_CODE (over_return) == REFERENCE_TYPE)
1801 over_return = TREE_TYPE (over_return);
1802 if (CLASS_TYPE_P (over_return))
1803 fail = 2;
1804 }
1805 else
1806 fail = 2;
1807 }
1808 else
1809 fail = 2;
1810 if (!fail)
1811 /* OK */;
1812 else if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider)))
1813 return 0;
1814 else
1815 {
1816 if (fail == 1)
1817 {
1818 cp_error_at ("invalid covariant return type for `%#D'", overrider);
1819 cp_error_at (" overriding `%#D'", basefn);
1820 }
1821 else
1822 {
1823 cp_error_at ("conflicting return type specified for `%#D'",
1824 overrider);
1825 cp_error_at (" overriding `%#D'", basefn);
1826 }
1827 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider),
1828 DECL_CONTEXT (overrider));
1829 return 0;
1830 }
1831
1832 /* Check throw specifier is at least as strict. */
1833 if (!comp_except_specs (base_throw, over_throw, 0))
1834 {
1835 if (!IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider)))
1836 {
1837 cp_error_at ("looser throw specifier for `%#F'", overrider);
1838 cp_error_at (" overriding `%#F'", basefn);
1839 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider),
1840 DECL_CONTEXT (overrider));
1841 }
1842 return 0;
1843 }
1844
1845 return 1;
1846 }
1847
1848 /* Given a class TYPE, and a function decl FNDECL, look for
1849 virtual functions in TYPE's hierarchy which FNDECL overrides.
1850 We do not look in TYPE itself, only its bases.
1851
1852 Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
1853 find that it overrides anything.
1854
1855 We check that every function which is overridden, is correctly
1856 overridden. */
1857
1858 int
1859 look_for_overrides (tree type, tree fndecl)
1860 {
1861 tree binfo = TYPE_BINFO (type);
1862 tree basebinfos = BINFO_BASETYPES (binfo);
1863 int nbasebinfos = basebinfos ? TREE_VEC_LENGTH (basebinfos) : 0;
1864 int ix;
1865 int found = 0;
1866
1867 for (ix = 0; ix != nbasebinfos; ix++)
1868 {
1869 tree basetype = BINFO_TYPE (TREE_VEC_ELT (basebinfos, ix));
1870
1871 if (TYPE_POLYMORPHIC_P (basetype))
1872 found += look_for_overrides_r (basetype, fndecl);
1873 }
1874 return found;
1875 }
1876
1877 /* Look in TYPE for virtual functions with the same signature as
1878 FNDECL. */
1879
1880 tree
1881 look_for_overrides_here (tree type, tree fndecl)
1882 {
1883 int ix;
1884
1885 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fndecl))
1886 ix = CLASSTYPE_DESTRUCTOR_SLOT;
1887 else
1888 ix = lookup_fnfields_1 (type, DECL_NAME (fndecl));
1889 if (ix >= 0)
1890 {
1891 tree fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), ix);
1892
1893 for (; fns; fns = OVL_NEXT (fns))
1894 {
1895 tree fn = OVL_CURRENT (fns);
1896
1897 if (!DECL_VIRTUAL_P (fn))
1898 /* Not a virtual. */;
1899 else if (DECL_CONTEXT (fn) != type)
1900 /* Introduced with a using declaration. */;
1901 else if (DECL_STATIC_FUNCTION_P (fndecl))
1902 {
1903 tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
1904 tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1905 if (compparms (TREE_CHAIN (btypes), dtypes))
1906 return fn;
1907 }
1908 else if (same_signature_p (fndecl, fn))
1909 return fn;
1910 }
1911 }
1912 return NULL_TREE;
1913 }
1914
1915 /* Look in TYPE for virtual functions overridden by FNDECL. Check both
1916 TYPE itself and its bases. */
1917
1918 static int
1919 look_for_overrides_r (tree type, tree fndecl)
1920 {
1921 tree fn = look_for_overrides_here (type, fndecl);
1922 if (fn)
1923 {
1924 if (DECL_STATIC_FUNCTION_P (fndecl))
1925 {
1926 /* A static member function cannot match an inherited
1927 virtual member function. */
1928 cp_error_at ("`%#D' cannot be declared", fndecl);
1929 cp_error_at (" since `%#D' declared in base class", fn);
1930 }
1931 else
1932 {
1933 /* It's definitely virtual, even if not explicitly set. */
1934 DECL_VIRTUAL_P (fndecl) = 1;
1935 check_final_overrider (fndecl, fn);
1936 }
1937 return 1;
1938 }
1939
1940 /* We failed to find one declared in this class. Look in its bases. */
1941 return look_for_overrides (type, fndecl);
1942 }
1943
1944 /* A queue function to use with dfs_walk that only walks into
1945 canonical bases. DATA should be the type of the complete object,
1946 or a TREE_LIST whose TREE_PURPOSE is the type of the complete
1947 object. By using this function as a queue function, you will walk
1948 over exactly those BINFOs that actually exist in the complete
1949 object, including those for virtual base classes. If you
1950 SET_BINFO_MARKED for each binfo you process, you are further
1951 guaranteed that you will walk into each virtual base class exactly
1952 once. */
1953
1954 tree
1955 dfs_unmarked_real_bases_queue_p (tree binfo, void *data)
1956 {
1957 if (TREE_VIA_VIRTUAL (binfo))
1958 {
1959 tree type = (tree) data;
1960
1961 if (TREE_CODE (type) == TREE_LIST)
1962 type = TREE_PURPOSE (type);
1963 binfo = binfo_for_vbase (BINFO_TYPE (binfo), type);
1964 }
1965 return unmarkedp (binfo, NULL);
1966 }
1967
1968 /* Like dfs_unmarked_real_bases_queue_p but walks only into things
1969 that are marked, rather than unmarked. */
1970
1971 tree
1972 dfs_marked_real_bases_queue_p (tree binfo, void *data)
1973 {
1974 if (TREE_VIA_VIRTUAL (binfo))
1975 {
1976 tree type = (tree) data;
1977
1978 if (TREE_CODE (type) == TREE_LIST)
1979 type = TREE_PURPOSE (type);
1980 binfo = binfo_for_vbase (BINFO_TYPE (binfo), type);
1981 }
1982 return markedp (binfo, NULL);
1983 }
1984
1985 /* A queue function that skips all virtual bases (and their
1986 bases). */
1987
1988 tree
1989 dfs_skip_vbases (tree binfo, void *data ATTRIBUTE_UNUSED)
1990 {
1991 if (TREE_VIA_VIRTUAL (binfo))
1992 return NULL_TREE;
1993
1994 return binfo;
1995 }
1996
1997 /* Called via dfs_walk from dfs_get_pure_virtuals. */
1998
1999 static tree
2000 dfs_get_pure_virtuals (tree binfo, void *data)
2001 {
2002 tree type = (tree) data;
2003
2004 /* We're not interested in primary base classes; the derived class
2005 of which they are a primary base will contain the information we
2006 need. */
2007 if (!BINFO_PRIMARY_P (binfo))
2008 {
2009 tree virtuals;
2010
2011 for (virtuals = BINFO_VIRTUALS (binfo);
2012 virtuals;
2013 virtuals = TREE_CHAIN (virtuals))
2014 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
2015 CLASSTYPE_PURE_VIRTUALS (type)
2016 = tree_cons (NULL_TREE, BV_FN (virtuals),
2017 CLASSTYPE_PURE_VIRTUALS (type));
2018 }
2019
2020 SET_BINFO_MARKED (binfo);
2021
2022 return NULL_TREE;
2023 }
2024
2025 /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
2026
2027 void
2028 get_pure_virtuals (tree type)
2029 {
2030 tree vbases;
2031
2032 /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
2033 is going to be overridden. */
2034 CLASSTYPE_PURE_VIRTUALS (type) = NULL_TREE;
2035 /* Now, run through all the bases which are not primary bases, and
2036 collect the pure virtual functions. We look at the vtable in
2037 each class to determine what pure virtual functions are present.
2038 (A primary base is not interesting because the derived class of
2039 which it is a primary base will contain vtable entries for the
2040 pure virtuals in the base class. */
2041 dfs_walk (TYPE_BINFO (type), dfs_get_pure_virtuals,
2042 dfs_unmarked_real_bases_queue_p, type);
2043 dfs_walk (TYPE_BINFO (type), dfs_unmark,
2044 dfs_marked_real_bases_queue_p, type);
2045
2046 /* Put the pure virtuals in dfs order. */
2047 CLASSTYPE_PURE_VIRTUALS (type) = nreverse (CLASSTYPE_PURE_VIRTUALS (type));
2048
2049 for (vbases = CLASSTYPE_VBASECLASSES (type);
2050 vbases;
2051 vbases = TREE_CHAIN (vbases))
2052 {
2053 tree virtuals;
2054
2055 for (virtuals = BINFO_VIRTUALS (TREE_VALUE (vbases));
2056 virtuals;
2057 virtuals = TREE_CHAIN (virtuals))
2058 {
2059 tree base_fndecl = BV_FN (virtuals);
2060 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl))
2061 error ("`%#D' needs a final overrider", base_fndecl);
2062 }
2063 }
2064 }
2065 \f
2066 /* DEPTH-FIRST SEARCH ROUTINES. */
2067
2068 tree
2069 markedp (tree binfo, void *data ATTRIBUTE_UNUSED)
2070 {
2071 return BINFO_MARKED (binfo) ? binfo : NULL_TREE;
2072 }
2073
2074 tree
2075 unmarkedp (tree binfo, void *data ATTRIBUTE_UNUSED)
2076 {
2077 return !BINFO_MARKED (binfo) ? binfo : NULL_TREE;
2078 }
2079
2080 tree
2081 marked_vtable_pathp (tree binfo, void *data ATTRIBUTE_UNUSED)
2082 {
2083 return BINFO_VTABLE_PATH_MARKED (binfo) ? binfo : NULL_TREE;
2084 }
2085
2086 tree
2087 unmarked_vtable_pathp (tree binfo, void *data ATTRIBUTE_UNUSED)
2088 {
2089 return !BINFO_VTABLE_PATH_MARKED (binfo) ? binfo : NULL_TREE;
2090 }
2091
2092 static tree
2093 marked_pushdecls_p (tree binfo, void *data ATTRIBUTE_UNUSED)
2094 {
2095 return (CLASS_TYPE_P (BINFO_TYPE (binfo))
2096 && !dependent_base_p (binfo)
2097 && BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
2098 }
2099
2100 static tree
2101 unmarked_pushdecls_p (tree binfo, void *data ATTRIBUTE_UNUSED)
2102 {
2103 return (CLASS_TYPE_P (BINFO_TYPE (binfo))
2104 && !dependent_base_p (binfo)
2105 && !BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
2106 }
2107
2108 /* The worker functions for `dfs_walk'. These do not need to
2109 test anything (vis a vis marking) if they are paired with
2110 a predicate function (above). */
2111
2112 tree
2113 dfs_unmark (tree binfo, void *data ATTRIBUTE_UNUSED)
2114 {
2115 CLEAR_BINFO_MARKED (binfo);
2116 return NULL_TREE;
2117 }
2118
2119 /* get virtual base class types.
2120 This adds type to the vbase_types list in reverse dfs order.
2121 Ordering is very important, so don't change it. */
2122
2123 static tree
2124 dfs_get_vbase_types (tree binfo, void *data)
2125 {
2126 tree type = (tree) data;
2127
2128 if (TREE_VIA_VIRTUAL (binfo))
2129 CLASSTYPE_VBASECLASSES (type)
2130 = tree_cons (BINFO_TYPE (binfo),
2131 binfo,
2132 CLASSTYPE_VBASECLASSES (type));
2133 SET_BINFO_MARKED (binfo);
2134 return NULL_TREE;
2135 }
2136
2137 /* Called via dfs_walk from mark_primary_bases. Builds the
2138 inheritance graph order list of BINFOs. */
2139
2140 static tree
2141 dfs_build_inheritance_graph_order (tree binfo, void *data)
2142 {
2143 tree *last_binfo = (tree *) data;
2144
2145 if (*last_binfo)
2146 TREE_CHAIN (*last_binfo) = binfo;
2147 *last_binfo = binfo;
2148 SET_BINFO_MARKED (binfo);
2149 return NULL_TREE;
2150 }
2151
2152 /* Set CLASSTYPE_VBASECLASSES for TYPE. */
2153
2154 void
2155 get_vbase_types (tree type)
2156 {
2157 tree last_binfo;
2158
2159 CLASSTYPE_VBASECLASSES (type) = NULL_TREE;
2160 dfs_walk (TYPE_BINFO (type), dfs_get_vbase_types, unmarkedp, type);
2161 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2162 reverse it so that we get normal dfs ordering. */
2163 CLASSTYPE_VBASECLASSES (type) = nreverse (CLASSTYPE_VBASECLASSES (type));
2164 dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, 0);
2165 /* Thread the BINFOs in inheritance-graph order. */
2166 last_binfo = NULL;
2167 dfs_walk_real (TYPE_BINFO (type),
2168 dfs_build_inheritance_graph_order,
2169 NULL,
2170 unmarkedp,
2171 &last_binfo);
2172 dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, NULL);
2173 }
2174
2175 /* Called from find_vbase_instance via dfs_walk. */
2176
2177 static tree
2178 dfs_find_vbase_instance (tree binfo, void *data)
2179 {
2180 tree base = TREE_VALUE ((tree) data);
2181
2182 if (BINFO_PRIMARY_P (binfo)
2183 && same_type_p (BINFO_TYPE (binfo), base))
2184 return binfo;
2185
2186 return NULL_TREE;
2187 }
2188
2189 /* Find the real occurrence of the virtual BASE (a class type) in the
2190 hierarchy dominated by TYPE. */
2191
2192 tree
2193 find_vbase_instance (tree base, tree type)
2194 {
2195 tree instance;
2196
2197 instance = binfo_for_vbase (base, type);
2198 if (!BINFO_PRIMARY_P (instance))
2199 return instance;
2200
2201 return dfs_walk (TYPE_BINFO (type),
2202 dfs_find_vbase_instance,
2203 NULL,
2204 build_tree_list (type, base));
2205 }
2206
2207 \f
2208 /* Debug info for C++ classes can get very large; try to avoid
2209 emitting it everywhere.
2210
2211 Note that this optimization wins even when the target supports
2212 BINCL (if only slightly), and reduces the amount of work for the
2213 linker. */
2214
2215 void
2216 maybe_suppress_debug_info (tree t)
2217 {
2218 /* We can't do the usual TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2219 does not support name references between translation units. It supports
2220 symbolic references between translation units, but only within a single
2221 executable or shared library.
2222
2223 For DWARF 2, we handle TYPE_DECL_SUPPRESS_DEBUG by pretending
2224 that the type was never defined, so we only get the members we
2225 actually define. */
2226 if (write_symbols == DWARF_DEBUG || write_symbols == NO_DEBUG)
2227 return;
2228
2229 /* We might have set this earlier in cp_finish_decl. */
2230 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
2231
2232 /* If we already know how we're handling this class, handle debug info
2233 the same way. */
2234 if (CLASSTYPE_INTERFACE_KNOWN (t))
2235 {
2236 if (CLASSTYPE_INTERFACE_ONLY (t))
2237 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
2238 /* else don't set it. */
2239 }
2240 /* If the class has a vtable, write out the debug info along with
2241 the vtable. */
2242 else if (TYPE_CONTAINS_VPTR_P (t))
2243 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
2244
2245 /* Otherwise, just emit the debug info normally. */
2246 }
2247
2248 /* Note that we want debugging information for a base class of a class
2249 whose vtable is being emitted. Normally, this would happen because
2250 calling the constructor for a derived class implies calling the
2251 constructors for all bases, which involve initializing the
2252 appropriate vptr with the vtable for the base class; but in the
2253 presence of optimization, this initialization may be optimized
2254 away, so we tell finish_vtable_vardecl that we want the debugging
2255 information anyway. */
2256
2257 static tree
2258 dfs_debug_mark (tree binfo, void *data ATTRIBUTE_UNUSED)
2259 {
2260 tree t = BINFO_TYPE (binfo);
2261
2262 CLASSTYPE_DEBUG_REQUESTED (t) = 1;
2263
2264 return NULL_TREE;
2265 }
2266
2267 /* Returns BINFO if we haven't already noted that we want debugging
2268 info for this base class. */
2269
2270 static tree
2271 dfs_debug_unmarkedp (tree binfo, void *data ATTRIBUTE_UNUSED)
2272 {
2273 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo))
2274 ? binfo : NULL_TREE);
2275 }
2276
2277 /* Write out the debugging information for TYPE, whose vtable is being
2278 emitted. Also walk through our bases and note that we want to
2279 write out information for them. This avoids the problem of not
2280 writing any debug info for intermediate basetypes whose
2281 constructors, and thus the references to their vtables, and thus
2282 the vtables themselves, were optimized away. */
2283
2284 void
2285 note_debug_info_needed (tree type)
2286 {
2287 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
2288 {
2289 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)) = 0;
2290 rest_of_type_compilation (type, toplevel_bindings_p ());
2291 }
2292
2293 dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp, 0);
2294 }
2295 \f
2296 /* Subroutines of push_class_decls (). */
2297
2298 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2299 because it (or one of the intermediate bases) depends on template parms. */
2300
2301 static int
2302 dependent_base_p (tree binfo)
2303 {
2304 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
2305 {
2306 if (currently_open_class (TREE_TYPE (binfo)))
2307 break;
2308 if (dependent_type_p (TREE_TYPE (binfo)))
2309 return 1;
2310 }
2311 return 0;
2312 }
2313
2314 static void
2315 setup_class_bindings (tree name, int type_binding_p)
2316 {
2317 tree type_binding = NULL_TREE;
2318 tree value_binding;
2319
2320 /* If we've already done the lookup for this declaration, we're
2321 done. */
2322 if (IDENTIFIER_CLASS_VALUE (name))
2323 return;
2324
2325 /* First, deal with the type binding. */
2326 if (type_binding_p)
2327 {
2328 type_binding = lookup_member (current_class_type, name,
2329 /*protect=*/2, /*want_type=*/true);
2330 if (TREE_CODE (type_binding) == TREE_LIST
2331 && TREE_TYPE (type_binding) == error_mark_node)
2332 /* NAME is ambiguous. */
2333 push_class_level_binding (name, type_binding);
2334 else
2335 pushdecl_class_level (type_binding);
2336 }
2337
2338 /* Now, do the value binding. */
2339 value_binding = lookup_member (current_class_type, name,
2340 /*protect=*/2, /*want_type=*/false);
2341
2342 if (type_binding_p
2343 && (TREE_CODE (value_binding) == TYPE_DECL
2344 || DECL_CLASS_TEMPLATE_P (value_binding)
2345 || (TREE_CODE (value_binding) == TREE_LIST
2346 && TREE_TYPE (value_binding) == error_mark_node
2347 && (TREE_CODE (TREE_VALUE (value_binding))
2348 == TYPE_DECL))))
2349 /* We found a type-binding, even when looking for a non-type
2350 binding. This means that we already processed this binding
2351 above. */;
2352 else if (value_binding)
2353 {
2354 if (TREE_CODE (value_binding) == TREE_LIST
2355 && TREE_TYPE (value_binding) == error_mark_node)
2356 /* NAME is ambiguous. */
2357 push_class_level_binding (name, value_binding);
2358 else
2359 {
2360 if (BASELINK_P (value_binding))
2361 /* NAME is some overloaded functions. */
2362 value_binding = BASELINK_FUNCTIONS (value_binding);
2363 pushdecl_class_level (value_binding);
2364 }
2365 }
2366 }
2367
2368 /* Push class-level declarations for any names appearing in BINFO that
2369 are TYPE_DECLS. */
2370
2371 static tree
2372 dfs_push_type_decls (tree binfo, void *data ATTRIBUTE_UNUSED)
2373 {
2374 tree type;
2375 tree fields;
2376
2377 type = BINFO_TYPE (binfo);
2378 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2379 if (DECL_NAME (fields) && TREE_CODE (fields) == TYPE_DECL
2380 && !(!same_type_p (type, current_class_type)
2381 && template_self_reference_p (type, fields)))
2382 setup_class_bindings (DECL_NAME (fields), /*type_binding_p=*/1);
2383
2384 /* We can't just use BINFO_MARKED because envelope_add_decl uses
2385 DERIVED_FROM_P, which calls get_base_distance. */
2386 SET_BINFO_PUSHDECLS_MARKED (binfo);
2387
2388 return NULL_TREE;
2389 }
2390
2391 /* Push class-level declarations for any names appearing in BINFO that
2392 are not TYPE_DECLS. */
2393
2394 static tree
2395 dfs_push_decls (tree binfo, void *data)
2396 {
2397 tree type;
2398 tree method_vec;
2399 int dep_base_p;
2400
2401 type = BINFO_TYPE (binfo);
2402 dep_base_p = (processing_template_decl && type != current_class_type
2403 && dependent_base_p (binfo));
2404 if (!dep_base_p)
2405 {
2406 tree fields;
2407 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2408 if (DECL_NAME (fields)
2409 && TREE_CODE (fields) != TYPE_DECL
2410 && TREE_CODE (fields) != USING_DECL
2411 && !DECL_ARTIFICIAL (fields))
2412 setup_class_bindings (DECL_NAME (fields), /*type_binding_p=*/0);
2413 else if (TREE_CODE (fields) == FIELD_DECL
2414 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
2415 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields)), data);
2416
2417 method_vec = (CLASS_TYPE_P (type)
2418 ? CLASSTYPE_METHOD_VEC (type) : NULL_TREE);
2419
2420 if (method_vec && TREE_VEC_LENGTH (method_vec) >= 3)
2421 {
2422 tree *methods;
2423 tree *end;
2424
2425 /* Farm out constructors and destructors. */
2426 end = TREE_VEC_END (method_vec);
2427
2428 for (methods = &TREE_VEC_ELT (method_vec, 2);
2429 methods < end && *methods;
2430 methods++)
2431 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods)),
2432 /*type_binding_p=*/0);
2433 }
2434 }
2435
2436 CLEAR_BINFO_PUSHDECLS_MARKED (binfo);
2437
2438 return NULL_TREE;
2439 }
2440
2441 /* When entering the scope of a class, we cache all of the
2442 fields that that class provides within its inheritance
2443 lattice. Where ambiguities result, we mark them
2444 with `error_mark_node' so that if they are encountered
2445 without explicit qualification, we can emit an error
2446 message. */
2447
2448 void
2449 push_class_decls (tree type)
2450 {
2451 search_stack = push_search_level (search_stack, &search_obstack);
2452
2453 /* Enter type declarations and mark. */
2454 dfs_walk (TYPE_BINFO (type), dfs_push_type_decls, unmarked_pushdecls_p, 0);
2455
2456 /* Enter non-type declarations and unmark. */
2457 dfs_walk (TYPE_BINFO (type), dfs_push_decls, marked_pushdecls_p, 0);
2458 }
2459
2460 /* Here's a subroutine we need because C lacks lambdas. */
2461
2462 static tree
2463 dfs_unuse_fields (tree binfo, void *data ATTRIBUTE_UNUSED)
2464 {
2465 tree type = TREE_TYPE (binfo);
2466 tree fields;
2467
2468 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2469 {
2470 if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields))
2471 continue;
2472
2473 TREE_USED (fields) = 0;
2474 if (DECL_NAME (fields) == NULL_TREE
2475 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
2476 unuse_fields (TREE_TYPE (fields));
2477 }
2478
2479 return NULL_TREE;
2480 }
2481
2482 void
2483 unuse_fields (tree type)
2484 {
2485 dfs_walk (TYPE_BINFO (type), dfs_unuse_fields, unmarkedp, 0);
2486 }
2487
2488 void
2489 pop_class_decls ()
2490 {
2491 /* We haven't pushed a search level when dealing with cached classes,
2492 so we'd better not try to pop it. */
2493 if (search_stack)
2494 search_stack = pop_search_level (search_stack);
2495 }
2496
2497 void
2498 print_search_statistics ()
2499 {
2500 #ifdef GATHER_STATISTICS
2501 fprintf (stderr, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
2502 n_fields_searched, n_calls_lookup_field, n_calls_lookup_field_1);
2503 fprintf (stderr, "%d fnfields searched in %d calls to lookup_fnfields\n",
2504 n_outer_fields_searched, n_calls_lookup_fnfields);
2505 fprintf (stderr, "%d calls to get_base_type\n", n_calls_get_base_type);
2506 #else /* GATHER_STATISTICS */
2507 fprintf (stderr, "no search statistics\n");
2508 #endif /* GATHER_STATISTICS */
2509 }
2510
2511 void
2512 init_search_processing ()
2513 {
2514 gcc_obstack_init (&search_obstack);
2515 }
2516
2517 void
2518 reinit_search_statistics ()
2519 {
2520 #ifdef GATHER_STATISTICS
2521 n_fields_searched = 0;
2522 n_calls_lookup_field = 0, n_calls_lookup_field_1 = 0;
2523 n_calls_lookup_fnfields = 0, n_calls_lookup_fnfields_1 = 0;
2524 n_calls_get_base_type = 0;
2525 n_outer_fields_searched = 0;
2526 n_contexts_saved = 0;
2527 #endif /* GATHER_STATISTICS */
2528 }
2529
2530 static tree
2531 add_conversions (tree binfo, void *data)
2532 {
2533 int i;
2534 tree method_vec = CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo));
2535 tree *conversions = (tree *) data;
2536
2537 /* Some builtin types have no method vector, not even an empty one. */
2538 if (!method_vec)
2539 return NULL_TREE;
2540
2541 for (i = 2; i < TREE_VEC_LENGTH (method_vec); ++i)
2542 {
2543 tree tmp = TREE_VEC_ELT (method_vec, i);
2544 tree name;
2545
2546 if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp)))
2547 break;
2548
2549 name = DECL_NAME (OVL_CURRENT (tmp));
2550
2551 /* Make sure we don't already have this conversion. */
2552 if (! IDENTIFIER_MARKED (name))
2553 {
2554 *conversions = tree_cons (binfo, tmp, *conversions);
2555 IDENTIFIER_MARKED (name) = 1;
2556 }
2557 }
2558 return NULL_TREE;
2559 }
2560
2561 /* Return a TREE_LIST containing all the non-hidden user-defined
2562 conversion functions for TYPE (and its base-classes). The
2563 TREE_VALUE of each node is a FUNCTION_DECL or an OVERLOAD
2564 containing the conversion functions. The TREE_PURPOSE is the BINFO
2565 from which the conversion functions in this node were selected. */
2566
2567 tree
2568 lookup_conversions (tree type)
2569 {
2570 tree t;
2571 tree conversions = NULL_TREE;
2572
2573 if (COMPLETE_TYPE_P (type))
2574 bfs_walk (TYPE_BINFO (type), add_conversions, 0, &conversions);
2575
2576 for (t = conversions; t; t = TREE_CHAIN (t))
2577 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t)))) = 0;
2578
2579 return conversions;
2580 }
2581
2582 struct overlap_info
2583 {
2584 tree compare_type;
2585 int found_overlap;
2586 };
2587
2588 /* Check whether the empty class indicated by EMPTY_BINFO is also present
2589 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
2590
2591 static tree
2592 dfs_check_overlap (tree empty_binfo, void *data)
2593 {
2594 struct overlap_info *oi = (struct overlap_info *) data;
2595 tree binfo;
2596 for (binfo = TYPE_BINFO (oi->compare_type);
2597 ;
2598 binfo = BINFO_BASETYPE (binfo, 0))
2599 {
2600 if (BINFO_TYPE (binfo) == BINFO_TYPE (empty_binfo))
2601 {
2602 oi->found_overlap = 1;
2603 break;
2604 }
2605 else if (BINFO_BASETYPES (binfo) == NULL_TREE)
2606 break;
2607 }
2608
2609 return NULL_TREE;
2610 }
2611
2612 /* Trivial function to stop base traversal when we find something. */
2613
2614 static tree
2615 dfs_no_overlap_yet (tree binfo, void *data)
2616 {
2617 struct overlap_info *oi = (struct overlap_info *) data;
2618 return !oi->found_overlap ? binfo : NULL_TREE;
2619 }
2620
2621 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
2622 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
2623
2624 int
2625 types_overlap_p (tree empty_type, tree next_type)
2626 {
2627 struct overlap_info oi;
2628
2629 if (! IS_AGGR_TYPE (next_type))
2630 return 0;
2631 oi.compare_type = next_type;
2632 oi.found_overlap = 0;
2633 dfs_walk (TYPE_BINFO (empty_type), dfs_check_overlap,
2634 dfs_no_overlap_yet, &oi);
2635 return oi.found_overlap;
2636 }
2637
2638 /* Given a vtable VAR, determine which of the inherited classes the vtable
2639 inherits (in a loose sense) functions from.
2640
2641 FIXME: This does not work with the new ABI. */
2642
2643 tree
2644 binfo_for_vtable (tree var)
2645 {
2646 tree main_binfo = TYPE_BINFO (DECL_CONTEXT (var));
2647 tree binfos = TYPE_BINFO_BASETYPES (BINFO_TYPE (main_binfo));
2648 int n_baseclasses = CLASSTYPE_N_BASECLASSES (BINFO_TYPE (main_binfo));
2649 int i;
2650
2651 for (i = 0; i < n_baseclasses; i++)
2652 {
2653 tree base_binfo = TREE_VEC_ELT (binfos, i);
2654 if (base_binfo != NULL_TREE && BINFO_VTABLE (base_binfo) == var)
2655 return base_binfo;
2656 }
2657
2658 /* If no secondary base classes matched, return the primary base, if
2659 there is one. */
2660 if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (main_binfo)))
2661 return get_primary_binfo (main_binfo);
2662
2663 return main_binfo;
2664 }
2665
2666 /* Returns the binfo of the first direct or indirect virtual base derived
2667 from BINFO, or NULL if binfo is not via virtual. */
2668
2669 tree
2670 binfo_from_vbase (tree binfo)
2671 {
2672 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
2673 {
2674 if (TREE_VIA_VIRTUAL (binfo))
2675 return binfo;
2676 }
2677 return NULL_TREE;
2678 }
2679
2680 /* Returns the binfo of the first direct or indirect virtual base derived
2681 from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
2682 via virtual. */
2683
2684 tree
2685 binfo_via_virtual (tree binfo, tree limit)
2686 {
2687 for (; binfo && (!limit || !same_type_p (BINFO_TYPE (binfo), limit));
2688 binfo = BINFO_INHERITANCE_CHAIN (binfo))
2689 {
2690 if (TREE_VIA_VIRTUAL (binfo))
2691 return binfo;
2692 }
2693 return NULL_TREE;
2694 }
2695
2696 /* Returns the BINFO (if any) for the virtual baseclass T of the class
2697 C from the CLASSTYPE_VBASECLASSES list. */
2698
2699 tree
2700 binfo_for_vbase (tree basetype, tree classtype)
2701 {
2702 tree binfo;
2703
2704 binfo = purpose_member (basetype, CLASSTYPE_VBASECLASSES (classtype));
2705 return binfo ? TREE_VALUE (binfo) : NULL_TREE;
2706 }
This page took 0.150288 seconds and 4 git commands to generate.