1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 89, 92-97, 1998, 1999 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* High-level class interface. */
35 #define obstack_chunk_alloc xmalloc
36 #define obstack_chunk_free free
38 extern struct obstack
*current_obstack
;
42 /* Obstack used for remembering decision points of breadth-first. */
44 static struct obstack search_obstack
;
46 /* Methods for pushing and popping objects to and from obstacks. */
49 push_stack_level (obstack
, tp
, size
)
50 struct obstack
*obstack
;
51 char *tp
; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
54 struct stack_level
*stack
;
55 obstack_grow (obstack
, tp
, size
);
56 stack
= (struct stack_level
*) ((char*)obstack_next_free (obstack
) - size
);
57 obstack_finish (obstack
);
58 stack
->obstack
= obstack
;
59 stack
->first
= (tree
*) obstack_base (obstack
);
60 stack
->limit
= obstack_room (obstack
) / sizeof (tree
*);
65 pop_stack_level (stack
)
66 struct stack_level
*stack
;
68 struct stack_level
*tem
= stack
;
69 struct obstack
*obstack
= tem
->obstack
;
71 obstack_free (obstack
, tem
);
75 #define search_level stack_level
76 static struct search_level
*search_stack
;
78 static tree get_abstract_virtuals_1
PROTO((tree
, int, tree
));
79 static tree next_baselink
PROTO((tree
));
80 static tree get_vbase_1
PROTO((tree
, tree
, unsigned int *));
81 static tree convert_pointer_to_vbase
PROTO((tree
, tree
));
82 static tree lookup_field_1
PROTO((tree
, tree
));
83 static tree convert_pointer_to_single_level
PROTO((tree
, tree
));
84 static int lookup_fnfields_here
PROTO((tree
, tree
));
85 static int is_subobject_of_p
PROTO((tree
, tree
));
86 static int hides
PROTO((tree
, tree
));
87 static tree virtual_context
PROTO((tree
, tree
, tree
));
88 static tree dfs_check_overlap
PROTO((tree
, void *));
89 static tree dfs_no_overlap_yet
PROTO((tree
, void *));
90 static int get_base_distance_recursive
91 PROTO((tree
, int, int, int, int *, tree
*, tree
,
92 int, int *, int, int));
93 static void expand_upcast_fixups
94 PROTO((tree
, tree
, tree
, tree
, tree
, tree
, tree
*));
95 static void fixup_virtual_upcast_offsets
96 PROTO((tree
, tree
, int, int, tree
, tree
, tree
, tree
,
98 static tree unmarkedp
PROTO((tree
, void *));
99 static tree marked_vtable_pathp
PROTO((tree
, void *));
100 static tree unmarked_vtable_pathp
PROTO((tree
, void *));
101 static tree marked_new_vtablep
PROTO((tree
, void *));
102 static tree unmarked_new_vtablep
PROTO((tree
, void *));
103 static tree marked_pushdecls_p
PROTO((tree
, void *));
104 static tree unmarked_pushdecls_p
PROTO((tree
, void *));
105 static tree dfs_debug_unmarkedp
PROTO((tree
, void *));
106 static tree dfs_debug_mark
PROTO((tree
, void *));
107 static tree dfs_find_vbases
PROTO((tree
, void *));
108 static tree dfs_clear_vbase_slots
PROTO((tree
, void *));
109 static tree dfs_init_vbase_pointers
PROTO((tree
, void *));
110 static tree dfs_get_vbase_types
PROTO((tree
, void *));
111 static tree dfs_push_type_decls
PROTO((tree
, void *));
112 static tree dfs_push_decls
PROTO((tree
, void *));
113 static tree dfs_unuse_fields
PROTO((tree
, void *));
114 static tree add_conversions
PROTO((tree
, void *));
115 static tree get_virtuals_named_this
PROTO((tree
, tree
));
116 static tree get_virtual_destructor
PROTO((tree
, void *));
117 static tree tree_has_any_destructor_p
PROTO((tree
, void *));
118 static int covariant_return_p
PROTO((tree
, tree
));
119 static int check_final_overrider
PROTO((tree
, tree
));
120 static struct search_level
*push_search_level
121 PROTO((struct stack_level
*, struct obstack
*));
122 static struct search_level
*pop_search_level
123 PROTO((struct stack_level
*));
125 PROTO((tree
, tree (*) (tree
, void *), tree (*) (tree
, void *),
127 static tree lookup_field_queue_p
PROTO((tree
, void *));
128 static tree lookup_field_r
PROTO((tree
, void *));
129 static tree dfs_walk_real
PROTO ((tree
,
130 tree (*) (tree
, void *),
131 tree (*) (tree
, void *),
132 tree (*) (tree
, void *),
134 static tree get_virtuals_named_this_r
PROTO ((tree
, void *));
135 static tree context_for_name_lookup
PROTO ((tree
));
136 static tree canonical_binfo
PROTO ((tree
));
137 static tree shared_marked_p
PROTO ((tree
, void *));
138 static tree shared_unmarked_p
PROTO ((tree
, void *));
139 static int dependent_base_p
PROTO ((tree
));
140 static tree dfs_accessible_queue_p
PROTO ((tree
, void *));
141 static tree dfs_accessible_p
PROTO ((tree
, void *));
142 static tree dfs_access_in_type
PROTO ((tree
, void *));
143 static tree access_in_type
PROTO ((tree
, tree
));
144 static tree dfs_canonical_queue
PROTO ((tree
, void *));
145 static tree dfs_assert_unmarked_p
PROTO ((tree
, void *));
146 static void assert_canonical_unmarked
PROTO ((tree
));
147 static int protected_accessible_p
PROTO ((tree
, tree
, tree
, tree
));
148 static int friend_accessible_p
PROTO ((tree
, tree
, tree
, tree
));
149 static void setup_class_bindings
PROTO ((tree
, int));
150 static int template_self_reference_p
PROTO ((tree
, tree
));
152 /* Allocate a level of searching. */
154 static struct search_level
*
155 push_search_level (stack
, obstack
)
156 struct stack_level
*stack
;
157 struct obstack
*obstack
;
159 struct search_level tem
;
162 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
165 /* Discard a level of search allocation. */
167 static struct search_level
*
168 pop_search_level (obstack
)
169 struct stack_level
*obstack
;
171 register struct search_level
*stack
= pop_stack_level (obstack
);
176 /* Variables for gathering statistics. */
177 #ifdef GATHER_STATISTICS
178 static int n_fields_searched
;
179 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
180 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
181 static int n_calls_get_base_type
;
182 static int n_outer_fields_searched
;
183 static int n_contexts_saved
;
184 #endif /* GATHER_STATISTICS */
187 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
188 the same type as the type given in PARENT. To be optimal, we want
189 the first one that is found by going through the least number of
192 This uses a clever algorithm that updates *depth when we find the vbase,
193 and cuts off other paths of search when they reach that depth. */
196 get_vbase_1 (parent
, binfo
, depth
)
202 tree rval
= NULL_TREE
;
204 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
212 binfos
= BINFO_BASETYPES (binfo
);
213 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
215 /* Process base types. */
216 for (i
= 0; i
< n_baselinks
; i
++)
218 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
224 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
232 /* Return the shortest path to vbase PARENT within BINFO, ignoring
233 access and ambiguity. */
236 get_vbase (parent
, binfo
)
240 unsigned int d
= (unsigned int)-1;
241 return get_vbase_1 (parent
, binfo
, &d
);
244 /* Convert EXPR to a virtual base class of type TYPE. We know that
245 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
246 the type of what expr points to has a virtual base of type TYPE. */
249 convert_pointer_to_vbase (type
, expr
)
253 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
254 return convert_pointer_to_real (vb
, expr
);
257 /* Check whether the type given in BINFO is derived from PARENT. If
258 it isn't, return 0. If it is, but the derivation is MI-ambiguous
259 AND protect != 0, emit an error message and return error_mark_node.
261 Otherwise, if TYPE is derived from PARENT, return the actual base
262 information, unless a one of the protection violations below
263 occurs, in which case emit an error message and return error_mark_node.
265 If PROTECT is 1, then check if access to a public field of PARENT
266 would be private. Also check for ambiguity. */
269 get_binfo (parent
, binfo
, protect
)
270 register tree parent
, binfo
;
273 tree type
= NULL_TREE
;
275 tree rval
= NULL_TREE
;
277 if (TREE_CODE (parent
) == TREE_VEC
)
278 parent
= BINFO_TYPE (parent
);
279 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
280 my_friendly_abort (89);
282 if (TREE_CODE (binfo
) == TREE_VEC
)
283 type
= BINFO_TYPE (binfo
);
284 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
287 my_friendly_abort (90);
289 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
293 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
295 return error_mark_node
;
297 else if (dist
== -2 && protect
)
299 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
301 return error_mark_node
;
307 /* This is the newer depth first get_base_distance routine. */
310 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
311 rval_private_ptr
, new_binfo_ptr
, parent
,
312 protect
, via_virtual_ptr
, via_virtual
,
313 current_scope_in_chain
)
315 int depth
, is_private
, rval
;
316 int *rval_private_ptr
;
317 tree
*new_binfo_ptr
, parent
;
318 int protect
, *via_virtual_ptr
, via_virtual
;
319 int current_scope_in_chain
;
325 && !current_scope_in_chain
326 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
327 current_scope_in_chain
= 1;
329 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
334 /* This is the first time we've found parent. */
336 else if (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
337 BINFO_OFFSET (binfo
))
338 && *via_virtual_ptr
&& via_virtual
)
340 /* A new path to the same vbase. If this one has better
341 access or is shorter, take it. */
344 better
= *rval_private_ptr
- is_private
;
346 better
= rval
- depth
;
350 /* Ambiguous base class. */
353 /* If we get an ambiguity between virtual and non-virtual base
354 class, return the non-virtual in case we are ignoring
356 better
= *via_virtual_ptr
- via_virtual
;
362 *rval_private_ptr
= is_private
;
363 *new_binfo_ptr
= binfo
;
364 *via_virtual_ptr
= via_virtual
;
370 binfos
= BINFO_BASETYPES (binfo
);
371 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
374 /* Process base types. */
375 for (i
= 0; i
< n_baselinks
; i
++)
377 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
382 || (!TREE_VIA_PUBLIC (base_binfo
)
383 && !(TREE_VIA_PROTECTED (base_binfo
)
384 && current_scope_in_chain
)
385 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
386 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
388 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
389 rval
, rval_private_ptr
,
390 new_binfo_ptr
, parent
,
391 protect
, via_virtual_ptr
,
393 current_scope_in_chain
);
395 /* If we've found a non-virtual, ambiguous base class, we don't need
396 to keep searching. */
397 if (rval
== -2 && *via_virtual_ptr
== 0)
404 /* Return the number of levels between type PARENT and the type given
405 in BINFO, following the leftmost path to PARENT not found along a
406 virtual path, if there are no real PARENTs (all come from virtual
407 base classes), then follow the shortest public path to PARENT.
409 Return -1 if TYPE is not derived from PARENT.
410 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
412 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
414 If PATH_PTR is non-NULL, then also build the list of types
415 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
418 PARENT can also be a binfo, in which case that exact parent is found
419 and no other. convert_pointer_to_real uses this functionality.
421 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
424 get_base_distance (parent
, binfo
, protect
, path_ptr
)
425 register tree parent
, binfo
;
430 int rval_private
= 0;
431 tree type
= NULL_TREE
;
432 tree new_binfo
= NULL_TREE
;
434 int watch_access
= protect
;
436 /* Should we be completing types here? */
437 if (TREE_CODE (parent
) != TREE_VEC
)
438 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
440 complete_type (TREE_TYPE (parent
));
442 if (TREE_CODE (binfo
) == TREE_VEC
)
443 type
= BINFO_TYPE (binfo
);
444 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
446 type
= complete_type (binfo
);
447 binfo
= TYPE_BINFO (type
);
450 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
,
454 my_friendly_abort (92);
456 if (parent
== type
|| parent
== binfo
)
458 /* If the distance is 0, then we don't really need
459 a path pointer, but we shouldn't let garbage go back. */
468 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
469 &rval_private
, &new_binfo
, parent
,
470 watch_access
, &via_virtual
, 0,
473 /* Access restrictions don't count if we found an ambiguous basetype. */
474 if (rval
== -2 && protect
>= 0)
477 if (rval
&& protect
&& rval_private
)
480 /* If they gave us the real vbase binfo, which isn't in the main binfo
481 tree, deal with it. This happens when we are called from
482 expand_upcast_fixups. */
483 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
484 && parent
== binfo_member (BINFO_TYPE (parent
),
485 CLASSTYPE_VBASECLASSES (type
)))
487 my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent
) == binfo
, 980827);
493 *path_ptr
= new_binfo
;
497 /* Search for a member with name NAME in a multiple inheritance lattice
498 specified by TYPE. If it does not exist, return NULL_TREE.
499 If the member is ambiguously referenced, return `error_mark_node'.
500 Otherwise, return the FIELD_DECL. */
502 /* Do a 1-level search for NAME as a member of TYPE. The caller must
503 figure out whether it can access this field. (Since it is only one
504 level, this is reasonable.) */
507 lookup_field_1 (type
, name
)
512 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
513 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
514 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
515 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
516 the code often worked even when we treated the index as a list
521 && DECL_LANG_SPECIFIC (TYPE_NAME (type
))
522 && DECL_SORTED_FIELDS (TYPE_NAME (type
)))
524 tree
*fields
= &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type
)), 0);
525 int lo
= 0, hi
= TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type
)));
532 #ifdef GATHER_STATISTICS
534 #endif /* GATHER_STATISTICS */
536 if (DECL_NAME (fields
[i
]) > name
)
538 else if (DECL_NAME (fields
[i
]) < name
)
546 field
= TYPE_FIELDS (type
);
548 #ifdef GATHER_STATISTICS
549 n_calls_lookup_field_1
++;
550 #endif /* GATHER_STATISTICS */
553 #ifdef GATHER_STATISTICS
555 #endif /* GATHER_STATISTICS */
556 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
557 if (DECL_NAME (field
) == NULL_TREE
558 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
560 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
564 if (TREE_CODE (field
) == USING_DECL
)
565 /* For now, we're just treating member using declarations as
566 old ARM-style access declarations. Thus, there's no reason
567 to return a USING_DECL, and the rest of the compiler can't
568 handle it. Once the class is defined, these are purged
569 from TYPE_FIELDS anyhow; see handle_using_decl. */
571 else if (DECL_NAME (field
) == name
)
573 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
574 && DECL_ASSEMBLER_NAME (field
) != NULL
)
575 GNU_xref_ref(current_function_decl
,
576 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
579 field
= TREE_CHAIN (field
);
582 if (name
== vptr_identifier
)
584 /* Give the user what s/he thinks s/he wants. */
585 if (TYPE_VIRTUAL_P (type
))
586 return CLASSTYPE_VFIELD (type
);
591 /* There are a number of cases we need to be aware of here:
592 current_class_type current_function_decl
599 Those last two make life interesting. If we're in a function which is
600 itself inside a class, we need decls to go into the fn's decls (our
601 second case below). But if we're in a class and the class itself is
602 inside a function, we need decls to go into the decls for the class. To
603 achieve this last goal, we must see if, when both current_class_ptr and
604 current_function_decl are set, the class was declared inside that
605 function. If so, we know to put the decls into the class's scope. */
610 if (current_function_decl
== NULL_TREE
)
611 return current_class_type
;
612 if (current_class_type
== NULL_TREE
)
613 return current_function_decl
;
614 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
615 return current_function_decl
;
617 return current_class_type
;
620 /* Returns non-zero if we are currently in a function scope. Note
621 that this function returns zero if we are within a local class, but
622 not within a member function body of the local class. */
625 at_function_scope_p ()
627 tree cs
= current_scope ();
628 return cs
&& TREE_CODE (cs
) == FUNCTION_DECL
;
631 /* Return the scope of DECL, as appropriate when doing name-lookup. */
634 context_for_name_lookup (decl
)
639 For the purposes of name lookup, after the anonymous union
640 definition, the members of the anonymous union are considered to
641 have been defined in the scope in which teh anonymous union is
643 tree context
= DECL_REAL_CONTEXT (decl
);
645 while (TYPE_P (context
) && ANON_AGGR_TYPE_P (context
))
646 context
= TYPE_CONTEXT (context
);
648 context
= global_namespace
;
653 /* Return a canonical BINFO if BINFO is a virtual base, or just BINFO
657 canonical_binfo (binfo
)
660 return (TREE_VIA_VIRTUAL (binfo
)
661 ? TYPE_BINFO (BINFO_TYPE (binfo
)) : binfo
);
664 /* A queue function that simply ensures that we walk into the
665 canonical versions of virtual bases. */
668 dfs_canonical_queue (binfo
, data
)
670 void *data ATTRIBUTE_UNUSED
;
672 return canonical_binfo (binfo
);
675 /* Called via dfs_walk from assert_canonical_unmarked. */
678 dfs_assert_unmarked_p (binfo
, data
)
680 void *data ATTRIBUTE_UNUSED
;
682 my_friendly_assert (!BINFO_MARKED (binfo
), 0);
686 /* Asserts that all the nodes below BINFO (using the canonical
687 versions of virtual bases) are unmarked. */
690 assert_canonical_unmarked (binfo
)
693 dfs_walk (binfo
, dfs_assert_unmarked_p
, dfs_canonical_queue
, 0);
696 /* If BINFO is marked, return a canonical version of BINFO.
697 Otherwise, return NULL_TREE. */
700 shared_marked_p (binfo
, data
)
704 binfo
= canonical_binfo (binfo
);
705 return markedp (binfo
, data
) ? binfo
: NULL_TREE
;
708 /* If BINFO is not marked, return a canonical version of BINFO.
709 Otherwise, return NULL_TREE. */
712 shared_unmarked_p (binfo
, data
)
716 binfo
= canonical_binfo (binfo
);
717 return unmarkedp (binfo
, data
) ? binfo
: NULL_TREE
;
720 /* Called from access_in_type via dfs_walk. Calculate the access to
721 DATA (which is really a DECL) in BINFO. */
724 dfs_access_in_type (binfo
, data
)
728 tree decl
= (tree
) data
;
729 tree type
= BINFO_TYPE (binfo
);
730 tree access
= NULL_TREE
;
732 if (context_for_name_lookup (decl
) == type
)
734 /* If we have desceneded to the scope of DECL, just note the
735 appropriate access. */
736 if (TREE_PRIVATE (decl
))
737 access
= access_private_node
;
738 else if (TREE_PROTECTED (decl
))
739 access
= access_protected_node
;
741 access
= access_public_node
;
745 /* First, check for an access-declaration that gives us more
746 access to the DECL. The CONST_DECL for an enumeration
747 constant will not have DECL_LANG_SPECIFIC, and thus no
749 if (DECL_LANG_SPECIFIC (decl
))
751 access
= purpose_member (type
, DECL_ACCESS (decl
));
753 access
= TREE_VALUE (access
);
762 /* Otherwise, scan our baseclasses, and pick the most favorable
764 binfos
= BINFO_BASETYPES (binfo
);
765 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
766 for (i
= 0; i
< n_baselinks
; ++i
)
768 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
769 tree base_access
= TREE_CHAIN (canonical_binfo (base_binfo
));
771 if (!base_access
|| base_access
== access_private_node
)
772 /* If it was not accessible in the base, or only
773 accessible as a private member, we can't access it
775 base_access
= NULL_TREE
;
776 else if (TREE_VIA_PROTECTED (base_binfo
))
777 /* Public and protected members in the base are
779 base_access
= access_protected_node
;
780 else if (!TREE_VIA_PUBLIC (base_binfo
))
781 /* Public and protected members in the base are
783 base_access
= access_private_node
;
785 /* See if the new access, via this base, gives more
786 access than our previous best access. */
788 (base_access
== access_public_node
789 || (base_access
== access_protected_node
790 && access
!= access_public_node
)
791 || (base_access
== access_private_node
794 access
= base_access
;
796 /* If the new access is public, we can't do better. */
797 if (access
== access_public_node
)
804 /* Note the access to DECL in TYPE. */
805 TREE_CHAIN (binfo
) = access
;
807 /* Mark TYPE as visited so that if we reach it again we do not
808 duplicate our efforts here. */
809 SET_BINFO_MARKED (binfo
);
814 /* Return the access to DECL in TYPE. */
817 access_in_type (type
, decl
)
821 tree binfo
= TYPE_BINFO (type
);
823 /* We must take into account
827 If a name can be reached by several paths through a multiple
828 inheritance graph, the access is that of the path that gives
831 The algorithm we use is to make a post-order depth-first traversal
832 of the base-class hierarchy. As we come up the tree, we annotate
833 each node with the most lenient access. */
834 dfs_walk_real (binfo
, 0, dfs_access_in_type
, shared_unmarked_p
, decl
);
835 dfs_walk (binfo
, dfs_unmark
, shared_marked_p
, 0);
836 assert_canonical_unmarked (binfo
);
838 return TREE_CHAIN (binfo
);
841 /* Called from dfs_accessible_p via dfs_walk. */
844 dfs_accessible_queue_p (binfo
, data
)
846 void *data ATTRIBUTE_UNUSED
;
848 if (BINFO_MARKED (binfo
))
851 /* If this class is inherited via private or protected inheritance,
852 then we can't see it, unless we are a friend of the subclass. */
853 if (!TREE_VIA_PUBLIC (binfo
)
854 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
)),
858 return canonical_binfo (binfo
);
861 /* Called from dfs_accessible_p via dfs_walk. */
864 dfs_accessible_p (binfo
, data
)
868 int protected_ok
= data
!= 0;
871 /* We marked the binfos while computing the access in each type.
872 So, we unmark as we go now. */
873 SET_BINFO_MARKED (binfo
);
875 access
= TREE_CHAIN (binfo
);
876 if (access
== access_public_node
877 || (access
== access_protected_node
&& protected_ok
))
879 else if (access
&& is_friend (BINFO_TYPE (binfo
), current_scope ()))
885 /* Returns non-zero if it is OK to access DECL when named in TYPE
886 through an object indiated by BINFO in the context of DERIVED. */
889 protected_accessible_p (type
, decl
, derived
, binfo
)
897 /* We're checking this clause from [class.access.base]
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 If DERIVED isn't derived from TYPE, then it certainly does not
906 if (!DERIVED_FROM_P (type
, derived
))
909 access
= access_in_type (derived
, decl
);
910 if (same_type_p (derived
, type
))
912 if (access
!= access_private_node
)
915 else if (access
!= access_private_node
916 && access
!= access_protected_node
)
921 When a friend or a member function of a derived class references
922 a protected nonstatic member of a base class, an access check
923 applies in addition to those described earlier in clause
924 _class.access_.4) Except when forming a pointer to member
925 (_expr.unary.op_), the access must be through a pointer to,
926 reference to, or object of the derived class itself (or any class
927 derived from that class) (_expr.ref_). If the access is to form
928 a pointer to member, the nested-name-specifier shall name the
929 derived class (or any class derived from that class). */
930 if (DECL_NONSTATIC_MEMBER_P (decl
))
932 /* We can tell through what the reference is occurring by
933 chasing BINFO up to the root. */
935 while (BINFO_INHERITANCE_CHAIN (t
))
936 t
= BINFO_INHERITANCE_CHAIN (t
);
938 if (!DERIVED_FROM_P (derived
, BINFO_TYPE (t
)))
945 /* Returns non-zero if SCOPE is a friend of a type which would be able
946 to acces DECL, named in TYPE, through the object indicated by
950 friend_accessible_p (scope
, type
, decl
, binfo
)
956 tree befriending_classes
;
962 if (TREE_CODE (scope
) == FUNCTION_DECL
963 || DECL_FUNCTION_TEMPLATE_P (scope
))
964 befriending_classes
= DECL_BEFRIENDING_CLASSES (scope
);
965 else if (TYPE_P (scope
))
966 befriending_classes
= CLASSTYPE_BEFRIENDING_CLASSES (scope
);
970 for (t
= befriending_classes
; t
; t
= TREE_CHAIN (t
))
971 if (protected_accessible_p (type
, decl
, TREE_VALUE (t
), binfo
))
974 if (TREE_CODE (scope
) == FUNCTION_DECL
975 || DECL_FUNCTION_TEMPLATE_P (scope
))
977 /* Perhaps this SCOPE is a member of a class which is a
979 if (friend_accessible_p (DECL_CLASS_CONTEXT (scope
), type
,
983 /* Or an instantiation of something which is a friend. */
984 if (DECL_TEMPLATE_INFO (scope
))
985 return friend_accessible_p (DECL_TI_TEMPLATE (scope
),
988 else if (CLASSTYPE_TEMPLATE_INFO (scope
))
989 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope
),
995 /* DECL is a declaration from a base class of TYPE, which was the
996 classs used to name DECL. Return non-zero if, in the current
997 context, DECL is accessible. If TYPE is actually a BINFO node,
998 then we can tell in what context the access is occurring by looking
999 at the most derived class along the path indicated by BINFO. */
1002 accessible_p (type
, decl
)
1010 /* Non-zero if it's OK to access DECL if it has protected
1011 accessibility in TYPE. */
1012 int protected_ok
= 0;
1014 /* If we're not checking access, everything is accessible. */
1015 if (!flag_access_control
)
1018 /* If this declaration is in a block or namespace scope, there's no
1020 if (!TYPE_P (context_for_name_lookup (decl
)))
1023 /* We don't do access control for types yet. */
1024 if (TREE_CODE (decl
) == TYPE_DECL
)
1030 type
= BINFO_TYPE (type
);
1033 binfo
= TYPE_BINFO (type
);
1035 /* [class.access.base]
1037 A member m is accessible when named in class N if
1039 --m as a member of N is public, or
1041 --m as a member of N is private, and the reference occurs in a
1042 member or friend of class N, or
1044 --m as a member of N is protected, and the reference occurs in a
1045 member or friend of class N, or in a member or friend of a
1046 class P derived from N, where m as a member of P is private or
1049 --there exists a base class B of N that is accessible at the point
1050 of reference, and m is accessible when named in class B.
1052 We walk the base class hierarchy, checking these conditions. */
1054 /* Figure out where the reference is occurring. Check to see if
1055 DECL is private or protected in this scope, since that will
1056 determine whether protected access in TYPE allowed. */
1057 if (current_class_type
)
1059 = protected_accessible_p (type
, decl
, current_class_type
,
1062 /* Now, loop through the classes of which we are a friend. */
1064 protected_ok
= friend_accessible_p (current_scope (),
1067 /* Standardize on the same that will access_in_type will use. We
1068 don't need to know what path was chosen from this point onwards. */
1069 binfo
= TYPE_BINFO (type
);
1071 /* Compute the accessibility of DECL in the class hierarchy
1072 dominated by type. */
1073 access_in_type (type
, decl
);
1074 /* Walk the hierarchy again, looking for a base class that allows
1076 t
= dfs_walk (binfo
, dfs_accessible_p
,
1077 dfs_accessible_queue_p
,
1078 protected_ok
? &protected_ok
: 0);
1079 /* Clear any mark bits. Note that we have to walk the whole tree
1080 here, since we have aborted the previous walk from some point
1081 deep in the tree. */
1082 dfs_walk (binfo
, dfs_unmark
, dfs_canonical_queue
, 0);
1083 assert_canonical_unmarked (binfo
);
1085 return t
!= NULL_TREE
;
1088 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1089 found as a base class and sub-object of the object denoted by
1090 BINFO. This routine relies upon binfos not being shared, except
1091 for binfos for virtual bases. */
1094 is_subobject_of_p (parent
, binfo
)
1100 /* We want to canonicalize for comparison purposes. But, when we
1101 iterate through basetypes later, we want the binfos from the
1102 original hierarchy. That's why we have to calculate BINFOS
1103 first, and then canonicalize. */
1104 binfos
= BINFO_BASETYPES (binfo
);
1105 parent
= canonical_binfo (parent
);
1106 binfo
= canonical_binfo (binfo
);
1108 if (parent
== binfo
)
1111 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1113 /* Process and/or queue base types. */
1114 for (i
= 0; i
< n_baselinks
; i
++)
1116 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1117 if (!CLASS_TYPE_P (TREE_TYPE (base_binfo
)))
1118 /* If we see a TEMPLATE_TYPE_PARM, or some such, as a base
1119 class there's no way to descend into it. */
1122 if (is_subobject_of_p (parent
, base_binfo
))
1128 /* See if a one FIELD_DECL hides another. This routine is meant to
1129 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1130 binfos given are the binfos corresponding to the particular places
1131 the FIELD_DECLs are found. This routine relies upon binfos not
1132 being shared, except for virtual bases. */
1135 hides (hider_binfo
, hidee_binfo
)
1136 tree hider_binfo
, hidee_binfo
;
1138 /* hider hides hidee, if hider has hidee as a base class and
1139 the instance of hidee is a sub-object of hider. The first
1140 part is always true is the second part is true.
1142 When hider and hidee are the same (two ways to get to the exact
1143 same member) we consider either one as hiding the other. */
1144 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
1147 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1148 function was declared inside the class given by TYPE. It really should
1149 only return functions that match the given TYPE. */
1152 lookup_fnfields_here (type
, name
)
1155 int idx
= lookup_fnfields_1 (type
, name
);
1158 /* ctors and dtors are always only in the right class. */
1161 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1164 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls
)))
1165 == TYPE_MAIN_VARIANT (type
))
1167 fndecls
= OVL_CHAIN (fndecls
);
1172 struct lookup_field_info
{
1173 /* The type in which we're looking. */
1175 /* The name of the field for which we're looking. */
1177 /* If non-NULL, the current result of the lookup. */
1179 /* The path to RVAL. */
1181 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1184 /* If non-zero, we are looking for types, not data members. */
1186 /* If non-zero, RVAL was found by looking through a dependent base. */
1187 int from_dep_base_p
;
1188 /* If something went wrong, a message indicating what. */
1192 /* Returns non-zero if BINFO is not hidden by the value found by the
1193 lookup so far. If BINFO is hidden, then there's no need to look in
1194 it. DATA is really a struct lookup_field_info. Called from
1195 lookup_field via breadth_first_search. */
1198 lookup_field_queue_p (binfo
, data
)
1202 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1204 /* Don't look for constructors or destructors in base classes. */
1205 if (lfi
->name
== ctor_identifier
|| lfi
->name
== dtor_identifier
)
1208 /* If this base class is hidden by the best-known value so far, we
1209 don't need to look. */
1210 if (!lfi
->from_dep_base_p
&& lfi
->rval_binfo
1211 && hides (lfi
->rval_binfo
, binfo
))
1214 if (TREE_VIA_VIRTUAL (binfo
))
1215 return binfo_member (BINFO_TYPE (binfo
),
1216 CLASSTYPE_VBASECLASSES (lfi
->type
));
1221 /* Within the scope of a template class, you can refer to the to the
1222 current specialization with the name of the template itself. For
1225 template <typename T> struct S { S* sp; }
1227 Returns non-zero if DECL is such a declaration in a class TYPE. */
1230 template_self_reference_p (type
, decl
)
1234 return (CLASSTYPE_USE_TEMPLATE (type
)
1235 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
))
1236 && TREE_CODE (decl
) == TYPE_DECL
1237 && DECL_ARTIFICIAL (decl
)
1238 && DECL_NAME (decl
) == constructor_name (type
));
1241 /* DATA is really a struct lookup_field_info. Look for a field with
1242 the name indicated there in BINFO. If this function returns a
1243 non-NULL value it is the result of the lookup. Called from
1244 lookup_field via breadth_first_search. */
1247 lookup_field_r (binfo
, data
)
1251 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1252 tree type
= BINFO_TYPE (binfo
);
1253 tree nval
= NULL_TREE
;
1254 int from_dep_base_p
;
1256 /* First, look for a function. There can't be a function and a data
1257 member with the same name, and if there's a function and a type
1258 with the same name, the type is hidden by the function. */
1259 if (!lfi
->want_type
)
1261 int idx
= lookup_fnfields_here (type
, lfi
->name
);
1263 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1267 /* Look for a data member or type. */
1268 nval
= lookup_field_1 (type
, lfi
->name
);
1270 /* If there is no declaration with the indicated name in this type,
1271 then there's nothing to do. */
1275 /* If we're looking up a type (as with an elaborated type specifier)
1276 we ignore all non-types we find. */
1277 if (lfi
->want_type
&& TREE_CODE (nval
) != TYPE_DECL
)
1279 nval
= purpose_member (lfi
->name
, CLASSTYPE_TAGS (type
));
1281 nval
= TYPE_MAIN_DECL (TREE_VALUE (nval
));
1286 /* You must name a template base class with a template-id. */
1287 if (!same_type_p (type
, lfi
->type
)
1288 && template_self_reference_p (type
, nval
))
1291 from_dep_base_p
= dependent_base_p (binfo
);
1292 if (lfi
->from_dep_base_p
&& !from_dep_base_p
)
1294 /* If the new declaration is not found via a dependent base, and
1295 the old one was, then we must prefer the new one. We weren't
1296 really supposed to be able to find the old one, so we don't
1297 want to be affected by a specialization. Consider:
1299 struct B { typedef int I; };
1300 template <typename T> struct D1 : virtual public B {};
1301 template <typename T> struct D :
1302 public D1, virtual pubic B { I i; };
1304 The `I' in `D<T>' is unambigousuly `B::I', regardless of how
1305 D1 is specialized. */
1306 lfi
->from_dep_base_p
= 0;
1307 lfi
->rval
= NULL_TREE
;
1308 lfi
->rval_binfo
= NULL_TREE
;
1309 lfi
->ambiguous
= NULL_TREE
;
1312 else if (lfi
->rval_binfo
&& !lfi
->from_dep_base_p
&& from_dep_base_p
)
1313 /* Similarly, if the old declaration was not found via a dependent
1314 base, and the new one is, ignore the new one. */
1317 /* If the lookup already found a match, and the new value doesn't
1318 hide the old one, we might have an ambiguity. */
1319 if (lfi
->rval_binfo
&& !hides (binfo
, lfi
->rval_binfo
))
1321 if (nval
== lfi
->rval
&& SHARED_MEMBER_P (nval
))
1322 /* The two things are really the same. */
1324 else if (hides (lfi
->rval_binfo
, binfo
))
1325 /* The previous value hides the new one. */
1329 /* We have a real ambiguity. We keep a chain of all the
1331 if (!lfi
->ambiguous
&& lfi
->rval
)
1333 /* This is the first time we noticed an ambiguity. Add
1334 what we previously thought was a reasonable candidate
1336 lfi
->ambiguous
= scratch_tree_cons (NULL_TREE
, lfi
->rval
,
1338 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1341 /* Add the new value. */
1342 lfi
->ambiguous
= scratch_tree_cons (NULL_TREE
, nval
,
1344 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1345 lfi
->errstr
= "request for member `%D' is ambiguous";
1350 /* If the thing we're looking for is a virtual base class, then
1351 we know we've got what we want at this point; there's no way
1352 to get an ambiguity. */
1353 if (VBASE_NAME_P (lfi
->name
))
1359 if (from_dep_base_p
&& TREE_CODE (nval
) != TYPE_DECL
1360 /* We need to return a member template class so we can
1361 define partial specializations. Is there a better
1363 && !DECL_CLASS_TEMPLATE_P (nval
))
1364 /* The thing we're looking for isn't a type, so the implicit
1365 typename extension doesn't apply, so we just pretend we
1366 didn't find anything. */
1370 lfi
->from_dep_base_p
= from_dep_base_p
;
1371 lfi
->rval_binfo
= binfo
;
1377 /* Look for a memer named NAME in an inheritance lattice dominated by
1378 XBASETYPE. PROTECT is 0 or two, we do not check access. If it is
1379 1, we enforce accessibility. If PROTECT is zero, then, for an
1380 ambiguous lookup, we return NULL. If PROTECT is 1, we issue an
1381 error message. If PROTECT is 2, we return a TREE_LIST whose
1382 TREEE_TYPE is error_mark_node and whose TREE_VALUEs are the list of
1383 ambiguous candidates.
1385 WANT_TYPE is 1 when we should only return TYPE_DECLs, if no
1386 TYPE_DECL can be found return NULL_TREE. */
1389 lookup_member (xbasetype
, name
, protect
, want_type
)
1390 register tree xbasetype
, name
;
1391 int protect
, want_type
;
1393 tree rval
, rval_binfo
= NULL_TREE
;
1394 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1395 struct lookup_field_info lfi
;
1397 /* rval_binfo is the binfo associated with the found member, note,
1398 this can be set with useful information, even when rval is not
1399 set, because it must deal with ALL members, not just non-function
1400 members. It is used for ambiguity checking and the hidden
1401 checks. Whereas rval is only set if a proper (not hidden)
1402 non-function member is found. */
1404 const char *errstr
= 0;
1406 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1407 && IDENTIFIER_CLASS_VALUE (name
))
1409 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1410 if (TREE_CODE (field
) != FUNCTION_DECL
1411 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1412 /* We're in the scope of this class, and the value has already
1413 been looked up. Just return the cached value. */
1417 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1419 type
= BINFO_TYPE (xbasetype
);
1420 basetype_path
= xbasetype
;
1422 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1425 basetype_path
= TYPE_BINFO (type
);
1426 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
1430 my_friendly_abort (97);
1432 complete_type (type
);
1434 #ifdef GATHER_STATISTICS
1435 n_calls_lookup_field
++;
1436 #endif /* GATHER_STATISTICS */
1438 bzero ((PTR
) &lfi
, sizeof (lfi
));
1441 lfi
.want_type
= want_type
;
1442 bfs_walk (basetype_path
, &lookup_field_r
, &lookup_field_queue_p
, &lfi
);
1444 rval_binfo
= lfi
.rval_binfo
;
1446 type
= BINFO_TYPE (rval_binfo
);
1447 errstr
= lfi
.errstr
;
1449 /* If we are not interested in ambiguities, don't report them;
1450 just return NULL_TREE. */
1451 if (!protect
&& lfi
.ambiguous
)
1457 return lfi
.ambiguous
;
1464 In the case of overloaded function names, access control is
1465 applied to the function selected by overloaded resolution. */
1466 if (rval
&& protect
&& !is_overloaded_fn (rval
)
1467 && !enforce_access (xbasetype
, rval
))
1468 return error_mark_node
;
1470 if (errstr
&& protect
)
1472 cp_error (errstr
, name
, type
);
1474 print_candidates (lfi
.ambiguous
);
1475 rval
= error_mark_node
;
1478 /* If the thing we found was found via the implicit typename
1479 extension, build the typename type. */
1480 if (rval
&& lfi
.from_dep_base_p
&& !DECL_CLASS_TEMPLATE_P (rval
))
1481 rval
= TYPE_STUB_DECL (build_typename_type (BINFO_TYPE (basetype_path
),
1485 if (rval
&& is_overloaded_fn (rval
))
1487 rval
= scratch_tree_cons (basetype_path
, rval
, NULL_TREE
);
1488 SET_BASELINK_P (rval
);
1494 /* Like lookup_member, except that if we find a function member we
1495 return NULL_TREE. */
1498 lookup_field (xbasetype
, name
, protect
, want_type
)
1499 register tree xbasetype
, name
;
1500 int protect
, want_type
;
1502 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
);
1504 /* Ignore functions. */
1505 if (rval
&& TREE_CODE (rval
) == TREE_LIST
)
1511 /* Like lookup_member, except that if we find a non-function member we
1512 return NULL_TREE. */
1515 lookup_fnfields (xbasetype
, name
, protect
)
1516 register tree xbasetype
, name
;
1519 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/0);
1521 /* Ignore non-functions. */
1522 if (rval
&& TREE_CODE (rval
) != TREE_LIST
)
1528 /* TYPE is a class type. Return the index of the fields within
1529 the method vector with name NAME, or -1 is no such field exists. */
1532 lookup_fnfields_1 (type
, name
)
1536 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
1538 if (method_vec
!= 0)
1541 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1542 int len
= TREE_VEC_LENGTH (method_vec
);
1545 #ifdef GATHER_STATISTICS
1546 n_calls_lookup_fnfields_1
++;
1547 #endif /* GATHER_STATISTICS */
1549 /* Constructors are first... */
1550 if (name
== ctor_identifier
)
1551 return methods
[0] ? 0 : -1;
1553 /* and destructors are second. */
1554 if (name
== dtor_identifier
)
1555 return methods
[1] ? 1 : -1;
1557 for (i
= 2; i
< len
&& methods
[i
]; ++i
)
1559 #ifdef GATHER_STATISTICS
1560 n_outer_fields_searched
++;
1561 #endif /* GATHER_STATISTICS */
1563 tmp
= OVL_CURRENT (methods
[i
]);
1564 if (DECL_NAME (tmp
) == name
)
1567 /* If the type is complete and we're past the conversion ops,
1568 switch to binary search. */
1569 if (! DECL_CONV_FN_P (tmp
)
1570 && TYPE_SIZE (type
))
1572 int lo
= i
+ 1, hi
= len
;
1578 #ifdef GATHER_STATISTICS
1579 n_outer_fields_searched
++;
1580 #endif /* GATHER_STATISTICS */
1582 tmp
= DECL_NAME (OVL_CURRENT (methods
[i
]));
1586 else if (tmp
< name
)
1595 /* If we didn't find it, it might have been a template
1596 conversion operator. (Note that we don't look for this case
1597 above so that we will always find specializations first.) */
1598 if (IDENTIFIER_TYPENAME_P (name
))
1600 for (i
= 2; i
< len
&& methods
[i
]; ++i
)
1602 tmp
= OVL_CURRENT (methods
[i
]);
1603 if (! DECL_CONV_FN_P (tmp
))
1605 /* Since all conversion operators come first, we know
1606 there is no such operator. */
1609 else if (TREE_CODE (tmp
) == TEMPLATE_DECL
)
1618 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1619 type in the hierarchy, in a breadth-first preorder traversal. .
1620 If it ever returns a non-NULL value, that value is immediately
1621 returned and the walk is terminated. At each node FN, is passed a
1622 BINFO indicating the path from the curently visited base-class to
1623 TYPE. The TREE_CHAINs of the BINFOs may be used for scratch space;
1624 they are otherwise unused. Before each base-class is walked QFN is
1625 called. If the value returned is non-zero, the base-class is
1626 walked; otherwise it is not. If QFN is NULL, it is treated as a
1627 function which always returns 1. Both FN and QFN are passed the
1628 DATA whenever they are called. */
1631 bfs_walk (binfo
, fn
, qfn
, data
)
1633 tree (*fn
) PROTO((tree
, void *));
1634 tree (*qfn
) PROTO((tree
, void *));
1639 tree rval
= NULL_TREE
;
1640 /* An array of the base classes of BINFO. These will be built up in
1641 breadth-first order, except where QFN prunes the search. */
1642 varray_type bfs_bases
;
1644 /* Start with enough room for ten base classes. That will be enough
1645 for most hierarchies. */
1646 VARRAY_TREE_INIT (bfs_bases
, 10, "search_stack");
1648 /* Put the first type into the stack. */
1649 VARRAY_TREE (bfs_bases
, 0) = binfo
;
1652 for (head
= 0; head
< tail
; ++head
)
1658 /* Pull the next type out of the queue. */
1659 binfo
= VARRAY_TREE (bfs_bases
, head
);
1661 /* If this is the one we're looking for, we're done. */
1662 rval
= (*fn
) (binfo
, data
);
1666 /* Queue up the base types. */
1667 binfos
= BINFO_BASETYPES (binfo
);
1668 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1669 for (i
= 0; i
< n_baselinks
; i
++)
1671 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1674 base_binfo
= (*qfn
) (base_binfo
, data
);
1678 if (tail
== VARRAY_SIZE (bfs_bases
))
1679 VARRAY_GROW (bfs_bases
, 2 * VARRAY_SIZE (bfs_bases
));
1680 VARRAY_TREE (bfs_bases
, tail
) = base_binfo
;
1687 VARRAY_FREE (bfs_bases
);
1692 /* Exactly like bfs_walk, except that a depth-first traversal is
1693 performed, and PREFN is called in preorder, while POSTFN is called
1697 dfs_walk_real (binfo
, prefn
, postfn
, qfn
, data
)
1699 tree (*prefn
) PROTO((tree
, void *));
1700 tree (*postfn
) PROTO((tree
, void *));
1701 tree (*qfn
) PROTO((tree
, void *));
1707 tree rval
= NULL_TREE
;
1709 /* Call the pre-order walking function. */
1712 rval
= (*prefn
) (binfo
, data
);
1717 /* Process the basetypes. */
1718 binfos
= BINFO_BASETYPES (binfo
);
1719 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1720 for (i
= 0; i
< n_baselinks
; i
++)
1722 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1725 base_binfo
= (*qfn
) (base_binfo
, data
);
1729 rval
= dfs_walk_real (base_binfo
, prefn
, postfn
, qfn
, data
);
1735 /* Call the post-order walking function. */
1737 rval
= (*postfn
) (binfo
, data
);
1742 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1746 dfs_walk (binfo
, fn
, qfn
, data
)
1748 tree (*fn
) PROTO((tree
, void *));
1749 tree (*qfn
) PROTO((tree
, void *));
1752 return dfs_walk_real (binfo
, 0, fn
, qfn
, data
);
1757 /* The name of the function we are looking for. */
1759 /* The overloaded functions we have found. */
1763 /* Called from get_virtuals_named_this via bfs_walk. */
1766 get_virtuals_named_this_r (binfo
, data
)
1770 struct gvnt_info
*gvnti
= (struct gvnt_info
*) data
;
1771 tree type
= BINFO_TYPE (binfo
);
1774 idx
= lookup_fnfields_here (BINFO_TYPE (binfo
), gvnti
->name
);
1777 = scratch_tree_cons (binfo
,
1778 TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
),
1785 /* Return the virtual functions with the indicated NAME in the type
1786 indicated by BINFO. The result is a TREE_LIST whose TREE_PURPOSE
1787 indicates the base class from which the TREE_VALUE (an OVERLOAD or
1788 just a FUNCTION_DECL) originated. */
1791 get_virtuals_named_this (binfo
, name
)
1795 struct gvnt_info gvnti
;
1799 gvnti
.fields
= NULL_TREE
;
1801 bfs_walk (binfo
, get_virtuals_named_this_r
, 0, &gvnti
);
1803 /* Get to the function decls, and return the first virtual function
1804 with this name, if there is one. */
1805 for (fields
= gvnti
.fields
; fields
; fields
= next_baselink (fields
))
1809 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
1810 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
1817 get_virtual_destructor (binfo
, data
)
1819 void *data ATTRIBUTE_UNUSED
;
1821 tree type
= BINFO_TYPE (binfo
);
1822 if (TYPE_HAS_DESTRUCTOR (type
)
1823 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
1824 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
1829 tree_has_any_destructor_p (binfo
, data
)
1831 void *data ATTRIBUTE_UNUSED
;
1833 tree type
= BINFO_TYPE (binfo
);
1834 return TYPE_NEEDS_DESTRUCTOR (type
) ? binfo
: NULL_TREE
;
1837 /* Returns > 0 if a function with type DRETTYPE overriding a function
1838 with type BRETTYPE is covariant, as defined in [class.virtual].
1840 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1841 adjustment), or -1 if pedantically invalid covariance. */
1844 covariant_return_p (brettype
, drettype
)
1845 tree brettype
, drettype
;
1849 if (TREE_CODE (brettype
) == FUNCTION_DECL
1850 || TREE_CODE (brettype
) == THUNK_DECL
)
1852 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
1853 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
1855 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
1857 brettype
= TREE_TYPE (brettype
);
1858 drettype
= TREE_TYPE (drettype
);
1861 if (same_type_p (brettype
, drettype
))
1864 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
1865 && (TREE_CODE (brettype
) == POINTER_TYPE
1866 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
1867 && TYPE_QUALS (brettype
) == TYPE_QUALS (drettype
)))
1870 if (! can_convert (brettype
, drettype
))
1873 brettype
= TREE_TYPE (brettype
);
1874 drettype
= TREE_TYPE (drettype
);
1876 /* If not pedantic, allow any standard pointer conversion. */
1877 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
1880 binfo
= get_binfo (brettype
, drettype
, 1);
1882 /* If we get an error_mark_node from get_binfo, it already complained,
1883 so let's just succeed. */
1884 if (binfo
== error_mark_node
)
1887 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
1892 /* Check that virtual overrider OVERRIDER is acceptable for base function
1893 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1896 check_final_overrider (overrider
, basefn
)
1897 tree overrider
, basefn
;
1899 tree over_type
= TREE_TYPE (overrider
);
1900 tree base_type
= TREE_TYPE (basefn
);
1901 tree over_return
= TREE_TYPE (over_type
);
1902 tree base_return
= TREE_TYPE (base_type
);
1903 tree over_throw
= TYPE_RAISES_EXCEPTIONS (over_type
);
1904 tree base_throw
= TYPE_RAISES_EXCEPTIONS (base_type
);
1907 if (same_type_p (base_return
, over_return
))
1909 else if ((i
= covariant_return_p (base_return
, over_return
)))
1912 sorry ("adjusting pointers for covariant returns");
1914 if (pedantic
&& i
== -1)
1916 cp_pedwarn_at ("invalid covariant return type for `virtual %#D'", overrider
);
1917 cp_pedwarn_at (" overriding `virtual %#D' (must be pointer or reference to class)", basefn
);
1920 else if (IS_AGGR_TYPE_2 (base_return
, over_return
)
1921 && same_or_base_type_p (base_return
, over_return
))
1923 cp_error_at ("invalid covariant return type for `virtual %#D'", overrider
);
1924 cp_error_at (" overriding `virtual %#D' (must use pointer or reference)", basefn
);
1927 else if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider
)) == NULL_TREE
)
1929 cp_error_at ("conflicting return type specified for `virtual %#D'", overrider
);
1930 cp_error_at (" overriding `virtual %#D'", basefn
);
1931 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider
),
1932 DECL_CLASS_CONTEXT (overrider
));
1936 /* Check throw specifier is subset. */
1937 /* XXX At the moment, punt on an overriding artificial function. We
1938 don't generate its exception specifier, so can't check it properly. */
1939 if (! DECL_ARTIFICIAL (overrider
)
1940 && !comp_except_specs (base_throw
, over_throw
, 0))
1942 cp_error_at ("looser throw specifier for `virtual %#F'", overrider
);
1943 cp_error_at (" overriding `virtual %#F'", basefn
);
1949 /* Given a class type TYPE, and a function decl FNDECL, look for a
1950 virtual function in TYPE's hierarchy which FNDECL could match as a
1951 virtual function. It doesn't matter which one we find.
1953 DTORP is nonzero if we are looking for a destructor. Destructors
1954 need special treatment because they do not match by name. */
1957 get_matching_virtual (binfo
, fndecl
, dtorp
)
1961 tree tmp
= NULL_TREE
;
1963 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
1964 /* In [temp.mem] we have:
1966 A specialization of a member function template does not
1967 override a virtual function from a base class. */
1970 /* Breadth first search routines start searching basetypes
1971 of TYPE, so we must perform first ply of search here. */
1973 return bfs_walk (binfo
, get_virtual_destructor
,
1974 tree_has_any_destructor_p
, 0);
1977 tree drettype
, dtypes
, btypes
, instptr_type
;
1978 tree baselink
, best
= NULL_TREE
;
1979 tree declarator
= DECL_NAME (fndecl
);
1980 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
1983 baselink
= get_virtuals_named_this (binfo
, declarator
);
1984 if (baselink
== NULL_TREE
)
1987 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
1988 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1989 if (DECL_STATIC_FUNCTION_P (fndecl
))
1990 instptr_type
= NULL_TREE
;
1992 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
1994 for (; baselink
; baselink
= next_baselink (baselink
))
1997 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
1999 tmp
= OVL_CURRENT (tmps
);
2000 if (! DECL_VINDEX (tmp
))
2003 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
2004 if (instptr_type
== NULL_TREE
)
2006 if (compparms (TREE_CHAIN (btypes
), dtypes
))
2007 /* Caller knows to give error in this case. */
2012 if (/* The first parameter is the `this' parameter,
2013 which has POINTER_TYPE, and we can therefore
2014 safely use TYPE_QUALS, rather than
2016 (TYPE_QUALS (TREE_TYPE (TREE_VALUE (btypes
)))
2017 == TYPE_QUALS (instptr_type
))
2018 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
)))
2020 check_final_overrider (fndecl
, tmp
);
2022 /* FNDECL overrides this function. We continue to
2023 check all the other functions in order to catch
2024 errors; it might be that in some other baseclass
2025 a virtual function was declared with the same
2026 parameter types, but a different return type. */
2036 /* Return the list of virtual functions which are abstract in type
2037 TYPE that come from non virtual base classes. See
2038 expand_direct_vtbls_init for the style of search we do. */
2041 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
2044 tree abstract_virtuals
;
2046 tree binfos
= BINFO_BASETYPES (binfo
);
2047 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2049 for (i
= 0; i
< n_baselinks
; i
++)
2051 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2052 int is_not_base_vtable
2053 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2054 if (! TREE_VIA_VIRTUAL (base_binfo
))
2056 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
2059 /* Should we use something besides CLASSTYPE_VFIELDS? */
2060 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2062 tree virtuals
= BINFO_VIRTUALS (binfo
);
2064 skip_rtti_stuff (&virtuals
, BINFO_TYPE (binfo
));
2068 tree base_fndecl
= TREE_VALUE (virtuals
);
2069 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2070 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
,
2072 virtuals
= TREE_CHAIN (virtuals
);
2075 return abstract_virtuals
;
2078 /* Return the list of virtual functions which are abstract in type TYPE.
2079 This information is cached, and so must be built on a
2080 non-temporary obstack. */
2083 get_abstract_virtuals (type
)
2087 tree abstract_virtuals
= NULL
;
2089 /* First get all from non-virtual bases. */
2091 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
2093 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
2095 tree virtuals
= BINFO_VIRTUALS (vbases
);
2097 skip_rtti_stuff (&virtuals
, BINFO_TYPE (vbases
));
2101 tree base_fndecl
= TREE_VALUE (virtuals
);
2102 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
2103 cp_error ("`%#D' needs a final overrider", base_fndecl
);
2104 else if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2105 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
,
2107 virtuals
= TREE_CHAIN (virtuals
);
2110 return nreverse (abstract_virtuals
);
2114 next_baselink (baselink
)
2117 tree tmp
= TREE_TYPE (baselink
);
2118 baselink
= TREE_CHAIN (baselink
);
2121 /* @@ does not yet add previous base types. */
2122 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2124 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2125 tmp
= TREE_CHAIN (tmp
);
2130 /* DEPTH-FIRST SEARCH ROUTINES. */
2132 /* This routine converts a pointer to be a pointer of an immediate
2133 base class. The normal convert_pointer_to routine would diagnose
2134 the conversion as ambiguous, under MI code that has the base class
2135 as an ambiguous base class. */
2138 convert_pointer_to_single_level (to_type
, expr
)
2142 tree binfo_of_derived
;
2145 derived
= TREE_TYPE (TREE_TYPE (expr
));
2146 binfo_of_derived
= TYPE_BINFO (derived
);
2147 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo_of_derived
) == NULL_TREE
,
2149 for (i
= CLASSTYPE_N_BASECLASSES (derived
) - 1; i
>= 0; --i
)
2151 tree binfo
= BINFO_BASETYPE (binfo_of_derived
, i
);
2152 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo
) == binfo_of_derived
,
2154 if (same_type_p (BINFO_TYPE (binfo
), to_type
))
2155 return build_vbase_path (PLUS_EXPR
,
2156 build_pointer_type (to_type
),
2160 my_friendly_abort (19990607);
2166 tree
markedp (binfo
, data
)
2168 void *data ATTRIBUTE_UNUSED
;
2170 return BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2174 unmarkedp (binfo
, data
)
2176 void *data ATTRIBUTE_UNUSED
;
2178 return !BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2182 marked_vtable_pathp (binfo
, data
)
2184 void *data ATTRIBUTE_UNUSED
;
2186 return BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2190 unmarked_vtable_pathp (binfo
, data
)
2192 void *data ATTRIBUTE_UNUSED
;
2194 return !BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2198 marked_new_vtablep (binfo
, data
)
2200 void *data ATTRIBUTE_UNUSED
;
2202 return BINFO_NEW_VTABLE_MARKED (binfo
) ? binfo
: NULL_TREE
;
2206 unmarked_new_vtablep (binfo
, data
)
2208 void *data ATTRIBUTE_UNUSED
;
2210 return !BINFO_NEW_VTABLE_MARKED (binfo
) ? binfo
: NULL_TREE
;
2214 marked_pushdecls_p (binfo
, data
)
2216 void *data ATTRIBUTE_UNUSED
;
2218 return (CLASS_TYPE_P (BINFO_TYPE (binfo
))
2219 && BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
2223 unmarked_pushdecls_p (binfo
, data
)
2225 void *data ATTRIBUTE_UNUSED
;
2227 return (CLASS_TYPE_P (BINFO_TYPE (binfo
))
2228 && !BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
2232 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2233 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2237 dfs_debug_unmarkedp (binfo
, data
)
2239 void *data ATTRIBUTE_UNUSED
;
2241 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
))
2242 ? binfo
: NULL_TREE
);
2245 /* The worker functions for `dfs_walk'. These do not need to
2246 test anything (vis a vis marking) if they are paired with
2247 a predicate function (above). */
2251 dfs_mark (binfo
) tree binfo
;
2252 { SET_BINFO_MARKED (binfo
); }
2256 dfs_unmark (binfo
, data
)
2258 void *data ATTRIBUTE_UNUSED
;
2260 CLEAR_BINFO_MARKED (binfo
);
2266 dfs_mark_vtable_path (binfo
) tree binfo
;
2267 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2270 dfs_unmark_vtable_path (binfo
) tree binfo
;
2271 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2274 dfs_mark_new_vtable (binfo
) tree binfo
;
2275 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2278 dfs_unmark_new_vtable (binfo
) tree binfo
;
2279 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2282 dfs_clear_search_slot (binfo
) tree binfo
;
2283 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2287 dfs_debug_mark (binfo
, data
)
2289 void *data ATTRIBUTE_UNUSED
;
2291 tree t
= BINFO_TYPE (binfo
);
2293 /* Use heuristic that if there are virtual functions,
2294 ignore until we see a non-inline virtual function. */
2295 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2297 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2302 /* If interface info is known, either we've already emitted the debug
2303 info or we don't need to. */
2304 if (CLASSTYPE_INTERFACE_KNOWN (t
))
2307 /* If debug info is requested from this context for this type, supply it.
2308 If debug info is requested from another context for this type,
2309 see if some third context can supply it. */
2310 if (current_function_decl
== NULL_TREE
2311 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2313 if (TREE_VEC_ELT (methods
, 1))
2314 methods
= TREE_VEC_ELT (methods
, 1);
2315 else if (TREE_VEC_ELT (methods
, 0))
2316 methods
= TREE_VEC_ELT (methods
, 0);
2318 methods
= TREE_VEC_ELT (methods
, 2);
2319 methods
= OVL_CURRENT (methods
);
2322 if (DECL_VINDEX (methods
)
2323 && DECL_THIS_INLINE (methods
) == 0
2324 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2326 /* Somebody, somewhere is going to have to define this
2327 virtual function. When they do, they will provide
2328 the debugging info. */
2331 methods
= TREE_CHAIN (methods
);
2334 /* We cannot rely on some alien method to solve our problems,
2335 so we must write out the debug info ourselves. */
2336 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2337 rest_of_type_compilation (t
, toplevel_bindings_p ());
2349 /* Attach to the type of the virtual base class, the pointer to the
2350 virtual base class. */
2353 dfs_find_vbases (binfo
, data
)
2357 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2358 tree binfos
= BINFO_BASETYPES (binfo
);
2359 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2361 for (i
= n_baselinks
-1; i
>= 0; i
--)
2363 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2365 if (TREE_VIA_VIRTUAL (base_binfo
)
2366 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2368 tree vbase
= BINFO_TYPE (base_binfo
);
2369 tree binfo
= binfo_member (vbase
, vi
->vbase_types
);
2371 CLASSTYPE_SEARCH_SLOT (vbase
)
2372 = build (PLUS_EXPR
, build_pointer_type (vbase
),
2373 vi
->decl_ptr
, BINFO_OFFSET (binfo
));
2376 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2377 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2383 dfs_init_vbase_pointers (binfo
, data
)
2387 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2388 tree type
= BINFO_TYPE (binfo
);
2389 tree fields
= TYPE_FIELDS (type
);
2390 tree this_vbase_ptr
;
2392 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2395 /* See finish_struct_1 for when we can enable this. */
2396 /* If we have a vtable pointer first, skip it. */
2397 if (VFIELD_NAME_P (DECL_NAME (fields
)))
2398 fields
= TREE_CHAIN (fields
);
2401 if (BINFO_INHERITANCE_CHAIN (binfo
))
2403 this_vbase_ptr
= TREE_CHAIN (BINFO_INHERITANCE_CHAIN (binfo
));
2404 if (TREE_VIA_VIRTUAL (binfo
))
2405 this_vbase_ptr
= CLASSTYPE_SEARCH_SLOT (type
);
2407 this_vbase_ptr
= convert_pointer_to_single_level (type
,
2409 TREE_CHAIN (binfo
) = this_vbase_ptr
;
2412 this_vbase_ptr
= TREE_CHAIN (binfo
);
2414 if (fields
== NULL_TREE
2415 || DECL_NAME (fields
) == NULL_TREE
2416 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2419 if (build_pointer_type (type
)
2420 != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2421 my_friendly_abort (125);
2423 while (fields
&& DECL_NAME (fields
) && VBASE_NAME_P (DECL_NAME (fields
)))
2425 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2426 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2427 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2428 vi
->inits
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2430 build_modify_expr (ref
, NOP_EXPR
, init
),
2432 fields
= TREE_CHAIN (fields
);
2438 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2439 times, just NEW_VTABLE, but optimizer should make both with equal
2440 efficiency (though it does not currently). */
2443 dfs_clear_vbase_slots (binfo
, data
)
2445 void *data ATTRIBUTE_UNUSED
;
2447 tree type
= BINFO_TYPE (binfo
);
2448 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2449 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2450 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2455 init_vbase_pointers (type
, decl_ptr
)
2459 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2461 struct vbase_info vi
;
2462 int old_flag
= flag_this_is_variable
;
2463 tree binfo
= TYPE_BINFO (type
);
2464 flag_this_is_variable
= -2;
2466 /* Find all the virtual base classes, marking them for later
2468 vi
.decl_ptr
= decl_ptr
;
2469 vi
.vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2470 vi
.inits
= NULL_TREE
;
2472 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
, &vi
);
2474 /* Build up a list of the initializers. */
2475 TREE_CHAIN (binfo
) = decl_ptr
;
2476 dfs_walk_real (binfo
,
2477 dfs_init_vbase_pointers
, 0,
2478 marked_vtable_pathp
,
2481 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
, 0);
2482 flag_this_is_variable
= old_flag
;
2488 /* get the virtual context (the vbase that directly contains the
2489 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2490 or NULL_TREE if there is none.
2492 FNDECL must come from a virtual table from a virtual base to ensure that
2493 there is only one possible DECL_CLASS_CONTEXT.
2495 We know that if there is more than one place (binfo) the fndecl that the
2496 declared, they all refer to the same binfo. See get_class_offset_1 for
2497 the check that ensures this. */
2500 virtual_context (fndecl
, t
, vbase
)
2501 tree fndecl
, t
, vbase
;
2504 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2506 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2507 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2511 /* Not sure if checking path == vbase is necessary here, but just in
2513 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2514 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2515 path
= BINFO_INHERITANCE_CHAIN (path
);
2518 /* This shouldn't happen, I don't want errors! */
2519 warning ("recoverable compiler error, fixups for virtual function");
2524 if (TREE_VIA_VIRTUAL (path
))
2525 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2526 path
= BINFO_INHERITANCE_CHAIN (path
);
2531 /* Fixups upcast offsets for one vtable.
2532 Entries may stay within the VBASE given, or
2533 they may upcast into a direct base, or
2534 they may upcast into a different vbase.
2536 We only need to do fixups in case 2 and 3. In case 2, we add in
2537 the virtual base offset to effect an upcast, in case 3, we add in
2538 the virtual base offset to effect an upcast, then subtract out the
2539 offset for the other virtual base, to effect a downcast into it.
2541 This routine mirrors fixup_vtable_deltas in functionality, though
2542 this one is runtime based, and the other is compile time based.
2543 Conceivably that routine could be removed entirely, and all fixups
2546 VBASE_OFFSETS is an association list of virtual bases that contains
2547 offset information for the virtual bases, so the offsets are only
2548 calculated once. The offsets are computed by where we think the
2549 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2550 the vbase really is. */
2553 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2555 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2557 tree virtuals
= BINFO_VIRTUALS (binfo
);
2560 unsigned HOST_WIDE_INT n
;
2562 delta
= purpose_member (vbase
, *vbase_offsets
);
2565 delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase
));
2566 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2567 delta
= save_expr (delta
);
2568 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2569 *vbase_offsets
= delta
;
2572 n
= skip_rtti_stuff (&virtuals
, BINFO_TYPE (binfo
));
2576 tree current_fndecl
= TREE_VALUE (virtuals
);
2579 && current_fndecl
!= abort_fndecl
2580 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2582 /* This may in fact need a runtime fixup. */
2583 tree idx
= build_int_2 (n
, 0);
2584 tree vtbl
= BINFO_VTABLE (binfo
);
2585 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2586 tree aref
, ref
, naref
;
2587 tree old_delta
, new_delta
;
2590 if (nvtbl
== NULL_TREE
2591 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2593 /* Dup it if it isn't in local scope yet. */
2595 (VAR_DECL
, DECL_NAME (vtbl
),
2596 TYPE_MAIN_VARIANT (TREE_TYPE (vtbl
)));
2597 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2598 DECL_ALIGN (nvtbl
));
2599 TREE_READONLY (nvtbl
) = 0;
2600 DECL_ARTIFICIAL (nvtbl
) = 1;
2601 nvtbl
= pushdecl (nvtbl
);
2603 cp_finish_decl (nvtbl
, init
, NULL_TREE
, 0,
2604 LOOKUP_ONLYCONVERTING
);
2606 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2607 because they wouldn't be useful; everything that wants to
2608 look at the vtable will look at the decl for the normal
2609 vtable. Setting DECL_CONTEXT also screws up
2610 decl_function_context. */
2612 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
2614 TREE_SIDE_EFFECTS (init
) = 1;
2615 expand_expr_stmt (init
);
2616 /* Update the vtable pointers as necessary. */
2617 ref
= build_vfield_ref
2618 (build_indirect_ref (addr
, NULL_PTR
),
2619 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))));
2621 (build_modify_expr (ref
, NOP_EXPR
, nvtbl
));
2623 assemble_external (vtbl
);
2624 aref
= build_array_ref (vtbl
, idx
);
2625 naref
= build_array_ref (nvtbl
, idx
);
2626 old_delta
= build_component_ref (aref
, delta_identifier
,
2628 new_delta
= build_component_ref (naref
, delta_identifier
,
2631 /* This is a upcast, so we have to add the offset for the
2633 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
2634 TREE_VALUE (delta
));
2637 /* If this is set, we need to subtract out the delta
2638 adjustments for the other virtual base that we
2640 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
2643 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
2644 vc_delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc
));
2645 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
2647 vc_delta
= save_expr (vc_delta
);
2648 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
2651 vc_delta
= TREE_VALUE (vc_delta
);
2653 /* This is a downcast, so we have to subtract the offset
2654 for the virtual base. */
2655 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
);
2658 TREE_READONLY (new_delta
) = 0;
2659 TREE_TYPE (new_delta
) =
2660 cp_build_qualified_type (TREE_TYPE (new_delta
),
2661 CP_TYPE_QUALS (TREE_TYPE (new_delta
))
2662 & ~TYPE_QUAL_CONST
);
2663 expand_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
2667 virtuals
= TREE_CHAIN (virtuals
);
2671 /* Fixup upcast offsets for all direct vtables. Patterned after
2672 expand_direct_vtbls_init. */
2675 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
2676 tree real_binfo
, binfo
;
2677 int init_self
, can_elide
;
2678 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
2680 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
2681 tree binfos
= BINFO_BASETYPES (binfo
);
2682 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
2684 for (i
= 0; i
< n_baselinks
; i
++)
2686 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
2687 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2688 int is_not_base_vtable
2689 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo
));
2690 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
2691 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
2692 is_not_base_vtable
, can_elide
, addr
,
2693 orig_addr
, type
, vbase
, vbase_offsets
);
2696 /* Before turning this on, make sure it is correct. */
2697 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
2700 /* Should we use something besides CLASSTYPE_VFIELDS? */
2701 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
2703 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
2704 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
2705 type
, vbase_offsets
);
2709 /* Build a COMPOUND_EXPR which when expanded will generate the code
2710 needed to initialize all the virtual function table slots of all
2711 the virtual baseclasses. MAIN_BINFO is the binfo which determines
2712 the virtual baseclasses to use; TYPE is the type of the object to
2713 which the initialization applies. TRUE_EXP is the true object we
2714 are initializing, and DECL_PTR is the pointer to the sub-object we
2717 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
2718 object was laid out by a top-level constructor and the computed
2719 offsets are valid to store vtables. When zero, we must store new
2720 vtables through virtual baseclass pointers. */
2723 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
)
2725 tree true_exp
, decl_ptr
;
2727 tree type
= BINFO_TYPE (binfo
);
2729 /* This function executes during the finish_function() segment,
2730 AFTER the auto variables and temporary stack space has been marked
2731 unused...If space is needed for the virtual function tables,
2732 some of them might fit within what the compiler now thinks
2733 are available stack slots... These values are actually initialized at
2734 the beginnning of the function, so when the automatics use their space,
2735 they will overwrite the values that are placed here. Marking all
2736 temporary space as unavailable prevents this from happening. */
2738 mark_all_temps_used();
2740 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2742 rtx fixup_insns
= NULL_RTX
;
2743 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
2744 struct vbase_info vi
;
2745 vi
.decl_ptr
= (true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0)
2747 vi
.vbase_types
= vbases
;
2749 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
, &vi
);
2751 /* Initialized with vtables of type TYPE. */
2752 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
2756 addr
= convert_pointer_to_vbase (TREE_TYPE (vbases
), vi
.decl_ptr
);
2758 /* Do all vtables from this virtual base. */
2759 /* This assumes that virtual bases can never serve as parent
2760 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
2761 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
2764 /* Now we adjust the offsets for virtual functions that
2765 cross virtual boundaries on an implicit upcast on vf call
2766 so that the layout of the most complete type is used,
2767 instead of assuming the layout of the virtual bases from
2768 our current type. */
2770 if (flag_vtable_thunks
)
2772 /* We don't have dynamic thunks yet!
2773 So for now, just fail silently. */
2777 tree vbase_offsets
= NULL_TREE
;
2778 push_to_sequence (fixup_insns
);
2779 fixup_virtual_upcast_offsets (vbases
,
2780 TYPE_BINFO (BINFO_TYPE (vbases
)),
2781 1, 0, addr
, vi
.decl_ptr
,
2782 type
, vbases
, &vbase_offsets
);
2783 fixup_insns
= get_insns ();
2790 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
2791 if (! in_charge_node
)
2793 warning ("recoverable internal compiler error, nobody's in charge!");
2794 in_charge_node
= integer_zero_node
;
2796 in_charge_node
= build_binary_op (EQ_EXPR
, in_charge_node
, integer_zero_node
);
2797 expand_start_cond (in_charge_node
, 0);
2798 emit_insns (fixup_insns
);
2802 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
, 0);
2806 /* get virtual base class types.
2807 This adds type to the vbase_types list in reverse dfs order.
2808 Ordering is very important, so don't change it. */
2811 dfs_get_vbase_types (binfo
, data
)
2815 tree
*vbase_types
= (tree
*) data
;
2817 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
2819 tree new_vbase
= make_binfo (integer_zero_node
, binfo
,
2820 BINFO_VTABLE (binfo
),
2821 BINFO_VIRTUALS (binfo
));
2822 TREE_CHAIN (new_vbase
) = *vbase_types
;
2823 TREE_VIA_VIRTUAL (new_vbase
) = 1;
2824 *vbase_types
= new_vbase
;
2825 SET_BINFO_VBASE_MARKED (binfo
);
2827 SET_BINFO_MARKED (binfo
);
2831 /* Return a list of binfos for the virtual base classes for TYPE, in
2832 depth-first search order. The list is freshly allocated, so
2833 no modification is made to the current binfo hierarchy. */
2836 get_vbase_types (type
)
2843 binfo
= TYPE_BINFO (type
);
2844 vbase_types
= NULL_TREE
;
2845 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
, &vbase_types
);
2846 dfs_walk (binfo
, dfs_unmark
, markedp
, 0);
2847 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2848 reverse it so that we get normal dfs ordering. */
2849 vbase_types
= nreverse (vbase_types
);
2851 /* unmark marked vbases */
2852 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
2853 CLEAR_BINFO_VBASE_MARKED (vbases
);
2858 /* If we want debug info for a type TYPE, make sure all its base types
2859 are also marked as being potentially interesting. This avoids
2860 the problem of not writing any debug info for intermediate basetypes
2861 that have abstract virtual functions. Also mark member types. */
2864 note_debug_info_needed (type
)
2869 if (current_template_parms
)
2872 if (TYPE_BEING_DEFINED (type
))
2873 /* We can't go looking for the base types and fields just yet. */
2876 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2877 does not support name references between translation units. Well, we
2878 could, but that would mean putting global labels in the debug output
2879 before each exported type and each of its functions and static data
2881 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
2882 || write_symbols
== NO_DEBUG
)
2885 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
, 0);
2886 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2889 if (TREE_CODE (field
) == FIELD_DECL
2890 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
2891 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
), 0))
2892 note_debug_info_needed (ttype
);
2896 /* Subroutines of push_class_decls (). */
2898 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2899 because it (or one of the intermediate bases) depends on template parms. */
2902 dependent_base_p (binfo
)
2905 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2907 if (currently_open_class (TREE_TYPE (binfo
)))
2909 if (uses_template_parms (TREE_TYPE (binfo
)))
2916 setup_class_bindings (name
, type_binding_p
)
2920 tree type_binding
= NULL_TREE
;
2923 /* If we've already done the lookup for this declaration, we're
2925 if (IDENTIFIER_CLASS_VALUE (name
))
2928 /* First, deal with the type binding. */
2931 type_binding
= lookup_member (current_class_type
, name
,
2934 if (TREE_CODE (type_binding
) == TREE_LIST
2935 && TREE_TYPE (type_binding
) == error_mark_node
)
2936 /* NAME is ambiguous. */
2937 push_class_level_binding (name
, type_binding
);
2939 pushdecl_class_level (type_binding
);
2942 /* Now, do the value binding. */
2943 value_binding
= lookup_member (current_class_type
, name
,
2948 && (TREE_CODE (value_binding
) == TYPE_DECL
2949 || (TREE_CODE (value_binding
) == TREE_LIST
2950 && TREE_TYPE (value_binding
) == error_mark_node
2951 && (TREE_CODE (TREE_VALUE (value_binding
))
2953 /* We found a type-binding, even when looking for a non-type
2954 binding. This means that we already processed this binding
2956 my_friendly_assert (type_binding_p
, 19990401);
2957 else if (value_binding
)
2959 if (TREE_CODE (value_binding
) == TREE_LIST
2960 && TREE_TYPE (value_binding
) == error_mark_node
)
2961 /* NAME is ambiguous. */
2962 push_class_level_binding (name
, value_binding
);
2965 if (BASELINK_P (value_binding
))
2966 /* NAME is some overloaded functions. */
2967 value_binding
= TREE_VALUE (value_binding
);
2968 pushdecl_class_level (value_binding
);
2973 /* Push class-level declarations for any names appearing in BINFO that
2977 dfs_push_type_decls (binfo
, data
)
2979 void *data ATTRIBUTE_UNUSED
;
2984 type
= BINFO_TYPE (binfo
);
2985 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2986 if (DECL_NAME (fields
) && TREE_CODE (fields
) == TYPE_DECL
2987 && !(!same_type_p (type
, current_class_type
)
2988 && template_self_reference_p (type
, fields
)))
2989 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/1);
2991 /* We can't just use BINFO_MARKED because envelope_add_decl uses
2992 DERIVED_FROM_P, which calls get_base_distance. */
2993 SET_BINFO_PUSHDECLS_MARKED (binfo
);
2998 /* Push class-level declarations for any names appearing in BINFO that
2999 are not TYPE_DECLS. */
3002 dfs_push_decls (binfo
, data
)
3010 type
= BINFO_TYPE (binfo
);
3011 dep_base_p
= (processing_template_decl
&& type
!= current_class_type
3012 && dependent_base_p (binfo
));
3016 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3017 if (DECL_NAME (fields
)
3018 && TREE_CODE (fields
) != TYPE_DECL
3019 && TREE_CODE (fields
) != USING_DECL
)
3020 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/0);
3021 else if (TREE_CODE (fields
) == FIELD_DECL
3022 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
3023 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields
)), data
);
3025 method_vec
= (CLASS_TYPE_P (type
)
3026 ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
);
3032 /* Farm out constructors and destructors. */
3033 end
= TREE_VEC_END (method_vec
);
3035 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3036 *methods
&& methods
!= end
;
3038 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods
)),
3039 /*type_binding_p=*/0);
3043 CLEAR_BINFO_PUSHDECLS_MARKED (binfo
);
3048 /* When entering the scope of a class, we cache all of the
3049 fields that that class provides within its inheritance
3050 lattice. Where ambiguities result, we mark them
3051 with `error_mark_node' so that if they are encountered
3052 without explicit qualification, we can emit an error
3056 push_class_decls (type
)
3059 struct obstack
*ambient_obstack
= current_obstack
;
3060 search_stack
= push_search_level (search_stack
, &search_obstack
);
3062 /* Build up all the relevant bindings and such on the cache
3063 obstack. That way no memory is wasted when we throw away the
3065 push_cache_obstack ();
3067 /* Enter type declarations and mark. */
3068 dfs_walk (TYPE_BINFO (type
), dfs_push_type_decls
, unmarked_pushdecls_p
, 0);
3070 /* Enter non-type declarations and unmark. */
3071 dfs_walk (TYPE_BINFO (type
), dfs_push_decls
, marked_pushdecls_p
, 0);
3073 /* Undo the call to push_cache_obstack above. */
3076 current_obstack
= ambient_obstack
;
3079 /* Here's a subroutine we need because C lacks lambdas. */
3082 dfs_unuse_fields (binfo
, data
)
3084 void *data ATTRIBUTE_UNUSED
;
3086 tree type
= TREE_TYPE (binfo
);
3089 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3091 if (TREE_CODE (fields
) != FIELD_DECL
)
3094 TREE_USED (fields
) = 0;
3095 if (DECL_NAME (fields
) == NULL_TREE
3096 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
3097 unuse_fields (TREE_TYPE (fields
));
3107 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
, 0);
3113 /* We haven't pushed a search level when dealing with cached classes,
3114 so we'd better not try to pop it. */
3116 search_stack
= pop_search_level (search_stack
);
3120 print_search_statistics ()
3122 #ifdef GATHER_STATISTICS
3123 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3124 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3125 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3126 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3127 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3128 #else /* GATHER_STATISTICS */
3129 fprintf (stderr
, "no search statistics\n");
3130 #endif /* GATHER_STATISTICS */
3134 init_search_processing ()
3136 gcc_obstack_init (&search_obstack
);
3137 vptr_identifier
= get_identifier ("_vptr");
3141 reinit_search_statistics ()
3143 #ifdef GATHER_STATISTICS
3144 n_fields_searched
= 0;
3145 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3146 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3147 n_calls_get_base_type
= 0;
3148 n_outer_fields_searched
= 0;
3149 n_contexts_saved
= 0;
3150 #endif /* GATHER_STATISTICS */
3153 #define scratch_tree_cons expr_tree_cons
3156 add_conversions (binfo
, data
)
3161 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3162 tree
*conversions
= (tree
*) data
;
3164 /* Some builtin types have no method vector, not even an empty one. */
3168 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3170 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3173 if (!tmp
|| ! DECL_CONV_FN_P (OVL_CURRENT (tmp
)))
3176 name
= DECL_NAME (OVL_CURRENT (tmp
));
3178 /* Make sure we don't already have this conversion. */
3179 if (! IDENTIFIER_MARKED (name
))
3181 *conversions
= scratch_tree_cons (binfo
, tmp
, *conversions
);
3182 IDENTIFIER_MARKED (name
) = 1;
3188 /* Return a TREE_LIST containing all the non-hidden user-defined
3189 conversion functions for TYPE (and its base-classes). The
3190 TREE_VALUE of each node is a FUNCTION_DECL or an OVERLOAD
3191 containing the conversion functions. The TREE_PURPOSE is the BINFO
3192 from which the conversion functions in this node were selected. */
3195 lookup_conversions (type
)
3199 tree conversions
= NULL_TREE
;
3201 if (TYPE_SIZE (type
))
3202 bfs_walk (TYPE_BINFO (type
), add_conversions
, 0, &conversions
);
3204 for (t
= conversions
; t
; t
= TREE_CHAIN (t
))
3205 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t
)))) = 0;
3216 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3217 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3220 dfs_check_overlap (empty_binfo
, data
)
3224 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3226 for (binfo
= TYPE_BINFO (oi
->compare_type
);
3228 binfo
= BINFO_BASETYPE (binfo
, 0))
3230 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3232 oi
->found_overlap
= 1;
3235 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3242 /* Trivial function to stop base traversal when we find something. */
3245 dfs_no_overlap_yet (binfo
, data
)
3249 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3250 return !oi
->found_overlap
? binfo
: NULL_TREE
;
3253 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3254 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3257 types_overlap_p (empty_type
, next_type
)
3258 tree empty_type
, next_type
;
3260 struct overlap_info oi
;
3262 if (! IS_AGGR_TYPE (next_type
))
3264 oi
.compare_type
= next_type
;
3265 oi
.found_overlap
= 0;
3266 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
,
3267 dfs_no_overlap_yet
, &oi
);
3268 return oi
.found_overlap
;
3271 /* Given a vtable VAR, determine which binfo it comes from. */
3274 binfo_for_vtable (var
)
3277 tree binfo
= TYPE_BINFO (DECL_CONTEXT (var
));
3283 binfos
= BINFO_BASETYPES (binfo
);
3284 if (binfos
== NULL_TREE
)
3287 i
= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
3291 binfo
= TREE_VEC_ELT (binfos
, i
);
3297 /* Returns 1 iff BINFO is from a direct or indirect virtual base. */
3300 binfo_from_vbase (binfo
)
3303 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
3305 if (TREE_VIA_VIRTUAL (binfo
))