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 int covariant_return_p
PROTO((tree
, tree
));
135 static struct search_level
*push_search_level
136 PROTO((struct stack_level
*, struct obstack
*));
137 static struct search_level
*pop_search_level
138 PROTO((struct stack_level
*));
139 static struct type_level
*push_type_level
140 PROTO((struct stack_level
*, struct obstack
*));
141 static struct type_level
*pop_type_level
142 PROTO((struct type_level
*));
143 static tree my_tree_cons
PROTO((tree
, tree
, tree
));
144 static tree my_build_string
PROTO((char *));
145 static struct memoized_entry
* my_new_memoized_entry
146 PROTO((struct memoized_entry
*));
147 static HOST_WIDE_INT breadth_first_search
148 PROTO((tree
, int (*) (tree
, int), int (*) (tree
, int)));
150 static tree vbase_types
;
151 static tree vbase_decl_ptr_intermediate
, vbase_decl_ptr
;
152 static tree vbase_init_result
;
154 /* Allocate a level of searching. */
156 static struct search_level
*
157 push_search_level (stack
, obstack
)
158 struct stack_level
*stack
;
159 struct obstack
*obstack
;
161 struct search_level tem
;
164 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
167 /* Discard a level of search allocation. */
169 static struct search_level
*
170 pop_search_level (obstack
)
171 struct stack_level
*obstack
;
173 register struct search_level
*stack
= pop_stack_level (obstack
);
178 /* Search memoization. */
182 struct stack_level base
;
184 /* First object allocated in obstack of entries. */
187 /* Number of types memoized in this context. */
190 /* Type being memoized; save this if we are saving
191 memoized contexts. */
195 /* Obstack used for memoizing member and member function lookup. */
197 static struct obstack type_obstack
, type_obstack_entries
;
198 static struct type_level
*type_stack
;
199 static tree _vptr_name
;
201 /* Make things that look like tree nodes, but allocate them
202 on type_obstack_entries. */
203 static int my_tree_node_counter
;
205 extern int flag_memoize_lookups
, flag_save_memoized_contexts
;
207 /* Variables for gathering statistics. */
208 static int my_memoized_entry_counter
;
209 static int memoized_fast_finds
[2], memoized_adds
[2], memoized_fast_rejects
[2];
210 static int memoized_fields_searched
[2];
211 #ifdef GATHER_STATISTICS
212 static int n_fields_searched
;
213 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
214 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
215 static int n_calls_get_base_type
;
216 static int n_outer_fields_searched
;
217 static int n_contexts_saved
;
218 #endif /* GATHER_STATISTICS */
220 /* Local variables to help save memoization contexts. */
221 static tree prev_type_memoized
;
222 static struct type_level
*prev_type_stack
;
224 /* This list is used by push_class_decls to know what decls need to
225 be pushed into class scope. */
226 static tree closed_envelopes
= NULL_TREE
;
228 /* Allocate a level of type memoization context. */
230 static struct type_level
*
231 push_type_level (stack
, obstack
)
232 struct stack_level
*stack
;
233 struct obstack
*obstack
;
235 struct type_level tem
;
237 tem
.base
.prev
= stack
;
239 obstack_finish (&type_obstack_entries
);
240 tem
.entries
= (char *) obstack_base (&type_obstack_entries
);
242 tem
.type
= NULL_TREE
;
244 return (struct type_level
*)push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
247 /* Discard a level of type memoization context. */
249 static struct type_level
*
250 pop_type_level (stack
)
251 struct type_level
*stack
;
253 obstack_free (&type_obstack_entries
, stack
->entries
);
254 return (struct type_level
*)pop_stack_level ((struct stack_level
*)stack
);
257 /* Make something that looks like a TREE_LIST, but
258 do it on the type_obstack_entries obstack. */
261 my_tree_cons (purpose
, value
, chain
)
262 tree purpose
, value
, chain
;
265 struct obstack
*ambient_obstack
= current_obstack
;
266 current_obstack
= &type_obstack_entries
;
267 p
= tree_cons (purpose
, value
, chain
);
268 current_obstack
= ambient_obstack
;
269 ++my_tree_node_counter
;
274 my_build_string (str
)
277 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_string
));
278 ++my_tree_node_counter
;
281 TREE_SET_CODE (p
, STRING_CST
);
282 TREE_STRING_POINTER (p
) = str
;
283 TREE_STRING_LENGTH (p
) = strlen (str
);
287 /* Memoizing machinery to make searches for multiple inheritance
288 reasonably efficient. */
290 #define MEMOIZE_HASHSIZE 8
291 typedef struct memoized_entry
293 struct memoized_entry
*chain
;
295 tree data_members
[MEMOIZE_HASHSIZE
];
296 tree function_members
[MEMOIZE_HASHSIZE
];
299 #define MEMOIZED_CHAIN(ENTRY) (((ME)ENTRY)->chain)
300 #define MEMOIZED_UID(ENTRY) (((ME)ENTRY)->uid)
301 #define MEMOIZED_FIELDS(ENTRY,INDEX) (((ME)ENTRY)->data_members[INDEX])
302 #define MEMOIZED_FNFIELDS(ENTRY,INDEX) (((ME)ENTRY)->function_members[INDEX])
303 /* The following is probably a lousy hash function. */
304 #define MEMOIZED_HASH_FN(NODE) (((long)(NODE)>>4)&(MEMOIZE_HASHSIZE - 1))
306 static struct memoized_entry
*
307 my_new_memoized_entry (chain
)
308 struct memoized_entry
*chain
;
310 struct memoized_entry
*p
311 = (struct memoized_entry
*)obstack_alloc (&type_obstack_entries
,
312 sizeof (struct memoized_entry
));
313 bzero ((char *) p
, sizeof (struct memoized_entry
));
314 MEMOIZED_CHAIN (p
) = chain
;
315 MEMOIZED_UID (p
) = ++my_memoized_entry_counter
;
319 /* Clears the deferred pop from pop_memoized_context, if any. */
322 clear_memoized_cache ()
326 type_stack
= pop_type_level (prev_type_stack
);
327 prev_type_memoized
= 0;
332 /* Make an entry in the memoized table for type TYPE
333 that the entry for NAME is FIELD. */
336 make_memoized_table_entry (type
, name
, function_p
)
340 int idx
= MEMOIZED_HASH_FN (name
);
341 tree entry
, *prev_entry
;
343 /* Since we allocate from the type_obstack, we must pop any deferred
345 clear_memoized_cache ();
347 memoized_adds
[function_p
] += 1;
348 if (CLASSTYPE_MTABLE_ENTRY (type
) == 0)
350 obstack_ptr_grow (&type_obstack
, type
);
351 obstack_blank (&type_obstack
, sizeof (struct memoized_entry
*));
352 CLASSTYPE_MTABLE_ENTRY (type
) = (char *)my_new_memoized_entry ((struct memoized_entry
*)0);
354 if (type_stack
->len
* 2 >= type_stack
->base
.limit
)
355 my_friendly_abort (88);
358 prev_entry
= &MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
360 prev_entry
= &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
362 entry
= my_tree_cons (name
, NULL_TREE
, *prev_entry
);
365 /* Don't know the error message to give yet. */
366 TREE_TYPE (entry
) = error_mark_node
;
371 /* When a new function or class context is entered, we build
372 a table of types which have been searched for members.
373 The table is an array (obstack) of types. When a type is
374 entered into the obstack, its CLASSTYPE_MTABLE_ENTRY
375 field is set to point to a new record, of type struct memoized_entry.
377 A non-NULL TREE_TYPE of the entry contains an access control error message.
379 The slots for the data members are arrays of tree nodes.
380 These tree nodes are lists, with the TREE_PURPOSE
381 of this list the known member name, and the TREE_VALUE
382 as the FIELD_DECL for the member.
384 For member functions, the TREE_PURPOSE is again the
385 name of the member functions for that class,
386 and the TREE_VALUE of the list is a pairs
387 whose TREE_PURPOSE is a member functions of this name,
388 and whose TREE_VALUE is a list of known argument lists this
389 member function has been called with. The TREE_TYPE of the pair,
390 if non-NULL, is an error message to print. */
392 /* Tell search machinery that we are entering a new context, and
393 to update tables appropriately.
395 TYPE is the type of the context we are entering, which can
396 be NULL_TREE if we are not in a class's scope.
398 USE_OLD, if nonzero tries to use previous context. */
401 push_memoized_context (type
, use_old
)
410 if (use_old
&& prev_type_memoized
== type
)
412 #ifdef GATHER_STATISTICS
414 #endif /* GATHER_STATISTICS */
415 type_stack
= prev_type_stack
;
418 tem
= &type_stack
->base
.first
[0];
419 len
= type_stack
->len
;
421 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]) = (char *)tem
[len
*2+1];
424 /* Otherwise, need to pop old stack here. */
425 clear_memoized_cache ();
428 type_stack
= push_type_level ((struct stack_level
*)type_stack
,
430 type_stack
->type
= type
;
433 /* Tell search machinery that we have left a context.
434 We do not currently save these contexts for later use.
435 If we wanted to, we could not use pop_search_level, since
436 poping that level allows the data we have collected to
437 be clobbered; a stack of obstacks would be needed. */
440 pop_memoized_context (use_old
)
444 tree
*tem
= &type_stack
->base
.first
[0];
446 if (! flag_save_memoized_contexts
)
450 len
= type_stack
->len
;
452 tem
[len
*2+1] = (tree
)CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]);
454 /* If there was a deferred pop, we need to pop it now. */
455 clear_memoized_cache ();
457 prev_type_stack
= type_stack
;
458 prev_type_memoized
= type_stack
->type
;
461 if (flag_memoize_lookups
)
463 len
= type_stack
->len
;
465 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2])
466 = (char *)MEMOIZED_CHAIN (CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]));
469 type_stack
= pop_type_level (type_stack
);
471 type_stack
= (struct type_level
*)type_stack
->base
.prev
;
474 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
475 the same type as the type given in PARENT. To be optimal, we want
476 the first one that is found by going through the least number of
480 get_vbase_1 (parent
, binfo
, depth
)
486 tree rval
= NULL_TREE
;
488 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
496 binfos
= BINFO_BASETYPES (binfo
);
497 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
499 /* Process base types. */
500 for (i
= 0; i
< n_baselinks
; i
++)
502 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
508 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
517 get_vbase (parent
, binfo
)
521 unsigned int d
= (unsigned int)-1;
522 return get_vbase_1 (parent
, binfo
, &d
);
525 /* Convert EXPR to a virtual base class of type TYPE. We know that
526 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
527 the type of what expr points to has a virtual base of type TYPE. */
530 convert_pointer_to_vbase (type
, expr
)
534 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
535 return convert_pointer_to_real (vb
, expr
);
538 /* Check whether the type given in BINFO is derived from PARENT. If
539 it isn't, return 0. If it is, but the derivation is MI-ambiguous
540 AND protect != 0, emit an error message and return error_mark_node.
542 Otherwise, if TYPE is derived from PARENT, return the actual base
543 information, unless a one of the protection violations below
544 occurs, in which case emit an error message and return error_mark_node.
546 If PROTECT is 1, then check if access to a public field of PARENT
547 would be private. Also check for ambiguity. */
550 get_binfo (parent
, binfo
, protect
)
551 register tree parent
, binfo
;
554 tree type
= NULL_TREE
;
556 tree rval
= NULL_TREE
;
558 if (TREE_CODE (parent
) == TREE_VEC
)
559 parent
= BINFO_TYPE (parent
);
560 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
561 my_friendly_abort (89);
563 if (TREE_CODE (binfo
) == TREE_VEC
)
564 type
= BINFO_TYPE (binfo
);
565 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
568 my_friendly_abort (90);
570 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
574 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
576 return error_mark_node
;
578 else if (dist
== -2 && protect
)
580 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
582 return error_mark_node
;
588 /* This is the newer depth first get_base_distance routine. */
591 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
592 rval_private_ptr
, new_binfo_ptr
, parent
, path_ptr
,
593 protect
, via_virtual_ptr
, via_virtual
,
594 current_scope_in_chain
)
596 int depth
, is_private
, rval
;
597 int *rval_private_ptr
;
598 tree
*new_binfo_ptr
, parent
, *path_ptr
;
599 int protect
, *via_virtual_ptr
, via_virtual
;
600 int current_scope_in_chain
;
606 && !current_scope_in_chain
607 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
608 current_scope_in_chain
= 1;
610 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
615 *rval_private_ptr
= is_private
;
616 *new_binfo_ptr
= binfo
;
617 *via_virtual_ptr
= via_virtual
;
621 int same_object
= (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
622 BINFO_OFFSET (binfo
))
623 && *via_virtual_ptr
&& via_virtual
);
625 if (*via_virtual_ptr
&& via_virtual
==0)
627 *rval_private_ptr
= is_private
;
628 *new_binfo_ptr
= binfo
;
629 *via_virtual_ptr
= via_virtual
;
631 else if (same_object
)
633 if (*rval_private_ptr
&& ! is_private
)
635 *rval_private_ptr
= is_private
;
636 *new_binfo_ptr
= binfo
;
637 *via_virtual_ptr
= via_virtual
;
647 binfos
= BINFO_BASETYPES (binfo
);
648 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
651 /* Process base types. */
652 for (i
= 0; i
< n_baselinks
; i
++)
654 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
656 /* Find any specific instance of a virtual base, when searching with
658 if (BINFO_MARKED (base_binfo
) == 0 || TREE_CODE (parent
) == TREE_VEC
)
663 || (!TREE_VIA_PUBLIC (base_binfo
)
664 && !(TREE_VIA_PROTECTED (base_binfo
)
665 && current_scope_in_chain
)
666 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
667 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
670 /* When searching for a non-virtual, we cannot mark
671 virtually found binfos. */
673 SET_BINFO_MARKED (base_binfo
);
675 #define WATCH_VALUES(rval, via_private) (rval == -1 ? 3 : via_private)
677 was
= WATCH_VALUES (rval
, *via_virtual_ptr
);
678 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
679 rval
, rval_private_ptr
,
680 new_binfo_ptr
, parent
, path_ptr
,
681 protect
, via_virtual_ptr
,
683 current_scope_in_chain
);
684 /* watch for updates; only update if path is good. */
685 if (path_ptr
&& WATCH_VALUES (rval
, *via_virtual_ptr
) != was
)
686 BINFO_INHERITANCE_CHAIN (base_binfo
) = binfo
;
687 if (rval
== -2 && *via_virtual_ptr
== 0)
698 /* Return the number of levels between type PARENT and the type given
699 in BINFO, following the leftmost path to PARENT not found along a
700 virtual path, if there are no real PARENTs (all come from virtual
701 base classes), then follow the leftmost path to PARENT.
703 Return -1 if TYPE is not derived from PARENT.
704 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
706 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
708 If PATH_PTR is non-NULL, then also build the list of types
709 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
712 PARENT can also be a binfo, in which case that exact parent is found
713 and no other. convert_pointer_to_real uses this functionality.
715 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
718 get_base_distance (parent
, binfo
, protect
, path_ptr
)
719 register tree parent
, binfo
;
724 int rval_private
= 0;
725 tree type
= NULL_TREE
;
726 tree new_binfo
= NULL_TREE
;
728 int watch_access
= protect
;
730 /* Should we be completing types here? */
731 if (TREE_CODE (parent
) != TREE_VEC
)
732 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
734 complete_type (TREE_TYPE (parent
));
736 if (TREE_CODE (binfo
) == TREE_VEC
)
737 type
= BINFO_TYPE (binfo
);
738 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
740 type
= complete_type (binfo
);
741 binfo
= TYPE_BINFO (type
);
744 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
747 my_friendly_abort (92);
749 if (parent
== type
|| parent
== binfo
)
751 /* If the distance is 0, then we don't really need
752 a path pointer, but we shouldn't let garbage go back. */
761 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
762 &rval_private
, &new_binfo
, parent
,
763 path_ptr
, watch_access
, &via_virtual
, 0,
766 dfs_walk (binfo
, dfs_unmark
, markedp
);
768 /* Access restrictions don't count if we found an ambiguous basetype. */
769 if (rval
== -2 && protect
>= 0)
772 if (rval
&& protect
&& rval_private
)
775 /* find real virtual base classes. */
776 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
777 && parent
== binfo_member (BINFO_TYPE (parent
),
778 CLASSTYPE_VBASECLASSES (type
)))
780 BINFO_INHERITANCE_CHAIN (parent
) = binfo
;
786 *path_ptr
= new_binfo
;
790 /* Search for a member with name NAME in a multiple inheritance lattice
791 specified by TYPE. If it does not exist, return NULL_TREE.
792 If the member is ambiguously referenced, return `error_mark_node'.
793 Otherwise, return the FIELD_DECL. */
795 /* Do a 1-level search for NAME as a member of TYPE. The caller must
796 figure out whether it can access this field. (Since it is only one
797 level, this is reasonable.) */
800 lookup_field_1 (type
, name
)
805 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
806 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
807 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
808 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
809 the code often worked even when we treated the index as a list
813 field
= TYPE_FIELDS (type
);
815 #ifdef GATHER_STATISTICS
816 n_calls_lookup_field_1
++;
817 #endif /* GATHER_STATISTICS */
820 #ifdef GATHER_STATISTICS
822 #endif /* GATHER_STATISTICS */
823 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
824 if (DECL_NAME (field
) == NULL_TREE
825 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
827 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
831 if (DECL_NAME (field
) == name
)
833 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
834 && DECL_ASSEMBLER_NAME (field
) != NULL
)
835 GNU_xref_ref(current_function_decl
,
836 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
839 field
= TREE_CHAIN (field
);
842 if (name
== _vptr_name
)
844 /* Give the user what s/he thinks s/he wants. */
845 if (TYPE_VIRTUAL_P (type
))
846 return CLASSTYPE_VFIELD (type
);
851 /* There are a number of cases we need to be aware of here:
852 current_class_type current_function_decl
859 Those last two make life interesting. If we're in a function which is
860 itself inside a class, we need decls to go into the fn's decls (our
861 second case below). But if we're in a class and the class itself is
862 inside a function, we need decls to go into the decls for the class. To
863 achieve this last goal, we must see if, when both current_class_ptr and
864 current_function_decl are set, the class was declared inside that
865 function. If so, we know to put the decls into the class's scope. */
870 if (current_function_decl
== NULL_TREE
)
871 return current_class_type
;
872 if (current_class_type
== NULL_TREE
)
873 return current_function_decl
;
874 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
875 return current_function_decl
;
877 return current_class_type
;
880 /* Compute the access of FIELD. This is done by computing
881 the access available to each type in BASETYPES (which comes
882 as a list of [via_public/basetype] in reverse order, namely base
883 class before derived class). The first one which defines a
884 access defines the access for the field. Otherwise, the
885 access of the field is that which occurs normally.
887 Uses global variables CURRENT_CLASS_TYPE and
888 CURRENT_FUNCTION_DECL to use friend relationships
891 This will be static when lookup_fnfield comes into this file.
893 access_public_node means that the field can be accessed by the current lexical
896 access_protected_node means that the field cannot be accessed by the current
897 lexical scope because it is protected.
899 access_private_node means that the field cannot be accessed by the current
900 lexical scope because it is private. */
903 #define PUBLIC_RETURN return (DECL_PUBLIC (field) = 1), access_public_node
904 #define PROTECTED_RETURN return (DECL_PROTECTED (field) = 1), access_protected_node
905 #define PRIVATE_RETURN return (DECL_PRIVATE (field) = 1), access_private_node
907 #define PUBLIC_RETURN return access_public_node
908 #define PROTECTED_RETURN return access_protected_node
909 #define PRIVATE_RETURN return access_private_node
913 /* Disabled with DECL_PUBLIC &c. */
914 static tree previous_scope
= NULL_TREE
;
918 compute_access (basetype_path
, field
)
919 tree basetype_path
, field
;
924 int protected_ok
, via_protected
;
925 extern int flag_access_control
;
927 /* Replaces static decl above. */
931 = ((TREE_CODE (field
) == FUNCTION_DECL
&& DECL_STATIC_FUNCTION_P (field
))
932 || (TREE_CODE (field
) != FUNCTION_DECL
&& TREE_STATIC (field
)));
934 if (! flag_access_control
)
935 return access_public_node
;
937 /* The field lives in the current class. */
938 if (BINFO_TYPE (basetype_path
) == current_class_type
)
939 return access_public_node
;
942 /* Disabled until pushing function scope clears these out. If ever. */
943 /* Make these special cases fast. */
944 if (current_scope () == previous_scope
)
946 if (DECL_PUBLIC (field
))
947 return access_public_node
;
948 if (DECL_PROTECTED (field
))
949 return access_protected_node
;
950 if (DECL_PRIVATE (field
))
951 return access_private_node
;
955 /* We don't currently support access control on nested types. */
956 if (TREE_CODE (field
) == TYPE_DECL
)
957 return access_public_node
;
959 previous_scope
= current_scope ();
961 context
= DECL_REAL_CONTEXT (field
);
963 /* Fields coming from nested anonymous unions have their DECL_CLASS_CONTEXT
964 slot set to the union type rather than the record type containing
965 the anonymous union. */
966 if (context
&& ANON_UNION_TYPE_P (context
)
967 && TREE_CODE (field
) == FIELD_DECL
)
968 context
= TYPE_CONTEXT (context
);
970 /* Virtual function tables are never private. But we should know that
971 we are looking for this, and not even try to hide it. */
972 if (DECL_NAME (field
) && VFIELD_NAME_P (DECL_NAME (field
)) == 1)
975 /* Member found immediately within object. */
976 if (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
)
978 /* Are we (or an enclosing scope) friends with the class that has
980 if (is_friend (context
, previous_scope
))
983 /* If it's private, it's private, you letch. */
984 if (TREE_PRIVATE (field
))
987 /* ARM $11.5. Member functions of a derived class can access the
988 non-static protected members of a base class only through a
989 pointer to the derived class, a reference to it, or an object
990 of it. Also any subsequently derived classes also have
992 else if (TREE_PROTECTED (field
))
994 if (current_class_type
995 && (static_mem
|| DECL_CONSTRUCTOR_P (field
))
996 && ACCESSIBLY_DERIVED_FROM_P (context
, current_class_type
))
1005 /* must reverse more than one element */
1006 basetype_path
= reverse_path (basetype_path
, /*copy=*/0);
1007 types
= basetype_path
;
1009 access
= access_default_node
;
1010 protected_ok
= static_mem
&& current_class_type
1011 && ACCESSIBLY_DERIVED_FROM_P (BINFO_TYPE (types
), current_class_type
);
1017 tree type
= BINFO_TYPE (binfo
);
1020 /* Friends of a class can see protected members of its bases.
1021 Note that classes are their own friends. */
1022 if (is_friend (type
, previous_scope
))
1028 member
= purpose_member (type
, DECL_ACCESS (field
));
1031 access
= TREE_VALUE (member
);
1035 types
= BINFO_INHERITANCE_CHAIN (types
);
1037 /* If the next type was VIA_PROTECTED, then fields of all remaining
1038 classes past that one are *at least* protected. */
1041 if (TREE_VIA_PROTECTED (types
))
1043 else if (! TREE_VIA_PUBLIC (types
) && ! private_ok
)
1045 access
= access_private_node
;
1052 reverse_path (basetype_path
, /*copy=*/0);
1054 /* No special visibilities apply. Use normal rules. */
1056 if (access
== access_default_node
)
1058 if (is_friend (context
, previous_scope
))
1059 access
= access_public_node
;
1060 else if (TREE_PRIVATE (field
))
1061 access
= access_private_node
;
1062 else if (TREE_PROTECTED (field
))
1063 access
= access_protected_node
;
1065 access
= access_public_node
;
1068 if (access
== access_public_node
&& via_protected
)
1069 access
= access_protected_node
;
1071 if (access
== access_protected_node
&& protected_ok
)
1072 access
= access_public_node
;
1075 if (access
== access_public_node
)
1076 DECL_PUBLIC (field
) = 1;
1077 else if (access
== access_protected_node
)
1078 DECL_PROTECTED (field
) = 1;
1079 else if (access
== access_private_node
)
1080 DECL_PRIVATE (field
) = 1;
1081 else my_friendly_abort (96);
1086 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1087 found as a base class and sub-object of the object denoted by
1088 BINFO. This routine relies upon binfos not being shared, except
1089 for binfos for virtual bases. */
1092 is_subobject_of_p (parent
, binfo
)
1095 tree binfos
= BINFO_BASETYPES (binfo
);
1096 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1098 if (parent
== binfo
)
1101 /* Process and/or queue base types. */
1102 for (i
= 0; i
< n_baselinks
; i
++)
1104 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1105 if (TREE_VIA_VIRTUAL (base_binfo
))
1106 base_binfo
= TYPE_BINFO (BINFO_TYPE (base_binfo
));
1107 if (is_subobject_of_p (parent
, base_binfo
))
1113 /* See if a one FIELD_DECL hides another. This routine is meant to
1114 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1115 binfos given are the binfos corresponding to the particular places
1116 the FIELD_DECLs are found. This routine relies upon binfos not
1117 being shared, except for virtual bases. */
1120 hides (hider_binfo
, hidee_binfo
)
1121 tree hider_binfo
, hidee_binfo
;
1123 /* hider hides hidee, if hider has hidee as a base class and
1124 the instance of hidee is a sub-object of hider. The first
1125 part is always true is the second part is true.
1127 When hider and hidee are the same (two ways to get to the exact
1128 same member) we consider either one as hiding the other. */
1129 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
1132 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1133 function was declared inside the class given by TYPE. It really should
1134 only return functions that match the given TYPE. */
1137 lookup_fnfields_here (type
, name
)
1140 int idx
= lookup_fnfields_1 (type
, name
);
1143 /* ctors and dtors are always only in the right class. */
1146 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1149 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls
)))
1150 == TYPE_MAIN_VARIANT (type
))
1152 fndecls
= OVL_CHAIN (fndecls
);
1157 /* Look for a field named NAME in an inheritance lattice dominated by
1158 XBASETYPE. PROTECT is zero if we can avoid computing access
1159 information, otherwise it is 1. WANT_TYPE is 1 when we should only
1160 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
1162 It was not clear what should happen if WANT_TYPE is set, and an
1163 ambiguity is found. At least one use (lookup_name) to not see
1167 lookup_field (xbasetype
, name
, protect
, want_type
)
1168 register tree xbasetype
, name
;
1169 int protect
, want_type
;
1171 int head
= 0, tail
= 0;
1172 tree rval
, rval_binfo
= NULL_TREE
, rval_binfo_h
= NULL_TREE
;
1173 tree type
= NULL_TREE
, basetype_chain
, basetype_path
= NULL_TREE
;
1174 tree this_v
= access_default_node
;
1175 tree entry
, binfo
, binfo_h
;
1176 tree own_access
= access_default_node
;
1177 int vbase_name_p
= VBASE_NAME_P (name
);
1179 /* rval_binfo is the binfo associated with the found member, note,
1180 this can be set with useful information, even when rval is not
1181 set, because it must deal with ALL members, not just non-function
1182 members. It is used for ambiguity checking and the hidden
1183 checks. Whereas rval is only set if a proper (not hidden)
1184 non-function member is found. */
1186 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1187 hiding checks, as virtual base classes may not be shared. The strategy
1188 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1189 virtual base classes, as we cross virtual base class lines. This way
1190 we know that binfo of a virtual base class will always == itself when
1191 found along any line. (mrs) */
1195 /* Set this to nonzero if we don't know how to compute
1196 accurate error messages for access control. */
1197 int idx
= MEMOIZED_HASH_FN (name
);
1200 /* We cannot search for constructor/destructor names like this. */
1201 /* This can't go here, but where should it go? */
1202 /* If we are looking for a constructor in a templated type, use the
1203 unspecialized name, as that is how we store it. */
1204 if (IDENTIFIER_TEMPLATE (name
))
1205 name
= constructor_name (name
);
1208 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1209 && IDENTIFIER_CLASS_VALUE (name
))
1211 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1212 if (TREE_CODE (field
) != FUNCTION_DECL
1213 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1217 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1219 type
= BINFO_TYPE (xbasetype
);
1220 basetype_path
= xbasetype
;
1222 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1225 basetype_path
= TYPE_BINFO (type
);
1226 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1229 my_friendly_abort (97);
1231 complete_type (type
);
1233 if (CLASSTYPE_MTABLE_ENTRY (type
))
1235 tree tem
= MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
1237 while (tem
&& TREE_PURPOSE (tem
) != name
)
1239 memoized_fields_searched
[0]++;
1240 tem
= TREE_CHAIN (tem
);
1244 if (protect
&& TREE_TYPE (tem
))
1246 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1247 IDENTIFIER_POINTER (name
),
1248 TYPE_NAME_STRING (DECL_FIELD_CONTEXT (TREE_VALUE (tem
))));
1249 return error_mark_node
;
1251 if (TREE_VALUE (tem
) == NULL_TREE
)
1252 memoized_fast_rejects
[0] += 1;
1254 memoized_fast_finds
[0] += 1;
1255 return TREE_VALUE (tem
);
1259 #ifdef GATHER_STATISTICS
1260 n_calls_lookup_field
++;
1261 #endif /* GATHER_STATISTICS */
1262 if (protect
&& flag_memoize_lookups
&& ! toplevel_bindings_p ())
1263 entry
= make_memoized_table_entry (type
, name
, 0);
1267 rval
= lookup_field_1 (type
, name
);
1269 if (rval
|| lookup_fnfields_here (type
, name
) >= 0)
1272 TREE_VALUE (entry
) = rval
;
1278 if (TREE_CODE (rval
) != TYPE_DECL
)
1280 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
1282 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
1287 if (TREE_CODE (rval
) == TYPE_DECL
1288 && lookup_fnfields_here (type
, name
) >= 0)
1293 if (protect
&& rval
)
1295 if (TREE_PRIVATE (rval
) | TREE_PROTECTED (rval
))
1296 this_v
= compute_access (basetype_path
, rval
);
1297 if (TREE_CODE (rval
) == CONST_DECL
)
1299 if (this_v
== access_private_node
)
1300 errstr
= "enum `%D' is a private value of class `%T'";
1301 else if (this_v
== access_protected_node
)
1302 errstr
= "enum `%D' is a protected value of class `%T'";
1306 if (this_v
== access_private_node
)
1307 errstr
= "member `%D' is a private member of class `%T'";
1308 else if (this_v
== access_protected_node
)
1309 errstr
= "member `%D' is a protected member of class `%T'";
1313 rval_binfo
= basetype_path
;
1317 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
1318 TREE_VIA_PUBLIC (basetype_chain
) = TREE_VIA_PUBLIC (basetype_path
);
1319 TREE_VIA_PROTECTED (basetype_chain
) = TREE_VIA_PROTECTED (basetype_path
);
1320 TREE_VIA_VIRTUAL (basetype_chain
) = TREE_VIA_VIRTUAL (basetype_path
);
1322 /* The ambiguity check relies upon breadth first searching. */
1324 search_stack
= push_search_level (search_stack
, &search_obstack
);
1325 binfo
= basetype_path
;
1330 tree binfos
= BINFO_BASETYPES (binfo
);
1331 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1334 /* Process and/or queue base types. */
1335 for (i
= 0; i
< n_baselinks
; i
++)
1337 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1338 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1342 SET_BINFO_FIELDS_MARKED (base_binfo
);
1343 btypes
= my_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1344 TREE_VIA_PUBLIC (btypes
) = TREE_VIA_PUBLIC (base_binfo
);
1345 TREE_VIA_PROTECTED (btypes
) = TREE_VIA_PROTECTED (base_binfo
);
1346 TREE_VIA_VIRTUAL (btypes
) = TREE_VIA_VIRTUAL (base_binfo
);
1347 if (TREE_VIA_VIRTUAL (base_binfo
))
1348 btypes
= my_tree_cons (NULL_TREE
,
1349 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1352 btypes
= my_tree_cons (NULL_TREE
,
1353 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1355 obstack_ptr_grow (&search_obstack
, btypes
);
1357 if (tail
>= search_stack
->limit
)
1358 my_friendly_abort (98);
1362 /* Process head of queue, if one exists. */
1366 basetype_chain
= search_stack
->first
[head
++];
1367 binfo_h
= TREE_VALUE (basetype_chain
);
1368 basetype_chain
= TREE_CHAIN (basetype_chain
);
1369 basetype_path
= TREE_VALUE (basetype_chain
);
1370 if (TREE_CHAIN (basetype_chain
))
1371 BINFO_INHERITANCE_CHAIN (basetype_path
) = TREE_VALUE (TREE_CHAIN (basetype_chain
));
1373 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1375 binfo
= basetype_path
;
1376 type
= BINFO_TYPE (binfo
);
1378 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1379 and we do find NAME in TYPE, verify that such a second
1380 sighting is in fact valid. */
1382 nval
= lookup_field_1 (type
, name
);
1384 if (nval
|| lookup_fnfields_here (type
, name
)>=0)
1386 if (nval
&& nval
== rval
&& SHARED_MEMBER_P (nval
))
1388 /* This is ok, the member found is the same [class.ambig] */
1390 else if (rval_binfo
&& hides (rval_binfo_h
, binfo_h
))
1392 /* This is ok, the member found is in rval_binfo, not
1395 else if (rval_binfo
==NULL_TREE
|| hides (binfo_h
, rval_binfo_h
))
1397 /* This is ok, the member found is here (binfo), not in
1402 if (entry
|| protect
)
1403 this_v
= compute_access (basetype_path
, rval
);
1404 /* These may look ambiguous, but they really are not. */
1410 /* Undo finding it before, as something else hides it. */
1414 rval_binfo_h
= binfo_h
;
1418 /* This is ambiguous. */
1419 errstr
= "request for member `%D' is ambiguous";
1426 tree
*tp
= search_stack
->first
;
1427 tree
*search_tail
= tp
+ tail
;
1430 TREE_VALUE (entry
) = rval
;
1434 type
= BINFO_TYPE (rval_binfo
);
1440 if (TREE_CODE (rval
) != TYPE_DECL
)
1442 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
1444 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
1449 if (TREE_CODE (rval
) == TYPE_DECL
1450 && lookup_fnfields_here (type
, name
) >= 0)
1456 if (rval
== NULL_TREE
)
1459 /* If this FIELD_DECL defines its own access level, deal with that. */
1460 if (rval
&& errstr
== 0
1461 && ((protect
&1) || entry
)
1462 && DECL_LANG_SPECIFIC (rval
)
1463 && DECL_ACCESS (rval
))
1465 while (tp
< search_tail
)
1467 /* If is possible for one of the derived types on the path to
1468 have defined special access for this field. Look for such
1469 declarations and report an error if a conflict is found. */
1470 tree new_v
= NULL_TREE
;
1472 if (this_v
!= access_default_node
)
1473 new_v
= compute_access (TREE_VALUE (TREE_CHAIN (*tp
)), rval
);
1474 if (this_v
!= access_default_node
&& new_v
!= this_v
)
1476 errstr
= "conflicting access to member `%D'";
1477 this_v
= access_default_node
;
1480 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1486 while (tp
< search_tail
)
1488 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1493 search_stack
= pop_search_level (search_stack
);
1497 if (own_access
== access_private_node
)
1498 errstr
= "member `%D' declared private";
1499 else if (own_access
== access_protected_node
)
1500 errstr
= "member `%D' declared protected";
1501 else if (this_v
== access_private_node
)
1502 errstr
= TREE_PRIVATE (rval
)
1503 ? "member `%D' is private"
1504 : "member `%D' is from private base class";
1505 else if (this_v
== access_protected_node
)
1506 errstr
= TREE_PROTECTED (rval
)
1507 ? "member `%D' is protected"
1508 : "member `%D' is from protected base class";
1516 tree error_string
= my_build_string (errstr
);
1517 /* Save error message with entry. */
1518 TREE_TYPE (entry
) = error_string
;
1522 /* Mark entry as having no error string. */
1523 TREE_TYPE (entry
) = NULL_TREE
;
1529 /* If we are not interested in ambiguities, don't report them,
1530 just return NULL_TREE. */
1535 if (errstr
&& protect
)
1537 cp_error (errstr
, name
, type
);
1538 rval
= error_mark_node
;
1541 /* Do implicit typename stuff. */
1542 if (rval
&& TREE_CODE (rval
) == TYPE_DECL
1543 && ! DECL_ARTIFICIAL (rval
)
1544 && processing_template_decl
1545 && ! currently_open_class (BINFO_TYPE (rval_binfo
))
1546 && uses_template_parms (type
))
1549 for (; ; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
1550 if (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
1551 || (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
))
1552 == current_class_type
))
1555 entry
= make_typename_type (BINFO_TYPE (binfo
), name
);
1556 TREE_TYPE (entry
) = TREE_TYPE (rval
);
1557 rval
= TYPE_MAIN_DECL (entry
);
1563 /* Try to find NAME inside a nested class. */
1566 lookup_nested_field (name
, complain
)
1572 tree id
= NULL_TREE
;
1573 if (TYPE_MAIN_DECL (current_class_type
))
1575 /* Climb our way up the nested ladder, seeing if we're trying to
1576 modify a field in an enclosing class. If so, we should only
1577 be able to modify if it's static. */
1578 for (t
= TYPE_MAIN_DECL (current_class_type
);
1579 t
&& DECL_CONTEXT (t
);
1580 t
= TYPE_MAIN_DECL (DECL_CONTEXT (t
)))
1582 if (TREE_CODE (DECL_CONTEXT (t
)) != RECORD_TYPE
)
1585 /* N.B.: lookup_field will do the access checking for us */
1586 id
= lookup_field (DECL_CONTEXT (t
), name
, complain
, 0);
1587 if (id
== error_mark_node
)
1593 if (id
!= NULL_TREE
)
1595 if (TREE_CODE (id
) == FIELD_DECL
1596 && ! TREE_STATIC (id
)
1597 && TREE_TYPE (id
) != error_mark_node
)
1601 /* At parse time, we don't want to give this error, since
1602 we won't have enough state to make this kind of
1603 decision properly. But there are times (e.g., with
1604 enums in nested classes) when we do need to call
1605 this fn at parse time. So, in those cases, we pass
1606 complain as a 0 and just return a NULL_TREE. */
1607 cp_error ("assignment to non-static member `%D' of enclosing class `%T'",
1608 id
, DECL_CONTEXT (t
));
1609 /* Mark this for do_identifier(). It would otherwise
1610 claim that the variable was undeclared. */
1611 TREE_TYPE (id
) = error_mark_node
;
1627 /* TYPE is a class type. Return the index of the fields within
1628 the method vector with name NAME, or -1 is no such field exists. */
1631 lookup_fnfields_1 (type
, name
)
1634 register tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1636 if (method_vec
!= 0)
1638 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1639 register tree
*end
= TREE_VEC_END (method_vec
);
1641 #ifdef GATHER_STATISTICS
1642 n_calls_lookup_fnfields_1
++;
1643 #endif /* GATHER_STATISTICS */
1645 /* Constructors are first... */
1646 if (*methods
&& name
== ctor_identifier
)
1649 /* and destructors are second. */
1650 if (*++methods
&& name
== dtor_identifier
)
1653 while (++methods
!= end
)
1655 #ifdef GATHER_STATISTICS
1656 n_outer_fields_searched
++;
1657 #endif /* GATHER_STATISTICS */
1658 if (DECL_NAME (OVL_CURRENT (*methods
)) == name
)
1662 /* If we didn't find it, it might have been a template
1663 conversion operator. (Note that we don't look for this case
1664 above so that we will always find specializations first.) */
1666 && IDENTIFIER_TYPENAME_P (name
))
1668 methods
= &TREE_VEC_ELT (method_vec
, 0) + 1;
1670 while (++methods
!= end
)
1672 if (TREE_CODE (OVL_CURRENT (*methods
)) == TEMPLATE_DECL
1673 && IDENTIFIER_TYPENAME_P (DECL_NAME (OVL_CURRENT (*methods
))))
1679 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1685 /* Starting from BASETYPE, return a TREE_BASELINK-like object
1686 which gives the following information (in a list):
1688 TREE_TYPE: list of basetypes needed to get to...
1689 TREE_VALUE: list of all functions in a given type
1690 which have name NAME.
1692 No access information is computed by this function,
1693 other then to adorn the list of basetypes with
1696 If there are two ways to find a name (two members), if COMPLAIN is
1697 non-zero, then error_mark_node is returned, and an error message is
1698 printed, otherwise, just an error_mark_node is returned.
1700 As a special case, is COMPLAIN is -1, we don't complain, and we
1701 don't return error_mark_node, but rather the complete list of
1702 virtuals. This is used by get_virtuals_named_this. */
1705 lookup_fnfields (basetype_path
, name
, complain
)
1706 tree basetype_path
, name
;
1709 int head
= 0, tail
= 0;
1710 tree type
, rval
, rval_binfo
= NULL_TREE
, rvals
= NULL_TREE
;
1711 tree rval_binfo_h
= NULL_TREE
, entry
, binfo
, basetype_chain
, binfo_h
;
1714 /* rval_binfo is the binfo associated with the found member, note,
1715 this can be set with useful information, even when rval is not
1716 set, because it must deal with ALL members, not just function
1717 members. It is used for ambiguity checking and the hidden
1718 checks. Whereas rval is only set if a proper (not hidden)
1719 function member is found. */
1721 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1722 hiding checks, as virtual base classes may not be shared. The strategy
1723 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1724 virtual base classes, as we cross virtual base class lines. This way
1725 we know that binfo of a virtual base class will always == itself when
1726 found along any line. (mrs) */
1728 /* For now, don't try this. */
1729 int protect
= complain
;
1733 /* Set this to nonzero if we don't know how to compute
1734 accurate error messages for access control. */
1735 int idx
= MEMOIZED_HASH_FN (name
);
1740 protect
= complain
= 0;
1744 /* We cannot search for constructor/destructor names like this. */
1745 /* This can't go here, but where should it go? */
1746 /* If we are looking for a constructor in a templated type, use the
1747 unspecialized name, as that is how we store it. */
1748 if (IDENTIFIER_TEMPLATE (name
))
1749 name
= constructor_name (name
);
1752 binfo
= basetype_path
;
1754 type
= complete_type (BINFO_TYPE (basetype_path
));
1756 /* The memoization code is in need of maintenance. */
1757 if (!find_all
&& CLASSTYPE_MTABLE_ENTRY (type
))
1759 tree tem
= MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
1761 while (tem
&& TREE_PURPOSE (tem
) != name
)
1763 memoized_fields_searched
[1]++;
1764 tem
= TREE_CHAIN (tem
);
1768 if (protect
&& TREE_TYPE (tem
))
1770 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1771 IDENTIFIER_POINTER (name
),
1772 TYPE_NAME_STRING (DECL_CLASS_CONTEXT (TREE_VALUE (TREE_VALUE (tem
)))));
1773 return error_mark_node
;
1775 if (TREE_VALUE (tem
) == NULL_TREE
)
1777 memoized_fast_rejects
[1] += 1;
1782 /* Want to return this, but we must make sure
1783 that access information is consistent. */
1784 tree baselink
= TREE_VALUE (tem
);
1785 tree memoized_basetypes
= TREE_PURPOSE (baselink
);
1786 tree these_basetypes
= basetype_path
;
1787 while (memoized_basetypes
&& these_basetypes
)
1789 memoized_fields_searched
[1]++;
1790 if (TREE_VALUE (memoized_basetypes
) != these_basetypes
)
1792 memoized_basetypes
= TREE_CHAIN (memoized_basetypes
);
1793 these_basetypes
= BINFO_INHERITANCE_CHAIN (these_basetypes
);
1795 /* The following statement is true only when both are NULL. */
1796 if (memoized_basetypes
== these_basetypes
)
1798 memoized_fast_finds
[1] += 1;
1799 return TREE_VALUE (tem
);
1801 /* else, we must re-find this field by hand. */
1802 baselink
= tree_cons (basetype_path
, TREE_VALUE (baselink
), TREE_CHAIN (baselink
));
1808 #ifdef GATHER_STATISTICS
1809 n_calls_lookup_fnfields
++;
1810 #endif /* GATHER_STATISTICS */
1811 if (protect
&& flag_memoize_lookups
&& ! toplevel_bindings_p ())
1812 entry
= make_memoized_table_entry (type
, name
, 1);
1816 idx
= lookup_fnfields_here (type
, name
);
1817 if (idx
>= 0 || lookup_field_1 (type
, name
))
1819 rval_binfo
= basetype_path
;
1820 rval_binfo_h
= rval_binfo
;
1825 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1826 rvals
= my_tree_cons (basetype_path
, rval
, rvals
);
1827 if (BINFO_BASETYPES (binfo
) && CLASSTYPE_BASELINK_VEC (type
))
1828 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1832 TREE_VALUE (entry
) = rvals
;
1833 TREE_TYPE (entry
) = NULL_TREE
;
1840 if (name
== ctor_identifier
|| name
== dtor_identifier
)
1842 /* Don't allow lookups of constructors and destructors to go
1843 deeper than the first place we look. */
1845 TREE_TYPE (entry
) = TREE_VALUE (entry
) = NULL_TREE
;
1850 if (basetype_path
== TYPE_BINFO (type
))
1852 basetype_chain
= CLASSTYPE_BINFO_AS_LIST (type
);
1853 TREE_VIA_PUBLIC (basetype_chain
) = 1;
1854 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1858 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
1859 TREE_VIA_PUBLIC (basetype_chain
) = TREE_VIA_PUBLIC (basetype_path
);
1860 TREE_VIA_PROTECTED (basetype_chain
) = TREE_VIA_PROTECTED (basetype_path
);
1861 TREE_VIA_VIRTUAL (basetype_chain
) = TREE_VIA_VIRTUAL (basetype_path
);
1864 /* The ambiguity check relies upon breadth first searching. */
1866 search_stack
= push_search_level (search_stack
, &search_obstack
);
1867 binfo
= basetype_path
;
1872 tree binfos
= BINFO_BASETYPES (binfo
);
1873 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1876 /* Process and/or queue base types. */
1877 for (i
= 0; i
< n_baselinks
; i
++)
1879 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1880 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1884 SET_BINFO_FIELDS_MARKED (base_binfo
);
1885 btypes
= my_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1886 TREE_VIA_PUBLIC (btypes
) = TREE_VIA_PUBLIC (base_binfo
);
1887 TREE_VIA_PROTECTED (btypes
) = TREE_VIA_PROTECTED (base_binfo
);
1888 TREE_VIA_VIRTUAL (btypes
) = TREE_VIA_VIRTUAL (base_binfo
);
1889 if (TREE_VIA_VIRTUAL (base_binfo
))
1890 btypes
= my_tree_cons (NULL_TREE
,
1891 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1894 btypes
= my_tree_cons (NULL_TREE
,
1895 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1897 obstack_ptr_grow (&search_obstack
, btypes
);
1899 if (tail
>= search_stack
->limit
)
1900 my_friendly_abort (99);
1904 /* Process head of queue, if one exists. */
1908 basetype_chain
= search_stack
->first
[head
++];
1909 binfo_h
= TREE_VALUE (basetype_chain
);
1910 basetype_chain
= TREE_CHAIN (basetype_chain
);
1911 basetype_path
= TREE_VALUE (basetype_chain
);
1912 if (TREE_CHAIN (basetype_chain
))
1913 BINFO_INHERITANCE_CHAIN (basetype_path
) = TREE_VALUE (TREE_CHAIN (basetype_chain
));
1915 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1917 binfo
= basetype_path
;
1918 type
= BINFO_TYPE (binfo
);
1920 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1921 and we do find NAME in TYPE, verify that such a second
1922 sighting is in fact valid. */
1924 idx
= lookup_fnfields_here (type
, name
);
1926 if (idx
>= 0 || (lookup_field_1 (type
, name
)!=NULL_TREE
&& !find_all
))
1928 if (rval_binfo
&& !find_all
&& hides (rval_binfo_h
, binfo_h
))
1930 /* This is ok, the member found is in rval_binfo, not
1933 else if (rval_binfo
==NULL_TREE
|| find_all
|| hides (binfo_h
, rval_binfo_h
))
1935 /* This is ok, the member found is here (binfo), not in
1939 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1940 /* Note, rvals can only be previously set if find_all is
1942 rvals
= my_tree_cons (basetype_path
, rval
, rvals
);
1943 if (TYPE_BINFO_BASETYPES (type
)
1944 && CLASSTYPE_BASELINK_VEC (type
))
1945 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1949 /* Undo finding it before, as something else hides it. */
1954 rval_binfo_h
= binfo_h
;
1958 /* This is ambiguous. */
1959 errstr
= "request for method `%D' is ambiguous";
1960 rvals
= error_mark_node
;
1966 tree
*tp
= search_stack
->first
;
1967 tree
*search_tail
= tp
+ tail
;
1969 while (tp
< search_tail
)
1971 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1975 search_stack
= pop_search_level (search_stack
);
1981 tree error_string
= my_build_string (errstr
);
1982 /* Save error message with entry. */
1983 TREE_TYPE (entry
) = error_string
;
1987 /* Mark entry as having no error string. */
1988 TREE_TYPE (entry
) = NULL_TREE
;
1989 TREE_VALUE (entry
) = rvals
;
1993 if (errstr
&& protect
)
1995 cp_error (errstr
, name
);
1996 rvals
= error_mark_node
;
2002 /* Look for a field or function named NAME in an inheritance lattice
2003 dominated by XBASETYPE. PROTECT is zero if we can avoid computing
2004 access information, otherwise it is 1. WANT_TYPE is 1 when we should
2005 only return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE. */
2008 lookup_member (xbasetype
, name
, protect
, want_type
)
2009 tree xbasetype
, name
;
2010 int protect
, want_type
;
2012 tree ret
, basetype_path
;
2014 if (TREE_CODE (xbasetype
) == TREE_VEC
)
2015 basetype_path
= xbasetype
;
2016 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
2018 basetype_path
= TYPE_BINFO (xbasetype
);
2019 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
2022 my_friendly_abort (97);
2024 ret
= lookup_field (basetype_path
, name
, protect
, want_type
);
2025 if (! ret
&& ! want_type
)
2026 ret
= lookup_fnfields (basetype_path
, name
, protect
);
2030 /* BREADTH-FIRST SEARCH ROUTINES. */
2032 /* Search a multiple inheritance hierarchy by breadth-first search.
2034 BINFO is an aggregate type, possibly in a multiple-inheritance hierarchy.
2035 TESTFN is a function, which, if true, means that our condition has been met,
2036 and its return value should be returned.
2037 QFN, if non-NULL, is a predicate dictating whether the type should
2040 static HOST_WIDE_INT
2041 breadth_first_search (binfo
, testfn
, qfn
)
2043 int (*testfn
) PROTO((tree
, int));
2044 int (*qfn
) PROTO((tree
, int));
2046 int head
= 0, tail
= 0;
2049 search_stack
= push_search_level (search_stack
, &search_obstack
);
2053 tree binfos
= BINFO_BASETYPES (binfo
);
2054 int n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2057 /* Process and/or queue base types. */
2058 for (i
= 0; i
< n_baselinks
; i
++)
2060 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2062 if (BINFO_MARKED (base_binfo
) == 0
2063 && (qfn
== 0 || (*qfn
) (binfo
, i
)))
2065 SET_BINFO_MARKED (base_binfo
);
2066 obstack_ptr_grow (&search_obstack
, binfo
);
2067 obstack_ptr_grow (&search_obstack
, (HOST_WIDE_INT
) i
);
2069 if (tail
>= search_stack
->limit
)
2070 my_friendly_abort (100);
2073 /* Process head of queue, if one exists. */
2080 binfo
= search_stack
->first
[head
++];
2081 i
= (HOST_WIDE_INT
) search_stack
->first
[head
++];
2082 if ((rval
= (*testfn
) (binfo
, i
)))
2084 binfo
= BINFO_BASETYPE (binfo
, i
);
2087 tree
*tp
= search_stack
->first
;
2088 tree
*search_tail
= tp
+ tail
;
2089 while (tp
< search_tail
)
2092 int i
= (HOST_WIDE_INT
)(*tp
++);
2093 CLEAR_BINFO_MARKED (BINFO_BASETYPE (binfo
, i
));
2097 search_stack
= pop_search_level (search_stack
);
2101 /* Functions to use in breadth first searches. */
2102 typedef int (*pfi
) PROTO((tree
, int));
2104 static tree declarator
;
2107 get_virtuals_named_this (binfo
)
2112 fields
= lookup_fnfields (binfo
, declarator
, -1);
2113 /* fields cannot be error_mark_node */
2118 /* Get to the function decls, and return the first virtual function
2119 with this name, if there is one. */
2124 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
2125 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
2127 fields
= next_baselink (fields
);
2133 get_virtual_destructor (binfo
, i
)
2137 tree type
= BINFO_TYPE (binfo
);
2139 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
2140 if (TYPE_HAS_DESTRUCTOR (type
)
2141 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
2142 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
2147 tree_has_any_destructor_p (binfo
, i
)
2151 tree type
= BINFO_TYPE (binfo
);
2153 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
2154 return TYPE_NEEDS_DESTRUCTOR (type
);
2157 /* Returns > 0 if a function with type DRETTYPE overriding a function
2158 with type BRETTYPE is covariant, as defined in [class.virtual].
2160 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
2161 adjustment), or -1 if pedantically invalid covariance. */
2164 covariant_return_p (brettype
, drettype
)
2165 tree brettype
, drettype
;
2169 if (TREE_CODE (brettype
) == FUNCTION_DECL
2170 || TREE_CODE (brettype
) == THUNK_DECL
)
2172 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
2173 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
2175 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
2177 brettype
= TREE_TYPE (brettype
);
2178 drettype
= TREE_TYPE (drettype
);
2181 if (comptypes (brettype
, drettype
, 1))
2184 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
2185 && (TREE_CODE (brettype
) == POINTER_TYPE
2186 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
2187 && TYPE_READONLY (brettype
) == TYPE_READONLY (drettype
)
2188 && TYPE_VOLATILE (brettype
) == TYPE_VOLATILE (drettype
)))
2191 if (! can_convert (brettype
, drettype
))
2194 brettype
= TREE_TYPE (brettype
);
2195 drettype
= TREE_TYPE (drettype
);
2197 /* If not pedantic, allow any standard pointer conversion. */
2198 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
2201 binfo
= get_binfo (brettype
, drettype
, 1);
2203 /* If we get an error_mark_node from get_binfo, it already complained,
2204 so let's just succeed. */
2205 if (binfo
== error_mark_node
)
2208 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
2213 /* Given a class type TYPE, and a function decl FNDECL, look for a
2214 virtual function in TYPE's hierarchy which FNDECL could match as a
2215 virtual function. It doesn't matter which one we find.
2217 DTORP is nonzero if we are looking for a destructor. Destructors
2218 need special treatment because they do not match by name. */
2221 get_matching_virtual (binfo
, fndecl
, dtorp
)
2225 tree tmp
= NULL_TREE
;
2228 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
2229 /* In [temp.mem] we have:
2231 A specialization of a member function template does not
2232 override a virtual function from a base class. */
2235 /* Breadth first search routines start searching basetypes
2236 of TYPE, so we must perform first ply of search here. */
2239 if (tree_has_any_destructor_p (binfo
, -1))
2240 tmp
= get_virtual_destructor (binfo
, -1);
2245 tmp
= (tree
) breadth_first_search (binfo
,
2246 (pfi
) get_virtual_destructor
,
2247 tree_has_any_destructor_p
);
2252 tree drettype
, dtypes
, btypes
, instptr_type
;
2253 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
2254 tree baselink
, best
= NULL_TREE
;
2255 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
2257 declarator
= DECL_NAME (fndecl
);
2258 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
2261 baselink
= get_virtuals_named_this (binfo
);
2262 if (baselink
== NULL_TREE
)
2265 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
2266 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2267 if (DECL_STATIC_FUNCTION_P (fndecl
))
2268 instptr_type
= NULL_TREE
;
2270 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
2272 for (; baselink
; baselink
= next_baselink (baselink
))
2275 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
2277 tmp
= OVL_CURRENT (tmps
);
2278 if (! DECL_VINDEX (tmp
))
2281 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
2282 if (instptr_type
== NULL_TREE
)
2284 if (compparms (TREE_CHAIN (btypes
), dtypes
, 3))
2285 /* Caller knows to give error in this case. */
2290 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (btypes
)))
2291 == TYPE_READONLY (instptr_type
))
2292 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
), 3))
2294 tree brettype
= TREE_TYPE (TREE_TYPE (tmp
));
2295 if (comptypes (brettype
, drettype
, 1))
2297 else if ((i
= covariant_return_p (brettype
, drettype
)))
2300 sorry ("adjusting pointers for covariant returns");
2302 if (pedantic
&& i
== -1)
2304 cp_pedwarn_at ("invalid covariant return type for `%#D' (must be pointer or reference to class)", fndecl
);
2305 cp_pedwarn_at (" overriding `%#D'", tmp
);
2308 else if (IS_AGGR_TYPE_2 (brettype
, drettype
)
2309 && comptypes (brettype
, drettype
, 0))
2311 error ("invalid covariant return type (must use pointer or reference)");
2312 cp_error_at (" overriding `%#D'", tmp
);
2313 cp_error_at (" with `%#D'", fndecl
);
2315 else if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
)
2317 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl
);
2318 cp_error_at (" overriding definition as `%#D'", tmp
);
2319 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
2324 /* If not at the end */
2336 /* Return the list of virtual functions which are abstract in type
2337 TYPE that come from non virtual base classes. See
2338 expand_direct_vtbls_init for the style of search we do. */
2341 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
2344 tree abstract_virtuals
;
2346 tree binfos
= BINFO_BASETYPES (binfo
);
2347 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2349 for (i
= 0; i
< n_baselinks
; i
++)
2351 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2352 int is_not_base_vtable
2353 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2354 if (! TREE_VIA_VIRTUAL (base_binfo
))
2356 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
2359 /* Should we use something besides CLASSTYPE_VFIELDS? */
2360 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2362 tree virtuals
= BINFO_VIRTUALS (binfo
);
2364 skip_rtti_stuff (&virtuals
);
2368 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2369 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2370 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2371 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2372 virtuals
= TREE_CHAIN (virtuals
);
2375 return abstract_virtuals
;
2378 /* Return the list of virtual functions which are abstract in type TYPE.
2379 This information is cached, and so must be built on a
2380 non-temporary obstack. */
2383 get_abstract_virtuals (type
)
2387 tree abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (type
);
2389 /* First get all from non-virtual bases. */
2391 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
2393 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
2395 tree virtuals
= BINFO_VIRTUALS (vbases
);
2397 skip_rtti_stuff (&virtuals
);
2401 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2402 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2403 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2404 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2405 virtuals
= TREE_CHAIN (virtuals
);
2408 return nreverse (abstract_virtuals
);
2411 /* For the type TYPE, return a list of member functions available from
2412 base classes with name NAME. The TREE_VALUE of the list is a chain of
2413 member functions with name NAME. The TREE_PURPOSE of the list is a
2414 basetype, or a list of base types (in reverse order) which were
2415 traversed to reach the chain of member functions. If we reach a base
2416 type which provides a member function of name NAME, and which has at
2417 most one base type itself, then we can terminate the search. */
2420 get_baselinks (type_as_binfo_list
, type
, name
)
2421 tree type_as_binfo_list
;
2424 int head
= 0, tail
= 0, idx
;
2425 tree rval
= 0, nval
= 0;
2426 tree basetypes
= type_as_binfo_list
;
2427 tree binfo
= TYPE_BINFO (type
);
2429 search_stack
= push_search_level (search_stack
, &search_obstack
);
2433 tree binfos
= BINFO_BASETYPES (binfo
);
2434 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2436 /* Process and/or queue base types. */
2437 for (i
= 0; i
< n_baselinks
; i
++)
2439 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2442 btypes
= hash_tree_cons (TREE_VIA_PUBLIC (base_binfo
),
2443 TREE_VIA_VIRTUAL (base_binfo
),
2444 TREE_VIA_PROTECTED (base_binfo
),
2445 NULL_TREE
, base_binfo
,
2447 obstack_ptr_grow (&search_obstack
, btypes
);
2448 search_stack
->first
= (tree
*)obstack_base (&search_obstack
);
2453 /* Process head of queue, if one exists. */
2457 basetypes
= search_stack
->first
[head
++];
2458 binfo
= TREE_VALUE (basetypes
);
2459 type
= BINFO_TYPE (binfo
);
2460 idx
= lookup_fnfields_1 (type
, name
);
2463 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
2464 rval
= hash_tree_cons (0, 0, 0, basetypes
, nval
, rval
);
2465 if (TYPE_BINFO_BASETYPES (type
) == 0)
2467 else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
)) == 1)
2469 if (CLASSTYPE_BASELINK_VEC (type
))
2470 TREE_TYPE (rval
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
2477 search_stack
= pop_search_level (search_stack
);
2482 next_baselink (baselink
)
2485 tree tmp
= TREE_TYPE (baselink
);
2486 baselink
= TREE_CHAIN (baselink
);
2489 /* @@ does not yet add previous base types. */
2490 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2492 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2493 tmp
= TREE_CHAIN (tmp
);
2498 /* DEPTH-FIRST SEARCH ROUTINES. */
2501 /* Assign unique numbers to _CLASSTYPE members of the lattice
2502 specified by TYPE. The root nodes are marked first; the nodes
2503 are marked depth-fisrt, left-right. */
2507 /* Matrix implementing a relation from CLASSTYPE X CLASSTYPE => INT.
2508 Relation yields 1 if C1 <= C2, 0 otherwise. */
2509 typedef char mi_boolean
;
2510 static mi_boolean
*mi_matrix
;
2512 /* Type for which this matrix is defined. */
2513 static tree mi_type
;
2515 /* Size of the matrix for indexing purposes. */
2518 /* Return nonzero if class C2 derives from class C1. */
2519 #define BINFO_DERIVES_FROM(C1, C2) \
2520 ((mi_matrix+mi_size*(BINFO_CID (C1)-1))[BINFO_CID (C2)-1])
2521 #define TYPE_DERIVES_FROM(C1, C2) \
2522 ((mi_matrix+mi_size*(CLASSTYPE_CID (C1)-1))[CLASSTYPE_CID (C2)-1])
2523 #define BINFO_DERIVES_FROM_STAR(C) \
2524 (mi_matrix+(BINFO_CID (C)-1))
2527 /* This routine converts a pointer to be a pointer of an immediate
2528 base class. The normal convert_pointer_to routine would diagnose
2529 the conversion as ambiguous, under MI code that has the base class
2530 as an ambiguous base class. */
2533 convert_pointer_to_single_level (to_type
, expr
)
2536 tree binfo_of_derived
;
2539 binfo_of_derived
= TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
)));
2540 last
= get_binfo (to_type
, TREE_TYPE (TREE_TYPE (expr
)), 0);
2541 BINFO_INHERITANCE_CHAIN (last
) = binfo_of_derived
;
2542 BINFO_INHERITANCE_CHAIN (binfo_of_derived
) = NULL_TREE
;
2543 return build_vbase_path (PLUS_EXPR
, build_pointer_type (to_type
), expr
, last
, 1);
2546 /* The main function which implements depth first search.
2548 This routine has to remember the path it walked up, when
2549 dfs_init_vbase_pointers is the work function, as otherwise there
2550 would be no record. */
2553 dfs_walk (binfo
, fn
, qfn
)
2555 void (*fn
) PROTO((tree
));
2556 int (*qfn
) PROTO((tree
));
2558 tree binfos
= BINFO_BASETYPES (binfo
);
2559 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2561 for (i
= 0; i
< n_baselinks
; i
++)
2563 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2565 if (qfn
== 0 || (*qfn
)(base_binfo
))
2567 if (TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TYPE_PARM
2568 || TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TEMPLATE_PARM
)
2570 else if (fn
== dfs_init_vbase_pointers
)
2572 /* When traversing an arbitrary MI hierarchy, we need to keep
2573 a record of the path we took to get down to the final base
2574 type, as otherwise there would be no record of it, and just
2575 trying to blindly convert at the bottom would be ambiguous.
2577 The easiest way is to do the conversions one step at a time,
2578 as we know we want the immediate base class at each step.
2580 The only special trick to converting one step at a time,
2581 is that when we hit the last virtual base class, we must
2582 use the SLOT value for it, and not use the normal convert
2583 routine. We use the last virtual base class, as in our
2584 implementation, we have pointers to all virtual base
2585 classes in the base object. */
2587 tree saved_vbase_decl_ptr_intermediate
2588 = vbase_decl_ptr_intermediate
;
2590 if (TREE_VIA_VIRTUAL (base_binfo
))
2592 /* No need for the conversion here, as we know it is the
2594 vbase_decl_ptr_intermediate
2595 = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
));
2599 vbase_decl_ptr_intermediate
2600 = convert_pointer_to_single_level (BINFO_TYPE (base_binfo
),
2601 vbase_decl_ptr_intermediate
);
2604 dfs_walk (base_binfo
, fn
, qfn
);
2606 vbase_decl_ptr_intermediate
= saved_vbase_decl_ptr_intermediate
;
2609 dfs_walk (base_binfo
, fn
, qfn
);
2617 /* Predicate functions which serve for dfs_walk. */
2618 static int numberedp (binfo
) tree binfo
;
2619 { return BINFO_CID (binfo
); }
2620 static int unnumberedp (binfo
) tree binfo
;
2621 { return BINFO_CID (binfo
) == 0; }
2624 static int markedp (binfo
) tree binfo
;
2625 { return BINFO_MARKED (binfo
); }
2626 static int unmarkedp (binfo
) tree binfo
;
2627 { return BINFO_MARKED (binfo
) == 0; }
2630 static int bfs_markedp (binfo
, i
) tree binfo
; int i
;
2631 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2632 static int bfs_unmarkedp (binfo
, i
) tree binfo
; int i
;
2633 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2634 static int bfs_marked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2635 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2636 static int bfs_unmarked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2637 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2638 static int bfs_marked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2639 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2640 static int bfs_unmarked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2641 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2644 static int marked_vtable_pathp (binfo
) tree binfo
;
2645 { return BINFO_VTABLE_PATH_MARKED (binfo
); }
2646 static int unmarked_vtable_pathp (binfo
) tree binfo
;
2647 { return BINFO_VTABLE_PATH_MARKED (binfo
) == 0; }
2648 static int marked_new_vtablep (binfo
) tree binfo
;
2649 { return BINFO_NEW_VTABLE_MARKED (binfo
); }
2650 static int unmarked_new_vtablep (binfo
) tree binfo
;
2651 { return BINFO_NEW_VTABLE_MARKED (binfo
) == 0; }
2652 static int marked_pushdecls_p (binfo
) tree binfo
;
2653 { return BINFO_PUSHDECLS_MARKED (binfo
); }
2654 static int unmarked_pushdecls_p (binfo
) tree binfo
;
2655 { return BINFO_PUSHDECLS_MARKED (binfo
) == 0; }
2658 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2659 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2662 static int dfs_debug_unmarkedp (binfo
) tree binfo
;
2663 { return CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
)) == 0; }
2665 /* The worker functions for `dfs_walk'. These do not need to
2666 test anything (vis a vis marking) if they are paired with
2667 a predicate function (above). */
2670 /* Assign each type within the lattice a number which is unique
2671 in the lattice. The first number assigned is 1. */
2677 BINFO_CID (binfo
) = ++cid
;
2681 dfs_unnumber (binfo
)
2684 BINFO_CID (binfo
) = 0;
2690 dfs_mark (binfo
) tree binfo
;
2691 { SET_BINFO_MARKED (binfo
); }
2695 dfs_unmark (binfo
) tree binfo
;
2696 { CLEAR_BINFO_MARKED (binfo
); }
2700 dfs_mark_vtable_path (binfo
) tree binfo
;
2701 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2704 dfs_unmark_vtable_path (binfo
) tree binfo
;
2705 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2708 dfs_mark_new_vtable (binfo
) tree binfo
;
2709 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2712 dfs_unmark_new_vtable (binfo
) tree binfo
;
2713 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2716 dfs_clear_search_slot (binfo
) tree binfo
;
2717 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2721 dfs_debug_mark (binfo
)
2724 tree t
= BINFO_TYPE (binfo
);
2726 /* Use heuristic that if there are virtual functions,
2727 ignore until we see a non-inline virtual function. */
2728 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2730 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2735 /* If interface info is known, either we've already emitted the debug
2736 info or we don't need to. */
2737 if (CLASSTYPE_INTERFACE_KNOWN (t
)
2738 || (write_virtuals
== 2 && TYPE_VIRTUAL_P (t
)))
2741 /* If debug info is requested from this context for this type, supply it.
2742 If debug info is requested from another context for this type,
2743 see if some third context can supply it. */
2744 if (current_function_decl
== NULL_TREE
2745 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2747 if (TREE_VEC_ELT (methods
, 1))
2748 methods
= TREE_VEC_ELT (methods
, 1);
2749 else if (TREE_VEC_ELT (methods
, 0))
2750 methods
= TREE_VEC_ELT (methods
, 0);
2752 methods
= TREE_VEC_ELT (methods
, 2);
2753 methods
= OVL_CURRENT (methods
);
2756 if (DECL_VINDEX (methods
)
2757 && DECL_THIS_INLINE (methods
) == 0
2758 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2760 /* Somebody, somewhere is going to have to define this
2761 virtual function. When they do, they will provide
2762 the debugging info. */
2765 methods
= TREE_CHAIN (methods
);
2768 /* We cannot rely on some alien method to solve our problems,
2769 so we must write out the debug info ourselves. */
2770 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2771 rest_of_type_compilation (t
, toplevel_bindings_p ());
2774 /* Attach to the type of the virtual base class, the pointer to the
2775 virtual base class, given the global pointer vbase_decl_ptr.
2777 We use the global vbase_types. ICK! */
2780 dfs_find_vbases (binfo
)
2783 tree binfos
= BINFO_BASETYPES (binfo
);
2784 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2786 for (i
= n_baselinks
-1; i
>= 0; i
--)
2788 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2790 if (TREE_VIA_VIRTUAL (base_binfo
)
2791 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2793 tree vbase
= BINFO_TYPE (base_binfo
);
2794 tree binfo
= binfo_member (vbase
, vbase_types
);
2796 CLASSTYPE_SEARCH_SLOT (vbase
)
2797 = build (PLUS_EXPR
, build_pointer_type (vbase
),
2798 vbase_decl_ptr
, BINFO_OFFSET (binfo
));
2801 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2802 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2806 dfs_init_vbase_pointers (binfo
)
2809 tree type
= BINFO_TYPE (binfo
);
2810 tree fields
= TYPE_FIELDS (type
);
2811 tree this_vbase_ptr
;
2813 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2816 /* See finish_struct_1 for when we can enable this. */
2817 /* If we have a vtable pointer first, skip it. */
2818 if (VFIELD_NAME_P (DECL_NAME (fields
)))
2819 fields
= TREE_CHAIN (fields
);
2822 if (fields
== NULL_TREE
2823 || DECL_NAME (fields
) == NULL_TREE
2824 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2827 this_vbase_ptr
= vbase_decl_ptr_intermediate
;
2829 if (build_pointer_type (type
) != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2830 my_friendly_abort (125);
2832 while (fields
&& DECL_NAME (fields
)
2833 && VBASE_NAME_P (DECL_NAME (fields
)))
2835 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2836 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2837 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2838 vbase_init_result
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2840 build_modify_expr (ref
, NOP_EXPR
, init
),
2842 fields
= TREE_CHAIN (fields
);
2846 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2847 times, just NEW_VTABLE, but optimizer should make both with equal
2848 efficiency (though it does not currently). */
2851 dfs_clear_vbase_slots (binfo
)
2854 tree type
= BINFO_TYPE (binfo
);
2855 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2856 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2857 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2861 init_vbase_pointers (type
, decl_ptr
)
2865 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2867 int old_flag
= flag_this_is_variable
;
2868 tree binfo
= TYPE_BINFO (type
);
2869 flag_this_is_variable
= -2;
2870 vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2871 vbase_decl_ptr
= vbase_decl_ptr_intermediate
= decl_ptr
;
2872 vbase_init_result
= NULL_TREE
;
2873 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
);
2874 dfs_walk (binfo
, dfs_init_vbase_pointers
, marked_vtable_pathp
);
2875 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
2876 flag_this_is_variable
= old_flag
;
2877 return vbase_init_result
;
2882 /* get the virtual context (the vbase that directly contains the
2883 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2884 or NULL_TREE if there is none.
2886 FNDECL must come from a virtual table from a virtual base to ensure that
2887 there is only one possible DECL_CLASS_CONTEXT.
2889 We know that if there is more than one place (binfo) the fndecl that the
2890 declared, they all refer to the same binfo. See get_class_offset_1 for
2891 the check that ensures this. */
2894 virtual_context (fndecl
, t
, vbase
)
2895 tree fndecl
, t
, vbase
;
2898 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2900 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2901 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2905 /* Not sure if checking path == vbase is necessary here, but just in
2907 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2908 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2909 path
= BINFO_INHERITANCE_CHAIN (path
);
2912 /* This shouldn't happen, I don't want errors! */
2913 warning ("recoverable compiler error, fixups for virtual function");
2918 if (TREE_VIA_VIRTUAL (path
))
2919 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2920 path
= BINFO_INHERITANCE_CHAIN (path
);
2925 /* Fixups upcast offsets for one vtable.
2926 Entries may stay within the VBASE given, or
2927 they may upcast into a direct base, or
2928 they may upcast into a different vbase.
2930 We only need to do fixups in case 2 and 3. In case 2, we add in
2931 the virtual base offset to effect an upcast, in case 3, we add in
2932 the virtual base offset to effect an upcast, then subtract out the
2933 offset for the other virtual base, to effect a downcast into it.
2935 This routine mirrors fixup_vtable_deltas in functionality, though
2936 this one is runtime based, and the other is compile time based.
2937 Conceivably that routine could be removed entirely, and all fixups
2940 VBASE_OFFSETS is an association list of virtual bases that contains
2941 offset information for the virtual bases, so the offsets are only
2942 calculated once. The offsets are computed by where we think the
2943 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2944 the vbase really is. */
2947 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2949 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2951 tree virtuals
= BINFO_VIRTUALS (binfo
);
2954 unsigned HOST_WIDE_INT n
;
2956 delta
= purpose_member (vbase
, *vbase_offsets
);
2959 delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase
));
2960 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2961 delta
= save_expr (delta
);
2962 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2963 *vbase_offsets
= delta
;
2966 n
= skip_rtti_stuff (&virtuals
);
2970 tree current_fndecl
= TREE_VALUE (virtuals
);
2971 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2972 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2974 && current_fndecl
!= abort_fndecl
2975 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2977 /* This may in fact need a runtime fixup. */
2978 tree idx
= build_int_2 (n
, 0);
2979 tree vtbl
= BINFO_VTABLE (binfo
);
2980 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2981 tree aref
, ref
, naref
;
2982 tree old_delta
, new_delta
;
2985 if (nvtbl
== NULL_TREE
2986 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2988 /* Dup it if it isn't in local scope yet. */
2990 (VAR_DECL
, DECL_NAME (vtbl
),
2991 TYPE_MAIN_VARIANT (TREE_TYPE (BINFO_VTABLE (binfo
))));
2992 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2993 DECL_ALIGN (nvtbl
));
2994 TREE_READONLY (nvtbl
) = 0;
2995 DECL_ARTIFICIAL (nvtbl
) = 1;
2996 nvtbl
= pushdecl (nvtbl
);
2998 cp_finish_decl (nvtbl
, init
, NULL_TREE
, 0,
2999 LOOKUP_ONLYCONVERTING
);
3001 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
3002 because they wouldn't be useful; everything that wants to
3003 look at the vtable will look at the decl for the normal
3004 vtable. Setting DECL_CONTEXT also screws up
3005 decl_function_context. */
3007 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
3009 TREE_SIDE_EFFECTS (init
) = 1;
3010 expand_expr_stmt (init
);
3011 /* Update the vtable pointers as necessary. */
3012 ref
= build_vfield_ref
3013 (build_indirect_ref (addr
, NULL_PTR
),
3014 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))));
3016 (build_modify_expr (ref
, NOP_EXPR
,
3017 build_unary_op (ADDR_EXPR
, nvtbl
, 0)));
3019 assemble_external (vtbl
);
3020 aref
= build_array_ref (vtbl
, idx
);
3021 naref
= build_array_ref (nvtbl
, idx
);
3022 old_delta
= build_component_ref (aref
, delta_identifier
,
3024 new_delta
= build_component_ref (naref
, delta_identifier
,
3027 /* This is a upcast, so we have to add the offset for the
3029 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
3030 TREE_VALUE (delta
), 0);
3033 /* If this is set, we need to subtract out the delta
3034 adjustments for the other virtual base that we
3036 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
3039 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
3040 vc_delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc
));
3041 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
3043 vc_delta
= save_expr (vc_delta
);
3044 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
3047 vc_delta
= TREE_VALUE (vc_delta
);
3049 /* This is a downcast, so we have to subtract the offset
3050 for the virtual base. */
3051 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
, 0);
3054 TREE_READONLY (new_delta
) = 0;
3055 expand_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
3059 virtuals
= TREE_CHAIN (virtuals
);
3063 /* Fixup upcast offsets for all direct vtables. Patterned after
3064 expand_direct_vtbls_init. */
3067 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
3068 tree real_binfo
, binfo
;
3069 int init_self
, can_elide
;
3070 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
3072 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
3073 tree binfos
= BINFO_BASETYPES (binfo
);
3074 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
3076 for (i
= 0; i
< n_baselinks
; i
++)
3078 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
3079 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3080 int is_not_base_vtable
3081 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo
));
3082 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
3083 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
3084 is_not_base_vtable
, can_elide
, addr
,
3085 orig_addr
, type
, vbase
, vbase_offsets
);
3088 /* Before turning this on, make sure it is correct. */
3089 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
3092 /* Should we use something besides CLASSTYPE_VFIELDS? */
3093 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
3095 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
3096 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
3097 type
, vbase_offsets
);
3101 /* Build a COMPOUND_EXPR which when expanded will generate the code
3102 needed to initialize all the virtual function table slots of all
3103 the virtual baseclasses. MAIN_BINFO is the binfo which determines
3104 the virtual baseclasses to use; TYPE is the type of the object to
3105 which the initialization applies. TRUE_EXP is the true object we
3106 are initializing, and DECL_PTR is the pointer to the sub-object we
3109 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
3110 object was laid out by a top-level constructor and the computed
3111 offsets are valid to store vtables. When zero, we must store new
3112 vtables through virtual baseclass pointers.
3114 We setup and use the globals: vbase_decl_ptr, vbase_types
3118 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
)
3120 tree true_exp
, decl_ptr
;
3122 tree type
= BINFO_TYPE (binfo
);
3124 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
3126 rtx fixup_insns
= NULL_RTX
;
3127 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
3128 vbase_types
= vbases
;
3129 vbase_decl_ptr
= true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0) : decl_ptr
;
3131 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
);
3133 /* Initialized with vtables of type TYPE. */
3134 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
3138 addr
= convert_pointer_to_vbase (TREE_TYPE (vbases
), vbase_decl_ptr
);
3140 /* Do all vtables from this virtual base. */
3141 /* This assumes that virtual bases can never serve as parent
3142 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
3143 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
3146 /* Now we adjust the offsets for virtual functions that
3147 cross virtual boundaries on an implicit upcast on vf call
3148 so that the layout of the most complete type is used,
3149 instead of assuming the layout of the virtual bases from
3150 our current type. */
3152 if (flag_vtable_thunks
)
3154 /* We don't have dynamic thunks yet!
3155 So for now, just fail silently. */
3159 tree vbase_offsets
= NULL_TREE
;
3160 push_to_sequence (fixup_insns
);
3161 fixup_virtual_upcast_offsets (vbases
,
3162 TYPE_BINFO (BINFO_TYPE (vbases
)),
3163 1, 0, addr
, vbase_decl_ptr
,
3164 type
, vbases
, &vbase_offsets
);
3165 fixup_insns
= get_insns ();
3172 extern tree in_charge_identifier
;
3173 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
3174 if (! in_charge_node
)
3176 warning ("recoverable internal compiler error, nobody's in charge!");
3177 in_charge_node
= integer_zero_node
;
3179 in_charge_node
= build_binary_op (EQ_EXPR
, in_charge_node
, integer_zero_node
, 1);
3180 expand_start_cond (in_charge_node
, 0);
3181 emit_insns (fixup_insns
);
3185 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
3189 /* get virtual base class types.
3190 This adds type to the vbase_types list in reverse dfs order.
3191 Ordering is very important, so don't change it. */
3194 dfs_get_vbase_types (binfo
)
3197 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
3199 tree new_vbase
= make_binfo (integer_zero_node
, binfo
,
3200 BINFO_VTABLE (binfo
),
3201 BINFO_VIRTUALS (binfo
));
3202 TREE_CHAIN (new_vbase
) = vbase_types
;
3203 TREE_VIA_VIRTUAL (new_vbase
) = 1;
3204 vbase_types
= new_vbase
;
3205 SET_BINFO_VBASE_MARKED (binfo
);
3207 SET_BINFO_MARKED (binfo
);
3210 /* get a list of virtual base classes in dfs order. */
3213 get_vbase_types (type
)
3219 binfo
= TYPE_BINFO (type
);
3220 vbase_types
= NULL_TREE
;
3221 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
);
3222 dfs_walk (binfo
, dfs_unmark
, markedp
);
3223 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
3224 reverse it so that we get normal dfs ordering. */
3225 vbase_types
= nreverse (vbase_types
);
3227 /* unmark marked vbases */
3228 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
3229 CLEAR_BINFO_VBASE_MARKED (vbases
);
3236 dfs_record_inheritance (binfo
)
3239 tree binfos
= BINFO_BASETYPES (binfo
);
3240 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3241 mi_boolean
*derived_row
= BINFO_DERIVES_FROM_STAR (binfo
);
3243 for (i
= n_baselinks
-1; i
>= 0; i
--)
3246 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3247 tree baseclass
= BINFO_TYPE (base_binfo
);
3248 mi_boolean
*base_row
= BINFO_DERIVES_FROM_STAR (base_binfo
);
3250 if (TREE_CODE (baseclass
) == TEMPLATE_TYPE_PARM
3251 || TREE_CODE (baseclass
) == TEMPLATE_TEMPLATE_PARM
)
3253 my_friendly_assert (CLASSTYPE_CID (baseclass
) != 0, 2365);
3255 /* Don't search if there's nothing there! MI_SIZE can be
3256 zero as a result of parse errors. */
3257 if (TYPE_BINFO_BASETYPES (baseclass
) && mi_size
> 0)
3258 for (j
= mi_size
*(CLASSTYPE_CID (baseclass
)-1); j
>= 0; j
-= mi_size
)
3259 derived_row
[j
] |= base_row
[j
];
3260 TYPE_DERIVES_FROM (baseclass
, BINFO_TYPE (binfo
)) = 1;
3263 SET_BINFO_MARKED (binfo
);
3266 /* Given a _CLASSTYPE node in a multiple inheritance lattice,
3267 convert the lattice into a simple relation such that,
3268 given to CIDs, C1 and C2, one can determine if C1 <= C2
3269 or C2 <= C1 or C1 <> C2.
3271 Once constructed, we walk the lattice depth fisrt,
3272 applying various functions to elements as they are encountered.
3274 We use xmalloc here, in case we want to randomly free these tables. */
3276 #define SAVE_MI_MATRIX
3279 build_mi_matrix (type
)
3282 tree binfo
= TYPE_BINFO (type
);
3285 #ifdef SAVE_MI_MATRIX
3286 if (CLASSTYPE_MI_MATRIX (type
))
3288 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
3289 mi_matrix
= CLASSTYPE_MI_MATRIX (type
);
3291 dfs_walk (binfo
, dfs_number
, unnumberedp
);
3296 dfs_walk (binfo
, dfs_number
, unnumberedp
);
3298 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
3299 if (mi_size
< (cid
-1))
3301 mi_matrix
= (char *)xmalloc ((mi_size
+ 1) * (mi_size
+ 1));
3303 bzero (mi_matrix
, (mi_size
+ 1) * (mi_size
+ 1));
3304 dfs_walk (binfo
, dfs_record_inheritance
, unmarkedp
);
3305 dfs_walk (binfo
, dfs_unmark
, markedp
);
3311 dfs_walk (TYPE_BINFO (mi_type
), dfs_unnumber
, numberedp
);
3313 #ifdef SAVE_MI_MATRIX
3314 CLASSTYPE_MI_MATRIX (mi_type
) = mi_matrix
;
3323 /* If we want debug info for a type TYPE, make sure all its base types
3324 are also marked as being potentially interesting. This avoids
3325 the problem of not writing any debug info for intermediate basetypes
3326 that have abstract virtual functions. Also mark member types. */
3329 note_debug_info_needed (type
)
3334 if (current_template_parms
)
3337 if (TYPE_BEING_DEFINED (type
))
3338 /* We can't go looking for the base types and fields just yet. */
3341 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
3342 does not support name references between translation units. Well, we
3343 could, but that would mean putting global labels in the debug output
3344 before each exported type and each of its functions and static data
3346 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
3349 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
);
3350 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
3353 if (TREE_CODE (field
) == FIELD_DECL
3354 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
3355 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
)))
3356 note_debug_info_needed (ttype
);
3360 /* Subroutines of push_class_decls (). */
3362 /* Add in a decl to the envelope. */
3364 envelope_add_decl (type
, decl
, values
)
3365 tree type
, decl
, *values
;
3368 tree name
= DECL_NAME (decl
);
3371 /* Yet Another Implicit Typename Kludge: Since we don't tsubst
3372 the members for partial instantiations, DECL_CONTEXT (decl) is wrong.
3373 But pretend it's right for this function. */
3374 if (processing_template_decl
)
3375 type
= DECL_REAL_CONTEXT (decl
);
3377 /* virtual base names are always unique. */
3378 if (VBASE_NAME_P (name
))
3379 *values
= NULL_TREE
;
3381 /* Possible ambiguity. If its defining type(s)
3382 is (are all) derived from us, no problem. */
3383 else if (*values
&& TREE_CODE (*values
) != TREE_LIST
)
3385 tree value
= *values
;
3386 /* Only complain if we shadow something we can access. */
3387 if (warn_shadow
&& TREE_CODE (decl
) == FUNCTION_DECL
3388 && ((DECL_LANG_SPECIFIC (*values
)
3389 && DECL_CLASS_CONTEXT (value
) == current_class_type
)
3390 || ! TREE_PRIVATE (value
)))
3391 /* Should figure out access control more accurately. */
3393 cp_warning_at ("member `%#D' is shadowed", value
);
3394 cp_warning_at ("by member function `%#D'", decl
);
3395 warning ("in this context");
3398 context
= DECL_REAL_CONTEXT (value
);
3400 if (context
== type
)
3402 if (TREE_CODE (value
) == TYPE_DECL
3403 && DECL_ARTIFICIAL (value
))
3404 *values
= NULL_TREE
;
3408 else if (type
== current_class_type
3410 /* If we don't check CLASSTYPE_CID on CONTEXT right now,
3411 we'll end up subtracting from the address of MI_MATRIX,
3412 putting us off in la la land. */
3413 || (CLASSTYPE_CID (type
)
3414 && TYPE_DERIVES_FROM (context
, type
))
3416 || DERIVED_FROM_P (context
, type
)
3420 /* Don't add in *values to list */
3421 *values
= NULL_TREE
;
3424 *values
= build_tree_list (NULL_TREE
, value
);
3427 for (tmp
= values
; *tmp
;)
3429 tree value
= TREE_VALUE (*tmp
);
3430 my_friendly_assert (TREE_CODE (value
) != TREE_LIST
, 999);
3431 context
= (TREE_CODE (value
) == FUNCTION_DECL
3432 && DECL_VIRTUAL_P (value
))
3433 ? DECL_CLASS_CONTEXT (value
)
3434 : DECL_CONTEXT (value
);
3436 if (type
== current_class_type
3438 /* If we don't check CLASSTYPE_CID on CONTEXT right now,
3439 we'll end up subtracting from the address of MI_MATRIX,
3440 putting us off in la la land. */
3441 || (CLASSTYPE_CID (type
)
3442 && TYPE_DERIVES_FROM (context
, type
))
3444 || DERIVED_FROM_P (context
, type
)
3448 /* remove *tmp from list */
3449 *tmp
= TREE_CHAIN (*tmp
);
3452 tmp
= &TREE_CHAIN (*tmp
);
3457 /* Put the new contents in our envelope. */
3458 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3460 *values
= tree_cons (name
, decl
, *values
);
3461 TREE_NONLOCAL_FLAG (*values
) = 1;
3462 TREE_TYPE (*values
) = unknown_type_node
;
3468 *values
= tree_cons (NULL_TREE
, decl
, *values
);
3469 /* Mark this as a potentially ambiguous member. */
3470 /* Leaving TREE_TYPE blank is intentional.
3471 We cannot use `error_mark_node' (lookup_name)
3472 or `unknown_type_node' (all member functions use this). */
3473 TREE_NONLOCAL_FLAG (*values
) = 1;
3481 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
3482 because it (or one of the intermediate bases) depends on template parms. */
3485 dependent_base_p (binfo
)
3488 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
3490 if (TREE_TYPE (binfo
) == current_class_type
)
3492 if (uses_template_parms (TREE_TYPE (binfo
)))
3498 /* Add the instance variables which this class contributed to the
3499 current class binding contour. When a redefinition occurs, if the
3500 redefinition is strictly within a single inheritance path, we just
3501 overwrite the old declaration with the new. If the fields are not
3502 within a single inheritance path, we must cons them.
3504 In order to know what decls are new (stemming from the current
3505 invocation of push_class_decls) we enclose them in an "envelope",
3506 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
3507 new decl (or possibly a list of competing ones), the TREE_VALUE slot
3508 points to the old value and the TREE_CHAIN slot chains together all
3509 envelopes which needs to be "opened" in push_class_decls. Opening an
3510 envelope means: push the old value onto the class_shadowed list,
3511 install the new one and if it's a TYPE_DECL do the same to the
3512 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
3513 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
3514 Because if it is, it could be a set of overloaded methods from an
3518 dfs_pushdecls (binfo
)
3521 tree type
= BINFO_TYPE (binfo
);
3522 tree fields
, *methods
, *end
;
3526 /* Only record types if we're a template base. */
3527 if (processing_template_decl
&& type
!= current_class_type
3528 && dependent_base_p (binfo
))
3531 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3533 if (dummy
&& TREE_CODE (fields
) != TYPE_DECL
)
3536 /* Unmark so that if we are in a constructor, and then find that
3537 this field was initialized by a base initializer,
3538 we can emit an error message. */
3539 if (TREE_CODE (fields
) == FIELD_DECL
)
3540 TREE_USED (fields
) = 0;
3542 /* Recurse into anonymous unions. */
3543 if (DECL_NAME (fields
) == NULL_TREE
3544 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3546 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields
)));
3550 if (DECL_NAME (fields
))
3552 tree name
= DECL_NAME (fields
);
3553 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
3555 /* If the class value is not an envelope of the kind described in
3556 the comment above, we create a new envelope. */
3557 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3558 || TREE_PURPOSE (class_value
) == NULL_TREE
3559 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3561 /* See comment above for a description of envelopes. */
3562 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3564 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
3565 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3568 envelope_add_decl (type
, fields
, &TREE_PURPOSE (class_value
));
3572 method_vec
= CLASSTYPE_METHOD_VEC (type
);
3573 if (method_vec
&& ! dummy
)
3575 /* Farm out constructors and destructors. */
3576 methods
= &TREE_VEC_ELT (method_vec
, 2);
3577 end
= TREE_VEC_END (method_vec
);
3579 while (methods
!= end
)
3581 /* This will cause lookup_name to return a pointer
3582 to the tree_list of possible methods of this name. */
3583 tree name
= DECL_NAME (OVL_CURRENT (*methods
));
3584 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
3586 /* If the class value is not an envelope of the kind described in
3587 the comment above, we create a new envelope. */
3588 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3589 || TREE_PURPOSE (class_value
) == NULL_TREE
3590 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3592 /* See comment above for a description of envelopes. */
3593 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3595 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
3596 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3599 /* Here we try to rule out possible ambiguities.
3600 If we can't do that, keep a TREE_LIST with possibly ambiguous
3602 maybe_push_cache_obstack ();
3603 /* Arbitrarily choose the first function in the list. This is OK
3604 because this is only used for initial lookup; anything that
3605 actually uses the function will look it up again. */
3606 envelope_add_decl (type
, OVL_CURRENT (*methods
),
3607 &TREE_PURPOSE (class_value
));
3614 /* We can't just use BINFO_MARKED because envelope_add_decl uses
3615 DERIVED_FROM_P, which calls get_base_distance. */
3616 SET_BINFO_PUSHDECLS_MARKED (binfo
);
3619 /* Consolidate unique (by name) member functions. */
3622 dfs_compress_decls (binfo
)
3625 tree type
= BINFO_TYPE (binfo
);
3626 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
3628 if (processing_template_decl
&& type
!= current_class_type
3629 && dependent_base_p (binfo
))
3630 /* We only record types if we're a template base. */;
3631 else if (method_vec
!= 0)
3633 /* Farm out constructors and destructors. */
3634 tree
*methods
= &TREE_VEC_ELT (method_vec
, 2);
3635 tree
*end
= TREE_VEC_END (method_vec
);
3637 for (; methods
!= end
; methods
++)
3639 /* This is known to be an envelope of the kind described before
3642 IDENTIFIER_CLASS_VALUE (DECL_NAME (OVL_CURRENT (*methods
)));
3643 tree tmp
= TREE_PURPOSE (class_value
);
3645 /* This was replaced in scope by somebody else. Just leave it
3647 if (TREE_CODE (tmp
) != TREE_LIST
)
3650 if (TREE_CHAIN (tmp
) == NULL_TREE
3652 && OVL_NEXT (TREE_VALUE (tmp
)) == NULL_TREE
)
3654 TREE_PURPOSE (class_value
) = TREE_VALUE (tmp
);
3658 CLEAR_BINFO_PUSHDECLS_MARKED (binfo
);
3661 /* When entering the scope of a class, we cache all of the
3662 fields that that class provides within its inheritance
3663 lattice. Where ambiguities result, we mark them
3664 with `error_mark_node' so that if they are encountered
3665 without explicit qualification, we can emit an error
3669 push_class_decls (type
)
3672 struct obstack
*ambient_obstack
= current_obstack
;
3673 search_stack
= push_search_level (search_stack
, &search_obstack
);
3675 /* Push class fields into CLASS_VALUE scope, and mark. */
3676 dfs_walk (TYPE_BINFO (type
), dfs_pushdecls
, unmarked_pushdecls_p
);
3678 /* Compress fields which have only a single entry
3679 by a given name, and unmark. */
3680 dfs_walk (TYPE_BINFO (type
), dfs_compress_decls
, marked_pushdecls_p
);
3682 /* Open up all the closed envelopes and push the contained decls into
3684 while (closed_envelopes
)
3686 tree
new = TREE_PURPOSE (closed_envelopes
);
3689 /* This is messy because the class value may be a *_DECL, or a
3690 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3691 *_DECLs. The name is stored at different places in these three
3693 if (TREE_CODE (new) == TREE_LIST
)
3695 if (TREE_PURPOSE (new) != NULL_TREE
)
3696 id
= TREE_PURPOSE (new);
3699 tree node
= TREE_VALUE (new);
3701 if (TREE_CODE (node
) == TYPE_DECL
3702 && DECL_ARTIFICIAL (node
)
3703 && IS_AGGR_TYPE (TREE_TYPE (node
))
3704 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (node
)))
3706 tree t
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (node
));
3709 for (; n
; n
= TREE_CHAIN (n
))
3711 tree d
= TREE_VALUE (n
);
3712 if (TREE_CODE (d
) == TYPE_DECL
3713 && DECL_ARTIFICIAL (node
)
3714 && IS_AGGR_TYPE (TREE_TYPE (d
))
3715 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (d
))
3716 && CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d
)) == t
)
3725 else while (TREE_CODE (node
) == TREE_LIST
)
3726 node
= TREE_VALUE (node
);
3727 id
= DECL_NAME (node
);
3731 id
= DECL_NAME (new);
3733 /* Install the original class value in order to make
3734 pushdecl_class_level work correctly. */
3735 IDENTIFIER_CLASS_VALUE (id
) = TREE_VALUE (closed_envelopes
);
3736 if (TREE_CODE (new) == TREE_LIST
)
3737 push_class_level_binding (id
, new);
3739 pushdecl_class_level (new);
3740 closed_envelopes
= TREE_CHAIN (closed_envelopes
);
3742 current_obstack
= ambient_obstack
;
3745 /* Here's a subroutine we need because C lacks lambdas. */
3748 dfs_unuse_fields (binfo
)
3751 tree type
= TREE_TYPE (binfo
);
3754 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3756 if (TREE_CODE (fields
) != FIELD_DECL
)
3759 TREE_USED (fields
) = 0;
3760 if (DECL_NAME (fields
) == NULL_TREE
3761 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3762 unuse_fields (TREE_TYPE (fields
));
3770 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
);
3776 /* We haven't pushed a search level when dealing with cached classes,
3777 so we'd better not try to pop it. */
3779 search_stack
= pop_search_level (search_stack
);
3783 print_search_statistics ()
3785 #ifdef GATHER_STATISTICS
3786 if (flag_memoize_lookups
)
3788 fprintf (stderr
, "%d memoized contexts saved\n",
3790 fprintf (stderr
, "%d local tree nodes made\n", my_tree_node_counter
);
3791 fprintf (stderr
, "%d local hash nodes made\n", my_memoized_entry_counter
);
3792 fprintf (stderr
, "fields statistics:\n");
3793 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3794 memoized_fast_finds
[0], memoized_fast_rejects
[0],
3795 memoized_fields_searched
[0]);
3796 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[0]);
3797 fprintf (stderr
, "fnfields statistics:\n");
3798 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3799 memoized_fast_finds
[1], memoized_fast_rejects
[1],
3800 memoized_fields_searched
[1]);
3801 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[1]);
3803 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3804 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3805 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3806 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3807 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3808 #else /* GATHER_STATISTICS */
3809 fprintf (stderr
, "no search statistics\n");
3810 #endif /* GATHER_STATISTICS */
3814 init_search_processing ()
3816 gcc_obstack_init (&search_obstack
);
3817 gcc_obstack_init (&type_obstack
);
3818 gcc_obstack_init (&type_obstack_entries
);
3820 /* This gives us room to build our chains of basetypes,
3821 whether or not we decide to memoize them. */
3822 type_stack
= push_type_level ((struct stack_level
*)0, &type_obstack
);
3823 _vptr_name
= get_identifier ("_vptr");
3827 reinit_search_statistics ()
3829 my_memoized_entry_counter
= 0;
3830 memoized_fast_finds
[0] = 0;
3831 memoized_fast_finds
[1] = 0;
3832 memoized_adds
[0] = 0;
3833 memoized_adds
[1] = 0;
3834 memoized_fast_rejects
[0] = 0;
3835 memoized_fast_rejects
[1] = 0;
3836 memoized_fields_searched
[0] = 0;
3837 memoized_fields_searched
[1] = 0;
3838 #ifdef GATHER_STATISTICS
3839 n_fields_searched
= 0;
3840 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3841 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3842 n_calls_get_base_type
= 0;
3843 n_outer_fields_searched
= 0;
3844 n_contexts_saved
= 0;
3845 #endif /* GATHER_STATISTICS */
3848 #define scratch_tree_cons expr_tree_cons
3850 static tree conversions
;
3852 add_conversions (binfo
)
3856 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3858 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3860 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3861 if (! IDENTIFIER_TYPENAME_P (DECL_NAME (OVL_CURRENT (tmp
))))
3863 conversions
= scratch_tree_cons (binfo
, tmp
, conversions
);
3865 SET_BINFO_MARKED (binfo
);
3869 lookup_conversions (type
)
3872 conversions
= NULL_TREE
;
3873 if (TYPE_SIZE (type
))
3875 dfs_walk (TYPE_BINFO (type
), add_conversions
, unmarkedp
);
3876 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
);
3881 /* Subroutine of get_template_base. */
3884 get_template_base_recursive (binfo
, rval
, template, via_virtual
)
3885 tree binfo
, template, rval
;
3890 tree type
= BINFO_TYPE (binfo
);
3892 if (CLASSTYPE_TEMPLATE_INFO (type
)
3893 && CLASSTYPE_TI_TEMPLATE (type
) == template)
3895 if (rval
== NULL_TREE
|| rval
== type
)
3898 return error_mark_node
;
3901 binfos
= BINFO_BASETYPES (binfo
);
3902 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3904 /* Process base types. */
3905 for (i
= 0; i
< n_baselinks
; i
++)
3907 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3909 /* Find any specific instance of a virtual base, when searching with
3911 if (BINFO_MARKED (base_binfo
) == 0)
3913 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
3915 /* When searching for a non-virtual, we cannot mark
3916 virtually found binfos. */
3918 SET_BINFO_MARKED (base_binfo
);
3920 rval
= get_template_base_recursive
3921 (base_binfo
, rval
, template, this_virtual
);
3922 if (rval
== error_mark_node
)
3930 /* Given a class template TEMPLATE and a class type or binfo node BINFO,
3931 find the unique base type in BINFO that is an instance of TEMPLATE.
3932 If there are more than one, return error_mark_node. Used by unify. */
3935 get_template_base (template, binfo
)
3936 register tree
template, binfo
;
3938 tree type
= NULL_TREE
, rval
;
3940 if (TREE_CODE (binfo
) == TREE_VEC
)
3941 type
= BINFO_TYPE (binfo
);
3942 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
3944 type
= complete_type (binfo
);
3945 binfo
= TYPE_BINFO (type
);
3948 my_friendly_abort (92);
3950 if (CLASSTYPE_TEMPLATE_INFO (type
)
3951 && CLASSTYPE_TI_TEMPLATE (type
) == template)
3954 rval
= get_template_base_recursive (binfo
, NULL_TREE
, template, 0);
3955 dfs_walk (binfo
, dfs_unmark
, markedp
);
3960 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3961 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3963 static tree compare_type
;
3964 static int found_overlap
;
3966 dfs_check_overlap (empty_binfo
)
3970 for (binfo
= TYPE_BINFO (compare_type
); ; binfo
= BINFO_BASETYPE (binfo
, 0))
3972 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3977 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3982 /* Trivial function to stop base traversal when we find something. */
3985 dfs_no_overlap_yet (t
)
3986 tree t ATTRIBUTE_UNUSED
;
3988 return found_overlap
== 0;
3991 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3992 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3995 types_overlap_p (empty_type
, next_type
)
3996 tree empty_type
, next_type
;
3998 if (! IS_AGGR_TYPE (next_type
))
4000 compare_type
= next_type
;
4002 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
, dfs_no_overlap_yet
);
4003 return found_overlap
;