1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@mcc.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 1, 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. */
23 /* High-level class interface. */
27 #include "cplus-tree.h"
33 /* For expand_asm_operands. */
34 extern char *input_filename
;
39 #define obstack_chunk_alloc xmalloc
40 #define obstack_chunk_free free
42 extern int xmalloc ();
46 extern struct obstack
*current_obstack
;
50 /* Obstack used for remembering decision points of breadth-first. */
51 static struct obstack search_obstack
;
53 /* Obstack used to bridge from one function context to another. */
54 static struct obstack bridge_obstack
;
56 /* Methods for pushing and popping objects to and from obstacks. */
59 push_stack_level (obstack
, tp
, size
)
60 struct obstack
*obstack
;
64 struct stack_level
*stack
;
65 stack
= (struct stack_level
*) obstack_next_free (obstack
);
66 obstack_grow (obstack
, tp
, size
);
67 obstack_finish (obstack
);
68 stack
->obstack
= obstack
;
69 stack
->first
= (tree
*) obstack_base (obstack
);
70 stack
->limit
= obstack_room (obstack
) / sizeof (tree
*);
75 pop_stack_level (stack
)
76 struct stack_level
*stack
;
78 struct stack_level
*tem
= stack
;
79 struct obstack
*obstack
= tem
->obstack
;
81 obstack_free (obstack
, tem
);
85 #define search_level stack_level
86 static struct search_level
*search_stack
;
88 static tree
lookup_field_1 ();
89 static int lookup_fnfields_1 ();
91 /* Allocate a level of searching. */
92 static struct search_level
*
93 push_search_level (stack
, obstack
)
94 struct stack_level
*stack
;
95 struct obstack
*obstack
;
97 struct search_level tem
;
100 return push_stack_level (obstack
, &tem
, sizeof (tem
));
103 /* Discard a level of search allocation. */
104 #define pop_search_level pop_stack_level
106 /* Search memoization. */
109 struct stack_level base
;
111 /* First object allocated in obstack of entries. */
114 /* Number of types memoized in this context. */
117 /* Type being memoized; save this if we are saving
118 memoized contexts. */
122 /* Obstack used for memoizing member and member function lookup. */
124 static struct obstack type_obstack
, type_obstack_entries
;
125 static struct type_level
*type_stack
;
126 static tree _vptr_name
;
128 /* Make things that look like tree nodes, but allocate them
129 on type_obstack_entries. */
130 static int my_tree_node_counter
;
131 static tree
my_tree_cons (), my_build_string ();
133 extern int flag_memoize_lookups
, flag_save_memoized_contexts
;
135 /* Variables for gathering statistics. */
136 static int my_memoized_entry_counter
;
137 static int memoized_fast_finds
[2], memoized_adds
[2], memoized_fast_rejects
[2];
138 static int memoized_fields_searched
[2];
139 static int n_fields_searched
;
140 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
141 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
142 static int n_calls_get_base_type
;
143 static int n_outer_fields_searched
;
144 static int n_contexts_saved
;
146 /* Local variables to help save memoization contexts. */
147 static tree prev_type_memoized
;
148 static struct type_level
*prev_type_stack
;
150 /* Allocate a level of type memoziation context. */
151 static struct type_level
*
152 push_type_level (stack
, obstack
)
153 struct stack_level
*stack
;
154 struct obstack
*obstack
;
156 struct type_level tem
;
158 tem
.base
.prev
= stack
;
160 obstack_finish (&type_obstack_entries
);
161 tem
.entries
= (char *) obstack_base (&type_obstack_entries
);
163 tem
.type
= NULL_TREE
;
165 return (struct type_level
*)push_stack_level (obstack
, &tem
, sizeof (tem
));
168 /* Discard a level of type memoziation context. */
170 static struct type_level
*
171 pop_type_level (stack
)
172 struct type_level
*stack
;
174 obstack_free (&type_obstack_entries
, stack
->entries
);
175 return (struct type_level
*)pop_stack_level (stack
);
178 /* Make something that looks like a TREE_LIST, but
179 do it on the type_obstack_entries obstack. */
181 my_tree_cons (purpose
, value
, chain
)
182 tree purpose
, value
, chain
;
184 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_list
));
185 TREE_UID (p
) = ++my_tree_node_counter
;
188 TREE_SET_CODE (p
, TREE_LIST
);
189 TREE_PURPOSE (p
) = purpose
;
190 TREE_VALUE (p
) = value
;
191 TREE_CHAIN (p
) = chain
;
196 my_build_string (str
)
199 tree p
= (tree
)obstack_alloc (&type_obstack_entries
, sizeof (struct tree_string
));
200 TREE_UID (p
) = ++my_tree_node_counter
;
203 TREE_SET_CODE (p
, STRING_CST
);
204 TREE_STRING_POINTER (p
) = str
;
205 TREE_STRING_LENGTH (p
) = strlen (str
);
213 struct obstack
*ambient_obstack
= current_obstack
;
216 current_obstack
= &type_obstack_entries
;
218 t
= copy_node (node
);
219 TREE_UID (t
) = ++my_tree_node_counter
;
221 current_obstack
= ambient_obstack
;
225 /* Memoizing machinery to make searches for multiple inheritance
226 reasonably efficient. */
227 #define MEMOIZE_HASHSIZE 8
228 typedef struct memoized_entry
230 struct memoized_entry
*chain
;
232 tree data_members
[MEMOIZE_HASHSIZE
];
233 tree function_members
[MEMOIZE_HASHSIZE
];
236 #define MEMOIZED_CHAIN(ENTRY) (((ME)ENTRY)->chain)
237 #define MEMOIZED_UID(ENTRY) (((ME)ENTRY)->uid)
238 #define MEMOIZED_FIELDS(ENTRY,INDEX) (((ME)ENTRY)->data_members[INDEX])
239 #define MEMOIZED_FNFIELDS(ENTRY,INDEX) (((ME)ENTRY)->function_members[INDEX])
240 #define MEMOIZED_HASH_FN(NODE) (TREE_UID (NODE)&(MEMOIZE_HASHSIZE - 1))
242 static struct memoized_entry
*
243 my_new_memoized_entry (chain
)
244 struct memoized_entry
*chain
;
246 struct memoized_entry
*p
=
247 (struct memoized_entry
*)obstack_alloc (&type_obstack_entries
,
248 sizeof (struct memoized_entry
));
249 bzero (p
, sizeof (struct memoized_entry
));
250 MEMOIZED_CHAIN (p
) = chain
;
251 MEMOIZED_UID (p
) = ++my_memoized_entry_counter
;
255 /* When a new function or class context is entered, we build
256 a table of types which have been searched for members.
257 The table is an array (obstack) of types. When a type is
258 entered into the obstack, its CLASSTYPE_MTABLE_ENTRY
259 field is set to point to a new record, of type struct memoized_entry.
261 A non-NULL TREE_TYPE of the entry contains a visibility error message.
263 The slots for the data members are arrays of tree nodes.
264 These tree nodes are lists, with the TREE_PURPOSE
265 of this list the known member name, and the TREE_VALUE
266 as the FIELD_DECL for the member.
268 For member functions, the TREE_PURPOSE is again the
269 name of the member functions for that class,
270 and the TREE_VALUE of the list is a pairs
271 whose TREE_PURPOSE is a member functions of this name,
272 and whose TREE_VALUE is a list of known argument lists this
273 member function has been called with. The TREE_TYPE of the pair,
274 if non-NULL, is an error message to print. */
276 /* Tell search machinery that we are entering a new context, and
277 to update tables appropriately.
279 TYPE is the type of the context we are entering, which can
280 be NULL_TREE if we are not in a class's scope.
282 USE_OLD, if nonzero tries to use previous context. */
284 push_memoized_context (type
, use_old
)
293 if (use_old
&& prev_type_memoized
== type
)
295 #ifdef GATHER_STATISTICS
298 type_stack
= prev_type_stack
;
301 tem
= &type_stack
->base
.first
[0];
302 len
= type_stack
->len
;
304 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]) = tem
[len
*2+1];
307 /* Otherwise, need to pop old stack here. */
308 type_stack
= pop_type_level (prev_type_stack
);
309 prev_type_memoized
= 0;
313 type_stack
= push_type_level (type_stack
, &type_obstack
);
314 type_stack
->type
= type
;
317 /* Tell search machinery that we have left a context.
318 We do not currently save these contexts for later use.
319 If we wanted to, we could not use pop_search_level, since
320 poping that level allows the data we have collected to
321 be clobbered; a stack of obstacks would be needed. */
322 pop_memoized_context (use_old
)
326 tree
*tem
= &type_stack
->base
.first
[0];
328 if (! flag_save_memoized_contexts
)
332 len
= type_stack
->len
;
334 tem
[len
*2+1] = (tree
)CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]);
336 prev_type_stack
= type_stack
;
337 prev_type_memoized
= type_stack
->type
;
340 if (flag_memoize_lookups
)
342 len
= type_stack
->len
;
344 CLASSTYPE_MTABLE_ENTRY (tem
[len
*2])
345 = MEMOIZED_CHAIN (CLASSTYPE_MTABLE_ENTRY (tem
[len
*2]));
348 type_stack
= pop_type_level (type_stack
);
350 type_stack
= (struct type_level
*)type_stack
->base
.prev
;
353 /* Some simple list processing predicates. */
355 /* Check whether TYPE is immediately derived from PARENT.
356 Return actual base information if so. Otherwise, return 0. */
358 get_base_type_1 (parent
, type
)
359 register tree parent
, type
;
363 parent
= TYPE_MAIN_VARIANT (parent
);
364 type
= TYPE_MAIN_VARIANT (type
);
366 for (i
= 1; i
<= CLASSTYPE_N_BASECLASSES (type
); i
++)
367 if (TYPE_MAIN_VARIANT (CLASSTYPE_BASECLASS (type
, i
)) == parent
)
368 return CLASSTYPE_BASECLASS (type
, i
);
373 /* Check whether TYPE is derived from PARENT.
374 Return the actual base information if so. Otherwise return 0.
375 If PROTECT is 1, then emit an error message if access to
376 a public field of PARENT would be private.
377 If PROTECT is 2, then emit an error message if
378 TYPE is derived from PARENT via private visibility rules.
379 If PROTECT is 3, then immediately private baseclass is ok,
380 but deeper than that, if private, emit error message. */
382 get_base_type (parent
, type
, protect
)
383 register tree parent
, type
;
387 int head
= 0, tail
= 0;
389 tree rval
= NULL_TREE
;
390 int rval_private
= 0;
391 tree friends
= current_class_type
392 ? CLASSTYPE_FRIEND_CLASSES (type
) : NULL_TREE
;
394 #ifdef GATHER_STATISTICS
395 n_calls_get_base_type
++;
398 parent
= TYPE_MAIN_VARIANT (parent
);
399 search_stack
= push_search_level (search_stack
, &search_obstack
);
403 int i
, n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
405 /* Process and/or queue base types. */
406 for (i
= 1; i
<= n_baselinks
; i
++)
407 if (CLASSTYPE_MARKED5 (CLASSTYPE_BASECLASS (type
, i
)) == 0)
409 int via_private
= is_private
|| !CLASSTYPE_VIA_PUBLIC (type
, i
);
411 if (via_private
== 0)
413 else if (protect
== 0)
415 else if (protect
== 1 && type
== current_class_type
)
416 /* The immediate base class of the class we are in
417 does let its public members through. */
421 && friends
!= NULL_TREE
423 && value_member (current_class_type
, friends
))
424 /* Friend types of the most derived type have access
425 to its baseclass pointers. */
429 CLASSTYPE_MARKED5 (CLASSTYPE_BASECLASS (type
, i
)) = 1;
431 obstack_ptr_grow (&search_obstack
, CLASSTYPE_BASECLASS (type
, i
));
432 obstack_int_grow (&search_obstack
, via_private
);
434 if (tail
>= search_stack
->limit
)
437 else if (protect
&& ! CLASSTYPE_VIA_VIRTUAL (type
, i
))
439 error_with_aggr_type (parent
, "type `%s' is ambiguous base class for type `%s'",
440 TYPE_NAME_STRING (xtype
));
441 error ("(base class for types `%s' and `%s')",
442 TYPE_NAME_STRING (type
),
443 TYPE_NAME_STRING (otype
));
444 rval
= error_mark_node
;
449 /* Process head of queue, if one exists. */
453 type
= search_stack
->first
[head
++];
454 is_private
= (int)search_stack
->first
[head
++];
455 if (TYPE_MAIN_VARIANT (type
) == parent
)
460 rval_private
= is_private
;
466 tree
*tp
= search_stack
->first
;
467 tree
*search_tail
= tp
+ tail
;
469 while (tp
< search_tail
)
471 CLASSTYPE_MARKED5 (*tp
) = 0;
475 search_stack
= pop_search_level (search_stack
);
477 if (rval
== error_mark_node
)
478 return error_mark_node
;
480 if (rval
&& protect
&& rval_private
)
486 for (i
= 1; i
<= CLASSTYPE_N_BASECLASSES (xtype
); i
++)
487 if (parent
== TYPE_MAIN_VARIANT (CLASSTYPE_BASECLASS (xtype
, i
)))
488 /* It's ok, since it's immedate. */
491 error ("type `%s' is derived from private `%s'",
492 TYPE_NAME_STRING (xtype
),
493 TYPE_NAME_STRING (parent
));
494 return error_mark_node
;
500 /* Return the number of levels between type PARENT and type TYPE,
501 following the leftmost path to PARENT. If PARENT is its own main
502 type variant, then if PARENT appears in different places from TYPE's
503 point of view, the leftmost PARENT will be the one chosen.
505 Return -1 if TYPE is not derived from PARENT.
506 Return -2 if PARENT is an ambiguous base class of TYPE.
507 Return -3 if PARENT is private to TYPE, and protect is non-zero.
509 If PATH_PTR is non-NULL, then also build the list of types
510 from PARENT to TYPE, with TREE_VIA_VIRUAL and TREE_VIA_PUBLIC
512 get_base_distance (parent
, type
, protect
, path_ptr
)
513 register tree parent
, type
;
517 int head
= 0, tail
= 0;
521 int rval_private
= 0;
523 tree friends
= current_class_type
524 ? CLASSTYPE_FRIEND_CLASSES (type
) : NULL_TREE
;
527 if (TREE_READONLY (parent
) || TREE_VOLATILE (parent
))
528 parent
= TYPE_MAIN_VARIANT (parent
);
529 use_leftmost
= (parent
== TYPE_MAIN_VARIANT (parent
));
532 basetypes
= CLASSTYPE_AS_LIST (type
);
534 if (TYPE_MAIN_VARIANT (parent
) == type
)
536 /* If the distance is 0, then we don't really need
537 a path pointer, but we shouldn't let garbage go back. */
539 *path_ptr
= basetypes
;
543 search_stack
= push_search_level (search_stack
, &search_obstack
);
547 int i
, n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
549 /* Process and/or queue base types. */
550 for (i
= 1; i
<= n_baselinks
; i
++)
551 if (CLASSTYPE_MARKED5 (CLASSTYPE_BASECLASS (type
, i
)) == 0)
555 int via_private
= is_private
|| !CLASSTYPE_VIA_PUBLIC (type
, i
);
557 if (via_private
== 0)
559 else if (protect
== 0)
562 /* 13 Jan, 1990: I guess this is turned off because
563 `get_base_type' will emit a more eloquent message
564 if a message desired [--Michael]. */
565 /* The immediate base class of the class we are in
566 does let its public members through. */
567 else if (type
== current_class_type
)
570 && friends
!= NULL_TREE
572 && value_member (current_class_type
, friends
))
573 /* Friend types of the most derived type have access
574 to its baseclass pointers. */
578 CLASSTYPE_MARKED5 (CLASSTYPE_BASECLASS (type
, i
)) = 1;
579 obstack_ptr_grow (&search_obstack
, CLASSTYPE_BASECLASS (type
, i
));
581 obstack_ptr_grow (&search_obstack
, depth
);
582 obstack_int_grow (&search_obstack
, via_private
);
585 btypes
= tree_cons (NULL_TREE
, CLASSTYPE_BASECLASS (type
, i
),
587 TREE_VIA_PUBLIC (btypes
) = CLASSTYPE_VIA_PUBLIC (type
, i
);
588 TREE_VIA_VIRTUAL (btypes
) = CLASSTYPE_VIA_VIRTUAL (type
, i
);
589 obstack_ptr_grow (&search_obstack
, btypes
);
593 if (tail
>= search_stack
->limit
)
596 else if (! CLASSTYPE_VIA_VIRTUAL (type
, i
))
602 /* Process head of queue, if one exists. */
609 type
= search_stack
->first
[head
++];
610 depth
= (int)search_stack
->first
[head
++] + 1;
611 is_private
= (int)search_stack
->first
[head
++];
613 basetypes
= search_stack
->first
[head
++];
615 || (use_leftmost
&& TYPE_MAIN_VARIANT (type
) == parent
))
618 rval_private
= is_private
;
624 tree
*tp
= search_stack
->first
;
625 tree
*search_tail
= tp
+ tail
;
626 int increment
= path_ptr
? 4 : 3;
628 while (tp
< search_tail
)
630 CLASSTYPE_MARKED5 (*tp
) = 0;
634 /* Now, guarantee that we are following the leftmost
635 path in the chain. */
638 && (DECL_OFFSET (TYPE_NAME (type
)) != 0
639 || TREE_VIA_VIRTUAL (type
)))
641 /* Reduce all types yet to be fully processed into
642 the base type we are looking for, or NULL_TREE. */
643 for (tp
= search_stack
->first
; tp
< search_tail
; tp
+= increment
)
645 tree
*sub_tp
, sub_path_ptr
;
648 /* Don't chase down more right-most paths. */
649 if (TREE_VIA_VIRTUAL (*tp
)
650 || DECL_OFFSET (TYPE_NAME (*tp
)) > DECL_OFFSET (TYPE_NAME (type
)))
656 /* Don't hassle with duplicates. */
660 for (sub_tp
= search_stack
->first
; sub_tp
< tp
; sub_tp
+= increment
)
664 /* Find this type's TYPE basetype, if it has one. */
665 sub_rval
= get_base_distance (parent
, *tp
, 0, &sub_path_ptr
);
670 if (path_ptr
&& TREE_CHAIN (tp
[3]))
673 tree next_to_last
= sub_path_ptr
;
674 while (TREE_CHAIN (next_to_last
)
675 && TREE_CHAIN (TREE_CHAIN (next_to_last
)))
676 next_to_last
= TREE_CHAIN (next_to_last
);
677 if (next_to_last
== sub_path_ptr
)
679 sub_path_ptr
= copy_node (sub_path_ptr
);
684 last
= copy_node (TREE_CHAIN (next_to_last
));
685 TREE_CHAIN (next_to_last
) = last
;
687 TREE_CHAIN (last
) = TREE_CHAIN (tp
[3]);
689 *tp
= TREE_VALUE (sub_path_ptr
);
691 tp
[3] = sub_path_ptr
;
696 /* For all the types which reduce to TYPE, choose
697 the leftmost non-virtual one of them. */
698 for (tp
= search_stack
->first
; tp
< search_tail
; tp
+= increment
)
700 if (*tp
== NULL_TREE
)
703 if (DECL_OFFSET (TYPE_NAME (*tp
)) < DECL_OFFSET (TYPE_NAME (type
)))
715 search_stack
= pop_search_level (search_stack
);
717 if (rval
&& protect
&& rval_private
)
721 *path_ptr
= basetypes
;
725 /* Search for a member with name NAME in a multiple inheritance lattice
726 specified by TYPE. If it does not exist, return NULL_TREE.
727 If the member is ambiguously referenced, return `error_mark_node'.
728 Otherwise, return the FIELD_DECL. */
730 /* Do a 1-level search for NAME as a member of TYPE. The caller
731 must figure out whether it has a visible path to this field.
732 (Since it is only one level, this is reasonable.) */
734 lookup_field_1 (type
, name
)
737 register tree field
= TYPE_FIELDS (type
);
739 #ifdef GATHER_STATISTICS
740 n_calls_lookup_field_1
++;
744 #ifdef GATHER_STATISTICS
747 if (DECL_ANON_UNION_ELEM (field
))
749 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
753 if (DECL_NAME (field
) == name
)
755 field
= TREE_CHAIN (field
);
758 if (name
== _vptr_name
)
760 /* Give the user what s/he thinks s/he wants. */
761 if (TYPE_VIRTUAL_P (type
))
762 return CLASSTYPE_VFIELD (type
);
767 /* Compute the visibility of FIELD. This is done by computing
768 the visibility available to each type in BASETYPES (which comes
769 as a list of [via_public/basetype] in reverse order, namely base
770 class before derived class). The first one which defines a
771 visibility defines the visibility for the field. Otherwise, the
772 visibility of the field is that which occurs normally.
774 Uses global variables CURRENT_CLASS_TYPE and
775 CURRENT_FUNCTION_DECL to use friend relationships
778 This will be static when lookup_fnfield comes into this file. */
780 #define PUBLIC_RETURN do { TREE_FIELD_PUBLIC (field) = 1; return visibility_public; } while (0)
781 #define PROTECTED_RETURN do { TREE_FIELD_PROTECTED (field) = 1; return visibility_protected; } while (0)
782 #define PRIVATE_RETURN do { TREE_FIELD_PRIVATE (field) = 1; return visibility_private; } while (0)
785 compute_visibility (basetypes
, field
)
786 tree basetypes
, field
;
788 enum visibility_type visibility
= visibility_public
;
790 tree context
= DECL_FIELD_CONTEXT (field
);
792 /* Virtual function tables are never private.
793 But we should know that we are looking for this,
794 and not even try to hide it. */
795 if (VFIELD_NAME_P (DECL_NAME (field
)) == 1)
796 return visibility_public
;
798 /* Make these special cases fast. */
799 if (TREE_VALUE (basetypes
) == current_class_type
)
801 if (TREE_FIELD_PUBLIC (field
))
802 return visibility_public
;
803 if (TREE_FIELD_PROTECTED (field
))
804 return visibility_protected
;
805 if (TREE_FIELD_PRIVATE (field
))
806 return visibility_private
;
809 /* Member function manipulating its own members. */
810 if (current_class_type
== context
)
813 /* Member found immediately within object. */
814 if (TREE_CHAIN (basetypes
) == NULL_TREE
)
816 /* At object's top level, public members are public. */
817 if (TREE_PROTECTED (field
) == 0 && TREE_PRIVATE (field
) == 0)
820 /* Friend function manipulating members it gets (for being a friend). */
821 if (is_friend (context
, current_function_decl
))
824 /* Inner than that, without special visibility,
826 protected members are ok if type of object is current_class_type
827 is derived therefrom. This means that if the type of the object
828 is a base type for our current class type, we cannot access
831 private members are not ok. */
832 if (current_class_type
&& DECL_VISIBILITY (field
) == NULL_TREE
)
834 if (TREE_PRIVATE (field
))
837 if (TREE_PROTECTED (field
))
839 if (context
== current_class_type
840 || (type
= get_base_type (current_class_type
, context
, 0)))
848 /* Friend function manipulating members it gets (for being a friend). */
849 if (is_friend (context
, current_function_decl
))
852 /* must reverse more than one element */
853 basetypes
= nreverse (basetypes
);
860 type
= TYPE_MAIN_VARIANT (TREE_VALUE (types
));
862 member
= purpose_member (type
, DECL_VISIBILITY (field
));
865 visibility
= (enum visibility_type
)TREE_VALUE (member
);
866 if (visibility
== visibility_public
867 || is_friend (type
, current_function_decl
)
868 || (visibility
== visibility_protected
869 && current_class_type
870 && get_base_type (context
, current_class_type
, 0)))
871 visibility
= visibility_public
;
875 /* Friends inherit the visibility of the class they inherit from. */
876 if (is_friend (type
, current_function_decl
))
880 visibility
= visibility_public
;
883 if (TREE_PROTECTED (field
))
885 visibility
= visibility_public
;
889 /* This short-cut is too short. */
890 if (visibility
== visibility_public
)
893 /* else, may be a friend of a deeper base class */
899 types
= TREE_CHAIN (types
);
900 /* If the next type was not VIA_PUBLIC, then fields of all
901 remaining class past that one are private. */
902 if (types
&& ! TREE_VIA_PUBLIC (types
))
903 visibility
= visibility_private
;
906 /* No special visibilities apply. Use normal rules.
907 No assignment needed for BASETYPEs here from the nreverse.
908 This is because we use it only for information about the
909 path to the base. The code earlier dealt with what
910 happens when we are at the base level. */
912 if (visibility
== visibility_public
)
914 basetypes
= nreverse (basetypes
);
915 if (TREE_PRIVATE (field
))
917 if (TREE_PROTECTED (field
))
919 /* Used to check if the current class type was derived from
920 the type that contains the field. This is wrong for
921 multiple inheritance because is gives one class reference
922 to protected members via another classes protected path.
923 I.e., if A; B1 : A; B2 : A; Then B1 and B2 can access
924 their own members which are protected in A, but not
925 those same members in one another. */
929 && get_base_type (context
, current_class_type
, 0)
932 && value_member (current_class_type
, basetypes
)
941 if (visibility
== visibility_private
942 && current_class_type
!= NULL_TREE
)
944 if (TREE_PRIVATE (field
))
946 nreverse (basetypes
);
950 /* See if the field isn't protected. */
951 if (TREE_PROTECTED (field
))
955 test
= get_base_type (type
, current_class_type
, 0);
957 test
= value_member (current_class_type
, basetypes
);
959 nreverse (basetypes
);
965 /* See if the field isn't a public member of
966 a private base class. */
968 visibility
= visibility_public
;
969 types
= TREE_CHAIN (basetypes
);
972 if (! TREE_VIA_PUBLIC (types
))
974 if (visibility
== visibility_private
)
976 visibility
= visibility_private
;
979 visibility
= visibility_private
;
981 if (TYPE_MAIN_VARIANT (TREE_VALUE (types
)) == context
)
983 visibility
= visibility_public
;
986 types
= TREE_CHAIN (types
);
992 nreverse (basetypes
);
994 if (visibility
== visibility_public
)
995 TREE_FIELD_PUBLIC (field
) = 1;
996 else if (visibility
== visibility_protected
)
997 TREE_FIELD_PROTECTED (field
) = 1;
998 else if (visibility
== visibility_private
)
999 TREE_FIELD_PRIVATE (field
) = 1;
1004 /* Make an entry in the memoized table for type TYPE
1005 that the entry for NAME is FIELD. */
1008 make_memoized_table_entry (type
, name
, function_p
)
1012 int index
= MEMOIZED_HASH_FN (name
);
1013 tree entry
, *prev_entry
;
1015 memoized_adds
[function_p
] += 1;
1016 if (CLASSTYPE_MTABLE_ENTRY (type
) == NULL_TREE
)
1018 obstack_ptr_grow (&type_obstack
, type
);
1019 obstack_blank (&type_obstack
, sizeof (struct memoized_entry
*));
1020 CLASSTYPE_MTABLE_ENTRY (type
) = my_new_memoized_entry (0);
1022 if (type_stack
->len
* 2 >= type_stack
->base
.limit
)
1026 prev_entry
= &MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type
), index
);
1028 prev_entry
= &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type
), index
);
1030 entry
= my_tree_cons (name
, 0, *prev_entry
);
1031 *prev_entry
= entry
;
1033 /* Don't know the error message to give yet. */
1034 TREE_TYPE (entry
) = error_mark_node
;
1040 lookup_field (xbasetype
, name
, protect
)
1041 register tree xbasetype
, name
;
1044 int head
= 0, tail
= 0;
1046 tree basetype
, basetypes
;
1047 enum visibility_type this_v
= visibility_default
;
1049 enum visibility_type own_visibility
= visibility_default
;
1050 int vbase_name_p
= VBASE_NAME_P (name
);
1052 /* Things for memoization. */
1055 /* Set this to nonzero if we don't know how to compute
1056 accurate error messages for visibility. */
1057 int index
= MEMOIZED_HASH_FN (name
);
1059 if (TREE_CODE (xbasetype
) == TREE_LIST
)
1060 basetypes
= xbasetype
, basetype
= TREE_VALUE (xbasetype
);
1062 basetypes
= CLASSTYPE_AS_LIST (xbasetype
), basetype
= xbasetype
;
1064 if (CLASSTYPE_MTABLE_ENTRY (basetype
))
1066 tree tem
= MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (basetype
), index
);
1068 while (tem
&& TREE_PURPOSE (tem
) != name
)
1070 memoized_fields_searched
[0]++;
1071 tem
= TREE_CHAIN (tem
);
1075 if (protect
&& TREE_TYPE (tem
))
1077 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1078 IDENTIFIER_POINTER (name
),
1079 TYPE_NAME_STRING (DECL_FIELD_CONTEXT (TREE_VALUE (tem
))));
1080 return error_mark_node
;
1082 if (TREE_VALUE (tem
) == NULL_TREE
)
1083 memoized_fast_rejects
[0] += 1;
1085 memoized_fast_finds
[0] += 1;
1086 return TREE_VALUE (tem
);
1090 #ifdef GATHER_STATISTICS
1091 n_calls_lookup_field
++;
1093 if (flag_memoize_lookups
&& ! global_bindings_p ())
1094 entry
= make_memoized_table_entry (basetype
, name
, 0);
1098 rval
= lookup_field_1 (basetype
, name
);
1102 if (flag_memoize_lookups
|| protect
)
1104 if (TREE_PRIVATE (rval
) | TREE_PROTECTED (rval
))
1105 this_v
= compute_visibility (basetypes
, rval
);
1106 if (TREE_CODE (rval
) == CONST_DECL
)
1108 if (this_v
== visibility_private
)
1109 errstr
= "enum `%s' is a private value of class `%s'";
1110 else if (this_v
== visibility_protected
)
1111 errstr
= "enum `%s' is a protected value of class `%s'";
1115 if (this_v
== visibility_private
)
1116 errstr
= "member `%s' is a private member of class `%s'";
1117 else if (this_v
== visibility_protected
)
1118 errstr
= "member `%s' is a protected member of class `%s'";
1126 /* This depends on behavior of lookup_field_1! */
1127 tree error_string
= my_build_string (errstr
);
1128 TREE_TYPE (entry
) = error_string
;
1132 /* Let entry know there is no problem with this access. */
1133 TREE_TYPE (entry
) = NULL_TREE
;
1135 /* And since everything is ok, bear the
1136 cost of generating correct code. */
1137 if (DECL_OFFSET (TYPE_NAME (basetype
)) != 0
1138 || TREE_VIA_VIRTUAL (basetype
))
1140 rval
= my_copy_node (rval
);
1141 DECL_FIELD_CONTEXT (rval
) = basetype
;
1145 TREE_VALUE (entry
) = rval
;
1148 else if ((DECL_OFFSET (TYPE_NAME (basetype
)) != 0
1149 || TREE_VIA_VIRTUAL (basetype
))
1150 && ! (errstr
&& protect
))
1152 rval
= my_copy_node (rval
);
1153 DECL_FIELD_CONTEXT (rval
) = basetype
;
1157 if (errstr
&& protect
)
1159 error (errstr
, IDENTIFIER_POINTER (name
), TYPE_NAME_STRING (basetype
));
1160 return error_mark_node
;
1165 type
= TYPE_MAIN_VARIANT (basetype
);
1167 search_stack
= push_search_level (search_stack
, &search_obstack
);
1168 TREE_VIA_PUBLIC (basetypes
) = 1;
1172 int i
, n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
1174 /* Process and/or queue base types. */
1175 for (i
= 1; i
<= n_baselinks
; i
++)
1177 if (CLASSTYPE_MARKED2 (CLASSTYPE_BASECLASS (type
, i
)) == 0)
1181 CLASSTYPE_MARKED2 (CLASSTYPE_BASECLASS (type
, i
)) = 1;
1182 btypes
= my_tree_cons (NULL_TREE
, CLASSTYPE_BASECLASS (type
, i
),
1184 TREE_VIA_PUBLIC (btypes
) = CLASSTYPE_VIA_PUBLIC (type
, i
);
1185 TREE_VIA_VIRTUAL (btypes
) = CLASSTYPE_VIA_VIRTUAL (type
, i
);
1186 obstack_ptr_grow (&search_obstack
, btypes
);
1188 if (tail
>= search_stack
->limit
)
1193 /* Process head of queue, if one exists. */
1197 basetypes
= search_stack
->first
[head
++];
1198 type
= TREE_VALUE (basetypes
);
1200 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1201 and we do find NAME in TYPE, verify that such a second
1202 sighting is in fact legal. */
1206 /* Just another way of finding the same member. */
1207 if (DECL_FIELD_CONTEXT (rval
) == type
)
1209 enum visibility_type new_v
1210 = compute_visibility (basetypes
, rval
);
1211 if (this_v
!= new_v
)
1212 errstr
= "conflicting visibilities to member `%s'";
1214 /* Same baseclass, different places in the lattice. */
1215 else if (DECL_FIELD_CONTEXT (rval
) == TYPE_MAIN_VARIANT (type
))
1216 errstr
= "member `%s' belongs to distinct base classes `%s'";
1219 tree nval
= lookup_field_1 (type
, name
);
1221 if (nval
&& get_base_type (type
, DECL_FIELD_CONTEXT (rval
), 0) == 0)
1223 /* We found it in other than a baseclass of RVAL's. */
1224 errstr
= "request for member `%s' is ambiguous";
1227 if (errstr
&& entry
)
1229 tree error_string
= my_build_string (errstr
);
1230 TREE_TYPE (entry
) = error_string
;
1232 if (errstr
&& protect
)
1237 rval
= lookup_field_1 (type
, name
);
1241 if (DECL_OFFSET (TYPE_NAME (type
)) != 0
1242 || TREE_VIA_VIRTUAL (type
))
1244 rval
= my_copy_node (rval
);
1245 DECL_FIELD_CONTEXT (rval
) = type
;
1249 if (entry
|| protect
)
1250 this_v
= compute_visibility (basetypes
, rval
);
1252 TREE_VALUE (entry
) = rval
;
1254 /* These may look ambiguous, but they really are not. */
1261 tree
*tp
= search_stack
->first
;
1262 tree
*search_tail
= tp
+ tail
;
1264 /* If this FIELD_DECL defines its own visibility, deal with that. */
1265 if (rval
&& errstr
== 0
1266 && DECL_VISIBILITY (rval
)
1267 && (protect
|| entry
))
1269 while (tp
< search_tail
)
1271 /* If is possible for one of the derived types on the
1272 path to have defined special visibility for this
1273 field. Look for such declarations and report an
1274 error if a conflict is found. */
1275 enum visibility_type new_v
;
1277 if (this_v
!= visibility_default
)
1278 new_v
= compute_visibility (*tp
, rval
);
1279 if (this_v
!= visibility_default
&& new_v
!= this_v
)
1281 errstr
= "conflicting visibilities to member `%s'";
1282 this_v
= visibility_default
;
1284 own_visibility
= new_v
;
1285 CLASSTYPE_MARKED2 (TREE_VALUE (*tp
++)) = 0;
1290 while (tp
< search_tail
)
1291 CLASSTYPE_MARKED2 (TREE_VALUE (*tp
++)) = 0;
1294 search_stack
= pop_search_level (search_stack
);
1298 if (own_visibility
== visibility_private
)
1299 errstr
= "member `%s' declared private";
1300 else if (own_visibility
== visibility_protected
)
1301 errstr
= "member `%s' declared protected";
1302 else if (this_v
== visibility_private
)
1303 errstr
= TREE_PRIVATE (rval
) ? "member `%s' is private" : "member `%s' is from private base class";
1304 else if (this_v
== visibility_protected
)
1305 errstr
= "member `%s' is protected";
1312 tree error_string
= my_build_string (errstr
);
1313 /* Save error message with entry. */
1314 TREE_TYPE (entry
) = error_string
;
1318 /* Mark entry as having no error string. */
1319 TREE_TYPE (entry
) = NULL_TREE
;
1323 if (errstr
&& protect
)
1325 error (errstr
, IDENTIFIER_POINTER (name
), TYPE_NAME_STRING (type
));
1326 rval
= error_mark_node
;
1331 /* TYPE is a class type. Return the index of the fields within
1332 the method vector with name NAME, or -1 is no such field exists. */
1334 lookup_fnfields_1 (type
, name
)
1337 register tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1339 if (method_vec
!= 0)
1341 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1342 register tree
*end
= TREE_VEC_END (method_vec
);
1344 #ifdef GATHER_STATISTICS
1345 n_calls_lookup_fnfields_1
++;
1349 while (methods
!= end
)
1351 #ifdef GATHER_STATISTICS
1352 n_outer_fields_searched
++;
1354 if (DECL_ORIGINAL_NAME (*methods
) == name
)
1359 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1365 /* Given a list of member functions FIELDS (which are implicitly
1366 named TREE_PURPOSE (FIELDS), and come from base type
1367 DECL_FIELD_CONTEXT (TREE_VALUE (FIELDS))), attempt to find the
1368 actual method which can accept (using conversions) PARMS.
1369 The types of PARMS are already computed in PARMTYPES. */
1371 lookup_fnfield (fields
, parms
, parmtypes
)
1372 tree fields
, parms
, parmtypes
;
1377 /* Starting from BASETYPE, return a TREE_BASELINK-like object
1378 which gives the following information (in a list):
1380 TREE_TYPE: list of basetypes needed to get to...
1381 TREE_VALUE: list of all functions in of given type
1382 which have name NAME.
1384 No visibility information is computed by this function,
1385 other then to adorn the list of basetypes with
1388 If FIND_AMBIGUOUS is non-zero, then if we find two ways to get
1389 to the same member function, both those ways are found,
1390 and the caller must know what to do about this. */
1392 lookup_fnfields (basetypes
, name
, find_ambiguous
)
1393 tree basetypes
, name
;
1396 int head
= 0, tail
= 0;
1397 tree type
, rval
, rvals
= NULL_TREE
;
1401 /* For now, don't try this. */
1402 int protect
= find_ambiguous
;
1404 /* Things for memoization. */
1407 /* Set this to nonzero if we don't know how to compute
1408 accurate error messages for visibility. */
1409 int index
= MEMOIZED_HASH_FN (name
);
1411 basetype
= TREE_VALUE (basetypes
);
1413 if (CLASSTYPE_MTABLE_ENTRY (basetype
))
1415 tree tem
= MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (basetype
), index
);
1417 while (tem
&& TREE_PURPOSE (tem
) != name
)
1419 memoized_fields_searched
[1]++;
1420 tem
= TREE_CHAIN (tem
);
1424 if (protect
&& TREE_TYPE (tem
))
1426 error (TREE_STRING_POINTER (TREE_TYPE (tem
)),
1427 IDENTIFIER_POINTER (name
),
1428 TYPE_NAME_STRING (DECL_FIELD_CONTEXT (TREE_VALUE (TREE_VALUE (tem
)))));
1429 return error_mark_node
;
1431 if (TREE_VALUE (tem
) == NULL_TREE
)
1433 memoized_fast_rejects
[1] += 1;
1438 /* Want to return this, but we must make sure
1439 that visibility information is consistent. */
1440 tree baselink
= TREE_VALUE (tem
);
1441 tree memoized_basetypes
= TREE_PURPOSE (baselink
);
1442 tree these_basetypes
= basetypes
;
1443 while (memoized_basetypes
&& these_basetypes
)
1445 memoized_fields_searched
[1]++;
1446 if (TREE_VALUE (memoized_basetypes
) != TREE_VALUE (these_basetypes
))
1448 memoized_basetypes
= TREE_CHAIN (memoized_basetypes
);
1449 these_basetypes
= TREE_CHAIN (these_basetypes
);
1451 if (memoized_basetypes
== these_basetypes
)
1453 memoized_fast_finds
[1] += 1;
1454 return TREE_VALUE (tem
);
1456 /* else, we must re-find this field by hand. */
1457 baselink
= tree_cons (basetypes
, TREE_VALUE (baselink
), TREE_CHAIN (baselink
));
1463 #ifdef GATHER_STATISTICS
1464 n_calls_lookup_fnfields
++;
1466 if (flag_memoize_lookups
&& ! global_bindings_p ())
1467 entry
= make_memoized_table_entry (basetype
, name
, 1);
1471 index
= lookup_fnfields_1 (basetype
, name
);
1475 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (basetype
), index
);
1476 rvals
= my_tree_cons (basetypes
, rval
, NULL_TREE
);
1477 if (CLASSTYPE_BASELINK_VEC (basetype
))
1478 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (basetype
), index
);
1482 TREE_VALUE (entry
) = rvals
;
1483 TREE_TYPE (entry
) = NULL_TREE
;
1486 if (errstr
&& protect
)
1488 error (errstr
, IDENTIFIER_POINTER (name
), TYPE_NAME_STRING (basetype
));
1489 return error_mark_node
;
1494 type
= TYPE_MAIN_VARIANT (basetype
);
1496 search_stack
= push_search_level (search_stack
, &search_obstack
);
1497 TREE_VIA_PUBLIC (basetypes
) = 1;
1501 int i
, n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
1503 /* Process and/or queue base types. */
1504 for (i
= 1; i
<= n_baselinks
; i
++)
1506 if (CLASSTYPE_MARKED2 (CLASSTYPE_BASECLASS (type
, i
)) == 0)
1510 CLASSTYPE_MARKED2 (CLASSTYPE_BASECLASS (type
, i
)) = 1;
1511 btypes
= my_tree_cons (NULL_TREE
, CLASSTYPE_BASECLASS (type
, i
),
1513 TREE_VIA_PUBLIC (btypes
) = CLASSTYPE_VIA_PUBLIC (type
, i
);
1514 TREE_VIA_VIRTUAL (btypes
) = CLASSTYPE_VIA_VIRTUAL (type
, i
);
1515 obstack_ptr_grow (&search_obstack
, btypes
);
1517 if (tail
>= search_stack
->limit
)
1522 /* Process head of queue, if one exists. */
1526 basetypes
= search_stack
->first
[head
++];
1527 type
= TREE_VALUE (basetypes
);
1529 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1530 and we do find NAME in TYPE, verify that such a second
1531 sighting is in fact legal. */
1535 tree context
= DECL_FIELD_CONTEXT (rval
);
1536 /* Just another way of finding the same member. */
1537 if (context
== type
)
1539 /* Same baseclass, maybe different places in the lattice. */
1540 else if (context
== TYPE_MAIN_VARIANT (type
))
1542 if (TREE_VIA_VIRTUAL (TREE_PURPOSE (rvals
)))
1543 if (TREE_VIA_VIRTUAL (basetypes
))
1546 errstr
= "member `%s' belongs to virtual and non-virtual baseclasses `%s'";
1547 else if (TREE_VIA_VIRTUAL (basetypes
))
1548 errstr
= "member `%s' belongs to virtual and non-virtual baseclasses `%s'";
1550 errstr
= "member `%s' belongs to MI-distinct base classes `%s'";
1554 int index
= lookup_fnfields_1 (type
, name
);
1556 if (index
>= 0 && get_base_type (type
, context
, 0) == 0)
1558 /* We found it in other than a baseclass of RVAL's. */
1559 rvals
= my_tree_cons (basetypes
, TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), index
), rvals
);
1560 if (CLASSTYPE_BASELINK_VEC (type
))
1561 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), index
);
1564 if (errstr
&& entry
)
1566 tree error_string
= my_build_string (errstr
);
1567 TREE_TYPE (entry
) = error_string
;
1569 if (errstr
&& find_ambiguous
)
1571 rvals
= error_mark_node
;
1577 int index
= lookup_fnfields_1 (type
, name
);
1580 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), index
);
1581 rvals
= my_tree_cons (basetypes
, rval
, NULL_TREE
);
1582 if (CLASSTYPE_BASELINK_VEC (type
))
1583 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), index
);
1585 TREE_VALUE (entry
) = rvals
;
1592 tree
*tp
= search_stack
->first
;
1593 tree
*search_tail
= tp
+ tail
;
1595 while (tp
< search_tail
)
1596 CLASSTYPE_MARKED2 (TREE_VALUE (*tp
++)) = 0;
1598 search_stack
= pop_search_level (search_stack
);
1604 tree error_string
= my_build_string (errstr
);
1605 /* Save error message with entry. */
1606 TREE_TYPE (entry
) = error_string
;
1610 /* Mark entry as having no error string. */
1611 TREE_TYPE (entry
) = NULL_TREE
;
1615 if (errstr
&& protect
)
1617 error (errstr
, IDENTIFIER_POINTER (name
), TYPE_NAME_STRING (type
));
1618 rvals
= error_mark_node
;
1624 /* BREADTH-FIRST SEARCH ROUTINES. */
1626 /* Search a multiple inheritance hierarchy by breadth-first search.
1628 TYPE is an aggregate type, possibly in a multiple-inheritance hierarchy.
1629 TESTFN is a function, which, if true, means that our condition has been met,
1630 and its return value should be returned.
1631 QFN, if non-NULL, is a predicate dictating whether the type should
1635 breadth_first_search (type
, testfn
, qfn
)
1640 int head
= 0, tail
= 0;
1643 search_stack
= push_search_level (search_stack
, &search_obstack
);
1647 int n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
1650 /* Process and/or queue base types. */
1651 for (i
= 1; i
<= n_baselinks
; i
++)
1652 if (CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (type
, i
)) == 0
1653 && (qfn
== 0 || (*qfn
) (type
, i
)))
1655 CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (type
, i
)) = 1;
1656 obstack_ptr_grow (&search_obstack
, type
);
1657 obstack_int_grow (&search_obstack
, i
);
1659 if (tail
>= search_stack
->limit
)
1663 /* Process head of queue, if one exists. */
1670 type
= search_stack
->first
[head
++];
1671 i
= (int)search_stack
->first
[head
++];
1672 if (rval
= (*testfn
) (type
, i
))
1674 type
= CLASSTYPE_BASECLASS (type
, i
);
1677 tree
*tp
= search_stack
->first
;
1678 tree
*search_tail
= tp
+ tail
;
1679 while (tp
< search_tail
)
1682 int i
= (int)(*tp
++);
1683 CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (type
, i
)) = 0;
1687 search_stack
= pop_search_level (search_stack
);
1691 /* Functions to use in breadth first searches. */
1692 typedef tree (*pft
)();
1693 typedef int (*pfi
)();
1695 int tree_needs_constructor_p (type
, i
)
1698 tree basetype
= i
== 0 ? type
: CLASSTYPE_BASECLASS (type
, i
);
1699 return TYPE_NEEDS_CONSTRUCTOR (basetype
);
1702 static tree declarator
;
1705 get_virtuals_named_this (type
, i
)
1709 tree basetype
= i
== 0? type
: CLASSTYPE_BASECLASS (type
, i
);
1710 tree fields
= lookup_fnfields (CLASSTYPE_AS_LIST (basetype
), declarator
, 0);
1712 if (fields
== 0 || fields
== error_mark_node
)
1715 /* Get to the function decls, and return the first virtual function
1716 with this name, if there is one. */
1721 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= TREE_CHAIN (fndecl
))
1722 if (DECL_VIRTUAL_P (fndecl
))
1724 fields
= next_baselink (fields
);
1729 static tree
get_virtual_destructor (type
, i
)
1733 type
= i
== 0 ? type
: CLASSTYPE_BASECLASS (type
, i
);
1734 if (TYPE_HAS_DESTRUCTOR (type
)
1735 && DECL_VIRTUAL_P (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 0)))
1736 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 0);
1740 int tree_has_any_destructor_p (type
, i
)
1745 return TYPE_NEEDS_DESTRUCTOR (type
);
1746 return TYPE_NEEDS_DESTRUCTOR (CLASSTYPE_BASECLASS (type
, i
));
1749 /* Given a class type TYPE, and a function decl FNDECL,
1750 look for the first function the TYPE's heirarchy which
1751 FNDECL could match as a virtual function.
1753 DTORP is nonzero if we are looking for a destructor. Destructors
1754 need special treatment because they do not match by name. */
1756 get_first_matching_virtual (type
, fndecl
, dtorp
)
1760 tree tmp
= NULL_TREE
;
1762 /* Breadth first search routines start searching basetypes
1763 of TYPE, so we must perform first ply of search here. */
1766 if (tree_has_any_destructor_p (type
, 0))
1767 tmp
= get_virtual_destructor (type
, 0);
1772 tmp
= (tree
) breadth_first_search (type
,
1773 (pfi
) get_virtual_destructor
,
1774 tree_has_any_destructor_p
);
1779 tree drettype
, dtypes
, btypes
, instptr_type
;
1780 tree basetype
= TYPE_METHOD_BASETYPE (fndecl
);
1781 tree baselink
, best
= NULL_TREE
;
1782 tree name
= DECL_NAME (fndecl
);
1784 declarator
= DECL_ORIGINAL_NAME (fndecl
);
1785 if (DECL_VIRTUAL_P (declarator
) == 0)
1788 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
1789 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1790 if (DECL_STATIC_FUNCTION_P (fndecl
))
1791 instptr_type
= NULL_TREE
;
1793 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
1795 for (baselink
= get_virtuals_named_this (type
, 0);
1796 baselink
; baselink
= next_baselink (baselink
))
1798 for (tmp
= TREE_VALUE (baselink
); tmp
; tmp
= TREE_CHAIN (tmp
))
1800 if (! DECL_VIRTUAL_P (tmp
))
1803 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
1804 if (instptr_type
== NULL_TREE
1805 && compparms (TREE_CHAIN (btypes
), dtypes
, 1))
1806 /* Caller knows to give error in this case. */
1809 if ((TREE_READONLY (TREE_TYPE (TREE_VALUE (btypes
)))
1810 == TREE_READONLY (instptr_type
))
1811 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
), 1))
1813 if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
1814 && ! comptypes (TREE_TYPE (TREE_TYPE (tmp
)), drettype
, 1))
1816 error_with_decl (fndecl
, "conflicting return type specified for virtual function `%s'");
1817 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
1824 /* If this is ambiguous, we will warn about it later. */
1827 if (get_base_distance (TYPE_METHOD_BASETYPE (TREE_TYPE (best
)),
1828 TYPE_METHOD_BASETYPE (TREE_TYPE (tmp
)), 0, 0) > 0)
1835 if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
1836 && best
== NULL_TREE
&& warn_overloaded_virtual
)
1838 error_with_decl (fndecl
, "conficting specification deriving virtual function `%s'");
1839 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
1845 /* Return the list of virtual functions which are abstract in type TYPE.
1846 This information is cached, and so must be built on a
1847 non-temporary obstack. */
1849 get_abstract_virtuals (type
)
1852 /* For each layer of base class (i.e., the first base class, and each
1853 virtual base class from that one), modify the virtual function table
1854 of the derived class to contain the new virtual function.
1855 A class has as many vfields as it has virtual base classes (total). */
1856 tree vfields
, vbases
, base
, tmp
;
1857 tree vfield
= CLASSTYPE_VFIELD (type
);
1858 tree fcontext
= vfield
? DECL_FCONTEXT (vfield
) : NULL_TREE
;
1859 tree abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (type
);
1861 for (vfields
= CLASSTYPE_VFIELDS (type
); vfields
; vfields
= TREE_CHAIN (vfields
))
1865 /* Find the right base class for this derived class, call it BASE. */
1866 base
= TREE_VALUE (vfields
);
1870 /* We call this case NORMAL iff this virtual function table
1871 pointer field has its storage reserved in this class.
1872 This is normally the case without virtual baseclasses
1873 or off-center multiple baseclasses. */
1874 normal
= (base
== fcontext
1875 && (TREE_PURPOSE (vfields
) == NULL_TREE
1876 || ! TREE_VIA_VIRTUAL (TREE_PURPOSE (vfields
))));
1879 tmp
= TREE_CHAIN (CLASS_ASSOC_VIRTUALS (type
));
1882 tree assoc
= assoc_value (base
, type
);
1883 tmp
= TREE_CHAIN (ASSOC_VIRTUALS (assoc
));
1888 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (tmp
));
1889 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
1890 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
1891 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
1892 tmp
= TREE_CHAIN (tmp
);
1895 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
1897 if (! ASSOC_VIRTUALS (vbases
));
1900 base
= TREE_TYPE (vbases
);
1901 tmp
= TREE_CHAIN (ASSOC_VIRTUALS (vbases
));
1904 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (tmp
));
1905 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
1906 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
1907 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
1908 tmp
= TREE_CHAIN (tmp
);
1911 return nreverse (abstract_virtuals
);
1914 /* For the type TYPE, return a list of member functions available from
1915 base classes with name NAME. The TREE_VALUE of the list is a chain of
1916 member functions with name NAME. The TREE_PURPOSE of the list is a
1917 basetype, or a list of base types (in reverse order) which were
1918 traversed to reach the chain of member functions. If we reach a base
1919 type which provides a member function of name NAME, and which has at
1920 most one base type itself, then we can terminate the search. */
1923 get_baselinks (type
, name
)
1926 tree
hash_tree_cons ();
1927 int head
= 0, tail
= 0, index
;
1928 tree rval
= 0, nval
= 0;
1929 tree basetypes
= CLASSTYPE_AS_LIST (type
);
1931 search_stack
= push_search_level (search_stack
, &search_obstack
);
1935 int i
, n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
1937 /* Process and/or queue base types. */
1938 for (i
= 1; i
<= n_baselinks
; i
++)
1939 if (CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (type
, i
)) == 0)
1943 btypes
= hash_tree_cons (CLASSTYPE_VIA_PUBLIC (type
, i
),
1944 CLASSTYPE_VIA_VIRTUAL (type
, i
),
1945 NULL_TREE
, CLASSTYPE_BASECLASS (type
, i
),
1947 CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (type
, i
)) = 1;
1948 obstack_ptr_grow (&search_obstack
, btypes
);
1951 if (tail
>= search_stack
->limit
)
1956 /* Process head of queue, if one exists. */
1960 basetypes
= search_stack
->first
[head
++];
1961 type
= TREE_VALUE (basetypes
);
1962 index
= lookup_fnfields_1 (type
, name
);
1965 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), index
);
1966 rval
= hash_tree_cons (0, 0, basetypes
, nval
, rval
);
1967 if (CLASSTYPE_N_BASECLASSES (type
) <= 1)
1969 if (CLASSTYPE_BASELINK_VEC (type
))
1970 TREE_TYPE (rval
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), index
);
1977 tree
*tp
= search_stack
->first
;
1978 tree
*search_tail
= tp
+ tail
;
1980 while (tp
< search_tail
)
1982 CLASSTYPE_MARKED (TREE_VALUE (*tp
++)) = 0;
1985 search_stack
= pop_search_level (search_stack
);
1990 next_baselink (baselink
)
1993 tree tmp
= TREE_TYPE (baselink
);
1994 baselink
= TREE_CHAIN (baselink
);
1997 /* @@ does not yet add previous base types. */
1998 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2000 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2001 tmp
= TREE_CHAIN (tmp
);
2006 /* DEPTH-FIRST SEARCH ROUTINES. */
2008 /* Assign unique numbers to _CLASSTYPE members of the lattice
2009 specified by TYPE. The root nodes are marked first; the nodes
2010 are marked depth-fisrt, left-right. */
2014 /* Matrix implementing a relation from CLASSTYPE X CLASSTYPE => INT.
2015 Relation yields 1 if C1 <= C2, 0 otherwise. */
2016 typedef char mi_boolean
;
2017 static mi_boolean
*mi_matrix
;
2019 /* Type for which this matrix is defined. */
2020 static tree mi_type
;
2022 /* Size of the matrix for indexing purposes. */
2025 /* Return nonzero if class C2 derives from class C1. */
2026 #define DERIVES_FROM(C1, C2) \
2027 ((mi_matrix+mi_size*(CLASSTYPE_CID (C1)-1))[CLASSTYPE_CID (C2)-1])
2028 #define DERIVES_FROM_STAR(C) \
2029 (mi_matrix+(CLASSTYPE_CID (C)-1))
2031 /* The main function which implements depth first search. */
2033 dfs_walk (type
, fn
, qfn
)
2038 int i
, n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
2040 for (i
= 1; i
<= n_baselinks
; i
++)
2041 if ((*qfn
)(CLASSTYPE_BASECLASS (type
, i
)))
2043 dfs_walk (CLASSTYPE_BASECLASS (type
, i
), fn
, qfn
);
2049 /* Predicate functions which serve for dfs_walk. */
2050 static int numberedp (type
) tree type
;
2051 { return CLASSTYPE_CID (type
); }
2052 static int unnumberedp (type
) tree type
;
2053 { return CLASSTYPE_CID (type
) == 0; }
2055 static int markedp (type
) tree type
;
2056 { return CLASSTYPE_MARKED (type
); }
2057 static int bfs_markedp (type
, i
) tree type
; int i
;
2058 { return CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (type
, i
)); }
2059 static int unmarkedp (type
) tree type
;
2060 { return CLASSTYPE_MARKED (type
) == 0; }
2061 static int bfs_unmarkedp (type
, i
) tree type
; int i
;
2062 { return CLASSTYPE_MARKED (CLASSTYPE_BASECLASS (type
, i
)) == 0; }
2063 static int marked2p (type
) tree type
;
2064 { return CLASSTYPE_MARKED2 (type
); }
2065 static int bfs_marked2p (type
, i
) tree type
; int i
;
2066 { return CLASSTYPE_MARKED2 (CLASSTYPE_BASECLASS (type
, i
)); }
2067 static int unmarked2p (type
) tree type
;
2068 { return CLASSTYPE_MARKED2 (type
) == 0; }
2069 static int bfs_unmarked2p (type
, i
) tree type
; int i
;
2070 { return CLASSTYPE_MARKED2 (CLASSTYPE_BASECLASS (type
, i
)) == 0; }
2071 static int marked3p (type
) tree type
;
2072 { return CLASSTYPE_MARKED3 (type
); }
2073 static int bfs_marked3p (type
, i
) tree type
; int i
;
2074 { return CLASSTYPE_MARKED3 (CLASSTYPE_BASECLASS (type
, i
)); }
2075 static int unmarked3p (type
) tree type
;
2076 { return CLASSTYPE_MARKED3 (type
) == 0; }
2077 static int bfs_unmarked3p (type
, i
) tree type
; int i
;
2078 { return CLASSTYPE_MARKED3 (CLASSTYPE_BASECLASS (type
, i
)) == 0; }
2079 static int marked4p (type
) tree type
;
2080 { return CLASSTYPE_MARKED4 (type
); }
2081 static int bfs_marked4p (type
, i
) tree type
; int i
;
2082 { return CLASSTYPE_MARKED4 (CLASSTYPE_BASECLASS (type
, i
)); }
2083 static int unmarked4p (type
) tree type
;
2084 { return CLASSTYPE_MARKED4 (type
) == 0; }
2085 static int bfs_unmarked4p (type
, i
) tree type
; int i
;
2086 { return CLASSTYPE_MARKED4 (CLASSTYPE_BASECLASS (type
, i
)) == 0; }
2088 static int dfs_search_slot_nonempty_p (type
) tree type
;
2089 { return CLASSTYPE_SEARCH_SLOT (type
) != 0; }
2092 /* The worker functions for `dfs_walk'. These do not need to
2093 test anything (vis a vis marking) if they are paired with
2094 a predicate function (above). */
2096 /* Assign each type within the lattice a number which is unique
2097 in the lattice. The first number assigned is 1. */
2103 CLASSTYPE_CID (type
) = ++cid
;
2110 CLASSTYPE_CID (type
) = 0;
2114 dfs_mark (type
) tree type
;
2115 { CLASSTYPE_MARKED (type
) = 1; }
2118 dfs_unmark (type
) tree type
;
2119 { CLASSTYPE_MARKED (type
) = 0; }
2122 dfs_mark2 (type
) tree type
;
2123 { CLASSTYPE_MARKED2 (type
) = 1; }
2126 dfs_unmark2 (type
) tree type
;
2127 { CLASSTYPE_MARKED2 (type
) = 0; }
2130 dfs_mark3 (type
) tree type
;
2131 { CLASSTYPE_MARKED3 (type
) = 1; }
2134 dfs_unmark3 (type
) tree type
;
2135 { CLASSTYPE_MARKED3 (type
) = 0; }
2138 dfs_mark4 (type
) tree type
;
2139 { CLASSTYPE_MARKED4 (type
) = 1; }
2142 dfs_unmark4 (type
) tree type
;
2143 { CLASSTYPE_MARKED4 (type
) = 0; }
2146 dfs_unmark12 (type
) tree type
;
2147 { CLASSTYPE_MARKED (type
) = 0;
2148 CLASSTYPE_MARKED2 (type
) = 0; }
2151 dfs_unmark34 (type
) tree type
;
2152 { CLASSTYPE_MARKED3 (type
) = 0;
2153 CLASSTYPE_MARKED4 (type
) = 0; }
2156 dfs_clear_search_slot (type
) tree type
;
2157 { CLASSTYPE_SEARCH_SLOT (type
) = 0; }
2159 static tree vbase_types
;
2160 static tree vbase_decl
, vbase_decl_ptr
;
2161 static tree vbase_init_result
;
2164 dfs_find_vbases (type
)
2167 int i
, n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
2169 for (i
= n_baselinks
; i
> 0; i
--)
2170 if (CLASSTYPE_VIA_VIRTUAL (type
, i
)
2171 && CLASSTYPE_SEARCH_SLOT (CLASSTYPE_BASECLASS (type
, i
)) == 0)
2173 tree vbase
= CLASSTYPE_BASECLASS (type
, i
);
2174 /* ??? ASSOC_VALUE and TREE_VALUE must be the same for this to work. */
2175 tree assoc
= value_member (TYPE_MAIN_VARIANT (vbase
), vbase_types
);
2177 CLASSTYPE_SEARCH_SLOT (vbase
)
2178 = build (PLUS_EXPR
, TYPE_POINTER_TO (vbase
),
2179 vbase_decl_ptr
, ASSOC_OFFSET (assoc
));
2181 CLASSTYPE_MARKED3 (type
) = 1;
2182 CLASSTYPE_MARKED4 (type
) = 1;
2186 dfs_init_vbase_pointers (type
)
2189 tree fields
= TYPE_FIELDS (type
);
2190 tree path
, this_vbase_ptr
;
2193 CLASSTYPE_MARKED3 (type
) = 0;
2195 if (fields
== NULL_TREE
2196 || DECL_NAME (fields
) == NULL_TREE
2197 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2200 distance
= get_base_distance (type
, TREE_TYPE (vbase_decl
), 0, &path
);
2203 if (TREE_VIA_VIRTUAL (path
))
2206 path
= TREE_CHAIN (path
);
2210 this_vbase_ptr
= convert_pointer_to (type
, CLASSTYPE_SEARCH_SLOT (TREE_VALUE (path
)));
2212 this_vbase_ptr
= convert_pointer_to (type
, vbase_decl_ptr
);
2214 while (fields
&& DECL_NAME (fields
)
2215 && VBASE_NAME_P (DECL_NAME (fields
)))
2217 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2218 build_indirect_ref (this_vbase_ptr
, 0), fields
);
2219 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2220 vbase_init_result
= tree_cons (TREE_TYPE (TREE_TYPE (fields
)),
2221 build_modify_expr (ref
, NOP_EXPR
, init
),
2223 fields
= TREE_CHAIN (fields
);
2227 /* Sometimes this needs to clear both 3 and 4. Other times,
2228 just 4, but optimizer should make both with equal efficiency
2229 (though it does not currently). */
2231 dfs_clear_vbase_slots (type
)
2234 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2235 CLASSTYPE_MARKED3 (type
) = 0;
2236 CLASSTYPE_MARKED4 (type
) = 0;
2240 init_vbase_pointers (type
, decl_ptr
)
2244 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2246 int old_flag
= flag_this_is_variable
;
2247 flag_this_is_variable
= 0;
2248 vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2249 vbase_decl_ptr
= decl_ptr
;
2250 vbase_decl
= build_indirect_ref (decl_ptr
, 0);
2251 vbase_init_result
= NULL_TREE
;
2253 expand_asm_operands (build_string (32, "! start of vbase initialization"), 0, 0, 0, 0, input_filename
, lineno
);
2255 dfs_walk (type
, dfs_find_vbases
, unmarked3p
);
2256 dfs_walk (type
, dfs_init_vbase_pointers
, marked3p
);
2257 dfs_walk (type
, dfs_clear_vbase_slots
, marked4p
);
2258 flag_this_is_variable
= old_flag
;
2259 return vbase_init_result
;
2264 /* Build a COMPOUND_EXPR which when expanded will generate the code
2265 needed to initialize all the virtual function table slots of all
2266 the virtual baseclasses. FOR_TYPE is the type which determines the
2267 virtual baseclasses to use; TYPE is the type of the object to which
2268 the initialization applies. TRUE_EXP is the true object we are
2269 initializing, and DECL_PTR is the pointer to the sub-object we
2272 CTOR_P is non-zero if the caller of this function is a top-level
2273 constructor. It is zero when called from a destructor. When
2274 non-zero, we can use computed offsets to store the vtables. When
2275 zero, we must store new vtables through virtual baseclass pointers. */
2278 build_vbase_vtables_init (for_type
, type
, true_exp
, decl_ptr
, ctor_p
)
2279 tree for_type
, type
;
2280 tree true_exp
, decl_ptr
;
2283 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2285 int old_flag
= flag_this_is_variable
;
2286 tree vtable_init_result
= NULL_TREE
;
2287 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
2289 vbase_types
= CLASSTYPE_VBASECLASSES (for_type
);
2290 vbase_decl_ptr
= true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0) : decl_ptr
;
2291 vbase_decl
= true_exp
? true_exp
: build_indirect_ref (decl_ptr
, 0);
2293 expand_asm_operands (build_string (32, "! start of vtable initialization"), 0, 0, 0, 0, input_filename
, lineno
);
2295 flag_this_is_variable
= 0;
2298 /* This is an object of type IN_TYPE, */
2299 dfs_walk (for_type
, dfs_find_vbases
, unmarked4p
);
2301 /* Initialized with vtables of type TYPE. */
2304 tree basetype
= get_base_type (ASSOC_VALUE (vbases
), type
, 0);
2306 /* This time through, not every class's vtable
2307 is going to be initialized. That is, we only initialize
2308 the "last" vtable pointer. */
2310 assert (basetype
== ASSOC_TYPE (vbases
));
2313 && CLASSTYPE_VSIZE (basetype
)
2314 && TYPE_MAIN_VARIANT (basetype
) == ASSOC_VALUE (vbases
))
2317 tree vtbl
= ASSOC_VTABLE (vbases
);
2318 tree init
= build_unary_op (ADDR_EXPR
, vtbl
, 0);
2319 TREE_USED (vtbl
) = 1;
2322 addr
= convert_pointer_to (basetype
, vbase_decl_ptr
);
2324 addr
= CLASSTYPE_SEARCH_SLOT (basetype
);
2328 tree ref
= build_vfield_ref (build_indirect_ref (addr
, 0), basetype
);
2329 init
= convert_force (TREE_TYPE (ref
), init
);
2330 vtable_init_result
= tree_cons (NULL_TREE
, build_modify_expr (ref
, NOP_EXPR
, init
),
2331 vtable_init_result
);
2334 vbases
= TREE_CHAIN (vbases
);
2337 dfs_walk (type
, dfs_clear_vbase_slots
, marked4p
);
2339 flag_this_is_variable
= old_flag
;
2340 if (vtable_init_result
)
2341 return build_compound_expr (vtable_init_result
);
2343 return error_mark_node
;
2347 clear_search_slots (type
)
2350 dfs_walk (type
, dfs_clear_search_slot
, dfs_search_slot_nonempty_p
);
2354 dfs_get_vbase_types (type
)
2358 tree these_vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2361 if (these_vbase_types
)
2363 while (these_vbase_types
)
2365 basetype
= ASSOC_TYPE (these_vbase_types
);
2366 if (! CLASSTYPE_MARKED2 (basetype
))
2368 vbase_types
= make_assoc (integer_zero_node
,
2370 CLASS_ASSOC_VTABLE (basetype
),
2371 CLASS_ASSOC_VIRTUALS (basetype
),
2373 CLASSTYPE_MARKED2 (basetype
) = 1;
2375 these_vbase_types
= TREE_CHAIN (these_vbase_types
);
2378 else for (i
= CLASSTYPE_N_BASECLASSES (type
); i
> 0; i
--)
2380 basetype
= CLASSTYPE_BASECLASS (type
, i
);
2381 if (CLASSTYPE_VIA_VIRTUAL (type
, i
) && ! CLASSTYPE_MARKED2 (basetype
))
2383 vbase_types
= make_assoc (integer_zero_node
,
2385 CLASS_ASSOC_VTABLE (basetype
),
2386 CLASS_ASSOC_VIRTUALS (basetype
),
2388 CLASSTYPE_MARKED2 (basetype
) = 1;
2391 CLASSTYPE_MARKED (type
) = 1;
2394 /* Some virtual baseclasses might be virtual baseclasses for
2395 other virtual baseclasses. We sort the virtual baseclasses
2396 topologically: in the list returned, the first virtual base
2397 classes have no virtual baseclasses themselves, and any entry
2398 on the list has no dependency on virtual base classes later in the
2401 get_vbase_types (type
)
2404 tree ordered_vbase_types
= NULL_TREE
, prev
, next
;
2407 vbase_types
= NULL_TREE
;
2408 dfs_walk (type
, dfs_get_vbase_types
, unmarkedp
);
2409 dfs_walk (type
, dfs_unmark
, markedp
);
2413 /* Now sort these types. This is essentially a bubble merge. */
2415 /* Farm out virtual baseclasses which have no marked ancestors. */
2416 for (vbases
= vbase_types
, prev
= NULL_TREE
;
2417 vbases
; vbases
= next
)
2419 next
= TREE_CHAIN (vbases
);
2420 if (! TYPE_USES_VIRTUAL_BASECLASSES (ASSOC_TYPE (vbases
))
2421 || CLASSTYPE_MARKED2 (ASSOC_TYPE (vbases
)) == 0)
2424 TREE_CHAIN (prev
) = TREE_CHAIN (vbases
);
2426 vbase_types
= TREE_CHAIN (vbases
);
2427 TREE_CHAIN (vbases
) = NULL_TREE
;
2428 ordered_vbase_types
= chainon (ordered_vbase_types
, vbases
);
2429 CLASSTYPE_MARKED2 (ASSOC_TYPE (vbases
)) = 0;
2435 /* Now unmark types all of whose ancestors are now on the
2436 `ordered_vbase_types' list. */
2437 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
2439 /* If all our virtual baseclasses are unmarked, ok. */
2440 tree t
= CLASSTYPE_VBASECLASSES (ASSOC_VALUE (vbases
));
2441 while (t
&& (CLASSTYPE_MARKED2 (ASSOC_TYPE (t
)) == 0
2442 || !TYPE_USES_VIRTUAL_BASECLASSES (ASSOC_TYPE (t
))))
2445 CLASSTYPE_MARKED2 (ASSOC_TYPE (vbases
)) = 0;
2449 return ordered_vbase_types
;
2453 dfs_record_inheritance (type
)
2456 int i
, n_baselinks
= CLASSTYPE_N_BASECLASSES (type
);
2457 mi_boolean
*derived_row
= DERIVES_FROM_STAR (type
);
2459 for (i
= n_baselinks
; i
> 0; i
--)
2462 tree baseclass
= TYPE_MAIN_VARIANT (CLASSTYPE_BASECLASS (type
, i
));
2463 mi_boolean
*base_row
= DERIVES_FROM_STAR (baseclass
);
2465 /* Don't search if there's nothing there! MI_SIZE can be
2466 zero as a result of parse errors. */
2467 if (CLASSTYPE_N_BASECLASSES (baseclass
) && mi_size
> 0)
2468 for (j
= mi_size
*(CLASSTYPE_CID (baseclass
)-1); j
>= 0; j
-= mi_size
)
2469 derived_row
[j
] |= base_row
[j
];
2470 DERIVES_FROM (baseclass
, type
) = 1;
2473 CLASSTYPE_MARKED (type
) = 1;
2476 /* Given a _CLASSTYPE node in a multiple inheritance lattice,
2477 convert the lattice into a simple relation such that,
2478 given to CIDs, C1 and C2, one can determine if C1 <= C2
2479 or C2 <= C1 or C1 <> C2.
2481 Once constructed, we walk the lattice depth fisrt,
2482 applying various functions to elements as they are encountered.
2484 We use malloc here, in case we want to randomly free these tables. */
2486 #define SAVE_MI_MATRIX
2489 build_mi_matrix (type
)
2494 #ifdef SAVE_MI_MATRIX
2495 if (CLASSTYPE_MI_MATRIX (type
))
2497 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
2498 mi_matrix
= CLASSTYPE_MI_MATRIX (type
);
2500 dfs_walk (type
, dfs_number
, unnumberedp
);
2505 mi_size
= CLASSTYPE_N_SUPERCLASSES (type
) + CLASSTYPE_N_VBASECLASSES (type
);
2506 mi_matrix
= (char *)malloc ((mi_size
+1) * (mi_size
+1));
2508 bzero (mi_matrix
, mi_size
* mi_size
);
2509 dfs_walk (type
, dfs_number
, unnumberedp
);
2510 dfs_walk (type
, dfs_record_inheritance
, unmarkedp
);
2511 dfs_walk (type
, dfs_unmark
, markedp
);
2517 dfs_walk (mi_type
, dfs_unnumber
, numberedp
);
2519 #ifdef SAVE_MI_MATRIX
2520 CLASSTYPE_MI_MATRIX (mi_type
) = mi_matrix
;
2528 /* Local variables for detecting ambiguities of virtual functions
2529 when two or more classes are joined at a multiple inheritance
2531 typedef tree mi_ventry
[3];
2532 static mi_ventry
*mi_vmatrix
;
2533 static int *mi_vmax
;
2534 static int mi_vrows
, mi_vcols
;
2535 #define MI_VMATRIX(ROW,COL) ((mi_vmatrix + (ROW)*mi_vcols)[COL])
2537 /* Build a table of virtual functions for a multiple-inheritance
2538 structure. Here, there are N base classes, and at most
2539 M entries per class.
2541 This function does nothing if N is 0 or 1. */
2543 build_mi_virtuals (rows
, cols
)
2550 mi_vmatrix
= (mi_ventry
*)malloc ((rows
+1) * cols
* sizeof (mi_ventry
));
2551 mi_vmax
= (int *)malloc ((rows
+1) * sizeof (int));
2553 bzero (mi_vmax
, rows
* sizeof (int));
2555 /* Row indicies start at 1, so adjust this. */
2560 /* Comparison function for ordering virtual function table entries. */
2562 rank_mi_virtuals (v1
, v2
)
2568 i
= (TREE_UID (DECL_ORIGINAL_NAME ((*v1
)[0]))
2569 - TREE_UID (DECL_ORIGINAL_NAME ((*v2
)[0])));
2580 i
= (TREE_UID (TREE_VALUE (p1
))
2581 - TREE_UID (TREE_VALUE (p2
)));
2585 if (TREE_CHAIN (p1
))
2587 if (! TREE_CHAIN (p2
))
2589 p1
= TREE_CHAIN (p1
);
2590 p2
= TREE_CHAIN (p2
);
2592 else if (TREE_CHAIN (p2
))
2596 /* When matches of argument lists occur, pick lowest
2597 TREE_UID to keep searching time to a minimum on
2598 later passes--like hashing, only different.
2599 *MUST BE STABLE*. */
2600 if (TREE_UID ((*v2
)[1]) < TREE_UID ((*v1
)[1]))
2601 (*v1
)[1] = (*v2
)[1];
2603 (*v2
)[1] = (*v1
)[1];
2610 /* Install the virtuals functions got from the initializer VIRTUALS to
2611 the table at index ROW. */
2613 add_mi_virtuals (row
, virtuals
)
2619 if (mi_vmatrix
== 0)
2623 tree decl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
2624 MI_VMATRIX (row
, col
)[0] = decl
;
2625 MI_VMATRIX (row
, col
)[1] = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl
)));
2626 MI_VMATRIX (row
, col
)[2] = TREE_VALUE (virtuals
);
2627 virtuals
= TREE_CHAIN (virtuals
);
2632 qsort (mi_vmatrix
+ row
* mi_vcols
,
2638 /* If joining two types results in an ambiguity in the virtual
2639 function table, report such here. */
2641 report_ambiguous_mi_virtuals (rows
, type
)
2646 int row1
, col1
, row
, col
;
2648 if (mi_vmatrix
== 0)
2651 /* Now virtuals are all sorted, so we merge to find ambiguous cases. */
2652 mi_vmin
= (int *)alloca ((rows
+1) * sizeof (int));
2653 bzero (mi_vmin
, rows
* sizeof (int));
2658 /* For each base class with virtual functions (and this includes views
2659 of the virtual baseclasses from different base classes), see that
2660 each virtual function in that base class has a unique meet.
2662 When the column loop is finished, THIS_DECL is in fact the meet.
2663 If that value does not appear in the virtual function table for
2664 the row, install it. This happens when that virtual function comes
2665 from a virtual baseclass, or a non-leftmost baseclass. */
2667 for (row1
= 1; row1
< rows
; row1
++)
2671 for (col1
= mi_vmax
[row1
]-1; col1
>= mi_vmin
[row1
]; col1
--)
2673 tree these_args
= MI_VMATRIX (row1
, col1
)[1];
2676 this_decl
= MI_VMATRIX (row1
, col1
)[0];
2679 this_context
= DECL_CONTEXT (this_decl
);
2681 if (this_context
!= type
)
2682 this_context
= get_base_type (this_context
, type
, 0);
2684 for (row
= row1
+1; row
<= rows
; row
++)
2685 for (col
= mi_vmax
[row
]-1; col
>= mi_vmin
[row
]; col
--)
2687 mi_ventry this_entry
;
2689 if (MI_VMATRIX (row
, col
)[0] == 0)
2692 this_entry
[0] = this_decl
;
2693 this_entry
[1] = these_args
;
2694 this_entry
[2] = MI_VMATRIX (row1
, col1
)[2];
2695 if (rank_mi_virtuals (&this_entry
,
2696 &MI_VMATRIX (row
, col
)) == 0)
2698 /* They are equal. There are four possibilities:
2700 (1) Derived class is defining this virtual function.
2701 (2) Two paths to the same virtual function in the
2703 (3) A path to a virtual function declared in one base
2704 class, and another path to a virtual function in a
2705 base class of the base class.
2706 (4) Two paths to the same virtual function in different
2709 The first three cases are ok (non-ambiguous). */
2711 tree that_context
, tmp
;
2712 int this_before_that
;
2714 if (type
== this_context
)
2717 that_context
= get_base_type (DECL_CONTEXT (MI_VMATRIX (row
, col
)[0]), type
, 0);
2718 if (that_context
== this_context
)
2721 if (that_context
!= NULL_TREE
)
2723 tmp
= get_base_type (that_context
, this_context
, 0);
2724 this_before_that
= (that_context
!= tmp
);
2725 if (this_before_that
== 0)
2728 tmp
= get_base_type (this_context
, that_context
, 0);
2729 this_before_that
= (this_context
== tmp
);
2730 if (this_before_that
!= 0)
2735 error_with_decl (MI_VMATRIX (row
, col
)[0], "ambiguous virtual function `%s'");
2736 error_with_decl (this_decl
, "ambiguating function `%s' (joined by type `%s')", IDENTIFIER_POINTER (current_class_name
));
2739 MI_VMATRIX (row
, col
)[0] = 0;
2741 /* Let zeros propagate. */
2742 if (col
== mi_vmax
[row
]-1)
2745 while (i
>= mi_vmin
[row
]
2746 && MI_VMATRIX (row
, i
)[0] == 0)
2750 else if (col
== mi_vmin
[row
])
2753 while (i
< mi_vmax
[row
]
2754 && MI_VMATRIX (row
, i
)[0] == 0)
2762 free (mi_vmatrix
+ mi_vcols
);
2768 /* Subroutines of push_class_decls (). */
2770 /* Add the instance variables which this class contributed to the
2771 current class binding contour. When a redefinition occurs,
2772 if the redefinition is strictly within a single inheritance path,
2773 we just overwrite (in the case of a data field) or
2774 cons (in the case of a member function) the old declaration with
2775 the new. If the fields are not within a single inheritance path,
2776 we must cons them in either case. */
2779 dfs_pushdecls (type
)
2782 tree fields
, *methods
, *end
;
2785 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2787 /* Unmark so that if we are in a constructor, and then find that
2788 this field was initialized by a base initializer,
2789 we can emit an error message. */
2790 if (TREE_CODE (fields
) == FIELD_DECL
)
2791 TREE_USED (fields
) = 0;
2793 if (DECL_ANON_UNION_ELEM (fields
))
2795 dfs_pushdecls (TREE_TYPE (fields
));
2798 if (TREE_CODE (fields
) != TYPE_DECL
)
2800 TREE_FIELD_PUBLIC (fields
) = 0;
2801 TREE_FIELD_PROTECTED (fields
) = 0;
2802 TREE_FIELD_PRIVATE (fields
) = 0;
2805 if (DECL_NAME (fields
))
2807 tree value
= IDENTIFIER_CLASS_VALUE (DECL_NAME (fields
));
2810 /* Possible ambiguity. If its defining type(s)
2811 is (are all) derived from us, no problem. */
2813 if (TREE_CODE (value
) != TREE_LIST
)
2815 if (DECL_FIELD_CONTEXT (value
) == type
2816 || DERIVES_FROM (DECL_FIELD_CONTEXT (value
), type
))
2819 value
= tree_cons (NULL_TREE
, fields
,
2820 build_tree_list (NULL_TREE
, value
));
2824 /* All children may derive from us, in which case
2825 there is no problem. Otherwise, we have to
2826 keep lists around of what the ambiguities might be. */
2830 for (values
= value
; values
; values
= TREE_CHAIN (values
))
2832 tree sub_values
= TREE_VALUE (values
);
2833 if (TREE_CODE (sub_values
) == TREE_LIST
)
2835 for (; sub_values
; sub_values
= TREE_CHAIN (sub_values
))
2836 if (! DERIVES_FROM (DECL_FIELD_CONTEXT (TREE_VALUE (sub_values
)), type
))
2838 value
= tree_cons (NULL_TREE
, TREE_VALUE (values
), value
);
2845 if (! DERIVES_FROM (DECL_FIELD_CONTEXT (sub_values
), type
))
2847 value
= tree_cons (NULL_TREE
, values
, value
);
2853 if (! problem
) value
= fields
;
2856 /* Mark this as a potentially ambiguous member. */
2857 if (TREE_CODE (value
) == TREE_LIST
)
2859 /* Leaving TREE_TYPE blank is intentional.
2860 We cannot use `error_mark_node' (lookup_name)
2861 or `unknown_type_node' (all member functions use this). */
2862 TREE_NONLOCAL (value
) = 1;
2865 IDENTIFIER_CLASS_VALUE (DECL_NAME (fields
)) = value
;
2867 else IDENTIFIER_CLASS_VALUE (DECL_NAME (fields
)) = fields
;
2871 method_vec
= CLASSTYPE_METHOD_VEC (type
);
2872 if (method_vec
!= 0)
2874 /* Farm out constructors and destructors. */
2875 methods
= &TREE_VEC_ELT (method_vec
, 1);
2876 end
= TREE_VEC_END (method_vec
);
2878 /* This does not work for multiple inheritance yet. */
2879 while (methods
!= end
)
2881 /* This will cause lookup_name to return a pointer
2882 to the tree_list of possible methods of this name.
2883 If the order is a problem, we can nreverse them. */
2885 tree old
= IDENTIFIER_CLASS_VALUE (DECL_ORIGINAL_NAME (*methods
));
2887 if (old
&& TREE_CODE (old
) == TREE_LIST
)
2888 tmp
= tree_cons (DECL_ORIGINAL_NAME (*methods
), *methods
, old
);
2891 /* Only complain if we shadow something we can access. */
2892 if (old
&& (DECL_CONTEXT (old
) == current_class_type
2893 || ! TREE_PRIVATE (old
)))
2894 /* Should figure out visibility more accurately. */
2895 warning ("shadowing member `%s' with member function",
2896 IDENTIFIER_POINTER (DECL_ORIGINAL_NAME (*methods
)));
2897 tmp
= build_tree_list (DECL_ORIGINAL_NAME (*methods
), *methods
);
2900 TREE_TYPE (tmp
) = unknown_type_node
;
2902 TREE_OVERLOADED (tmp
) = DECL_OVERLOADED (*methods
);
2904 TREE_NONLOCAL (tmp
) = 1;
2905 IDENTIFIER_CLASS_VALUE (DECL_ORIGINAL_NAME (*methods
)) = tmp
;
2910 TREE_FIELD_PUBLIC (tmp
) = 0;
2911 TREE_FIELD_PROTECTED (tmp
) = 0;
2912 TREE_FIELD_PRIVATE (tmp
) = 0;
2913 tmp
= TREE_CHAIN (tmp
);
2919 CLASSTYPE_MARKED (type
) = 1;
2922 /* Consolidate unique (by name) member functions. */
2924 dfs_compress_decls (type
)
2927 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
2929 if (method_vec
!= 0)
2931 /* Farm out constructors and destructors. */
2932 tree
*methods
= &TREE_VEC_ELT (method_vec
, 1);
2933 tree
*end
= TREE_VEC_END (method_vec
);
2935 for (; methods
!= end
; methods
++)
2937 tree tmp
= IDENTIFIER_CLASS_VALUE (DECL_ORIGINAL_NAME (*methods
));
2939 /* This was replaced in scope by somebody else. Just leave it
2941 if (TREE_CODE (tmp
) != TREE_LIST
)
2944 if (TREE_CHAIN (tmp
) == NULL_TREE
2946 && TREE_CHAIN (TREE_VALUE (tmp
)) == NULL_TREE
)
2948 IDENTIFIER_CLASS_VALUE (DECL_ORIGINAL_NAME (*methods
))
2953 CLASSTYPE_MARKED (type
) = 0;
2956 /* When entering the scope of a class, we cache all of the
2957 fields that that class provides within its inheritance
2958 lattice. Where ambiguities result, we mark them
2959 with `error_mark_node' so that if they are encountered
2960 without explicit qualification, we can emit an error
2963 push_class_decls (type
)
2966 struct obstack
*ambient_obstack
= current_obstack
;
2969 tree tags
= CLASSTYPE_TAGS (type
);
2973 tree code_type_node
;
2976 switch (TREE_CODE (TREE_VALUE (tags
)))
2979 code_type_node
= enum_type_node
;
2982 code_type_node
= record_type_node
;
2985 code_type_node
= class_type_node
;
2988 code_type_node
= union_type_node
;
2993 tag
= xref_tag (code_type_node
, TREE_PURPOSE (tags
),
2994 CLASSTYPE_BASECLASS (TREE_VALUE (tags
), 1));
2995 pushdecl (build_decl (TYPE_DECL
, TREE_PURPOSE (tags
), TREE_VALUE (tags
)));
2999 current_obstack
= &bridge_obstack
;
3000 search_stack
= push_search_level (search_stack
, &bridge_obstack
);
3002 /* Push class fields into CLASS_VALUE scope, and mark. */
3003 dfs_walk (type
, dfs_pushdecls
, unmarkedp
);
3005 /* Compress fields which have only a single entry
3006 by a given name, and unmark. */
3007 dfs_walk (type
, dfs_compress_decls
, markedp
);
3008 current_obstack
= ambient_obstack
;
3015 tree fields
= TYPE_FIELDS (type
);
3016 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
3020 if (DECL_ANON_UNION_ELEM (fields
))
3022 dfs_popdecls (TREE_TYPE (fields
));
3024 else if (DECL_NAME (fields
))
3025 IDENTIFIER_CLASS_VALUE (DECL_NAME (fields
)) = NULL_TREE
;
3026 fields
= TREE_CHAIN (fields
);
3028 if (method_vec
!= 0)
3030 tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
3031 tree
*end
= TREE_VEC_END (method_vec
);
3036 for (; methods
!= end
; methods
++)
3037 IDENTIFIER_CLASS_VALUE (DECL_ORIGINAL_NAME (*methods
)) = NULL_TREE
;
3040 CLASSTYPE_MARKED (type
) = 1;
3044 pop_class_decls (type
)
3047 /* Clear out the IDENTIFIER_CLASS_VALUE which this
3048 class may have occupied, and mark. */
3049 dfs_walk (type
, dfs_popdecls
, unmarkedp
);
3052 dfs_walk (type
, dfs_unmark
, markedp
);
3053 search_stack
= pop_search_level (search_stack
);
3056 /* Given a base type PARENT, and a derived type TYPE, build
3057 a name which distinguishes exactly the PARENT member of TYPE's type.
3059 FORMAT is a string which controls how sprintf formats the name
3064 class A; class B; class C : A, B;
3066 it is possible to distinguish "A" from "C's A". And given
3069 class A : L; class B : L; class C : A, B;
3071 it is possible to distinguish "L" from "A's L", and also from
3074 build_type_pathname (format
, parent
, type
)
3078 extern struct obstack temporary_obstack
;
3079 char *first
, *base
, *name
;
3083 parent
= TYPE_MAIN_VARIANT (parent
);
3085 /* Remember where to cut the obstack to. */
3086 first
= obstack_base (&temporary_obstack
);
3088 /* Put on TYPE+PARENT. */
3089 obstack_grow (&temporary_obstack
,
3090 TYPE_NAME_STRING (type
), TYPE_NAME_LENGTH (type
));
3091 obstack_1grow (&temporary_obstack
, JOINER
);
3092 obstack_grow0 (&temporary_obstack
,
3093 TYPE_NAME_STRING (parent
), TYPE_NAME_LENGTH (parent
));
3094 i
= obstack_object_size (&temporary_obstack
);
3095 base
= obstack_base (&temporary_obstack
);
3096 obstack_finish (&temporary_obstack
);
3098 /* Put on FORMAT+TYPE+PARENT. */
3099 obstack_blank (&temporary_obstack
, strlen (format
) + i
+ 1);
3100 name
= obstack_base (&temporary_obstack
);
3101 sprintf (name
, format
, base
);
3102 id
= get_identifier (name
);
3103 obstack_free (&temporary_obstack
, first
);
3109 bfs_unmark_finished_struct (type
, i
)
3113 type
= i
== 0 ? type
: CLASSTYPE_BASECLASS (type
, i
);
3114 if (CLASSTYPE_MARKED4 (type
))
3116 tree assoc
, decl
, context
;
3118 if (type
== current_class_type
)
3119 assoc
= CLASSTYPE_ASSOC (type
);
3120 else if (TREE_VIA_VIRTUAL (type
))
3121 assoc
= value_member (TYPE_MAIN_VARIANT (type
), CLASSTYPE_VBASECLASSES (current_class_type
));
3123 assoc
= assoc_value (TYPE_MAIN_VARIANT (type
), current_class_type
);
3124 decl
= ASSOC_VTABLE (assoc
);
3125 context
= DECL_CONTEXT (decl
);
3126 DECL_CONTEXT (decl
) = 0;
3127 if (write_virtuals
>= 0
3128 && DECL_INITIAL (decl
) != ASSOC_VIRTUALS (assoc
))
3129 DECL_INITIAL (decl
) = build_nt (CONSTRUCTOR
, NULL_TREE
,
3130 ASSOC_VIRTUALS (assoc
));
3131 finish_decl (decl
, DECL_INITIAL (decl
), NULL_TREE
);
3132 DECL_CONTEXT (decl
) = context
;
3134 CLASSTYPE_MARKED3 (type
) = 0;
3135 CLASSTYPE_MARKED4 (type
) = 0;
3140 unmark_finished_struct (type
)
3143 bfs_unmark_finished_struct (type
, 0);
3144 breadth_first_search (type
, bfs_unmark_finished_struct
, bfs_marked3p
);
3148 print_search_statistics ()
3150 #ifdef GATHER_STATISTICS
3151 if (flag_memoize_lookups
)
3153 fprintf (stderr
, "%d memoized contexts saved\n",
3155 fprintf (stderr
, "%d local tree nodes made\n", my_tree_node_counter
);
3156 fprintf (stderr
, "%d local hash nodes made\n", my_memoized_entry_counter
);
3157 fprintf (stderr
, "fields statistics:\n");
3158 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3159 memoized_fast_finds
[0], memoized_fast_rejects
[0],
3160 memoized_fields_searched
[0]);
3161 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[0]);
3162 fprintf (stderr
, "fnfields statistics:\n");
3163 fprintf (stderr
, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3164 memoized_fast_finds
[1], memoized_fast_rejects
[1],
3165 memoized_fields_searched
[1]);
3166 fprintf (stderr
, " memoized_adds = %d\n", memoized_adds
[1]);
3168 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3169 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3170 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3171 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3172 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3174 fprintf (stderr
, "no search statistics\n");
3179 init_search_processing ()
3181 obstack_init (&search_obstack
);
3182 obstack_init (&type_obstack
);
3183 obstack_init (&type_obstack_entries
);
3184 obstack_init (&bridge_obstack
);
3186 /* This gives us room to build our chains of basetypes,
3187 whether or not we decide to memoize them. */
3188 type_stack
= push_type_level (0, &type_obstack
);
3189 _vptr_name
= get_identifier ("_vptr");
3198 assert (IS_AGGR_TYPE (type
));
3199 wrap_type
= TYPE_WRAP_TYPE (type
);
3200 name
= (char *)alloca (TYPE_NAME_LENGTH (wrap_type
)
3201 + strlen (WRAPPER_NAME_FORMAT
));
3202 sprintf (name
, WRAPPER_NAME_FORMAT
, TYPE_NAME_STRING (wrap_type
));
3203 return lookup_fnfields (CLASSTYPE_AS_LIST (wrap_type
),
3204 get_identifier (name
), 0);
3208 reinit_search_statistics ()
3210 my_memoized_entry_counter
= 0;
3211 memoized_fast_finds
[0] = 0;
3212 memoized_fast_finds
[1] = 0;
3213 memoized_adds
[0] = 0;
3214 memoized_adds
[1] = 0;
3215 memoized_fast_rejects
[0] = 0;
3216 memoized_fast_rejects
[1] = 0;
3217 memoized_fields_searched
[0] = 0;
3218 memoized_fields_searched
[1] = 0;
3219 n_fields_searched
= 0;
3220 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3221 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3222 n_calls_get_base_type
= 0;
3223 n_outer_fields_searched
= 0;
3224 n_contexts_saved
= 0;