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, 2004 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"
41 /* The class dominating the hierarchy. */
43 /* A pointer to a complete object of the indicated TYPE. */
48 static tree
dfs_check_overlap (tree
, void *);
49 static tree
dfs_no_overlap_yet (tree
, int, void *);
50 static base_kind
lookup_base_r (tree
, tree
, base_access
, bool, tree
*);
51 static int dynamic_cast_base_recurse (tree
, tree
, bool, tree
*);
52 static tree
dfs_debug_unmarkedp (tree
, int, void *);
53 static tree
dfs_debug_mark (tree
, void *);
54 static int check_hidden_convs (tree
, int, int, tree
, tree
, tree
);
55 static tree
split_conversions (tree
, tree
, tree
, tree
);
56 static int lookup_conversions_r (tree
, int, int,
57 tree
, tree
, tree
, tree
, tree
*, tree
*);
58 static int look_for_overrides_r (tree
, tree
);
59 static tree
bfs_walk (tree
, tree (*) (tree
, void *),
60 tree (*) (tree
, int, void *), void *);
61 static tree
lookup_field_queue_p (tree
, int, void *);
62 static int shared_member_p (tree
);
63 static tree
lookup_field_r (tree
, void *);
64 static tree
dfs_accessible_queue_p (tree
, int, void *);
65 static tree
dfs_accessible_p (tree
, void *);
66 static tree
dfs_access_in_type (tree
, void *);
67 static access_kind
access_in_type (tree
, tree
);
68 static int protected_accessible_p (tree
, tree
, tree
);
69 static int friend_accessible_p (tree
, tree
, tree
);
70 static int template_self_reference_p (tree
, tree
);
71 static tree
dfs_get_pure_virtuals (tree
, void *);
74 /* Variables for gathering statistics. */
75 #ifdef GATHER_STATISTICS
76 static int n_fields_searched
;
77 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
78 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
79 static int n_calls_get_base_type
;
80 static int n_outer_fields_searched
;
81 static int n_contexts_saved
;
82 #endif /* GATHER_STATISTICS */
85 /* Worker for lookup_base. BINFO is the binfo we are searching at,
86 BASE is the RECORD_TYPE we are searching for. ACCESS is the
87 required access checks. IS_VIRTUAL indicates if BINFO is morally
90 If BINFO is of the required type, then *BINFO_PTR is examined to
91 compare with any other instance of BASE we might have already
92 discovered. *BINFO_PTR is initialized and a base_kind return value
93 indicates what kind of base was located.
95 Otherwise BINFO's bases are searched. */
98 lookup_base_r (tree binfo
, tree base
, base_access access
,
99 bool is_virtual
, /* inside a virtual part */
104 base_kind found
= bk_not_base
;
106 if (same_type_p (BINFO_TYPE (binfo
), base
))
108 /* We have found a base. Check against what we have found
110 found
= bk_same_type
;
112 found
= bk_via_virtual
;
116 else if (binfo
!= *binfo_ptr
)
118 if (access
!= ba_any
)
120 else if (!is_virtual
)
121 /* Prefer a non-virtual base. */
129 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
133 bk
= lookup_base_r (base_binfo
, base
,
135 is_virtual
|| BINFO_VIRTUAL_P (base_binfo
),
141 if (access
!= ba_any
)
150 my_friendly_assert (found
== bk_not_base
, 20010723);
155 if (found
!= bk_ambig
)
169 /* Returns true if type BASE is accessible in T. (BASE is known to be
170 a (possibly non-proper) base class of T.) */
173 accessible_base_p (tree t
, tree base
)
177 /* [class.access.base]
179 A base class is said to be accessible if an invented public
180 member of the base class is accessible.
182 If BASE is a non-proper base, this condition is trivially
184 if (same_type_p (t
, base
))
186 /* Rather than inventing a public member, we use the implicit
187 public typedef created in the scope of every class. */
188 decl
= TYPE_FIELDS (base
);
189 while (!DECL_SELF_REFERENCE_P (decl
))
190 decl
= TREE_CHAIN (decl
);
191 while (ANON_AGGR_TYPE_P (t
))
192 t
= TYPE_CONTEXT (t
);
193 return accessible_p (t
, decl
);
196 /* Lookup BASE in the hierarchy dominated by T. Do access checking as
197 ACCESS specifies. Return the binfo we discover. If KIND_PTR is
198 non-NULL, fill with information about what kind of base we
201 If the base is inaccessible, or ambiguous, and the ba_quiet bit is
202 not set in ACCESS, then an error is issued and error_mark_node is
203 returned. If the ba_quiet bit is set, then no error is issued and
204 NULL_TREE is returned. */
207 lookup_base (tree t
, tree base
, base_access access
, base_kind
*kind_ptr
)
209 tree binfo
= NULL_TREE
; /* The binfo we've found so far. */
210 tree t_binfo
= NULL_TREE
;
213 if (t
== error_mark_node
|| base
== error_mark_node
)
216 *kind_ptr
= bk_not_base
;
217 return error_mark_node
;
219 my_friendly_assert (TYPE_P (base
), 20011127);
228 t
= complete_type (TYPE_MAIN_VARIANT (t
));
229 t_binfo
= TYPE_BINFO (t
);
232 base
= complete_type (TYPE_MAIN_VARIANT (base
));
235 bk
= lookup_base_r (t_binfo
, base
, access
, 0, &binfo
);
239 /* Check that the base is unambiguous and accessible. */
240 if (access
!= ba_any
)
248 if (!(access
& ba_quiet
))
250 error ("`%T' is an ambiguous base of `%T'", base
, t
);
251 binfo
= error_mark_node
;
256 if ((access
& ~ba_quiet
) != ba_ignore
257 /* If BASE is incomplete, then BASE and TYPE are probably
258 the same, in which case BASE is accessible. If they
259 are not the same, then TYPE is invalid. In that case,
260 there's no need to issue another error here, and
261 there's no implicit typedef to use in the code that
262 follows, so we skip the check. */
263 && COMPLETE_TYPE_P (base
)
264 && !accessible_base_p (t
, base
))
266 if (!(access
& ba_quiet
))
268 error ("`%T' is an inaccessible base of `%T'", base
, t
);
269 binfo
= error_mark_node
;
273 bk
= bk_inaccessible
;
284 /* Worker function for get_dynamic_cast_base_type. */
287 dynamic_cast_base_recurse (tree subtype
, tree binfo
, bool is_via_virtual
,
290 VEC (tree
) *accesses
;
295 if (BINFO_TYPE (binfo
) == subtype
)
301 *offset_ptr
= BINFO_OFFSET (binfo
);
306 accesses
= BINFO_BASE_ACCESSES (binfo
);
307 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
309 tree base_access
= VEC_index (tree
, accesses
, i
);
312 if (base_access
!= access_public_node
)
314 rval
= dynamic_cast_base_recurse
315 (subtype
, base_binfo
,
316 is_via_virtual
|| BINFO_VIRTUAL_P (base_binfo
), offset_ptr
);
320 worst
= worst
>= 0 ? -3 : worst
;
323 else if (rval
== -3 && worst
!= -1)
329 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
330 started from is related to the required TARGET type, in order to optimize
331 the inheritance graph search. This information is independent of the
332 current context, and ignores private paths, hence get_base_distance is
333 inappropriate. Return a TREE specifying the base offset, BOFF.
334 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
335 and there are no public virtual SUBTYPE bases.
336 BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
337 BOFF == -2, SUBTYPE is not a public base.
338 BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
341 get_dynamic_cast_base_type (tree subtype
, tree target
)
343 tree offset
= NULL_TREE
;
344 int boff
= dynamic_cast_base_recurse (subtype
, TYPE_BINFO (target
),
349 offset
= build_int_cst (ssizetype
, boff
, -1);
353 /* Search for a member with name NAME in a multiple inheritance
354 lattice specified by TYPE. If it does not exist, return NULL_TREE.
355 If the member is ambiguously referenced, return `error_mark_node'.
356 Otherwise, return a DECL with the indicated name. If WANT_TYPE is
357 true, type declarations are preferred. */
359 /* Do a 1-level search for NAME as a member of TYPE. The caller must
360 figure out whether it can access this field. (Since it is only one
361 level, this is reasonable.) */
364 lookup_field_1 (tree type
, tree name
, bool want_type
)
368 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
369 || TREE_CODE (type
) == BOUND_TEMPLATE_TEMPLATE_PARM
370 || TREE_CODE (type
) == TYPENAME_TYPE
)
371 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM and
372 BOUND_TEMPLATE_TEMPLATE_PARM are not fields at all;
373 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
374 the code often worked even when we treated the index as a list
376 The TYPE_FIELDS of TYPENAME_TYPE is its TYPENAME_TYPE_FULLNAME. */
380 && DECL_LANG_SPECIFIC (TYPE_NAME (type
))
381 && DECL_SORTED_FIELDS (TYPE_NAME (type
)))
383 tree
*fields
= &DECL_SORTED_FIELDS (TYPE_NAME (type
))->elts
[0];
384 int lo
= 0, hi
= DECL_SORTED_FIELDS (TYPE_NAME (type
))->len
;
391 #ifdef GATHER_STATISTICS
393 #endif /* GATHER_STATISTICS */
395 if (DECL_NAME (fields
[i
]) > name
)
397 else if (DECL_NAME (fields
[i
]) < name
)
403 /* We might have a nested class and a field with the
404 same name; we sorted them appropriately via
405 field_decl_cmp, so just look for the first or last
406 field with this name. */
411 while (i
>= lo
&& DECL_NAME (fields
[i
]) == name
);
412 if (TREE_CODE (field
) != TYPE_DECL
413 && !DECL_CLASS_TEMPLATE_P (field
))
420 while (i
< hi
&& DECL_NAME (fields
[i
]) == name
);
428 field
= TYPE_FIELDS (type
);
430 #ifdef GATHER_STATISTICS
431 n_calls_lookup_field_1
++;
432 #endif /* GATHER_STATISTICS */
433 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
435 #ifdef GATHER_STATISTICS
437 #endif /* GATHER_STATISTICS */
438 my_friendly_assert (DECL_P (field
), 0);
439 if (DECL_NAME (field
) == NULL_TREE
440 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
442 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
, want_type
);
446 if (TREE_CODE (field
) == USING_DECL
)
448 /* We generally treat class-scope using-declarations as
449 ARM-style access specifications, because support for the
450 ISO semantics has not been implemented. So, in general,
451 there's no reason to return a USING_DECL, and the rest of
452 the compiler cannot handle that. Once the class is
453 defined, USING_DECLs are purged from TYPE_FIELDS; see
454 handle_using_decl. However, we make special efforts to
455 make using-declarations in template classes work
457 if (CLASSTYPE_TEMPLATE_INFO (type
)
458 && !CLASSTYPE_USE_TEMPLATE (type
)
459 && !TREE_TYPE (field
))
465 if (DECL_NAME (field
) == name
467 || TREE_CODE (field
) == TYPE_DECL
468 || DECL_CLASS_TEMPLATE_P (field
)))
472 if (name
== vptr_identifier
)
474 /* Give the user what s/he thinks s/he wants. */
475 if (TYPE_POLYMORPHIC_P (type
))
476 return TYPE_VFIELD (type
);
481 /* There are a number of cases we need to be aware of here:
482 current_class_type current_function_decl
489 Those last two make life interesting. If we're in a function which is
490 itself inside a class, we need decls to go into the fn's decls (our
491 second case below). But if we're in a class and the class itself is
492 inside a function, we need decls to go into the decls for the class. To
493 achieve this last goal, we must see if, when both current_class_ptr and
494 current_function_decl are set, the class was declared inside that
495 function. If so, we know to put the decls into the class's scope. */
500 if (current_function_decl
== NULL_TREE
)
501 return current_class_type
;
502 if (current_class_type
== NULL_TREE
)
503 return current_function_decl
;
504 if ((DECL_FUNCTION_MEMBER_P (current_function_decl
)
505 && same_type_p (DECL_CONTEXT (current_function_decl
),
507 || (DECL_FRIEND_CONTEXT (current_function_decl
)
508 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl
),
509 current_class_type
)))
510 return current_function_decl
;
512 return current_class_type
;
515 /* Returns nonzero if we are currently in a function scope. Note
516 that this function returns zero if we are within a local class, but
517 not within a member function body of the local class. */
520 at_function_scope_p (void)
522 tree cs
= current_scope ();
523 return cs
&& TREE_CODE (cs
) == FUNCTION_DECL
;
526 /* Returns true if the innermost active scope is a class scope. */
529 at_class_scope_p (void)
531 tree cs
= current_scope ();
532 return cs
&& TYPE_P (cs
);
535 /* Returns true if the innermost active scope is a namespace scope. */
538 at_namespace_scope_p (void)
540 /* We are in a namespace scope if we are not it a class scope or a
542 return !current_scope();
545 /* Return the scope of DECL, as appropriate when doing name-lookup. */
548 context_for_name_lookup (tree decl
)
552 For the purposes of name lookup, after the anonymous union
553 definition, the members of the anonymous union are considered to
554 have been defined in the scope in which the anonymous union is
556 tree context
= DECL_CONTEXT (decl
);
558 while (context
&& TYPE_P (context
) && ANON_AGGR_TYPE_P (context
))
559 context
= TYPE_CONTEXT (context
);
561 context
= global_namespace
;
566 /* The accessibility routines use BINFO_ACCESS for scratch space
567 during the computation of the accessibility of some declaration. */
569 #define BINFO_ACCESS(NODE) \
570 ((access_kind) ((TREE_PUBLIC (NODE) << 1) | TREE_PRIVATE (NODE)))
572 /* Set the access associated with NODE to ACCESS. */
574 #define SET_BINFO_ACCESS(NODE, ACCESS) \
575 ((TREE_PUBLIC (NODE) = ((ACCESS) & 2) != 0), \
576 (TREE_PRIVATE (NODE) = ((ACCESS) & 1) != 0))
578 /* Called from access_in_type via dfs_walk. Calculate the access to
579 DATA (which is really a DECL) in BINFO. */
582 dfs_access_in_type (tree binfo
, void *data
)
584 tree decl
= (tree
) data
;
585 tree type
= BINFO_TYPE (binfo
);
586 access_kind access
= ak_none
;
588 if (context_for_name_lookup (decl
) == type
)
590 /* If we have descended to the scope of DECL, just note the
591 appropriate access. */
592 if (TREE_PRIVATE (decl
))
594 else if (TREE_PROTECTED (decl
))
595 access
= ak_protected
;
601 /* First, check for an access-declaration that gives us more
602 access to the DECL. The CONST_DECL for an enumeration
603 constant will not have DECL_LANG_SPECIFIC, and thus no
605 if (DECL_LANG_SPECIFIC (decl
) && !DECL_DISCRIMINATOR_P (decl
))
607 tree decl_access
= purpose_member (type
, DECL_ACCESS (decl
));
611 decl_access
= TREE_VALUE (decl_access
);
613 if (decl_access
== access_public_node
)
615 else if (decl_access
== access_protected_node
)
616 access
= ak_protected
;
617 else if (decl_access
== access_private_node
)
620 my_friendly_assert (false, 20030217);
628 VEC (tree
) *accesses
;
630 /* Otherwise, scan our baseclasses, and pick the most favorable
632 accesses
= BINFO_BASE_ACCESSES (binfo
);
633 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
635 tree base_access
= VEC_index (tree
, accesses
, i
);
636 access_kind base_access_now
= BINFO_ACCESS (base_binfo
);
638 if (base_access_now
== ak_none
|| base_access_now
== ak_private
)
639 /* If it was not accessible in the base, or only
640 accessible as a private member, we can't access it
642 base_access_now
= ak_none
;
643 else if (base_access
== access_protected_node
)
644 /* Public and protected members in the base become
646 base_access_now
= ak_protected
;
647 else if (base_access
== access_private_node
)
648 /* Public and protected members in the base become
650 base_access_now
= ak_private
;
652 /* See if the new access, via this base, gives more
653 access than our previous best access. */
654 if (base_access_now
!= ak_none
655 && (access
== ak_none
|| base_access_now
< access
))
657 access
= base_access_now
;
659 /* If the new access is public, we can't do better. */
660 if (access
== ak_public
)
667 /* Note the access to DECL in TYPE. */
668 SET_BINFO_ACCESS (binfo
, access
);
670 /* Mark TYPE as visited so that if we reach it again we do not
671 duplicate our efforts here. */
672 BINFO_MARKED (binfo
) = 1;
677 /* Return the access to DECL in TYPE. */
680 access_in_type (tree type
, tree decl
)
682 tree binfo
= TYPE_BINFO (type
);
684 /* We must take into account
688 If a name can be reached by several paths through a multiple
689 inheritance graph, the access is that of the path that gives
692 The algorithm we use is to make a post-order depth-first traversal
693 of the base-class hierarchy. As we come up the tree, we annotate
694 each node with the most lenient access. */
695 dfs_walk_real (binfo
, 0, dfs_access_in_type
, unmarkedp
, decl
);
696 dfs_walk (binfo
, dfs_unmark
, markedp
, 0);
698 return BINFO_ACCESS (binfo
);
701 /* Called from accessible_p via dfs_walk. */
704 dfs_accessible_queue_p (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
706 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
708 if (BINFO_MARKED (binfo
))
711 /* If this class is inherited via private or protected inheritance,
712 then we can't see it, unless we are a friend of the derived class. */
713 if (BINFO_BASE_ACCESS (derived
, ix
) != access_public_node
714 && !is_friend (BINFO_TYPE (derived
), current_scope ()))
720 /* Called from accessible_p via dfs_walk. */
723 dfs_accessible_p (tree binfo
, void *data ATTRIBUTE_UNUSED
)
727 BINFO_MARKED (binfo
) = 1;
728 access
= BINFO_ACCESS (binfo
);
729 if (access
!= ak_none
730 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
736 /* Returns nonzero if it is OK to access DECL through an object
737 indicated by BINFO in the context of DERIVED. */
740 protected_accessible_p (tree decl
, tree derived
, tree binfo
)
744 /* We're checking this clause from [class.access.base]
746 m as a member of N is protected, and the reference occurs in a
747 member or friend of class N, or in a member or friend of a
748 class P derived from N, where m as a member of P is private or
751 Here DERIVED is a possible P and DECL is m. accessible_p will
752 iterate over various values of N, but the access to m in DERIVED
755 Note that I believe that the passage above is wrong, and should read
756 "...is private or protected or public"; otherwise you get bizarre results
757 whereby a public using-decl can prevent you from accessing a protected
758 member of a base. (jason 2000/02/28) */
760 /* If DERIVED isn't derived from m's class, then it can't be a P. */
761 if (!DERIVED_FROM_P (context_for_name_lookup (decl
), derived
))
764 access
= access_in_type (derived
, decl
);
766 /* If m is inaccessible in DERIVED, then it's not a P. */
767 if (access
== ak_none
)
772 When a friend or a member function of a derived class references
773 a protected nonstatic member of a base class, an access check
774 applies in addition to those described earlier in clause
775 _class.access_) Except when forming a pointer to member
776 (_expr.unary.op_), the access must be through a pointer to,
777 reference to, or object of the derived class itself (or any class
778 derived from that class) (_expr.ref_). If the access is to form
779 a pointer to member, the nested-name-specifier shall name the
780 derived class (or any class derived from that class). */
781 if (DECL_NONSTATIC_MEMBER_P (decl
))
783 /* We can tell through what the reference is occurring by
784 chasing BINFO up to the root. */
786 while (BINFO_INHERITANCE_CHAIN (t
))
787 t
= BINFO_INHERITANCE_CHAIN (t
);
789 if (!DERIVED_FROM_P (derived
, BINFO_TYPE (t
)))
796 /* Returns nonzero if SCOPE is a friend of a type which would be able
797 to access DECL through the object indicated by BINFO. */
800 friend_accessible_p (tree scope
, tree decl
, tree binfo
)
802 tree befriending_classes
;
808 if (TREE_CODE (scope
) == FUNCTION_DECL
809 || DECL_FUNCTION_TEMPLATE_P (scope
))
810 befriending_classes
= DECL_BEFRIENDING_CLASSES (scope
);
811 else if (TYPE_P (scope
))
812 befriending_classes
= CLASSTYPE_BEFRIENDING_CLASSES (scope
);
816 for (t
= befriending_classes
; t
; t
= TREE_CHAIN (t
))
817 if (protected_accessible_p (decl
, TREE_VALUE (t
), binfo
))
820 /* Nested classes are implicitly friends of their enclosing types, as
821 per core issue 45 (this is a change from the standard). */
823 for (t
= TYPE_CONTEXT (scope
); t
&& TYPE_P (t
); t
= TYPE_CONTEXT (t
))
824 if (protected_accessible_p (decl
, t
, binfo
))
827 if (TREE_CODE (scope
) == FUNCTION_DECL
828 || DECL_FUNCTION_TEMPLATE_P (scope
))
830 /* Perhaps this SCOPE is a member of a class which is a
832 if (DECL_CLASS_SCOPE_P (decl
)
833 && friend_accessible_p (DECL_CONTEXT (scope
), decl
, binfo
))
836 /* Or an instantiation of something which is a friend. */
837 if (DECL_TEMPLATE_INFO (scope
))
838 return friend_accessible_p (DECL_TI_TEMPLATE (scope
), decl
, binfo
);
840 else if (CLASSTYPE_TEMPLATE_INFO (scope
))
841 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope
), decl
, binfo
);
846 /* DECL is a declaration from a base class of TYPE, which was the
847 class used to name DECL. Return nonzero if, in the current
848 context, DECL is accessible. If TYPE is actually a BINFO node,
849 then we can tell in what context the access is occurring by looking
850 at the most derived class along the path indicated by BINFO. */
853 accessible_p (tree type
, tree decl
)
860 /* Nonzero if it's OK to access DECL if it has protected
861 accessibility in TYPE. */
862 int protected_ok
= 0;
864 /* If this declaration is in a block or namespace scope, there's no
866 if (!TYPE_P (context_for_name_lookup (decl
)))
869 /* There is no need to perform access checks inside a thunk. */
870 scope
= current_scope ();
871 if (scope
&& DECL_THUNK_P (scope
))
874 /* In a template declaration, we cannot be sure whether the
875 particular specialization that is instantiated will be a friend
876 or not. Therefore, all access checks are deferred until
878 if (processing_template_decl
)
884 type
= BINFO_TYPE (type
);
887 binfo
= TYPE_BINFO (type
);
889 /* [class.access.base]
891 A member m is accessible when named in class N if
893 --m as a member of N is public, or
895 --m as a member of N is private, and the reference occurs in a
896 member or friend of class N, or
898 --m as a member of N is protected, and the reference occurs in a
899 member or friend of class N, or in a member or friend of a
900 class P derived from N, where m as a member of P is private or
903 --there exists a base class B of N that is accessible at the point
904 of reference, and m is accessible when named in class B.
906 We walk the base class hierarchy, checking these conditions. */
908 /* Figure out where the reference is occurring. Check to see if
909 DECL is private or protected in this scope, since that will
910 determine whether protected access is allowed. */
911 if (current_class_type
)
912 protected_ok
= protected_accessible_p (decl
, current_class_type
, binfo
);
914 /* Now, loop through the classes of which we are a friend. */
916 protected_ok
= friend_accessible_p (scope
, decl
, binfo
);
918 /* Standardize the binfo that access_in_type will use. We don't
919 need to know what path was chosen from this point onwards. */
920 binfo
= TYPE_BINFO (type
);
922 /* Compute the accessibility of DECL in the class hierarchy
923 dominated by type. */
924 access
= access_in_type (type
, decl
);
925 if (access
== ak_public
926 || (access
== ak_protected
&& protected_ok
))
930 /* Walk the hierarchy again, looking for a base class that allows
932 t
= dfs_walk (binfo
, dfs_accessible_p
, dfs_accessible_queue_p
, 0);
933 /* Clear any mark bits. Note that we have to walk the whole tree
934 here, since we have aborted the previous walk from some point
936 dfs_walk (binfo
, dfs_unmark
, 0, 0);
938 return t
!= NULL_TREE
;
942 struct lookup_field_info
{
943 /* The type in which we're looking. */
945 /* The name of the field for which we're looking. */
947 /* If non-NULL, the current result of the lookup. */
949 /* The path to RVAL. */
951 /* If non-NULL, the lookup was ambiguous, and this is a list of the
954 /* If nonzero, we are looking for types, not data members. */
956 /* If something went wrong, a message indicating what. */
960 /* Returns nonzero if BINFO is not hidden by the value found by the
961 lookup so far. If BINFO is hidden, then there's no need to look in
962 it. DATA is really a struct lookup_field_info. Called from
963 lookup_field via breadth_first_search. */
966 lookup_field_queue_p (tree derived
, int ix
, void *data
)
968 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
969 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
971 /* Don't look for constructors or destructors in base classes. */
972 if (IDENTIFIER_CTOR_OR_DTOR_P (lfi
->name
))
975 /* If this base class is hidden by the best-known value so far, we
976 don't need to look. */
977 if (lfi
->rval_binfo
&& original_binfo (binfo
, lfi
->rval_binfo
))
980 /* If this is a dependent base, don't look in it. */
981 if (BINFO_DEPENDENT_BASE_P (binfo
))
987 /* Within the scope of a template class, you can refer to the to the
988 current specialization with the name of the template itself. For
991 template <typename T> struct S { S* sp; }
993 Returns nonzero if DECL is such a declaration in a class TYPE. */
996 template_self_reference_p (tree type
, tree decl
)
998 return (CLASSTYPE_USE_TEMPLATE (type
)
999 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
))
1000 && TREE_CODE (decl
) == TYPE_DECL
1001 && DECL_ARTIFICIAL (decl
)
1002 && DECL_NAME (decl
) == constructor_name (type
));
1006 /* Nonzero for a class member means that it is shared between all objects
1009 [class.member.lookup]:If the resulting set of declarations are not all
1010 from sub-objects of the same type, or the set has a nonstatic member
1011 and includes members from distinct sub-objects, there is an ambiguity
1012 and the program is ill-formed.
1014 This function checks that T contains no nonstatic members. */
1017 shared_member_p (tree t
)
1019 if (TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == TYPE_DECL \
1020 || TREE_CODE (t
) == CONST_DECL
)
1022 if (is_overloaded_fn (t
))
1024 for (; t
; t
= OVL_NEXT (t
))
1026 tree fn
= OVL_CURRENT (t
);
1027 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn
))
1035 /* DATA is really a struct lookup_field_info. Look for a field with
1036 the name indicated there in BINFO. If this function returns a
1037 non-NULL value it is the result of the lookup. Called from
1038 lookup_field via breadth_first_search. */
1041 lookup_field_r (tree binfo
, void *data
)
1043 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1044 tree type
= BINFO_TYPE (binfo
);
1045 tree nval
= NULL_TREE
;
1047 /* First, look for a function. There can't be a function and a data
1048 member with the same name, and if there's a function and a type
1049 with the same name, the type is hidden by the function. */
1050 if (!lfi
->want_type
)
1052 int idx
= lookup_fnfields_1 (type
, lfi
->name
);
1054 nval
= VEC_index (tree
, CLASSTYPE_METHOD_VEC (type
), idx
);
1058 /* Look for a data member or type. */
1059 nval
= lookup_field_1 (type
, lfi
->name
, lfi
->want_type
);
1061 /* If there is no declaration with the indicated name in this type,
1062 then there's nothing to do. */
1066 /* If we're looking up a type (as with an elaborated type specifier)
1067 we ignore all non-types we find. */
1068 if (lfi
->want_type
&& TREE_CODE (nval
) != TYPE_DECL
1069 && !DECL_CLASS_TEMPLATE_P (nval
))
1071 if (lfi
->name
== TYPE_IDENTIFIER (type
))
1073 /* If the aggregate has no user defined constructors, we allow
1074 it to have fields with the same name as the enclosing type.
1075 If we are looking for that name, find the corresponding
1077 for (nval
= TREE_CHAIN (nval
); nval
; nval
= TREE_CHAIN (nval
))
1078 if (DECL_NAME (nval
) == lfi
->name
1079 && TREE_CODE (nval
) == TYPE_DECL
)
1084 if (!nval
&& CLASSTYPE_NESTED_UTDS (type
) != NULL
)
1086 binding_entry e
= binding_table_find (CLASSTYPE_NESTED_UTDS (type
),
1089 nval
= TYPE_MAIN_DECL (e
->type
);
1095 /* You must name a template base class with a template-id. */
1096 if (!same_type_p (type
, lfi
->type
)
1097 && template_self_reference_p (type
, nval
))
1100 /* If the lookup already found a match, and the new value doesn't
1101 hide the old one, we might have an ambiguity. */
1102 if (lfi
->rval_binfo
&& !original_binfo (lfi
->rval_binfo
, binfo
))
1104 if (nval
== lfi
->rval
&& shared_member_p (nval
))
1105 /* The two things are really the same. */
1107 else if (original_binfo (binfo
, lfi
->rval_binfo
))
1108 /* The previous value hides the new one. */
1112 /* We have a real ambiguity. We keep a chain of all the
1114 if (!lfi
->ambiguous
&& lfi
->rval
)
1116 /* This is the first time we noticed an ambiguity. Add
1117 what we previously thought was a reasonable candidate
1119 lfi
->ambiguous
= tree_cons (NULL_TREE
, lfi
->rval
, NULL_TREE
);
1120 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1123 /* Add the new value. */
1124 lfi
->ambiguous
= tree_cons (NULL_TREE
, nval
, lfi
->ambiguous
);
1125 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1126 lfi
->errstr
= "request for member `%D' is ambiguous";
1132 lfi
->rval_binfo
= binfo
;
1138 /* Return a "baselink" with BASELINK_BINFO, BASELINK_ACCESS_BINFO,
1139 BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
1140 FUNCTIONS, and OPTYPE respectively. */
1143 build_baselink (tree binfo
, tree access_binfo
, tree functions
, tree optype
)
1147 my_friendly_assert (TREE_CODE (functions
) == FUNCTION_DECL
1148 || TREE_CODE (functions
) == TEMPLATE_DECL
1149 || TREE_CODE (functions
) == TEMPLATE_ID_EXPR
1150 || TREE_CODE (functions
) == OVERLOAD
,
1152 my_friendly_assert (!optype
|| TYPE_P (optype
), 20020730);
1153 my_friendly_assert (TREE_TYPE (functions
), 20020805);
1155 baselink
= make_node (BASELINK
);
1156 TREE_TYPE (baselink
) = TREE_TYPE (functions
);
1157 BASELINK_BINFO (baselink
) = binfo
;
1158 BASELINK_ACCESS_BINFO (baselink
) = access_binfo
;
1159 BASELINK_FUNCTIONS (baselink
) = functions
;
1160 BASELINK_OPTYPE (baselink
) = optype
;
1165 /* Look for a member named NAME in an inheritance lattice dominated by
1166 XBASETYPE. If PROTECT is 0 or two, we do not check access. If it
1167 is 1, we enforce accessibility. If PROTECT is zero, then, for an
1168 ambiguous lookup, we return NULL. If PROTECT is 1, we issue error
1169 messages about inaccessible or ambiguous lookup. If PROTECT is 2,
1170 we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
1171 TREE_VALUEs are the list of ambiguous candidates.
1173 WANT_TYPE is 1 when we should only return TYPE_DECLs.
1175 If nothing can be found return NULL_TREE and do not issue an error. */
1178 lookup_member (tree xbasetype
, tree name
, int protect
, bool want_type
)
1180 tree rval
, rval_binfo
= NULL_TREE
;
1181 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1182 struct lookup_field_info lfi
;
1184 /* rval_binfo is the binfo associated with the found member, note,
1185 this can be set with useful information, even when rval is not
1186 set, because it must deal with ALL members, not just non-function
1187 members. It is used for ambiguity checking and the hidden
1188 checks. Whereas rval is only set if a proper (not hidden)
1189 non-function member is found. */
1191 const char *errstr
= 0;
1193 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 20030624);
1195 if (TREE_CODE (xbasetype
) == TREE_BINFO
)
1197 type
= BINFO_TYPE (xbasetype
);
1198 basetype_path
= xbasetype
;
1202 my_friendly_assert (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)), 20030624);
1204 xbasetype
= NULL_TREE
;
1207 type
= complete_type (type
);
1209 basetype_path
= TYPE_BINFO (type
);
1214 #ifdef GATHER_STATISTICS
1215 n_calls_lookup_field
++;
1216 #endif /* GATHER_STATISTICS */
1218 memset (&lfi
, 0, sizeof (lfi
));
1221 lfi
.want_type
= want_type
;
1222 bfs_walk (basetype_path
, &lookup_field_r
, &lookup_field_queue_p
, &lfi
);
1224 rval_binfo
= lfi
.rval_binfo
;
1226 type
= BINFO_TYPE (rval_binfo
);
1227 errstr
= lfi
.errstr
;
1229 /* If we are not interested in ambiguities, don't report them;
1230 just return NULL_TREE. */
1231 if (!protect
&& lfi
.ambiguous
)
1237 return lfi
.ambiguous
;
1244 In the case of overloaded function names, access control is
1245 applied to the function selected by overloaded resolution. */
1246 if (rval
&& protect
&& !is_overloaded_fn (rval
))
1247 perform_or_defer_access_check (basetype_path
, rval
);
1249 if (errstr
&& protect
)
1251 error (errstr
, name
, type
);
1253 print_candidates (lfi
.ambiguous
);
1254 rval
= error_mark_node
;
1257 if (rval
&& is_overloaded_fn (rval
))
1258 rval
= build_baselink (rval_binfo
, basetype_path
, rval
,
1259 (IDENTIFIER_TYPENAME_P (name
)
1260 ? TREE_TYPE (name
): NULL_TREE
));
1264 /* Like lookup_member, except that if we find a function member we
1265 return NULL_TREE. */
1268 lookup_field (tree xbasetype
, tree name
, int protect
, bool want_type
)
1270 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
);
1272 /* Ignore functions, but propagate the ambiguity list. */
1273 if (!error_operand_p (rval
)
1274 && (rval
&& BASELINK_P (rval
)))
1280 /* Like lookup_member, except that if we find a non-function member we
1281 return NULL_TREE. */
1284 lookup_fnfields (tree xbasetype
, tree name
, int protect
)
1286 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/false);
1288 /* Ignore non-functions, but propagate the ambiguity list. */
1289 if (!error_operand_p (rval
)
1290 && (rval
&& !BASELINK_P (rval
)))
1296 /* Return the index in the CLASSTYPE_METHOD_VEC for CLASS_TYPE
1297 corresponding to "operator TYPE ()", or -1 if there is no such
1298 operator. Only CLASS_TYPE itself is searched; this routine does
1299 not scan the base classes of CLASS_TYPE. */
1302 lookup_conversion_operator (tree class_type
, tree type
)
1306 if (TYPE_HAS_CONVERSION (class_type
))
1310 VEC(tree
) *methods
= CLASSTYPE_METHOD_VEC (class_type
);
1312 for (i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
1313 VEC_iterate (tree
, methods
, i
, fn
); ++i
)
1315 /* All the conversion operators come near the beginning of
1316 the class. Therefore, if FN is not a conversion
1317 operator, there is no matching conversion operator in
1319 fn
= OVL_CURRENT (fn
);
1320 if (!DECL_CONV_FN_P (fn
))
1323 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
1324 /* All the templated conversion functions are on the same
1325 slot, so remember it. */
1327 else if (same_type_p (DECL_CONV_FN_TYPE (fn
), type
))
1335 /* TYPE is a class type. Return the index of the fields within
1336 the method vector with name NAME, or -1 is no such field exists. */
1339 lookup_fnfields_1 (tree type
, tree name
)
1341 VEC(tree
) *method_vec
;
1346 if (!CLASS_TYPE_P (type
))
1349 if (COMPLETE_TYPE_P (type
))
1351 if ((name
== ctor_identifier
1352 || name
== base_ctor_identifier
1353 || name
== complete_ctor_identifier
))
1355 if (CLASSTYPE_LAZY_DEFAULT_CTOR (type
))
1356 lazily_declare_fn (sfk_constructor
, type
);
1357 if (CLASSTYPE_LAZY_COPY_CTOR (type
))
1358 lazily_declare_fn (sfk_copy_constructor
, type
);
1360 else if (name
== ansi_assopname(NOP_EXPR
)
1361 && CLASSTYPE_LAZY_ASSIGNMENT_OP (type
))
1362 lazily_declare_fn (sfk_assignment_operator
, type
);
1365 method_vec
= CLASSTYPE_METHOD_VEC (type
);
1369 #ifdef GATHER_STATISTICS
1370 n_calls_lookup_fnfields_1
++;
1371 #endif /* GATHER_STATISTICS */
1373 /* Constructors are first... */
1374 if (name
== ctor_identifier
)
1376 fn
= CLASSTYPE_CONSTRUCTORS (type
);
1377 return fn
? CLASSTYPE_CONSTRUCTOR_SLOT
: -1;
1379 /* and destructors are second. */
1380 if (name
== dtor_identifier
)
1382 fn
= CLASSTYPE_DESTRUCTORS (type
);
1383 return fn
? CLASSTYPE_DESTRUCTOR_SLOT
: -1;
1385 if (IDENTIFIER_TYPENAME_P (name
))
1386 return lookup_conversion_operator (type
, TREE_TYPE (name
));
1388 /* Skip the conversion operators. */
1389 for (i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
1390 VEC_iterate (tree
, method_vec
, i
, fn
);
1392 if (!DECL_CONV_FN_P (OVL_CURRENT (fn
)))
1395 /* If the type is complete, use binary search. */
1396 if (COMPLETE_TYPE_P (type
))
1402 hi
= VEC_length (tree
, method_vec
);
1407 #ifdef GATHER_STATISTICS
1408 n_outer_fields_searched
++;
1409 #endif /* GATHER_STATISTICS */
1411 tmp
= VEC_index (tree
, method_vec
, i
);
1412 tmp
= DECL_NAME (OVL_CURRENT (tmp
));
1415 else if (tmp
< name
)
1422 for (; VEC_iterate (tree
, method_vec
, i
, fn
); ++i
)
1424 #ifdef GATHER_STATISTICS
1425 n_outer_fields_searched
++;
1426 #endif /* GATHER_STATISTICS */
1427 if (DECL_NAME (OVL_CURRENT (fn
)) == name
)
1434 /* DECL is the result of a qualified name lookup. QUALIFYING_SCOPE is
1435 the class or namespace used to qualify the name. CONTEXT_CLASS is
1436 the class corresponding to the object in which DECL will be used.
1437 Return a possibly modified version of DECL that takes into account
1440 In particular, consider an expression like `B::m' in the context of
1441 a derived class `D'. If `B::m' has been resolved to a BASELINK,
1442 then the most derived class indicated by the BASELINK_BINFO will be
1443 `B', not `D'. This function makes that adjustment. */
1446 adjust_result_of_qualified_name_lookup (tree decl
,
1447 tree qualifying_scope
,
1450 if (context_class
&& CLASS_TYPE_P (qualifying_scope
)
1451 && DERIVED_FROM_P (qualifying_scope
, context_class
)
1452 && BASELINK_P (decl
))
1456 my_friendly_assert (CLASS_TYPE_P (context_class
), 20020808);
1458 /* Look for the QUALIFYING_SCOPE as a base of the CONTEXT_CLASS.
1459 Because we do not yet know which function will be chosen by
1460 overload resolution, we cannot yet check either accessibility
1461 or ambiguity -- in either case, the choice of a static member
1462 function might make the usage valid. */
1463 base
= lookup_base (context_class
, qualifying_scope
,
1464 ba_ignore
| ba_quiet
, NULL
);
1467 BASELINK_ACCESS_BINFO (decl
) = base
;
1468 BASELINK_BINFO (decl
)
1469 = lookup_base (base
, BINFO_TYPE (BASELINK_BINFO (decl
)),
1470 ba_ignore
| ba_quiet
,
1479 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1480 type in the hierarchy, in a breadth-first preorder traversal.
1481 If it ever returns a non-NULL value, that value is immediately
1482 returned and the walk is terminated. At each node, FN is passed a
1483 BINFO indicating the path from the currently visited base-class to
1484 TYPE. Before each base-class is walked QFN is called. If the
1485 value returned is nonzero, the base-class is walked; otherwise it
1486 is not. If QFN is NULL, it is treated as a function which always
1487 returns 1. Both FN and QFN are passed the DATA whenever they are
1490 Implementation notes: Uses a circular queue, which starts off on
1491 the stack but gets moved to the malloc arena if it needs to be
1492 enlarged. The underflow and overflow conditions are
1493 indistinguishable except by context: if head == tail and we just
1494 moved the head pointer, the queue is empty, but if we just moved
1495 the tail pointer, the queue is full.
1496 Start with enough room for ten concurrent base classes. That
1497 will be enough for most hierarchies. */
1498 #define BFS_WALK_INITIAL_QUEUE_SIZE 10
1501 bfs_walk (tree binfo
,
1502 tree (*fn
) (tree
, void *),
1503 tree (*qfn
) (tree
, int, void *),
1506 tree rval
= NULL_TREE
;
1508 tree bases_initial
[BFS_WALK_INITIAL_QUEUE_SIZE
];
1509 /* A circular queue of the base classes of BINFO. These will be
1510 built up in breadth-first order, except where QFN prunes the
1513 size_t base_buffer_size
= BFS_WALK_INITIAL_QUEUE_SIZE
;
1514 tree
*base_buffer
= bases_initial
;
1517 base_buffer
[tail
++] = binfo
;
1519 while (head
!= tail
)
1522 tree binfo
= base_buffer
[head
++];
1523 if (head
== base_buffer_size
)
1526 /* Is this the one we're looking for? If so, we're done. */
1527 rval
= fn (binfo
, data
);
1531 n_bases
= BINFO_N_BASE_BINFOS (binfo
);
1532 for (ix
= 0; ix
!= n_bases
; ix
++)
1537 base_binfo
= (*qfn
) (binfo
, ix
, data
);
1539 base_binfo
= BINFO_BASE_BINFO (binfo
, ix
);
1543 base_buffer
[tail
++] = base_binfo
;
1544 if (tail
== base_buffer_size
)
1548 tree
*new_buffer
= xmalloc (2 * base_buffer_size
1550 memcpy (&new_buffer
[0], &base_buffer
[0],
1551 tail
* sizeof (tree
));
1552 memcpy (&new_buffer
[head
+ base_buffer_size
],
1554 (base_buffer_size
- head
) * sizeof (tree
));
1555 if (base_buffer_size
!= BFS_WALK_INITIAL_QUEUE_SIZE
)
1557 base_buffer
= new_buffer
;
1558 head
+= base_buffer_size
;
1559 base_buffer_size
*= 2;
1566 if (base_buffer_size
!= BFS_WALK_INITIAL_QUEUE_SIZE
)
1571 /* Exactly like bfs_walk, except that a depth-first traversal is
1572 performed, and PREFN is called in preorder, while POSTFN is called
1576 dfs_walk_real (tree binfo
,
1577 tree (*prefn
) (tree
, void *),
1578 tree (*postfn
) (tree
, void *),
1579 tree (*qfn
) (tree
, int, void *),
1584 tree rval
= NULL_TREE
;
1586 /* Call the pre-order walking function. */
1589 rval
= (*prefn
) (binfo
, data
);
1594 /* Process the basetypes. */
1595 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
1599 base_binfo
= (*qfn
) (binfo
, i
, data
);
1603 rval
= dfs_walk_real (base_binfo
, prefn
, postfn
, qfn
, data
);
1608 /* Call the post-order walking function. */
1610 rval
= (*postfn
) (binfo
, data
);
1615 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1619 dfs_walk (tree binfo
,
1620 tree (*fn
) (tree
, void *),
1621 tree (*qfn
) (tree
, int, void *),
1624 return dfs_walk_real (binfo
, 0, fn
, qfn
, data
);
1627 /* Check that virtual overrider OVERRIDER is acceptable for base function
1628 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1631 check_final_overrider (tree overrider
, tree basefn
)
1633 tree over_type
= TREE_TYPE (overrider
);
1634 tree base_type
= TREE_TYPE (basefn
);
1635 tree over_return
= TREE_TYPE (over_type
);
1636 tree base_return
= TREE_TYPE (base_type
);
1637 tree over_throw
= TYPE_RAISES_EXCEPTIONS (over_type
);
1638 tree base_throw
= TYPE_RAISES_EXCEPTIONS (base_type
);
1641 if (DECL_INVALID_OVERRIDER_P (overrider
))
1644 if (same_type_p (base_return
, over_return
))
1646 else if ((CLASS_TYPE_P (over_return
) && CLASS_TYPE_P (base_return
))
1647 || (TREE_CODE (base_return
) == TREE_CODE (over_return
)
1648 && POINTER_TYPE_P (base_return
)))
1650 /* Potentially covariant. */
1651 unsigned base_quals
, over_quals
;
1653 fail
= !POINTER_TYPE_P (base_return
);
1656 fail
= cp_type_quals (base_return
) != cp_type_quals (over_return
);
1658 base_return
= TREE_TYPE (base_return
);
1659 over_return
= TREE_TYPE (over_return
);
1661 base_quals
= cp_type_quals (base_return
);
1662 over_quals
= cp_type_quals (over_return
);
1664 if ((base_quals
& over_quals
) != over_quals
)
1667 if (CLASS_TYPE_P (base_return
) && CLASS_TYPE_P (over_return
))
1669 tree binfo
= lookup_base (over_return
, base_return
,
1670 ba_check
| ba_quiet
, NULL
);
1676 && can_convert (TREE_TYPE (base_type
), TREE_TYPE (over_type
)))
1677 /* GNU extension, allow trivial pointer conversions such as
1678 converting to void *, or qualification conversion. */
1680 /* can_convert will permit user defined conversion from a
1681 (reference to) class type. We must reject them. */
1682 over_return
= non_reference (TREE_TYPE (over_type
));
1683 if (CLASS_TYPE_P (over_return
))
1697 cp_error_at ("invalid covariant return type for `%#D'", overrider
);
1698 cp_error_at (" overriding `%#D'", basefn
);
1702 cp_error_at ("conflicting return type specified for `%#D'",
1704 cp_error_at (" overriding `%#D'", basefn
);
1706 DECL_INVALID_OVERRIDER_P (overrider
) = 1;
1710 /* Check throw specifier is at least as strict. */
1711 if (!comp_except_specs (base_throw
, over_throw
, 0))
1713 cp_error_at ("looser throw specifier for `%#F'", overrider
);
1714 cp_error_at (" overriding `%#F'", basefn
);
1715 DECL_INVALID_OVERRIDER_P (overrider
) = 1;
1722 /* Given a class TYPE, and a function decl FNDECL, look for
1723 virtual functions in TYPE's hierarchy which FNDECL overrides.
1724 We do not look in TYPE itself, only its bases.
1726 Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
1727 find that it overrides anything.
1729 We check that every function which is overridden, is correctly
1733 look_for_overrides (tree type
, tree fndecl
)
1735 tree binfo
= TYPE_BINFO (type
);
1740 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
1742 tree basetype
= BINFO_TYPE (base_binfo
);
1744 if (TYPE_POLYMORPHIC_P (basetype
))
1745 found
+= look_for_overrides_r (basetype
, fndecl
);
1750 /* Look in TYPE for virtual functions with the same signature as
1754 look_for_overrides_here (tree type
, tree fndecl
)
1758 /* If there are no methods in TYPE (meaning that only implicitly
1759 declared methods will ever be provided for TYPE), then there are
1760 no virtual functions. */
1761 if (!CLASSTYPE_METHOD_VEC (type
))
1764 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fndecl
))
1765 ix
= CLASSTYPE_DESTRUCTOR_SLOT
;
1767 ix
= lookup_fnfields_1 (type
, DECL_NAME (fndecl
));
1770 tree fns
= VEC_index (tree
, CLASSTYPE_METHOD_VEC (type
), ix
);
1772 for (; fns
; fns
= OVL_NEXT (fns
))
1774 tree fn
= OVL_CURRENT (fns
);
1776 if (!DECL_VIRTUAL_P (fn
))
1777 /* Not a virtual. */;
1778 else if (DECL_CONTEXT (fn
) != type
)
1779 /* Introduced with a using declaration. */;
1780 else if (DECL_STATIC_FUNCTION_P (fndecl
))
1782 tree btypes
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1783 tree dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1784 if (compparms (TREE_CHAIN (btypes
), dtypes
))
1787 else if (same_signature_p (fndecl
, fn
))
1794 /* Look in TYPE for virtual functions overridden by FNDECL. Check both
1795 TYPE itself and its bases. */
1798 look_for_overrides_r (tree type
, tree fndecl
)
1800 tree fn
= look_for_overrides_here (type
, fndecl
);
1803 if (DECL_STATIC_FUNCTION_P (fndecl
))
1805 /* A static member function cannot match an inherited
1806 virtual member function. */
1807 cp_error_at ("`%#D' cannot be declared", fndecl
);
1808 cp_error_at (" since `%#D' declared in base class", fn
);
1812 /* It's definitely virtual, even if not explicitly set. */
1813 DECL_VIRTUAL_P (fndecl
) = 1;
1814 check_final_overrider (fndecl
, fn
);
1819 /* We failed to find one declared in this class. Look in its bases. */
1820 return look_for_overrides (type
, fndecl
);
1823 /* Called via dfs_walk from dfs_get_pure_virtuals. */
1826 dfs_get_pure_virtuals (tree binfo
, void *data
)
1828 tree type
= (tree
) data
;
1830 /* We're not interested in primary base classes; the derived class
1831 of which they are a primary base will contain the information we
1833 if (!BINFO_PRIMARY_P (binfo
))
1837 for (virtuals
= BINFO_VIRTUALS (binfo
);
1839 virtuals
= TREE_CHAIN (virtuals
))
1840 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals
)))
1841 CLASSTYPE_PURE_VIRTUALS (type
)
1842 = tree_cons (NULL_TREE
, BV_FN (virtuals
),
1843 CLASSTYPE_PURE_VIRTUALS (type
));
1846 BINFO_MARKED (binfo
) = 1;
1851 /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
1854 get_pure_virtuals (tree type
)
1860 /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
1861 is going to be overridden. */
1862 CLASSTYPE_PURE_VIRTUALS (type
) = NULL_TREE
;
1863 /* Now, run through all the bases which are not primary bases, and
1864 collect the pure virtual functions. We look at the vtable in
1865 each class to determine what pure virtual functions are present.
1866 (A primary base is not interesting because the derived class of
1867 which it is a primary base will contain vtable entries for the
1868 pure virtuals in the base class. */
1869 dfs_walk (TYPE_BINFO (type
), dfs_get_pure_virtuals
, unmarkedp
, type
);
1870 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
, type
);
1872 /* Put the pure virtuals in dfs order. */
1873 CLASSTYPE_PURE_VIRTUALS (type
) = nreverse (CLASSTYPE_PURE_VIRTUALS (type
));
1875 for (vbases
= CLASSTYPE_VBASECLASSES (type
), ix
= 0;
1876 VEC_iterate (tree
, vbases
, ix
, binfo
); ix
++)
1880 for (virtuals
= BINFO_VIRTUALS (binfo
); virtuals
;
1881 virtuals
= TREE_CHAIN (virtuals
))
1883 tree base_fndecl
= BV_FN (virtuals
);
1884 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
1885 error ("`%#D' needs a final overrider", base_fndecl
);
1890 /* DEPTH-FIRST SEARCH ROUTINES. */
1893 markedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1895 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
1897 return BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
1901 unmarkedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1903 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
1905 return !BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
1908 /* The worker functions for `dfs_walk'. These do not need to
1909 test anything (vis a vis marking) if they are paired with
1910 a predicate function (above). */
1913 dfs_unmark (tree binfo
, void *data ATTRIBUTE_UNUSED
)
1915 BINFO_MARKED (binfo
) = 0;
1920 /* Debug info for C++ classes can get very large; try to avoid
1921 emitting it everywhere.
1923 Note that this optimization wins even when the target supports
1924 BINCL (if only slightly), and reduces the amount of work for the
1928 maybe_suppress_debug_info (tree t
)
1930 /* We can't do the usual TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
1931 does not support name references between translation units. It supports
1932 symbolic references between translation units, but only within a single
1933 executable or shared library.
1935 For DWARF 2, we handle TYPE_DECL_SUPPRESS_DEBUG by pretending
1936 that the type was never defined, so we only get the members we
1938 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== NO_DEBUG
)
1941 /* We might have set this earlier in cp_finish_decl. */
1942 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 0;
1944 /* If we already know how we're handling this class, handle debug info
1946 if (CLASSTYPE_INTERFACE_KNOWN (t
))
1948 if (CLASSTYPE_INTERFACE_ONLY (t
))
1949 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
1950 /* else don't set it. */
1952 /* If the class has a vtable, write out the debug info along with
1954 else if (TYPE_CONTAINS_VPTR_P (t
))
1955 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
1957 /* Otherwise, just emit the debug info normally. */
1960 /* Note that we want debugging information for a base class of a class
1961 whose vtable is being emitted. Normally, this would happen because
1962 calling the constructor for a derived class implies calling the
1963 constructors for all bases, which involve initializing the
1964 appropriate vptr with the vtable for the base class; but in the
1965 presence of optimization, this initialization may be optimized
1966 away, so we tell finish_vtable_vardecl that we want the debugging
1967 information anyway. */
1970 dfs_debug_mark (tree binfo
, void *data ATTRIBUTE_UNUSED
)
1972 tree t
= BINFO_TYPE (binfo
);
1974 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
1979 /* Returns BINFO if we haven't already noted that we want debugging
1980 info for this base class. */
1983 dfs_debug_unmarkedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1985 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
1987 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
))
1988 ? binfo
: NULL_TREE
);
1991 /* Write out the debugging information for TYPE, whose vtable is being
1992 emitted. Also walk through our bases and note that we want to
1993 write out information for them. This avoids the problem of not
1994 writing any debug info for intermediate basetypes whose
1995 constructors, and thus the references to their vtables, and thus
1996 the vtables themselves, were optimized away. */
1999 note_debug_info_needed (tree type
)
2001 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)))
2003 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)) = 0;
2004 rest_of_type_compilation (type
, toplevel_bindings_p ());
2007 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
, 0);
2011 print_search_statistics (void)
2013 #ifdef GATHER_STATISTICS
2014 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
2015 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
2016 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
2017 n_outer_fields_searched
, n_calls_lookup_fnfields
);
2018 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
2019 #else /* GATHER_STATISTICS */
2020 fprintf (stderr
, "no search statistics\n");
2021 #endif /* GATHER_STATISTICS */
2025 reinit_search_statistics (void)
2027 #ifdef GATHER_STATISTICS
2028 n_fields_searched
= 0;
2029 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
2030 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
2031 n_calls_get_base_type
= 0;
2032 n_outer_fields_searched
= 0;
2033 n_contexts_saved
= 0;
2034 #endif /* GATHER_STATISTICS */
2037 /* Helper for lookup_conversions_r. TO_TYPE is the type converted to
2038 by a conversion op in base BINFO. VIRTUAL_DEPTH is non-zero if
2039 BINFO is morally virtual, and VIRTUALNESS is non-zero if virtual
2040 bases have been encountered already in the tree walk. PARENT_CONVS
2041 is the list of lists of conversion functions that could hide CONV
2042 and OTHER_CONVS is the list of lists of conversion functions that
2043 could hide or be hidden by CONV, should virtualness be involved in
2044 the hierarchy. Merely checking the conversion op's name is not
2045 enough because two conversion operators to the same type can have
2046 different names. Return non-zero if we are visible. */
2049 check_hidden_convs (tree binfo
, int virtual_depth
, int virtualness
,
2050 tree to_type
, tree parent_convs
, tree other_convs
)
2054 /* See if we are hidden by a parent conversion. */
2055 for (level
= parent_convs
; level
; level
= TREE_CHAIN (level
))
2056 for (probe
= TREE_VALUE (level
); probe
; probe
= TREE_CHAIN (probe
))
2057 if (same_type_p (to_type
, TREE_TYPE (probe
)))
2060 if (virtual_depth
|| virtualness
)
2062 /* In a virtual hierarchy, we could be hidden, or could hide a
2063 conversion function on the other_convs list. */
2064 for (level
= other_convs
; level
; level
= TREE_CHAIN (level
))
2070 if (!(virtual_depth
|| TREE_STATIC (level
)))
2071 /* Neither is morally virtual, so cannot hide each other. */
2074 if (!TREE_VALUE (level
))
2075 /* They evaporated away already. */
2078 they_hide_us
= (virtual_depth
2079 && original_binfo (binfo
, TREE_PURPOSE (level
)));
2080 we_hide_them
= (!they_hide_us
&& TREE_STATIC (level
)
2081 && original_binfo (TREE_PURPOSE (level
), binfo
));
2083 if (!(we_hide_them
|| they_hide_us
))
2084 /* Neither is within the other, so no hiding can occur. */
2087 for (prev
= &TREE_VALUE (level
), other
= *prev
; other
;)
2089 if (same_type_p (to_type
, TREE_TYPE (other
)))
2092 /* We are hidden. */
2097 /* We hide the other one. */
2098 other
= TREE_CHAIN (other
);
2103 prev
= &TREE_CHAIN (other
);
2111 /* Helper for lookup_conversions_r. PARENT_CONVS is a list of lists
2112 of conversion functions, the first slot will be for the current
2113 binfo, if MY_CONVS is non-NULL. CHILD_CONVS is the list of lists
2114 of conversion functions from childen of the current binfo,
2115 concatenated with conversions from elsewhere in the heirarchy --
2116 that list begins with OTHER_CONVS. Return a single list of lists
2117 containing only conversions from the current binfo and its
2121 split_conversions (tree my_convs
, tree parent_convs
,
2122 tree child_convs
, tree other_convs
)
2127 /* Remove the original other_convs portion from child_convs. */
2128 for (prev
= NULL
, t
= child_convs
;
2129 t
!= other_convs
; prev
= t
, t
= TREE_CHAIN (t
))
2133 TREE_CHAIN (prev
) = NULL_TREE
;
2135 child_convs
= NULL_TREE
;
2137 /* Attach the child convs to any we had at this level. */
2140 my_convs
= parent_convs
;
2141 TREE_CHAIN (my_convs
) = child_convs
;
2144 my_convs
= child_convs
;
2149 /* Worker for lookup_conversions. Lookup conversion functions in
2150 BINFO and its children. VIRTUAL_DEPTH is non-zero, if BINFO is in
2151 a morally virtual base, and VIRTUALNESS is non-zero, if we've
2152 encountered virtual bases already in the tree walk. PARENT_CONVS &
2153 PARENT_TPL_CONVS are lists of list of conversions within parent
2154 binfos. OTHER_CONVS and OTHER_TPL_CONVS are conversions found
2155 elsewhere in the tree. Return the conversions found within this
2156 portion of the graph in CONVS and TPL_CONVS. Return non-zero is we
2157 encountered virtualness. We keep template and non-template
2158 conversions separate, to avoid unnecessary type comparisons.
2160 The located conversion functions are held in lists of lists. The
2161 TREE_VALUE of the outer list is the list of conversion functions
2162 found in a particular binfo. The TREE_PURPOSE of both the outer
2163 and inner lists is the binfo at which those conversions were
2164 found. TREE_STATIC is set for those lists within of morally
2165 virtual binfos. The TREE_VALUE of the inner list is the conversion
2166 function or overload itself. The TREE_TYPE of each inner list node
2167 is the converted-to type. */
2170 lookup_conversions_r (tree binfo
,
2171 int virtual_depth
, int virtualness
,
2172 tree parent_convs
, tree parent_tpl_convs
,
2173 tree other_convs
, tree other_tpl_convs
,
2174 tree
*convs
, tree
*tpl_convs
)
2176 int my_virtualness
= 0;
2177 tree my_convs
= NULL_TREE
;
2178 tree my_tpl_convs
= NULL_TREE
;
2179 tree child_convs
= NULL_TREE
;
2180 tree child_tpl_convs
= NULL_TREE
;
2183 VEC(tree
) *method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
2186 /* If we have no conversion operators, then don't look. */
2187 if (!TYPE_HAS_CONVERSION (BINFO_TYPE (binfo
)))
2189 *convs
= *tpl_convs
= NULL_TREE
;
2194 if (BINFO_VIRTUAL_P (binfo
))
2197 /* First, locate the unhidden ones at this level. */
2198 for (i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
2199 VEC_iterate (tree
, method_vec
, i
, conv
);
2202 tree cur
= OVL_CURRENT (conv
);
2204 if (!DECL_CONV_FN_P (cur
))
2207 if (TREE_CODE (cur
) == TEMPLATE_DECL
)
2209 /* Only template conversions can be overloaded, and we must
2210 flatten them out and check each one individually. */
2213 for (tpls
= conv
; tpls
; tpls
= OVL_NEXT (tpls
))
2215 tree tpl
= OVL_CURRENT (tpls
);
2216 tree type
= DECL_CONV_FN_TYPE (tpl
);
2218 if (check_hidden_convs (binfo
, virtual_depth
, virtualness
,
2219 type
, parent_tpl_convs
, other_tpl_convs
))
2221 my_tpl_convs
= tree_cons (binfo
, tpl
, my_tpl_convs
);
2222 TREE_TYPE (my_tpl_convs
) = type
;
2225 TREE_STATIC (my_tpl_convs
) = 1;
2233 tree name
= DECL_NAME (cur
);
2235 if (!IDENTIFIER_MARKED (name
))
2237 tree type
= DECL_CONV_FN_TYPE (cur
);
2239 if (check_hidden_convs (binfo
, virtual_depth
, virtualness
,
2240 type
, parent_convs
, other_convs
))
2242 my_convs
= tree_cons (binfo
, conv
, my_convs
);
2243 TREE_TYPE (my_convs
) = type
;
2246 TREE_STATIC (my_convs
) = 1;
2249 IDENTIFIER_MARKED (name
) = 1;
2257 parent_convs
= tree_cons (binfo
, my_convs
, parent_convs
);
2259 TREE_STATIC (parent_convs
) = 1;
2264 parent_tpl_convs
= tree_cons (binfo
, my_tpl_convs
, parent_tpl_convs
);
2266 TREE_STATIC (parent_convs
) = 1;
2269 child_convs
= other_convs
;
2270 child_tpl_convs
= other_tpl_convs
;
2272 /* Now iterate over each base, looking for more conversions. */
2273 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, base_binfo
); i
++)
2275 tree base_convs
, base_tpl_convs
;
2276 unsigned base_virtualness
;
2278 base_virtualness
= lookup_conversions_r (base_binfo
,
2279 virtual_depth
, virtualness
,
2280 parent_convs
, parent_tpl_convs
,
2281 child_convs
, child_tpl_convs
,
2282 &base_convs
, &base_tpl_convs
);
2283 if (base_virtualness
)
2284 my_virtualness
= virtualness
= 1;
2285 child_convs
= chainon (base_convs
, child_convs
);
2286 child_tpl_convs
= chainon (base_tpl_convs
, child_tpl_convs
);
2289 /* Unmark the conversions found at this level */
2290 for (conv
= my_convs
; conv
; conv
= TREE_CHAIN (conv
))
2291 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (conv
)))) = 0;
2293 *convs
= split_conversions (my_convs
, parent_convs
,
2294 child_convs
, other_convs
);
2295 *tpl_convs
= split_conversions (my_tpl_convs
, parent_tpl_convs
,
2296 child_tpl_convs
, other_tpl_convs
);
2298 return my_virtualness
;
2301 /* Return a TREE_LIST containing all the non-hidden user-defined
2302 conversion functions for TYPE (and its base-classes). The
2303 TREE_VALUE of each node is the FUNCTION_DECL of the conversion
2304 function. The TREE_PURPOSE is the BINFO from which the conversion
2305 functions in this node were selected. This function is effectively
2306 performing a set of member lookups as lookup_fnfield does, but
2307 using the type being converted to as the unique key, rather than the
2311 lookup_conversions (tree type
)
2313 tree convs
, tpl_convs
;
2314 tree list
= NULL_TREE
;
2316 complete_type (type
);
2317 if (!TYPE_BINFO (type
))
2320 lookup_conversions_r (TYPE_BINFO (type
), 0, 0,
2321 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
,
2322 &convs
, &tpl_convs
);
2324 /* Flatten the list-of-lists */
2325 for (; convs
; convs
= TREE_CHAIN (convs
))
2329 for (probe
= TREE_VALUE (convs
); probe
; probe
= next
)
2331 next
= TREE_CHAIN (probe
);
2333 TREE_CHAIN (probe
) = list
;
2338 for (; tpl_convs
; tpl_convs
= TREE_CHAIN (tpl_convs
))
2342 for (probe
= TREE_VALUE (tpl_convs
); probe
; probe
= next
)
2344 next
= TREE_CHAIN (probe
);
2346 TREE_CHAIN (probe
) = list
;
2360 /* Check whether the empty class indicated by EMPTY_BINFO is also present
2361 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
2364 dfs_check_overlap (tree empty_binfo
, void *data
)
2366 struct overlap_info
*oi
= (struct overlap_info
*) data
;
2369 for (binfo
= TYPE_BINFO (oi
->compare_type
);
2371 binfo
= BINFO_BASE_BINFO (binfo
, 0))
2373 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
2375 oi
->found_overlap
= 1;
2378 else if (!BINFO_N_BASE_BINFOS (binfo
))
2385 /* Trivial function to stop base traversal when we find something. */
2388 dfs_no_overlap_yet (tree derived
, int ix
, void *data
)
2390 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
2391 struct overlap_info
*oi
= (struct overlap_info
*) data
;
2393 return !oi
->found_overlap
? binfo
: NULL_TREE
;
2396 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
2397 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
2400 types_overlap_p (tree empty_type
, tree next_type
)
2402 struct overlap_info oi
;
2404 if (! IS_AGGR_TYPE (next_type
))
2406 oi
.compare_type
= next_type
;
2407 oi
.found_overlap
= 0;
2408 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
,
2409 dfs_no_overlap_yet
, &oi
);
2410 return oi
.found_overlap
;
2413 /* Returns the binfo of the first direct or indirect virtual base derived
2414 from BINFO, or NULL if binfo is not via virtual. */
2417 binfo_from_vbase (tree binfo
)
2419 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2421 if (BINFO_VIRTUAL_P (binfo
))
2427 /* Returns the binfo of the first direct or indirect virtual base derived
2428 from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
2432 binfo_via_virtual (tree binfo
, tree limit
)
2434 for (; binfo
&& (!limit
|| !same_type_p (BINFO_TYPE (binfo
), limit
));
2435 binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2437 if (BINFO_VIRTUAL_P (binfo
))
2443 /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
2444 Find the equivalent binfo within whatever graph HERE is located.
2445 This is the inverse of original_binfo. */
2448 copied_binfo (tree binfo
, tree here
)
2450 tree result
= NULL_TREE
;
2452 if (BINFO_VIRTUAL_P (binfo
))
2456 for (t
= here
; BINFO_INHERITANCE_CHAIN (t
);
2457 t
= BINFO_INHERITANCE_CHAIN (t
))
2460 result
= binfo_for_vbase (BINFO_TYPE (binfo
), BINFO_TYPE (t
));
2462 else if (BINFO_INHERITANCE_CHAIN (binfo
))
2468 cbinfo
= copied_binfo (BINFO_INHERITANCE_CHAIN (binfo
), here
);
2469 for (ix
= 0; BINFO_BASE_ITERATE (cbinfo
, ix
, base_binfo
); ix
++)
2470 if (BINFO_TYPE (base_binfo
) == BINFO_TYPE (binfo
))
2472 result
= base_binfo
;
2478 my_friendly_assert (BINFO_TYPE (here
) == BINFO_TYPE (binfo
), 20030202);
2482 my_friendly_assert (result
, 20030202);
2487 binfo_for_vbase (tree base
, tree t
)
2493 for (vbases
= CLASSTYPE_VBASECLASSES (t
), ix
= 0;
2494 VEC_iterate (tree
, vbases
, ix
, binfo
); ix
++)
2495 if (BINFO_TYPE (binfo
) == base
)
2500 /* BINFO is some base binfo of HERE, within some other
2501 hierarchy. Return the equivalent binfo, but in the hierarchy
2502 dominated by HERE. This is the inverse of copied_binfo. If BINFO
2503 is not a base binfo of HERE, returns NULL_TREE. */
2506 original_binfo (tree binfo
, tree here
)
2510 if (BINFO_TYPE (binfo
) == BINFO_TYPE (here
))
2512 else if (BINFO_VIRTUAL_P (binfo
))
2513 result
= (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here
))
2514 ? binfo_for_vbase (BINFO_TYPE (binfo
), BINFO_TYPE (here
))
2516 else if (BINFO_INHERITANCE_CHAIN (binfo
))
2520 base_binfos
= original_binfo (BINFO_INHERITANCE_CHAIN (binfo
), here
);
2526 for (ix
= 0; (base_binfo
= BINFO_BASE_BINFO (base_binfos
, ix
)); ix
++)
2527 if (BINFO_TYPE (base_binfo
) == BINFO_TYPE (binfo
))
2529 result
= base_binfo
;