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 next_baselink
PROTO((tree
));
82 static tree get_vbase_1
PROTO((tree
, tree
, unsigned int *));
83 static tree convert_pointer_to_vbase
PROTO((tree
, tree
));
84 static tree lookup_field_1
PROTO((tree
, tree
));
85 static tree convert_pointer_to_single_level
PROTO((tree
, tree
));
86 static int lookup_fnfields_here
PROTO((tree
, tree
));
87 static int is_subobject_of_p
PROTO((tree
, tree
));
88 static int hides
PROTO((tree
, tree
));
89 static tree virtual_context
PROTO((tree
, tree
, tree
));
90 static tree dfs_check_overlap
PROTO((tree
, void *));
91 static tree dfs_no_overlap_yet
PROTO((tree
, void *));
92 static void envelope_add_decl
PROTO((tree
, tree
, tree
*));
93 static int get_base_distance_recursive
94 PROTO((tree
, int, int, int, int *, tree
*, tree
,
95 int, int *, int, int));
96 static void expand_upcast_fixups
97 PROTO((tree
, tree
, tree
, tree
, tree
, tree
, tree
*));
98 static void fixup_virtual_upcast_offsets
99 PROTO((tree
, tree
, int, int, tree
, tree
, tree
, tree
,
101 static tree unmarkedp
PROTO((tree
, void *));
102 static tree marked_vtable_pathp
PROTO((tree
, void *));
103 static tree unmarked_vtable_pathp
PROTO((tree
, void *));
104 static tree marked_new_vtablep
PROTO((tree
, void *));
105 static tree unmarked_new_vtablep
PROTO((tree
, void *));
106 static tree marked_pushdecls_p
PROTO((tree
, void *));
107 static tree unmarked_pushdecls_p
PROTO((tree
, void *));
108 static tree dfs_debug_unmarkedp
PROTO((tree
, void *));
109 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_pushdecls
PROTO((tree
, void *));
115 static tree dfs_compress_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 struct search_level
*push_search_level
123 PROTO((struct stack_level
*, struct obstack
*));
124 static struct search_level
*pop_search_level
125 PROTO((struct stack_level
*));
127 PROTO((tree
, tree (*) (tree
, void *), tree (*) (tree
, void *),
129 static tree lookup_field_queue_p
PROTO((tree
, void *));
130 static tree lookup_field_r
PROTO((tree
, void *));
131 static tree dfs_walk_real
PROTO ((tree
,
132 tree (*) (tree
, void *),
133 tree (*) (tree
, void *),
134 tree (*) (tree
, void *),
136 static tree dfs_bfv_queue_p
PROTO ((tree
, void *));
137 static tree dfs_bfv_helper
PROTO ((tree
, void *));
138 static tree get_virtuals_named_this_r
PROTO ((tree
, void *));
139 static tree context_for_name_lookup
PROTO ((tree
));
140 static tree canonical_binfo
PROTO ((tree
));
141 static tree shared_marked_p
PROTO ((tree
, void *));
142 static tree shared_unmarked_p
PROTO ((tree
, void *));
143 static int dependent_base_p
PROTO ((tree
));
144 static tree dfs_accessible_queue_p
PROTO ((tree
, void *));
145 static tree dfs_accessible_p
PROTO ((tree
, void *));
146 static tree dfs_access_in_type
PROTO ((tree
, void *));
147 static tree access_in_type
PROTO ((tree
, tree
));
148 static tree dfs_canonical_queue
PROTO ((tree
, void *));
149 static tree dfs_assert_unmarked_p
PROTO ((tree
, void *));
150 static void assert_canonical_unmarked
PROTO ((tree
));
151 static int protected_accessible_p
PROTO ((tree
, tree
, tree
, tree
));
152 static int friend_accessible_p
PROTO ((tree
, tree
, tree
, tree
));
154 /* Allocate a level of searching. */
156 static struct search_level
*
157 push_search_level (stack
, obstack
)
158 struct stack_level
*stack
;
159 struct obstack
*obstack
;
161 struct search_level tem
;
164 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
167 /* Discard a level of search allocation. */
169 static struct search_level
*
170 pop_search_level (obstack
)
171 struct stack_level
*obstack
;
173 register struct search_level
*stack
= pop_stack_level (obstack
);
178 static tree _vptr_name
;
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 /* Search for a member with name NAME in a multiple inheritance lattice
502 specified by TYPE. If it does not exist, return NULL_TREE.
503 If the member is ambiguously referenced, return `error_mark_node'.
504 Otherwise, return the FIELD_DECL. */
506 /* Do a 1-level search for NAME as a member of TYPE. The caller must
507 figure out whether it can access this field. (Since it is only one
508 level, this is reasonable.) */
511 lookup_field_1 (type
, name
)
516 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
517 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
518 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
519 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
520 the code often worked even when we treated the index as a list
524 field
= TYPE_FIELDS (type
);
526 #ifdef GATHER_STATISTICS
527 n_calls_lookup_field_1
++;
528 #endif /* GATHER_STATISTICS */
531 #ifdef GATHER_STATISTICS
533 #endif /* GATHER_STATISTICS */
534 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
535 if (DECL_NAME (field
) == NULL_TREE
536 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
538 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
542 if (TREE_CODE (field
) == USING_DECL
)
543 /* For now, we're just treating member using declarations as
544 old ARM-style access declarations. Thus, there's no reason
545 to return a USING_DECL, and the rest of the compiler can't
546 handle it. Once the class is defined, these are purged
547 from TYPE_FIELDS anyhow; see handle_using_decl. */
549 else if (DECL_NAME (field
) == name
)
551 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
552 && DECL_ASSEMBLER_NAME (field
) != NULL
)
553 GNU_xref_ref(current_function_decl
,
554 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
557 field
= TREE_CHAIN (field
);
560 if (name
== _vptr_name
)
562 /* Give the user what s/he thinks s/he wants. */
563 if (TYPE_VIRTUAL_P (type
))
564 return CLASSTYPE_VFIELD (type
);
569 /* There are a number of cases we need to be aware of here:
570 current_class_type current_function_decl
577 Those last two make life interesting. If we're in a function which is
578 itself inside a class, we need decls to go into the fn's decls (our
579 second case below). But if we're in a class and the class itself is
580 inside a function, we need decls to go into the decls for the class. To
581 achieve this last goal, we must see if, when both current_class_ptr and
582 current_function_decl are set, the class was declared inside that
583 function. If so, we know to put the decls into the class's scope. */
588 if (current_function_decl
== NULL_TREE
)
589 return current_class_type
;
590 if (current_class_type
== NULL_TREE
)
591 return current_function_decl
;
592 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
593 return current_function_decl
;
595 return current_class_type
;
598 /* Return the scope of DECL, as appropriate when doing name-lookup. */
601 context_for_name_lookup (decl
)
606 For the purposes of name lookup, after the anonymous union
607 definition, the members of the anonymous union are considered to
608 have been defined in the scope in which teh anonymous union is
610 tree context
= DECL_REAL_CONTEXT (decl
);
612 while (TYPE_P (context
) && ANON_UNION_TYPE_P (context
))
613 context
= TYPE_CONTEXT (context
);
615 context
= global_namespace
;
620 /* Return a canonical BINFO if BINFO is a virtual base, or just BINFO
624 canonical_binfo (binfo
)
627 return (TREE_VIA_VIRTUAL (binfo
)
628 ? TYPE_BINFO (BINFO_TYPE (binfo
)) : binfo
);
631 /* A queue function that simply ensures that we walk into the
632 canonical versions of virtual bases. */
635 dfs_canonical_queue (binfo
, data
)
637 void *data ATTRIBUTE_UNUSED
;
639 return canonical_binfo (binfo
);
642 /* Called via dfs_walk from assert_canonical_unmarked. */
645 dfs_assert_unmarked_p (binfo
, data
)
647 void *data ATTRIBUTE_UNUSED
;
649 my_friendly_assert (!BINFO_MARKED (binfo
), 0);
653 /* Asserts that all the nodes below BINFO (using the canonical
654 versions of virtual bases) are unmarked. */
657 assert_canonical_unmarked (binfo
)
660 dfs_walk (binfo
, dfs_assert_unmarked_p
, dfs_canonical_queue
, 0);
663 /* If BINFO is marked, return a canonical version of BINFO.
664 Otherwise, return NULL_TREE. */
667 shared_marked_p (binfo
, data
)
671 binfo
= canonical_binfo (binfo
);
672 return markedp (binfo
, data
) ? binfo
: NULL_TREE
;
675 /* If BINFO is not marked, return a canonical version of BINFO.
676 Otherwise, return NULL_TREE. */
679 shared_unmarked_p (binfo
, data
)
683 binfo
= canonical_binfo (binfo
);
684 return unmarkedp (binfo
, data
) ? binfo
: NULL_TREE
;
687 /* Called from access_in_type via dfs_walk. Calculate the access to
688 DATA (which is really a DECL) in BINFO. */
691 dfs_access_in_type (binfo
, data
)
695 tree decl
= (tree
) data
;
696 tree type
= BINFO_TYPE (binfo
);
697 tree access
= NULL_TREE
;
699 if (context_for_name_lookup (decl
) == type
)
701 /* If we have desceneded to the scope of DECL, just note the
702 appropriate access. */
703 if (TREE_PRIVATE (decl
))
704 access
= access_private_node
;
705 else if (TREE_PROTECTED (decl
))
706 access
= access_protected_node
;
708 access
= access_public_node
;
712 /* First, check for an access-declaration that gives us more
713 access to the DECL. The CONST_DECL for an enumeration
714 constant will not have DECL_LANG_SPECIFIC, and thus no
716 if (DECL_LANG_SPECIFIC (decl
))
718 access
= purpose_member (type
, DECL_ACCESS (decl
));
720 access
= TREE_VALUE (access
);
729 /* Otherwise, scan our baseclasses, and pick the most favorable
731 binfos
= BINFO_BASETYPES (binfo
);
732 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
733 for (i
= 0; i
< n_baselinks
; ++i
)
735 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
736 tree base_access
= TREE_CHAIN (canonical_binfo (base_binfo
));
738 if (!base_access
|| base_access
== access_private_node
)
739 /* If it was not accessible in the base, or only
740 accessible as a private member, we can't access it
742 base_access
= NULL_TREE
;
743 else if (TREE_VIA_PROTECTED (base_binfo
))
744 /* Public and protected members in the base are
746 base_access
= access_protected_node
;
747 else if (!TREE_VIA_PUBLIC (base_binfo
))
748 /* Public and protected members in the base are
750 base_access
= access_private_node
;
752 /* See if the new access, via this base, gives more
753 access than our previous best access. */
755 (base_access
== access_public_node
756 || (base_access
== access_protected_node
757 && access
!= access_public_node
)
758 || (base_access
== access_private_node
761 access
= base_access
;
763 /* If the new access is public, we can't do better. */
764 if (access
== access_public_node
)
771 /* Note the access to DECL in TYPE. */
772 TREE_CHAIN (binfo
) = access
;
774 /* Mark TYPE as visited so that if we reach it again we do not
775 duplicate our efforts here. */
776 SET_BINFO_MARKED (binfo
);
781 /* Return the access to DECL in TYPE. */
784 access_in_type (type
, decl
)
788 tree binfo
= TYPE_BINFO (type
);
790 /* We must take into account
794 If a name can be reached by several paths through a multiple
795 inheritance graph, the access is that of the path that gives
798 The algorithm we use is to make a post-order depth-first traversal
799 of the base-class hierarchy. As we come up the tree, we annotate
800 each node with the most lenient access. */
801 dfs_walk_real (binfo
, 0, dfs_access_in_type
, shared_unmarked_p
, decl
);
802 dfs_walk (binfo
, dfs_unmark
, shared_marked_p
, 0);
803 assert_canonical_unmarked (binfo
);
805 return TREE_CHAIN (binfo
);
808 /* Called from dfs_accessible_p via dfs_walk. */
811 dfs_accessible_queue_p (binfo
, data
)
813 void *data ATTRIBUTE_UNUSED
;
815 if (BINFO_MARKED (binfo
))
818 /* If this class is inherited via private or protected inheritance,
819 then we can't see it, unless we are a friend of the subclass. */
820 if (!TREE_VIA_PUBLIC (binfo
)
821 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
)),
825 return canonical_binfo (binfo
);
828 /* Called from dfs_accessible_p via dfs_walk. */
831 dfs_accessible_p (binfo
, data
)
835 int protected_ok
= data
!= 0;
838 /* We marked the binfos while computing the access in each type.
839 So, we unmark as we go now. */
840 SET_BINFO_MARKED (binfo
);
842 access
= TREE_CHAIN (binfo
);
843 if (access
== access_public_node
844 || (access
== access_protected_node
&& protected_ok
))
846 else if (access
&& is_friend (BINFO_TYPE (binfo
), current_scope ()))
852 /* Returns non-zero if it is OK to access DECL when named in TYPE
853 through an object indiated by BINFO in the context of DERIVED. */
856 protected_accessible_p (type
, decl
, derived
, binfo
)
864 /* We're checking this clause from [class.access.base]
866 m as a member of N is protected, and the reference occurs in a
867 member or friend of class N, or in a member or friend of a
868 class P derived from N, where m as a member of P is private or
871 If DERIVED isn't derived from TYPE, then it certainly does not
873 if (!DERIVED_FROM_P (type
, derived
))
876 access
= access_in_type (derived
, decl
);
877 if (same_type_p (derived
, type
))
879 if (access
!= access_private_node
)
882 else if (access
!= access_private_node
883 && access
!= access_protected_node
)
888 When a friend or a member function of a derived class references
889 a protected nonstatic member of a base class, an access check
890 applies in addition to those described earlier in clause
891 _class.access_.4) Except when forming a pointer to member
892 (_expr.unary.op_), the access must be through a pointer to,
893 reference to, or object of the derived class itself (or any class
894 derived from that class) (_expr.ref_). If the access is to form
895 a pointer to member, the nested-name-specifier shall name the
896 derived class (or any class derived from that class). */
897 if (DECL_NONSTATIC_MEMBER_P (decl
))
899 /* We can tell through what the reference is occurring by
900 chasing BINFO up to the root. */
902 while (BINFO_INHERITANCE_CHAIN (t
))
903 t
= BINFO_INHERITANCE_CHAIN (t
);
905 if (!DERIVED_FROM_P (derived
, BINFO_TYPE (t
)))
912 /* Returns non-zero if SCOPE is a friend of a type which would be able
913 to acces DECL, named in TYPE, through the object indicated by
917 friend_accessible_p (scope
, type
, decl
, binfo
)
923 tree befriending_classes
;
929 if (TREE_CODE (scope
) == FUNCTION_DECL
930 || DECL_FUNCTION_TEMPLATE_P (scope
))
931 befriending_classes
= DECL_BEFRIENDING_CLASSES (scope
);
932 else if (TYPE_P (scope
))
933 befriending_classes
= CLASSTYPE_BEFRIENDING_CLASSES (scope
);
937 for (t
= befriending_classes
; t
; t
= TREE_CHAIN (t
))
938 if (protected_accessible_p (type
, decl
, TREE_VALUE (t
), binfo
))
941 if (TREE_CODE (scope
) == FUNCTION_DECL
942 || DECL_FUNCTION_TEMPLATE_P (scope
))
944 /* Perhaps this SCOPE is a member of a class which is a
946 if (friend_accessible_p (DECL_CLASS_CONTEXT (scope
), type
,
950 /* Or an instantiation of something which is a friend. */
951 if (DECL_TEMPLATE_INFO (scope
))
952 return friend_accessible_p (DECL_TI_TEMPLATE (scope
),
955 else if (CLASSTYPE_TEMPLATE_INFO (scope
))
956 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope
),
962 /* DECL is a declaration from a base class of TYPE, which was the
963 classs used to name DECL. Return non-zero if, in the current
964 context, DECL is accessible. If TYPE is actually a BINFO node,
965 then we can tell in what context the access is occurring by looking
966 at the most derived class along the path indicated by BINFO. */
969 accessible_p (type
, decl
)
977 /* Non-zero if it's OK to access DECL if it has protected
978 accessibility in TYPE. */
979 int protected_ok
= 0;
981 /* If we're not checking access, everything is accessible. */
982 if (!flag_access_control
)
985 /* If this declaration is in a block or namespace scope, there's no
987 if (!TYPE_P (context_for_name_lookup (decl
)))
990 /* We don't do access control for types yet. */
991 if (TREE_CODE (decl
) == TYPE_DECL
)
997 type
= BINFO_TYPE (type
);
1000 binfo
= TYPE_BINFO (type
);
1002 /* [class.access.base]
1004 A member m is accessible when named in class N if
1006 --m as a member of N is public, or
1008 --m as a member of N is private, and the reference occurs in a
1009 member or friend of class N, or
1011 --m as a member of N is protected, and the reference occurs in a
1012 member or friend of class N, or in a member or friend of a
1013 class P derived from N, where m as a member of P is private or
1016 --there exists a base class B of N that is accessible at the point
1017 of reference, and m is accessible when named in class B.
1019 We walk the base class hierarchy, checking these conditions. */
1021 /* Figure out where the reference is occurring. Check to see if
1022 DECL is private or protected in this scope, since that will
1023 determine whether protected access in TYPE allowed. */
1024 if (current_class_type
)
1026 = protected_accessible_p (type
, decl
, current_class_type
,
1029 /* Now, loop through the classes of which we are a friend. */
1031 protected_ok
= friend_accessible_p (current_scope (),
1034 /* Standardize on the same that will access_in_type will use. We
1035 don't need to know what path was chosen from this point onwards. */
1036 binfo
= TYPE_BINFO (type
);
1038 /* Compute the accessibility of DECL in the class hierarchy
1039 dominated by type. */
1040 access_in_type (type
, decl
);
1041 /* Walk the hierarchy again, looking for a base class that allows
1043 t
= dfs_walk (binfo
, dfs_accessible_p
,
1044 dfs_accessible_queue_p
,
1045 protected_ok
? &protected_ok
: 0);
1046 /* Clear any mark bits. Note that we have to walk the whole tree
1047 here, since we have aborted the previous walk from some point
1048 deep in the tree. */
1049 dfs_walk (binfo
, dfs_unmark
, dfs_canonical_queue
, 0);
1050 assert_canonical_unmarked (binfo
);
1052 return t
!= NULL_TREE
;
1055 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1056 found as a base class and sub-object of the object denoted by
1057 BINFO. This routine relies upon binfos not being shared, except
1058 for binfos for virtual bases. */
1061 is_subobject_of_p (parent
, binfo
)
1064 tree binfos
= BINFO_BASETYPES (binfo
);
1065 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1067 if (TREE_VIA_VIRTUAL (parent
))
1068 parent
= TYPE_BINFO (TREE_TYPE (parent
));
1069 if (TREE_VIA_VIRTUAL (binfo
))
1070 binfo
= TYPE_BINFO (TREE_TYPE (binfo
));
1072 if (parent
== binfo
)
1075 /* Process and/or queue base types. */
1076 for (i
= 0; i
< n_baselinks
; i
++)
1078 tree base_binfo
= canonical_binfo (TREE_VEC_ELT (binfos
, i
));
1079 if (is_subobject_of_p (parent
, base_binfo
))
1085 /* See if a one FIELD_DECL hides another. This routine is meant to
1086 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1087 binfos given are the binfos corresponding to the particular places
1088 the FIELD_DECLs are found. This routine relies upon binfos not
1089 being shared, except for virtual bases. */
1092 hides (hider_binfo
, hidee_binfo
)
1093 tree hider_binfo
, hidee_binfo
;
1095 /* hider hides hidee, if hider has hidee as a base class and
1096 the instance of hidee is a sub-object of hider. The first
1097 part is always true is the second part is true.
1099 When hider and hidee are the same (two ways to get to the exact
1100 same member) we consider either one as hiding the other. */
1101 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
1104 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1105 function was declared inside the class given by TYPE. It really should
1106 only return functions that match the given TYPE. */
1109 lookup_fnfields_here (type
, name
)
1112 int idx
= lookup_fnfields_1 (type
, name
);
1115 /* ctors and dtors are always only in the right class. */
1118 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1121 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls
)))
1122 == TYPE_MAIN_VARIANT (type
))
1124 fndecls
= OVL_CHAIN (fndecls
);
1129 struct lookup_field_info
{
1130 /* The type in which we're looking. */
1132 /* The name of the field for which we're looking. */
1134 /* If non-NULL, the current result of the lookup. */
1136 /* The path to RVAL. */
1138 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1141 /* If non-zero, we are looking for types, not data members. */
1143 /* If non-zero, RVAL was found by looking through a dependent base. */
1144 int from_dep_base_p
;
1145 /* If something went wrong, a message indicating what. */
1149 /* Returns non-zero if BINFO is not hidden by the value found by the
1150 lookup so far. If BINFO is hidden, then there's no need to look in
1151 it. DATA is really a struct lookup_field_info. Called from
1152 lookup_field via breadth_first_search. */
1155 lookup_field_queue_p (binfo
, data
)
1159 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1161 /* Don't look for constructors or destructors in base classes. */
1162 if (lfi
->name
== ctor_identifier
|| lfi
->name
== dtor_identifier
)
1165 /* If this base class is hidden by the best-known value so far, we
1166 don't need to look. */
1167 if (!lfi
->from_dep_base_p
&& lfi
->rval_binfo
1168 && hides (lfi
->rval_binfo
, binfo
))
1171 if (TREE_VIA_VIRTUAL (binfo
))
1172 return binfo_member (BINFO_TYPE (binfo
),
1173 CLASSTYPE_VBASECLASSES (lfi
->type
));
1178 /* DATA is really a struct lookup_field_info. Look for a field with
1179 the name indicated there in BINFO. If this function returns a
1180 non-NULL value it is the result of the lookup. Called from
1181 lookup_field via breadth_first_search. */
1184 lookup_field_r (binfo
, data
)
1188 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1189 tree type
= BINFO_TYPE (binfo
);
1192 int from_dep_base_p
;
1194 /* First, look for a function. There can't be a function and a data
1195 member with the same name, and if there's a function and a type
1196 with the same name, the type is hidden by the function. */
1197 idx
= lookup_fnfields_here (type
, lfi
->name
);
1199 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1201 /* Look for a data member or type. */
1202 nval
= lookup_field_1 (type
, lfi
->name
);
1204 /* If there is no declaration with the indicated name in this type,
1205 then there's nothing to do. */
1209 from_dep_base_p
= dependent_base_p (binfo
);
1210 if (lfi
->from_dep_base_p
&& !from_dep_base_p
)
1212 /* If the new declaration is not found via a dependent base, and
1213 the old one was, then we must prefer the new one. We weren't
1214 really supposed to be able to find the old one, so we don't
1215 want to be affected by a specialization. Consider:
1217 struct B { typedef int I; };
1218 template <typename T> struct D1 : virtual public B {};
1219 template <typename T> struct D :
1220 public D1, virtual pubic B { I i; };
1222 The `I' in `D<T>' is unambigousuly `B::I', regardless of how
1223 D1 is specialized. */
1224 lfi
->from_dep_base_p
= 0;
1225 lfi
->rval
= NULL_TREE
;
1226 lfi
->rval_binfo
= NULL_TREE
;
1227 lfi
->ambiguous
= NULL_TREE
;
1230 else if (lfi
->rval_binfo
&& !lfi
->from_dep_base_p
&& from_dep_base_p
)
1231 /* Similarly, if the old declaration was not found via a dependent
1232 base, and the new one is, ignore the new one. */
1235 /* If the lookup already found a match, and the new value doesn't
1236 hide the old one, we might have an ambiguity. */
1237 if (lfi
->rval_binfo
&& !hides (binfo
, lfi
->rval_binfo
))
1239 if (nval
== lfi
->rval
&& SHARED_MEMBER_P (nval
))
1240 /* The two things are really the same. */
1242 else if (hides (lfi
->rval_binfo
, binfo
))
1243 /* The previous value hides the new one. */
1247 /* We have a real ambiguity. We keep a chain of all the
1249 if (!lfi
->ambiguous
&& lfi
->rval
)
1250 /* This is the first time we noticed an ambiguity. Add
1251 what we previously thought was a reasonable candidate
1253 lfi
->ambiguous
= scratch_tree_cons (NULL_TREE
, lfi
->rval
,
1255 /* Add the new value. */
1256 lfi
->ambiguous
= scratch_tree_cons (NULL_TREE
, nval
,
1258 lfi
->errstr
= "request for member `%D' is ambiguous";
1263 /* The new lookup is the best we've got so far. Verify that
1264 it's the kind of thing we're looking for. */
1265 if (lfi
->want_type
&& TREE_CODE (nval
) != TYPE_DECL
)
1267 nval
= purpose_member (lfi
->name
, CLASSTYPE_TAGS (type
));
1269 nval
= TYPE_MAIN_DECL (TREE_VALUE (nval
));
1274 /* If the thing we're looking for is a virtual base class,
1275 then we know we've got what we want at this point;
1276 there's no way to get an ambiguity. */
1277 if (VBASE_NAME_P (lfi
->name
))
1283 if (from_dep_base_p
&& TREE_CODE (nval
) != TYPE_DECL
1284 /* We need to return a member template class so we can
1285 define partial specializations. Is there a better
1287 && !DECL_CLASS_TEMPLATE_P (nval
))
1288 /* The thing we're looking for isn't a type, so the implicit
1289 typename extension doesn't apply, so we just pretend we
1290 didn't find anything. */
1295 lfi
->from_dep_base_p
= from_dep_base_p
;
1296 lfi
->rval_binfo
= binfo
;
1302 /* Look for a memer named NAME in an inheritance lattice dominated by
1303 XBASETYPE. PROTECT is zero if we can avoid computing access
1304 information, otherwise it is 1. WANT_TYPE is 1 when we should only
1305 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
1307 It was not clear what should happen if WANT_TYPE is set, and an
1308 ambiguity is found. At least one use (lookup_name) to not see
1312 lookup_member (xbasetype
, name
, protect
, want_type
)
1313 register tree xbasetype
, name
;
1314 int protect
, want_type
;
1316 tree rval
, rval_binfo
= NULL_TREE
;
1317 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1318 struct lookup_field_info lfi
;
1320 /* rval_binfo is the binfo associated with the found member, note,
1321 this can be set with useful information, even when rval is not
1322 set, because it must deal with ALL members, not just non-function
1323 members. It is used for ambiguity checking and the hidden
1324 checks. Whereas rval is only set if a proper (not hidden)
1325 non-function member is found. */
1327 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1328 hiding checks, as virtual base classes may not be shared. The strategy
1329 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1330 virtual base classes, as we cross virtual base class lines. This way
1331 we know that binfo of a virtual base class will always == itself when
1332 found along any line. (mrs) */
1334 const char *errstr
= 0;
1336 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1337 && IDENTIFIER_CLASS_VALUE (name
))
1339 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1340 if (TREE_CODE (field
) != FUNCTION_DECL
1341 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1345 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1347 type
= BINFO_TYPE (xbasetype
);
1348 basetype_path
= xbasetype
;
1350 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1353 basetype_path
= TYPE_BINFO (type
);
1354 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
1358 my_friendly_abort (97);
1360 complete_type (type
);
1362 #ifdef GATHER_STATISTICS
1363 n_calls_lookup_field
++;
1364 #endif /* GATHER_STATISTICS */
1366 bzero ((PTR
) &lfi
, sizeof (lfi
));
1369 lfi
.want_type
= want_type
;
1370 bfs_walk (basetype_path
, &lookup_field_r
, &lookup_field_queue_p
, &lfi
);
1372 rval_binfo
= lfi
.rval_binfo
;
1374 type
= BINFO_TYPE (rval_binfo
);
1375 errstr
= lfi
.errstr
;
1377 /* If we are not interested in ambiguities, don't report them;
1378 just return NULL_TREE. */
1379 if (!protect
&& lfi
.ambiguous
)
1384 In the case of overloaded function names, access control is
1385 applied to the function selected by overloaded resolution. */
1386 if (rval
&& protect
&& !is_overloaded_fn (rval
)
1387 && !IS_SIGNATURE_POINTER (DECL_REAL_CONTEXT (rval
))
1388 && !IS_SIGNATURE_REFERENCE (DECL_REAL_CONTEXT (rval
))
1389 && !enforce_access (xbasetype
, rval
))
1390 return error_mark_node
;
1392 if (errstr
&& protect
)
1394 cp_error (errstr
, name
, type
);
1396 print_candidates (lfi
.ambiguous
);
1397 rval
= error_mark_node
;
1400 /* If the thing we found was found via the implicit typename
1401 extension, build the typename type. */
1402 if (rval
&& lfi
.from_dep_base_p
&& !DECL_CLASS_TEMPLATE_P (rval
))
1403 rval
= TYPE_STUB_DECL (build_typename_type (BINFO_TYPE (basetype_path
),
1407 if (rval
&& is_overloaded_fn (rval
))
1408 rval
= scratch_tree_cons (basetype_path
, rval
, NULL_TREE
);
1413 /* Like lookup_member, except that if we find a function member we
1414 return NULL_TREE. */
1417 lookup_field (xbasetype
, name
, protect
, want_type
)
1418 register tree xbasetype
, name
;
1419 int protect
, want_type
;
1421 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
);
1423 /* Ignore functions. */
1424 if (rval
&& TREE_CODE (rval
) == TREE_LIST
)
1430 /* Like lookup_member, except that if we find a non-function member we
1431 return NULL_TREE. */
1434 lookup_fnfields (xbasetype
, name
, protect
)
1435 register tree xbasetype
, name
;
1438 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/0);
1440 /* Ignore non-functions. */
1441 if (rval
&& TREE_CODE (rval
) != TREE_LIST
)
1447 /* Try to find NAME inside a nested class. */
1450 lookup_nested_field (name
, complain
)
1456 tree id
= NULL_TREE
;
1457 if (TYPE_MAIN_DECL (current_class_type
))
1459 /* Climb our way up the nested ladder, seeing if we're trying to
1460 modify a field in an enclosing class. If so, we should only
1461 be able to modify if it's static. */
1462 for (t
= TYPE_MAIN_DECL (current_class_type
);
1463 t
&& DECL_CONTEXT (t
);
1464 t
= TYPE_MAIN_DECL (DECL_CONTEXT (t
)))
1466 if (TREE_CODE (DECL_CONTEXT (t
)) != RECORD_TYPE
)
1469 /* N.B.: lookup_field will do the access checking for us */
1470 id
= lookup_field (DECL_CONTEXT (t
), name
, complain
, 0);
1471 if (id
== error_mark_node
)
1477 if (id
!= NULL_TREE
)
1479 if (TREE_CODE (id
) == FIELD_DECL
1480 && ! TREE_STATIC (id
)
1481 && TREE_TYPE (id
) != error_mark_node
)
1485 /* At parse time, we don't want to give this error, since
1486 we won't have enough state to make this kind of
1487 decision properly. But there are times (e.g., with
1488 enums in nested classes) when we do need to call
1489 this fn at parse time. So, in those cases, we pass
1490 complain as a 0 and just return a NULL_TREE. */
1491 cp_error ("assignment to non-static member `%D' of enclosing class `%T'",
1492 id
, DECL_CONTEXT (t
));
1493 /* Mark this for do_identifier(). It would otherwise
1494 claim that the variable was undeclared. */
1495 TREE_TYPE (id
) = error_mark_node
;
1511 /* TYPE is a class type. Return the index of the fields within
1512 the method vector with name NAME, or -1 is no such field exists. */
1515 lookup_fnfields_1 (type
, name
)
1518 register tree method_vec
1519 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
1521 if (method_vec
!= 0)
1523 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1524 register tree
*end
= TREE_VEC_END (method_vec
);
1526 #ifdef GATHER_STATISTICS
1527 n_calls_lookup_fnfields_1
++;
1528 #endif /* GATHER_STATISTICS */
1530 /* Constructors are first... */
1531 if (*methods
&& name
== ctor_identifier
)
1534 /* and destructors are second. */
1535 if (*++methods
&& name
== dtor_identifier
)
1538 while (++methods
!= end
&& *methods
)
1540 #ifdef GATHER_STATISTICS
1541 n_outer_fields_searched
++;
1542 #endif /* GATHER_STATISTICS */
1543 if (DECL_NAME (OVL_CURRENT (*methods
)) == name
)
1547 /* If we didn't find it, it might have been a template
1548 conversion operator. (Note that we don't look for this case
1549 above so that we will always find specializations first.) */
1550 if ((methods
== end
|| !*methods
)
1551 && IDENTIFIER_TYPENAME_P (name
))
1553 methods
= &TREE_VEC_ELT (method_vec
, 0) + 1;
1555 while (++methods
!= end
&& *methods
)
1557 tree method_name
= DECL_NAME (OVL_CURRENT (*methods
));
1559 if (!IDENTIFIER_TYPENAME_P (method_name
))
1561 /* Since all conversion operators come first, we know
1562 there is no such operator. */
1566 else if (TREE_CODE (OVL_CURRENT (*methods
)) == TEMPLATE_DECL
)
1571 if (methods
!= end
&& *methods
)
1572 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1578 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1579 type in the hierarchy, in a breadth-first preorder traversal. .
1580 If it ever returns a non-NULL value, that value is immediately
1581 returned and the walk is terminated. At each node FN, is passed a
1582 BINFO indicating the path from the curently visited base-class to
1583 TYPE. The TREE_CHAINs of the BINFOs may be used for scratch space;
1584 they are otherwise unused. Before each base-class is walked QFN is
1585 called. If the value returned is non-zero, the base-class is
1586 walked; otherwise it is not. If QFN is NULL, it is treated as a
1587 function which always returns 1. Both FN and QFN are passed the
1588 DATA whenever they are called. */
1591 bfs_walk (binfo
, fn
, qfn
, data
)
1593 tree (*fn
) PROTO((tree
, void *));
1594 tree (*qfn
) PROTO((tree
, void *));
1599 tree rval
= NULL_TREE
;
1600 /* An array of the base classes of BINFO. These will be built up in
1601 breadth-first order, except where QFN prunes the search. */
1602 varray_type bfs_bases
;
1604 /* Start with enough room for ten base classes. That will be enough
1605 for most hierarchies. */
1606 VARRAY_TREE_INIT (bfs_bases
, 10, "search_stack");
1608 /* Put the first type into the stack. */
1609 VARRAY_TREE (bfs_bases
, 0) = binfo
;
1612 for (head
= 0; head
< tail
; ++head
)
1618 /* Pull the next type out of the queue. */
1619 binfo
= VARRAY_TREE (bfs_bases
, head
);
1621 /* If this is the one we're looking for, we're done. */
1622 rval
= (*fn
) (binfo
, data
);
1626 /* Queue up the base types. */
1627 binfos
= BINFO_BASETYPES (binfo
);
1628 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1629 for (i
= 0; i
< n_baselinks
; i
++)
1631 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1634 base_binfo
= (*qfn
) (base_binfo
, data
);
1638 if (tail
== VARRAY_SIZE (bfs_bases
))
1639 VARRAY_GROW (bfs_bases
, 2 * VARRAY_SIZE (bfs_bases
));
1640 VARRAY_TREE (bfs_bases
, tail
) = base_binfo
;
1647 VARRAY_FREE (bfs_bases
);
1652 /* Exactly like bfs_walk, except that a depth-first traversal is
1653 performed, and PREFN is called in preorder, while POSTFN is called
1657 dfs_walk_real (binfo
, prefn
, postfn
, qfn
, data
)
1659 tree (*prefn
) PROTO((tree
, void *));
1660 tree (*postfn
) PROTO((tree
, void *));
1661 tree (*qfn
) PROTO((tree
, void *));
1667 tree rval
= NULL_TREE
;
1669 /* Call the pre-order walking function. */
1672 rval
= (*prefn
) (binfo
, data
);
1677 /* Process the basetypes. */
1678 binfos
= BINFO_BASETYPES (binfo
);
1679 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1680 for (i
= 0; i
< n_baselinks
; i
++)
1682 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1685 base_binfo
= (*qfn
) (base_binfo
, data
);
1689 rval
= dfs_walk_real (base_binfo
, prefn
, postfn
, qfn
, data
);
1695 /* Call the post-order walking function. */
1697 rval
= (*postfn
) (binfo
, data
);
1702 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1706 dfs_walk (binfo
, fn
, qfn
, data
)
1708 tree (*fn
) PROTO((tree
, void *));
1709 tree (*qfn
) PROTO((tree
, void *));
1712 return dfs_walk_real (binfo
, 0, fn
, qfn
, data
);
1717 /* The name of the function we are looking for. */
1719 /* The overloaded functions we have found. */
1723 /* Called from get_virtuals_named_this via bfs_walk. */
1726 get_virtuals_named_this_r (binfo
, data
)
1730 struct gvnt_info
*gvnti
= (struct gvnt_info
*) data
;
1731 tree type
= BINFO_TYPE (binfo
);
1734 idx
= lookup_fnfields_here (BINFO_TYPE (binfo
), gvnti
->name
);
1737 = scratch_tree_cons (binfo
,
1738 TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
),
1745 /* Return the virtual functions with the indicated NAME in the type
1746 indicated by BINFO. The result is a TREE_LIST whose TREE_PURPOSE
1747 indicates the base class from which the TREE_VALUE (an OVERLOAD or
1748 just a FUNCTION_DECL) originated. */
1751 get_virtuals_named_this (binfo
, name
)
1755 struct gvnt_info gvnti
;
1759 gvnti
.fields
= NULL_TREE
;
1761 bfs_walk (binfo
, get_virtuals_named_this_r
, 0, &gvnti
);
1763 /* Get to the function decls, and return the first virtual function
1764 with this name, if there is one. */
1765 for (fields
= gvnti
.fields
; fields
; fields
= next_baselink (fields
))
1769 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
1770 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
1777 get_virtual_destructor (binfo
, data
)
1779 void *data ATTRIBUTE_UNUSED
;
1781 tree type
= BINFO_TYPE (binfo
);
1782 if (TYPE_HAS_DESTRUCTOR (type
)
1783 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
1784 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
1789 tree_has_any_destructor_p (binfo
, data
)
1791 void *data ATTRIBUTE_UNUSED
;
1793 tree type
= BINFO_TYPE (binfo
);
1794 return TYPE_NEEDS_DESTRUCTOR (type
) ? binfo
: NULL_TREE
;
1797 /* Returns > 0 if a function with type DRETTYPE overriding a function
1798 with type BRETTYPE is covariant, as defined in [class.virtual].
1800 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1801 adjustment), or -1 if pedantically invalid covariance. */
1804 covariant_return_p (brettype
, drettype
)
1805 tree brettype
, drettype
;
1809 if (TREE_CODE (brettype
) == FUNCTION_DECL
1810 || TREE_CODE (brettype
) == THUNK_DECL
)
1812 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
1813 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
1815 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
1817 brettype
= TREE_TYPE (brettype
);
1818 drettype
= TREE_TYPE (drettype
);
1821 if (same_type_p (brettype
, drettype
))
1824 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
1825 && (TREE_CODE (brettype
) == POINTER_TYPE
1826 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
1827 && TYPE_QUALS (brettype
) == TYPE_QUALS (drettype
)))
1830 if (! can_convert (brettype
, drettype
))
1833 brettype
= TREE_TYPE (brettype
);
1834 drettype
= TREE_TYPE (drettype
);
1836 /* If not pedantic, allow any standard pointer conversion. */
1837 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
1840 binfo
= get_binfo (brettype
, drettype
, 1);
1842 /* If we get an error_mark_node from get_binfo, it already complained,
1843 so let's just succeed. */
1844 if (binfo
== error_mark_node
)
1847 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
1852 /* Given a class type TYPE, and a function decl FNDECL, look for a
1853 virtual function in TYPE's hierarchy which FNDECL could match as a
1854 virtual function. It doesn't matter which one we find.
1856 DTORP is nonzero if we are looking for a destructor. Destructors
1857 need special treatment because they do not match by name. */
1860 get_matching_virtual (binfo
, fndecl
, dtorp
)
1864 tree tmp
= NULL_TREE
;
1867 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
1868 /* In [temp.mem] we have:
1870 A specialization of a member function template does not
1871 override a virtual function from a base class. */
1874 /* Breadth first search routines start searching basetypes
1875 of TYPE, so we must perform first ply of search here. */
1877 return bfs_walk (binfo
, get_virtual_destructor
,
1878 tree_has_any_destructor_p
, 0);
1881 tree drettype
, dtypes
, btypes
, instptr_type
;
1882 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
1883 tree baselink
, best
= NULL_TREE
;
1884 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
1885 tree declarator
= DECL_NAME (fndecl
);
1886 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
1889 baselink
= get_virtuals_named_this (binfo
, declarator
);
1890 if (baselink
== NULL_TREE
)
1893 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
1894 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1895 if (DECL_STATIC_FUNCTION_P (fndecl
))
1896 instptr_type
= NULL_TREE
;
1898 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
1900 for (; baselink
; baselink
= next_baselink (baselink
))
1903 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
1905 tmp
= OVL_CURRENT (tmps
);
1906 if (! DECL_VINDEX (tmp
))
1909 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
1910 if (instptr_type
== NULL_TREE
)
1912 if (compparms (TREE_CHAIN (btypes
), dtypes
))
1913 /* Caller knows to give error in this case. */
1918 if (/* The first parameter is the `this' parameter,
1919 which has POINTER_TYPE, and we can therefore
1920 safely use TYPE_QUALS, rather than
1922 (TYPE_QUALS (TREE_TYPE (TREE_VALUE (btypes
)))
1923 == TYPE_QUALS (instptr_type
))
1924 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
)))
1926 tree brettype
= TREE_TYPE (TREE_TYPE (tmp
));
1927 if (same_type_p (brettype
, drettype
))
1929 else if ((i
= covariant_return_p (brettype
, drettype
)))
1932 sorry ("adjusting pointers for covariant returns");
1934 if (pedantic
&& i
== -1)
1936 cp_pedwarn_at ("invalid covariant return type for `%#D' (must be pointer or reference to class)", fndecl
);
1937 cp_pedwarn_at (" overriding `%#D'", tmp
);
1940 else if (IS_AGGR_TYPE_2 (brettype
, drettype
)
1941 && same_or_base_type_p (brettype
, drettype
))
1943 error ("invalid covariant return type (must use pointer or reference)");
1944 cp_error_at (" overriding `%#D'", tmp
);
1945 cp_error_at (" with `%#D'", fndecl
);
1947 else if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
)
1949 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl
);
1950 cp_error_at (" overriding definition as `%#D'", tmp
);
1951 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
1954 /* FNDECL overrides this function. We continue to
1955 check all the other functions in order to catch
1956 errors; it might be that in some other baseclass
1957 a virtual function was declared with the same
1958 parameter types, but a different return type. */
1968 /* Return the list of virtual functions which are abstract in type
1969 TYPE that come from non virtual base classes. See
1970 expand_direct_vtbls_init for the style of search we do. */
1973 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
1976 tree abstract_virtuals
;
1978 tree binfos
= BINFO_BASETYPES (binfo
);
1979 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1981 for (i
= 0; i
< n_baselinks
; i
++)
1983 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1984 int is_not_base_vtable
1985 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
1986 if (! TREE_VIA_VIRTUAL (base_binfo
))
1988 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
1991 /* Should we use something besides CLASSTYPE_VFIELDS? */
1992 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
1994 tree virtuals
= BINFO_VIRTUALS (binfo
);
1996 skip_rtti_stuff (&virtuals
);
2000 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2001 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2002 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2003 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2004 virtuals
= TREE_CHAIN (virtuals
);
2007 return abstract_virtuals
;
2010 /* Return the list of virtual functions which are abstract in type TYPE.
2011 This information is cached, and so must be built on a
2012 non-temporary obstack. */
2015 get_abstract_virtuals (type
)
2019 tree abstract_virtuals
= NULL
;
2021 /* First get all from non-virtual bases. */
2023 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
2025 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
2027 tree virtuals
= BINFO_VIRTUALS (vbases
);
2029 skip_rtti_stuff (&virtuals
);
2033 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2034 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2035 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
2036 cp_error ("`%#D' needs a final overrider", base_fndecl
);
2037 else if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2038 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2039 virtuals
= TREE_CHAIN (virtuals
);
2042 return nreverse (abstract_virtuals
);
2046 next_baselink (baselink
)
2049 tree tmp
= TREE_TYPE (baselink
);
2050 baselink
= TREE_CHAIN (baselink
);
2053 /* @@ does not yet add previous base types. */
2054 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2056 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2057 tmp
= TREE_CHAIN (tmp
);
2062 /* DEPTH-FIRST SEARCH ROUTINES. */
2064 /* This routine converts a pointer to be a pointer of an immediate
2065 base class. The normal convert_pointer_to routine would diagnose
2066 the conversion as ambiguous, under MI code that has the base class
2067 as an ambiguous base class. */
2070 convert_pointer_to_single_level (to_type
, expr
)
2073 tree binfo_of_derived
;
2076 binfo_of_derived
= TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
)));
2077 last
= get_binfo (to_type
, TREE_TYPE (TREE_TYPE (expr
)), 0);
2078 my_friendly_assert (BINFO_INHERITANCE_CHAIN (last
) == binfo_of_derived
,
2080 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo_of_derived
) == NULL_TREE
,
2082 return build_vbase_path (PLUS_EXPR
, build_pointer_type (to_type
), expr
,
2086 tree
markedp (binfo
, data
)
2088 void *data ATTRIBUTE_UNUSED
;
2090 return BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2094 unmarkedp (binfo
, data
)
2096 void *data ATTRIBUTE_UNUSED
;
2098 return !BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2102 marked_vtable_pathp (binfo
, data
)
2104 void *data ATTRIBUTE_UNUSED
;
2106 return BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2110 unmarked_vtable_pathp (binfo
, data
)
2112 void *data ATTRIBUTE_UNUSED
;
2114 return !BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2118 marked_new_vtablep (binfo
, data
)
2120 void *data ATTRIBUTE_UNUSED
;
2122 return BINFO_NEW_VTABLE_MARKED (binfo
) ? binfo
: NULL_TREE
;
2126 unmarked_new_vtablep (binfo
, data
)
2128 void *data ATTRIBUTE_UNUSED
;
2130 return !BINFO_NEW_VTABLE_MARKED (binfo
) ? binfo
: NULL_TREE
;
2134 marked_pushdecls_p (binfo
, data
)
2136 void *data ATTRIBUTE_UNUSED
;
2138 return BINFO_PUSHDECLS_MARKED (binfo
) ? binfo
: NULL_TREE
;
2142 unmarked_pushdecls_p (binfo
, data
)
2144 void *data ATTRIBUTE_UNUSED
;
2146 return !BINFO_PUSHDECLS_MARKED (binfo
) ? binfo
: NULL_TREE
;
2150 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2151 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2155 dfs_debug_unmarkedp (binfo
, data
)
2157 void *data ATTRIBUTE_UNUSED
;
2159 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
))
2160 ? binfo
: NULL_TREE
);
2163 /* The worker functions for `dfs_walk'. These do not need to
2164 test anything (vis a vis marking) if they are paired with
2165 a predicate function (above). */
2169 dfs_mark (binfo
) tree binfo
;
2170 { SET_BINFO_MARKED (binfo
); }
2174 dfs_unmark (binfo
, data
)
2176 void *data ATTRIBUTE_UNUSED
;
2178 CLEAR_BINFO_MARKED (binfo
);
2184 dfs_mark_vtable_path (binfo
) tree binfo
;
2185 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2188 dfs_unmark_vtable_path (binfo
) tree binfo
;
2189 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2192 dfs_mark_new_vtable (binfo
) tree binfo
;
2193 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2196 dfs_unmark_new_vtable (binfo
) tree binfo
;
2197 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2200 dfs_clear_search_slot (binfo
) tree binfo
;
2201 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2205 dfs_debug_mark (binfo
, data
)
2207 void *data ATTRIBUTE_UNUSED
;
2209 tree t
= BINFO_TYPE (binfo
);
2211 /* Use heuristic that if there are virtual functions,
2212 ignore until we see a non-inline virtual function. */
2213 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2215 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2220 /* If interface info is known, either we've already emitted the debug
2221 info or we don't need to. */
2222 if (CLASSTYPE_INTERFACE_KNOWN (t
))
2225 /* If debug info is requested from this context for this type, supply it.
2226 If debug info is requested from another context for this type,
2227 see if some third context can supply it. */
2228 if (current_function_decl
== NULL_TREE
2229 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2231 if (TREE_VEC_ELT (methods
, 1))
2232 methods
= TREE_VEC_ELT (methods
, 1);
2233 else if (TREE_VEC_ELT (methods
, 0))
2234 methods
= TREE_VEC_ELT (methods
, 0);
2236 methods
= TREE_VEC_ELT (methods
, 2);
2237 methods
= OVL_CURRENT (methods
);
2240 if (DECL_VINDEX (methods
)
2241 && DECL_THIS_INLINE (methods
) == 0
2242 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2244 /* Somebody, somewhere is going to have to define this
2245 virtual function. When they do, they will provide
2246 the debugging info. */
2249 methods
= TREE_CHAIN (methods
);
2252 /* We cannot rely on some alien method to solve our problems,
2253 so we must write out the debug info ourselves. */
2254 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2255 rest_of_type_compilation (t
, toplevel_bindings_p ());
2267 /* Attach to the type of the virtual base class, the pointer to the
2268 virtual base class. */
2271 dfs_find_vbases (binfo
, data
)
2275 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2276 tree binfos
= BINFO_BASETYPES (binfo
);
2277 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2279 for (i
= n_baselinks
-1; i
>= 0; i
--)
2281 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2283 if (TREE_VIA_VIRTUAL (base_binfo
)
2284 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2286 tree vbase
= BINFO_TYPE (base_binfo
);
2287 tree binfo
= binfo_member (vbase
, vi
->vbase_types
);
2289 CLASSTYPE_SEARCH_SLOT (vbase
)
2290 = build (PLUS_EXPR
, build_pointer_type (vbase
),
2291 vi
->decl_ptr
, BINFO_OFFSET (binfo
));
2294 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2295 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2301 dfs_init_vbase_pointers (binfo
, data
)
2305 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2306 tree type
= BINFO_TYPE (binfo
);
2307 tree fields
= TYPE_FIELDS (type
);
2308 tree this_vbase_ptr
;
2310 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2313 /* See finish_struct_1 for when we can enable this. */
2314 /* If we have a vtable pointer first, skip it. */
2315 if (VFIELD_NAME_P (DECL_NAME (fields
)))
2316 fields
= TREE_CHAIN (fields
);
2319 if (BINFO_INHERITANCE_CHAIN (binfo
))
2321 this_vbase_ptr
= TREE_CHAIN (BINFO_INHERITANCE_CHAIN (binfo
));
2322 if (TREE_VIA_VIRTUAL (binfo
))
2323 this_vbase_ptr
= CLASSTYPE_SEARCH_SLOT (type
);
2325 this_vbase_ptr
= convert_pointer_to_single_level (type
,
2327 TREE_CHAIN (binfo
) = this_vbase_ptr
;
2330 this_vbase_ptr
= TREE_CHAIN (binfo
);
2332 if (fields
== NULL_TREE
2333 || DECL_NAME (fields
) == NULL_TREE
2334 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2337 if (build_pointer_type (type
)
2338 != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2339 my_friendly_abort (125);
2341 while (fields
&& DECL_NAME (fields
) && VBASE_NAME_P (DECL_NAME (fields
)))
2343 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2344 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2345 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2346 vi
->inits
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2348 build_modify_expr (ref
, NOP_EXPR
, init
),
2350 fields
= TREE_CHAIN (fields
);
2356 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2357 times, just NEW_VTABLE, but optimizer should make both with equal
2358 efficiency (though it does not currently). */
2361 dfs_clear_vbase_slots (binfo
, data
)
2363 void *data ATTRIBUTE_UNUSED
;
2365 tree type
= BINFO_TYPE (binfo
);
2366 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2367 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2368 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2373 init_vbase_pointers (type
, decl_ptr
)
2377 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2379 struct vbase_info vi
;
2380 int old_flag
= flag_this_is_variable
;
2381 tree binfo
= TYPE_BINFO (type
);
2382 flag_this_is_variable
= -2;
2384 /* Find all the virtual base classes, marking them for later
2386 vi
.decl_ptr
= decl_ptr
;
2387 vi
.vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2388 vi
.inits
= NULL_TREE
;
2390 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
, &vi
);
2392 /* Build up a list of the initializers. */
2393 TREE_CHAIN (binfo
) = decl_ptr
;
2394 dfs_walk_real (binfo
,
2395 dfs_init_vbase_pointers
, 0,
2396 marked_vtable_pathp
,
2399 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
, 0);
2400 flag_this_is_variable
= old_flag
;
2406 /* get the virtual context (the vbase that directly contains the
2407 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2408 or NULL_TREE if there is none.
2410 FNDECL must come from a virtual table from a virtual base to ensure that
2411 there is only one possible DECL_CLASS_CONTEXT.
2413 We know that if there is more than one place (binfo) the fndecl that the
2414 declared, they all refer to the same binfo. See get_class_offset_1 for
2415 the check that ensures this. */
2418 virtual_context (fndecl
, t
, vbase
)
2419 tree fndecl
, t
, vbase
;
2422 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2424 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2425 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2429 /* Not sure if checking path == vbase is necessary here, but just in
2431 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2432 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2433 path
= BINFO_INHERITANCE_CHAIN (path
);
2436 /* This shouldn't happen, I don't want errors! */
2437 warning ("recoverable compiler error, fixups for virtual function");
2442 if (TREE_VIA_VIRTUAL (path
))
2443 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2444 path
= BINFO_INHERITANCE_CHAIN (path
);
2449 /* Fixups upcast offsets for one vtable.
2450 Entries may stay within the VBASE given, or
2451 they may upcast into a direct base, or
2452 they may upcast into a different vbase.
2454 We only need to do fixups in case 2 and 3. In case 2, we add in
2455 the virtual base offset to effect an upcast, in case 3, we add in
2456 the virtual base offset to effect an upcast, then subtract out the
2457 offset for the other virtual base, to effect a downcast into it.
2459 This routine mirrors fixup_vtable_deltas in functionality, though
2460 this one is runtime based, and the other is compile time based.
2461 Conceivably that routine could be removed entirely, and all fixups
2464 VBASE_OFFSETS is an association list of virtual bases that contains
2465 offset information for the virtual bases, so the offsets are only
2466 calculated once. The offsets are computed by where we think the
2467 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2468 the vbase really is. */
2471 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2473 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2475 tree virtuals
= BINFO_VIRTUALS (binfo
);
2478 unsigned HOST_WIDE_INT n
;
2480 delta
= purpose_member (vbase
, *vbase_offsets
);
2483 delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase
));
2484 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2485 delta
= save_expr (delta
);
2486 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2487 *vbase_offsets
= delta
;
2490 n
= skip_rtti_stuff (&virtuals
);
2494 tree current_fndecl
= TREE_VALUE (virtuals
);
2495 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2496 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2498 && current_fndecl
!= abort_fndecl
2499 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2501 /* This may in fact need a runtime fixup. */
2502 tree idx
= build_int_2 (n
, 0);
2503 tree vtbl
= BINFO_VTABLE (binfo
);
2504 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2505 tree aref
, ref
, naref
;
2506 tree old_delta
, new_delta
;
2509 if (nvtbl
== NULL_TREE
2510 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2512 /* Dup it if it isn't in local scope yet. */
2514 (VAR_DECL
, DECL_NAME (vtbl
),
2515 TYPE_MAIN_VARIANT (TREE_TYPE (vtbl
)));
2516 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2517 DECL_ALIGN (nvtbl
));
2518 TREE_READONLY (nvtbl
) = 0;
2519 DECL_ARTIFICIAL (nvtbl
) = 1;
2520 nvtbl
= pushdecl (nvtbl
);
2522 cp_finish_decl (nvtbl
, init
, NULL_TREE
, 0,
2523 LOOKUP_ONLYCONVERTING
);
2525 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2526 because they wouldn't be useful; everything that wants to
2527 look at the vtable will look at the decl for the normal
2528 vtable. Setting DECL_CONTEXT also screws up
2529 decl_function_context. */
2531 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
2533 TREE_SIDE_EFFECTS (init
) = 1;
2534 expand_expr_stmt (init
);
2535 /* Update the vtable pointers as necessary. */
2536 ref
= build_vfield_ref
2537 (build_indirect_ref (addr
, NULL_PTR
),
2538 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))));
2540 (build_modify_expr (ref
, NOP_EXPR
, nvtbl
));
2542 assemble_external (vtbl
);
2543 aref
= build_array_ref (vtbl
, idx
);
2544 naref
= build_array_ref (nvtbl
, idx
);
2545 old_delta
= build_component_ref (aref
, delta_identifier
,
2547 new_delta
= build_component_ref (naref
, delta_identifier
,
2550 /* This is a upcast, so we have to add the offset for the
2552 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
2553 TREE_VALUE (delta
), 0);
2556 /* If this is set, we need to subtract out the delta
2557 adjustments for the other virtual base that we
2559 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
2562 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
2563 vc_delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc
));
2564 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
2566 vc_delta
= save_expr (vc_delta
);
2567 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
2570 vc_delta
= TREE_VALUE (vc_delta
);
2572 /* This is a downcast, so we have to subtract the offset
2573 for the virtual base. */
2574 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
, 0);
2577 TREE_READONLY (new_delta
) = 0;
2578 TREE_TYPE (new_delta
) =
2579 cp_build_qualified_type (TREE_TYPE (new_delta
),
2580 CP_TYPE_QUALS (TREE_TYPE (new_delta
))
2581 & ~TYPE_QUAL_CONST
);
2582 expand_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
2586 virtuals
= TREE_CHAIN (virtuals
);
2590 /* Fixup upcast offsets for all direct vtables. Patterned after
2591 expand_direct_vtbls_init. */
2594 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
2595 tree real_binfo
, binfo
;
2596 int init_self
, can_elide
;
2597 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
2599 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
2600 tree binfos
= BINFO_BASETYPES (binfo
);
2601 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
2603 for (i
= 0; i
< n_baselinks
; i
++)
2605 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
2606 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2607 int is_not_base_vtable
2608 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo
));
2609 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
2610 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
2611 is_not_base_vtable
, can_elide
, addr
,
2612 orig_addr
, type
, vbase
, vbase_offsets
);
2615 /* Before turning this on, make sure it is correct. */
2616 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
2619 /* Should we use something besides CLASSTYPE_VFIELDS? */
2620 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
2622 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
2623 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
2624 type
, vbase_offsets
);
2628 /* Build a COMPOUND_EXPR which when expanded will generate the code
2629 needed to initialize all the virtual function table slots of all
2630 the virtual baseclasses. MAIN_BINFO is the binfo which determines
2631 the virtual baseclasses to use; TYPE is the type of the object to
2632 which the initialization applies. TRUE_EXP is the true object we
2633 are initializing, and DECL_PTR is the pointer to the sub-object we
2636 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
2637 object was laid out by a top-level constructor and the computed
2638 offsets are valid to store vtables. When zero, we must store new
2639 vtables through virtual baseclass pointers. */
2642 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
)
2644 tree true_exp
, decl_ptr
;
2646 tree type
= BINFO_TYPE (binfo
);
2648 /* This function executes during the finish_function() segment,
2649 AFTER the auto variables and temporary stack space has been marked
2650 unused...If space is needed for the virtual function tables,
2651 some of them might fit within what the compiler now thinks
2652 are available stack slots... These values are actually initialized at
2653 the beginnning of the function, so when the automatics use their space,
2654 they will overwrite the values that are placed here. Marking all
2655 temporary space as unavailable prevents this from happening. */
2657 mark_all_temps_used();
2659 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2661 rtx fixup_insns
= NULL_RTX
;
2662 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
2663 struct vbase_info vi
;
2664 vi
.decl_ptr
= (true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0)
2666 vi
.vbase_types
= vbases
;
2668 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
, &vi
);
2670 /* Initialized with vtables of type TYPE. */
2671 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
2675 addr
= convert_pointer_to_vbase (TREE_TYPE (vbases
), vi
.decl_ptr
);
2677 /* Do all vtables from this virtual base. */
2678 /* This assumes that virtual bases can never serve as parent
2679 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
2680 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
2683 /* Now we adjust the offsets for virtual functions that
2684 cross virtual boundaries on an implicit upcast on vf call
2685 so that the layout of the most complete type is used,
2686 instead of assuming the layout of the virtual bases from
2687 our current type. */
2689 if (flag_vtable_thunks
)
2691 /* We don't have dynamic thunks yet!
2692 So for now, just fail silently. */
2696 tree vbase_offsets
= NULL_TREE
;
2697 push_to_sequence (fixup_insns
);
2698 fixup_virtual_upcast_offsets (vbases
,
2699 TYPE_BINFO (BINFO_TYPE (vbases
)),
2700 1, 0, addr
, vi
.decl_ptr
,
2701 type
, vbases
, &vbase_offsets
);
2702 fixup_insns
= get_insns ();
2709 extern tree in_charge_identifier
;
2710 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
2711 if (! in_charge_node
)
2713 warning ("recoverable internal compiler error, nobody's in charge!");
2714 in_charge_node
= integer_zero_node
;
2716 in_charge_node
= build_binary_op (EQ_EXPR
, in_charge_node
, integer_zero_node
, 1);
2717 expand_start_cond (in_charge_node
, 0);
2718 emit_insns (fixup_insns
);
2722 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
, 0);
2726 /* get virtual base class types.
2727 This adds type to the vbase_types list in reverse dfs order.
2728 Ordering is very important, so don't change it. */
2731 dfs_get_vbase_types (binfo
, data
)
2735 tree
*vbase_types
= (tree
*) data
;
2737 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
2739 tree new_vbase
= make_binfo (integer_zero_node
, binfo
,
2740 BINFO_VTABLE (binfo
),
2741 BINFO_VIRTUALS (binfo
));
2742 TREE_CHAIN (new_vbase
) = *vbase_types
;
2743 TREE_VIA_VIRTUAL (new_vbase
) = 1;
2744 *vbase_types
= new_vbase
;
2745 SET_BINFO_VBASE_MARKED (binfo
);
2747 SET_BINFO_MARKED (binfo
);
2751 /* Return a list of binfos for the virtual base classes for TYPE, in
2752 depth-first search order. The list is freshly allocated, so
2753 no modification is made to the current binfo hierarchy. */
2756 get_vbase_types (type
)
2763 binfo
= TYPE_BINFO (type
);
2764 vbase_types
= NULL_TREE
;
2765 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
, &vbase_types
);
2766 dfs_walk (binfo
, dfs_unmark
, markedp
, 0);
2767 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2768 reverse it so that we get normal dfs ordering. */
2769 vbase_types
= nreverse (vbase_types
);
2771 /* unmark marked vbases */
2772 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
2773 CLEAR_BINFO_VBASE_MARKED (vbases
);
2778 /* If we want debug info for a type TYPE, make sure all its base types
2779 are also marked as being potentially interesting. This avoids
2780 the problem of not writing any debug info for intermediate basetypes
2781 that have abstract virtual functions. Also mark member types. */
2784 note_debug_info_needed (type
)
2789 if (current_template_parms
)
2792 if (TYPE_BEING_DEFINED (type
))
2793 /* We can't go looking for the base types and fields just yet. */
2796 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2797 does not support name references between translation units. Well, we
2798 could, but that would mean putting global labels in the debug output
2799 before each exported type and each of its functions and static data
2801 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2804 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
, 0);
2805 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2808 if (TREE_CODE (field
) == FIELD_DECL
2809 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
2810 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
), 0))
2811 note_debug_info_needed (ttype
);
2815 /* Subroutines of push_class_decls (). */
2817 /* Add in a decl to the envelope. */
2819 envelope_add_decl (type
, decl
, values
)
2820 tree type
, decl
, *values
;
2823 tree name
= DECL_NAME (decl
);
2826 /* Yet Another Implicit Typename Kludge: Since we don't tsubst
2827 the members for partial instantiations, DECL_CONTEXT (decl) is wrong.
2828 But pretend it's right for this function. */
2829 if (processing_template_decl
)
2830 type
= DECL_REAL_CONTEXT (decl
);
2832 /* virtual base names are always unique. */
2833 if (VBASE_NAME_P (name
))
2834 *values
= NULL_TREE
;
2836 /* Possible ambiguity. If its defining type(s)
2837 is (are all) derived from us, no problem. */
2838 else if (*values
&& TREE_CODE (*values
) != TREE_LIST
)
2840 tree value
= *values
;
2841 /* Only complain if we shadow something we can access. */
2842 if (warn_shadow
&& TREE_CODE (decl
) == FUNCTION_DECL
2843 && ((DECL_LANG_SPECIFIC (*values
)
2844 && DECL_CLASS_CONTEXT (value
) == current_class_type
)
2845 || ! TREE_PRIVATE (value
)))
2846 /* Should figure out access control more accurately. */
2848 cp_warning_at ("member `%#D' is shadowed", value
);
2849 cp_warning_at ("by member function `%#D'", decl
);
2850 warning ("in this context");
2853 context
= DECL_REAL_CONTEXT (value
);
2855 if (context
== type
)
2857 if (TREE_CODE (value
) == TYPE_DECL
2858 && DECL_ARTIFICIAL (value
))
2859 *values
= NULL_TREE
;
2863 else if (type
== current_class_type
2864 || DERIVED_FROM_P (context
, type
))
2866 /* Don't add in *values to list */
2867 *values
= NULL_TREE
;
2870 *values
= build_tree_list (NULL_TREE
, value
);
2873 for (tmp
= values
; *tmp
;)
2875 tree value
= TREE_VALUE (*tmp
);
2876 my_friendly_assert (TREE_CODE (value
) != TREE_LIST
, 999);
2877 context
= (TREE_CODE (value
) == FUNCTION_DECL
2878 && DECL_VIRTUAL_P (value
))
2879 ? DECL_CLASS_CONTEXT (value
)
2880 : DECL_CONTEXT (value
);
2882 if (type
== current_class_type
2883 || DERIVED_FROM_P (context
, type
))
2885 /* remove *tmp from list */
2886 *tmp
= TREE_CHAIN (*tmp
);
2889 tmp
= &TREE_CHAIN (*tmp
);
2894 /* Put the new contents in our envelope. */
2895 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2897 *values
= tree_cons (name
, decl
, *values
);
2898 TREE_NONLOCAL_FLAG (*values
) = 1;
2899 TREE_TYPE (*values
) = unknown_type_node
;
2905 *values
= tree_cons (NULL_TREE
, decl
, *values
);
2906 /* Mark this as a potentially ambiguous member. */
2907 /* Leaving TREE_TYPE blank is intentional.
2908 We cannot use `error_mark_node' (lookup_name)
2909 or `unknown_type_node' (all member functions use this). */
2910 TREE_NONLOCAL_FLAG (*values
) = 1;
2918 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2919 because it (or one of the intermediate bases) depends on template parms. */
2922 dependent_base_p (binfo
)
2925 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2927 if (currently_open_class (TREE_TYPE (binfo
)))
2929 if (uses_template_parms (TREE_TYPE (binfo
)))
2935 /* Add the instance variables which this class contributed to the
2936 current class binding contour. When a redefinition occurs, if the
2937 redefinition is strictly within a single inheritance path, we just
2938 overwrite the old declaration with the new. If the fields are not
2939 within a single inheritance path, we must cons them.
2941 In order to know what decls are new (stemming from the current
2942 invocation of push_class_decls) we enclose them in an "envelope",
2943 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
2944 new decl (or possibly a list of competing ones), the TREE_VALUE slot
2945 points to the old value and the TREE_CHAIN slot chains together all
2946 envelopes which needs to be "opened" in push_class_decls. Opening an
2947 envelope means: push the old value onto the class_shadowed list,
2948 install the new one and if it's a TYPE_DECL do the same to the
2949 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
2950 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
2951 Because if it is, it could be a set of overloaded methods from an
2955 dfs_pushdecls (binfo
, data
)
2959 tree
*closed_envelopes
= (tree
*) data
;
2960 tree type
= BINFO_TYPE (binfo
);
2965 /* Only record types if we're a template base. */
2966 if (processing_template_decl
&& type
!= current_class_type
2967 && dependent_base_p (binfo
))
2970 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2972 if (dummy
&& TREE_CODE (fields
) != TYPE_DECL
)
2975 /* Unmark so that if we are in a constructor, and then find that
2976 this field was initialized by a base initializer,
2977 we can emit an error message. */
2978 if (TREE_CODE (fields
) == FIELD_DECL
)
2979 TREE_USED (fields
) = 0;
2981 /* Recurse into anonymous unions. */
2982 if (DECL_NAME (fields
) == NULL_TREE
2983 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
2985 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields
)), data
);
2989 if (DECL_NAME (fields
))
2991 tree name
= DECL_NAME (fields
);
2992 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
2994 /* If the class value is not an envelope of the kind described in
2995 the comment above, we create a new envelope. */
2996 maybe_push_cache_obstack ();
2997 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
2998 || TREE_PURPOSE (class_value
) == NULL_TREE
2999 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3001 /* See comment above for a description of envelopes. */
3002 *closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3004 IDENTIFIER_CLASS_VALUE (name
) = *closed_envelopes
;
3005 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3008 envelope_add_decl (type
, fields
, &TREE_PURPOSE (class_value
));
3013 method_vec
= CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
3014 if (method_vec
&& ! dummy
)
3019 /* Farm out constructors and destructors. */
3020 end
= TREE_VEC_END (method_vec
);
3022 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3023 *methods
&& methods
!= end
;
3026 /* This will cause lookup_name to return a pointer
3027 to the tree_list of possible methods of this name. */
3032 name
= DECL_NAME (OVL_CURRENT (*methods
));
3033 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3035 maybe_push_cache_obstack ();
3037 /* If the class value is not an envelope of the kind described in
3038 the comment above, we create a new envelope. */
3039 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3040 || TREE_PURPOSE (class_value
) == NULL_TREE
3041 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3043 /* See comment above for a description of envelopes. */
3044 *closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3046 IDENTIFIER_CLASS_VALUE (name
) = *closed_envelopes
;
3047 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3050 /* Here we try to rule out possible ambiguities.
3051 If we can't do that, keep a TREE_LIST with possibly ambiguous
3053 /* Arbitrarily choose the first function in the list. This is OK
3054 because this is only used for initial lookup; anything that
3055 actually uses the function will look it up again. */
3056 envelope_add_decl (type
, OVL_CURRENT (*methods
),
3057 &TREE_PURPOSE (class_value
));
3062 /* We can't just use BINFO_MARKED because envelope_add_decl uses
3063 DERIVED_FROM_P, which calls get_base_distance. */
3064 SET_BINFO_PUSHDECLS_MARKED (binfo
);
3069 /* Consolidate unique (by name) member functions. */
3072 dfs_compress_decls (binfo
, data
)
3074 void *data ATTRIBUTE_UNUSED
;
3076 tree type
= BINFO_TYPE (binfo
);
3078 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
3080 if (processing_template_decl
&& type
!= current_class_type
3081 && dependent_base_p (binfo
))
3082 /* We only record types if we're a template base. */;
3083 else if (method_vec
!= 0)
3085 /* Farm out constructors and destructors. */
3087 tree
*end
= TREE_VEC_END (method_vec
);
3089 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3090 methods
!= end
&& *methods
; methods
++)
3092 /* This is known to be an envelope of the kind described before
3095 IDENTIFIER_CLASS_VALUE (DECL_NAME (OVL_CURRENT (*methods
)));
3096 tree tmp
= TREE_PURPOSE (class_value
);
3098 /* This was replaced in scope by somebody else. Just leave it
3100 if (TREE_CODE (tmp
) != TREE_LIST
)
3103 if (TREE_CHAIN (tmp
) == NULL_TREE
3105 && OVL_NEXT (TREE_VALUE (tmp
)) == NULL_TREE
)
3107 TREE_PURPOSE (class_value
) = TREE_VALUE (tmp
);
3111 CLEAR_BINFO_PUSHDECLS_MARKED (binfo
);
3116 /* When entering the scope of a class, we cache all of the
3117 fields that that class provides within its inheritance
3118 lattice. Where ambiguities result, we mark them
3119 with `error_mark_node' so that if they are encountered
3120 without explicit qualification, we can emit an error
3124 push_class_decls (type
)
3127 struct obstack
*ambient_obstack
= current_obstack
;
3128 tree closed_envelopes
= NULL_TREE
;
3129 search_stack
= push_search_level (search_stack
, &search_obstack
);
3131 /* Build up all the relevant bindings and such on the cache
3132 obstack. That way no memory is wasted when we throw away the
3134 maybe_push_cache_obstack ();
3136 /* Push class fields into CLASS_VALUE scope, and mark. */
3137 dfs_walk (TYPE_BINFO (type
), dfs_pushdecls
, unmarked_pushdecls_p
,
3140 /* Compress fields which have only a single entry
3141 by a given name, and unmark. */
3142 dfs_walk (TYPE_BINFO (type
), dfs_compress_decls
, marked_pushdecls_p
,
3145 /* Open up all the closed envelopes and push the contained decls into
3147 while (closed_envelopes
)
3149 tree
new = TREE_PURPOSE (closed_envelopes
);
3152 /* This is messy because the class value may be a *_DECL, or a
3153 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3154 *_DECLs. The name is stored at different places in these three
3156 if (TREE_CODE (new) == TREE_LIST
)
3158 if (TREE_PURPOSE (new) != NULL_TREE
)
3159 id
= TREE_PURPOSE (new);
3162 tree node
= TREE_VALUE (new);
3164 if (TREE_CODE (node
) == TYPE_DECL
3165 && DECL_ARTIFICIAL (node
)
3166 && IS_AGGR_TYPE (TREE_TYPE (node
))
3167 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (node
)))
3169 tree t
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (node
));
3172 for (; n
; n
= TREE_CHAIN (n
))
3174 tree d
= TREE_VALUE (n
);
3175 if (TREE_CODE (d
) == TYPE_DECL
3176 && DECL_ARTIFICIAL (node
)
3177 && IS_AGGR_TYPE (TREE_TYPE (d
))
3178 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (d
))
3179 && CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d
)) == t
)
3188 else while (TREE_CODE (node
) == TREE_LIST
)
3189 node
= TREE_VALUE (node
);
3190 id
= DECL_NAME (node
);
3194 id
= DECL_NAME (new);
3196 /* Install the original class value in order to make
3197 pushdecl_class_level work correctly. */
3198 IDENTIFIER_CLASS_VALUE (id
) = TREE_VALUE (closed_envelopes
);
3199 if (TREE_CODE (new) == TREE_LIST
)
3200 push_class_level_binding (id
, new);
3202 pushdecl_class_level (new);
3203 closed_envelopes
= TREE_CHAIN (closed_envelopes
);
3206 /* Undo the call to maybe_push_cache_obstack above. */
3209 current_obstack
= ambient_obstack
;
3212 /* Here's a subroutine we need because C lacks lambdas. */
3215 dfs_unuse_fields (binfo
, data
)
3217 void *data ATTRIBUTE_UNUSED
;
3219 tree type
= TREE_TYPE (binfo
);
3222 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3224 if (TREE_CODE (fields
) != FIELD_DECL
)
3227 TREE_USED (fields
) = 0;
3228 if (DECL_NAME (fields
) == NULL_TREE
3229 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3230 unuse_fields (TREE_TYPE (fields
));
3240 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
, 0);
3246 /* We haven't pushed a search level when dealing with cached classes,
3247 so we'd better not try to pop it. */
3249 search_stack
= pop_search_level (search_stack
);
3253 print_search_statistics ()
3255 #ifdef GATHER_STATISTICS
3256 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3257 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3258 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3259 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3260 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3261 #else /* GATHER_STATISTICS */
3262 fprintf (stderr
, "no search statistics\n");
3263 #endif /* GATHER_STATISTICS */
3267 init_search_processing ()
3269 gcc_obstack_init (&search_obstack
);
3270 _vptr_name
= get_identifier ("_vptr");
3274 reinit_search_statistics ()
3276 #ifdef GATHER_STATISTICS
3277 n_fields_searched
= 0;
3278 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3279 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3280 n_calls_get_base_type
= 0;
3281 n_outer_fields_searched
= 0;
3282 n_contexts_saved
= 0;
3283 #endif /* GATHER_STATISTICS */
3286 #define scratch_tree_cons expr_tree_cons
3289 add_conversions (binfo
, data
)
3294 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3295 tree
*conversions
= (tree
*) data
;
3297 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3299 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3302 if (!tmp
|| ! DECL_CONV_FN_P (OVL_CURRENT (tmp
)))
3305 name
= DECL_NAME (OVL_CURRENT (tmp
));
3307 /* Make sure we don't already have this conversion. */
3308 if (! IDENTIFIER_MARKED (name
))
3310 *conversions
= scratch_tree_cons (binfo
, tmp
, *conversions
);
3311 IDENTIFIER_MARKED (name
) = 1;
3318 lookup_conversions (type
)
3322 tree conversions
= NULL_TREE
;
3324 if (TYPE_SIZE (type
))
3325 bfs_walk (TYPE_BINFO (type
), add_conversions
, 0, &conversions
);
3327 for (t
= conversions
; t
; t
= TREE_CHAIN (t
))
3328 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t
)))) = 0;
3339 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3340 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3343 dfs_check_overlap (empty_binfo
, data
)
3347 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3349 for (binfo
= TYPE_BINFO (oi
->compare_type
);
3351 binfo
= BINFO_BASETYPE (binfo
, 0))
3353 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3355 oi
->found_overlap
= 1;
3358 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3365 /* Trivial function to stop base traversal when we find something. */
3368 dfs_no_overlap_yet (binfo
, data
)
3372 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3373 return !oi
->found_overlap
? binfo
: NULL_TREE
;
3376 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3377 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3380 types_overlap_p (empty_type
, next_type
)
3381 tree empty_type
, next_type
;
3383 struct overlap_info oi
;
3385 if (! IS_AGGR_TYPE (next_type
))
3387 oi
.compare_type
= next_type
;
3388 oi
.found_overlap
= 0;
3389 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
,
3390 dfs_no_overlap_yet
, &oi
);
3391 return oi
.found_overlap
;
3400 dfs_bfv_queue_p (binfo
, data
)
3404 struct bfv_info
*bfvi
= (struct bfv_info
*) data
;
3406 /* Use the real virtual base class objects, not the placeholders in
3407 the usual hierarchy. */
3408 if (TREE_VIA_VIRTUAL (binfo
))
3409 return binfo_member (BINFO_TYPE (binfo
), bfvi
->vbases
);
3414 /* Passed to dfs_walk_real by binfo_for_vtable; determine if bvtable
3415 comes from BINFO. */
3418 dfs_bfv_helper (binfo
, data
)
3422 struct bfv_info
*bfvi
= (struct bfv_info
*) data
;
3424 if (BINFO_VTABLE (binfo
) == bfvi
->var
)
3429 /* Given a vtable VAR, determine which binfo it comes from. */
3432 binfo_for_vtable (var
)
3436 struct bfv_info bfvi
;
3438 type
= DECL_CONTEXT (var
);
3439 bfvi
.vbases
= CLASSTYPE_VBASECLASSES (type
);
3440 return dfs_walk_real (TYPE_BINFO (type
),
3441 0, dfs_bfv_helper
, dfs_bfv_queue_p
, &bfvi
);