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 int get_base_distance_recursive
93 PROTO((tree
, int, int, int, int *, tree
*, tree
,
94 int, int *, int, int));
95 static void expand_upcast_fixups
96 PROTO((tree
, tree
, tree
, tree
, tree
, tree
, tree
*));
97 static void fixup_virtual_upcast_offsets
98 PROTO((tree
, tree
, int, int, tree
, tree
, tree
, tree
,
100 static tree unmarkedp
PROTO((tree
, void *));
101 static tree marked_vtable_pathp
PROTO((tree
, void *));
102 static tree unmarked_vtable_pathp
PROTO((tree
, void *));
103 static tree marked_new_vtablep
PROTO((tree
, void *));
104 static tree unmarked_new_vtablep
PROTO((tree
, void *));
105 static tree marked_pushdecls_p
PROTO((tree
, void *));
106 static tree unmarked_pushdecls_p
PROTO((tree
, void *));
107 static tree dfs_debug_unmarkedp
PROTO((tree
, void *));
108 static tree dfs_debug_mark
PROTO((tree
, void *));
109 static tree dfs_find_vbases
PROTO((tree
, void *));
110 static tree dfs_clear_vbase_slots
PROTO((tree
, void *));
111 static tree dfs_init_vbase_pointers
PROTO((tree
, void *));
112 static tree dfs_get_vbase_types
PROTO((tree
, void *));
113 static tree dfs_push_type_decls
PROTO((tree
, void *));
114 static tree dfs_push_decls
PROTO((tree
, void *));
115 static tree dfs_unuse_fields
PROTO((tree
, void *));
116 static tree add_conversions
PROTO((tree
, void *));
117 static tree get_virtuals_named_this
PROTO((tree
, tree
));
118 static tree get_virtual_destructor
PROTO((tree
, void *));
119 static tree tree_has_any_destructor_p
PROTO((tree
, void *));
120 static int covariant_return_p
PROTO((tree
, tree
));
121 static struct search_level
*push_search_level
122 PROTO((struct stack_level
*, struct obstack
*));
123 static struct search_level
*pop_search_level
124 PROTO((struct stack_level
*));
126 PROTO((tree
, tree (*) (tree
, void *), tree (*) (tree
, void *),
128 static tree lookup_field_queue_p
PROTO((tree
, void *));
129 static tree lookup_field_r
PROTO((tree
, void *));
130 static tree dfs_walk_real
PROTO ((tree
,
131 tree (*) (tree
, void *),
132 tree (*) (tree
, void *),
133 tree (*) (tree
, void *),
135 static tree dfs_bfv_queue_p
PROTO ((tree
, void *));
136 static tree dfs_bfv_helper
PROTO ((tree
, void *));
137 static tree get_virtuals_named_this_r
PROTO ((tree
, void *));
138 static tree context_for_name_lookup
PROTO ((tree
));
139 static tree canonical_binfo
PROTO ((tree
));
140 static tree shared_marked_p
PROTO ((tree
, void *));
141 static tree shared_unmarked_p
PROTO ((tree
, void *));
142 static int dependent_base_p
PROTO ((tree
));
143 static tree dfs_accessible_queue_p
PROTO ((tree
, void *));
144 static tree dfs_accessible_p
PROTO ((tree
, void *));
145 static tree dfs_access_in_type
PROTO ((tree
, void *));
146 static tree access_in_type
PROTO ((tree
, tree
));
147 static tree dfs_canonical_queue
PROTO ((tree
, void *));
148 static tree dfs_assert_unmarked_p
PROTO ((tree
, void *));
149 static void assert_canonical_unmarked
PROTO ((tree
));
150 static int protected_accessible_p
PROTO ((tree
, tree
, tree
, tree
));
151 static int friend_accessible_p
PROTO ((tree
, tree
, tree
, tree
));
152 static void setup_class_bindings
PROTO ((tree
, int));
153 static int template_self_reference_p
PROTO ((tree
, tree
));
155 /* Allocate a level of searching. */
157 static struct search_level
*
158 push_search_level (stack
, obstack
)
159 struct stack_level
*stack
;
160 struct obstack
*obstack
;
162 struct search_level tem
;
165 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
168 /* Discard a level of search allocation. */
170 static struct search_level
*
171 pop_search_level (obstack
)
172 struct stack_level
*obstack
;
174 register struct search_level
*stack
= pop_stack_level (obstack
);
179 static tree _vptr_name
;
181 /* Variables for gathering statistics. */
182 #ifdef GATHER_STATISTICS
183 static int n_fields_searched
;
184 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
185 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
186 static int n_calls_get_base_type
;
187 static int n_outer_fields_searched
;
188 static int n_contexts_saved
;
189 #endif /* GATHER_STATISTICS */
192 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
193 the same type as the type given in PARENT. To be optimal, we want
194 the first one that is found by going through the least number of
197 This uses a clever algorithm that updates *depth when we find the vbase,
198 and cuts off other paths of search when they reach that depth. */
201 get_vbase_1 (parent
, binfo
, depth
)
207 tree rval
= NULL_TREE
;
209 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
217 binfos
= BINFO_BASETYPES (binfo
);
218 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
220 /* Process base types. */
221 for (i
= 0; i
< n_baselinks
; i
++)
223 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
229 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
237 /* Return the shortest path to vbase PARENT within BINFO, ignoring
238 access and ambiguity. */
241 get_vbase (parent
, binfo
)
245 unsigned int d
= (unsigned int)-1;
246 return get_vbase_1 (parent
, binfo
, &d
);
249 /* Convert EXPR to a virtual base class of type TYPE. We know that
250 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
251 the type of what expr points to has a virtual base of type TYPE. */
254 convert_pointer_to_vbase (type
, expr
)
258 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
259 return convert_pointer_to_real (vb
, expr
);
262 /* Check whether the type given in BINFO is derived from PARENT. If
263 it isn't, return 0. If it is, but the derivation is MI-ambiguous
264 AND protect != 0, emit an error message and return error_mark_node.
266 Otherwise, if TYPE is derived from PARENT, return the actual base
267 information, unless a one of the protection violations below
268 occurs, in which case emit an error message and return error_mark_node.
270 If PROTECT is 1, then check if access to a public field of PARENT
271 would be private. Also check for ambiguity. */
274 get_binfo (parent
, binfo
, protect
)
275 register tree parent
, binfo
;
278 tree type
= NULL_TREE
;
280 tree rval
= NULL_TREE
;
282 if (TREE_CODE (parent
) == TREE_VEC
)
283 parent
= BINFO_TYPE (parent
);
284 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
285 my_friendly_abort (89);
287 if (TREE_CODE (binfo
) == TREE_VEC
)
288 type
= BINFO_TYPE (binfo
);
289 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
292 my_friendly_abort (90);
294 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
298 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
300 return error_mark_node
;
302 else if (dist
== -2 && protect
)
304 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
306 return error_mark_node
;
312 /* This is the newer depth first get_base_distance routine. */
315 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
316 rval_private_ptr
, new_binfo_ptr
, parent
,
317 protect
, via_virtual_ptr
, via_virtual
,
318 current_scope_in_chain
)
320 int depth
, is_private
, rval
;
321 int *rval_private_ptr
;
322 tree
*new_binfo_ptr
, parent
;
323 int protect
, *via_virtual_ptr
, via_virtual
;
324 int current_scope_in_chain
;
330 && !current_scope_in_chain
331 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
332 current_scope_in_chain
= 1;
334 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
339 /* This is the first time we've found parent. */
341 else if (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
342 BINFO_OFFSET (binfo
))
343 && *via_virtual_ptr
&& via_virtual
)
345 /* A new path to the same vbase. If this one has better
346 access or is shorter, take it. */
349 better
= *rval_private_ptr
- is_private
;
351 better
= rval
- depth
;
355 /* Ambiguous base class. */
358 /* If we get an ambiguity between virtual and non-virtual base
359 class, return the non-virtual in case we are ignoring
361 better
= *via_virtual_ptr
- via_virtual
;
367 *rval_private_ptr
= is_private
;
368 *new_binfo_ptr
= binfo
;
369 *via_virtual_ptr
= via_virtual
;
375 binfos
= BINFO_BASETYPES (binfo
);
376 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
379 /* Process base types. */
380 for (i
= 0; i
< n_baselinks
; i
++)
382 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
387 || (!TREE_VIA_PUBLIC (base_binfo
)
388 && !(TREE_VIA_PROTECTED (base_binfo
)
389 && current_scope_in_chain
)
390 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
391 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
393 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
394 rval
, rval_private_ptr
,
395 new_binfo_ptr
, parent
,
396 protect
, via_virtual_ptr
,
398 current_scope_in_chain
);
400 /* If we've found a non-virtual, ambiguous base class, we don't need
401 to keep searching. */
402 if (rval
== -2 && *via_virtual_ptr
== 0)
409 /* Return the number of levels between type PARENT and the type given
410 in BINFO, following the leftmost path to PARENT not found along a
411 virtual path, if there are no real PARENTs (all come from virtual
412 base classes), then follow the shortest public path to PARENT.
414 Return -1 if TYPE is not derived from PARENT.
415 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
417 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
419 If PATH_PTR is non-NULL, then also build the list of types
420 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
423 PARENT can also be a binfo, in which case that exact parent is found
424 and no other. convert_pointer_to_real uses this functionality.
426 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
429 get_base_distance (parent
, binfo
, protect
, path_ptr
)
430 register tree parent
, binfo
;
435 int rval_private
= 0;
436 tree type
= NULL_TREE
;
437 tree new_binfo
= NULL_TREE
;
439 int watch_access
= protect
;
441 /* Should we be completing types here? */
442 if (TREE_CODE (parent
) != TREE_VEC
)
443 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
445 complete_type (TREE_TYPE (parent
));
447 if (TREE_CODE (binfo
) == TREE_VEC
)
448 type
= BINFO_TYPE (binfo
);
449 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
451 type
= complete_type (binfo
);
452 binfo
= TYPE_BINFO (type
);
455 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
,
459 my_friendly_abort (92);
461 if (parent
== type
|| parent
== binfo
)
463 /* If the distance is 0, then we don't really need
464 a path pointer, but we shouldn't let garbage go back. */
473 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
474 &rval_private
, &new_binfo
, parent
,
475 watch_access
, &via_virtual
, 0,
478 /* Access restrictions don't count if we found an ambiguous basetype. */
479 if (rval
== -2 && protect
>= 0)
482 if (rval
&& protect
&& rval_private
)
485 /* If they gave us the real vbase binfo, which isn't in the main binfo
486 tree, deal with it. This happens when we are called from
487 expand_upcast_fixups. */
488 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
489 && parent
== binfo_member (BINFO_TYPE (parent
),
490 CLASSTYPE_VBASECLASSES (type
)))
492 my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent
) == binfo
, 980827);
498 *path_ptr
= new_binfo
;
502 /* Search for a member with name NAME in a multiple inheritance lattice
503 specified by TYPE. If it does not exist, return NULL_TREE.
504 If the member is ambiguously referenced, return `error_mark_node'.
505 Otherwise, return the FIELD_DECL. */
507 /* Do a 1-level search for NAME as a member of TYPE. The caller must
508 figure out whether it can access this field. (Since it is only one
509 level, this is reasonable.) */
512 lookup_field_1 (type
, name
)
517 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
518 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
519 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
520 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
521 the code often worked even when we treated the index as a list
526 && DECL_LANG_SPECIFIC (TYPE_NAME (type
))
527 && DECL_SORTED_FIELDS (TYPE_NAME (type
)))
529 tree
*fields
= &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type
)), 0);
530 int lo
= 0, hi
= TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type
)));
537 #ifdef GATHER_STATISTICS
539 #endif /* GATHER_STATISTICS */
541 if (DECL_NAME (fields
[i
]) > name
)
543 else if (DECL_NAME (fields
[i
]) < name
)
551 field
= TYPE_FIELDS (type
);
553 #ifdef GATHER_STATISTICS
554 n_calls_lookup_field_1
++;
555 #endif /* GATHER_STATISTICS */
558 #ifdef GATHER_STATISTICS
560 #endif /* GATHER_STATISTICS */
561 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
562 if (DECL_NAME (field
) == NULL_TREE
563 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
565 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
569 if (TREE_CODE (field
) == USING_DECL
)
570 /* For now, we're just treating member using declarations as
571 old ARM-style access declarations. Thus, there's no reason
572 to return a USING_DECL, and the rest of the compiler can't
573 handle it. Once the class is defined, these are purged
574 from TYPE_FIELDS anyhow; see handle_using_decl. */
576 else if (DECL_NAME (field
) == name
)
578 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
579 && DECL_ASSEMBLER_NAME (field
) != NULL
)
580 GNU_xref_ref(current_function_decl
,
581 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
584 field
= TREE_CHAIN (field
);
587 if (name
== _vptr_name
)
589 /* Give the user what s/he thinks s/he wants. */
590 if (TYPE_VIRTUAL_P (type
))
591 return CLASSTYPE_VFIELD (type
);
596 /* There are a number of cases we need to be aware of here:
597 current_class_type current_function_decl
604 Those last two make life interesting. If we're in a function which is
605 itself inside a class, we need decls to go into the fn's decls (our
606 second case below). But if we're in a class and the class itself is
607 inside a function, we need decls to go into the decls for the class. To
608 achieve this last goal, we must see if, when both current_class_ptr and
609 current_function_decl are set, the class was declared inside that
610 function. If so, we know to put the decls into the class's scope. */
615 if (current_function_decl
== NULL_TREE
)
616 return current_class_type
;
617 if (current_class_type
== NULL_TREE
)
618 return current_function_decl
;
619 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
620 return current_function_decl
;
622 return current_class_type
;
625 /* Return the scope of DECL, as appropriate when doing name-lookup. */
628 context_for_name_lookup (decl
)
633 For the purposes of name lookup, after the anonymous union
634 definition, the members of the anonymous union are considered to
635 have been defined in the scope in which teh anonymous union is
637 tree context
= DECL_REAL_CONTEXT (decl
);
639 while (TYPE_P (context
) && ANON_AGGR_TYPE_P (context
))
640 context
= TYPE_CONTEXT (context
);
642 context
= global_namespace
;
647 /* Return a canonical BINFO if BINFO is a virtual base, or just BINFO
651 canonical_binfo (binfo
)
654 return (TREE_VIA_VIRTUAL (binfo
)
655 ? TYPE_BINFO (BINFO_TYPE (binfo
)) : binfo
);
658 /* A queue function that simply ensures that we walk into the
659 canonical versions of virtual bases. */
662 dfs_canonical_queue (binfo
, data
)
664 void *data ATTRIBUTE_UNUSED
;
666 return canonical_binfo (binfo
);
669 /* Called via dfs_walk from assert_canonical_unmarked. */
672 dfs_assert_unmarked_p (binfo
, data
)
674 void *data ATTRIBUTE_UNUSED
;
676 my_friendly_assert (!BINFO_MARKED (binfo
), 0);
680 /* Asserts that all the nodes below BINFO (using the canonical
681 versions of virtual bases) are unmarked. */
684 assert_canonical_unmarked (binfo
)
687 dfs_walk (binfo
, dfs_assert_unmarked_p
, dfs_canonical_queue
, 0);
690 /* If BINFO is marked, return a canonical version of BINFO.
691 Otherwise, return NULL_TREE. */
694 shared_marked_p (binfo
, data
)
698 binfo
= canonical_binfo (binfo
);
699 return markedp (binfo
, data
) ? binfo
: NULL_TREE
;
702 /* If BINFO is not marked, return a canonical version of BINFO.
703 Otherwise, return NULL_TREE. */
706 shared_unmarked_p (binfo
, data
)
710 binfo
= canonical_binfo (binfo
);
711 return unmarkedp (binfo
, data
) ? binfo
: NULL_TREE
;
714 /* Called from access_in_type via dfs_walk. Calculate the access to
715 DATA (which is really a DECL) in BINFO. */
718 dfs_access_in_type (binfo
, data
)
722 tree decl
= (tree
) data
;
723 tree type
= BINFO_TYPE (binfo
);
724 tree access
= NULL_TREE
;
726 if (context_for_name_lookup (decl
) == type
)
728 /* If we have desceneded to the scope of DECL, just note the
729 appropriate access. */
730 if (TREE_PRIVATE (decl
))
731 access
= access_private_node
;
732 else if (TREE_PROTECTED (decl
))
733 access
= access_protected_node
;
735 access
= access_public_node
;
739 /* First, check for an access-declaration that gives us more
740 access to the DECL. The CONST_DECL for an enumeration
741 constant will not have DECL_LANG_SPECIFIC, and thus no
743 if (DECL_LANG_SPECIFIC (decl
))
745 access
= purpose_member (type
, DECL_ACCESS (decl
));
747 access
= TREE_VALUE (access
);
756 /* Otherwise, scan our baseclasses, and pick the most favorable
758 binfos
= BINFO_BASETYPES (binfo
);
759 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
760 for (i
= 0; i
< n_baselinks
; ++i
)
762 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
763 tree base_access
= TREE_CHAIN (canonical_binfo (base_binfo
));
765 if (!base_access
|| base_access
== access_private_node
)
766 /* If it was not accessible in the base, or only
767 accessible as a private member, we can't access it
769 base_access
= NULL_TREE
;
770 else if (TREE_VIA_PROTECTED (base_binfo
))
771 /* Public and protected members in the base are
773 base_access
= access_protected_node
;
774 else if (!TREE_VIA_PUBLIC (base_binfo
))
775 /* Public and protected members in the base are
777 base_access
= access_private_node
;
779 /* See if the new access, via this base, gives more
780 access than our previous best access. */
782 (base_access
== access_public_node
783 || (base_access
== access_protected_node
784 && access
!= access_public_node
)
785 || (base_access
== access_private_node
788 access
= base_access
;
790 /* If the new access is public, we can't do better. */
791 if (access
== access_public_node
)
798 /* Note the access to DECL in TYPE. */
799 TREE_CHAIN (binfo
) = access
;
801 /* Mark TYPE as visited so that if we reach it again we do not
802 duplicate our efforts here. */
803 SET_BINFO_MARKED (binfo
);
808 /* Return the access to DECL in TYPE. */
811 access_in_type (type
, decl
)
815 tree binfo
= TYPE_BINFO (type
);
817 /* We must take into account
821 If a name can be reached by several paths through a multiple
822 inheritance graph, the access is that of the path that gives
825 The algorithm we use is to make a post-order depth-first traversal
826 of the base-class hierarchy. As we come up the tree, we annotate
827 each node with the most lenient access. */
828 dfs_walk_real (binfo
, 0, dfs_access_in_type
, shared_unmarked_p
, decl
);
829 dfs_walk (binfo
, dfs_unmark
, shared_marked_p
, 0);
830 assert_canonical_unmarked (binfo
);
832 return TREE_CHAIN (binfo
);
835 /* Called from dfs_accessible_p via dfs_walk. */
838 dfs_accessible_queue_p (binfo
, data
)
840 void *data ATTRIBUTE_UNUSED
;
842 if (BINFO_MARKED (binfo
))
845 /* If this class is inherited via private or protected inheritance,
846 then we can't see it, unless we are a friend of the subclass. */
847 if (!TREE_VIA_PUBLIC (binfo
)
848 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
)),
852 return canonical_binfo (binfo
);
855 /* Called from dfs_accessible_p via dfs_walk. */
858 dfs_accessible_p (binfo
, data
)
862 int protected_ok
= data
!= 0;
865 /* We marked the binfos while computing the access in each type.
866 So, we unmark as we go now. */
867 SET_BINFO_MARKED (binfo
);
869 access
= TREE_CHAIN (binfo
);
870 if (access
== access_public_node
871 || (access
== access_protected_node
&& protected_ok
))
873 else if (access
&& is_friend (BINFO_TYPE (binfo
), current_scope ()))
879 /* Returns non-zero if it is OK to access DECL when named in TYPE
880 through an object indiated by BINFO in the context of DERIVED. */
883 protected_accessible_p (type
, decl
, derived
, binfo
)
891 /* We're checking this clause from [class.access.base]
893 m as a member of N is protected, and the reference occurs in a
894 member or friend of class N, or in a member or friend of a
895 class P derived from N, where m as a member of P is private or
898 If DERIVED isn't derived from TYPE, then it certainly does not
900 if (!DERIVED_FROM_P (type
, derived
))
903 access
= access_in_type (derived
, decl
);
904 if (same_type_p (derived
, type
))
906 if (access
!= access_private_node
)
909 else if (access
!= access_private_node
910 && access
!= access_protected_node
)
915 When a friend or a member function of a derived class references
916 a protected nonstatic member of a base class, an access check
917 applies in addition to those described earlier in clause
918 _class.access_.4) Except when forming a pointer to member
919 (_expr.unary.op_), the access must be through a pointer to,
920 reference to, or object of the derived class itself (or any class
921 derived from that class) (_expr.ref_). If the access is to form
922 a pointer to member, the nested-name-specifier shall name the
923 derived class (or any class derived from that class). */
924 if (DECL_NONSTATIC_MEMBER_P (decl
))
926 /* We can tell through what the reference is occurring by
927 chasing BINFO up to the root. */
929 while (BINFO_INHERITANCE_CHAIN (t
))
930 t
= BINFO_INHERITANCE_CHAIN (t
);
932 if (!DERIVED_FROM_P (derived
, BINFO_TYPE (t
)))
939 /* Returns non-zero if SCOPE is a friend of a type which would be able
940 to acces DECL, named in TYPE, through the object indicated by
944 friend_accessible_p (scope
, type
, decl
, binfo
)
950 tree befriending_classes
;
956 if (TREE_CODE (scope
) == FUNCTION_DECL
957 || DECL_FUNCTION_TEMPLATE_P (scope
))
958 befriending_classes
= DECL_BEFRIENDING_CLASSES (scope
);
959 else if (TYPE_P (scope
))
960 befriending_classes
= CLASSTYPE_BEFRIENDING_CLASSES (scope
);
964 for (t
= befriending_classes
; t
; t
= TREE_CHAIN (t
))
965 if (protected_accessible_p (type
, decl
, TREE_VALUE (t
), binfo
))
968 if (TREE_CODE (scope
) == FUNCTION_DECL
969 || DECL_FUNCTION_TEMPLATE_P (scope
))
971 /* Perhaps this SCOPE is a member of a class which is a
973 if (friend_accessible_p (DECL_CLASS_CONTEXT (scope
), type
,
977 /* Or an instantiation of something which is a friend. */
978 if (DECL_TEMPLATE_INFO (scope
))
979 return friend_accessible_p (DECL_TI_TEMPLATE (scope
),
982 else if (CLASSTYPE_TEMPLATE_INFO (scope
))
983 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope
),
989 /* DECL is a declaration from a base class of TYPE, which was the
990 classs used to name DECL. Return non-zero if, in the current
991 context, DECL is accessible. If TYPE is actually a BINFO node,
992 then we can tell in what context the access is occurring by looking
993 at the most derived class along the path indicated by BINFO. */
996 accessible_p (type
, decl
)
1004 /* Non-zero if it's OK to access DECL if it has protected
1005 accessibility in TYPE. */
1006 int protected_ok
= 0;
1008 /* If we're not checking access, everything is accessible. */
1009 if (!flag_access_control
)
1012 /* If this declaration is in a block or namespace scope, there's no
1014 if (!TYPE_P (context_for_name_lookup (decl
)))
1017 /* We don't do access control for types yet. */
1018 if (TREE_CODE (decl
) == TYPE_DECL
)
1024 type
= BINFO_TYPE (type
);
1027 binfo
= TYPE_BINFO (type
);
1029 /* [class.access.base]
1031 A member m is accessible when named in class N if
1033 --m as a member of N is public, or
1035 --m as a member of N is private, and the reference occurs in a
1036 member or friend of class N, or
1038 --m as a member of N is protected, and the reference occurs in a
1039 member or friend of class N, or in a member or friend of a
1040 class P derived from N, where m as a member of P is private or
1043 --there exists a base class B of N that is accessible at the point
1044 of reference, and m is accessible when named in class B.
1046 We walk the base class hierarchy, checking these conditions. */
1048 /* Figure out where the reference is occurring. Check to see if
1049 DECL is private or protected in this scope, since that will
1050 determine whether protected access in TYPE allowed. */
1051 if (current_class_type
)
1053 = protected_accessible_p (type
, decl
, current_class_type
,
1056 /* Now, loop through the classes of which we are a friend. */
1058 protected_ok
= friend_accessible_p (current_scope (),
1061 /* Standardize on the same that will access_in_type will use. We
1062 don't need to know what path was chosen from this point onwards. */
1063 binfo
= TYPE_BINFO (type
);
1065 /* Compute the accessibility of DECL in the class hierarchy
1066 dominated by type. */
1067 access_in_type (type
, decl
);
1068 /* Walk the hierarchy again, looking for a base class that allows
1070 t
= dfs_walk (binfo
, dfs_accessible_p
,
1071 dfs_accessible_queue_p
,
1072 protected_ok
? &protected_ok
: 0);
1073 /* Clear any mark bits. Note that we have to walk the whole tree
1074 here, since we have aborted the previous walk from some point
1075 deep in the tree. */
1076 dfs_walk (binfo
, dfs_unmark
, dfs_canonical_queue
, 0);
1077 assert_canonical_unmarked (binfo
);
1079 return t
!= NULL_TREE
;
1082 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1083 found as a base class and sub-object of the object denoted by
1084 BINFO. This routine relies upon binfos not being shared, except
1085 for binfos for virtual bases. */
1088 is_subobject_of_p (parent
, binfo
)
1094 /* We want to canonicalize for comparison purposes. But, when we
1095 iterate through basetypes later, we want the binfos from the
1096 original hierarchy. That's why we have to calculate BINFOS
1097 first, and then canonicalize. */
1098 binfos
= BINFO_BASETYPES (binfo
);
1099 parent
= canonical_binfo (parent
);
1100 binfo
= canonical_binfo (binfo
);
1102 if (parent
== binfo
)
1105 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1107 /* Process and/or queue base types. */
1108 for (i
= 0; i
< n_baselinks
; i
++)
1110 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1111 if (!CLASS_TYPE_P (TREE_TYPE (base_binfo
)))
1112 /* If we see a TEMPLATE_TYPE_PARM, or some such, as a base
1113 class there's no way to descend into it. */
1116 if (is_subobject_of_p (parent
, base_binfo
))
1122 /* See if a one FIELD_DECL hides another. This routine is meant to
1123 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1124 binfos given are the binfos corresponding to the particular places
1125 the FIELD_DECLs are found. This routine relies upon binfos not
1126 being shared, except for virtual bases. */
1129 hides (hider_binfo
, hidee_binfo
)
1130 tree hider_binfo
, hidee_binfo
;
1132 /* hider hides hidee, if hider has hidee as a base class and
1133 the instance of hidee is a sub-object of hider. The first
1134 part is always true is the second part is true.
1136 When hider and hidee are the same (two ways to get to the exact
1137 same member) we consider either one as hiding the other. */
1138 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
1141 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1142 function was declared inside the class given by TYPE. It really should
1143 only return functions that match the given TYPE. */
1146 lookup_fnfields_here (type
, name
)
1149 int idx
= lookup_fnfields_1 (type
, name
);
1152 /* ctors and dtors are always only in the right class. */
1155 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1158 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls
)))
1159 == TYPE_MAIN_VARIANT (type
))
1161 fndecls
= OVL_CHAIN (fndecls
);
1166 struct lookup_field_info
{
1167 /* The type in which we're looking. */
1169 /* The name of the field for which we're looking. */
1171 /* If non-NULL, the current result of the lookup. */
1173 /* The path to RVAL. */
1175 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1178 /* If non-zero, we are looking for types, not data members. */
1180 /* If non-zero, RVAL was found by looking through a dependent base. */
1181 int from_dep_base_p
;
1182 /* If something went wrong, a message indicating what. */
1186 /* Returns non-zero if BINFO is not hidden by the value found by the
1187 lookup so far. If BINFO is hidden, then there's no need to look in
1188 it. DATA is really a struct lookup_field_info. Called from
1189 lookup_field via breadth_first_search. */
1192 lookup_field_queue_p (binfo
, data
)
1196 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1198 /* Don't look for constructors or destructors in base classes. */
1199 if (lfi
->name
== ctor_identifier
|| lfi
->name
== dtor_identifier
)
1202 /* If this base class is hidden by the best-known value so far, we
1203 don't need to look. */
1204 if (!lfi
->from_dep_base_p
&& lfi
->rval_binfo
1205 && hides (lfi
->rval_binfo
, binfo
))
1208 if (TREE_VIA_VIRTUAL (binfo
))
1209 return binfo_member (BINFO_TYPE (binfo
),
1210 CLASSTYPE_VBASECLASSES (lfi
->type
));
1215 /* Within the scope of a template class, you can refer to the
1216 particular to the current specialization with the name of the
1217 template itself. For example:
1219 template <typename T> struct S { S* sp; }
1221 Returns non-zero if DECL is such a declaration in a class TYPE. */
1224 template_self_reference_p (type
, decl
)
1228 return (CLASSTYPE_USE_TEMPLATE (type
)
1229 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
))
1230 && TREE_CODE (decl
) == TYPE_DECL
1231 && DECL_ARTIFICIAL (decl
)
1232 && DECL_NAME (decl
) == constructor_name (type
));
1235 /* DATA is really a struct lookup_field_info. Look for a field with
1236 the name indicated there in BINFO. If this function returns a
1237 non-NULL value it is the result of the lookup. Called from
1238 lookup_field via breadth_first_search. */
1241 lookup_field_r (binfo
, data
)
1245 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1246 tree type
= BINFO_TYPE (binfo
);
1247 tree nval
= NULL_TREE
;
1248 int from_dep_base_p
;
1250 /* First, look for a function. There can't be a function and a data
1251 member with the same name, and if there's a function and a type
1252 with the same name, the type is hidden by the function. */
1253 if (!lfi
->want_type
)
1255 int idx
= lookup_fnfields_here (type
, lfi
->name
);
1257 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1261 /* Look for a data member or type. */
1262 nval
= lookup_field_1 (type
, lfi
->name
);
1264 /* If there is no declaration with the indicated name in this type,
1265 then there's nothing to do. */
1269 /* If we're looking up a type (as with an elaborated type specifier)
1270 we ignore all non-types we find. */
1271 if (lfi
->want_type
&& TREE_CODE (nval
) != TYPE_DECL
)
1273 nval
= purpose_member (lfi
->name
, CLASSTYPE_TAGS (type
));
1275 nval
= TYPE_MAIN_DECL (TREE_VALUE (nval
));
1280 /* You must name a template base class with a template-id. */
1281 if (!same_type_p (type
, lfi
->type
)
1282 && template_self_reference_p (type
, nval
))
1285 from_dep_base_p
= dependent_base_p (binfo
);
1286 if (lfi
->from_dep_base_p
&& !from_dep_base_p
)
1288 /* If the new declaration is not found via a dependent base, and
1289 the old one was, then we must prefer the new one. We weren't
1290 really supposed to be able to find the old one, so we don't
1291 want to be affected by a specialization. Consider:
1293 struct B { typedef int I; };
1294 template <typename T> struct D1 : virtual public B {};
1295 template <typename T> struct D :
1296 public D1, virtual pubic B { I i; };
1298 The `I' in `D<T>' is unambigousuly `B::I', regardless of how
1299 D1 is specialized. */
1300 lfi
->from_dep_base_p
= 0;
1301 lfi
->rval
= NULL_TREE
;
1302 lfi
->rval_binfo
= NULL_TREE
;
1303 lfi
->ambiguous
= NULL_TREE
;
1306 else if (lfi
->rval_binfo
&& !lfi
->from_dep_base_p
&& from_dep_base_p
)
1307 /* Similarly, if the old declaration was not found via a dependent
1308 base, and the new one is, ignore the new one. */
1311 /* If the lookup already found a match, and the new value doesn't
1312 hide the old one, we might have an ambiguity. */
1313 if (lfi
->rval_binfo
&& !hides (binfo
, lfi
->rval_binfo
))
1315 if (nval
== lfi
->rval
&& SHARED_MEMBER_P (nval
))
1316 /* The two things are really the same. */
1318 else if (hides (lfi
->rval_binfo
, binfo
))
1319 /* The previous value hides the new one. */
1323 /* We have a real ambiguity. We keep a chain of all the
1325 if (!lfi
->ambiguous
&& lfi
->rval
)
1327 /* This is the first time we noticed an ambiguity. Add
1328 what we previously thought was a reasonable candidate
1330 lfi
->ambiguous
= scratch_tree_cons (NULL_TREE
, lfi
->rval
,
1332 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1335 /* Add the new value. */
1336 lfi
->ambiguous
= scratch_tree_cons (NULL_TREE
, nval
,
1338 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1339 lfi
->errstr
= "request for member `%D' is ambiguous";
1344 /* If the thing we're looking for is a virtual base class, then
1345 we know we've got what we want at this point; there's no way
1346 to get an ambiguity. */
1347 if (VBASE_NAME_P (lfi
->name
))
1353 if (from_dep_base_p
&& TREE_CODE (nval
) != TYPE_DECL
1354 /* We need to return a member template class so we can
1355 define partial specializations. Is there a better
1357 && !DECL_CLASS_TEMPLATE_P (nval
))
1358 /* The thing we're looking for isn't a type, so the implicit
1359 typename extension doesn't apply, so we just pretend we
1360 didn't find anything. */
1364 lfi
->from_dep_base_p
= from_dep_base_p
;
1365 lfi
->rval_binfo
= binfo
;
1371 /* Look for a memer named NAME in an inheritance lattice dominated by
1372 XBASETYPE. PROTECT is 0 or two, we do not check access. If it is
1373 1, we enforce accessibility. If PROTECT is zero, then, for an
1374 ambiguous lookup, we return NULL. If PROTECT is 1, we issue an
1375 error message. If PROTECT is 2, we return a TREE_LIST whose
1376 TREEE_TYPE is error_mark_node and whose TREE_VALUEs are the list of
1377 ambiguous candidates.
1379 WANT_TYPE is 1 when we should only return TYPE_DECLs, if no
1380 TYPE_DECL can be found return NULL_TREE. */
1383 lookup_member (xbasetype
, name
, protect
, want_type
)
1384 register tree xbasetype
, name
;
1385 int protect
, want_type
;
1387 tree rval
, rval_binfo
= NULL_TREE
;
1388 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1389 struct lookup_field_info lfi
;
1391 /* rval_binfo is the binfo associated with the found member, note,
1392 this can be set with useful information, even when rval is not
1393 set, because it must deal with ALL members, not just non-function
1394 members. It is used for ambiguity checking and the hidden
1395 checks. Whereas rval is only set if a proper (not hidden)
1396 non-function member is found. */
1398 const char *errstr
= 0;
1400 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1401 && IDENTIFIER_CLASS_VALUE (name
))
1403 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1404 if (TREE_CODE (field
) != FUNCTION_DECL
1405 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1406 /* We're in the scope of this class, and the value has already
1407 been looked up. Just return the cached value. */
1411 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1413 type
= BINFO_TYPE (xbasetype
);
1414 basetype_path
= xbasetype
;
1416 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1419 basetype_path
= TYPE_BINFO (type
);
1420 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
1424 my_friendly_abort (97);
1426 complete_type (type
);
1428 #ifdef GATHER_STATISTICS
1429 n_calls_lookup_field
++;
1430 #endif /* GATHER_STATISTICS */
1432 bzero ((PTR
) &lfi
, sizeof (lfi
));
1435 lfi
.want_type
= want_type
;
1436 bfs_walk (basetype_path
, &lookup_field_r
, &lookup_field_queue_p
, &lfi
);
1438 rval_binfo
= lfi
.rval_binfo
;
1440 type
= BINFO_TYPE (rval_binfo
);
1441 errstr
= lfi
.errstr
;
1443 /* If we are not interested in ambiguities, don't report them;
1444 just return NULL_TREE. */
1445 if (!protect
&& lfi
.ambiguous
)
1451 return lfi
.ambiguous
;
1458 In the case of overloaded function names, access control is
1459 applied to the function selected by overloaded resolution. */
1460 if (rval
&& protect
&& !is_overloaded_fn (rval
)
1461 && !IS_SIGNATURE_POINTER (DECL_REAL_CONTEXT (rval
))
1462 && !IS_SIGNATURE_REFERENCE (DECL_REAL_CONTEXT (rval
))
1463 && !enforce_access (xbasetype
, rval
))
1464 return error_mark_node
;
1466 if (errstr
&& protect
)
1468 cp_error (errstr
, name
, type
);
1470 print_candidates (lfi
.ambiguous
);
1471 rval
= error_mark_node
;
1474 /* If the thing we found was found via the implicit typename
1475 extension, build the typename type. */
1476 if (rval
&& lfi
.from_dep_base_p
&& !DECL_CLASS_TEMPLATE_P (rval
))
1477 rval
= TYPE_STUB_DECL (build_typename_type (BINFO_TYPE (basetype_path
),
1481 if (rval
&& is_overloaded_fn (rval
))
1483 rval
= scratch_tree_cons (basetype_path
, rval
, NULL_TREE
);
1484 SET_BASELINK_P (rval
);
1490 /* Like lookup_member, except that if we find a function member we
1491 return NULL_TREE. */
1494 lookup_field (xbasetype
, name
, protect
, want_type
)
1495 register tree xbasetype
, name
;
1496 int protect
, want_type
;
1498 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
);
1500 /* Ignore functions. */
1501 if (rval
&& TREE_CODE (rval
) == TREE_LIST
)
1507 /* Like lookup_member, except that if we find a non-function member we
1508 return NULL_TREE. */
1511 lookup_fnfields (xbasetype
, name
, protect
)
1512 register tree xbasetype
, name
;
1515 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/0);
1517 /* Ignore non-functions. */
1518 if (rval
&& TREE_CODE (rval
) != TREE_LIST
)
1524 /* TYPE is a class type. Return the index of the fields within
1525 the method vector with name NAME, or -1 is no such field exists. */
1528 lookup_fnfields_1 (type
, name
)
1532 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
1534 if (method_vec
!= 0)
1537 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1538 int len
= TREE_VEC_LENGTH (method_vec
);
1541 #ifdef GATHER_STATISTICS
1542 n_calls_lookup_fnfields_1
++;
1543 #endif /* GATHER_STATISTICS */
1545 /* Constructors are first... */
1546 if (name
== ctor_identifier
)
1547 return methods
[0] ? 0 : -1;
1549 /* and destructors are second. */
1550 if (name
== dtor_identifier
)
1551 return methods
[1] ? 1 : -1;
1553 for (i
= 2; i
< len
&& methods
[i
]; ++i
)
1555 #ifdef GATHER_STATISTICS
1556 n_outer_fields_searched
++;
1557 #endif /* GATHER_STATISTICS */
1559 tmp
= OVL_CURRENT (methods
[i
]);
1560 if (DECL_NAME (tmp
) == name
)
1563 /* If the type is complete and we're past the conversion ops,
1564 switch to binary search. */
1565 if (! DECL_CONV_FN_P (tmp
)
1566 && TYPE_SIZE (type
))
1568 int lo
= i
+ 1, hi
= len
;
1574 #ifdef GATHER_STATISTICS
1575 n_outer_fields_searched
++;
1576 #endif /* GATHER_STATISTICS */
1578 tmp
= DECL_NAME (OVL_CURRENT (methods
[i
]));
1582 else if (tmp
< name
)
1591 /* If we didn't find it, it might have been a template
1592 conversion operator. (Note that we don't look for this case
1593 above so that we will always find specializations first.) */
1594 if (IDENTIFIER_TYPENAME_P (name
))
1596 for (i
= 2; i
< len
&& methods
[i
]; ++i
)
1598 tmp
= OVL_CURRENT (methods
[i
]);
1599 if (! DECL_CONV_FN_P (tmp
))
1601 /* Since all conversion operators come first, we know
1602 there is no such operator. */
1605 else if (TREE_CODE (tmp
) == TEMPLATE_DECL
)
1614 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1615 type in the hierarchy, in a breadth-first preorder traversal. .
1616 If it ever returns a non-NULL value, that value is immediately
1617 returned and the walk is terminated. At each node FN, is passed a
1618 BINFO indicating the path from the curently visited base-class to
1619 TYPE. The TREE_CHAINs of the BINFOs may be used for scratch space;
1620 they are otherwise unused. Before each base-class is walked QFN is
1621 called. If the value returned is non-zero, the base-class is
1622 walked; otherwise it is not. If QFN is NULL, it is treated as a
1623 function which always returns 1. Both FN and QFN are passed the
1624 DATA whenever they are called. */
1627 bfs_walk (binfo
, fn
, qfn
, data
)
1629 tree (*fn
) PROTO((tree
, void *));
1630 tree (*qfn
) PROTO((tree
, void *));
1635 tree rval
= NULL_TREE
;
1636 /* An array of the base classes of BINFO. These will be built up in
1637 breadth-first order, except where QFN prunes the search. */
1638 varray_type bfs_bases
;
1640 /* Start with enough room for ten base classes. That will be enough
1641 for most hierarchies. */
1642 VARRAY_TREE_INIT (bfs_bases
, 10, "search_stack");
1644 /* Put the first type into the stack. */
1645 VARRAY_TREE (bfs_bases
, 0) = binfo
;
1648 for (head
= 0; head
< tail
; ++head
)
1654 /* Pull the next type out of the queue. */
1655 binfo
= VARRAY_TREE (bfs_bases
, head
);
1657 /* If this is the one we're looking for, we're done. */
1658 rval
= (*fn
) (binfo
, data
);
1662 /* Queue up the base types. */
1663 binfos
= BINFO_BASETYPES (binfo
);
1664 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1665 for (i
= 0; i
< n_baselinks
; i
++)
1667 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1670 base_binfo
= (*qfn
) (base_binfo
, data
);
1674 if (tail
== VARRAY_SIZE (bfs_bases
))
1675 VARRAY_GROW (bfs_bases
, 2 * VARRAY_SIZE (bfs_bases
));
1676 VARRAY_TREE (bfs_bases
, tail
) = base_binfo
;
1683 VARRAY_FREE (bfs_bases
);
1688 /* Exactly like bfs_walk, except that a depth-first traversal is
1689 performed, and PREFN is called in preorder, while POSTFN is called
1693 dfs_walk_real (binfo
, prefn
, postfn
, qfn
, data
)
1695 tree (*prefn
) PROTO((tree
, void *));
1696 tree (*postfn
) PROTO((tree
, void *));
1697 tree (*qfn
) PROTO((tree
, void *));
1703 tree rval
= NULL_TREE
;
1705 /* Call the pre-order walking function. */
1708 rval
= (*prefn
) (binfo
, data
);
1713 /* Process the basetypes. */
1714 binfos
= BINFO_BASETYPES (binfo
);
1715 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1716 for (i
= 0; i
< n_baselinks
; i
++)
1718 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1721 base_binfo
= (*qfn
) (base_binfo
, data
);
1725 rval
= dfs_walk_real (base_binfo
, prefn
, postfn
, qfn
, data
);
1731 /* Call the post-order walking function. */
1733 rval
= (*postfn
) (binfo
, data
);
1738 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1742 dfs_walk (binfo
, fn
, qfn
, data
)
1744 tree (*fn
) PROTO((tree
, void *));
1745 tree (*qfn
) PROTO((tree
, void *));
1748 return dfs_walk_real (binfo
, 0, fn
, qfn
, data
);
1753 /* The name of the function we are looking for. */
1755 /* The overloaded functions we have found. */
1759 /* Called from get_virtuals_named_this via bfs_walk. */
1762 get_virtuals_named_this_r (binfo
, data
)
1766 struct gvnt_info
*gvnti
= (struct gvnt_info
*) data
;
1767 tree type
= BINFO_TYPE (binfo
);
1770 idx
= lookup_fnfields_here (BINFO_TYPE (binfo
), gvnti
->name
);
1773 = scratch_tree_cons (binfo
,
1774 TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
),
1781 /* Return the virtual functions with the indicated NAME in the type
1782 indicated by BINFO. The result is a TREE_LIST whose TREE_PURPOSE
1783 indicates the base class from which the TREE_VALUE (an OVERLOAD or
1784 just a FUNCTION_DECL) originated. */
1787 get_virtuals_named_this (binfo
, name
)
1791 struct gvnt_info gvnti
;
1795 gvnti
.fields
= NULL_TREE
;
1797 bfs_walk (binfo
, get_virtuals_named_this_r
, 0, &gvnti
);
1799 /* Get to the function decls, and return the first virtual function
1800 with this name, if there is one. */
1801 for (fields
= gvnti
.fields
; fields
; fields
= next_baselink (fields
))
1805 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
1806 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
1813 get_virtual_destructor (binfo
, data
)
1815 void *data ATTRIBUTE_UNUSED
;
1817 tree type
= BINFO_TYPE (binfo
);
1818 if (TYPE_HAS_DESTRUCTOR (type
)
1819 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
1820 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
1825 tree_has_any_destructor_p (binfo
, data
)
1827 void *data ATTRIBUTE_UNUSED
;
1829 tree type
= BINFO_TYPE (binfo
);
1830 return TYPE_NEEDS_DESTRUCTOR (type
) ? binfo
: NULL_TREE
;
1833 /* Returns > 0 if a function with type DRETTYPE overriding a function
1834 with type BRETTYPE is covariant, as defined in [class.virtual].
1836 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1837 adjustment), or -1 if pedantically invalid covariance. */
1840 covariant_return_p (brettype
, drettype
)
1841 tree brettype
, drettype
;
1845 if (TREE_CODE (brettype
) == FUNCTION_DECL
1846 || TREE_CODE (brettype
) == THUNK_DECL
)
1848 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
1849 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
1851 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
1853 brettype
= TREE_TYPE (brettype
);
1854 drettype
= TREE_TYPE (drettype
);
1857 if (same_type_p (brettype
, drettype
))
1860 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
1861 && (TREE_CODE (brettype
) == POINTER_TYPE
1862 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
1863 && TYPE_QUALS (brettype
) == TYPE_QUALS (drettype
)))
1866 if (! can_convert (brettype
, drettype
))
1869 brettype
= TREE_TYPE (brettype
);
1870 drettype
= TREE_TYPE (drettype
);
1872 /* If not pedantic, allow any standard pointer conversion. */
1873 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
1876 binfo
= get_binfo (brettype
, drettype
, 1);
1878 /* If we get an error_mark_node from get_binfo, it already complained,
1879 so let's just succeed. */
1880 if (binfo
== error_mark_node
)
1883 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
1888 /* Given a class type TYPE, and a function decl FNDECL, look for a
1889 virtual function in TYPE's hierarchy which FNDECL could match as a
1890 virtual function. It doesn't matter which one we find.
1892 DTORP is nonzero if we are looking for a destructor. Destructors
1893 need special treatment because they do not match by name. */
1896 get_matching_virtual (binfo
, fndecl
, dtorp
)
1900 tree tmp
= NULL_TREE
;
1903 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
1904 /* In [temp.mem] we have:
1906 A specialization of a member function template does not
1907 override a virtual function from a base class. */
1910 /* Breadth first search routines start searching basetypes
1911 of TYPE, so we must perform first ply of search here. */
1913 return bfs_walk (binfo
, get_virtual_destructor
,
1914 tree_has_any_destructor_p
, 0);
1917 tree drettype
, dtypes
, btypes
, instptr_type
;
1918 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
1919 tree baselink
, best
= NULL_TREE
;
1920 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
1921 tree declarator
= DECL_NAME (fndecl
);
1922 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
1925 baselink
= get_virtuals_named_this (binfo
, declarator
);
1926 if (baselink
== NULL_TREE
)
1929 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
1930 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1931 if (DECL_STATIC_FUNCTION_P (fndecl
))
1932 instptr_type
= NULL_TREE
;
1934 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
1936 for (; baselink
; baselink
= next_baselink (baselink
))
1939 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
1941 tmp
= OVL_CURRENT (tmps
);
1942 if (! DECL_VINDEX (tmp
))
1945 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
1946 if (instptr_type
== NULL_TREE
)
1948 if (compparms (TREE_CHAIN (btypes
), dtypes
))
1949 /* Caller knows to give error in this case. */
1954 if (/* The first parameter is the `this' parameter,
1955 which has POINTER_TYPE, and we can therefore
1956 safely use TYPE_QUALS, rather than
1958 (TYPE_QUALS (TREE_TYPE (TREE_VALUE (btypes
)))
1959 == TYPE_QUALS (instptr_type
))
1960 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
)))
1962 tree brettype
= TREE_TYPE (TREE_TYPE (tmp
));
1963 if (same_type_p (brettype
, drettype
))
1965 else if ((i
= covariant_return_p (brettype
, drettype
)))
1968 sorry ("adjusting pointers for covariant returns");
1970 if (pedantic
&& i
== -1)
1972 cp_pedwarn_at ("invalid covariant return type for `%#D' (must be pointer or reference to class)", fndecl
);
1973 cp_pedwarn_at (" overriding `%#D'", tmp
);
1976 else if (IS_AGGR_TYPE_2 (brettype
, drettype
)
1977 && same_or_base_type_p (brettype
, drettype
))
1979 error ("invalid covariant return type (must use pointer or reference)");
1980 cp_error_at (" overriding `%#D'", tmp
);
1981 cp_error_at (" with `%#D'", fndecl
);
1983 else if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
)
1985 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl
);
1986 cp_error_at (" overriding definition as `%#D'", tmp
);
1987 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
1990 /* FNDECL overrides this function. We continue to
1991 check all the other functions in order to catch
1992 errors; it might be that in some other baseclass
1993 a virtual function was declared with the same
1994 parameter types, but a different return type. */
2004 /* Return the list of virtual functions which are abstract in type
2005 TYPE that come from non virtual base classes. See
2006 expand_direct_vtbls_init for the style of search we do. */
2009 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
2012 tree abstract_virtuals
;
2014 tree binfos
= BINFO_BASETYPES (binfo
);
2015 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2017 for (i
= 0; i
< n_baselinks
; i
++)
2019 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2020 int is_not_base_vtable
2021 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2022 if (! TREE_VIA_VIRTUAL (base_binfo
))
2024 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
2027 /* Should we use something besides CLASSTYPE_VFIELDS? */
2028 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2030 tree virtuals
= BINFO_VIRTUALS (binfo
);
2032 skip_rtti_stuff (&virtuals
, BINFO_TYPE (binfo
));
2036 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2037 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2038 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2039 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2040 virtuals
= TREE_CHAIN (virtuals
);
2043 return abstract_virtuals
;
2046 /* Return the list of virtual functions which are abstract in type TYPE.
2047 This information is cached, and so must be built on a
2048 non-temporary obstack. */
2051 get_abstract_virtuals (type
)
2055 tree abstract_virtuals
= NULL
;
2057 /* First get all from non-virtual bases. */
2059 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
2061 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
2063 tree virtuals
= BINFO_VIRTUALS (vbases
);
2065 skip_rtti_stuff (&virtuals
, BINFO_TYPE (vbases
));
2069 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2070 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2071 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
2072 cp_error ("`%#D' needs a final overrider", base_fndecl
);
2073 else if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2074 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2075 virtuals
= TREE_CHAIN (virtuals
);
2078 return nreverse (abstract_virtuals
);
2082 next_baselink (baselink
)
2085 tree tmp
= TREE_TYPE (baselink
);
2086 baselink
= TREE_CHAIN (baselink
);
2089 /* @@ does not yet add previous base types. */
2090 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2092 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2093 tmp
= TREE_CHAIN (tmp
);
2098 /* DEPTH-FIRST SEARCH ROUTINES. */
2100 /* This routine converts a pointer to be a pointer of an immediate
2101 base class. The normal convert_pointer_to routine would diagnose
2102 the conversion as ambiguous, under MI code that has the base class
2103 as an ambiguous base class. */
2106 convert_pointer_to_single_level (to_type
, expr
)
2110 tree binfo_of_derived
;
2113 derived
= TREE_TYPE (TREE_TYPE (expr
));
2114 binfo_of_derived
= TYPE_BINFO (derived
);
2115 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo_of_derived
) == NULL_TREE
,
2117 for (i
= CLASSTYPE_N_BASECLASSES (derived
) - 1; i
>= 0; --i
)
2119 tree binfo
= BINFO_BASETYPE (binfo_of_derived
, i
);
2120 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo
) == binfo_of_derived
,
2122 if (same_type_p (BINFO_TYPE (binfo
), to_type
))
2123 return build_vbase_path (PLUS_EXPR
,
2124 build_pointer_type (to_type
),
2128 my_friendly_abort (19990607);
2134 tree
markedp (binfo
, data
)
2136 void *data ATTRIBUTE_UNUSED
;
2138 return BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2142 unmarkedp (binfo
, data
)
2144 void *data ATTRIBUTE_UNUSED
;
2146 return !BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2150 marked_vtable_pathp (binfo
, data
)
2152 void *data ATTRIBUTE_UNUSED
;
2154 return BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2158 unmarked_vtable_pathp (binfo
, data
)
2160 void *data ATTRIBUTE_UNUSED
;
2162 return !BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2166 marked_new_vtablep (binfo
, data
)
2168 void *data ATTRIBUTE_UNUSED
;
2170 return BINFO_NEW_VTABLE_MARKED (binfo
) ? binfo
: NULL_TREE
;
2174 unmarked_new_vtablep (binfo
, data
)
2176 void *data ATTRIBUTE_UNUSED
;
2178 return !BINFO_NEW_VTABLE_MARKED (binfo
) ? binfo
: NULL_TREE
;
2182 marked_pushdecls_p (binfo
, data
)
2184 void *data ATTRIBUTE_UNUSED
;
2186 return (CLASS_TYPE_P (BINFO_TYPE (binfo
))
2187 && BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
2191 unmarked_pushdecls_p (binfo
, data
)
2193 void *data ATTRIBUTE_UNUSED
;
2195 return (CLASS_TYPE_P (BINFO_TYPE (binfo
))
2196 && !BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
2200 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2201 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2205 dfs_debug_unmarkedp (binfo
, data
)
2207 void *data ATTRIBUTE_UNUSED
;
2209 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
))
2210 ? binfo
: NULL_TREE
);
2213 /* The worker functions for `dfs_walk'. These do not need to
2214 test anything (vis a vis marking) if they are paired with
2215 a predicate function (above). */
2219 dfs_mark (binfo
) tree binfo
;
2220 { SET_BINFO_MARKED (binfo
); }
2224 dfs_unmark (binfo
, data
)
2226 void *data ATTRIBUTE_UNUSED
;
2228 CLEAR_BINFO_MARKED (binfo
);
2234 dfs_mark_vtable_path (binfo
) tree binfo
;
2235 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2238 dfs_unmark_vtable_path (binfo
) tree binfo
;
2239 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2242 dfs_mark_new_vtable (binfo
) tree binfo
;
2243 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2246 dfs_unmark_new_vtable (binfo
) tree binfo
;
2247 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2250 dfs_clear_search_slot (binfo
) tree binfo
;
2251 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2255 dfs_debug_mark (binfo
, data
)
2257 void *data ATTRIBUTE_UNUSED
;
2259 tree t
= BINFO_TYPE (binfo
);
2261 /* Use heuristic that if there are virtual functions,
2262 ignore until we see a non-inline virtual function. */
2263 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2265 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2270 /* If interface info is known, either we've already emitted the debug
2271 info or we don't need to. */
2272 if (CLASSTYPE_INTERFACE_KNOWN (t
))
2275 /* If debug info is requested from this context for this type, supply it.
2276 If debug info is requested from another context for this type,
2277 see if some third context can supply it. */
2278 if (current_function_decl
== NULL_TREE
2279 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2281 if (TREE_VEC_ELT (methods
, 1))
2282 methods
= TREE_VEC_ELT (methods
, 1);
2283 else if (TREE_VEC_ELT (methods
, 0))
2284 methods
= TREE_VEC_ELT (methods
, 0);
2286 methods
= TREE_VEC_ELT (methods
, 2);
2287 methods
= OVL_CURRENT (methods
);
2290 if (DECL_VINDEX (methods
)
2291 && DECL_THIS_INLINE (methods
) == 0
2292 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2294 /* Somebody, somewhere is going to have to define this
2295 virtual function. When they do, they will provide
2296 the debugging info. */
2299 methods
= TREE_CHAIN (methods
);
2302 /* We cannot rely on some alien method to solve our problems,
2303 so we must write out the debug info ourselves. */
2304 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2305 rest_of_type_compilation (t
, toplevel_bindings_p ());
2317 /* Attach to the type of the virtual base class, the pointer to the
2318 virtual base class. */
2321 dfs_find_vbases (binfo
, data
)
2325 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2326 tree binfos
= BINFO_BASETYPES (binfo
);
2327 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2329 for (i
= n_baselinks
-1; i
>= 0; i
--)
2331 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2333 if (TREE_VIA_VIRTUAL (base_binfo
)
2334 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2336 tree vbase
= BINFO_TYPE (base_binfo
);
2337 tree binfo
= binfo_member (vbase
, vi
->vbase_types
);
2339 CLASSTYPE_SEARCH_SLOT (vbase
)
2340 = build (PLUS_EXPR
, build_pointer_type (vbase
),
2341 vi
->decl_ptr
, BINFO_OFFSET (binfo
));
2344 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2345 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2351 dfs_init_vbase_pointers (binfo
, data
)
2355 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2356 tree type
= BINFO_TYPE (binfo
);
2357 tree fields
= TYPE_FIELDS (type
);
2358 tree this_vbase_ptr
;
2360 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2363 /* See finish_struct_1 for when we can enable this. */
2364 /* If we have a vtable pointer first, skip it. */
2365 if (VFIELD_NAME_P (DECL_NAME (fields
)))
2366 fields
= TREE_CHAIN (fields
);
2369 if (BINFO_INHERITANCE_CHAIN (binfo
))
2371 this_vbase_ptr
= TREE_CHAIN (BINFO_INHERITANCE_CHAIN (binfo
));
2372 if (TREE_VIA_VIRTUAL (binfo
))
2373 this_vbase_ptr
= CLASSTYPE_SEARCH_SLOT (type
);
2375 this_vbase_ptr
= convert_pointer_to_single_level (type
,
2377 TREE_CHAIN (binfo
) = this_vbase_ptr
;
2380 this_vbase_ptr
= TREE_CHAIN (binfo
);
2382 if (fields
== NULL_TREE
2383 || DECL_NAME (fields
) == NULL_TREE
2384 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2387 if (build_pointer_type (type
)
2388 != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2389 my_friendly_abort (125);
2391 while (fields
&& DECL_NAME (fields
) && VBASE_NAME_P (DECL_NAME (fields
)))
2393 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2394 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2395 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2396 vi
->inits
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2398 build_modify_expr (ref
, NOP_EXPR
, init
),
2400 fields
= TREE_CHAIN (fields
);
2406 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2407 times, just NEW_VTABLE, but optimizer should make both with equal
2408 efficiency (though it does not currently). */
2411 dfs_clear_vbase_slots (binfo
, data
)
2413 void *data ATTRIBUTE_UNUSED
;
2415 tree type
= BINFO_TYPE (binfo
);
2416 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2417 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2418 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2423 init_vbase_pointers (type
, decl_ptr
)
2427 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2429 struct vbase_info vi
;
2430 int old_flag
= flag_this_is_variable
;
2431 tree binfo
= TYPE_BINFO (type
);
2432 flag_this_is_variable
= -2;
2434 /* Find all the virtual base classes, marking them for later
2436 vi
.decl_ptr
= decl_ptr
;
2437 vi
.vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2438 vi
.inits
= NULL_TREE
;
2440 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
, &vi
);
2442 /* Build up a list of the initializers. */
2443 TREE_CHAIN (binfo
) = decl_ptr
;
2444 dfs_walk_real (binfo
,
2445 dfs_init_vbase_pointers
, 0,
2446 marked_vtable_pathp
,
2449 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
, 0);
2450 flag_this_is_variable
= old_flag
;
2456 /* get the virtual context (the vbase that directly contains the
2457 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2458 or NULL_TREE if there is none.
2460 FNDECL must come from a virtual table from a virtual base to ensure that
2461 there is only one possible DECL_CLASS_CONTEXT.
2463 We know that if there is more than one place (binfo) the fndecl that the
2464 declared, they all refer to the same binfo. See get_class_offset_1 for
2465 the check that ensures this. */
2468 virtual_context (fndecl
, t
, vbase
)
2469 tree fndecl
, t
, vbase
;
2472 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2474 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2475 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2479 /* Not sure if checking path == vbase is necessary here, but just in
2481 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2482 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2483 path
= BINFO_INHERITANCE_CHAIN (path
);
2486 /* This shouldn't happen, I don't want errors! */
2487 warning ("recoverable compiler error, fixups for virtual function");
2492 if (TREE_VIA_VIRTUAL (path
))
2493 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2494 path
= BINFO_INHERITANCE_CHAIN (path
);
2499 /* Fixups upcast offsets for one vtable.
2500 Entries may stay within the VBASE given, or
2501 they may upcast into a direct base, or
2502 they may upcast into a different vbase.
2504 We only need to do fixups in case 2 and 3. In case 2, we add in
2505 the virtual base offset to effect an upcast, in case 3, we add in
2506 the virtual base offset to effect an upcast, then subtract out the
2507 offset for the other virtual base, to effect a downcast into it.
2509 This routine mirrors fixup_vtable_deltas in functionality, though
2510 this one is runtime based, and the other is compile time based.
2511 Conceivably that routine could be removed entirely, and all fixups
2514 VBASE_OFFSETS is an association list of virtual bases that contains
2515 offset information for the virtual bases, so the offsets are only
2516 calculated once. The offsets are computed by where we think the
2517 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2518 the vbase really is. */
2521 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2523 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2525 tree virtuals
= BINFO_VIRTUALS (binfo
);
2528 unsigned HOST_WIDE_INT n
;
2530 delta
= purpose_member (vbase
, *vbase_offsets
);
2533 delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase
));
2534 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2535 delta
= save_expr (delta
);
2536 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2537 *vbase_offsets
= delta
;
2540 n
= skip_rtti_stuff (&virtuals
, BINFO_TYPE (binfo
));
2544 tree current_fndecl
= TREE_VALUE (virtuals
);
2545 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2546 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2548 && current_fndecl
!= abort_fndecl
2549 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2551 /* This may in fact need a runtime fixup. */
2552 tree idx
= build_int_2 (n
, 0);
2553 tree vtbl
= BINFO_VTABLE (binfo
);
2554 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2555 tree aref
, ref
, naref
;
2556 tree old_delta
, new_delta
;
2559 if (nvtbl
== NULL_TREE
2560 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2562 /* Dup it if it isn't in local scope yet. */
2564 (VAR_DECL
, DECL_NAME (vtbl
),
2565 TYPE_MAIN_VARIANT (TREE_TYPE (vtbl
)));
2566 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2567 DECL_ALIGN (nvtbl
));
2568 TREE_READONLY (nvtbl
) = 0;
2569 DECL_ARTIFICIAL (nvtbl
) = 1;
2570 nvtbl
= pushdecl (nvtbl
);
2572 cp_finish_decl (nvtbl
, init
, NULL_TREE
, 0,
2573 LOOKUP_ONLYCONVERTING
);
2575 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2576 because they wouldn't be useful; everything that wants to
2577 look at the vtable will look at the decl for the normal
2578 vtable. Setting DECL_CONTEXT also screws up
2579 decl_function_context. */
2581 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
2583 TREE_SIDE_EFFECTS (init
) = 1;
2584 expand_expr_stmt (init
);
2585 /* Update the vtable pointers as necessary. */
2586 ref
= build_vfield_ref
2587 (build_indirect_ref (addr
, NULL_PTR
),
2588 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))));
2590 (build_modify_expr (ref
, NOP_EXPR
, nvtbl
));
2592 assemble_external (vtbl
);
2593 aref
= build_array_ref (vtbl
, idx
);
2594 naref
= build_array_ref (nvtbl
, idx
);
2595 old_delta
= build_component_ref (aref
, delta_identifier
,
2597 new_delta
= build_component_ref (naref
, delta_identifier
,
2600 /* This is a upcast, so we have to add the offset for the
2602 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
2603 TREE_VALUE (delta
));
2606 /* If this is set, we need to subtract out the delta
2607 adjustments for the other virtual base that we
2609 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
2612 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
2613 vc_delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc
));
2614 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
2616 vc_delta
= save_expr (vc_delta
);
2617 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
2620 vc_delta
= TREE_VALUE (vc_delta
);
2622 /* This is a downcast, so we have to subtract the offset
2623 for the virtual base. */
2624 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
);
2627 TREE_READONLY (new_delta
) = 0;
2628 TREE_TYPE (new_delta
) =
2629 cp_build_qualified_type (TREE_TYPE (new_delta
),
2630 CP_TYPE_QUALS (TREE_TYPE (new_delta
))
2631 & ~TYPE_QUAL_CONST
);
2632 expand_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
2636 virtuals
= TREE_CHAIN (virtuals
);
2640 /* Fixup upcast offsets for all direct vtables. Patterned after
2641 expand_direct_vtbls_init. */
2644 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
2645 tree real_binfo
, binfo
;
2646 int init_self
, can_elide
;
2647 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
2649 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
2650 tree binfos
= BINFO_BASETYPES (binfo
);
2651 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
2653 for (i
= 0; i
< n_baselinks
; i
++)
2655 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
2656 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2657 int is_not_base_vtable
2658 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo
));
2659 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
2660 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
2661 is_not_base_vtable
, can_elide
, addr
,
2662 orig_addr
, type
, vbase
, vbase_offsets
);
2665 /* Before turning this on, make sure it is correct. */
2666 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
2669 /* Should we use something besides CLASSTYPE_VFIELDS? */
2670 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
2672 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
2673 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
2674 type
, vbase_offsets
);
2678 /* Build a COMPOUND_EXPR which when expanded will generate the code
2679 needed to initialize all the virtual function table slots of all
2680 the virtual baseclasses. MAIN_BINFO is the binfo which determines
2681 the virtual baseclasses to use; TYPE is the type of the object to
2682 which the initialization applies. TRUE_EXP is the true object we
2683 are initializing, and DECL_PTR is the pointer to the sub-object we
2686 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
2687 object was laid out by a top-level constructor and the computed
2688 offsets are valid to store vtables. When zero, we must store new
2689 vtables through virtual baseclass pointers. */
2692 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
)
2694 tree true_exp
, decl_ptr
;
2696 tree type
= BINFO_TYPE (binfo
);
2698 /* This function executes during the finish_function() segment,
2699 AFTER the auto variables and temporary stack space has been marked
2700 unused...If space is needed for the virtual function tables,
2701 some of them might fit within what the compiler now thinks
2702 are available stack slots... These values are actually initialized at
2703 the beginnning of the function, so when the automatics use their space,
2704 they will overwrite the values that are placed here. Marking all
2705 temporary space as unavailable prevents this from happening. */
2707 mark_all_temps_used();
2709 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2711 rtx fixup_insns
= NULL_RTX
;
2712 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
2713 struct vbase_info vi
;
2714 vi
.decl_ptr
= (true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0)
2716 vi
.vbase_types
= vbases
;
2718 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
, &vi
);
2720 /* Initialized with vtables of type TYPE. */
2721 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
2725 addr
= convert_pointer_to_vbase (TREE_TYPE (vbases
), vi
.decl_ptr
);
2727 /* Do all vtables from this virtual base. */
2728 /* This assumes that virtual bases can never serve as parent
2729 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
2730 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
2733 /* Now we adjust the offsets for virtual functions that
2734 cross virtual boundaries on an implicit upcast on vf call
2735 so that the layout of the most complete type is used,
2736 instead of assuming the layout of the virtual bases from
2737 our current type. */
2739 if (flag_vtable_thunks
)
2741 /* We don't have dynamic thunks yet!
2742 So for now, just fail silently. */
2746 tree vbase_offsets
= NULL_TREE
;
2747 push_to_sequence (fixup_insns
);
2748 fixup_virtual_upcast_offsets (vbases
,
2749 TYPE_BINFO (BINFO_TYPE (vbases
)),
2750 1, 0, addr
, vi
.decl_ptr
,
2751 type
, vbases
, &vbase_offsets
);
2752 fixup_insns
= get_insns ();
2759 extern tree in_charge_identifier
;
2760 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
2761 if (! in_charge_node
)
2763 warning ("recoverable internal compiler error, nobody's in charge!");
2764 in_charge_node
= integer_zero_node
;
2766 in_charge_node
= build_binary_op (EQ_EXPR
, in_charge_node
, integer_zero_node
);
2767 expand_start_cond (in_charge_node
, 0);
2768 emit_insns (fixup_insns
);
2772 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
, 0);
2776 /* get virtual base class types.
2777 This adds type to the vbase_types list in reverse dfs order.
2778 Ordering is very important, so don't change it. */
2781 dfs_get_vbase_types (binfo
, data
)
2785 tree
*vbase_types
= (tree
*) data
;
2787 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
2789 tree new_vbase
= make_binfo (integer_zero_node
, binfo
,
2790 BINFO_VTABLE (binfo
),
2791 BINFO_VIRTUALS (binfo
));
2792 TREE_CHAIN (new_vbase
) = *vbase_types
;
2793 TREE_VIA_VIRTUAL (new_vbase
) = 1;
2794 *vbase_types
= new_vbase
;
2795 SET_BINFO_VBASE_MARKED (binfo
);
2797 SET_BINFO_MARKED (binfo
);
2801 /* Return a list of binfos for the virtual base classes for TYPE, in
2802 depth-first search order. The list is freshly allocated, so
2803 no modification is made to the current binfo hierarchy. */
2806 get_vbase_types (type
)
2813 binfo
= TYPE_BINFO (type
);
2814 vbase_types
= NULL_TREE
;
2815 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
, &vbase_types
);
2816 dfs_walk (binfo
, dfs_unmark
, markedp
, 0);
2817 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2818 reverse it so that we get normal dfs ordering. */
2819 vbase_types
= nreverse (vbase_types
);
2821 /* unmark marked vbases */
2822 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
2823 CLEAR_BINFO_VBASE_MARKED (vbases
);
2828 /* If we want debug info for a type TYPE, make sure all its base types
2829 are also marked as being potentially interesting. This avoids
2830 the problem of not writing any debug info for intermediate basetypes
2831 that have abstract virtual functions. Also mark member types. */
2834 note_debug_info_needed (type
)
2839 if (current_template_parms
)
2842 if (TYPE_BEING_DEFINED (type
))
2843 /* We can't go looking for the base types and fields just yet. */
2846 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2847 does not support name references between translation units. Well, we
2848 could, but that would mean putting global labels in the debug output
2849 before each exported type and each of its functions and static data
2851 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
2852 || write_symbols
== NO_DEBUG
)
2855 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
, 0);
2856 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2859 if (TREE_CODE (field
) == FIELD_DECL
2860 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
2861 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
), 0))
2862 note_debug_info_needed (ttype
);
2866 /* Subroutines of push_class_decls (). */
2868 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2869 because it (or one of the intermediate bases) depends on template parms. */
2872 dependent_base_p (binfo
)
2875 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2877 if (currently_open_class (TREE_TYPE (binfo
)))
2879 if (uses_template_parms (TREE_TYPE (binfo
)))
2886 setup_class_bindings (name
, type_binding_p
)
2890 tree type_binding
= NULL_TREE
;
2893 /* If we've already done the lookup for this declaration, we're
2895 if (IDENTIFIER_CLASS_VALUE (name
))
2898 /* First, deal with the type binding. */
2901 type_binding
= lookup_member (current_class_type
, name
,
2904 if (TREE_CODE (type_binding
) == TREE_LIST
2905 && TREE_TYPE (type_binding
) == error_mark_node
)
2906 /* NAME is ambiguous. */
2907 push_class_level_binding (name
, type_binding
);
2909 pushdecl_class_level (type_binding
);
2912 /* Now, do the value binding. */
2913 value_binding
= lookup_member (current_class_type
, name
,
2918 && (TREE_CODE (value_binding
) == TYPE_DECL
2919 || (TREE_CODE (value_binding
) == TREE_LIST
2920 && TREE_TYPE (value_binding
) == error_mark_node
2921 && (TREE_CODE (TREE_VALUE (value_binding
))
2923 /* We found a type-binding, even when looking for a non-type
2924 binding. This means that we already processed this binding
2926 my_friendly_assert (type_binding_p
, 19990401);
2929 if (TREE_CODE (value_binding
) == TREE_LIST
2930 && TREE_TYPE (value_binding
) == error_mark_node
)
2931 /* NAME is ambiguous. */
2932 push_class_level_binding (name
, value_binding
);
2935 if (BASELINK_P (value_binding
))
2936 /* NAME is some overloaded functions. */
2937 value_binding
= TREE_VALUE (value_binding
);
2938 pushdecl_class_level (value_binding
);
2943 /* Push class-level declarations for any names appearing in BINFO that
2947 dfs_push_type_decls (binfo
, data
)
2949 void *data ATTRIBUTE_UNUSED
;
2954 type
= BINFO_TYPE (binfo
);
2955 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2956 if (DECL_NAME (fields
) && TREE_CODE (fields
) == TYPE_DECL
2957 && !(!same_type_p (type
, current_class_type
)
2958 && template_self_reference_p (type
, fields
)))
2959 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/1);
2961 /* We can't just use BINFO_MARKED because envelope_add_decl uses
2962 DERIVED_FROM_P, which calls get_base_distance. */
2963 SET_BINFO_PUSHDECLS_MARKED (binfo
);
2968 /* Push class-level declarations for any names appearing in BINFO that
2969 are not TYPE_DECLS. */
2972 dfs_push_decls (binfo
, data
)
2980 type
= BINFO_TYPE (binfo
);
2981 dep_base_p
= (processing_template_decl
&& type
!= current_class_type
2982 && dependent_base_p (binfo
));
2986 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2987 if (DECL_NAME (fields
)
2988 && TREE_CODE (fields
) != TYPE_DECL
2989 && TREE_CODE (fields
) != USING_DECL
)
2990 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/0);
2991 else if (TREE_CODE (fields
) == FIELD_DECL
2992 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
2993 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields
)), data
);
2995 method_vec
= (CLASS_TYPE_P (type
)
2996 ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
);
3002 /* Farm out constructors and destructors. */
3003 end
= TREE_VEC_END (method_vec
);
3005 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3006 *methods
&& methods
!= end
;
3008 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods
)),
3009 /*type_binding_p=*/0);
3013 CLEAR_BINFO_PUSHDECLS_MARKED (binfo
);
3018 /* When entering the scope of a class, we cache all of the
3019 fields that that class provides within its inheritance
3020 lattice. Where ambiguities result, we mark them
3021 with `error_mark_node' so that if they are encountered
3022 without explicit qualification, we can emit an error
3026 push_class_decls (type
)
3029 struct obstack
*ambient_obstack
= current_obstack
;
3030 search_stack
= push_search_level (search_stack
, &search_obstack
);
3032 /* Build up all the relevant bindings and such on the cache
3033 obstack. That way no memory is wasted when we throw away the
3035 push_cache_obstack ();
3037 /* Enter type declarations and mark. */
3038 dfs_walk (TYPE_BINFO (type
), dfs_push_type_decls
, unmarked_pushdecls_p
, 0);
3040 /* Enter non-type declarations and unmark. */
3041 dfs_walk (TYPE_BINFO (type
), dfs_push_decls
, marked_pushdecls_p
, 0);
3043 /* Undo the call to push_cache_obstack above. */
3046 current_obstack
= ambient_obstack
;
3049 /* Here's a subroutine we need because C lacks lambdas. */
3052 dfs_unuse_fields (binfo
, data
)
3054 void *data ATTRIBUTE_UNUSED
;
3056 tree type
= TREE_TYPE (binfo
);
3059 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3061 if (TREE_CODE (fields
) != FIELD_DECL
)
3064 TREE_USED (fields
) = 0;
3065 if (DECL_NAME (fields
) == NULL_TREE
3066 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
3067 unuse_fields (TREE_TYPE (fields
));
3077 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
, 0);
3083 /* We haven't pushed a search level when dealing with cached classes,
3084 so we'd better not try to pop it. */
3086 search_stack
= pop_search_level (search_stack
);
3090 print_search_statistics ()
3092 #ifdef GATHER_STATISTICS
3093 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3094 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3095 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3096 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3097 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3098 #else /* GATHER_STATISTICS */
3099 fprintf (stderr
, "no search statistics\n");
3100 #endif /* GATHER_STATISTICS */
3104 init_search_processing ()
3106 gcc_obstack_init (&search_obstack
);
3107 _vptr_name
= get_identifier ("_vptr");
3111 reinit_search_statistics ()
3113 #ifdef GATHER_STATISTICS
3114 n_fields_searched
= 0;
3115 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3116 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3117 n_calls_get_base_type
= 0;
3118 n_outer_fields_searched
= 0;
3119 n_contexts_saved
= 0;
3120 #endif /* GATHER_STATISTICS */
3123 #define scratch_tree_cons expr_tree_cons
3126 add_conversions (binfo
, data
)
3131 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3132 tree
*conversions
= (tree
*) data
;
3134 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3136 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3139 if (!tmp
|| ! DECL_CONV_FN_P (OVL_CURRENT (tmp
)))
3142 name
= DECL_NAME (OVL_CURRENT (tmp
));
3144 /* Make sure we don't already have this conversion. */
3145 if (! IDENTIFIER_MARKED (name
))
3147 *conversions
= scratch_tree_cons (binfo
, tmp
, *conversions
);
3148 IDENTIFIER_MARKED (name
) = 1;
3155 lookup_conversions (type
)
3159 tree conversions
= NULL_TREE
;
3161 if (TYPE_SIZE (type
))
3162 bfs_walk (TYPE_BINFO (type
), add_conversions
, 0, &conversions
);
3164 for (t
= conversions
; t
; t
= TREE_CHAIN (t
))
3165 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t
)))) = 0;
3176 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3177 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3180 dfs_check_overlap (empty_binfo
, data
)
3184 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3186 for (binfo
= TYPE_BINFO (oi
->compare_type
);
3188 binfo
= BINFO_BASETYPE (binfo
, 0))
3190 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3192 oi
->found_overlap
= 1;
3195 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3202 /* Trivial function to stop base traversal when we find something. */
3205 dfs_no_overlap_yet (binfo
, data
)
3209 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3210 return !oi
->found_overlap
? binfo
: NULL_TREE
;
3213 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3214 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3217 types_overlap_p (empty_type
, next_type
)
3218 tree empty_type
, next_type
;
3220 struct overlap_info oi
;
3222 if (! IS_AGGR_TYPE (next_type
))
3224 oi
.compare_type
= next_type
;
3225 oi
.found_overlap
= 0;
3226 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
,
3227 dfs_no_overlap_yet
, &oi
);
3228 return oi
.found_overlap
;
3237 dfs_bfv_queue_p (binfo
, data
)
3241 struct bfv_info
*bfvi
= (struct bfv_info
*) data
;
3243 /* Use the real virtual base class objects, not the placeholders in
3244 the usual hierarchy. */
3245 if (TREE_VIA_VIRTUAL (binfo
))
3246 return binfo_member (BINFO_TYPE (binfo
), bfvi
->vbases
);
3251 /* Passed to dfs_walk_real by binfo_for_vtable; determine if bvtable
3252 comes from BINFO. */
3255 dfs_bfv_helper (binfo
, data
)
3259 struct bfv_info
*bfvi
= (struct bfv_info
*) data
;
3261 if (BINFO_VTABLE (binfo
) == bfvi
->var
)
3266 /* Given a vtable VAR, determine which binfo it comes from. */
3269 binfo_for_vtable (var
)
3273 struct bfv_info bfvi
;
3275 type
= DECL_CONTEXT (var
);
3276 bfvi
.vbases
= CLASSTYPE_VBASECLASSES (type
);
3278 return dfs_walk_real (TYPE_BINFO (type
),
3279 0, dfs_bfv_helper
, dfs_bfv_queue_p
, &bfvi
);