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. */
36 #define obstack_chunk_alloc xmalloc
37 #define obstack_chunk_free free
39 extern struct obstack
*current_obstack
;
40 extern tree abort_fndecl
;
44 /* Obstack used for remembering decision points of breadth-first. */
46 static struct obstack search_obstack
;
48 /* Methods for pushing and popping objects to and from obstacks. */
51 push_stack_level (obstack
, tp
, size
)
52 struct obstack
*obstack
;
53 char *tp
; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
56 struct stack_level
*stack
;
57 obstack_grow (obstack
, tp
, size
);
58 stack
= (struct stack_level
*) ((char*)obstack_next_free (obstack
) - size
);
59 obstack_finish (obstack
);
60 stack
->obstack
= obstack
;
61 stack
->first
= (tree
*) obstack_base (obstack
);
62 stack
->limit
= obstack_room (obstack
) / sizeof (tree
*);
67 pop_stack_level (stack
)
68 struct stack_level
*stack
;
70 struct stack_level
*tem
= stack
;
71 struct obstack
*obstack
= tem
->obstack
;
73 obstack_free (obstack
, tem
);
77 #define search_level stack_level
78 static struct search_level
*search_stack
;
80 static tree get_abstract_virtuals_1
PROTO((tree
, int, tree
));
81 static tree get_vbase_1
PROTO((tree
, tree
, unsigned int *));
82 static tree convert_pointer_to_vbase
PROTO((tree
, tree
));
83 static tree lookup_field_1
PROTO((tree
, tree
));
84 static tree convert_pointer_to_single_level
PROTO((tree
, tree
));
85 static int lookup_fnfields_here
PROTO((tree
, tree
));
86 static int is_subobject_of_p
PROTO((tree
, tree
));
87 static int hides
PROTO((tree
, tree
));
88 static tree virtual_context
PROTO((tree
, tree
, tree
));
89 static tree dfs_check_overlap
PROTO((tree
, void *));
90 static tree dfs_no_overlap_yet
PROTO((tree
, void *));
91 static void envelope_add_decl
PROTO((tree
, tree
, tree
*));
92 static int get_base_distance_recursive
93 PROTO((tree
, int, int, int, int *, tree
*, tree
,
94 int, int *, int, int));
95 static void expand_upcast_fixups
96 PROTO((tree
, tree
, tree
, tree
, tree
, tree
, tree
*));
97 static void fixup_virtual_upcast_offsets
98 PROTO((tree
, tree
, int, int, tree
, tree
, tree
, tree
,
100 static tree unmarkedp
PROTO((tree
, void *));
101 static tree marked_vtable_pathp
PROTO((tree
, void *));
102 static tree unmarked_vtable_pathp
PROTO((tree
, void *));
103 static tree marked_new_vtablep
PROTO((tree
, void *));
104 static tree unmarked_new_vtablep
PROTO((tree
, void *));
105 static tree marked_pushdecls_p
PROTO((tree
, void *));
106 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 *));
109 static tree dfs_find_vbases
PROTO((tree
, void *));
110 static tree dfs_clear_vbase_slots
PROTO((tree
, void *));
111 static tree dfs_init_vbase_pointers
PROTO((tree
, void *));
112 static tree dfs_get_vbase_types
PROTO((tree
, void *));
113 static tree dfs_pushdecls
PROTO((tree
, void *));
114 static tree dfs_compress_decls
PROTO((tree
, void *));
115 static tree dfs_unuse_fields
PROTO((tree
, void *));
116 static tree add_conversions
PROTO((tree
, void *));
117 static tree get_virtuals_named_this
PROTO((tree
, tree
));
118 static tree get_virtual_destructor
PROTO((tree
, void *));
119 static tree tree_has_any_destructor_p
PROTO((tree
, void *));
120 static int covariant_return_p
PROTO((tree
, tree
));
121 static struct search_level
*push_search_level
122 PROTO((struct stack_level
*, struct obstack
*));
123 static struct search_level
*pop_search_level
124 PROTO((struct stack_level
*));
126 PROTO((tree
, tree (*) (tree
, void *), tree (*) (tree
, void *),
128 static tree lookup_field_queue_p
PROTO((tree
, void *));
129 static tree lookup_field_r
PROTO((tree
, void *));
130 static tree dfs_walk_real
PROTO ((tree
,
131 tree (*) (tree
, void *),
132 tree (*) (tree
, void *),
133 tree (*) (tree
, void *),
135 static tree dfs_bfv_queue_p
PROTO ((tree
, void *));
136 static tree dfs_bfv_helper
PROTO ((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
));
151 /* Allocate a level of searching. */
153 static struct search_level
*
154 push_search_level (stack
, obstack
)
155 struct stack_level
*stack
;
156 struct obstack
*obstack
;
158 struct search_level tem
;
161 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
164 /* Discard a level of search allocation. */
166 static struct search_level
*
167 pop_search_level (obstack
)
168 struct stack_level
*obstack
;
170 register struct search_level
*stack
= pop_stack_level (obstack
);
175 static tree _vptr_name
;
177 /* Variables for gathering statistics. */
178 #ifdef GATHER_STATISTICS
179 static int n_fields_searched
;
180 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
181 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
182 static int n_calls_get_base_type
;
183 static int n_outer_fields_searched
;
184 static int n_contexts_saved
;
185 #endif /* GATHER_STATISTICS */
188 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
189 the same type as the type given in PARENT. To be optimal, we want
190 the first one that is found by going through the least number of
193 This uses a clever algorithm that updates *depth when we find the vbase,
194 and cuts off other paths of search when they reach that depth. */
197 get_vbase_1 (parent
, binfo
, depth
)
203 tree rval
= NULL_TREE
;
205 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
213 binfos
= BINFO_BASETYPES (binfo
);
214 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
216 /* Process base types. */
217 for (i
= 0; i
< n_baselinks
; i
++)
219 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
225 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
233 /* Return the shortest path to vbase PARENT within BINFO, ignoring
234 access and ambiguity. */
237 get_vbase (parent
, binfo
)
241 unsigned int d
= (unsigned int)-1;
242 return get_vbase_1 (parent
, binfo
, &d
);
245 /* Convert EXPR to a virtual base class of type TYPE. We know that
246 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
247 the type of what expr points to has a virtual base of type TYPE. */
250 convert_pointer_to_vbase (type
, expr
)
254 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
255 return convert_pointer_to_real (vb
, expr
);
258 /* Check whether the type given in BINFO is derived from PARENT. If
259 it isn't, return 0. If it is, but the derivation is MI-ambiguous
260 AND protect != 0, emit an error message and return error_mark_node.
262 Otherwise, if TYPE is derived from PARENT, return the actual base
263 information, unless a one of the protection violations below
264 occurs, in which case emit an error message and return error_mark_node.
266 If PROTECT is 1, then check if access to a public field of PARENT
267 would be private. Also check for ambiguity. */
270 get_binfo (parent
, binfo
, protect
)
271 register tree parent
, binfo
;
274 tree type
= NULL_TREE
;
276 tree rval
= NULL_TREE
;
278 if (TREE_CODE (parent
) == TREE_VEC
)
279 parent
= BINFO_TYPE (parent
);
280 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
281 my_friendly_abort (89);
283 if (TREE_CODE (binfo
) == TREE_VEC
)
284 type
= BINFO_TYPE (binfo
);
285 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
288 my_friendly_abort (90);
290 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
294 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
296 return error_mark_node
;
298 else if (dist
== -2 && protect
)
300 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
302 return error_mark_node
;
308 /* This is the newer depth first get_base_distance routine. */
311 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
312 rval_private_ptr
, new_binfo_ptr
, parent
,
313 protect
, via_virtual_ptr
, via_virtual
,
314 current_scope_in_chain
)
316 int depth
, is_private
, rval
;
317 int *rval_private_ptr
;
318 tree
*new_binfo_ptr
, parent
;
319 int protect
, *via_virtual_ptr
, via_virtual
;
320 int current_scope_in_chain
;
326 && !current_scope_in_chain
327 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
328 current_scope_in_chain
= 1;
330 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
335 /* This is the first time we've found parent. */
337 else if (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
338 BINFO_OFFSET (binfo
))
339 && *via_virtual_ptr
&& via_virtual
)
341 /* A new path to the same vbase. If this one has better
342 access or is shorter, take it. */
345 better
= *rval_private_ptr
- is_private
;
347 better
= rval
- depth
;
351 /* Ambiguous base class. */
354 /* If we get an ambiguity between virtual and non-virtual base
355 class, return the non-virtual in case we are ignoring
357 better
= *via_virtual_ptr
- via_virtual
;
363 *rval_private_ptr
= is_private
;
364 *new_binfo_ptr
= binfo
;
365 *via_virtual_ptr
= via_virtual
;
371 binfos
= BINFO_BASETYPES (binfo
);
372 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
375 /* Process base types. */
376 for (i
= 0; i
< n_baselinks
; i
++)
378 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
383 || (!TREE_VIA_PUBLIC (base_binfo
)
384 && !(TREE_VIA_PROTECTED (base_binfo
)
385 && current_scope_in_chain
)
386 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
387 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
389 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
390 rval
, rval_private_ptr
,
391 new_binfo_ptr
, parent
,
392 protect
, via_virtual_ptr
,
394 current_scope_in_chain
);
396 /* If we've found a non-virtual, ambiguous base class, we don't need
397 to keep searching. */
398 if (rval
== -2 && *via_virtual_ptr
== 0)
405 /* Return the number of levels between type PARENT and the type given
406 in BINFO, following the leftmost path to PARENT not found along a
407 virtual path, if there are no real PARENTs (all come from virtual
408 base classes), then follow the shortest public path to PARENT.
410 Return -1 if TYPE is not derived from PARENT.
411 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
413 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
415 If PATH_PTR is non-NULL, then also build the list of types
416 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
419 PARENT can also be a binfo, in which case that exact parent is found
420 and no other. convert_pointer_to_real uses this functionality.
422 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
425 get_base_distance (parent
, binfo
, protect
, path_ptr
)
426 register tree parent
, binfo
;
431 int rval_private
= 0;
432 tree type
= NULL_TREE
;
433 tree new_binfo
= NULL_TREE
;
435 int watch_access
= protect
;
437 /* Should we be completing types here? */
438 if (TREE_CODE (parent
) != TREE_VEC
)
439 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
441 complete_type (TREE_TYPE (parent
));
443 if (TREE_CODE (binfo
) == TREE_VEC
)
444 type
= BINFO_TYPE (binfo
);
445 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
447 type
= complete_type (binfo
);
448 binfo
= TYPE_BINFO (type
);
451 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
,
455 my_friendly_abort (92);
457 if (parent
== type
|| parent
== binfo
)
459 /* If the distance is 0, then we don't really need
460 a path pointer, but we shouldn't let garbage go back. */
469 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
470 &rval_private
, &new_binfo
, parent
,
471 watch_access
, &via_virtual
, 0,
474 /* Access restrictions don't count if we found an ambiguous basetype. */
475 if (rval
== -2 && protect
>= 0)
478 if (rval
&& protect
&& rval_private
)
481 /* If they gave us the real vbase binfo, which isn't in the main binfo
482 tree, deal with it. This happens when we are called from
483 expand_upcast_fixups. */
484 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
485 && parent
== binfo_member (BINFO_TYPE (parent
),
486 CLASSTYPE_VBASECLASSES (type
)))
488 my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent
) == binfo
, 980827);
494 *path_ptr
= new_binfo
;
498 /* Search for a member with name NAME in a multiple inheritance lattice
499 specified by TYPE. If it does not exist, return NULL_TREE.
500 If the member is ambiguously referenced, return `error_mark_node'.
501 Otherwise, return the FIELD_DECL. */
503 /* Do a 1-level search for NAME as a member of TYPE. The caller must
504 figure out whether it can access this field. (Since it is only one
505 level, this is reasonable.) */
508 lookup_field_1 (type
, name
)
513 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
514 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
515 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
516 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
517 the code often worked even when we treated the index as a list
521 field
= TYPE_FIELDS (type
);
523 #ifdef GATHER_STATISTICS
524 n_calls_lookup_field_1
++;
525 #endif /* GATHER_STATISTICS */
528 #ifdef GATHER_STATISTICS
530 #endif /* GATHER_STATISTICS */
531 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
532 if (DECL_NAME (field
) == NULL_TREE
533 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
535 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
539 if (TREE_CODE (field
) == USING_DECL
)
540 /* For now, we're just treating member using declarations as
541 old ARM-style access declarations. Thus, there's no reason
542 to return a USING_DECL, and the rest of the compiler can't
543 handle it. Once the class is defined, these are purged
544 from TYPE_FIELDS anyhow; see handle_using_decl. */
546 else if (DECL_NAME (field
) == name
)
548 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
549 && DECL_ASSEMBLER_NAME (field
) != NULL
)
550 GNU_xref_ref(current_function_decl
,
551 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
554 field
= TREE_CHAIN (field
);
557 if (name
== _vptr_name
)
559 /* Give the user what s/he thinks s/he wants. */
560 if (TYPE_VIRTUAL_P (type
))
561 return CLASSTYPE_VFIELD (type
);
566 /* There are a number of cases we need to be aware of here:
567 current_class_type current_function_decl
574 Those last two make life interesting. If we're in a function which is
575 itself inside a class, we need decls to go into the fn's decls (our
576 second case below). But if we're in a class and the class itself is
577 inside a function, we need decls to go into the decls for the class. To
578 achieve this last goal, we must see if, when both current_class_ptr and
579 current_function_decl are set, the class was declared inside that
580 function. If so, we know to put the decls into the class's scope. */
585 if (current_function_decl
== NULL_TREE
)
586 return current_class_type
;
587 if (current_class_type
== NULL_TREE
)
588 return current_function_decl
;
589 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
590 return current_function_decl
;
592 return current_class_type
;
595 /* Return the scope of DECL, as appropriate when doing name-lookup. */
598 context_for_name_lookup (decl
)
603 For the purposes of name lookup, after the anonymous union
604 definition, the members of the anonymous union are considered to
605 have been defined in the scope in which teh anonymous union is
607 tree context
= DECL_REAL_CONTEXT (decl
);
609 while (TYPE_P (context
) && ANON_UNION_TYPE_P (context
))
610 context
= TYPE_CONTEXT (context
);
612 context
= global_namespace
;
617 /* Return a canonical BINFO if BINFO is a virtual base, or just BINFO
621 canonical_binfo (binfo
)
624 return (TREE_VIA_VIRTUAL (binfo
)
625 ? TYPE_BINFO (BINFO_TYPE (binfo
)) : binfo
);
628 /* A queue function that simply ensures that we walk into the
629 canonical versions of virtual bases. */
632 dfs_canonical_queue (binfo
, data
)
634 void *data ATTRIBUTE_UNUSED
;
636 return canonical_binfo (binfo
);
639 /* Called via dfs_walk from assert_canonical_unmarked. */
642 dfs_assert_unmarked_p (binfo
, data
)
644 void *data ATTRIBUTE_UNUSED
;
646 my_friendly_assert (!BINFO_MARKED (binfo
), 0);
650 /* Asserts that all the nodes below BINFO (using the canonical
651 versions of virtual bases) are unmarked. */
654 assert_canonical_unmarked (binfo
)
657 dfs_walk (binfo
, dfs_assert_unmarked_p
, dfs_canonical_queue
, 0);
660 /* If BINFO is marked, return a canonical version of BINFO.
661 Otherwise, return NULL_TREE. */
664 shared_marked_p (binfo
, data
)
668 binfo
= canonical_binfo (binfo
);
669 return markedp (binfo
, data
) ? binfo
: NULL_TREE
;
672 /* If BINFO is not marked, return a canonical version of BINFO.
673 Otherwise, return NULL_TREE. */
676 shared_unmarked_p (binfo
, data
)
680 binfo
= canonical_binfo (binfo
);
681 return unmarkedp (binfo
, data
) ? binfo
: NULL_TREE
;
684 /* Called from access_in_type via dfs_walk. Calculate the access to
685 DATA (which is really a DECL) in BINFO. */
688 dfs_access_in_type (binfo
, data
)
692 tree decl
= (tree
) data
;
693 tree type
= BINFO_TYPE (binfo
);
694 tree access
= NULL_TREE
;
696 if (context_for_name_lookup (decl
) == type
)
698 /* If we have desceneded to the scope of DECL, just note the
699 appropriate access. */
700 if (TREE_PRIVATE (decl
))
701 access
= access_private_node
;
702 else if (TREE_PROTECTED (decl
))
703 access
= access_protected_node
;
705 access
= access_public_node
;
709 /* First, check for an access-declaration that gives us more
710 access to the DECL. The CONST_DECL for an enumeration
711 constant will not have DECL_LANG_SPECIFIC, and thus no
713 if (DECL_LANG_SPECIFIC (decl
))
715 access
= purpose_member (type
, DECL_ACCESS (decl
));
717 access
= TREE_VALUE (access
);
726 /* Otherwise, scan our baseclasses, and pick the most favorable
728 binfos
= BINFO_BASETYPES (binfo
);
729 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
730 for (i
= 0; i
< n_baselinks
; ++i
)
732 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
733 tree base_access
= TREE_CHAIN (canonical_binfo (base_binfo
));
735 if (!base_access
|| base_access
== access_private_node
)
736 /* If it was not accessible in the base, or only
737 accessible as a private member, we can't access it
739 base_access
= NULL_TREE
;
740 else if (TREE_VIA_PROTECTED (base_binfo
))
741 /* Public and protected members in the base are
743 base_access
= access_protected_node
;
744 else if (!TREE_VIA_PUBLIC (base_binfo
))
745 /* Public and protected members in the base are
747 base_access
= access_private_node
;
749 /* See if the new access, via this base, gives more
750 access than our previous best access. */
752 (base_access
== access_public_node
753 || (base_access
== access_protected_node
754 && access
!= access_public_node
)
755 || (base_access
== access_private_node
758 access
= base_access
;
760 /* If the new access is public, we can't do better. */
761 if (access
== access_public_node
)
768 /* Note the access to DECL in TYPE. */
769 TREE_CHAIN (binfo
) = access
;
771 /* Mark TYPE as visited so that if we reach it again we do not
772 duplicate our efforts here. */
773 SET_BINFO_MARKED (binfo
);
778 /* Return the access to DECL in TYPE. */
781 access_in_type (type
, decl
)
785 tree binfo
= TYPE_BINFO (type
);
787 /* We must take into account
791 If a name can be reached by several paths through a multiple
792 inheritance graph, the access is that of the path that gives
795 The algorithm we use is to make a post-order depth-first traversal
796 of the base-class hierarchy. As we come up the tree, we annotate
797 each node with the most lenient access. */
798 dfs_walk_real (binfo
, 0, dfs_access_in_type
, shared_unmarked_p
, decl
);
799 dfs_walk (binfo
, dfs_unmark
, shared_marked_p
, 0);
800 assert_canonical_unmarked (binfo
);
802 return TREE_CHAIN (binfo
);
805 /* Called from dfs_accessible_p via dfs_walk. */
808 dfs_accessible_queue_p (binfo
, data
)
810 void *data ATTRIBUTE_UNUSED
;
812 if (BINFO_MARKED (binfo
))
815 /* If this class is inherited via private or protected inheritance,
816 then we can't see it, unless we are a friend of the subclass. */
817 if (!TREE_VIA_PUBLIC (binfo
)
818 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
)),
822 return canonical_binfo (binfo
);
825 /* Called from dfs_accessible_p via dfs_walk. */
828 dfs_accessible_p (binfo
, data
)
832 int protected_ok
= data
!= 0;
835 /* We marked the binfos while computing the access in each type.
836 So, we unmark as we go now. */
837 SET_BINFO_MARKED (binfo
);
839 access
= TREE_CHAIN (binfo
);
840 if (access
== access_public_node
841 || (access
== access_protected_node
&& protected_ok
))
843 else if (access
&& is_friend (BINFO_TYPE (binfo
), current_scope ()))
849 /* DECL is a declaration from a base class of TYPE, which was the
850 classs used to name DECL. Return non-zero 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 (type
, decl
)
865 /* Non-zero if it's OK to access DECL if it has protected
866 accessibility in TYPE. */
867 int protected_ok
= 0;
869 /* If we're not checking access, everything is accessible. */
870 if (!flag_access_control
)
873 /* If this declaration is in a block or namespace scope, there's no
875 if (!TYPE_P (context_for_name_lookup (decl
)))
878 /* We don't do access control for types yet. */
879 if (TREE_CODE (decl
) == TYPE_DECL
)
885 type
= BINFO_TYPE (type
);
888 binfo
= TYPE_BINFO (type
);
890 /* [class.access.base]
892 A member m is accessible when named in class N if
894 --m as a member of N is public, or
896 --m as a member of N is private, and the reference occurs in a
897 member or friend of class N, or
899 --m as a member of N is protected, and the reference occurs in a
900 member or friend of class N, or in a member or friend of a
901 class P derived from N, where m as a member of P is private or
904 --there exists a base class B of N that is accessible at the point
905 of reference, and m is accessible when named in class B.
907 We walk the base class hierarchy, checking these conditions. */
909 /* Figure out where the reference is occurring. Check to see if
910 DECL is private or protected in this scope, since that will
911 determine whether protected access in TYPE allowed. */
912 if (current_class_type
913 && DERIVED_FROM_P (type
, current_class_type
))
915 tree access
= access_in_type (current_class_type
, decl
);
916 if (same_type_p (current_class_type
, type
)
917 && access
== access_private_node
)
919 else if (access
&& (access
== access_private_node
920 || access
== access_protected_node
))
924 /* Now, loop through the classes of which SCOPE is a friend. */
925 if (!protected_ok
&& scope
)
927 /* FIXME: Implement this. Right now, we have no way of knowing
928 which classes befriend a particular function or class. */
933 When a friend or a member function of a derived class references
934 a protected nonstatic member of a base class, an access check
935 applies in addition to those described earlier in clause
936 _class.access_.4) Except when forming a pointer to member
937 (_expr.unary.op_), the access must be through a pointer to,
938 reference to, or object of the derived class itself (or any class
939 derived from that class) (_expr.ref_). If the access is to form
940 a pointer to member, the nested-name-specifier shall name the
941 derived class (or any class derived from that class). */
942 if (protected_ok
&& DECL_NONSTATIC_MEMBER_P (decl
))
944 /* We can tell through what the reference is occurring by
945 chasing BINFO up to the root. */
947 while (BINFO_INHERITANCE_CHAIN (t
))
948 t
= BINFO_INHERITANCE_CHAIN (t
);
950 if (!DERIVED_FROM_P (current_class_type
, BINFO_TYPE (t
)))
954 /* Standardize on the same that will access_in_type will use. We
955 don't need to know what path was chosen from this point onwards. */
956 binfo
= TYPE_BINFO (type
);
958 /* Compute the accessibility of DECL in the class hierarchy
959 dominated by type. */
960 access_in_type (type
, decl
);
961 /* Walk the hierarchy again, looking for a base class that allows
963 t
= dfs_walk (binfo
, dfs_accessible_p
,
964 dfs_accessible_queue_p
,
965 protected_ok
? &protected_ok
: 0);
966 /* Clear any mark bits. Note that we have to walk the whole tree
967 here, since we have aborted the previous walk from some point
969 dfs_walk (binfo
, dfs_unmark
, dfs_canonical_queue
, 0);
970 assert_canonical_unmarked (binfo
);
972 return t
!= NULL_TREE
;
975 /* Routine to see if the sub-object denoted by the binfo PARENT can be
976 found as a base class and sub-object of the object denoted by
977 BINFO. This routine relies upon binfos not being shared, except
978 for binfos for virtual bases. */
981 is_subobject_of_p (parent
, binfo
)
984 tree binfos
= BINFO_BASETYPES (binfo
);
985 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
987 if (TREE_VIA_VIRTUAL (parent
))
988 parent
= TYPE_BINFO (TREE_TYPE (parent
));
989 if (TREE_VIA_VIRTUAL (binfo
))
990 binfo
= TYPE_BINFO (TREE_TYPE (binfo
));
995 /* Process and/or queue base types. */
996 for (i
= 0; i
< n_baselinks
; i
++)
998 tree base_binfo
= canonical_binfo (TREE_VEC_ELT (binfos
, i
));
999 if (is_subobject_of_p (parent
, base_binfo
))
1005 /* See if a one FIELD_DECL hides another. This routine is meant to
1006 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1007 binfos given are the binfos corresponding to the particular places
1008 the FIELD_DECLs are found. This routine relies upon binfos not
1009 being shared, except for virtual bases. */
1012 hides (hider_binfo
, hidee_binfo
)
1013 tree hider_binfo
, hidee_binfo
;
1015 /* hider hides hidee, if hider has hidee as a base class and
1016 the instance of hidee is a sub-object of hider. The first
1017 part is always true is the second part is true.
1019 When hider and hidee are the same (two ways to get to the exact
1020 same member) we consider either one as hiding the other. */
1021 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
1024 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1025 function was declared inside the class given by TYPE. It really should
1026 only return functions that match the given TYPE. */
1029 lookup_fnfields_here (type
, name
)
1032 int idx
= lookup_fnfields_1 (type
, name
);
1035 /* ctors and dtors are always only in the right class. */
1038 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1041 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls
)))
1042 == TYPE_MAIN_VARIANT (type
))
1044 fndecls
= OVL_CHAIN (fndecls
);
1049 struct lookup_field_info
{
1050 /* The type in which we're looking. */
1052 /* The name of the field for which we're looking. */
1054 /* If non-NULL, the current result of the lookup. */
1056 /* The path to RVAL. */
1058 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1061 /* If non-zero, we are looking for types, not data members. */
1063 /* If non-zero, RVAL was found by looking through a dependent base. */
1064 int from_dep_base_p
;
1065 /* If something went wrong, a message indicating what. */
1069 /* Returns non-zero if BINFO is not hidden by the value found by the
1070 lookup so far. If BINFO is hidden, then there's no need to look in
1071 it. DATA is really a struct lookup_field_info. Called from
1072 lookup_field via breadth_first_search. */
1075 lookup_field_queue_p (binfo
, data
)
1079 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1081 /* Don't look for constructors or destructors in base classes. */
1082 if (lfi
->name
== ctor_identifier
|| lfi
->name
== dtor_identifier
)
1085 /* If this base class is hidden by the best-known value so far, we
1086 don't need to look. */
1087 if (!lfi
->from_dep_base_p
&& lfi
->rval_binfo
1088 && hides (lfi
->rval_binfo
, binfo
))
1091 if (TREE_VIA_VIRTUAL (binfo
))
1092 return binfo_member (BINFO_TYPE (binfo
),
1093 CLASSTYPE_VBASECLASSES (lfi
->type
));
1098 /* DATA is really a struct lookup_field_info. Look for a field with
1099 the name indicated there in BINFO. If this function returns a
1100 non-NULL value it is the result of the lookup. Called from
1101 lookup_field via breadth_first_search. */
1104 lookup_field_r (binfo
, data
)
1108 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1109 tree type
= BINFO_TYPE (binfo
);
1112 int from_dep_base_p
;
1114 /* First, look for a function. There can't be a function and a data
1115 member with the same name, and if there's a function and a type
1116 with the same name, the type is hidden by the function. */
1117 idx
= lookup_fnfields_here (type
, lfi
->name
);
1119 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1121 /* Look for a data member or type. */
1122 nval
= lookup_field_1 (type
, lfi
->name
);
1124 /* If there is no declaration with the indicated name in this type,
1125 then there's nothing to do. */
1129 from_dep_base_p
= dependent_base_p (binfo
);
1130 if (lfi
->from_dep_base_p
&& !from_dep_base_p
)
1132 /* If the new declaration is not found via a dependent base, and
1133 the old one was, then we must prefer the new one. We weren't
1134 really supposed to be able to find the old one, so we don't
1135 want to be affected by a specialization. Consider:
1137 struct B { typedef int I; };
1138 template <typename T> struct D1 : virtual public B {};
1139 template <typename T> struct D :
1140 public D1, virtual pubic B { I i; };
1142 The `I' in `D<T>' is unambigousuly `B::I', regardless of how
1143 D1 is specialized. */
1144 lfi
->from_dep_base_p
= 0;
1145 lfi
->rval
= NULL_TREE
;
1146 lfi
->rval_binfo
= NULL_TREE
;
1147 lfi
->ambiguous
= NULL_TREE
;
1150 else if (lfi
->rval_binfo
&& !lfi
->from_dep_base_p
&& from_dep_base_p
)
1151 /* Similarly, if the old declaration was not found via a dependent
1152 base, and the new one is, ignore the new one. */
1155 /* If the lookup already found a match, and the new value doesn't
1156 hide the old one, we might have an ambiguity. */
1157 if (lfi
->rval_binfo
&& !hides (binfo
, lfi
->rval_binfo
))
1159 if (nval
== lfi
->rval
&& SHARED_MEMBER_P (nval
))
1160 /* The two things are really the same. */
1162 else if (hides (lfi
->rval_binfo
, binfo
))
1163 /* The previous value hides the new one. */
1167 /* We have a real ambiguity. We keep a chain of all the
1169 if (!lfi
->ambiguous
&& lfi
->rval
)
1170 /* This is the first time we noticed an ambiguity. Add
1171 what we previously thought was a reasonable candidate
1173 lfi
->ambiguous
= scratch_tree_cons (NULL_TREE
, lfi
->rval
,
1175 /* Add the new value. */
1176 lfi
->ambiguous
= scratch_tree_cons (NULL_TREE
, nval
,
1178 lfi
->errstr
= "request for member `%D' is ambiguous";
1183 /* The new lookup is the best we've got so far. Verify that
1184 it's the kind of thing we're looking for. */
1185 if (lfi
->want_type
&& TREE_CODE (nval
) != TYPE_DECL
)
1187 nval
= purpose_member (lfi
->name
, CLASSTYPE_TAGS (type
));
1189 nval
= TYPE_MAIN_DECL (TREE_VALUE (nval
));
1194 /* If the thing we're looking for is a virtual base class,
1195 then we know we've got what we want at this point;
1196 there's no way to get an ambiguity. */
1197 if (VBASE_NAME_P (lfi
->name
))
1203 if (from_dep_base_p
&& TREE_CODE (nval
) != TYPE_DECL
1204 /* We need to return a member template class so we can
1205 define partial specializations. Is there a better
1207 && !DECL_CLASS_TEMPLATE_P (nval
))
1208 /* The thing we're looking for isn't a type, so the implicit
1209 typename extension doesn't apply, so we just pretend we
1210 didn't find anything. */
1215 lfi
->from_dep_base_p
= from_dep_base_p
;
1216 lfi
->rval_binfo
= binfo
;
1222 /* Look for a memer named NAME in an inheritance lattice dominated by
1223 XBASETYPE. PROTECT is zero if we can avoid computing access
1224 information, otherwise it is 1. WANT_TYPE is 1 when we should only
1225 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
1227 It was not clear what should happen if WANT_TYPE is set, and an
1228 ambiguity is found. At least one use (lookup_name) to not see
1232 lookup_member (xbasetype
, name
, protect
, want_type
)
1233 register tree xbasetype
, name
;
1234 int protect
, want_type
;
1236 tree rval
, rval_binfo
= NULL_TREE
;
1237 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1238 struct lookup_field_info lfi
;
1240 /* rval_binfo is the binfo associated with the found member, note,
1241 this can be set with useful information, even when rval is not
1242 set, because it must deal with ALL members, not just non-function
1243 members. It is used for ambiguity checking and the hidden
1244 checks. Whereas rval is only set if a proper (not hidden)
1245 non-function member is found. */
1247 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1248 hiding checks, as virtual base classes may not be shared. The strategy
1249 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1250 virtual base classes, as we cross virtual base class lines. This way
1251 we know that binfo of a virtual base class will always == itself when
1252 found along any line. (mrs) */
1256 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1257 && IDENTIFIER_CLASS_VALUE (name
))
1259 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1260 if (TREE_CODE (field
) != FUNCTION_DECL
1261 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1265 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1267 type
= BINFO_TYPE (xbasetype
);
1268 basetype_path
= xbasetype
;
1270 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1273 basetype_path
= TYPE_BINFO (type
);
1274 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
1278 my_friendly_abort (97);
1280 complete_type (type
);
1282 #ifdef GATHER_STATISTICS
1283 n_calls_lookup_field
++;
1284 #endif /* GATHER_STATISTICS */
1286 bzero (&lfi
, sizeof (lfi
));
1289 lfi
.want_type
= want_type
;
1290 bfs_walk (basetype_path
, &lookup_field_r
, &lookup_field_queue_p
, &lfi
);
1292 rval_binfo
= lfi
.rval_binfo
;
1294 type
= BINFO_TYPE (rval_binfo
);
1295 errstr
= lfi
.errstr
;
1297 /* If we are not interested in ambiguities, don't report them;
1298 just return NULL_TREE. */
1299 if (!protect
&& lfi
.ambiguous
)
1304 In the case of overloaded function names, access control is
1305 applied to the function selected by overloaded resolution. */
1306 if (rval
&& protect
&& !is_overloaded_fn (rval
)
1307 && !IS_SIGNATURE_POINTER (DECL_REAL_CONTEXT (rval
))
1308 && !IS_SIGNATURE_REFERENCE (DECL_REAL_CONTEXT (rval
))
1309 && !enforce_access (xbasetype
, rval
))
1310 return error_mark_node
;
1312 if (errstr
&& protect
)
1314 cp_error (errstr
, name
, type
);
1316 print_candidates (lfi
.ambiguous
);
1317 rval
= error_mark_node
;
1320 /* If the thing we found was found via the implicit typename
1321 extension, build the typename type. */
1322 if (rval
&& lfi
.from_dep_base_p
&& !DECL_CLASS_TEMPLATE_P (rval
))
1323 rval
= TYPE_STUB_DECL (build_typename_type (BINFO_TYPE (basetype_path
),
1327 if (rval
&& is_overloaded_fn (rval
))
1328 rval
= scratch_tree_cons (basetype_path
, rval
, NULL_TREE
);
1333 /* Like lookup_member, except that if we find a function member we
1334 return NULL_TREE. */
1337 lookup_field (xbasetype
, name
, protect
, want_type
)
1338 register tree xbasetype
, name
;
1339 int protect
, want_type
;
1341 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
);
1343 /* Ignore functions. */
1344 if (rval
&& TREE_CODE (rval
) == TREE_LIST
)
1350 /* Like lookup_member, except that if we find a non-function member we
1351 return NULL_TREE. */
1354 lookup_fnfields (xbasetype
, name
, protect
)
1355 register tree xbasetype
, name
;
1358 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/0);
1360 /* Ignore non-functions. */
1361 if (rval
&& TREE_CODE (rval
) != TREE_LIST
)
1367 /* Try to find NAME inside a nested class. */
1370 lookup_nested_field (name
, complain
)
1376 tree id
= NULL_TREE
;
1377 if (TYPE_MAIN_DECL (current_class_type
))
1379 /* Climb our way up the nested ladder, seeing if we're trying to
1380 modify a field in an enclosing class. If so, we should only
1381 be able to modify if it's static. */
1382 for (t
= TYPE_MAIN_DECL (current_class_type
);
1383 t
&& DECL_CONTEXT (t
);
1384 t
= TYPE_MAIN_DECL (DECL_CONTEXT (t
)))
1386 if (TREE_CODE (DECL_CONTEXT (t
)) != RECORD_TYPE
)
1389 /* N.B.: lookup_field will do the access checking for us */
1390 id
= lookup_field (DECL_CONTEXT (t
), name
, complain
, 0);
1391 if (id
== error_mark_node
)
1397 if (id
!= NULL_TREE
)
1399 if (TREE_CODE (id
) == FIELD_DECL
1400 && ! TREE_STATIC (id
)
1401 && TREE_TYPE (id
) != error_mark_node
)
1405 /* At parse time, we don't want to give this error, since
1406 we won't have enough state to make this kind of
1407 decision properly. But there are times (e.g., with
1408 enums in nested classes) when we do need to call
1409 this fn at parse time. So, in those cases, we pass
1410 complain as a 0 and just return a NULL_TREE. */
1411 cp_error ("assignment to non-static member `%D' of enclosing class `%T'",
1412 id
, DECL_CONTEXT (t
));
1413 /* Mark this for do_identifier(). It would otherwise
1414 claim that the variable was undeclared. */
1415 TREE_TYPE (id
) = error_mark_node
;
1431 /* TYPE is a class type. Return the index of the fields within
1432 the method vector with name NAME, or -1 is no such field exists. */
1435 lookup_fnfields_1 (type
, name
)
1438 register tree method_vec
1439 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
1441 if (method_vec
!= 0)
1443 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1444 register tree
*end
= TREE_VEC_END (method_vec
);
1446 #ifdef GATHER_STATISTICS
1447 n_calls_lookup_fnfields_1
++;
1448 #endif /* GATHER_STATISTICS */
1450 /* Constructors are first... */
1451 if (*methods
&& name
== ctor_identifier
)
1454 /* and destructors are second. */
1455 if (*++methods
&& name
== dtor_identifier
)
1458 while (++methods
!= end
&& *methods
)
1460 #ifdef GATHER_STATISTICS
1461 n_outer_fields_searched
++;
1462 #endif /* GATHER_STATISTICS */
1463 if (DECL_NAME (OVL_CURRENT (*methods
)) == name
)
1467 /* If we didn't find it, it might have been a template
1468 conversion operator. (Note that we don't look for this case
1469 above so that we will always find specializations first.) */
1470 if ((methods
== end
|| !*methods
)
1471 && IDENTIFIER_TYPENAME_P (name
))
1473 methods
= &TREE_VEC_ELT (method_vec
, 0) + 1;
1475 while (++methods
!= end
&& *methods
)
1477 tree method_name
= DECL_NAME (OVL_CURRENT (*methods
));
1479 if (!IDENTIFIER_TYPENAME_P (method_name
))
1481 /* Since all conversion operators come first, we know
1482 there is no such operator. */
1486 else if (TREE_CODE (OVL_CURRENT (*methods
)) == TEMPLATE_DECL
)
1491 if (methods
!= end
&& *methods
)
1492 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1498 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1499 type in the hierarchy, in a breadth-first preorder traversal. .
1500 If it ever returns a non-NULL value, that value is immediately
1501 returned and the walk is terminated. At each node FN, is passed a
1502 BINFO indicating the path from the curently visited base-class to
1503 TYPE. The TREE_CHAINs of the BINFOs may be used for scratch space;
1504 they are otherwise unused. Before each base-class is walked QFN is
1505 called. If the value returned is non-zero, the base-class is
1506 walked; otherwise it is not. If QFN is NULL, it is treated as a
1507 function which always returns 1. Both FN and QFN are passed the
1508 DATA whenever they are called. */
1511 bfs_walk (binfo
, fn
, qfn
, data
)
1513 tree (*fn
) PROTO((tree
, void *));
1514 tree (*qfn
) PROTO((tree
, void *));
1519 tree rval
= NULL_TREE
;
1520 /* An array of the base classes of BINFO. These will be built up in
1521 breadth-first order, except where QFN prunes the search. */
1522 varray_type bfs_bases
;
1524 /* Start with enough room for ten base classes. That will be enough
1525 for most hierarchies. */
1526 VARRAY_TREE_INIT (bfs_bases
, 10, "search_stack");
1528 /* Put the first type into the stack. */
1529 VARRAY_TREE (bfs_bases
, 0) = binfo
;
1532 for (head
= 0; head
< tail
; ++head
)
1538 /* Pull the next type out of the queue. */
1539 binfo
= VARRAY_TREE (bfs_bases
, head
);
1541 /* If this is the one we're looking for, we're done. */
1542 rval
= (*fn
) (binfo
, data
);
1546 /* Queue up the base types. */
1547 binfos
= BINFO_BASETYPES (binfo
);
1548 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1549 for (i
= 0; i
< n_baselinks
; i
++)
1551 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1554 base_binfo
= (*qfn
) (base_binfo
, data
);
1558 if (tail
== VARRAY_SIZE (bfs_bases
))
1559 VARRAY_GROW (bfs_bases
, 2 * VARRAY_SIZE (bfs_bases
));
1560 VARRAY_TREE (bfs_bases
, tail
) = base_binfo
;
1567 VARRAY_FREE (bfs_bases
);
1572 /* Exactly like bfs_walk, except that a depth-first traversal is
1573 performed, and PREFN is called in preorder, while POSTFN is called
1577 dfs_walk_real (binfo
, prefn
, postfn
, qfn
, data
)
1579 tree (*prefn
) PROTO((tree
, void *));
1580 tree (*postfn
) PROTO((tree
, void *));
1581 tree (*qfn
) PROTO((tree
, void *));
1587 tree rval
= NULL_TREE
;
1589 /* Call the pre-order walking function. */
1592 rval
= (*prefn
) (binfo
, data
);
1597 /* Process the basetypes. */
1598 binfos
= BINFO_BASETYPES (binfo
);
1599 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1600 for (i
= 0; i
< n_baselinks
; i
++)
1602 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1605 base_binfo
= (*qfn
) (base_binfo
, data
);
1609 rval
= dfs_walk_real (base_binfo
, prefn
, postfn
, qfn
, data
);
1615 /* Call the post-order walking function. */
1617 rval
= (*postfn
) (binfo
, data
);
1622 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1626 dfs_walk (binfo
, fn
, qfn
, data
)
1628 tree (*fn
) PROTO((tree
, void *));
1629 tree (*qfn
) PROTO((tree
, void *));
1632 return dfs_walk_real (binfo
, 0, fn
, qfn
, data
);
1637 /* The name of the function we are looking for. */
1639 /* The overloaded functions we have found. */
1643 /* Called from get_virtuals_named_this via bfs_walk. */
1646 get_virtuals_named_this_r (binfo
, data
)
1650 struct gvnt_info
*gvnti
= (struct gvnt_info
*) data
;
1651 tree type
= BINFO_TYPE (binfo
);
1654 idx
= lookup_fnfields_here (BINFO_TYPE (binfo
), gvnti
->name
);
1657 = scratch_tree_cons (binfo
,
1658 TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
),
1665 /* Return the virtual functions with the indicated NAME in the type
1666 indicated by BINFO. The result is a TREE_LIST whose TREE_PURPOSE
1667 indicates the base class from which the TREE_VALUE (an OVERLOAD or
1668 just a FUNCTION_DECL) originated. */
1671 get_virtuals_named_this (binfo
, name
)
1675 struct gvnt_info gvnti
;
1679 gvnti
.fields
= NULL_TREE
;
1681 bfs_walk (binfo
, get_virtuals_named_this_r
, 0, &gvnti
);
1683 /* Get to the function decls, and return the first virtual function
1684 with this name, if there is one. */
1685 for (fields
= gvnti
.fields
; fields
; fields
= next_baselink (fields
))
1689 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
1690 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
1697 get_virtual_destructor (binfo
, data
)
1699 void *data ATTRIBUTE_UNUSED
;
1701 tree type
= BINFO_TYPE (binfo
);
1702 if (TYPE_HAS_DESTRUCTOR (type
)
1703 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
1704 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
1709 tree_has_any_destructor_p (binfo
, data
)
1711 void *data ATTRIBUTE_UNUSED
;
1713 tree type
= BINFO_TYPE (binfo
);
1714 return TYPE_NEEDS_DESTRUCTOR (type
) ? binfo
: NULL_TREE
;
1717 /* Returns > 0 if a function with type DRETTYPE overriding a function
1718 with type BRETTYPE is covariant, as defined in [class.virtual].
1720 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1721 adjustment), or -1 if pedantically invalid covariance. */
1724 covariant_return_p (brettype
, drettype
)
1725 tree brettype
, drettype
;
1729 if (TREE_CODE (brettype
) == FUNCTION_DECL
1730 || TREE_CODE (brettype
) == THUNK_DECL
)
1732 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
1733 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
1735 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
1737 brettype
= TREE_TYPE (brettype
);
1738 drettype
= TREE_TYPE (drettype
);
1741 if (same_type_p (brettype
, drettype
))
1744 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
1745 && (TREE_CODE (brettype
) == POINTER_TYPE
1746 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
1747 && TYPE_QUALS (brettype
) == TYPE_QUALS (drettype
)))
1750 if (! can_convert (brettype
, drettype
))
1753 brettype
= TREE_TYPE (brettype
);
1754 drettype
= TREE_TYPE (drettype
);
1756 /* If not pedantic, allow any standard pointer conversion. */
1757 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
1760 binfo
= get_binfo (brettype
, drettype
, 1);
1762 /* If we get an error_mark_node from get_binfo, it already complained,
1763 so let's just succeed. */
1764 if (binfo
== error_mark_node
)
1767 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
1772 /* Given a class type TYPE, and a function decl FNDECL, look for a
1773 virtual function in TYPE's hierarchy which FNDECL could match as a
1774 virtual function. It doesn't matter which one we find.
1776 DTORP is nonzero if we are looking for a destructor. Destructors
1777 need special treatment because they do not match by name. */
1780 get_matching_virtual (binfo
, fndecl
, dtorp
)
1784 tree tmp
= NULL_TREE
;
1787 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
1788 /* In [temp.mem] we have:
1790 A specialization of a member function template does not
1791 override a virtual function from a base class. */
1794 /* Breadth first search routines start searching basetypes
1795 of TYPE, so we must perform first ply of search here. */
1797 return bfs_walk (binfo
, get_virtual_destructor
,
1798 tree_has_any_destructor_p
, 0);
1801 tree drettype
, dtypes
, btypes
, instptr_type
;
1802 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
1803 tree baselink
, best
= NULL_TREE
;
1804 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
1805 tree declarator
= DECL_NAME (fndecl
);
1806 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
1809 baselink
= get_virtuals_named_this (binfo
, declarator
);
1810 if (baselink
== NULL_TREE
)
1813 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
1814 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1815 if (DECL_STATIC_FUNCTION_P (fndecl
))
1816 instptr_type
= NULL_TREE
;
1818 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
1820 for (; baselink
; baselink
= next_baselink (baselink
))
1823 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
1825 tmp
= OVL_CURRENT (tmps
);
1826 if (! DECL_VINDEX (tmp
))
1829 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
1830 if (instptr_type
== NULL_TREE
)
1832 if (compparms (TREE_CHAIN (btypes
), dtypes
))
1833 /* Caller knows to give error in this case. */
1838 if (/* The first parameter is the `this' parameter,
1839 which has POINTER_TYPE, and we can therefore
1840 safely use TYPE_QUALS, rather than
1842 (TYPE_QUALS (TREE_TYPE (TREE_VALUE (btypes
)))
1843 == TYPE_QUALS (instptr_type
))
1844 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
)))
1846 tree brettype
= TREE_TYPE (TREE_TYPE (tmp
));
1847 if (same_type_p (brettype
, drettype
))
1849 else if ((i
= covariant_return_p (brettype
, drettype
)))
1852 sorry ("adjusting pointers for covariant returns");
1854 if (pedantic
&& i
== -1)
1856 cp_pedwarn_at ("invalid covariant return type for `%#D' (must be pointer or reference to class)", fndecl
);
1857 cp_pedwarn_at (" overriding `%#D'", tmp
);
1860 else if (IS_AGGR_TYPE_2 (brettype
, drettype
)
1861 && same_or_base_type_p (brettype
, drettype
))
1863 error ("invalid covariant return type (must use pointer or reference)");
1864 cp_error_at (" overriding `%#D'", tmp
);
1865 cp_error_at (" with `%#D'", fndecl
);
1867 else if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
)
1869 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl
);
1870 cp_error_at (" overriding definition as `%#D'", tmp
);
1871 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
1874 /* FNDECL overrides this function. We continue to
1875 check all the other functions in order to catch
1876 errors; it might be that in some other baseclass
1877 a virtual function was declared with the same
1878 parameter types, but a different return type. */
1888 /* Return the list of virtual functions which are abstract in type
1889 TYPE that come from non virtual base classes. See
1890 expand_direct_vtbls_init for the style of search we do. */
1893 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
1896 tree abstract_virtuals
;
1898 tree binfos
= BINFO_BASETYPES (binfo
);
1899 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1901 for (i
= 0; i
< n_baselinks
; i
++)
1903 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1904 int is_not_base_vtable
1905 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
1906 if (! TREE_VIA_VIRTUAL (base_binfo
))
1908 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
1911 /* Should we use something besides CLASSTYPE_VFIELDS? */
1912 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
1914 tree virtuals
= BINFO_VIRTUALS (binfo
);
1916 skip_rtti_stuff (&virtuals
);
1920 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
1921 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
1922 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
1923 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
1924 virtuals
= TREE_CHAIN (virtuals
);
1927 return abstract_virtuals
;
1930 /* Return the list of virtual functions which are abstract in type TYPE.
1931 This information is cached, and so must be built on a
1932 non-temporary obstack. */
1935 get_abstract_virtuals (type
)
1939 tree abstract_virtuals
= NULL
;
1941 /* First get all from non-virtual bases. */
1943 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
1945 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
1947 tree virtuals
= BINFO_VIRTUALS (vbases
);
1949 skip_rtti_stuff (&virtuals
);
1953 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
1954 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
1955 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
1956 cp_error ("`%#D' needs a final overrider", base_fndecl
);
1957 else if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
1958 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
1959 virtuals
= TREE_CHAIN (virtuals
);
1962 return nreverse (abstract_virtuals
);
1965 /* For the type TYPE, return a list of member functions available from
1966 base classes with name NAME. The TREE_VALUE of the list is a chain of
1967 member functions with name NAME. The TREE_PURPOSE of the list is a
1968 basetype, or a list of base types (in reverse order) which were
1969 traversed to reach the chain of member functions. If we reach a base
1970 type which provides a member function of name NAME, and which has at
1971 most one base type itself, then we can terminate the search. */
1974 get_baselinks (type_as_binfo_list
, type
, name
)
1975 tree type_as_binfo_list
;
1978 int head
= 0, tail
= 0, idx
;
1979 tree rval
= 0, nval
= 0;
1980 tree basetypes
= type_as_binfo_list
;
1981 tree binfo
= TYPE_BINFO (type
);
1983 search_stack
= push_search_level (search_stack
, &search_obstack
);
1987 tree binfos
= BINFO_BASETYPES (binfo
);
1988 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1990 /* Process and/or queue base types. */
1991 for (i
= 0; i
< n_baselinks
; i
++)
1993 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1996 btypes
= hash_tree_cons (TREE_VIA_PUBLIC (base_binfo
),
1997 TREE_VIA_VIRTUAL (base_binfo
),
1998 TREE_VIA_PROTECTED (base_binfo
),
1999 NULL_TREE
, base_binfo
,
2001 obstack_ptr_grow (&search_obstack
, btypes
);
2002 search_stack
->first
= (tree
*)obstack_base (&search_obstack
);
2007 /* Process head of queue, if one exists. */
2011 basetypes
= search_stack
->first
[head
++];
2012 binfo
= TREE_VALUE (basetypes
);
2013 type
= BINFO_TYPE (binfo
);
2014 idx
= lookup_fnfields_1 (type
, name
);
2017 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
2018 rval
= hash_tree_cons (0, 0, 0, basetypes
, nval
, rval
);
2019 if (TYPE_BINFO_BASETYPES (type
) == 0)
2021 else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
)) == 1)
2023 if (CLASSTYPE_BASELINK_VEC (type
))
2024 TREE_TYPE (rval
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
2031 search_stack
= pop_search_level (search_stack
);
2036 next_baselink (baselink
)
2039 tree tmp
= TREE_TYPE (baselink
);
2040 baselink
= TREE_CHAIN (baselink
);
2043 /* @@ does not yet add previous base types. */
2044 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2046 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2047 tmp
= TREE_CHAIN (tmp
);
2052 /* DEPTH-FIRST SEARCH ROUTINES. */
2054 /* This routine converts a pointer to be a pointer of an immediate
2055 base class. The normal convert_pointer_to routine would diagnose
2056 the conversion as ambiguous, under MI code that has the base class
2057 as an ambiguous base class. */
2060 convert_pointer_to_single_level (to_type
, expr
)
2063 tree binfo_of_derived
;
2066 binfo_of_derived
= TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
)));
2067 last
= get_binfo (to_type
, TREE_TYPE (TREE_TYPE (expr
)), 0);
2068 my_friendly_assert (BINFO_INHERITANCE_CHAIN (last
) == binfo_of_derived
,
2070 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo_of_derived
) == NULL_TREE
,
2072 return build_vbase_path (PLUS_EXPR
, build_pointer_type (to_type
), expr
,
2076 tree
markedp (binfo
, data
)
2078 void *data ATTRIBUTE_UNUSED
;
2080 return BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2084 unmarkedp (binfo
, data
)
2086 void *data ATTRIBUTE_UNUSED
;
2088 return !BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2092 marked_vtable_pathp (binfo
, data
)
2094 void *data ATTRIBUTE_UNUSED
;
2096 return BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2100 unmarked_vtable_pathp (binfo
, data
)
2102 void *data ATTRIBUTE_UNUSED
;
2104 return !BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2108 marked_new_vtablep (binfo
, data
)
2110 void *data ATTRIBUTE_UNUSED
;
2112 return BINFO_NEW_VTABLE_MARKED (binfo
) ? binfo
: NULL_TREE
;
2116 unmarked_new_vtablep (binfo
, data
)
2118 void *data ATTRIBUTE_UNUSED
;
2120 return !BINFO_NEW_VTABLE_MARKED (binfo
) ? binfo
: NULL_TREE
;
2124 marked_pushdecls_p (binfo
, data
)
2126 void *data ATTRIBUTE_UNUSED
;
2128 return BINFO_PUSHDECLS_MARKED (binfo
) ? binfo
: NULL_TREE
;
2132 unmarked_pushdecls_p (binfo
, data
)
2134 void *data ATTRIBUTE_UNUSED
;
2136 return !BINFO_PUSHDECLS_MARKED (binfo
) ? binfo
: NULL_TREE
;
2140 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2141 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2145 dfs_debug_unmarkedp (binfo
, data
)
2147 void *data ATTRIBUTE_UNUSED
;
2149 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
))
2150 ? binfo
: NULL_TREE
);
2153 /* The worker functions for `dfs_walk'. These do not need to
2154 test anything (vis a vis marking) if they are paired with
2155 a predicate function (above). */
2159 dfs_mark (binfo
) tree binfo
;
2160 { SET_BINFO_MARKED (binfo
); }
2164 dfs_unmark (binfo
, data
)
2166 void *data ATTRIBUTE_UNUSED
;
2168 CLEAR_BINFO_MARKED (binfo
);
2174 dfs_mark_vtable_path (binfo
) tree binfo
;
2175 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2178 dfs_unmark_vtable_path (binfo
) tree binfo
;
2179 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2182 dfs_mark_new_vtable (binfo
) tree binfo
;
2183 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2186 dfs_unmark_new_vtable (binfo
) tree binfo
;
2187 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2190 dfs_clear_search_slot (binfo
) tree binfo
;
2191 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2195 dfs_debug_mark (binfo
, data
)
2197 void *data ATTRIBUTE_UNUSED
;
2199 tree t
= BINFO_TYPE (binfo
);
2201 /* Use heuristic that if there are virtual functions,
2202 ignore until we see a non-inline virtual function. */
2203 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2205 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2210 /* If interface info is known, either we've already emitted the debug
2211 info or we don't need to. */
2212 if (CLASSTYPE_INTERFACE_KNOWN (t
))
2215 /* If debug info is requested from this context for this type, supply it.
2216 If debug info is requested from another context for this type,
2217 see if some third context can supply it. */
2218 if (current_function_decl
== NULL_TREE
2219 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2221 if (TREE_VEC_ELT (methods
, 1))
2222 methods
= TREE_VEC_ELT (methods
, 1);
2223 else if (TREE_VEC_ELT (methods
, 0))
2224 methods
= TREE_VEC_ELT (methods
, 0);
2226 methods
= TREE_VEC_ELT (methods
, 2);
2227 methods
= OVL_CURRENT (methods
);
2230 if (DECL_VINDEX (methods
)
2231 && DECL_THIS_INLINE (methods
) == 0
2232 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2234 /* Somebody, somewhere is going to have to define this
2235 virtual function. When they do, they will provide
2236 the debugging info. */
2239 methods
= TREE_CHAIN (methods
);
2242 /* We cannot rely on some alien method to solve our problems,
2243 so we must write out the debug info ourselves. */
2244 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2245 rest_of_type_compilation (t
, toplevel_bindings_p ());
2257 /* Attach to the type of the virtual base class, the pointer to the
2258 virtual base class. */
2261 dfs_find_vbases (binfo
, data
)
2265 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2266 tree binfos
= BINFO_BASETYPES (binfo
);
2267 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2269 for (i
= n_baselinks
-1; i
>= 0; i
--)
2271 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2273 if (TREE_VIA_VIRTUAL (base_binfo
)
2274 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2276 tree vbase
= BINFO_TYPE (base_binfo
);
2277 tree binfo
= binfo_member (vbase
, vi
->vbase_types
);
2279 CLASSTYPE_SEARCH_SLOT (vbase
)
2280 = build (PLUS_EXPR
, build_pointer_type (vbase
),
2281 vi
->decl_ptr
, BINFO_OFFSET (binfo
));
2284 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2285 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2291 dfs_init_vbase_pointers (binfo
, data
)
2295 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2296 tree type
= BINFO_TYPE (binfo
);
2297 tree fields
= TYPE_FIELDS (type
);
2298 tree this_vbase_ptr
;
2300 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2303 /* See finish_struct_1 for when we can enable this. */
2304 /* If we have a vtable pointer first, skip it. */
2305 if (VFIELD_NAME_P (DECL_NAME (fields
)))
2306 fields
= TREE_CHAIN (fields
);
2309 if (BINFO_INHERITANCE_CHAIN (binfo
))
2311 this_vbase_ptr
= TREE_CHAIN (BINFO_INHERITANCE_CHAIN (binfo
));
2312 if (TREE_VIA_VIRTUAL (binfo
))
2313 this_vbase_ptr
= CLASSTYPE_SEARCH_SLOT (type
);
2315 this_vbase_ptr
= convert_pointer_to_single_level (type
,
2317 TREE_CHAIN (binfo
) = this_vbase_ptr
;
2320 this_vbase_ptr
= TREE_CHAIN (binfo
);
2322 if (fields
== NULL_TREE
2323 || DECL_NAME (fields
) == NULL_TREE
2324 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2327 if (build_pointer_type (type
)
2328 != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2329 my_friendly_abort (125);
2331 while (fields
&& DECL_NAME (fields
) && VBASE_NAME_P (DECL_NAME (fields
)))
2333 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2334 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2335 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2336 vi
->inits
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2338 build_modify_expr (ref
, NOP_EXPR
, init
),
2340 fields
= TREE_CHAIN (fields
);
2346 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2347 times, just NEW_VTABLE, but optimizer should make both with equal
2348 efficiency (though it does not currently). */
2351 dfs_clear_vbase_slots (binfo
, data
)
2353 void *data ATTRIBUTE_UNUSED
;
2355 tree type
= BINFO_TYPE (binfo
);
2356 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2357 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2358 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2363 init_vbase_pointers (type
, decl_ptr
)
2367 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2369 struct vbase_info vi
;
2370 int old_flag
= flag_this_is_variable
;
2371 tree binfo
= TYPE_BINFO (type
);
2372 flag_this_is_variable
= -2;
2374 /* Find all the virtual base classes, marking them for later
2376 vi
.decl_ptr
= decl_ptr
;
2377 vi
.vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2378 vi
.inits
= NULL_TREE
;
2380 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
, &vi
);
2382 /* Build up a list of the initializers. */
2383 TREE_CHAIN (binfo
) = decl_ptr
;
2384 dfs_walk_real (binfo
,
2385 dfs_init_vbase_pointers
, 0,
2386 marked_vtable_pathp
,
2389 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
, 0);
2390 flag_this_is_variable
= old_flag
;
2396 /* get the virtual context (the vbase that directly contains the
2397 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2398 or NULL_TREE if there is none.
2400 FNDECL must come from a virtual table from a virtual base to ensure that
2401 there is only one possible DECL_CLASS_CONTEXT.
2403 We know that if there is more than one place (binfo) the fndecl that the
2404 declared, they all refer to the same binfo. See get_class_offset_1 for
2405 the check that ensures this. */
2408 virtual_context (fndecl
, t
, vbase
)
2409 tree fndecl
, t
, vbase
;
2412 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2414 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2415 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2419 /* Not sure if checking path == vbase is necessary here, but just in
2421 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2422 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2423 path
= BINFO_INHERITANCE_CHAIN (path
);
2426 /* This shouldn't happen, I don't want errors! */
2427 warning ("recoverable compiler error, fixups for virtual function");
2432 if (TREE_VIA_VIRTUAL (path
))
2433 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2434 path
= BINFO_INHERITANCE_CHAIN (path
);
2439 /* Fixups upcast offsets for one vtable.
2440 Entries may stay within the VBASE given, or
2441 they may upcast into a direct base, or
2442 they may upcast into a different vbase.
2444 We only need to do fixups in case 2 and 3. In case 2, we add in
2445 the virtual base offset to effect an upcast, in case 3, we add in
2446 the virtual base offset to effect an upcast, then subtract out the
2447 offset for the other virtual base, to effect a downcast into it.
2449 This routine mirrors fixup_vtable_deltas in functionality, though
2450 this one is runtime based, and the other is compile time based.
2451 Conceivably that routine could be removed entirely, and all fixups
2454 VBASE_OFFSETS is an association list of virtual bases that contains
2455 offset information for the virtual bases, so the offsets are only
2456 calculated once. The offsets are computed by where we think the
2457 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2458 the vbase really is. */
2461 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2463 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2465 tree virtuals
= BINFO_VIRTUALS (binfo
);
2468 unsigned HOST_WIDE_INT n
;
2470 delta
= purpose_member (vbase
, *vbase_offsets
);
2473 delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase
));
2474 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2475 delta
= save_expr (delta
);
2476 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2477 *vbase_offsets
= delta
;
2480 n
= skip_rtti_stuff (&virtuals
);
2484 tree current_fndecl
= TREE_VALUE (virtuals
);
2485 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2486 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2488 && current_fndecl
!= abort_fndecl
2489 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2491 /* This may in fact need a runtime fixup. */
2492 tree idx
= build_int_2 (n
, 0);
2493 tree vtbl
= BINFO_VTABLE (binfo
);
2494 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2495 tree aref
, ref
, naref
;
2496 tree old_delta
, new_delta
;
2499 if (nvtbl
== NULL_TREE
2500 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2502 /* Dup it if it isn't in local scope yet. */
2504 (VAR_DECL
, DECL_NAME (vtbl
),
2505 TYPE_MAIN_VARIANT (TREE_TYPE (vtbl
)));
2506 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2507 DECL_ALIGN (nvtbl
));
2508 TREE_READONLY (nvtbl
) = 0;
2509 DECL_ARTIFICIAL (nvtbl
) = 1;
2510 nvtbl
= pushdecl (nvtbl
);
2512 cp_finish_decl (nvtbl
, init
, NULL_TREE
, 0,
2513 LOOKUP_ONLYCONVERTING
);
2515 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2516 because they wouldn't be useful; everything that wants to
2517 look at the vtable will look at the decl for the normal
2518 vtable. Setting DECL_CONTEXT also screws up
2519 decl_function_context. */
2521 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
2523 TREE_SIDE_EFFECTS (init
) = 1;
2524 expand_expr_stmt (init
);
2525 /* Update the vtable pointers as necessary. */
2526 ref
= build_vfield_ref
2527 (build_indirect_ref (addr
, NULL_PTR
),
2528 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))));
2530 (build_modify_expr (ref
, NOP_EXPR
, nvtbl
));
2532 assemble_external (vtbl
);
2533 aref
= build_array_ref (vtbl
, idx
);
2534 naref
= build_array_ref (nvtbl
, idx
);
2535 old_delta
= build_component_ref (aref
, delta_identifier
,
2537 new_delta
= build_component_ref (naref
, delta_identifier
,
2540 /* This is a upcast, so we have to add the offset for the
2542 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
2543 TREE_VALUE (delta
), 0);
2546 /* If this is set, we need to subtract out the delta
2547 adjustments for the other virtual base that we
2549 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
2552 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
2553 vc_delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc
));
2554 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
2556 vc_delta
= save_expr (vc_delta
);
2557 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
2560 vc_delta
= TREE_VALUE (vc_delta
);
2562 /* This is a downcast, so we have to subtract the offset
2563 for the virtual base. */
2564 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
, 0);
2567 TREE_READONLY (new_delta
) = 0;
2568 TREE_TYPE (new_delta
) =
2569 cp_build_qualified_type (TREE_TYPE (new_delta
),
2570 CP_TYPE_QUALS (TREE_TYPE (new_delta
))
2571 & ~TYPE_QUAL_CONST
);
2572 expand_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
2576 virtuals
= TREE_CHAIN (virtuals
);
2580 /* Fixup upcast offsets for all direct vtables. Patterned after
2581 expand_direct_vtbls_init. */
2584 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
2585 tree real_binfo
, binfo
;
2586 int init_self
, can_elide
;
2587 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
2589 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
2590 tree binfos
= BINFO_BASETYPES (binfo
);
2591 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
2593 for (i
= 0; i
< n_baselinks
; i
++)
2595 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
2596 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2597 int is_not_base_vtable
2598 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo
));
2599 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
2600 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
2601 is_not_base_vtable
, can_elide
, addr
,
2602 orig_addr
, type
, vbase
, vbase_offsets
);
2605 /* Before turning this on, make sure it is correct. */
2606 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
2609 /* Should we use something besides CLASSTYPE_VFIELDS? */
2610 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
2612 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
2613 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
2614 type
, vbase_offsets
);
2618 /* Build a COMPOUND_EXPR which when expanded will generate the code
2619 needed to initialize all the virtual function table slots of all
2620 the virtual baseclasses. MAIN_BINFO is the binfo which determines
2621 the virtual baseclasses to use; TYPE is the type of the object to
2622 which the initialization applies. TRUE_EXP is the true object we
2623 are initializing, and DECL_PTR is the pointer to the sub-object we
2626 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
2627 object was laid out by a top-level constructor and the computed
2628 offsets are valid to store vtables. When zero, we must store new
2629 vtables through virtual baseclass pointers. */
2632 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
)
2634 tree true_exp
, decl_ptr
;
2636 tree type
= BINFO_TYPE (binfo
);
2638 /* This function executes during the finish_function() segment,
2639 AFTER the auto variables and temporary stack space has been marked
2640 unused...If space is needed for the virtual function tables,
2641 some of them might fit within what the compiler now thinks
2642 are available stack slots... These values are actually initialized at
2643 the beginnning of the function, so when the automatics use their space,
2644 they will overwrite the values that are placed here. Marking all
2645 temporary space as unavailable prevents this from happening. */
2647 mark_all_temps_used();
2649 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2651 rtx fixup_insns
= NULL_RTX
;
2652 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
2653 struct vbase_info vi
;
2654 vi
.decl_ptr
= (true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0)
2656 vi
.vbase_types
= vbases
;
2658 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
, &vi
);
2660 /* Initialized with vtables of type TYPE. */
2661 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
2665 addr
= convert_pointer_to_vbase (TREE_TYPE (vbases
), vi
.decl_ptr
);
2667 /* Do all vtables from this virtual base. */
2668 /* This assumes that virtual bases can never serve as parent
2669 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
2670 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
2673 /* Now we adjust the offsets for virtual functions that
2674 cross virtual boundaries on an implicit upcast on vf call
2675 so that the layout of the most complete type is used,
2676 instead of assuming the layout of the virtual bases from
2677 our current type. */
2679 if (flag_vtable_thunks
)
2681 /* We don't have dynamic thunks yet!
2682 So for now, just fail silently. */
2686 tree vbase_offsets
= NULL_TREE
;
2687 push_to_sequence (fixup_insns
);
2688 fixup_virtual_upcast_offsets (vbases
,
2689 TYPE_BINFO (BINFO_TYPE (vbases
)),
2690 1, 0, addr
, vi
.decl_ptr
,
2691 type
, vbases
, &vbase_offsets
);
2692 fixup_insns
= get_insns ();
2699 extern tree in_charge_identifier
;
2700 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
2701 if (! in_charge_node
)
2703 warning ("recoverable internal compiler error, nobody's in charge!");
2704 in_charge_node
= integer_zero_node
;
2706 in_charge_node
= build_binary_op (EQ_EXPR
, in_charge_node
, integer_zero_node
, 1);
2707 expand_start_cond (in_charge_node
, 0);
2708 emit_insns (fixup_insns
);
2712 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
, 0);
2716 /* get virtual base class types.
2717 This adds type to the vbase_types list in reverse dfs order.
2718 Ordering is very important, so don't change it. */
2721 dfs_get_vbase_types (binfo
, data
)
2725 tree
*vbase_types
= (tree
*) data
;
2727 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
2729 tree new_vbase
= make_binfo (integer_zero_node
, binfo
,
2730 BINFO_VTABLE (binfo
),
2731 BINFO_VIRTUALS (binfo
));
2732 TREE_CHAIN (new_vbase
) = *vbase_types
;
2733 TREE_VIA_VIRTUAL (new_vbase
) = 1;
2734 *vbase_types
= new_vbase
;
2735 SET_BINFO_VBASE_MARKED (binfo
);
2737 SET_BINFO_MARKED (binfo
);
2741 /* Return a list of binfos for the virtual base classes for TYPE, in
2742 depth-first search order. The list is freshly allocated, so
2743 no modification is made to the current binfo hierarchy. */
2746 get_vbase_types (type
)
2753 binfo
= TYPE_BINFO (type
);
2754 vbase_types
= NULL_TREE
;
2755 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
, &vbase_types
);
2756 dfs_walk (binfo
, dfs_unmark
, markedp
, 0);
2757 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2758 reverse it so that we get normal dfs ordering. */
2759 vbase_types
= nreverse (vbase_types
);
2761 /* unmark marked vbases */
2762 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
2763 CLEAR_BINFO_VBASE_MARKED (vbases
);
2768 /* If we want debug info for a type TYPE, make sure all its base types
2769 are also marked as being potentially interesting. This avoids
2770 the problem of not writing any debug info for intermediate basetypes
2771 that have abstract virtual functions. Also mark member types. */
2774 note_debug_info_needed (type
)
2779 if (current_template_parms
)
2782 if (TYPE_BEING_DEFINED (type
))
2783 /* We can't go looking for the base types and fields just yet. */
2786 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2787 does not support name references between translation units. Well, we
2788 could, but that would mean putting global labels in the debug output
2789 before each exported type and each of its functions and static data
2791 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2794 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
, 0);
2795 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2798 if (TREE_CODE (field
) == FIELD_DECL
2799 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
2800 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
), 0))
2801 note_debug_info_needed (ttype
);
2805 /* Subroutines of push_class_decls (). */
2807 /* Add in a decl to the envelope. */
2809 envelope_add_decl (type
, decl
, values
)
2810 tree type
, decl
, *values
;
2813 tree name
= DECL_NAME (decl
);
2816 /* Yet Another Implicit Typename Kludge: Since we don't tsubst
2817 the members for partial instantiations, DECL_CONTEXT (decl) is wrong.
2818 But pretend it's right for this function. */
2819 if (processing_template_decl
)
2820 type
= DECL_REAL_CONTEXT (decl
);
2822 /* virtual base names are always unique. */
2823 if (VBASE_NAME_P (name
))
2824 *values
= NULL_TREE
;
2826 /* Possible ambiguity. If its defining type(s)
2827 is (are all) derived from us, no problem. */
2828 else if (*values
&& TREE_CODE (*values
) != TREE_LIST
)
2830 tree value
= *values
;
2831 /* Only complain if we shadow something we can access. */
2832 if (warn_shadow
&& TREE_CODE (decl
) == FUNCTION_DECL
2833 && ((DECL_LANG_SPECIFIC (*values
)
2834 && DECL_CLASS_CONTEXT (value
) == current_class_type
)
2835 || ! TREE_PRIVATE (value
)))
2836 /* Should figure out access control more accurately. */
2838 cp_warning_at ("member `%#D' is shadowed", value
);
2839 cp_warning_at ("by member function `%#D'", decl
);
2840 warning ("in this context");
2843 context
= DECL_REAL_CONTEXT (value
);
2845 if (context
== type
)
2847 if (TREE_CODE (value
) == TYPE_DECL
2848 && DECL_ARTIFICIAL (value
))
2849 *values
= NULL_TREE
;
2853 else if (type
== current_class_type
2854 || DERIVED_FROM_P (context
, type
))
2856 /* Don't add in *values to list */
2857 *values
= NULL_TREE
;
2860 *values
= build_tree_list (NULL_TREE
, value
);
2863 for (tmp
= values
; *tmp
;)
2865 tree value
= TREE_VALUE (*tmp
);
2866 my_friendly_assert (TREE_CODE (value
) != TREE_LIST
, 999);
2867 context
= (TREE_CODE (value
) == FUNCTION_DECL
2868 && DECL_VIRTUAL_P (value
))
2869 ? DECL_CLASS_CONTEXT (value
)
2870 : DECL_CONTEXT (value
);
2872 if (type
== current_class_type
2873 || DERIVED_FROM_P (context
, type
))
2875 /* remove *tmp from list */
2876 *tmp
= TREE_CHAIN (*tmp
);
2879 tmp
= &TREE_CHAIN (*tmp
);
2884 /* Put the new contents in our envelope. */
2885 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2887 *values
= tree_cons (name
, decl
, *values
);
2888 TREE_NONLOCAL_FLAG (*values
) = 1;
2889 TREE_TYPE (*values
) = unknown_type_node
;
2895 *values
= tree_cons (NULL_TREE
, decl
, *values
);
2896 /* Mark this as a potentially ambiguous member. */
2897 /* Leaving TREE_TYPE blank is intentional.
2898 We cannot use `error_mark_node' (lookup_name)
2899 or `unknown_type_node' (all member functions use this). */
2900 TREE_NONLOCAL_FLAG (*values
) = 1;
2908 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2909 because it (or one of the intermediate bases) depends on template parms. */
2912 dependent_base_p (binfo
)
2915 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2917 if (currently_open_class (TREE_TYPE (binfo
)))
2919 if (uses_template_parms (TREE_TYPE (binfo
)))
2925 /* Add the instance variables which this class contributed to the
2926 current class binding contour. When a redefinition occurs, if the
2927 redefinition is strictly within a single inheritance path, we just
2928 overwrite the old declaration with the new. If the fields are not
2929 within a single inheritance path, we must cons them.
2931 In order to know what decls are new (stemming from the current
2932 invocation of push_class_decls) we enclose them in an "envelope",
2933 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
2934 new decl (or possibly a list of competing ones), the TREE_VALUE slot
2935 points to the old value and the TREE_CHAIN slot chains together all
2936 envelopes which needs to be "opened" in push_class_decls. Opening an
2937 envelope means: push the old value onto the class_shadowed list,
2938 install the new one and if it's a TYPE_DECL do the same to the
2939 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
2940 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
2941 Because if it is, it could be a set of overloaded methods from an
2945 dfs_pushdecls (binfo
, data
)
2949 tree
*closed_envelopes
= (tree
*) data
;
2950 tree type
= BINFO_TYPE (binfo
);
2955 /* Only record types if we're a template base. */
2956 if (processing_template_decl
&& type
!= current_class_type
2957 && dependent_base_p (binfo
))
2960 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2962 if (dummy
&& TREE_CODE (fields
) != TYPE_DECL
)
2965 /* Unmark so that if we are in a constructor, and then find that
2966 this field was initialized by a base initializer,
2967 we can emit an error message. */
2968 if (TREE_CODE (fields
) == FIELD_DECL
)
2969 TREE_USED (fields
) = 0;
2971 /* Recurse into anonymous unions. */
2972 if (DECL_NAME (fields
) == NULL_TREE
2973 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
2975 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields
)), data
);
2979 if (DECL_NAME (fields
))
2981 tree name
= DECL_NAME (fields
);
2982 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
2984 /* If the class value is not an envelope of the kind described in
2985 the comment above, we create a new envelope. */
2986 maybe_push_cache_obstack ();
2987 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
2988 || TREE_PURPOSE (class_value
) == NULL_TREE
2989 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
2991 /* See comment above for a description of envelopes. */
2992 *closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
2994 IDENTIFIER_CLASS_VALUE (name
) = *closed_envelopes
;
2995 class_value
= IDENTIFIER_CLASS_VALUE (name
);
2998 envelope_add_decl (type
, fields
, &TREE_PURPOSE (class_value
));
3003 method_vec
= CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
3004 if (method_vec
&& ! dummy
)
3009 /* Farm out constructors and destructors. */
3010 end
= TREE_VEC_END (method_vec
);
3012 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3013 *methods
&& methods
!= end
;
3016 /* This will cause lookup_name to return a pointer
3017 to the tree_list of possible methods of this name. */
3022 name
= DECL_NAME (OVL_CURRENT (*methods
));
3023 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3025 maybe_push_cache_obstack ();
3027 /* If the class value is not an envelope of the kind described in
3028 the comment above, we create a new envelope. */
3029 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3030 || TREE_PURPOSE (class_value
) == NULL_TREE
3031 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3033 /* See comment above for a description of envelopes. */
3034 *closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3036 IDENTIFIER_CLASS_VALUE (name
) = *closed_envelopes
;
3037 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3040 /* Here we try to rule out possible ambiguities.
3041 If we can't do that, keep a TREE_LIST with possibly ambiguous
3043 /* Arbitrarily choose the first function in the list. This is OK
3044 because this is only used for initial lookup; anything that
3045 actually uses the function will look it up again. */
3046 envelope_add_decl (type
, OVL_CURRENT (*methods
),
3047 &TREE_PURPOSE (class_value
));
3052 /* We can't just use BINFO_MARKED because envelope_add_decl uses
3053 DERIVED_FROM_P, which calls get_base_distance. */
3054 SET_BINFO_PUSHDECLS_MARKED (binfo
);
3059 /* Consolidate unique (by name) member functions. */
3062 dfs_compress_decls (binfo
, data
)
3064 void *data ATTRIBUTE_UNUSED
;
3066 tree type
= BINFO_TYPE (binfo
);
3068 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
3070 if (processing_template_decl
&& type
!= current_class_type
3071 && dependent_base_p (binfo
))
3072 /* We only record types if we're a template base. */;
3073 else if (method_vec
!= 0)
3075 /* Farm out constructors and destructors. */
3077 tree
*end
= TREE_VEC_END (method_vec
);
3079 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3080 methods
!= end
&& *methods
; methods
++)
3082 /* This is known to be an envelope of the kind described before
3085 IDENTIFIER_CLASS_VALUE (DECL_NAME (OVL_CURRENT (*methods
)));
3086 tree tmp
= TREE_PURPOSE (class_value
);
3088 /* This was replaced in scope by somebody else. Just leave it
3090 if (TREE_CODE (tmp
) != TREE_LIST
)
3093 if (TREE_CHAIN (tmp
) == NULL_TREE
3095 && OVL_NEXT (TREE_VALUE (tmp
)) == NULL_TREE
)
3097 TREE_PURPOSE (class_value
) = TREE_VALUE (tmp
);
3101 CLEAR_BINFO_PUSHDECLS_MARKED (binfo
);
3106 /* When entering the scope of a class, we cache all of the
3107 fields that that class provides within its inheritance
3108 lattice. Where ambiguities result, we mark them
3109 with `error_mark_node' so that if they are encountered
3110 without explicit qualification, we can emit an error
3114 push_class_decls (type
)
3117 struct obstack
*ambient_obstack
= current_obstack
;
3118 tree closed_envelopes
= NULL_TREE
;
3119 search_stack
= push_search_level (search_stack
, &search_obstack
);
3121 /* Build up all the relevant bindings and such on the cache
3122 obstack. That way no memory is wasted when we throw away the
3124 maybe_push_cache_obstack ();
3126 /* Push class fields into CLASS_VALUE scope, and mark. */
3127 dfs_walk (TYPE_BINFO (type
), dfs_pushdecls
, unmarked_pushdecls_p
,
3130 /* Compress fields which have only a single entry
3131 by a given name, and unmark. */
3132 dfs_walk (TYPE_BINFO (type
), dfs_compress_decls
, marked_pushdecls_p
,
3135 /* Open up all the closed envelopes and push the contained decls into
3137 while (closed_envelopes
)
3139 tree
new = TREE_PURPOSE (closed_envelopes
);
3142 /* This is messy because the class value may be a *_DECL, or a
3143 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3144 *_DECLs. The name is stored at different places in these three
3146 if (TREE_CODE (new) == TREE_LIST
)
3148 if (TREE_PURPOSE (new) != NULL_TREE
)
3149 id
= TREE_PURPOSE (new);
3152 tree node
= TREE_VALUE (new);
3154 if (TREE_CODE (node
) == TYPE_DECL
3155 && DECL_ARTIFICIAL (node
)
3156 && IS_AGGR_TYPE (TREE_TYPE (node
))
3157 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (node
)))
3159 tree t
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (node
));
3162 for (; n
; n
= TREE_CHAIN (n
))
3164 tree d
= TREE_VALUE (n
);
3165 if (TREE_CODE (d
) == TYPE_DECL
3166 && DECL_ARTIFICIAL (node
)
3167 && IS_AGGR_TYPE (TREE_TYPE (d
))
3168 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (d
))
3169 && CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d
)) == t
)
3178 else while (TREE_CODE (node
) == TREE_LIST
)
3179 node
= TREE_VALUE (node
);
3180 id
= DECL_NAME (node
);
3184 id
= DECL_NAME (new);
3186 /* Install the original class value in order to make
3187 pushdecl_class_level work correctly. */
3188 IDENTIFIER_CLASS_VALUE (id
) = TREE_VALUE (closed_envelopes
);
3189 if (TREE_CODE (new) == TREE_LIST
)
3190 push_class_level_binding (id
, new);
3192 pushdecl_class_level (new);
3193 closed_envelopes
= TREE_CHAIN (closed_envelopes
);
3196 /* Undo the call to maybe_push_cache_obstack above. */
3199 current_obstack
= ambient_obstack
;
3202 /* Here's a subroutine we need because C lacks lambdas. */
3205 dfs_unuse_fields (binfo
, data
)
3207 void *data ATTRIBUTE_UNUSED
;
3209 tree type
= TREE_TYPE (binfo
);
3212 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3214 if (TREE_CODE (fields
) != FIELD_DECL
)
3217 TREE_USED (fields
) = 0;
3218 if (DECL_NAME (fields
) == NULL_TREE
3219 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3220 unuse_fields (TREE_TYPE (fields
));
3230 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
, 0);
3236 /* We haven't pushed a search level when dealing with cached classes,
3237 so we'd better not try to pop it. */
3239 search_stack
= pop_search_level (search_stack
);
3243 print_search_statistics ()
3245 #ifdef GATHER_STATISTICS
3246 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3247 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3248 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3249 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3250 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3251 #else /* GATHER_STATISTICS */
3252 fprintf (stderr
, "no search statistics\n");
3253 #endif /* GATHER_STATISTICS */
3257 init_search_processing ()
3259 gcc_obstack_init (&search_obstack
);
3260 _vptr_name
= get_identifier ("_vptr");
3264 reinit_search_statistics ()
3266 #ifdef GATHER_STATISTICS
3267 n_fields_searched
= 0;
3268 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3269 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3270 n_calls_get_base_type
= 0;
3271 n_outer_fields_searched
= 0;
3272 n_contexts_saved
= 0;
3273 #endif /* GATHER_STATISTICS */
3276 #define scratch_tree_cons expr_tree_cons
3279 add_conversions (binfo
, data
)
3284 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3285 tree
*conversions
= (tree
*) data
;
3287 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3289 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3292 if (!tmp
|| ! DECL_CONV_FN_P (OVL_CURRENT (tmp
)))
3295 name
= DECL_NAME (OVL_CURRENT (tmp
));
3297 /* Make sure we don't already have this conversion. */
3298 if (! IDENTIFIER_MARKED (name
))
3300 *conversions
= scratch_tree_cons (binfo
, tmp
, *conversions
);
3301 IDENTIFIER_MARKED (name
) = 1;
3308 lookup_conversions (type
)
3312 tree conversions
= NULL_TREE
;
3314 if (TYPE_SIZE (type
))
3315 bfs_walk (TYPE_BINFO (type
), add_conversions
, 0, &conversions
);
3317 for (t
= conversions
; t
; t
= TREE_CHAIN (t
))
3318 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t
)))) = 0;
3329 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3330 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3333 dfs_check_overlap (empty_binfo
, data
)
3337 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3339 for (binfo
= TYPE_BINFO (oi
->compare_type
);
3341 binfo
= BINFO_BASETYPE (binfo
, 0))
3343 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3345 oi
->found_overlap
= 1;
3348 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3355 /* Trivial function to stop base traversal when we find something. */
3358 dfs_no_overlap_yet (binfo
, data
)
3362 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3363 return !oi
->found_overlap
? binfo
: NULL_TREE
;
3366 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3367 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3370 types_overlap_p (empty_type
, next_type
)
3371 tree empty_type
, next_type
;
3373 struct overlap_info oi
;
3375 if (! IS_AGGR_TYPE (next_type
))
3377 oi
.compare_type
= next_type
;
3378 oi
.found_overlap
= 0;
3379 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
,
3380 dfs_no_overlap_yet
, &oi
);
3381 return oi
.found_overlap
;
3390 dfs_bfv_queue_p (binfo
, data
)
3394 struct bfv_info
*bfvi
= (struct bfv_info
*) data
;
3396 /* Use the real virtual base class objects, not the placeholders in
3397 the usual hierarchy. */
3398 if (TREE_VIA_VIRTUAL (binfo
))
3399 return binfo_member (BINFO_TYPE (binfo
), bfvi
->vbases
);
3404 /* Passed to dfs_walk_real by binfo_for_vtable; determine if bvtable
3405 comes from BINFO. */
3408 dfs_bfv_helper (binfo
, data
)
3412 struct bfv_info
*bfvi
= (struct bfv_info
*) data
;
3414 if (BINFO_VTABLE (binfo
) == bfvi
->var
)
3419 /* Given a vtable VAR, determine which binfo it comes from. */
3422 binfo_for_vtable (var
)
3426 struct bfv_info bfvi
;
3428 type
= DECL_CONTEXT (var
);
3429 bfvi
.vbases
= CLASSTYPE_VBASECLASSES (type
);
3430 return dfs_walk_real (TYPE_BINFO (type
),
3431 0, dfs_bfv_helper
, dfs_bfv_queue_p
, &bfvi
);