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
lookup_field_1 (tree
, tree
, bool);
85 static tree
dfs_check_overlap (tree
, void *);
86 static tree
dfs_no_overlap_yet (tree
, int, void *);
87 static base_kind
lookup_base_r (tree
, tree
, base_access
,
88 bool, bool, bool, tree
*);
89 static int dynamic_cast_base_recurse (tree
, tree
, bool, tree
*);
90 static tree
marked_pushdecls_p (tree
, int, void *);
91 static tree
unmarked_pushdecls_p (tree
, int, void *);
92 static tree
dfs_debug_unmarkedp (tree
, int, void *);
93 static tree
dfs_debug_mark (tree
, void *);
94 static tree
dfs_push_type_decls (tree
, void *);
95 static tree
dfs_push_decls (tree
, void *);
96 static tree
dfs_unuse_fields (tree
, void *);
97 static tree
add_conversions (tree
, void *);
98 static int look_for_overrides_r (tree
, tree
);
99 static struct search_level
*push_search_level (struct stack_level
*,
101 static struct search_level
*pop_search_level (struct stack_level
*);
102 static tree
bfs_walk (tree
, tree (*) (tree
, void *),
103 tree (*) (tree
, int, void *), void *);
104 static tree
lookup_field_queue_p (tree
, int, void *);
105 static int shared_member_p (tree
);
106 static tree
lookup_field_r (tree
, void *);
107 static tree
dfs_accessible_queue_p (tree
, int, void *);
108 static tree
dfs_accessible_p (tree
, void *);
109 static tree
dfs_access_in_type (tree
, void *);
110 static access_kind
access_in_type (tree
, tree
);
111 static int protected_accessible_p (tree
, tree
, tree
);
112 static int friend_accessible_p (tree
, tree
, tree
);
113 static void setup_class_bindings (tree
, int);
114 static int template_self_reference_p (tree
, tree
);
115 static tree
dfs_get_pure_virtuals (tree
, void *);
117 /* Allocate a level of searching. */
119 static struct search_level
*
120 push_search_level (struct stack_level
*stack
, struct obstack
*obstack
)
122 struct search_level tem
;
125 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
128 /* Discard a level of search allocation. */
130 static struct search_level
*
131 pop_search_level (struct stack_level
*obstack
)
133 register struct search_level
*stack
= pop_stack_level (obstack
);
138 /* Variables for gathering statistics. */
139 #ifdef GATHER_STATISTICS
140 static int n_fields_searched
;
141 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
142 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
143 static int n_calls_get_base_type
;
144 static int n_outer_fields_searched
;
145 static int n_contexts_saved
;
146 #endif /* GATHER_STATISTICS */
149 /* Worker for lookup_base. BINFO is the binfo we are searching at,
150 BASE is the RECORD_TYPE we are searching for. ACCESS is the
151 required access checks. WITHIN_CURRENT_SCOPE, IS_NON_PUBLIC and
152 IS_VIRTUAL indicate how BINFO was reached from the start of the
153 search. WITHIN_CURRENT_SCOPE is true if we met the current scope,
154 or friend thereof (this allows us to determine whether a protected
155 base is accessible or not). IS_NON_PUBLIC indicates whether BINFO
156 is accessible and IS_VIRTUAL indicates if it is morally virtual.
158 If BINFO is of the required type, then *BINFO_PTR is examined to
159 compare with any other instance of BASE we might have already
160 discovered. *BINFO_PTR is initialized and a base_kind return value
161 indicates what kind of base was located.
163 Otherwise BINFO's bases are searched. */
166 lookup_base_r (tree binfo
, tree base
, base_access access
,
167 bool within_current_scope
,
168 bool is_non_public
, /* inside a non-public part */
169 bool is_virtual
, /* inside a virtual part */
173 tree bases
, accesses
;
174 base_kind found
= bk_not_base
;
176 if (access
== ba_check
177 && !within_current_scope
178 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
180 /* Do not clear is_non_public here. If A is a private base of B, A
181 is not allowed to convert a B* to an A*. */
182 within_current_scope
= 1;
185 if (same_type_p (BINFO_TYPE (binfo
), base
))
187 /* We have found a base. Check against what we have found
189 found
= bk_same_type
;
191 found
= bk_via_virtual
;
193 found
= bk_inaccessible
;
197 else if (binfo
!= *binfo_ptr
)
199 if (access
!= ba_any
)
201 else if (!is_virtual
)
202 /* Prefer a non-virtual base. */
210 bases
= BINFO_BASETYPES (binfo
);
211 accesses
= BINFO_BASEACCESSES (binfo
);
215 for (i
= TREE_VEC_LENGTH (bases
); i
--;)
217 tree base_binfo
= TREE_VEC_ELT (bases
, i
);
218 tree base_access
= TREE_VEC_ELT (accesses
, i
);
220 int this_non_public
= is_non_public
;
221 int this_virtual
= is_virtual
;
224 if (access
<= ba_ignore
)
226 else if (base_access
== access_public_node
)
228 else if (access
== ba_not_special
)
230 else if (base_access
== access_protected_node
&& within_current_scope
)
232 else if (is_friend (BINFO_TYPE (binfo
), current_scope ()))
237 if (TREE_VIA_VIRTUAL (base_binfo
))
240 bk
= lookup_base_r (base_binfo
, base
,
241 access
, within_current_scope
,
242 this_non_public
, this_virtual
,
248 if (access
!= ba_any
)
253 case bk_inaccessible
:
254 if (found
== bk_not_base
)
256 my_friendly_assert (found
== bk_via_virtual
257 || found
== bk_inaccessible
, 20010723);
265 my_friendly_assert (found
== bk_not_base
, 20010723);
270 if (found
!= bk_ambig
)
281 /* Lookup BASE in the hierarchy dominated by T. Do access checking as
282 ACCESS specifies. Return the binfo we discover. If KIND_PTR is
283 non-NULL, fill with information about what kind of base we
286 If the base is inaccessible, or ambiguous, and the ba_quiet bit is
287 not set in ACCESS, then an error is issued and error_mark_node is
288 returned. If the ba_quiet bit is set, then no error is issued and
289 NULL_TREE is returned. */
292 lookup_base (tree t
, tree base
, base_access access
, base_kind
*kind_ptr
)
294 tree binfo
= NULL
; /* The binfo we've found so far. */
298 if (t
== error_mark_node
|| base
== error_mark_node
)
301 *kind_ptr
= bk_not_base
;
302 return error_mark_node
;
304 my_friendly_assert (TYPE_P (base
), 20011127);
312 t_binfo
= TYPE_BINFO (t
);
314 /* Ensure that the types are instantiated. */
315 t
= complete_type (TYPE_MAIN_VARIANT (t
));
316 base
= complete_type (TYPE_MAIN_VARIANT (base
));
318 bk
= lookup_base_r (t_binfo
, base
, access
& ~ba_quiet
,
323 case bk_inaccessible
:
325 if (!(access
& ba_quiet
))
327 error ("`%T' is an inaccessible base of `%T'", base
, t
);
328 binfo
= error_mark_node
;
332 if (access
!= ba_any
)
335 if (!(access
& ba_quiet
))
337 error ("`%T' is an ambiguous base of `%T'", base
, t
);
338 binfo
= error_mark_node
;
351 /* Worker function for get_dynamic_cast_base_type. */
354 dynamic_cast_base_recurse (tree subtype
, tree binfo
, bool is_via_virtual
,
357 tree binfos
, accesses
;
361 if (BINFO_TYPE (binfo
) == subtype
)
367 *offset_ptr
= BINFO_OFFSET (binfo
);
372 binfos
= BINFO_BASETYPES (binfo
);
373 accesses
= BINFO_BASEACCESSES (binfo
);
374 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
375 for (i
= 0; i
< n_baselinks
; i
++)
377 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
378 tree base_access
= TREE_VEC_ELT (accesses
, i
);
381 if (base_access
!= access_public_node
)
383 rval
= dynamic_cast_base_recurse
384 (subtype
, base_binfo
,
385 is_via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
), offset_ptr
);
389 worst
= worst
>= 0 ? -3 : worst
;
392 else if (rval
== -3 && worst
!= -1)
398 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
399 started from is related to the required TARGET type, in order to optimize
400 the inheritance graph search. This information is independent of the
401 current context, and ignores private paths, hence get_base_distance is
402 inappropriate. Return a TREE specifying the base offset, BOFF.
403 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
404 and there are no public virtual SUBTYPE bases.
405 BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
406 BOFF == -2, SUBTYPE is not a public base.
407 BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
410 get_dynamic_cast_base_type (tree subtype
, tree target
)
412 tree offset
= NULL_TREE
;
413 int boff
= dynamic_cast_base_recurse (subtype
, TYPE_BINFO (target
),
418 offset
= build_int_2 (boff
, -1);
419 TREE_TYPE (offset
) = ssizetype
;
423 /* Search for a member with name NAME in a multiple inheritance
424 lattice specified by TYPE. If it does not exist, return NULL_TREE.
425 If the member is ambiguously referenced, return `error_mark_node'.
426 Otherwise, return a DECL with the indicated name. If WANT_TYPE is
427 true, type declarations are preferred. */
429 /* Do a 1-level search for NAME as a member of TYPE. The caller must
430 figure out whether it can access this field. (Since it is only one
431 level, this is reasonable.) */
434 lookup_field_1 (tree type
, tree name
, bool want_type
)
438 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
439 || TREE_CODE (type
) == BOUND_TEMPLATE_TEMPLATE_PARM
440 || TREE_CODE (type
) == TYPENAME_TYPE
)
441 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM and
442 BOUND_TEMPLATE_TEMPLATE_PARM are not fields at all;
443 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
444 the code often worked even when we treated the index as a list
446 The TYPE_FIELDS of TYPENAME_TYPE is its TYPENAME_TYPE_FULLNAME. */
450 && DECL_LANG_SPECIFIC (TYPE_NAME (type
))
451 && DECL_SORTED_FIELDS (TYPE_NAME (type
)))
453 tree
*fields
= &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type
)), 0);
454 int lo
= 0, hi
= TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type
)));
461 #ifdef GATHER_STATISTICS
463 #endif /* GATHER_STATISTICS */
465 if (DECL_NAME (fields
[i
]) > name
)
467 else if (DECL_NAME (fields
[i
]) < name
)
473 /* We might have a nested class and a field with the
474 same name; we sorted them appropriately via
475 field_decl_cmp, so just look for the first or last
476 field with this name. */
481 while (i
>= lo
&& DECL_NAME (fields
[i
]) == name
);
482 if (TREE_CODE (field
) != TYPE_DECL
483 && !DECL_CLASS_TEMPLATE_P (field
))
490 while (i
< hi
&& DECL_NAME (fields
[i
]) == name
);
498 field
= TYPE_FIELDS (type
);
500 #ifdef GATHER_STATISTICS
501 n_calls_lookup_field_1
++;
502 #endif /* GATHER_STATISTICS */
503 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
505 #ifdef GATHER_STATISTICS
507 #endif /* GATHER_STATISTICS */
508 my_friendly_assert (DECL_P (field
), 0);
509 if (DECL_NAME (field
) == NULL_TREE
510 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
512 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
, want_type
);
516 if (TREE_CODE (field
) == USING_DECL
)
517 /* For now, we're just treating member using declarations as
518 old ARM-style access declarations. Thus, there's no reason
519 to return a USING_DECL, and the rest of the compiler can't
520 handle it. Once the class is defined, these are purged
521 from TYPE_FIELDS anyhow; see handle_using_decl. */
524 if (DECL_NAME (field
) == name
526 || TREE_CODE (field
) == TYPE_DECL
527 || DECL_CLASS_TEMPLATE_P (field
)))
531 if (name
== vptr_identifier
)
533 /* Give the user what s/he thinks s/he wants. */
534 if (TYPE_POLYMORPHIC_P (type
))
535 return TYPE_VFIELD (type
);
540 /* There are a number of cases we need to be aware of here:
541 current_class_type current_function_decl
548 Those last two make life interesting. If we're in a function which is
549 itself inside a class, we need decls to go into the fn's decls (our
550 second case below). But if we're in a class and the class itself is
551 inside a function, we need decls to go into the decls for the class. To
552 achieve this last goal, we must see if, when both current_class_ptr and
553 current_function_decl are set, the class was declared inside that
554 function. If so, we know to put the decls into the class's scope. */
559 if (current_function_decl
== NULL_TREE
)
560 return current_class_type
;
561 if (current_class_type
== NULL_TREE
)
562 return current_function_decl
;
563 if ((DECL_FUNCTION_MEMBER_P (current_function_decl
)
564 && same_type_p (DECL_CONTEXT (current_function_decl
),
566 || (DECL_FRIEND_CONTEXT (current_function_decl
)
567 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl
),
568 current_class_type
)))
569 return current_function_decl
;
571 return current_class_type
;
574 /* Returns nonzero if we are currently in a function scope. Note
575 that this function returns zero if we are within a local class, but
576 not within a member function body of the local class. */
579 at_function_scope_p ()
581 tree cs
= current_scope ();
582 return cs
&& TREE_CODE (cs
) == FUNCTION_DECL
;
585 /* Returns true if the innermost active scope is a class scope. */
590 tree cs
= current_scope ();
591 return cs
&& TYPE_P (cs
);
594 /* Return the scope of DECL, as appropriate when doing name-lookup. */
597 context_for_name_lookup (tree decl
)
601 For the purposes of name lookup, after the anonymous union
602 definition, the members of the anonymous union are considered to
603 have been defined in the scope in which the anonymous union is
605 tree context
= DECL_CONTEXT (decl
);
607 while (context
&& TYPE_P (context
) && ANON_AGGR_TYPE_P (context
))
608 context
= TYPE_CONTEXT (context
);
610 context
= global_namespace
;
615 /* The accessibility routines use BINFO_ACCESS for scratch space
616 during the computation of the accssibility of some declaration. */
618 #define BINFO_ACCESS(NODE) \
619 ((access_kind) ((TREE_PUBLIC (NODE) << 1) | TREE_PRIVATE (NODE)))
621 /* Set the access associated with NODE to ACCESS. */
623 #define SET_BINFO_ACCESS(NODE, ACCESS) \
624 ((TREE_PUBLIC (NODE) = ((ACCESS) & 2) != 0), \
625 (TREE_PRIVATE (NODE) = ((ACCESS) & 1) != 0))
627 /* Called from access_in_type via dfs_walk. Calculate the access to
628 DATA (which is really a DECL) in BINFO. */
631 dfs_access_in_type (tree binfo
, void *data
)
633 tree decl
= (tree
) data
;
634 tree type
= BINFO_TYPE (binfo
);
635 access_kind access
= ak_none
;
637 if (context_for_name_lookup (decl
) == type
)
639 /* If we have desceneded to the scope of DECL, just note the
640 appropriate access. */
641 if (TREE_PRIVATE (decl
))
643 else if (TREE_PROTECTED (decl
))
644 access
= ak_protected
;
650 /* First, check for an access-declaration that gives us more
651 access to the DECL. The CONST_DECL for an enumeration
652 constant will not have DECL_LANG_SPECIFIC, and thus no
654 if (DECL_LANG_SPECIFIC (decl
) && !DECL_DISCRIMINATOR_P (decl
))
656 tree decl_access
= purpose_member (type
, DECL_ACCESS (decl
));
660 decl_access
= TREE_VALUE (decl_access
);
662 if (decl_access
== access_public_node
)
664 else if (decl_access
== access_protected_node
)
665 access
= ak_protected
;
666 else if (decl_access
== access_private_node
)
669 my_friendly_assert (false, 20030217);
677 tree binfos
, accesses
;
679 /* Otherwise, scan our baseclasses, and pick the most favorable
681 binfos
= BINFO_BASETYPES (binfo
);
682 accesses
= BINFO_BASEACCESSES (binfo
);
683 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
684 for (i
= 0; i
< n_baselinks
; ++i
)
686 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
687 tree base_access
= TREE_VEC_ELT (accesses
, i
);
688 access_kind base_access_now
= BINFO_ACCESS (base_binfo
);
690 if (base_access_now
== ak_none
|| base_access_now
== ak_private
)
691 /* If it was not accessible in the base, or only
692 accessible as a private member, we can't access it
694 base_access_now
= ak_none
;
695 else if (base_access
== access_protected_node
)
696 /* Public and protected members in the base become
698 base_access_now
= ak_protected
;
699 else if (base_access
== access_private_node
)
700 /* Public and protected members in the base become
702 base_access_now
= ak_private
;
704 /* See if the new access, via this base, gives more
705 access than our previous best access. */
706 if (base_access_now
!= ak_none
707 && (access
== ak_none
|| base_access_now
< access
))
709 access
= base_access_now
;
711 /* If the new access is public, we can't do better. */
712 if (access
== ak_public
)
719 /* Note the access to DECL in TYPE. */
720 SET_BINFO_ACCESS (binfo
, access
);
722 /* Mark TYPE as visited so that if we reach it again we do not
723 duplicate our efforts here. */
724 BINFO_MARKED (binfo
) = 1;
729 /* Return the access to DECL in TYPE. */
732 access_in_type (tree type
, tree decl
)
734 tree binfo
= TYPE_BINFO (type
);
736 /* We must take into account
740 If a name can be reached by several paths through a multiple
741 inheritance graph, the access is that of the path that gives
744 The algorithm we use is to make a post-order depth-first traversal
745 of the base-class hierarchy. As we come up the tree, we annotate
746 each node with the most lenient access. */
747 dfs_walk_real (binfo
, 0, dfs_access_in_type
, unmarkedp
, decl
);
748 dfs_walk (binfo
, dfs_unmark
, markedp
, 0);
750 return BINFO_ACCESS (binfo
);
753 /* Called from dfs_accessible_p via dfs_walk. */
756 dfs_accessible_queue_p (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
758 tree binfo
= BINFO_BASETYPE (derived
, ix
);
760 if (BINFO_MARKED (binfo
))
763 /* If this class is inherited via private or protected inheritance,
764 then we can't see it, unless we are a friend of the derived class. */
765 if (BINFO_BASEACCESS (derived
, ix
) != access_public_node
766 && !is_friend (BINFO_TYPE (derived
), current_scope ()))
772 /* Called from dfs_accessible_p via dfs_walk. */
775 dfs_accessible_p (tree binfo
, void *data
)
777 int protected_ok
= data
!= 0;
780 BINFO_MARKED (binfo
) = 1;
781 access
= BINFO_ACCESS (binfo
);
782 if (access
== ak_public
|| (access
== ak_protected
&& protected_ok
))
784 else if (access
!= ak_none
785 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
791 /* Returns nonzero if it is OK to access DECL through an object
792 indiated by BINFO in the context of DERIVED. */
795 protected_accessible_p (tree decl
, tree derived
, tree binfo
)
799 /* We're checking this clause from [class.access.base]
801 m as a member of N is protected, and the reference occurs in a
802 member or friend of class N, or in a member or friend of a
803 class P derived from N, where m as a member of P is private or
806 Here DERIVED is a possible P and DECL is m. accessible_p will
807 iterate over various values of N, but the access to m in DERIVED
810 Note that I believe that the passage above is wrong, and should read
811 "...is private or protected or public"; otherwise you get bizarre results
812 whereby a public using-decl can prevent you from accessing a protected
813 member of a base. (jason 2000/02/28) */
815 /* If DERIVED isn't derived from m's class, then it can't be a P. */
816 if (!DERIVED_FROM_P (context_for_name_lookup (decl
), derived
))
819 access
= access_in_type (derived
, decl
);
821 /* If m is inaccessible in DERIVED, then it's not a P. */
822 if (access
== ak_none
)
827 When a friend or a member function of a derived class references
828 a protected nonstatic member of a base class, an access check
829 applies in addition to those described earlier in clause
830 _class.access_) Except when forming a pointer to member
831 (_expr.unary.op_), the access must be through a pointer to,
832 reference to, or object of the derived class itself (or any class
833 derived from that class) (_expr.ref_). If the access is to form
834 a pointer to member, the nested-name-specifier shall name the
835 derived class (or any class derived from that class). */
836 if (DECL_NONSTATIC_MEMBER_P (decl
))
838 /* We can tell through what the reference is occurring by
839 chasing BINFO up to the root. */
841 while (BINFO_INHERITANCE_CHAIN (t
))
842 t
= BINFO_INHERITANCE_CHAIN (t
);
844 if (!DERIVED_FROM_P (derived
, BINFO_TYPE (t
)))
851 /* Returns nonzero if SCOPE is a friend of a type which would be able
852 to access DECL through the object indicated by BINFO. */
855 friend_accessible_p (tree scope
, tree decl
, tree binfo
)
857 tree befriending_classes
;
863 if (TREE_CODE (scope
) == FUNCTION_DECL
864 || DECL_FUNCTION_TEMPLATE_P (scope
))
865 befriending_classes
= DECL_BEFRIENDING_CLASSES (scope
);
866 else if (TYPE_P (scope
))
867 befriending_classes
= CLASSTYPE_BEFRIENDING_CLASSES (scope
);
871 for (t
= befriending_classes
; t
; t
= TREE_CHAIN (t
))
872 if (protected_accessible_p (decl
, TREE_VALUE (t
), binfo
))
875 /* Nested classes are implicitly friends of their enclosing types, as
876 per core issue 45 (this is a change from the standard). */
878 for (t
= TYPE_CONTEXT (scope
); t
&& TYPE_P (t
); t
= TYPE_CONTEXT (t
))
879 if (protected_accessible_p (decl
, t
, binfo
))
882 if (TREE_CODE (scope
) == FUNCTION_DECL
883 || DECL_FUNCTION_TEMPLATE_P (scope
))
885 /* Perhaps this SCOPE is a member of a class which is a
887 if (DECL_CLASS_SCOPE_P (decl
)
888 && friend_accessible_p (DECL_CONTEXT (scope
), decl
, binfo
))
891 /* Or an instantiation of something which is a friend. */
892 if (DECL_TEMPLATE_INFO (scope
))
893 return friend_accessible_p (DECL_TI_TEMPLATE (scope
), decl
, binfo
);
895 else if (CLASSTYPE_TEMPLATE_INFO (scope
))
896 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope
), decl
, binfo
);
901 /* DECL is a declaration from a base class of TYPE, which was the
902 class used to name DECL. Return nonzero if, in the current
903 context, DECL is accessible. If TYPE is actually a BINFO node,
904 then we can tell in what context the access is occurring by looking
905 at the most derived class along the path indicated by BINFO. */
908 accessible_p (tree type
, tree decl
)
913 /* Nonzero if it's OK to access DECL if it has protected
914 accessibility in TYPE. */
915 int protected_ok
= 0;
917 /* If we're not checking access, everything is accessible. */
918 if (!scope_chain
->check_access
)
921 /* If this declaration is in a block or namespace scope, there's no
923 if (!TYPE_P (context_for_name_lookup (decl
)))
929 type
= BINFO_TYPE (type
);
932 binfo
= TYPE_BINFO (type
);
934 /* [class.access.base]
936 A member m is accessible when named in class N if
938 --m as a member of N is public, or
940 --m as a member of N is private, and the reference occurs in a
941 member or friend of class N, or
943 --m as a member of N is protected, and the reference occurs in a
944 member or friend of class N, or in a member or friend of a
945 class P derived from N, where m as a member of P is private or
948 --there exists a base class B of N that is accessible at the point
949 of reference, and m is accessible when named in class B.
951 We walk the base class hierarchy, checking these conditions. */
953 /* Figure out where the reference is occurring. Check to see if
954 DECL is private or protected in this scope, since that will
955 determine whether protected access is allowed. */
956 if (current_class_type
)
957 protected_ok
= protected_accessible_p (decl
, current_class_type
, binfo
);
959 /* Now, loop through the classes of which we are a friend. */
961 protected_ok
= friend_accessible_p (current_scope (), decl
, binfo
);
963 /* Standardize the binfo that access_in_type will use. We don't
964 need to know what path was chosen from this point onwards. */
965 binfo
= TYPE_BINFO (type
);
967 /* Compute the accessibility of DECL in the class hierarchy
968 dominated by type. */
969 access_in_type (type
, decl
);
970 /* Walk the hierarchy again, looking for a base class that allows
972 t
= dfs_walk (binfo
, dfs_accessible_p
,
973 dfs_accessible_queue_p
,
974 protected_ok
? &protected_ok
: 0);
975 /* Clear any mark bits. Note that we have to walk the whole tree
976 here, since we have aborted the previous walk from some point
978 dfs_walk (binfo
, dfs_unmark
, 0, 0);
980 return t
!= NULL_TREE
;
983 struct lookup_field_info
{
984 /* The type in which we're looking. */
986 /* The name of the field for which we're looking. */
988 /* If non-NULL, the current result of the lookup. */
990 /* The path to RVAL. */
992 /* If non-NULL, the lookup was ambiguous, and this is a list of the
995 /* If nonzero, we are looking for types, not data members. */
997 /* If something went wrong, a message indicating what. */
1001 /* Returns nonzero if BINFO is not hidden by the value found by the
1002 lookup so far. If BINFO is hidden, then there's no need to look in
1003 it. DATA is really a struct lookup_field_info. Called from
1004 lookup_field via breadth_first_search. */
1007 lookup_field_queue_p (tree derived
, int ix
, void *data
)
1009 tree binfo
= BINFO_BASETYPE (derived
, ix
);
1010 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1012 /* Don't look for constructors or destructors in base classes. */
1013 if (IDENTIFIER_CTOR_OR_DTOR_P (lfi
->name
))
1016 /* If this base class is hidden by the best-known value so far, we
1017 don't need to look. */
1018 if (lfi
->rval_binfo
&& original_binfo (binfo
, lfi
->rval_binfo
))
1021 /* If this is a dependent base, don't look in it. */
1022 if (BINFO_DEPENDENT_BASE_P (binfo
))
1028 /* Within the scope of a template class, you can refer to the to the
1029 current specialization with the name of the template itself. For
1032 template <typename T> struct S { S* sp; }
1034 Returns nonzero if DECL is such a declaration in a class TYPE. */
1037 template_self_reference_p (tree type
, tree decl
)
1039 return (CLASSTYPE_USE_TEMPLATE (type
)
1040 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
))
1041 && TREE_CODE (decl
) == TYPE_DECL
1042 && DECL_ARTIFICIAL (decl
)
1043 && DECL_NAME (decl
) == constructor_name (type
));
1047 /* Nonzero for a class member means that it is shared between all objects
1050 [class.member.lookup]:If the resulting set of declarations are not all
1051 from sub-objects of the same type, or the set has a nonstatic member
1052 and includes members from distinct sub-objects, there is an ambiguity
1053 and the program is ill-formed.
1055 This function checks that T contains no nonstatic members. */
1058 shared_member_p (tree t
)
1060 if (TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == TYPE_DECL \
1061 || TREE_CODE (t
) == CONST_DECL
)
1063 if (is_overloaded_fn (t
))
1065 for (; t
; t
= OVL_NEXT (t
))
1067 tree fn
= OVL_CURRENT (t
);
1068 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn
))
1076 /* DATA is really a struct lookup_field_info. Look for a field with
1077 the name indicated there in BINFO. If this function returns a
1078 non-NULL value it is the result of the lookup. Called from
1079 lookup_field via breadth_first_search. */
1082 lookup_field_r (tree binfo
, void *data
)
1084 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1085 tree type
= BINFO_TYPE (binfo
);
1086 tree nval
= NULL_TREE
;
1088 /* First, look for a function. There can't be a function and a data
1089 member with the same name, and if there's a function and a type
1090 with the same name, the type is hidden by the function. */
1091 if (!lfi
->want_type
)
1093 int idx
= lookup_fnfields_1 (type
, lfi
->name
);
1095 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1099 /* Look for a data member or type. */
1100 nval
= lookup_field_1 (type
, lfi
->name
, lfi
->want_type
);
1102 /* If there is no declaration with the indicated name in this type,
1103 then there's nothing to do. */
1107 /* If we're looking up a type (as with an elaborated type specifier)
1108 we ignore all non-types we find. */
1109 if (lfi
->want_type
&& TREE_CODE (nval
) != TYPE_DECL
1110 && !DECL_CLASS_TEMPLATE_P (nval
))
1112 if (lfi
->name
== TYPE_IDENTIFIER (type
))
1114 /* If the aggregate has no user defined constructors, we allow
1115 it to have fields with the same name as the enclosing type.
1116 If we are looking for that name, find the corresponding
1118 for (nval
= TREE_CHAIN (nval
); nval
; nval
= TREE_CHAIN (nval
))
1119 if (DECL_NAME (nval
) == lfi
->name
1120 && TREE_CODE (nval
) == TYPE_DECL
)
1127 nval
= purpose_member (lfi
->name
, CLASSTYPE_TAGS (type
));
1129 nval
= TYPE_MAIN_DECL (TREE_VALUE (nval
));
1135 /* You must name a template base class with a template-id. */
1136 if (!same_type_p (type
, lfi
->type
)
1137 && template_self_reference_p (type
, nval
))
1140 /* If the lookup already found a match, and the new value doesn't
1141 hide the old one, we might have an ambiguity. */
1142 if (lfi
->rval_binfo
&& !original_binfo (lfi
->rval_binfo
, binfo
))
1144 if (nval
== lfi
->rval
&& shared_member_p (nval
))
1145 /* The two things are really the same. */
1147 else if (original_binfo (binfo
, lfi
->rval_binfo
))
1148 /* The previous value hides the new one. */
1152 /* We have a real ambiguity. We keep a chain of all the
1154 if (!lfi
->ambiguous
&& lfi
->rval
)
1156 /* This is the first time we noticed an ambiguity. Add
1157 what we previously thought was a reasonable candidate
1159 lfi
->ambiguous
= tree_cons (NULL_TREE
, lfi
->rval
, NULL_TREE
);
1160 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1163 /* Add the new value. */
1164 lfi
->ambiguous
= tree_cons (NULL_TREE
, nval
, lfi
->ambiguous
);
1165 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1166 lfi
->errstr
= "request for member `%D' is ambiguous";
1172 lfi
->rval_binfo
= binfo
;
1178 /* Return a "baselink" which BASELINK_BINFO, BASELINK_ACCESS_BINFO,
1179 BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
1180 FUNCTIONS, and OPTYPE respectively. */
1183 build_baselink (tree binfo
, tree access_binfo
, tree functions
, tree optype
)
1187 my_friendly_assert (TREE_CODE (functions
) == FUNCTION_DECL
1188 || TREE_CODE (functions
) == TEMPLATE_DECL
1189 || TREE_CODE (functions
) == TEMPLATE_ID_EXPR
1190 || TREE_CODE (functions
) == OVERLOAD
,
1192 my_friendly_assert (!optype
|| TYPE_P (optype
), 20020730);
1193 my_friendly_assert (TREE_TYPE (functions
), 20020805);
1195 baselink
= make_node (BASELINK
);
1196 TREE_TYPE (baselink
) = TREE_TYPE (functions
);
1197 BASELINK_BINFO (baselink
) = binfo
;
1198 BASELINK_ACCESS_BINFO (baselink
) = access_binfo
;
1199 BASELINK_FUNCTIONS (baselink
) = functions
;
1200 BASELINK_OPTYPE (baselink
) = optype
;
1205 /* Look for a member named NAME in an inheritance lattice dominated by
1206 XBASETYPE. If PROTECT is 0 or two, we do not check access. If it
1207 is 1, we enforce accessibility. If PROTECT is zero, then, for an
1208 ambiguous lookup, we return NULL. If PROTECT is 1, we issue error
1209 messages about inaccessible or ambiguous lookup. If PROTECT is 2,
1210 we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
1211 TREE_VALUEs are the list of ambiguous candidates.
1213 WANT_TYPE is 1 when we should only return TYPE_DECLs.
1215 If nothing can be found return NULL_TREE and do not issue an error. */
1218 lookup_member (tree xbasetype
, tree name
, int protect
, bool want_type
)
1220 tree rval
, rval_binfo
= NULL_TREE
;
1221 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1222 struct lookup_field_info lfi
;
1224 /* rval_binfo is the binfo associated with the found member, note,
1225 this can be set with useful information, even when rval is not
1226 set, because it must deal with ALL members, not just non-function
1227 members. It is used for ambiguity checking and the hidden
1228 checks. Whereas rval is only set if a proper (not hidden)
1229 non-function member is found. */
1231 const char *errstr
= 0;
1234 if (TREE_CODE (name
) != IDENTIFIER_NODE
)
1237 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1238 && IDENTIFIER_CLASS_VALUE (name
))
1240 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1241 if (! is_overloaded_fn (field
)
1242 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1243 /* We're in the scope of this class, and the value has already
1244 been looked up. Just return the cached value. */
1248 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1250 type
= BINFO_TYPE (xbasetype
);
1251 basetype_path
= xbasetype
;
1253 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1256 basetype_path
= TYPE_BINFO (type
);
1257 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
1263 complete_type (type
);
1265 #ifdef GATHER_STATISTICS
1266 n_calls_lookup_field
++;
1267 #endif /* GATHER_STATISTICS */
1269 memset ((PTR
) &lfi
, 0, sizeof (lfi
));
1272 lfi
.want_type
= want_type
;
1273 bfs_walk (basetype_path
, &lookup_field_r
, &lookup_field_queue_p
, &lfi
);
1275 rval_binfo
= lfi
.rval_binfo
;
1277 type
= BINFO_TYPE (rval_binfo
);
1278 errstr
= lfi
.errstr
;
1280 /* If we are not interested in ambiguities, don't report them;
1281 just return NULL_TREE. */
1282 if (!protect
&& lfi
.ambiguous
)
1288 return lfi
.ambiguous
;
1295 In the case of overloaded function names, access control is
1296 applied to the function selected by overloaded resolution. */
1297 if (rval
&& protect
&& !is_overloaded_fn (rval
)
1298 && !enforce_access (xbasetype
, rval
))
1299 return error_mark_node
;
1301 if (errstr
&& protect
)
1303 error (errstr
, name
, type
);
1305 print_candidates (lfi
.ambiguous
);
1306 rval
= error_mark_node
;
1309 if (rval
&& is_overloaded_fn (rval
))
1310 rval
= build_baselink (rval_binfo
, basetype_path
, rval
,
1311 (IDENTIFIER_TYPENAME_P (name
)
1312 ? TREE_TYPE (name
): NULL_TREE
));
1316 /* Like lookup_member, except that if we find a function member we
1317 return NULL_TREE. */
1320 lookup_field (tree xbasetype
, tree name
, int protect
, bool want_type
)
1322 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
);
1324 /* Ignore functions. */
1325 if (rval
&& BASELINK_P (rval
))
1331 /* Like lookup_member, except that if we find a non-function member we
1332 return NULL_TREE. */
1335 lookup_fnfields (tree xbasetype
, tree name
, int protect
)
1337 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/false);
1339 /* Ignore non-functions. */
1340 if (rval
&& !BASELINK_P (rval
))
1346 /* TYPE is a class type. Return the index of the fields within
1347 the method vector with name NAME, or -1 is no such field exists. */
1350 lookup_fnfields_1 (tree type
, tree name
)
1352 tree method_vec
= (CLASS_TYPE_P (type
)
1353 ? CLASSTYPE_METHOD_VEC (type
)
1356 if (method_vec
!= 0)
1359 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1360 int len
= TREE_VEC_LENGTH (method_vec
);
1363 #ifdef GATHER_STATISTICS
1364 n_calls_lookup_fnfields_1
++;
1365 #endif /* GATHER_STATISTICS */
1367 /* Constructors are first... */
1368 if (name
== ctor_identifier
)
1369 return (methods
[CLASSTYPE_CONSTRUCTOR_SLOT
]
1370 ? CLASSTYPE_CONSTRUCTOR_SLOT
: -1);
1371 /* and destructors are second. */
1372 if (name
== dtor_identifier
)
1373 return (methods
[CLASSTYPE_DESTRUCTOR_SLOT
]
1374 ? CLASSTYPE_DESTRUCTOR_SLOT
: -1);
1376 for (i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
1377 i
< len
&& methods
[i
];
1380 #ifdef GATHER_STATISTICS
1381 n_outer_fields_searched
++;
1382 #endif /* GATHER_STATISTICS */
1384 tmp
= OVL_CURRENT (methods
[i
]);
1385 if (DECL_NAME (tmp
) == name
)
1388 /* If the type is complete and we're past the conversion ops,
1389 switch to binary search. */
1390 if (! DECL_CONV_FN_P (tmp
)
1391 && COMPLETE_TYPE_P (type
))
1393 int lo
= i
+ 1, hi
= len
;
1399 #ifdef GATHER_STATISTICS
1400 n_outer_fields_searched
++;
1401 #endif /* GATHER_STATISTICS */
1404 /* This slot may be empty; we allocate more slots
1405 than we need. In that case, the entry we're
1406 looking for is closer to the beginning of the
1409 tmp
= DECL_NAME (OVL_CURRENT (tmp
));
1410 if (!tmp
|| tmp
> name
)
1412 else if (tmp
< name
)
1421 /* If we didn't find it, it might have been a template
1422 conversion operator to a templated type. If there are any,
1423 such template conversion operators will all be overloaded on
1424 the first conversion slot. (Note that we don't look for this
1425 case above so that we will always find specializations
1427 if (IDENTIFIER_TYPENAME_P (name
))
1429 i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
1430 if (i
< len
&& methods
[i
])
1432 tmp
= OVL_CURRENT (methods
[i
]);
1433 if (TREE_CODE (tmp
) == TEMPLATE_DECL
1434 && DECL_TEMPLATE_CONV_FN_P (tmp
))
1443 /* DECL is the result of a qualified name lookup. QUALIFYING_SCOPE is
1444 the class or namespace used to qualify the name. CONTEXT_CLASS is
1445 the class corresponding to the object in which DECL will be used.
1446 Return a possibly modified version of DECL that takes into account
1449 In particular, consider an expression like `B::m' in the context of
1450 a derived class `D'. If `B::m' has been resolved to a BASELINK,
1451 then the most derived class indicated by the BASELINK_BINFO will be
1452 `B', not `D'. This function makes that adjustment. */
1455 adjust_result_of_qualified_name_lookup (tree decl
,
1456 tree qualifying_scope
,
1459 if (context_class
&& CLASS_TYPE_P (qualifying_scope
)
1460 && DERIVED_FROM_P (qualifying_scope
, context_class
)
1461 && BASELINK_P (decl
))
1465 my_friendly_assert (CLASS_TYPE_P (context_class
), 20020808);
1467 /* Look for the QUALIFYING_SCOPE as a base of the
1468 CONTEXT_CLASS. If QUALIFYING_SCOPE is ambiguous, we cannot
1469 be sure yet than an error has occurred; perhaps the function
1470 chosen by overload resolution will be static. */
1471 base
= lookup_base (context_class
, qualifying_scope
,
1472 ba_ignore
| ba_quiet
, NULL
);
1475 BASELINK_ACCESS_BINFO (decl
) = base
;
1476 BASELINK_BINFO (decl
)
1477 = lookup_base (base
, BINFO_TYPE (BASELINK_BINFO (decl
)),
1478 ba_ignore
| ba_quiet
,
1487 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1488 type in the hierarchy, in a breadth-first preorder traversal.
1489 If it ever returns a non-NULL value, that value is immediately
1490 returned and the walk is terminated. At each node, FN is passed a
1491 BINFO indicating the path from the curently visited base-class to
1492 TYPE. Before each base-class is walked QFN is called. If the
1493 value returned is nonzero, the base-class is walked; otherwise it
1494 is not. If QFN is NULL, it is treated as a function which always
1495 returns 1. Both FN and QFN are passed the DATA whenever they are
1498 Implementation notes: Uses a circular queue, which starts off on
1499 the stack but gets moved to the malloc arena if it needs to be
1500 enlarged. The underflow and overflow conditions are
1501 indistinguishable except by context: if head == tail and we just
1502 moved the head pointer, the queue is empty, but if we just moved
1503 the tail pointer, the queue is full.
1504 Start with enough room for ten concurrent base classes. That
1505 will be enough for most hierarchies. */
1506 #define BFS_WALK_INITIAL_QUEUE_SIZE 10
1509 bfs_walk (tree binfo
,
1510 tree (*fn
) (tree
, void *),
1511 tree (*qfn
) (tree
, int, void *),
1514 tree rval
= NULL_TREE
;
1516 tree bases_initial
[BFS_WALK_INITIAL_QUEUE_SIZE
];
1517 /* A circular queue of the base classes of BINFO. These will be
1518 built up in breadth-first order, except where QFN prunes the
1521 size_t base_buffer_size
= BFS_WALK_INITIAL_QUEUE_SIZE
;
1522 tree
*base_buffer
= bases_initial
;
1525 base_buffer
[tail
++] = binfo
;
1527 while (head
!= tail
)
1530 tree binfo
= base_buffer
[head
++];
1531 if (head
== base_buffer_size
)
1534 /* Is this the one we're looking for? If so, we're done. */
1535 rval
= fn (binfo
, data
);
1539 n_bases
= BINFO_N_BASETYPES (binfo
);
1540 for (ix
= 0; ix
!= n_bases
; ix
++)
1545 base_binfo
= (*qfn
) (binfo
, ix
, data
);
1547 base_binfo
= BINFO_BASETYPE (binfo
, ix
);
1551 base_buffer
[tail
++] = base_binfo
;
1552 if (tail
== base_buffer_size
)
1556 tree
*new_buffer
= xmalloc (2 * base_buffer_size
1558 memcpy (&new_buffer
[0], &base_buffer
[0],
1559 tail
* sizeof (tree
));
1560 memcpy (&new_buffer
[head
+ base_buffer_size
],
1562 (base_buffer_size
- head
) * sizeof (tree
));
1563 if (base_buffer_size
!= BFS_WALK_INITIAL_QUEUE_SIZE
)
1565 base_buffer
= new_buffer
;
1566 head
+= base_buffer_size
;
1567 base_buffer_size
*= 2;
1574 if (base_buffer_size
!= BFS_WALK_INITIAL_QUEUE_SIZE
)
1579 /* Exactly like bfs_walk, except that a depth-first traversal is
1580 performed, and PREFN is called in preorder, while POSTFN is called
1584 dfs_walk_real (tree binfo
,
1585 tree (*prefn
) (tree
, void *),
1586 tree (*postfn
) (tree
, void *),
1587 tree (*qfn
) (tree
, int, void *),
1590 tree rval
= NULL_TREE
;
1592 /* Call the pre-order walking function. */
1595 rval
= (*prefn
) (binfo
, data
);
1600 /* Process the basetypes. */
1601 if (BINFO_BASETYPES (binfo
))
1603 int i
, n
= TREE_VEC_LENGTH (BINFO_BASETYPES (binfo
));
1604 for (i
= 0; i
!= n
; i
++)
1609 base_binfo
= (*qfn
) (binfo
, i
, data
);
1611 base_binfo
= BINFO_BASETYPE (binfo
, i
);
1615 rval
= dfs_walk_real (base_binfo
, prefn
, postfn
, qfn
, data
);
1622 /* Call the post-order walking function. */
1624 rval
= (*postfn
) (binfo
, data
);
1629 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1633 dfs_walk (tree binfo
,
1634 tree (*fn
) (tree
, void *),
1635 tree (*qfn
) (tree
, int, void *),
1638 return dfs_walk_real (binfo
, 0, fn
, qfn
, data
);
1641 /* Check that virtual overrider OVERRIDER is acceptable for base function
1642 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1645 check_final_overrider (tree overrider
, tree basefn
)
1647 tree over_type
= TREE_TYPE (overrider
);
1648 tree base_type
= TREE_TYPE (basefn
);
1649 tree over_return
= TREE_TYPE (over_type
);
1650 tree base_return
= TREE_TYPE (base_type
);
1651 tree over_throw
= TYPE_RAISES_EXCEPTIONS (over_type
);
1652 tree base_throw
= TYPE_RAISES_EXCEPTIONS (base_type
);
1655 if (same_type_p (base_return
, over_return
))
1657 else if ((CLASS_TYPE_P (over_return
) && CLASS_TYPE_P (base_return
))
1658 || (TREE_CODE (base_return
) == TREE_CODE (over_return
)
1659 && POINTER_TYPE_P (base_return
)))
1661 /* Potentially covariant. */
1662 unsigned base_quals
, over_quals
;
1664 fail
= !POINTER_TYPE_P (base_return
);
1667 fail
= cp_type_quals (base_return
) != cp_type_quals (over_return
);
1669 base_return
= TREE_TYPE (base_return
);
1670 over_return
= TREE_TYPE (over_return
);
1672 base_quals
= cp_type_quals (base_return
);
1673 over_quals
= cp_type_quals (over_return
);
1675 if ((base_quals
& over_quals
) != over_quals
)
1678 if (CLASS_TYPE_P (base_return
) && CLASS_TYPE_P (over_return
))
1680 tree binfo
= lookup_base (over_return
, base_return
,
1681 ba_check
| ba_quiet
, NULL
);
1687 && can_convert (TREE_TYPE (base_type
), TREE_TYPE (over_type
)))
1688 /* GNU extension, allow trivial pointer conversions such as
1689 converting to void *, or qualification conversion. */
1691 /* can_convert will permit user defined conversion from a
1692 (reference to) class type. We must reject them. */
1693 over_return
= TREE_TYPE (over_type
);
1694 if (TREE_CODE (over_return
) == REFERENCE_TYPE
)
1695 over_return
= TREE_TYPE (over_return
);
1696 if (CLASS_TYPE_P (over_return
))
1706 else if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider
)))
1712 cp_error_at ("invalid covariant return type for `%#D'", overrider
);
1713 cp_error_at (" overriding `%#D'", basefn
);
1717 cp_error_at ("conflicting return type specified for `%#D'",
1719 cp_error_at (" overriding `%#D'", basefn
);
1721 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider
),
1722 DECL_CONTEXT (overrider
));
1726 /* Check throw specifier is at least as strict. */
1727 if (!comp_except_specs (base_throw
, over_throw
, 0))
1729 if (!IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider
)))
1731 cp_error_at ("looser throw specifier for `%#F'", overrider
);
1732 cp_error_at (" overriding `%#F'", basefn
);
1733 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider
),
1734 DECL_CONTEXT (overrider
));
1742 /* Given a class TYPE, and a function decl FNDECL, look for
1743 virtual functions in TYPE's hierarchy which FNDECL overrides.
1744 We do not look in TYPE itself, only its bases.
1746 Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
1747 find that it overrides anything.
1749 We check that every function which is overridden, is correctly
1753 look_for_overrides (tree type
, tree fndecl
)
1755 tree binfo
= TYPE_BINFO (type
);
1756 tree basebinfos
= BINFO_BASETYPES (binfo
);
1757 int nbasebinfos
= basebinfos
? TREE_VEC_LENGTH (basebinfos
) : 0;
1761 for (ix
= 0; ix
!= nbasebinfos
; ix
++)
1763 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (basebinfos
, ix
));
1765 if (TYPE_POLYMORPHIC_P (basetype
))
1766 found
+= look_for_overrides_r (basetype
, fndecl
);
1771 /* Look in TYPE for virtual functions with the same signature as
1775 look_for_overrides_here (tree type
, tree fndecl
)
1779 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fndecl
))
1780 ix
= CLASSTYPE_DESTRUCTOR_SLOT
;
1782 ix
= lookup_fnfields_1 (type
, DECL_NAME (fndecl
));
1785 tree fns
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), ix
);
1787 for (; fns
; fns
= OVL_NEXT (fns
))
1789 tree fn
= OVL_CURRENT (fns
);
1791 if (!DECL_VIRTUAL_P (fn
))
1792 /* Not a virtual. */;
1793 else if (DECL_CONTEXT (fn
) != type
)
1794 /* Introduced with a using declaration. */;
1795 else if (DECL_STATIC_FUNCTION_P (fndecl
))
1797 tree btypes
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1798 tree dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1799 if (compparms (TREE_CHAIN (btypes
), dtypes
))
1802 else if (same_signature_p (fndecl
, fn
))
1809 /* Look in TYPE for virtual functions overridden by FNDECL. Check both
1810 TYPE itself and its bases. */
1813 look_for_overrides_r (tree type
, tree fndecl
)
1815 tree fn
= look_for_overrides_here (type
, fndecl
);
1818 if (DECL_STATIC_FUNCTION_P (fndecl
))
1820 /* A static member function cannot match an inherited
1821 virtual member function. */
1822 cp_error_at ("`%#D' cannot be declared", fndecl
);
1823 cp_error_at (" since `%#D' declared in base class", fn
);
1827 /* It's definitely virtual, even if not explicitly set. */
1828 DECL_VIRTUAL_P (fndecl
) = 1;
1829 check_final_overrider (fndecl
, fn
);
1834 /* We failed to find one declared in this class. Look in its bases. */
1835 return look_for_overrides (type
, fndecl
);
1838 /* Called via dfs_walk from dfs_get_pure_virtuals. */
1841 dfs_get_pure_virtuals (tree binfo
, void *data
)
1843 tree type
= (tree
) data
;
1845 /* We're not interested in primary base classes; the derived class
1846 of which they are a primary base will contain the information we
1848 if (!BINFO_PRIMARY_P (binfo
))
1852 for (virtuals
= BINFO_VIRTUALS (binfo
);
1854 virtuals
= TREE_CHAIN (virtuals
))
1855 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals
)))
1856 CLASSTYPE_PURE_VIRTUALS (type
)
1857 = tree_cons (NULL_TREE
, BV_FN (virtuals
),
1858 CLASSTYPE_PURE_VIRTUALS (type
));
1861 BINFO_MARKED (binfo
) = 1;
1866 /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
1869 get_pure_virtuals (tree type
)
1873 /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
1874 is going to be overridden. */
1875 CLASSTYPE_PURE_VIRTUALS (type
) = NULL_TREE
;
1876 /* Now, run through all the bases which are not primary bases, and
1877 collect the pure virtual functions. We look at the vtable in
1878 each class to determine what pure virtual functions are present.
1879 (A primary base is not interesting because the derived class of
1880 which it is a primary base will contain vtable entries for the
1881 pure virtuals in the base class. */
1882 dfs_walk (TYPE_BINFO (type
), dfs_get_pure_virtuals
, unmarkedp
, type
);
1883 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
, type
);
1885 /* Put the pure virtuals in dfs order. */
1886 CLASSTYPE_PURE_VIRTUALS (type
) = nreverse (CLASSTYPE_PURE_VIRTUALS (type
));
1888 for (vbases
= CLASSTYPE_VBASECLASSES (type
);
1890 vbases
= TREE_CHAIN (vbases
))
1894 for (virtuals
= BINFO_VIRTUALS (TREE_VALUE (vbases
));
1896 virtuals
= TREE_CHAIN (virtuals
))
1898 tree base_fndecl
= BV_FN (virtuals
);
1899 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
1900 error ("`%#D' needs a final overrider", base_fndecl
);
1905 /* DEPTH-FIRST SEARCH ROUTINES. */
1908 markedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1910 tree binfo
= BINFO_BASETYPE (derived
, ix
);
1912 return BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
1916 unmarkedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1918 tree binfo
= BINFO_BASETYPE (derived
, ix
);
1920 return !BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
1924 marked_pushdecls_p (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1926 tree binfo
= BINFO_BASETYPE (derived
, ix
);
1928 return (!BINFO_DEPENDENT_BASE_P (binfo
)
1929 && BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
1933 unmarked_pushdecls_p (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1935 tree binfo
= BINFO_BASETYPE (derived
, ix
);
1937 return (!BINFO_DEPENDENT_BASE_P (binfo
)
1938 && !BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
1941 /* The worker functions for `dfs_walk'. These do not need to
1942 test anything (vis a vis marking) if they are paired with
1943 a predicate function (above). */
1946 dfs_unmark (tree binfo
, void *data ATTRIBUTE_UNUSED
)
1948 BINFO_MARKED (binfo
) = 0;
1953 /* Debug info for C++ classes can get very large; try to avoid
1954 emitting it everywhere.
1956 Note that this optimization wins even when the target supports
1957 BINCL (if only slightly), and reduces the amount of work for the
1961 maybe_suppress_debug_info (tree t
)
1963 /* We can't do the usual TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
1964 does not support name references between translation units. It supports
1965 symbolic references between translation units, but only within a single
1966 executable or shared library.
1968 For DWARF 2, we handle TYPE_DECL_SUPPRESS_DEBUG by pretending
1969 that the type was never defined, so we only get the members we
1971 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== NO_DEBUG
)
1974 /* We might have set this earlier in cp_finish_decl. */
1975 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 0;
1977 /* If we already know how we're handling this class, handle debug info
1979 if (CLASSTYPE_INTERFACE_KNOWN (t
))
1981 if (CLASSTYPE_INTERFACE_ONLY (t
))
1982 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
1983 /* else don't set it. */
1985 /* If the class has a vtable, write out the debug info along with
1987 else if (TYPE_CONTAINS_VPTR_P (t
))
1988 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
1990 /* Otherwise, just emit the debug info normally. */
1993 /* Note that we want debugging information for a base class of a class
1994 whose vtable is being emitted. Normally, this would happen because
1995 calling the constructor for a derived class implies calling the
1996 constructors for all bases, which involve initializing the
1997 appropriate vptr with the vtable for the base class; but in the
1998 presence of optimization, this initialization may be optimized
1999 away, so we tell finish_vtable_vardecl that we want the debugging
2000 information anyway. */
2003 dfs_debug_mark (tree binfo
, void *data ATTRIBUTE_UNUSED
)
2005 tree t
= BINFO_TYPE (binfo
);
2007 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2012 /* Returns BINFO if we haven't already noted that we want debugging
2013 info for this base class. */
2016 dfs_debug_unmarkedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
2018 tree binfo
= BINFO_BASETYPE (derived
, ix
);
2020 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
))
2021 ? binfo
: NULL_TREE
);
2024 /* Write out the debugging information for TYPE, whose vtable is being
2025 emitted. Also walk through our bases and note that we want to
2026 write out information for them. This avoids the problem of not
2027 writing any debug info for intermediate basetypes whose
2028 constructors, and thus the references to their vtables, and thus
2029 the vtables themselves, were optimized away. */
2032 note_debug_info_needed (tree type
)
2034 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)))
2036 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)) = 0;
2037 rest_of_type_compilation (type
, toplevel_bindings_p ());
2040 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
, 0);
2043 /* Subroutines of push_class_decls (). */
2046 setup_class_bindings (tree name
, int type_binding_p
)
2048 tree type_binding
= NULL_TREE
;
2051 /* If we've already done the lookup for this declaration, we're
2053 if (IDENTIFIER_CLASS_VALUE (name
))
2056 /* First, deal with the type binding. */
2059 type_binding
= lookup_member (current_class_type
, name
,
2060 /*protect=*/2, /*want_type=*/true);
2061 if (TREE_CODE (type_binding
) == TREE_LIST
2062 && TREE_TYPE (type_binding
) == error_mark_node
)
2063 /* NAME is ambiguous. */
2064 push_class_level_binding (name
, type_binding
);
2066 pushdecl_class_level (type_binding
);
2069 /* Now, do the value binding. */
2070 value_binding
= lookup_member (current_class_type
, name
,
2071 /*protect=*/2, /*want_type=*/false);
2074 && (TREE_CODE (value_binding
) == TYPE_DECL
2075 || DECL_CLASS_TEMPLATE_P (value_binding
)
2076 || (TREE_CODE (value_binding
) == TREE_LIST
2077 && TREE_TYPE (value_binding
) == error_mark_node
2078 && (TREE_CODE (TREE_VALUE (value_binding
))
2080 /* We found a type-binding, even when looking for a non-type
2081 binding. This means that we already processed this binding
2083 else if (value_binding
)
2085 if (TREE_CODE (value_binding
) == TREE_LIST
2086 && TREE_TYPE (value_binding
) == error_mark_node
)
2087 /* NAME is ambiguous. */
2088 push_class_level_binding (name
, value_binding
);
2091 if (BASELINK_P (value_binding
))
2092 /* NAME is some overloaded functions. */
2093 value_binding
= BASELINK_FUNCTIONS (value_binding
);
2094 pushdecl_class_level (value_binding
);
2099 /* Push class-level declarations for any names appearing in BINFO that
2103 dfs_push_type_decls (tree binfo
, void *data ATTRIBUTE_UNUSED
)
2108 type
= BINFO_TYPE (binfo
);
2109 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2110 if (DECL_NAME (fields
) && TREE_CODE (fields
) == TYPE_DECL
2111 && !(!same_type_p (type
, current_class_type
)
2112 && template_self_reference_p (type
, fields
)))
2113 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/1);
2115 /* We can't just use BINFO_MARKED because envelope_add_decl uses
2116 DERIVED_FROM_P, which calls get_base_distance. */
2117 BINFO_PUSHDECLS_MARKED (binfo
) = 1;
2122 /* Push class-level declarations for any names appearing in BINFO that
2123 are not TYPE_DECLS. */
2126 dfs_push_decls (tree binfo
, void *data
)
2128 tree type
= BINFO_TYPE (binfo
);
2132 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2133 if (DECL_NAME (fields
)
2134 && TREE_CODE (fields
) != TYPE_DECL
2135 && TREE_CODE (fields
) != USING_DECL
2136 && !DECL_ARTIFICIAL (fields
))
2137 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/0);
2138 else if (TREE_CODE (fields
) == FIELD_DECL
2139 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
2140 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields
)), data
);
2142 method_vec
= (CLASS_TYPE_P (type
)
2143 ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
);
2145 if (method_vec
&& TREE_VEC_LENGTH (method_vec
) >= 3)
2150 /* Farm out constructors and destructors. */
2151 end
= TREE_VEC_END (method_vec
);
2153 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
2154 methods
< end
&& *methods
;
2156 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods
)),
2157 /*type_binding_p=*/0);
2160 BINFO_PUSHDECLS_MARKED (binfo
) = 0;
2165 /* When entering the scope of a class, we cache all of the
2166 fields that that class provides within its inheritance
2167 lattice. Where ambiguities result, we mark them
2168 with `error_mark_node' so that if they are encountered
2169 without explicit qualification, we can emit an error
2173 push_class_decls (tree type
)
2175 search_stack
= push_search_level (search_stack
, &search_obstack
);
2177 /* Enter type declarations and mark. */
2178 dfs_walk (TYPE_BINFO (type
), dfs_push_type_decls
, unmarked_pushdecls_p
, 0);
2180 /* Enter non-type declarations and unmark. */
2181 dfs_walk (TYPE_BINFO (type
), dfs_push_decls
, marked_pushdecls_p
, 0);
2184 /* Here's a subroutine we need because C lacks lambdas. */
2187 dfs_unuse_fields (tree binfo
, void *data ATTRIBUTE_UNUSED
)
2189 tree type
= TREE_TYPE (binfo
);
2192 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2194 if (TREE_CODE (fields
) != FIELD_DECL
|| DECL_ARTIFICIAL (fields
))
2197 TREE_USED (fields
) = 0;
2198 if (DECL_NAME (fields
) == NULL_TREE
2199 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
2200 unuse_fields (TREE_TYPE (fields
));
2207 unuse_fields (tree type
)
2209 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
, 0);
2215 /* We haven't pushed a search level when dealing with cached classes,
2216 so we'd better not try to pop it. */
2218 search_stack
= pop_search_level (search_stack
);
2222 print_search_statistics ()
2224 #ifdef GATHER_STATISTICS
2225 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
2226 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
2227 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
2228 n_outer_fields_searched
, n_calls_lookup_fnfields
);
2229 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
2230 #else /* GATHER_STATISTICS */
2231 fprintf (stderr
, "no search statistics\n");
2232 #endif /* GATHER_STATISTICS */
2236 init_search_processing ()
2238 gcc_obstack_init (&search_obstack
);
2242 reinit_search_statistics ()
2244 #ifdef GATHER_STATISTICS
2245 n_fields_searched
= 0;
2246 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
2247 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
2248 n_calls_get_base_type
= 0;
2249 n_outer_fields_searched
= 0;
2250 n_contexts_saved
= 0;
2251 #endif /* GATHER_STATISTICS */
2255 add_conversions (tree binfo
, void *data
)
2258 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
2259 tree
*conversions
= (tree
*) data
;
2261 /* Some builtin types have no method vector, not even an empty one. */
2265 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
2267 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
2270 if (!tmp
|| ! DECL_CONV_FN_P (OVL_CURRENT (tmp
)))
2273 name
= DECL_NAME (OVL_CURRENT (tmp
));
2275 /* Make sure we don't already have this conversion. */
2276 if (! IDENTIFIER_MARKED (name
))
2278 *conversions
= tree_cons (binfo
, tmp
, *conversions
);
2279 IDENTIFIER_MARKED (name
) = 1;
2285 /* Return a TREE_LIST containing all the non-hidden user-defined
2286 conversion functions for TYPE (and its base-classes). The
2287 TREE_VALUE of each node is a FUNCTION_DECL or an OVERLOAD
2288 containing the conversion functions. The TREE_PURPOSE is the BINFO
2289 from which the conversion functions in this node were selected. */
2292 lookup_conversions (tree type
)
2295 tree conversions
= NULL_TREE
;
2297 complete_type (type
);
2298 bfs_walk (TYPE_BINFO (type
), add_conversions
, 0, &conversions
);
2300 for (t
= conversions
; t
; t
= TREE_CHAIN (t
))
2301 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t
)))) = 0;
2312 /* Check whether the empty class indicated by EMPTY_BINFO is also present
2313 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
2316 dfs_check_overlap (tree empty_binfo
, void *data
)
2318 struct overlap_info
*oi
= (struct overlap_info
*) data
;
2320 for (binfo
= TYPE_BINFO (oi
->compare_type
);
2322 binfo
= BINFO_BASETYPE (binfo
, 0))
2324 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
2326 oi
->found_overlap
= 1;
2329 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
2336 /* Trivial function to stop base traversal when we find something. */
2339 dfs_no_overlap_yet (tree derived
, int ix
, void *data
)
2341 tree binfo
= BINFO_BASETYPE (derived
, ix
);
2342 struct overlap_info
*oi
= (struct overlap_info
*) data
;
2344 return !oi
->found_overlap
? binfo
: NULL_TREE
;
2347 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
2348 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
2351 types_overlap_p (tree empty_type
, tree next_type
)
2353 struct overlap_info oi
;
2355 if (! IS_AGGR_TYPE (next_type
))
2357 oi
.compare_type
= next_type
;
2358 oi
.found_overlap
= 0;
2359 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
,
2360 dfs_no_overlap_yet
, &oi
);
2361 return oi
.found_overlap
;
2364 /* Given a vtable VAR, determine which of the inherited classes the vtable
2365 inherits (in a loose sense) functions from.
2367 FIXME: This does not work with the new ABI. */
2370 binfo_for_vtable (tree var
)
2372 tree main_binfo
= TYPE_BINFO (DECL_CONTEXT (var
));
2373 tree binfos
= TYPE_BINFO_BASETYPES (BINFO_TYPE (main_binfo
));
2374 int n_baseclasses
= CLASSTYPE_N_BASECLASSES (BINFO_TYPE (main_binfo
));
2377 for (i
= 0; i
< n_baseclasses
; i
++)
2379 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2380 if (base_binfo
!= NULL_TREE
&& BINFO_VTABLE (base_binfo
) == var
)
2384 /* If no secondary base classes matched, return the primary base, if
2386 if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (main_binfo
)))
2387 return get_primary_binfo (main_binfo
);
2392 /* Returns the binfo of the first direct or indirect virtual base derived
2393 from BINFO, or NULL if binfo is not via virtual. */
2396 binfo_from_vbase (tree binfo
)
2398 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2400 if (TREE_VIA_VIRTUAL (binfo
))
2406 /* Returns the binfo of the first direct or indirect virtual base derived
2407 from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
2411 binfo_via_virtual (tree binfo
, tree limit
)
2413 for (; binfo
&& (!limit
|| !same_type_p (BINFO_TYPE (binfo
), limit
));
2414 binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2416 if (TREE_VIA_VIRTUAL (binfo
))
2422 /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
2423 Find the equivalent binfo within whatever graph HERE is located.
2424 This is the inverse of original_binfo. */
2427 copied_binfo (tree binfo
, tree here
)
2429 tree result
= NULL_TREE
;
2431 if (TREE_VIA_VIRTUAL (binfo
))
2435 for (t
= here
; BINFO_INHERITANCE_CHAIN (t
);
2436 t
= BINFO_INHERITANCE_CHAIN (t
))
2439 result
= purpose_member (BINFO_TYPE (binfo
),
2440 CLASSTYPE_VBASECLASSES (BINFO_TYPE (t
)));
2441 result
= TREE_VALUE (result
);
2443 else if (BINFO_INHERITANCE_CHAIN (binfo
))
2448 base_binfos
= copied_binfo (BINFO_INHERITANCE_CHAIN (binfo
), here
);
2449 base_binfos
= BINFO_BASETYPES (base_binfos
);
2450 n
= TREE_VEC_LENGTH (base_binfos
);
2451 for (ix
= 0; ix
!= n
; ix
++)
2453 tree base
= TREE_VEC_ELT (base_binfos
, ix
);
2455 if (BINFO_TYPE (base
) == BINFO_TYPE (binfo
))
2464 my_friendly_assert (BINFO_TYPE (here
) == BINFO_TYPE (binfo
), 20030202);
2468 my_friendly_assert (result
, 20030202);
2472 /* BINFO is some base binfo of HERE, within some other
2473 hierachy. Return the equivalent binfo, but in the hierarchy
2474 dominated by HERE. This is the inverse of copied_binfo. If BINFO
2475 is not a base binfo of HERE, returns NULL_TREE. */
2478 original_binfo (tree binfo
, tree here
)
2482 if (BINFO_TYPE (binfo
) == BINFO_TYPE (here
))
2484 else if (TREE_VIA_VIRTUAL (binfo
))
2486 result
= purpose_member (BINFO_TYPE (binfo
),
2487 CLASSTYPE_VBASECLASSES (BINFO_TYPE (here
)));
2489 result
= TREE_VALUE (result
);
2491 else if (BINFO_INHERITANCE_CHAIN (binfo
))
2495 base_binfos
= original_binfo (BINFO_INHERITANCE_CHAIN (binfo
), here
);
2500 base_binfos
= BINFO_BASETYPES (base_binfos
);
2501 n
= TREE_VEC_LENGTH (base_binfos
);
2502 for (ix
= 0; ix
!= n
; ix
++)
2504 tree base
= TREE_VEC_ELT (base_binfos
, ix
);
2506 if (BINFO_TYPE (base
) == BINFO_TYPE (binfo
))