1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 89, 92-97, 1998, 1999 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* High-level class interface. */
35 #define obstack_chunk_alloc xmalloc
36 #define obstack_chunk_free free
38 extern struct obstack *current_obstack;
42 /* Obstack used for remembering decision points of breadth-first. */
44 static struct obstack search_obstack;
46 /* Methods for pushing and popping objects to and from obstacks. */
49 push_stack_level (obstack, tp, size)
50 struct obstack *obstack;
51 char *tp; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
54 struct stack_level *stack;
55 obstack_grow (obstack, tp, size);
56 stack = (struct stack_level *) ((char*)obstack_next_free (obstack) - size);
57 obstack_finish (obstack);
58 stack->obstack = obstack;
59 stack->first = (tree *) obstack_base (obstack);
60 stack->limit = obstack_room (obstack) / sizeof (tree *);
65 pop_stack_level (stack)
66 struct stack_level *stack;
68 struct stack_level *tem = stack;
69 struct obstack *obstack = tem->obstack;
71 obstack_free (obstack, tem);
75 #define search_level stack_level
76 static struct search_level *search_stack;
78 static tree get_abstract_virtuals_1 PROTO((tree, int, tree));
79 static tree next_baselink PROTO((tree));
80 static tree get_vbase_1 PROTO((tree, tree, unsigned int *));
81 static tree convert_pointer_to_vbase PROTO((tree, tree));
82 static tree lookup_field_1 PROTO((tree, tree));
83 static tree convert_pointer_to_single_level PROTO((tree, tree));
84 static int lookup_fnfields_here PROTO((tree, tree));
85 static int is_subobject_of_p PROTO((tree, tree));
86 static int hides PROTO((tree, tree));
87 static tree virtual_context PROTO((tree, tree, tree));
88 static tree dfs_check_overlap PROTO((tree, void *));
89 static tree dfs_no_overlap_yet PROTO((tree, void *));
90 static int get_base_distance_recursive
91 PROTO((tree, int, int, int, int *, tree *, tree,
92 int, int *, int, int));
93 static int dynamic_cast_base_recurse PROTO((tree, tree, int, tree *));
94 static void expand_upcast_fixups
95 PROTO((tree, tree, tree, tree, tree, tree, tree *));
96 static void fixup_virtual_upcast_offsets
97 PROTO((tree, tree, int, int, tree, tree, tree, tree,
99 static tree unmarkedp PROTO((tree, void *));
100 static tree marked_vtable_pathp PROTO((tree, void *));
101 static tree unmarked_vtable_pathp PROTO((tree, void *));
102 static tree marked_new_vtablep PROTO((tree, void *));
103 static tree unmarked_new_vtablep PROTO((tree, void *));
104 static tree marked_pushdecls_p PROTO((tree, void *));
105 static tree unmarked_pushdecls_p PROTO((tree, void *));
107 static tree dfs_debug_unmarkedp PROTO((tree, void *));
108 static tree dfs_debug_mark PROTO((tree, void *));
110 static tree dfs_find_vbases PROTO((tree, void *));
111 static tree dfs_clear_vbase_slots PROTO((tree, void *));
112 static tree dfs_init_vbase_pointers PROTO((tree, void *));
113 static tree dfs_get_vbase_types PROTO((tree, void *));
114 static tree dfs_push_type_decls PROTO((tree, void *));
115 static tree dfs_push_decls PROTO((tree, void *));
116 static tree dfs_unuse_fields PROTO((tree, void *));
117 static tree add_conversions PROTO((tree, void *));
118 static tree get_virtuals_named_this PROTO((tree, tree));
119 static tree get_virtual_destructor PROTO((tree, void *));
120 static tree tree_has_any_destructor_p PROTO((tree, void *));
121 static int covariant_return_p PROTO((tree, tree));
122 static int check_final_overrider PROTO((tree, tree));
123 static struct search_level *push_search_level
124 PROTO((struct stack_level *, struct obstack *));
125 static struct search_level *pop_search_level
126 PROTO((struct stack_level *));
128 PROTO((tree, tree (*) (tree, void *), tree (*) (tree, void *),
130 static tree lookup_field_queue_p PROTO((tree, void *));
131 static tree lookup_field_r PROTO((tree, void *));
132 static tree dfs_walk_real PROTO ((tree,
133 tree (*) (tree, void *),
134 tree (*) (tree, void *),
135 tree (*) (tree, void *),
137 static tree get_virtuals_named_this_r PROTO ((tree, void *));
138 static tree context_for_name_lookup PROTO ((tree));
139 static tree canonical_binfo PROTO ((tree));
140 static tree shared_marked_p PROTO ((tree, void *));
141 static tree shared_unmarked_p PROTO ((tree, void *));
142 static int dependent_base_p PROTO ((tree));
143 static tree dfs_accessible_queue_p PROTO ((tree, void *));
144 static tree dfs_accessible_p PROTO ((tree, void *));
145 static tree dfs_access_in_type PROTO ((tree, void *));
146 static tree access_in_type PROTO ((tree, tree));
147 static tree dfs_canonical_queue PROTO ((tree, void *));
148 static tree dfs_assert_unmarked_p PROTO ((tree, void *));
149 static void assert_canonical_unmarked PROTO ((tree));
150 static int protected_accessible_p PROTO ((tree, tree, tree, tree));
151 static int friend_accessible_p PROTO ((tree, tree, tree, tree));
152 static void setup_class_bindings PROTO ((tree, int));
153 static int template_self_reference_p PROTO ((tree, tree));
154 static void fixup_all_virtual_upcast_offsets PROTO ((tree, tree));
156 /* Allocate a level of searching. */
158 static struct search_level *
159 push_search_level (stack, obstack)
160 struct stack_level *stack;
161 struct obstack *obstack;
163 struct search_level tem;
166 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
169 /* Discard a level of search allocation. */
171 static struct search_level *
172 pop_search_level (obstack)
173 struct stack_level *obstack;
175 register struct search_level *stack = pop_stack_level (obstack);
180 /* Variables for gathering statistics. */
181 #ifdef GATHER_STATISTICS
182 static int n_fields_searched;
183 static int n_calls_lookup_field, n_calls_lookup_field_1;
184 static int n_calls_lookup_fnfields, n_calls_lookup_fnfields_1;
185 static int n_calls_get_base_type;
186 static int n_outer_fields_searched;
187 static int n_contexts_saved;
188 #endif /* GATHER_STATISTICS */
191 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
192 the same type as the type given in PARENT. To be optimal, we want
193 the first one that is found by going through the least number of
196 This uses a clever algorithm that updates *depth when we find the vbase,
197 and cuts off other paths of search when they reach that depth. */
200 get_vbase_1 (parent, binfo, depth)
206 tree rval = NULL_TREE;
208 if (BINFO_TYPE (binfo) == parent && TREE_VIA_VIRTUAL (binfo))
216 binfos = BINFO_BASETYPES (binfo);
217 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
219 /* Process base types. */
220 for (i = 0; i < n_baselinks; i++)
222 tree base_binfo = TREE_VEC_ELT (binfos, i);
228 nrval = get_vbase_1 (parent, base_binfo, depth);
236 /* Return the shortest path to vbase PARENT within BINFO, ignoring
237 access and ambiguity. */
240 get_vbase (parent, binfo)
244 unsigned int d = (unsigned int)-1;
245 return get_vbase_1 (parent, binfo, &d);
248 /* Convert EXPR to a virtual base class of type TYPE. We know that
249 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
250 the type of what expr points to has a virtual base of type TYPE. */
253 convert_pointer_to_vbase (type, expr)
257 tree vb = get_vbase (type, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr))));
258 return convert_pointer_to_real (vb, expr);
261 /* Check whether the type given in BINFO is derived from PARENT. If
262 it isn't, return 0. If it is, but the derivation is MI-ambiguous
263 AND protect != 0, emit an error message and return error_mark_node.
265 Otherwise, if TYPE is derived from PARENT, return the actual base
266 information, unless a one of the protection violations below
267 occurs, in which case emit an error message and return error_mark_node.
269 If PROTECT is 1, then check if access to a public field of PARENT
270 would be private. Also check for ambiguity. */
273 get_binfo (parent, binfo, protect)
274 register tree parent, binfo;
277 tree type = NULL_TREE;
279 tree rval = NULL_TREE;
281 if (TREE_CODE (parent) == TREE_VEC)
282 parent = BINFO_TYPE (parent);
283 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent)))
284 my_friendly_abort (89);
286 if (TREE_CODE (binfo) == TREE_VEC)
287 type = BINFO_TYPE (binfo);
288 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo)))
291 my_friendly_abort (90);
293 dist = get_base_distance (parent, binfo, protect, &rval);
297 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
299 return error_mark_node;
301 else if (dist == -2 && protect)
303 cp_error ("type `%T' is ambiguous base class for type `%T'", parent,
305 return error_mark_node;
311 /* This is the newer depth first get_base_distance routine. */
314 get_base_distance_recursive (binfo, depth, is_private, rval,
315 rval_private_ptr, new_binfo_ptr, parent,
316 protect, via_virtual_ptr, via_virtual,
317 current_scope_in_chain)
319 int depth, is_private, rval;
320 int *rval_private_ptr;
321 tree *new_binfo_ptr, parent;
322 int protect, *via_virtual_ptr, via_virtual;
323 int current_scope_in_chain;
329 && !current_scope_in_chain
330 && is_friend (BINFO_TYPE (binfo), current_scope ()))
331 current_scope_in_chain = 1;
333 if (BINFO_TYPE (binfo) == parent || binfo == parent)
338 /* This is the first time we've found parent. */
340 else if (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr),
341 BINFO_OFFSET (binfo))
342 && *via_virtual_ptr && via_virtual)
344 /* A new path to the same vbase. If this one has better
345 access or is shorter, take it. */
348 better = *rval_private_ptr - is_private;
350 better = rval - depth;
354 /* Ambiguous base class. */
357 /* If we get an ambiguity between virtual and non-virtual base
358 class, return the non-virtual in case we are ignoring
360 better = *via_virtual_ptr - via_virtual;
366 *rval_private_ptr = is_private;
367 *new_binfo_ptr = binfo;
368 *via_virtual_ptr = via_virtual;
374 binfos = BINFO_BASETYPES (binfo);
375 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
378 /* Process base types. */
379 for (i = 0; i < n_baselinks; i++)
381 tree base_binfo = TREE_VEC_ELT (binfos, i);
386 || (!TREE_VIA_PUBLIC (base_binfo)
387 && !(TREE_VIA_PROTECTED (base_binfo)
388 && current_scope_in_chain)
389 && !is_friend (BINFO_TYPE (binfo), current_scope ()))));
390 int this_virtual = via_virtual || TREE_VIA_VIRTUAL (base_binfo);
392 rval = get_base_distance_recursive (base_binfo, depth, via_private,
393 rval, rval_private_ptr,
394 new_binfo_ptr, parent,
395 protect, via_virtual_ptr,
397 current_scope_in_chain);
399 /* If we've found a non-virtual, ambiguous base class, we don't need
400 to keep searching. */
401 if (rval == -2 && *via_virtual_ptr == 0)
408 /* Return the number of levels between type PARENT and the type given
409 in BINFO, following the leftmost path to PARENT not found along a
410 virtual path, if there are no real PARENTs (all come from virtual
411 base classes), then follow the shortest public path to PARENT.
413 Return -1 if TYPE is not derived from PARENT.
414 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
416 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
418 If PATH_PTR is non-NULL, then also build the list of types
419 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
422 PARENT can also be a binfo, in which case that exact parent is found
423 and no other. convert_pointer_to_real uses this functionality.
425 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
428 get_base_distance (parent, binfo, protect, path_ptr)
429 register tree parent, binfo;
434 int rval_private = 0;
435 tree type = NULL_TREE;
436 tree new_binfo = NULL_TREE;
438 int watch_access = protect;
440 /* Should we be completing types here? */
441 if (TREE_CODE (parent) != TREE_VEC)
442 parent = complete_type (TYPE_MAIN_VARIANT (parent));
444 complete_type (TREE_TYPE (parent));
446 if (TREE_CODE (binfo) == TREE_VEC)
447 type = BINFO_TYPE (binfo);
448 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo)))
450 type = complete_type (binfo);
451 binfo = TYPE_BINFO (type);
454 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo) == NULL_TREE,
458 my_friendly_abort (92);
460 if (parent == type || parent == binfo)
462 /* If the distance is 0, then we don't really need
463 a path pointer, but we shouldn't let garbage go back. */
472 rval = get_base_distance_recursive (binfo, 0, 0, -1,
473 &rval_private, &new_binfo, parent,
474 watch_access, &via_virtual, 0,
477 /* Access restrictions don't count if we found an ambiguous basetype. */
478 if (rval == -2 && protect >= 0)
481 if (rval && protect && rval_private)
484 /* If they gave us the real vbase binfo, which isn't in the main binfo
485 tree, deal with it. This happens when we are called from
486 expand_upcast_fixups. */
487 if (rval == -1 && TREE_CODE (parent) == TREE_VEC
488 && parent == binfo_member (BINFO_TYPE (parent),
489 CLASSTYPE_VBASECLASSES (type)))
491 my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent) == binfo, 980827);
497 *path_ptr = new_binfo;
501 /* Worker function for get_dynamic_cast_base_type. */
504 dynamic_cast_base_recurse (subtype, binfo, via_virtual, offset_ptr)
514 if (BINFO_TYPE (binfo) == subtype)
520 *offset_ptr = BINFO_OFFSET (binfo);
525 binfos = BINFO_BASETYPES (binfo);
526 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
527 for (i = 0; i < n_baselinks; i++)
529 tree base_binfo = TREE_VEC_ELT (binfos, i);
532 if (!TREE_VIA_PUBLIC (base_binfo))
534 rval = dynamic_cast_base_recurse
535 (subtype, base_binfo,
536 via_virtual || TREE_VIA_VIRTUAL (base_binfo), offset_ptr);
540 worst = worst >= 0 ? -1 : worst;
542 worst = worst < rval ? worst : rval;
547 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type started
548 from is related to the required TARGET type, in order to optimize the
549 inheritance graph search. This information is independant of the
550 current context, and ignores private paths, hence get_base_distance is
551 inappropriate. Return a TREE specifying the base offset, BOFF.
552 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
553 and there are no public virtual SUBTYPE bases.
554 BOFF == -1, SUBTYPE occurs as multiple public non-virtual bases.
555 BOFF == -2, SUBTYPE occurs as multiple public virtual or non-virtual bases.
556 BOFF == -3, SUBTYPE is not a public base. */
559 get_dynamic_cast_base_type (subtype, target)
563 tree offset = NULL_TREE;
564 int boff = dynamic_cast_base_recurse (subtype, TYPE_BINFO (target),
569 return build_int_2 (boff, -1);
572 /* Search for a member with name NAME in a multiple inheritance lattice
573 specified by TYPE. If it does not exist, return NULL_TREE.
574 If the member is ambiguously referenced, return `error_mark_node'.
575 Otherwise, return the FIELD_DECL. */
577 /* Do a 1-level search for NAME as a member of TYPE. The caller must
578 figure out whether it can access this field. (Since it is only one
579 level, this is reasonable.) */
582 lookup_field_1 (type, name)
587 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
588 || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
589 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
590 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
591 the code often worked even when we treated the index as a list
596 && DECL_LANG_SPECIFIC (TYPE_NAME (type))
597 && DECL_SORTED_FIELDS (TYPE_NAME (type)))
599 tree *fields = &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type)), 0);
600 int lo = 0, hi = TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type)));
607 #ifdef GATHER_STATISTICS
609 #endif /* GATHER_STATISTICS */
611 if (DECL_NAME (fields[i]) > name)
613 else if (DECL_NAME (fields[i]) < name)
621 field = TYPE_FIELDS (type);
623 #ifdef GATHER_STATISTICS
624 n_calls_lookup_field_1++;
625 #endif /* GATHER_STATISTICS */
628 #ifdef GATHER_STATISTICS
630 #endif /* GATHER_STATISTICS */
631 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field)) == 'd', 0);
632 if (DECL_NAME (field) == NULL_TREE
633 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
635 tree temp = lookup_field_1 (TREE_TYPE (field), name);
639 if (TREE_CODE (field) == USING_DECL)
640 /* For now, we're just treating member using declarations as
641 old ARM-style access declarations. Thus, there's no reason
642 to return a USING_DECL, and the rest of the compiler can't
643 handle it. Once the class is defined, these are purged
644 from TYPE_FIELDS anyhow; see handle_using_decl. */
646 else if (DECL_NAME (field) == name)
648 if ((TREE_CODE(field) == VAR_DECL || TREE_CODE(field) == CONST_DECL)
649 && DECL_ASSEMBLER_NAME (field) != NULL)
650 GNU_xref_ref(current_function_decl,
651 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field)));
654 field = TREE_CHAIN (field);
657 if (name == vptr_identifier)
659 /* Give the user what s/he thinks s/he wants. */
660 if (TYPE_POLYMORPHIC_P (type))
661 return TYPE_VFIELD (type);
666 /* There are a number of cases we need to be aware of here:
667 current_class_type current_function_decl
674 Those last two make life interesting. If we're in a function which is
675 itself inside a class, we need decls to go into the fn's decls (our
676 second case below). But if we're in a class and the class itself is
677 inside a function, we need decls to go into the decls for the class. To
678 achieve this last goal, we must see if, when both current_class_ptr and
679 current_function_decl are set, the class was declared inside that
680 function. If so, we know to put the decls into the class's scope. */
685 if (current_function_decl == NULL_TREE)
686 return current_class_type;
687 if (current_class_type == NULL_TREE)
688 return current_function_decl;
689 if (DECL_CLASS_CONTEXT (current_function_decl) == current_class_type)
690 return current_function_decl;
692 return current_class_type;
695 /* Returns non-zero if we are currently in a function scope. Note
696 that this function returns zero if we are within a local class, but
697 not within a member function body of the local class. */
700 at_function_scope_p ()
702 tree cs = current_scope ();
703 return cs && TREE_CODE (cs) == FUNCTION_DECL;
706 /* Return the scope of DECL, as appropriate when doing name-lookup. */
709 context_for_name_lookup (decl)
714 For the purposes of name lookup, after the anonymous union
715 definition, the members of the anonymous union are considered to
716 have been defined in the scope in which teh anonymous union is
718 tree context = DECL_REAL_CONTEXT (decl);
720 while (TYPE_P (context) && ANON_AGGR_TYPE_P (context))
721 context = TYPE_CONTEXT (context);
723 context = global_namespace;
728 /* Return a canonical BINFO if BINFO is a virtual base, or just BINFO
732 canonical_binfo (binfo)
735 return (TREE_VIA_VIRTUAL (binfo)
736 ? TYPE_BINFO (BINFO_TYPE (binfo)) : binfo);
739 /* A queue function that simply ensures that we walk into the
740 canonical versions of virtual bases. */
743 dfs_canonical_queue (binfo, data)
745 void *data ATTRIBUTE_UNUSED;
747 return canonical_binfo (binfo);
750 /* Called via dfs_walk from assert_canonical_unmarked. */
753 dfs_assert_unmarked_p (binfo, data)
755 void *data ATTRIBUTE_UNUSED;
757 my_friendly_assert (!BINFO_MARKED (binfo), 0);
761 /* Asserts that all the nodes below BINFO (using the canonical
762 versions of virtual bases) are unmarked. */
765 assert_canonical_unmarked (binfo)
768 dfs_walk (binfo, dfs_assert_unmarked_p, dfs_canonical_queue, 0);
771 /* If BINFO is marked, return a canonical version of BINFO.
772 Otherwise, return NULL_TREE. */
775 shared_marked_p (binfo, data)
779 binfo = canonical_binfo (binfo);
780 return markedp (binfo, data) ? binfo : NULL_TREE;
783 /* If BINFO is not marked, return a canonical version of BINFO.
784 Otherwise, return NULL_TREE. */
787 shared_unmarked_p (binfo, data)
791 binfo = canonical_binfo (binfo);
792 return unmarkedp (binfo, data) ? binfo : NULL_TREE;
795 /* Called from access_in_type via dfs_walk. Calculate the access to
796 DATA (which is really a DECL) in BINFO. */
799 dfs_access_in_type (binfo, data)
803 tree decl = (tree) data;
804 tree type = BINFO_TYPE (binfo);
805 tree access = NULL_TREE;
807 if (context_for_name_lookup (decl) == type)
809 /* If we have desceneded to the scope of DECL, just note the
810 appropriate access. */
811 if (TREE_PRIVATE (decl))
812 access = access_private_node;
813 else if (TREE_PROTECTED (decl))
814 access = access_protected_node;
816 access = access_public_node;
820 /* First, check for an access-declaration that gives us more
821 access to the DECL. The CONST_DECL for an enumeration
822 constant will not have DECL_LANG_SPECIFIC, and thus no
824 if (DECL_LANG_SPECIFIC (decl))
826 access = purpose_member (type, DECL_ACCESS (decl));
828 access = TREE_VALUE (access);
837 /* Otherwise, scan our baseclasses, and pick the most favorable
839 binfos = BINFO_BASETYPES (binfo);
840 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
841 for (i = 0; i < n_baselinks; ++i)
843 tree base_binfo = TREE_VEC_ELT (binfos, i);
844 tree base_access = TREE_CHAIN (canonical_binfo (base_binfo));
846 if (!base_access || base_access == access_private_node)
847 /* If it was not accessible in the base, or only
848 accessible as a private member, we can't access it
850 base_access = NULL_TREE;
851 else if (TREE_VIA_PROTECTED (base_binfo))
852 /* Public and protected members in the base are
854 base_access = access_protected_node;
855 else if (!TREE_VIA_PUBLIC (base_binfo))
856 /* Public and protected members in the base are
858 base_access = access_private_node;
860 /* See if the new access, via this base, gives more
861 access than our previous best access. */
863 (base_access == access_public_node
864 || (base_access == access_protected_node
865 && access != access_public_node)
866 || (base_access == access_private_node
869 access = base_access;
871 /* If the new access is public, we can't do better. */
872 if (access == access_public_node)
879 /* Note the access to DECL in TYPE. */
880 TREE_CHAIN (binfo) = access;
882 /* Mark TYPE as visited so that if we reach it again we do not
883 duplicate our efforts here. */
884 SET_BINFO_MARKED (binfo);
889 /* Return the access to DECL in TYPE. */
892 access_in_type (type, decl)
896 tree binfo = TYPE_BINFO (type);
898 /* We must take into account
902 If a name can be reached by several paths through a multiple
903 inheritance graph, the access is that of the path that gives
906 The algorithm we use is to make a post-order depth-first traversal
907 of the base-class hierarchy. As we come up the tree, we annotate
908 each node with the most lenient access. */
909 dfs_walk_real (binfo, 0, dfs_access_in_type, shared_unmarked_p, decl);
910 dfs_walk (binfo, dfs_unmark, shared_marked_p, 0);
911 assert_canonical_unmarked (binfo);
913 return TREE_CHAIN (binfo);
916 /* Called from dfs_accessible_p via dfs_walk. */
919 dfs_accessible_queue_p (binfo, data)
921 void *data ATTRIBUTE_UNUSED;
923 if (BINFO_MARKED (binfo))
926 /* If this class is inherited via private or protected inheritance,
927 then we can't see it, unless we are a friend of the subclass. */
928 if (!TREE_VIA_PUBLIC (binfo)
929 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo)),
933 return canonical_binfo (binfo);
936 /* Called from dfs_accessible_p via dfs_walk. */
939 dfs_accessible_p (binfo, data)
943 int protected_ok = data != 0;
946 /* We marked the binfos while computing the access in each type.
947 So, we unmark as we go now. */
948 SET_BINFO_MARKED (binfo);
950 access = TREE_CHAIN (binfo);
951 if (access == access_public_node
952 || (access == access_protected_node && protected_ok))
954 else if (access && is_friend (BINFO_TYPE (binfo), current_scope ()))
960 /* Returns non-zero if it is OK to access DECL when named in TYPE
961 through an object indiated by BINFO in the context of DERIVED. */
964 protected_accessible_p (type, decl, derived, binfo)
972 /* We're checking this clause from [class.access.base]
974 m as a member of N is protected, and the reference occurs in a
975 member or friend of class N, or in a member or friend of a
976 class P derived from N, where m as a member of P is private or
979 If DERIVED isn't derived from TYPE, then it certainly does not
981 if (!DERIVED_FROM_P (type, derived))
984 access = access_in_type (derived, decl);
985 if (same_type_p (derived, type))
987 if (access != access_private_node)
990 else if (access != access_private_node
991 && access != access_protected_node)
996 When a friend or a member function of a derived class references
997 a protected nonstatic member of a base class, an access check
998 applies in addition to those described earlier in clause
999 _class.access_.4) Except when forming a pointer to member
1000 (_expr.unary.op_), the access must be through a pointer to,
1001 reference to, or object of the derived class itself (or any class
1002 derived from that class) (_expr.ref_). If the access is to form
1003 a pointer to member, the nested-name-specifier shall name the
1004 derived class (or any class derived from that class). */
1005 if (DECL_NONSTATIC_MEMBER_P (decl))
1007 /* We can tell through what the reference is occurring by
1008 chasing BINFO up to the root. */
1010 while (BINFO_INHERITANCE_CHAIN (t))
1011 t = BINFO_INHERITANCE_CHAIN (t);
1013 if (!DERIVED_FROM_P (derived, BINFO_TYPE (t)))
1020 /* Returns non-zero if SCOPE is a friend of a type which would be able
1021 to acces DECL, named in TYPE, through the object indicated by
1025 friend_accessible_p (scope, type, decl, binfo)
1031 tree befriending_classes;
1037 if (TREE_CODE (scope) == FUNCTION_DECL
1038 || DECL_FUNCTION_TEMPLATE_P (scope))
1039 befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
1040 else if (TYPE_P (scope))
1041 befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
1045 for (t = befriending_classes; t; t = TREE_CHAIN (t))
1046 if (protected_accessible_p (type, decl, TREE_VALUE (t), binfo))
1049 if (TREE_CODE (scope) == FUNCTION_DECL
1050 || DECL_FUNCTION_TEMPLATE_P (scope))
1052 /* Perhaps this SCOPE is a member of a class which is a
1054 if (friend_accessible_p (DECL_CLASS_CONTEXT (scope), type,
1058 /* Or an instantiation of something which is a friend. */
1059 if (DECL_TEMPLATE_INFO (scope))
1060 return friend_accessible_p (DECL_TI_TEMPLATE (scope),
1063 else if (CLASSTYPE_TEMPLATE_INFO (scope))
1064 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope),
1070 /* DECL is a declaration from a base class of TYPE, which was the
1071 classs used to name DECL. Return non-zero if, in the current
1072 context, DECL is accessible. If TYPE is actually a BINFO node,
1073 then we can tell in what context the access is occurring by looking
1074 at the most derived class along the path indicated by BINFO. */
1077 accessible_p (type, decl)
1085 /* Non-zero if it's OK to access DECL if it has protected
1086 accessibility in TYPE. */
1087 int protected_ok = 0;
1089 /* If we're not checking access, everything is accessible. */
1090 if (!flag_access_control)
1093 /* If this declaration is in a block or namespace scope, there's no
1095 if (!TYPE_P (context_for_name_lookup (decl)))
1098 /* We don't do access control for types yet. */
1099 if (TREE_CODE (decl) == TYPE_DECL)
1105 type = BINFO_TYPE (type);
1108 binfo = TYPE_BINFO (type);
1110 /* [class.access.base]
1112 A member m is accessible when named in class N if
1114 --m as a member of N is public, or
1116 --m as a member of N is private, and the reference occurs in a
1117 member or friend of class N, or
1119 --m as a member of N is protected, and the reference occurs in a
1120 member or friend of class N, or in a member or friend of a
1121 class P derived from N, where m as a member of P is private or
1124 --there exists a base class B of N that is accessible at the point
1125 of reference, and m is accessible when named in class B.
1127 We walk the base class hierarchy, checking these conditions. */
1129 /* Figure out where the reference is occurring. Check to see if
1130 DECL is private or protected in this scope, since that will
1131 determine whether protected access in TYPE allowed. */
1132 if (current_class_type)
1134 = protected_accessible_p (type, decl, current_class_type,
1137 /* Now, loop through the classes of which we are a friend. */
1139 protected_ok = friend_accessible_p (current_scope (),
1142 /* Standardize on the same that will access_in_type will use. We
1143 don't need to know what path was chosen from this point onwards. */
1144 binfo = TYPE_BINFO (type);
1146 /* Compute the accessibility of DECL in the class hierarchy
1147 dominated by type. */
1148 access_in_type (type, decl);
1149 /* Walk the hierarchy again, looking for a base class that allows
1151 t = dfs_walk (binfo, dfs_accessible_p,
1152 dfs_accessible_queue_p,
1153 protected_ok ? &protected_ok : 0);
1154 /* Clear any mark bits. Note that we have to walk the whole tree
1155 here, since we have aborted the previous walk from some point
1156 deep in the tree. */
1157 dfs_walk (binfo, dfs_unmark, dfs_canonical_queue, 0);
1158 assert_canonical_unmarked (binfo);
1160 return t != NULL_TREE;
1163 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1164 found as a base class and sub-object of the object denoted by
1165 BINFO. This routine relies upon binfos not being shared, except
1166 for binfos for virtual bases. */
1169 is_subobject_of_p (parent, binfo)
1175 /* We want to canonicalize for comparison purposes. But, when we
1176 iterate through basetypes later, we want the binfos from the
1177 original hierarchy. That's why we have to calculate BINFOS
1178 first, and then canonicalize. */
1179 binfos = BINFO_BASETYPES (binfo);
1180 parent = canonical_binfo (parent);
1181 binfo = canonical_binfo (binfo);
1183 if (parent == binfo)
1186 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1188 /* Process and/or queue base types. */
1189 for (i = 0; i < n_baselinks; i++)
1191 tree base_binfo = TREE_VEC_ELT (binfos, i);
1192 if (!CLASS_TYPE_P (TREE_TYPE (base_binfo)))
1193 /* If we see a TEMPLATE_TYPE_PARM, or some such, as a base
1194 class there's no way to descend into it. */
1197 if (is_subobject_of_p (parent, base_binfo))
1203 /* See if a one FIELD_DECL hides another. This routine is meant to
1204 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1205 binfos given are the binfos corresponding to the particular places
1206 the FIELD_DECLs are found. This routine relies upon binfos not
1207 being shared, except for virtual bases. */
1210 hides (hider_binfo, hidee_binfo)
1211 tree hider_binfo, hidee_binfo;
1213 /* hider hides hidee, if hider has hidee as a base class and
1214 the instance of hidee is a sub-object of hider. The first
1215 part is always true is the second part is true.
1217 When hider and hidee are the same (two ways to get to the exact
1218 same member) we consider either one as hiding the other. */
1219 return is_subobject_of_p (hidee_binfo, hider_binfo);
1222 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1223 function was declared inside the class given by TYPE. It really should
1224 only return functions that match the given TYPE. */
1227 lookup_fnfields_here (type, name)
1230 int idx = lookup_fnfields_1 (type, name);
1233 /* ctors and dtors are always only in the right class. */
1236 fndecls = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1239 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls)))
1240 == TYPE_MAIN_VARIANT (type))
1242 fndecls = OVL_CHAIN (fndecls);
1247 struct lookup_field_info {
1248 /* The type in which we're looking. */
1250 /* The name of the field for which we're looking. */
1252 /* If non-NULL, the current result of the lookup. */
1254 /* The path to RVAL. */
1256 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1259 /* If non-zero, we are looking for types, not data members. */
1261 /* If non-zero, RVAL was found by looking through a dependent base. */
1262 int from_dep_base_p;
1263 /* If something went wrong, a message indicating what. */
1267 /* Returns non-zero if BINFO is not hidden by the value found by the
1268 lookup so far. If BINFO is hidden, then there's no need to look in
1269 it. DATA is really a struct lookup_field_info. Called from
1270 lookup_field via breadth_first_search. */
1273 lookup_field_queue_p (binfo, data)
1277 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1279 /* Don't look for constructors or destructors in base classes. */
1280 if (lfi->name == ctor_identifier || lfi->name == dtor_identifier)
1283 /* If this base class is hidden by the best-known value so far, we
1284 don't need to look. */
1285 if (!lfi->from_dep_base_p && lfi->rval_binfo
1286 && hides (lfi->rval_binfo, binfo))
1289 if (TREE_VIA_VIRTUAL (binfo))
1290 return binfo_member (BINFO_TYPE (binfo),
1291 CLASSTYPE_VBASECLASSES (lfi->type));
1296 /* Within the scope of a template class, you can refer to the to the
1297 current specialization with the name of the template itself. For
1300 template <typename T> struct S { S* sp; }
1302 Returns non-zero if DECL is such a declaration in a class TYPE. */
1305 template_self_reference_p (type, decl)
1309 return (CLASSTYPE_USE_TEMPLATE (type)
1310 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))
1311 && TREE_CODE (decl) == TYPE_DECL
1312 && DECL_ARTIFICIAL (decl)
1313 && DECL_NAME (decl) == constructor_name (type));
1316 /* DATA is really a struct lookup_field_info. Look for a field with
1317 the name indicated there in BINFO. If this function returns a
1318 non-NULL value it is the result of the lookup. Called from
1319 lookup_field via breadth_first_search. */
1322 lookup_field_r (binfo, data)
1326 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1327 tree type = BINFO_TYPE (binfo);
1328 tree nval = NULL_TREE;
1329 int from_dep_base_p;
1331 /* First, look for a function. There can't be a function and a data
1332 member with the same name, and if there's a function and a type
1333 with the same name, the type is hidden by the function. */
1334 if (!lfi->want_type)
1336 int idx = lookup_fnfields_here (type, lfi->name);
1338 nval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1342 /* Look for a data member or type. */
1343 nval = lookup_field_1 (type, lfi->name);
1345 /* If there is no declaration with the indicated name in this type,
1346 then there's nothing to do. */
1350 /* If we're looking up a type (as with an elaborated type specifier)
1351 we ignore all non-types we find. */
1352 if (lfi->want_type && TREE_CODE (nval) != TYPE_DECL)
1354 nval = purpose_member (lfi->name, CLASSTYPE_TAGS (type));
1356 nval = TYPE_MAIN_DECL (TREE_VALUE (nval));
1361 /* You must name a template base class with a template-id. */
1362 if (!same_type_p (type, lfi->type)
1363 && template_self_reference_p (type, nval))
1366 from_dep_base_p = dependent_base_p (binfo);
1367 if (lfi->from_dep_base_p && !from_dep_base_p)
1369 /* If the new declaration is not found via a dependent base, and
1370 the old one was, then we must prefer the new one. We weren't
1371 really supposed to be able to find the old one, so we don't
1372 want to be affected by a specialization. Consider:
1374 struct B { typedef int I; };
1375 template <typename T> struct D1 : virtual public B {};
1376 template <typename T> struct D :
1377 public D1, virtual pubic B { I i; };
1379 The `I' in `D<T>' is unambigousuly `B::I', regardless of how
1380 D1 is specialized. */
1381 lfi->from_dep_base_p = 0;
1382 lfi->rval = NULL_TREE;
1383 lfi->rval_binfo = NULL_TREE;
1384 lfi->ambiguous = NULL_TREE;
1387 else if (lfi->rval_binfo && !lfi->from_dep_base_p && from_dep_base_p)
1388 /* Similarly, if the old declaration was not found via a dependent
1389 base, and the new one is, ignore the new one. */
1392 /* If the lookup already found a match, and the new value doesn't
1393 hide the old one, we might have an ambiguity. */
1394 if (lfi->rval_binfo && !hides (binfo, lfi->rval_binfo))
1396 if (nval == lfi->rval && SHARED_MEMBER_P (nval))
1397 /* The two things are really the same. */
1399 else if (hides (lfi->rval_binfo, binfo))
1400 /* The previous value hides the new one. */
1404 /* We have a real ambiguity. We keep a chain of all the
1406 if (!lfi->ambiguous && lfi->rval)
1408 /* This is the first time we noticed an ambiguity. Add
1409 what we previously thought was a reasonable candidate
1411 lfi->ambiguous = tree_cons (NULL_TREE, lfi->rval, NULL_TREE);
1412 TREE_TYPE (lfi->ambiguous) = error_mark_node;
1415 /* Add the new value. */
1416 lfi->ambiguous = tree_cons (NULL_TREE, nval, lfi->ambiguous);
1417 TREE_TYPE (lfi->ambiguous) = error_mark_node;
1418 lfi->errstr = "request for member `%D' is ambiguous";
1423 /* If the thing we're looking for is a virtual base class, then
1424 we know we've got what we want at this point; there's no way
1425 to get an ambiguity. */
1426 if (VBASE_NAME_P (lfi->name))
1432 if (from_dep_base_p && TREE_CODE (nval) != TYPE_DECL
1433 /* We need to return a member template class so we can
1434 define partial specializations. Is there a better
1436 && !DECL_CLASS_TEMPLATE_P (nval))
1437 /* The thing we're looking for isn't a type, so the implicit
1438 typename extension doesn't apply, so we just pretend we
1439 didn't find anything. */
1443 lfi->from_dep_base_p = from_dep_base_p;
1444 lfi->rval_binfo = binfo;
1450 /* Look for a memer named NAME in an inheritance lattice dominated by
1451 XBASETYPE. PROTECT is 0 or two, we do not check access. If it is
1452 1, we enforce accessibility. If PROTECT is zero, then, for an
1453 ambiguous lookup, we return NULL. If PROTECT is 1, we issue an
1454 error message. If PROTECT is 2, we return a TREE_LIST whose
1455 TREEE_TYPE is error_mark_node and whose TREE_VALUEs are the list of
1456 ambiguous candidates.
1458 WANT_TYPE is 1 when we should only return TYPE_DECLs, if no
1459 TYPE_DECL can be found return NULL_TREE. */
1462 lookup_member (xbasetype, name, protect, want_type)
1463 register tree xbasetype, name;
1464 int protect, want_type;
1466 tree rval, rval_binfo = NULL_TREE;
1467 tree type = NULL_TREE, basetype_path = NULL_TREE;
1468 struct lookup_field_info lfi;
1470 /* rval_binfo is the binfo associated with the found member, note,
1471 this can be set with useful information, even when rval is not
1472 set, because it must deal with ALL members, not just non-function
1473 members. It is used for ambiguity checking and the hidden
1474 checks. Whereas rval is only set if a proper (not hidden)
1475 non-function member is found. */
1477 const char *errstr = 0;
1479 if (xbasetype == current_class_type && TYPE_BEING_DEFINED (xbasetype)
1480 && IDENTIFIER_CLASS_VALUE (name))
1482 tree field = IDENTIFIER_CLASS_VALUE (name);
1483 if (TREE_CODE (field) != FUNCTION_DECL
1484 && ! (want_type && TREE_CODE (field) != TYPE_DECL))
1485 /* We're in the scope of this class, and the value has already
1486 been looked up. Just return the cached value. */
1490 if (TREE_CODE (xbasetype) == TREE_VEC)
1492 type = BINFO_TYPE (xbasetype);
1493 basetype_path = xbasetype;
1495 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)))
1498 basetype_path = TYPE_BINFO (type);
1499 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path) == NULL_TREE,
1503 my_friendly_abort (97);
1505 complete_type (type);
1507 #ifdef GATHER_STATISTICS
1508 n_calls_lookup_field++;
1509 #endif /* GATHER_STATISTICS */
1511 bzero ((PTR) &lfi, sizeof (lfi));
1514 lfi.want_type = want_type;
1515 bfs_walk (basetype_path, &lookup_field_r, &lookup_field_queue_p, &lfi);
1517 rval_binfo = lfi.rval_binfo;
1519 type = BINFO_TYPE (rval_binfo);
1520 errstr = lfi.errstr;
1522 /* If we are not interested in ambiguities, don't report them;
1523 just return NULL_TREE. */
1524 if (!protect && lfi.ambiguous)
1530 return lfi.ambiguous;
1537 In the case of overloaded function names, access control is
1538 applied to the function selected by overloaded resolution. */
1539 if (rval && protect && !is_overloaded_fn (rval)
1540 && !enforce_access (xbasetype, rval))
1541 return error_mark_node;
1543 if (errstr && protect)
1545 cp_error (errstr, name, type);
1547 print_candidates (lfi.ambiguous);
1548 rval = error_mark_node;
1551 /* If the thing we found was found via the implicit typename
1552 extension, build the typename type. */
1553 if (rval && lfi.from_dep_base_p && !DECL_CLASS_TEMPLATE_P (rval))
1554 rval = TYPE_STUB_DECL (build_typename_type (BINFO_TYPE (basetype_path),
1558 if (rval && is_overloaded_fn (rval))
1560 rval = tree_cons (basetype_path, rval, NULL_TREE);
1561 SET_BASELINK_P (rval);
1567 /* Like lookup_member, except that if we find a function member we
1568 return NULL_TREE. */
1571 lookup_field (xbasetype, name, protect, want_type)
1572 register tree xbasetype, name;
1573 int protect, want_type;
1575 tree rval = lookup_member (xbasetype, name, protect, want_type);
1577 /* Ignore functions. */
1578 if (rval && TREE_CODE (rval) == TREE_LIST)
1584 /* Like lookup_member, except that if we find a non-function member we
1585 return NULL_TREE. */
1588 lookup_fnfields (xbasetype, name, protect)
1589 register tree xbasetype, name;
1592 tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/0);
1594 /* Ignore non-functions. */
1595 if (rval && TREE_CODE (rval) != TREE_LIST)
1601 /* TYPE is a class type. Return the index of the fields within
1602 the method vector with name NAME, or -1 is no such field exists. */
1605 lookup_fnfields_1 (type, name)
1609 = CLASS_TYPE_P (type) ? CLASSTYPE_METHOD_VEC (type) : NULL_TREE;
1611 if (method_vec != 0)
1614 register tree *methods = &TREE_VEC_ELT (method_vec, 0);
1615 int len = TREE_VEC_LENGTH (method_vec);
1618 #ifdef GATHER_STATISTICS
1619 n_calls_lookup_fnfields_1++;
1620 #endif /* GATHER_STATISTICS */
1622 /* Constructors are first... */
1623 if (name == ctor_identifier)
1624 return methods[0] ? 0 : -1;
1626 /* and destructors are second. */
1627 if (name == dtor_identifier)
1628 return methods[1] ? 1 : -1;
1630 for (i = 2; i < len && methods[i]; ++i)
1632 #ifdef GATHER_STATISTICS
1633 n_outer_fields_searched++;
1634 #endif /* GATHER_STATISTICS */
1636 tmp = OVL_CURRENT (methods[i]);
1637 if (DECL_NAME (tmp) == name)
1640 /* If the type is complete and we're past the conversion ops,
1641 switch to binary search. */
1642 if (! DECL_CONV_FN_P (tmp)
1643 && TYPE_SIZE (type))
1645 int lo = i + 1, hi = len;
1651 #ifdef GATHER_STATISTICS
1652 n_outer_fields_searched++;
1653 #endif /* GATHER_STATISTICS */
1655 tmp = DECL_NAME (OVL_CURRENT (methods[i]));
1659 else if (tmp < name)
1668 /* If we didn't find it, it might have been a template
1669 conversion operator. (Note that we don't look for this case
1670 above so that we will always find specializations first.) */
1671 if (IDENTIFIER_TYPENAME_P (name))
1673 for (i = 2; i < len && methods[i]; ++i)
1675 tmp = OVL_CURRENT (methods[i]);
1676 if (! DECL_CONV_FN_P (tmp))
1678 /* Since all conversion operators come first, we know
1679 there is no such operator. */
1682 else if (TREE_CODE (tmp) == TEMPLATE_DECL)
1691 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1692 type in the hierarchy, in a breadth-first preorder traversal. .
1693 If it ever returns a non-NULL value, that value is immediately
1694 returned and the walk is terminated. At each node FN, is passed a
1695 BINFO indicating the path from the curently visited base-class to
1696 TYPE. The TREE_CHAINs of the BINFOs may be used for scratch space;
1697 they are otherwise unused. Before each base-class is walked QFN is
1698 called. If the value returned is non-zero, the base-class is
1699 walked; otherwise it is not. If QFN is NULL, it is treated as a
1700 function which always returns 1. Both FN and QFN are passed the
1701 DATA whenever they are called. */
1704 bfs_walk (binfo, fn, qfn, data)
1706 tree (*fn) PROTO((tree, void *));
1707 tree (*qfn) PROTO((tree, void *));
1712 tree rval = NULL_TREE;
1713 /* An array of the base classes of BINFO. These will be built up in
1714 breadth-first order, except where QFN prunes the search. */
1715 varray_type bfs_bases;
1717 /* Start with enough room for ten base classes. That will be enough
1718 for most hierarchies. */
1719 VARRAY_TREE_INIT (bfs_bases, 10, "search_stack");
1721 /* Put the first type into the stack. */
1722 VARRAY_TREE (bfs_bases, 0) = binfo;
1725 for (head = 0; head < tail; ++head)
1731 /* Pull the next type out of the queue. */
1732 binfo = VARRAY_TREE (bfs_bases, head);
1734 /* If this is the one we're looking for, we're done. */
1735 rval = (*fn) (binfo, data);
1739 /* Queue up the base types. */
1740 binfos = BINFO_BASETYPES (binfo);
1741 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos): 0;
1742 for (i = 0; i < n_baselinks; i++)
1744 tree base_binfo = TREE_VEC_ELT (binfos, i);
1747 base_binfo = (*qfn) (base_binfo, data);
1751 if (tail == VARRAY_SIZE (bfs_bases))
1752 VARRAY_GROW (bfs_bases, 2 * VARRAY_SIZE (bfs_bases));
1753 VARRAY_TREE (bfs_bases, tail) = base_binfo;
1760 VARRAY_FREE (bfs_bases);
1765 /* Exactly like bfs_walk, except that a depth-first traversal is
1766 performed, and PREFN is called in preorder, while POSTFN is called
1770 dfs_walk_real (binfo, prefn, postfn, qfn, data)
1772 tree (*prefn) PROTO((tree, void *));
1773 tree (*postfn) PROTO((tree, void *));
1774 tree (*qfn) PROTO((tree, void *));
1780 tree rval = NULL_TREE;
1782 /* Call the pre-order walking function. */
1785 rval = (*prefn) (binfo, data);
1790 /* Process the basetypes. */
1791 binfos = BINFO_BASETYPES (binfo);
1792 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos): 0;
1793 for (i = 0; i < n_baselinks; i++)
1795 tree base_binfo = TREE_VEC_ELT (binfos, i);
1798 base_binfo = (*qfn) (base_binfo, data);
1802 rval = dfs_walk_real (base_binfo, prefn, postfn, qfn, data);
1808 /* Call the post-order walking function. */
1810 rval = (*postfn) (binfo, data);
1815 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1819 dfs_walk (binfo, fn, qfn, data)
1821 tree (*fn) PROTO((tree, void *));
1822 tree (*qfn) PROTO((tree, void *));
1825 return dfs_walk_real (binfo, 0, fn, qfn, data);
1830 /* The name of the function we are looking for. */
1832 /* The overloaded functions we have found. */
1836 /* Called from get_virtuals_named_this via bfs_walk. */
1839 get_virtuals_named_this_r (binfo, data)
1843 struct gvnt_info *gvnti = (struct gvnt_info *) data;
1844 tree type = BINFO_TYPE (binfo);
1847 idx = lookup_fnfields_here (BINFO_TYPE (binfo), gvnti->name);
1851 TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx),
1857 /* Return the virtual functions with the indicated NAME in the type
1858 indicated by BINFO. The result is a TREE_LIST whose TREE_PURPOSE
1859 indicates the base class from which the TREE_VALUE (an OVERLOAD or
1860 just a FUNCTION_DECL) originated. */
1863 get_virtuals_named_this (binfo, name)
1867 struct gvnt_info gvnti;
1871 gvnti.fields = NULL_TREE;
1873 bfs_walk (binfo, get_virtuals_named_this_r, 0, &gvnti);
1875 /* Get to the function decls, and return the first virtual function
1876 with this name, if there is one. */
1877 for (fields = gvnti.fields; fields; fields = next_baselink (fields))
1881 for (fndecl = TREE_VALUE (fields); fndecl; fndecl = OVL_NEXT (fndecl))
1882 if (DECL_VINDEX (OVL_CURRENT (fndecl)))
1889 get_virtual_destructor (binfo, data)
1891 void *data ATTRIBUTE_UNUSED;
1893 tree type = BINFO_TYPE (binfo);
1894 if (TYPE_HAS_DESTRUCTOR (type)
1895 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1)))
1896 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1);
1901 tree_has_any_destructor_p (binfo, data)
1903 void *data ATTRIBUTE_UNUSED;
1905 tree type = BINFO_TYPE (binfo);
1906 return TYPE_NEEDS_DESTRUCTOR (type) ? binfo : NULL_TREE;
1909 /* Returns > 0 if a function with type DRETTYPE overriding a function
1910 with type BRETTYPE is covariant, as defined in [class.virtual].
1912 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1913 adjustment), or -1 if pedantically invalid covariance. */
1916 covariant_return_p (brettype, drettype)
1917 tree brettype, drettype;
1921 if (TREE_CODE (brettype) == FUNCTION_DECL
1922 || TREE_CODE (brettype) == THUNK_DECL)
1924 brettype = TREE_TYPE (TREE_TYPE (brettype));
1925 drettype = TREE_TYPE (TREE_TYPE (drettype));
1927 else if (TREE_CODE (brettype) == METHOD_TYPE)
1929 brettype = TREE_TYPE (brettype);
1930 drettype = TREE_TYPE (drettype);
1933 if (same_type_p (brettype, drettype))
1936 if (! (TREE_CODE (brettype) == TREE_CODE (drettype)
1937 && (TREE_CODE (brettype) == POINTER_TYPE
1938 || TREE_CODE (brettype) == REFERENCE_TYPE)
1939 && TYPE_QUALS (brettype) == TYPE_QUALS (drettype)))
1942 if (! can_convert (brettype, drettype))
1945 brettype = TREE_TYPE (brettype);
1946 drettype = TREE_TYPE (drettype);
1948 /* If not pedantic, allow any standard pointer conversion. */
1949 if (! IS_AGGR_TYPE (drettype) || ! IS_AGGR_TYPE (brettype))
1952 binfo = get_binfo (brettype, drettype, 1);
1954 /* If we get an error_mark_node from get_binfo, it already complained,
1955 so let's just succeed. */
1956 if (binfo == error_mark_node)
1959 if (! BINFO_OFFSET_ZEROP (binfo) || TREE_VIA_VIRTUAL (binfo))
1964 /* Check that virtual overrider OVERRIDER is acceptable for base function
1965 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1968 check_final_overrider (overrider, basefn)
1969 tree overrider, basefn;
1971 tree over_type = TREE_TYPE (overrider);
1972 tree base_type = TREE_TYPE (basefn);
1973 tree over_return = TREE_TYPE (over_type);
1974 tree base_return = TREE_TYPE (base_type);
1975 tree over_throw = TYPE_RAISES_EXCEPTIONS (over_type);
1976 tree base_throw = TYPE_RAISES_EXCEPTIONS (base_type);
1979 if (same_type_p (base_return, over_return))
1981 else if ((i = covariant_return_p (base_return, over_return)))
1984 sorry ("adjusting pointers for covariant returns");
1986 if (pedantic && i == -1)
1988 cp_pedwarn_at ("invalid covariant return type for `virtual %#D'", overrider);
1989 cp_pedwarn_at (" overriding `virtual %#D' (must be pointer or reference to class)", basefn);
1992 else if (IS_AGGR_TYPE_2 (base_return, over_return)
1993 && same_or_base_type_p (base_return, over_return))
1995 cp_error_at ("invalid covariant return type for `virtual %#D'", overrider);
1996 cp_error_at (" overriding `virtual %#D' (must use pointer or reference)", basefn);
1999 else if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider)) == NULL_TREE)
2001 cp_error_at ("conflicting return type specified for `virtual %#D'", overrider);
2002 cp_error_at (" overriding `virtual %#D'", basefn);
2003 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider),
2004 DECL_CLASS_CONTEXT (overrider));
2008 /* Check throw specifier is subset. */
2009 /* XXX At the moment, punt on an overriding artificial function. We
2010 don't generate its exception specifier, so can't check it properly. */
2011 if (! DECL_ARTIFICIAL (overrider)
2012 && !comp_except_specs (base_throw, over_throw, 0))
2014 cp_error_at ("looser throw specifier for `virtual %#F'", overrider);
2015 cp_error_at (" overriding `virtual %#F'", basefn);
2021 /* Given a class type TYPE, and a function decl FNDECL, look for a
2022 virtual function in TYPE's hierarchy which FNDECL could match as a
2023 virtual function. It doesn't matter which one we find.
2025 DTORP is nonzero if we are looking for a destructor. Destructors
2026 need special treatment because they do not match by name. */
2029 get_matching_virtual (binfo, fndecl, dtorp)
2033 tree tmp = NULL_TREE;
2035 if (TREE_CODE (fndecl) == TEMPLATE_DECL)
2036 /* In [temp.mem] we have:
2038 A specialization of a member function template does not
2039 override a virtual function from a base class. */
2042 /* Breadth first search routines start searching basetypes
2043 of TYPE, so we must perform first ply of search here. */
2045 return bfs_walk (binfo, get_virtual_destructor,
2046 tree_has_any_destructor_p, 0);
2049 tree drettype, dtypes, btypes, instptr_type;
2050 tree baselink, best = NULL_TREE;
2051 tree declarator = DECL_NAME (fndecl);
2052 if (IDENTIFIER_VIRTUAL_P (declarator) == 0)
2055 baselink = get_virtuals_named_this (binfo, declarator);
2056 if (baselink == NULL_TREE)
2059 drettype = TREE_TYPE (TREE_TYPE (fndecl));
2060 dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2061 if (DECL_STATIC_FUNCTION_P (fndecl))
2062 instptr_type = NULL_TREE;
2064 instptr_type = TREE_TYPE (TREE_VALUE (dtypes));
2066 for (; baselink; baselink = next_baselink (baselink))
2069 for (tmps = TREE_VALUE (baselink); tmps; tmps = OVL_NEXT (tmps))
2071 tmp = OVL_CURRENT (tmps);
2072 if (! DECL_VINDEX (tmp))
2075 btypes = TYPE_ARG_TYPES (TREE_TYPE (tmp));
2076 if (instptr_type == NULL_TREE)
2078 if (compparms (TREE_CHAIN (btypes), dtypes))
2079 /* Caller knows to give error in this case. */
2084 if (/* The first parameter is the `this' parameter,
2085 which has POINTER_TYPE, and we can therefore
2086 safely use TYPE_QUALS, rather than
2088 (TYPE_QUALS (TREE_TYPE (TREE_VALUE (btypes)))
2089 == TYPE_QUALS (instptr_type))
2090 && compparms (TREE_CHAIN (btypes), TREE_CHAIN (dtypes)))
2092 check_final_overrider (fndecl, tmp);
2094 /* FNDECL overrides this function. We continue to
2095 check all the other functions in order to catch
2096 errors; it might be that in some other baseclass
2097 a virtual function was declared with the same
2098 parameter types, but a different return type. */
2108 /* Return the list of virtual functions which are abstract in type
2109 TYPE that come from non virtual base classes. See
2110 expand_direct_vtbls_init for the style of search we do. */
2113 get_abstract_virtuals_1 (binfo, do_self, abstract_virtuals)
2116 tree abstract_virtuals;
2118 tree binfos = BINFO_BASETYPES (binfo);
2119 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2121 for (i = 0; i < n_baselinks; i++)
2123 tree base_binfo = TREE_VEC_ELT (binfos, i);
2124 int is_not_base_vtable
2125 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2126 if (! TREE_VIA_VIRTUAL (base_binfo))
2128 = get_abstract_virtuals_1 (base_binfo, is_not_base_vtable,
2131 /* Should we use something besides CLASSTYPE_VFIELDS? */
2132 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2134 tree virtuals = BINFO_VIRTUALS (binfo);
2136 skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
2140 tree base_fndecl = TREE_VALUE (virtuals);
2141 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl))
2142 abstract_virtuals = tree_cons (NULL_TREE, base_fndecl,
2144 virtuals = TREE_CHAIN (virtuals);
2147 return abstract_virtuals;
2150 /* Return the list of virtual functions which are abstract in type TYPE.
2151 This information is cached, and so must be built on a
2152 non-temporary obstack. */
2155 get_abstract_virtuals (type)
2159 tree abstract_virtuals = NULL;
2161 /* First get all from non-virtual bases. */
2163 = get_abstract_virtuals_1 (TYPE_BINFO (type), 1, abstract_virtuals);
2165 for (vbases = CLASSTYPE_VBASECLASSES (type); vbases; vbases = TREE_CHAIN (vbases))
2167 tree virtuals = BINFO_VIRTUALS (vbases);
2169 skip_rtti_stuff (&virtuals, BINFO_TYPE (vbases));
2173 tree base_fndecl = TREE_VALUE (virtuals);
2174 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl))
2175 cp_error ("`%#D' needs a final overrider", base_fndecl);
2176 else if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl))
2177 abstract_virtuals = tree_cons (NULL_TREE, base_fndecl,
2179 virtuals = TREE_CHAIN (virtuals);
2182 return nreverse (abstract_virtuals);
2186 next_baselink (baselink)
2189 tree tmp = TREE_TYPE (baselink);
2190 baselink = TREE_CHAIN (baselink);
2193 /* @@ does not yet add previous base types. */
2194 baselink = tree_cons (TREE_PURPOSE (tmp), TREE_VALUE (tmp),
2196 TREE_TYPE (baselink) = TREE_TYPE (tmp);
2197 tmp = TREE_CHAIN (tmp);
2202 /* DEPTH-FIRST SEARCH ROUTINES. */
2204 /* This routine converts a pointer to be a pointer of an immediate
2205 base class. The normal convert_pointer_to routine would diagnose
2206 the conversion as ambiguous, under MI code that has the base class
2207 as an ambiguous base class. */
2210 convert_pointer_to_single_level (to_type, expr)
2214 tree binfo_of_derived;
2217 derived = TREE_TYPE (TREE_TYPE (expr));
2218 binfo_of_derived = TYPE_BINFO (derived);
2219 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo_of_derived) == NULL_TREE,
2221 for (i = CLASSTYPE_N_BASECLASSES (derived) - 1; i >= 0; --i)
2223 tree binfo = BINFO_BASETYPE (binfo_of_derived, i);
2224 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo) == binfo_of_derived,
2226 if (same_type_p (BINFO_TYPE (binfo), to_type))
2227 return build_vbase_path (PLUS_EXPR,
2228 build_pointer_type (to_type),
2232 my_friendly_abort (19990607);
2238 tree markedp (binfo, data)
2240 void *data ATTRIBUTE_UNUSED;
2242 return BINFO_MARKED (binfo) ? binfo : NULL_TREE;
2246 unmarkedp (binfo, data)
2248 void *data ATTRIBUTE_UNUSED;
2250 return !BINFO_MARKED (binfo) ? binfo : NULL_TREE;
2254 marked_vtable_pathp (binfo, data)
2256 void *data ATTRIBUTE_UNUSED;
2258 return BINFO_VTABLE_PATH_MARKED (binfo) ? binfo : NULL_TREE;
2262 unmarked_vtable_pathp (binfo, data)
2264 void *data ATTRIBUTE_UNUSED;
2266 return !BINFO_VTABLE_PATH_MARKED (binfo) ? binfo : NULL_TREE;
2270 marked_new_vtablep (binfo, data)
2272 void *data ATTRIBUTE_UNUSED;
2274 return BINFO_NEW_VTABLE_MARKED (binfo) ? binfo : NULL_TREE;
2278 unmarked_new_vtablep (binfo, data)
2280 void *data ATTRIBUTE_UNUSED;
2282 return !BINFO_NEW_VTABLE_MARKED (binfo) ? binfo : NULL_TREE;
2286 marked_pushdecls_p (binfo, data)
2288 void *data ATTRIBUTE_UNUSED;
2290 return (CLASS_TYPE_P (BINFO_TYPE (binfo))
2291 && BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
2295 unmarked_pushdecls_p (binfo, data)
2297 void *data ATTRIBUTE_UNUSED;
2299 return (CLASS_TYPE_P (BINFO_TYPE (binfo))
2300 && !BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
2304 static int dfs_search_slot_nonempty_p (binfo) tree binfo;
2305 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo)) != 0; }
2308 dfs_debug_unmarkedp (binfo, data)
2310 void *data ATTRIBUTE_UNUSED;
2312 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo))
2313 ? binfo : NULL_TREE);
2317 /* The worker functions for `dfs_walk'. These do not need to
2318 test anything (vis a vis marking) if they are paired with
2319 a predicate function (above). */
2323 dfs_mark (binfo) tree binfo;
2324 { SET_BINFO_MARKED (binfo); }
2328 dfs_unmark (binfo, data)
2330 void *data ATTRIBUTE_UNUSED;
2332 CLEAR_BINFO_MARKED (binfo);
2338 dfs_mark_vtable_path (binfo) tree binfo;
2339 { SET_BINFO_VTABLE_PATH_MARKED (binfo); }
2342 dfs_unmark_vtable_path (binfo) tree binfo;
2343 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo); }
2346 dfs_mark_new_vtable (binfo) tree binfo;
2347 { SET_BINFO_NEW_VTABLE_MARKED (binfo); }
2350 dfs_unmark_new_vtable (binfo) tree binfo;
2351 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo); }
2354 dfs_clear_search_slot (binfo) tree binfo;
2355 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo)) = 0; }
2357 /* Keep this code around in case we later want to control debug info
2358 based on whether a type is "used". Currently, we only suppress debug
2359 info if we can emit it with the vtable. jason 1999-11-11) */
2361 dfs_debug_mark (binfo, data)
2363 void *data ATTRIBUTE_UNUSED;
2365 tree t = BINFO_TYPE (binfo);
2367 CLASSTYPE_DEBUG_REQUESTED (t) = 1;
2369 /* If interface info is known, either we've already emitted the debug
2370 info or we don't need to. */
2371 if (CLASSTYPE_INTERFACE_KNOWN (t))
2374 /* If the class has virtual functions, we'll emit the debug info
2376 if (TYPE_POLYMORPHIC_P (t))
2379 /* We cannot rely on some alien method to solve our problems,
2380 so we must write out the debug info ourselves. */
2381 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 0;
2382 rest_of_type_compilation (t, toplevel_bindings_p ());
2395 /* Attach to the type of the virtual base class, the pointer to the
2396 virtual base class. */
2399 dfs_find_vbases (binfo, data)
2403 struct vbase_info *vi = (struct vbase_info *) data;
2404 tree binfos = BINFO_BASETYPES (binfo);
2405 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2407 for (i = n_baselinks-1; i >= 0; i--)
2409 tree base_binfo = TREE_VEC_ELT (binfos, i);
2411 if (TREE_VIA_VIRTUAL (base_binfo)
2412 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo)) == 0)
2414 tree vbase = BINFO_TYPE (base_binfo);
2415 tree binfo = binfo_member (vbase, vi->vbase_types);
2417 CLASSTYPE_SEARCH_SLOT (vbase)
2418 = build (PLUS_EXPR, build_pointer_type (vbase),
2419 vi->decl_ptr, BINFO_OFFSET (binfo));
2422 SET_BINFO_VTABLE_PATH_MARKED (binfo);
2423 SET_BINFO_NEW_VTABLE_MARKED (binfo);
2429 dfs_init_vbase_pointers (binfo, data)
2433 struct vbase_info *vi = (struct vbase_info *) data;
2434 tree type = BINFO_TYPE (binfo);
2435 tree fields = TYPE_FIELDS (type);
2436 tree this_vbase_ptr;
2438 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo);
2441 /* See finish_struct_1 for when we can enable this. */
2442 /* If we have a vtable pointer first, skip it. */
2443 if (VFIELD_NAME_P (DECL_NAME (fields)))
2444 fields = TREE_CHAIN (fields);
2447 if (BINFO_INHERITANCE_CHAIN (binfo))
2449 this_vbase_ptr = TREE_CHAIN (BINFO_INHERITANCE_CHAIN (binfo));
2450 if (TREE_VIA_VIRTUAL (binfo))
2451 this_vbase_ptr = CLASSTYPE_SEARCH_SLOT (type);
2453 this_vbase_ptr = convert_pointer_to_single_level (type,
2455 TREE_CHAIN (binfo) = this_vbase_ptr;
2458 this_vbase_ptr = TREE_CHAIN (binfo);
2460 if (fields == NULL_TREE
2461 || DECL_NAME (fields) == NULL_TREE
2462 || ! VBASE_NAME_P (DECL_NAME (fields)))
2465 if (build_pointer_type (type)
2466 != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr)))
2467 my_friendly_abort (125);
2469 while (fields && DECL_NAME (fields) && VBASE_NAME_P (DECL_NAME (fields)))
2471 tree ref = build (COMPONENT_REF, TREE_TYPE (fields),
2472 build_indirect_ref (this_vbase_ptr, NULL_PTR), fields);
2473 tree init = CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields)));
2474 vi->inits = tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields)),
2476 build_modify_expr (ref, NOP_EXPR, init),
2478 fields = TREE_CHAIN (fields);
2484 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2485 times, just NEW_VTABLE, but optimizer should make both with equal
2486 efficiency (though it does not currently). */
2489 dfs_clear_vbase_slots (binfo, data)
2491 void *data ATTRIBUTE_UNUSED;
2493 tree type = BINFO_TYPE (binfo);
2494 CLASSTYPE_SEARCH_SLOT (type) = 0;
2495 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo);
2496 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2501 init_vbase_pointers (type, decl_ptr)
2505 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
2507 struct vbase_info vi;
2508 int old_flag = flag_this_is_variable;
2509 tree binfo = TYPE_BINFO (type);
2510 flag_this_is_variable = -2;
2512 /* Find all the virtual base classes, marking them for later
2514 vi.decl_ptr = decl_ptr;
2515 vi.vbase_types = CLASSTYPE_VBASECLASSES (type);
2516 vi.inits = NULL_TREE;
2518 dfs_walk (binfo, dfs_find_vbases, unmarked_vtable_pathp, &vi);
2520 /* Build up a list of the initializers. */
2521 TREE_CHAIN (binfo) = decl_ptr;
2522 dfs_walk_real (binfo,
2523 dfs_init_vbase_pointers, 0,
2524 marked_vtable_pathp,
2527 dfs_walk (binfo, dfs_clear_vbase_slots, marked_new_vtablep, 0);
2528 flag_this_is_variable = old_flag;
2534 /* get the virtual context (the vbase that directly contains the
2535 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2536 or NULL_TREE if there is none.
2538 FNDECL must come from a virtual table from a virtual base to ensure that
2539 there is only one possible DECL_CLASS_CONTEXT.
2541 We know that if there is more than one place (binfo) the fndecl that the
2542 declared, they all refer to the same binfo. See get_class_offset_1 for
2543 the check that ensures this. */
2546 virtual_context (fndecl, t, vbase)
2547 tree fndecl, t, vbase;
2550 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl), t, 0, &path) < 0)
2552 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2553 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl), vbase, 0, &path) >= 0)
2557 /* Not sure if checking path == vbase is necessary here, but just in
2559 if (TREE_VIA_VIRTUAL (path) || path == vbase)
2560 return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t));
2561 path = BINFO_INHERITANCE_CHAIN (path);
2564 /* This shouldn't happen, I don't want errors! */
2565 warning ("recoverable compiler error, fixups for virtual function");
2570 if (TREE_VIA_VIRTUAL (path))
2571 return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t));
2572 path = BINFO_INHERITANCE_CHAIN (path);
2577 /* Fixups upcast offsets for one vtable.
2578 Entries may stay within the VBASE given, or
2579 they may upcast into a direct base, or
2580 they may upcast into a different vbase.
2582 We only need to do fixups in case 2 and 3. In case 2, we add in
2583 the virtual base offset to effect an upcast, in case 3, we add in
2584 the virtual base offset to effect an upcast, then subtract out the
2585 offset for the other virtual base, to effect a downcast into it.
2587 This routine mirrors fixup_vtable_deltas in functionality, though
2588 this one is runtime based, and the other is compile time based.
2589 Conceivably that routine could be removed entirely, and all fixups
2592 VBASE_OFFSETS is an association list of virtual bases that contains
2593 offset information for the virtual bases, so the offsets are only
2594 calculated once. The offsets are computed by where we think the
2595 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2596 the vbase really is. */
2599 expand_upcast_fixups (binfo, addr, orig_addr, vbase, vbase_addr, t,
2601 tree binfo, addr, orig_addr, vbase, vbase_addr, t, *vbase_offsets;
2603 tree virtuals = BINFO_VIRTUALS (binfo);
2606 unsigned HOST_WIDE_INT n;
2608 delta = purpose_member (vbase, *vbase_offsets);
2611 delta = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase));
2612 delta = build (MINUS_EXPR, ptrdiff_type_node, delta, vbase_addr);
2613 delta = save_expr (delta);
2614 delta = tree_cons (vbase, delta, *vbase_offsets);
2615 *vbase_offsets = delta;
2618 n = skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
2622 tree current_fndecl = TREE_VALUE (virtuals);
2625 && current_fndecl != abort_fndecl
2626 && (vc=virtual_context (current_fndecl, t, vbase)) != vbase)
2628 /* This may in fact need a runtime fixup. */
2629 tree idx = build_int_2 (n, 0);
2630 tree vtbl = BINFO_VTABLE (binfo);
2631 tree nvtbl = lookup_name (DECL_NAME (vtbl), 0);
2632 tree aref, ref, naref;
2633 tree old_delta, new_delta;
2636 if (nvtbl == NULL_TREE
2637 || nvtbl == IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl)))
2639 /* Dup it if it isn't in local scope yet. */
2641 (VAR_DECL, DECL_NAME (vtbl),
2642 TYPE_MAIN_VARIANT (TREE_TYPE (vtbl)));
2643 DECL_ALIGN (nvtbl) = MAX (TYPE_ALIGN (double_type_node),
2644 DECL_ALIGN (nvtbl));
2645 TREE_READONLY (nvtbl) = 0;
2646 DECL_ARTIFICIAL (nvtbl) = 1;
2647 nvtbl = pushdecl (nvtbl);
2649 cp_finish_decl (nvtbl, init, NULL_TREE,
2650 LOOKUP_ONLYCONVERTING);
2652 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2653 because they wouldn't be useful; everything that wants to
2654 look at the vtable will look at the decl for the normal
2655 vtable. Setting DECL_CONTEXT also screws up
2656 decl_function_context. */
2658 init = build (MODIFY_EXPR, TREE_TYPE (nvtbl),
2660 finish_expr_stmt (init);
2661 /* Update the vtable pointers as necessary. */
2662 ref = build_vfield_ref
2663 (build_indirect_ref (addr, NULL_PTR),
2664 DECL_CONTEXT (TYPE_VFIELD (BINFO_TYPE (binfo))));
2666 (build_modify_expr (ref, NOP_EXPR, nvtbl));
2668 assemble_external (vtbl);
2669 aref = build_array_ref (vtbl, idx);
2670 naref = build_array_ref (nvtbl, idx);
2671 old_delta = build_component_ref (aref, delta_identifier,
2673 new_delta = build_component_ref (naref, delta_identifier,
2676 /* This is a upcast, so we have to add the offset for the
2678 old_delta = build_binary_op (PLUS_EXPR, old_delta,
2679 TREE_VALUE (delta));
2682 /* If this is set, we need to subtract out the delta
2683 adjustments for the other virtual base that we
2685 tree vc_delta = purpose_member (vc, *vbase_offsets);
2688 tree vc_addr = convert_pointer_to_real (vc, orig_addr);
2689 vc_delta = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc));
2690 vc_delta = build (MINUS_EXPR, ptrdiff_type_node,
2692 vc_delta = save_expr (vc_delta);
2693 *vbase_offsets = tree_cons (vc, vc_delta, *vbase_offsets);
2696 vc_delta = TREE_VALUE (vc_delta);
2698 /* This is a downcast, so we have to subtract the offset
2699 for the virtual base. */
2700 old_delta = build_binary_op (MINUS_EXPR, old_delta, vc_delta);
2703 TREE_READONLY (new_delta) = 0;
2704 TREE_TYPE (new_delta) =
2705 cp_build_qualified_type (TREE_TYPE (new_delta),
2706 CP_TYPE_QUALS (TREE_TYPE (new_delta))
2707 & ~TYPE_QUAL_CONST);
2708 finish_expr_stmt (build_modify_expr (new_delta, NOP_EXPR,
2712 virtuals = TREE_CHAIN (virtuals);
2716 /* Fixup upcast offsets for all direct vtables. Patterned after
2717 expand_direct_vtbls_init. */
2720 fixup_virtual_upcast_offsets (real_binfo, binfo, init_self, can_elide, addr, orig_addr, type, vbase, vbase_offsets)
2721 tree real_binfo, binfo;
2722 int init_self, can_elide;
2723 tree addr, orig_addr, type, vbase, *vbase_offsets;
2725 tree real_binfos = BINFO_BASETYPES (real_binfo);
2726 tree binfos = BINFO_BASETYPES (binfo);
2727 int i, n_baselinks = real_binfos ? TREE_VEC_LENGTH (real_binfos) : 0;
2729 for (i = 0; i < n_baselinks; i++)
2731 tree real_base_binfo = TREE_VEC_ELT (real_binfos, i);
2732 tree base_binfo = TREE_VEC_ELT (binfos, i);
2733 int is_not_base_vtable
2734 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo));
2735 if (! TREE_VIA_VIRTUAL (real_base_binfo))
2736 fixup_virtual_upcast_offsets (real_base_binfo, base_binfo,
2737 is_not_base_vtable, can_elide, addr,
2738 orig_addr, type, vbase, vbase_offsets);
2741 /* Before turning this on, make sure it is correct. */
2742 if (can_elide && ! BINFO_MODIFIED (binfo))
2745 /* Should we use something besides CLASSTYPE_VFIELDS? */
2746 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo)))
2748 tree new_addr = convert_pointer_to_real (binfo, addr);
2749 expand_upcast_fixups (real_binfo, new_addr, orig_addr, vbase, addr,
2750 type, vbase_offsets);
2754 /* Fixup all the virtual upcast offsets for TYPE. DECL_PTR is the
2755 address of the sub-object being initialized. */
2758 fixup_all_virtual_upcast_offsets (type, decl_ptr)
2763 tree in_charge_node;
2766 /* Only tweak the vtables if we're in charge. */
2767 in_charge_node = current_in_charge_parm;
2768 if (!in_charge_node)
2769 /* There's no need for any fixups in this case. */
2771 in_charge_node = build_binary_op (EQ_EXPR,
2772 in_charge_node, integer_zero_node);
2773 if_stmt = begin_if_stmt ();
2774 finish_if_stmt_cond (in_charge_node, if_stmt);
2776 /* Iterate through the virtual bases, fixing up the upcast offset
2778 for (vbases = CLASSTYPE_VBASECLASSES (type);
2780 vbases = TREE_CHAIN (vbases))
2782 if (flag_vtable_thunks)
2783 /* We don't have dynamic thunks yet! So for now, just fail
2791 vbase_offsets = NULL_TREE;
2792 addr = convert_pointer_to_vbase (TREE_TYPE (vbases), decl_ptr);
2793 fixup_virtual_upcast_offsets (vbases,
2794 TYPE_BINFO (BINFO_TYPE (vbases)),
2795 1, 0, addr, decl_ptr,
2796 type, vbases, &vbase_offsets);
2800 /* Close out the if-statement. */
2801 finish_then_clause (if_stmt);
2805 /* Generate the code needed to initialize all the virtual function
2806 table slots of all the virtual baseclasses. BINFO is the binfo
2807 which determines the virtual baseclasses to use. TRUE_EXP is the
2808 true object we are initializing, and DECL_PTR is the pointer to the
2809 sub-object we are initializing. */
2812 expand_indirect_vtbls_init (binfo, true_exp, decl_ptr)
2814 tree true_exp, decl_ptr;
2816 tree type = BINFO_TYPE (binfo);
2818 /* This function executes during the finish_function() segment,
2819 AFTER the auto variables and temporary stack space has been marked
2820 unused...If space is needed for the virtual function tables,
2821 some of them might fit within what the compiler now thinks
2822 are available stack slots... These values are actually initialized at
2823 the beginnning of the function, so when the automatics use their space,
2824 they will overwrite the values that are placed here. Marking all
2825 temporary space as unavailable prevents this from happening. */
2827 mark_all_temps_used();
2829 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
2831 tree vbases = CLASSTYPE_VBASECLASSES (type);
2832 struct vbase_info vi;
2833 vi.decl_ptr = (true_exp ? build_unary_op (ADDR_EXPR, true_exp, 0)
2835 vi.vbase_types = vbases;
2837 dfs_walk (binfo, dfs_find_vbases, unmarked_new_vtablep, &vi);
2839 /* Initialized with vtables of type TYPE. */
2840 for (; vbases; vbases = TREE_CHAIN (vbases))
2844 addr = convert_pointer_to_vbase (TREE_TYPE (vbases), vi.decl_ptr);
2846 /* Do all vtables from this virtual base. */
2847 /* This assumes that virtual bases can never serve as parent
2848 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
2849 expand_direct_vtbls_init (vbases, TYPE_BINFO (BINFO_TYPE (vbases)),
2853 fixup_all_virtual_upcast_offsets (type,
2856 dfs_walk (binfo, dfs_clear_vbase_slots, marked_new_vtablep, 0);
2860 /* get virtual base class types.
2861 This adds type to the vbase_types list in reverse dfs order.
2862 Ordering is very important, so don't change it. */
2865 dfs_get_vbase_types (binfo, data)
2869 tree *vbase_types = (tree *) data;
2871 if (TREE_VIA_VIRTUAL (binfo) && ! BINFO_VBASE_MARKED (binfo))
2873 tree new_vbase = make_binfo (integer_zero_node, binfo,
2874 BINFO_VTABLE (binfo),
2875 BINFO_VIRTUALS (binfo));
2876 TREE_CHAIN (new_vbase) = *vbase_types;
2877 TREE_VIA_VIRTUAL (new_vbase) = 1;
2878 *vbase_types = new_vbase;
2879 SET_BINFO_VBASE_MARKED (binfo);
2881 SET_BINFO_MARKED (binfo);
2885 /* Return a list of binfos for the virtual base classes for TYPE, in
2886 depth-first search order. The list is freshly allocated, so
2887 no modification is made to the current binfo hierarchy. */
2890 get_vbase_types (type)
2897 binfo = TYPE_BINFO (type);
2898 vbase_types = NULL_TREE;
2899 dfs_walk (binfo, dfs_get_vbase_types, unmarkedp, &vbase_types);
2900 dfs_walk (binfo, dfs_unmark, markedp, 0);
2901 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2902 reverse it so that we get normal dfs ordering. */
2903 vbase_types = nreverse (vbase_types);
2905 /* unmark marked vbases */
2906 for (vbases = vbase_types; vbases; vbases = TREE_CHAIN (vbases))
2907 CLEAR_BINFO_VBASE_MARKED (vbases);
2912 /* Debug info for C++ classes can get very large; try to avoid
2913 emitting it everywhere.
2915 Note that this optimization wins even when the target supports
2916 BINCL (if only slightly), and reduces the amount of work for the
2920 maybe_suppress_debug_info (t)
2923 /* We can't do the usual TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2924 does not support name references between translation units. It supports
2925 symbolic references between translation units, but only within a single
2926 executable or shared library.
2928 For DWARF 2, we handle TYPE_DECL_SUPPRESS_DEBUG by pretending
2929 that the type was never defined, so we only get the members we
2931 if (write_symbols == DWARF_DEBUG || write_symbols == NO_DEBUG)
2934 /* We might have set this earlier in cp_finish_decl. */
2935 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 0;
2937 /* If we already know how we're handling this class, handle debug info
2939 if (CLASSTYPE_INTERFACE_ONLY (t))
2940 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
2941 else if (CLASSTYPE_INTERFACE_KNOWN (t))
2942 /* Don't set it. */;
2943 /* If the class has virtual functions, write out the debug info
2944 along with the vtable. */
2945 else if (TYPE_POLYMORPHIC_P (t))
2946 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
2948 /* Otherwise, just emit the debug info normally. */
2952 /* Keep this code around in case we later want to control debug info
2953 based on whether a type is "used". Currently, we only suppress debug
2954 info if we can emit it with the vtable. jason 1999-11-11) */
2956 /* If we want debug info for a type TYPE, make sure all its base types
2957 are also marked as being potentially interesting. This avoids
2958 the problem of not writing any debug info for intermediate basetypes
2959 that have abstract virtual functions. Also mark member types. */
2962 note_debug_info_needed (type)
2967 if (current_template_parms)
2970 if (TYPE_BEING_DEFINED (type))
2971 /* We can't go looking for the base types and fields just yet. */
2974 /* See the comment in maybe_suppress_debug_info. */
2975 if (write_symbols == DWARF_DEBUG || write_symbols == NO_DEBUG)
2978 dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp, 0);
2979 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
2982 if (TREE_CODE (field) == FIELD_DECL
2983 && IS_AGGR_TYPE (ttype = target_type (TREE_TYPE (field)))
2984 && dfs_debug_unmarkedp (TYPE_BINFO (ttype), 0))
2985 note_debug_info_needed (ttype);
2990 /* Subroutines of push_class_decls (). */
2992 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2993 because it (or one of the intermediate bases) depends on template parms. */
2996 dependent_base_p (binfo)
2999 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
3001 if (currently_open_class (TREE_TYPE (binfo)))
3003 if (uses_template_parms (TREE_TYPE (binfo)))
3010 setup_class_bindings (name, type_binding_p)
3014 tree type_binding = NULL_TREE;
3017 /* If we've already done the lookup for this declaration, we're
3019 if (IDENTIFIER_CLASS_VALUE (name))
3022 /* First, deal with the type binding. */
3025 type_binding = lookup_member (current_class_type, name,
3028 if (TREE_CODE (type_binding) == TREE_LIST
3029 && TREE_TYPE (type_binding) == error_mark_node)
3030 /* NAME is ambiguous. */
3031 push_class_level_binding (name, type_binding);
3033 pushdecl_class_level (type_binding);
3036 /* Now, do the value binding. */
3037 value_binding = lookup_member (current_class_type, name,
3042 && (TREE_CODE (value_binding) == TYPE_DECL
3043 || (TREE_CODE (value_binding) == TREE_LIST
3044 && TREE_TYPE (value_binding) == error_mark_node
3045 && (TREE_CODE (TREE_VALUE (value_binding))
3047 /* We found a type-binding, even when looking for a non-type
3048 binding. This means that we already processed this binding
3050 my_friendly_assert (type_binding_p, 19990401);
3051 else if (value_binding)
3053 if (TREE_CODE (value_binding) == TREE_LIST
3054 && TREE_TYPE (value_binding) == error_mark_node)
3055 /* NAME is ambiguous. */
3056 push_class_level_binding (name, value_binding);
3059 if (BASELINK_P (value_binding))
3060 /* NAME is some overloaded functions. */
3061 value_binding = TREE_VALUE (value_binding);
3062 pushdecl_class_level (value_binding);
3067 /* Push class-level declarations for any names appearing in BINFO that
3071 dfs_push_type_decls (binfo, data)
3073 void *data ATTRIBUTE_UNUSED;
3078 type = BINFO_TYPE (binfo);
3079 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
3080 if (DECL_NAME (fields) && TREE_CODE (fields) == TYPE_DECL
3081 && !(!same_type_p (type, current_class_type)
3082 && template_self_reference_p (type, fields)))
3083 setup_class_bindings (DECL_NAME (fields), /*type_binding_p=*/1);
3085 /* We can't just use BINFO_MARKED because envelope_add_decl uses
3086 DERIVED_FROM_P, which calls get_base_distance. */
3087 SET_BINFO_PUSHDECLS_MARKED (binfo);
3092 /* Push class-level declarations for any names appearing in BINFO that
3093 are not TYPE_DECLS. */
3096 dfs_push_decls (binfo, data)
3104 type = BINFO_TYPE (binfo);
3105 dep_base_p = (processing_template_decl && type != current_class_type
3106 && dependent_base_p (binfo));
3110 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
3111 if (DECL_NAME (fields)
3112 && TREE_CODE (fields) != TYPE_DECL
3113 && TREE_CODE (fields) != USING_DECL)
3114 setup_class_bindings (DECL_NAME (fields), /*type_binding_p=*/0);
3115 else if (TREE_CODE (fields) == FIELD_DECL
3116 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
3117 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields)), data);
3119 method_vec = (CLASS_TYPE_P (type)
3120 ? CLASSTYPE_METHOD_VEC (type) : NULL_TREE);
3126 /* Farm out constructors and destructors. */
3127 end = TREE_VEC_END (method_vec);
3129 for (methods = &TREE_VEC_ELT (method_vec, 2);
3130 *methods && methods != end;
3132 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods)),
3133 /*type_binding_p=*/0);
3137 CLEAR_BINFO_PUSHDECLS_MARKED (binfo);
3142 /* When entering the scope of a class, we cache all of the
3143 fields that that class provides within its inheritance
3144 lattice. Where ambiguities result, we mark them
3145 with `error_mark_node' so that if they are encountered
3146 without explicit qualification, we can emit an error
3150 push_class_decls (type)
3153 search_stack = push_search_level (search_stack, &search_obstack);
3155 /* Enter type declarations and mark. */
3156 dfs_walk (TYPE_BINFO (type), dfs_push_type_decls, unmarked_pushdecls_p, 0);
3158 /* Enter non-type declarations and unmark. */
3159 dfs_walk (TYPE_BINFO (type), dfs_push_decls, marked_pushdecls_p, 0);
3162 /* Here's a subroutine we need because C lacks lambdas. */
3165 dfs_unuse_fields (binfo, data)
3167 void *data ATTRIBUTE_UNUSED;
3169 tree type = TREE_TYPE (binfo);
3172 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
3174 if (TREE_CODE (fields) != FIELD_DECL)
3177 TREE_USED (fields) = 0;
3178 if (DECL_NAME (fields) == NULL_TREE
3179 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
3180 unuse_fields (TREE_TYPE (fields));
3190 dfs_walk (TYPE_BINFO (type), dfs_unuse_fields, unmarkedp, 0);
3196 /* We haven't pushed a search level when dealing with cached classes,
3197 so we'd better not try to pop it. */
3199 search_stack = pop_search_level (search_stack);
3203 print_search_statistics ()
3205 #ifdef GATHER_STATISTICS
3206 fprintf (stderr, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3207 n_fields_searched, n_calls_lookup_field, n_calls_lookup_field_1);
3208 fprintf (stderr, "%d fnfields searched in %d calls to lookup_fnfields\n",
3209 n_outer_fields_searched, n_calls_lookup_fnfields);
3210 fprintf (stderr, "%d calls to get_base_type\n", n_calls_get_base_type);
3211 #else /* GATHER_STATISTICS */
3212 fprintf (stderr, "no search statistics\n");
3213 #endif /* GATHER_STATISTICS */
3217 init_search_processing ()
3219 gcc_obstack_init (&search_obstack);
3220 vptr_identifier = get_identifier ("_vptr");
3224 reinit_search_statistics ()
3226 #ifdef GATHER_STATISTICS
3227 n_fields_searched = 0;
3228 n_calls_lookup_field = 0, n_calls_lookup_field_1 = 0;
3229 n_calls_lookup_fnfields = 0, n_calls_lookup_fnfields_1 = 0;
3230 n_calls_get_base_type = 0;
3231 n_outer_fields_searched = 0;
3232 n_contexts_saved = 0;
3233 #endif /* GATHER_STATISTICS */
3237 add_conversions (binfo, data)
3242 tree method_vec = CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo));
3243 tree *conversions = (tree *) data;
3245 /* Some builtin types have no method vector, not even an empty one. */
3249 for (i = 2; i < TREE_VEC_LENGTH (method_vec); ++i)
3251 tree tmp = TREE_VEC_ELT (method_vec, i);
3254 if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp)))
3257 name = DECL_NAME (OVL_CURRENT (tmp));
3259 /* Make sure we don't already have this conversion. */
3260 if (! IDENTIFIER_MARKED (name))
3262 *conversions = tree_cons (binfo, tmp, *conversions);
3263 IDENTIFIER_MARKED (name) = 1;
3269 /* Return a TREE_LIST containing all the non-hidden user-defined
3270 conversion functions for TYPE (and its base-classes). The
3271 TREE_VALUE of each node is a FUNCTION_DECL or an OVERLOAD
3272 containing the conversion functions. The TREE_PURPOSE is the BINFO
3273 from which the conversion functions in this node were selected. */
3276 lookup_conversions (type)
3280 tree conversions = NULL_TREE;
3282 if (TYPE_SIZE (type))
3283 bfs_walk (TYPE_BINFO (type), add_conversions, 0, &conversions);
3285 for (t = conversions; t; t = TREE_CHAIN (t))
3286 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t)))) = 0;
3297 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3298 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3301 dfs_check_overlap (empty_binfo, data)
3305 struct overlap_info *oi = (struct overlap_info *) data;
3307 for (binfo = TYPE_BINFO (oi->compare_type);
3309 binfo = BINFO_BASETYPE (binfo, 0))
3311 if (BINFO_TYPE (binfo) == BINFO_TYPE (empty_binfo))
3313 oi->found_overlap = 1;
3316 else if (BINFO_BASETYPES (binfo) == NULL_TREE)
3323 /* Trivial function to stop base traversal when we find something. */
3326 dfs_no_overlap_yet (binfo, data)
3330 struct overlap_info *oi = (struct overlap_info *) data;
3331 return !oi->found_overlap ? binfo : NULL_TREE;
3334 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3335 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3338 types_overlap_p (empty_type, next_type)
3339 tree empty_type, next_type;
3341 struct overlap_info oi;
3343 if (! IS_AGGR_TYPE (next_type))
3345 oi.compare_type = next_type;
3346 oi.found_overlap = 0;
3347 dfs_walk (TYPE_BINFO (empty_type), dfs_check_overlap,
3348 dfs_no_overlap_yet, &oi);
3349 return oi.found_overlap;
3352 /* Given a vtable VAR, determine which binfo it comes from.
3354 FIXME What about secondary vtables? */
3357 binfo_for_vtable (var)
3360 tree binfo = TYPE_BINFO (DECL_CONTEXT (var));
3366 binfos = BINFO_BASETYPES (binfo);
3367 if (binfos == NULL_TREE)
3370 i = CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
3374 binfo = TREE_VEC_ELT (binfos, i);
3380 /* Returns 1 iff BINFO is from a direct or indirect virtual base. */
3383 binfo_from_vbase (binfo)
3386 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
3388 if (TREE_VIA_VIRTUAL (binfo))