1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 1989, 1992, 1993 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* High-level class interface. */
31 #define obstack_chunk_alloc xmalloc
32 #define obstack_chunk_free free
35 extern struct obstack
*current_obstack
;
39 /* Obstack used for remembering decision points of breadth-first. */
40 static struct obstack search_obstack
;
42 /* Methods for pushing and popping objects to and from obstacks. */
44 push_stack_level (obstack
, tp
, size
)
45 struct obstack
*obstack
;
46 char *tp
; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
49 struct stack_level
*stack
;
50 obstack_grow (obstack
, tp
, size
);
51 stack
= (struct stack_level
*) ((char*)obstack_next_free (obstack
) - size
);
52 obstack_finish (obstack
);
53 stack
->obstack
= obstack
;
54 stack
->first
= (tree
*) obstack_base (obstack
);
55 stack
->limit
= obstack_room (obstack
) / sizeof (tree
*);
60 pop_stack_level (stack
)
61 struct stack_level
*stack
;
63 struct stack_level
*tem
= stack
;
64 struct obstack
*obstack
= tem
->obstack
;
66 obstack_free (obstack
, tem
);
70 #define search_level stack_level
71 static struct search_level
*search_stack
;
73 static tree
lookup_field_1 ();
74 static int lookup_fnfields_1 ();
75 static void dfs_walk ();
76 static int markedp ();
77 static void dfs_unmark ();
78 static void dfs_init_vbase_pointers ();
80 static tree vbase_types
;
81 static tree vbase_decl
, vbase_decl_ptr
;
82 static tree vbase_decl_ptr_intermediate
;
83 static tree vbase_init_result
;
85 /* Allocate a level of searching. */
86 static struct search_level
*
87 push_search_level (stack
, obstack
)
88 struct stack_level
*stack
;
89 struct obstack
*obstack
;
91 struct search_level tem
;
94 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
97 /* Discard a level of search allocation. */
98 static struct search_level
*
99 pop_search_level (obstack
)
100 struct stack_level
*obstack
;
102 register struct search_level
*stack
= pop_stack_level (obstack
);
107 /* Search memoization. */
110 struct stack_level base
;
112 /* First object allocated in obstack of entries. */
115 /* Number of types memoized in this context. */
118 /* Type being memoized; save this if we are saving
119 memoized contexts. */
123 /* Obstack used for memoizing member and member function lookup. */
125 static struct obstack type_obstack
, type_obstack_entries
;
126 static struct type_level
*type_stack
;
127 static tree _vptr_name
;
129 /* Make things that look like tree nodes, but allocate them
130 on type_obstack_entries. */
131 static int my_tree_node_counter
;
132 static tree
my_tree_cons (), my_build_string ();
134 extern int flag_memoize_lookups
, flag_save_memoized_contexts
;
136 /* Variables for gathering statistics. */
137 static int my_memoized_entry_counter
;
138 static int memoized_fast_finds
[2], memoized_adds
[2], memoized_fast_rejects
[2];
139 static int memoized_fields_searched
[2];
140 static int n_fields_searched
;
141 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
142 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
143 static int n_calls_get_base_type
;
144 static int n_outer_fields_searched
;
145 static int n_contexts_saved
;
147 /* Local variables to help save memoization contexts. */
148 static tree prev_type_memoized
;
149 static struct type_level
*prev_type_stack
;
151 /* This list is used by push_class_decls to know what decls need to
152 be pushed into class scope. */
153 static tree closed_envelopes
= NULL_TREE
;
155 /* Allocate a level of type memoization context. */
156 static struct type_level
*
157 push_type_level (stack
, obstack
)
158 struct stack_level
*stack
;
159 struct obstack
*obstack
;
161 struct type_level tem
;
163 tem
.base
.prev
= stack
;
165 obstack_finish (&type_obstack_entries
);
166 tem
.entries
= (char *) obstack_base (&type_obstack_entries
);
168 tem
.type
= NULL_TREE
;
170 return (struct type_level
*)push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
173 /* Discard a level of type memoization context. */
175 static struct type_level
*
176 pop_type_level (stack
)
177 struct type_level
*stack
;
179 obstack_free (&type_obstack_entries
, stack
->entries
);
180 return (struct type_level
*)pop_stack_level ((struct stack_level
*)stack
);
183 /* Make something that looks like a TREE_LIST, but
184 do it on the type_obstack_entries obstack. */
186 my_tree_cons (purpose
, value
, chain
)
187 tree purpose
, value
, chain
;
189 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_list
));
190 ++my_tree_node_counter
;
191 TREE_TYPE (p
) = NULL_TREE
;
192 ((HOST_WIDE_INT
*)p
)[3] = 0;
193 TREE_SET_CODE (p
, TREE_LIST
);
194 TREE_PURPOSE (p
) = purpose
;
195 TREE_VALUE (p
) = value
;
196 TREE_CHAIN (p
) = chain
;
201 my_build_string (str
)
204 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_string
));
205 ++my_tree_node_counter
;
208 TREE_SET_CODE (p
, STRING_CST
);
209 TREE_STRING_POINTER (p
) = str
;
210 TREE_STRING_LENGTH (p
) = strlen (str
);
214 /* Memoizing machinery to make searches for multiple inheritance
215 reasonably efficient. */
216 #define MEMOIZE_HASHSIZE 8
217 typedef struct memoized_entry
219 struct memoized_entry
*chain
;
221 tree data_members
[MEMOIZE_HASHSIZE
];
222 tree function_members
[MEMOIZE_HASHSIZE
];
225 #define MEMOIZED_CHAIN(ENTRY) (((ME)ENTRY)->chain)
226 #define MEMOIZED_UID(ENTRY) (((ME)ENTRY)->uid)
227 #define MEMOIZED_FIELDS(ENTRY,INDEX) (((ME)ENTRY)->data_members[INDEX])
228 #define MEMOIZED_FNFIELDS(ENTRY,INDEX) (((ME)ENTRY)->function_members[INDEX])
229 /* The following is probably a lousy hash function. */
230 #define MEMOIZED_HASH_FN(NODE) (((long)(NODE)>>4)&(MEMOIZE_HASHSIZE - 1))
232 static struct memoized_entry
*
233 my_new_memoized_entry (chain
)
234 struct memoized_entry
*chain
;
236 struct memoized_entry
*p
=
237 (struct memoized_entry
*)obstack_alloc (&type_obstack_entries
,
238 sizeof (struct memoized_entry
));
239 bzero (p
, sizeof (struct memoized_entry
));
240 MEMOIZED_CHAIN (p
) = chain
;
241 MEMOIZED_UID (p
) = ++my_memoized_entry_counter
;
245 /* Make an entry in the memoized table for type TYPE
246 that the entry for NAME is FIELD. */
249 make_memoized_table_entry (type
, name
, function_p
)
253 int index
= MEMOIZED_HASH_FN (name
);
254 tree entry
, *prev_entry
;
256 memoized_adds
[function_p
] += 1;
257 if (CLASSTYPE_MTABLE_ENTRY (type
) == 0)
259 obstack_ptr_grow (&type_obstack
, type
);
260 obstack_blank (&type_obstack
, sizeof (struct memoized_entry
*));
261 CLASSTYPE_MTABLE_ENTRY (type
) = (char *)my_new_memoized_entry ((struct memoized_entry
*)0);
263 if (type_stack
->len
* 2 >= type_stack
->base
.limit
)
264 my_friendly_abort (88);
267 prev_entry
= &MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), index
);
269 prev_entry
= &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), index
);
271 entry
= my_tree_cons (name
, NULL_TREE
, *prev_entry
);
274 /* Don't know the error message to give yet. */
275 TREE_TYPE (entry
) = error_mark_node
;
280 /* When a new function or class context is entered, we build
281 a table of types which have been searched for members.
282 The table is an array (obstack) of types. When a type is
283 entered into the obstack, its CLASSTYPE_MTABLE_ENTRY
284 field is set to point to a new record, of type struct memoized_entry.
286 A non-NULL TREE_TYPE of the entry contains an access control error message.
288 The slots for the data members are arrays of tree nodes.
289 These tree nodes are lists, with the TREE_PURPOSE
290 of this list the known member name, and the TREE_VALUE
291 as the FIELD_DECL for the member.
293 For member functions, the TREE_PURPOSE is again the
294 name of the member functions for that class,
295 and the TREE_VALUE of the list is a pairs
296 whose TREE_PURPOSE is a member functions of this name,
297 and whose TREE_VALUE is a list of known argument lists this
298 member function has been called with. The TREE_TYPE of the pair,
299 if non-NULL, is an error message to print. */
301 /* Tell search machinery that we are entering a new context, and
302 to update tables appropriately.
304 TYPE is the type of the context we are entering, which can
305 be NULL_TREE if we are not in a class's scope.
307 USE_OLD, if nonzero tries to use previous context. */
309 push_memoized_context (type
, use_old
)
318 if (use_old
&& prev_type_memoized
== type
)
320 #ifdef GATHER_STATISTICS
323 type_stack
= prev_type_stack
;
326 tem
= &type_stack
->base
.first
[0];
327 len
= type_stack
->len
;
329 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]) = (char *)tem
[len
*2+1];
332 /* Otherwise, need to pop old stack here. */
333 type_stack
= pop_type_level (prev_type_stack
);
334 prev_type_memoized
= 0;
338 type_stack
= push_type_level ((struct stack_level
*)type_stack
,
340 type_stack
->type
= type
;
343 /* Tell search machinery that we have left a context.
344 We do not currently save these contexts for later use.
345 If we wanted to, we could not use pop_search_level, since
346 poping that level allows the data we have collected to
347 be clobbered; a stack of obstacks would be needed. */
349 pop_memoized_context (use_old
)
353 tree
*tem
= &type_stack
->base
.first
[0];
355 if (! flag_save_memoized_contexts
)
359 len
= type_stack
->len
;
361 tem
[len
*2+1] = (tree
)CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]);
363 prev_type_stack
= type_stack
;
364 prev_type_memoized
= type_stack
->type
;
367 if (flag_memoize_lookups
)
369 len
= type_stack
->len
;
371 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2])
372 = (char *)MEMOIZED_CHAIN (CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]));
375 type_stack
= pop_type_level (type_stack
);
377 type_stack
= (struct type_level
*)type_stack
->base
.prev
;
381 /* This is the newer recursive depth first search routine. */
382 /* Return non-zero if PARENT is directly derived from TYPE. By directly
383 we mean it's only one step up the inheritance lattice. We check this
384 by walking horizontally across the types that TYPE directly inherits
385 from, to see if PARENT is among them. This is used by get_binfo and
386 by compute_access. */
388 immediately_derived (parent
, type
)
391 if (TYPE_BINFO (type
))
393 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (type
));
394 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
396 for (i
= 0; i
< n_baselinks
; i
++)
398 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
400 if (parent
== BINFO_TYPE (base_binfo
))
408 /* Check whether the type given in BINFO is derived from PARENT. If
409 it isn't, return 0. If it is, but the derivation is MI-ambiguous
410 AND protect != 0, emit an error message and return error_mark_node.
412 Otherwise, if TYPE is derived from PARENT, return the actual base
413 information, unless a one of the protection violations below
414 occurs, in which case emit an error message and return error_mark_node.
416 If PROTECT is 1, then check if access to a public field of PARENT
417 would be private. Also check for ambiguity. */
420 get_binfo (parent
, binfo
, protect
)
421 register tree parent
, binfo
;
426 tree rval
= NULL_TREE
;
428 if (TREE_CODE (parent
) == TREE_VEC
)
429 parent
= BINFO_TYPE (parent
);
430 /* unions cannot participate in inheritance relationships */
431 else if (TREE_CODE (parent
) == UNION_TYPE
)
433 else if (TREE_CODE (parent
) != RECORD_TYPE
)
434 my_friendly_abort (89);
436 if (TREE_CODE (binfo
) == TREE_VEC
)
437 type
= BINFO_TYPE (binfo
);
438 else if (TREE_CODE (binfo
) == RECORD_TYPE
)
440 else if (TREE_CODE (binfo
) == UNION_TYPE
)
443 my_friendly_abort (90);
445 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
449 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
451 return error_mark_node
;
453 else if (dist
== -2 && protect
)
455 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
457 return error_mark_node
;
463 /* This is the newer depth first get_base_distance routine. */
465 get_base_distance_recursive (binfo
, depth
, is_private
, basetype_path
, rval
,
466 rval_private_ptr
, new_binfo_ptr
, parent
, path_ptr
,
467 protect
, via_virtual_ptr
, via_virtual
)
468 tree binfo
, basetype_path
, *new_binfo_ptr
, parent
, *path_ptr
;
469 int *rval_private_ptr
, depth
, is_private
, rval
, protect
, *via_virtual_ptr
,
475 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
480 *rval_private_ptr
= is_private
;
481 *new_binfo_ptr
= binfo
;
482 *via_virtual_ptr
= via_virtual
;
486 int same_object
= (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
487 BINFO_OFFSET (binfo
))
488 && *via_virtual_ptr
&& via_virtual
);
490 if (*via_virtual_ptr
&& via_virtual
==0)
492 *rval_private_ptr
= is_private
;
493 *new_binfo_ptr
= binfo
;
494 *via_virtual_ptr
= via_virtual
;
496 else if (same_object
)
498 if (*rval_private_ptr
&& ! is_private
)
500 *rval_private_ptr
= is_private
;
501 *new_binfo_ptr
= binfo
;
502 *via_virtual_ptr
= via_virtual
;
512 binfos
= BINFO_BASETYPES (binfo
);
513 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
516 /* Process base types. */
517 for (i
= 0; i
< n_baselinks
; i
++)
519 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
521 /* Find any specific instance of a virtual base, when searching with
523 if (BINFO_MARKED (base_binfo
) == 0 || TREE_CODE (parent
) == TREE_VEC
)
528 || (!TREE_VIA_PUBLIC (base_binfo
)
529 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
530 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
533 /* When searching for a non-virtual, we cannot mark
534 virtually found binfos. */
536 SET_BINFO_MARKED (base_binfo
);
538 #define WATCH_VALUES(rval, via_private) (rval == -1 ? 3 : via_private)
540 was
= WATCH_VALUES (rval
, *via_virtual_ptr
);
541 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
542 binfo
, rval
, rval_private_ptr
,
543 new_binfo_ptr
, parent
, path_ptr
,
544 protect
, via_virtual_ptr
,
546 /* watch for updates; only update if path is good. */
547 if (path_ptr
&& WATCH_VALUES (rval
, *via_virtual_ptr
) != was
)
548 BINFO_INHERITANCE_CHAIN (base_binfo
) = binfo
;
549 if (rval
== -2 && *via_virtual_ptr
== 0)
560 /* Return the number of levels between type PARENT and the type given
561 in BINFO, following the leftmost path to PARENT not found along a
562 virtual path, if there are no real PARENTs (all come from virtual
563 base classes), then follow the leftmost path to PARENT.
565 Return -1 if TYPE is not derived from PARENT.
566 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
568 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
570 If PATH_PTR is non-NULL, then also build the list of types
571 from PARENT to TYPE, with TREE_VIA_VIRUAL and TREE_VIA_PUBLIC
574 PARENT can also be a binfo, in which case that exact parent is found
575 and no other. convert_pointer_to_real uses this functionality.
577 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
580 get_base_distance (parent
, binfo
, protect
, path_ptr
)
581 register tree parent
, binfo
;
586 int rval_private
= 0;
588 tree new_binfo
= NULL_TREE
;
590 int watch_access
= protect
;
592 if (TREE_CODE (parent
) != TREE_VEC
)
593 parent
= TYPE_MAIN_VARIANT (parent
);
595 if (TREE_CODE (binfo
) == TREE_VEC
)
596 type
= BINFO_TYPE (binfo
);
597 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
600 binfo
= TYPE_BINFO (type
);
603 BINFO_INHERITANCE_CHAIN (binfo
) = NULL_TREE
;
606 my_friendly_abort (92);
608 if (parent
== type
|| parent
== binfo
)
610 /* If the distance is 0, then we don't really need
611 a path pointer, but we shouldn't let garbage go back. */
620 rval
= get_base_distance_recursive (binfo
, 0, 0, NULL_TREE
, -1,
621 &rval_private
, &new_binfo
, parent
,
622 path_ptr
, watch_access
, &via_virtual
, 0);
624 dfs_walk (binfo
, dfs_unmark
, markedp
);
626 /* Access restrictions don't count if we found an ambiguous basetype. */
627 if (rval
== -2 && protect
>= 0)
630 if (rval
&& protect
&& rval_private
)
633 /* find real virtual base classes. */
634 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
635 && parent
== binfo_member (BINFO_TYPE (parent
),
636 CLASSTYPE_VBASECLASSES (type
)))
638 BINFO_INHERITANCE_CHAIN (parent
) = binfo
;
644 *path_ptr
= new_binfo
;
648 /* Search for a member with name NAME in a multiple inheritance lattice
649 specified by TYPE. If it does not exist, return NULL_TREE.
650 If the member is ambiguously referenced, return `error_mark_node'.
651 Otherwise, return the FIELD_DECL. */
653 /* Do a 1-level search for NAME as a member of TYPE. The caller must
654 figure out whether it can access this field. (Since it is only one
655 level, this is reasonable.) */
657 lookup_field_1 (type
, name
)
660 register tree field
= TYPE_FIELDS (type
);
662 #ifdef GATHER_STATISTICS
663 n_calls_lookup_field_1
++;
667 #ifdef GATHER_STATISTICS
670 if (DECL_NAME (field
) == NULL_TREE
671 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
673 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
677 if (DECL_NAME (field
) == name
)
679 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
680 && DECL_ASSEMBLER_NAME (field
) != NULL
)
681 GNU_xref_ref(current_function_decl
,
682 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
685 field
= TREE_CHAIN (field
);
688 if (name
== _vptr_name
)
690 /* Give the user what s/he thinks s/he wants. */
691 if (TYPE_VIRTUAL_P (type
))
692 return CLASSTYPE_VFIELD (type
);
697 /* There are a number of cases we need to be aware of here:
698 current_class_type current_function_decl
701 * class-local SET NULL
705 Those last two make life interesting. If we're in a function which is
706 itself inside a class, we need decls to go into the fn's decls (our
707 second case below). But if we're in a class and the class itself is
708 inside a function, we need decls to go into the decls for the class. To
709 achieve this last goal, we must see if, when both current_class_decl and
710 current_function_decl are set, the class was declared inside that
711 function. If so, we know to put the decls into the class's scope. */
716 if (current_function_decl
== NULL_TREE
)
717 return current_class_type
;
718 if (current_class_type
== NULL_TREE
)
719 return current_function_decl
;
720 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
721 return current_function_decl
;
723 return current_class_type
;
726 /* Compute the access of FIELD. This is done by computing
727 the access available to each type in BASETYPES (which comes
728 as a list of [via_public/basetype] in reverse order, namely base
729 class before derived class). The first one which defines a
730 access defines the access for the field. Otherwise, the
731 access of the field is that which occurs normally.
733 Uses global variables CURRENT_CLASS_TYPE and
734 CURRENT_FUNCTION_DECL to use friend relationships
737 This will be static when lookup_fnfield comes into this file.
739 access_public means that the field can be accessed by the current lexical
742 access_protected means that the field cannot be accessed by the current
743 lexical scope because it is protected.
745 access_private means that the field cannot be accessed by the current
746 lexical scope because it is private. */
749 #define PUBLIC_RETURN return (DECL_PUBLIC (field) = 1), access_public
750 #define PROTECTED_RETURN return (DECL_PROTECTED (field) = 1), access_protected
751 #define PRIVATE_RETURN return (DECL_PRIVATE (field) = 1), access_private
753 #define PUBLIC_RETURN return access_public
754 #define PROTECTED_RETURN return access_protected
755 #define PRIVATE_RETURN return access_private
759 /* Disabled with DECL_PUBLIC &c. */
760 static tree previous_scope
= NULL_TREE
;
764 compute_access (basetype_path
, field
)
765 tree basetype_path
, field
;
767 enum access_type access
;
770 int protected_ok
, via_protected
;
772 /* Replaces static decl above. */
776 ((TREE_CODE (field
) == FUNCTION_DECL
&& DECL_STATIC_FUNCTION_P (field
))
777 || (TREE_CODE (field
) != FUNCTION_DECL
&& TREE_STATIC (field
)));
779 /* The field lives in the current class. */
780 if (BINFO_TYPE (basetype_path
) == current_class_type
)
781 return access_public
;
784 /* Disabled until pushing function scope clears these out. If ever. */
785 /* Make these special cases fast. */
786 if (current_scope () == previous_scope
)
788 if (DECL_PUBLIC (field
))
789 return access_public
;
790 if (DECL_PROTECTED (field
))
791 return access_protected
;
792 if (DECL_PRIVATE (field
))
793 return access_private
;
797 previous_scope
= current_scope ();
799 context
= DECL_CLASS_CONTEXT (field
);
800 if (context
== NULL_TREE
)
801 context
= DECL_CONTEXT (field
);
803 /* Fields coming from nested anonymous unions have their DECL_CLASS_CONTEXT
804 slot set to the union type rather than the record type containing
805 the anonymous union. In this case, DECL_FIELD_CONTEXT is correct. */
806 if (context
&& TREE_CODE (context
) == UNION_TYPE
807 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context
)))
808 context
= DECL_FIELD_CONTEXT (field
);
810 /* Virtual function tables are never private. But we should know that
811 we are looking for this, and not even try to hide it. */
812 if (DECL_NAME (field
) && VFIELD_NAME_P (DECL_NAME (field
)) == 1)
815 /* Member found immediately within object. */
816 if (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
)
818 /* Are we (or an enclosing scope) friends with the class that has
820 if (is_friend (context
, previous_scope
))
823 /* If it's private, it's private, you letch. */
824 if (TREE_PRIVATE (field
))
827 /* ARM $11.5. Member functions of a derived class can access the
828 non-static protected members of a base class only through a
829 pointer to the derived class, a reference to it, or an object
830 of it. Also any subsequently derived classes also have
832 else if (TREE_PROTECTED (field
))
834 if (current_class_type
836 && ACCESSIBLY_DERIVED_FROM_P (context
, current_class_type
))
845 /* must reverse more than one element */
846 basetype_path
= reverse_path (basetype_path
);
847 types
= basetype_path
;
849 access
= access_default
;
850 protected_ok
= static_mem
&& current_class_type
851 && ACCESSIBLY_DERIVED_FROM_P (BINFO_TYPE (types
), current_class_type
);
857 tree type
= BINFO_TYPE (binfo
);
860 /* Friends of a class can see protected members of its bases.
861 Note that classes are their own friends. */
862 if (is_friend (type
, previous_scope
))
868 member
= purpose_member (type
, DECL_ACCESS (field
));
871 access
= (enum access_type
) TREE_VALUE (member
);
875 types
= BINFO_INHERITANCE_CHAIN (types
);
877 /* If the next type was VIA_PROTECTED, then fields of all remaining
878 classes past that one are *at least* protected. */
881 if (TREE_VIA_PROTECTED (types
))
883 else if (! TREE_VIA_PUBLIC (types
) && ! private_ok
)
885 access
= access_private
;
892 reverse_path (basetype_path
);
894 /* No special visibilities apply. Use normal rules. */
896 if (access
== access_default
)
898 if (is_friend (context
, previous_scope
))
899 access
= access_public
;
900 else if (TREE_PRIVATE (field
))
901 access
= access_private
;
902 else if (TREE_PROTECTED (field
))
903 access
= access_protected
;
905 access
= access_public
;
908 if (access
== access_public
&& via_protected
)
909 access
= access_protected
;
911 if (access
== access_protected
&& protected_ok
)
912 access
= access_public
;
915 if (access
== access_public
)
916 DECL_PUBLIC (field
) = 1;
917 else if (access
== access_protected
)
918 DECL_PROTECTED (field
) = 1;
919 else if (access
== access_private
)
920 DECL_PRIVATE (field
) = 1;
921 else my_friendly_abort (96);
926 /* Routine to see if the sub-object denoted by the binfo PARENT can be
927 found as a base class and sub-object of the object denoted by
928 BINFO. This routine relies upon binfos not being shared, except
929 for binfos for virtual bases. */
931 is_subobject_of_p (parent
, binfo
)
934 tree binfos
= BINFO_BASETYPES (binfo
);
935 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
940 /* Process and/or queue base types. */
941 for (i
= 0; i
< n_baselinks
; i
++)
943 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
944 if (TREE_VIA_VIRTUAL (base_binfo
))
945 base_binfo
= TYPE_BINFO (BINFO_TYPE (base_binfo
));
946 if (is_subobject_of_p (parent
, base_binfo
))
952 /* See if a one FIELD_DECL hides another. This routine is meant to
953 correspond to ANSI working paper Sept 17, 1992 10p4. The two
954 binfos given are the binfos corresponding to the particular places
955 the FIELD_DECLs are found. This routine relies upon binfos not
956 being shared, except for virtual bases. */
958 hides (hider_binfo
, hidee_binfo
)
959 tree hider_binfo
, hidee_binfo
;
961 /* hider hides hidee, if hider has hidee as a base class and
962 the instance of hidee is a sub-object of hider. The first
963 part is always true is the second part is true.
965 When hider and hidee are the same (two ways to get to the exact
966 same member) we consider either one as hiding the other. */
967 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
970 /* Very similar to lookup_fnfields_1 but it ensures that at least one
971 function was declared inside the class given by TYPE. It really should
972 only return functions that match the given TYPE. */
974 lookup_fnfields_here (type
, name
)
977 int index
= lookup_fnfields_1 (type
, name
);
982 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), index
);
985 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (fndecls
))
986 == TYPE_MAIN_VARIANT (type
))
988 fndecls
= TREE_CHAIN (fndecls
);
993 /* Look for a field named NAME in an inheritance lattice dominated by
994 XBASETYPE. PROTECT is zero if we can avoid computing access
995 information, otherwise it is 1. WANT_TYPE is 1 when we should only
996 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
998 It was not clear what should happen if WANT_TYPE is set, and an
999 ambiguity is found. At least one use (lookup_name) to not see
1002 lookup_field (xbasetype
, name
, protect
, want_type
)
1003 register tree xbasetype
, name
;
1004 int protect
, want_type
;
1006 int head
= 0, tail
= 0;
1007 tree rval
, rval_binfo
= NULL_TREE
, rval_binfo_h
;
1008 tree type
, basetype_chain
, basetype_path
;
1009 enum access_type this_v
= access_default
;
1010 tree entry
, binfo
, binfo_h
;
1011 enum access_type own_access
= access_default
;
1012 int vbase_name_p
= VBASE_NAME_P (name
);
1014 /* rval_binfo is the binfo associated with the found member, note,
1015 this can be set with useful information, even when rval is not
1016 set, because it must deal with ALL members, not just non-function
1017 members. It is used for ambiguity checking and the hidden
1018 checks. Whereas rval is only set if a proper (not hidden)
1019 non-function member is found. */
1021 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1022 hiding checks, as virtual base classes may not be shared. The strategy
1023 is we always go into the the binfo hierarchy owned by TYPE_BINFO of
1024 virtual base classes, as we cross virtual base class lines. This way
1025 we know that binfo of a virtual base class will always == itself when
1026 found along any line. (mrs) */
1030 /* Set this to nonzero if we don't know how to compute
1031 accurate error messages for access control. */
1032 int index
= MEMOIZED_HASH_FN (name
);
1034 /* If we are looking for a constructor in a templated type, use the
1035 unspecialized name, as that is how we store it. */
1036 if (IDENTIFIER_TEMPLATE (name
))
1037 name
= constructor_name (name
);
1039 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1041 type
= BINFO_TYPE (xbasetype
);
1042 basetype_path
= xbasetype
;
1044 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1047 basetype_path
= TYPE_BINFO (xbasetype
);
1048 BINFO_VIA_PUBLIC (basetype_path
) = 1;
1049 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1051 else my_friendly_abort (97);
1053 if (CLASSTYPE_MTABLE_ENTRY (type
))
1055 tree tem
= MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), index
);
1057 while (tem
&& TREE_PURPOSE (tem
) != name
)
1059 memoized_fields_searched
[0]++;
1060 tem
= TREE_CHAIN (tem
);
1064 if (protect
&& TREE_TYPE (tem
))
1066 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1067 IDENTIFIER_POINTER (name
),
1068 TYPE_NAME_STRING (DECL_FIELD_CONTEXT (TREE_VALUE (tem
))));
1069 return error_mark_node
;
1071 if (TREE_VALUE (tem
) == NULL_TREE
)
1072 memoized_fast_rejects
[0] += 1;
1074 memoized_fast_finds
[0] += 1;
1075 return TREE_VALUE (tem
);
1079 #ifdef GATHER_STATISTICS
1080 n_calls_lookup_field
++;
1082 if (protect
&& flag_memoize_lookups
&& ! global_bindings_p ())
1083 entry
= make_memoized_table_entry (type
, name
, 0);
1087 rval
= lookup_field_1 (type
, name
);
1088 if (rval
|| lookup_fnfields_here (type
, name
)>=0)
1090 rval_binfo
= basetype_path
;
1091 rval_binfo_h
= rval_binfo
;
1094 if (rval
&& TREE_CODE (rval
) != TYPE_DECL
&& want_type
)
1101 if (TREE_PRIVATE (rval
) | TREE_PROTECTED (rval
))
1102 this_v
= compute_access (basetype_path
, rval
);
1103 if (TREE_CODE (rval
) == CONST_DECL
)
1105 if (this_v
== access_private
)
1106 errstr
= "enum `%D' is a private value of class `%T'";
1107 else if (this_v
== access_protected
)
1108 errstr
= "enum `%D' is a protected value of class `%T'";
1112 if (this_v
== access_private
)
1113 errstr
= "member `%D' is a private member of class `%T'";
1114 else if (this_v
== access_protected
)
1115 errstr
= "member `%D' is a protected member of class `%T'";
1123 /* This depends on behavior of lookup_field_1! */
1124 tree error_string
= my_build_string (errstr
);
1125 TREE_TYPE (entry
) = error_string
;
1129 /* Let entry know there is no problem with this access. */
1130 TREE_TYPE (entry
) = NULL_TREE
;
1132 TREE_VALUE (entry
) = rval
;
1135 if (errstr
&& protect
)
1137 cp_error (errstr
, name
, type
);
1138 return error_mark_node
;
1143 basetype_chain
= build_tree_list (NULL_TREE
, basetype_path
);
1144 TREE_VIA_PUBLIC (basetype_chain
) = TREE_VIA_PUBLIC (basetype_path
);
1145 TREE_VIA_PROTECTED (basetype_chain
) = TREE_VIA_PROTECTED (basetype_path
);
1146 TREE_VIA_VIRTUAL (basetype_chain
) = TREE_VIA_VIRTUAL (basetype_path
);
1148 /* The ambiguity check relies upon breadth first searching. */
1150 search_stack
= push_search_level (search_stack
, &search_obstack
);
1151 binfo
= basetype_path
;
1156 tree binfos
= BINFO_BASETYPES (binfo
);
1157 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1160 /* Process and/or queue base types. */
1161 for (i
= 0; i
< n_baselinks
; i
++)
1163 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1164 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1168 SET_BINFO_FIELDS_MARKED (base_binfo
);
1169 btypes
= my_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1170 TREE_VIA_PUBLIC (btypes
) = TREE_VIA_PUBLIC (base_binfo
);
1171 TREE_VIA_PROTECTED (btypes
) = TREE_VIA_PROTECTED (base_binfo
);
1172 TREE_VIA_VIRTUAL (btypes
) = TREE_VIA_VIRTUAL (base_binfo
);
1173 if (TREE_VIA_VIRTUAL (base_binfo
))
1174 btypes
= tree_cons (NULL_TREE
,
1175 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1178 btypes
= tree_cons (NULL_TREE
,
1179 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1181 obstack_ptr_grow (&search_obstack
, btypes
);
1183 if (tail
>= search_stack
->limit
)
1184 my_friendly_abort (98);
1188 /* Process head of queue, if one exists. */
1192 basetype_chain
= search_stack
->first
[head
++];
1193 binfo_h
= TREE_VALUE (basetype_chain
);
1194 basetype_chain
= TREE_CHAIN (basetype_chain
);
1195 basetype_path
= TREE_VALUE (basetype_chain
);
1196 if (TREE_CHAIN (basetype_chain
))
1197 BINFO_INHERITANCE_CHAIN (basetype_path
) = TREE_VALUE (TREE_CHAIN (basetype_chain
));
1199 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1201 binfo
= basetype_path
;
1202 type
= BINFO_TYPE (binfo
);
1204 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1205 and we do find NAME in TYPE, verify that such a second
1206 sighting is in fact legal. */
1208 nval
= lookup_field_1 (type
, name
);
1210 if (nval
|| lookup_fnfields_here (type
, name
)>=0)
1212 if (nval
&& nval
== rval
&& SHARED_MEMBER_P (nval
))
1214 /* This is ok, the member found is the same [class.ambig] */
1216 else if (rval_binfo
&& hides (rval_binfo_h
, binfo_h
))
1218 /* This is ok, the member found is in rval_binfo, not
1221 else if (rval_binfo
==NULL_TREE
|| hides (binfo_h
, rval_binfo_h
))
1223 /* This is ok, the member found is here (binfo), not in
1228 if (entry
|| protect
)
1229 this_v
= compute_access (basetype_path
, rval
);
1230 /* These may look ambiguous, but they really are not. */
1236 /* Undo finding it before, as something else hides it. */
1240 rval_binfo_h
= binfo_h
;
1244 /* This is ambiguous. */
1245 errstr
= "request for member `%D' is ambiguous";
1252 tree
*tp
= search_stack
->first
;
1253 tree
*search_tail
= tp
+ tail
;
1256 TREE_VALUE (entry
) = rval
;
1258 if (want_type
&& (rval
== NULL_TREE
|| TREE_CODE (rval
) != TYPE_DECL
))
1264 /* If this FIELD_DECL defines its own access level, deal with that. */
1265 if (rval
&& errstr
== 0
1266 && ((protect
&1) || entry
)
1267 && DECL_LANG_SPECIFIC (rval
)
1268 && DECL_ACCESS (rval
))
1270 while (tp
< search_tail
)
1272 /* If is possible for one of the derived types on the path to
1273 have defined special access for this field. Look for such
1274 declarations and report an error if a conflict is found. */
1275 enum access_type new_v
;
1277 if (this_v
!= access_default
)
1278 new_v
= compute_access (TREE_VALUE (TREE_CHAIN (*tp
)), rval
);
1279 if (this_v
!= access_default
&& new_v
!= this_v
)
1281 errstr
= "conflicting access to member `%D'";
1282 this_v
= access_default
;
1285 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1291 while (tp
< search_tail
)
1293 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1298 search_stack
= pop_search_level (search_stack
);
1302 if (own_access
== access_private
)
1303 errstr
= "member `%D' declared private";
1304 else if (own_access
== access_protected
)
1305 errstr
= "member `%D' declared protected";
1306 else if (this_v
== access_private
)
1307 errstr
= TREE_PRIVATE (rval
)
1308 ? "member `%D' is private"
1309 : "member `%D' is from private base class";
1310 else if (this_v
== access_protected
)
1311 errstr
= TREE_PROTECTED (rval
)
1312 ? "member `%D' is protected"
1313 : "member `%D' is from protected base class";
1320 tree error_string
= my_build_string (errstr
);
1321 /* Save error message with entry. */
1322 TREE_TYPE (entry
) = error_string
;
1326 /* Mark entry as having no error string. */
1327 TREE_TYPE (entry
) = NULL_TREE
;
1331 if (errstr
&& protect
)
1333 cp_error (errstr
, name
, type
);
1334 rval
= error_mark_node
;
1339 /* Try to find NAME inside a nested class. */
1341 lookup_nested_field (name
, complain
)
1347 tree id
= NULL_TREE
;
1348 if (TREE_CHAIN (current_class_type
))
1350 /* Climb our way up the nested ladder, seeing if we're trying to
1351 modify a field in an enclosing class. If so, we should only
1352 be able to modify if it's static. */
1353 for (t
= TREE_CHAIN (current_class_type
);
1354 t
&& DECL_CONTEXT (t
);
1355 t
= TREE_CHAIN (DECL_CONTEXT (t
)))
1357 if (TREE_CODE (DECL_CONTEXT (t
)) != RECORD_TYPE
)
1360 /* N.B.: lookup_field will do the access checking for us */
1361 id
= lookup_field (DECL_CONTEXT (t
), name
, complain
, 0);
1362 if (id
== error_mark_node
)
1368 if (id
!= NULL_TREE
)
1370 if (TREE_CODE (id
) == FIELD_DECL
1371 && ! TREE_STATIC (id
)
1372 && TREE_TYPE (id
) != error_mark_node
)
1376 /* At parse time, we don't want to give this error, since
1377 we won't have enough state to make this kind of
1378 decision properly. But there are times (e.g., with
1379 enums in nested classes) when we do need to call
1380 this fn at parse time. So, in those cases, we pass
1381 complain as a 0 and just return a NULL_TREE. */
1382 error ("assignment to non-static member `%s' of enclosing class `%s'",
1383 lang_printable_name (id
),
1384 IDENTIFIER_POINTER (TYPE_IDENTIFIER
1385 (DECL_CONTEXT (t
))));
1386 /* Mark this for do_identifier(). It would otherwise
1387 claim that the variable was undeclared. */
1388 TREE_TYPE (id
) = error_mark_node
;
1404 /* TYPE is a class type. Return the index of the fields within
1405 the method vector with name NAME, or -1 is no such field exists. */
1407 lookup_fnfields_1 (type
, name
)
1410 register tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1412 if (method_vec
!= 0)
1414 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1415 register tree
*end
= TREE_VEC_END (method_vec
);
1417 #ifdef GATHER_STATISTICS
1418 n_calls_lookup_fnfields_1
++;
1420 if (*methods
&& name
== constructor_name (type
))
1423 while (++methods
!= end
)
1425 #ifdef GATHER_STATISTICS
1426 n_outer_fields_searched
++;
1428 if (DECL_NAME (*methods
) == name
)
1432 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1438 /* Starting from BASETYPE, return a TREE_BASELINK-like object
1439 which gives the following information (in a list):
1441 TREE_TYPE: list of basetypes needed to get to...
1442 TREE_VALUE: list of all functions in of given type
1443 which have name NAME.
1445 No access information is computed by this function,
1446 other then to adorn the list of basetypes with
1449 If there are two ways to find a name (two members), if COMPLAIN is
1450 non-zero, then error_mark_node is returned, and an error message is
1451 printed, otherwise, just an error_mark_node is returned.
1453 As a special case, is COMPLAIN is -1, we don't complain, and we
1454 don't return error_mark_node, but rather the complete list of
1455 virtuals. This is used by get_virtuals_named_this. */
1457 lookup_fnfields (basetype_path
, name
, complain
)
1458 tree basetype_path
, name
;
1461 int head
= 0, tail
= 0;
1462 tree type
, rval
, rval_binfo
= NULL_TREE
, rvals
= NULL_TREE
, rval_binfo_h
;
1463 tree entry
, binfo
, basetype_chain
, binfo_h
;
1466 /* rval_binfo is the binfo associated with the found member, note,
1467 this can be set with useful information, even when rval is not
1468 set, because it must deal with ALL members, not just function
1469 members. It is used for ambiguity checking and the hidden
1470 checks. Whereas rval is only set if a proper (not hidden)
1471 function member is found. */
1473 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1474 hiding checks, as virtual base classes may not be shared. The strategy
1475 is we always go into the the binfo hierarchy owned by TYPE_BINFO of
1476 virtual base classes, as we cross virtual base class lines. This way
1477 we know that binfo of a virtual base class will always == itself when
1478 found along any line. (mrs) */
1480 /* For now, don't try this. */
1481 int protect
= complain
;
1485 /* Set this to nonzero if we don't know how to compute
1486 accurate error messages for access control. */
1487 int index
= MEMOIZED_HASH_FN (name
);
1492 protect
= complain
= 0;
1495 /* If we are looking for a constructor in a templated type, use the
1496 unspecialized name, as that is how we store it. */
1497 if (IDENTIFIER_TEMPLATE (name
))
1498 name
= constructor_name (name
);
1500 binfo
= basetype_path
;
1502 type
= BINFO_TYPE (basetype_path
);
1504 /* The memoization code is in need of maintenance. */
1505 if (!find_all
&& CLASSTYPE_MTABLE_ENTRY (type
))
1507 tree tem
= MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), index
);
1509 while (tem
&& TREE_PURPOSE (tem
) != name
)
1511 memoized_fields_searched
[1]++;
1512 tem
= TREE_CHAIN (tem
);
1516 if (protect
&& TREE_TYPE (tem
))
1518 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1519 IDENTIFIER_POINTER (name
),
1520 TYPE_NAME_STRING (DECL_CLASS_CONTEXT (TREE_VALUE (TREE_VALUE (tem
)))));
1521 return error_mark_node
;
1523 if (TREE_VALUE (tem
) == NULL_TREE
)
1525 memoized_fast_rejects
[1] += 1;
1530 /* Want to return this, but we must make sure
1531 that access information is consistent. */
1532 tree baselink
= TREE_VALUE (tem
);
1533 tree memoized_basetypes
= TREE_PURPOSE (baselink
);
1534 tree these_basetypes
= basetype_path
;
1535 while (memoized_basetypes
&& these_basetypes
)
1537 memoized_fields_searched
[1]++;
1538 if (TREE_VALUE (memoized_basetypes
) != these_basetypes
)
1540 memoized_basetypes
= TREE_CHAIN (memoized_basetypes
);
1541 these_basetypes
= BINFO_INHERITANCE_CHAIN (these_basetypes
);
1543 /* The following statement is true only when both are NULL. */
1544 if (memoized_basetypes
== these_basetypes
)
1546 memoized_fast_finds
[1] += 1;
1547 return TREE_VALUE (tem
);
1549 /* else, we must re-find this field by hand. */
1550 baselink
= tree_cons (basetype_path
, TREE_VALUE (baselink
), TREE_CHAIN (baselink
));
1556 #ifdef GATHER_STATISTICS
1557 n_calls_lookup_fnfields
++;
1559 if (protect
&& flag_memoize_lookups
&& ! global_bindings_p ())
1560 entry
= make_memoized_table_entry (type
, name
, 1);
1564 index
= lookup_fnfields_here (type
, name
);
1565 if (index
>= 0 || lookup_field_1 (type
, name
))
1567 rval_binfo
= basetype_path
;
1568 rval_binfo_h
= rval_binfo
;
1573 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), index
);
1574 rvals
= my_tree_cons (basetype_path
, rval
, rvals
);
1575 if (BINFO_BASETYPES (binfo
) && CLASSTYPE_BASELINK_VEC (type
))
1576 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), index
);
1580 TREE_VALUE (entry
) = rvals
;
1581 TREE_TYPE (entry
) = NULL_TREE
;
1588 if (basetype_path
== TYPE_BINFO (type
))
1590 basetype_chain
= CLASSTYPE_BINFO_AS_LIST (type
);
1591 TREE_VIA_PUBLIC (basetype_chain
) = 1;
1592 BINFO_VIA_PUBLIC (basetype_path
) = 1;
1593 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1597 basetype_chain
= build_tree_list (NULL_TREE
, basetype_path
);
1598 TREE_VIA_PUBLIC (basetype_chain
) = TREE_VIA_PUBLIC (basetype_path
);
1599 TREE_VIA_PROTECTED (basetype_chain
) = TREE_VIA_PROTECTED (basetype_path
);
1600 TREE_VIA_VIRTUAL (basetype_chain
) = TREE_VIA_VIRTUAL (basetype_path
);
1603 /* The ambiguity check relies upon breadth first searching. */
1605 search_stack
= push_search_level (search_stack
, &search_obstack
);
1606 binfo
= basetype_path
;
1611 tree binfos
= BINFO_BASETYPES (binfo
);
1612 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1615 /* Process and/or queue base types. */
1616 for (i
= 0; i
< n_baselinks
; i
++)
1618 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1619 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1623 SET_BINFO_FIELDS_MARKED (base_binfo
);
1624 btypes
= my_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1625 TREE_VIA_PUBLIC (btypes
) = TREE_VIA_PUBLIC (base_binfo
);
1626 TREE_VIA_PROTECTED (btypes
) = TREE_VIA_PROTECTED (base_binfo
);
1627 TREE_VIA_VIRTUAL (btypes
) = TREE_VIA_VIRTUAL (base_binfo
);
1628 if (TREE_VIA_VIRTUAL (base_binfo
))
1629 btypes
= tree_cons (NULL_TREE
,
1630 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1633 btypes
= tree_cons (NULL_TREE
,
1634 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1636 obstack_ptr_grow (&search_obstack
, btypes
);
1638 if (tail
>= search_stack
->limit
)
1639 my_friendly_abort (99);
1643 /* Process head of queue, if one exists. */
1647 basetype_chain
= search_stack
->first
[head
++];
1648 binfo_h
= TREE_VALUE (basetype_chain
);
1649 basetype_chain
= TREE_CHAIN (basetype_chain
);
1650 basetype_path
= TREE_VALUE (basetype_chain
);
1651 if (TREE_CHAIN (basetype_chain
))
1652 BINFO_INHERITANCE_CHAIN (basetype_path
) = TREE_VALUE (TREE_CHAIN (basetype_chain
));
1654 BINFO_INHERITANCE_CHAIN (basetype_path
) = NULL_TREE
;
1656 binfo
= basetype_path
;
1657 type
= BINFO_TYPE (binfo
);
1659 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1660 and we do find NAME in TYPE, verify that such a second
1661 sighting is in fact legal. */
1663 index
= lookup_fnfields_here (type
, name
);
1665 if (index
>= 0 || (lookup_field_1 (type
, name
)!=NULL_TREE
&& !find_all
))
1667 if (rval_binfo
&& !find_all
&& hides (rval_binfo_h
, binfo_h
))
1669 /* This is ok, the member found is in rval_binfo, not
1672 else if (rval_binfo
==NULL_TREE
|| find_all
|| hides (binfo_h
, rval_binfo_h
))
1674 /* This is ok, the member found is here (binfo), not in
1678 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), index
);
1679 /* Note, rvals can only be previously set if find_all is
1681 rvals
= my_tree_cons (basetype_path
, rval
, rvals
);
1682 if (TYPE_BINFO_BASETYPES (type
)
1683 && CLASSTYPE_BASELINK_VEC (type
))
1684 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), index
);
1688 /* Undo finding it before, as something else hides it. */
1693 rval_binfo_h
= binfo_h
;
1697 /* This is ambiguous. */
1698 errstr
= "request for method `%D' is ambiguous";
1699 rvals
= error_mark_node
;
1705 tree
*tp
= search_stack
->first
;
1706 tree
*search_tail
= tp
+ tail
;
1708 while (tp
< search_tail
)
1710 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1714 search_stack
= pop_search_level (search_stack
);
1720 tree error_string
= my_build_string (errstr
);
1721 /* Save error message with entry. */
1722 TREE_TYPE (entry
) = error_string
;
1726 /* Mark entry as having no error string. */
1727 TREE_TYPE (entry
) = NULL_TREE
;
1728 TREE_VALUE (entry
) = rvals
;
1732 if (errstr
&& protect
)
1734 cp_error (errstr
, name
);
1735 rvals
= error_mark_node
;
1741 /* BREADTH-FIRST SEARCH ROUTINES. */
1743 /* Search a multiple inheritance hierarchy by breadth-first search.
1745 TYPE is an aggregate type, possibly in a multiple-inheritance hierarchy.
1746 TESTFN is a function, which, if true, means that our condition has been met,
1747 and its return value should be returned.
1748 QFN, if non-NULL, is a predicate dictating whether the type should
1752 breadth_first_search (binfo
, testfn
, qfn
)
1757 int head
= 0, tail
= 0;
1760 search_stack
= push_search_level (search_stack
, &search_obstack
);
1764 tree binfos
= BINFO_BASETYPES (binfo
);
1765 int n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1768 /* Process and/or queue base types. */
1769 for (i
= 0; i
< n_baselinks
; i
++)
1771 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1773 if (BINFO_MARKED (base_binfo
) == 0
1774 && (qfn
== 0 || (*qfn
) (binfo
, i
)))
1776 SET_BINFO_MARKED (base_binfo
);
1777 obstack_ptr_grow (&search_obstack
, binfo
);
1778 obstack_ptr_grow (&search_obstack
, (HOST_WIDE_INT
) i
);
1780 if (tail
>= search_stack
->limit
)
1781 my_friendly_abort (100);
1784 /* Process head of queue, if one exists. */
1791 binfo
= search_stack
->first
[head
++];
1792 i
= (HOST_WIDE_INT
) search_stack
->first
[head
++];
1793 if (rval
= (*testfn
) (binfo
, i
))
1795 binfo
= BINFO_BASETYPE (binfo
, i
);
1798 tree
*tp
= search_stack
->first
;
1799 tree
*search_tail
= tp
+ tail
;
1800 while (tp
< search_tail
)
1803 int i
= (HOST_WIDE_INT
)(*tp
++);
1804 CLEAR_BINFO_MARKED (BINFO_BASETYPE (binfo
, i
));
1808 search_stack
= pop_search_level (search_stack
);
1812 /* Functions to use in breadth first searches. */
1813 typedef tree (*pft
)();
1814 typedef int (*pfi
)();
1816 int tree_needs_constructor_p (binfo
, i
)
1821 my_friendly_assert (i
!= 0, 296);
1822 basetype
= BINFO_TYPE (BINFO_BASETYPE (binfo
, i
));
1823 return TYPE_NEEDS_CONSTRUCTING (basetype
);
1826 static tree declarator
;
1829 get_virtuals_named_this (binfo
)
1834 fields
= lookup_fnfields (binfo
, declarator
, -1);
1835 /* fields cannot be error_mark_node */
1840 /* Get to the function decls, and return the first virtual function
1841 with this name, if there is one. */
1846 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= DECL_CHAIN (fndecl
))
1847 if (DECL_VINDEX (fndecl
))
1849 fields
= next_baselink (fields
);
1854 static tree
get_virtual_destructor (binfo
, i
)
1858 tree type
= BINFO_TYPE (binfo
);
1860 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
1861 if (TYPE_HAS_DESTRUCTOR (type
)
1862 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 0)))
1863 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 0);
1867 int tree_has_any_destructor_p (binfo
, i
)
1871 tree type
= BINFO_TYPE (binfo
);
1873 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
1874 return TYPE_NEEDS_DESTRUCTOR (type
);
1877 /* Given a class type TYPE, and a function decl FNDECL, look for a
1878 virtual function in TYPE's hierarchy which FNDECL could match as a
1879 virtual function. It doesn't matter which one we find.
1881 DTORP is nonzero if we are looking for a destructor. Destructors
1882 need special treatment because they do not match by name. */
1884 get_matching_virtual (binfo
, fndecl
, dtorp
)
1888 tree tmp
= NULL_TREE
;
1890 /* Breadth first search routines start searching basetypes
1891 of TYPE, so we must perform first ply of search here. */
1894 if (tree_has_any_destructor_p (binfo
, -1))
1895 tmp
= get_virtual_destructor (binfo
, -1);
1900 tmp
= (tree
) breadth_first_search (binfo
,
1901 (pfi
) get_virtual_destructor
,
1902 tree_has_any_destructor_p
);
1907 tree drettype
, dtypes
, btypes
, instptr_type
;
1908 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
1909 tree baselink
, best
= NULL_TREE
;
1910 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
1912 declarator
= DECL_NAME (fndecl
);
1913 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
1916 baselink
= get_virtuals_named_this (binfo
);
1917 if (baselink
== NULL_TREE
)
1920 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
1921 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1922 if (DECL_STATIC_FUNCTION_P (fndecl
))
1923 instptr_type
= NULL_TREE
;
1925 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
1927 for (; baselink
; baselink
= next_baselink (baselink
))
1929 for (tmp
= TREE_VALUE (baselink
); tmp
; tmp
= DECL_CHAIN (tmp
))
1931 if (! DECL_VINDEX (tmp
))
1934 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
1935 if (instptr_type
== NULL_TREE
)
1937 if (compparms (TREE_CHAIN (btypes
), dtypes
, 3))
1938 /* Caller knows to give error in this case. */
1943 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (btypes
)))
1944 == TYPE_READONLY (instptr_type
))
1945 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
), 3))
1947 if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
1948 && ! comptypes (TREE_TYPE (TREE_TYPE (tmp
)), drettype
, 1))
1950 cp_error ("conflicting return type specified for virtual function `%#D'", fndecl
);
1951 cp_error_at ("overriding definition as `%#D'", tmp
);
1952 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
1963 if (best
== NULL_TREE
&& warn_overloaded_virtual
)
1964 cp_warning_at ("conflicting specification deriving virtual function `%D'", fndecl
);
1970 /* Return the list of virtual functions which are abstract in type
1971 TYPE that come from non virtual base classes. See
1972 expand_direct_vtbls_init for the style of search we do. */
1974 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
1975 tree binfo
, abstract_virtuals
;
1978 tree binfos
= BINFO_BASETYPES (binfo
);
1979 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1981 for (i
= 0; i
< n_baselinks
; i
++)
1983 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1984 int is_not_base_vtable
=
1985 i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
1986 if (! TREE_VIA_VIRTUAL (base_binfo
))
1988 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
1991 /* Should we use something besides CLASSTYPE_VFIELDS? */
1992 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
1994 tree tmp
= TREE_CHAIN (BINFO_VIRTUALS (binfo
));
1996 /* Get around dossier entry if there is one. */
1998 tmp
= TREE_CHAIN (tmp
);
2002 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (tmp
));
2003 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2004 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2005 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2006 tmp
= TREE_CHAIN (tmp
);
2009 return abstract_virtuals
;
2012 /* Return the list of virtual functions which are abstract in type TYPE.
2013 This information is cached, and so must be built on a
2014 non-temporary obstack. */
2016 get_abstract_virtuals (type
)
2020 tree abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (type
);
2022 /* First get all from non-virtual bases. */
2024 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
2026 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
2028 if (! BINFO_VIRTUALS (vbases
))
2031 tmp
= TREE_CHAIN (BINFO_VIRTUALS (vbases
));
2034 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (tmp
));
2035 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
2036 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
2037 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
2038 tmp
= TREE_CHAIN (tmp
);
2041 return nreverse (abstract_virtuals
);
2044 /* For the type TYPE, return a list of member functions available from
2045 base classes with name NAME. The TREE_VALUE of the list is a chain of
2046 member functions with name NAME. The TREE_PURPOSE of the list is a
2047 basetype, or a list of base types (in reverse order) which were
2048 traversed to reach the chain of member functions. If we reach a base
2049 type which provides a member function of name NAME, and which has at
2050 most one base type itself, then we can terminate the search. */
2053 get_baselinks (type_as_binfo_list
, type
, name
)
2054 tree type_as_binfo_list
;
2057 int head
= 0, tail
= 0, index
;
2058 tree rval
= 0, nval
= 0;
2059 tree basetypes
= type_as_binfo_list
;
2060 tree binfo
= TYPE_BINFO (type
);
2062 search_stack
= push_search_level (search_stack
, &search_obstack
);
2066 tree binfos
= BINFO_BASETYPES (binfo
);
2067 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2069 /* Process and/or queue base types. */
2070 for (i
= 0; i
< n_baselinks
; i
++)
2072 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2075 btypes
= hash_tree_cons (TREE_VIA_PUBLIC (base_binfo
),
2076 TREE_VIA_VIRTUAL (base_binfo
),
2077 TREE_VIA_PROTECTED (base_binfo
),
2078 NULL_TREE
, base_binfo
,
2080 obstack_ptr_grow (&search_obstack
, btypes
);
2081 search_stack
->first
= (tree
*)obstack_base (&search_obstack
);
2086 /* Process head of queue, if one exists. */
2090 basetypes
= search_stack
->first
[head
++];
2091 binfo
= TREE_VALUE (basetypes
);
2092 type
= BINFO_TYPE (binfo
);
2093 index
= lookup_fnfields_1 (type
, name
);
2096 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), index
);
2097 rval
= hash_tree_cons (0, 0, 0, basetypes
, nval
, rval
);
2098 if (TYPE_BINFO_BASETYPES (type
) == 0)
2100 else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
)) == 1)
2102 if (CLASSTYPE_BASELINK_VEC (type
))
2103 TREE_TYPE (rval
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), index
);
2110 search_stack
= pop_search_level (search_stack
);
2115 next_baselink (baselink
)
2118 tree tmp
= TREE_TYPE (baselink
);
2119 baselink
= TREE_CHAIN (baselink
);
2122 /* @@ does not yet add previous base types. */
2123 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2125 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2126 tmp
= TREE_CHAIN (tmp
);
2131 /* DEPTH-FIRST SEARCH ROUTINES. */
2133 /* Assign unique numbers to _CLASSTYPE members of the lattice
2134 specified by TYPE. The root nodes are marked first; the nodes
2135 are marked depth-fisrt, left-right. */
2139 /* Matrix implementing a relation from CLASSTYPE X CLASSTYPE => INT.
2140 Relation yields 1 if C1 <= C2, 0 otherwise. */
2141 typedef char mi_boolean
;
2142 static mi_boolean
*mi_matrix
;
2144 /* Type for which this matrix is defined. */
2145 static tree mi_type
;
2147 /* Size of the matrix for indexing purposes. */
2150 /* Return nonzero if class C2 derives from class C1. */
2151 #define BINFO_DERIVES_FROM(C1, C2) \
2152 ((mi_matrix+mi_size*(BINFO_CID (C1)-1))[BINFO_CID (C2)-1])
2153 #define TYPE_DERIVES_FROM(C1, C2) \
2154 ((mi_matrix+mi_size*(CLASSTYPE_CID (C1)-1))[CLASSTYPE_CID (C2)-1])
2155 #define BINFO_DERIVES_FROM_STAR(C) \
2156 (mi_matrix+(BINFO_CID (C)-1))
2158 /* This routine converts a pointer to be a pointer of an immediate
2159 base class. The normal convert_pointer_to routine would diagnose
2160 the conversion as ambiguous, under MI code that has the base class
2161 as an ambiguous base class. */
2163 convert_pointer_to_single_level (to_type
, expr
)
2166 tree binfo_of_derived
;
2169 binfo_of_derived
= TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
)));
2170 last
= get_binfo (to_type
, TREE_TYPE (TREE_TYPE (expr
)), 0);
2171 BINFO_INHERITANCE_CHAIN (last
) = binfo_of_derived
;
2172 BINFO_INHERITANCE_CHAIN (binfo_of_derived
) = NULL_TREE
;
2173 return build_vbase_path (PLUS_EXPR
, TYPE_POINTER_TO (to_type
), expr
, last
, 1);
2176 /* The main function which implements depth first search.
2178 This routine has to remember the path it walked up, when
2179 dfs_init_vbase_pointers is the work function, as otherwise there
2180 would be no record. */
2182 dfs_walk (binfo
, fn
, qfn
)
2187 tree binfos
= BINFO_BASETYPES (binfo
);
2188 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2190 for (i
= 0; i
< n_baselinks
; i
++)
2192 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2194 if ((*qfn
)(base_binfo
))
2196 if (fn
== dfs_init_vbase_pointers
)
2198 /* When traversing an arbitrary MI hierarchy, we need to keep
2199 a record of the path we took to get down to the final base
2200 type, as otherwise there would be no record of it, and just
2201 trying to blindly convert at the bottom would be ambiguous.
2203 The easiest way is to do the conversions one step at a time,
2204 as we know we want the immediate base class at each step.
2206 The only special trick to converting one step at a time,
2207 is that when we hit the last virtual base class, we must
2208 use the SLOT value for it, and not use the normal convert
2209 routine. We use the last virtual base class, as in our
2210 implementation, we have pointers to all virtual base
2211 classes in the base object. */
2213 tree saved_vbase_decl_ptr_intermediate
2214 = vbase_decl_ptr_intermediate
;
2216 if (TREE_VIA_VIRTUAL (base_binfo
))
2218 /* No need for the conversion here, as we know it is the
2220 vbase_decl_ptr_intermediate
2221 = (tree
)CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
));
2225 vbase_decl_ptr_intermediate
2226 = convert_pointer_to_single_level (BINFO_TYPE (base_binfo
),
2227 vbase_decl_ptr_intermediate
);
2230 dfs_walk (base_binfo
, fn
, qfn
);
2232 vbase_decl_ptr_intermediate
= saved_vbase_decl_ptr_intermediate
;
2234 dfs_walk (base_binfo
, fn
, qfn
);
2241 /* Predicate functions which serve for dfs_walk. */
2242 static int numberedp (binfo
) tree binfo
;
2243 { return BINFO_CID (binfo
); }
2244 static int unnumberedp (binfo
) tree binfo
;
2245 { return BINFO_CID (binfo
) == 0; }
2247 static int markedp (binfo
) tree binfo
;
2248 { return BINFO_MARKED (binfo
); }
2249 static int bfs_markedp (binfo
, i
) tree binfo
; int i
;
2250 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2251 static int unmarkedp (binfo
) tree binfo
;
2252 { return BINFO_MARKED (binfo
) == 0; }
2253 static int bfs_unmarkedp (binfo
, i
) tree binfo
; int i
;
2254 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2255 static int marked_vtable_pathp (binfo
) tree binfo
;
2256 { return BINFO_VTABLE_PATH_MARKED (binfo
); }
2257 static int bfs_marked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2258 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2259 static int unmarked_vtable_pathp (binfo
) tree binfo
;
2260 { return BINFO_VTABLE_PATH_MARKED (binfo
) == 0; }
2261 static int bfs_unmarked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2262 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2263 static int marked_new_vtablep (binfo
) tree binfo
;
2264 { return BINFO_NEW_VTABLE_MARKED (binfo
); }
2265 static int bfs_marked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2266 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2267 static int unmarked_new_vtablep (binfo
) tree binfo
;
2268 { return BINFO_NEW_VTABLE_MARKED (binfo
) == 0; }
2269 static int bfs_unmarked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2270 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2272 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2273 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2275 static int dfs_debug_unmarkedp (binfo
) tree binfo
;
2276 { return CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
)) == 0; }
2278 /* The worker functions for `dfs_walk'. These do not need to
2279 test anything (vis a vis marking) if they are paired with
2280 a predicate function (above). */
2282 /* Assign each type within the lattice a number which is unique
2283 in the lattice. The first number assigned is 1. */
2289 BINFO_CID (binfo
) = ++cid
;
2293 dfs_unnumber (binfo
)
2296 BINFO_CID (binfo
) = 0;
2300 dfs_mark (binfo
) tree binfo
;
2301 { SET_BINFO_MARKED (binfo
); }
2304 dfs_unmark (binfo
) tree binfo
;
2305 { CLEAR_BINFO_MARKED (binfo
); }
2308 dfs_mark_vtable_path (binfo
) tree binfo
;
2309 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2312 dfs_unmark_vtable_path (binfo
) tree binfo
;
2313 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2316 dfs_mark_new_vtable (binfo
) tree binfo
;
2317 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2320 dfs_unmark_new_vtable (binfo
) tree binfo
;
2321 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2324 dfs_clear_search_slot (binfo
) tree binfo
;
2325 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2328 dfs_debug_mark (binfo
)
2331 tree t
= BINFO_TYPE (binfo
);
2333 /* Use heuristic that if there are virtual functions,
2334 ignore until we see a non-inline virtual function. */
2335 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2337 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2339 /* If interface info is known, the value of (?@@?) is correct. */
2341 || CLASSTYPE_INTERFACE_KNOWN (t
)
2342 || (write_virtuals
== 2 && TYPE_VIRTUAL_P (t
)))
2345 /* If debug info is requested from this context for this type, supply it.
2346 If debug info is requested from another context for this type,
2347 see if some third context can supply it. */
2348 if (current_function_decl
== NULL_TREE
2349 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2351 if (TREE_VEC_ELT (methods
, 0))
2352 methods
= TREE_VEC_ELT (methods
, 0);
2354 methods
= TREE_VEC_ELT (methods
, 1);
2357 if (DECL_VINDEX (methods
)
2358 && DECL_SAVED_INSNS (methods
) == 0
2359 && DECL_PENDING_INLINE_INFO (methods
) == 0
2360 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2362 /* Somebody, somewhere is going to have to define this
2363 virtual function. When they do, they will provide
2364 the debugging info. */
2367 methods
= TREE_CHAIN (methods
);
2370 /* We cannot rely on some alien method to solve our problems,
2371 so we must write out the debug info ourselves. */
2372 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2373 rest_of_type_compilation (t
, global_bindings_p ());
2376 /* Attach to the type of the virtual base class, the pointer to the
2377 virtual base class, given the global pointer vbase_decl_ptr.
2379 We use the global vbase_types. ICK! */
2381 dfs_find_vbases (binfo
)
2384 tree binfos
= BINFO_BASETYPES (binfo
);
2385 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2387 for (i
= n_baselinks
-1; i
>= 0; i
--)
2389 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2391 if (TREE_VIA_VIRTUAL (base_binfo
)
2392 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2394 tree vbase
= BINFO_TYPE (base_binfo
);
2395 tree binfo
= binfo_member (vbase
, vbase_types
);
2397 CLASSTYPE_SEARCH_SLOT (vbase
)
2398 = (char *) build (PLUS_EXPR
, TYPE_POINTER_TO (vbase
),
2399 vbase_decl_ptr
, BINFO_OFFSET (binfo
));
2402 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2403 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2407 dfs_init_vbase_pointers (binfo
)
2410 tree type
= BINFO_TYPE (binfo
);
2411 tree fields
= TYPE_FIELDS (type
);
2412 tree this_vbase_ptr
;
2414 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2416 /* If there is a dossier, it is the first field, though perhaps from
2417 the base class. Otherwise, the first fields are virtual base class
2419 if (CLASSTYPE_DOSSIER (type
) && VFIELD_NAME_P (DECL_NAME (fields
)))
2420 /* Get past vtable for the object. */
2421 fields
= TREE_CHAIN (fields
);
2423 if (fields
== NULL_TREE
2424 || DECL_NAME (fields
) == NULL_TREE
2425 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2428 this_vbase_ptr
= vbase_decl_ptr_intermediate
;
2430 if (TYPE_POINTER_TO (type
) != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2431 my_friendly_abort (125);
2433 while (fields
&& DECL_NAME (fields
)
2434 && VBASE_NAME_P (DECL_NAME (fields
)))
2436 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2437 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2438 tree init
= (tree
)CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2439 vbase_init_result
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2441 build_modify_expr (ref
, NOP_EXPR
, init
),
2443 fields
= TREE_CHAIN (fields
);
2447 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2448 times, just NEW_VTABLE, but optimizer should make both with equal
2449 efficiency (though it does not currently). */
2451 dfs_clear_vbase_slots (binfo
)
2454 tree type
= BINFO_TYPE (binfo
);
2455 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2456 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2457 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2461 init_vbase_pointers (type
, decl_ptr
)
2465 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2467 int old_flag
= flag_this_is_variable
;
2468 tree binfo
= TYPE_BINFO (type
);
2469 flag_this_is_variable
= -2;
2470 vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2471 vbase_decl_ptr
= decl_ptr
;
2472 vbase_decl
= build_indirect_ref (decl_ptr
, NULL_PTR
);
2473 vbase_decl_ptr_intermediate
= vbase_decl_ptr
;
2474 vbase_init_result
= NULL_TREE
;
2475 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
);
2476 dfs_walk (binfo
, dfs_init_vbase_pointers
, marked_vtable_pathp
);
2477 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
2478 flag_this_is_variable
= old_flag
;
2479 return vbase_init_result
;
2484 /* Build a COMPOUND_EXPR which when expanded will generate the code
2485 needed to initialize all the virtual function table slots of all
2486 the virtual baseclasses. MAIN_BINFO is the binfo which determines
2487 the virtual baseclasses to use; TYPE is the type of the object to
2488 which the initialization applies. TRUE_EXP is the true object we
2489 are initializing, and DECL_PTR is the pointer to the sub-object we
2492 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
2493 object was laidout by a top-level contructor and the computed
2494 offsets are valid to store vtables. When zero, we must store new
2495 vtables through virtual baseclass pointers.
2497 We setup and use the globals: vbase_decl, vbase_decl_ptr, vbase_types
2501 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
, use_computed_offsets
)
2503 tree true_exp
, decl_ptr
;
2504 int use_computed_offsets
;
2506 tree type
= BINFO_TYPE (binfo
);
2507 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2509 int old_flag
= flag_this_is_variable
;
2510 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
2511 vbase_types
= vbases
;
2512 vbase_decl_ptr
= true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0) : decl_ptr
;
2513 vbase_decl
= true_exp
? true_exp
: build_indirect_ref (decl_ptr
, NULL_PTR
);
2515 if (use_computed_offsets
)
2517 /* This is an object of type IN_TYPE, */
2518 flag_this_is_variable
= -2;
2519 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
);
2522 /* Initialized with vtables of type TYPE. */
2523 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
2526 if (use_computed_offsets
)
2527 addr
= (tree
)CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbases
));
2530 tree vbinfo
= get_binfo (TREE_TYPE (vbases
),
2531 TREE_TYPE (vbase_decl
),
2534 /* See is we can get lucky. */
2535 if (TREE_VIA_VIRTUAL (vbinfo
))
2536 addr
= convert_pointer_to_real (vbinfo
, vbase_decl_ptr
);
2539 /* We go through all these contortions to avoid this
2540 call, as it will fail when the virtual base type
2541 is ambiguous from here. We don't yet have a way
2542 to search for and find just an instance of the
2543 virtual base class. Searching for the binfo in
2544 vbases won't work, as we don't have the vbase
2545 pointer field, for all vbases in the main class,
2546 only direct vbases. */
2547 addr
= convert_pointer_to_real (TREE_TYPE (vbases
),
2549 if (addr
== error_mark_node
)
2554 /* Do all vtables from this virtual base. */
2555 /* This assumes that virtual bases can never serve as parent
2556 binfos. (in the CLASSTPE_VFIELD_PARENT sense) */
2557 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
2561 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
2563 flag_this_is_variable
= old_flag
;
2568 clear_search_slots (type
)
2571 dfs_walk (TYPE_BINFO (type
),
2572 dfs_clear_search_slot
, dfs_search_slot_nonempty_p
);
2575 /* get virtual base class types.
2576 This adds type to the vbase_types list in reverse dfs order.
2577 Ordering is very important, so don't change it. */
2580 dfs_get_vbase_types (binfo
)
2583 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
2585 vbase_types
= make_binfo (integer_zero_node
, binfo
,
2586 BINFO_VTABLE (binfo
),
2587 BINFO_VIRTUALS (binfo
), vbase_types
);
2588 TREE_VIA_VIRTUAL (vbase_types
) = 1;
2589 SET_BINFO_VBASE_MARKED (binfo
);
2591 SET_BINFO_MARKED (binfo
);
2594 /* get a list of virtual base classes in dfs order. */
2596 get_vbase_types (type
)
2602 if (TREE_CODE (type
) == TREE_VEC
)
2605 binfo
= TYPE_BINFO (type
);
2607 vbase_types
= NULL_TREE
;
2608 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
);
2609 dfs_walk (binfo
, dfs_unmark
, markedp
);
2610 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2611 reverse it so that we get normal dfs ordering. */
2612 vbase_types
= nreverse (vbase_types
);
2614 /* unmark marked vbases */
2615 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
2616 CLEAR_BINFO_VBASE_MARKED (vbases
);
2622 dfs_record_inheritance (binfo
)
2625 tree binfos
= BINFO_BASETYPES (binfo
);
2626 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2627 mi_boolean
*derived_row
= BINFO_DERIVES_FROM_STAR (binfo
);
2629 for (i
= n_baselinks
-1; i
>= 0; i
--)
2632 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2633 tree baseclass
= BINFO_TYPE (base_binfo
);
2634 mi_boolean
*base_row
= BINFO_DERIVES_FROM_STAR (base_binfo
);
2636 /* Don't search if there's nothing there! MI_SIZE can be
2637 zero as a result of parse errors. */
2638 if (TYPE_BINFO_BASETYPES (baseclass
) && mi_size
> 0)
2639 for (j
= mi_size
*(CLASSTYPE_CID (baseclass
)-1); j
>= 0; j
-= mi_size
)
2640 derived_row
[j
] |= base_row
[j
];
2641 TYPE_DERIVES_FROM (baseclass
, BINFO_TYPE (binfo
)) = 1;
2644 SET_BINFO_MARKED (binfo
);
2647 /* Given a _CLASSTYPE node in a multiple inheritance lattice,
2648 convert the lattice into a simple relation such that,
2649 given to CIDs, C1 and C2, one can determine if C1 <= C2
2650 or C2 <= C1 or C1 <> C2.
2652 Once constructed, we walk the lattice depth fisrt,
2653 applying various functions to elements as they are encountered.
2655 We use xmalloc here, in case we want to randomly free these tables. */
2657 #define SAVE_MI_MATRIX
2660 build_mi_matrix (type
)
2663 tree binfo
= TYPE_BINFO (type
);
2666 #ifdef SAVE_MI_MATRIX
2667 if (CLASSTYPE_MI_MATRIX (type
))
2669 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
2670 mi_matrix
= CLASSTYPE_MI_MATRIX (type
);
2672 dfs_walk (binfo
, dfs_number
, unnumberedp
);
2677 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
2678 mi_matrix
= (char *)xmalloc ((mi_size
+ 1) * (mi_size
+ 1));
2680 bzero (mi_matrix
, (mi_size
+ 1) * (mi_size
+ 1));
2681 dfs_walk (binfo
, dfs_number
, unnumberedp
);
2682 dfs_walk (binfo
, dfs_record_inheritance
, unmarkedp
);
2683 dfs_walk (binfo
, dfs_unmark
, markedp
);
2689 dfs_walk (TYPE_BINFO (mi_type
), dfs_unnumber
, numberedp
);
2691 #ifdef SAVE_MI_MATRIX
2692 CLASSTYPE_MI_MATRIX (mi_type
) = mi_matrix
;
2700 /* If we want debug info for a type TYPE, make sure all its base types
2701 are also marked as being potentially interesting. This avoids
2702 the problem of not writing any debug info for intermediate basetypes
2703 that have abstract virtual functions. Also mark member types. */
2706 note_debug_info_needed (type
)
2710 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
);
2711 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2714 if (TREE_CODE (field
) == FIELD_DECL
2715 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
2716 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
)))
2717 note_debug_info_needed (ttype
);
2721 /* Subroutines of push_class_decls (). */
2723 /* Add the instance variables which this class contributed to the
2724 current class binding contour. When a redefinition occurs,
2725 if the redefinition is strictly within a single inheritance path,
2726 we just overwrite (in the case of a data field) or
2727 cons (in the case of a member function) the old declaration with
2728 the new. If the fields are not within a single inheritance path,
2729 we must cons them in either case.
2731 In order to know what decls are new (stemming from the current
2732 invocation of push_class_decls) we enclose them in an "envelope",
2733 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
2734 new decl (or possibly a list of competing ones), the TREE_VALUE slot
2735 points to the old value and the TREE_CHAIN slot chains together all
2736 envelopes which needs to be "opened" in push_class_decls. Opening an
2737 envelope means: push the old value onto the class_shadowed list,
2738 install the new one and if it's a TYPE_DECL do the same to the
2739 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
2740 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
2741 Because if it is, it could be a set of overloaded methods from an
2745 dfs_pushdecls (binfo
)
2748 tree type
= BINFO_TYPE (binfo
);
2749 tree fields
, *methods
, *end
;
2752 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2754 /* Unmark so that if we are in a constructor, and then find that
2755 this field was initialized by a base initializer,
2756 we can emit an error message. */
2757 if (TREE_CODE (fields
) == FIELD_DECL
)
2758 TREE_USED (fields
) = 0;
2760 /* Recurse into anonymous unions. */
2761 if (DECL_NAME (fields
) == NULL_TREE
2762 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
2764 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields
)));
2769 if (TREE_CODE (fields
) != TYPE_DECL
)
2771 DECL_PUBLIC (fields
) = 0;
2772 DECL_PROTECTED (fields
) = 0;
2773 DECL_PRIVATE (fields
) = 0;
2777 if (DECL_NAME (fields
))
2779 tree class_value
= IDENTIFIER_CLASS_VALUE (DECL_NAME (fields
));
2781 /* If the class value is an envelope of the kind described in
2782 the comment above, we try to rule out possible ambiguities.
2783 If we can't do that, keep a TREE_LIST with possibly ambiguous
2785 if (class_value
&& TREE_CODE (class_value
) == TREE_LIST
2786 && TREE_PURPOSE (class_value
) != NULL_TREE
2787 && (TREE_CODE (TREE_PURPOSE (class_value
))
2788 != IDENTIFIER_NODE
))
2790 tree value
= TREE_PURPOSE (class_value
);
2793 /* Possible ambiguity. If its defining type(s)
2794 is (are all) derived from us, no problem. */
2795 if (TREE_CODE (value
) != TREE_LIST
)
2797 context
= (TREE_CODE (value
) == FUNCTION_DECL
2798 && DECL_VIRTUAL_P (value
))
2799 ? DECL_CLASS_CONTEXT (value
)
2800 : DECL_CONTEXT (value
);
2802 if (context
&& (context
== type
2803 || TYPE_DERIVES_FROM (context
, type
)))
2806 value
= tree_cons (NULL_TREE
, fields
,
2807 build_tree_list (NULL_TREE
, value
));
2811 /* All children may derive from us, in which case
2812 there is no problem. Otherwise, we have to
2813 keep lists around of what the ambiguities might be. */
2817 for (values
= value
; values
; values
= TREE_CHAIN (values
))
2819 tree sub_values
= TREE_VALUE (values
);
2821 if (TREE_CODE (sub_values
) == TREE_LIST
)
2823 for (; sub_values
; sub_values
= TREE_CHAIN (sub_values
))
2825 register tree list_mbr
= TREE_VALUE (sub_values
);
2827 context
= (TREE_CODE (list_mbr
) == FUNCTION_DECL
2828 && DECL_VIRTUAL_P (list_mbr
))
2829 ? DECL_CLASS_CONTEXT (list_mbr
)
2830 : DECL_CONTEXT (list_mbr
);
2832 if (! TYPE_DERIVES_FROM (context
, type
))
2834 value
= tree_cons (NULL_TREE
, TREE_VALUE (values
), value
);
2842 context
= (TREE_CODE (sub_values
) == FUNCTION_DECL
2843 && DECL_VIRTUAL_P (sub_values
))
2844 ? DECL_CLASS_CONTEXT (sub_values
)
2845 : DECL_CONTEXT (sub_values
);
2847 if (context
&& ! TYPE_DERIVES_FROM (context
, type
))
2849 value
= tree_cons (NULL_TREE
, values
, value
);
2855 if (! problem
) value
= fields
;
2858 /* Mark this as a potentially ambiguous member. */
2859 if (TREE_CODE (value
) == TREE_LIST
)
2861 /* Leaving TREE_TYPE blank is intentional.
2862 We cannot use `error_mark_node' (lookup_name)
2863 or `unknown_type_node' (all member functions use this). */
2864 TREE_NONLOCAL_FLAG (value
) = 1;
2867 /* Put the new contents in our envelope. */
2868 TREE_PURPOSE (class_value
) = value
;
2872 /* See comment above for a description of envelopes. */
2873 tree envelope
= tree_cons (fields
, class_value
,
2876 closed_envelopes
= envelope
;
2877 IDENTIFIER_CLASS_VALUE (DECL_NAME (fields
)) = envelope
;
2882 method_vec
= CLASSTYPE_METHOD_VEC (type
);
2883 if (method_vec
!= 0)
2885 /* Farm out constructors and destructors. */
2886 methods
= &TREE_VEC_ELT (method_vec
, 1);
2887 end
= TREE_VEC_END (method_vec
);
2889 /* This does not work for multiple inheritance yet. */
2890 while (methods
!= end
)
2892 /* This will cause lookup_name to return a pointer
2893 to the tree_list of possible methods of this name.
2894 If the order is a problem, we can nreverse them. */
2896 tree class_value
= IDENTIFIER_CLASS_VALUE (DECL_NAME (*methods
));
2898 if (class_value
&& TREE_CODE (class_value
) == TREE_LIST
2899 && TREE_PURPOSE (class_value
) != NULL_TREE
2900 && TREE_CODE (TREE_PURPOSE (class_value
)) != IDENTIFIER_NODE
)
2902 tree old
= TREE_PURPOSE (class_value
);
2904 maybe_push_cache_obstack ();
2905 if (TREE_CODE (old
) == TREE_LIST
)
2906 tmp
= tree_cons (DECL_NAME (*methods
), *methods
, old
);
2909 /* Only complain if we shadow something we can access. */
2912 && ((DECL_LANG_SPECIFIC (old
)
2913 && DECL_CLASS_CONTEXT (old
) == current_class_type
)
2914 || ! TREE_PRIVATE (old
)))
2915 /* Should figure out access control more accurately. */
2917 cp_warning_at ("member `%#D' is shadowed", old
);
2918 cp_warning_at ("by member function `%#D'", *methods
);
2919 warning ("in this context");
2921 tmp
= build_tree_list (DECL_NAME (*methods
), *methods
);
2925 TREE_TYPE (tmp
) = unknown_type_node
;
2927 TREE_OVERLOADED (tmp
) = DECL_OVERLOADED (*methods
);
2929 TREE_NONLOCAL_FLAG (tmp
) = 1;
2931 /* Put the new contents in our envelope. */
2932 TREE_PURPOSE (class_value
) = tmp
;
2936 maybe_push_cache_obstack ();
2937 tmp
= build_tree_list (DECL_NAME (*methods
), *methods
);
2940 TREE_TYPE (tmp
) = unknown_type_node
;
2942 TREE_OVERLOADED (tmp
) = DECL_OVERLOADED (*methods
);
2944 TREE_NONLOCAL_FLAG (tmp
) = 1;
2946 /* See comment above for a description of envelopes. */
2947 closed_envelopes
= tree_cons (tmp
, class_value
,
2949 IDENTIFIER_CLASS_VALUE (DECL_NAME (*methods
)) = closed_envelopes
;
2955 DECL_PUBLIC (tmp
) = 0;
2956 DECL_PROTECTED (tmp
) = 0;
2957 DECL_PRIVATE (tmp
) = 0;
2958 tmp
= DECL_CHAIN (tmp
);
2965 SET_BINFO_MARKED (binfo
);
2968 /* Consolidate unique (by name) member functions. */
2970 dfs_compress_decls (binfo
)
2973 tree type
= BINFO_TYPE (binfo
);
2974 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
2976 if (method_vec
!= 0)
2978 /* Farm out constructors and destructors. */
2979 tree
*methods
= &TREE_VEC_ELT (method_vec
, 1);
2980 tree
*end
= TREE_VEC_END (method_vec
);
2982 for (; methods
!= end
; methods
++)
2984 /* This is known to be an envelope of the kind described before
2986 tree class_value
= IDENTIFIER_CLASS_VALUE (DECL_NAME (*methods
));
2987 tree tmp
= TREE_PURPOSE (class_value
);
2989 /* This was replaced in scope by somebody else. Just leave it
2991 if (TREE_CODE (tmp
) != TREE_LIST
)
2994 if (TREE_CHAIN (tmp
) == NULL_TREE
2996 && DECL_CHAIN (TREE_VALUE (tmp
)) == NULL_TREE
)
2998 TREE_PURPOSE (class_value
) = TREE_VALUE (tmp
);
3002 CLEAR_BINFO_MARKED (binfo
);
3005 /* When entering the scope of a class, we cache all of the
3006 fields that that class provides within its inheritance
3007 lattice. Where ambiguities result, we mark them
3008 with `error_mark_node' so that if they are encountered
3009 without explicit qualification, we can emit an error
3012 push_class_decls (type
)
3016 struct obstack
*ambient_obstack
= current_obstack
;
3019 tree tags
= CLASSTYPE_TAGS (type
);
3023 tree code_type_node
;
3026 switch (TREE_CODE (TREE_VALUE (tags
)))
3029 code_type_node
= enum_type_node
;
3032 code_type_node
= record_type_node
;
3035 code_type_node
= class_type_node
;
3038 code_type_node
= union_type_node
;
3041 my_friendly_abort (297);
3043 tag
= xref_tag (code_type_node
, TREE_PURPOSE (tags
),
3044 TYPE_BINFO_BASETYPE (TREE_VALUE (tags
), 0), 0);
3045 #if 0 /* not yet, should get fixed properly later */
3046 pushdecl (make_type_decl (TREE_PURPOSE (tags
), TREE_VALUE (tags
)));
3048 pushdecl (build_decl (TYPE_DECL
, TREE_PURPOSE (tags
), TREE_VALUE (tags
)));
3053 search_stack
= push_search_level (search_stack
, &search_obstack
);
3055 id
= TYPE_IDENTIFIER (type
);
3057 if (IDENTIFIER_TEMPLATE (id
) != 0)
3059 tree tmpl
= IDENTIFIER_TEMPLATE (id
);
3060 push_template_decls (DECL_ARGUMENTS (TREE_PURPOSE (tmpl
)),
3061 TREE_VALUE (tmpl
), 1);
3062 overload_template_name (id
, 1);
3066 /* Push class fields into CLASS_VALUE scope, and mark. */
3067 dfs_walk (TYPE_BINFO (type
), dfs_pushdecls
, unmarkedp
);
3069 /* Compress fields which have only a single entry
3070 by a given name, and unmark. */
3071 dfs_walk (TYPE_BINFO (type
), dfs_compress_decls
, markedp
);
3073 /* Open up all the closed envelopes and push the contained decls into
3075 while (closed_envelopes
)
3077 tree
new = TREE_PURPOSE (closed_envelopes
);
3080 /* This is messy because the class value may be a *_DECL, or a
3081 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3082 *_DECLs. The name is stored at different places in these three
3084 if (TREE_CODE (new) == TREE_LIST
)
3086 if (TREE_PURPOSE (new) != NULL_TREE
)
3087 id
= TREE_PURPOSE (new);
3090 tree node
= TREE_VALUE (new);
3092 while (TREE_CODE (node
) == TREE_LIST
)
3093 node
= TREE_VALUE (node
);
3094 id
= DECL_NAME (node
);
3098 id
= DECL_NAME (new);
3100 /* Install the original class value in order to make
3101 pushdecl_class_level work correctly. */
3102 IDENTIFIER_CLASS_VALUE (id
) = TREE_VALUE (closed_envelopes
);
3103 if (TREE_CODE (new) == TREE_LIST
)
3104 push_class_level_binding (id
, new);
3106 pushdecl_class_level (new);
3107 closed_envelopes
= TREE_CHAIN (closed_envelopes
);
3109 current_obstack
= ambient_obstack
;
3112 /* Here's a subroutine we need because C lacks lambdas. */
3114 dfs_unuse_fields (binfo
)
3117 tree type
= TREE_TYPE (binfo
);
3120 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3122 if (TREE_CODE (fields
) != FIELD_DECL
)
3125 TREE_USED (fields
) = 0;
3126 if (DECL_NAME (fields
) == NULL_TREE
3127 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3128 unuse_fields (TREE_TYPE (fields
));
3136 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
);
3140 pop_class_decls (type
)
3143 /* We haven't pushed a search level when dealing with cached classes,
3144 so we'd better not try to pop it. */
3146 search_stack
= pop_search_level (search_stack
);
3150 print_search_statistics ()
3152 #ifdef GATHER_STATISTICS
3153 if (flag_memoize_lookups
)
3155 fprintf (stderr
, "%d memoized contexts saved\n",
3157 fprintf (stderr
, "%d local tree nodes made\n", my_tree_node_counter
);
3158 fprintf (stderr
, "%d local hash nodes made\n", my_memoized_entry_counter
);
3159 fprintf (stderr
, "fields statistics:\n");
3160 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3161 memoized_fast_finds
[0], memoized_fast_rejects
[0],
3162 memoized_fields_searched
[0]);
3163 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[0]);
3164 fprintf (stderr
, "fnfields statistics:\n");
3165 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3166 memoized_fast_finds
[1], memoized_fast_rejects
[1],
3167 memoized_fields_searched
[1]);
3168 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[1]);
3170 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3171 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3172 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3173 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3174 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3176 fprintf (stderr
, "no search statistics\n");
3181 init_search_processing ()
3183 gcc_obstack_init (&search_obstack
);
3184 gcc_obstack_init (&type_obstack
);
3185 gcc_obstack_init (&type_obstack_entries
);
3187 /* This gives us room to build our chains of basetypes,
3188 whether or not we decide to memoize them. */
3189 type_stack
= push_type_level (0, &type_obstack
);
3190 _vptr_name
= get_identifier ("_vptr");
3194 reinit_search_statistics ()
3196 my_memoized_entry_counter
= 0;
3197 memoized_fast_finds
[0] = 0;
3198 memoized_fast_finds
[1] = 0;
3199 memoized_adds
[0] = 0;
3200 memoized_adds
[1] = 0;
3201 memoized_fast_rejects
[0] = 0;
3202 memoized_fast_rejects
[1] = 0;
3203 memoized_fields_searched
[0] = 0;
3204 memoized_fields_searched
[1] = 0;
3205 n_fields_searched
= 0;
3206 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3207 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3208 n_calls_get_base_type
= 0;
3209 n_outer_fields_searched
= 0;
3210 n_contexts_saved
= 0;