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
;
264 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_list
));
265 bzero ((char *)p
, sizeof (struct tree_list
));
266 ++my_tree_node_counter
;
267 TREE_SET_CODE (p
, TREE_LIST
);
268 TREE_PURPOSE (p
) = purpose
;
269 TREE_VALUE (p
) = value
;
270 TREE_CHAIN (p
) = chain
;
275 my_build_string (str
)
278 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_string
));
279 ++my_tree_node_counter
;
282 TREE_SET_CODE (p
, STRING_CST
);
283 TREE_STRING_POINTER (p
) = str
;
284 TREE_STRING_LENGTH (p
) = strlen (str
);
288 /* Memoizing machinery to make searches for multiple inheritance
289 reasonably efficient. */
291 #define MEMOIZE_HASHSIZE 8
292 typedef struct memoized_entry
294 struct memoized_entry
*chain
;
296 tree data_members
[MEMOIZE_HASHSIZE
];
297 tree function_members
[MEMOIZE_HASHSIZE
];
300 #define MEMOIZED_CHAIN(ENTRY) (((ME)ENTRY)->chain)
301 #define MEMOIZED_UID(ENTRY) (((ME)ENTRY)->uid)
302 #define MEMOIZED_FIELDS(ENTRY,INDEX) (((ME)ENTRY)->data_members[INDEX])
303 #define MEMOIZED_FNFIELDS(ENTRY,INDEX) (((ME)ENTRY)->function_members[INDEX])
304 /* The following is probably a lousy hash function. */
305 #define MEMOIZED_HASH_FN(NODE) (((long)(NODE)>>4)&(MEMOIZE_HASHSIZE - 1))
307 static struct memoized_entry
*
308 my_new_memoized_entry (chain
)
309 struct memoized_entry
*chain
;
311 struct memoized_entry
*p
312 = (struct memoized_entry
*)obstack_alloc (&type_obstack_entries
,
313 sizeof (struct memoized_entry
));
314 bzero ((char *) p
, sizeof (struct memoized_entry
));
315 MEMOIZED_CHAIN (p
) = chain
;
316 MEMOIZED_UID (p
) = ++my_memoized_entry_counter
;
320 /* Clears the deferred pop from pop_memoized_context, if any. */
323 clear_memoized_cache ()
327 type_stack
= pop_type_level (prev_type_stack
);
328 prev_type_memoized
= 0;
333 /* Make an entry in the memoized table for type TYPE
334 that the entry for NAME is FIELD. */
337 make_memoized_table_entry (type
, name
, function_p
)
341 int idx
= MEMOIZED_HASH_FN (name
);
342 tree entry
, *prev_entry
;
344 /* Since we allocate from the type_obstack, we must pop any deferred
346 clear_memoized_cache ();
348 memoized_adds
[function_p
] += 1;
349 if (CLASSTYPE_MTABLE_ENTRY (type
) == 0)
351 obstack_ptr_grow (&type_obstack
, type
);
352 obstack_blank (&type_obstack
, sizeof (struct memoized_entry
*));
353 CLASSTYPE_MTABLE_ENTRY (type
) = (char *)my_new_memoized_entry ((struct memoized_entry
*)0);
355 if (type_stack
->len
* 2 >= type_stack
->base
.limit
)
356 my_friendly_abort (88);
359 prev_entry
= &MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
361 prev_entry
= &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
363 entry
= my_tree_cons (name
, NULL_TREE
, *prev_entry
);
366 /* Don't know the error message to give yet. */
367 TREE_TYPE (entry
) = error_mark_node
;
372 /* When a new function or class context is entered, we build
373 a table of types which have been searched for members.
374 The table is an array (obstack) of types. When a type is
375 entered into the obstack, its CLASSTYPE_MTABLE_ENTRY
376 field is set to point to a new record, of type struct memoized_entry.
378 A non-NULL TREE_TYPE of the entry contains an access control error message.
380 The slots for the data members are arrays of tree nodes.
381 These tree nodes are lists, with the TREE_PURPOSE
382 of this list the known member name, and the TREE_VALUE
383 as the FIELD_DECL for the member.
385 For member functions, the TREE_PURPOSE is again the
386 name of the member functions for that class,
387 and the TREE_VALUE of the list is a pairs
388 whose TREE_PURPOSE is a member functions of this name,
389 and whose TREE_VALUE is a list of known argument lists this
390 member function has been called with. The TREE_TYPE of the pair,
391 if non-NULL, is an error message to print. */
393 /* Tell search machinery that we are entering a new context, and
394 to update tables appropriately.
396 TYPE is the type of the context we are entering, which can
397 be NULL_TREE if we are not in a class's scope.
399 USE_OLD, if nonzero tries to use previous context. */
402 push_memoized_context (type
, use_old
)
411 if (use_old
&& prev_type_memoized
== type
)
413 #ifdef GATHER_STATISTICS
415 #endif /* GATHER_STATISTICS */
416 type_stack
= prev_type_stack
;
419 tem
= &type_stack
->base
.first
[0];
420 len
= type_stack
->len
;
422 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]) = (char *)tem
[len
*2+1];
425 /* Otherwise, need to pop old stack here. */
426 clear_memoized_cache ();
429 type_stack
= push_type_level ((struct stack_level
*)type_stack
,
431 type_stack
->type
= type
;
434 /* Tell search machinery that we have left a context.
435 We do not currently save these contexts for later use.
436 If we wanted to, we could not use pop_search_level, since
437 poping that level allows the data we have collected to
438 be clobbered; a stack of obstacks would be needed. */
441 pop_memoized_context (use_old
)
445 tree
*tem
= &type_stack
->base
.first
[0];
447 if (! flag_save_memoized_contexts
)
451 len
= type_stack
->len
;
453 tem
[len
*2+1] = (tree
)CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]);
455 /* If there was a deferred pop, we need to pop it now. */
456 clear_memoized_cache ();
458 prev_type_stack
= type_stack
;
459 prev_type_memoized
= type_stack
->type
;
462 if (flag_memoize_lookups
)
464 len
= type_stack
->len
;
466 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2])
467 = (char *)MEMOIZED_CHAIN (CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]));
470 type_stack
= pop_type_level (type_stack
);
472 type_stack
= (struct type_level
*)type_stack
->base
.prev
;
475 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
476 the same type as the type given in PARENT. To be optimal, we want
477 the first one that is found by going through the least number of
481 get_vbase_1 (parent
, binfo
, depth
)
487 tree rval
= NULL_TREE
;
489 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
497 binfos
= BINFO_BASETYPES (binfo
);
498 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
500 /* Process base types. */
501 for (i
= 0; i
< n_baselinks
; i
++)
503 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
509 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
518 get_vbase (parent
, binfo
)
522 unsigned int d
= (unsigned int)-1;
523 return get_vbase_1 (parent
, binfo
, &d
);
526 /* Convert EXPR to a virtual base class of type TYPE. We know that
527 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
528 the type of what expr points to has a virtual base of type TYPE. */
531 convert_pointer_to_vbase (type
, expr
)
535 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
536 return convert_pointer_to_real (vb
, expr
);
539 /* Check whether the type given in BINFO is derived from PARENT. If
540 it isn't, return 0. If it is, but the derivation is MI-ambiguous
541 AND protect != 0, emit an error message and return error_mark_node.
543 Otherwise, if TYPE is derived from PARENT, return the actual base
544 information, unless a one of the protection violations below
545 occurs, in which case emit an error message and return error_mark_node.
547 If PROTECT is 1, then check if access to a public field of PARENT
548 would be private. Also check for ambiguity. */
551 get_binfo (parent
, binfo
, protect
)
552 register tree parent
, binfo
;
555 tree type
= NULL_TREE
;
557 tree rval
= NULL_TREE
;
559 if (TREE_CODE (parent
) == TREE_VEC
)
560 parent
= BINFO_TYPE (parent
);
561 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
562 my_friendly_abort (89);
564 if (TREE_CODE (binfo
) == TREE_VEC
)
565 type
= BINFO_TYPE (binfo
);
566 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
569 my_friendly_abort (90);
571 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
575 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
577 return error_mark_node
;
579 else if (dist
== -2 && protect
)
581 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
583 return error_mark_node
;
589 /* This is the newer depth first get_base_distance routine. */
592 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
593 rval_private_ptr
, new_binfo_ptr
, parent
, path_ptr
,
594 protect
, via_virtual_ptr
, via_virtual
,
595 current_scope_in_chain
)
597 int depth
, is_private
, rval
;
598 int *rval_private_ptr
;
599 tree
*new_binfo_ptr
, parent
, *path_ptr
;
600 int protect
, *via_virtual_ptr
, via_virtual
;
601 int current_scope_in_chain
;
607 && !current_scope_in_chain
608 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
609 current_scope_in_chain
= 1;
611 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
616 *rval_private_ptr
= is_private
;
617 *new_binfo_ptr
= binfo
;
618 *via_virtual_ptr
= via_virtual
;
622 int same_object
= (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
623 BINFO_OFFSET (binfo
))
624 && *via_virtual_ptr
&& via_virtual
);
626 if (*via_virtual_ptr
&& via_virtual
==0)
628 *rval_private_ptr
= is_private
;
629 *new_binfo_ptr
= binfo
;
630 *via_virtual_ptr
= via_virtual
;
632 else if (same_object
)
634 if (*rval_private_ptr
&& ! is_private
)
636 *rval_private_ptr
= is_private
;
637 *new_binfo_ptr
= binfo
;
638 *via_virtual_ptr
= via_virtual
;
648 binfos
= BINFO_BASETYPES (binfo
);
649 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
652 /* Process base types. */
653 for (i
= 0; i
< n_baselinks
; i
++)
655 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
657 /* Find any specific instance of a virtual base, when searching with
659 if (BINFO_MARKED (base_binfo
) == 0 || TREE_CODE (parent
) == TREE_VEC
)
664 || (!TREE_VIA_PUBLIC (base_binfo
)
665 && !(TREE_VIA_PROTECTED (base_binfo
)
666 && current_scope_in_chain
)
667 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
668 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
671 /* When searching for a non-virtual, we cannot mark
672 virtually found binfos. */
674 SET_BINFO_MARKED (base_binfo
);
676 #define WATCH_VALUES(rval, via_private) (rval == -1 ? 3 : via_private)
678 was
= WATCH_VALUES (rval
, *via_virtual_ptr
);
679 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
680 rval
, rval_private_ptr
,
681 new_binfo_ptr
, parent
, path_ptr
,
682 protect
, via_virtual_ptr
,
684 current_scope_in_chain
);
685 /* watch for updates; only update if path is good. */
686 if (path_ptr
&& WATCH_VALUES (rval
, *via_virtual_ptr
) != was
)
687 BINFO_INHERITANCE_CHAIN (base_binfo
) = binfo
;
688 if (rval
== -2 && *via_virtual_ptr
== 0)
699 /* Return the number of levels between type PARENT and the type given
700 in BINFO, following the leftmost path to PARENT not found along a
701 virtual path, if there are no real PARENTs (all come from virtual
702 base classes), then follow the leftmost path to PARENT.
704 Return -1 if TYPE is not derived from PARENT.
705 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
707 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
709 If PATH_PTR is non-NULL, then also build the list of types
710 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
713 PARENT can also be a binfo, in which case that exact parent is found
714 and no other. convert_pointer_to_real uses this functionality.
716 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
719 get_base_distance (parent
, binfo
, protect
, path_ptr
)
720 register tree parent
, binfo
;
725 int rval_private
= 0;
726 tree type
= NULL_TREE
;
727 tree new_binfo
= NULL_TREE
;
729 int watch_access
= protect
;
731 /* Should we be completing types here? */
732 if (TREE_CODE (parent
) != TREE_VEC
)
733 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
735 complete_type (TREE_TYPE (parent
));
737 if (TREE_CODE (binfo
) == TREE_VEC
)
738 type
= BINFO_TYPE (binfo
);
739 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
741 type
= complete_type (binfo
);
742 binfo
= TYPE_BINFO (type
);
745 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
748 my_friendly_abort (92);
750 if (parent
== type
|| parent
== binfo
)
752 /* If the distance is 0, then we don't really need
753 a path pointer, but we shouldn't let garbage go back. */
762 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
763 &rval_private
, &new_binfo
, parent
,
764 path_ptr
, watch_access
, &via_virtual
, 0,
767 dfs_walk (binfo
, dfs_unmark
, markedp
);
769 /* Access restrictions don't count if we found an ambiguous basetype. */
770 if (rval
== -2 && protect
>= 0)
773 if (rval
&& protect
&& rval_private
)
776 /* find real virtual base classes. */
777 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
778 && parent
== binfo_member (BINFO_TYPE (parent
),
779 CLASSTYPE_VBASECLASSES (type
)))
781 BINFO_INHERITANCE_CHAIN (parent
) = binfo
;
787 *path_ptr
= new_binfo
;
791 /* Search for a member with name NAME in a multiple inheritance lattice
792 specified by TYPE. If it does not exist, return NULL_TREE.
793 If the member is ambiguously referenced, return `error_mark_node'.
794 Otherwise, return the FIELD_DECL. */
796 /* Do a 1-level search for NAME as a member of TYPE. The caller must
797 figure out whether it can access this field. (Since it is only one
798 level, this is reasonable.) */
801 lookup_field_1 (type
, name
)
806 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
807 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
808 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
809 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
810 the code often worked even when we treated the index as a list
814 field
= TYPE_FIELDS (type
);
816 #ifdef GATHER_STATISTICS
817 n_calls_lookup_field_1
++;
818 #endif /* GATHER_STATISTICS */
821 #ifdef GATHER_STATISTICS
823 #endif /* GATHER_STATISTICS */
824 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
825 if (DECL_NAME (field
) == NULL_TREE
826 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
828 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
832 if (DECL_NAME (field
) == name
)
834 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
835 && DECL_ASSEMBLER_NAME (field
) != NULL
)
836 GNU_xref_ref(current_function_decl
,
837 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
840 field
= TREE_CHAIN (field
);
843 if (name
== _vptr_name
)
845 /* Give the user what s/he thinks s/he wants. */
846 if (TYPE_VIRTUAL_P (type
))
847 return CLASSTYPE_VFIELD (type
);
852 /* There are a number of cases we need to be aware of here:
853 current_class_type current_function_decl
860 Those last two make life interesting. If we're in a function which is
861 itself inside a class, we need decls to go into the fn's decls (our
862 second case below). But if we're in a class and the class itself is
863 inside a function, we need decls to go into the decls for the class. To
864 achieve this last goal, we must see if, when both current_class_ptr and
865 current_function_decl are set, the class was declared inside that
866 function. If so, we know to put the decls into the class's scope. */
871 if (current_function_decl
== NULL_TREE
)
872 return current_class_type
;
873 if (current_class_type
== NULL_TREE
)
874 return current_function_decl
;
875 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
876 return current_function_decl
;
878 return current_class_type
;
881 /* Compute the access of FIELD. This is done by computing
882 the access available to each type in BASETYPES (which comes
883 as a list of [via_public/basetype] in reverse order, namely base
884 class before derived class). The first one which defines a
885 access defines the access for the field. Otherwise, the
886 access of the field is that which occurs normally.
888 Uses global variables CURRENT_CLASS_TYPE and
889 CURRENT_FUNCTION_DECL to use friend relationships
892 This will be static when lookup_fnfield comes into this file.
894 access_public_node means that the field can be accessed by the current lexical
897 access_protected_node means that the field cannot be accessed by the current
898 lexical scope because it is protected.
900 access_private_node means that the field cannot be accessed by the current
901 lexical scope because it is private. */
904 #define PUBLIC_RETURN return (DECL_PUBLIC (field) = 1), access_public_node
905 #define PROTECTED_RETURN return (DECL_PROTECTED (field) = 1), access_protected_node
906 #define PRIVATE_RETURN return (DECL_PRIVATE (field) = 1), access_private_node
908 #define PUBLIC_RETURN return access_public_node
909 #define PROTECTED_RETURN return access_protected_node
910 #define PRIVATE_RETURN return access_private_node
914 /* Disabled with DECL_PUBLIC &c. */
915 static tree previous_scope
= NULL_TREE
;
919 compute_access (basetype_path
, field
)
920 tree basetype_path
, field
;
925 int protected_ok
, via_protected
;
926 extern int flag_access_control
;
928 /* Replaces static decl above. */
932 = ((TREE_CODE (field
) == FUNCTION_DECL
&& DECL_STATIC_FUNCTION_P (field
))
933 || (TREE_CODE (field
) != FUNCTION_DECL
&& TREE_STATIC (field
)));
935 if (! flag_access_control
)
936 return access_public_node
;
938 /* The field lives in the current class. */
939 if (BINFO_TYPE (basetype_path
) == current_class_type
)
940 return access_public_node
;
943 /* Disabled until pushing function scope clears these out. If ever. */
944 /* Make these special cases fast. */
945 if (current_scope () == previous_scope
)
947 if (DECL_PUBLIC (field
))
948 return access_public_node
;
949 if (DECL_PROTECTED (field
))
950 return access_protected_node
;
951 if (DECL_PRIVATE (field
))
952 return access_private_node
;
956 /* We don't currently support access control on nested types. */
957 if (TREE_CODE (field
) == TYPE_DECL
)
958 return access_public_node
;
960 previous_scope
= current_scope ();
962 context
= DECL_REAL_CONTEXT (field
);
964 /* Fields coming from nested anonymous unions have their DECL_CLASS_CONTEXT
965 slot set to the union type rather than the record type containing
966 the anonymous union. */
967 if (context
&& ANON_UNION_TYPE_P (context
)
968 && TREE_CODE (field
) == FIELD_DECL
)
969 context
= TYPE_CONTEXT (context
);
971 /* Virtual function tables are never private. But we should know that
972 we are looking for this, and not even try to hide it. */
973 if (DECL_NAME (field
) && VFIELD_NAME_P (DECL_NAME (field
)) == 1)
976 /* Member found immediately within object. */
977 if (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
)
979 /* Are we (or an enclosing scope) friends with the class that has
981 if (is_friend (context
, previous_scope
))
984 /* If it's private, it's private, you letch. */
985 if (TREE_PRIVATE (field
))
988 /* ARM $11.5. Member functions of a derived class can access the
989 non-static protected members of a base class only through a
990 pointer to the derived class, a reference to it, or an object
991 of it. Also any subsequently derived classes also have
993 else if (TREE_PROTECTED (field
))
995 if (current_class_type
996 && (static_mem
|| DECL_CONSTRUCTOR_P (field
))
997 && ACCESSIBLY_DERIVED_FROM_P (context
, current_class_type
))
1006 /* must reverse more than one element */
1007 basetype_path
= reverse_path (basetype_path
);
1008 types
= basetype_path
;
1010 access
= access_default_node
;
1011 protected_ok
= static_mem
&& current_class_type
1012 && ACCESSIBLY_DERIVED_FROM_P (BINFO_TYPE (types
), current_class_type
);
1018 tree type
= BINFO_TYPE (binfo
);
1021 /* Friends of a class can see protected members of its bases.
1022 Note that classes are their own friends. */
1023 if (is_friend (type
, previous_scope
))
1029 member
= purpose_member (type
, DECL_ACCESS (field
));
1032 access
= TREE_VALUE (member
);
1036 types
= BINFO_INHERITANCE_CHAIN (types
);
1038 /* If the next type was VIA_PROTECTED, then fields of all remaining
1039 classes past that one are *at least* protected. */
1042 if (TREE_VIA_PROTECTED (types
))
1044 else if (! TREE_VIA_PUBLIC (types
) && ! private_ok
)
1046 access
= access_private_node
;
1053 reverse_path (basetype_path
);
1055 /* No special visibilities apply. Use normal rules. */
1057 if (access
== access_default_node
)
1059 if (is_friend (context
, previous_scope
))
1060 access
= access_public_node
;
1061 else if (TREE_PRIVATE (field
))
1062 access
= access_private_node
;
1063 else if (TREE_PROTECTED (field
))
1064 access
= access_protected_node
;
1066 access
= access_public_node
;
1069 if (access
== access_public_node
&& via_protected
)
1070 access
= access_protected_node
;
1072 if (access
== access_protected_node
&& protected_ok
)
1073 access
= access_public_node
;
1076 if (access
== access_public_node
)
1077 DECL_PUBLIC (field
) = 1;
1078 else if (access
== access_protected_node
)
1079 DECL_PROTECTED (field
) = 1;
1080 else if (access
== access_private_node
)
1081 DECL_PRIVATE (field
) = 1;
1082 else my_friendly_abort (96);
1087 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1088 found as a base class and sub-object of the object denoted by
1089 BINFO. This routine relies upon binfos not being shared, except
1090 for binfos for virtual bases. */
1093 is_subobject_of_p (parent
, binfo
)
1096 tree binfos
= BINFO_BASETYPES (binfo
);
1097 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1099 if (parent
== binfo
)
1102 /* Process and/or queue base types. */
1103 for (i
= 0; i
< n_baselinks
; i
++)
1105 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1106 if (TREE_VIA_VIRTUAL (base_binfo
))
1107 base_binfo
= TYPE_BINFO (BINFO_TYPE (base_binfo
));
1108 if (is_subobject_of_p (parent
, base_binfo
))
1114 /* See if a one FIELD_DECL hides another. This routine is meant to
1115 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1116 binfos given are the binfos corresponding to the particular places
1117 the FIELD_DECLs are found. This routine relies upon binfos not
1118 being shared, except for virtual bases. */
1121 hides (hider_binfo
, hidee_binfo
)
1122 tree hider_binfo
, hidee_binfo
;
1124 /* hider hides hidee, if hider has hidee as a base class and
1125 the instance of hidee is a sub-object of hider. The first
1126 part is always true is the second part is true.
1128 When hider and hidee are the same (two ways to get to the exact
1129 same member) we consider either one as hiding the other. */
1130 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
1133 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1134 function was declared inside the class given by TYPE. It really should
1135 only return functions that match the given TYPE. */
1138 lookup_fnfields_here (type
, name
)
1141 int idx
= lookup_fnfields_1 (type
, name
);
1144 /* ctors and dtors are always only in the right class. */
1147 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1150 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls
)))
1151 == TYPE_MAIN_VARIANT (type
))
1153 fndecls
= OVL_CHAIN (fndecls
);
1158 /* Look for a field named NAME in an inheritance lattice dominated by
1159 XBASETYPE. PROTECT is zero if we can avoid computing access
1160 information, otherwise it is 1. WANT_TYPE is 1 when we should only
1161 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
1163 It was not clear what should happen if WANT_TYPE is set, and an
1164 ambiguity is found. At least one use (lookup_name) to not see
1168 lookup_field (xbasetype
, name
, protect
, want_type
)
1169 register tree xbasetype
, name
;
1170 int protect
, want_type
;
1172 int head
= 0, tail
= 0;
1173 tree rval
, rval_binfo
= NULL_TREE
, rval_binfo_h
= NULL_TREE
;
1174 tree type
= NULL_TREE
, basetype_chain
, basetype_path
= NULL_TREE
;
1175 tree this_v
= access_default_node
;
1176 tree entry
, binfo
, binfo_h
;
1177 tree own_access
= access_default_node
;
1178 int vbase_name_p
= VBASE_NAME_P (name
);
1180 /* rval_binfo is the binfo associated with the found member, note,
1181 this can be set with useful information, even when rval is not
1182 set, because it must deal with ALL members, not just non-function
1183 members. It is used for ambiguity checking and the hidden
1184 checks. Whereas rval is only set if a proper (not hidden)
1185 non-function member is found. */
1187 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1188 hiding checks, as virtual base classes may not be shared. The strategy
1189 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1190 virtual base classes, as we cross virtual base class lines. This way
1191 we know that binfo of a virtual base class will always == itself when
1192 found along any line. (mrs) */
1196 /* Set this to nonzero if we don't know how to compute
1197 accurate error messages for access control. */
1198 int idx
= MEMOIZED_HASH_FN (name
);
1201 /* We cannot search for constructor/destructor names like this. */
1202 /* This can't go here, but where should it go? */
1203 /* If we are looking for a constructor in a templated type, use the
1204 unspecialized name, as that is how we store it. */
1205 if (IDENTIFIER_TEMPLATE (name
))
1206 name
= constructor_name (name
);
1209 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
1210 && IDENTIFIER_CLASS_VALUE (name
))
1212 tree field
= IDENTIFIER_CLASS_VALUE (name
);
1213 if (TREE_CODE (field
) != FUNCTION_DECL
1214 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
1218 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1220 type
= BINFO_TYPE (xbasetype
);
1221 basetype_path
= xbasetype
;
1223 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1226 basetype_path
= TYPE_BINFO (type
);
1227 BINFO_VIA_PUBLIC (basetype_path
) = 1;
1228 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1231 my_friendly_abort (97);
1233 complete_type (type
);
1235 if (CLASSTYPE_MTABLE_ENTRY (type
))
1237 tree tem
= MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
1239 while (tem
&& TREE_PURPOSE (tem
) != name
)
1241 memoized_fields_searched
[0]++;
1242 tem
= TREE_CHAIN (tem
);
1246 if (protect
&& TREE_TYPE (tem
))
1248 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1249 IDENTIFIER_POINTER (name
),
1250 TYPE_NAME_STRING (DECL_FIELD_CONTEXT (TREE_VALUE (tem
))));
1251 return error_mark_node
;
1253 if (TREE_VALUE (tem
) == NULL_TREE
)
1254 memoized_fast_rejects
[0] += 1;
1256 memoized_fast_finds
[0] += 1;
1257 return TREE_VALUE (tem
);
1261 #ifdef GATHER_STATISTICS
1262 n_calls_lookup_field
++;
1263 #endif /* GATHER_STATISTICS */
1264 if (protect
&& flag_memoize_lookups
&& ! toplevel_bindings_p ())
1265 entry
= make_memoized_table_entry (type
, name
, 0);
1269 rval
= lookup_field_1 (type
, name
);
1271 if (rval
|| lookup_fnfields_here (type
, name
) >= 0)
1274 TREE_VALUE (entry
) = rval
;
1280 if (TREE_CODE (rval
) != TYPE_DECL
)
1282 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
1284 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
1289 if (TREE_CODE (rval
) == TYPE_DECL
1290 && lookup_fnfields_here (type
, name
) >= 0)
1295 if (protect
&& rval
)
1297 if (TREE_PRIVATE (rval
) | TREE_PROTECTED (rval
))
1298 this_v
= compute_access (basetype_path
, rval
);
1299 if (TREE_CODE (rval
) == CONST_DECL
)
1301 if (this_v
== access_private_node
)
1302 errstr
= "enum `%D' is a private value of class `%T'";
1303 else if (this_v
== access_protected_node
)
1304 errstr
= "enum `%D' is a protected value of class `%T'";
1308 if (this_v
== access_private_node
)
1309 errstr
= "member `%D' is a private member of class `%T'";
1310 else if (this_v
== access_protected_node
)
1311 errstr
= "member `%D' is a protected member of class `%T'";
1315 rval_binfo
= basetype_path
;
1319 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
1320 TREE_VIA_PUBLIC (basetype_chain
) = TREE_VIA_PUBLIC (basetype_path
);
1321 TREE_VIA_PROTECTED (basetype_chain
) = TREE_VIA_PROTECTED (basetype_path
);
1322 TREE_VIA_VIRTUAL (basetype_chain
) = TREE_VIA_VIRTUAL (basetype_path
);
1324 /* The ambiguity check relies upon breadth first searching. */
1326 search_stack
= push_search_level (search_stack
, &search_obstack
);
1327 binfo
= basetype_path
;
1332 tree binfos
= BINFO_BASETYPES (binfo
);
1333 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1336 /* Process and/or queue base types. */
1337 for (i
= 0; i
< n_baselinks
; i
++)
1339 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1340 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1344 SET_BINFO_FIELDS_MARKED (base_binfo
);
1345 btypes
= my_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1346 TREE_VIA_PUBLIC (btypes
) = TREE_VIA_PUBLIC (base_binfo
);
1347 TREE_VIA_PROTECTED (btypes
) = TREE_VIA_PROTECTED (base_binfo
);
1348 TREE_VIA_VIRTUAL (btypes
) = TREE_VIA_VIRTUAL (base_binfo
);
1349 if (TREE_VIA_VIRTUAL (base_binfo
))
1350 btypes
= my_tree_cons (NULL_TREE
,
1351 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1354 btypes
= my_tree_cons (NULL_TREE
,
1355 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1357 obstack_ptr_grow (&search_obstack
, btypes
);
1359 if (tail
>= search_stack
->limit
)
1360 my_friendly_abort (98);
1364 /* Process head of queue, if one exists. */
1368 basetype_chain
= search_stack
->first
[head
++];
1369 binfo_h
= TREE_VALUE (basetype_chain
);
1370 basetype_chain
= TREE_CHAIN (basetype_chain
);
1371 basetype_path
= TREE_VALUE (basetype_chain
);
1372 if (TREE_CHAIN (basetype_chain
))
1373 BINFO_INHERITANCE_CHAIN (basetype_path
) = TREE_VALUE (TREE_CHAIN (basetype_chain
));
1375 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1377 binfo
= basetype_path
;
1378 type
= BINFO_TYPE (binfo
);
1380 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1381 and we do find NAME in TYPE, verify that such a second
1382 sighting is in fact valid. */
1384 nval
= lookup_field_1 (type
, name
);
1386 if (nval
|| lookup_fnfields_here (type
, name
)>=0)
1388 if (nval
&& nval
== rval
&& SHARED_MEMBER_P (nval
))
1390 /* This is ok, the member found is the same [class.ambig] */
1392 else if (rval_binfo
&& hides (rval_binfo_h
, binfo_h
))
1394 /* This is ok, the member found is in rval_binfo, not
1397 else if (rval_binfo
==NULL_TREE
|| hides (binfo_h
, rval_binfo_h
))
1399 /* This is ok, the member found is here (binfo), not in
1404 if (entry
|| protect
)
1405 this_v
= compute_access (basetype_path
, rval
);
1406 /* These may look ambiguous, but they really are not. */
1412 /* Undo finding it before, as something else hides it. */
1416 rval_binfo_h
= binfo_h
;
1420 /* This is ambiguous. */
1421 errstr
= "request for member `%D' is ambiguous";
1428 tree
*tp
= search_stack
->first
;
1429 tree
*search_tail
= tp
+ tail
;
1432 TREE_VALUE (entry
) = rval
;
1436 type
= BINFO_TYPE (rval_binfo
);
1442 if (TREE_CODE (rval
) != TYPE_DECL
)
1444 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
1446 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
1451 if (TREE_CODE (rval
) == TYPE_DECL
1452 && lookup_fnfields_here (type
, name
) >= 0)
1458 if (rval
== NULL_TREE
)
1461 /* If this FIELD_DECL defines its own access level, deal with that. */
1462 if (rval
&& errstr
== 0
1463 && ((protect
&1) || entry
)
1464 && DECL_LANG_SPECIFIC (rval
)
1465 && DECL_ACCESS (rval
))
1467 while (tp
< search_tail
)
1469 /* If is possible for one of the derived types on the path to
1470 have defined special access for this field. Look for such
1471 declarations and report an error if a conflict is found. */
1472 tree new_v
= NULL_TREE
;
1474 if (this_v
!= access_default_node
)
1475 new_v
= compute_access (TREE_VALUE (TREE_CHAIN (*tp
)), rval
);
1476 if (this_v
!= access_default_node
&& new_v
!= this_v
)
1478 errstr
= "conflicting access to member `%D'";
1479 this_v
= access_default_node
;
1482 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1488 while (tp
< search_tail
)
1490 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1495 search_stack
= pop_search_level (search_stack
);
1499 if (own_access
== access_private_node
)
1500 errstr
= "member `%D' declared private";
1501 else if (own_access
== access_protected_node
)
1502 errstr
= "member `%D' declared protected";
1503 else if (this_v
== access_private_node
)
1504 errstr
= TREE_PRIVATE (rval
)
1505 ? "member `%D' is private"
1506 : "member `%D' is from private base class";
1507 else if (this_v
== access_protected_node
)
1508 errstr
= TREE_PROTECTED (rval
)
1509 ? "member `%D' is protected"
1510 : "member `%D' is from protected base class";
1518 tree error_string
= my_build_string (errstr
);
1519 /* Save error message with entry. */
1520 TREE_TYPE (entry
) = error_string
;
1524 /* Mark entry as having no error string. */
1525 TREE_TYPE (entry
) = NULL_TREE
;
1531 /* If we are not interested in ambiguities, don't report them,
1532 just return NULL_TREE. */
1537 if (errstr
&& protect
)
1539 cp_error (errstr
, name
, type
);
1540 rval
= error_mark_node
;
1543 /* Do implicit typename stuff. */
1544 if (rval
&& TREE_CODE (rval
) == TYPE_DECL
1545 && ! DECL_ARTIFICIAL (rval
)
1546 && processing_template_decl
1547 && ! currently_open_class (BINFO_TYPE (rval_binfo
))
1548 && uses_template_parms (type
))
1551 for (; ; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
1552 if (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
1553 || (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
))
1554 == current_class_type
))
1557 entry
= make_typename_type (BINFO_TYPE (binfo
), name
);
1558 TREE_TYPE (entry
) = TREE_TYPE (rval
);
1559 rval
= TYPE_MAIN_DECL (entry
);
1565 /* Try to find NAME inside a nested class. */
1568 lookup_nested_field (name
, complain
)
1574 tree id
= NULL_TREE
;
1575 if (TYPE_MAIN_DECL (current_class_type
))
1577 /* Climb our way up the nested ladder, seeing if we're trying to
1578 modify a field in an enclosing class. If so, we should only
1579 be able to modify if it's static. */
1580 for (t
= TYPE_MAIN_DECL (current_class_type
);
1581 t
&& DECL_CONTEXT (t
);
1582 t
= TYPE_MAIN_DECL (DECL_CONTEXT (t
)))
1584 if (TREE_CODE (DECL_CONTEXT (t
)) != RECORD_TYPE
)
1587 /* N.B.: lookup_field will do the access checking for us */
1588 id
= lookup_field (DECL_CONTEXT (t
), name
, complain
, 0);
1589 if (id
== error_mark_node
)
1595 if (id
!= NULL_TREE
)
1597 if (TREE_CODE (id
) == FIELD_DECL
1598 && ! TREE_STATIC (id
)
1599 && TREE_TYPE (id
) != error_mark_node
)
1603 /* At parse time, we don't want to give this error, since
1604 we won't have enough state to make this kind of
1605 decision properly. But there are times (e.g., with
1606 enums in nested classes) when we do need to call
1607 this fn at parse time. So, in those cases, we pass
1608 complain as a 0 and just return a NULL_TREE. */
1609 cp_error ("assignment to non-static member `%D' of enclosing class `%T'",
1610 id
, DECL_CONTEXT (t
));
1611 /* Mark this for do_identifier(). It would otherwise
1612 claim that the variable was undeclared. */
1613 TREE_TYPE (id
) = error_mark_node
;
1629 /* TYPE is a class type. Return the index of the fields within
1630 the method vector with name NAME, or -1 is no such field exists. */
1633 lookup_fnfields_1 (type
, name
)
1636 register tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1638 if (method_vec
!= 0)
1640 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1641 register tree
*end
= TREE_VEC_END (method_vec
);
1643 #ifdef GATHER_STATISTICS
1644 n_calls_lookup_fnfields_1
++;
1645 #endif /* GATHER_STATISTICS */
1647 /* Constructors are first... */
1648 if (*methods
&& name
== ctor_identifier
)
1651 /* and destructors are second. */
1652 if (*++methods
&& name
== dtor_identifier
)
1655 while (++methods
!= end
)
1657 #ifdef GATHER_STATISTICS
1658 n_outer_fields_searched
++;
1659 #endif /* GATHER_STATISTICS */
1660 if (DECL_NAME (OVL_CURRENT (*methods
)) == name
)
1664 /* If we didn't find it, it might have been a template
1665 conversion operator. (Note that we don't look for this case
1666 above so that we will always find specializations first.) */
1668 && IDENTIFIER_TYPENAME_P (name
))
1670 methods
= &TREE_VEC_ELT (method_vec
, 0) + 1;
1672 while (++methods
!= end
)
1674 if (TREE_CODE (OVL_CURRENT (*methods
)) == TEMPLATE_DECL
1675 && IDENTIFIER_TYPENAME_P (DECL_NAME (OVL_CURRENT (*methods
))))
1681 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1687 /* Starting from BASETYPE, return a TREE_BASELINK-like object
1688 which gives the following information (in a list):
1690 TREE_TYPE: list of basetypes needed to get to...
1691 TREE_VALUE: list of all functions in a given type
1692 which have name NAME.
1694 No access information is computed by this function,
1695 other then to adorn the list of basetypes with
1698 If there are two ways to find a name (two members), if COMPLAIN is
1699 non-zero, then error_mark_node is returned, and an error message is
1700 printed, otherwise, just an error_mark_node is returned.
1702 As a special case, is COMPLAIN is -1, we don't complain, and we
1703 don't return error_mark_node, but rather the complete list of
1704 virtuals. This is used by get_virtuals_named_this. */
1707 lookup_fnfields (basetype_path
, name
, complain
)
1708 tree basetype_path
, name
;
1711 int head
= 0, tail
= 0;
1712 tree type
, rval
, rval_binfo
= NULL_TREE
, rvals
= NULL_TREE
;
1713 tree rval_binfo_h
= NULL_TREE
, entry
, binfo
, basetype_chain
, binfo_h
;
1716 /* rval_binfo is the binfo associated with the found member, note,
1717 this can be set with useful information, even when rval is not
1718 set, because it must deal with ALL members, not just function
1719 members. It is used for ambiguity checking and the hidden
1720 checks. Whereas rval is only set if a proper (not hidden)
1721 function member is found. */
1723 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1724 hiding checks, as virtual base classes may not be shared. The strategy
1725 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1726 virtual base classes, as we cross virtual base class lines. This way
1727 we know that binfo of a virtual base class will always == itself when
1728 found along any line. (mrs) */
1730 /* For now, don't try this. */
1731 int protect
= complain
;
1735 /* Set this to nonzero if we don't know how to compute
1736 accurate error messages for access control. */
1737 int idx
= MEMOIZED_HASH_FN (name
);
1742 protect
= complain
= 0;
1746 /* We cannot search for constructor/destructor names like this. */
1747 /* This can't go here, but where should it go? */
1748 /* If we are looking for a constructor in a templated type, use the
1749 unspecialized name, as that is how we store it. */
1750 if (IDENTIFIER_TEMPLATE (name
))
1751 name
= constructor_name (name
);
1754 binfo
= basetype_path
;
1756 type
= complete_type (BINFO_TYPE (basetype_path
));
1758 /* The memoization code is in need of maintenance. */
1759 if (!find_all
&& CLASSTYPE_MTABLE_ENTRY (type
))
1761 tree tem
= MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), idx
);
1763 while (tem
&& TREE_PURPOSE (tem
) != name
)
1765 memoized_fields_searched
[1]++;
1766 tem
= TREE_CHAIN (tem
);
1770 if (protect
&& TREE_TYPE (tem
))
1772 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1773 IDENTIFIER_POINTER (name
),
1774 TYPE_NAME_STRING (DECL_CLASS_CONTEXT (TREE_VALUE (TREE_VALUE (tem
)))));
1775 return error_mark_node
;
1777 if (TREE_VALUE (tem
) == NULL_TREE
)
1779 memoized_fast_rejects
[1] += 1;
1784 /* Want to return this, but we must make sure
1785 that access information is consistent. */
1786 tree baselink
= TREE_VALUE (tem
);
1787 tree memoized_basetypes
= TREE_PURPOSE (baselink
);
1788 tree these_basetypes
= basetype_path
;
1789 while (memoized_basetypes
&& these_basetypes
)
1791 memoized_fields_searched
[1]++;
1792 if (TREE_VALUE (memoized_basetypes
) != these_basetypes
)
1794 memoized_basetypes
= TREE_CHAIN (memoized_basetypes
);
1795 these_basetypes
= BINFO_INHERITANCE_CHAIN (these_basetypes
);
1797 /* The following statement is true only when both are NULL. */
1798 if (memoized_basetypes
== these_basetypes
)
1800 memoized_fast_finds
[1] += 1;
1801 return TREE_VALUE (tem
);
1803 /* else, we must re-find this field by hand. */
1804 baselink
= tree_cons (basetype_path
, TREE_VALUE (baselink
), TREE_CHAIN (baselink
));
1810 #ifdef GATHER_STATISTICS
1811 n_calls_lookup_fnfields
++;
1812 #endif /* GATHER_STATISTICS */
1813 if (protect
&& flag_memoize_lookups
&& ! toplevel_bindings_p ())
1814 entry
= make_memoized_table_entry (type
, name
, 1);
1818 idx
= lookup_fnfields_here (type
, name
);
1819 if (idx
>= 0 || lookup_field_1 (type
, name
))
1821 rval_binfo
= basetype_path
;
1822 rval_binfo_h
= rval_binfo
;
1827 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1828 rvals
= my_tree_cons (basetype_path
, rval
, rvals
);
1829 if (BINFO_BASETYPES (binfo
) && CLASSTYPE_BASELINK_VEC (type
))
1830 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1834 TREE_VALUE (entry
) = rvals
;
1835 TREE_TYPE (entry
) = NULL_TREE
;
1842 if (name
== ctor_identifier
|| name
== dtor_identifier
)
1844 /* Don't allow lookups of constructors and destructors to go
1845 deeper than the first place we look. */
1847 TREE_TYPE (entry
) = TREE_VALUE (entry
) = NULL_TREE
;
1852 if (basetype_path
== TYPE_BINFO (type
))
1854 basetype_chain
= CLASSTYPE_BINFO_AS_LIST (type
);
1855 TREE_VIA_PUBLIC (basetype_chain
) = 1;
1856 BINFO_VIA_PUBLIC (basetype_path
) = 1;
1857 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1861 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
1862 TREE_VIA_PUBLIC (basetype_chain
) = TREE_VIA_PUBLIC (basetype_path
);
1863 TREE_VIA_PROTECTED (basetype_chain
) = TREE_VIA_PROTECTED (basetype_path
);
1864 TREE_VIA_VIRTUAL (basetype_chain
) = TREE_VIA_VIRTUAL (basetype_path
);
1867 /* The ambiguity check relies upon breadth first searching. */
1869 search_stack
= push_search_level (search_stack
, &search_obstack
);
1870 binfo
= basetype_path
;
1875 tree binfos
= BINFO_BASETYPES (binfo
);
1876 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1879 /* Process and/or queue base types. */
1880 for (i
= 0; i
< n_baselinks
; i
++)
1882 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1883 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1887 SET_BINFO_FIELDS_MARKED (base_binfo
);
1888 btypes
= my_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1889 TREE_VIA_PUBLIC (btypes
) = TREE_VIA_PUBLIC (base_binfo
);
1890 TREE_VIA_PROTECTED (btypes
) = TREE_VIA_PROTECTED (base_binfo
);
1891 TREE_VIA_VIRTUAL (btypes
) = TREE_VIA_VIRTUAL (base_binfo
);
1892 if (TREE_VIA_VIRTUAL (base_binfo
))
1893 btypes
= my_tree_cons (NULL_TREE
,
1894 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1897 btypes
= my_tree_cons (NULL_TREE
,
1898 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1900 obstack_ptr_grow (&search_obstack
, btypes
);
1902 if (tail
>= search_stack
->limit
)
1903 my_friendly_abort (99);
1907 /* Process head of queue, if one exists. */
1911 basetype_chain
= search_stack
->first
[head
++];
1912 binfo_h
= TREE_VALUE (basetype_chain
);
1913 basetype_chain
= TREE_CHAIN (basetype_chain
);
1914 basetype_path
= TREE_VALUE (basetype_chain
);
1915 if (TREE_CHAIN (basetype_chain
))
1916 BINFO_INHERITANCE_CHAIN (basetype_path
) = TREE_VALUE (TREE_CHAIN (basetype_chain
));
1918 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1920 binfo
= basetype_path
;
1921 type
= BINFO_TYPE (binfo
);
1923 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1924 and we do find NAME in TYPE, verify that such a second
1925 sighting is in fact valid. */
1927 idx
= lookup_fnfields_here (type
, name
);
1929 if (idx
>= 0 || (lookup_field_1 (type
, name
)!=NULL_TREE
&& !find_all
))
1931 if (rval_binfo
&& !find_all
&& hides (rval_binfo_h
, binfo_h
))
1933 /* This is ok, the member found is in rval_binfo, not
1936 else if (rval_binfo
==NULL_TREE
|| find_all
|| hides (binfo_h
, rval_binfo_h
))
1938 /* This is ok, the member found is here (binfo), not in
1942 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1943 /* Note, rvals can only be previously set if find_all is
1945 rvals
= my_tree_cons (basetype_path
, rval
, rvals
);
1946 if (TYPE_BINFO_BASETYPES (type
)
1947 && CLASSTYPE_BASELINK_VEC (type
))
1948 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1952 /* Undo finding it before, as something else hides it. */
1957 rval_binfo_h
= binfo_h
;
1961 /* This is ambiguous. */
1962 errstr
= "request for method `%D' is ambiguous";
1963 rvals
= error_mark_node
;
1969 tree
*tp
= search_stack
->first
;
1970 tree
*search_tail
= tp
+ tail
;
1972 while (tp
< search_tail
)
1974 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1978 search_stack
= pop_search_level (search_stack
);
1984 tree error_string
= my_build_string (errstr
);
1985 /* Save error message with entry. */
1986 TREE_TYPE (entry
) = error_string
;
1990 /* Mark entry as having no error string. */
1991 TREE_TYPE (entry
) = NULL_TREE
;
1992 TREE_VALUE (entry
) = rvals
;
1996 if (errstr
&& protect
)
1998 cp_error (errstr
, name
);
1999 rvals
= error_mark_node
;
2005 /* Look for a field or function named NAME in an inheritance lattice
2006 dominated by XBASETYPE. PROTECT is zero if we can avoid computing
2007 access information, otherwise it is 1. WANT_TYPE is 1 when we should
2008 only return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE. */
2011 lookup_member (xbasetype
, name
, protect
, want_type
)
2012 tree xbasetype
, name
;
2013 int protect
, want_type
;
2015 tree ret
, basetype_path
;
2017 if (TREE_CODE (xbasetype
) == TREE_VEC
)
2018 basetype_path
= xbasetype
;
2019 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
2021 basetype_path
= TYPE_BINFO (xbasetype
);
2022 BINFO_VIA_PUBLIC (basetype_path
) = 1;
2023 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
2026 my_friendly_abort (97);
2028 ret
= lookup_field (basetype_path
, name
, protect
, want_type
);
2029 if (! ret
&& ! want_type
)
2030 ret
= lookup_fnfields (basetype_path
, name
, protect
);
2034 /* BREADTH-FIRST SEARCH ROUTINES. */
2036 /* Search a multiple inheritance hierarchy by breadth-first search.
2038 BINFO is an aggregate type, possibly in a multiple-inheritance hierarchy.
2039 TESTFN is a function, which, if true, means that our condition has been met,
2040 and its return value should be returned.
2041 QFN, if non-NULL, is a predicate dictating whether the type should
2044 static HOST_WIDE_INT
2045 breadth_first_search (binfo
, testfn
, qfn
)
2047 int (*testfn
) PROTO((tree
, int));
2048 int (*qfn
) PROTO((tree
, int));
2050 int head
= 0, tail
= 0;
2053 search_stack
= push_search_level (search_stack
, &search_obstack
);
2057 tree binfos
= BINFO_BASETYPES (binfo
);
2058 int n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2061 /* Process and/or queue base types. */
2062 for (i
= 0; i
< n_baselinks
; i
++)
2064 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2066 if (BINFO_MARKED (base_binfo
) == 0
2067 && (qfn
== 0 || (*qfn
) (binfo
, i
)))
2069 SET_BINFO_MARKED (base_binfo
);
2070 obstack_ptr_grow (&search_obstack
, binfo
);
2071 obstack_ptr_grow (&search_obstack
, (HOST_WIDE_INT
) i
);
2073 if (tail
>= search_stack
->limit
)
2074 my_friendly_abort (100);
2077 /* Process head of queue, if one exists. */
2084 binfo
= search_stack
->first
[head
++];
2085 i
= (HOST_WIDE_INT
) search_stack
->first
[head
++];
2086 if ((rval
= (*testfn
) (binfo
, i
)))
2088 binfo
= BINFO_BASETYPE (binfo
, i
);
2091 tree
*tp
= search_stack
->first
;
2092 tree
*search_tail
= tp
+ tail
;
2093 while (tp
< search_tail
)
2096 int i
= (HOST_WIDE_INT
)(*tp
++);
2097 CLEAR_BINFO_MARKED (BINFO_BASETYPE (binfo
, i
));
2101 search_stack
= pop_search_level (search_stack
);
2105 /* Functions to use in breadth first searches. */
2106 typedef int (*pfi
) PROTO((tree
, int));
2108 static tree declarator
;
2111 get_virtuals_named_this (binfo
)
2116 fields
= lookup_fnfields (binfo
, declarator
, -1);
2117 /* fields cannot be error_mark_node */
2122 /* Get to the function decls, and return the first virtual function
2123 with this name, if there is one. */
2128 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
2129 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
2131 fields
= next_baselink (fields
);
2137 get_virtual_destructor (binfo
, i
)
2141 tree type
= BINFO_TYPE (binfo
);
2143 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
2144 if (TYPE_HAS_DESTRUCTOR (type
)
2145 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
2146 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
2151 tree_has_any_destructor_p (binfo
, i
)
2155 tree type
= BINFO_TYPE (binfo
);
2157 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
2158 return TYPE_NEEDS_DESTRUCTOR (type
);
2161 /* Returns > 0 if a function with type DRETTYPE overriding a function
2162 with type BRETTYPE is covariant, as defined in [class.virtual].
2164 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
2165 adjustment), or -1 if pedantically invalid covariance. */
2168 covariant_return_p (brettype
, drettype
)
2169 tree brettype
, drettype
;
2173 if (TREE_CODE (brettype
) == FUNCTION_DECL
2174 || TREE_CODE (brettype
) == THUNK_DECL
)
2176 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
2177 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
2179 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
2181 brettype
= TREE_TYPE (brettype
);
2182 drettype
= TREE_TYPE (drettype
);
2185 if (comptypes (brettype
, drettype
, 1))
2188 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
2189 && (TREE_CODE (brettype
) == POINTER_TYPE
2190 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
2191 && TYPE_READONLY (brettype
) == TYPE_READONLY (drettype
)
2192 && TYPE_VOLATILE (brettype
) == TYPE_VOLATILE (drettype
)))
2195 if (! can_convert (brettype
, drettype
))
2198 brettype
= TREE_TYPE (brettype
);
2199 drettype
= TREE_TYPE (drettype
);
2201 /* If not pedantic, allow any standard pointer conversion. */
2202 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
2205 binfo
= get_binfo (brettype
, drettype
, 1);
2207 /* If we get an error_mark_node from get_binfo, it already complained,
2208 so let's just succeed. */
2209 if (binfo
== error_mark_node
)
2212 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
2217 /* Given a class type TYPE, and a function decl FNDECL, look for a
2218 virtual function in TYPE's hierarchy which FNDECL could match as a
2219 virtual function. It doesn't matter which one we find.
2221 DTORP is nonzero if we are looking for a destructor. Destructors
2222 need special treatment because they do not match by name. */
2225 get_matching_virtual (binfo
, fndecl
, dtorp
)
2229 tree tmp
= NULL_TREE
;
2232 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
2233 /* In [temp.mem] we have:
2235 A specialization of a member function template does not
2236 override a virtual function from a base class. */
2239 /* Breadth first search routines start searching basetypes
2240 of TYPE, so we must perform first ply of search here. */
2243 if (tree_has_any_destructor_p (binfo
, -1))
2244 tmp
= get_virtual_destructor (binfo
, -1);
2249 tmp
= (tree
) breadth_first_search (binfo
,
2250 (pfi
) get_virtual_destructor
,
2251 tree_has_any_destructor_p
);
2256 tree drettype
, dtypes
, btypes
, instptr_type
;
2257 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
2258 tree baselink
, best
= NULL_TREE
;
2259 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
2261 declarator
= DECL_NAME (fndecl
);
2262 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
2265 baselink
= get_virtuals_named_this (binfo
);
2266 if (baselink
== NULL_TREE
)
2269 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
2270 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2271 if (DECL_STATIC_FUNCTION_P (fndecl
))
2272 instptr_type
= NULL_TREE
;
2274 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
2276 for (; baselink
; baselink
= next_baselink (baselink
))
2279 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
2281 tmp
= OVL_CURRENT (tmps
);
2282 if (! DECL_VINDEX (tmp
))
2285 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
2286 if (instptr_type
== NULL_TREE
)
2288 if (compparms (TREE_CHAIN (btypes
), dtypes
, 3))
2289 /* Caller knows to give error in this case. */
2294 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (btypes
)))
2295 == TYPE_READONLY (instptr_type
))
2296 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
), 3))
2298 tree brettype
= TREE_TYPE (TREE_TYPE (tmp
));
2299 if (comptypes (brettype
, drettype
, 1))
2301 else if ((i
= covariant_return_p (brettype
, drettype
)))
2304 sorry ("adjusting pointers for covariant returns");
2306 if (pedantic
&& i
== -1)
2308 cp_pedwarn_at ("invalid covariant return type for `%#D' (must be pointer or reference to class)", fndecl
);
2309 cp_pedwarn_at (" overriding `%#D'", tmp
);
2312 else if (IS_AGGR_TYPE_2 (brettype
, drettype
)
2313 && comptypes (brettype
, drettype
, 0))
2315 error ("invalid covariant return type (must use pointer or reference)");
2316 cp_error_at (" overriding `%#D'", tmp
);
2317 cp_error_at (" with `%#D'", fndecl
);
2319 else if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
)
2321 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl
);
2322 cp_error_at (" overriding definition as `%#D'", tmp
);
2323 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
2328 /* If not at the end */
2340 /* Return the list of virtual functions which are abstract in type
2341 TYPE that come from non virtual base classes. See
2342 expand_direct_vtbls_init for the style of search we do. */
2345 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
2348 tree abstract_virtuals
;
2350 tree binfos
= BINFO_BASETYPES (binfo
);
2351 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2353 for (i
= 0; i
< n_baselinks
; i
++)
2355 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2356 int is_not_base_vtable
2357 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2358 if (! TREE_VIA_VIRTUAL (base_binfo
))
2360 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
2363 /* Should we use something besides CLASSTYPE_VFIELDS? */
2364 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2366 tree virtuals
= BINFO_VIRTUALS (binfo
);
2368 skip_rtti_stuff (&virtuals
);
2372 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2373 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2374 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2375 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2376 virtuals
= TREE_CHAIN (virtuals
);
2379 return abstract_virtuals
;
2382 /* Return the list of virtual functions which are abstract in type TYPE.
2383 This information is cached, and so must be built on a
2384 non-temporary obstack. */
2387 get_abstract_virtuals (type
)
2391 tree abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (type
);
2393 /* First get all from non-virtual bases. */
2395 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
2397 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
2399 tree virtuals
= BINFO_VIRTUALS (vbases
);
2401 skip_rtti_stuff (&virtuals
);
2405 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
2406 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2407 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2408 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2409 virtuals
= TREE_CHAIN (virtuals
);
2412 return nreverse (abstract_virtuals
);
2415 /* For the type TYPE, return a list of member functions available from
2416 base classes with name NAME. The TREE_VALUE of the list is a chain of
2417 member functions with name NAME. The TREE_PURPOSE of the list is a
2418 basetype, or a list of base types (in reverse order) which were
2419 traversed to reach the chain of member functions. If we reach a base
2420 type which provides a member function of name NAME, and which has at
2421 most one base type itself, then we can terminate the search. */
2424 get_baselinks (type_as_binfo_list
, type
, name
)
2425 tree type_as_binfo_list
;
2428 int head
= 0, tail
= 0, idx
;
2429 tree rval
= 0, nval
= 0;
2430 tree basetypes
= type_as_binfo_list
;
2431 tree binfo
= TYPE_BINFO (type
);
2433 search_stack
= push_search_level (search_stack
, &search_obstack
);
2437 tree binfos
= BINFO_BASETYPES (binfo
);
2438 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2440 /* Process and/or queue base types. */
2441 for (i
= 0; i
< n_baselinks
; i
++)
2443 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2446 btypes
= hash_tree_cons (TREE_VIA_PUBLIC (base_binfo
),
2447 TREE_VIA_VIRTUAL (base_binfo
),
2448 TREE_VIA_PROTECTED (base_binfo
),
2449 NULL_TREE
, base_binfo
,
2451 obstack_ptr_grow (&search_obstack
, btypes
);
2452 search_stack
->first
= (tree
*)obstack_base (&search_obstack
);
2457 /* Process head of queue, if one exists. */
2461 basetypes
= search_stack
->first
[head
++];
2462 binfo
= TREE_VALUE (basetypes
);
2463 type
= BINFO_TYPE (binfo
);
2464 idx
= lookup_fnfields_1 (type
, name
);
2467 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
2468 rval
= hash_tree_cons (0, 0, 0, basetypes
, nval
, rval
);
2469 if (TYPE_BINFO_BASETYPES (type
) == 0)
2471 else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
)) == 1)
2473 if (CLASSTYPE_BASELINK_VEC (type
))
2474 TREE_TYPE (rval
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
2481 search_stack
= pop_search_level (search_stack
);
2486 next_baselink (baselink
)
2489 tree tmp
= TREE_TYPE (baselink
);
2490 baselink
= TREE_CHAIN (baselink
);
2493 /* @@ does not yet add previous base types. */
2494 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2496 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2497 tmp
= TREE_CHAIN (tmp
);
2502 /* DEPTH-FIRST SEARCH ROUTINES. */
2505 /* Assign unique numbers to _CLASSTYPE members of the lattice
2506 specified by TYPE. The root nodes are marked first; the nodes
2507 are marked depth-fisrt, left-right. */
2511 /* Matrix implementing a relation from CLASSTYPE X CLASSTYPE => INT.
2512 Relation yields 1 if C1 <= C2, 0 otherwise. */
2513 typedef char mi_boolean
;
2514 static mi_boolean
*mi_matrix
;
2516 /* Type for which this matrix is defined. */
2517 static tree mi_type
;
2519 /* Size of the matrix for indexing purposes. */
2522 /* Return nonzero if class C2 derives from class C1. */
2523 #define BINFO_DERIVES_FROM(C1, C2) \
2524 ((mi_matrix+mi_size*(BINFO_CID (C1)-1))[BINFO_CID (C2)-1])
2525 #define TYPE_DERIVES_FROM(C1, C2) \
2526 ((mi_matrix+mi_size*(CLASSTYPE_CID (C1)-1))[CLASSTYPE_CID (C2)-1])
2527 #define BINFO_DERIVES_FROM_STAR(C) \
2528 (mi_matrix+(BINFO_CID (C)-1))
2531 /* This routine converts a pointer to be a pointer of an immediate
2532 base class. The normal convert_pointer_to routine would diagnose
2533 the conversion as ambiguous, under MI code that has the base class
2534 as an ambiguous base class. */
2537 convert_pointer_to_single_level (to_type
, expr
)
2540 tree binfo_of_derived
;
2543 binfo_of_derived
= TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
)));
2544 last
= get_binfo (to_type
, TREE_TYPE (TREE_TYPE (expr
)), 0);
2545 BINFO_INHERITANCE_CHAIN (last
) = binfo_of_derived
;
2546 BINFO_INHERITANCE_CHAIN (binfo_of_derived
) = NULL_TREE
;
2547 return build_vbase_path (PLUS_EXPR
, build_pointer_type (to_type
), expr
, last
, 1);
2550 /* The main function which implements depth first search.
2552 This routine has to remember the path it walked up, when
2553 dfs_init_vbase_pointers is the work function, as otherwise there
2554 would be no record. */
2557 dfs_walk (binfo
, fn
, qfn
)
2559 void (*fn
) PROTO((tree
));
2560 int (*qfn
) PROTO((tree
));
2562 tree binfos
= BINFO_BASETYPES (binfo
);
2563 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2565 for (i
= 0; i
< n_baselinks
; i
++)
2567 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2569 if (qfn
== 0 || (*qfn
)(base_binfo
))
2571 if (TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TYPE_PARM
2572 || TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TEMPLATE_PARM
)
2574 else if (fn
== dfs_init_vbase_pointers
)
2576 /* When traversing an arbitrary MI hierarchy, we need to keep
2577 a record of the path we took to get down to the final base
2578 type, as otherwise there would be no record of it, and just
2579 trying to blindly convert at the bottom would be ambiguous.
2581 The easiest way is to do the conversions one step at a time,
2582 as we know we want the immediate base class at each step.
2584 The only special trick to converting one step at a time,
2585 is that when we hit the last virtual base class, we must
2586 use the SLOT value for it, and not use the normal convert
2587 routine. We use the last virtual base class, as in our
2588 implementation, we have pointers to all virtual base
2589 classes in the base object. */
2591 tree saved_vbase_decl_ptr_intermediate
2592 = vbase_decl_ptr_intermediate
;
2594 if (TREE_VIA_VIRTUAL (base_binfo
))
2596 /* No need for the conversion here, as we know it is the
2598 vbase_decl_ptr_intermediate
2599 = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
));
2603 vbase_decl_ptr_intermediate
2604 = convert_pointer_to_single_level (BINFO_TYPE (base_binfo
),
2605 vbase_decl_ptr_intermediate
);
2608 dfs_walk (base_binfo
, fn
, qfn
);
2610 vbase_decl_ptr_intermediate
= saved_vbase_decl_ptr_intermediate
;
2613 dfs_walk (base_binfo
, fn
, qfn
);
2621 /* Predicate functions which serve for dfs_walk. */
2622 static int numberedp (binfo
) tree binfo
;
2623 { return BINFO_CID (binfo
); }
2624 static int unnumberedp (binfo
) tree binfo
;
2625 { return BINFO_CID (binfo
) == 0; }
2628 static int markedp (binfo
) tree binfo
;
2629 { return BINFO_MARKED (binfo
); }
2630 static int unmarkedp (binfo
) tree binfo
;
2631 { return BINFO_MARKED (binfo
) == 0; }
2634 static int bfs_markedp (binfo
, i
) tree binfo
; int i
;
2635 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2636 static int bfs_unmarkedp (binfo
, i
) tree binfo
; int i
;
2637 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2638 static int bfs_marked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2639 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2640 static int bfs_unmarked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2641 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2642 static int bfs_marked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2643 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2644 static int bfs_unmarked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2645 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2648 static int marked_vtable_pathp (binfo
) tree binfo
;
2649 { return BINFO_VTABLE_PATH_MARKED (binfo
); }
2650 static int unmarked_vtable_pathp (binfo
) tree binfo
;
2651 { return BINFO_VTABLE_PATH_MARKED (binfo
) == 0; }
2652 static int marked_new_vtablep (binfo
) tree binfo
;
2653 { return BINFO_NEW_VTABLE_MARKED (binfo
); }
2654 static int unmarked_new_vtablep (binfo
) tree binfo
;
2655 { return BINFO_NEW_VTABLE_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 vbase_types
= make_binfo (integer_zero_node
, binfo
,
3200 BINFO_VTABLE (binfo
),
3201 BINFO_VIRTUALS (binfo
), vbase_types
);
3202 TREE_VIA_VIRTUAL (vbase_types
) = 1;
3203 SET_BINFO_VBASE_MARKED (binfo
);
3205 SET_BINFO_MARKED (binfo
);
3208 /* get a list of virtual base classes in dfs order. */
3211 get_vbase_types (type
)
3217 if (TREE_CODE (type
) == TREE_VEC
)
3220 binfo
= TYPE_BINFO (type
);
3222 vbase_types
= NULL_TREE
;
3223 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
);
3224 dfs_walk (binfo
, dfs_unmark
, markedp
);
3225 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
3226 reverse it so that we get normal dfs ordering. */
3227 vbase_types
= nreverse (vbase_types
);
3229 /* unmark marked vbases */
3230 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
3231 CLEAR_BINFO_VBASE_MARKED (vbases
);
3238 dfs_record_inheritance (binfo
)
3241 tree binfos
= BINFO_BASETYPES (binfo
);
3242 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3243 mi_boolean
*derived_row
= BINFO_DERIVES_FROM_STAR (binfo
);
3245 for (i
= n_baselinks
-1; i
>= 0; i
--)
3248 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3249 tree baseclass
= BINFO_TYPE (base_binfo
);
3250 mi_boolean
*base_row
= BINFO_DERIVES_FROM_STAR (base_binfo
);
3252 if (TREE_CODE (baseclass
) == TEMPLATE_TYPE_PARM
3253 || TREE_CODE (baseclass
) == TEMPLATE_TEMPLATE_PARM
)
3255 my_friendly_assert (CLASSTYPE_CID (baseclass
) != 0, 2365);
3257 /* Don't search if there's nothing there! MI_SIZE can be
3258 zero as a result of parse errors. */
3259 if (TYPE_BINFO_BASETYPES (baseclass
) && mi_size
> 0)
3260 for (j
= mi_size
*(CLASSTYPE_CID (baseclass
)-1); j
>= 0; j
-= mi_size
)
3261 derived_row
[j
] |= base_row
[j
];
3262 TYPE_DERIVES_FROM (baseclass
, BINFO_TYPE (binfo
)) = 1;
3265 SET_BINFO_MARKED (binfo
);
3268 /* Given a _CLASSTYPE node in a multiple inheritance lattice,
3269 convert the lattice into a simple relation such that,
3270 given to CIDs, C1 and C2, one can determine if C1 <= C2
3271 or C2 <= C1 or C1 <> C2.
3273 Once constructed, we walk the lattice depth fisrt,
3274 applying various functions to elements as they are encountered.
3276 We use xmalloc here, in case we want to randomly free these tables. */
3278 #define SAVE_MI_MATRIX
3281 build_mi_matrix (type
)
3284 tree binfo
= TYPE_BINFO (type
);
3287 #ifdef SAVE_MI_MATRIX
3288 if (CLASSTYPE_MI_MATRIX (type
))
3290 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
3291 mi_matrix
= CLASSTYPE_MI_MATRIX (type
);
3293 dfs_walk (binfo
, dfs_number
, unnumberedp
);
3298 dfs_walk (binfo
, dfs_number
, unnumberedp
);
3300 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
3301 if (mi_size
< (cid
-1))
3303 mi_matrix
= (char *)xmalloc ((mi_size
+ 1) * (mi_size
+ 1));
3305 bzero (mi_matrix
, (mi_size
+ 1) * (mi_size
+ 1));
3306 dfs_walk (binfo
, dfs_record_inheritance
, unmarkedp
);
3307 dfs_walk (binfo
, dfs_unmark
, markedp
);
3313 dfs_walk (TYPE_BINFO (mi_type
), dfs_unnumber
, numberedp
);
3315 #ifdef SAVE_MI_MATRIX
3316 CLASSTYPE_MI_MATRIX (mi_type
) = mi_matrix
;
3325 /* If we want debug info for a type TYPE, make sure all its base types
3326 are also marked as being potentially interesting. This avoids
3327 the problem of not writing any debug info for intermediate basetypes
3328 that have abstract virtual functions. Also mark member types. */
3331 note_debug_info_needed (type
)
3336 if (current_template_parms
)
3339 if (TYPE_BEING_DEFINED (type
))
3340 /* We can't go looking for the base types and fields just yet. */
3343 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
3344 does not support name references between translation units. Well, we
3345 could, but that would mean putting global labels in the debug output
3346 before each exported type and each of its functions and static data
3348 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
3351 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
);
3352 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
3355 if (TREE_CODE (field
) == FIELD_DECL
3356 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
3357 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
)))
3358 note_debug_info_needed (ttype
);
3362 /* Subroutines of push_class_decls (). */
3364 /* Add in a decl to the envelope. */
3366 envelope_add_decl (type
, decl
, values
)
3367 tree type
, decl
, *values
;
3370 tree name
= DECL_NAME (decl
);
3373 /* Yet Another Implicit Typename Kludge: Since we don't tsubst
3374 the members for partial instantiations, DECL_CONTEXT (decl) is wrong.
3375 But pretend it's right for this function. */
3376 if (processing_template_decl
)
3377 type
= DECL_REAL_CONTEXT (decl
);
3379 /* virtual base names are always unique. */
3380 if (VBASE_NAME_P (name
))
3381 *values
= NULL_TREE
;
3383 /* Possible ambiguity. If its defining type(s)
3384 is (are all) derived from us, no problem. */
3385 else if (*values
&& TREE_CODE (*values
) != TREE_LIST
)
3387 tree value
= *values
;
3388 /* Only complain if we shadow something we can access. */
3389 if (warn_shadow
&& TREE_CODE (decl
) == FUNCTION_DECL
3390 && ((DECL_LANG_SPECIFIC (*values
)
3391 && DECL_CLASS_CONTEXT (value
) == current_class_type
)
3392 || ! TREE_PRIVATE (value
)))
3393 /* Should figure out access control more accurately. */
3395 cp_warning_at ("member `%#D' is shadowed", value
);
3396 cp_warning_at ("by member function `%#D'", decl
);
3397 warning ("in this context");
3400 context
= DECL_REAL_CONTEXT (value
);
3402 if (context
== type
)
3404 if (TREE_CODE (value
) == TYPE_DECL
3405 && DECL_ARTIFICIAL (value
))
3406 *values
= NULL_TREE
;
3410 else if (type
== current_class_type
3412 /* If we don't check CLASSTYPE_CID on CONTEXT right now,
3413 we'll end up subtracting from the address of MI_MATRIX,
3414 putting us off in la la land. */
3415 || (CLASSTYPE_CID (type
)
3416 && TYPE_DERIVES_FROM (context
, type
))
3418 || DERIVED_FROM_P (context
, type
)
3422 /* Don't add in *values to list */
3423 *values
= NULL_TREE
;
3426 *values
= build_tree_list (NULL_TREE
, value
);
3429 for (tmp
= values
; *tmp
;)
3431 tree value
= TREE_VALUE (*tmp
);
3432 my_friendly_assert (TREE_CODE (value
) != TREE_LIST
, 999);
3433 context
= (TREE_CODE (value
) == FUNCTION_DECL
3434 && DECL_VIRTUAL_P (value
))
3435 ? DECL_CLASS_CONTEXT (value
)
3436 : DECL_CONTEXT (value
);
3438 if (type
== current_class_type
3440 /* If we don't check CLASSTYPE_CID on CONTEXT right now,
3441 we'll end up subtracting from the address of MI_MATRIX,
3442 putting us off in la la land. */
3443 || (CLASSTYPE_CID (type
)
3444 && TYPE_DERIVES_FROM (context
, type
))
3446 || DERIVED_FROM_P (context
, type
)
3450 /* remove *tmp from list */
3451 *tmp
= TREE_CHAIN (*tmp
);
3454 tmp
= &TREE_CHAIN (*tmp
);
3459 /* Put the new contents in our envelope. */
3460 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3462 *values
= tree_cons (name
, decl
, *values
);
3463 TREE_NONLOCAL_FLAG (*values
) = 1;
3464 TREE_TYPE (*values
) = unknown_type_node
;
3470 *values
= tree_cons (NULL_TREE
, decl
, *values
);
3471 /* Mark this as a potentially ambiguous member. */
3472 /* Leaving TREE_TYPE blank is intentional.
3473 We cannot use `error_mark_node' (lookup_name)
3474 or `unknown_type_node' (all member functions use this). */
3475 TREE_NONLOCAL_FLAG (*values
) = 1;
3483 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
3484 because it (or one of the intermediate bases) depends on template parms. */
3487 dependent_base_p (binfo
)
3490 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
3492 if (binfo
== current_class_type
)
3494 if (uses_template_parms (TREE_TYPE (binfo
)))
3500 /* Add the instance variables which this class contributed to the
3501 current class binding contour. When a redefinition occurs, if the
3502 redefinition is strictly within a single inheritance path, we just
3503 overwrite the old declaration with the new. If the fields are not
3504 within a single inheritance path, we must cons them.
3506 In order to know what decls are new (stemming from the current
3507 invocation of push_class_decls) we enclose them in an "envelope",
3508 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
3509 new decl (or possibly a list of competing ones), the TREE_VALUE slot
3510 points to the old value and the TREE_CHAIN slot chains together all
3511 envelopes which needs to be "opened" in push_class_decls. Opening an
3512 envelope means: push the old value onto the class_shadowed list,
3513 install the new one and if it's a TYPE_DECL do the same to the
3514 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
3515 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
3516 Because if it is, it could be a set of overloaded methods from an
3520 dfs_pushdecls (binfo
)
3523 tree type
= BINFO_TYPE (binfo
);
3524 tree fields
, *methods
, *end
;
3528 /* Only record types if we're a template base. */
3529 if (processing_template_decl
&& type
!= current_class_type
3530 && dependent_base_p (binfo
))
3533 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3535 if (dummy
&& TREE_CODE (fields
) != TYPE_DECL
)
3538 /* Unmark so that if we are in a constructor, and then find that
3539 this field was initialized by a base initializer,
3540 we can emit an error message. */
3541 if (TREE_CODE (fields
) == FIELD_DECL
)
3542 TREE_USED (fields
) = 0;
3544 /* Recurse into anonymous unions. */
3545 if (DECL_NAME (fields
) == NULL_TREE
3546 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3548 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields
)));
3552 if (DECL_NAME (fields
))
3554 tree name
= DECL_NAME (fields
);
3555 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
3557 /* If the class value is not an envelope of the kind described in
3558 the comment above, we create a new envelope. */
3559 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3560 || TREE_PURPOSE (class_value
) == NULL_TREE
3561 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3563 /* See comment above for a description of envelopes. */
3564 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3566 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
3567 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3570 envelope_add_decl (type
, fields
, &TREE_PURPOSE (class_value
));
3574 method_vec
= CLASSTYPE_METHOD_VEC (type
);
3575 if (method_vec
&& ! dummy
)
3577 /* Farm out constructors and destructors. */
3578 methods
= &TREE_VEC_ELT (method_vec
, 2);
3579 end
= TREE_VEC_END (method_vec
);
3581 while (methods
!= end
)
3583 /* This will cause lookup_name to return a pointer
3584 to the tree_list of possible methods of this name. */
3585 tree name
= DECL_NAME (OVL_CURRENT (*methods
));
3586 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
3588 /* If the class value is not an envelope of the kind described in
3589 the comment above, we create a new envelope. */
3590 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3591 || TREE_PURPOSE (class_value
) == NULL_TREE
3592 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3594 /* See comment above for a description of envelopes. */
3595 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3597 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
3598 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3601 /* Here we try to rule out possible ambiguities.
3602 If we can't do that, keep a TREE_LIST with possibly ambiguous
3604 maybe_push_cache_obstack ();
3605 /* Arbitrarily choose the first function in the list. This is OK
3606 because this is only used for initial lookup; anything that
3607 actually uses the function will look it up again. */
3608 envelope_add_decl (type
, OVL_CURRENT (*methods
),
3609 &TREE_PURPOSE (class_value
));
3615 SET_BINFO_MARKED (binfo
);
3618 /* Consolidate unique (by name) member functions. */
3621 dfs_compress_decls (binfo
)
3624 tree type
= BINFO_TYPE (binfo
);
3625 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
3627 if (processing_template_decl
&& type
!= current_class_type
3628 && dependent_base_p (binfo
))
3629 /* We only record types if we're a template base. */;
3630 else if (method_vec
!= 0)
3632 /* Farm out constructors and destructors. */
3633 tree
*methods
= &TREE_VEC_ELT (method_vec
, 2);
3634 tree
*end
= TREE_VEC_END (method_vec
);
3636 for (; methods
!= end
; methods
++)
3638 /* This is known to be an envelope of the kind described before
3641 IDENTIFIER_CLASS_VALUE (DECL_NAME (OVL_CURRENT (*methods
)));
3642 tree tmp
= TREE_PURPOSE (class_value
);
3644 /* This was replaced in scope by somebody else. Just leave it
3646 if (TREE_CODE (tmp
) != TREE_LIST
)
3649 if (TREE_CHAIN (tmp
) == NULL_TREE
3651 && OVL_NEXT (TREE_VALUE (tmp
)) == NULL_TREE
)
3653 TREE_PURPOSE (class_value
) = TREE_VALUE (tmp
);
3657 CLEAR_BINFO_MARKED (binfo
);
3660 /* When entering the scope of a class, we cache all of the
3661 fields that that class provides within its inheritance
3662 lattice. Where ambiguities result, we mark them
3663 with `error_mark_node' so that if they are encountered
3664 without explicit qualification, we can emit an error
3668 push_class_decls (type
)
3671 struct obstack
*ambient_obstack
= current_obstack
;
3672 search_stack
= push_search_level (search_stack
, &search_obstack
);
3674 /* Push class fields into CLASS_VALUE scope, and mark. */
3675 dfs_walk (TYPE_BINFO (type
), dfs_pushdecls
, unmarkedp
);
3677 /* Compress fields which have only a single entry
3678 by a given name, and unmark. */
3679 dfs_walk (TYPE_BINFO (type
), dfs_compress_decls
, markedp
);
3681 /* Open up all the closed envelopes and push the contained decls into
3683 while (closed_envelopes
)
3685 tree
new = TREE_PURPOSE (closed_envelopes
);
3688 /* This is messy because the class value may be a *_DECL, or a
3689 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3690 *_DECLs. The name is stored at different places in these three
3692 if (TREE_CODE (new) == TREE_LIST
)
3694 if (TREE_PURPOSE (new) != NULL_TREE
)
3695 id
= TREE_PURPOSE (new);
3698 tree node
= TREE_VALUE (new);
3700 if (TREE_CODE (node
) == TYPE_DECL
3701 && DECL_ARTIFICIAL (node
)
3702 && IS_AGGR_TYPE (TREE_TYPE (node
))
3703 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (node
)))
3705 tree t
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (node
));
3708 for (; n
; n
= TREE_CHAIN (n
))
3710 tree d
= TREE_VALUE (n
);
3711 if (TREE_CODE (d
) == TYPE_DECL
3712 && DECL_ARTIFICIAL (node
)
3713 && IS_AGGR_TYPE (TREE_TYPE (d
))
3714 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (d
))
3715 && CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d
)) == t
)
3724 else while (TREE_CODE (node
) == TREE_LIST
)
3725 node
= TREE_VALUE (node
);
3726 id
= DECL_NAME (node
);
3730 id
= DECL_NAME (new);
3732 /* Install the original class value in order to make
3733 pushdecl_class_level work correctly. */
3734 IDENTIFIER_CLASS_VALUE (id
) = TREE_VALUE (closed_envelopes
);
3735 if (TREE_CODE (new) == TREE_LIST
)
3736 push_class_level_binding (id
, new);
3738 pushdecl_class_level (new);
3739 closed_envelopes
= TREE_CHAIN (closed_envelopes
);
3741 current_obstack
= ambient_obstack
;
3744 /* Here's a subroutine we need because C lacks lambdas. */
3747 dfs_unuse_fields (binfo
)
3750 tree type
= TREE_TYPE (binfo
);
3753 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3755 if (TREE_CODE (fields
) != FIELD_DECL
)
3758 TREE_USED (fields
) = 0;
3759 if (DECL_NAME (fields
) == NULL_TREE
3760 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3761 unuse_fields (TREE_TYPE (fields
));
3769 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
);
3775 /* We haven't pushed a search level when dealing with cached classes,
3776 so we'd better not try to pop it. */
3778 search_stack
= pop_search_level (search_stack
);
3782 print_search_statistics ()
3784 #ifdef GATHER_STATISTICS
3785 if (flag_memoize_lookups
)
3787 fprintf (stderr
, "%d memoized contexts saved\n",
3789 fprintf (stderr
, "%d local tree nodes made\n", my_tree_node_counter
);
3790 fprintf (stderr
, "%d local hash nodes made\n", my_memoized_entry_counter
);
3791 fprintf (stderr
, "fields statistics:\n");
3792 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3793 memoized_fast_finds
[0], memoized_fast_rejects
[0],
3794 memoized_fields_searched
[0]);
3795 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[0]);
3796 fprintf (stderr
, "fnfields statistics:\n");
3797 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3798 memoized_fast_finds
[1], memoized_fast_rejects
[1],
3799 memoized_fields_searched
[1]);
3800 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[1]);
3802 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3803 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3804 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3805 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3806 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3807 #else /* GATHER_STATISTICS */
3808 fprintf (stderr
, "no search statistics\n");
3809 #endif /* GATHER_STATISTICS */
3813 init_search_processing ()
3815 gcc_obstack_init (&search_obstack
);
3816 gcc_obstack_init (&type_obstack
);
3817 gcc_obstack_init (&type_obstack_entries
);
3819 /* This gives us room to build our chains of basetypes,
3820 whether or not we decide to memoize them. */
3821 type_stack
= push_type_level ((struct stack_level
*)0, &type_obstack
);
3822 _vptr_name
= get_identifier ("_vptr");
3826 reinit_search_statistics ()
3828 my_memoized_entry_counter
= 0;
3829 memoized_fast_finds
[0] = 0;
3830 memoized_fast_finds
[1] = 0;
3831 memoized_adds
[0] = 0;
3832 memoized_adds
[1] = 0;
3833 memoized_fast_rejects
[0] = 0;
3834 memoized_fast_rejects
[1] = 0;
3835 memoized_fields_searched
[0] = 0;
3836 memoized_fields_searched
[1] = 0;
3837 #ifdef GATHER_STATISTICS
3838 n_fields_searched
= 0;
3839 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3840 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3841 n_calls_get_base_type
= 0;
3842 n_outer_fields_searched
= 0;
3843 n_contexts_saved
= 0;
3844 #endif /* GATHER_STATISTICS */
3847 #define scratch_tree_cons expr_tree_cons
3849 static tree conversions
;
3851 add_conversions (binfo
)
3855 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3857 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3859 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3860 if (! IDENTIFIER_TYPENAME_P (DECL_NAME (OVL_CURRENT (tmp
))))
3862 conversions
= scratch_tree_cons (binfo
, tmp
, conversions
);
3864 SET_BINFO_MARKED (binfo
);
3868 lookup_conversions (type
)
3871 conversions
= NULL_TREE
;
3872 if (TYPE_SIZE (type
))
3874 dfs_walk (TYPE_BINFO (type
), add_conversions
, unmarkedp
);
3875 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
);
3880 /* Subroutine of get_template_base. */
3883 get_template_base_recursive (binfo
, rval
, template, via_virtual
)
3884 tree binfo
, template, rval
;
3889 tree type
= BINFO_TYPE (binfo
);
3891 if (CLASSTYPE_TEMPLATE_INFO (type
)
3892 && CLASSTYPE_TI_TEMPLATE (type
) == template)
3894 if (rval
== NULL_TREE
|| rval
== type
)
3897 return error_mark_node
;
3900 binfos
= BINFO_BASETYPES (binfo
);
3901 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3903 /* Process base types. */
3904 for (i
= 0; i
< n_baselinks
; i
++)
3906 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3908 /* Find any specific instance of a virtual base, when searching with
3910 if (BINFO_MARKED (base_binfo
) == 0)
3912 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
3914 /* When searching for a non-virtual, we cannot mark
3915 virtually found binfos. */
3917 SET_BINFO_MARKED (base_binfo
);
3919 rval
= get_template_base_recursive
3920 (base_binfo
, rval
, template, this_virtual
);
3921 if (rval
== error_mark_node
)
3929 /* Given a class template TEMPLATE and a class type or binfo node BINFO,
3930 find the unique base type in BINFO that is an instance of TEMPLATE.
3931 If there are more than one, return error_mark_node. Used by unify. */
3934 get_template_base (template, binfo
)
3935 register tree
template, binfo
;
3937 tree type
= NULL_TREE
, rval
;
3939 if (TREE_CODE (binfo
) == TREE_VEC
)
3940 type
= BINFO_TYPE (binfo
);
3941 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
3943 type
= complete_type (binfo
);
3944 binfo
= TYPE_BINFO (type
);
3947 my_friendly_abort (92);
3949 if (CLASSTYPE_TEMPLATE_INFO (type
)
3950 && CLASSTYPE_TI_TEMPLATE (type
) == template)
3953 rval
= get_template_base_recursive (binfo
, NULL_TREE
, template, 0);
3954 dfs_walk (binfo
, dfs_unmark
, markedp
);
3959 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3960 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3962 static tree compare_type
;
3963 static int found_overlap
;
3965 dfs_check_overlap (empty_binfo
)
3969 for (binfo
= TYPE_BINFO (compare_type
); ; binfo
= BINFO_BASETYPE (binfo
, 0))
3971 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3976 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3981 /* Trivial function to stop base traversal when we find something. */
3984 dfs_no_overlap_yet (t
)
3985 tree t ATTRIBUTE_UNUSED
;
3987 return found_overlap
== 0;
3990 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3991 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3994 types_overlap_p (empty_type
, next_type
)
3995 tree empty_type
, next_type
;
3997 if (! IS_AGGR_TYPE (next_type
))
3999 compare_type
= next_type
;
4001 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
, dfs_no_overlap_yet
);
4002 return found_overlap
;