1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 89, 92-96, 1997 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* High-level class interface. */
35 #define obstack_chunk_alloc xmalloc
36 #define obstack_chunk_free free
38 extern struct obstack
*current_obstack
;
39 extern tree abort_fndecl
;
43 /* Obstack used for remembering decision points of breadth-first. */
45 static struct obstack search_obstack
;
47 /* Methods for pushing and popping objects to and from obstacks. */
50 push_stack_level (obstack
, tp
, size
)
51 struct obstack
*obstack
;
52 char *tp
; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
55 struct stack_level
*stack
;
56 obstack_grow (obstack
, tp
, size
);
57 stack
= (struct stack_level
*) ((char*)obstack_next_free (obstack
) - size
);
58 obstack_finish (obstack
);
59 stack
->obstack
= obstack
;
60 stack
->first
= (tree
*) obstack_base (obstack
);
61 stack
->limit
= obstack_room (obstack
) / sizeof (tree
*);
66 pop_stack_level (stack
)
67 struct stack_level
*stack
;
69 struct stack_level
*tem
= stack
;
70 struct obstack
*obstack
= tem
->obstack
;
72 obstack_free (obstack
, tem
);
76 #define search_level stack_level
77 static struct search_level
*search_stack
;
79 static tree get_abstract_virtuals_1
PROTO((tree
, int, tree
));
80 static tree get_vbase_1
PROTO((tree
, tree
, unsigned int *));
81 static tree convert_pointer_to_vbase
PROTO((tree
, tree
));
82 static tree lookup_field_1
PROTO((tree
, tree
));
83 static tree convert_pointer_to_single_level
PROTO((tree
, tree
));
84 static int lookup_fnfields_1
PROTO((tree
, tree
));
85 static int lookup_fnfields_here
PROTO((tree
, tree
));
86 static int is_subobject_of_p
PROTO((tree
, tree
));
87 static int hides
PROTO((tree
, tree
));
88 static tree virtual_context
PROTO((tree
, tree
, tree
));
89 static tree get_template_base_recursive
90 PROTO((tree
, tree
, tree
, int));
91 static void dfs_walk
PROTO((tree
, void (*) (tree
), int (*) (tree
)));
92 static void dfs_check_overlap
PROTO((tree
));
93 static int dfs_no_overlap_yet
PROTO((tree
));
94 static void envelope_add_decl
PROTO((tree
, tree
, tree
*));
95 static int get_base_distance_recursive
96 PROTO((tree
, int, int, int, int *, tree
*, tree
, tree
*,
97 int, int *, int, int));
98 static void expand_upcast_fixups
99 PROTO((tree
, tree
, tree
, tree
, tree
, tree
, tree
*));
100 static void fixup_virtual_upcast_offsets
101 PROTO((tree
, tree
, int, int, tree
, tree
, tree
, tree
,
103 static int markedp
PROTO((tree
));
104 static int unmarkedp
PROTO((tree
));
105 static int marked_vtable_pathp
PROTO((tree
));
106 static int unmarked_vtable_pathp
PROTO((tree
));
107 static int marked_new_vtablep
PROTO((tree
));
108 static int unmarked_new_vtablep
PROTO((tree
));
109 static int dfs_debug_unmarkedp
PROTO((tree
));
110 static void dfs_debug_mark
PROTO((tree
));
111 static void dfs_find_vbases
PROTO((tree
));
112 static void dfs_clear_vbase_slots
PROTO((tree
));
113 static void dfs_unmark
PROTO((tree
));
114 static void dfs_init_vbase_pointers
PROTO((tree
));
115 static void dfs_get_vbase_types
PROTO((tree
));
116 static void dfs_pushdecls
PROTO((tree
));
117 static void dfs_compress_decls
PROTO((tree
));
118 static void dfs_unuse_fields
PROTO((tree
));
119 static void add_conversions
PROTO((tree
));
120 static tree get_virtuals_named_this
PROTO((tree
));
121 static tree get_virtual_destructor
PROTO((tree
, int));
122 static int tree_has_any_destructor_p
PROTO((tree
, int));
123 static int covariant_return_p
PROTO((tree
, tree
));
124 static struct search_level
*push_search_level
125 PROTO((struct stack_level
*, struct obstack
*));
126 static struct search_level
*pop_search_level
127 PROTO((struct stack_level
*));
128 static HOST_WIDE_INT breadth_first_search
129 PROTO((tree
, int (*) (tree
, int), int (*) (tree
, int)));
131 static tree vbase_types
;
132 static tree vbase_decl_ptr_intermediate
, vbase_decl_ptr
;
133 static tree vbase_init_result
;
135 /* Allocate a level of searching. */
137 static struct search_level
*
138 push_search_level (stack
, obstack
)
139 struct stack_level
*stack
;
140 struct obstack
*obstack
;
142 struct search_level tem
;
145 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
148 /* Discard a level of search allocation. */
150 static struct search_level
*
151 pop_search_level (obstack
)
152 struct stack_level
*obstack
;
154 register struct search_level
*stack
= pop_stack_level (obstack
);
159 /* Obstack used for memoizing member and member function lookup. */
161 static tree _vptr_name
;
163 /* Variables for gathering statistics. */
164 #ifdef GATHER_STATISTICS
165 static int n_fields_searched
;
166 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
167 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
168 static int n_calls_get_base_type
;
169 static int n_outer_fields_searched
;
170 static int n_contexts_saved
;
171 #endif /* GATHER_STATISTICS */
173 /* This list is used by push_class_decls to know what decls need to
174 be pushed into class scope. */
175 static tree closed_envelopes
= NULL_TREE
;
177 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
178 the same type as the type given in PARENT. To be optimal, we want
179 the first one that is found by going through the least number of
183 get_vbase_1 (parent
, binfo
, depth
)
189 tree rval
= NULL_TREE
;
191 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
199 binfos
= BINFO_BASETYPES (binfo
);
200 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
202 /* Process base types. */
203 for (i
= 0; i
< n_baselinks
; i
++)
205 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
211 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
220 get_vbase (parent
, binfo
)
224 unsigned int d
= (unsigned int)-1;
225 return get_vbase_1 (parent
, binfo
, &d
);
228 /* Convert EXPR to a virtual base class of type TYPE. We know that
229 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
230 the type of what expr points to has a virtual base of type TYPE. */
233 convert_pointer_to_vbase (type
, expr
)
237 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
238 return convert_pointer_to_real (vb
, expr
);
241 /* Check whether the type given in BINFO is derived from PARENT. If
242 it isn't, return 0. If it is, but the derivation is MI-ambiguous
243 AND protect != 0, emit an error message and return error_mark_node.
245 Otherwise, if TYPE is derived from PARENT, return the actual base
246 information, unless a one of the protection violations below
247 occurs, in which case emit an error message and return error_mark_node.
249 If PROTECT is 1, then check if access to a public field of PARENT
250 would be private. Also check for ambiguity. */
253 get_binfo (parent
, binfo
, protect
)
254 register tree parent
, binfo
;
257 tree type
= NULL_TREE
;
259 tree rval
= NULL_TREE
;
261 if (TREE_CODE (parent
) == TREE_VEC
)
262 parent
= BINFO_TYPE (parent
);
263 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
264 my_friendly_abort (89);
266 if (TREE_CODE (binfo
) == TREE_VEC
)
267 type
= BINFO_TYPE (binfo
);
268 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
271 my_friendly_abort (90);
273 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
277 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
279 return error_mark_node
;
281 else if (dist
== -2 && protect
)
283 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
285 return error_mark_node
;
291 /* This is the newer depth first get_base_distance routine. */
294 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
295 rval_private_ptr
, new_binfo_ptr
, parent
, path_ptr
,
296 protect
, via_virtual_ptr
, via_virtual
,
297 current_scope_in_chain
)
299 int depth
, is_private
, rval
;
300 int *rval_private_ptr
;
301 tree
*new_binfo_ptr
, parent
, *path_ptr
;
302 int protect
, *via_virtual_ptr
, via_virtual
;
303 int current_scope_in_chain
;
309 && !current_scope_in_chain
310 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
311 current_scope_in_chain
= 1;
313 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
318 *rval_private_ptr
= is_private
;
319 *new_binfo_ptr
= binfo
;
320 *via_virtual_ptr
= via_virtual
;
324 int same_object
= (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
325 BINFO_OFFSET (binfo
))
326 && *via_virtual_ptr
&& via_virtual
);
328 if (*via_virtual_ptr
&& via_virtual
==0)
330 *rval_private_ptr
= is_private
;
331 *new_binfo_ptr
= binfo
;
332 *via_virtual_ptr
= via_virtual
;
334 else if (same_object
)
336 if (*rval_private_ptr
&& ! is_private
)
338 *rval_private_ptr
= is_private
;
339 *new_binfo_ptr
= binfo
;
340 *via_virtual_ptr
= via_virtual
;
350 binfos
= BINFO_BASETYPES (binfo
);
351 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
354 /* Process base types. */
355 for (i
= 0; i
< n_baselinks
; i
++)
357 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
359 /* Find any specific instance of a virtual base, when searching with
361 if (BINFO_MARKED (base_binfo
) == 0 || TREE_CODE (parent
) == TREE_VEC
)
366 || (!TREE_VIA_PUBLIC (base_binfo
)
367 && !(TREE_VIA_PROTECTED (base_binfo
)
368 && current_scope_in_chain
)
369 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
370 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
373 /* When searching for a non-virtual, we cannot mark
374 virtually found binfos. */
376 SET_BINFO_MARKED (base_binfo
);
378 #define WATCH_VALUES(rval, via_private) (rval == -1 ? 3 : via_private)
380 was
= WATCH_VALUES (rval
, *via_virtual_ptr
);
381 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
382 rval
, rval_private_ptr
,
383 new_binfo_ptr
, parent
, path_ptr
,
384 protect
, via_virtual_ptr
,
386 current_scope_in_chain
);
387 /* watch for updates; only update if path is good. */
388 if (path_ptr
&& WATCH_VALUES (rval
, *via_virtual_ptr
) != was
)
389 my_friendly_assert (BINFO_INHERITANCE_CHAIN (base_binfo
) == binfo
,
391 if (rval
== -2 && *via_virtual_ptr
== 0)
402 /* Return the number of levels between type PARENT and the type given
403 in BINFO, following the leftmost path to PARENT not found along a
404 virtual path, if there are no real PARENTs (all come from virtual
405 base classes), then follow the leftmost path to PARENT.
407 Return -1 if TYPE is not derived from PARENT.
408 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
410 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
412 If PATH_PTR is non-NULL, then also build the list of types
413 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
416 PARENT can also be a binfo, in which case that exact parent is found
417 and no other. convert_pointer_to_real uses this functionality.
419 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
422 get_base_distance (parent
, binfo
, protect
, path_ptr
)
423 register tree parent
, binfo
;
428 int rval_private
= 0;
429 tree type
= NULL_TREE
;
430 tree new_binfo
= NULL_TREE
;
432 int watch_access
= protect
;
434 /* Should we be completing types here? */
435 if (TREE_CODE (parent
) != TREE_VEC
)
436 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
438 complete_type (TREE_TYPE (parent
));
440 if (TREE_CODE (binfo
) == TREE_VEC
)
441 type
= BINFO_TYPE (binfo
);
442 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
444 type
= complete_type (binfo
);
445 binfo
= TYPE_BINFO (type
);
448 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
,
452 my_friendly_abort (92);
454 if (parent
== type
|| parent
== binfo
)
456 /* If the distance is 0, then we don't really need
457 a path pointer, but we shouldn't let garbage go back. */
466 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
467 &rval_private
, &new_binfo
, parent
,
468 path_ptr
, watch_access
, &via_virtual
, 0,
471 dfs_walk (binfo
, dfs_unmark
, markedp
);
473 /* Access restrictions don't count if we found an ambiguous basetype. */
474 if (rval
== -2 && protect
>= 0)
477 if (rval
&& protect
&& rval_private
)
480 /* find real virtual base classes. */
481 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
482 && parent
== binfo_member (BINFO_TYPE (parent
),
483 CLASSTYPE_VBASECLASSES (type
)))
485 my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent
) == binfo
, 980827);
491 *path_ptr
= new_binfo
;
495 /* Search for a member with name NAME in a multiple inheritance lattice
496 specified by TYPE. If it does not exist, return NULL_TREE.
497 If the member is ambiguously referenced, return `error_mark_node'.
498 Otherwise, return the FIELD_DECL. */
500 /* Do a 1-level search for NAME as a member of TYPE. The caller must
501 figure out whether it can access this field. (Since it is only one
502 level, this is reasonable.) */
505 lookup_field_1 (type
, name
)
510 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
511 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
512 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
513 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
514 the code often worked even when we treated the index as a list
518 field
= TYPE_FIELDS (type
);
520 #ifdef GATHER_STATISTICS
521 n_calls_lookup_field_1
++;
522 #endif /* GATHER_STATISTICS */
525 #ifdef GATHER_STATISTICS
527 #endif /* GATHER_STATISTICS */
528 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
529 if (DECL_NAME (field
) == NULL_TREE
530 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
532 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
536 if (DECL_NAME (field
) == name
)
538 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
539 && DECL_ASSEMBLER_NAME (field
) != NULL
)
540 GNU_xref_ref(current_function_decl
,
541 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
544 field
= TREE_CHAIN (field
);
547 if (name
== _vptr_name
)
549 /* Give the user what s/he thinks s/he wants. */
550 if (TYPE_VIRTUAL_P (type
))
551 return CLASSTYPE_VFIELD (type
);
556 /* There are a number of cases we need to be aware of here:
557 current_class_type current_function_decl
564 Those last two make life interesting. If we're in a function which is
565 itself inside a class, we need decls to go into the fn's decls (our
566 second case below). But if we're in a class and the class itself is
567 inside a function, we need decls to go into the decls for the class. To
568 achieve this last goal, we must see if, when both current_class_ptr and
569 current_function_decl are set, the class was declared inside that
570 function. If so, we know to put the decls into the class's scope. */
575 if (current_function_decl
== NULL_TREE
)
576 return current_class_type
;
577 if (current_class_type
== NULL_TREE
)
578 return current_function_decl
;
579 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
580 return current_function_decl
;
582 return current_class_type
;
585 /* Compute the access of FIELD. This is done by computing
586 the access available to each type in BASETYPES (which comes
587 as a list of [via_public/basetype] in reverse order, namely base
588 class before derived class). The first one which defines a
589 access defines the access for the field. Otherwise, the
590 access of the field is that which occurs normally.
592 Uses global variables CURRENT_CLASS_TYPE and
593 CURRENT_FUNCTION_DECL to use friend relationships
596 This will be static when lookup_fnfield comes into this file.
598 access_public_node means that the field can be accessed by the current lexical
601 access_protected_node means that the field cannot be accessed by the current
602 lexical scope because it is protected.
604 access_private_node means that the field cannot be accessed by the current
605 lexical scope because it is private. */
608 #define PUBLIC_RETURN return (DECL_PUBLIC (field) = 1), access_public_node
609 #define PROTECTED_RETURN return (DECL_PROTECTED (field) = 1), access_protected_node
610 #define PRIVATE_RETURN return (DECL_PRIVATE (field) = 1), access_private_node
612 #define PUBLIC_RETURN return access_public_node
613 #define PROTECTED_RETURN return access_protected_node
614 #define PRIVATE_RETURN return access_private_node
618 /* Disabled with DECL_PUBLIC &c. */
619 static tree previous_scope
= NULL_TREE
;
623 compute_access (basetype_path
, field
)
624 tree basetype_path
, field
;
629 int protected_ok
, via_protected
;
630 extern int flag_access_control
;
632 /* Replaces static decl above. */
636 = ((TREE_CODE (field
) == FUNCTION_DECL
&& DECL_STATIC_FUNCTION_P (field
))
637 || (TREE_CODE (field
) != FUNCTION_DECL
&& TREE_STATIC (field
)));
639 if (! flag_access_control
)
640 return access_public_node
;
642 /* The field lives in the current class. */
643 if (BINFO_TYPE (basetype_path
) == current_class_type
)
644 return access_public_node
;
647 /* Disabled until pushing function scope clears these out. If ever. */
648 /* Make these special cases fast. */
649 if (current_scope () == previous_scope
)
651 if (DECL_PUBLIC (field
))
652 return access_public_node
;
653 if (DECL_PROTECTED (field
))
654 return access_protected_node
;
655 if (DECL_PRIVATE (field
))
656 return access_private_node
;
660 /* We don't currently support access control on nested types. */
661 if (TREE_CODE (field
) == TYPE_DECL
)
662 return access_public_node
;
664 previous_scope
= current_scope ();
666 context
= DECL_REAL_CONTEXT (field
);
668 /* Fields coming from nested anonymous unions have their DECL_CLASS_CONTEXT
669 slot set to the union type rather than the record type containing
670 the anonymous union. */
671 if (context
&& ANON_UNION_TYPE_P (context
)
672 && TREE_CODE (field
) == FIELD_DECL
)
673 context
= TYPE_CONTEXT (context
);
675 /* Virtual function tables are never private. But we should know that
676 we are looking for this, and not even try to hide it. */
677 if (DECL_NAME (field
) && VFIELD_NAME_P (DECL_NAME (field
)) == 1)
680 /* Member found immediately within object. */
681 if (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
)
683 /* Are we (or an enclosing scope) friends with the class that has
685 if (is_friend (context
, previous_scope
))
688 /* If it's private, it's private, you letch. */
689 if (TREE_PRIVATE (field
))
692 /* ARM $11.5. Member functions of a derived class can access the
693 non-static protected members of a base class only through a
694 pointer to the derived class, a reference to it, or an object
695 of it. Also any subsequently derived classes also have
697 else if (TREE_PROTECTED (field
))
699 if (current_class_type
700 && (static_mem
|| DECL_CONSTRUCTOR_P (field
))
701 && ACCESSIBLY_DERIVED_FROM_P (context
, current_class_type
))
710 /* must reverse more than one element */
711 basetype_path
= reverse_path (basetype_path
);
712 types
= basetype_path
;
714 access
= access_default_node
;
715 protected_ok
= static_mem
&& current_class_type
716 && ACCESSIBLY_DERIVED_FROM_P (BINFO_TYPE (types
), current_class_type
);
722 tree type
= BINFO_TYPE (binfo
);
725 /* Friends of a class can see protected members of its bases.
726 Note that classes are their own friends. */
727 if (is_friend (type
, previous_scope
))
733 member
= purpose_member (type
, DECL_ACCESS (field
));
736 access
= TREE_VALUE (member
);
740 types
= BINFO_INHERITANCE_CHAIN (types
);
742 /* If the next type was VIA_PROTECTED, then fields of all remaining
743 classes past that one are *at least* protected. */
746 if (TREE_VIA_PROTECTED (types
))
748 else if (! TREE_VIA_PUBLIC (types
) && ! private_ok
)
750 access
= access_private_node
;
758 /* No special visibilities apply. Use normal rules. */
760 if (access
== access_default_node
)
762 if (is_friend (context
, previous_scope
))
763 access
= access_public_node
;
764 else if (TREE_PRIVATE (field
))
765 access
= access_private_node
;
766 else if (TREE_PROTECTED (field
))
767 access
= access_protected_node
;
769 access
= access_public_node
;
772 if (access
== access_public_node
&& via_protected
)
773 access
= access_protected_node
;
775 if (access
== access_protected_node
&& protected_ok
)
776 access
= access_public_node
;
779 if (access
== access_public_node
)
780 DECL_PUBLIC (field
) = 1;
781 else if (access
== access_protected_node
)
782 DECL_PROTECTED (field
) = 1;
783 else if (access
== access_private_node
)
784 DECL_PRIVATE (field
) = 1;
785 else my_friendly_abort (96);
790 /* Routine to see if the sub-object denoted by the binfo PARENT can be
791 found as a base class and sub-object of the object denoted by
792 BINFO. This routine relies upon binfos not being shared, except
793 for binfos for virtual bases. */
796 is_subobject_of_p (parent
, binfo
)
799 tree binfos
= BINFO_BASETYPES (binfo
);
800 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
805 /* Process and/or queue base types. */
806 for (i
= 0; i
< n_baselinks
; i
++)
808 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
809 if (TREE_VIA_VIRTUAL (base_binfo
))
810 base_binfo
= TYPE_BINFO (BINFO_TYPE (base_binfo
));
811 if (is_subobject_of_p (parent
, base_binfo
))
817 /* See if a one FIELD_DECL hides another. This routine is meant to
818 correspond to ANSI working paper Sept 17, 1992 10p4. The two
819 binfos given are the binfos corresponding to the particular places
820 the FIELD_DECLs are found. This routine relies upon binfos not
821 being shared, except for virtual bases. */
824 hides (hider_binfo
, hidee_binfo
)
825 tree hider_binfo
, hidee_binfo
;
827 /* hider hides hidee, if hider has hidee as a base class and
828 the instance of hidee is a sub-object of hider. The first
829 part is always true is the second part is true.
831 When hider and hidee are the same (two ways to get to the exact
832 same member) we consider either one as hiding the other. */
833 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
836 /* Very similar to lookup_fnfields_1 but it ensures that at least one
837 function was declared inside the class given by TYPE. It really should
838 only return functions that match the given TYPE. */
841 lookup_fnfields_here (type
, name
)
844 int idx
= lookup_fnfields_1 (type
, name
);
847 /* ctors and dtors are always only in the right class. */
850 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
853 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls
)))
854 == TYPE_MAIN_VARIANT (type
))
856 fndecls
= OVL_CHAIN (fndecls
);
861 /* Look for a field named NAME in an inheritance lattice dominated by
862 XBASETYPE. PROTECT is zero if we can avoid computing access
863 information, otherwise it is 1. WANT_TYPE is 1 when we should only
864 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
866 It was not clear what should happen if WANT_TYPE is set, and an
867 ambiguity is found. At least one use (lookup_name) to not see
871 lookup_field (xbasetype
, name
, protect
, want_type
)
872 register tree xbasetype
, name
;
873 int protect
, want_type
;
875 int head
= 0, tail
= 0;
876 tree rval
, rval_binfo
= NULL_TREE
, rval_binfo_h
= NULL_TREE
;
877 tree type
= NULL_TREE
, basetype_chain
, basetype_path
= NULL_TREE
;
878 tree this_v
= access_default_node
;
879 tree entry
, binfo
, binfo_h
;
880 tree own_access
= access_default_node
;
881 int vbase_name_p
= VBASE_NAME_P (name
);
883 /* rval_binfo is the binfo associated with the found member, note,
884 this can be set with useful information, even when rval is not
885 set, because it must deal with ALL members, not just non-function
886 members. It is used for ambiguity checking and the hidden
887 checks. Whereas rval is only set if a proper (not hidden)
888 non-function member is found. */
890 /* rval_binfo_h and binfo_h are binfo values used when we perform the
891 hiding checks, as virtual base classes may not be shared. The strategy
892 is we always go into the binfo hierarchy owned by TYPE_BINFO of
893 virtual base classes, as we cross virtual base class lines. This way
894 we know that binfo of a virtual base class will always == itself when
895 found along any line. (mrs) */
900 /* We cannot search for constructor/destructor names like this. */
901 /* This can't go here, but where should it go? */
902 /* If we are looking for a constructor in a templated type, use the
903 unspecialized name, as that is how we store it. */
904 if (IDENTIFIER_TEMPLATE (name
))
905 name
= constructor_name (name
);
908 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
909 && IDENTIFIER_CLASS_VALUE (name
))
911 tree field
= IDENTIFIER_CLASS_VALUE (name
);
912 if (TREE_CODE (field
) != FUNCTION_DECL
913 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
917 if (TREE_CODE (xbasetype
) == TREE_VEC
)
919 type
= BINFO_TYPE (xbasetype
);
920 basetype_path
= xbasetype
;
922 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
925 basetype_path
= TYPE_BINFO (type
);
926 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
930 my_friendly_abort (97);
932 complete_type (type
);
934 #ifdef GATHER_STATISTICS
935 n_calls_lookup_field
++;
936 #endif /* GATHER_STATISTICS */
938 rval
= lookup_field_1 (type
, name
);
940 if (rval
|| lookup_fnfields_here (type
, name
) >= 0)
946 if (TREE_CODE (rval
) != TYPE_DECL
)
948 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
950 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
955 if (TREE_CODE (rval
) == TYPE_DECL
956 && lookup_fnfields_here (type
, name
) >= 0)
963 if (TREE_PRIVATE (rval
) | TREE_PROTECTED (rval
))
964 this_v
= compute_access (basetype_path
, rval
);
965 if (TREE_CODE (rval
) == CONST_DECL
)
967 if (this_v
== access_private_node
)
968 errstr
= "enum `%D' is a private value of class `%T'";
969 else if (this_v
== access_protected_node
)
970 errstr
= "enum `%D' is a protected value of class `%T'";
974 if (this_v
== access_private_node
)
975 errstr
= "member `%D' is a private member of class `%T'";
976 else if (this_v
== access_protected_node
)
977 errstr
= "member `%D' is a protected member of class `%T'";
981 rval_binfo
= basetype_path
;
985 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
987 /* The ambiguity check relies upon breadth first searching. */
989 search_stack
= push_search_level (search_stack
, &search_obstack
);
990 binfo
= basetype_path
;
995 tree binfos
= BINFO_BASETYPES (binfo
);
996 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
999 /* Process and/or queue base types. */
1000 for (i
= 0; i
< n_baselinks
; i
++)
1002 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1003 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1007 SET_BINFO_FIELDS_MARKED (base_binfo
);
1008 btypes
= scratch_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1009 if (TREE_VIA_VIRTUAL (base_binfo
))
1010 btypes
= scratch_tree_cons (NULL_TREE
,
1011 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1014 btypes
= scratch_tree_cons (NULL_TREE
,
1015 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1017 obstack_ptr_grow (&search_obstack
, btypes
);
1019 if (tail
>= search_stack
->limit
)
1020 my_friendly_abort (98);
1024 /* Process head of queue, if one exists. */
1028 basetype_chain
= search_stack
->first
[head
++];
1029 binfo_h
= TREE_VALUE (basetype_chain
);
1030 basetype_chain
= TREE_CHAIN (basetype_chain
);
1031 basetype_path
= TREE_VALUE (basetype_chain
);
1032 if (TREE_CHAIN (basetype_chain
))
1033 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
)
1034 == TREE_VALUE (TREE_CHAIN (basetype_chain
)),
1037 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
)
1038 == NULL_TREE
, 980827);
1040 binfo
= basetype_path
;
1041 type
= BINFO_TYPE (binfo
);
1043 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1044 and we do find NAME in TYPE, verify that such a second
1045 sighting is in fact valid. */
1047 nval
= lookup_field_1 (type
, name
);
1049 if (nval
|| lookup_fnfields_here (type
, name
)>=0)
1051 if (nval
&& nval
== rval
&& SHARED_MEMBER_P (nval
))
1053 /* This is ok, the member found is the same [class.ambig] */
1055 else if (rval_binfo
&& hides (rval_binfo_h
, binfo_h
))
1057 /* This is ok, the member found is in rval_binfo, not
1060 else if (rval_binfo
==NULL_TREE
|| hides (binfo_h
, rval_binfo_h
))
1062 /* This is ok, the member found is here (binfo), not in
1068 this_v
= compute_access (basetype_path
, rval
);
1069 /* These may look ambiguous, but they really are not. */
1075 /* Undo finding it before, as something else hides it. */
1079 rval_binfo_h
= binfo_h
;
1083 /* This is ambiguous. */
1084 errstr
= "request for member `%D' is ambiguous";
1091 tree
*tp
= search_stack
->first
;
1092 tree
*search_tail
= tp
+ tail
;
1096 type
= BINFO_TYPE (rval_binfo
);
1102 if (TREE_CODE (rval
) != TYPE_DECL
)
1104 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
1106 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
1111 if (TREE_CODE (rval
) == TYPE_DECL
1112 && lookup_fnfields_here (type
, name
) >= 0)
1118 if (rval
== NULL_TREE
)
1121 /* If this FIELD_DECL defines its own access level, deal with that. */
1122 if (rval
&& errstr
== 0
1124 && DECL_LANG_SPECIFIC (rval
)
1125 && DECL_ACCESS (rval
))
1127 while (tp
< search_tail
)
1129 /* If is possible for one of the derived types on the path to
1130 have defined special access for this field. Look for such
1131 declarations and report an error if a conflict is found. */
1132 tree new_v
= NULL_TREE
;
1134 if (this_v
!= access_default_node
)
1135 new_v
= compute_access (TREE_VALUE (TREE_CHAIN (*tp
)), rval
);
1136 if (this_v
!= access_default_node
&& new_v
!= this_v
)
1138 errstr
= "conflicting access to member `%D'";
1139 this_v
= access_default_node
;
1142 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1148 while (tp
< search_tail
)
1150 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1155 search_stack
= pop_search_level (search_stack
);
1159 if (own_access
== access_private_node
)
1160 errstr
= "member `%D' declared private";
1161 else if (own_access
== access_protected_node
)
1162 errstr
= "member `%D' declared protected";
1163 else if (this_v
== access_private_node
)
1164 errstr
= TREE_PRIVATE (rval
)
1165 ? "member `%D' is private"
1166 : "member `%D' is from private base class";
1167 else if (this_v
== access_protected_node
)
1168 errstr
= TREE_PROTECTED (rval
)
1169 ? "member `%D' is protected"
1170 : "member `%D' is from protected base class";
1176 /* If we are not interested in ambiguities, don't report them,
1177 just return NULL_TREE. */
1182 if (errstr
&& protect
)
1184 cp_error (errstr
, name
, type
);
1185 rval
= error_mark_node
;
1188 /* Do implicit typename stuff. */
1189 if (rval
&& TREE_CODE (rval
) == TYPE_DECL
1190 && ! DECL_ARTIFICIAL (rval
)
1191 && processing_template_decl
1192 && ! currently_open_class (BINFO_TYPE (rval_binfo
))
1193 && uses_template_parms (type
))
1196 for (; ; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
1197 if (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
1198 || (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
))
1199 == current_class_type
))
1202 entry
= make_typename_type (BINFO_TYPE (binfo
), name
);
1203 TREE_TYPE (entry
) = TREE_TYPE (rval
);
1204 rval
= TYPE_MAIN_DECL (entry
);
1210 /* Try to find NAME inside a nested class. */
1213 lookup_nested_field (name
, complain
)
1219 tree id
= NULL_TREE
;
1220 if (TYPE_MAIN_DECL (current_class_type
))
1222 /* Climb our way up the nested ladder, seeing if we're trying to
1223 modify a field in an enclosing class. If so, we should only
1224 be able to modify if it's static. */
1225 for (t
= TYPE_MAIN_DECL (current_class_type
);
1226 t
&& DECL_CONTEXT (t
);
1227 t
= TYPE_MAIN_DECL (DECL_CONTEXT (t
)))
1229 if (TREE_CODE (DECL_CONTEXT (t
)) != RECORD_TYPE
)
1232 /* N.B.: lookup_field will do the access checking for us */
1233 id
= lookup_field (DECL_CONTEXT (t
), name
, complain
, 0);
1234 if (id
== error_mark_node
)
1240 if (id
!= NULL_TREE
)
1242 if (TREE_CODE (id
) == FIELD_DECL
1243 && ! TREE_STATIC (id
)
1244 && TREE_TYPE (id
) != error_mark_node
)
1248 /* At parse time, we don't want to give this error, since
1249 we won't have enough state to make this kind of
1250 decision properly. But there are times (e.g., with
1251 enums in nested classes) when we do need to call
1252 this fn at parse time. So, in those cases, we pass
1253 complain as a 0 and just return a NULL_TREE. */
1254 cp_error ("assignment to non-static member `%D' of enclosing class `%T'",
1255 id
, DECL_CONTEXT (t
));
1256 /* Mark this for do_identifier(). It would otherwise
1257 claim that the variable was undeclared. */
1258 TREE_TYPE (id
) = error_mark_node
;
1274 /* TYPE is a class type. Return the index of the fields within
1275 the method vector with name NAME, or -1 is no such field exists. */
1278 lookup_fnfields_1 (type
, name
)
1281 register tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1283 if (method_vec
!= 0)
1285 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1286 register tree
*end
= TREE_VEC_END (method_vec
);
1288 #ifdef GATHER_STATISTICS
1289 n_calls_lookup_fnfields_1
++;
1290 #endif /* GATHER_STATISTICS */
1292 /* Constructors are first... */
1293 if (*methods
&& name
== ctor_identifier
)
1296 /* and destructors are second. */
1297 if (*++methods
&& name
== dtor_identifier
)
1300 while (++methods
!= end
)
1302 #ifdef GATHER_STATISTICS
1303 n_outer_fields_searched
++;
1304 #endif /* GATHER_STATISTICS */
1305 if (DECL_NAME (OVL_CURRENT (*methods
)) == name
)
1309 /* If we didn't find it, it might have been a template
1310 conversion operator. (Note that we don't look for this case
1311 above so that we will always find specializations first.) */
1313 && IDENTIFIER_TYPENAME_P (name
))
1315 methods
= &TREE_VEC_ELT (method_vec
, 0) + 1;
1317 while (++methods
!= end
)
1319 if (TREE_CODE (OVL_CURRENT (*methods
)) == TEMPLATE_DECL
1320 && IDENTIFIER_TYPENAME_P (DECL_NAME (OVL_CURRENT (*methods
))))
1326 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1332 /* Starting from BASETYPE, return a TREE_BASELINK-like object
1333 which gives the following information (in a list):
1335 TREE_TYPE: list of basetypes needed to get to...
1336 TREE_VALUE: list of all functions in a given type
1337 which have name NAME.
1339 No access information is computed by this function,
1340 other then to adorn the list of basetypes with
1343 If there are two ways to find a name (two members), if COMPLAIN is
1344 non-zero, then error_mark_node is returned, and an error message is
1345 printed, otherwise, just an error_mark_node is returned.
1347 As a special case, is COMPLAIN is -1, we don't complain, and we
1348 don't return error_mark_node, but rather the complete list of
1349 virtuals. This is used by get_virtuals_named_this. */
1352 lookup_fnfields (basetype_path
, name
, complain
)
1353 tree basetype_path
, name
;
1356 int head
= 0, tail
= 0;
1357 tree type
, rval
, rval_binfo
= NULL_TREE
, rvals
= NULL_TREE
;
1358 tree rval_binfo_h
= NULL_TREE
, binfo
, basetype_chain
, binfo_h
;
1359 int idx
, find_all
= 0;
1361 /* rval_binfo is the binfo associated with the found member, note,
1362 this can be set with useful information, even when rval is not
1363 set, because it must deal with ALL members, not just function
1364 members. It is used for ambiguity checking and the hidden
1365 checks. Whereas rval is only set if a proper (not hidden)
1366 function member is found. */
1368 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1369 hiding checks, as virtual base classes may not be shared. The strategy
1370 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1371 virtual base classes, as we cross virtual base class lines. This way
1372 we know that binfo of a virtual base class will always == itself when
1373 found along any line. (mrs) */
1375 /* For now, don't try this. */
1376 int protect
= complain
;
1383 protect
= complain
= 0;
1387 /* We cannot search for constructor/destructor names like this. */
1388 /* This can't go here, but where should it go? */
1389 /* If we are looking for a constructor in a templated type, use the
1390 unspecialized name, as that is how we store it. */
1391 if (IDENTIFIER_TEMPLATE (name
))
1392 name
= constructor_name (name
);
1395 binfo
= basetype_path
;
1397 type
= complete_type (BINFO_TYPE (basetype_path
));
1399 #ifdef GATHER_STATISTICS
1400 n_calls_lookup_fnfields
++;
1401 #endif /* GATHER_STATISTICS */
1403 idx
= lookup_fnfields_here (type
, name
);
1404 if (idx
>= 0 || lookup_field_1 (type
, name
))
1406 rval_binfo
= basetype_path
;
1407 rval_binfo_h
= rval_binfo
;
1412 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1413 rvals
= scratch_tree_cons (basetype_path
, rval
, rvals
);
1414 if (BINFO_BASETYPES (binfo
) && CLASSTYPE_BASELINK_VEC (type
))
1415 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1421 if (name
== ctor_identifier
|| name
== dtor_identifier
)
1423 /* Don't allow lookups of constructors and destructors to go
1424 deeper than the first place we look. */
1428 if (basetype_path
== TYPE_BINFO (type
))
1430 basetype_chain
= CLASSTYPE_BINFO_AS_LIST (type
);
1431 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
1435 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
1437 /* The ambiguity check relies upon breadth first searching. */
1439 search_stack
= push_search_level (search_stack
, &search_obstack
);
1440 binfo
= basetype_path
;
1445 tree binfos
= BINFO_BASETYPES (binfo
);
1446 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1449 /* Process and/or queue base types. */
1450 for (i
= 0; i
< n_baselinks
; i
++)
1452 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1453 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1457 SET_BINFO_FIELDS_MARKED (base_binfo
);
1458 btypes
= scratch_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1459 if (TREE_VIA_VIRTUAL (base_binfo
))
1460 btypes
= scratch_tree_cons (NULL_TREE
,
1461 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1464 btypes
= scratch_tree_cons (NULL_TREE
,
1465 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1467 obstack_ptr_grow (&search_obstack
, btypes
);
1469 if (tail
>= search_stack
->limit
)
1470 my_friendly_abort (99);
1474 /* Process head of queue, if one exists. */
1478 basetype_chain
= search_stack
->first
[head
++];
1479 binfo_h
= TREE_VALUE (basetype_chain
);
1480 basetype_chain
= TREE_CHAIN (basetype_chain
);
1481 basetype_path
= TREE_VALUE (basetype_chain
);
1482 if (TREE_CHAIN (basetype_chain
))
1483 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
)
1484 == TREE_VALUE (TREE_CHAIN (basetype_chain
)),
1487 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
)
1488 == NULL_TREE
, 980827);
1490 binfo
= basetype_path
;
1491 type
= BINFO_TYPE (binfo
);
1493 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1494 and we do find NAME in TYPE, verify that such a second
1495 sighting is in fact valid. */
1497 idx
= lookup_fnfields_here (type
, name
);
1499 if (idx
>= 0 || (lookup_field_1 (type
, name
)!=NULL_TREE
&& !find_all
))
1501 if (rval_binfo
&& !find_all
&& hides (rval_binfo_h
, binfo_h
))
1503 /* This is ok, the member found is in rval_binfo, not
1506 else if (rval_binfo
==NULL_TREE
|| find_all
|| hides (binfo_h
, rval_binfo_h
))
1508 /* This is ok, the member found is here (binfo), not in
1512 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1513 /* Note, rvals can only be previously set if find_all is
1515 rvals
= scratch_tree_cons (basetype_path
, rval
, rvals
);
1516 if (TYPE_BINFO_BASETYPES (type
)
1517 && CLASSTYPE_BASELINK_VEC (type
))
1518 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1522 /* Undo finding it before, as something else hides it. */
1527 rval_binfo_h
= binfo_h
;
1531 /* This is ambiguous. */
1532 errstr
= "request for method `%D' is ambiguous";
1533 rvals
= error_mark_node
;
1539 tree
*tp
= search_stack
->first
;
1540 tree
*search_tail
= tp
+ tail
;
1542 while (tp
< search_tail
)
1544 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1548 search_stack
= pop_search_level (search_stack
);
1550 if (errstr
&& protect
)
1552 cp_error (errstr
, name
);
1553 rvals
= error_mark_node
;
1559 /* Look for a field or function named NAME in an inheritance lattice
1560 dominated by XBASETYPE. PROTECT is zero if we can avoid computing
1561 access information, otherwise it is 1. WANT_TYPE is 1 when we should
1562 only return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE. */
1565 lookup_member (xbasetype
, name
, protect
, want_type
)
1566 tree xbasetype
, name
;
1567 int protect
, want_type
;
1569 tree ret
, basetype_path
;
1571 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1572 basetype_path
= xbasetype
;
1573 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1575 basetype_path
= TYPE_BINFO (xbasetype
);
1576 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
)
1577 == NULL_TREE
, 980827);
1580 my_friendly_abort (97);
1582 ret
= lookup_field (basetype_path
, name
, protect
, want_type
);
1583 if (! ret
&& ! want_type
)
1584 ret
= lookup_fnfields (basetype_path
, name
, protect
);
1588 /* BREADTH-FIRST SEARCH ROUTINES. */
1590 /* Search a multiple inheritance hierarchy by breadth-first search.
1592 BINFO is an aggregate type, possibly in a multiple-inheritance hierarchy.
1593 TESTFN is a function, which, if true, means that our condition has been met,
1594 and its return value should be returned.
1595 QFN, if non-NULL, is a predicate dictating whether the type should
1598 static HOST_WIDE_INT
1599 breadth_first_search (binfo
, testfn
, qfn
)
1601 int (*testfn
) PROTO((tree
, int));
1602 int (*qfn
) PROTO((tree
, int));
1604 int head
= 0, tail
= 0;
1607 search_stack
= push_search_level (search_stack
, &search_obstack
);
1611 tree binfos
= BINFO_BASETYPES (binfo
);
1612 int 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
);
1620 if (BINFO_MARKED (base_binfo
) == 0
1621 && (qfn
== 0 || (*qfn
) (binfo
, i
)))
1623 SET_BINFO_MARKED (base_binfo
);
1624 obstack_ptr_grow (&search_obstack
, binfo
);
1625 obstack_ptr_grow (&search_obstack
, (HOST_WIDE_INT
) i
);
1627 if (tail
>= search_stack
->limit
)
1628 my_friendly_abort (100);
1631 /* Process head of queue, if one exists. */
1638 binfo
= search_stack
->first
[head
++];
1639 i
= (HOST_WIDE_INT
) search_stack
->first
[head
++];
1640 if ((rval
= (*testfn
) (binfo
, i
)))
1642 binfo
= BINFO_BASETYPE (binfo
, i
);
1645 tree
*tp
= search_stack
->first
;
1646 tree
*search_tail
= tp
+ tail
;
1647 while (tp
< search_tail
)
1650 int i
= (HOST_WIDE_INT
)(*tp
++);
1651 CLEAR_BINFO_MARKED (BINFO_BASETYPE (binfo
, i
));
1655 search_stack
= pop_search_level (search_stack
);
1659 /* Functions to use in breadth first searches. */
1660 typedef int (*pfi
) PROTO((tree
, int));
1662 static tree declarator
;
1665 get_virtuals_named_this (binfo
)
1670 fields
= lookup_fnfields (binfo
, declarator
, -1);
1671 /* fields cannot be error_mark_node */
1676 /* Get to the function decls, and return the first virtual function
1677 with this name, if there is one. */
1682 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
1683 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
1685 fields
= next_baselink (fields
);
1691 get_virtual_destructor (binfo
, i
)
1695 tree type
= BINFO_TYPE (binfo
);
1697 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
1698 if (TYPE_HAS_DESTRUCTOR (type
)
1699 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
1700 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
1705 tree_has_any_destructor_p (binfo
, i
)
1709 tree type
= BINFO_TYPE (binfo
);
1711 type
= BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo
), i
));
1712 return TYPE_NEEDS_DESTRUCTOR (type
);
1715 /* Returns > 0 if a function with type DRETTYPE overriding a function
1716 with type BRETTYPE is covariant, as defined in [class.virtual].
1718 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1719 adjustment), or -1 if pedantically invalid covariance. */
1722 covariant_return_p (brettype
, drettype
)
1723 tree brettype
, drettype
;
1727 if (TREE_CODE (brettype
) == FUNCTION_DECL
1728 || TREE_CODE (brettype
) == THUNK_DECL
)
1730 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
1731 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
1733 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
1735 brettype
= TREE_TYPE (brettype
);
1736 drettype
= TREE_TYPE (drettype
);
1739 if (comptypes (brettype
, drettype
, 1))
1742 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
1743 && (TREE_CODE (brettype
) == POINTER_TYPE
1744 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
1745 && TYPE_READONLY (brettype
) == TYPE_READONLY (drettype
)
1746 && TYPE_VOLATILE (brettype
) == TYPE_VOLATILE (drettype
)))
1749 if (! can_convert (brettype
, drettype
))
1752 brettype
= TREE_TYPE (brettype
);
1753 drettype
= TREE_TYPE (drettype
);
1755 /* If not pedantic, allow any standard pointer conversion. */
1756 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
1759 binfo
= get_binfo (brettype
, drettype
, 1);
1761 /* If we get an error_mark_node from get_binfo, it already complained,
1762 so let's just succeed. */
1763 if (binfo
== error_mark_node
)
1766 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
1771 /* Given a class type TYPE, and a function decl FNDECL, look for a
1772 virtual function in TYPE's hierarchy which FNDECL could match as a
1773 virtual function. It doesn't matter which one we find.
1775 DTORP is nonzero if we are looking for a destructor. Destructors
1776 need special treatment because they do not match by name. */
1779 get_matching_virtual (binfo
, fndecl
, dtorp
)
1783 tree tmp
= NULL_TREE
;
1786 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
1787 /* In [temp.mem] we have:
1789 A specialization of a member function template does not
1790 override a virtual function from a base class. */
1793 /* Breadth first search routines start searching basetypes
1794 of TYPE, so we must perform first ply of search here. */
1797 if (tree_has_any_destructor_p (binfo
, -1))
1798 tmp
= get_virtual_destructor (binfo
, -1);
1803 tmp
= (tree
) breadth_first_search (binfo
,
1804 (pfi
) get_virtual_destructor
,
1805 tree_has_any_destructor_p
);
1810 tree drettype
, dtypes
, btypes
, instptr_type
;
1811 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
1812 tree baselink
, best
= NULL_TREE
;
1813 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
1815 declarator
= DECL_NAME (fndecl
);
1816 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
1819 baselink
= get_virtuals_named_this (binfo
);
1820 if (baselink
== NULL_TREE
)
1823 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
1824 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1825 if (DECL_STATIC_FUNCTION_P (fndecl
))
1826 instptr_type
= NULL_TREE
;
1828 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
1830 for (; baselink
; baselink
= next_baselink (baselink
))
1833 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
1835 tmp
= OVL_CURRENT (tmps
);
1836 if (! DECL_VINDEX (tmp
))
1839 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
1840 if (instptr_type
== NULL_TREE
)
1842 if (compparms (TREE_CHAIN (btypes
), dtypes
, 3))
1843 /* Caller knows to give error in this case. */
1848 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (btypes
)))
1849 == TYPE_READONLY (instptr_type
))
1850 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
), 3))
1852 tree brettype
= TREE_TYPE (TREE_TYPE (tmp
));
1853 if (comptypes (brettype
, drettype
, 1))
1855 else if ((i
= covariant_return_p (brettype
, drettype
)))
1858 sorry ("adjusting pointers for covariant returns");
1860 if (pedantic
&& i
== -1)
1862 cp_pedwarn_at ("invalid covariant return type for `%#D' (must be pointer or reference to class)", fndecl
);
1863 cp_pedwarn_at (" overriding `%#D'", tmp
);
1866 else if (IS_AGGR_TYPE_2 (brettype
, drettype
)
1867 && comptypes (brettype
, drettype
, 0))
1869 error ("invalid covariant return type (must use pointer or reference)");
1870 cp_error_at (" overriding `%#D'", tmp
);
1871 cp_error_at (" with `%#D'", fndecl
);
1873 else if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
)
1875 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl
);
1876 cp_error_at (" overriding definition as `%#D'", tmp
);
1877 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
1882 /* If not at the end */
1894 /* Return the list of virtual functions which are abstract in type
1895 TYPE that come from non virtual base classes. See
1896 expand_direct_vtbls_init for the style of search we do. */
1899 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
1902 tree abstract_virtuals
;
1904 tree binfos
= BINFO_BASETYPES (binfo
);
1905 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1907 for (i
= 0; i
< n_baselinks
; i
++)
1909 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1910 int is_not_base_vtable
1911 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
1912 if (! TREE_VIA_VIRTUAL (base_binfo
))
1914 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
1917 /* Should we use something besides CLASSTYPE_VFIELDS? */
1918 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
1920 tree virtuals
= BINFO_VIRTUALS (binfo
);
1922 skip_rtti_stuff (&virtuals
);
1926 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
1927 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
1928 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
1929 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
1930 virtuals
= TREE_CHAIN (virtuals
);
1933 return abstract_virtuals
;
1936 /* Return the list of virtual functions which are abstract in type TYPE.
1937 This information is cached, and so must be built on a
1938 non-temporary obstack. */
1941 get_abstract_virtuals (type
)
1945 tree abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (type
);
1947 /* First get all from non-virtual bases. */
1949 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
1951 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
1953 tree virtuals
= BINFO_VIRTUALS (vbases
);
1955 skip_rtti_stuff (&virtuals
);
1959 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
1960 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
1961 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
1962 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
1963 virtuals
= TREE_CHAIN (virtuals
);
1966 return nreverse (abstract_virtuals
);
1969 /* For the type TYPE, return a list of member functions available from
1970 base classes with name NAME. The TREE_VALUE of the list is a chain of
1971 member functions with name NAME. The TREE_PURPOSE of the list is a
1972 basetype, or a list of base types (in reverse order) which were
1973 traversed to reach the chain of member functions. If we reach a base
1974 type which provides a member function of name NAME, and which has at
1975 most one base type itself, then we can terminate the search. */
1978 get_baselinks (type_as_binfo_list
, type
, name
)
1979 tree type_as_binfo_list
;
1982 int head
= 0, tail
= 0, idx
;
1983 tree rval
= 0, nval
= 0;
1984 tree basetypes
= type_as_binfo_list
;
1985 tree binfo
= TYPE_BINFO (type
);
1987 search_stack
= push_search_level (search_stack
, &search_obstack
);
1991 tree binfos
= BINFO_BASETYPES (binfo
);
1992 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1994 /* Process and/or queue base types. */
1995 for (i
= 0; i
< n_baselinks
; i
++)
1997 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2000 btypes
= hash_tree_cons (TREE_VIA_PUBLIC (base_binfo
),
2001 TREE_VIA_VIRTUAL (base_binfo
),
2002 TREE_VIA_PROTECTED (base_binfo
),
2003 NULL_TREE
, base_binfo
,
2005 obstack_ptr_grow (&search_obstack
, btypes
);
2006 search_stack
->first
= (tree
*)obstack_base (&search_obstack
);
2011 /* Process head of queue, if one exists. */
2015 basetypes
= search_stack
->first
[head
++];
2016 binfo
= TREE_VALUE (basetypes
);
2017 type
= BINFO_TYPE (binfo
);
2018 idx
= lookup_fnfields_1 (type
, name
);
2021 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
2022 rval
= hash_tree_cons (0, 0, 0, basetypes
, nval
, rval
);
2023 if (TYPE_BINFO_BASETYPES (type
) == 0)
2025 else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
)) == 1)
2027 if (CLASSTYPE_BASELINK_VEC (type
))
2028 TREE_TYPE (rval
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
2035 search_stack
= pop_search_level (search_stack
);
2040 next_baselink (baselink
)
2043 tree tmp
= TREE_TYPE (baselink
);
2044 baselink
= TREE_CHAIN (baselink
);
2047 /* @@ does not yet add previous base types. */
2048 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2050 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2051 tmp
= TREE_CHAIN (tmp
);
2056 /* DEPTH-FIRST SEARCH ROUTINES. */
2058 /* This routine converts a pointer to be a pointer of an immediate
2059 base class. The normal convert_pointer_to routine would diagnose
2060 the conversion as ambiguous, under MI code that has the base class
2061 as an ambiguous base class. */
2064 convert_pointer_to_single_level (to_type
, expr
)
2067 tree binfo_of_derived
;
2070 binfo_of_derived
= TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
)));
2071 last
= get_binfo (to_type
, TREE_TYPE (TREE_TYPE (expr
)), 0);
2072 my_friendly_assert (BINFO_INHERITANCE_CHAIN (last
) == binfo_of_derived
,
2074 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo_of_derived
) == NULL_TREE
,
2076 return build_vbase_path (PLUS_EXPR
, build_pointer_type (to_type
), expr
,
2080 /* The main function which implements depth first search.
2082 This routine has to remember the path it walked up, when
2083 dfs_init_vbase_pointers is the work function, as otherwise there
2084 would be no record. */
2087 dfs_walk (binfo
, fn
, qfn
)
2089 void (*fn
) PROTO((tree
));
2090 int (*qfn
) PROTO((tree
));
2092 tree binfos
= BINFO_BASETYPES (binfo
);
2093 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2095 for (i
= 0; i
< n_baselinks
; i
++)
2097 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2099 if (qfn
== 0 || (*qfn
)(base_binfo
))
2101 if (TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TYPE_PARM
2102 || TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TEMPLATE_PARM
)
2104 else if (fn
== dfs_init_vbase_pointers
)
2106 /* When traversing an arbitrary MI hierarchy, we need to keep
2107 a record of the path we took to get down to the final base
2108 type, as otherwise there would be no record of it, and just
2109 trying to blindly convert at the bottom would be ambiguous.
2111 The easiest way is to do the conversions one step at a time,
2112 as we know we want the immediate base class at each step.
2114 The only special trick to converting one step at a time,
2115 is that when we hit the last virtual base class, we must
2116 use the SLOT value for it, and not use the normal convert
2117 routine. We use the last virtual base class, as in our
2118 implementation, we have pointers to all virtual base
2119 classes in the base object. */
2121 tree saved_vbase_decl_ptr_intermediate
2122 = vbase_decl_ptr_intermediate
;
2124 if (TREE_VIA_VIRTUAL (base_binfo
))
2126 /* No need for the conversion here, as we know it is the
2128 vbase_decl_ptr_intermediate
2129 = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
));
2133 vbase_decl_ptr_intermediate
2134 = convert_pointer_to_single_level (BINFO_TYPE (base_binfo
),
2135 vbase_decl_ptr_intermediate
);
2138 dfs_walk (base_binfo
, fn
, qfn
);
2140 vbase_decl_ptr_intermediate
= saved_vbase_decl_ptr_intermediate
;
2143 dfs_walk (base_binfo
, fn
, qfn
);
2150 static int markedp (binfo
) tree binfo
;
2151 { return BINFO_MARKED (binfo
); }
2152 static int unmarkedp (binfo
) tree binfo
;
2153 { return BINFO_MARKED (binfo
) == 0; }
2156 static int bfs_markedp (binfo
, i
) tree binfo
; int i
;
2157 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2158 static int bfs_unmarkedp (binfo
, i
) tree binfo
; int i
;
2159 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2160 static int bfs_marked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2161 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2162 static int bfs_unmarked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2163 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2164 static int bfs_marked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2165 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2166 static int bfs_unmarked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2167 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2170 static int marked_vtable_pathp (binfo
) tree binfo
;
2171 { return BINFO_VTABLE_PATH_MARKED (binfo
); }
2172 static int unmarked_vtable_pathp (binfo
) tree binfo
;
2173 { return BINFO_VTABLE_PATH_MARKED (binfo
) == 0; }
2174 static int marked_new_vtablep (binfo
) tree binfo
;
2175 { return BINFO_NEW_VTABLE_MARKED (binfo
); }
2176 static int unmarked_new_vtablep (binfo
) tree binfo
;
2177 { return BINFO_NEW_VTABLE_MARKED (binfo
) == 0; }
2178 static int marked_pushdecls_p (binfo
) tree binfo
;
2179 { return BINFO_PUSHDECLS_MARKED (binfo
); }
2180 static int unmarked_pushdecls_p (binfo
) tree binfo
;
2181 { return BINFO_PUSHDECLS_MARKED (binfo
) == 0; }
2184 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2185 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2188 static int dfs_debug_unmarkedp (binfo
) tree binfo
;
2189 { return CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
)) == 0; }
2191 /* The worker functions for `dfs_walk'. These do not need to
2192 test anything (vis a vis marking) if they are paired with
2193 a predicate function (above). */
2197 dfs_mark (binfo
) tree binfo
;
2198 { SET_BINFO_MARKED (binfo
); }
2202 dfs_unmark (binfo
) tree binfo
;
2203 { CLEAR_BINFO_MARKED (binfo
); }
2207 dfs_mark_vtable_path (binfo
) tree binfo
;
2208 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2211 dfs_unmark_vtable_path (binfo
) tree binfo
;
2212 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2215 dfs_mark_new_vtable (binfo
) tree binfo
;
2216 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2219 dfs_unmark_new_vtable (binfo
) tree binfo
;
2220 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2223 dfs_clear_search_slot (binfo
) tree binfo
;
2224 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2228 dfs_debug_mark (binfo
)
2231 tree t
= BINFO_TYPE (binfo
);
2233 /* Use heuristic that if there are virtual functions,
2234 ignore until we see a non-inline virtual function. */
2235 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2237 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2242 /* If interface info is known, either we've already emitted the debug
2243 info or we don't need to. */
2244 if (CLASSTYPE_INTERFACE_KNOWN (t
)
2245 || (write_virtuals
== 2 && TYPE_VIRTUAL_P (t
)))
2248 /* If debug info is requested from this context for this type, supply it.
2249 If debug info is requested from another context for this type,
2250 see if some third context can supply it. */
2251 if (current_function_decl
== NULL_TREE
2252 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2254 if (TREE_VEC_ELT (methods
, 1))
2255 methods
= TREE_VEC_ELT (methods
, 1);
2256 else if (TREE_VEC_ELT (methods
, 0))
2257 methods
= TREE_VEC_ELT (methods
, 0);
2259 methods
= TREE_VEC_ELT (methods
, 2);
2260 methods
= OVL_CURRENT (methods
);
2263 if (DECL_VINDEX (methods
)
2264 && DECL_THIS_INLINE (methods
) == 0
2265 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2267 /* Somebody, somewhere is going to have to define this
2268 virtual function. When they do, they will provide
2269 the debugging info. */
2272 methods
= TREE_CHAIN (methods
);
2275 /* We cannot rely on some alien method to solve our problems,
2276 so we must write out the debug info ourselves. */
2277 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2278 rest_of_type_compilation (t
, toplevel_bindings_p ());
2281 /* Attach to the type of the virtual base class, the pointer to the
2282 virtual base class, given the global pointer vbase_decl_ptr.
2284 We use the global vbase_types. ICK! */
2287 dfs_find_vbases (binfo
)
2290 tree binfos
= BINFO_BASETYPES (binfo
);
2291 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2293 for (i
= n_baselinks
-1; i
>= 0; i
--)
2295 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2297 if (TREE_VIA_VIRTUAL (base_binfo
)
2298 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2300 tree vbase
= BINFO_TYPE (base_binfo
);
2301 tree binfo
= binfo_member (vbase
, vbase_types
);
2303 CLASSTYPE_SEARCH_SLOT (vbase
)
2304 = build (PLUS_EXPR
, build_pointer_type (vbase
),
2305 vbase_decl_ptr
, BINFO_OFFSET (binfo
));
2308 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2309 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2313 dfs_init_vbase_pointers (binfo
)
2316 tree type
= BINFO_TYPE (binfo
);
2317 tree fields
= TYPE_FIELDS (type
);
2318 tree this_vbase_ptr
;
2320 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2323 /* See finish_struct_1 for when we can enable this. */
2324 /* If we have a vtable pointer first, skip it. */
2325 if (VFIELD_NAME_P (DECL_NAME (fields
)))
2326 fields
= TREE_CHAIN (fields
);
2329 if (fields
== NULL_TREE
2330 || DECL_NAME (fields
) == NULL_TREE
2331 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2334 this_vbase_ptr
= vbase_decl_ptr_intermediate
;
2336 if (build_pointer_type (type
) != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2337 my_friendly_abort (125);
2339 while (fields
&& DECL_NAME (fields
)
2340 && VBASE_NAME_P (DECL_NAME (fields
)))
2342 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2343 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2344 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2345 vbase_init_result
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2347 build_modify_expr (ref
, NOP_EXPR
, init
),
2349 fields
= TREE_CHAIN (fields
);
2353 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2354 times, just NEW_VTABLE, but optimizer should make both with equal
2355 efficiency (though it does not currently). */
2358 dfs_clear_vbase_slots (binfo
)
2361 tree type
= BINFO_TYPE (binfo
);
2362 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2363 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2364 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2368 init_vbase_pointers (type
, decl_ptr
)
2372 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2374 int old_flag
= flag_this_is_variable
;
2375 tree binfo
= TYPE_BINFO (type
);
2376 flag_this_is_variable
= -2;
2377 vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2378 vbase_decl_ptr
= vbase_decl_ptr_intermediate
= decl_ptr
;
2379 vbase_init_result
= NULL_TREE
;
2380 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
);
2381 dfs_walk (binfo
, dfs_init_vbase_pointers
, marked_vtable_pathp
);
2382 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
2383 flag_this_is_variable
= old_flag
;
2384 return vbase_init_result
;
2389 /* get the virtual context (the vbase that directly contains the
2390 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2391 or NULL_TREE if there is none.
2393 FNDECL must come from a virtual table from a virtual base to ensure that
2394 there is only one possible DECL_CLASS_CONTEXT.
2396 We know that if there is more than one place (binfo) the fndecl that the
2397 declared, they all refer to the same binfo. See get_class_offset_1 for
2398 the check that ensures this. */
2401 virtual_context (fndecl
, t
, vbase
)
2402 tree fndecl
, t
, vbase
;
2405 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2407 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2408 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2412 /* Not sure if checking path == vbase is necessary here, but just in
2414 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2415 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2416 path
= BINFO_INHERITANCE_CHAIN (path
);
2419 /* This shouldn't happen, I don't want errors! */
2420 warning ("recoverable compiler error, fixups for virtual function");
2425 if (TREE_VIA_VIRTUAL (path
))
2426 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2427 path
= BINFO_INHERITANCE_CHAIN (path
);
2432 /* Fixups upcast offsets for one vtable.
2433 Entries may stay within the VBASE given, or
2434 they may upcast into a direct base, or
2435 they may upcast into a different vbase.
2437 We only need to do fixups in case 2 and 3. In case 2, we add in
2438 the virtual base offset to effect an upcast, in case 3, we add in
2439 the virtual base offset to effect an upcast, then subtract out the
2440 offset for the other virtual base, to effect a downcast into it.
2442 This routine mirrors fixup_vtable_deltas in functionality, though
2443 this one is runtime based, and the other is compile time based.
2444 Conceivably that routine could be removed entirely, and all fixups
2447 VBASE_OFFSETS is an association list of virtual bases that contains
2448 offset information for the virtual bases, so the offsets are only
2449 calculated once. The offsets are computed by where we think the
2450 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2451 the vbase really is. */
2454 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2456 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2458 tree virtuals
= BINFO_VIRTUALS (binfo
);
2461 unsigned HOST_WIDE_INT n
;
2463 delta
= purpose_member (vbase
, *vbase_offsets
);
2466 delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase
));
2467 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2468 delta
= save_expr (delta
);
2469 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2470 *vbase_offsets
= delta
;
2473 n
= skip_rtti_stuff (&virtuals
);
2477 tree current_fndecl
= TREE_VALUE (virtuals
);
2478 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2479 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2481 && current_fndecl
!= abort_fndecl
2482 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2484 /* This may in fact need a runtime fixup. */
2485 tree idx
= build_int_2 (n
, 0);
2486 tree vtbl
= BINFO_VTABLE (binfo
);
2487 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2488 tree aref
, ref
, naref
;
2489 tree old_delta
, new_delta
;
2492 if (nvtbl
== NULL_TREE
2493 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2495 /* Dup it if it isn't in local scope yet. */
2497 (VAR_DECL
, DECL_NAME (vtbl
),
2498 TYPE_MAIN_VARIANT (TREE_TYPE (BINFO_VTABLE (binfo
))));
2499 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2500 DECL_ALIGN (nvtbl
));
2501 TREE_READONLY (nvtbl
) = 0;
2502 DECL_ARTIFICIAL (nvtbl
) = 1;
2503 nvtbl
= pushdecl (nvtbl
);
2505 cp_finish_decl (nvtbl
, init
, NULL_TREE
, 0,
2506 LOOKUP_ONLYCONVERTING
);
2508 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2509 because they wouldn't be useful; everything that wants to
2510 look at the vtable will look at the decl for the normal
2511 vtable. Setting DECL_CONTEXT also screws up
2512 decl_function_context. */
2514 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
2516 TREE_SIDE_EFFECTS (init
) = 1;
2517 expand_expr_stmt (init
);
2518 /* Update the vtable pointers as necessary. */
2519 ref
= build_vfield_ref
2520 (build_indirect_ref (addr
, NULL_PTR
),
2521 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))));
2523 (build_modify_expr (ref
, NOP_EXPR
,
2524 build_unary_op (ADDR_EXPR
, nvtbl
, 0)));
2526 assemble_external (vtbl
);
2527 aref
= build_array_ref (vtbl
, idx
);
2528 naref
= build_array_ref (nvtbl
, idx
);
2529 old_delta
= build_component_ref (aref
, delta_identifier
,
2531 new_delta
= build_component_ref (naref
, delta_identifier
,
2534 /* This is a upcast, so we have to add the offset for the
2536 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
2537 TREE_VALUE (delta
), 0);
2540 /* If this is set, we need to subtract out the delta
2541 adjustments for the other virtual base that we
2543 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
2546 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
2547 vc_delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc
));
2548 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
2550 vc_delta
= save_expr (vc_delta
);
2551 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
2554 vc_delta
= TREE_VALUE (vc_delta
);
2556 /* This is a downcast, so we have to subtract the offset
2557 for the virtual base. */
2558 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
, 0);
2561 TREE_READONLY (new_delta
) = 0;
2562 expand_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
2566 virtuals
= TREE_CHAIN (virtuals
);
2570 /* Fixup upcast offsets for all direct vtables. Patterned after
2571 expand_direct_vtbls_init. */
2574 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
2575 tree real_binfo
, binfo
;
2576 int init_self
, can_elide
;
2577 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
2579 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
2580 tree binfos
= BINFO_BASETYPES (binfo
);
2581 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
2583 for (i
= 0; i
< n_baselinks
; i
++)
2585 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
2586 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2587 int is_not_base_vtable
2588 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo
));
2589 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
2590 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
2591 is_not_base_vtable
, can_elide
, addr
,
2592 orig_addr
, type
, vbase
, vbase_offsets
);
2595 /* Before turning this on, make sure it is correct. */
2596 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
2599 /* Should we use something besides CLASSTYPE_VFIELDS? */
2600 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
2602 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
2603 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
2604 type
, vbase_offsets
);
2608 /* Build a COMPOUND_EXPR which when expanded will generate the code
2609 needed to initialize all the virtual function table slots of all
2610 the virtual baseclasses. MAIN_BINFO is the binfo which determines
2611 the virtual baseclasses to use; TYPE is the type of the object to
2612 which the initialization applies. TRUE_EXP is the true object we
2613 are initializing, and DECL_PTR is the pointer to the sub-object we
2616 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
2617 object was laid out by a top-level constructor and the computed
2618 offsets are valid to store vtables. When zero, we must store new
2619 vtables through virtual baseclass pointers.
2621 We setup and use the globals: vbase_decl_ptr, vbase_types
2625 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
)
2627 tree true_exp
, decl_ptr
;
2629 tree type
= BINFO_TYPE (binfo
);
2631 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2633 rtx fixup_insns
= NULL_RTX
;
2634 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
2635 vbase_types
= vbases
;
2636 vbase_decl_ptr
= true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0) : decl_ptr
;
2638 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
);
2640 /* Initialized with vtables of type TYPE. */
2641 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
2645 addr
= convert_pointer_to_vbase (TREE_TYPE (vbases
), vbase_decl_ptr
);
2647 /* Do all vtables from this virtual base. */
2648 /* This assumes that virtual bases can never serve as parent
2649 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
2650 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
2653 /* Now we adjust the offsets for virtual functions that
2654 cross virtual boundaries on an implicit upcast on vf call
2655 so that the layout of the most complete type is used,
2656 instead of assuming the layout of the virtual bases from
2657 our current type. */
2659 if (flag_vtable_thunks
)
2661 /* We don't have dynamic thunks yet!
2662 So for now, just fail silently. */
2666 tree vbase_offsets
= NULL_TREE
;
2667 push_to_sequence (fixup_insns
);
2668 fixup_virtual_upcast_offsets (vbases
,
2669 TYPE_BINFO (BINFO_TYPE (vbases
)),
2670 1, 0, addr
, vbase_decl_ptr
,
2671 type
, vbases
, &vbase_offsets
);
2672 fixup_insns
= get_insns ();
2679 extern tree in_charge_identifier
;
2680 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
2681 if (! in_charge_node
)
2683 warning ("recoverable internal compiler error, nobody's in charge!");
2684 in_charge_node
= integer_zero_node
;
2686 in_charge_node
= build_binary_op (EQ_EXPR
, in_charge_node
, integer_zero_node
, 1);
2687 expand_start_cond (in_charge_node
, 0);
2688 emit_insns (fixup_insns
);
2692 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
2696 /* get virtual base class types.
2697 This adds type to the vbase_types list in reverse dfs order.
2698 Ordering is very important, so don't change it. */
2701 dfs_get_vbase_types (binfo
)
2704 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
2706 tree new_vbase
= make_binfo (integer_zero_node
, binfo
,
2707 BINFO_VTABLE (binfo
),
2708 BINFO_VIRTUALS (binfo
));
2709 TREE_CHAIN (new_vbase
) = vbase_types
;
2710 TREE_VIA_VIRTUAL (new_vbase
) = 1;
2711 vbase_types
= new_vbase
;
2712 SET_BINFO_VBASE_MARKED (binfo
);
2714 SET_BINFO_MARKED (binfo
);
2717 /* get a list of virtual base classes in dfs order. */
2720 get_vbase_types (type
)
2726 binfo
= TYPE_BINFO (type
);
2727 vbase_types
= NULL_TREE
;
2728 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
);
2729 dfs_walk (binfo
, dfs_unmark
, markedp
);
2730 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2731 reverse it so that we get normal dfs ordering. */
2732 vbase_types
= nreverse (vbase_types
);
2734 /* unmark marked vbases */
2735 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
2736 CLEAR_BINFO_VBASE_MARKED (vbases
);
2741 /* If we want debug info for a type TYPE, make sure all its base types
2742 are also marked as being potentially interesting. This avoids
2743 the problem of not writing any debug info for intermediate basetypes
2744 that have abstract virtual functions. Also mark member types. */
2747 note_debug_info_needed (type
)
2752 if (current_template_parms
)
2755 if (TYPE_BEING_DEFINED (type
))
2756 /* We can't go looking for the base types and fields just yet. */
2759 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2760 does not support name references between translation units. Well, we
2761 could, but that would mean putting global labels in the debug output
2762 before each exported type and each of its functions and static data
2764 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2767 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
);
2768 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2771 if (TREE_CODE (field
) == FIELD_DECL
2772 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
2773 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
)))
2774 note_debug_info_needed (ttype
);
2778 /* Subroutines of push_class_decls (). */
2780 /* Add in a decl to the envelope. */
2782 envelope_add_decl (type
, decl
, values
)
2783 tree type
, decl
, *values
;
2786 tree name
= DECL_NAME (decl
);
2789 /* Yet Another Implicit Typename Kludge: Since we don't tsubst
2790 the members for partial instantiations, DECL_CONTEXT (decl) is wrong.
2791 But pretend it's right for this function. */
2792 if (processing_template_decl
)
2793 type
= DECL_REAL_CONTEXT (decl
);
2795 /* virtual base names are always unique. */
2796 if (VBASE_NAME_P (name
))
2797 *values
= NULL_TREE
;
2799 /* Possible ambiguity. If its defining type(s)
2800 is (are all) derived from us, no problem. */
2801 else if (*values
&& TREE_CODE (*values
) != TREE_LIST
)
2803 tree value
= *values
;
2804 /* Only complain if we shadow something we can access. */
2805 if (warn_shadow
&& TREE_CODE (decl
) == FUNCTION_DECL
2806 && ((DECL_LANG_SPECIFIC (*values
)
2807 && DECL_CLASS_CONTEXT (value
) == current_class_type
)
2808 || ! TREE_PRIVATE (value
)))
2809 /* Should figure out access control more accurately. */
2811 cp_warning_at ("member `%#D' is shadowed", value
);
2812 cp_warning_at ("by member function `%#D'", decl
);
2813 warning ("in this context");
2816 context
= DECL_REAL_CONTEXT (value
);
2818 if (context
== type
)
2820 if (TREE_CODE (value
) == TYPE_DECL
2821 && DECL_ARTIFICIAL (value
))
2822 *values
= NULL_TREE
;
2826 else if (type
== current_class_type
2827 || DERIVED_FROM_P (context
, type
))
2829 /* Don't add in *values to list */
2830 *values
= NULL_TREE
;
2833 *values
= build_tree_list (NULL_TREE
, value
);
2836 for (tmp
= values
; *tmp
;)
2838 tree value
= TREE_VALUE (*tmp
);
2839 my_friendly_assert (TREE_CODE (value
) != TREE_LIST
, 999);
2840 context
= (TREE_CODE (value
) == FUNCTION_DECL
2841 && DECL_VIRTUAL_P (value
))
2842 ? DECL_CLASS_CONTEXT (value
)
2843 : DECL_CONTEXT (value
);
2845 if (type
== current_class_type
2846 || DERIVED_FROM_P (context
, type
))
2848 /* remove *tmp from list */
2849 *tmp
= TREE_CHAIN (*tmp
);
2852 tmp
= &TREE_CHAIN (*tmp
);
2857 /* Put the new contents in our envelope. */
2858 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2860 *values
= tree_cons (name
, decl
, *values
);
2861 TREE_NONLOCAL_FLAG (*values
) = 1;
2862 TREE_TYPE (*values
) = unknown_type_node
;
2868 *values
= tree_cons (NULL_TREE
, decl
, *values
);
2869 /* Mark this as a potentially ambiguous member. */
2870 /* Leaving TREE_TYPE blank is intentional.
2871 We cannot use `error_mark_node' (lookup_name)
2872 or `unknown_type_node' (all member functions use this). */
2873 TREE_NONLOCAL_FLAG (*values
) = 1;
2881 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2882 because it (or one of the intermediate bases) depends on template parms. */
2885 dependent_base_p (binfo
)
2888 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2890 if (TREE_TYPE (binfo
) == current_class_type
)
2892 if (uses_template_parms (TREE_TYPE (binfo
)))
2898 /* Add the instance variables which this class contributed to the
2899 current class binding contour. When a redefinition occurs, if the
2900 redefinition is strictly within a single inheritance path, we just
2901 overwrite the old declaration with the new. If the fields are not
2902 within a single inheritance path, we must cons them.
2904 In order to know what decls are new (stemming from the current
2905 invocation of push_class_decls) we enclose them in an "envelope",
2906 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
2907 new decl (or possibly a list of competing ones), the TREE_VALUE slot
2908 points to the old value and the TREE_CHAIN slot chains together all
2909 envelopes which needs to be "opened" in push_class_decls. Opening an
2910 envelope means: push the old value onto the class_shadowed list,
2911 install the new one and if it's a TYPE_DECL do the same to the
2912 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
2913 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
2914 Because if it is, it could be a set of overloaded methods from an
2918 dfs_pushdecls (binfo
)
2921 tree type
= BINFO_TYPE (binfo
);
2922 tree fields
, *methods
, *end
;
2926 /* Only record types if we're a template base. */
2927 if (processing_template_decl
&& type
!= current_class_type
2928 && dependent_base_p (binfo
))
2931 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2933 if (dummy
&& TREE_CODE (fields
) != TYPE_DECL
)
2936 /* Unmark so that if we are in a constructor, and then find that
2937 this field was initialized by a base initializer,
2938 we can emit an error message. */
2939 if (TREE_CODE (fields
) == FIELD_DECL
)
2940 TREE_USED (fields
) = 0;
2942 /* Recurse into anonymous unions. */
2943 if (DECL_NAME (fields
) == NULL_TREE
2944 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
2946 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields
)));
2950 if (DECL_NAME (fields
))
2952 tree name
= DECL_NAME (fields
);
2953 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
2955 /* If the class value is not an envelope of the kind described in
2956 the comment above, we create a new envelope. */
2957 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
2958 || TREE_PURPOSE (class_value
) == NULL_TREE
2959 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
2961 /* See comment above for a description of envelopes. */
2962 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
2964 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
2965 class_value
= IDENTIFIER_CLASS_VALUE (name
);
2968 envelope_add_decl (type
, fields
, &TREE_PURPOSE (class_value
));
2972 method_vec
= CLASSTYPE_METHOD_VEC (type
);
2973 if (method_vec
&& ! dummy
)
2975 /* Farm out constructors and destructors. */
2976 methods
= &TREE_VEC_ELT (method_vec
, 2);
2977 end
= TREE_VEC_END (method_vec
);
2979 while (methods
!= end
)
2981 /* This will cause lookup_name to return a pointer
2982 to the tree_list of possible methods of this name. */
2983 tree name
= DECL_NAME (OVL_CURRENT (*methods
));
2984 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
2986 /* If the class value is not an envelope of the kind described in
2987 the comment above, we create a new envelope. */
2988 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
2989 || TREE_PURPOSE (class_value
) == NULL_TREE
2990 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
2992 /* See comment above for a description of envelopes. */
2993 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
2995 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
2996 class_value
= IDENTIFIER_CLASS_VALUE (name
);
2999 /* Here we try to rule out possible ambiguities.
3000 If we can't do that, keep a TREE_LIST with possibly ambiguous
3002 maybe_push_cache_obstack ();
3003 /* Arbitrarily choose the first function in the list. This is OK
3004 because this is only used for initial lookup; anything that
3005 actually uses the function will look it up again. */
3006 envelope_add_decl (type
, OVL_CURRENT (*methods
),
3007 &TREE_PURPOSE (class_value
));
3014 /* We can't just use BINFO_MARKED because envelope_add_decl uses
3015 DERIVED_FROM_P, which calls get_base_distance. */
3016 SET_BINFO_PUSHDECLS_MARKED (binfo
);
3019 /* Consolidate unique (by name) member functions. */
3022 dfs_compress_decls (binfo
)
3025 tree type
= BINFO_TYPE (binfo
);
3026 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
3028 if (processing_template_decl
&& type
!= current_class_type
3029 && dependent_base_p (binfo
))
3030 /* We only record types if we're a template base. */;
3031 else if (method_vec
!= 0)
3033 /* Farm out constructors and destructors. */
3034 tree
*methods
= &TREE_VEC_ELT (method_vec
, 2);
3035 tree
*end
= TREE_VEC_END (method_vec
);
3037 for (; methods
!= end
; methods
++)
3039 /* This is known to be an envelope of the kind described before
3042 IDENTIFIER_CLASS_VALUE (DECL_NAME (OVL_CURRENT (*methods
)));
3043 tree tmp
= TREE_PURPOSE (class_value
);
3045 /* This was replaced in scope by somebody else. Just leave it
3047 if (TREE_CODE (tmp
) != TREE_LIST
)
3050 if (TREE_CHAIN (tmp
) == NULL_TREE
3052 && OVL_NEXT (TREE_VALUE (tmp
)) == NULL_TREE
)
3054 TREE_PURPOSE (class_value
) = TREE_VALUE (tmp
);
3058 CLEAR_BINFO_PUSHDECLS_MARKED (binfo
);
3061 /* When entering the scope of a class, we cache all of the
3062 fields that that class provides within its inheritance
3063 lattice. Where ambiguities result, we mark them
3064 with `error_mark_node' so that if they are encountered
3065 without explicit qualification, we can emit an error
3069 push_class_decls (type
)
3072 struct obstack
*ambient_obstack
= current_obstack
;
3073 search_stack
= push_search_level (search_stack
, &search_obstack
);
3075 /* Push class fields into CLASS_VALUE scope, and mark. */
3076 dfs_walk (TYPE_BINFO (type
), dfs_pushdecls
, unmarked_pushdecls_p
);
3078 /* Compress fields which have only a single entry
3079 by a given name, and unmark. */
3080 dfs_walk (TYPE_BINFO (type
), dfs_compress_decls
, marked_pushdecls_p
);
3082 /* Open up all the closed envelopes and push the contained decls into
3084 while (closed_envelopes
)
3086 tree
new = TREE_PURPOSE (closed_envelopes
);
3089 /* This is messy because the class value may be a *_DECL, or a
3090 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3091 *_DECLs. The name is stored at different places in these three
3093 if (TREE_CODE (new) == TREE_LIST
)
3095 if (TREE_PURPOSE (new) != NULL_TREE
)
3096 id
= TREE_PURPOSE (new);
3099 tree node
= TREE_VALUE (new);
3101 if (TREE_CODE (node
) == TYPE_DECL
3102 && DECL_ARTIFICIAL (node
)
3103 && IS_AGGR_TYPE (TREE_TYPE (node
))
3104 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (node
)))
3106 tree t
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (node
));
3109 for (; n
; n
= TREE_CHAIN (n
))
3111 tree d
= TREE_VALUE (n
);
3112 if (TREE_CODE (d
) == TYPE_DECL
3113 && DECL_ARTIFICIAL (node
)
3114 && IS_AGGR_TYPE (TREE_TYPE (d
))
3115 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (d
))
3116 && CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d
)) == t
)
3125 else while (TREE_CODE (node
) == TREE_LIST
)
3126 node
= TREE_VALUE (node
);
3127 id
= DECL_NAME (node
);
3131 id
= DECL_NAME (new);
3133 /* Install the original class value in order to make
3134 pushdecl_class_level work correctly. */
3135 IDENTIFIER_CLASS_VALUE (id
) = TREE_VALUE (closed_envelopes
);
3136 if (TREE_CODE (new) == TREE_LIST
)
3137 push_class_level_binding (id
, new);
3139 pushdecl_class_level (new);
3140 closed_envelopes
= TREE_CHAIN (closed_envelopes
);
3142 current_obstack
= ambient_obstack
;
3145 /* Here's a subroutine we need because C lacks lambdas. */
3148 dfs_unuse_fields (binfo
)
3151 tree type
= TREE_TYPE (binfo
);
3154 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3156 if (TREE_CODE (fields
) != FIELD_DECL
)
3159 TREE_USED (fields
) = 0;
3160 if (DECL_NAME (fields
) == NULL_TREE
3161 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3162 unuse_fields (TREE_TYPE (fields
));
3170 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
);
3176 /* We haven't pushed a search level when dealing with cached classes,
3177 so we'd better not try to pop it. */
3179 search_stack
= pop_search_level (search_stack
);
3183 print_search_statistics ()
3185 #ifdef GATHER_STATISTICS
3186 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3187 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3188 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3189 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3190 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3191 #else /* GATHER_STATISTICS */
3192 fprintf (stderr
, "no search statistics\n");
3193 #endif /* GATHER_STATISTICS */
3197 init_search_processing ()
3199 gcc_obstack_init (&search_obstack
);
3200 _vptr_name
= get_identifier ("_vptr");
3204 reinit_search_statistics ()
3206 #ifdef GATHER_STATISTICS
3207 n_fields_searched
= 0;
3208 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3209 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3210 n_calls_get_base_type
= 0;
3211 n_outer_fields_searched
= 0;
3212 n_contexts_saved
= 0;
3213 #endif /* GATHER_STATISTICS */
3216 #define scratch_tree_cons expr_tree_cons
3218 static tree conversions
;
3220 add_conversions (binfo
)
3224 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3226 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3228 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3229 if (! IDENTIFIER_TYPENAME_P (DECL_NAME (OVL_CURRENT (tmp
))))
3231 conversions
= scratch_tree_cons (binfo
, tmp
, conversions
);
3233 SET_BINFO_MARKED (binfo
);
3237 lookup_conversions (type
)
3240 conversions
= NULL_TREE
;
3241 if (TYPE_SIZE (type
))
3243 dfs_walk (TYPE_BINFO (type
), add_conversions
, unmarkedp
);
3244 dfs_walk (TYPE_BINFO (type
), dfs_unmark
, markedp
);
3249 /* Subroutine of get_template_base. */
3252 get_template_base_recursive (binfo
, rval
, template, via_virtual
)
3253 tree binfo
, template, rval
;
3258 tree type
= BINFO_TYPE (binfo
);
3260 if (CLASSTYPE_TEMPLATE_INFO (type
)
3261 && CLASSTYPE_TI_TEMPLATE (type
) == template)
3263 if (rval
== NULL_TREE
|| rval
== type
)
3266 return error_mark_node
;
3269 binfos
= BINFO_BASETYPES (binfo
);
3270 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3272 /* Process base types. */
3273 for (i
= 0; i
< n_baselinks
; i
++)
3275 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3277 /* Find any specific instance of a virtual base, when searching with
3279 if (BINFO_MARKED (base_binfo
) == 0)
3281 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
3283 /* When searching for a non-virtual, we cannot mark
3284 virtually found binfos. */
3286 SET_BINFO_MARKED (base_binfo
);
3288 rval
= get_template_base_recursive
3289 (base_binfo
, rval
, template, this_virtual
);
3290 if (rval
== error_mark_node
)
3298 /* Given a class template TEMPLATE and a class type or binfo node BINFO,
3299 find the unique base type in BINFO that is an instance of TEMPLATE.
3300 If there are more than one, return error_mark_node. Used by unify. */
3303 get_template_base (template, binfo
)
3304 register tree
template, binfo
;
3306 tree type
= NULL_TREE
, rval
;
3308 if (TREE_CODE (binfo
) == TREE_VEC
)
3309 type
= BINFO_TYPE (binfo
);
3310 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
3312 type
= complete_type (binfo
);
3313 binfo
= TYPE_BINFO (type
);
3316 my_friendly_abort (92);
3318 if (CLASSTYPE_TEMPLATE_INFO (type
)
3319 && CLASSTYPE_TI_TEMPLATE (type
) == template)
3322 rval
= get_template_base_recursive (binfo
, NULL_TREE
, template, 0);
3323 dfs_walk (binfo
, dfs_unmark
, markedp
);
3328 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3329 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3331 static tree compare_type
;
3332 static int found_overlap
;
3334 dfs_check_overlap (empty_binfo
)
3338 for (binfo
= TYPE_BINFO (compare_type
); ; binfo
= BINFO_BASETYPE (binfo
, 0))
3340 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3345 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3350 /* Trivial function to stop base traversal when we find something. */
3353 dfs_no_overlap_yet (t
)
3354 tree t ATTRIBUTE_UNUSED
;
3356 return found_overlap
== 0;
3359 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3360 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3363 types_overlap_p (empty_type
, next_type
)
3364 tree empty_type
, next_type
;
3366 if (! IS_AGGR_TYPE (next_type
))
3368 compare_type
= next_type
;
3370 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
, dfs_no_overlap_yet
);
3371 return found_overlap
;