1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000 Free Software Foundation, Inc.
5 Contributed by Michael Tiemann (tiemann@cygnus.com)
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 /* High-level class interface. */
36 #define obstack_chunk_alloc xmalloc
37 #define obstack_chunk_free free
39 extern struct obstack
*current_obstack
;
43 /* Obstack used for remembering decision points of breadth-first. */
45 static struct obstack search_obstack
;
47 /* Methods for pushing and popping objects to and from obstacks. */
50 push_stack_level (obstack
, tp
, size
)
51 struct obstack
*obstack
;
52 char *tp
; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
55 struct stack_level
*stack
;
56 obstack_grow (obstack
, tp
, size
);
57 stack
= (struct stack_level
*) ((char*)obstack_next_free (obstack
) - size
);
58 obstack_finish (obstack
);
59 stack
->obstack
= obstack
;
60 stack
->first
= (tree
*) obstack_base (obstack
);
61 stack
->limit
= obstack_room (obstack
) / sizeof (tree
*);
66 pop_stack_level (stack
)
67 struct stack_level
*stack
;
69 struct stack_level
*tem
= stack
;
70 struct obstack
*obstack
= tem
->obstack
;
72 obstack_free (obstack
, tem
);
76 #define search_level stack_level
77 static struct search_level
*search_stack
;
81 /* The class dominating the hierarchy. */
83 /* A pointer to a complete object of the indicated TYPE. */
88 static tree next_baselink
PARAMS ((tree
));
89 static tree get_vbase_1
PARAMS ((tree
, tree
, unsigned int *));
90 static tree lookup_field_1
PARAMS ((tree
, tree
));
91 static int lookup_fnfields_here
PARAMS ((tree
, tree
));
92 static int is_subobject_of_p
PARAMS ((tree
, tree
));
93 static int hides
PARAMS ((tree
, tree
));
94 static tree virtual_context
PARAMS ((tree
, tree
, tree
));
95 static tree dfs_check_overlap
PARAMS ((tree
, void *));
96 static tree dfs_no_overlap_yet
PARAMS ((tree
, void *));
97 static int get_base_distance_recursive
98 PARAMS ((tree
, int, int, int, int *, tree
*, tree
,
99 int, int *, int, int));
100 static int dynamic_cast_base_recurse
PARAMS ((tree
, tree
, int, tree
*));
101 static void expand_upcast_fixups
102 PARAMS ((tree
, tree
, tree
, tree
, tree
, tree
, tree
*));
103 static void fixup_virtual_upcast_offsets
104 PARAMS ((tree
, tree
, int, int, tree
, tree
, tree
, tree
,
106 static tree marked_pushdecls_p
PARAMS ((tree
, void *));
107 static tree unmarked_pushdecls_p
PARAMS ((tree
, void *));
108 static tree dfs_debug_unmarkedp
PARAMS ((tree
, void *));
109 static tree dfs_debug_mark
PARAMS ((tree
, void *));
110 static tree dfs_init_vbase_pointers
PARAMS ((tree
, void *));
111 static tree dfs_get_vbase_types
PARAMS ((tree
, void *));
112 static tree dfs_push_type_decls
PARAMS ((tree
, void *));
113 static tree dfs_push_decls
PARAMS ((tree
, void *));
114 static tree dfs_unuse_fields
PARAMS ((tree
, void *));
115 static tree add_conversions
PARAMS ((tree
, void *));
116 static tree get_virtuals_named_this
PARAMS ((tree
, tree
));
117 static tree get_virtual_destructor
PARAMS ((tree
, void *));
118 static tree tree_has_any_destructor_p
PARAMS ((tree
, void *));
119 static int covariant_return_p
PARAMS ((tree
, tree
));
120 static int check_final_overrider
PARAMS ((tree
, tree
));
121 static struct search_level
*push_search_level
122 PARAMS ((struct stack_level
*, struct obstack
*));
123 static struct search_level
*pop_search_level
124 PARAMS ((struct stack_level
*));
126 PARAMS ((tree
, tree (*) (tree
, void *), tree (*) (tree
, void *),
128 static tree lookup_field_queue_p
PARAMS ((tree
, void *));
129 static tree lookup_field_r
PARAMS ((tree
, void *));
130 static tree get_virtuals_named_this_r
PARAMS ((tree
, void *));
131 static tree context_for_name_lookup
PARAMS ((tree
));
132 static tree canonical_binfo
PARAMS ((tree
));
133 static tree shared_marked_p
PARAMS ((tree
, void *));
134 static tree shared_unmarked_p
PARAMS ((tree
, void *));
135 static int dependent_base_p
PARAMS ((tree
));
136 static tree dfs_accessible_queue_p
PARAMS ((tree
, void *));
137 static tree dfs_accessible_p
PARAMS ((tree
, void *));
138 static tree dfs_access_in_type
PARAMS ((tree
, void *));
139 static access_kind access_in_type
PARAMS ((tree
, tree
));
140 static tree dfs_canonical_queue
PARAMS ((tree
, void *));
141 static tree dfs_assert_unmarked_p
PARAMS ((tree
, void *));
142 static void assert_canonical_unmarked
PARAMS ((tree
));
143 static int protected_accessible_p
PARAMS ((tree
, tree
, tree
));
144 static int friend_accessible_p
PARAMS ((tree
, tree
, tree
));
145 static void setup_class_bindings
PARAMS ((tree
, int));
146 static int template_self_reference_p
PARAMS ((tree
, tree
));
147 static tree get_shared_vbase_if_not_primary
PARAMS ((tree
, void *));
148 static tree dfs_find_vbase_instance
PARAMS ((tree
, void *));
149 static tree dfs_get_pure_virtuals
PARAMS ((tree
, void *));
150 static tree dfs_build_inheritance_graph_order
PARAMS ((tree
, void *));
151 static tree dfs_vtable_path_unmark
PARAMS ((tree
, void *));
153 /* Allocate a level of searching. */
155 static struct search_level
*
156 push_search_level (stack
, obstack
)
157 struct stack_level
*stack
;
158 struct obstack
*obstack
;
160 struct search_level tem
;
163 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
166 /* Discard a level of search allocation. */
168 static struct search_level
*
169 pop_search_level (obstack
)
170 struct stack_level
*obstack
;
172 register struct search_level
*stack
= pop_stack_level (obstack
);
177 /* Variables for gathering statistics. */
178 #ifdef GATHER_STATISTICS
179 static int n_fields_searched
;
180 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
181 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
182 static int n_calls_get_base_type
;
183 static int n_outer_fields_searched
;
184 static int n_contexts_saved
;
185 #endif /* GATHER_STATISTICS */
188 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
189 the same type as the type given in PARENT. To be optimal, we want
190 the first one that is found by going through the least number of
193 This uses a clever algorithm that updates *depth when we find the vbase,
194 and cuts off other paths of search when they reach that depth. */
197 get_vbase_1 (parent
, binfo
, depth
)
203 tree rval
= NULL_TREE
;
205 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
213 binfos
= BINFO_BASETYPES (binfo
);
214 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
216 /* Process base types. */
217 for (i
= 0; i
< n_baselinks
; i
++)
219 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
225 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
233 /* Return the shortest path to vbase PARENT within BINFO, ignoring
234 access and ambiguity. */
237 get_vbase (parent
, binfo
)
241 unsigned int d
= (unsigned int)-1;
242 return get_vbase_1 (parent
, binfo
, &d
);
245 /* Convert EXPR to a virtual base class of type TYPE. We know that
246 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
247 the type of what expr points to has a virtual base of type TYPE. */
250 convert_pointer_to_vbase (type
, expr
)
254 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
255 return convert_pointer_to_real (vb
, expr
);
258 /* Check whether the type given in BINFO is derived from PARENT. If
259 it isn't, return 0. If it is, but the derivation is MI-ambiguous
260 AND protect != 0, emit an error message and return error_mark_node.
262 Otherwise, if TYPE is derived from PARENT, return the actual base
263 information, unless a one of the protection violations below
264 occurs, in which case emit an error message and return error_mark_node.
266 If PROTECT is 1, then check if access to a public field of PARENT
267 would be private. Also check for ambiguity. */
270 get_binfo (parent
, binfo
, protect
)
271 register tree parent
, binfo
;
274 tree type
= NULL_TREE
;
276 tree rval
= NULL_TREE
;
278 if (TREE_CODE (parent
) == TREE_VEC
)
279 parent
= BINFO_TYPE (parent
);
280 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
281 my_friendly_abort (89);
283 if (TREE_CODE (binfo
) == TREE_VEC
)
284 type
= BINFO_TYPE (binfo
);
285 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
288 my_friendly_abort (90);
290 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
294 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
296 return error_mark_node
;
298 else if (dist
== -2 && protect
)
300 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
302 return error_mark_node
;
308 /* This is the newer depth first get_base_distance routine. */
311 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
312 rval_private_ptr
, new_binfo_ptr
, parent
,
313 protect
, via_virtual_ptr
, via_virtual
,
314 current_scope_in_chain
)
316 int depth
, is_private
, rval
;
317 int *rval_private_ptr
;
318 tree
*new_binfo_ptr
, parent
;
319 int protect
, *via_virtual_ptr
, via_virtual
;
320 int current_scope_in_chain
;
326 && !current_scope_in_chain
327 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
328 current_scope_in_chain
= 1;
330 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
335 /* This is the first time we've found parent. */
337 else if (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
338 BINFO_OFFSET (binfo
))
339 && *via_virtual_ptr
&& via_virtual
)
341 /* A new path to the same vbase. If this one has better
342 access or is shorter, take it. */
345 better
= *rval_private_ptr
- is_private
;
347 better
= rval
- depth
;
351 /* Ambiguous base class. */
354 /* If we get an ambiguity between virtual and non-virtual base
355 class, return the non-virtual in case we are ignoring
357 better
= *via_virtual_ptr
- via_virtual
;
363 *rval_private_ptr
= is_private
;
364 *new_binfo_ptr
= binfo
;
365 *via_virtual_ptr
= via_virtual
;
371 binfos
= BINFO_BASETYPES (binfo
);
372 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
375 /* Process base types. */
376 for (i
= 0; i
< n_baselinks
; i
++)
378 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
383 || (!TREE_VIA_PUBLIC (base_binfo
)
384 && !(TREE_VIA_PROTECTED (base_binfo
)
385 && current_scope_in_chain
)
386 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))))
388 && (is_private
|| !TREE_VIA_PUBLIC (base_binfo
))));
390 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
392 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
393 rval
, rval_private_ptr
,
394 new_binfo_ptr
, parent
,
395 protect
, via_virtual_ptr
,
397 current_scope_in_chain
);
399 /* If we've found a non-virtual, ambiguous base class, we don't need
400 to keep searching. */
401 if (rval
== -2 && *via_virtual_ptr
== 0)
408 /* Return the number of levels between type PARENT and the type given
409 in BINFO, following the leftmost path to PARENT not found along a
410 virtual path, if there are no real PARENTs (all come from virtual
411 base classes), then follow the shortest public path to PARENT.
413 Return -1 if TYPE is not derived from PARENT.
414 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
416 Return -3 if PARENT is not accessible in TYPE, and PROTECT is non-zero.
418 If PATH_PTR is non-NULL, then also build the list of types
419 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
422 If PROTECT is greater than 1, ignore any special access the current
423 scope might have when determining whether PARENT is inaccessible.
425 PARENT can also be a binfo, in which case that exact parent is found
426 and no other. convert_pointer_to_real uses this functionality.
428 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
431 get_base_distance (parent
, binfo
, protect
, path_ptr
)
432 register tree parent
, binfo
;
437 int rval_private
= 0;
438 tree type
= NULL_TREE
;
439 tree new_binfo
= NULL_TREE
;
441 int watch_access
= protect
;
443 /* Should we be completing types here? */
444 if (TREE_CODE (parent
) != TREE_VEC
)
445 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
447 complete_type (TREE_TYPE (parent
));
449 if (TREE_CODE (binfo
) == TREE_VEC
)
450 type
= BINFO_TYPE (binfo
);
451 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
453 type
= complete_type (binfo
);
454 binfo
= TYPE_BINFO (type
);
457 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
,
461 my_friendly_abort (92);
463 if (parent
== type
|| parent
== binfo
)
465 /* If the distance is 0, then we don't really need
466 a path pointer, but we shouldn't let garbage go back. */
472 if (path_ptr
&& watch_access
== 0)
475 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
476 &rval_private
, &new_binfo
, parent
,
477 watch_access
, &via_virtual
, 0,
480 /* Access restrictions don't count if we found an ambiguous basetype. */
481 if (rval
== -2 && protect
>= 0)
484 if (rval
&& protect
&& rval_private
)
487 /* If they gave us the real vbase binfo, which isn't in the main binfo
488 tree, deal with it. This happens when we are called from
489 expand_upcast_fixups. */
490 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
491 && parent
== binfo_for_vbase (BINFO_TYPE (parent
), type
))
498 *path_ptr
= new_binfo
;
502 /* Worker function for get_dynamic_cast_base_type. */
505 dynamic_cast_base_recurse (subtype
, binfo
, via_virtual
, offset_ptr
)
515 if (BINFO_TYPE (binfo
) == subtype
)
521 *offset_ptr
= BINFO_OFFSET (binfo
);
526 binfos
= BINFO_BASETYPES (binfo
);
527 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
528 for (i
= 0; i
< n_baselinks
; i
++)
530 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
533 if (!TREE_VIA_PUBLIC (base_binfo
))
535 rval
= dynamic_cast_base_recurse
536 (subtype
, base_binfo
,
537 via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
), offset_ptr
);
541 worst
= worst
>= 0 ? -3 : worst
;
544 else if (rval
== -3 && worst
!= -1)
550 /* The dynamic cast runtime needs a hint about how the static SUBTYPE type
551 started from is related to the required TARGET type, in order to optimize
552 the inheritance graph search. This information is independant of the
553 current context, and ignores private paths, hence get_base_distance is
554 inappropriate. Return a TREE specifying the base offset, BOFF.
555 BOFF >= 0, there is only one public non-virtual SUBTYPE base at offset BOFF,
556 and there are no public virtual SUBTYPE bases.
557 BOFF == -1, SUBTYPE occurs as multiple public virtual or non-virtual bases.
558 BOFF == -2, SUBTYPE is not a public base.
559 BOFF == -3, SUBTYPE occurs as multiple public non-virtual bases. */
562 get_dynamic_cast_base_type (subtype
, target
)
566 tree offset
= NULL_TREE
;
567 int boff
= dynamic_cast_base_recurse (subtype
, TYPE_BINFO (target
),
572 return build_int_2 (boff
, -1);
575 /* Search for a member with name NAME in a multiple inheritance lattice
576 specified by TYPE. If it does not exist, return NULL_TREE.
577 If the member is ambiguously referenced, return `error_mark_node'.
578 Otherwise, return the FIELD_DECL. */
580 /* Do a 1-level search for NAME as a member of TYPE. The caller must
581 figure out whether it can access this field. (Since it is only one
582 level, this is reasonable.) */
585 lookup_field_1 (type
, name
)
590 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
591 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
592 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
593 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
594 the code often worked even when we treated the index as a list
599 && DECL_LANG_SPECIFIC (TYPE_NAME (type
))
600 && DECL_SORTED_FIELDS (TYPE_NAME (type
)))
602 tree
*fields
= &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type
)), 0);
603 int lo
= 0, hi
= TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type
)));
610 #ifdef GATHER_STATISTICS
612 #endif /* GATHER_STATISTICS */
614 if (DECL_NAME (fields
[i
]) > name
)
616 else if (DECL_NAME (fields
[i
]) < name
)
620 /* We might have a nested class and a field with the
621 same name; we sorted them appropriately via
622 field_decl_cmp, so just look for the last field with
625 && DECL_NAME (fields
[i
+1]) == name
)
633 field
= TYPE_FIELDS (type
);
635 #ifdef GATHER_STATISTICS
636 n_calls_lookup_field_1
++;
637 #endif /* GATHER_STATISTICS */
640 #ifdef GATHER_STATISTICS
642 #endif /* GATHER_STATISTICS */
643 my_friendly_assert (DECL_P (field
), 0);
644 if (DECL_NAME (field
) == NULL_TREE
645 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
647 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
651 if (TREE_CODE (field
) == USING_DECL
)
652 /* For now, we're just treating member using declarations as
653 old ARM-style access declarations. Thus, there's no reason
654 to return a USING_DECL, and the rest of the compiler can't
655 handle it. Once the class is defined, these are purged
656 from TYPE_FIELDS anyhow; see handle_using_decl. */
658 else if (DECL_NAME (field
) == name
)
660 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
661 && DECL_ASSEMBLER_NAME (field
) != NULL
)
662 GNU_xref_ref(current_function_decl
,
663 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
666 field
= TREE_CHAIN (field
);
669 if (name
== vptr_identifier
)
671 /* Give the user what s/he thinks s/he wants. */
672 if (TYPE_POLYMORPHIC_P (type
))
673 return TYPE_VFIELD (type
);
678 /* There are a number of cases we need to be aware of here:
679 current_class_type current_function_decl
686 Those last two make life interesting. If we're in a function which is
687 itself inside a class, we need decls to go into the fn's decls (our
688 second case below). But if we're in a class and the class itself is
689 inside a function, we need decls to go into the decls for the class. To
690 achieve this last goal, we must see if, when both current_class_ptr and
691 current_function_decl are set, the class was declared inside that
692 function. If so, we know to put the decls into the class's scope. */
697 if (current_function_decl
== NULL_TREE
)
698 return current_class_type
;
699 if (current_class_type
== NULL_TREE
)
700 return current_function_decl
;
701 if ((DECL_FUNCTION_MEMBER_P (current_function_decl
)
702 && same_type_p (DECL_CONTEXT (current_function_decl
),
704 || (DECL_FRIEND_CONTEXT (current_function_decl
)
705 && same_type_p (DECL_FRIEND_CONTEXT (current_function_decl
),
706 current_class_type
)))
707 return current_function_decl
;
709 return current_class_type
;
712 /* Returns non-zero if we are currently in a function scope. Note
713 that this function returns zero if we are within a local class, but
714 not within a member function body of the local class. */
717 at_function_scope_p ()
719 tree cs
= current_scope ();
720 return cs
&& TREE_CODE (cs
) == FUNCTION_DECL
;
723 /* Return the scope of DECL, as appropriate when doing name-lookup. */
726 context_for_name_lookup (decl
)
731 For the purposes of name lookup, after the anonymous union
732 definition, the members of the anonymous union are considered to
733 have been defined in the scope in which the anonymous union is
735 tree context
= CP_DECL_CONTEXT (decl
);
737 while (TYPE_P (context
) && ANON_AGGR_TYPE_P (context
))
738 context
= TYPE_CONTEXT (context
);
740 context
= global_namespace
;
745 /* Return a canonical BINFO if BINFO is a virtual base, or just BINFO
749 canonical_binfo (binfo
)
752 return (TREE_VIA_VIRTUAL (binfo
)
753 ? TYPE_BINFO (BINFO_TYPE (binfo
)) : binfo
);
756 /* A queue function that simply ensures that we walk into the
757 canonical versions of virtual bases. */
760 dfs_canonical_queue (binfo
, data
)
762 void *data ATTRIBUTE_UNUSED
;
764 return canonical_binfo (binfo
);
767 /* Called via dfs_walk from assert_canonical_unmarked. */
770 dfs_assert_unmarked_p (binfo
, data
)
772 void *data ATTRIBUTE_UNUSED
;
774 my_friendly_assert (!BINFO_MARKED (binfo
), 0);
778 /* Asserts that all the nodes below BINFO (using the canonical
779 versions of virtual bases) are unmarked. */
782 assert_canonical_unmarked (binfo
)
785 dfs_walk (binfo
, dfs_assert_unmarked_p
, dfs_canonical_queue
, 0);
788 /* If BINFO is marked, return a canonical version of BINFO.
789 Otherwise, return NULL_TREE. */
792 shared_marked_p (binfo
, data
)
796 binfo
= canonical_binfo (binfo
);
797 return markedp (binfo
, data
);
800 /* If BINFO is not marked, return a canonical version of BINFO.
801 Otherwise, return NULL_TREE. */
804 shared_unmarked_p (binfo
, data
)
808 binfo
= canonical_binfo (binfo
);
809 return unmarkedp (binfo
, data
);
812 /* The accessibility routines use BINFO_ACCESS for scratch space
813 during the computation of the accssibility of some declaration. */
815 #define BINFO_ACCESS(NODE) \
816 ((access_kind) ((TREE_LANG_FLAG_1 (NODE) << 1) | TREE_LANG_FLAG_6 (NODE)))
818 /* Set the access associated with NODE to ACCESS. */
820 #define SET_BINFO_ACCESS(NODE, ACCESS) \
821 ((TREE_LANG_FLAG_1 (NODE) = (ACCESS & 2) != 0), \
822 (TREE_LANG_FLAG_6 (NODE) = (ACCESS & 1) != 0))
824 /* Called from access_in_type via dfs_walk. Calculate the access to
825 DATA (which is really a DECL) in BINFO. */
828 dfs_access_in_type (binfo
, data
)
832 tree decl
= (tree
) data
;
833 tree type
= BINFO_TYPE (binfo
);
834 access_kind access
= ak_none
;
836 if (context_for_name_lookup (decl
) == type
)
838 /* If we have desceneded to the scope of DECL, just note the
839 appropriate access. */
840 if (TREE_PRIVATE (decl
))
842 else if (TREE_PROTECTED (decl
))
843 access
= ak_protected
;
849 /* First, check for an access-declaration that gives us more
850 access to the DECL. The CONST_DECL for an enumeration
851 constant will not have DECL_LANG_SPECIFIC, and thus no
853 if (DECL_LANG_SPECIFIC (decl
))
855 tree decl_access
= purpose_member (type
, DECL_ACCESS (decl
));
857 access
= ((access_kind
)
858 TREE_INT_CST_LOW (TREE_VALUE (decl_access
)));
867 /* Otherwise, scan our baseclasses, and pick the most favorable
869 binfos
= BINFO_BASETYPES (binfo
);
870 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
871 for (i
= 0; i
< n_baselinks
; ++i
)
873 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
874 access_kind base_access
875 = BINFO_ACCESS (canonical_binfo (base_binfo
));
877 if (base_access
== ak_none
|| base_access
== ak_private
)
878 /* If it was not accessible in the base, or only
879 accessible as a private member, we can't access it
881 base_access
= ak_none
;
882 else if (TREE_VIA_PROTECTED (base_binfo
))
883 /* Public and protected members in the base are
885 base_access
= ak_protected
;
886 else if (!TREE_VIA_PUBLIC (base_binfo
))
887 /* Public and protected members in the base are
889 base_access
= ak_private
;
891 /* See if the new access, via this base, gives more
892 access than our previous best access. */
893 if (base_access
!= ak_none
894 && (base_access
== ak_public
895 || (base_access
== ak_protected
896 && access
!= ak_public
)
897 || (base_access
== ak_private
898 && access
== ak_none
)))
900 access
= base_access
;
902 /* If the new access is public, we can't do better. */
903 if (access
== ak_public
)
910 /* Note the access to DECL in TYPE. */
911 SET_BINFO_ACCESS (binfo
, access
);
913 /* Mark TYPE as visited so that if we reach it again we do not
914 duplicate our efforts here. */
915 SET_BINFO_MARKED (binfo
);
920 /* Return the access to DECL in TYPE. */
923 access_in_type (type
, decl
)
927 tree binfo
= TYPE_BINFO (type
);
929 /* We must take into account
933 If a name can be reached by several paths through a multiple
934 inheritance graph, the access is that of the path that gives
937 The algorithm we use is to make a post-order depth-first traversal
938 of the base-class hierarchy. As we come up the tree, we annotate
939 each node with the most lenient access. */
940 dfs_walk_real (binfo
, 0, dfs_access_in_type
, shared_unmarked_p
, decl
);
941 dfs_walk (binfo
, dfs_unmark
, shared_marked_p
, 0);
942 assert_canonical_unmarked (binfo
);
944 return BINFO_ACCESS (binfo
);
947 /* Called from dfs_accessible_p via dfs_walk. */
950 dfs_accessible_queue_p (binfo
, data
)
952 void *data ATTRIBUTE_UNUSED
;
954 if (BINFO_MARKED (binfo
))
957 /* If this class is inherited via private or protected inheritance,
958 then we can't see it, unless we are a friend of the subclass. */
959 if (!TREE_VIA_PUBLIC (binfo
)
960 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
)),
964 return canonical_binfo (binfo
);
967 /* Called from dfs_accessible_p via dfs_walk. */
970 dfs_accessible_p (binfo
, data
)
974 int protected_ok
= data
!= 0;
977 SET_BINFO_MARKED (binfo
);
978 access
= BINFO_ACCESS (binfo
);
979 if (access
== ak_public
|| (access
== ak_protected
&& protected_ok
))
981 else if (access
!= ak_none
982 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
988 /* Returns non-zero if it is OK to access DECL through an object
989 indiated by BINFO in the context of DERIVED. */
992 protected_accessible_p (decl
, derived
, binfo
)
999 /* We're checking this clause from [class.access.base]
1001 m as a member of N is protected, and the reference occurs in a
1002 member or friend of class N, or in a member or friend of a
1003 class P derived from N, where m as a member of P is private or
1006 Here DERIVED is a possible P and DECL is m. accessible_p will
1007 iterate over various values of N, but the access to m in DERIVED
1010 Note that I believe that the passage above is wrong, and should read
1011 "...is private or protected or public"; otherwise you get bizarre results
1012 whereby a public using-decl can prevent you from accessing a protected
1013 member of a base. (jason 2000/02/28) */
1015 /* If DERIVED isn't derived from m's class, then it can't be a P. */
1016 if (!DERIVED_FROM_P (context_for_name_lookup (decl
), derived
))
1019 access
= access_in_type (derived
, decl
);
1021 /* If m is inaccessible in DERIVED, then it's not a P. */
1022 if (access
== ak_none
)
1025 /* [class.protected]
1027 When a friend or a member function of a derived class references
1028 a protected nonstatic member of a base class, an access check
1029 applies in addition to those described earlier in clause
1030 _class.access_) Except when forming a pointer to member
1031 (_expr.unary.op_), the access must be through a pointer to,
1032 reference to, or object of the derived class itself (or any class
1033 derived from that class) (_expr.ref_). If the access is to form
1034 a pointer to member, the nested-name-specifier shall name the
1035 derived class (or any class derived from that class). */
1036 if (DECL_NONSTATIC_MEMBER_P (decl
))
1038 /* We can tell through what the reference is occurring by
1039 chasing BINFO up to the root. */
1041 while (BINFO_INHERITANCE_CHAIN (t
))
1042 t
= BINFO_INHERITANCE_CHAIN (t
);
1044 if (!DERIVED_FROM_P (derived
, BINFO_TYPE (t
)))
1051 /* Returns non-zero if SCOPE is a friend of a type which would be able
1052 to access DECL through the object indicated by BINFO. */
1055 friend_accessible_p (scope
, decl
, binfo
)
1060 tree befriending_classes
;
1066 if (TREE_CODE (scope
) == FUNCTION_DECL
1067 || DECL_FUNCTION_TEMPLATE_P (scope
))
1068 befriending_classes
= DECL_BEFRIENDING_CLASSES (scope
);
1069 else if (TYPE_P (scope
))
1070 befriending_classes
= CLASSTYPE_BEFRIENDING_CLASSES (scope
);
1074 for (t
= befriending_classes
; t
; t
= TREE_CHAIN (t
))
1075 if (protected_accessible_p (decl
, TREE_VALUE (t
), binfo
))
1078 /* Nested classes are implicitly friends of their enclosing types, as
1079 per core issue 45 (this is a change from the standard). */
1081 for (t
= TYPE_CONTEXT (scope
); t
&& TYPE_P (t
); t
= TYPE_CONTEXT (t
))
1082 if (protected_accessible_p (decl
, t
, binfo
))
1085 if (TREE_CODE (scope
) == FUNCTION_DECL
1086 || DECL_FUNCTION_TEMPLATE_P (scope
))
1088 /* Perhaps this SCOPE is a member of a class which is a
1090 if (DECL_CLASS_SCOPE_P (decl
)
1091 && friend_accessible_p (DECL_CONTEXT (scope
), decl
, binfo
))
1094 /* Or an instantiation of something which is a friend. */
1095 if (DECL_TEMPLATE_INFO (scope
))
1096 return friend_accessible_p (DECL_TI_TEMPLATE (scope
), decl
, binfo
);
1098 else if (CLASSTYPE_TEMPLATE_INFO (scope
))
1099 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope
), decl
, binfo
);
1104 /* Perform access control on TYPE_DECL VAL, which was looked up in TYPE.
1105 This is fairly complex, so here's the design:
1107 The lang_extdef nonterminal sets type_lookups to NULL_TREE before we
1108 start to process a top-level declaration.
1109 As we process the decl-specifier-seq for the declaration, any types we
1110 see that might need access control are passed to type_access_control,
1111 which defers checking by adding them to type_lookups.
1112 When we are done with the decl-specifier-seq, we record the lookups we've
1113 seen in the lookups field of the typed_declspecs nonterminal.
1114 When we process the first declarator, either in parse_decl or
1115 begin_function_definition, we call save_type_access_control,
1116 which stores the lookups from the decl-specifier-seq in
1117 current_type_lookups.
1118 As we finish with each declarator, we process everything in type_lookups
1119 via decl_type_access_control, which resets type_lookups to the value of
1120 current_type_lookups for subsequent declarators.
1121 When we enter a function, we set type_lookups to error_mark_node, so all
1122 lookups are processed immediately. */
1125 type_access_control (type
, val
)
1128 if (val
== NULL_TREE
|| TREE_CODE (val
) != TYPE_DECL
1129 || ! DECL_CLASS_SCOPE_P (val
))
1132 if (type_lookups
== error_mark_node
)
1133 enforce_access (type
, val
);
1134 else if (! accessible_p (type
, val
))
1135 type_lookups
= tree_cons (type
, val
, type_lookups
);
1138 /* DECL is a declaration from a base class of TYPE, which was the
1139 class used to name DECL. Return non-zero if, in the current
1140 context, DECL is accessible. If TYPE is actually a BINFO node,
1141 then we can tell in what context the access is occurring by looking
1142 at the most derived class along the path indicated by BINFO. */
1145 accessible_p (type
, decl
)
1153 /* Non-zero if it's OK to access DECL if it has protected
1154 accessibility in TYPE. */
1155 int protected_ok
= 0;
1157 /* If we're not checking access, everything is accessible. */
1158 if (!flag_access_control
)
1161 /* If this declaration is in a block or namespace scope, there's no
1163 if (!TYPE_P (context_for_name_lookup (decl
)))
1169 type
= BINFO_TYPE (type
);
1172 binfo
= TYPE_BINFO (type
);
1174 /* [class.access.base]
1176 A member m is accessible when named in class N if
1178 --m as a member of N is public, or
1180 --m as a member of N is private, and the reference occurs in a
1181 member or friend of class N, or
1183 --m as a member of N is protected, and the reference occurs in a
1184 member or friend of class N, or in a member or friend of a
1185 class P derived from N, where m as a member of P is private or
1188 --there exists a base class B of N that is accessible at the point
1189 of reference, and m is accessible when named in class B.
1191 We walk the base class hierarchy, checking these conditions. */
1193 /* Figure out where the reference is occurring. Check to see if
1194 DECL is private or protected in this scope, since that will
1195 determine whether protected access is allowed. */
1196 if (current_class_type
)
1197 protected_ok
= protected_accessible_p (decl
, current_class_type
, binfo
);
1199 /* Now, loop through the classes of which we are a friend. */
1201 protected_ok
= friend_accessible_p (current_scope (), decl
, binfo
);
1203 /* Standardize the binfo that access_in_type will use. We don't
1204 need to know what path was chosen from this point onwards. */
1205 binfo
= TYPE_BINFO (type
);
1207 /* Compute the accessibility of DECL in the class hierarchy
1208 dominated by type. */
1209 access_in_type (type
, decl
);
1210 /* Walk the hierarchy again, looking for a base class that allows
1212 t
= dfs_walk (binfo
, dfs_accessible_p
,
1213 dfs_accessible_queue_p
,
1214 protected_ok
? &protected_ok
: 0);
1215 /* Clear any mark bits. Note that we have to walk the whole tree
1216 here, since we have aborted the previous walk from some point
1217 deep in the tree. */
1218 dfs_walk (binfo
, dfs_unmark
, dfs_canonical_queue
, 0);
1219 assert_canonical_unmarked (binfo
);
1221 return t
!= NULL_TREE
;
1224 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1225 found as a base class and sub-object of the object denoted by
1226 BINFO. This routine relies upon binfos not being shared, except
1227 for binfos for virtual bases. */
1230 is_subobject_of_p (parent
, binfo
)
1236 /* We want to canonicalize for comparison purposes. But, when we
1237 iterate through basetypes later, we want the binfos from the
1238 original hierarchy. That's why we have to calculate BINFOS
1239 first, and then canonicalize. */
1240 binfos
= BINFO_BASETYPES (binfo
);
1241 parent
= canonical_binfo (parent
);
1242 binfo
= canonical_binfo (binfo
);
1244 if (parent
== binfo
)
1247 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1249 /* Process and/or queue base types. */
1250 for (i
= 0; i
< n_baselinks
; i
++)
1252 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1253 if (!CLASS_TYPE_P (TREE_TYPE (base_binfo
)))
1254 /* If we see a TEMPLATE_TYPE_PARM, or some such, as a base
1255 class there's no way to descend into it. */
1258 if (is_subobject_of_p (parent
, base_binfo
))
1264 /* See if a one FIELD_DECL hides another. This routine is meant to
1265 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1266 binfos given are the binfos corresponding to the particular places
1267 the FIELD_DECLs are found. This routine relies upon binfos not
1268 being shared, except for virtual bases. */
1271 hides (hider_binfo
, hidee_binfo
)
1272 tree hider_binfo
, hidee_binfo
;
1274 /* hider hides hidee, if hider has hidee as a base class and
1275 the instance of hidee is a sub-object of hider. The first
1276 part is always true is the second part is true.
1278 When hider and hidee are the same (two ways to get to the exact
1279 same member) we consider either one as hiding the other. */
1280 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
1283 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1284 function was declared inside the class given by TYPE. It really should
1285 only return functions that match the given TYPE. */
1288 lookup_fnfields_here (type
, name
)
1291 int idx
= lookup_fnfields_1 (type
, name
);
1294 /* ctors and dtors are always only in the right class. */
1297 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1300 if (TYPE_MAIN_VARIANT (DECL_CONTEXT (OVL_CURRENT (fndecls
)))
1301 == TYPE_MAIN_VARIANT (type
))
1303 fndecls
= OVL_CHAIN (fndecls
);
1308 struct lookup_field_info
{
1309 /* The type in which we're looking. */
1311 /* The name of the field for which we're looking. */
1313 /* If non-NULL, the current result of the lookup. */
1315 /* The path to RVAL. */
1317 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1320 /* If non-zero, we are looking for types, not data members. */
1322 /* If non-zero, RVAL was found by looking through a dependent base. */
1323 int from_dep_base_p
;
1324 /* If something went wrong, a message indicating what. */
1328 /* Returns non-zero if BINFO is not hidden by the value found by the
1329 lookup so far. If BINFO is hidden, then there's no need to look in
1330 it. DATA is really a struct lookup_field_info. Called from
1331 lookup_field via breadth_first_search. */
1334 lookup_field_queue_p (binfo
, data
)
1338 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1340 /* Don't look for constructors or destructors in base classes. */
1341 if (IDENTIFIER_CTOR_OR_DTOR_P (lfi
->name
))
1344 /* If this base class is hidden by the best-known value so far, we
1345 don't need to look. */
1346 if (!lfi
->from_dep_base_p
&& lfi
->rval_binfo
1347 && hides (lfi
->rval_binfo
, binfo
))
1350 return CANONICAL_BINFO (binfo
, lfi
->type
);
1353 /* Within the scope of a template class, you can refer to the to the
1354 current specialization with the name of the template itself. For
1357 template <typename T> struct S { S* sp; }
1359 Returns non-zero if DECL is such a declaration in a class TYPE. */
1362 template_self_reference_p (type
, decl
)
1366 return (CLASSTYPE_USE_TEMPLATE (type
)
1367 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
))
1368 && TREE_CODE (decl
) == TYPE_DECL
1369 && DECL_ARTIFICIAL (decl
)
1370 && DECL_NAME (decl
) == constructor_name (type
));
1373 /* DATA is really a struct lookup_field_info. Look for a field with
1374 the name indicated there in BINFO. If this function returns a
1375 non-NULL value it is the result of the lookup. Called from
1376 lookup_field via breadth_first_search. */
1379 lookup_field_r (binfo
, data
)
1383 struct lookup_field_info
*lfi
= (struct lookup_field_info
*) data
;
1384 tree type
= BINFO_TYPE (binfo
);
1385 tree nval
= NULL_TREE
;
1386 int from_dep_base_p
;
1388 /* First, look for a function. There can't be a function and a data
1389 member with the same name, and if there's a function and a type
1390 with the same name, the type is hidden by the function. */
1391 if (!lfi
->want_type
)
1393 int idx
= lookup_fnfields_here (type
, lfi
->name
);
1395 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1399 /* Look for a data member or type. */
1400 nval
= lookup_field_1 (type
, lfi
->name
);
1402 /* If there is no declaration with the indicated name in this type,
1403 then there's nothing to do. */
1407 /* If we're looking up a type (as with an elaborated type specifier)
1408 we ignore all non-types we find. */
1409 if (lfi
->want_type
&& TREE_CODE (nval
) != TYPE_DECL
)
1411 nval
= purpose_member (lfi
->name
, CLASSTYPE_TAGS (type
));
1413 nval
= TYPE_MAIN_DECL (TREE_VALUE (nval
));
1418 /* You must name a template base class with a template-id. */
1419 if (!same_type_p (type
, lfi
->type
)
1420 && template_self_reference_p (type
, nval
))
1423 from_dep_base_p
= dependent_base_p (binfo
);
1424 if (lfi
->from_dep_base_p
&& !from_dep_base_p
)
1426 /* If the new declaration is not found via a dependent base, and
1427 the old one was, then we must prefer the new one. We weren't
1428 really supposed to be able to find the old one, so we don't
1429 want to be affected by a specialization. Consider:
1431 struct B { typedef int I; };
1432 template <typename T> struct D1 : virtual public B {};
1433 template <typename T> struct D :
1434 public D1, virtual pubic B { I i; };
1436 The `I' in `D<T>' is unambigousuly `B::I', regardless of how
1437 D1 is specialized. */
1438 lfi
->from_dep_base_p
= 0;
1439 lfi
->rval
= NULL_TREE
;
1440 lfi
->rval_binfo
= NULL_TREE
;
1441 lfi
->ambiguous
= NULL_TREE
;
1444 else if (lfi
->rval_binfo
&& !lfi
->from_dep_base_p
&& from_dep_base_p
)
1445 /* Similarly, if the old declaration was not found via a dependent
1446 base, and the new one is, ignore the new one. */
1449 /* If the lookup already found a match, and the new value doesn't
1450 hide the old one, we might have an ambiguity. */
1451 if (lfi
->rval_binfo
&& !hides (binfo
, lfi
->rval_binfo
))
1453 if (nval
== lfi
->rval
&& SHARED_MEMBER_P (nval
))
1454 /* The two things are really the same. */
1456 else if (hides (lfi
->rval_binfo
, binfo
))
1457 /* The previous value hides the new one. */
1461 /* We have a real ambiguity. We keep a chain of all the
1463 if (!lfi
->ambiguous
&& lfi
->rval
)
1465 /* This is the first time we noticed an ambiguity. Add
1466 what we previously thought was a reasonable candidate
1468 lfi
->ambiguous
= tree_cons (NULL_TREE
, lfi
->rval
, NULL_TREE
);
1469 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1472 /* Add the new value. */
1473 lfi
->ambiguous
= tree_cons (NULL_TREE
, nval
, lfi
->ambiguous
);
1474 TREE_TYPE (lfi
->ambiguous
) = error_mark_node
;
1475 lfi
->errstr
= "request for member `%D' is ambiguous";
1480 /* If the thing we're looking for is a virtual base class, then
1481 we know we've got what we want at this point; there's no way
1482 to get an ambiguity. */
1483 if (VBASE_NAME_P (lfi
->name
))
1489 if (from_dep_base_p
&& TREE_CODE (nval
) != TYPE_DECL
1490 /* We need to return a member template class so we can
1491 define partial specializations. Is there a better
1493 && !DECL_CLASS_TEMPLATE_P (nval
))
1494 /* The thing we're looking for isn't a type, so the implicit
1495 typename extension doesn't apply, so we just pretend we
1496 didn't find anything. */
1500 lfi
->from_dep_base_p
= from_dep_base_p
;
1501 lfi
->rval_binfo
= binfo
;
1507 /* Look for a memer named NAME in an inheritance lattice dominated by
1508 XBASETYPE. PROTECT is 0 or two, we do not check access. If it is
1509 1, we enforce accessibility. If PROTECT is zero, then, for an
1510 ambiguous lookup, we return NULL. If PROTECT is 1, we issue an
1511 error message. If PROTECT is 2, we return a TREE_LIST whose
1512 TREE_TYPE is error_mark_node and whose TREE_VALUEs are the list of
1513 ambiguous candidates.
1515 WANT_TYPE is 1 when we should only return TYPE_DECLs, if no
1516 TYPE_DECL can be found return NULL_TREE. */
1519 lookup_member (xbasetype
, name
, protect
, want_type
)
1520 register tree xbasetype
, name
;
1521 int protect
, want_type
;
1523 tree rval
, rval_binfo
= NULL_TREE
;
1524 tree type
= NULL_TREE
, basetype_path
= NULL_TREE
;
1525 struct lookup_field_info lfi
;
1527 /* rval_binfo is the binfo associated with the found member, note,
1528 this can be set with useful information, even when rval is not
1529 set, because it must deal with ALL members, not just non-function
1530 members. It is used for ambiguity checking and the hidden
1531 checks. Whereas rval is only set if a proper (not hidden)
1532 non-function member is found. */
1534 const char *errstr
= 0;
1536 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1537 && IDENTIFIER_CLASS_VALUE (name
))
1539 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1540 if (TREE_CODE (field
) != FUNCTION_DECL
1541 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1542 /* We're in the scope of this class, and the value has already
1543 been looked up. Just return the cached value. */
1547 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1549 type
= BINFO_TYPE (xbasetype
);
1550 basetype_path
= xbasetype
;
1552 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1555 basetype_path
= TYPE_BINFO (type
);
1556 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
1560 my_friendly_abort (97);
1562 complete_type (type
);
1564 #ifdef GATHER_STATISTICS
1565 n_calls_lookup_field
++;
1566 #endif /* GATHER_STATISTICS */
1568 bzero ((PTR
) &lfi
, sizeof (lfi
));
1571 lfi
.want_type
= want_type
;
1572 bfs_walk (basetype_path
, &lookup_field_r
, &lookup_field_queue_p
, &lfi
);
1574 rval_binfo
= lfi
.rval_binfo
;
1576 type
= BINFO_TYPE (rval_binfo
);
1577 errstr
= lfi
.errstr
;
1579 /* If we are not interested in ambiguities, don't report them;
1580 just return NULL_TREE. */
1581 if (!protect
&& lfi
.ambiguous
)
1587 return lfi
.ambiguous
;
1594 In the case of overloaded function names, access control is
1595 applied to the function selected by overloaded resolution. */
1596 if (rval
&& protect
&& !is_overloaded_fn (rval
)
1597 && !enforce_access (xbasetype
, rval
))
1598 return error_mark_node
;
1600 if (errstr
&& protect
)
1602 cp_error (errstr
, name
, type
);
1604 print_candidates (lfi
.ambiguous
);
1605 rval
= error_mark_node
;
1608 /* If the thing we found was found via the implicit typename
1609 extension, build the typename type. */
1610 if (rval
&& lfi
.from_dep_base_p
&& !DECL_CLASS_TEMPLATE_P (rval
))
1611 rval
= TYPE_STUB_DECL (build_typename_type (BINFO_TYPE (basetype_path
),
1615 if (rval
&& is_overloaded_fn (rval
))
1617 /* Note that the binfo we put in the baselink is the binfo where
1618 we found the functions, which we need for overload
1619 resolution, but which should not be passed to enforce_access;
1620 rather, enforce_access wants a binfo which refers to the
1621 scope in which we started looking for the function. This
1622 will generally be the binfo passed into this function as
1625 rval
= tree_cons (rval_binfo
, rval
, NULL_TREE
);
1626 SET_BASELINK_P (rval
);
1632 /* Like lookup_member, except that if we find a function member we
1633 return NULL_TREE. */
1636 lookup_field (xbasetype
, name
, protect
, want_type
)
1637 register tree xbasetype
, name
;
1638 int protect
, want_type
;
1640 tree rval
= lookup_member (xbasetype
, name
, protect
, want_type
);
1642 /* Ignore functions. */
1643 if (rval
&& TREE_CODE (rval
) == TREE_LIST
)
1649 /* Like lookup_member, except that if we find a non-function member we
1650 return NULL_TREE. */
1653 lookup_fnfields (xbasetype
, name
, protect
)
1654 register tree xbasetype
, name
;
1657 tree rval
= lookup_member (xbasetype
, name
, protect
, /*want_type=*/0);
1659 /* Ignore non-functions. */
1660 if (rval
&& TREE_CODE (rval
) != TREE_LIST
)
1666 /* TYPE is a class type. Return the index of the fields within
1667 the method vector with name NAME, or -1 is no such field exists. */
1670 lookup_fnfields_1 (type
, name
)
1674 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
1676 if (method_vec
!= 0)
1679 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1680 int len
= TREE_VEC_LENGTH (method_vec
);
1683 #ifdef GATHER_STATISTICS
1684 n_calls_lookup_fnfields_1
++;
1685 #endif /* GATHER_STATISTICS */
1687 /* Constructors are first... */
1688 if (name
== ctor_identifier
)
1689 return (methods
[CLASSTYPE_CONSTRUCTOR_SLOT
]
1690 ? CLASSTYPE_CONSTRUCTOR_SLOT
: -1);
1691 /* and destructors are second. */
1692 if (name
== dtor_identifier
)
1693 return (methods
[CLASSTYPE_DESTRUCTOR_SLOT
]
1694 ? CLASSTYPE_DESTRUCTOR_SLOT
: -1);
1696 for (i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
1697 i
< len
&& methods
[i
];
1700 #ifdef GATHER_STATISTICS
1701 n_outer_fields_searched
++;
1702 #endif /* GATHER_STATISTICS */
1704 tmp
= OVL_CURRENT (methods
[i
]);
1705 if (DECL_NAME (tmp
) == name
)
1708 /* If the type is complete and we're past the conversion ops,
1709 switch to binary search. */
1710 if (! DECL_CONV_FN_P (tmp
)
1711 && COMPLETE_TYPE_P (type
))
1713 int lo
= i
+ 1, hi
= len
;
1719 #ifdef GATHER_STATISTICS
1720 n_outer_fields_searched
++;
1721 #endif /* GATHER_STATISTICS */
1723 tmp
= DECL_NAME (OVL_CURRENT (methods
[i
]));
1727 else if (tmp
< name
)
1736 /* If we didn't find it, it might have been a template
1737 conversion operator. (Note that we don't look for this case
1738 above so that we will always find specializations first.) */
1739 if (IDENTIFIER_TYPENAME_P (name
))
1741 for (i
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
1742 i
< len
&& methods
[i
];
1745 tmp
= OVL_CURRENT (methods
[i
]);
1746 if (! DECL_CONV_FN_P (tmp
))
1748 /* Since all conversion operators come first, we know
1749 there is no such operator. */
1752 else if (TREE_CODE (tmp
) == TEMPLATE_DECL
)
1761 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1762 type in the hierarchy, in a breadth-first preorder traversal. .
1763 If it ever returns a non-NULL value, that value is immediately
1764 returned and the walk is terminated. At each node FN, is passed a
1765 BINFO indicating the path from the curently visited base-class to
1766 TYPE. Before each base-class is walked QFN is called. If the
1767 value returned is non-zero, the base-class is walked; otherwise it
1768 is not. If QFN is NULL, it is treated as a function which always
1769 returns 1. Both FN and QFN are passed the DATA whenever they are
1773 bfs_walk (binfo
, fn
, qfn
, data
)
1775 tree (*fn
) PARAMS ((tree
, void *));
1776 tree (*qfn
) PARAMS ((tree
, void *));
1781 tree rval
= NULL_TREE
;
1782 /* An array of the base classes of BINFO. These will be built up in
1783 breadth-first order, except where QFN prunes the search. */
1784 varray_type bfs_bases
;
1786 /* Start with enough room for ten base classes. That will be enough
1787 for most hierarchies. */
1788 VARRAY_TREE_INIT (bfs_bases
, 10, "search_stack");
1790 /* Put the first type into the stack. */
1791 VARRAY_TREE (bfs_bases
, 0) = binfo
;
1794 for (head
= 0; head
< tail
; ++head
)
1800 /* Pull the next type out of the queue. */
1801 binfo
= VARRAY_TREE (bfs_bases
, head
);
1803 /* If this is the one we're looking for, we're done. */
1804 rval
= (*fn
) (binfo
, data
);
1808 /* Queue up the base types. */
1809 binfos
= BINFO_BASETYPES (binfo
);
1810 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
): 0;
1811 for (i
= 0; i
< n_baselinks
; i
++)
1813 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1816 base_binfo
= (*qfn
) (base_binfo
, data
);
1820 if (tail
== VARRAY_SIZE (bfs_bases
))
1821 VARRAY_GROW (bfs_bases
, 2 * VARRAY_SIZE (bfs_bases
));
1822 VARRAY_TREE (bfs_bases
, tail
) = base_binfo
;
1829 VARRAY_FREE (bfs_bases
);
1834 /* Exactly like bfs_walk, except that a depth-first traversal is
1835 performed, and PREFN is called in preorder, while POSTFN is called
1839 dfs_walk_real (binfo
, prefn
, postfn
, qfn
, data
)
1841 tree (*prefn
) PARAMS ((tree
, void *));
1842 tree (*postfn
) PARAMS ((tree
, void *));
1843 tree (*qfn
) PARAMS ((tree
, void *));
1849 tree rval
= NULL_TREE
;
1851 /* Call the pre-order walking function. */
1854 rval
= (*prefn
) (binfo
, data
);
1859 /* Process the basetypes. */
1860 binfos
= BINFO_BASETYPES (binfo
);
1861 n_baselinks
= BINFO_N_BASETYPES (binfo
);
1862 for (i
= 0; i
< n_baselinks
; i
++)
1864 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1867 base_binfo
= (*qfn
) (base_binfo
, data
);
1871 rval
= dfs_walk_real (base_binfo
, prefn
, postfn
, qfn
, data
);
1877 /* Call the post-order walking function. */
1879 rval
= (*postfn
) (binfo
, data
);
1884 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1888 dfs_walk (binfo
, fn
, qfn
, data
)
1890 tree (*fn
) PARAMS ((tree
, void *));
1891 tree (*qfn
) PARAMS ((tree
, void *));
1894 return dfs_walk_real (binfo
, 0, fn
, qfn
, data
);
1899 /* The name of the function we are looking for. */
1901 /* The overloaded functions we have found. */
1905 /* Called from get_virtuals_named_this via bfs_walk. */
1908 get_virtuals_named_this_r (binfo
, data
)
1912 struct gvnt_info
*gvnti
= (struct gvnt_info
*) data
;
1913 tree type
= BINFO_TYPE (binfo
);
1916 idx
= lookup_fnfields_here (BINFO_TYPE (binfo
), gvnti
->name
);
1920 TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
),
1926 /* Return the virtual functions with the indicated NAME in the type
1927 indicated by BINFO. The result is a TREE_LIST whose TREE_PURPOSE
1928 indicates the base class from which the TREE_VALUE (an OVERLOAD or
1929 just a FUNCTION_DECL) originated. */
1932 get_virtuals_named_this (binfo
, name
)
1936 struct gvnt_info gvnti
;
1940 gvnti
.fields
= NULL_TREE
;
1942 bfs_walk (binfo
, get_virtuals_named_this_r
, 0, &gvnti
);
1944 /* Get to the function decls, and return the first virtual function
1945 with this name, if there is one. */
1946 for (fields
= gvnti
.fields
; fields
; fields
= next_baselink (fields
))
1950 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
1951 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
1958 get_virtual_destructor (binfo
, data
)
1960 void *data ATTRIBUTE_UNUSED
;
1962 tree type
= BINFO_TYPE (binfo
);
1963 if (TYPE_HAS_DESTRUCTOR (type
)
1964 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
1965 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
1970 tree_has_any_destructor_p (binfo
, data
)
1972 void *data ATTRIBUTE_UNUSED
;
1974 tree type
= BINFO_TYPE (binfo
);
1975 return TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
) ? binfo
: NULL_TREE
;
1978 /* Returns > 0 if a function with type DRETTYPE overriding a function
1979 with type BRETTYPE is covariant, as defined in [class.virtual].
1981 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1982 adjustment), or -1 if pedantically invalid covariance. */
1985 covariant_return_p (brettype
, drettype
)
1986 tree brettype
, drettype
;
1990 if (TREE_CODE (brettype
) == FUNCTION_DECL
)
1992 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
1993 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
1995 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
1997 brettype
= TREE_TYPE (brettype
);
1998 drettype
= TREE_TYPE (drettype
);
2001 if (same_type_p (brettype
, drettype
))
2004 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
2005 && (TREE_CODE (brettype
) == POINTER_TYPE
2006 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
2007 && TYPE_QUALS (brettype
) == TYPE_QUALS (drettype
)))
2010 if (! can_convert (brettype
, drettype
))
2013 brettype
= TREE_TYPE (brettype
);
2014 drettype
= TREE_TYPE (drettype
);
2016 /* If not pedantic, allow any standard pointer conversion. */
2017 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
2020 binfo
= get_binfo (brettype
, drettype
, 1);
2022 /* If we get an error_mark_node from get_binfo, it already complained,
2023 so let's just succeed. */
2024 if (binfo
== error_mark_node
)
2027 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
2032 /* Check that virtual overrider OVERRIDER is acceptable for base function
2033 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
2036 check_final_overrider (overrider
, basefn
)
2037 tree overrider
, basefn
;
2039 tree over_type
= TREE_TYPE (overrider
);
2040 tree base_type
= TREE_TYPE (basefn
);
2041 tree over_return
= TREE_TYPE (over_type
);
2042 tree base_return
= TREE_TYPE (base_type
);
2043 tree over_throw
= TYPE_RAISES_EXCEPTIONS (over_type
);
2044 tree base_throw
= TYPE_RAISES_EXCEPTIONS (base_type
);
2047 if (same_type_p (base_return
, over_return
))
2049 else if ((i
= covariant_return_p (base_return
, over_return
)))
2052 sorry ("adjusting pointers for covariant returns");
2054 if (pedantic
&& i
== -1)
2056 cp_pedwarn_at ("invalid covariant return type for `virtual %#D'", overrider
);
2057 cp_pedwarn_at (" overriding `virtual %#D' (must be pointer or reference to class)", basefn
);
2060 else if (IS_AGGR_TYPE_2 (base_return
, over_return
)
2061 && same_or_base_type_p (base_return
, over_return
))
2063 cp_error_at ("invalid covariant return type for `virtual %#D'", overrider
);
2064 cp_error_at (" overriding `virtual %#D' (must use pointer or reference)", basefn
);
2067 else if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider
)) == NULL_TREE
)
2069 cp_error_at ("conflicting return type specified for `virtual %#D'", overrider
);
2070 cp_error_at (" overriding `virtual %#D'", basefn
);
2071 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider
),
2072 DECL_CONTEXT (overrider
));
2076 /* Check throw specifier is subset. */
2077 /* XXX At the moment, punt on an overriding artificial function. We
2078 don't generate its exception specifier, so can't check it properly. */
2079 if (! DECL_ARTIFICIAL (overrider
)
2080 && !comp_except_specs (base_throw
, over_throw
, 0))
2082 cp_error_at ("looser throw specifier for `virtual %#F'", overrider
);
2083 cp_error_at (" overriding `virtual %#F'", basefn
);
2089 /* Given a class type TYPE, and a function decl FNDECL, look for a
2090 virtual function in TYPE's hierarchy which FNDECL could match as a
2091 virtual function. It doesn't matter which one we find.
2093 DTORP is nonzero if we are looking for a destructor. Destructors
2094 need special treatment because they do not match by name. */
2097 get_matching_virtual (binfo
, fndecl
, dtorp
)
2101 tree tmp
= NULL_TREE
;
2103 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
2104 /* In [temp.mem] we have:
2106 A specialization of a member function template does not
2107 override a virtual function from a base class. */
2110 /* Breadth first search routines start searching basetypes
2111 of TYPE, so we must perform first ply of search here. */
2113 return bfs_walk (binfo
, get_virtual_destructor
,
2114 tree_has_any_destructor_p
, 0);
2117 tree drettype
, dtypes
, btypes
, instptr_type
;
2118 tree baselink
, best
= NULL_TREE
;
2119 tree declarator
= DECL_NAME (fndecl
);
2120 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
2123 baselink
= get_virtuals_named_this (binfo
, declarator
);
2124 if (baselink
== NULL_TREE
)
2127 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
2128 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2129 if (DECL_STATIC_FUNCTION_P (fndecl
))
2130 instptr_type
= NULL_TREE
;
2132 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
2134 for (; baselink
; baselink
= next_baselink (baselink
))
2137 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
2139 tmp
= OVL_CURRENT (tmps
);
2140 if (! DECL_VINDEX (tmp
))
2143 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
2144 if (instptr_type
== NULL_TREE
)
2146 if (compparms (TREE_CHAIN (btypes
), dtypes
))
2147 /* Caller knows to give error in this case. */
2152 if (/* The first parameter is the `this' parameter,
2153 which has POINTER_TYPE, and we can therefore
2154 safely use TYPE_QUALS, rather than
2156 (TYPE_QUALS (TREE_TYPE (TREE_VALUE (btypes
)))
2157 == TYPE_QUALS (instptr_type
))
2158 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
)))
2160 check_final_overrider (fndecl
, tmp
);
2162 /* FNDECL overrides this function. We continue to
2163 check all the other functions in order to catch
2164 errors; it might be that in some other baseclass
2165 a virtual function was declared with the same
2166 parameter types, but a different return type. */
2176 /* A queue function for dfs_walk that skips any nonprimary virtual
2177 bases and any already marked bases. */
2180 dfs_skip_nonprimary_vbases_unmarkedp (binfo
, data
)
2182 void *data ATTRIBUTE_UNUSED
;
2184 if (TREE_VIA_VIRTUAL (binfo
) && !BINFO_PRIMARY_MARKED_P (binfo
))
2185 /* This is a non-primary virtual base. Skip it. */
2188 return unmarkedp (binfo
, NULL
);
2191 /* A queue function for dfs_walk that skips any nonprimary virtual
2192 bases and any unmarked bases. */
2195 dfs_skip_nonprimary_vbases_markedp (binfo
, data
)
2197 void *data ATTRIBUTE_UNUSED
;
2199 if (TREE_VIA_VIRTUAL (binfo
) && !BINFO_PRIMARY_MARKED_P (binfo
))
2200 /* This is a non-primary virtual base. Skip it. */
2203 return markedp (binfo
, NULL
);
2206 /* If BINFO is a non-primary virtual baseclass (in the hierarchy
2207 dominated by TYPE), and no primary copy appears anywhere in the
2208 hierarchy, return the shared copy. If a primary copy appears
2209 elsewhere, return NULL_TREE. Otherwise, return BINFO itself; it is
2210 either a non-virtual base or a primary virtual base. */
2213 get_shared_vbase_if_not_primary (binfo
, data
)
2217 if (TREE_VIA_VIRTUAL (binfo
) && !BINFO_PRIMARY_MARKED_P (binfo
))
2219 tree type
= (tree
) data
;
2221 if (TREE_CODE (type
) == TREE_LIST
)
2222 type
= TREE_PURPOSE (type
);
2224 /* This is a non-primary virtual base. If there is no primary
2225 version, get the shared version. */
2226 binfo
= binfo_for_vbase (BINFO_TYPE (binfo
), type
);
2227 if (BINFO_VBASE_PRIMARY_P (binfo
))
2234 /* A queue function to use with dfs_walk that prevents travel into any
2235 nonprimary virtual base, or its baseclasses. DATA should be the
2236 type of the complete object, or a TREE_LIST whose TREE_PURPOSE is
2237 the type of the complete object. By using this function as a queue
2238 function, you will walk over exactly those BINFOs that actually
2239 exist in the complete object, including those for virtual base
2240 classes. If you SET_BINFO_MARKED for each binfo you process, you
2241 are further guaranteed that you will walk into each virtual base
2242 class exactly once. */
2245 dfs_unmarked_real_bases_queue_p (binfo
, data
)
2249 binfo
= get_shared_vbase_if_not_primary (binfo
, data
);
2250 return binfo
? unmarkedp (binfo
, NULL
) : NULL_TREE
;
2253 /* Like dfs_unmarked_real_bases_queue_p but walks only into things
2254 that are marked, rather than unmarked. */
2257 dfs_marked_real_bases_queue_p (binfo
, data
)
2261 binfo
= get_shared_vbase_if_not_primary (binfo
, data
);
2262 return binfo
? markedp (binfo
, NULL
) : NULL_TREE
;
2265 /* A queue function that skips all virtual bases (and their
2269 dfs_skip_vbases (binfo
, data
)
2271 void *data ATTRIBUTE_UNUSED
;
2273 if (TREE_VIA_VIRTUAL (binfo
))
2279 /* Called via dfs_walk from dfs_get_pure_virtuals. */
2282 dfs_get_pure_virtuals (binfo
, data
)
2286 tree type
= (tree
) data
;
2288 /* We're not interested in primary base classes; the derived class
2289 of which they are a primary base will contain the information we
2291 if (!BINFO_PRIMARY_MARKED_P (binfo
))
2295 for (virtuals
= BINFO_VIRTUALS (binfo
);
2297 virtuals
= TREE_CHAIN (virtuals
))
2298 if (DECL_PURE_VIRTUAL_P (BV_FN (virtuals
)))
2299 CLASSTYPE_PURE_VIRTUALS (type
)
2300 = tree_cons (NULL_TREE
, BV_FN (virtuals
),
2301 CLASSTYPE_PURE_VIRTUALS (type
));
2304 SET_BINFO_MARKED (binfo
);
2309 /* Set CLASSTYPE_PURE_VIRTUALS for TYPE. */
2312 get_pure_virtuals (type
)
2317 /* Clear the CLASSTYPE_PURE_VIRTUALS list; whatever is already there
2318 is going to be overridden. */
2319 CLASSTYPE_PURE_VIRTUALS (type
) = NULL_TREE
;
2320 /* Now, run through all the bases which are not primary bases, and
2321 collect the pure virtual functions. We look at the vtable in
2322 each class to determine what pure virtual functions are present.
2323 (A primary base is not interesting because the derived class of
2324 which it is a primary base will contain vtable entries for the
2325 pure virtuals in the base class. */
2326 dfs_walk (TYPE_BINFO (type
), dfs_get_pure_virtuals
,
2327 dfs_unmarked_real_bases_queue_p
, type
);
2328 dfs_walk (TYPE_BINFO (type
), dfs_unmark
,
2329 dfs_marked_real_bases_queue_p
, type
);
2331 /* Put the pure virtuals in dfs order. */
2332 CLASSTYPE_PURE_VIRTUALS (type
) = nreverse (CLASSTYPE_PURE_VIRTUALS (type
));
2334 for (vbases
= CLASSTYPE_VBASECLASSES (type
);
2336 vbases
= TREE_CHAIN (vbases
))
2340 for (virtuals
= BINFO_VIRTUALS (TREE_VALUE (vbases
));
2342 virtuals
= TREE_CHAIN (virtuals
))
2344 tree base_fndecl
= BV_FN (virtuals
);
2345 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
2346 cp_error ("`%#D' needs a final overrider", base_fndecl
);
2352 next_baselink (baselink
)
2355 tree tmp
= TREE_TYPE (baselink
);
2356 baselink
= TREE_CHAIN (baselink
);
2359 /* @@ does not yet add previous base types. */
2360 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2362 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2363 tmp
= TREE_CHAIN (tmp
);
2368 /* DEPTH-FIRST SEARCH ROUTINES. */
2371 markedp (binfo
, data
)
2373 void *data ATTRIBUTE_UNUSED
;
2375 return BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2379 unmarkedp (binfo
, data
)
2381 void *data ATTRIBUTE_UNUSED
;
2383 return !BINFO_MARKED (binfo
) ? binfo
: NULL_TREE
;
2387 marked_vtable_pathp (binfo
, data
)
2389 void *data ATTRIBUTE_UNUSED
;
2391 return BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2395 unmarked_vtable_pathp (binfo
, data
)
2397 void *data ATTRIBUTE_UNUSED
;
2399 return !BINFO_VTABLE_PATH_MARKED (binfo
) ? binfo
: NULL_TREE
;
2403 marked_pushdecls_p (binfo
, data
)
2405 void *data ATTRIBUTE_UNUSED
;
2407 return (CLASS_TYPE_P (BINFO_TYPE (binfo
))
2408 && BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
2412 unmarked_pushdecls_p (binfo
, data
)
2414 void *data ATTRIBUTE_UNUSED
;
2416 return (CLASS_TYPE_P (BINFO_TYPE (binfo
))
2417 && !BINFO_PUSHDECLS_MARKED (binfo
)) ? binfo
: NULL_TREE
;
2420 /* The worker functions for `dfs_walk'. These do not need to
2421 test anything (vis a vis marking) if they are paired with
2422 a predicate function (above). */
2425 dfs_unmark (binfo
, data
)
2427 void *data ATTRIBUTE_UNUSED
;
2429 CLEAR_BINFO_MARKED (binfo
);
2435 dfs_init_vbase_pointers (binfo
, data
)
2439 struct vbase_info
*vi
= (struct vbase_info
*) data
;
2440 tree type
= BINFO_TYPE (binfo
);
2442 tree this_vbase_ptr
;
2444 /* Don't initialize the same base more than once. */
2445 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2447 /* We know that VI->DECL_PTR points to the complete object. So,
2448 finding a pointer to this subobject is easy. */
2449 this_vbase_ptr
= build (PLUS_EXPR
,
2450 build_pointer_type (type
),
2452 BINFO_OFFSET (binfo
));
2454 /* We're going to iterate through all the pointers to virtual
2455 base-classes. They come at the beginning of the class. */
2456 fields
= TYPE_FIELDS (type
);
2458 if (fields
== NULL_TREE
2459 || DECL_NAME (fields
) == NULL_TREE
2460 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2463 if (build_pointer_type (type
)
2464 != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2465 my_friendly_abort (125);
2467 while (fields
&& DECL_NAME (fields
) && VBASE_NAME_P (DECL_NAME (fields
)))
2469 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2470 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2475 vbase_type
= TREE_TYPE (TREE_TYPE (fields
));
2476 vbase_binfo
= binfo_for_vbase (vbase_type
, vi
->type
);
2477 init
= build (PLUS_EXPR
,
2478 build_pointer_type (vbase_type
),
2480 BINFO_OFFSET (vbase_binfo
));
2482 = tree_cons (vbase_binfo
,
2483 build_modify_expr (ref
, NOP_EXPR
, init
),
2485 fields
= TREE_CHAIN (fields
);
2491 /* Call CLEAR_BINFO_VTABLE_PATH_MARKED for BINFO. */
2494 dfs_vtable_path_unmark (binfo
, data
)
2496 void *data ATTRIBUTE_UNUSED
;
2498 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2503 init_vbase_pointers (type
, decl_ptr
)
2507 my_friendly_assert (!vbase_offsets_in_vtable_p (), 20000516);
2509 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2511 struct vbase_info vi
;
2512 int old_flag
= flag_this_is_variable
;
2513 tree binfo
= TYPE_BINFO (type
);
2514 flag_this_is_variable
= -2;
2516 /* Find all the virtual base classes, marking them for later
2519 vi
.decl_ptr
= decl_ptr
;
2520 vi
.inits
= NULL_TREE
;
2522 /* Build up a list of the initializers. */
2523 dfs_walk_real (binfo
,
2524 dfs_init_vbase_pointers
, 0,
2525 unmarked_vtable_pathp
,
2528 dfs_vtable_path_unmark
,
2529 marked_vtable_pathp
,
2532 flag_this_is_variable
= old_flag
;
2539 /* get the virtual context (the vbase that directly contains the
2540 DECL_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2541 or NULL_TREE if there is none.
2543 FNDECL must come from a virtual table from a virtual base to ensure
2544 that there is only one possible DECL_CONTEXT.
2546 We know that if there is more than one place (binfo) the fndecl that the
2547 declared, they all refer to the same binfo. See get_class_offset_1 for
2548 the check that ensures this. */
2551 virtual_context (fndecl
, t
, vbase
)
2552 tree fndecl
, t
, vbase
;
2555 if (get_base_distance (DECL_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2557 /* DECL_CONTEXT can be ambiguous in t. */
2558 if (get_base_distance (DECL_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2562 /* Not sure if checking path == vbase is necessary here, but just in
2564 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2565 return binfo_for_vbase (BINFO_TYPE (path
), t
);
2566 path
= BINFO_INHERITANCE_CHAIN (path
);
2569 /* This shouldn't happen, I don't want errors! */
2570 warning ("recoverable compiler error, fixups for virtual function");
2575 if (TREE_VIA_VIRTUAL (path
))
2576 return binfo_for_vbase (BINFO_TYPE (path
), t
);
2577 path
= BINFO_INHERITANCE_CHAIN (path
);
2582 /* Fixups upcast offsets for one vtable.
2583 Entries may stay within the VBASE given, or
2584 they may upcast into a direct base, or
2585 they may upcast into a different vbase.
2587 We only need to do fixups in case 2 and 3. In case 2, we add in
2588 the virtual base offset to effect an upcast, in case 3, we add in
2589 the virtual base offset to effect an upcast, then subtract out the
2590 offset for the other virtual base, to effect a downcast into it.
2592 This routine mirrors fixup_vtable_deltas in functionality, though
2593 this one is runtime based, and the other is compile time based.
2594 Conceivably that routine could be removed entirely, and all fixups
2597 VBASE_OFFSETS is an association list of virtual bases that contains
2598 offset information for the virtual bases, so the offsets are only
2602 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2604 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2611 while (BINFO_PRIMARY_MARKED_P (binfo
))
2613 binfo
= BINFO_INHERITANCE_CHAIN (binfo
);
2614 if (TREE_VIA_VIRTUAL (binfo
))
2618 delta
= purpose_member (vbase
, *vbase_offsets
);
2621 delta
= build (PLUS_EXPR
,
2622 build_pointer_type (BINFO_TYPE (vbase
)),
2624 BINFO_OFFSET (vbase
));
2625 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2626 delta
= save_expr (delta
);
2627 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2628 *vbase_offsets
= delta
;
2631 for (virtuals
= BINFO_VIRTUALS (binfo
),
2632 n
= first_vfun_index (BINFO_TYPE (binfo
));
2634 virtuals
= TREE_CHAIN (virtuals
), ++n
)
2636 tree current_fndecl
= TREE_VALUE (virtuals
);
2639 && current_fndecl
!= abort_fndecl
2640 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2642 /* This may in fact need a runtime fixup. */
2643 tree idx
= build_int_2 (n
, 0);
2644 tree vtbl
= BINFO_VTABLE (binfo
);
2645 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2646 tree aref
, ref
, naref
;
2647 tree old_delta
, new_delta
;
2650 if (nvtbl
== NULL_TREE
2651 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2653 /* Dup it if it isn't in local scope yet. */
2655 (VAR_DECL
, DECL_NAME (vtbl
),
2656 TYPE_MAIN_VARIANT (TREE_TYPE (vtbl
)));
2657 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2658 DECL_ALIGN (nvtbl
));
2659 TREE_READONLY (nvtbl
) = 0;
2660 DECL_ARTIFICIAL (nvtbl
) = 1;
2661 nvtbl
= pushdecl (nvtbl
);
2663 cp_finish_decl (nvtbl
, init
, NULL_TREE
,
2664 LOOKUP_ONLYCONVERTING
);
2666 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2667 because they wouldn't be useful; everything that wants to
2668 look at the vtable will look at the decl for the normal
2669 vtable. Setting DECL_CONTEXT also screws up
2670 decl_function_context. */
2672 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
2674 finish_expr_stmt (init
);
2675 /* Update the vtable pointers as necessary. */
2676 ref
= build_vfield_ref
2677 (build_indirect_ref (addr
, NULL_PTR
),
2678 DECL_CONTEXT (TYPE_VFIELD (BINFO_TYPE (binfo
))));
2680 (build_modify_expr (ref
, NOP_EXPR
, nvtbl
));
2682 assemble_external (vtbl
);
2683 aref
= build_array_ref (vtbl
, idx
);
2684 naref
= build_array_ref (nvtbl
, idx
);
2685 old_delta
= build_component_ref (aref
, delta_identifier
,
2687 new_delta
= build_component_ref (naref
, delta_identifier
,
2690 /* This is a upcast, so we have to add the offset for the
2692 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
2693 TREE_VALUE (delta
));
2696 /* If this is set, we need to subtract out the delta
2697 adjustments for the other virtual base that we
2699 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
2702 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
2703 vc_delta
= build (PLUS_EXPR
,
2704 build_pointer_type (BINFO_TYPE (vc
)),
2707 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
2709 vc_delta
= save_expr (vc_delta
);
2710 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
2713 vc_delta
= TREE_VALUE (vc_delta
);
2715 /* This is a downcast, so we have to subtract the offset
2716 for the virtual base. */
2717 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
);
2720 TREE_READONLY (new_delta
) = 0;
2721 TREE_TYPE (new_delta
) =
2722 cp_build_qualified_type (TREE_TYPE (new_delta
),
2723 CP_TYPE_QUALS (TREE_TYPE (new_delta
))
2724 & ~TYPE_QUAL_CONST
);
2725 finish_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
2731 /* Fixup upcast offsets for all direct vtables. Patterned after
2732 expand_direct_vtbls_init. */
2735 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
2736 tree real_binfo
, binfo
;
2737 int init_self
, can_elide
;
2738 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
2740 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
2741 tree binfos
= BINFO_BASETYPES (binfo
);
2742 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
2744 for (i
= 0; i
< n_baselinks
; i
++)
2746 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
2747 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2748 int is_not_base_vtable
2749 = !BINFO_PRIMARY_MARKED_P (real_base_binfo
);
2750 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
2751 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
2752 is_not_base_vtable
, can_elide
, addr
,
2753 orig_addr
, type
, vbase
, vbase_offsets
);
2756 /* Before turning this on, make sure it is correct. */
2757 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
2760 /* Should we use something besides CLASSTYPE_VFIELDS? */
2761 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
2763 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
2764 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
2765 type
, vbase_offsets
);
2769 /* Fixup all the virtual upcast offsets for TYPE. DECL_PTR is the
2770 address of the sub-object being initialized. */
2773 fixup_all_virtual_upcast_offsets (decl_ptr
)
2777 tree in_charge_node
;
2781 /* Only tweak the vtables if we're in charge. */
2782 in_charge_node
= current_in_charge_parm
;
2783 if (!in_charge_node
)
2784 /* There's no need for any fixups in this case. */
2786 in_charge_node
= build_binary_op (EQ_EXPR
,
2787 in_charge_node
, integer_zero_node
);
2788 if_stmt
= begin_if_stmt ();
2789 finish_if_stmt_cond (in_charge_node
, if_stmt
);
2791 /* Iterate through the virtual bases, fixing up the upcast offset
2793 type
= TREE_TYPE (TREE_TYPE (decl_ptr
));
2794 for (vbases
= CLASSTYPE_VBASECLASSES (type
);
2796 vbases
= TREE_CHAIN (vbases
))
2798 if (flag_vtable_thunks
)
2799 /* We don't have dynamic thunks yet! So for now, just fail
2808 vbase
= find_vbase_instance (TREE_PURPOSE (vbases
), type
);
2809 vbase_offsets
= NULL_TREE
;
2810 addr
= convert_pointer_to_vbase (TREE_PURPOSE (vbases
), decl_ptr
);
2811 fixup_virtual_upcast_offsets (vbase
,
2812 TYPE_BINFO (TREE_PURPOSE (vbases
)),
2813 1, 0, addr
, decl_ptr
,
2814 type
, vbase
, &vbase_offsets
);
2818 /* Close out the if-statement. */
2819 finish_then_clause (if_stmt
);
2823 /* get virtual base class types.
2824 This adds type to the vbase_types list in reverse dfs order.
2825 Ordering is very important, so don't change it. */
2828 dfs_get_vbase_types (binfo
, data
)
2832 tree type
= (tree
) data
;
2834 if (TREE_VIA_VIRTUAL (binfo
))
2835 CLASSTYPE_VBASECLASSES (type
)
2836 = tree_cons (BINFO_TYPE (binfo
),
2838 CLASSTYPE_VBASECLASSES (type
));
2839 SET_BINFO_MARKED (binfo
);
2843 /* Called via dfs_walk from mark_primary_bases. Builds the
2844 inheritance graph order list of BINFOs. */
2847 dfs_build_inheritance_graph_order (binfo
, data
)
2851 tree
*last_binfo
= (tree
*) data
;
2854 TREE_CHAIN (*last_binfo
) = binfo
;
2855 *last_binfo
= binfo
;
2856 SET_BINFO_MARKED (binfo
);
2860 /* Set CLASSTYPE_VBASECLASSES for TYPE. */
2863 get_vbase_types (type
)
2868 CLASSTYPE_VBASECLASSES (type
) = NULL_TREE
;
2869 dfs_walk (TYPE_BINFO (type
), dfs_get_vbase_types
, unmarkedp
, type
);
2870 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2871 reverse it so that we get normal dfs ordering. */
2872 CLASSTYPE_VBASECLASSES (type
) = nreverse (CLASSTYPE_VBASECLASSES (type
));
2873 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
, 0);
2874 /* Thread the BINFOs in inheritance-graph order. */
2876 dfs_walk_real (TYPE_BINFO (type
),
2877 dfs_build_inheritance_graph_order
,
2881 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
, NULL
);
2884 /* Called from find_vbase_instance via dfs_walk. */
2887 dfs_find_vbase_instance (binfo
, data
)
2891 tree base
= TREE_VALUE ((tree
) data
);
2893 if (BINFO_PRIMARY_MARKED_P (binfo
)
2894 && same_type_p (BINFO_TYPE (binfo
), base
))
2900 /* Find the real occurrence of the virtual BASE (a class type) in the
2901 hierarchy dominated by TYPE. */
2904 find_vbase_instance (base
, type
)
2910 instance
= binfo_for_vbase (base
, type
);
2911 if (!BINFO_VBASE_PRIMARY_P (instance
))
2914 return dfs_walk (TYPE_BINFO (type
),
2915 dfs_find_vbase_instance
,
2917 build_tree_list (type
, base
));
2921 /* Debug info for C++ classes can get very large; try to avoid
2922 emitting it everywhere.
2924 Note that this optimization wins even when the target supports
2925 BINCL (if only slightly), and reduces the amount of work for the
2929 maybe_suppress_debug_info (t
)
2932 /* We can't do the usual TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2933 does not support name references between translation units. It supports
2934 symbolic references between translation units, but only within a single
2935 executable or shared library.
2937 For DWARF 2, we handle TYPE_DECL_SUPPRESS_DEBUG by pretending
2938 that the type was never defined, so we only get the members we
2940 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== NO_DEBUG
)
2943 /* We might have set this earlier in cp_finish_decl. */
2944 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 0;
2946 /* If we already know how we're handling this class, handle debug info
2948 if (CLASSTYPE_INTERFACE_KNOWN (t
))
2950 if (CLASSTYPE_INTERFACE_ONLY (t
))
2951 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
2952 /* else don't set it. */
2954 /* If the class has a vtable, write out the debug info along with
2956 else if (TYPE_CONTAINS_VPTR_P (t
))
2957 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
2959 /* Otherwise, just emit the debug info normally. */
2962 /* Note that we want debugging information for a base class of a class
2963 whose vtable is being emitted. Normally, this would happen because
2964 calling the constructor for a derived class implies calling the
2965 constructors for all bases, which involve initializing the
2966 appropriate vptr with the vtable for the base class; but in the
2967 presence of optimization, this initialization may be optimized
2968 away, so we tell finish_vtable_vardecl that we want the debugging
2969 information anyway. */
2972 dfs_debug_mark (binfo
, data
)
2974 void *data ATTRIBUTE_UNUSED
;
2976 tree t
= BINFO_TYPE (binfo
);
2978 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2983 /* Returns BINFO if we haven't already noted that we want debugging
2984 info for this base class. */
2987 dfs_debug_unmarkedp (binfo
, data
)
2989 void *data ATTRIBUTE_UNUSED
;
2991 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
))
2992 ? binfo
: NULL_TREE
);
2995 /* Write out the debugging information for TYPE, whose vtable is being
2996 emitted. Also walk through our bases and note that we want to
2997 write out information for them. This avoids the problem of not
2998 writing any debug info for intermediate basetypes whose
2999 constructors, and thus the references to their vtables, and thus
3000 the vtables themselves, were optimized away. */
3003 note_debug_info_needed (type
)
3006 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)))
3008 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type
)) = 0;
3009 rest_of_type_compilation (type
, toplevel_bindings_p ());
3012 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
, 0);
3015 /* Subroutines of push_class_decls (). */
3017 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
3018 because it (or one of the intermediate bases) depends on template parms. */
3021 dependent_base_p (binfo
)
3024 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
3026 if (currently_open_class (TREE_TYPE (binfo
)))
3028 if (uses_template_parms (TREE_TYPE (binfo
)))
3035 setup_class_bindings (name
, type_binding_p
)
3039 tree type_binding
= NULL_TREE
;
3042 /* If we've already done the lookup for this declaration, we're
3044 if (IDENTIFIER_CLASS_VALUE (name
))
3047 /* First, deal with the type binding. */
3050 type_binding
= lookup_member (current_class_type
, name
,
3053 if (TREE_CODE (type_binding
) == TREE_LIST
3054 && TREE_TYPE (type_binding
) == error_mark_node
)
3055 /* NAME is ambiguous. */
3056 push_class_level_binding (name
, type_binding
);
3058 pushdecl_class_level (type_binding
);
3061 /* Now, do the value binding. */
3062 value_binding
= lookup_member (current_class_type
, name
,
3067 && (TREE_CODE (value_binding
) == TYPE_DECL
3068 || (TREE_CODE (value_binding
) == TREE_LIST
3069 && TREE_TYPE (value_binding
) == error_mark_node
3070 && (TREE_CODE (TREE_VALUE (value_binding
))
3072 /* We found a type-binding, even when looking for a non-type
3073 binding. This means that we already processed this binding
3075 my_friendly_assert (type_binding_p
, 19990401);
3076 else if (value_binding
)
3078 if (TREE_CODE (value_binding
) == TREE_LIST
3079 && TREE_TYPE (value_binding
) == error_mark_node
)
3080 /* NAME is ambiguous. */
3081 push_class_level_binding (name
, value_binding
);
3084 if (BASELINK_P (value_binding
))
3085 /* NAME is some overloaded functions. */
3086 value_binding
= TREE_VALUE (value_binding
);
3087 pushdecl_class_level (value_binding
);
3092 /* Push class-level declarations for any names appearing in BINFO that
3096 dfs_push_type_decls (binfo
, data
)
3098 void *data ATTRIBUTE_UNUSED
;
3103 type
= BINFO_TYPE (binfo
);
3104 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3105 if (DECL_NAME (fields
) && TREE_CODE (fields
) == TYPE_DECL
3106 && !(!same_type_p (type
, current_class_type
)
3107 && template_self_reference_p (type
, fields
)))
3108 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/1);
3110 /* We can't just use BINFO_MARKED because envelope_add_decl uses
3111 DERIVED_FROM_P, which calls get_base_distance. */
3112 SET_BINFO_PUSHDECLS_MARKED (binfo
);
3117 /* Push class-level declarations for any names appearing in BINFO that
3118 are not TYPE_DECLS. */
3121 dfs_push_decls (binfo
, data
)
3129 type
= BINFO_TYPE (binfo
);
3130 dep_base_p
= (processing_template_decl
&& type
!= current_class_type
3131 && dependent_base_p (binfo
));
3135 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3136 if (DECL_NAME (fields
)
3137 && TREE_CODE (fields
) != TYPE_DECL
3138 && TREE_CODE (fields
) != USING_DECL
)
3139 setup_class_bindings (DECL_NAME (fields
), /*type_binding_p=*/0);
3140 else if (TREE_CODE (fields
) == FIELD_DECL
3141 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
3142 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields
)), data
);
3144 method_vec
= (CLASS_TYPE_P (type
)
3145 ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
);
3151 /* Farm out constructors and destructors. */
3152 end
= TREE_VEC_END (method_vec
);
3154 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3155 *methods
&& methods
!= end
;
3157 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods
)),
3158 /*type_binding_p=*/0);
3162 CLEAR_BINFO_PUSHDECLS_MARKED (binfo
);
3167 /* When entering the scope of a class, we cache all of the
3168 fields that that class provides within its inheritance
3169 lattice. Where ambiguities result, we mark them
3170 with `error_mark_node' so that if they are encountered
3171 without explicit qualification, we can emit an error
3175 push_class_decls (type
)
3178 search_stack
= push_search_level (search_stack
, &search_obstack
);
3180 /* Enter type declarations and mark. */
3181 dfs_walk (TYPE_BINFO (type
), dfs_push_type_decls
, unmarked_pushdecls_p
, 0);
3183 /* Enter non-type declarations and unmark. */
3184 dfs_walk (TYPE_BINFO (type
), dfs_push_decls
, marked_pushdecls_p
, 0);
3187 /* Here's a subroutine we need because C lacks lambdas. */
3190 dfs_unuse_fields (binfo
, data
)
3192 void *data ATTRIBUTE_UNUSED
;
3194 tree type
= TREE_TYPE (binfo
);
3197 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3199 if (TREE_CODE (fields
) != FIELD_DECL
)
3202 TREE_USED (fields
) = 0;
3203 if (DECL_NAME (fields
) == NULL_TREE
3204 && ANON_AGGR_TYPE_P (TREE_TYPE (fields
)))
3205 unuse_fields (TREE_TYPE (fields
));
3215 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
, 0);
3221 /* We haven't pushed a search level when dealing with cached classes,
3222 so we'd better not try to pop it. */
3224 search_stack
= pop_search_level (search_stack
);
3228 print_search_statistics ()
3230 #ifdef GATHER_STATISTICS
3231 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3232 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3233 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3234 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3235 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3236 #else /* GATHER_STATISTICS */
3237 fprintf (stderr
, "no search statistics\n");
3238 #endif /* GATHER_STATISTICS */
3242 init_search_processing ()
3244 gcc_obstack_init (&search_obstack
);
3248 reinit_search_statistics ()
3250 #ifdef GATHER_STATISTICS
3251 n_fields_searched
= 0;
3252 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3253 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3254 n_calls_get_base_type
= 0;
3255 n_outer_fields_searched
= 0;
3256 n_contexts_saved
= 0;
3257 #endif /* GATHER_STATISTICS */
3261 add_conversions (binfo
, data
)
3266 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3267 tree
*conversions
= (tree
*) data
;
3269 /* Some builtin types have no method vector, not even an empty one. */
3273 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3275 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3278 if (!tmp
|| ! DECL_CONV_FN_P (OVL_CURRENT (tmp
)))
3281 name
= DECL_NAME (OVL_CURRENT (tmp
));
3283 /* Make sure we don't already have this conversion. */
3284 if (! IDENTIFIER_MARKED (name
))
3286 *conversions
= tree_cons (binfo
, tmp
, *conversions
);
3287 IDENTIFIER_MARKED (name
) = 1;
3293 /* Return a TREE_LIST containing all the non-hidden user-defined
3294 conversion functions for TYPE (and its base-classes). The
3295 TREE_VALUE of each node is a FUNCTION_DECL or an OVERLOAD
3296 containing the conversion functions. The TREE_PURPOSE is the BINFO
3297 from which the conversion functions in this node were selected. */
3300 lookup_conversions (type
)
3304 tree conversions
= NULL_TREE
;
3306 if (COMPLETE_TYPE_P (type
))
3307 bfs_walk (TYPE_BINFO (type
), add_conversions
, 0, &conversions
);
3309 for (t
= conversions
; t
; t
= TREE_CHAIN (t
))
3310 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t
)))) = 0;
3321 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3322 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3325 dfs_check_overlap (empty_binfo
, data
)
3329 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3331 for (binfo
= TYPE_BINFO (oi
->compare_type
);
3333 binfo
= BINFO_BASETYPE (binfo
, 0))
3335 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3337 oi
->found_overlap
= 1;
3340 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3347 /* Trivial function to stop base traversal when we find something. */
3350 dfs_no_overlap_yet (binfo
, data
)
3354 struct overlap_info
*oi
= (struct overlap_info
*) data
;
3355 return !oi
->found_overlap
? binfo
: NULL_TREE
;
3358 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3359 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3362 types_overlap_p (empty_type
, next_type
)
3363 tree empty_type
, next_type
;
3365 struct overlap_info oi
;
3367 if (! IS_AGGR_TYPE (next_type
))
3369 oi
.compare_type
= next_type
;
3370 oi
.found_overlap
= 0;
3371 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
,
3372 dfs_no_overlap_yet
, &oi
);
3373 return oi
.found_overlap
;
3376 /* Given a vtable VAR, determine which binfo it comes from.
3378 FIXME What about secondary vtables? */
3381 binfo_for_vtable (var
)
3384 tree binfo
= TYPE_BINFO (DECL_CONTEXT (var
));
3390 binfos
= BINFO_BASETYPES (binfo
);
3391 if (binfos
== NULL_TREE
)
3394 i
= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
3398 binfo
= TREE_VEC_ELT (binfos
, i
);
3404 /* Returns 1 iff BINFO is from a direct or indirect virtual base. */
3407 binfo_from_vbase (binfo
)
3410 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
3412 if (TREE_VIA_VIRTUAL (binfo
))
3418 /* Returns the BINFO (if any) for the virtual baseclass T of the class
3419 C from the CLASSTYPE_VBASECLASSES list. */
3422 binfo_for_vbase (basetype
, classtype
)
3428 binfo
= purpose_member (basetype
, CLASSTYPE_VBASECLASSES (classtype
));
3429 return binfo
? TREE_VALUE (binfo
) : NULL_TREE
;