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
marked_pushdecls_p (tree
, int, void *);
53 static tree
unmarked_pushdecls_p (tree
, int, void *);
54 static tree
dfs_debug_unmarkedp (tree
, int, void *);
55 static tree
dfs_debug_mark (tree
, void *);
56 static tree
dfs_push_type_decls (tree
, void *);
57 static tree
dfs_push_decls (tree
, void *);
58 static tree
add_conversions (tree
, void *);
59 static int look_for_overrides_r (tree
, tree
);
60 static tree
bfs_walk (tree
, tree (*) (tree
, void *),
61 tree (*) (tree
, int, void *), void *);
62 static tree
lookup_field_queue_p (tree
, int, void *);
63 static int shared_member_p (tree
);
64 static tree
lookup_field_r (tree
, void *);
65 static tree
dfs_accessible_queue_p (tree
, int, void *);
66 static tree
dfs_accessible_p (tree
, void *);
67 static tree
dfs_access_in_type (tree
, void *);
68 static access_kind
access_in_type (tree
, tree
);
69 static int protected_accessible_p (tree
, tree
, tree
);
70 static int friend_accessible_p (tree
, tree
, tree
);
71 static void setup_class_bindings (tree
, int);
72 static int template_self_reference_p (tree
, tree
);
73 static tree
dfs_get_pure_virtuals (tree
, void *);
76 /* Variables for gathering statistics. */
77 #ifdef GATHER_STATISTICS
78 static int n_fields_searched
;
79 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
80 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
81 static int n_calls_get_base_type
;
82 static int n_outer_fields_searched
;
83 static int n_contexts_saved
;
84 #endif /* GATHER_STATISTICS */
87 /* Worker for lookup_base. BINFO is the binfo we are searching at,
88 BASE is the RECORD_TYPE we are searching for. ACCESS is the
89 required access checks. IS_VIRTUAL indicates if BINFO is morally
92 If BINFO is of the required type, then *BINFO_PTR is examined to
93 compare with any other instance of BASE we might have already
94 discovered. *BINFO_PTR is initialized and a base_kind return value
95 indicates what kind of base was located.
97 Otherwise BINFO's bases are searched. */
100 lookup_base_r (tree binfo
, tree base
, base_access access
,
101 bool is_virtual
, /* inside a virtual part */
105 tree bases
, accesses
;
106 base_kind found
= bk_not_base
;
108 if (same_type_p (BINFO_TYPE (binfo
), base
))
110 /* We have found a base. Check against what we have found
112 found
= bk_same_type
;
114 found
= bk_via_virtual
;
118 else if (binfo
!= *binfo_ptr
)
120 if (access
!= ba_any
)
122 else if (!is_virtual
)
123 /* Prefer a non-virtual base. */
131 bases
= BINFO_BASE_BINFOS (binfo
);
132 accesses
= BINFO_BASE_ACCESSES (binfo
);
136 for (i
= TREE_VEC_LENGTH (bases
); i
--;)
138 tree base_binfo
= TREE_VEC_ELT (bases
, i
);
141 bk
= lookup_base_r (base_binfo
, base
,
143 is_virtual
|| BINFO_VIRTUAL_P (base_binfo
),
149 if (access
!= ba_any
)
158 my_friendly_assert (found
== bk_not_base
, 20010723);
163 if (found
!= bk_ambig
)
177 /* Returns true if type BASE is accessible in T. (BASE is known to be
178 a (possibly non-proper) base class of T.) */
181 accessible_base_p (tree t
, tree base
)
185 /* [class.access.base]
187 A base class is said to be accessible if an invented public
188 member of the base class is accessible.
190 If BASE is a non-proper base, this condition is trivially
192 if (same_type_p (t
, base
))
194 /* Rather than inventing a public member, we use the implicit
195 public typedef created in the scope of every class. */
196 decl
= TYPE_FIELDS (base
);
197 while (!DECL_SELF_REFERENCE_P (decl
))
198 decl
= TREE_CHAIN (decl
);
199 while (ANON_AGGR_TYPE_P (t
))
200 t
= TYPE_CONTEXT (t
);
201 return accessible_p (t
, decl
);
204 /* Lookup BASE in the hierarchy dominated by T. Do access checking as
205 ACCESS specifies. Return the binfo we discover. If KIND_PTR is
206 non-NULL, fill with information about what kind of base we
209 If the base is inaccessible, or ambiguous, and the ba_quiet bit is
210 not set in ACCESS, then an error is issued and error_mark_node is
211 returned. If the ba_quiet bit is set, then no error is issued and
212 NULL_TREE is returned. */
215 lookup_base (tree t
, tree base
, base_access access
, base_kind
*kind_ptr
)
217 tree binfo
= NULL_TREE
; /* The binfo we've found so far. */
218 tree t_binfo
= NULL_TREE
;
221 if (t
== error_mark_node
|| base
== error_mark_node
)
224 *kind_ptr
= bk_not_base
;
225 return error_mark_node
;
227 my_friendly_assert (TYPE_P (base
), 20011127);
236 t
= complete_type (TYPE_MAIN_VARIANT (t
));
237 t_binfo
= TYPE_BINFO (t
);
240 base
= complete_type (TYPE_MAIN_VARIANT (base
));
243 bk
= lookup_base_r (t_binfo
, base
, access
, 0, &binfo
);
247 /* Check that the base is unambiguous and accessible. */
248 if (access
!= ba_any
)
256 if (!(access
& ba_quiet
))
258 error ("`%T' is an ambiguous base of `%T'", base
, t
);
259 binfo
= error_mark_node
;
264 if ((access
& ~ba_quiet
) != ba_ignore
265 /* If BASE is incomplete, then BASE and TYPE are probably
266 the same, in which case BASE is accessible. If they
267 are not the same, then TYPE is invalid. In that case,
268 there's no need to issue another error here, and
269 there's no implicit typedef to use in the code that
270 follows, so we skip the check. */
271 && COMPLETE_TYPE_P (base
)
272 && !accessible_base_p (t
, base
))
274 if (!(access
& ba_quiet
))
276 error ("`%T' is an inaccessible base of `%T'", base
, t
);
277 binfo
= error_mark_node
;
281 bk
= bk_inaccessible
;
292 /* Worker function for get_dynamic_cast_base_type. */
295 dynamic_cast_base_recurse (tree subtype
, tree binfo
, bool is_via_virtual
,
298 tree binfos
, accesses
;
302 if (BINFO_TYPE (binfo
) == subtype
)
308 *offset_ptr
= BINFO_OFFSET (binfo
);
313 binfos
= BINFO_BASE_BINFOS (binfo
);
314 accesses
= BINFO_BASE_ACCESSES (binfo
);
315 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
316 for (i
= 0; i
< n_baselinks
; i
++)
318 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
319 tree base_access
= TREE_VEC_ELT (accesses
, i
);
322 if (base_access
!= access_public_node
)
324 rval
= dynamic_cast_base_recurse
325 (subtype
, base_binfo
,
326 is_via_virtual
|| BINFO_VIRTUAL_P (base_binfo
), offset_ptr
);
330 worst
= worst
>= 0 ? -3 : worst
;
333 else if (rval
== -3 && worst
!= -1)
339 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
340 started from is related to the required TARGET type, in order to optimize
341 the inheritance graph search. This information is independent of the
342 current context, and ignores private paths, hence get_base_distance is
343 inappropriate. Return a TREE specifying the base offset, BOFF.
344 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
345 and there are no public virtual SUBTYPE bases.
346 BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
347 BOFF == -2, SUBTYPE is not a public base.
348 BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
351 get_dynamic_cast_base_type (tree subtype
, tree target
)
353 tree offset
= NULL_TREE
;
354 int boff
= dynamic_cast_base_recurse (subtype
, TYPE_BINFO (target
),
359 offset
= build_int_2 (boff
, -1);
360 TREE_TYPE (offset
) = ssizetype
;
364 /* Search for a member with name NAME in a multiple inheritance
365 lattice specified by TYPE. If it does not exist, return NULL_TREE.
366 If the member is ambiguously referenced, return `error_mark_node'.
367 Otherwise, return a DECL with the indicated name. If WANT_TYPE is
368 true, type declarations are preferred. */
370 /* Do a 1-level search for NAME as a member of TYPE. The caller must
371 figure out whether it can access this field. (Since it is only one
372 level, this is reasonable.) */
375 lookup_field_1 (tree type
, tree name
, bool want_type
)
379 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
380 || TREE_CODE (type
) == BOUND_TEMPLATE_TEMPLATE_PARM
381 || TREE_CODE (type
) == TYPENAME_TYPE
)
382 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM and
383 BOUND_TEMPLATE_TEMPLATE_PARM are not fields at all;
384 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
385 the code often worked even when we treated the index as a list
387 The TYPE_FIELDS of TYPENAME_TYPE is its TYPENAME_TYPE_FULLNAME. */
391 && DECL_LANG_SPECIFIC (TYPE_NAME (type
))
392 && DECL_SORTED_FIELDS (TYPE_NAME (type
)))
394 tree
*fields
= &DECL_SORTED_FIELDS (TYPE_NAME (type
))->elts
[0];
395 int lo
= 0, hi
= DECL_SORTED_FIELDS (TYPE_NAME (type
))->len
;
402 #ifdef GATHER_STATISTICS
404 #endif /* GATHER_STATISTICS */
406 if (DECL_NAME (fields
[i
]) > name
)
408 else if (DECL_NAME (fields
[i
]) < name
)
414 /* We might have a nested class and a field with the
415 same name; we sorted them appropriately via
416 field_decl_cmp, so just look for the first or last
417 field with this name. */
422 while (i
>= lo
&& DECL_NAME (fields
[i
]) == name
);
423 if (TREE_CODE (field
) != TYPE_DECL
424 && !DECL_CLASS_TEMPLATE_P (field
))
431 while (i
< hi
&& DECL_NAME (fields
[i
]) == name
);
439 field
= TYPE_FIELDS (type
);
441 #ifdef GATHER_STATISTICS
442 n_calls_lookup_field_1
++;
443 #endif /* GATHER_STATISTICS */
444 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
446 #ifdef GATHER_STATISTICS
448 #endif /* GATHER_STATISTICS */
449 my_friendly_assert (DECL_P (field
), 0);
450 if (DECL_NAME (field
) == NULL_TREE
451 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
453 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
, want_type
);
457 if (TREE_CODE (field
) == USING_DECL
)
458 /* For now, we're just treating member using declarations as
459 old ARM-style access declarations. Thus, there's no reason
460 to return a USING_DECL, and the rest of the compiler can't
461 handle it. Once the class is defined, these are purged
462 from TYPE_FIELDS anyhow; see handle_using_decl. */
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 tree binfos
, accesses
;
630 /* Otherwise, scan our baseclasses, and pick the most favorable
632 binfos
= BINFO_BASE_BINFOS (binfo
);
633 accesses
= BINFO_BASE_ACCESSES (binfo
);
634 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
635 for (i
= 0; i
< n_baselinks
; ++i
)
637 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
638 tree base_access
= TREE_VEC_ELT (accesses
, i
);
639 access_kind base_access_now
= BINFO_ACCESS (base_binfo
);
641 if (base_access_now
== ak_none
|| base_access_now
== ak_private
)
642 /* If it was not accessible in the base, or only
643 accessible as a private member, we can't access it
645 base_access_now
= ak_none
;
646 else if (base_access
== access_protected_node
)
647 /* Public and protected members in the base become
649 base_access_now
= ak_protected
;
650 else if (base_access
== access_private_node
)
651 /* Public and protected members in the base become
653 base_access_now
= ak_private
;
655 /* See if the new access, via this base, gives more
656 access than our previous best access. */
657 if (base_access_now
!= ak_none
658 && (access
== ak_none
|| base_access_now
< access
))
660 access
= base_access_now
;
662 /* If the new access is public, we can't do better. */
663 if (access
== ak_public
)
670 /* Note the access to DECL in TYPE. */
671 SET_BINFO_ACCESS (binfo
, access
);
673 /* Mark TYPE as visited so that if we reach it again we do not
674 duplicate our efforts here. */
675 BINFO_MARKED (binfo
) = 1;
680 /* Return the access to DECL in TYPE. */
683 access_in_type (tree type
, tree decl
)
685 tree binfo
= TYPE_BINFO (type
);
687 /* We must take into account
691 If a name can be reached by several paths through a multiple
692 inheritance graph, the access is that of the path that gives
695 The algorithm we use is to make a post-order depth-first traversal
696 of the base-class hierarchy. As we come up the tree, we annotate
697 each node with the most lenient access. */
698 dfs_walk_real (binfo
, 0, dfs_access_in_type
, unmarkedp
, decl
);
699 dfs_walk (binfo
, dfs_unmark
, markedp
, 0);
701 return BINFO_ACCESS (binfo
);
704 /* Called from accessible_p via dfs_walk. */
707 dfs_accessible_queue_p (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
709 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
711 if (BINFO_MARKED (binfo
))
714 /* If this class is inherited via private or protected inheritance,
715 then we can't see it, unless we are a friend of the derived class. */
716 if (BINFO_BASE_ACCESS (derived
, ix
) != access_public_node
717 && !is_friend (BINFO_TYPE (derived
), current_scope ()))
723 /* Called from accessible_p via dfs_walk. */
726 dfs_accessible_p (tree binfo
, void *data ATTRIBUTE_UNUSED
)
730 BINFO_MARKED (binfo
) = 1;
731 access
= BINFO_ACCESS (binfo
);
732 if (access
!= ak_none
733 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
739 /* Returns nonzero if it is OK to access DECL through an object
740 indicated by BINFO in the context of DERIVED. */
743 protected_accessible_p (tree decl
, tree derived
, tree binfo
)
747 /* We're checking this clause from [class.access.base]
749 m as a member of N is protected, and the reference occurs in a
750 member or friend of class N, or in a member or friend of a
751 class P derived from N, where m as a member of P is private or
754 Here DERIVED is a possible P and DECL is m. accessible_p will
755 iterate over various values of N, but the access to m in DERIVED
758 Note that I believe that the passage above is wrong, and should read
759 "...is private or protected or public"; otherwise you get bizarre results
760 whereby a public using-decl can prevent you from accessing a protected
761 member of a base. (jason 2000/02/28) */
763 /* If DERIVED isn't derived from m's class, then it can't be a P. */
764 if (!DERIVED_FROM_P (context_for_name_lookup (decl
), derived
))
767 access
= access_in_type (derived
, decl
);
769 /* If m is inaccessible in DERIVED, then it's not a P. */
770 if (access
== ak_none
)
775 When a friend or a member function of a derived class references
776 a protected nonstatic member of a base class, an access check
777 applies in addition to those described earlier in clause
778 _class.access_) Except when forming a pointer to member
779 (_expr.unary.op_), the access must be through a pointer to,
780 reference to, or object of the derived class itself (or any class
781 derived from that class) (_expr.ref_). If the access is to form
782 a pointer to member, the nested-name-specifier shall name the
783 derived class (or any class derived from that class). */
784 if (DECL_NONSTATIC_MEMBER_P (decl
))
786 /* We can tell through what the reference is occurring by
787 chasing BINFO up to the root. */
789 while (BINFO_INHERITANCE_CHAIN (t
))
790 t
= BINFO_INHERITANCE_CHAIN (t
);
792 if (!DERIVED_FROM_P (derived
, BINFO_TYPE (t
)))
799 /* Returns nonzero if SCOPE is a friend of a type which would be able
800 to access DECL through the object indicated by BINFO. */
803 friend_accessible_p (tree scope
, tree decl
, tree binfo
)
805 tree befriending_classes
;
811 if (TREE_CODE (scope
) == FUNCTION_DECL
812 || DECL_FUNCTION_TEMPLATE_P (scope
))
813 befriending_classes
= DECL_BEFRIENDING_CLASSES (scope
);
814 else if (TYPE_P (scope
))
815 befriending_classes
= CLASSTYPE_BEFRIENDING_CLASSES (scope
);
819 for (t
= befriending_classes
; t
; t
= TREE_CHAIN (t
))
820 if (protected_accessible_p (decl
, TREE_VALUE (t
), binfo
))
823 /* Nested classes are implicitly friends of their enclosing types, as
824 per core issue 45 (this is a change from the standard). */
826 for (t
= TYPE_CONTEXT (scope
); t
&& TYPE_P (t
); t
= TYPE_CONTEXT (t
))
827 if (protected_accessible_p (decl
, t
, binfo
))
830 if (TREE_CODE (scope
) == FUNCTION_DECL
831 || DECL_FUNCTION_TEMPLATE_P (scope
))
833 /* Perhaps this SCOPE is a member of a class which is a
835 if (DECL_CLASS_SCOPE_P (decl
)
836 && friend_accessible_p (DECL_CONTEXT (scope
), decl
, binfo
))
839 /* Or an instantiation of something which is a friend. */
840 if (DECL_TEMPLATE_INFO (scope
))
841 return friend_accessible_p (DECL_TI_TEMPLATE (scope
), decl
, binfo
);
843 else if (CLASSTYPE_TEMPLATE_INFO (scope
))
844 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope
), decl
, binfo
);
849 /* DECL is a declaration from a base class of TYPE, which was the
850 class used to name DECL. Return nonzero if, in the current
851 context, DECL is accessible. If TYPE is actually a BINFO node,
852 then we can tell in what context the access is occurring by looking
853 at the most derived class along the path indicated by BINFO. */
856 accessible_p (tree type
, tree decl
)
863 /* Nonzero if it's OK to access DECL if it has protected
864 accessibility in TYPE. */
865 int protected_ok
= 0;
867 /* If this declaration is in a block or namespace scope, there's no
869 if (!TYPE_P (context_for_name_lookup (decl
)))
872 /* There is no need to perform access checks inside a thunk. */
873 scope
= current_scope ();
874 if (scope
&& DECL_THUNK_P (scope
))
877 /* In a template declaration, we cannot be sure whether the
878 particular specialization that is instantiated will be a friend
879 or not. Therefore, all access checks are deferred until
881 if (processing_template_decl
)
887 type
= BINFO_TYPE (type
);
890 binfo
= TYPE_BINFO (type
);
892 /* [class.access.base]
894 A member m is accessible when named in class N if
896 --m as a member of N is public, or
898 --m as a member of N is private, and the reference occurs in a
899 member or friend of class N, or
901 --m as a member of N is protected, and the reference occurs in a
902 member or friend of class N, or in a member or friend of a
903 class P derived from N, where m as a member of P is private or
906 --there exists a base class B of N that is accessible at the point
907 of reference, and m is accessible when named in class B.
909 We walk the base class hierarchy, checking these conditions. */
911 /* Figure out where the reference is occurring. Check to see if
912 DECL is private or protected in this scope, since that will
913 determine whether protected access is allowed. */
914 if (current_class_type
)
915 protected_ok
= protected_accessible_p (decl
, current_class_type
, binfo
);
917 /* Now, loop through the classes of which we are a friend. */
919 protected_ok
= friend_accessible_p (scope
, decl
, binfo
);
921 /* Standardize the binfo that access_in_type will use. We don't
922 need to know what path was chosen from this point onwards. */
923 binfo
= TYPE_BINFO (type
);
925 /* Compute the accessibility of DECL in the class hierarchy
926 dominated by type. */
927 access
= access_in_type (type
, decl
);
928 if (access
== ak_public
929 || (access
== ak_protected
&& protected_ok
))
933 /* Walk the hierarchy again, looking for a base class that allows
935 t
= dfs_walk (binfo
, dfs_accessible_p
, dfs_accessible_queue_p
, 0);
936 /* Clear any mark bits. Note that we have to walk the whole tree
937 here, since we have aborted the previous walk from some point
939 dfs_walk (binfo
, dfs_unmark
, 0, 0);
941 return t
!= NULL_TREE
;
945 struct lookup_field_info
{
946 /* The type in which we're looking. */
948 /* The name of the field for which we're looking. */
950 /* If non-NULL, the current result of the lookup. */
952 /* The path to RVAL. */
954 /* If non-NULL, the lookup was ambiguous, and this is a list of the
957 /* If nonzero, we are looking for types, not data members. */
959 /* If something went wrong, a message indicating what. */
963 /* Returns nonzero if BINFO is not hidden by the value found by the
964 lookup so far. If BINFO is hidden, then there's no need to look in
965 it. DATA is really a struct lookup_field_info. Called from
966 lookup_field via breadth_first_search. */
969 lookup_field_queue_p (tree derived
, int ix
, void *data
)
971 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
972 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
974 /* Don't look for constructors or destructors in base classes. */
975 if (IDENTIFIER_CTOR_OR_DTOR_P (lfi
->name
))
978 /* If this base class is hidden by the best-known value so far, we
979 don't need to look. */
980 if (lfi
->rval_binfo
&& original_binfo (binfo
, lfi
->rval_binfo
))
983 /* If this is a dependent base, don't look in it. */
984 if (BINFO_DEPENDENT_BASE_P (binfo
))
990 /* Within the scope of a template class, you can refer to the to the
991 current specialization with the name of the template itself. For
994 template <typename T> struct S { S* sp; }
996 Returns nonzero if DECL is such a declaration in a class TYPE. */
999 template_self_reference_p (tree type
, tree decl
)
1001 return (CLASSTYPE_USE_TEMPLATE (type
)
1002 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
))
1003 && TREE_CODE (decl
) == TYPE_DECL
1004 && DECL_ARTIFICIAL (decl
)
1005 && DECL_NAME (decl
) == constructor_name (type
));
1009 /* Nonzero for a class member means that it is shared between all objects
1012 [class.member.lookup]:If the resulting set of declarations are not all
1013 from sub-objects of the same type, or the set has a nonstatic member
1014 and includes members from distinct sub-objects, there is an ambiguity
1015 and the program is ill-formed.
1017 This function checks that T contains no nonstatic members. */
1020 shared_member_p (tree t
)
1022 if (TREE_CODE (t
) == VAR_DECL
|| TREE_CODE (t
) == TYPE_DECL \
1023 || TREE_CODE (t
) == CONST_DECL
)
1025 if (is_overloaded_fn (t
))
1027 for (; t
; t
= OVL_NEXT (t
))
1029 tree fn
= OVL_CURRENT (t
);
1030 if (DECL_NONSTATIC_MEMBER_FUNCTION_P (fn
))
1038 /* DATA is really a struct lookup_field_info. Look for a field with
1039 the name indicated there in BINFO. If this function returns a
1040 non-NULL value it is the result of the lookup. Called from
1041 lookup_field via breadth_first_search. */
1044 lookup_field_r (tree binfo
, void *data
)
1046 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1047 tree type
= BINFO_TYPE (binfo
);
1048 tree nval
= NULL_TREE
;
1050 /* First, look for a function. There can't be a function and a data
1051 member with the same name, and if there's a function and a type
1052 with the same name, the type is hidden by the function. */
1053 if (!lfi
->want_type
)
1055 int idx
= lookup_fnfields_1 (type
, lfi
->name
);
1057 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1061 /* Look for a data member or type. */
1062 nval
= lookup_field_1 (type
, lfi
->name
, lfi
->want_type
);
1064 /* If there is no declaration with the indicated name in this type,
1065 then there's nothing to do. */
1069 /* If we're looking up a type (as with an elaborated type specifier)
1070 we ignore all non-types we find. */
1071 if (lfi
->want_type
&& TREE_CODE (nval
) != TYPE_DECL
1072 && !DECL_CLASS_TEMPLATE_P (nval
))
1074 if (lfi
->name
== TYPE_IDENTIFIER (type
))
1076 /* If the aggregate has no user defined constructors, we allow
1077 it to have fields with the same name as the enclosing type.
1078 If we are looking for that name, find the corresponding
1080 for (nval
= TREE_CHAIN (nval
); nval
; nval
= TREE_CHAIN (nval
))
1081 if (DECL_NAME (nval
) == lfi
->name
1082 && TREE_CODE (nval
) == TYPE_DECL
)
1087 if (!nval
&& CLASSTYPE_NESTED_UTDS (type
) != NULL
)
1089 binding_entry e
= binding_table_find (CLASSTYPE_NESTED_UTDS (type
),
1092 nval
= TYPE_MAIN_DECL (e
->type
);
1098 /* You must name a template base class with a template-id. */
1099 if (!same_type_p (type
, lfi
->type
)
1100 && template_self_reference_p (type
, nval
))
1103 /* If the lookup already found a match, and the new value doesn't
1104 hide the old one, we might have an ambiguity. */
1105 if (lfi
->rval_binfo
&& !original_binfo (lfi
->rval_binfo
, binfo
))
1107 if (nval
== lfi
->rval
&& shared_member_p (nval
))
1108 /* The two things are really the same. */
1110 else if (original_binfo (binfo
, lfi
->rval_binfo
))
1111 /* The previous value hides the new one. */
1115 /* We have a real ambiguity. We keep a chain of all the
1117 if (!lfi
->ambiguous
&& lfi
->rval
)
1119 /* This is the first time we noticed an ambiguity. Add
1120 what we previously thought was a reasonable candidate
1122 lfi
->ambiguous
= tree_cons (NULL_TREE
, lfi
->rval
, NULL_TREE
);
1123 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1126 /* Add the new value. */
1127 lfi
->ambiguous
= tree_cons (NULL_TREE
, nval
, lfi
->ambiguous
);
1128 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1129 lfi
->errstr
= "request for member `%D' is ambiguous";
1135 lfi
->rval_binfo
= binfo
;
1141 /* Return a "baselink" which BASELINK_BINFO, BASELINK_ACCESS_BINFO,
1142 BASELINK_FUNCTIONS, and BASELINK_OPTYPE set to BINFO, ACCESS_BINFO,
1143 FUNCTIONS, and OPTYPE respectively. */
1146 build_baselink (tree binfo
, tree access_binfo
, tree functions
, tree optype
)
1150 my_friendly_assert (TREE_CODE (functions
) == FUNCTION_DECL
1151 || TREE_CODE (functions
) == TEMPLATE_DECL
1152 || TREE_CODE (functions
) == TEMPLATE_ID_EXPR
1153 || TREE_CODE (functions
) == OVERLOAD
,
1155 my_friendly_assert (!optype
|| TYPE_P (optype
), 20020730);
1156 my_friendly_assert (TREE_TYPE (functions
), 20020805);
1158 baselink
= make_node (BASELINK
);
1159 TREE_TYPE (baselink
) = TREE_TYPE (functions
);
1160 BASELINK_BINFO (baselink
) = binfo
;
1161 BASELINK_ACCESS_BINFO (baselink
) = access_binfo
;
1162 BASELINK_FUNCTIONS (baselink
) = functions
;
1163 BASELINK_OPTYPE (baselink
) = optype
;
1168 /* Look for a member named NAME in an inheritance lattice dominated by
1169 XBASETYPE. If PROTECT is 0 or two, we do not check access. If it
1170 is 1, we enforce accessibility. If PROTECT is zero, then, for an
1171 ambiguous lookup, we return NULL. If PROTECT is 1, we issue error
1172 messages about inaccessible or ambiguous lookup. If PROTECT is 2,
1173 we return a TREE_LIST whose TREE_TYPE is error_mark_node and whose
1174 TREE_VALUEs are the list of ambiguous candidates.
1176 WANT_TYPE is 1 when we should only return TYPE_DECLs.
1178 If nothing can be found return NULL_TREE and do not issue an error. */
1181 lookup_member (tree xbasetype
, tree name
, int protect
, bool want_type
)
1183 tree rval
, rval_binfo
= NULL_TREE
;
1184 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1185 struct lookup_field_info lfi
;
1187 /* rval_binfo is the binfo associated with the found member, note,
1188 this can be set with useful information, even when rval is not
1189 set, because it must deal with ALL members, not just non-function
1190 members. It is used for ambiguity checking and the hidden
1191 checks. Whereas rval is only set if a proper (not hidden)
1192 non-function member is found. */
1194 const char *errstr
= 0;
1196 my_friendly_assert (TREE_CODE (name
) == IDENTIFIER_NODE
, 20030624);
1198 if (TREE_CODE (xbasetype
) == TREE_BINFO
)
1200 type
= BINFO_TYPE (xbasetype
);
1201 basetype_path
= xbasetype
;
1205 my_friendly_assert (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)), 20030624);
1207 xbasetype
= NULL_TREE
;
1210 type
= complete_type (type
);
1212 basetype_path
= TYPE_BINFO (type
);
1217 #ifdef GATHER_STATISTICS
1218 n_calls_lookup_field
++;
1219 #endif /* GATHER_STATISTICS */
1221 memset (&lfi
, 0, sizeof (lfi
));
1224 lfi
.want_type
= want_type
;
1225 bfs_walk (basetype_path
, &lookup_field_r
, &lookup_field_queue_p
, &lfi
);
1227 rval_binfo
= lfi
.rval_binfo
;
1229 type
= BINFO_TYPE (rval_binfo
);
1230 errstr
= lfi
.errstr
;
1232 /* If we are not interested in ambiguities, don't report them;
1233 just return NULL_TREE. */
1234 if (!protect
&& lfi
.ambiguous
)
1240 return lfi
.ambiguous
;
1247 In the case of overloaded function names, access control is
1248 applied to the function selected by overloaded resolution. */
1249 if (rval
&& protect
&& !is_overloaded_fn (rval
))
1250 perform_or_defer_access_check (basetype_path
, rval
);
1252 if (errstr
&& protect
)
1254 error (errstr
, name
, type
);
1256 print_candidates (lfi
.ambiguous
);
1257 rval
= error_mark_node
;
1260 if (rval
&& is_overloaded_fn (rval
))
1261 rval
= build_baselink (rval_binfo
, basetype_path
, rval
,
1262 (IDENTIFIER_TYPENAME_P (name
)
1263 ? TREE_TYPE (name
): NULL_TREE
));
1267 /* Like lookup_member, except that if we find a function member we
1268 return NULL_TREE. */
1271 lookup_field (tree xbasetype
, tree name
, int protect
, bool want_type
)
1273 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
);
1275 /* Ignore functions, but propagate the ambiguity list. */
1276 if (!error_operand_p (rval
)
1277 && (rval
&& BASELINK_P (rval
)))
1283 /* Like lookup_member, except that if we find a non-function member we
1284 return NULL_TREE. */
1287 lookup_fnfields (tree xbasetype
, tree name
, int protect
)
1289 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/false);
1291 /* Ignore non-functions, but propagate the ambiguity list. */
1292 if (!error_operand_p (rval
)
1293 && (rval
&& !BASELINK_P (rval
)))
1299 /* Return the index in the CLASSTYPE_METHOD_VEC for CLASS_TYPE
1300 corresponding to "operator TYPE ()", or -1 if there is no such
1301 operator. Only CLASS_TYPE itself is searched; this routine does
1302 not scan the base classes of CLASS_TYPE. */
1305 lookup_conversion_operator (tree class_type
, tree type
)
1310 tree methods
= CLASSTYPE_METHOD_VEC (class_type
);
1312 for (pass
= 0; pass
< 2; ++pass
)
1313 for (i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
1314 i
< TREE_VEC_LENGTH (methods
);
1317 tree fn
= TREE_VEC_ELT (methods
, i
);
1318 /* The size of the vector may have some unused slots at the
1323 /* All the conversion operators come near the beginning of the
1324 class. Therefore, if FN is not a conversion operator, there
1325 is no matching conversion operator in CLASS_TYPE. */
1326 fn
= OVL_CURRENT (fn
);
1327 if (!DECL_CONV_FN_P (fn
))
1332 /* On the first pass we only consider exact matches. If
1333 the types match, this slot is the one where the right
1334 conversion operators can be found. */
1335 if (TREE_CODE (fn
) != TEMPLATE_DECL
1336 && same_type_p (DECL_CONV_FN_TYPE (fn
), type
))
1341 /* On the second pass we look for template conversion
1342 operators. It may be possible to instantiate the
1343 template to get the type desired. All of the template
1344 conversion operators share a slot. By looking for
1345 templates second we ensure that specializations are
1346 preferred over templates. */
1347 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
1355 /* TYPE is a class type. Return the index of the fields within
1356 the method vector with name NAME, or -1 is no such field exists. */
1359 lookup_fnfields_1 (tree type
, tree name
)
1367 if (!CLASS_TYPE_P (type
))
1370 method_vec
= CLASSTYPE_METHOD_VEC (type
);
1375 methods
= &TREE_VEC_ELT (method_vec
, 0);
1376 len
= TREE_VEC_LENGTH (method_vec
);
1378 #ifdef GATHER_STATISTICS
1379 n_calls_lookup_fnfields_1
++;
1380 #endif /* GATHER_STATISTICS */
1382 /* Constructors are first... */
1383 if (name
== ctor_identifier
)
1384 return (methods
[CLASSTYPE_CONSTRUCTOR_SLOT
]
1385 ? CLASSTYPE_CONSTRUCTOR_SLOT
: -1);
1386 /* and destructors are second. */
1387 if (name
== dtor_identifier
)
1388 return (methods
[CLASSTYPE_DESTRUCTOR_SLOT
]
1389 ? CLASSTYPE_DESTRUCTOR_SLOT
: -1);
1390 if (IDENTIFIER_TYPENAME_P (name
))
1391 return lookup_conversion_operator (type
, TREE_TYPE (name
));
1393 /* Skip the conversion operators. */
1394 i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
1395 while (i
< len
&& methods
[i
] && DECL_CONV_FN_P (OVL_CURRENT (methods
[i
])))
1398 /* If the type is complete, use binary search. */
1399 if (COMPLETE_TYPE_P (type
))
1408 #ifdef GATHER_STATISTICS
1409 n_outer_fields_searched
++;
1410 #endif /* GATHER_STATISTICS */
1413 /* This slot may be empty; we allocate more slots than we
1414 need. In that case, the entry we're looking for is
1415 closer to the beginning of the list. */
1417 tmp
= DECL_NAME (OVL_CURRENT (tmp
));
1418 if (!tmp
|| tmp
> name
)
1420 else if (tmp
< name
)
1427 for (; i
< len
&& methods
[i
]; ++i
)
1429 #ifdef GATHER_STATISTICS
1430 n_outer_fields_searched
++;
1431 #endif /* GATHER_STATISTICS */
1433 tmp
= OVL_CURRENT (methods
[i
]);
1434 if (DECL_NAME (tmp
) == name
)
1441 /* DECL is the result of a qualified name lookup. QUALIFYING_SCOPE is
1442 the class or namespace used to qualify the name. CONTEXT_CLASS is
1443 the class corresponding to the object in which DECL will be used.
1444 Return a possibly modified version of DECL that takes into account
1447 In particular, consider an expression like `B::m' in the context of
1448 a derived class `D'. If `B::m' has been resolved to a BASELINK,
1449 then the most derived class indicated by the BASELINK_BINFO will be
1450 `B', not `D'. This function makes that adjustment. */
1453 adjust_result_of_qualified_name_lookup (tree decl
,
1454 tree qualifying_scope
,
1457 if (context_class
&& CLASS_TYPE_P (qualifying_scope
)
1458 && DERIVED_FROM_P (qualifying_scope
, context_class
)
1459 && BASELINK_P (decl
))
1463 my_friendly_assert (CLASS_TYPE_P (context_class
), 20020808);
1465 /* Look for the QUALIFYING_SCOPE as a base of the CONTEXT_CLASS.
1466 Because we do not yet know which function will be chosen by
1467 overload resolution, we cannot yet check either accessibility
1468 or ambiguity -- in either case, the choice of a static member
1469 function might make the usage valid. */
1470 base
= lookup_base (context_class
, qualifying_scope
,
1471 ba_ignore
| ba_quiet
, NULL
);
1474 BASELINK_ACCESS_BINFO (decl
) = base
;
1475 BASELINK_BINFO (decl
)
1476 = lookup_base (base
, BINFO_TYPE (BASELINK_BINFO (decl
)),
1477 ba_ignore
| ba_quiet
,
1486 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1487 type in the hierarchy, in a breadth-first preorder traversal.
1488 If it ever returns a non-NULL value, that value is immediately
1489 returned and the walk is terminated. At each node, FN is passed a
1490 BINFO indicating the path from the currently visited base-class to
1491 TYPE. Before each base-class is walked QFN is called. If the
1492 value returned is nonzero, the base-class is walked; otherwise it
1493 is not. If QFN is NULL, it is treated as a function which always
1494 returns 1. Both FN and QFN are passed the DATA whenever they are
1497 Implementation notes: Uses a circular queue, which starts off on
1498 the stack but gets moved to the malloc arena if it needs to be
1499 enlarged. The underflow and overflow conditions are
1500 indistinguishable except by context: if head == tail and we just
1501 moved the head pointer, the queue is empty, but if we just moved
1502 the tail pointer, the queue is full.
1503 Start with enough room for ten concurrent base classes. That
1504 will be enough for most hierarchies. */
1505 #define BFS_WALK_INITIAL_QUEUE_SIZE 10
1508 bfs_walk (tree binfo
,
1509 tree (*fn
) (tree
, void *),
1510 tree (*qfn
) (tree
, int, void *),
1513 tree rval
= NULL_TREE
;
1515 tree bases_initial
[BFS_WALK_INITIAL_QUEUE_SIZE
];
1516 /* A circular queue of the base classes of BINFO. These will be
1517 built up in breadth-first order, except where QFN prunes the
1520 size_t base_buffer_size
= BFS_WALK_INITIAL_QUEUE_SIZE
;
1521 tree
*base_buffer
= bases_initial
;
1524 base_buffer
[tail
++] = binfo
;
1526 while (head
!= tail
)
1529 tree binfo
= base_buffer
[head
++];
1530 if (head
== base_buffer_size
)
1533 /* Is this the one we're looking for? If so, we're done. */
1534 rval
= fn (binfo
, data
);
1538 n_bases
= BINFO_N_BASE_BINFOS (binfo
);
1539 for (ix
= 0; ix
!= n_bases
; ix
++)
1544 base_binfo
= (*qfn
) (binfo
, ix
, data
);
1546 base_binfo
= BINFO_BASE_BINFO (binfo
, ix
);
1550 base_buffer
[tail
++] = base_binfo
;
1551 if (tail
== base_buffer_size
)
1555 tree
*new_buffer
= xmalloc (2 * base_buffer_size
1557 memcpy (&new_buffer
[0], &base_buffer
[0],
1558 tail
* sizeof (tree
));
1559 memcpy (&new_buffer
[head
+ base_buffer_size
],
1561 (base_buffer_size
- head
) * sizeof (tree
));
1562 if (base_buffer_size
!= BFS_WALK_INITIAL_QUEUE_SIZE
)
1564 base_buffer
= new_buffer
;
1565 head
+= base_buffer_size
;
1566 base_buffer_size
*= 2;
1573 if (base_buffer_size
!= BFS_WALK_INITIAL_QUEUE_SIZE
)
1578 /* Exactly like bfs_walk, except that a depth-first traversal is
1579 performed, and PREFN is called in preorder, while POSTFN is called
1583 dfs_walk_real (tree binfo
,
1584 tree (*prefn
) (tree
, void *),
1585 tree (*postfn
) (tree
, void *),
1586 tree (*qfn
) (tree
, int, void *),
1589 tree rval
= NULL_TREE
;
1591 /* Call the pre-order walking function. */
1594 rval
= (*prefn
) (binfo
, data
);
1599 /* Process the basetypes. */
1600 if (BINFO_BASE_BINFOS (binfo
))
1602 int i
, n
= TREE_VEC_LENGTH (BINFO_BASE_BINFOS (binfo
));
1603 for (i
= 0; i
!= n
; i
++)
1608 base_binfo
= (*qfn
) (binfo
, i
, data
);
1610 base_binfo
= BINFO_BASE_BINFO (binfo
, i
);
1614 rval
= dfs_walk_real (base_binfo
, prefn
, postfn
, qfn
, data
);
1621 /* Call the post-order walking function. */
1623 rval
= (*postfn
) (binfo
, data
);
1628 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1632 dfs_walk (tree binfo
,
1633 tree (*fn
) (tree
, void *),
1634 tree (*qfn
) (tree
, int, void *),
1637 return dfs_walk_real (binfo
, 0, fn
, qfn
, data
);
1640 /* Check that virtual overrider OVERRIDER is acceptable for base function
1641 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1644 check_final_overrider (tree overrider
, tree basefn
)
1646 tree over_type
= TREE_TYPE (overrider
);
1647 tree base_type
= TREE_TYPE (basefn
);
1648 tree over_return
= TREE_TYPE (over_type
);
1649 tree base_return
= TREE_TYPE (base_type
);
1650 tree over_throw
= TYPE_RAISES_EXCEPTIONS (over_type
);
1651 tree base_throw
= TYPE_RAISES_EXCEPTIONS (base_type
);
1654 if (DECL_INVALID_OVERRIDER_P (overrider
))
1657 if (same_type_p (base_return
, over_return
))
1659 else if ((CLASS_TYPE_P (over_return
) && CLASS_TYPE_P (base_return
))
1660 || (TREE_CODE (base_return
) == TREE_CODE (over_return
)
1661 && POINTER_TYPE_P (base_return
)))
1663 /* Potentially covariant. */
1664 unsigned base_quals
, over_quals
;
1666 fail
= !POINTER_TYPE_P (base_return
);
1669 fail
= cp_type_quals (base_return
) != cp_type_quals (over_return
);
1671 base_return
= TREE_TYPE (base_return
);
1672 over_return
= TREE_TYPE (over_return
);
1674 base_quals
= cp_type_quals (base_return
);
1675 over_quals
= cp_type_quals (over_return
);
1677 if ((base_quals
& over_quals
) != over_quals
)
1680 if (CLASS_TYPE_P (base_return
) && CLASS_TYPE_P (over_return
))
1682 tree binfo
= lookup_base (over_return
, base_return
,
1683 ba_check
| ba_quiet
, NULL
);
1689 && can_convert (TREE_TYPE (base_type
), TREE_TYPE (over_type
)))
1690 /* GNU extension, allow trivial pointer conversions such as
1691 converting to void *, or qualification conversion. */
1693 /* can_convert will permit user defined conversion from a
1694 (reference to) class type. We must reject them. */
1695 over_return
= non_reference (TREE_TYPE (over_type
));
1696 if (CLASS_TYPE_P (over_return
))
1710 cp_error_at ("invalid covariant return type for `%#D'", overrider
);
1711 cp_error_at (" overriding `%#D'", basefn
);
1715 cp_error_at ("conflicting return type specified for `%#D'",
1717 cp_error_at (" overriding `%#D'", basefn
);
1719 DECL_INVALID_OVERRIDER_P (overrider
) = 1;
1723 /* Check throw specifier is at least as strict. */
1724 if (!comp_except_specs (base_throw
, over_throw
, 0))
1726 cp_error_at ("looser throw specifier for `%#F'", overrider
);
1727 cp_error_at (" overriding `%#F'", basefn
);
1728 DECL_INVALID_OVERRIDER_P (overrider
) = 1;
1735 /* Given a class TYPE, and a function decl FNDECL, look for
1736 virtual functions in TYPE's hierarchy which FNDECL overrides.
1737 We do not look in TYPE itself, only its bases.
1739 Returns nonzero, if we find any. Set FNDECL's DECL_VIRTUAL_P, if we
1740 find that it overrides anything.
1742 We check that every function which is overridden, is correctly
1746 look_for_overrides (tree type
, tree fndecl
)
1748 tree binfo
= TYPE_BINFO (type
);
1749 tree basebinfos
= BINFO_BASE_BINFOS (binfo
);
1750 int nbasebinfos
= basebinfos
? TREE_VEC_LENGTH (basebinfos
) : 0;
1754 for (ix
= 0; ix
!= nbasebinfos
; ix
++)
1756 tree basetype
= BINFO_TYPE (TREE_VEC_ELT (basebinfos
, ix
));
1758 if (TYPE_POLYMORPHIC_P (basetype
))
1759 found
+= look_for_overrides_r (basetype
, fndecl
);
1764 /* Look in TYPE for virtual functions with the same signature as
1768 look_for_overrides_here (tree type
, tree fndecl
)
1772 if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (fndecl
))
1773 ix
= CLASSTYPE_DESTRUCTOR_SLOT
;
1775 ix
= lookup_fnfields_1 (type
, DECL_NAME (fndecl
));
1778 tree fns
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), ix
);
1780 for (; fns
; fns
= OVL_NEXT (fns
))
1782 tree fn
= OVL_CURRENT (fns
);
1784 if (!DECL_VIRTUAL_P (fn
))
1785 /* Not a virtual. */;
1786 else if (DECL_CONTEXT (fn
) != type
)
1787 /* Introduced with a using declaration. */;
1788 else if (DECL_STATIC_FUNCTION_P (fndecl
))
1790 tree btypes
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1791 tree dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1792 if (compparms (TREE_CHAIN (btypes
), dtypes
))
1795 else if (same_signature_p (fndecl
, fn
))
1802 /* Look in TYPE for virtual functions overridden by FNDECL. Check both
1803 TYPE itself and its bases. */
1806 look_for_overrides_r (tree type
, tree fndecl
)
1808 tree fn
= look_for_overrides_here (type
, fndecl
);
1811 if (DECL_STATIC_FUNCTION_P (fndecl
))
1813 /* A static member function cannot match an inherited
1814 virtual member function. */
1815 cp_error_at ("`%#D' cannot be declared", fndecl
);
1816 cp_error_at (" since `%#D' declared in base class", fn
);
1820 /* It's definitely virtual, even if not explicitly set. */
1821 DECL_VIRTUAL_P (fndecl
) = 1;
1822 check_final_overrider (fndecl
, fn
);
1827 /* We failed to find one declared in this class. Look in its bases. */
1828 return look_for_overrides (type
, fndecl
);
1831 /* Called via dfs_walk from dfs_get_pure_virtuals. */
1834 dfs_get_pure_virtuals (tree binfo
, void *data
)
1836 tree type
= (tree
) data
;
1838 /* We're not interested in primary base classes; the derived class
1839 of which they are a primary base will contain the information we
1841 if (!BINFO_PRIMARY_P (binfo
))
1845 for (virtuals
= BINFO_VIRTUALS (binfo
);
1847 virtuals
= TREE_CHAIN (virtuals
))
1848 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals
)))
1849 CLASSTYPE_PURE_VIRTUALS (type
)
1850 = tree_cons (NULL_TREE
, BV_FN (virtuals
),
1851 CLASSTYPE_PURE_VIRTUALS (type
));
1854 BINFO_MARKED (binfo
) = 1;
1859 /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
1862 get_pure_virtuals (tree type
)
1867 /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
1868 is going to be overridden. */
1869 CLASSTYPE_PURE_VIRTUALS (type
) = NULL_TREE
;
1870 /* Now, run through all the bases which are not primary bases, and
1871 collect the pure virtual functions. We look at the vtable in
1872 each class to determine what pure virtual functions are present.
1873 (A primary base is not interesting because the derived class of
1874 which it is a primary base will contain vtable entries for the
1875 pure virtuals in the base class. */
1876 dfs_walk (TYPE_BINFO (type
), dfs_get_pure_virtuals
, unmarkedp
, type
);
1877 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
, type
);
1879 /* Put the pure virtuals in dfs order. */
1880 CLASSTYPE_PURE_VIRTUALS (type
) = nreverse (CLASSTYPE_PURE_VIRTUALS (type
));
1882 for (ix
= 0; (binfo
= VEC_iterate
1883 (tree
, CLASSTYPE_VBASECLASSES (type
), ix
)); ix
++)
1887 for (virtuals
= BINFO_VIRTUALS (binfo
); virtuals
;
1888 virtuals
= TREE_CHAIN (virtuals
))
1890 tree base_fndecl
= BV_FN (virtuals
);
1891 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
1892 error ("`%#D' needs a final overrider", base_fndecl
);
1897 /* DEPTH-FIRST SEARCH ROUTINES. */
1900 markedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1902 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
1904 return BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
1908 unmarkedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1910 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
1912 return !BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
1916 marked_pushdecls_p (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1918 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
1920 return (!BINFO_DEPENDENT_BASE_P (binfo
)
1921 && BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
1925 unmarked_pushdecls_p (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
1927 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
1929 return (!BINFO_DEPENDENT_BASE_P (binfo
)
1930 && !BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
1933 /* The worker functions for `dfs_walk'. These do not need to
1934 test anything (vis a vis marking) if they are paired with
1935 a predicate function (above). */
1938 dfs_unmark (tree binfo
, void *data ATTRIBUTE_UNUSED
)
1940 BINFO_MARKED (binfo
) = 0;
1945 /* Debug info for C++ classes can get very large; try to avoid
1946 emitting it everywhere.
1948 Note that this optimization wins even when the target supports
1949 BINCL (if only slightly), and reduces the amount of work for the
1953 maybe_suppress_debug_info (tree t
)
1955 /* We can't do the usual TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
1956 does not support name references between translation units. It supports
1957 symbolic references between translation units, but only within a single
1958 executable or shared library.
1960 For DWARF 2, we handle TYPE_DECL_SUPPRESS_DEBUG by pretending
1961 that the type was never defined, so we only get the members we
1963 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== NO_DEBUG
)
1966 /* We might have set this earlier in cp_finish_decl. */
1967 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 0;
1969 /* If we already know how we're handling this class, handle debug info
1971 if (CLASSTYPE_INTERFACE_KNOWN (t
))
1973 if (CLASSTYPE_INTERFACE_ONLY (t
))
1974 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
1975 /* else don't set it. */
1977 /* If the class has a vtable, write out the debug info along with
1979 else if (TYPE_CONTAINS_VPTR_P (t
))
1980 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
1982 /* Otherwise, just emit the debug info normally. */
1985 /* Note that we want debugging information for a base class of a class
1986 whose vtable is being emitted. Normally, this would happen because
1987 calling the constructor for a derived class implies calling the
1988 constructors for all bases, which involve initializing the
1989 appropriate vptr with the vtable for the base class; but in the
1990 presence of optimization, this initialization may be optimized
1991 away, so we tell finish_vtable_vardecl that we want the debugging
1992 information anyway. */
1995 dfs_debug_mark (tree binfo
, void *data ATTRIBUTE_UNUSED
)
1997 tree t
= BINFO_TYPE (binfo
);
1999 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2004 /* Returns BINFO if we haven't already noted that we want debugging
2005 info for this base class. */
2008 dfs_debug_unmarkedp (tree derived
, int ix
, void *data ATTRIBUTE_UNUSED
)
2010 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
2012 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
))
2013 ? binfo
: NULL_TREE
);
2016 /* Write out the debugging information for TYPE, whose vtable is being
2017 emitted. Also walk through our bases and note that we want to
2018 write out information for them. This avoids the problem of not
2019 writing any debug info for intermediate basetypes whose
2020 constructors, and thus the references to their vtables, and thus
2021 the vtables themselves, were optimized away. */
2024 note_debug_info_needed (tree type
)
2026 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)))
2028 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)) = 0;
2029 rest_of_type_compilation (type
, toplevel_bindings_p ());
2032 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
, 0);
2035 /* A vector of IDENTIFIER_NODEs that have been processed by
2036 setup_class_bindings. */
2038 static GTY(()) VEC(tree
) *marked_identifiers
;
2040 /* Subroutines of push_class_decls (). */
2043 setup_class_bindings (tree name
, int type_binding_p
)
2045 tree type_binding
= NULL_TREE
;
2048 /* If we've already done the lookup for this declaration, we're
2050 if (IDENTIFIER_MARKED (name
))
2053 IDENTIFIER_MARKED (name
) = 1;
2054 VEC_safe_push (tree
, marked_identifiers
, 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 /* Two conversion operators that convert to the same type
2095 may have different names. (See
2096 mangle_conv_op_name_for_type.) To avoid recording the
2097 same conversion operator declaration more than once we
2098 must check to see that the same operator was not already
2099 found under another name. */
2100 if (IDENTIFIER_TYPENAME_P (name
)
2101 && is_overloaded_fn (value_binding
))
2104 for (fns
= value_binding
; fns
; fns
= OVL_NEXT (fns
))
2106 tree name
= DECL_NAME (OVL_CURRENT (fns
));
2107 if (IDENTIFIER_MARKED (name
))
2109 IDENTIFIER_MARKED (name
) = 1;
2110 VEC_safe_push (tree
, marked_identifiers
, name
);
2113 pushdecl_class_level (value_binding
);
2118 /* Push class-level declarations for any names appearing in BINFO that
2122 dfs_push_type_decls (tree binfo
, void *data ATTRIBUTE_UNUSED
)
2127 type
= BINFO_TYPE (binfo
);
2128 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2129 if (DECL_NAME (fields
) && TREE_CODE (fields
) == TYPE_DECL
2130 && !(!same_type_p (type
, current_class_type
)
2131 && template_self_reference_p (type
, fields
)))
2132 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/1);
2134 /* We can't just use BINFO_MARKED because envelope_add_decl uses
2135 DERIVED_FROM_P, which calls get_base_distance. */
2136 BINFO_PUSHDECLS_MARKED (binfo
) = 1;
2141 /* Push class-level declarations for any names appearing in BINFO that
2142 are not TYPE_DECLS. */
2145 dfs_push_decls (tree binfo
, void *data
)
2147 tree type
= BINFO_TYPE (binfo
);
2151 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2152 if (DECL_NAME (fields
)
2153 && TREE_CODE (fields
) != TYPE_DECL
2154 && TREE_CODE (fields
) != USING_DECL
2155 && !DECL_ARTIFICIAL (fields
))
2156 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/0);
2157 else if (TREE_CODE (fields
) == FIELD_DECL
2158 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
2159 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields
)), data
);
2161 method_vec
= (CLASS_TYPE_P (type
)
2162 ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
);
2164 if (method_vec
&& TREE_VEC_LENGTH (method_vec
) >= 3)
2169 /* Farm out constructors and destructors. */
2170 end
= TREE_VEC_END (method_vec
);
2172 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
2173 methods
< end
&& *methods
;
2175 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods
)),
2176 /*type_binding_p=*/0);
2179 BINFO_PUSHDECLS_MARKED (binfo
) = 0;
2184 /* When entering the scope of a class, we cache all of the
2185 fields that that class provides within its inheritance
2186 lattice. Where ambiguities result, we mark them
2187 with `error_mark_node' so that if they are encountered
2188 without explicit qualification, we can emit an error
2192 push_class_decls (tree type
)
2197 if (!TYPE_BINFO (type
))
2198 /* This occurs when parsing an invalid declarator id where the
2199 scope is incomplete. */
2202 /* Enter type declarations and mark. */
2203 dfs_walk (TYPE_BINFO (type
), dfs_push_type_decls
, unmarked_pushdecls_p
, 0);
2205 /* Enter non-type declarations and unmark. */
2206 dfs_walk (TYPE_BINFO (type
), dfs_push_decls
, marked_pushdecls_p
, 0);
2208 /* Clear the IDENTIFIER_MARKED bits. */
2210 (id
= VEC_iterate (tree
, marked_identifiers
, i
));
2212 IDENTIFIER_MARKED (id
) = 0;
2213 if (marked_identifiers
)
2214 VEC_truncate (tree
, marked_identifiers
, 0);
2218 print_search_statistics (void)
2220 #ifdef GATHER_STATISTICS
2221 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
2222 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
2223 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
2224 n_outer_fields_searched
, n_calls_lookup_fnfields
);
2225 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
2226 #else /* GATHER_STATISTICS */
2227 fprintf (stderr
, "no search statistics\n");
2228 #endif /* GATHER_STATISTICS */
2232 reinit_search_statistics (void)
2234 #ifdef GATHER_STATISTICS
2235 n_fields_searched
= 0;
2236 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
2237 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
2238 n_calls_get_base_type
= 0;
2239 n_outer_fields_searched
= 0;
2240 n_contexts_saved
= 0;
2241 #endif /* GATHER_STATISTICS */
2245 add_conversions (tree binfo
, void *data
)
2248 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
2249 tree
*conversions
= (tree
*) data
;
2251 /* Some builtin types have no method vector, not even an empty one. */
2255 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
2257 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
2260 if (!tmp
|| ! DECL_CONV_FN_P (OVL_CURRENT (tmp
)))
2263 name
= DECL_NAME (OVL_CURRENT (tmp
));
2265 /* Make sure we don't already have this conversion. */
2266 if (! IDENTIFIER_MARKED (name
))
2270 /* Make sure that we do not already have a conversion
2271 operator for this type. Merely checking the NAME is not
2272 enough because two conversion operators to the same type
2273 may not have the same NAME. */
2274 for (t
= *conversions
; t
; t
= TREE_CHAIN (t
))
2277 for (fn
= TREE_VALUE (t
); fn
; fn
= OVL_NEXT (fn
))
2278 if (same_type_p (TREE_TYPE (name
),
2279 DECL_CONV_FN_TYPE (OVL_CURRENT (fn
))))
2286 *conversions
= tree_cons (binfo
, tmp
, *conversions
);
2287 IDENTIFIER_MARKED (name
) = 1;
2294 /* Return a TREE_LIST containing all the non-hidden user-defined
2295 conversion functions for TYPE (and its base-classes). The
2296 TREE_VALUE of each node is a FUNCTION_DECL or an OVERLOAD
2297 containing the conversion functions. The TREE_PURPOSE is the BINFO
2298 from which the conversion functions in this node were selected. */
2301 lookup_conversions (tree type
)
2304 tree conversions
= NULL_TREE
;
2306 complete_type (type
);
2307 if (TYPE_BINFO (type
))
2308 bfs_walk (TYPE_BINFO (type
), add_conversions
, 0, &conversions
);
2310 for (t
= conversions
; t
; t
= TREE_CHAIN (t
))
2311 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t
)))) = 0;
2322 /* Check whether the empty class indicated by EMPTY_BINFO is also present
2323 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
2326 dfs_check_overlap (tree empty_binfo
, void *data
)
2328 struct overlap_info
*oi
= (struct overlap_info
*) data
;
2330 for (binfo
= TYPE_BINFO (oi
->compare_type
);
2332 binfo
= BINFO_BASE_BINFO (binfo
, 0))
2334 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
2336 oi
->found_overlap
= 1;
2339 else if (BINFO_BASE_BINFOS (binfo
) == NULL_TREE
)
2346 /* Trivial function to stop base traversal when we find something. */
2349 dfs_no_overlap_yet (tree derived
, int ix
, void *data
)
2351 tree binfo
= BINFO_BASE_BINFO (derived
, ix
);
2352 struct overlap_info
*oi
= (struct overlap_info
*) data
;
2354 return !oi
->found_overlap
? binfo
: NULL_TREE
;
2357 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
2358 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
2361 types_overlap_p (tree empty_type
, tree next_type
)
2363 struct overlap_info oi
;
2365 if (! IS_AGGR_TYPE (next_type
))
2367 oi
.compare_type
= next_type
;
2368 oi
.found_overlap
= 0;
2369 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
,
2370 dfs_no_overlap_yet
, &oi
);
2371 return oi
.found_overlap
;
2374 /* Given a vtable VAR, determine which of the inherited classes the vtable
2375 inherits (in a loose sense) functions from.
2377 FIXME: This does not work with the new ABI. */
2380 binfo_for_vtable (tree var
)
2382 tree main_binfo
= TYPE_BINFO (DECL_CONTEXT (var
));
2383 tree binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (BINFO_TYPE (main_binfo
)));
2384 int n_baseclasses
= BINFO_N_BASE_BINFOS (TYPE_BINFO (BINFO_TYPE (main_binfo
)));
2387 for (i
= 0; i
< n_baseclasses
; i
++)
2389 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2390 if (base_binfo
!= NULL_TREE
&& BINFO_VTABLE (base_binfo
) == var
)
2394 /* If no secondary base classes matched, return the primary base, if
2396 if (CLASSTYPE_HAS_PRIMARY_BASE_P (BINFO_TYPE (main_binfo
)))
2397 return get_primary_binfo (main_binfo
);
2402 /* Returns the binfo of the first direct or indirect virtual base derived
2403 from BINFO, or NULL if binfo is not via virtual. */
2406 binfo_from_vbase (tree binfo
)
2408 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2410 if (BINFO_VIRTUAL_P (binfo
))
2416 /* Returns the binfo of the first direct or indirect virtual base derived
2417 from BINFO up to the TREE_TYPE, LIMIT, or NULL if binfo is not
2421 binfo_via_virtual (tree binfo
, tree limit
)
2423 for (; binfo
&& (!limit
|| !same_type_p (BINFO_TYPE (binfo
), limit
));
2424 binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2426 if (BINFO_VIRTUAL_P (binfo
))
2432 /* BINFO is a base binfo in the complete type BINFO_TYPE (HERE).
2433 Find the equivalent binfo within whatever graph HERE is located.
2434 This is the inverse of original_binfo. */
2437 copied_binfo (tree binfo
, tree here
)
2439 tree result
= NULL_TREE
;
2441 if (BINFO_VIRTUAL_P (binfo
))
2445 for (t
= here
; BINFO_INHERITANCE_CHAIN (t
);
2446 t
= BINFO_INHERITANCE_CHAIN (t
))
2449 result
= binfo_for_vbase (BINFO_TYPE (binfo
), BINFO_TYPE (t
));
2451 else if (BINFO_INHERITANCE_CHAIN (binfo
))
2456 base_binfos
= copied_binfo (BINFO_INHERITANCE_CHAIN (binfo
), here
);
2457 base_binfos
= BINFO_BASE_BINFOS (base_binfos
);
2458 n
= TREE_VEC_LENGTH (base_binfos
);
2459 for (ix
= 0; ix
!= n
; ix
++)
2461 tree base
= TREE_VEC_ELT (base_binfos
, ix
);
2463 if (BINFO_TYPE (base
) == BINFO_TYPE (binfo
))
2472 my_friendly_assert (BINFO_TYPE (here
) == BINFO_TYPE (binfo
), 20030202);
2476 my_friendly_assert (result
, 20030202);
2481 binfo_for_vbase (tree base
, tree t
)
2486 for (ix
= 0; (binfo
= VEC_iterate
2487 (tree
, CLASSTYPE_VBASECLASSES (t
), ix
)); ix
++)
2488 if (BINFO_TYPE (binfo
) == base
)
2493 /* BINFO is some base binfo of HERE, within some other
2494 hierarchy. Return the equivalent binfo, but in the hierarchy
2495 dominated by HERE. This is the inverse of copied_binfo. If BINFO
2496 is not a base binfo of HERE, returns NULL_TREE. */
2499 original_binfo (tree binfo
, tree here
)
2503 if (BINFO_TYPE (binfo
) == BINFO_TYPE (here
))
2505 else if (BINFO_VIRTUAL_P (binfo
))
2506 result
= (CLASSTYPE_VBASECLASSES (BINFO_TYPE (here
))
2507 ? binfo_for_vbase (BINFO_TYPE (binfo
), BINFO_TYPE (here
))
2509 else if (BINFO_INHERITANCE_CHAIN (binfo
))
2513 base_binfos
= original_binfo (BINFO_INHERITANCE_CHAIN (binfo
), here
);
2518 base_binfos
= BINFO_BASE_BINFOS (base_binfos
);
2519 n
= TREE_VEC_LENGTH (base_binfos
);
2520 for (ix
= 0; ix
!= n
; ix
++)
2522 tree base
= TREE_VEC_ELT (base_binfos
, ix
);
2524 if (BINFO_TYPE (base
) == BINFO_TYPE (binfo
))
2536 #include "gt-cp-search.h"