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)
7 This file is part of GCC.
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)
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.
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. */
24 /* High-level class interface. */
28 #include "coretypes.h"
39 /* Obstack used for remembering decision points of breadth-first. */
41 static struct obstack search_obstack;
43 /* Methods for pushing and popping objects to and from obstacks. */
46 push_stack_level (obstack, tp, size)
47 struct obstack *obstack;
48 char *tp; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
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 *);
62 pop_stack_level (stack)
63 struct stack_level *stack;
65 struct stack_level *tem = stack;
66 struct obstack *obstack = tem->obstack;
68 obstack_free (obstack, tem);
72 #define search_level stack_level
73 static struct search_level *search_stack;
77 /* The class dominating the hierarchy. */
79 /* A pointer to a complete object of the indicated TYPE. */
84 static tree dfs_check_overlap (tree, void *);
85 static tree dfs_no_overlap_yet (tree, int, void *);
86 static base_kind lookup_base_r (tree, tree, base_access,
87 bool, bool, bool, tree *);
88 static int dynamic_cast_base_recurse (tree, tree, bool, tree *);
89 static tree marked_pushdecls_p (tree, int, void *);
90 static tree unmarked_pushdecls_p (tree, int, void *);
91 static tree dfs_debug_unmarkedp (tree, int, void *);
92 static tree dfs_debug_mark (tree, void *);
93 static tree dfs_push_type_decls (tree, void *);
94 static tree dfs_push_decls (tree, void *);
95 static tree dfs_unuse_fields (tree, void *);
96 static tree add_conversions (tree, void *);
97 static int look_for_overrides_r (tree, tree);
98 static struct search_level *push_search_level (struct stack_level *,
100 static struct search_level *pop_search_level (struct stack_level *);
101 static tree bfs_walk (tree, tree (*) (tree, void *),
102 tree (*) (tree, int, void *), void *);
103 static tree lookup_field_queue_p (tree, int, void *);
104 static int shared_member_p (tree);
105 static tree lookup_field_r (tree, void *);
106 static tree dfs_accessible_queue_p (tree, int, void *);
107 static tree dfs_accessible_p (tree, void *);
108 static tree dfs_access_in_type (tree, void *);
109 static access_kind access_in_type (tree, tree);
110 static int protected_accessible_p (tree, tree, tree);
111 static int friend_accessible_p (tree, tree, tree);
112 static void setup_class_bindings (tree, int);
113 static int template_self_reference_p (tree, tree);
114 static tree dfs_get_pure_virtuals (tree, void *);
116 /* Allocate a level of searching. */
118 static struct search_level *
119 push_search_level (struct stack_level *stack, struct obstack *obstack)
121 struct search_level tem;
124 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
127 /* Discard a level of search allocation. */
129 static struct search_level *
130 pop_search_level (struct stack_level *obstack)
132 register struct search_level *stack = pop_stack_level (obstack);
137 /* Variables for gathering statistics. */
138 #ifdef GATHER_STATISTICS
139 static int n_fields_searched;
140 static int n_calls_lookup_field, n_calls_lookup_field_1;
141 static int n_calls_lookup_fnfields, n_calls_lookup_fnfields_1;
142 static int n_calls_get_base_type;
143 static int n_outer_fields_searched;
144 static int n_contexts_saved;
145 #endif /* GATHER_STATISTICS */
148 /* Worker for lookup_base. BINFO is the binfo we are searching at,
149 BASE is the RECORD_TYPE we are searching for. ACCESS is the
150 required access checks. WITHIN_CURRENT_SCOPE, IS_NON_PUBLIC and
151 IS_VIRTUAL indicate how BINFO was reached from the start of the
152 search. WITHIN_CURRENT_SCOPE is true if we met the current scope,
153 or friend thereof (this allows us to determine whether a protected
154 base is accessible or not). IS_NON_PUBLIC indicates whether BINFO
155 is accessible and IS_VIRTUAL indicates if it is morally virtual.
157 If BINFO is of the required type, then *BINFO_PTR is examined to
158 compare with any other instance of BASE we might have already
159 discovered. *BINFO_PTR is initialized and a base_kind return value
160 indicates what kind of base was located.
162 Otherwise BINFO's bases are searched. */
165 lookup_base_r (tree binfo, tree base, base_access access,
166 bool within_current_scope,
167 bool is_non_public, /* inside a non-public part */
168 bool is_virtual, /* inside a virtual part */
172 tree bases, accesses;
173 base_kind found = bk_not_base;
175 if (access == ba_check
176 && !within_current_scope
177 && is_friend (BINFO_TYPE (binfo), current_scope ()))
179 /* Do not clear is_non_public here. If A is a private base of B, A
180 is not allowed to convert a B* to an A*. */
181 within_current_scope = 1;
184 if (same_type_p (BINFO_TYPE (binfo), base))
186 /* We have found a base. Check against what we have found
188 found = bk_same_type;
190 found = bk_via_virtual;
194 else if (binfo != *binfo_ptr)
196 if (access != ba_any)
198 else if (!is_virtual)
199 /* Prefer a non-virtual base. */
207 bases = BINFO_BASETYPES (binfo);
208 accesses = BINFO_BASEACCESSES (binfo);
212 for (i = TREE_VEC_LENGTH (bases); i--;)
214 tree base_binfo = TREE_VEC_ELT (bases, i);
215 tree base_access = TREE_VEC_ELT (accesses, i);
217 int this_non_public = is_non_public;
218 int this_virtual = is_virtual;
221 if (access <= ba_ignore)
223 else if (base_access == access_public_node)
225 else if (access == ba_not_special)
227 else if (base_access == access_protected_node && within_current_scope)
229 else if (is_friend (BINFO_TYPE (binfo), current_scope ()))
234 if (TREE_VIA_VIRTUAL (base_binfo))
237 bk = lookup_base_r (base_binfo, base,
238 access, within_current_scope,
239 this_non_public, this_virtual,
245 if (access != ba_any)
250 case bk_inaccessible:
251 if (found == bk_not_base)
253 my_friendly_assert (found == bk_via_virtual
254 || found == bk_inaccessible, 20010723);
262 my_friendly_assert (found == bk_not_base, 20010723);
267 if (found != bk_ambig)
278 /* Lookup BASE in the hierarchy dominated by T. Do access checking as
279 ACCESS specifies. Return the binfo we discover. If KIND_PTR is
280 non-NULL, fill with information about what kind of base we
283 If the base is inaccessible, or ambiguous, and the ba_quiet bit is
284 not set in ACCESS, then an error is issued and error_mark_node is
285 returned. If the ba_quiet bit is set, then no error is issued and
286 NULL_TREE is returned. */
289 lookup_base (tree t, tree base, base_access access, base_kind *kind_ptr)
291 tree binfo = NULL; /* The binfo we've found so far. */
295 if (t == error_mark_node || base == error_mark_node)
298 *kind_ptr = bk_not_base;
299 return error_mark_node;
301 my_friendly_assert (TYPE_P (base), 20011127);
309 t_binfo = TYPE_BINFO (t);
311 /* Ensure that the types are instantiated. */
312 t = complete_type (TYPE_MAIN_VARIANT (t));
313 base = complete_type (TYPE_MAIN_VARIANT (base));
315 bk = lookup_base_r (t_binfo, base, access & ~ba_quiet,
318 /* Check that the base is unambiguous and accessible. */
319 if (access != ba_any)
327 if (!(access & ba_quiet))
329 error ("`%T' is an ambiguous base of `%T'", base, t);
330 binfo = error_mark_node;
335 if (access != ba_ignore
336 /* If BASE is incomplete, then BASE and TYPE are probably
337 the same, in which case BASE is accessible. If they
338 are not the same, then TYPE is invalid. In that case,
339 there's no need to issue another error here, and
340 there's no implicit typedef to use in the code that
341 follows, so we skip the check. */
342 && COMPLETE_TYPE_P (base))
346 /* [class.access.base]
348 A base class is said to be accessible if an invented public
349 member of the base class is accessible. */
350 /* Rather than inventing a public member, we use the implicit
351 public typedef created in the scope of every class. */
352 decl = TYPE_FIELDS (base);
353 while (TREE_CODE (decl) != TYPE_DECL
354 || !DECL_ARTIFICIAL (decl)
355 || DECL_NAME (decl) != constructor_name (base))
356 decl = TREE_CHAIN (decl);
357 while (ANON_AGGR_TYPE_P (t))
358 t = TYPE_CONTEXT (t);
359 if (!accessible_p (t, decl))
361 if (!(access & ba_quiet))
363 error ("`%T' is an inaccessible base of `%T'", base, t);
364 binfo = error_mark_node;
368 bk = bk_inaccessible;
380 /* Worker function for get_dynamic_cast_base_type. */
383 dynamic_cast_base_recurse (tree subtype, tree binfo, bool is_via_virtual,
386 tree binfos, accesses;
390 if (BINFO_TYPE (binfo) == subtype)
396 *offset_ptr = BINFO_OFFSET (binfo);
401 binfos = BINFO_BASETYPES (binfo);
402 accesses = BINFO_BASEACCESSES (binfo);
403 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
404 for (i = 0; i < n_baselinks; i++)
406 tree base_binfo = TREE_VEC_ELT (binfos, i);
407 tree base_access = TREE_VEC_ELT (accesses, i);
410 if (base_access != access_public_node)
412 rval = dynamic_cast_base_recurse
413 (subtype, base_binfo,
414 is_via_virtual || TREE_VIA_VIRTUAL (base_binfo), offset_ptr);
418 worst = worst >= 0 ? -3 : worst;
421 else if (rval == -3 && worst != -1)
427 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
428 started from is related to the required TARGET type, in order to optimize
429 the inheritance graph search. This information is independent of the
430 current context, and ignores private paths, hence get_base_distance is
431 inappropriate. Return a TREE specifying the base offset, BOFF.
432 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
433 and there are no public virtual SUBTYPE bases.
434 BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
435 BOFF == -2, SUBTYPE is not a public base.
436 BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
439 get_dynamic_cast_base_type (tree subtype, tree target)
441 tree offset = NULL_TREE;
442 int boff = dynamic_cast_base_recurse (subtype, TYPE_BINFO (target),
447 offset = build_int_2 (boff, -1);
448 TREE_TYPE (offset) = ssizetype;
452 /* Search for a member with name NAME in a multiple inheritance
453 lattice specified by TYPE. If it does not exist, return NULL_TREE.
454 If the member is ambiguously referenced, return `error_mark_node'.
455 Otherwise, return a DECL with the indicated name. If WANT_TYPE is
456 true, type declarations are preferred. */
458 /* Do a 1-level search for NAME as a member of TYPE. The caller must
459 figure out whether it can access this field. (Since it is only one
460 level, this is reasonable.) */
463 lookup_field_1 (tree type, tree name, bool want_type)
467 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
468 || TREE_CODE (type) == BOUND_TEMPLATE_TEMPLATE_PARM
469 || TREE_CODE (type) == TYPENAME_TYPE)
470 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM and
471 BOUND_TEMPLATE_TEMPLATE_PARM are not fields at all;
472 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
473 the code often worked even when we treated the index as a list
475 The TYPE_FIELDS of TYPENAME_TYPE is its TYPENAME_TYPE_FULLNAME. */
479 && DECL_LANG_SPECIFIC (TYPE_NAME (type))
480 && DECL_SORTED_FIELDS (TYPE_NAME (type)))
482 tree *fields = &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type)), 0);
483 int lo = 0, hi = TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type)));
490 #ifdef GATHER_STATISTICS
492 #endif /* GATHER_STATISTICS */
494 if (DECL_NAME (fields[i]) > name)
496 else if (DECL_NAME (fields[i]) < name)
502 /* We might have a nested class and a field with the
503 same name; we sorted them appropriately via
504 field_decl_cmp, so just look for the first or last
505 field with this name. */
510 while (i >= lo && DECL_NAME (fields[i]) == name);
511 if (TREE_CODE (field) != TYPE_DECL
512 && !DECL_CLASS_TEMPLATE_P (field))
519 while (i < hi && DECL_NAME (fields[i]) == name);
527 field = TYPE_FIELDS (type);
529 #ifdef GATHER_STATISTICS
530 n_calls_lookup_field_1++;
531 #endif /* GATHER_STATISTICS */
532 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
534 #ifdef GATHER_STATISTICS
536 #endif /* GATHER_STATISTICS */
537 my_friendly_assert (DECL_P (field), 0);
538 if (DECL_NAME (field) == NULL_TREE
539 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
541 tree temp = lookup_field_1 (TREE_TYPE (field), name, want_type);
545 if (TREE_CODE (field) == USING_DECL)
546 /* For now, we're just treating member using declarations as
547 old ARM-style access declarations. Thus, there's no reason
548 to return a USING_DECL, and the rest of the compiler can't
549 handle it. Once the class is defined, these are purged
550 from TYPE_FIELDS anyhow; see handle_using_decl. */
553 if (DECL_NAME (field) == name
555 || TREE_CODE (field) == TYPE_DECL
556 || DECL_CLASS_TEMPLATE_P (field)))
560 if (name == vptr_identifier)
562 /* Give the user what s/he thinks s/he wants. */
563 if (TYPE_POLYMORPHIC_P (type))
564 return TYPE_VFIELD (type);
569 /* There are a number of cases we need to be aware of here:
570 current_class_type current_function_decl
577 Those last two make life interesting. If we're in a function which is
578 itself inside a class, we need decls to go into the fn's decls (our
579 second case below). But if we're in a class and the class itself is
580 inside a function, we need decls to go into the decls for the class. To
581 achieve this last goal, we must see if, when both current_class_ptr and
582 current_function_decl are set, the class was declared inside that
583 function. If so, we know to put the decls into the class's scope. */
588 if (current_function_decl == NULL_TREE)
589 return current_class_type;
590 if (current_class_type == NULL_TREE)
591 return current_function_decl;
592 if ((DECL_FUNCTION_MEMBER_P (current_function_decl)
593 && same_type_p (DECL_CONTEXT (current_function_decl),
595 || (DECL_FRIEND_CONTEXT (current_function_decl)
596 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl),
597 current_class_type)))
598 return current_function_decl;
600 return current_class_type;
603 /* Returns nonzero if we are currently in a function scope. Note
604 that this function returns zero if we are within a local class, but
605 not within a member function body of the local class. */
608 at_function_scope_p ()
610 tree cs = current_scope ();
611 return cs && TREE_CODE (cs) == FUNCTION_DECL;
614 /* Returns true if the innermost active scope is a class scope. */
619 tree cs = current_scope ();
620 return cs && TYPE_P (cs);
623 /* Return the scope of DECL, as appropriate when doing name-lookup. */
626 context_for_name_lookup (tree decl)
630 For the purposes of name lookup, after the anonymous union
631 definition, the members of the anonymous union are considered to
632 have been defined in the scope in which the anonymous union is
634 tree context = DECL_CONTEXT (decl);
636 while (context && TYPE_P (context) && ANON_AGGR_TYPE_P (context))
637 context = TYPE_CONTEXT (context);
639 context = global_namespace;
644 /* The accessibility routines use BINFO_ACCESS for scratch space
645 during the computation of the accssibility of some declaration. */
647 #define BINFO_ACCESS(NODE) \
648 ((access_kind) ((TREE_PUBLIC (NODE) << 1) | TREE_PRIVATE (NODE)))
650 /* Set the access associated with NODE to ACCESS. */
652 #define SET_BINFO_ACCESS(NODE, ACCESS) \
653 ((TREE_PUBLIC (NODE) = ((ACCESS) & 2) != 0), \
654 (TREE_PRIVATE (NODE) = ((ACCESS) & 1) != 0))
656 /* Called from access_in_type via dfs_walk. Calculate the access to
657 DATA (which is really a DECL) in BINFO. */
660 dfs_access_in_type (tree binfo, void *data)
662 tree decl = (tree) data;
663 tree type = BINFO_TYPE (binfo);
664 access_kind access = ak_none;
666 if (context_for_name_lookup (decl) == type)
668 /* If we have desceneded to the scope of DECL, just note the
669 appropriate access. */
670 if (TREE_PRIVATE (decl))
672 else if (TREE_PROTECTED (decl))
673 access = ak_protected;
679 /* First, check for an access-declaration that gives us more
680 access to the DECL. The CONST_DECL for an enumeration
681 constant will not have DECL_LANG_SPECIFIC, and thus no
683 if (DECL_LANG_SPECIFIC (decl) && !DECL_DISCRIMINATOR_P (decl))
685 tree decl_access = purpose_member (type, DECL_ACCESS (decl));
689 decl_access = TREE_VALUE (decl_access);
691 if (decl_access == access_public_node)
693 else if (decl_access == access_protected_node)
694 access = ak_protected;
695 else if (decl_access == access_private_node)
698 my_friendly_assert (false, 20030217);
706 tree binfos, accesses;
708 /* Otherwise, scan our baseclasses, and pick the most favorable
710 binfos = BINFO_BASETYPES (binfo);
711 accesses = BINFO_BASEACCESSES (binfo);
712 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
713 for (i = 0; i < n_baselinks; ++i)
715 tree base_binfo = TREE_VEC_ELT (binfos, i);
716 tree base_access = TREE_VEC_ELT (accesses, i);
717 access_kind base_access_now = BINFO_ACCESS (base_binfo);
719 if (base_access_now == ak_none || base_access_now == ak_private)
720 /* If it was not accessible in the base, or only
721 accessible as a private member, we can't access it
723 base_access_now = ak_none;
724 else if (base_access == access_protected_node)
725 /* Public and protected members in the base become
727 base_access_now = ak_protected;
728 else if (base_access == access_private_node)
729 /* Public and protected members in the base become
731 base_access_now = ak_private;
733 /* See if the new access, via this base, gives more
734 access than our previous best access. */
735 if (base_access_now != ak_none
736 && (access == ak_none || base_access_now < access))
738 access = base_access_now;
740 /* If the new access is public, we can't do better. */
741 if (access == ak_public)
748 /* Note the access to DECL in TYPE. */
749 SET_BINFO_ACCESS (binfo, access);
751 /* Mark TYPE as visited so that if we reach it again we do not
752 duplicate our efforts here. */
753 BINFO_MARKED (binfo) = 1;
758 /* Return the access to DECL in TYPE. */
761 access_in_type (tree type, tree decl)
763 tree binfo = TYPE_BINFO (type);
765 /* We must take into account
769 If a name can be reached by several paths through a multiple
770 inheritance graph, the access is that of the path that gives
773 The algorithm we use is to make a post-order depth-first traversal
774 of the base-class hierarchy. As we come up the tree, we annotate
775 each node with the most lenient access. */
776 dfs_walk_real (binfo, 0, dfs_access_in_type, unmarkedp, decl);
777 dfs_walk (binfo, dfs_unmark, markedp, 0);
779 return BINFO_ACCESS (binfo);
782 /* Called from dfs_accessible_p via dfs_walk. */
785 dfs_accessible_queue_p (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
787 tree binfo = BINFO_BASETYPE (derived, ix);
789 if (BINFO_MARKED (binfo))
792 /* If this class is inherited via private or protected inheritance,
793 then we can't see it, unless we are a friend of the derived class. */
794 if (BINFO_BASEACCESS (derived, ix) != access_public_node
795 && !is_friend (BINFO_TYPE (derived), current_scope ()))
801 /* Called from dfs_accessible_p via dfs_walk. */
804 dfs_accessible_p (tree binfo, void *data)
806 int protected_ok = data != 0;
809 BINFO_MARKED (binfo) = 1;
810 access = BINFO_ACCESS (binfo);
811 if (access == ak_public || (access == ak_protected && protected_ok))
813 else if (access != ak_none
814 && is_friend (BINFO_TYPE (binfo), current_scope ()))
820 /* Returns nonzero if it is OK to access DECL through an object
821 indicated by BINFO in the context of DERIVED. */
824 protected_accessible_p (tree decl, tree derived, tree binfo)
828 /* We're checking this clause from [class.access.base]
830 m as a member of N is protected, and the reference occurs in a
831 member or friend of class N, or in a member or friend of a
832 class P derived from N, where m as a member of P is private or
835 Here DERIVED is a possible P and DECL is m. accessible_p will
836 iterate over various values of N, but the access to m in DERIVED
839 Note that I believe that the passage above is wrong, and should read
840 "...is private or protected or public"; otherwise you get bizarre results
841 whereby a public using-decl can prevent you from accessing a protected
842 member of a base. (jason 2000/02/28) */
844 /* If DERIVED isn't derived from m's class, then it can't be a P. */
845 if (!DERIVED_FROM_P (context_for_name_lookup (decl), derived))
848 access = access_in_type (derived, decl);
850 /* If m is inaccessible in DERIVED, then it's not a P. */
851 if (access == ak_none)
856 When a friend or a member function of a derived class references
857 a protected nonstatic member of a base class, an access check
858 applies in addition to those described earlier in clause
859 _class.access_) Except when forming a pointer to member
860 (_expr.unary.op_), the access must be through a pointer to,
861 reference to, or object of the derived class itself (or any class
862 derived from that class) (_expr.ref_). If the access is to form
863 a pointer to member, the nested-name-specifier shall name the
864 derived class (or any class derived from that class). */
865 if (DECL_NONSTATIC_MEMBER_P (decl))
867 /* We can tell through what the reference is occurring by
868 chasing BINFO up to the root. */
870 while (BINFO_INHERITANCE_CHAIN (t))
871 t = BINFO_INHERITANCE_CHAIN (t);
873 if (!DERIVED_FROM_P (derived, BINFO_TYPE (t)))
880 /* Returns nonzero if SCOPE is a friend of a type which would be able
881 to access DECL through the object indicated by BINFO. */
884 friend_accessible_p (tree scope, tree decl, tree binfo)
886 tree befriending_classes;
892 if (TREE_CODE (scope) == FUNCTION_DECL
893 || DECL_FUNCTION_TEMPLATE_P (scope))
894 befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
895 else if (TYPE_P (scope))
896 befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
900 for (t = befriending_classes; t; t = TREE_CHAIN (t))
901 if (protected_accessible_p (decl, TREE_VALUE (t), binfo))
904 /* Nested classes are implicitly friends of their enclosing types, as
905 per core issue 45 (this is a change from the standard). */
907 for (t = TYPE_CONTEXT (scope); t && TYPE_P (t); t = TYPE_CONTEXT (t))
908 if (protected_accessible_p (decl, t, binfo))
911 if (TREE_CODE (scope) == FUNCTION_DECL
912 || DECL_FUNCTION_TEMPLATE_P (scope))
914 /* Perhaps this SCOPE is a member of a class which is a
916 if (DECL_CLASS_SCOPE_P (decl)
917 && friend_accessible_p (DECL_CONTEXT (scope), decl, binfo))
920 /* Or an instantiation of something which is a friend. */
921 if (DECL_TEMPLATE_INFO (scope))
922 return friend_accessible_p (DECL_TI_TEMPLATE (scope), decl, binfo);
924 else if (CLASSTYPE_TEMPLATE_INFO (scope))
925 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope), decl, binfo);
930 /* DECL is a declaration from a base class of TYPE, which was the
931 class used to name DECL. Return nonzero if, in the current
932 context, DECL is accessible. If TYPE is actually a BINFO node,
933 then we can tell in what context the access is occurring by looking
934 at the most derived class along the path indicated by BINFO. */
937 accessible_p (tree type, tree decl)
942 /* Nonzero if it's OK to access DECL if it has protected
943 accessibility in TYPE. */
944 int protected_ok = 0;
946 /* If this declaration is in a block or namespace scope, there's no
948 if (!TYPE_P (context_for_name_lookup (decl)))
954 type = BINFO_TYPE (type);
957 binfo = TYPE_BINFO (type);
959 /* [class.access.base]
961 A member m is accessible when named in class N if
963 --m as a member of N is public, or
965 --m as a member of N is private, and the reference occurs in a
966 member or friend of class N, or
968 --m as a member of N is protected, and the reference occurs in a
969 member or friend of class N, or in a member or friend of a
970 class P derived from N, where m as a member of P is private or
973 --there exists a base class B of N that is accessible at the point
974 of reference, and m is accessible when named in class B.
976 We walk the base class hierarchy, checking these conditions. */
978 /* Figure out where the reference is occurring. Check to see if
979 DECL is private or protected in this scope, since that will
980 determine whether protected access is allowed. */
981 if (current_class_type)
982 protected_ok = protected_accessible_p (decl, current_class_type, binfo);
984 /* Now, loop through the classes of which we are a friend. */
986 protected_ok = friend_accessible_p (current_scope (), decl, binfo);
988 /* Standardize the binfo that access_in_type will use. We don't
989 need to know what path was chosen from this point onwards. */
990 binfo = TYPE_BINFO (type);
992 /* Compute the accessibility of DECL in the class hierarchy
993 dominated by type. */
994 access_in_type (type, decl);
995 /* Walk the hierarchy again, looking for a base class that allows
997 t = dfs_walk (binfo, dfs_accessible_p,
998 dfs_accessible_queue_p,
999 protected_ok ? &protected_ok : 0);
1000 /* Clear any mark bits. Note that we have to walk the whole tree
1001 here, since we have aborted the previous walk from some point
1002 deep in the tree. */
1003 dfs_walk (binfo, dfs_unmark, 0, 0);
1005 return t != NULL_TREE;
1008 struct lookup_field_info {
1009 /* The type in which we're looking. */
1011 /* The name of the field for which we're looking. */
1013 /* If non-NULL, the current result of the lookup. */
1015 /* The path to RVAL. */
1017 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1020 /* If nonzero, we are looking for types, not data members. */
1022 /* If something went wrong, a message indicating what. */
1026 /* Returns nonzero if BINFO is not hidden by the value found by the
1027 lookup so far. If BINFO is hidden, then there's no need to look in
1028 it. DATA is really a struct lookup_field_info. Called from
1029 lookup_field via breadth_first_search. */
1032 lookup_field_queue_p (tree derived, int ix, void *data)
1034 tree binfo = BINFO_BASETYPE (derived, ix);
1035 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1037 /* Don't look for constructors or destructors in base classes. */
1038 if (IDENTIFIER_CTOR_OR_DTOR_P (lfi->name))
1041 /* If this base class is hidden by the best-known value so far, we
1042 don't need to look. */
1043 if (lfi->rval_binfo && original_binfo (binfo, lfi->rval_binfo))
1046 /* If this is a dependent base, don't look in it. */
1047 if (BINFO_DEPENDENT_BASE_P (binfo))
1053 /* Within the scope of a template class, you can refer to the to the
1054 current specialization with the name of the template itself. For
1057 template <typename T> struct S { S* sp; }
1059 Returns nonzero if DECL is such a declaration in a class TYPE. */
1062 template_self_reference_p (tree type, tree decl)
1064 return (CLASSTYPE_USE_TEMPLATE (type)
1065 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))
1066 && TREE_CODE (decl) == TYPE_DECL
1067 && DECL_ARTIFICIAL (decl)
1068 && DECL_NAME (decl) == constructor_name (type));
1072 /* Nonzero for a class member means that it is shared between all objects
1075 [class.member.lookup]:If the resulting set of declarations are not all
1076 from sub-objects of the same type, or the set has a nonstatic member
1077 and includes members from distinct sub-objects, there is an ambiguity
1078 and the program is ill-formed.
1080 This function checks that T contains no nonstatic members. */
1083 shared_member_p (tree t)
1085 if (TREE_CODE (t) == VAR_DECL || TREE_CODE (t) == TYPE_DECL \
1086 || TREE_CODE (t) == CONST_DECL)
1088 if (is_overloaded_fn (t))
1090 for (; t; t = OVL_NEXT (t))
1092 tree fn = OVL_CURRENT (t);
1093 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn))
1101 /* DATA is really a struct lookup_field_info. Look for a field with
1102 the name indicated there in BINFO. If this function returns a
1103 non-NULL value it is the result of the lookup. Called from
1104 lookup_field via breadth_first_search. */
1107 lookup_field_r (tree binfo, void *data)
1109 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1110 tree type = BINFO_TYPE (binfo);
1111 tree nval = NULL_TREE;
1113 /* First, look for a function. There can't be a function and a data
1114 member with the same name, and if there's a function and a type
1115 with the same name, the type is hidden by the function. */
1116 if (!lfi->want_type)
1118 int idx = lookup_fnfields_1 (type, lfi->name);
1120 nval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1124 /* Look for a data member or type. */
1125 nval = lookup_field_1 (type, lfi->name, lfi->want_type);
1127 /* If there is no declaration with the indicated name in this type,
1128 then there's nothing to do. */
1132 /* If we're looking up a type (as with an elaborated type specifier)
1133 we ignore all non-types we find. */
1134 if (lfi->want_type && TREE_CODE (nval) != TYPE_DECL
1135 && !DECL_CLASS_TEMPLATE_P (nval))
1137 if (lfi->name == TYPE_IDENTIFIER (type))
1139 /* If the aggregate has no user defined constructors, we allow
1140 it to have fields with the same name as the enclosing type.
1141 If we are looking for that name, find the corresponding
1143 for (nval = TREE_CHAIN (nval); nval; nval = TREE_CHAIN (nval))
1144 if (DECL_NAME (nval) == lfi->name
1145 && TREE_CODE (nval) == TYPE_DECL)
1150 if (!nval && CLASSTYPE_NESTED_UTDS (type) != NULL)
1152 binding_entry e = binding_table_find (CLASSTYPE_NESTED_UTDS (type),
1155 nval = TYPE_MAIN_DECL (e->type);
1161 /* You must name a template base class with a template-id. */
1162 if (!same_type_p (type, lfi->type)
1163 && template_self_reference_p (type, nval))
1166 /* If the lookup already found a match, and the new value doesn't
1167 hide the old one, we might have an ambiguity. */
1168 if (lfi->rval_binfo && !original_binfo (lfi->rval_binfo, binfo))
1170 if (nval == lfi->rval && shared_member_p (nval))
1171 /* The two things are really the same. */
1173 else if (original_binfo (binfo, lfi->rval_binfo))
1174 /* The previous value hides the new one. */
1178 /* We have a real ambiguity. We keep a chain of all the
1180 if (!lfi->ambiguous && lfi->rval)
1182 /* This is the first time we noticed an ambiguity. Add
1183 what we previously thought was a reasonable candidate
1185 lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
1186 TREE_TYPE (lfi->ambiguous) = error_mark_node;
1189 /* Add the new value. */
1190 lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
1191 TREE_TYPE (lfi->ambiguous) = error_mark_node;
1192 lfi->errstr = "request for member `%D' is ambiguous";
1198 lfi->rval_binfo = binfo;
1204 /* Return a "baselink" which BASELINK_BINFO, BASELINK_ACCESS_BINFO,
1205 BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
1206 FUNCTIONS, and OPTYPE respectively. */
1209 build_baselink (tree binfo, tree access_binfo, tree functions, tree optype)
1213 my_friendly_assert (TREE_CODE (functions) == FUNCTION_DECL
1214 || TREE_CODE (functions) == TEMPLATE_DECL
1215 || TREE_CODE (functions) == TEMPLATE_ID_EXPR
1216 || TREE_CODE (functions) == OVERLOAD,
1218 my_friendly_assert (!optype || TYPE_P (optype), 20020730);
1219 my_friendly_assert (TREE_TYPE (functions), 20020805);
1221 baselink = make_node (BASELINK);
1222 TREE_TYPE (baselink) = TREE_TYPE (functions);
1223 BASELINK_BINFO (baselink) = binfo;
1224 BASELINK_ACCESS_BINFO (baselink) = access_binfo;
1225 BASELINK_FUNCTIONS (baselink) = functions;
1226 BASELINK_OPTYPE (baselink) = optype;
1231 /* Look for a member named NAME in an inheritance lattice dominated by
1232 XBASETYPE. If PROTECT is 0 or two, we do not check access. If it
1233 is 1, we enforce accessibility. If PROTECT is zero, then, for an
1234 ambiguous lookup, we return NULL. If PROTECT is 1, we issue error
1235 messages about inaccessible or ambiguous lookup. If PROTECT is 2,
1236 we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
1237 TREE_VALUEs are the list of ambiguous candidates.
1239 WANT_TYPE is 1 when we should only return TYPE_DECLs.
1241 If nothing can be found return NULL_TREE and do not issue an error. */
1244 lookup_member (tree xbasetype, tree name, int protect, bool want_type)
1246 tree rval, rval_binfo = NULL_TREE;
1247 tree type = NULL_TREE, basetype_path = NULL_TREE;
1248 struct lookup_field_info lfi;
1250 /* rval_binfo is the binfo associated with the found member, note,
1251 this can be set with useful information, even when rval is not
1252 set, because it must deal with ALL members, not just non-function
1253 members. It is used for ambiguity checking and the hidden
1254 checks. Whereas rval is only set if a proper (not hidden)
1255 non-function member is found. */
1257 const char *errstr = 0;
1259 my_friendly_assert (TREE_CODE (name) == IDENTIFIER_NODE, 20030624);
1261 if (TREE_CODE (xbasetype) == TREE_VEC)
1263 type = BINFO_TYPE (xbasetype);
1264 basetype_path = xbasetype;
1268 my_friendly_assert (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)), 20030624);
1270 basetype_path = TYPE_BINFO (type);
1271 my_friendly_assert (!BINFO_INHERITANCE_CHAIN (basetype_path), 980827);
1274 if (type == current_class_type && TYPE_BEING_DEFINED (type)
1275 && IDENTIFIER_CLASS_VALUE (name))
1277 tree field = IDENTIFIER_CLASS_VALUE (name);
1278 if (! is_overloaded_fn (field)
1279 && ! (want_type && TREE_CODE (field) != TYPE_DECL))
1280 /* We're in the scope of this class, and the value has already
1281 been looked up. Just return the cached value. */
1285 complete_type (type);
1287 #ifdef GATHER_STATISTICS
1288 n_calls_lookup_field++;
1289 #endif /* GATHER_STATISTICS */
1291 memset (&lfi, 0, sizeof (lfi));
1294 lfi.want_type = want_type;
1295 bfs_walk (basetype_path, &lookup_field_r, &lookup_field_queue_p, &lfi);
1297 rval_binfo = lfi.rval_binfo;
1299 type = BINFO_TYPE (rval_binfo);
1300 errstr = lfi.errstr;
1302 /* If we are not interested in ambiguities, don't report them;
1303 just return NULL_TREE. */
1304 if (!protect && lfi.ambiguous)
1310 return lfi.ambiguous;
1317 In the case of overloaded function names, access control is
1318 applied to the function selected by overloaded resolution. */
1319 if (rval && protect && !is_overloaded_fn (rval))
1320 perform_or_defer_access_check (basetype_path, rval);
1322 if (errstr && protect)
1324 error (errstr, name, type);
1326 print_candidates (lfi.ambiguous);
1327 rval = error_mark_node;
1330 if (rval && is_overloaded_fn (rval))
1331 rval = build_baselink (rval_binfo, basetype_path, rval,
1332 (IDENTIFIER_TYPENAME_P (name)
1333 ? TREE_TYPE (name): NULL_TREE));
1337 /* Like lookup_member, except that if we find a function member we
1338 return NULL_TREE. */
1341 lookup_field (tree xbasetype, tree name, int protect, bool want_type)
1343 tree rval = lookup_member (xbasetype, name, protect, want_type);
1345 /* Ignore functions. */
1346 if (rval && BASELINK_P (rval))
1352 /* Like lookup_member, except that if we find a non-function member we
1353 return NULL_TREE. */
1356 lookup_fnfields (tree xbasetype, tree name, int protect)
1358 tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/false);
1360 /* Ignore non-functions. */
1361 if (rval && !BASELINK_P (rval))
1367 /* Return the index in the CLASSTYPE_METHOD_VEC for CLASS_TYPE
1368 corresponding to "operator TYPE ()", or -1 if there is no such
1369 operator. Only CLASS_TYPE itself is searched; this routine does
1370 not scan the base classes of CLASS_TYPE. */
1373 lookup_conversion_operator (tree class_type, tree type)
1378 tree methods = CLASSTYPE_METHOD_VEC (class_type);
1380 for (pass = 0; pass < 2; ++pass)
1381 for (i = CLASSTYPE_FIRST_CONVERSION_SLOT;
1382 i < TREE_VEC_LENGTH (methods);
1385 tree fn = TREE_VEC_ELT (methods, i);
1386 /* The size of the vector may have some unused slots at the
1391 /* All the conversion operators come near the beginning of the
1392 class. Therefore, if FN is not a conversion operator, there
1393 is no matching conversion operator in CLASS_TYPE. */
1394 fn = OVL_CURRENT (fn);
1395 if (!DECL_CONV_FN_P (fn))
1400 /* On the first pass we only consider exact matches. If
1401 the types match, this slot is the one where the right
1402 conversion operators can be found. */
1403 if (TREE_CODE (fn) != TEMPLATE_DECL
1404 && same_type_p (DECL_CONV_FN_TYPE (fn), type))
1409 /* On the second pass we look for template conversion
1410 operators. It may be possible to instantiate the
1411 template to get the type desired. All of the template
1412 conversion operators share a slot. By looking for
1413 templates second we ensure that specializations are
1414 preferred over templates. */
1415 if (TREE_CODE (fn) == TEMPLATE_DECL)
1423 /* TYPE is a class type. Return the index of the fields within
1424 the method vector with name NAME, or -1 is no such field exists. */
1427 lookup_fnfields_1 (tree type, tree name)
1435 if (!CLASS_TYPE_P (type))
1438 method_vec = CLASSTYPE_METHOD_VEC (type);
1443 methods = &TREE_VEC_ELT (method_vec, 0);
1444 len = TREE_VEC_LENGTH (method_vec);
1446 #ifdef GATHER_STATISTICS
1447 n_calls_lookup_fnfields_1++;
1448 #endif /* GATHER_STATISTICS */
1450 /* Constructors are first... */
1451 if (name == ctor_identifier)
1452 return (methods[CLASSTYPE_CONSTRUCTOR_SLOT]
1453 ? CLASSTYPE_CONSTRUCTOR_SLOT : -1);
1454 /* and destructors are second. */
1455 if (name == dtor_identifier)
1456 return (methods[CLASSTYPE_DESTRUCTOR_SLOT]
1457 ? CLASSTYPE_DESTRUCTOR_SLOT : -1);
1458 if (IDENTIFIER_TYPENAME_P (name))
1459 return lookup_conversion_operator (type, TREE_TYPE (name));
1461 /* Skip the conversion operators. */
1462 i = CLASSTYPE_FIRST_CONVERSION_SLOT;
1463 while (i < len && methods[i] && DECL_CONV_FN_P (OVL_CURRENT (methods[i])))
1466 /* If the type is complete, use binary search. */
1467 if (COMPLETE_TYPE_P (type))
1476 #ifdef GATHER_STATISTICS
1477 n_outer_fields_searched++;
1478 #endif /* GATHER_STATISTICS */
1481 /* This slot may be empty; we allocate more slots than we
1482 need. In that case, the entry we're looking for is
1483 closer to the beginning of the list. */
1485 tmp = DECL_NAME (OVL_CURRENT (tmp));
1486 if (!tmp || tmp > name)
1488 else if (tmp < name)
1495 for (; i < len && methods[i]; ++i)
1497 #ifdef GATHER_STATISTICS
1498 n_outer_fields_searched++;
1499 #endif /* GATHER_STATISTICS */
1501 tmp = OVL_CURRENT (methods[i]);
1502 if (DECL_NAME (tmp) == name)
1509 /* DECL is the result of a qualified name lookup. QUALIFYING_SCOPE is
1510 the class or namespace used to qualify the name. CONTEXT_CLASS is
1511 the class corresponding to the object in which DECL will be used.
1512 Return a possibly modified version of DECL that takes into account
1515 In particular, consider an expression like `B::m' in the context of
1516 a derived class `D'. If `B::m' has been resolved to a BASELINK,
1517 then the most derived class indicated by the BASELINK_BINFO will be
1518 `B', not `D'. This function makes that adjustment. */
1521 adjust_result_of_qualified_name_lookup (tree decl,
1522 tree qualifying_scope,
1525 if (context_class && CLASS_TYPE_P (qualifying_scope)
1526 && DERIVED_FROM_P (qualifying_scope, context_class)
1527 && BASELINK_P (decl))
1531 my_friendly_assert (CLASS_TYPE_P (context_class), 20020808);
1533 /* Look for the QUALIFYING_SCOPE as a base of the
1534 CONTEXT_CLASS. If QUALIFYING_SCOPE is ambiguous, we cannot
1535 be sure yet than an error has occurred; perhaps the function
1536 chosen by overload resolution will be static. */
1537 base = lookup_base (context_class, qualifying_scope,
1538 ba_ignore | ba_quiet, NULL);
1541 BASELINK_ACCESS_BINFO (decl) = base;
1542 BASELINK_BINFO (decl)
1543 = lookup_base (base, BINFO_TYPE (BASELINK_BINFO (decl)),
1544 ba_ignore | ba_quiet,
1553 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1554 type in the hierarchy, in a breadth-first preorder traversal.
1555 If it ever returns a non-NULL value, that value is immediately
1556 returned and the walk is terminated. At each node, FN is passed a
1557 BINFO indicating the path from the currently visited base-class to
1558 TYPE. Before each base-class is walked QFN is called. If the
1559 value returned is nonzero, the base-class is walked; otherwise it
1560 is not. If QFN is NULL, it is treated as a function which always
1561 returns 1. Both FN and QFN are passed the DATA whenever they are
1564 Implementation notes: Uses a circular queue, which starts off on
1565 the stack but gets moved to the malloc arena if it needs to be
1566 enlarged. The underflow and overflow conditions are
1567 indistinguishable except by context: if head == tail and we just
1568 moved the head pointer, the queue is empty, but if we just moved
1569 the tail pointer, the queue is full.
1570 Start with enough room for ten concurrent base classes. That
1571 will be enough for most hierarchies. */
1572 #define BFS_WALK_INITIAL_QUEUE_SIZE 10
1575 bfs_walk (tree binfo,
1576 tree (*fn) (tree, void *),
1577 tree (*qfn) (tree, int, void *),
1580 tree rval = NULL_TREE;
1582 tree bases_initial[BFS_WALK_INITIAL_QUEUE_SIZE];
1583 /* A circular queue of the base classes of BINFO. These will be
1584 built up in breadth-first order, except where QFN prunes the
1587 size_t base_buffer_size = BFS_WALK_INITIAL_QUEUE_SIZE;
1588 tree *base_buffer = bases_initial;
1591 base_buffer[tail++] = binfo;
1593 while (head != tail)
1596 tree binfo = base_buffer[head++];
1597 if (head == base_buffer_size)
1600 /* Is this the one we're looking for? If so, we're done. */
1601 rval = fn (binfo, data);
1605 n_bases = BINFO_N_BASETYPES (binfo);
1606 for (ix = 0; ix != n_bases; ix++)
1611 base_binfo = (*qfn) (binfo, ix, data);
1613 base_binfo = BINFO_BASETYPE (binfo, ix);
1617 base_buffer[tail++] = base_binfo;
1618 if (tail == base_buffer_size)
1622 tree *new_buffer = xmalloc (2 * base_buffer_size
1624 memcpy (&new_buffer[0], &base_buffer[0],
1625 tail * sizeof (tree));
1626 memcpy (&new_buffer[head + base_buffer_size],
1628 (base_buffer_size - head) * sizeof (tree));
1629 if (base_buffer_size != BFS_WALK_INITIAL_QUEUE_SIZE)
1631 base_buffer = new_buffer;
1632 head += base_buffer_size;
1633 base_buffer_size *= 2;
1640 if (base_buffer_size != BFS_WALK_INITIAL_QUEUE_SIZE)
1645 /* Exactly like bfs_walk, except that a depth-first traversal is
1646 performed, and PREFN is called in preorder, while POSTFN is called
1650 dfs_walk_real (tree binfo,
1651 tree (*prefn) (tree, void *),
1652 tree (*postfn) (tree, void *),
1653 tree (*qfn) (tree, int, void *),
1656 tree rval = NULL_TREE;
1658 /* Call the pre-order walking function. */
1661 rval = (*prefn) (binfo, data);
1666 /* Process the basetypes. */
1667 if (BINFO_BASETYPES (binfo))
1669 int i, n = TREE_VEC_LENGTH (BINFO_BASETYPES (binfo));
1670 for (i = 0; i != n; i++)
1675 base_binfo = (*qfn) (binfo, i, data);
1677 base_binfo = BINFO_BASETYPE (binfo, i);
1681 rval = dfs_walk_real (base_binfo, prefn, postfn, qfn, data);
1688 /* Call the post-order walking function. */
1690 rval = (*postfn) (binfo, data);
1695 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1699 dfs_walk (tree binfo,
1700 tree (*fn) (tree, void *),
1701 tree (*qfn) (tree, int, void *),
1704 return dfs_walk_real (binfo, 0, fn, qfn, data);
1707 /* Check that virtual overrider OVERRIDER is acceptable for base function
1708 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1711 check_final_overrider (tree overrider, tree basefn)
1713 tree over_type = TREE_TYPE (overrider);
1714 tree base_type = TREE_TYPE (basefn);
1715 tree over_return = TREE_TYPE (over_type);
1716 tree base_return = TREE_TYPE (base_type);
1717 tree over_throw = TYPE_RAISES_EXCEPTIONS (over_type);
1718 tree base_throw = TYPE_RAISES_EXCEPTIONS (base_type);
1721 if (same_type_p (base_return, over_return))
1723 else if ((CLASS_TYPE_P (over_return) && CLASS_TYPE_P (base_return))
1724 || (TREE_CODE (base_return) == TREE_CODE (over_return)
1725 && POINTER_TYPE_P (base_return)))
1727 /* Potentially covariant. */
1728 unsigned base_quals, over_quals;
1730 fail = !POINTER_TYPE_P (base_return);
1733 fail = cp_type_quals (base_return) != cp_type_quals (over_return);
1735 base_return = TREE_TYPE (base_return);
1736 over_return = TREE_TYPE (over_return);
1738 base_quals = cp_type_quals (base_return);
1739 over_quals = cp_type_quals (over_return);
1741 if ((base_quals & over_quals) != over_quals)
1744 if (CLASS_TYPE_P (base_return) && CLASS_TYPE_P (over_return))
1746 tree binfo = lookup_base (over_return, base_return,
1747 ba_check | ba_quiet, NULL);
1753 && can_convert (TREE_TYPE (base_type), TREE_TYPE (over_type)))
1754 /* GNU extension, allow trivial pointer conversions such as
1755 converting to void *, or qualification conversion. */
1757 /* can_convert will permit user defined conversion from a
1758 (reference to) class type. We must reject them. */
1759 over_return = TREE_TYPE (over_type);
1760 if (TREE_CODE (over_return) == REFERENCE_TYPE)
1761 over_return = TREE_TYPE (over_return);
1762 if (CLASS_TYPE_P (over_return))
1772 else if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider)))
1778 cp_error_at ("invalid covariant return type for `%#D'", overrider);
1779 cp_error_at (" overriding `%#D'", basefn);
1783 cp_error_at ("conflicting return type specified for `%#D'",
1785 cp_error_at (" overriding `%#D'", basefn);
1787 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider),
1788 DECL_CONTEXT (overrider));
1792 /* Check throw specifier is at least as strict. */
1793 if (!comp_except_specs (base_throw, over_throw, 0))
1795 if (!IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider)))
1797 cp_error_at ("looser throw specifier for `%#F'", overrider);
1798 cp_error_at (" overriding `%#F'", basefn);
1799 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider),
1800 DECL_CONTEXT (overrider));
1808 /* Given a class TYPE, and a function decl FNDECL, look for
1809 virtual functions in TYPE's hierarchy which FNDECL overrides.
1810 We do not look in TYPE itself, only its bases.
1812 Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
1813 find that it overrides anything.
1815 We check that every function which is overridden, is correctly
1819 look_for_overrides (tree type, tree fndecl)
1821 tree binfo = TYPE_BINFO (type);
1822 tree basebinfos = BINFO_BASETYPES (binfo);
1823 int nbasebinfos = basebinfos ? TREE_VEC_LENGTH (basebinfos) : 0;
1827 for (ix = 0; ix != nbasebinfos; ix++)
1829 tree basetype = BINFO_TYPE (TREE_VEC_ELT (basebinfos, ix));
1831 if (TYPE_POLYMORPHIC_P (basetype))
1832 found += look_for_overrides_r (basetype, fndecl);
1837 /* Look in TYPE for virtual functions with the same signature as
1841 look_for_overrides_here (tree type, tree fndecl)
1845 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fndecl))
1846 ix = CLASSTYPE_DESTRUCTOR_SLOT;
1848 ix = lookup_fnfields_1 (type, DECL_NAME (fndecl));
1851 tree fns = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), ix);
1853 for (; fns; fns = OVL_NEXT (fns))
1855 tree fn = OVL_CURRENT (fns);
1857 if (!DECL_VIRTUAL_P (fn))
1858 /* Not a virtual. */;
1859 else if (DECL_CONTEXT (fn) != type)
1860 /* Introduced with a using declaration. */;
1861 else if (DECL_STATIC_FUNCTION_P (fndecl))
1863 tree btypes = TYPE_ARG_TYPES (TREE_TYPE (fn));
1864 tree dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1865 if (compparms (TREE_CHAIN (btypes), dtypes))
1868 else if (same_signature_p (fndecl, fn))
1875 /* Look in TYPE for virtual functions overridden by FNDECL. Check both
1876 TYPE itself and its bases. */
1879 look_for_overrides_r (tree type, tree fndecl)
1881 tree fn = look_for_overrides_here (type, fndecl);
1884 if (DECL_STATIC_FUNCTION_P (fndecl))
1886 /* A static member function cannot match an inherited
1887 virtual member function. */
1888 cp_error_at ("`%#D' cannot be declared", fndecl);
1889 cp_error_at (" since `%#D' declared in base class", fn);
1893 /* It's definitely virtual, even if not explicitly set. */
1894 DECL_VIRTUAL_P (fndecl) = 1;
1895 check_final_overrider (fndecl, fn);
1900 /* We failed to find one declared in this class. Look in its bases. */
1901 return look_for_overrides (type, fndecl);
1904 /* Called via dfs_walk from dfs_get_pure_virtuals. */
1907 dfs_get_pure_virtuals (tree binfo, void *data)
1909 tree type = (tree) data;
1911 /* We're not interested in primary base classes; the derived class
1912 of which they are a primary base will contain the information we
1914 if (!BINFO_PRIMARY_P (binfo))
1918 for (virtuals = BINFO_VIRTUALS (binfo);
1920 virtuals = TREE_CHAIN (virtuals))
1921 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals)))
1922 CLASSTYPE_PURE_VIRTUALS (type)
1923 = tree_cons (NULL_TREE, BV_FN (virtuals),
1924 CLASSTYPE_PURE_VIRTUALS (type));
1927 BINFO_MARKED (binfo) = 1;
1932 /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
1935 get_pure_virtuals (tree type)
1939 /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
1940 is going to be overridden. */
1941 CLASSTYPE_PURE_VIRTUALS (type) = NULL_TREE;
1942 /* Now, run through all the bases which are not primary bases, and
1943 collect the pure virtual functions. We look at the vtable in
1944 each class to determine what pure virtual functions are present.
1945 (A primary base is not interesting because the derived class of
1946 which it is a primary base will contain vtable entries for the
1947 pure virtuals in the base class. */
1948 dfs_walk (TYPE_BINFO (type), dfs_get_pure_virtuals, unmarkedp, type);
1949 dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp, type);
1951 /* Put the pure virtuals in dfs order. */
1952 CLASSTYPE_PURE_VIRTUALS (type) = nreverse (CLASSTYPE_PURE_VIRTUALS (type));
1954 for (vbases = CLASSTYPE_VBASECLASSES (type);
1956 vbases = TREE_CHAIN (vbases))
1960 for (virtuals = BINFO_VIRTUALS (TREE_VALUE (vbases));
1962 virtuals = TREE_CHAIN (virtuals))
1964 tree base_fndecl = BV_FN (virtuals);
1965 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl))
1966 error ("`%#D' needs a final overrider", base_fndecl);
1971 /* DEPTH-FIRST SEARCH ROUTINES. */
1974 markedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
1976 tree binfo = BINFO_BASETYPE (derived, ix);
1978 return BINFO_MARKED (binfo) ? binfo : NULL_TREE;
1982 unmarkedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
1984 tree binfo = BINFO_BASETYPE (derived, ix);
1986 return !BINFO_MARKED (binfo) ? binfo : NULL_TREE;
1990 marked_pushdecls_p (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
1992 tree binfo = BINFO_BASETYPE (derived, ix);
1994 return (!BINFO_DEPENDENT_BASE_P (binfo)
1995 && BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
1999 unmarked_pushdecls_p (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
2001 tree binfo = BINFO_BASETYPE (derived, ix);
2003 return (!BINFO_DEPENDENT_BASE_P (binfo)
2004 && !BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
2007 /* The worker functions for `dfs_walk'. These do not need to
2008 test anything (vis a vis marking) if they are paired with
2009 a predicate function (above). */
2012 dfs_unmark (tree binfo, void *data ATTRIBUTE_UNUSED)
2014 BINFO_MARKED (binfo) = 0;
2019 /* Debug info for C++ classes can get very large; try to avoid
2020 emitting it everywhere.
2022 Note that this optimization wins even when the target supports
2023 BINCL (if only slightly), and reduces the amount of work for the
2027 maybe_suppress_debug_info (tree t)
2029 /* We can't do the usual TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2030 does not support name references between translation units. It supports
2031 symbolic references between translation units, but only within a single
2032 executable or shared library.
2034 For DWARF 2, we handle TYPE_DECL_SUPPRESS_DEBUG by pretending
2035 that the type was never defined, so we only get the members we
2037 if (write_symbols == DWARF_DEBUG || write_symbols == NO_DEBUG)
2040 /* We might have set this earlier in cp_finish_decl. */
2041 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
2043 /* If we already know how we're handling this class, handle debug info
2045 if (CLASSTYPE_INTERFACE_KNOWN (t))
2047 if (CLASSTYPE_INTERFACE_ONLY (t))
2048 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
2049 /* else don't set it. */
2051 /* If the class has a vtable, write out the debug info along with
2053 else if (TYPE_CONTAINS_VPTR_P (t))
2054 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
2056 /* Otherwise, just emit the debug info normally. */
2059 /* Note that we want debugging information for a base class of a class
2060 whose vtable is being emitted. Normally, this would happen because
2061 calling the constructor for a derived class implies calling the
2062 constructors for all bases, which involve initializing the
2063 appropriate vptr with the vtable for the base class; but in the
2064 presence of optimization, this initialization may be optimized
2065 away, so we tell finish_vtable_vardecl that we want the debugging
2066 information anyway. */
2069 dfs_debug_mark (tree binfo, void *data ATTRIBUTE_UNUSED)
2071 tree t = BINFO_TYPE (binfo);
2073 CLASSTYPE_DEBUG_REQUESTED (t) = 1;
2078 /* Returns BINFO if we haven't already noted that we want debugging
2079 info for this base class. */
2082 dfs_debug_unmarkedp (tree derived, int ix, void *data ATTRIBUTE_UNUSED)
2084 tree binfo = BINFO_BASETYPE (derived, ix);
2086 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo))
2087 ? binfo : NULL_TREE);
2090 /* Write out the debugging information for TYPE, whose vtable is being
2091 emitted. Also walk through our bases and note that we want to
2092 write out information for them. This avoids the problem of not
2093 writing any debug info for intermediate basetypes whose
2094 constructors, and thus the references to their vtables, and thus
2095 the vtables themselves, were optimized away. */
2098 note_debug_info_needed (tree type)
2100 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
2102 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)) = 0;
2103 rest_of_type_compilation (type, toplevel_bindings_p ());
2106 dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp, 0);
2109 /* Subroutines of push_class_decls (). */
2112 setup_class_bindings (tree name, int type_binding_p)
2114 tree type_binding = NULL_TREE;
2117 /* If we've already done the lookup for this declaration, we're
2119 if (IDENTIFIER_CLASS_VALUE (name))
2122 /* First, deal with the type binding. */
2125 type_binding = lookup_member (current_class_type, name,
2126 /*protect=*/2, /*want_type=*/true);
2127 if (TREE_CODE (type_binding) == TREE_LIST
2128 && TREE_TYPE (type_binding) == error_mark_node)
2129 /* NAME is ambiguous. */
2130 push_class_level_binding (name, type_binding);
2132 pushdecl_class_level (type_binding);
2135 /* Now, do the value binding. */
2136 value_binding = lookup_member (current_class_type, name,
2137 /*protect=*/2, /*want_type=*/false);
2140 && (TREE_CODE (value_binding) == TYPE_DECL
2141 || DECL_CLASS_TEMPLATE_P (value_binding)
2142 || (TREE_CODE (value_binding) == TREE_LIST
2143 && TREE_TYPE (value_binding) == error_mark_node
2144 && (TREE_CODE (TREE_VALUE (value_binding))
2146 /* We found a type-binding, even when looking for a non-type
2147 binding. This means that we already processed this binding
2149 else if (value_binding)
2151 if (TREE_CODE (value_binding) == TREE_LIST
2152 && TREE_TYPE (value_binding) == error_mark_node)
2153 /* NAME is ambiguous. */
2154 push_class_level_binding (name, value_binding);
2157 if (BASELINK_P (value_binding))
2158 /* NAME is some overloaded functions. */
2159 value_binding = BASELINK_FUNCTIONS (value_binding);
2160 pushdecl_class_level (value_binding);
2165 /* Push class-level declarations for any names appearing in BINFO that
2169 dfs_push_type_decls (tree binfo, void *data ATTRIBUTE_UNUSED)
2174 type = BINFO_TYPE (binfo);
2175 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2176 if (DECL_NAME (fields) && TREE_CODE (fields) == TYPE_DECL
2177 && !(!same_type_p (type, current_class_type)
2178 && template_self_reference_p (type, fields)))
2179 setup_class_bindings (DECL_NAME (fields), /*type_binding_p=*/1);
2181 /* We can't just use BINFO_MARKED because envelope_add_decl uses
2182 DERIVED_FROM_P, which calls get_base_distance. */
2183 BINFO_PUSHDECLS_MARKED (binfo) = 1;
2188 /* Push class-level declarations for any names appearing in BINFO that
2189 are not TYPE_DECLS. */
2192 dfs_push_decls (tree binfo, void *data)
2194 tree type = BINFO_TYPE (binfo);
2198 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2199 if (DECL_NAME (fields)
2200 && TREE_CODE (fields) != TYPE_DECL
2201 && TREE_CODE (fields) != USING_DECL
2202 && !DECL_ARTIFICIAL (fields))
2203 setup_class_bindings (DECL_NAME (fields), /*type_binding_p=*/0);
2204 else if (TREE_CODE (fields) == FIELD_DECL
2205 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
2206 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields)), data);
2208 method_vec = (CLASS_TYPE_P (type)
2209 ? CLASSTYPE_METHOD_VEC (type) : NULL_TREE);
2211 if (method_vec && TREE_VEC_LENGTH (method_vec) >= 3)
2216 /* Farm out constructors and destructors. */
2217 end = TREE_VEC_END (method_vec);
2219 for (methods = &TREE_VEC_ELT (method_vec, 2);
2220 methods < end && *methods;
2222 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods)),
2223 /*type_binding_p=*/0);
2226 BINFO_PUSHDECLS_MARKED (binfo) = 0;
2231 /* When entering the scope of a class, we cache all of the
2232 fields that that class provides within its inheritance
2233 lattice. Where ambiguities result, we mark them
2234 with `error_mark_node' so that if they are encountered
2235 without explicit qualification, we can emit an error
2239 push_class_decls (tree type)
2241 search_stack = push_search_level (search_stack, &search_obstack);
2243 /* Enter type declarations and mark. */
2244 dfs_walk (TYPE_BINFO (type), dfs_push_type_decls, unmarked_pushdecls_p, 0);
2246 /* Enter non-type declarations and unmark. */
2247 dfs_walk (TYPE_BINFO (type), dfs_push_decls, marked_pushdecls_p, 0);
2250 /* Here's a subroutine we need because C lacks lambdas. */
2253 dfs_unuse_fields (tree binfo, void *data ATTRIBUTE_UNUSED)
2255 tree type = TREE_TYPE (binfo);
2258 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2260 if (TREE_CODE (fields) != FIELD_DECL || DECL_ARTIFICIAL (fields))
2263 TREE_USED (fields) = 0;
2264 if (DECL_NAME (fields) == NULL_TREE
2265 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
2266 unuse_fields (TREE_TYPE (fields));
2273 unuse_fields (tree type)
2275 dfs_walk (TYPE_BINFO (type), dfs_unuse_fields, unmarkedp, 0);
2281 /* We haven't pushed a search level when dealing with cached classes,
2282 so we'd better not try to pop it. */
2284 search_stack = pop_search_level (search_stack);
2288 print_search_statistics ()
2290 #ifdef GATHER_STATISTICS
2291 fprintf (stderr, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
2292 n_fields_searched, n_calls_lookup_field, n_calls_lookup_field_1);
2293 fprintf (stderr, "%d fnfields searched in %d calls to lookup_fnfields\n",
2294 n_outer_fields_searched, n_calls_lookup_fnfields);
2295 fprintf (stderr, "%d calls to get_base_type\n", n_calls_get_base_type);
2296 #else /* GATHER_STATISTICS */
2297 fprintf (stderr, "no search statistics\n");
2298 #endif /* GATHER_STATISTICS */
2302 init_search_processing ()
2304 gcc_obstack_init (&search_obstack);
2308 reinit_search_statistics ()
2310 #ifdef GATHER_STATISTICS
2311 n_fields_searched = 0;
2312 n_calls_lookup_field = 0, n_calls_lookup_field_1 = 0;
2313 n_calls_lookup_fnfields = 0, n_calls_lookup_fnfields_1 = 0;
2314 n_calls_get_base_type = 0;
2315 n_outer_fields_searched = 0;
2316 n_contexts_saved = 0;
2317 #endif /* GATHER_STATISTICS */
2321 add_conversions (tree binfo, void *data)
2324 tree method_vec = CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo));
2325 tree *conversions = (tree *) data;
2327 /* Some builtin types have no method vector, not even an empty one. */
2331 for (i = 2; i < TREE_VEC_LENGTH (method_vec); ++i)
2333 tree tmp = TREE_VEC_ELT (method_vec, i);
2336 if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp)))
2339 name = DECL_NAME (OVL_CURRENT (tmp));
2341 /* Make sure we don't already have this conversion. */
2342 if (! IDENTIFIER_MARKED (name))
2344 *conversions = tree_cons (binfo, tmp, *conversions);
2345 IDENTIFIER_MARKED (name) = 1;
2351 /* Return a TREE_LIST containing all the non-hidden user-defined
2352 conversion functions for TYPE (and its base-classes). The
2353 TREE_VALUE of each node is a FUNCTION_DECL or an OVERLOAD
2354 containing the conversion functions. The TREE_PURPOSE is the BINFO
2355 from which the conversion functions in this node were selected. */
2358 lookup_conversions (tree type)
2361 tree conversions = NULL_TREE;
2363 complete_type (type);
2364 bfs_walk (TYPE_BINFO (type), add_conversions, 0, &conversions);
2366 for (t = conversions; t; t = TREE_CHAIN (t))
2367 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t)))) = 0;
2378 /* Check whether the empty class indicated by EMPTY_BINFO is also present
2379 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
2382 dfs_check_overlap (tree empty_binfo, void *data)
2384 struct overlap_info *oi = (struct overlap_info *) data;
2386 for (binfo = TYPE_BINFO (oi->compare_type);
2388 binfo = BINFO_BASETYPE (binfo, 0))
2390 if (BINFO_TYPE (binfo) == BINFO_TYPE (empty_binfo))
2392 oi->found_overlap = 1;
2395 else if (BINFO_BASETYPES (binfo) == NULL_TREE)
2402 /* Trivial function to stop base traversal when we find something. */
2405 dfs_no_overlap_yet (tree derived, int ix, void *data)
2407 tree binfo = BINFO_BASETYPE (derived, ix);
2408 struct overlap_info *oi = (struct overlap_info *) data;
2410 return !oi->found_overlap ? binfo : NULL_TREE;
2413 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
2414 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
2417 types_overlap_p (tree empty_type, tree next_type)
2419 struct overlap_info oi;
2421 if (! IS_AGGR_TYPE (next_type))
2423 oi.compare_type = next_type;
2424 oi.found_overlap = 0;
2425 dfs_walk (TYPE_BINFO (empty_type), dfs_check_overlap,
2426 dfs_no_overlap_yet, &oi);
2427 return oi.found_overlap;
2430 /* Given a vtable VAR, determine which of the inherited classes the vtable
2431 inherits (in a loose sense) functions from.
2433 FIXME: This does not work with the new ABI. */
2436 binfo_for_vtable (tree var)
2438 tree main_binfo = TYPE_BINFO (DECL_CONTEXT (var));
2439 tree binfos = TYPE_BINFO_BASETYPES (BINFO_TYPE (main_binfo));
2440 int n_baseclasses = CLASSTYPE_N_BASECLASSES (BINFO_TYPE (main_binfo));
2443 for (i = 0; i < n_baseclasses; i++)
2445 tree base_binfo = TREE_VEC_ELT (binfos, i);
2446 if (base_binfo != NULL_TREE && BINFO_VTABLE (base_binfo) == var)
2450 /* If no secondary base classes matched, return the primary base, if
2452 if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (main_binfo)))
2453 return get_primary_binfo (main_binfo);
2458 /* Returns the binfo of the first direct or indirect virtual base derived
2459 from BINFO, or NULL if binfo is not via virtual. */
2462 binfo_from_vbase (tree binfo)
2464 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
2466 if (TREE_VIA_VIRTUAL (binfo))
2472 /* Returns the binfo of the first direct or indirect virtual base derived
2473 from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
2477 binfo_via_virtual (tree binfo, tree limit)
2479 for (; binfo && (!limit || !same_type_p (BINFO_TYPE (binfo), limit));
2480 binfo = BINFO_INHERITANCE_CHAIN (binfo))
2482 if (TREE_VIA_VIRTUAL (binfo))
2488 /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
2489 Find the equivalent binfo within whatever graph HERE is located.
2490 This is the inverse of original_binfo. */
2493 copied_binfo (tree binfo, tree here)
2495 tree result = NULL_TREE;
2497 if (TREE_VIA_VIRTUAL (binfo))
2501 for (t = here; BINFO_INHERITANCE_CHAIN (t);
2502 t = BINFO_INHERITANCE_CHAIN (t))
2505 result = purpose_member (BINFO_TYPE (binfo),
2506 CLASSTYPE_VBASECLASSES (BINFO_TYPE (t)));
2507 result = TREE_VALUE (result);
2509 else if (BINFO_INHERITANCE_CHAIN (binfo))
2514 base_binfos = copied_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
2515 base_binfos = BINFO_BASETYPES (base_binfos);
2516 n = TREE_VEC_LENGTH (base_binfos);
2517 for (ix = 0; ix != n; ix++)
2519 tree base = TREE_VEC_ELT (base_binfos, ix);
2521 if (BINFO_TYPE (base) == BINFO_TYPE (binfo))
2530 my_friendly_assert (BINFO_TYPE (here) == BINFO_TYPE (binfo), 20030202);
2534 my_friendly_assert (result, 20030202);
2538 /* BINFO is some base binfo of HERE, within some other
2539 hierarchy. Return the equivalent binfo, but in the hierarchy
2540 dominated by HERE. This is the inverse of copied_binfo. If BINFO
2541 is not a base binfo of HERE, returns NULL_TREE. */
2544 original_binfo (tree binfo, tree here)
2548 if (BINFO_TYPE (binfo) == BINFO_TYPE (here))
2550 else if (TREE_VIA_VIRTUAL (binfo))
2552 result = purpose_member (BINFO_TYPE (binfo),
2553 CLASSTYPE_VBASECLASSES (BINFO_TYPE (here)));
2555 result = TREE_VALUE (result);
2557 else if (BINFO_INHERITANCE_CHAIN (binfo))
2561 base_binfos = original_binfo (BINFO_INHERITANCE_CHAIN (binfo), here);
2566 base_binfos = BINFO_BASETYPES (base_binfos);
2567 n = TREE_VEC_LENGTH (base_binfos);
2568 for (ix = 0; ix != n; ix++)
2570 tree base = TREE_VEC_ELT (base_binfos, ix);
2572 if (BINFO_TYPE (base) == BINFO_TYPE (binfo))