1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 89, 92-96, 1997 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* High-level class interface. */
35 #define obstack_chunk_alloc xmalloc
36 #define obstack_chunk_free free
38 extern struct obstack
*current_obstack
;
39 extern tree abort_fndecl
;
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
;
79 static void clear_memoized_cache
PROTO((void));
80 static tree make_memoized_table_entry
PROTO((tree
, tree
, int));
81 static tree get_abstract_virtuals_1
PROTO((tree
, int, 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_1
PROTO((tree
, tree
));
87 static int lookup_fnfields_here
PROTO((tree
, tree
));
88 static int is_subobject_of_p
PROTO((tree
, tree
));
89 static int hides
PROTO((tree
, tree
));
90 static tree virtual_context
PROTO((tree
, tree
, tree
));
91 static tree get_template_base_recursive
92 PROTO((tree
, tree
, tree
, int));
93 static void dfs_walk
PROTO((tree
, void (*) (tree
), int (*) (tree
)));
94 static void dfs_check_overlap
PROTO((tree
));
95 static int dfs_no_overlap_yet
PROTO((tree
));
96 static void envelope_add_decl
PROTO((tree
, tree
, tree
*));
97 static int get_base_distance_recursive
98 PROTO((tree
, int, int, int, int *, tree
*, tree
, tree
*,
99 int, int *, int, int));
100 static void expand_upcast_fixups
101 PROTO((tree
, tree
, tree
, tree
, tree
, tree
, tree
*));
102 static void fixup_virtual_upcast_offsets
103 PROTO((tree
, tree
, int, int, tree
, tree
, tree
, tree
,
105 static int markedp
PROTO((tree
));
106 static int unmarkedp
PROTO((tree
));
108 static int numberedp
PROTO((tree
));
109 static int unnumberedp
PROTO((tree
));
111 static int marked_vtable_pathp
PROTO((tree
));
112 static int unmarked_vtable_pathp
PROTO((tree
));
113 static int marked_new_vtablep
PROTO((tree
));
114 static int unmarked_new_vtablep
PROTO((tree
));
115 static int dfs_debug_unmarkedp
PROTO((tree
));
117 static void dfs_number
PROTO((tree
));
118 static void dfs_unnumber
PROTO((tree
));
119 static void dfs_record_inheritance
PROTO((tree
));
121 static void dfs_debug_mark
PROTO((tree
));
122 static void dfs_find_vbases
PROTO((tree
));
123 static void dfs_clear_vbase_slots
PROTO((tree
));
124 static void dfs_unmark
PROTO((tree
));
125 static void dfs_init_vbase_pointers
PROTO((tree
));
126 static void dfs_get_vbase_types
PROTO((tree
));
127 static void dfs_pushdecls
PROTO((tree
));
128 static void dfs_compress_decls
PROTO((tree
));
129 static void dfs_unuse_fields
PROTO((tree
));
130 static void add_conversions
PROTO((tree
));
131 static tree get_virtuals_named_this
PROTO((tree
));
132 static tree get_virtual_destructor
PROTO((tree
, int));
133 static int tree_has_any_destructor_p
PROTO((tree
, int));
134 static struct search_level
*push_search_level
135 PROTO((struct stack_level
*, struct obstack
*));
136 static struct search_level
*pop_search_level
137 PROTO((struct stack_level
*));
138 static struct type_level
*push_type_level
139 PROTO((struct stack_level
*, struct obstack
*));
140 static struct type_level
*pop_type_level
141 PROTO((struct type_level
*));
142 static tree my_tree_cons
PROTO((tree
, tree
, tree
));
143 static tree my_build_string
PROTO((char *));
144 static struct memoized_entry
* my_new_memoized_entry
145 PROTO((struct memoized_entry
*));
146 static HOST_WIDE_INT breadth_first_search
147 PROTO((tree
, int (*) (tree
, int), int (*) (tree
, int)));
149 static tree vbase_types
;
150 static tree vbase_decl_ptr_intermediate
, vbase_decl_ptr
;
151 static tree vbase_init_result
;
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 /* Search memoization. */
181 struct stack_level base
;
183 /* First object allocated in obstack of entries. */
186 /* Number of types memoized in this context. */
189 /* Type being memoized; save this if we are saving
190 memoized contexts. */
194 /* Obstack used for memoizing member and member function lookup. */
196 static struct obstack type_obstack
, type_obstack_entries
;
197 static struct type_level
*type_stack
;
198 static tree _vptr_name
;
200 /* Make things that look like tree nodes, but allocate them
201 on type_obstack_entries. */
202 static int my_tree_node_counter
;
204 extern int flag_memoize_lookups
, flag_save_memoized_contexts
;
206 /* Variables for gathering statistics. */
207 static int my_memoized_entry_counter
;
208 static int memoized_fast_finds
[2], memoized_adds
[2], memoized_fast_rejects
[2];
209 static int memoized_fields_searched
[2];
210 #ifdef GATHER_STATISTICS
211 static int n_fields_searched
;
212 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
213 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
214 static int n_calls_get_base_type
;
215 static int n_outer_fields_searched
;
216 static int n_contexts_saved
;
217 #endif /* GATHER_STATISTICS */
219 /* Local variables to help save memoization contexts. */
220 static tree prev_type_memoized
;
221 static struct type_level
*prev_type_stack
;
223 /* This list is used by push_class_decls to know what decls need to
224 be pushed into class scope. */
225 static tree closed_envelopes
= NULL_TREE
;
227 /* Allocate a level of type memoization context. */
229 static struct type_level
*
230 push_type_level (stack
, obstack
)
231 struct stack_level
*stack
;
232 struct obstack
*obstack
;
234 struct type_level tem
;
236 tem
.base
.prev
= stack
;
238 obstack_finish (&type_obstack_entries
);
239 tem
.entries
= (char *) obstack_base (&type_obstack_entries
);
241 tem
.type
= NULL_TREE
;
243 return (struct type_level
*)push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
246 /* Discard a level of type memoization context. */
248 static struct type_level
*
249 pop_type_level (stack
)
250 struct type_level
*stack
;
252 obstack_free (&type_obstack_entries
, stack
->entries
);
253 return (struct type_level
*)pop_stack_level ((struct stack_level
*)stack
);
256 /* Make something that looks like a TREE_LIST, but
257 do it on the type_obstack_entries obstack. */
260 my_tree_cons (purpose
, value
, chain
)
261 tree purpose
, value
, chain
;
263 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_list
));
264 ++my_tree_node_counter
;
265 TREE_TYPE (p
) = NULL_TREE
;
266 /* The type of the last on the LHS of this statement must be a pointer
267 to the same type as the bitfields in struct tree_common. Otherwise
268 we may write beyond our intended area. */
269 ((unsigned *)p
)[3] = 0;
270 TREE_SET_CODE (p
, TREE_LIST
);
271 TREE_PURPOSE (p
) = purpose
;
272 TREE_VALUE (p
) = value
;
273 TREE_CHAIN (p
) = chain
;
278 my_build_string (str
)
281 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_string
));
282 ++my_tree_node_counter
;
285 TREE_SET_CODE (p
, STRING_CST
);
286 TREE_STRING_POINTER (p
) = str
;
287 TREE_STRING_LENGTH (p
) = strlen (str
);
291 /* Memoizing machinery to make searches for multiple inheritance
292 reasonably efficient. */
294 #define MEMOIZE_HASHSIZE 8
295 typedef struct memoized_entry
297 struct memoized_entry
*chain
;
299 tree data_members
[MEMOIZE_HASHSIZE
];
300 tree function_members
[MEMOIZE_HASHSIZE
];
303 #define MEMOIZED_CHAIN(ENTRY) (((ME)ENTRY)->chain)
304 #define MEMOIZED_UID(ENTRY) (((ME)ENTRY)->uid)
305 #define MEMOIZED_FIELDS(ENTRY,INDEX) (((ME)ENTRY)->data_members[INDEX])
306 #define MEMOIZED_FNFIELDS(ENTRY,INDEX) (((ME)ENTRY)->function_members[INDEX])
307 /* The following is probably a lousy hash function. */
308 #define MEMOIZED_HASH_FN(NODE) (((long)(NODE)>>4)&(MEMOIZE_HASHSIZE - 1))
310 static struct memoized_entry
*
311 my_new_memoized_entry (chain
)
312 struct memoized_entry
*chain
;
314 struct memoized_entry
*p
315 = (struct memoized_entry
*)obstack_alloc (&type_obstack_entries
,
316 sizeof (struct memoized_entry
));
317 bzero ((char *) p
, sizeof (struct memoized_entry
));
318 MEMOIZED_CHAIN (p
) = chain
;
319 MEMOIZED_UID (p
) = ++my_memoized_entry_counter
;
323 /* Clears the deferred pop from pop_memoized_context, if any. */
326 clear_memoized_cache ()
330 type_stack
= pop_type_level (prev_type_stack
);
331 prev_type_memoized
= 0;
336 /* Make an entry in the memoized table for type TYPE
337 that the entry for NAME is FIELD. */
340 make_memoized_table_entry (type
, name
, function_p
)
344 int idx
= MEMOIZED_HASH_FN (name
);
345 tree entry
, *prev_entry
;
347 /* Since we allocate from the type_obstack, we must pop any deferred
349 clear_memoized_cache ();
351 memoized_adds
[function_p
] += 1;
352 if (CLASSTYPE_MTABLE_ENTRY (type
) == 0)
354 obstack_ptr_grow (&type_obstack
, type
);
355 obstack_blank (&type_obstack
, sizeof (struct memoized_entry
*));
356 CLASSTYPE_MTABLE_ENTRY (type
) = (char *)my_new_memoized_entry ((struct memoized_entry
*)0);
358 if (type_stack
->len
* 2 >= type_stack
->base
.limit
)
359 my_friendly_abort (88);
362 prev_entry
= &MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
364 prev_entry
= &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
366 entry
= my_tree_cons (name
, NULL_TREE
, *prev_entry
);
369 /* Don't know the error message to give yet. */
370 TREE_TYPE (entry
) = error_mark_node
;
375 /* When a new function or class context is entered, we build
376 a table of types which have been searched for members.
377 The table is an array (obstack) of types. When a type is
378 entered into the obstack, its CLASSTYPE_MTABLE_ENTRY
379 field is set to point to a new record, of type struct memoized_entry.
381 A non-NULL TREE_TYPE of the entry contains an access control error message.
383 The slots for the data members are arrays of tree nodes.
384 These tree nodes are lists, with the TREE_PURPOSE
385 of this list the known member name, and the TREE_VALUE
386 as the FIELD_DECL for the member.
388 For member functions, the TREE_PURPOSE is again the
389 name of the member functions for that class,
390 and the TREE_VALUE of the list is a pairs
391 whose TREE_PURPOSE is a member functions of this name,
392 and whose TREE_VALUE is a list of known argument lists this
393 member function has been called with. The TREE_TYPE of the pair,
394 if non-NULL, is an error message to print. */
396 /* Tell search machinery that we are entering a new context, and
397 to update tables appropriately.
399 TYPE is the type of the context we are entering, which can
400 be NULL_TREE if we are not in a class's scope.
402 USE_OLD, if nonzero tries to use previous context. */
405 push_memoized_context (type
, use_old
)
414 if (use_old
&& prev_type_memoized
== type
)
416 #ifdef GATHER_STATISTICS
418 #endif /* GATHER_STATISTICS */
419 type_stack
= prev_type_stack
;
422 tem
= &type_stack
->base
.first
[0];
423 len
= type_stack
->len
;
425 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]) = (char *)tem
[len
*2+1];
428 /* Otherwise, need to pop old stack here. */
429 clear_memoized_cache ();
432 type_stack
= push_type_level ((struct stack_level
*)type_stack
,
434 type_stack
->type
= type
;
437 /* Tell search machinery that we have left a context.
438 We do not currently save these contexts for later use.
439 If we wanted to, we could not use pop_search_level, since
440 poping that level allows the data we have collected to
441 be clobbered; a stack of obstacks would be needed. */
444 pop_memoized_context (use_old
)
448 tree
*tem
= &type_stack
->base
.first
[0];
450 if (! flag_save_memoized_contexts
)
454 len
= type_stack
->len
;
456 tem
[len
*2+1] = (tree
)CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]);
458 /* If there was a deferred pop, we need to pop it now. */
459 clear_memoized_cache ();
461 prev_type_stack
= type_stack
;
462 prev_type_memoized
= type_stack
->type
;
465 if (flag_memoize_lookups
)
467 len
= type_stack
->len
;
469 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2])
470 = (char *)MEMOIZED_CHAIN (CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]));
473 type_stack
= pop_type_level (type_stack
);
475 type_stack
= (struct type_level
*)type_stack
->base
.prev
;
478 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
479 the same type as the type given in PARENT. To be optimal, we want
480 the first one that is found by going through the least number of
484 get_vbase_1 (parent
, binfo
, depth
)
490 tree rval
= NULL_TREE
;
492 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
500 binfos
= BINFO_BASETYPES (binfo
);
501 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
503 /* Process base types. */
504 for (i
= 0; i
< n_baselinks
; i
++)
506 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
512 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
521 get_vbase (parent
, binfo
)
525 unsigned int d
= (unsigned int)-1;
526 return get_vbase_1 (parent
, binfo
, &d
);
529 /* Convert EXPR to a virtual base class of type TYPE. We know that
530 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
531 the type of what expr points to has a virtual base of type TYPE. */
534 convert_pointer_to_vbase (type
, expr
)
538 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
539 return convert_pointer_to_real (vb
, expr
);
542 /* Check whether the type given in BINFO is derived from PARENT. If
543 it isn't, return 0. If it is, but the derivation is MI-ambiguous
544 AND protect != 0, emit an error message and return error_mark_node.
546 Otherwise, if TYPE is derived from PARENT, return the actual base
547 information, unless a one of the protection violations below
548 occurs, in which case emit an error message and return error_mark_node.
550 If PROTECT is 1, then check if access to a public field of PARENT
551 would be private. Also check for ambiguity. */
554 get_binfo (parent
, binfo
, protect
)
555 register tree parent
, binfo
;
558 tree type
= NULL_TREE
;
560 tree rval
= NULL_TREE
;
562 if (TREE_CODE (parent
) == TREE_VEC
)
563 parent
= BINFO_TYPE (parent
);
564 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
565 my_friendly_abort (89);
567 if (TREE_CODE (binfo
) == TREE_VEC
)
568 type
= BINFO_TYPE (binfo
);
569 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
572 my_friendly_abort (90);
574 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
578 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
580 return error_mark_node
;
582 else if (dist
== -2 && protect
)
584 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
586 return error_mark_node
;
592 /* This is the newer depth first get_base_distance routine. */
595 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
596 rval_private_ptr
, new_binfo_ptr
, parent
, path_ptr
,
597 protect
, via_virtual_ptr
, via_virtual
,
598 current_scope_in_chain
)
600 int depth
, is_private
, rval
;
601 int *rval_private_ptr
;
602 tree
*new_binfo_ptr
, parent
, *path_ptr
;
603 int protect
, *via_virtual_ptr
, via_virtual
;
604 int current_scope_in_chain
;
610 && !current_scope_in_chain
611 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
612 current_scope_in_chain
= 1;
614 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
619 *rval_private_ptr
= is_private
;
620 *new_binfo_ptr
= binfo
;
621 *via_virtual_ptr
= via_virtual
;
625 int same_object
= (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
626 BINFO_OFFSET (binfo
))
627 && *via_virtual_ptr
&& via_virtual
);
629 if (*via_virtual_ptr
&& via_virtual
==0)
631 *rval_private_ptr
= is_private
;
632 *new_binfo_ptr
= binfo
;
633 *via_virtual_ptr
= via_virtual
;
635 else if (same_object
)
637 if (*rval_private_ptr
&& ! is_private
)
639 *rval_private_ptr
= is_private
;
640 *new_binfo_ptr
= binfo
;
641 *via_virtual_ptr
= via_virtual
;
651 binfos
= BINFO_BASETYPES (binfo
);
652 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
655 /* Process base types. */
656 for (i
= 0; i
< n_baselinks
; i
++)
658 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
660 /* Find any specific instance of a virtual base, when searching with
662 if (BINFO_MARKED (base_binfo
) == 0 || TREE_CODE (parent
) == TREE_VEC
)
667 || (!TREE_VIA_PUBLIC (base_binfo
)
668 && !(TREE_VIA_PROTECTED (base_binfo
)
669 && current_scope_in_chain
)
670 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
671 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
674 /* When searching for a non-virtual, we cannot mark
675 virtually found binfos. */
677 SET_BINFO_MARKED (base_binfo
);
679 #define WATCH_VALUES(rval, via_private) (rval == -1 ? 3 : via_private)
681 was
= WATCH_VALUES (rval
, *via_virtual_ptr
);
682 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
683 rval
, rval_private_ptr
,
684 new_binfo_ptr
, parent
, path_ptr
,
685 protect
, via_virtual_ptr
,
687 current_scope_in_chain
);
688 /* watch for updates; only update if path is good. */
689 if (path_ptr
&& WATCH_VALUES (rval
, *via_virtual_ptr
) != was
)
690 BINFO_INHERITANCE_CHAIN (base_binfo
) = binfo
;
691 if (rval
== -2 && *via_virtual_ptr
== 0)
702 /* Return the number of levels between type PARENT and the type given
703 in BINFO, following the leftmost path to PARENT not found along a
704 virtual path, if there are no real PARENTs (all come from virtual
705 base classes), then follow the leftmost path to PARENT.
707 Return -1 if TYPE is not derived from PARENT.
708 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
710 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
712 If PATH_PTR is non-NULL, then also build the list of types
713 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
716 PARENT can also be a binfo, in which case that exact parent is found
717 and no other. convert_pointer_to_real uses this functionality.
719 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
722 get_base_distance (parent
, binfo
, protect
, path_ptr
)
723 register tree parent
, binfo
;
728 int rval_private
= 0;
729 tree type
= NULL_TREE
;
730 tree new_binfo
= NULL_TREE
;
732 int watch_access
= protect
;
734 /* Should we be completing types here? */
735 if (TREE_CODE (parent
) != TREE_VEC
)
736 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
738 complete_type (TREE_TYPE (parent
));
740 if (TREE_CODE (binfo
) == TREE_VEC
)
741 type
= BINFO_TYPE (binfo
);
742 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
744 type
= complete_type (binfo
);
745 binfo
= TYPE_BINFO (type
);
748 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
751 my_friendly_abort (92);
753 if (parent
== type
|| parent
== binfo
)
755 /* If the distance is 0, then we don't really need
756 a path pointer, but we shouldn't let garbage go back. */
765 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
766 &rval_private
, &new_binfo
, parent
,
767 path_ptr
, watch_access
, &via_virtual
, 0,
770 dfs_walk (binfo
, dfs_unmark
, markedp
);
772 /* Access restrictions don't count if we found an ambiguous basetype. */
773 if (rval
== -2 && protect
>= 0)
776 if (rval
&& protect
&& rval_private
)
779 /* find real virtual base classes. */
780 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
781 && parent
== binfo_member (BINFO_TYPE (parent
),
782 CLASSTYPE_VBASECLASSES (type
)))
784 BINFO_INHERITANCE_CHAIN (parent
) = binfo
;
790 *path_ptr
= new_binfo
;
794 /* Search for a member with name NAME in a multiple inheritance lattice
795 specified by TYPE. If it does not exist, return NULL_TREE.
796 If the member is ambiguously referenced, return `error_mark_node'.
797 Otherwise, return the FIELD_DECL. */
799 /* Do a 1-level search for NAME as a member of TYPE. The caller must
800 figure out whether it can access this field. (Since it is only one
801 level, this is reasonable.) */
804 lookup_field_1 (type
, name
)
809 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
810 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
811 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
812 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
813 the code often worked even when we treated the index as a list
817 field
= TYPE_FIELDS (type
);
819 #ifdef GATHER_STATISTICS
820 n_calls_lookup_field_1
++;
821 #endif /* GATHER_STATISTICS */
824 #ifdef GATHER_STATISTICS
826 #endif /* GATHER_STATISTICS */
827 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
828 if (DECL_NAME (field
) == NULL_TREE
829 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
831 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
835 if (DECL_NAME (field
) == name
)
837 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
838 && DECL_ASSEMBLER_NAME (field
) != NULL
)
839 GNU_xref_ref(current_function_decl
,
840 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
843 field
= TREE_CHAIN (field
);
846 if (name
== _vptr_name
)
848 /* Give the user what s/he thinks s/he wants. */
849 if (TYPE_VIRTUAL_P (type
))
850 return CLASSTYPE_VFIELD (type
);
855 /* There are a number of cases we need to be aware of here:
856 current_class_type current_function_decl
863 Those last two make life interesting. If we're in a function which is
864 itself inside a class, we need decls to go into the fn's decls (our
865 second case below). But if we're in a class and the class itself is
866 inside a function, we need decls to go into the decls for the class. To
867 achieve this last goal, we must see if, when both current_class_ptr and
868 current_function_decl are set, the class was declared inside that
869 function. If so, we know to put the decls into the class's scope. */
874 if (current_function_decl
== NULL_TREE
)
875 return current_class_type
;
876 if (current_class_type
== NULL_TREE
)
877 return current_function_decl
;
878 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
879 return current_function_decl
;
881 return current_class_type
;
884 /* Compute the access of FIELD. This is done by computing
885 the access available to each type in BASETYPES (which comes
886 as a list of [via_public/basetype] in reverse order, namely base
887 class before derived class). The first one which defines a
888 access defines the access for the field. Otherwise, the
889 access of the field is that which occurs normally.
891 Uses global variables CURRENT_CLASS_TYPE and
892 CURRENT_FUNCTION_DECL to use friend relationships
895 This will be static when lookup_fnfield comes into this file.
897 access_public_node means that the field can be accessed by the current lexical
900 access_protected_node means that the field cannot be accessed by the current
901 lexical scope because it is protected.
903 access_private_node means that the field cannot be accessed by the current
904 lexical scope because it is private. */
907 #define PUBLIC_RETURN return (DECL_PUBLIC (field) = 1), access_public_node
908 #define PROTECTED_RETURN return (DECL_PROTECTED (field) = 1), access_protected_node
909 #define PRIVATE_RETURN return (DECL_PRIVATE (field) = 1), access_private_node
911 #define PUBLIC_RETURN return access_public_node
912 #define PROTECTED_RETURN return access_protected_node
913 #define PRIVATE_RETURN return access_private_node
917 /* Disabled with DECL_PUBLIC &c. */
918 static tree previous_scope
= NULL_TREE
;
922 compute_access (basetype_path
, field
)
923 tree basetype_path
, field
;
928 int protected_ok
, via_protected
;
929 extern int flag_access_control
;
931 /* Replaces static decl above. */
935 = ((TREE_CODE (field
) == FUNCTION_DECL
&& DECL_STATIC_FUNCTION_P (field
))
936 || (TREE_CODE (field
) != FUNCTION_DECL
&& TREE_STATIC (field
)));
938 if (! flag_access_control
)
939 return access_public_node
;
941 /* The field lives in the current class. */
942 if (BINFO_TYPE (basetype_path
) == current_class_type
)
943 return access_public_node
;
946 /* Disabled until pushing function scope clears these out. If ever. */
947 /* Make these special cases fast. */
948 if (current_scope () == previous_scope
)
950 if (DECL_PUBLIC (field
))
951 return access_public_node
;
952 if (DECL_PROTECTED (field
))
953 return access_protected_node
;
954 if (DECL_PRIVATE (field
))
955 return access_private_node
;
959 /* We don't currently support access control on nested types. */
960 if (TREE_CODE (field
) == TYPE_DECL
)
961 return access_public_node
;
963 previous_scope
= current_scope ();
965 context
= DECL_CLASS_CONTEXT (field
);
966 if (context
== NULL_TREE
)
967 context
= DECL_CONTEXT (field
);
969 /* Fields coming from nested anonymous unions have their DECL_CLASS_CONTEXT
970 slot set to the union type rather than the record type containing
971 the anonymous union. */
972 if (context
&& TREE_CODE (context
) == UNION_TYPE
973 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context
)))
974 context
= TYPE_CONTEXT (context
);
976 /* Virtual function tables are never private. But we should know that
977 we are looking for this, and not even try to hide it. */
978 if (DECL_NAME (field
) && VFIELD_NAME_P (DECL_NAME (field
)) == 1)
981 /* Member found immediately within object. */
982 if (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
)
984 /* Are we (or an enclosing scope) friends with the class that has
986 if (is_friend (context
, previous_scope
))
989 /* If it's private, it's private, you letch. */
990 if (TREE_PRIVATE (field
))
993 /* ARM $11.5. Member functions of a derived class can access the
994 non-static protected members of a base class only through a
995 pointer to the derived class, a reference to it, or an object
996 of it. Also any subsequently derived classes also have
998 else if (TREE_PROTECTED (field
))
1000 if (current_class_type
1001 && (static_mem
|| DECL_CONSTRUCTOR_P (field
))
1002 && ACCESSIBLY_DERIVED_FROM_P (context
, current_class_type
))
1011 /* must reverse more than one element */
1012 basetype_path
= reverse_path (basetype_path
);
1013 types
= basetype_path
;
1015 access
= access_default_node
;
1016 protected_ok
= static_mem
&& current_class_type
1017 && ACCESSIBLY_DERIVED_FROM_P (BINFO_TYPE (types
), current_class_type
);
1023 tree type
= BINFO_TYPE (binfo
);
1026 /* Friends of a class can see protected members of its bases.
1027 Note that classes are their own friends. */
1028 if (is_friend (type
, previous_scope
))
1034 member
= purpose_member (type
, DECL_ACCESS (field
));
1037 access
= TREE_VALUE (member
);
1041 types
= BINFO_INHERITANCE_CHAIN (types
);
1043 /* If the next type was VIA_PROTECTED, then fields of all remaining
1044 classes past that one are *at least* protected. */
1047 if (TREE_VIA_PROTECTED (types
))
1049 else if (! TREE_VIA_PUBLIC (types
) && ! private_ok
)
1051 access
= access_private_node
;
1058 reverse_path (basetype_path
);
1060 /* No special visibilities apply. Use normal rules. */
1062 if (access
== access_default_node
)
1064 if (is_friend (context
, previous_scope
))
1065 access
= access_public_node
;
1066 else if (TREE_PRIVATE (field
))
1067 access
= access_private_node
;
1068 else if (TREE_PROTECTED (field
))
1069 access
= access_protected_node
;
1071 access
= access_public_node
;
1074 if (access
== access_public_node
&& via_protected
)
1075 access
= access_protected_node
;
1077 if (access
== access_protected_node
&& protected_ok
)
1078 access
= access_public_node
;
1081 if (access
== access_public_node
)
1082 DECL_PUBLIC (field
) = 1;
1083 else if (access
== access_protected_node
)
1084 DECL_PROTECTED (field
) = 1;
1085 else if (access
== access_private_node
)
1086 DECL_PRIVATE (field
) = 1;
1087 else my_friendly_abort (96);
1092 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1093 found as a base class and sub-object of the object denoted by
1094 BINFO. This routine relies upon binfos not being shared, except
1095 for binfos for virtual bases. */
1098 is_subobject_of_p (parent
, binfo
)
1101 tree binfos
= BINFO_BASETYPES (binfo
);
1102 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1104 if (parent
== binfo
)
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 (TREE_VIA_VIRTUAL (base_binfo
))
1112 base_binfo
= TYPE_BINFO (BINFO_TYPE (base_binfo
));
1113 if (is_subobject_of_p (parent
, base_binfo
))
1119 /* See if a one FIELD_DECL hides another. This routine is meant to
1120 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1121 binfos given are the binfos corresponding to the particular places
1122 the FIELD_DECLs are found. This routine relies upon binfos not
1123 being shared, except for virtual bases. */
1126 hides (hider_binfo
, hidee_binfo
)
1127 tree hider_binfo
, hidee_binfo
;
1129 /* hider hides hidee, if hider has hidee as a base class and
1130 the instance of hidee is a sub-object of hider. The first
1131 part is always true is the second part is true.
1133 When hider and hidee are the same (two ways to get to the exact
1134 same member) we consider either one as hiding the other. */
1135 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
1138 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1139 function was declared inside the class given by TYPE. It really should
1140 only return functions that match the given TYPE. */
1143 lookup_fnfields_here (type
, name
)
1146 int idx
= lookup_fnfields_1 (type
, name
);
1149 /* ctors and dtors are always only in the right class. */
1152 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1155 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (fndecls
))
1156 == TYPE_MAIN_VARIANT (type
))
1158 fndecls
= TREE_CHAIN (fndecls
);
1163 /* Look for a field named NAME in an inheritance lattice dominated by
1164 XBASETYPE. PROTECT is zero if we can avoid computing access
1165 information, otherwise it is 1. WANT_TYPE is 1 when we should only
1166 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
1168 It was not clear what should happen if WANT_TYPE is set, and an
1169 ambiguity is found. At least one use (lookup_name) to not see
1173 lookup_field (xbasetype
, name
, protect
, want_type
)
1174 register tree xbasetype
, name
;
1175 int protect
, want_type
;
1177 int head
= 0, tail
= 0;
1178 tree rval
, rval_binfo
= NULL_TREE
, rval_binfo_h
= NULL_TREE
;
1179 tree type
= NULL_TREE
, basetype_chain
, basetype_path
= NULL_TREE
;
1180 tree this_v
= access_default_node
;
1181 tree entry
, binfo
, binfo_h
;
1182 tree own_access
= access_default_node
;
1183 int vbase_name_p
= VBASE_NAME_P (name
);
1185 /* rval_binfo is the binfo associated with the found member, note,
1186 this can be set with useful information, even when rval is not
1187 set, because it must deal with ALL members, not just non-function
1188 members. It is used for ambiguity checking and the hidden
1189 checks. Whereas rval is only set if a proper (not hidden)
1190 non-function member is found. */
1192 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1193 hiding checks, as virtual base classes may not be shared. The strategy
1194 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1195 virtual base classes, as we cross virtual base class lines. This way
1196 we know that binfo of a virtual base class will always == itself when
1197 found along any line. (mrs) */
1201 /* Set this to nonzero if we don't know how to compute
1202 accurate error messages for access control. */
1203 int idx
= MEMOIZED_HASH_FN (name
);
1206 /* We cannot search for constructor/destructor names like this. */
1207 /* This can't go here, but where should it go? */
1208 /* If we are looking for a constructor in a templated type, use the
1209 unspecialized name, as that is how we store it. */
1210 if (IDENTIFIER_TEMPLATE (name
))
1211 name
= constructor_name (name
);
1214 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1215 && IDENTIFIER_CLASS_VALUE (name
))
1217 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1218 if (TREE_CODE (field
) != FUNCTION_DECL
1219 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1223 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1225 type
= BINFO_TYPE (xbasetype
);
1226 basetype_path
= xbasetype
;
1228 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1231 basetype_path
= TYPE_BINFO (type
);
1232 BINFO_VIA_PUBLIC (basetype_path
) = 1;
1233 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1236 my_friendly_abort (97);
1238 complete_type (type
);
1240 if (CLASSTYPE_MTABLE_ENTRY (type
))
1242 tree tem
= MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
1244 while (tem
&& TREE_PURPOSE (tem
) != name
)
1246 memoized_fields_searched
[0]++;
1247 tem
= TREE_CHAIN (tem
);
1251 if (protect
&& TREE_TYPE (tem
))
1253 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1254 IDENTIFIER_POINTER (name
),
1255 TYPE_NAME_STRING (DECL_FIELD_CONTEXT (TREE_VALUE (tem
))));
1256 return error_mark_node
;
1258 if (TREE_VALUE (tem
) == NULL_TREE
)
1259 memoized_fast_rejects
[0] += 1;
1261 memoized_fast_finds
[0] += 1;
1262 return TREE_VALUE (tem
);
1266 #ifdef GATHER_STATISTICS
1267 n_calls_lookup_field
++;
1268 #endif /* GATHER_STATISTICS */
1269 if (protect
&& flag_memoize_lookups
&& ! global_bindings_p ())
1270 entry
= make_memoized_table_entry (type
, name
, 0);
1274 rval
= lookup_field_1 (type
, name
);
1276 if (rval
|| lookup_fnfields_here (type
, name
) >= 0)
1279 TREE_VALUE (entry
) = rval
;
1285 if (TREE_CODE (rval
) != TYPE_DECL
)
1287 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
1289 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
1294 if (TREE_CODE (rval
) == TYPE_DECL
1295 && lookup_fnfields_here (type
, name
) >= 0)
1300 if (protect
&& rval
)
1302 if (TREE_PRIVATE (rval
) | TREE_PROTECTED (rval
))
1303 this_v
= compute_access (basetype_path
, rval
);
1304 if (TREE_CODE (rval
) == CONST_DECL
)
1306 if (this_v
== access_private_node
)
1307 errstr
= "enum `%D' is a private value of class `%T'";
1308 else if (this_v
== access_protected_node
)
1309 errstr
= "enum `%D' is a protected value of class `%T'";
1313 if (this_v
== access_private_node
)
1314 errstr
= "member `%D' is a private member of class `%T'";
1315 else if (this_v
== access_protected_node
)
1316 errstr
= "member `%D' is a protected member of class `%T'";
1320 rval_binfo
= basetype_path
;
1324 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
1325 TREE_VIA_PUBLIC (basetype_chain
) = TREE_VIA_PUBLIC (basetype_path
);
1326 TREE_VIA_PROTECTED (basetype_chain
) = TREE_VIA_PROTECTED (basetype_path
);
1327 TREE_VIA_VIRTUAL (basetype_chain
) = TREE_VIA_VIRTUAL (basetype_path
);
1329 /* The ambiguity check relies upon breadth first searching. */
1331 search_stack
= push_search_level (search_stack
, &search_obstack
);
1332 binfo
= basetype_path
;
1337 tree binfos
= BINFO_BASETYPES (binfo
);
1338 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1341 /* Process and/or queue base types. */
1342 for (i
= 0; i
< n_baselinks
; i
++)
1344 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1345 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1349 SET_BINFO_FIELDS_MARKED (base_binfo
);
1350 btypes
= my_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1351 TREE_VIA_PUBLIC (btypes
) = TREE_VIA_PUBLIC (base_binfo
);
1352 TREE_VIA_PROTECTED (btypes
) = TREE_VIA_PROTECTED (base_binfo
);
1353 TREE_VIA_VIRTUAL (btypes
) = TREE_VIA_VIRTUAL (base_binfo
);
1354 if (TREE_VIA_VIRTUAL (base_binfo
))
1355 btypes
= my_tree_cons (NULL_TREE
,
1356 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1359 btypes
= my_tree_cons (NULL_TREE
,
1360 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1362 obstack_ptr_grow (&search_obstack
, btypes
);
1364 if (tail
>= search_stack
->limit
)
1365 my_friendly_abort (98);
1369 /* Process head of queue, if one exists. */
1373 basetype_chain
= search_stack
->first
[head
++];
1374 binfo_h
= TREE_VALUE (basetype_chain
);
1375 basetype_chain
= TREE_CHAIN (basetype_chain
);
1376 basetype_path
= TREE_VALUE (basetype_chain
);
1377 if (TREE_CHAIN (basetype_chain
))
1378 BINFO_INHERITANCE_CHAIN (basetype_path
) = TREE_VALUE (TREE_CHAIN (basetype_chain
));
1380 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1382 binfo
= basetype_path
;
1383 type
= BINFO_TYPE (binfo
);
1385 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1386 and we do find NAME in TYPE, verify that such a second
1387 sighting is in fact valid. */
1389 nval
= lookup_field_1 (type
, name
);
1391 if (nval
|| lookup_fnfields_here (type
, name
)>=0)
1393 if (nval
&& nval
== rval
&& SHARED_MEMBER_P (nval
))
1395 /* This is ok, the member found is the same [class.ambig] */
1397 else if (rval_binfo
&& hides (rval_binfo_h
, binfo_h
))
1399 /* This is ok, the member found is in rval_binfo, not
1402 else if (rval_binfo
==NULL_TREE
|| hides (binfo_h
, rval_binfo_h
))
1404 /* This is ok, the member found is here (binfo), not in
1409 if (entry
|| protect
)
1410 this_v
= compute_access (basetype_path
, rval
);
1411 /* These may look ambiguous, but they really are not. */
1417 /* Undo finding it before, as something else hides it. */
1421 rval_binfo_h
= binfo_h
;
1425 /* This is ambiguous. */
1426 errstr
= "request for member `%D' is ambiguous";
1433 tree
*tp
= search_stack
->first
;
1434 tree
*search_tail
= tp
+ tail
;
1437 TREE_VALUE (entry
) = rval
;
1441 type
= BINFO_TYPE (rval_binfo
);
1447 if (TREE_CODE (rval
) != TYPE_DECL
)
1449 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
1451 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
1456 if (TREE_CODE (rval
) == TYPE_DECL
1457 && lookup_fnfields_here (type
, name
) >= 0)
1463 if (rval
== NULL_TREE
)
1466 /* If this FIELD_DECL defines its own access level, deal with that. */
1467 if (rval
&& errstr
== 0
1468 && ((protect
&1) || entry
)
1469 && DECL_LANG_SPECIFIC (rval
)
1470 && DECL_ACCESS (rval
))
1472 while (tp
< search_tail
)
1474 /* If is possible for one of the derived types on the path to
1475 have defined special access for this field. Look for such
1476 declarations and report an error if a conflict is found. */
1477 tree new_v
= NULL_TREE
;
1479 if (this_v
!= access_default_node
)
1480 new_v
= compute_access (TREE_VALUE (TREE_CHAIN (*tp
)), rval
);
1481 if (this_v
!= access_default_node
&& new_v
!= this_v
)
1483 errstr
= "conflicting access to member `%D'";
1484 this_v
= access_default_node
;
1487 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1493 while (tp
< search_tail
)
1495 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1500 search_stack
= pop_search_level (search_stack
);
1504 if (own_access
== access_private_node
)
1505 errstr
= "member `%D' declared private";
1506 else if (own_access
== access_protected_node
)
1507 errstr
= "member `%D' declared protected";
1508 else if (this_v
== access_private_node
)
1509 errstr
= TREE_PRIVATE (rval
)
1510 ? "member `%D' is private"
1511 : "member `%D' is from private base class";
1512 else if (this_v
== access_protected_node
)
1513 errstr
= TREE_PROTECTED (rval
)
1514 ? "member `%D' is protected"
1515 : "member `%D' is from protected base class";
1523 tree error_string
= my_build_string (errstr
);
1524 /* Save error message with entry. */
1525 TREE_TYPE (entry
) = error_string
;
1529 /* Mark entry as having no error string. */
1530 TREE_TYPE (entry
) = NULL_TREE
;
1536 /* If we are not interested in ambiguities, don't report them,
1537 just return NULL_TREE. */
1542 if (errstr
&& protect
)
1544 cp_error (errstr
, name
, type
);
1545 rval
= error_mark_node
;
1548 /* Do implicit typename stuff. */
1549 if (rval
&& TREE_CODE (rval
) == TYPE_DECL
1550 && ! DECL_ARTIFICIAL (rval
)
1551 && processing_template_decl
1552 && BINFO_TYPE (rval_binfo
) != current_class_type
1553 && uses_template_parms (type
))
1556 for (; ; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
1557 if (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
1558 || (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
))
1559 == current_class_type
))
1562 entry
= make_typename_type (BINFO_TYPE (binfo
), name
);
1563 TREE_TYPE (entry
) = TREE_TYPE (rval
);
1564 rval
= TYPE_MAIN_DECL (entry
);
1570 /* Try to find NAME inside a nested class. */
1573 lookup_nested_field (name
, complain
)
1579 tree id
= NULL_TREE
;
1580 if (TREE_CHAIN (current_class_type
))
1582 /* Climb our way up the nested ladder, seeing if we're trying to
1583 modify a field in an enclosing class. If so, we should only
1584 be able to modify if it's static. */
1585 for (t
= TREE_CHAIN (current_class_type
);
1586 t
&& DECL_CONTEXT (t
);
1587 t
= TREE_CHAIN (DECL_CONTEXT (t
)))
1589 if (TREE_CODE (DECL_CONTEXT (t
)) != RECORD_TYPE
)
1592 /* N.B.: lookup_field will do the access checking for us */
1593 id
= lookup_field (DECL_CONTEXT (t
), name
, complain
, 0);
1594 if (id
== error_mark_node
)
1600 if (id
!= NULL_TREE
)
1602 if (TREE_CODE (id
) == FIELD_DECL
1603 && ! TREE_STATIC (id
)
1604 && TREE_TYPE (id
) != error_mark_node
)
1608 /* At parse time, we don't want to give this error, since
1609 we won't have enough state to make this kind of
1610 decision properly. But there are times (e.g., with
1611 enums in nested classes) when we do need to call
1612 this fn at parse time. So, in those cases, we pass
1613 complain as a 0 and just return a NULL_TREE. */
1614 cp_error ("assignment to non-static member `%D' of enclosing class `%T'",
1615 id
, DECL_CONTEXT (t
));
1616 /* Mark this for do_identifier(). It would otherwise
1617 claim that the variable was undeclared. */
1618 TREE_TYPE (id
) = error_mark_node
;
1634 /* TYPE is a class type. Return the index of the fields within
1635 the method vector with name NAME, or -1 is no such field exists. */
1638 lookup_fnfields_1 (type
, name
)
1641 register tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1643 if (method_vec
!= 0)
1645 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1646 register tree
*end
= TREE_VEC_END (method_vec
);
1648 #ifdef GATHER_STATISTICS
1649 n_calls_lookup_fnfields_1
++;
1650 #endif /* GATHER_STATISTICS */
1652 /* Constructors are first... */
1653 if (*methods
&& name
== ctor_identifier
)
1656 /* and destructors are second. */
1657 if (*++methods
&& name
== dtor_identifier
)
1660 while (++methods
!= end
)
1662 #ifdef GATHER_STATISTICS
1663 n_outer_fields_searched
++;
1664 #endif /* GATHER_STATISTICS */
1665 if (DECL_NAME (*methods
) == name
)
1669 /* If we didn't find it, it might have been a template
1670 conversion operator. (Note that we don't look for this case
1671 above so that we will always find specializations first.) */
1673 && IDENTIFIER_TYPENAME_P (name
))
1675 methods
= &TREE_VEC_ELT (method_vec
, 0) + 1;
1677 while (++methods
!= end
)
1679 if (TREE_CODE (*methods
) == TEMPLATE_DECL
1680 && IDENTIFIER_TYPENAME_P (DECL_NAME (*methods
)))
1686 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1692 /* Starting from BASETYPE, return a TREE_BASELINK-like object
1693 which gives the following information (in a list):
1695 TREE_TYPE: list of basetypes needed to get to...
1696 TREE_VALUE: list of all functions in a given type
1697 which have name NAME.
1699 No access information is computed by this function,
1700 other then to adorn the list of basetypes with
1703 If there are two ways to find a name (two members), if COMPLAIN is
1704 non-zero, then error_mark_node is returned, and an error message is
1705 printed, otherwise, just an error_mark_node is returned.
1707 As a special case, is COMPLAIN is -1, we don't complain, and we
1708 don't return error_mark_node, but rather the complete list of
1709 virtuals. This is used by get_virtuals_named_this. */
1712 lookup_fnfields (basetype_path
, name
, complain
)
1713 tree basetype_path
, name
;
1716 int head
= 0, tail
= 0;
1717 tree type
, rval
, rval_binfo
= NULL_TREE
, rvals
= NULL_TREE
;
1718 tree rval_binfo_h
= NULL_TREE
, entry
, binfo
, basetype_chain
, binfo_h
;
1721 /* rval_binfo is the binfo associated with the found member, note,
1722 this can be set with useful information, even when rval is not
1723 set, because it must deal with ALL members, not just function
1724 members. It is used for ambiguity checking and the hidden
1725 checks. Whereas rval is only set if a proper (not hidden)
1726 function member is found. */
1728 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1729 hiding checks, as virtual base classes may not be shared. The strategy
1730 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1731 virtual base classes, as we cross virtual base class lines. This way
1732 we know that binfo of a virtual base class will always == itself when
1733 found along any line. (mrs) */
1735 /* For now, don't try this. */
1736 int protect
= complain
;
1740 /* Set this to nonzero if we don't know how to compute
1741 accurate error messages for access control. */
1742 int idx
= MEMOIZED_HASH_FN (name
);
1747 protect
= complain
= 0;
1751 /* We cannot search for constructor/destructor names like this. */
1752 /* This can't go here, but where should it go? */
1753 /* If we are looking for a constructor in a templated type, use the
1754 unspecialized name, as that is how we store it. */
1755 if (IDENTIFIER_TEMPLATE (name
))
1756 name
= constructor_name (name
);
1759 binfo
= basetype_path
;
1761 type
= complete_type (BINFO_TYPE (basetype_path
));
1763 /* The memoization code is in need of maintenance. */
1764 if (!find_all
&& CLASSTYPE_MTABLE_ENTRY (type
))
1766 tree tem
= MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
1768 while (tem
&& TREE_PURPOSE (tem
) != name
)
1770 memoized_fields_searched
[1]++;
1771 tem
= TREE_CHAIN (tem
);
1775 if (protect
&& TREE_TYPE (tem
))
1777 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1778 IDENTIFIER_POINTER (name
),
1779 TYPE_NAME_STRING (DECL_CLASS_CONTEXT (TREE_VALUE (TREE_VALUE (tem
)))));
1780 return error_mark_node
;
1782 if (TREE_VALUE (tem
) == NULL_TREE
)
1784 memoized_fast_rejects
[1] += 1;
1789 /* Want to return this, but we must make sure
1790 that access information is consistent. */
1791 tree baselink
= TREE_VALUE (tem
);
1792 tree memoized_basetypes
= TREE_PURPOSE (baselink
);
1793 tree these_basetypes
= basetype_path
;
1794 while (memoized_basetypes
&& these_basetypes
)
1796 memoized_fields_searched
[1]++;
1797 if (TREE_VALUE (memoized_basetypes
) != these_basetypes
)
1799 memoized_basetypes
= TREE_CHAIN (memoized_basetypes
);
1800 these_basetypes
= BINFO_INHERITANCE_CHAIN (these_basetypes
);
1802 /* The following statement is true only when both are NULL. */
1803 if (memoized_basetypes
== these_basetypes
)
1805 memoized_fast_finds
[1] += 1;
1806 return TREE_VALUE (tem
);
1808 /* else, we must re-find this field by hand. */
1809 baselink
= tree_cons (basetype_path
, TREE_VALUE (baselink
), TREE_CHAIN (baselink
));
1815 #ifdef GATHER_STATISTICS
1816 n_calls_lookup_fnfields
++;
1817 #endif /* GATHER_STATISTICS */
1818 if (protect
&& flag_memoize_lookups
&& ! global_bindings_p ())
1819 entry
= make_memoized_table_entry (type
, name
, 1);
1823 idx
= lookup_fnfields_here (type
, name
);
1824 if (idx
>= 0 || lookup_field_1 (type
, name
))
1826 rval_binfo
= basetype_path
;
1827 rval_binfo_h
= rval_binfo
;
1832 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1833 rvals
= my_tree_cons (basetype_path
, rval
, rvals
);
1834 if (BINFO_BASETYPES (binfo
) && CLASSTYPE_BASELINK_VEC (type
))
1835 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1839 TREE_VALUE (entry
) = rvals
;
1840 TREE_TYPE (entry
) = NULL_TREE
;
1847 if (name
== ctor_identifier
|| name
== dtor_identifier
)
1849 /* Don't allow lookups of constructors and destructors to go
1850 deeper than the first place we look. */
1852 TREE_TYPE (entry
) = TREE_VALUE (entry
) = NULL_TREE
;
1857 if (basetype_path
== TYPE_BINFO (type
))
1859 basetype_chain
= CLASSTYPE_BINFO_AS_LIST (type
);
1860 TREE_VIA_PUBLIC (basetype_chain
) = 1;
1861 BINFO_VIA_PUBLIC (basetype_path
) = 1;
1862 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1866 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
1867 TREE_VIA_PUBLIC (basetype_chain
) = TREE_VIA_PUBLIC (basetype_path
);
1868 TREE_VIA_PROTECTED (basetype_chain
) = TREE_VIA_PROTECTED (basetype_path
);
1869 TREE_VIA_VIRTUAL (basetype_chain
) = TREE_VIA_VIRTUAL (basetype_path
);
1872 /* The ambiguity check relies upon breadth first searching. */
1874 search_stack
= push_search_level (search_stack
, &search_obstack
);
1875 binfo
= basetype_path
;
1880 tree binfos
= BINFO_BASETYPES (binfo
);
1881 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1884 /* Process and/or queue base types. */
1885 for (i
= 0; i
< n_baselinks
; i
++)
1887 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1888 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1892 SET_BINFO_FIELDS_MARKED (base_binfo
);
1893 btypes
= my_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1894 TREE_VIA_PUBLIC (btypes
) = TREE_VIA_PUBLIC (base_binfo
);
1895 TREE_VIA_PROTECTED (btypes
) = TREE_VIA_PROTECTED (base_binfo
);
1896 TREE_VIA_VIRTUAL (btypes
) = TREE_VIA_VIRTUAL (base_binfo
);
1897 if (TREE_VIA_VIRTUAL (base_binfo
))
1898 btypes
= my_tree_cons (NULL_TREE
,
1899 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1902 btypes
= my_tree_cons (NULL_TREE
,
1903 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1905 obstack_ptr_grow (&search_obstack
, btypes
);
1907 if (tail
>= search_stack
->limit
)
1908 my_friendly_abort (99);
1912 /* Process head of queue, if one exists. */
1916 basetype_chain
= search_stack
->first
[head
++];
1917 binfo_h
= TREE_VALUE (basetype_chain
);
1918 basetype_chain
= TREE_CHAIN (basetype_chain
);
1919 basetype_path
= TREE_VALUE (basetype_chain
);
1920 if (TREE_CHAIN (basetype_chain
))
1921 BINFO_INHERITANCE_CHAIN (basetype_path
) = TREE_VALUE (TREE_CHAIN (basetype_chain
));
1923 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1925 binfo
= basetype_path
;
1926 type
= BINFO_TYPE (binfo
);
1928 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1929 and we do find NAME in TYPE, verify that such a second
1930 sighting is in fact valid. */
1932 idx
= lookup_fnfields_here (type
, name
);
1934 if (idx
>= 0 || (lookup_field_1 (type
, name
)!=NULL_TREE
&& !find_all
))
1936 if (rval_binfo
&& !find_all
&& hides (rval_binfo_h
, binfo_h
))
1938 /* This is ok, the member found is in rval_binfo, not
1941 else if (rval_binfo
==NULL_TREE
|| find_all
|| hides (binfo_h
, rval_binfo_h
))
1943 /* This is ok, the member found is here (binfo), not in
1947 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1948 /* Note, rvals can only be previously set if find_all is
1950 rvals
= my_tree_cons (basetype_path
, rval
, rvals
);
1951 if (TYPE_BINFO_BASETYPES (type
)
1952 && CLASSTYPE_BASELINK_VEC (type
))
1953 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1957 /* Undo finding it before, as something else hides it. */
1962 rval_binfo_h
= binfo_h
;
1966 /* This is ambiguous. */
1967 errstr
= "request for method `%D' is ambiguous";
1968 rvals
= error_mark_node
;
1974 tree
*tp
= search_stack
->first
;
1975 tree
*search_tail
= tp
+ tail
;
1977 while (tp
< search_tail
)
1979 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1983 search_stack
= pop_search_level (search_stack
);
1989 tree error_string
= my_build_string (errstr
);
1990 /* Save error message with entry. */
1991 TREE_TYPE (entry
) = error_string
;
1995 /* Mark entry as having no error string. */
1996 TREE_TYPE (entry
) = NULL_TREE
;
1997 TREE_VALUE (entry
) = rvals
;
2001 if (errstr
&& protect
)
2003 cp_error (errstr
, name
);
2004 rvals
= error_mark_node
;
2010 /* BREADTH-FIRST SEARCH ROUTINES. */
2012 /* Search a multiple inheritance hierarchy by breadth-first search.
2014 BINFO is an aggregate type, possibly in a multiple-inheritance hierarchy.
2015 TESTFN is a function, which, if true, means that our condition has been met,
2016 and its return value should be returned.
2017 QFN, if non-NULL, is a predicate dictating whether the type should
2020 static HOST_WIDE_INT
2021 breadth_first_search (binfo
, testfn
, qfn
)
2023 int (*testfn
) PROTO((tree
, int));
2024 int (*qfn
) PROTO((tree
, int));
2026 int head
= 0, tail
= 0;
2029 search_stack
= push_search_level (search_stack
, &search_obstack
);
2033 tree binfos
= BINFO_BASETYPES (binfo
);
2034 int n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2037 /* Process and/or queue base types. */
2038 for (i
= 0; i
< n_baselinks
; i
++)
2040 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2042 if (BINFO_MARKED (base_binfo
) == 0
2043 && (qfn
== 0 || (*qfn
) (binfo
, i
)))
2045 SET_BINFO_MARKED (base_binfo
);
2046 obstack_ptr_grow (&search_obstack
, binfo
);
2047 obstack_ptr_grow (&search_obstack
, (HOST_WIDE_INT
) i
);
2049 if (tail
>= search_stack
->limit
)
2050 my_friendly_abort (100);
2053 /* Process head of queue, if one exists. */
2060 binfo
= search_stack
->first
[head
++];
2061 i
= (HOST_WIDE_INT
) search_stack
->first
[head
++];
2062 if ((rval
= (*testfn
) (binfo
, i
)))
2064 binfo
= BINFO_BASETYPE (binfo
, i
);
2067 tree
*tp
= search_stack
->first
;
2068 tree
*search_tail
= tp
+ tail
;
2069 while (tp
< search_tail
)
2072 int i
= (HOST_WIDE_INT
)(*tp
++);
2073 CLEAR_BINFO_MARKED (BINFO_BASETYPE (binfo
, i
));
2077 search_stack
= pop_search_level (search_stack
);
2081 /* Functions to use in breadth first searches. */
2082 typedef int (*pfi
) PROTO((tree
, int));
2084 static tree declarator
;
2087 get_virtuals_named_this (binfo
)
2092 fields
= lookup_fnfields (binfo
, declarator
, -1);
2093 /* fields cannot be error_mark_node */
2098 /* Get to the function decls, and return the first virtual function
2099 with this name, if there is one. */
2104 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= DECL_CHAIN (fndecl
))
2105 if (DECL_VINDEX (fndecl
))
2107 fields
= next_baselink (fields
);
2113 get_virtual_destructor (binfo
, i
)
2117 tree type
= BINFO_TYPE (binfo
);
2119 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
2120 if (TYPE_HAS_DESTRUCTOR (type
)
2121 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
2122 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
2127 tree_has_any_destructor_p (binfo
, i
)
2131 tree type
= BINFO_TYPE (binfo
);
2133 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
2134 return TYPE_NEEDS_DESTRUCTOR (type
);
2137 /* Given a class type TYPE, and a function decl FNDECL, look for a
2138 virtual function in TYPE's hierarchy which FNDECL could match as a
2139 virtual function. It doesn't matter which one we find.
2141 DTORP is nonzero if we are looking for a destructor. Destructors
2142 need special treatment because they do not match by name. */
2145 get_matching_virtual (binfo
, fndecl
, dtorp
)
2149 tree tmp
= NULL_TREE
;
2151 /* Breadth first search routines start searching basetypes
2152 of TYPE, so we must perform first ply of search here. */
2155 if (tree_has_any_destructor_p (binfo
, -1))
2156 tmp
= get_virtual_destructor (binfo
, -1);
2161 tmp
= (tree
) breadth_first_search (binfo
,
2162 (pfi
) get_virtual_destructor
,
2163 tree_has_any_destructor_p
);
2168 tree drettype
, dtypes
, btypes
, instptr_type
;
2169 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
2170 tree baselink
, best
= NULL_TREE
;
2171 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
2173 declarator
= DECL_NAME (fndecl
);
2174 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
2177 baselink
= get_virtuals_named_this (binfo
);
2178 if (baselink
== NULL_TREE
)
2181 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
2182 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2183 if (DECL_STATIC_FUNCTION_P (fndecl
))
2184 instptr_type
= NULL_TREE
;
2186 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
2188 for (; baselink
; baselink
= next_baselink (baselink
))
2190 for (tmp
= TREE_VALUE (baselink
); tmp
; tmp
= DECL_CHAIN (tmp
))
2192 if (! DECL_VINDEX (tmp
))
2195 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
2196 if (instptr_type
== NULL_TREE
)
2198 if (compparms (TREE_CHAIN (btypes
), dtypes
, 3))
2199 /* Caller knows to give error in this case. */
2204 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (btypes
)))
2205 == TYPE_READONLY (instptr_type
))
2206 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
), 3))
2208 tree brettype
= TREE_TYPE (TREE_TYPE (tmp
));
2209 if (comptypes (brettype
, drettype
, 1))
2212 (TREE_CODE (brettype
) == TREE_CODE (drettype
)
2213 && (TREE_CODE (brettype
) == POINTER_TYPE
2214 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
2215 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (brettype
)),
2216 TYPE_MAIN_VARIANT (TREE_TYPE (drettype
)),
2218 /* covariant return type */
2220 tree b
= TREE_TYPE (brettype
), d
= TREE_TYPE (drettype
);
2221 if (TYPE_MAIN_VARIANT (b
) != TYPE_MAIN_VARIANT (d
))
2223 tree binfo
= get_binfo (b
, d
, 1);
2224 if (binfo
!= error_mark_node
2225 && (! BINFO_OFFSET_ZEROP (binfo
)
2226 || TREE_VIA_VIRTUAL (binfo
)))
2227 sorry ("adjusting pointers for covariant returns");
2229 if (TYPE_READONLY (d
) > TYPE_READONLY (b
))
2231 cp_error_at ("return type of `%#D' adds const", fndecl
);
2232 cp_error_at (" overriding definition as `%#D'",
2235 else if (TYPE_VOLATILE (d
) > TYPE_VOLATILE (b
))
2237 cp_error_at ("return type of `%#D' adds volatile",
2239 cp_error_at (" overriding definition as `%#D'",
2243 else if (IS_AGGR_TYPE_2 (brettype
, drettype
)
2244 && comptypes (brettype
, drettype
, 0))
2246 error ("invalid covariant return type (must use pointer or reference)");
2247 cp_error_at (" overriding `%#D'", tmp
);
2248 cp_error_at (" with `%#D'", fndecl
);
2250 else if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
)
2252 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl
);
2253 cp_error_at (" overriding definition as `%#D'", tmp
);
2254 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
2270 /* Return the list of virtual functions which are abstract in type
2271 TYPE that come from non virtual base classes. See
2272 expand_direct_vtbls_init for the style of search we do. */
2275 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
2278 tree abstract_virtuals
;
2280 tree binfos
= BINFO_BASETYPES (binfo
);
2281 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2283 for (i
= 0; i
< n_baselinks
; i
++)
2285 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2286 int is_not_base_vtable
2287 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2288 if (! TREE_VIA_VIRTUAL (base_binfo
))
2290 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
2293 /* Should we use something besides CLASSTYPE_VFIELDS? */
2294 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2296 tree virtuals
= BINFO_VIRTUALS (binfo
);
2298 skip_rtti_stuff (&virtuals
);
2302 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2303 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2304 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2305 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2306 virtuals
= TREE_CHAIN (virtuals
);
2309 return abstract_virtuals
;
2312 /* Return the list of virtual functions which are abstract in type TYPE.
2313 This information is cached, and so must be built on a
2314 non-temporary obstack. */
2317 get_abstract_virtuals (type
)
2321 tree abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (type
);
2323 /* First get all from non-virtual bases. */
2325 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
2327 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
2329 tree virtuals
= BINFO_VIRTUALS (vbases
);
2331 skip_rtti_stuff (&virtuals
);
2335 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2336 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2337 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2338 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2339 virtuals
= TREE_CHAIN (virtuals
);
2342 return nreverse (abstract_virtuals
);
2345 /* For the type TYPE, return a list of member functions available from
2346 base classes with name NAME. The TREE_VALUE of the list is a chain of
2347 member functions with name NAME. The TREE_PURPOSE of the list is a
2348 basetype, or a list of base types (in reverse order) which were
2349 traversed to reach the chain of member functions. If we reach a base
2350 type which provides a member function of name NAME, and which has at
2351 most one base type itself, then we can terminate the search. */
2354 get_baselinks (type_as_binfo_list
, type
, name
)
2355 tree type_as_binfo_list
;
2358 int head
= 0, tail
= 0, idx
;
2359 tree rval
= 0, nval
= 0;
2360 tree basetypes
= type_as_binfo_list
;
2361 tree binfo
= TYPE_BINFO (type
);
2363 search_stack
= push_search_level (search_stack
, &search_obstack
);
2367 tree binfos
= BINFO_BASETYPES (binfo
);
2368 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2370 /* Process and/or queue base types. */
2371 for (i
= 0; i
< n_baselinks
; i
++)
2373 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2376 btypes
= hash_tree_cons (TREE_VIA_PUBLIC (base_binfo
),
2377 TREE_VIA_VIRTUAL (base_binfo
),
2378 TREE_VIA_PROTECTED (base_binfo
),
2379 NULL_TREE
, base_binfo
,
2381 obstack_ptr_grow (&search_obstack
, btypes
);
2382 search_stack
->first
= (tree
*)obstack_base (&search_obstack
);
2387 /* Process head of queue, if one exists. */
2391 basetypes
= search_stack
->first
[head
++];
2392 binfo
= TREE_VALUE (basetypes
);
2393 type
= BINFO_TYPE (binfo
);
2394 idx
= lookup_fnfields_1 (type
, name
);
2397 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
2398 rval
= hash_tree_cons (0, 0, 0, basetypes
, nval
, rval
);
2399 if (TYPE_BINFO_BASETYPES (type
) == 0)
2401 else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
)) == 1)
2403 if (CLASSTYPE_BASELINK_VEC (type
))
2404 TREE_TYPE (rval
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
2411 search_stack
= pop_search_level (search_stack
);
2416 next_baselink (baselink
)
2419 tree tmp
= TREE_TYPE (baselink
);
2420 baselink
= TREE_CHAIN (baselink
);
2423 /* @@ does not yet add previous base types. */
2424 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2426 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2427 tmp
= TREE_CHAIN (tmp
);
2432 /* DEPTH-FIRST SEARCH ROUTINES. */
2435 /* Assign unique numbers to _CLASSTYPE members of the lattice
2436 specified by TYPE. The root nodes are marked first; the nodes
2437 are marked depth-fisrt, left-right. */
2441 /* Matrix implementing a relation from CLASSTYPE X CLASSTYPE => INT.
2442 Relation yields 1 if C1 <= C2, 0 otherwise. */
2443 typedef char mi_boolean
;
2444 static mi_boolean
*mi_matrix
;
2446 /* Type for which this matrix is defined. */
2447 static tree mi_type
;
2449 /* Size of the matrix for indexing purposes. */
2452 /* Return nonzero if class C2 derives from class C1. */
2453 #define BINFO_DERIVES_FROM(C1, C2) \
2454 ((mi_matrix+mi_size*(BINFO_CID (C1)-1))[BINFO_CID (C2)-1])
2455 #define TYPE_DERIVES_FROM(C1, C2) \
2456 ((mi_matrix+mi_size*(CLASSTYPE_CID (C1)-1))[CLASSTYPE_CID (C2)-1])
2457 #define BINFO_DERIVES_FROM_STAR(C) \
2458 (mi_matrix+(BINFO_CID (C)-1))
2461 /* This routine converts a pointer to be a pointer of an immediate
2462 base class. The normal convert_pointer_to routine would diagnose
2463 the conversion as ambiguous, under MI code that has the base class
2464 as an ambiguous base class. */
2467 convert_pointer_to_single_level (to_type
, expr
)
2470 tree binfo_of_derived
;
2473 binfo_of_derived
= TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
)));
2474 last
= get_binfo (to_type
, TREE_TYPE (TREE_TYPE (expr
)), 0);
2475 BINFO_INHERITANCE_CHAIN (last
) = binfo_of_derived
;
2476 BINFO_INHERITANCE_CHAIN (binfo_of_derived
) = NULL_TREE
;
2477 return build_vbase_path (PLUS_EXPR
, build_pointer_type (to_type
), expr
, last
, 1);
2480 /* The main function which implements depth first search.
2482 This routine has to remember the path it walked up, when
2483 dfs_init_vbase_pointers is the work function, as otherwise there
2484 would be no record. */
2487 dfs_walk (binfo
, fn
, qfn
)
2489 void (*fn
) PROTO((tree
));
2490 int (*qfn
) PROTO((tree
));
2492 tree binfos
= BINFO_BASETYPES (binfo
);
2493 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2495 for (i
= 0; i
< n_baselinks
; i
++)
2497 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2499 if (qfn
== 0 || (*qfn
)(base_binfo
))
2501 if (TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TYPE_PARM
2502 || TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TEMPLATE_PARM
)
2504 else if (fn
== dfs_init_vbase_pointers
)
2506 /* When traversing an arbitrary MI hierarchy, we need to keep
2507 a record of the path we took to get down to the final base
2508 type, as otherwise there would be no record of it, and just
2509 trying to blindly convert at the bottom would be ambiguous.
2511 The easiest way is to do the conversions one step at a time,
2512 as we know we want the immediate base class at each step.
2514 The only special trick to converting one step at a time,
2515 is that when we hit the last virtual base class, we must
2516 use the SLOT value for it, and not use the normal convert
2517 routine. We use the last virtual base class, as in our
2518 implementation, we have pointers to all virtual base
2519 classes in the base object. */
2521 tree saved_vbase_decl_ptr_intermediate
2522 = vbase_decl_ptr_intermediate
;
2524 if (TREE_VIA_VIRTUAL (base_binfo
))
2526 /* No need for the conversion here, as we know it is the
2528 vbase_decl_ptr_intermediate
2529 = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
));
2533 vbase_decl_ptr_intermediate
2534 = convert_pointer_to_single_level (BINFO_TYPE (base_binfo
),
2535 vbase_decl_ptr_intermediate
);
2538 dfs_walk (base_binfo
, fn
, qfn
);
2540 vbase_decl_ptr_intermediate
= saved_vbase_decl_ptr_intermediate
;
2543 dfs_walk (base_binfo
, fn
, qfn
);
2551 /* Predicate functions which serve for dfs_walk. */
2552 static int numberedp (binfo
) tree binfo
;
2553 { return BINFO_CID (binfo
); }
2554 static int unnumberedp (binfo
) tree binfo
;
2555 { return BINFO_CID (binfo
) == 0; }
2558 static int markedp (binfo
) tree binfo
;
2559 { return BINFO_MARKED (binfo
); }
2560 static int unmarkedp (binfo
) tree binfo
;
2561 { return BINFO_MARKED (binfo
) == 0; }
2564 static int bfs_markedp (binfo
, i
) tree binfo
; int i
;
2565 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2566 static int bfs_unmarkedp (binfo
, i
) tree binfo
; int i
;
2567 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2568 static int bfs_marked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2569 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2570 static int bfs_unmarked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2571 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2572 static int bfs_marked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2573 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2574 static int bfs_unmarked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2575 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2578 static int marked_vtable_pathp (binfo
) tree binfo
;
2579 { return BINFO_VTABLE_PATH_MARKED (binfo
); }
2580 static int unmarked_vtable_pathp (binfo
) tree binfo
;
2581 { return BINFO_VTABLE_PATH_MARKED (binfo
) == 0; }
2582 static int marked_new_vtablep (binfo
) tree binfo
;
2583 { return BINFO_NEW_VTABLE_MARKED (binfo
); }
2584 static int unmarked_new_vtablep (binfo
) tree binfo
;
2585 { return BINFO_NEW_VTABLE_MARKED (binfo
) == 0; }
2588 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2589 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2592 static int dfs_debug_unmarkedp (binfo
) tree binfo
;
2593 { return CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
)) == 0; }
2595 /* The worker functions for `dfs_walk'. These do not need to
2596 test anything (vis a vis marking) if they are paired with
2597 a predicate function (above). */
2600 /* Assign each type within the lattice a number which is unique
2601 in the lattice. The first number assigned is 1. */
2607 BINFO_CID (binfo
) = ++cid
;
2611 dfs_unnumber (binfo
)
2614 BINFO_CID (binfo
) = 0;
2620 dfs_mark (binfo
) tree binfo
;
2621 { SET_BINFO_MARKED (binfo
); }
2625 dfs_unmark (binfo
) tree binfo
;
2626 { CLEAR_BINFO_MARKED (binfo
); }
2630 dfs_mark_vtable_path (binfo
) tree binfo
;
2631 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2634 dfs_unmark_vtable_path (binfo
) tree binfo
;
2635 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2638 dfs_mark_new_vtable (binfo
) tree binfo
;
2639 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2642 dfs_unmark_new_vtable (binfo
) tree binfo
;
2643 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2646 dfs_clear_search_slot (binfo
) tree binfo
;
2647 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2651 dfs_debug_mark (binfo
)
2654 tree t
= BINFO_TYPE (binfo
);
2656 /* Use heuristic that if there are virtual functions,
2657 ignore until we see a non-inline virtual function. */
2658 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2660 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2665 /* If interface info is known, either we've already emitted the debug
2666 info or we don't need to. */
2667 if (CLASSTYPE_INTERFACE_KNOWN (t
)
2668 || (write_virtuals
== 2 && TYPE_VIRTUAL_P (t
)))
2671 /* If debug info is requested from this context for this type, supply it.
2672 If debug info is requested from another context for this type,
2673 see if some third context can supply it. */
2674 if (current_function_decl
== NULL_TREE
2675 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2677 if (TREE_VEC_ELT (methods
, 1))
2678 methods
= TREE_VEC_ELT (methods
, 1);
2679 else if (TREE_VEC_ELT (methods
, 0))
2680 methods
= TREE_VEC_ELT (methods
, 0);
2682 methods
= TREE_VEC_ELT (methods
, 2);
2685 if (DECL_VINDEX (methods
)
2686 && DECL_THIS_INLINE (methods
) == 0
2687 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2689 /* Somebody, somewhere is going to have to define this
2690 virtual function. When they do, they will provide
2691 the debugging info. */
2694 methods
= TREE_CHAIN (methods
);
2697 /* We cannot rely on some alien method to solve our problems,
2698 so we must write out the debug info ourselves. */
2699 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2700 rest_of_type_compilation (t
, global_bindings_p ());
2703 /* Attach to the type of the virtual base class, the pointer to the
2704 virtual base class, given the global pointer vbase_decl_ptr.
2706 We use the global vbase_types. ICK! */
2709 dfs_find_vbases (binfo
)
2712 tree binfos
= BINFO_BASETYPES (binfo
);
2713 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2715 for (i
= n_baselinks
-1; i
>= 0; i
--)
2717 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2719 if (TREE_VIA_VIRTUAL (base_binfo
)
2720 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2722 tree vbase
= BINFO_TYPE (base_binfo
);
2723 tree binfo
= binfo_member (vbase
, vbase_types
);
2725 CLASSTYPE_SEARCH_SLOT (vbase
)
2726 = build (PLUS_EXPR
, build_pointer_type (vbase
),
2727 vbase_decl_ptr
, BINFO_OFFSET (binfo
));
2730 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2731 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2735 dfs_init_vbase_pointers (binfo
)
2738 tree type
= BINFO_TYPE (binfo
);
2739 tree fields
= TYPE_FIELDS (type
);
2740 tree this_vbase_ptr
;
2742 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2745 /* See finish_struct_1 for when we can enable this. */
2746 /* If we have a vtable pointer first, skip it. */
2747 if (VFIELD_NAME_P (DECL_NAME (fields
)))
2748 fields
= TREE_CHAIN (fields
);
2751 if (fields
== NULL_TREE
2752 || DECL_NAME (fields
) == NULL_TREE
2753 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2756 this_vbase_ptr
= vbase_decl_ptr_intermediate
;
2758 if (build_pointer_type (type
) != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2759 my_friendly_abort (125);
2761 while (fields
&& DECL_NAME (fields
)
2762 && VBASE_NAME_P (DECL_NAME (fields
)))
2764 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2765 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2766 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2767 vbase_init_result
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2769 build_modify_expr (ref
, NOP_EXPR
, init
),
2771 fields
= TREE_CHAIN (fields
);
2775 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2776 times, just NEW_VTABLE, but optimizer should make both with equal
2777 efficiency (though it does not currently). */
2780 dfs_clear_vbase_slots (binfo
)
2783 tree type
= BINFO_TYPE (binfo
);
2784 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2785 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2786 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2790 init_vbase_pointers (type
, decl_ptr
)
2794 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2796 int old_flag
= flag_this_is_variable
;
2797 tree binfo
= TYPE_BINFO (type
);
2798 flag_this_is_variable
= -2;
2799 vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2800 vbase_decl_ptr
= vbase_decl_ptr_intermediate
= decl_ptr
;
2801 vbase_init_result
= NULL_TREE
;
2802 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
);
2803 dfs_walk (binfo
, dfs_init_vbase_pointers
, marked_vtable_pathp
);
2804 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
2805 flag_this_is_variable
= old_flag
;
2806 return vbase_init_result
;
2811 /* get the virtual context (the vbase that directly contains the
2812 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2813 or NULL_TREE if there is none.
2815 FNDECL must come from a virtual table from a virtual base to ensure that
2816 there is only one possible DECL_CLASS_CONTEXT.
2818 We know that if there is more than one place (binfo) the fndecl that the
2819 declared, they all refer to the same binfo. See get_class_offset_1 for
2820 the check that ensures this. */
2823 virtual_context (fndecl
, t
, vbase
)
2824 tree fndecl
, t
, vbase
;
2827 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2829 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2830 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2834 /* Not sure if checking path == vbase is necessary here, but just in
2836 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2837 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2838 path
= BINFO_INHERITANCE_CHAIN (path
);
2841 /* This shouldn't happen, I don't want errors! */
2842 warning ("recoverable compiler error, fixups for virtual function");
2847 if (TREE_VIA_VIRTUAL (path
))
2848 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2849 path
= BINFO_INHERITANCE_CHAIN (path
);
2854 /* Fixups upcast offsets for one vtable.
2855 Entries may stay within the VBASE given, or
2856 they may upcast into a direct base, or
2857 they may upcast into a different vbase.
2859 We only need to do fixups in case 2 and 3. In case 2, we add in
2860 the virtual base offset to effect an upcast, in case 3, we add in
2861 the virtual base offset to effect an upcast, then subtract out the
2862 offset for the other virtual base, to effect a downcast into it.
2864 This routine mirrors fixup_vtable_deltas in functionality, though
2865 this one is runtime based, and the other is compile time based.
2866 Conceivably that routine could be removed entirely, and all fixups
2869 VBASE_OFFSETS is an association list of virtual bases that contains
2870 offset information for the virtual bases, so the offsets are only
2871 calculated once. The offsets are computed by where we think the
2872 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2873 the vbase really is. */
2876 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2878 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2880 tree virtuals
= BINFO_VIRTUALS (binfo
);
2883 unsigned HOST_WIDE_INT n
;
2885 delta
= purpose_member (vbase
, *vbase_offsets
);
2888 delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase
));
2889 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2890 delta
= save_expr (delta
);
2891 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2892 *vbase_offsets
= delta
;
2895 n
= skip_rtti_stuff (&virtuals
);
2899 tree current_fndecl
= TREE_VALUE (virtuals
);
2900 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2901 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2903 && current_fndecl
!= abort_fndecl
2904 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2906 /* This may in fact need a runtime fixup. */
2907 tree idx
= build_int_2 (n
, 0);
2908 tree vtbl
= BINFO_VTABLE (binfo
);
2909 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2910 tree aref
, ref
, naref
;
2911 tree old_delta
, new_delta
;
2914 if (nvtbl
== NULL_TREE
2915 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2917 /* Dup it if it isn't in local scope yet. */
2918 nvtbl
= build_decl (VAR_DECL
,
2920 TYPE_MAIN_VARIANT (TREE_TYPE (BINFO_VTABLE (binfo
))));
2921 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2922 DECL_ALIGN (nvtbl
));
2923 TREE_READONLY (nvtbl
) = 0;
2924 DECL_ARTIFICIAL (nvtbl
) = 1;
2925 nvtbl
= pushdecl (nvtbl
);
2927 cp_finish_decl (nvtbl
, init
, NULL_TREE
, 0, LOOKUP_ONLYCONVERTING
);
2928 DECL_VIRTUAL_P (nvtbl
) = 1;
2929 DECL_CONTEXT (nvtbl
) = t
;
2930 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
2932 TREE_SIDE_EFFECTS (init
) = 1;
2933 expand_expr_stmt (init
);
2934 /* Update the vtable pointers as necessary. */
2935 ref
= build_vfield_ref (build_indirect_ref (addr
, NULL_PTR
), DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))));
2936 expand_expr_stmt (build_modify_expr (ref
, NOP_EXPR
,
2937 build_unary_op (ADDR_EXPR
, nvtbl
, 0)));
2939 assemble_external (vtbl
);
2940 aref
= build_array_ref (vtbl
, idx
);
2941 naref
= build_array_ref (nvtbl
, idx
);
2942 old_delta
= build_component_ref (aref
, delta_identifier
, NULL_TREE
, 0);
2943 new_delta
= build_component_ref (naref
, delta_identifier
, NULL_TREE
, 0);
2945 /* This is a upcast, so we have to add the offset for the
2947 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
2948 TREE_VALUE (delta
), 0);
2951 /* If this is set, we need to subtract out the delta
2952 adjustments for the other virtual base that we
2954 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
2957 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
2958 vc_delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc
));
2959 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
2961 vc_delta
= save_expr (vc_delta
);
2962 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
2965 vc_delta
= TREE_VALUE (vc_delta
);
2967 /* This is a downcast, so we have to subtract the offset
2968 for the virtual base. */
2969 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
, 0);
2972 TREE_READONLY (new_delta
) = 0;
2973 expand_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
2977 virtuals
= TREE_CHAIN (virtuals
);
2981 /* Fixup upcast offsets for all direct vtables. Patterned after
2982 expand_direct_vtbls_init. */
2985 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
2986 tree real_binfo
, binfo
;
2987 int init_self
, can_elide
;
2988 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
2990 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
2991 tree binfos
= BINFO_BASETYPES (binfo
);
2992 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
2994 for (i
= 0; i
< n_baselinks
; i
++)
2996 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
2997 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2998 int is_not_base_vtable
2999 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo
));
3000 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
3001 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
3002 is_not_base_vtable
, can_elide
, addr
,
3003 orig_addr
, type
, vbase
, vbase_offsets
);
3006 /* Before turning this on, make sure it is correct. */
3007 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
3010 /* Should we use something besides CLASSTYPE_VFIELDS? */
3011 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
3013 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
3014 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
3015 type
, vbase_offsets
);
3019 /* Build a COMPOUND_EXPR which when expanded will generate the code
3020 needed to initialize all the virtual function table slots of all
3021 the virtual baseclasses. MAIN_BINFO is the binfo which determines
3022 the virtual baseclasses to use; TYPE is the type of the object to
3023 which the initialization applies. TRUE_EXP is the true object we
3024 are initializing, and DECL_PTR is the pointer to the sub-object we
3027 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
3028 object was laid out by a top-level constructor and the computed
3029 offsets are valid to store vtables. When zero, we must store new
3030 vtables through virtual baseclass pointers.
3032 We setup and use the globals: vbase_decl_ptr, vbase_types
3036 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
)
3038 tree true_exp
, decl_ptr
;
3040 tree type
= BINFO_TYPE (binfo
);
3042 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
3044 rtx fixup_insns
= NULL_RTX
;
3045 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
3046 vbase_types
= vbases
;
3047 vbase_decl_ptr
= true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0) : decl_ptr
;
3049 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
);
3051 /* Initialized with vtables of type TYPE. */
3052 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
3056 addr
= convert_pointer_to_vbase (TREE_TYPE (vbases
), vbase_decl_ptr
);
3058 /* Do all vtables from this virtual base. */
3059 /* This assumes that virtual bases can never serve as parent
3060 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
3061 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
3064 /* Now we adjust the offsets for virtual functions that
3065 cross virtual boundaries on an implicit upcast on vf call
3066 so that the layout of the most complete type is used,
3067 instead of assuming the layout of the virtual bases from
3068 our current type. */
3070 if (flag_vtable_thunks
)
3072 /* We don't have dynamic thunks yet!
3073 So for now, just fail silently. */
3077 tree vbase_offsets
= NULL_TREE
;
3078 push_to_sequence (fixup_insns
);
3079 fixup_virtual_upcast_offsets (vbases
,
3080 TYPE_BINFO (BINFO_TYPE (vbases
)),
3081 1, 0, addr
, vbase_decl_ptr
,
3082 type
, vbases
, &vbase_offsets
);
3083 fixup_insns
= get_insns ();
3090 extern tree in_charge_identifier
;
3091 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
3092 if (! in_charge_node
)
3094 warning ("recoverable internal compiler error, nobody's in charge!");
3095 in_charge_node
= integer_zero_node
;
3097 in_charge_node
= build_binary_op (EQ_EXPR
, in_charge_node
, integer_zero_node
, 1);
3098 expand_start_cond (in_charge_node
, 0);
3099 emit_insns (fixup_insns
);
3103 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
3107 /* get virtual base class types.
3108 This adds type to the vbase_types list in reverse dfs order.
3109 Ordering is very important, so don't change it. */
3112 dfs_get_vbase_types (binfo
)
3115 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
3117 vbase_types
= make_binfo (integer_zero_node
, binfo
,
3118 BINFO_VTABLE (binfo
),
3119 BINFO_VIRTUALS (binfo
), vbase_types
);
3120 TREE_VIA_VIRTUAL (vbase_types
) = 1;
3121 SET_BINFO_VBASE_MARKED (binfo
);
3123 SET_BINFO_MARKED (binfo
);
3126 /* get a list of virtual base classes in dfs order. */
3129 get_vbase_types (type
)
3135 if (TREE_CODE (type
) == TREE_VEC
)
3138 binfo
= TYPE_BINFO (type
);
3140 vbase_types
= NULL_TREE
;
3141 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
);
3142 dfs_walk (binfo
, dfs_unmark
, markedp
);
3143 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
3144 reverse it so that we get normal dfs ordering. */
3145 vbase_types
= nreverse (vbase_types
);
3147 /* unmark marked vbases */
3148 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
3149 CLEAR_BINFO_VBASE_MARKED (vbases
);
3156 dfs_record_inheritance (binfo
)
3159 tree binfos
= BINFO_BASETYPES (binfo
);
3160 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3161 mi_boolean
*derived_row
= BINFO_DERIVES_FROM_STAR (binfo
);
3163 for (i
= n_baselinks
-1; i
>= 0; i
--)
3166 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3167 tree baseclass
= BINFO_TYPE (base_binfo
);
3168 mi_boolean
*base_row
= BINFO_DERIVES_FROM_STAR (base_binfo
);
3170 if (TREE_CODE (baseclass
) == TEMPLATE_TYPE_PARM
3171 || TREE_CODE (baseclass
) == TEMPLATE_TEMPLATE_PARM
)
3173 my_friendly_assert (CLASSTYPE_CID (baseclass
) != 0, 2365);
3175 /* Don't search if there's nothing there! MI_SIZE can be
3176 zero as a result of parse errors. */
3177 if (TYPE_BINFO_BASETYPES (baseclass
) && mi_size
> 0)
3178 for (j
= mi_size
*(CLASSTYPE_CID (baseclass
)-1); j
>= 0; j
-= mi_size
)
3179 derived_row
[j
] |= base_row
[j
];
3180 TYPE_DERIVES_FROM (baseclass
, BINFO_TYPE (binfo
)) = 1;
3183 SET_BINFO_MARKED (binfo
);
3186 /* Given a _CLASSTYPE node in a multiple inheritance lattice,
3187 convert the lattice into a simple relation such that,
3188 given to CIDs, C1 and C2, one can determine if C1 <= C2
3189 or C2 <= C1 or C1 <> C2.
3191 Once constructed, we walk the lattice depth fisrt,
3192 applying various functions to elements as they are encountered.
3194 We use xmalloc here, in case we want to randomly free these tables. */
3196 #define SAVE_MI_MATRIX
3199 build_mi_matrix (type
)
3202 tree binfo
= TYPE_BINFO (type
);
3205 #ifdef SAVE_MI_MATRIX
3206 if (CLASSTYPE_MI_MATRIX (type
))
3208 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
3209 mi_matrix
= CLASSTYPE_MI_MATRIX (type
);
3211 dfs_walk (binfo
, dfs_number
, unnumberedp
);
3216 dfs_walk (binfo
, dfs_number
, unnumberedp
);
3218 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
3219 if (mi_size
< (cid
-1))
3221 mi_matrix
= (char *)xmalloc ((mi_size
+ 1) * (mi_size
+ 1));
3223 bzero (mi_matrix
, (mi_size
+ 1) * (mi_size
+ 1));
3224 dfs_walk (binfo
, dfs_record_inheritance
, unmarkedp
);
3225 dfs_walk (binfo
, dfs_unmark
, markedp
);
3231 dfs_walk (TYPE_BINFO (mi_type
), dfs_unnumber
, numberedp
);
3233 #ifdef SAVE_MI_MATRIX
3234 CLASSTYPE_MI_MATRIX (mi_type
) = mi_matrix
;
3243 /* If we want debug info for a type TYPE, make sure all its base types
3244 are also marked as being potentially interesting. This avoids
3245 the problem of not writing any debug info for intermediate basetypes
3246 that have abstract virtual functions. Also mark member types. */
3249 note_debug_info_needed (type
)
3254 if (current_template_parms
)
3257 if (TYPE_BEING_DEFINED (type
))
3258 /* We can't go looking for the base types and fields just yet. */
3261 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
3262 does not support name references between translation units. Well, we
3263 could, but that would mean putting global labels in the debug output
3264 before each exported type and each of its functions and static data
3266 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
3269 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
);
3270 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
3273 if (TREE_CODE (field
) == FIELD_DECL
3274 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
3275 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
)))
3276 note_debug_info_needed (ttype
);
3280 /* Subroutines of push_class_decls (). */
3282 /* Add in a decl to the envelope. */
3284 envelope_add_decl (type
, decl
, values
)
3285 tree type
, decl
, *values
;
3288 tree name
= DECL_NAME (decl
);
3291 /* virtual base names are always unique. */
3292 if (VBASE_NAME_P (name
))
3293 *values
= NULL_TREE
;
3295 /* Possible ambiguity. If its defining type(s)
3296 is (are all) derived from us, no problem. */
3297 else if (*values
&& TREE_CODE (*values
) != TREE_LIST
)
3299 tree value
= *values
;
3300 /* Only complain if we shadow something we can access. */
3301 if (warn_shadow
&& TREE_CODE (decl
) == FUNCTION_DECL
3302 && ((DECL_LANG_SPECIFIC (*values
)
3303 && DECL_CLASS_CONTEXT (value
) == current_class_type
)
3304 || ! TREE_PRIVATE (value
)))
3305 /* Should figure out access control more accurately. */
3307 cp_warning_at ("member `%#D' is shadowed", value
);
3308 cp_warning_at ("by member function `%#D'", decl
);
3309 warning ("in this context");
3312 context
= (TREE_CODE (value
) == FUNCTION_DECL
3313 && DECL_VIRTUAL_P (value
))
3314 ? DECL_CLASS_CONTEXT (value
)
3315 : DECL_CONTEXT (value
);
3317 if (context
== type
)
3319 if (TREE_CODE (value
) == TYPE_DECL
3320 && DECL_ARTIFICIAL (value
))
3321 *values
= NULL_TREE
;
3325 else if (type
== current_class_type
3327 /* If we don't check CLASSTYPE_CID on CONTEXT right now,
3328 we'll end up subtracting from the address of MI_MATRIX,
3329 putting us off in la la land. */
3330 || (CLASSTYPE_CID (type
)
3331 && TYPE_DERIVES_FROM (context
, type
))
3333 || DERIVED_FROM_P (context
, type
)
3337 /* Don't add in *values to list */
3338 *values
= NULL_TREE
;
3341 *values
= build_tree_list (NULL_TREE
, value
);
3344 for (tmp
= values
; *tmp
;)
3346 tree value
= TREE_VALUE (*tmp
);
3347 my_friendly_assert (TREE_CODE (value
) != TREE_LIST
, 999);
3348 context
= (TREE_CODE (value
) == FUNCTION_DECL
3349 && DECL_VIRTUAL_P (value
))
3350 ? DECL_CLASS_CONTEXT (value
)
3351 : DECL_CONTEXT (value
);
3353 if (type
== current_class_type
3355 /* If we don't check CLASSTYPE_CID on CONTEXT right now,
3356 we'll end up subtracting from the address of MI_MATRIX,
3357 putting us off in la la land. */
3358 || (CLASSTYPE_CID (type
)
3359 && TYPE_DERIVES_FROM (context
, type
))
3361 || DERIVED_FROM_P (context
, type
)
3365 /* remove *tmp from list */
3366 *tmp
= TREE_CHAIN (*tmp
);
3369 tmp
= &TREE_CHAIN (*tmp
);
3374 /* Put the new contents in our envelope. */
3375 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3377 *values
= tree_cons (name
, decl
, *values
);
3378 TREE_NONLOCAL_FLAG (*values
) = 1;
3379 TREE_TYPE (*values
) = unknown_type_node
;
3385 *values
= tree_cons (NULL_TREE
, decl
, *values
);
3386 /* Mark this as a potentially ambiguous member. */
3387 /* Leaving TREE_TYPE blank is intentional.
3388 We cannot use `error_mark_node' (lookup_name)
3389 or `unknown_type_node' (all member functions use this). */
3390 TREE_NONLOCAL_FLAG (*values
) = 1;
3398 /* Add the instance variables which this class contributed to the
3399 current class binding contour. When a redefinition occurs, if the
3400 redefinition is strictly within a single inheritance path, we just
3401 overwrite the old declaration with the new. If the fields are not
3402 within a single inheritance path, we must cons them.
3404 In order to know what decls are new (stemming from the current
3405 invocation of push_class_decls) we enclose them in an "envelope",
3406 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
3407 new decl (or possibly a list of competing ones), the TREE_VALUE slot
3408 points to the old value and the TREE_CHAIN slot chains together all
3409 envelopes which needs to be "opened" in push_class_decls. Opening an
3410 envelope means: push the old value onto the class_shadowed list,
3411 install the new one and if it's a TYPE_DECL do the same to the
3412 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
3413 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
3414 Because if it is, it could be a set of overloaded methods from an
3418 dfs_pushdecls (binfo
)
3421 tree type
= BINFO_TYPE (binfo
);
3422 tree fields
, *methods
, *end
;
3425 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3427 /* Unmark so that if we are in a constructor, and then find that
3428 this field was initialized by a base initializer,
3429 we can emit an error message. */
3430 if (TREE_CODE (fields
) == FIELD_DECL
)
3431 TREE_USED (fields
) = 0;
3433 /* Recurse into anonymous unions. */
3434 if (DECL_NAME (fields
) == NULL_TREE
3435 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3437 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields
)));
3441 if (DECL_NAME (fields
))
3443 tree name
= DECL_NAME (fields
);
3444 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
3446 /* If the class value is not an envelope of the kind described in
3447 the comment above, we create a new envelope. */
3448 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3449 || TREE_PURPOSE (class_value
) == NULL_TREE
3450 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3452 /* See comment above for a description of envelopes. */
3453 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3455 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
3456 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3459 envelope_add_decl (type
, fields
, &TREE_PURPOSE (class_value
));
3463 method_vec
= CLASSTYPE_METHOD_VEC (type
);
3466 /* Farm out constructors and destructors. */
3467 methods
= &TREE_VEC_ELT (method_vec
, 2);
3468 end
= TREE_VEC_END (method_vec
);
3470 while (methods
!= end
)
3472 /* This will cause lookup_name to return a pointer
3473 to the tree_list of possible methods of this name. */
3474 tree name
= DECL_NAME (*methods
);
3475 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
3477 /* If the class value is not an envelope of the kind described in
3478 the comment above, we create a new envelope. */
3479 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3480 || TREE_PURPOSE (class_value
) == NULL_TREE
3481 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3483 /* See comment above for a description of envelopes. */
3484 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3486 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
3487 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3490 /* Here we try to rule out possible ambiguities.
3491 If we can't do that, keep a TREE_LIST with possibly ambiguous
3493 maybe_push_cache_obstack ();
3494 envelope_add_decl (type
, *methods
, &TREE_PURPOSE (class_value
));
3500 SET_BINFO_MARKED (binfo
);
3503 /* Consolidate unique (by name) member functions. */
3506 dfs_compress_decls (binfo
)
3509 tree type
= BINFO_TYPE (binfo
);
3510 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
3512 if (method_vec
!= 0)
3514 /* Farm out constructors and destructors. */
3515 tree
*methods
= &TREE_VEC_ELT (method_vec
, 2);
3516 tree
*end
= TREE_VEC_END (method_vec
);
3518 for (; methods
!= end
; methods
++)
3520 /* This is known to be an envelope of the kind described before
3522 tree class_value
= IDENTIFIER_CLASS_VALUE (DECL_NAME (*methods
));
3523 tree tmp
= TREE_PURPOSE (class_value
);
3525 /* This was replaced in scope by somebody else. Just leave it
3527 if (TREE_CODE (tmp
) != TREE_LIST
)
3530 if (TREE_CHAIN (tmp
) == NULL_TREE
3532 && DECL_CHAIN (TREE_VALUE (tmp
)) == NULL_TREE
)
3534 TREE_PURPOSE (class_value
) = TREE_VALUE (tmp
);
3538 CLEAR_BINFO_MARKED (binfo
);
3541 /* When entering the scope of a class, we cache all of the
3542 fields that that class provides within its inheritance
3543 lattice. Where ambiguities result, we mark them
3544 with `error_mark_node' so that if they are encountered
3545 without explicit qualification, we can emit an error
3549 push_class_decls (type
)
3552 struct obstack
*ambient_obstack
= current_obstack
;
3553 search_stack
= push_search_level (search_stack
, &search_obstack
);
3555 /* Push class fields into CLASS_VALUE scope, and mark. */
3556 dfs_walk (TYPE_BINFO (type
), dfs_pushdecls
, unmarkedp
);
3558 /* Compress fields which have only a single entry
3559 by a given name, and unmark. */
3560 dfs_walk (TYPE_BINFO (type
), dfs_compress_decls
, markedp
);
3562 /* Open up all the closed envelopes and push the contained decls into
3564 while (closed_envelopes
)
3566 tree
new = TREE_PURPOSE (closed_envelopes
);
3569 /* This is messy because the class value may be a *_DECL, or a
3570 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3571 *_DECLs. The name is stored at different places in these three
3573 if (TREE_CODE (new) == TREE_LIST
)
3575 if (TREE_PURPOSE (new) != NULL_TREE
)
3576 id
= TREE_PURPOSE (new);
3579 tree node
= TREE_VALUE (new);
3581 if (TREE_CODE (node
) == TYPE_DECL
3582 && DECL_ARTIFICIAL (node
)
3583 && IS_AGGR_TYPE (TREE_TYPE (node
))
3584 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (node
)))
3586 tree t
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (node
));
3589 for (; n
; n
= TREE_CHAIN (n
))
3591 tree d
= TREE_VALUE (n
);
3592 if (TREE_CODE (d
) == TYPE_DECL
3593 && DECL_ARTIFICIAL (node
)
3594 && IS_AGGR_TYPE (TREE_TYPE (d
))
3595 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (d
))
3596 && CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d
)) == t
)
3605 else while (TREE_CODE (node
) == TREE_LIST
)
3606 node
= TREE_VALUE (node
);
3607 id
= DECL_NAME (node
);
3611 id
= DECL_NAME (new);
3613 /* Install the original class value in order to make
3614 pushdecl_class_level work correctly. */
3615 IDENTIFIER_CLASS_VALUE (id
) = TREE_VALUE (closed_envelopes
);
3616 if (TREE_CODE (new) == TREE_LIST
)
3617 push_class_level_binding (id
, new);
3619 pushdecl_class_level (new);
3620 closed_envelopes
= TREE_CHAIN (closed_envelopes
);
3622 current_obstack
= ambient_obstack
;
3625 /* Here's a subroutine we need because C lacks lambdas. */
3628 dfs_unuse_fields (binfo
)
3631 tree type
= TREE_TYPE (binfo
);
3634 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3636 if (TREE_CODE (fields
) != FIELD_DECL
)
3639 TREE_USED (fields
) = 0;
3640 if (DECL_NAME (fields
) == NULL_TREE
3641 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3642 unuse_fields (TREE_TYPE (fields
));
3650 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
);
3656 /* We haven't pushed a search level when dealing with cached classes,
3657 so we'd better not try to pop it. */
3659 search_stack
= pop_search_level (search_stack
);
3663 print_search_statistics ()
3665 #ifdef GATHER_STATISTICS
3666 if (flag_memoize_lookups
)
3668 fprintf (stderr
, "%d memoized contexts saved\n",
3670 fprintf (stderr
, "%d local tree nodes made\n", my_tree_node_counter
);
3671 fprintf (stderr
, "%d local hash nodes made\n", my_memoized_entry_counter
);
3672 fprintf (stderr
, "fields statistics:\n");
3673 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3674 memoized_fast_finds
[0], memoized_fast_rejects
[0],
3675 memoized_fields_searched
[0]);
3676 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[0]);
3677 fprintf (stderr
, "fnfields statistics:\n");
3678 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3679 memoized_fast_finds
[1], memoized_fast_rejects
[1],
3680 memoized_fields_searched
[1]);
3681 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[1]);
3683 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3684 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3685 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3686 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3687 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3688 #else /* GATHER_STATISTICS */
3689 fprintf (stderr
, "no search statistics\n");
3690 #endif /* GATHER_STATISTICS */
3694 init_search_processing ()
3696 gcc_obstack_init (&search_obstack
);
3697 gcc_obstack_init (&type_obstack
);
3698 gcc_obstack_init (&type_obstack_entries
);
3700 /* This gives us room to build our chains of basetypes,
3701 whether or not we decide to memoize them. */
3702 type_stack
= push_type_level ((struct stack_level
*)0, &type_obstack
);
3703 _vptr_name
= get_identifier ("_vptr");
3707 reinit_search_statistics ()
3709 my_memoized_entry_counter
= 0;
3710 memoized_fast_finds
[0] = 0;
3711 memoized_fast_finds
[1] = 0;
3712 memoized_adds
[0] = 0;
3713 memoized_adds
[1] = 0;
3714 memoized_fast_rejects
[0] = 0;
3715 memoized_fast_rejects
[1] = 0;
3716 memoized_fields_searched
[0] = 0;
3717 memoized_fields_searched
[1] = 0;
3718 #ifdef GATHER_STATISTICS
3719 n_fields_searched
= 0;
3720 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3721 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3722 n_calls_get_base_type
= 0;
3723 n_outer_fields_searched
= 0;
3724 n_contexts_saved
= 0;
3725 #endif /* GATHER_STATISTICS */
3728 #define scratch_tree_cons expr_tree_cons
3730 static tree conversions
;
3732 add_conversions (binfo
)
3736 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3738 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3740 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3741 if (! IDENTIFIER_TYPENAME_P (DECL_NAME (tmp
)))
3743 conversions
= scratch_tree_cons (binfo
, tmp
, conversions
);
3745 SET_BINFO_MARKED (binfo
);
3749 lookup_conversions (type
)
3752 conversions
= NULL_TREE
;
3753 if (TYPE_SIZE (type
))
3755 dfs_walk (TYPE_BINFO (type
), add_conversions
, unmarkedp
);
3756 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
);
3761 /* Subroutine of get_template_base. */
3764 get_template_base_recursive (binfo
, rval
, template, via_virtual
)
3765 tree binfo
, template, rval
;
3770 tree type
= BINFO_TYPE (binfo
);
3772 if (CLASSTYPE_TEMPLATE_INFO (type
)
3773 && CLASSTYPE_TI_TEMPLATE (type
) == template)
3775 if (rval
== NULL_TREE
|| rval
== type
)
3778 return error_mark_node
;
3781 binfos
= BINFO_BASETYPES (binfo
);
3782 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3784 /* Process base types. */
3785 for (i
= 0; i
< n_baselinks
; i
++)
3787 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3789 /* Find any specific instance of a virtual base, when searching with
3791 if (BINFO_MARKED (base_binfo
) == 0)
3793 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
3795 /* When searching for a non-virtual, we cannot mark
3796 virtually found binfos. */
3798 SET_BINFO_MARKED (base_binfo
);
3800 rval
= get_template_base_recursive
3801 (base_binfo
, rval
, template, this_virtual
);
3802 if (rval
== error_mark_node
)
3810 /* Given a class template TEMPLATE and a class type or binfo node BINFO,
3811 find the unique base type in BINFO that is an instance of TEMPLATE.
3812 If there are more than one, return error_mark_node. Used by unify. */
3815 get_template_base (template, binfo
)
3816 register tree
template, binfo
;
3818 tree type
= NULL_TREE
, rval
;
3820 if (TREE_CODE (binfo
) == TREE_VEC
)
3821 type
= BINFO_TYPE (binfo
);
3822 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
3824 type
= complete_type (binfo
);
3825 binfo
= TYPE_BINFO (type
);
3828 my_friendly_abort (92);
3830 if (CLASSTYPE_TEMPLATE_INFO (type
)
3831 && CLASSTYPE_TI_TEMPLATE (type
) == template)
3834 rval
= get_template_base_recursive (binfo
, NULL_TREE
, template, 0);
3835 dfs_walk (binfo
, dfs_unmark
, markedp
);
3840 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3841 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3843 static tree compare_type
;
3844 static int found_overlap
;
3846 dfs_check_overlap (empty_binfo
)
3850 for (binfo
= TYPE_BINFO (compare_type
); ; binfo
= BINFO_BASETYPE (binfo
, 0))
3852 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3857 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3862 /* Trivial function to stop base traversal when we find something. */
3865 dfs_no_overlap_yet (t
)
3868 return found_overlap
== 0;
3871 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3872 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3875 types_overlap_p (empty_type
, next_type
)
3876 tree empty_type
, next_type
;
3878 if (! IS_AGGR_TYPE (next_type
))
3880 compare_type
= next_type
;
3882 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
, dfs_no_overlap_yet
);
3883 return found_overlap
;