1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 89, 92-97, 1998 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_here
PROTO((tree
, tree
));
85 static int is_subobject_of_p
PROTO((tree
, tree
));
86 static int hides
PROTO((tree
, tree
));
87 static tree virtual_context
PROTO((tree
, tree
, tree
));
88 static void dfs_check_overlap
PROTO((tree
));
89 static int dfs_no_overlap_yet
PROTO((tree
));
90 static void envelope_add_decl
PROTO((tree
, tree
, tree
*));
91 static int get_base_distance_recursive
92 PROTO((tree
, int, int, int, int *, tree
*, tree
,
93 int, int *, int, int));
94 static void expand_upcast_fixups
95 PROTO((tree
, tree
, tree
, tree
, tree
, tree
, tree
*));
96 static void fixup_virtual_upcast_offsets
97 PROTO((tree
, tree
, int, int, tree
, tree
, tree
, tree
,
99 static int unmarkedp
PROTO((tree
));
100 static int marked_vtable_pathp
PROTO((tree
));
101 static int unmarked_vtable_pathp
PROTO((tree
));
102 static int marked_new_vtablep
PROTO((tree
));
103 static int unmarked_new_vtablep
PROTO((tree
));
104 static int dfs_debug_unmarkedp
PROTO((tree
));
105 static void dfs_debug_mark
PROTO((tree
));
106 static void dfs_find_vbases
PROTO((tree
));
107 static void dfs_clear_vbase_slots
PROTO((tree
));
108 static void dfs_init_vbase_pointers
PROTO((tree
));
109 static void dfs_get_vbase_types
PROTO((tree
));
110 static void dfs_pushdecls
PROTO((tree
));
111 static void dfs_compress_decls
PROTO((tree
));
112 static void dfs_unuse_fields
PROTO((tree
));
113 static tree add_conversions
PROTO((tree
));
114 static tree get_virtuals_named_this
PROTO((tree
));
115 static tree get_virtual_destructor
PROTO((tree
));
116 static int tree_has_any_destructor_p
PROTO((tree
));
117 static int covariant_return_p
PROTO((tree
, tree
));
118 static struct search_level
*push_search_level
119 PROTO((struct stack_level
*, struct obstack
*));
120 static struct search_level
*pop_search_level
121 PROTO((struct stack_level
*));
122 static tree breadth_first_search
123 PROTO((tree
, tree (*) (tree
), int (*) (tree
)));
125 static tree vbase_types
;
126 static tree vbase_decl_ptr_intermediate
, vbase_decl_ptr
;
127 static tree vbase_init_result
;
129 /* Allocate a level of searching. */
131 static struct search_level
*
132 push_search_level (stack
, obstack
)
133 struct stack_level
*stack
;
134 struct obstack
*obstack
;
136 struct search_level tem
;
139 return push_stack_level (obstack
, (char *)&tem
, sizeof (tem
));
142 /* Discard a level of search allocation. */
144 static struct search_level
*
145 pop_search_level (obstack
)
146 struct stack_level
*obstack
;
148 register struct search_level
*stack
= pop_stack_level (obstack
);
153 static tree _vptr_name
;
155 /* Variables for gathering statistics. */
156 #ifdef GATHER_STATISTICS
157 static int n_fields_searched
;
158 static int n_calls_lookup_field
, n_calls_lookup_field_1
;
159 static int n_calls_lookup_fnfields
, n_calls_lookup_fnfields_1
;
160 static int n_calls_get_base_type
;
161 static int n_outer_fields_searched
;
162 static int n_contexts_saved
;
163 #endif /* GATHER_STATISTICS */
165 /* This list is used by push_class_decls to know what decls need to
166 be pushed into class scope. */
167 static tree closed_envelopes
= NULL_TREE
;
169 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
170 the same type as the type given in PARENT. To be optimal, we want
171 the first one that is found by going through the least number of
174 This uses a clever algorithm that updates *depth when we find the vbase,
175 and cuts off other paths of search when they reach that depth. */
178 get_vbase_1 (parent
, binfo
, depth
)
184 tree rval
= NULL_TREE
;
186 if (BINFO_TYPE (binfo
) == parent
&& TREE_VIA_VIRTUAL (binfo
))
194 binfos
= BINFO_BASETYPES (binfo
);
195 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
197 /* Process base types. */
198 for (i
= 0; i
< n_baselinks
; i
++)
200 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
206 nrval
= get_vbase_1 (parent
, base_binfo
, depth
);
214 /* Return the shortest path to vbase PARENT within BINFO, ignoring
215 access and ambiguity. */
218 get_vbase (parent
, binfo
)
222 unsigned int d
= (unsigned int)-1;
223 return get_vbase_1 (parent
, binfo
, &d
);
226 /* Convert EXPR to a virtual base class of type TYPE. We know that
227 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
228 the type of what expr points to has a virtual base of type TYPE. */
231 convert_pointer_to_vbase (type
, expr
)
235 tree vb
= get_vbase (type
, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
))));
236 return convert_pointer_to_real (vb
, expr
);
239 /* Check whether the type given in BINFO is derived from PARENT. If
240 it isn't, return 0. If it is, but the derivation is MI-ambiguous
241 AND protect != 0, emit an error message and return error_mark_node.
243 Otherwise, if TYPE is derived from PARENT, return the actual base
244 information, unless a one of the protection violations below
245 occurs, in which case emit an error message and return error_mark_node.
247 If PROTECT is 1, then check if access to a public field of PARENT
248 would be private. Also check for ambiguity. */
251 get_binfo (parent
, binfo
, protect
)
252 register tree parent
, binfo
;
255 tree type
= NULL_TREE
;
257 tree rval
= NULL_TREE
;
259 if (TREE_CODE (parent
) == TREE_VEC
)
260 parent
= BINFO_TYPE (parent
);
261 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent
)))
262 my_friendly_abort (89);
264 if (TREE_CODE (binfo
) == TREE_VEC
)
265 type
= BINFO_TYPE (binfo
);
266 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
269 my_friendly_abort (90);
271 dist
= get_base_distance (parent
, binfo
, protect
, &rval
);
275 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
277 return error_mark_node
;
279 else if (dist
== -2 && protect
)
281 cp_error ("type `%T' is ambiguous base class for type `%T'", parent
,
283 return error_mark_node
;
289 /* This is the newer depth first get_base_distance routine. */
292 get_base_distance_recursive (binfo
, depth
, is_private
, rval
,
293 rval_private_ptr
, new_binfo_ptr
, parent
,
294 protect
, via_virtual_ptr
, via_virtual
,
295 current_scope_in_chain
)
297 int depth
, is_private
, rval
;
298 int *rval_private_ptr
;
299 tree
*new_binfo_ptr
, parent
;
300 int protect
, *via_virtual_ptr
, via_virtual
;
301 int current_scope_in_chain
;
307 && !current_scope_in_chain
308 && is_friend (BINFO_TYPE (binfo
), current_scope ()))
309 current_scope_in_chain
= 1;
311 if (BINFO_TYPE (binfo
) == parent
|| binfo
== parent
)
316 /* This is the first time we've found parent. */
318 else if (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr
),
319 BINFO_OFFSET (binfo
))
320 && *via_virtual_ptr
&& via_virtual
)
322 /* A new path to the same vbase. If this one has better
323 access or is shorter, take it. */
326 better
= *rval_private_ptr
- is_private
;
328 better
= rval
- depth
;
332 /* Ambiguous base class. */
335 /* If we get an ambiguity between virtual and non-virtual base
336 class, return the non-virtual in case we are ignoring
338 better
= *via_virtual_ptr
- via_virtual
;
344 *rval_private_ptr
= is_private
;
345 *new_binfo_ptr
= binfo
;
346 *via_virtual_ptr
= via_virtual
;
352 binfos
= BINFO_BASETYPES (binfo
);
353 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
356 /* Process base types. */
357 for (i
= 0; i
< n_baselinks
; i
++)
359 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
364 || (!TREE_VIA_PUBLIC (base_binfo
)
365 && !(TREE_VIA_PROTECTED (base_binfo
)
366 && current_scope_in_chain
)
367 && !is_friend (BINFO_TYPE (binfo
), current_scope ()))));
368 int this_virtual
= via_virtual
|| TREE_VIA_VIRTUAL (base_binfo
);
370 rval
= get_base_distance_recursive (base_binfo
, depth
, via_private
,
371 rval
, rval_private_ptr
,
372 new_binfo_ptr
, parent
,
373 protect
, via_virtual_ptr
,
375 current_scope_in_chain
);
377 /* If we've found a non-virtual, ambiguous base class, we don't need
378 to keep searching. */
379 if (rval
== -2 && *via_virtual_ptr
== 0)
386 /* Return the number of levels between type PARENT and the type given
387 in BINFO, following the leftmost path to PARENT not found along a
388 virtual path, if there are no real PARENTs (all come from virtual
389 base classes), then follow the shortest public path to PARENT.
391 Return -1 if TYPE is not derived from PARENT.
392 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
394 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
396 If PATH_PTR is non-NULL, then also build the list of types
397 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
400 PARENT can also be a binfo, in which case that exact parent is found
401 and no other. convert_pointer_to_real uses this functionality.
403 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
406 get_base_distance (parent
, binfo
, protect
, path_ptr
)
407 register tree parent
, binfo
;
412 int rval_private
= 0;
413 tree type
= NULL_TREE
;
414 tree new_binfo
= NULL_TREE
;
416 int watch_access
= protect
;
418 /* Should we be completing types here? */
419 if (TREE_CODE (parent
) != TREE_VEC
)
420 parent
= complete_type (TYPE_MAIN_VARIANT (parent
));
422 complete_type (TREE_TYPE (parent
));
424 if (TREE_CODE (binfo
) == TREE_VEC
)
425 type
= BINFO_TYPE (binfo
);
426 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo
)))
428 type
= complete_type (binfo
);
429 binfo
= TYPE_BINFO (type
);
432 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
,
436 my_friendly_abort (92);
438 if (parent
== type
|| parent
== binfo
)
440 /* If the distance is 0, then we don't really need
441 a path pointer, but we shouldn't let garbage go back. */
450 rval
= get_base_distance_recursive (binfo
, 0, 0, -1,
451 &rval_private
, &new_binfo
, parent
,
452 watch_access
, &via_virtual
, 0,
455 /* Access restrictions don't count if we found an ambiguous basetype. */
456 if (rval
== -2 && protect
>= 0)
459 if (rval
&& protect
&& rval_private
)
462 /* If they gave us the real vbase binfo, which isn't in the main binfo
463 tree, deal with it. This happens when we are called from
464 expand_upcast_fixups. */
465 if (rval
== -1 && TREE_CODE (parent
) == TREE_VEC
466 && parent
== binfo_member (BINFO_TYPE (parent
),
467 CLASSTYPE_VBASECLASSES (type
)))
469 my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent
) == binfo
, 980827);
475 *path_ptr
= new_binfo
;
479 /* Search for a member with name NAME in a multiple inheritance lattice
480 specified by TYPE. If it does not exist, return NULL_TREE.
481 If the member is ambiguously referenced, return `error_mark_node'.
482 Otherwise, return the FIELD_DECL. */
484 /* Do a 1-level search for NAME as a member of TYPE. The caller must
485 figure out whether it can access this field. (Since it is only one
486 level, this is reasonable.) */
489 lookup_field_1 (type
, name
)
494 if (TREE_CODE (type
) == TEMPLATE_TYPE_PARM
495 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
496 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
497 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
498 the code often worked even when we treated the index as a list
502 field
= TYPE_FIELDS (type
);
504 #ifdef GATHER_STATISTICS
505 n_calls_lookup_field_1
++;
506 #endif /* GATHER_STATISTICS */
509 #ifdef GATHER_STATISTICS
511 #endif /* GATHER_STATISTICS */
512 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field
)) == 'd', 0);
513 if (DECL_NAME (field
) == NULL_TREE
514 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
516 tree temp
= lookup_field_1 (TREE_TYPE (field
), name
);
520 if (TREE_CODE (field
) == USING_DECL
)
521 /* For now, we're just treating member using declarations as
522 old ARM-style access declarations. Thus, there's no reason
523 to return a USING_DECL, and the rest of the compiler can't
524 handle it. Once the class is defined, these are purged
525 from TYPE_FIELDS anyhow; see handle_using_decl. */
527 else if (DECL_NAME (field
) == name
)
529 if ((TREE_CODE(field
) == VAR_DECL
|| TREE_CODE(field
) == CONST_DECL
)
530 && DECL_ASSEMBLER_NAME (field
) != NULL
)
531 GNU_xref_ref(current_function_decl
,
532 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field
)));
535 field
= TREE_CHAIN (field
);
538 if (name
== _vptr_name
)
540 /* Give the user what s/he thinks s/he wants. */
541 if (TYPE_VIRTUAL_P (type
))
542 return CLASSTYPE_VFIELD (type
);
547 /* There are a number of cases we need to be aware of here:
548 current_class_type current_function_decl
555 Those last two make life interesting. If we're in a function which is
556 itself inside a class, we need decls to go into the fn's decls (our
557 second case below). But if we're in a class and the class itself is
558 inside a function, we need decls to go into the decls for the class. To
559 achieve this last goal, we must see if, when both current_class_ptr and
560 current_function_decl are set, the class was declared inside that
561 function. If so, we know to put the decls into the class's scope. */
566 if (current_function_decl
== NULL_TREE
)
567 return current_class_type
;
568 if (current_class_type
== NULL_TREE
)
569 return current_function_decl
;
570 if (DECL_CLASS_CONTEXT (current_function_decl
) == current_class_type
)
571 return current_function_decl
;
573 return current_class_type
;
576 /* Compute the access of FIELD. This is done by computing
577 the access available to each type in BASETYPES (which comes
578 as a list of [via_public/basetype] in reverse order, namely base
579 class before derived class). The first one which defines a
580 access defines the access for the field. Otherwise, the
581 access of the field is that which occurs normally.
583 Uses global variables CURRENT_CLASS_TYPE and
584 CURRENT_FUNCTION_DECL to use friend relationships
587 This will be static when lookup_fnfield comes into this file.
589 access_public_node means that the field can be accessed by the current lexical
592 access_protected_node means that the field cannot be accessed by the current
593 lexical scope because it is protected.
595 access_private_node means that the field cannot be accessed by the current
596 lexical scope because it is private. */
599 #define PUBLIC_RETURN return (DECL_PUBLIC (field) = 1), access_public_node
600 #define PROTECTED_RETURN return (DECL_PROTECTED (field) = 1), access_protected_node
601 #define PRIVATE_RETURN return (DECL_PRIVATE (field) = 1), access_private_node
603 #define PUBLIC_RETURN return access_public_node
604 #define PROTECTED_RETURN return access_protected_node
605 #define PRIVATE_RETURN return access_private_node
609 /* Disabled with DECL_PUBLIC &c. */
610 static tree previous_scope
= NULL_TREE
;
614 compute_access (basetype_path
, field
)
615 tree basetype_path
, field
;
620 int protected_ok
, via_protected
;
621 extern int flag_access_control
;
623 /* Replaces static decl above. */
627 = ((TREE_CODE (field
) == FUNCTION_DECL
&& DECL_STATIC_FUNCTION_P (field
))
628 || (TREE_CODE (field
) != FUNCTION_DECL
&& TREE_STATIC (field
)));
630 if (! flag_access_control
)
631 return access_public_node
;
633 /* The field lives in the current class. */
634 if (BINFO_TYPE (basetype_path
) == current_class_type
)
635 return access_public_node
;
638 /* Disabled until pushing function scope clears these out. If ever. */
639 /* Make these special cases fast. */
640 if (current_scope () == previous_scope
)
642 if (DECL_PUBLIC (field
))
643 return access_public_node
;
644 if (DECL_PROTECTED (field
))
645 return access_protected_node
;
646 if (DECL_PRIVATE (field
))
647 return access_private_node
;
651 /* We don't currently support access control on nested types. */
652 if (TREE_CODE (field
) == TYPE_DECL
)
653 return access_public_node
;
655 previous_scope
= current_scope ();
657 context
= DECL_REAL_CONTEXT (field
);
659 /* Fields coming from nested anonymous unions have their DECL_CLASS_CONTEXT
660 slot set to the union type rather than the record type containing
661 the anonymous union. */
662 if (context
&& ANON_UNION_TYPE_P (context
)
663 && TREE_CODE (field
) == FIELD_DECL
)
664 context
= TYPE_CONTEXT (context
);
666 /* Virtual function tables are never private. But we should know that
667 we are looking for this, and not even try to hide it. */
668 if (DECL_NAME (field
) && VFIELD_NAME_P (DECL_NAME (field
)) == 1)
671 /* Member found immediately within object. */
672 if (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
)
674 /* Are we (or an enclosing scope) friends with the class that has
676 if (is_friend (context
, previous_scope
))
679 /* If it's private, it's private, you letch. */
680 if (TREE_PRIVATE (field
))
683 /* ARM $11.5. Member functions of a derived class can access the
684 non-static protected members of a base class only through a
685 pointer to the derived class, a reference to it, or an object
686 of it. Also any subsequently derived classes also have
688 else if (TREE_PROTECTED (field
))
690 if (current_class_type
691 && (static_mem
|| DECL_CONSTRUCTOR_P (field
))
692 && ACCESSIBLY_DERIVED_FROM_P (context
, current_class_type
))
701 /* must reverse more than one element */
702 basetype_path
= reverse_path (basetype_path
);
703 types
= basetype_path
;
705 access
= access_default_node
;
706 protected_ok
= static_mem
&& current_class_type
707 && ACCESSIBLY_DERIVED_FROM_P (BINFO_TYPE (types
), current_class_type
);
713 tree type
= BINFO_TYPE (binfo
);
716 /* Friends of a class can see protected members of its bases.
717 Note that classes are their own friends. */
718 if (is_friend (type
, previous_scope
))
724 member
= purpose_member (type
, DECL_ACCESS (field
));
727 access
= TREE_VALUE (member
);
731 types
= BINFO_INHERITANCE_CHAIN (types
);
733 /* If the next type was VIA_PROTECTED, then fields of all remaining
734 classes past that one are *at least* protected. */
737 if (TREE_VIA_PROTECTED (types
))
739 else if (! TREE_VIA_PUBLIC (types
) && ! private_ok
)
741 access
= access_private_node
;
749 /* No special visibilities apply. Use normal rules. */
751 if (access
== access_default_node
)
753 if (is_friend (context
, previous_scope
))
754 access
= access_public_node
;
755 else if (TREE_PRIVATE (field
))
756 access
= access_private_node
;
757 else if (TREE_PROTECTED (field
))
758 access
= access_protected_node
;
760 access
= access_public_node
;
763 if (access
== access_public_node
&& via_protected
)
764 access
= access_protected_node
;
766 if (access
== access_protected_node
&& protected_ok
)
767 access
= access_public_node
;
770 if (access
== access_public_node
)
771 DECL_PUBLIC (field
) = 1;
772 else if (access
== access_protected_node
)
773 DECL_PROTECTED (field
) = 1;
774 else if (access
== access_private_node
)
775 DECL_PRIVATE (field
) = 1;
776 else my_friendly_abort (96);
781 /* Routine to see if the sub-object denoted by the binfo PARENT can be
782 found as a base class and sub-object of the object denoted by
783 BINFO. This routine relies upon binfos not being shared, except
784 for binfos for virtual bases. */
787 is_subobject_of_p (parent
, binfo
)
790 tree binfos
= BINFO_BASETYPES (binfo
);
791 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
796 /* Process and/or queue base types. */
797 for (i
= 0; i
< n_baselinks
; i
++)
799 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
800 if (TREE_VIA_VIRTUAL (base_binfo
))
801 base_binfo
= TYPE_BINFO (BINFO_TYPE (base_binfo
));
802 if (is_subobject_of_p (parent
, base_binfo
))
808 /* See if a one FIELD_DECL hides another. This routine is meant to
809 correspond to ANSI working paper Sept 17, 1992 10p4. The two
810 binfos given are the binfos corresponding to the particular places
811 the FIELD_DECLs are found. This routine relies upon binfos not
812 being shared, except for virtual bases. */
815 hides (hider_binfo
, hidee_binfo
)
816 tree hider_binfo
, hidee_binfo
;
818 /* hider hides hidee, if hider has hidee as a base class and
819 the instance of hidee is a sub-object of hider. The first
820 part is always true is the second part is true.
822 When hider and hidee are the same (two ways to get to the exact
823 same member) we consider either one as hiding the other. */
824 return is_subobject_of_p (hidee_binfo
, hider_binfo
);
827 /* Very similar to lookup_fnfields_1 but it ensures that at least one
828 function was declared inside the class given by TYPE. It really should
829 only return functions that match the given TYPE. */
832 lookup_fnfields_here (type
, name
)
835 int idx
= lookup_fnfields_1 (type
, name
);
838 /* ctors and dtors are always only in the right class. */
841 fndecls
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
844 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls
)))
845 == TYPE_MAIN_VARIANT (type
))
847 fndecls
= OVL_CHAIN (fndecls
);
852 /* Look for a field named NAME in an inheritance lattice dominated by
853 XBASETYPE. PROTECT is zero if we can avoid computing access
854 information, otherwise it is 1. WANT_TYPE is 1 when we should only
855 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
857 It was not clear what should happen if WANT_TYPE is set, and an
858 ambiguity is found. At least one use (lookup_name) to not see
862 lookup_field (xbasetype
, name
, protect
, want_type
)
863 register tree xbasetype
, name
;
864 int protect
, want_type
;
866 int head
= 0, tail
= 0;
867 tree rval
, rval_binfo
= NULL_TREE
, rval_binfo_h
= NULL_TREE
;
868 tree type
= NULL_TREE
, basetype_chain
, basetype_path
= NULL_TREE
;
869 tree this_v
= access_default_node
;
870 tree entry
, binfo
, binfo_h
;
871 tree own_access
= access_default_node
;
872 int vbase_name_p
= VBASE_NAME_P (name
);
873 tree ambiguous
= NULL_TREE
;
875 /* rval_binfo is the binfo associated with the found member, note,
876 this can be set with useful information, even when rval is not
877 set, because it must deal with ALL members, not just non-function
878 members. It is used for ambiguity checking and the hidden
879 checks. Whereas rval is only set if a proper (not hidden)
880 non-function member is found. */
882 /* rval_binfo_h and binfo_h are binfo values used when we perform the
883 hiding checks, as virtual base classes may not be shared. The strategy
884 is we always go into the binfo hierarchy owned by TYPE_BINFO of
885 virtual base classes, as we cross virtual base class lines. This way
886 we know that binfo of a virtual base class will always == itself when
887 found along any line. (mrs) */
892 /* We cannot search for constructor/destructor names like this. */
893 /* This can't go here, but where should it go? */
894 /* If we are looking for a constructor in a templated type, use the
895 unspecialized name, as that is how we store it. */
896 if (IDENTIFIER_TEMPLATE (name
))
897 name
= constructor_name (name
);
900 if (xbasetype
== current_class_type
&& TYPE_BEING_DEFINED (xbasetype
)
901 && IDENTIFIER_CLASS_VALUE (name
))
903 tree field
= IDENTIFIER_CLASS_VALUE (name
);
904 if (TREE_CODE (field
) != FUNCTION_DECL
905 && ! (want_type
&& TREE_CODE (field
) != TYPE_DECL
))
909 if (TREE_CODE (xbasetype
) == TREE_VEC
)
911 type
= BINFO_TYPE (xbasetype
);
912 basetype_path
= xbasetype
;
914 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
917 basetype_path
= TYPE_BINFO (type
);
918 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
922 my_friendly_abort (97);
924 complete_type (type
);
926 #ifdef GATHER_STATISTICS
927 n_calls_lookup_field
++;
928 #endif /* GATHER_STATISTICS */
930 rval
= lookup_field_1 (type
, name
);
932 if (rval
|| lookup_fnfields_here (type
, name
) >= 0)
938 if (TREE_CODE (rval
) != TYPE_DECL
)
940 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
942 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
947 if (TREE_CODE (rval
) == TYPE_DECL
948 && lookup_fnfields_here (type
, name
) >= 0)
955 if (TREE_PRIVATE (rval
) | TREE_PROTECTED (rval
))
956 this_v
= compute_access (basetype_path
, rval
);
957 if (TREE_CODE (rval
) == CONST_DECL
)
959 if (this_v
== access_private_node
)
960 errstr
= "enum `%D' is a private value of class `%T'";
961 else if (this_v
== access_protected_node
)
962 errstr
= "enum `%D' is a protected value of class `%T'";
966 if (this_v
== access_private_node
)
967 errstr
= "member `%D' is a private member of class `%T'";
968 else if (this_v
== access_protected_node
)
969 errstr
= "member `%D' is a protected member of class `%T'";
973 rval_binfo
= basetype_path
;
977 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
979 /* The ambiguity check relies upon breadth first searching. */
981 search_stack
= push_search_level (search_stack
, &search_obstack
);
982 binfo
= basetype_path
;
987 tree binfos
= BINFO_BASETYPES (binfo
);
988 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
992 /* Process and/or queue base types. */
993 for (i
= 0; i
< n_baselinks
; i
++)
995 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
996 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1000 SET_BINFO_FIELDS_MARKED (base_binfo
);
1001 btypes
= scratch_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1002 if (TREE_VIA_VIRTUAL (base_binfo
))
1003 btypes
= scratch_tree_cons (NULL_TREE
,
1004 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1007 btypes
= scratch_tree_cons (NULL_TREE
,
1008 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1010 obstack_ptr_grow (&search_obstack
, btypes
);
1012 if (tail
>= search_stack
->limit
)
1013 my_friendly_abort (98);
1017 /* Process head of queue, if one exists. */
1021 basetype_chain
= search_stack
->first
[head
++];
1022 binfo_h
= TREE_VALUE (basetype_chain
);
1023 basetype_chain
= TREE_CHAIN (basetype_chain
);
1024 basetype_path
= TREE_VALUE (basetype_chain
);
1025 if (TREE_CHAIN (basetype_chain
))
1027 ((BINFO_INHERITANCE_CHAIN (basetype_path
)
1028 == TREE_VALUE (TREE_CHAIN (basetype_chain
)))
1029 /* We only approximate base info for partial instantiations. */
1030 || current_template_parms
,
1033 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
)
1034 == NULL_TREE
, 980827);
1036 binfo
= basetype_path
;
1037 type
= BINFO_TYPE (binfo
);
1039 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1040 and we do find NAME in TYPE, verify that such a second
1041 sighting is in fact valid. */
1043 nval
= lookup_field_1 (type
, name
);
1045 if (nval
|| (idx
= lookup_fnfields_here (type
, name
)) >= 0)
1047 if (nval
&& nval
== rval
&& SHARED_MEMBER_P (nval
))
1049 /* This is ok, the member found is the same [class.ambig] */
1051 else if (rval_binfo
&& hides (rval_binfo_h
, binfo_h
))
1053 /* This is ok, the member found is in rval_binfo, not
1056 else if (rval_binfo
==NULL_TREE
|| hides (binfo_h
, rval_binfo_h
))
1058 /* This is ok, the member found is here (binfo), not in
1064 this_v
= compute_access (basetype_path
, rval
);
1065 /* These may look ambiguous, but they really are not. */
1071 /* Undo finding it before, as something else hides it. */
1075 rval_binfo_h
= binfo_h
;
1079 /* This is ambiguous. Remember it. */
1082 errstr
= "request for member `%D' is ambiguous";
1085 ambiguous
= scratch_tree_cons (NULL_TREE
, rval
, ambiguous
);
1089 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1090 nval
= OVL_CURRENT (nval
);
1092 ambiguous
= scratch_tree_cons (NULL_TREE
, nval
, ambiguous
);
1097 tree
*tp
= search_stack
->first
;
1098 tree
*search_tail
= tp
+ tail
;
1102 type
= BINFO_TYPE (rval_binfo
);
1108 if (TREE_CODE (rval
) != TYPE_DECL
)
1110 rval
= purpose_member (name
, CLASSTYPE_TAGS (type
));
1112 rval
= TYPE_MAIN_DECL (TREE_VALUE (rval
));
1117 if (TREE_CODE (rval
) == TYPE_DECL
1118 && lookup_fnfields_here (type
, name
) >= 0)
1124 if (rval
== NULL_TREE
)
1127 /* If this FIELD_DECL defines its own access level, deal with that. */
1128 if (rval
&& errstr
== 0
1130 && DECL_LANG_SPECIFIC (rval
)
1131 && DECL_ACCESS (rval
))
1133 while (tp
< search_tail
)
1135 /* If is possible for one of the derived types on the path to
1136 have defined special access for this field. Look for such
1137 declarations and report an error if a conflict is found. */
1138 tree new_v
= NULL_TREE
;
1140 if (this_v
!= access_default_node
)
1141 new_v
= compute_access (TREE_VALUE (TREE_CHAIN (*tp
)), rval
);
1142 if (this_v
!= access_default_node
&& new_v
!= this_v
)
1144 errstr
= "conflicting access to member `%D'";
1145 this_v
= access_default_node
;
1148 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1154 while (tp
< search_tail
)
1156 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1161 search_stack
= pop_search_level (search_stack
);
1165 if (own_access
== access_private_node
)
1166 errstr
= "member `%D' declared private";
1167 else if (own_access
== access_protected_node
)
1168 errstr
= "member `%D' declared protected";
1169 else if (this_v
== access_private_node
)
1170 errstr
= TREE_PRIVATE (rval
)
1171 ? "member `%D' is private"
1172 : "member `%D' is from private base class";
1173 else if (this_v
== access_protected_node
)
1174 errstr
= TREE_PROTECTED (rval
)
1175 ? "member `%D' is protected"
1176 : "member `%D' is from protected base class";
1182 /* If we are not interested in ambiguities, don't report them,
1183 just return NULL_TREE. */
1188 if (errstr
&& protect
)
1190 cp_error (errstr
, name
, type
);
1192 print_candidates (ambiguous
);
1193 rval
= error_mark_node
;
1196 /* Do implicit typename stuff. This code also handles out-of-class
1197 definitions of nested classes whose enclosing class is a
1198 template. For example:
1200 template <class T> struct S { struct I { void f(); }; };
1201 template <class T> void S<T>::I::f() {}
1203 will come through here to handle `S<T>::I'. */
1204 if (rval
&& processing_template_decl
1205 && ! currently_open_class (BINFO_TYPE (rval_binfo
))
1206 && uses_template_parms (type
))
1208 /* We need to return a member template class so we can define partial
1209 specializations. Is there a better way? */
1210 if (DECL_CLASS_TEMPLATE_P (rval
))
1213 /* Don't return a non-type. Actually, we ought to return something
1214 so lookup_name_real can give a warning. */
1215 if (TREE_CODE (rval
) != TYPE_DECL
)
1219 for (; ; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
1220 if (BINFO_INHERITANCE_CHAIN (binfo
) == NULL_TREE
1221 || (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo
))
1222 == current_class_type
))
1225 entry
= build_typename_type (BINFO_TYPE (binfo
), name
, name
,
1227 return TYPE_STUB_DECL (entry
);
1233 /* Try to find NAME inside a nested class. */
1236 lookup_nested_field (name
, complain
)
1242 tree id
= NULL_TREE
;
1243 if (TYPE_MAIN_DECL (current_class_type
))
1245 /* Climb our way up the nested ladder, seeing if we're trying to
1246 modify a field in an enclosing class. If so, we should only
1247 be able to modify if it's static. */
1248 for (t
= TYPE_MAIN_DECL (current_class_type
);
1249 t
&& DECL_CONTEXT (t
);
1250 t
= TYPE_MAIN_DECL (DECL_CONTEXT (t
)))
1252 if (TREE_CODE (DECL_CONTEXT (t
)) != RECORD_TYPE
)
1255 /* N.B.: lookup_field will do the access checking for us */
1256 id
= lookup_field (DECL_CONTEXT (t
), name
, complain
, 0);
1257 if (id
== error_mark_node
)
1263 if (id
!= NULL_TREE
)
1265 if (TREE_CODE (id
) == FIELD_DECL
1266 && ! TREE_STATIC (id
)
1267 && TREE_TYPE (id
) != error_mark_node
)
1271 /* At parse time, we don't want to give this error, since
1272 we won't have enough state to make this kind of
1273 decision properly. But there are times (e.g., with
1274 enums in nested classes) when we do need to call
1275 this fn at parse time. So, in those cases, we pass
1276 complain as a 0 and just return a NULL_TREE. */
1277 cp_error ("assignment to non-static member `%D' of enclosing class `%T'",
1278 id
, DECL_CONTEXT (t
));
1279 /* Mark this for do_identifier(). It would otherwise
1280 claim that the variable was undeclared. */
1281 TREE_TYPE (id
) = error_mark_node
;
1297 /* TYPE is a class type. Return the index of the fields within
1298 the method vector with name NAME, or -1 is no such field exists. */
1301 lookup_fnfields_1 (type
, name
)
1304 register tree method_vec
1305 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
1307 if (method_vec
!= 0)
1309 register tree
*methods
= &TREE_VEC_ELT (method_vec
, 0);
1310 register tree
*end
= TREE_VEC_END (method_vec
);
1312 #ifdef GATHER_STATISTICS
1313 n_calls_lookup_fnfields_1
++;
1314 #endif /* GATHER_STATISTICS */
1316 /* Constructors are first... */
1317 if (*methods
&& name
== ctor_identifier
)
1320 /* and destructors are second. */
1321 if (*++methods
&& name
== dtor_identifier
)
1324 while (++methods
!= end
&& *methods
)
1326 #ifdef GATHER_STATISTICS
1327 n_outer_fields_searched
++;
1328 #endif /* GATHER_STATISTICS */
1329 if (DECL_NAME (OVL_CURRENT (*methods
)) == name
)
1333 /* If we didn't find it, it might have been a template
1334 conversion operator. (Note that we don't look for this case
1335 above so that we will always find specializations first.) */
1336 if ((methods
== end
|| !*methods
)
1337 && IDENTIFIER_TYPENAME_P (name
))
1339 methods
= &TREE_VEC_ELT (method_vec
, 0) + 1;
1341 while (++methods
!= end
&& *methods
)
1343 tree method_name
= DECL_NAME (OVL_CURRENT (*methods
));
1345 if (!IDENTIFIER_TYPENAME_P (method_name
))
1347 /* Since all conversion operators come first, we know
1348 there is no such operator. */
1352 else if (TREE_CODE (OVL_CURRENT (*methods
)) == TEMPLATE_DECL
)
1357 if (methods
!= end
&& *methods
)
1358 return methods
- &TREE_VEC_ELT (method_vec
, 0);
1364 /* Starting from BASETYPE, return a TREE_BASELINK-like object
1365 which gives the following information (in a list):
1367 TREE_TYPE: list of basetypes needed to get to...
1368 TREE_VALUE: list of all functions in a given type
1369 which have name NAME.
1371 No access information is computed by this function,
1372 other then to adorn the list of basetypes with
1375 If there are two ways to find a name (two members), if COMPLAIN is
1376 non-zero, then error_mark_node is returned, and an error message is
1377 printed, otherwise, just an error_mark_node is returned.
1379 As a special case, is COMPLAIN is -1, we don't complain, and we
1380 don't return error_mark_node, but rather the complete list of
1381 virtuals. This is used by get_virtuals_named_this. */
1384 lookup_fnfields (basetype_path
, name
, complain
)
1385 tree basetype_path
, name
;
1388 int head
= 0, tail
= 0;
1389 tree type
, rval
, rval_binfo
= NULL_TREE
, rvals
= NULL_TREE
;
1390 tree rval_binfo_h
= NULL_TREE
, binfo
, basetype_chain
, binfo_h
;
1391 int idx
, find_all
= 0;
1393 /* rval_binfo is the binfo associated with the found member, note,
1394 this can be set with useful information, even when rval is not
1395 set, because it must deal with ALL members, not just function
1396 members. It is used for ambiguity checking and the hidden
1397 checks. Whereas rval is only set if a proper (not hidden)
1398 function member is found. */
1400 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1401 hiding checks, as virtual base classes may not be shared. The strategy
1402 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1403 virtual base classes, as we cross virtual base class lines. This way
1404 we know that binfo of a virtual base class will always == itself when
1405 found along any line. (mrs) */
1407 /* For now, don't try this. */
1408 int protect
= complain
;
1415 protect
= complain
= 0;
1419 /* We cannot search for constructor/destructor names like this. */
1420 /* This can't go here, but where should it go? */
1421 /* If we are looking for a constructor in a templated type, use the
1422 unspecialized name, as that is how we store it. */
1423 if (IDENTIFIER_TEMPLATE (name
))
1424 name
= constructor_name (name
);
1427 binfo
= basetype_path
;
1429 type
= complete_type (BINFO_TYPE (basetype_path
));
1431 #ifdef GATHER_STATISTICS
1432 n_calls_lookup_fnfields
++;
1433 #endif /* GATHER_STATISTICS */
1435 idx
= lookup_fnfields_here (type
, name
);
1436 if (idx
>= 0 || lookup_field_1 (type
, name
))
1438 rval_binfo
= basetype_path
;
1439 rval_binfo_h
= rval_binfo
;
1444 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1445 rvals
= scratch_tree_cons (basetype_path
, rval
, rvals
);
1446 if (BINFO_BASETYPES (binfo
) && CLASSTYPE_BASELINK_VEC (type
))
1447 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1453 if (name
== ctor_identifier
|| name
== dtor_identifier
)
1455 /* Don't allow lookups of constructors and destructors to go
1456 deeper than the first place we look. */
1460 if (basetype_path
== TYPE_BINFO (type
))
1462 basetype_chain
= CLASSTYPE_BINFO_AS_LIST (type
);
1463 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
) == NULL_TREE
,
1467 basetype_chain
= build_expr_list (NULL_TREE
, basetype_path
);
1469 /* The ambiguity check relies upon breadth first searching. */
1471 search_stack
= push_search_level (search_stack
, &search_obstack
);
1472 binfo
= basetype_path
;
1477 tree binfos
= BINFO_BASETYPES (binfo
);
1478 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1481 /* Process and/or queue base types. */
1482 for (i
= 0; i
< n_baselinks
; i
++)
1484 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1485 if (BINFO_FIELDS_MARKED (base_binfo
) == 0)
1489 SET_BINFO_FIELDS_MARKED (base_binfo
);
1490 btypes
= scratch_tree_cons (NULL_TREE
, base_binfo
, basetype_chain
);
1491 if (TREE_VIA_VIRTUAL (base_binfo
))
1492 btypes
= scratch_tree_cons (NULL_TREE
,
1493 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
))),
1496 btypes
= scratch_tree_cons (NULL_TREE
,
1497 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h
), i
),
1499 obstack_ptr_grow (&search_obstack
, btypes
);
1501 if (tail
>= search_stack
->limit
)
1502 my_friendly_abort (99);
1506 /* Process head of queue, if one exists. */
1510 basetype_chain
= search_stack
->first
[head
++];
1511 binfo_h
= TREE_VALUE (basetype_chain
);
1512 basetype_chain
= TREE_CHAIN (basetype_chain
);
1513 basetype_path
= TREE_VALUE (basetype_chain
);
1514 if (TREE_CHAIN (basetype_chain
))
1516 ((BINFO_INHERITANCE_CHAIN (basetype_path
)
1517 == TREE_VALUE (TREE_CHAIN (basetype_chain
)))
1518 /* We only approximate base info for partial instantiations. */
1519 || current_template_parms
,
1522 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
)
1523 == NULL_TREE
, 980827);
1525 binfo
= basetype_path
;
1526 type
= BINFO_TYPE (binfo
);
1528 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1529 and we do find NAME in TYPE, verify that such a second
1530 sighting is in fact valid. */
1532 idx
= lookup_fnfields_here (type
, name
);
1534 if (idx
>= 0 || (lookup_field_1 (type
, name
)!=NULL_TREE
&& !find_all
))
1536 if (rval_binfo
&& !find_all
&& hides (rval_binfo_h
, binfo_h
))
1538 /* This is ok, the member found is in rval_binfo, not
1541 else if (rval_binfo
==NULL_TREE
|| find_all
|| hides (binfo_h
, rval_binfo_h
))
1543 /* This is ok, the member found is here (binfo), not in
1547 rval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
1548 /* Note, rvals can only be previously set if find_all is
1550 rvals
= scratch_tree_cons (basetype_path
, rval
, rvals
);
1551 if (TYPE_BINFO_BASETYPES (type
)
1552 && CLASSTYPE_BASELINK_VEC (type
))
1553 TREE_TYPE (rvals
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
1557 /* Undo finding it before, as something else hides it. */
1562 rval_binfo_h
= binfo_h
;
1566 /* This is ambiguous. */
1567 errstr
= "request for method `%D' is ambiguous";
1568 rvals
= error_mark_node
;
1574 tree
*tp
= search_stack
->first
;
1575 tree
*search_tail
= tp
+ tail
;
1577 while (tp
< search_tail
)
1579 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp
)));
1583 search_stack
= pop_search_level (search_stack
);
1585 if (errstr
&& protect
)
1587 cp_error (errstr
, name
);
1588 rvals
= error_mark_node
;
1594 /* Look for a field or function named NAME in an inheritance lattice
1595 dominated by XBASETYPE. PROTECT is zero if we can avoid computing
1596 access information, otherwise it is 1. WANT_TYPE is 1 when we should
1597 only return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE. */
1600 lookup_member (xbasetype
, name
, protect
, want_type
)
1601 tree xbasetype
, name
;
1602 int protect
, want_type
;
1604 tree ret
, basetype_path
;
1606 if (TREE_CODE (xbasetype
) == TREE_VEC
)
1607 basetype_path
= xbasetype
;
1608 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype
)))
1610 basetype_path
= TYPE_BINFO (xbasetype
);
1611 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path
)
1612 == NULL_TREE
, 980827);
1615 my_friendly_abort (97);
1617 ret
= lookup_field (basetype_path
, name
, protect
, want_type
);
1618 if (! ret
&& ! want_type
)
1619 ret
= lookup_fnfields (basetype_path
, name
, protect
);
1623 /* BREADTH-FIRST SEARCH ROUTINES. */
1625 /* Search a multiple inheritance hierarchy by breadth-first search.
1627 BINFO is an aggregate type, possibly in a multiple-inheritance hierarchy.
1628 TESTFN is a function, which, if true, means that our condition has been met,
1629 and its return value should be returned.
1630 QFN, if non-NULL, is a predicate dictating whether the type should
1634 breadth_first_search (binfo
, testfn
, qfn
)
1636 tree (*testfn
) PROTO((tree
));
1637 int (*qfn
) PROTO((tree
));
1639 int head
= 0, tail
= 0;
1640 tree rval
= NULL_TREE
;
1642 search_stack
= push_search_level (search_stack
, &search_obstack
);
1644 SET_BINFO_MARKED (binfo
);
1645 obstack_ptr_grow (&search_obstack
, binfo
);
1650 tree binfos
= BINFO_BASETYPES (binfo
);
1651 int n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1654 /* Process and/or queue base types. */
1655 for (i
= 0; i
< n_baselinks
; i
++)
1657 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1659 if (BINFO_MARKED (base_binfo
) == 0
1660 && (qfn
== 0 || (*qfn
) (base_binfo
)))
1662 SET_BINFO_MARKED (base_binfo
);
1663 obstack_ptr_grow (&search_obstack
, base_binfo
);
1665 if (tail
>= search_stack
->limit
)
1666 my_friendly_abort (100);
1669 /* Process head of queue, if one exists. */
1676 binfo
= search_stack
->first
[head
++];
1677 if ((rval
= (*testfn
) (binfo
)))
1681 tree
*tp
= search_stack
->first
;
1682 tree
*search_tail
= tp
+ tail
;
1683 while (tp
< search_tail
)
1686 CLEAR_BINFO_MARKED (binfo
);
1690 search_stack
= pop_search_level (search_stack
);
1694 /* Functions to use in breadth first searches. */
1695 typedef tree (*pfi
) PROTO((tree
));
1697 static tree declarator
;
1700 get_virtuals_named_this (binfo
)
1705 fields
= lookup_fnfields (binfo
, declarator
, -1);
1706 /* fields cannot be error_mark_node */
1711 /* Get to the function decls, and return the first virtual function
1712 with this name, if there is one. */
1717 for (fndecl
= TREE_VALUE (fields
); fndecl
; fndecl
= OVL_NEXT (fndecl
))
1718 if (DECL_VINDEX (OVL_CURRENT (fndecl
)))
1720 fields
= next_baselink (fields
);
1726 get_virtual_destructor (binfo
)
1729 tree type
= BINFO_TYPE (binfo
);
1730 if (TYPE_HAS_DESTRUCTOR (type
)
1731 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1)))
1732 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), 1);
1737 tree_has_any_destructor_p (binfo
)
1740 tree type
= BINFO_TYPE (binfo
);
1741 return TYPE_NEEDS_DESTRUCTOR (type
);
1744 /* Returns > 0 if a function with type DRETTYPE overriding a function
1745 with type BRETTYPE is covariant, as defined in [class.virtual].
1747 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1748 adjustment), or -1 if pedantically invalid covariance. */
1751 covariant_return_p (brettype
, drettype
)
1752 tree brettype
, drettype
;
1756 if (TREE_CODE (brettype
) == FUNCTION_DECL
1757 || TREE_CODE (brettype
) == THUNK_DECL
)
1759 brettype
= TREE_TYPE (TREE_TYPE (brettype
));
1760 drettype
= TREE_TYPE (TREE_TYPE (drettype
));
1762 else if (TREE_CODE (brettype
) == METHOD_TYPE
)
1764 brettype
= TREE_TYPE (brettype
);
1765 drettype
= TREE_TYPE (drettype
);
1768 if (same_type_p (brettype
, drettype
))
1771 if (! (TREE_CODE (brettype
) == TREE_CODE (drettype
)
1772 && (TREE_CODE (brettype
) == POINTER_TYPE
1773 || TREE_CODE (brettype
) == REFERENCE_TYPE
)
1774 && TYPE_QUALS (brettype
) == TYPE_QUALS (drettype
)))
1777 if (! can_convert (brettype
, drettype
))
1780 brettype
= TREE_TYPE (brettype
);
1781 drettype
= TREE_TYPE (drettype
);
1783 /* If not pedantic, allow any standard pointer conversion. */
1784 if (! IS_AGGR_TYPE (drettype
) || ! IS_AGGR_TYPE (brettype
))
1787 binfo
= get_binfo (brettype
, drettype
, 1);
1789 /* If we get an error_mark_node from get_binfo, it already complained,
1790 so let's just succeed. */
1791 if (binfo
== error_mark_node
)
1794 if (! BINFO_OFFSET_ZEROP (binfo
) || TREE_VIA_VIRTUAL (binfo
))
1799 /* Given a class type TYPE, and a function decl FNDECL, look for a
1800 virtual function in TYPE's hierarchy which FNDECL could match as a
1801 virtual function. It doesn't matter which one we find.
1803 DTORP is nonzero if we are looking for a destructor. Destructors
1804 need special treatment because they do not match by name. */
1807 get_matching_virtual (binfo
, fndecl
, dtorp
)
1811 tree tmp
= NULL_TREE
;
1814 if (TREE_CODE (fndecl
) == TEMPLATE_DECL
)
1815 /* In [temp.mem] we have:
1817 A specialization of a member function template does not
1818 override a virtual function from a base class. */
1821 /* Breadth first search routines start searching basetypes
1822 of TYPE, so we must perform first ply of search here. */
1825 return breadth_first_search (binfo
,
1826 get_virtual_destructor
,
1827 tree_has_any_destructor_p
);
1831 tree drettype
, dtypes
, btypes
, instptr_type
;
1832 tree basetype
= DECL_CLASS_CONTEXT (fndecl
);
1833 tree baselink
, best
= NULL_TREE
;
1834 tree name
= DECL_ASSEMBLER_NAME (fndecl
);
1836 declarator
= DECL_NAME (fndecl
);
1837 if (IDENTIFIER_VIRTUAL_P (declarator
) == 0)
1840 baselink
= get_virtuals_named_this (binfo
);
1841 if (baselink
== NULL_TREE
)
1844 drettype
= TREE_TYPE (TREE_TYPE (fndecl
));
1845 dtypes
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
1846 if (DECL_STATIC_FUNCTION_P (fndecl
))
1847 instptr_type
= NULL_TREE
;
1849 instptr_type
= TREE_TYPE (TREE_VALUE (dtypes
));
1851 for (; baselink
; baselink
= next_baselink (baselink
))
1854 for (tmps
= TREE_VALUE (baselink
); tmps
; tmps
= OVL_NEXT (tmps
))
1856 tmp
= OVL_CURRENT (tmps
);
1857 if (! DECL_VINDEX (tmp
))
1860 btypes
= TYPE_ARG_TYPES (TREE_TYPE (tmp
));
1861 if (instptr_type
== NULL_TREE
)
1863 if (compparms (TREE_CHAIN (btypes
), dtypes
))
1864 /* Caller knows to give error in this case. */
1869 if (/* The first parameter is the `this' parameter,
1870 which has POINTER_TYPE, and we can therefore
1871 safely use TYPE_QUALS, rather than
1873 (TYPE_QUALS (TREE_TYPE (TREE_VALUE (btypes
)))
1874 == TYPE_QUALS (instptr_type
))
1875 && compparms (TREE_CHAIN (btypes
), TREE_CHAIN (dtypes
)))
1877 tree brettype
= TREE_TYPE (TREE_TYPE (tmp
));
1878 if (same_type_p (brettype
, drettype
))
1880 else if ((i
= covariant_return_p (brettype
, drettype
)))
1883 sorry ("adjusting pointers for covariant returns");
1885 if (pedantic
&& i
== -1)
1887 cp_pedwarn_at ("invalid covariant return type for `%#D' (must be pointer or reference to class)", fndecl
);
1888 cp_pedwarn_at (" overriding `%#D'", tmp
);
1891 else if (IS_AGGR_TYPE_2 (brettype
, drettype
)
1892 && same_or_base_type_p (brettype
, drettype
))
1894 error ("invalid covariant return type (must use pointer or reference)");
1895 cp_error_at (" overriding `%#D'", tmp
);
1896 cp_error_at (" with `%#D'", fndecl
);
1898 else if (IDENTIFIER_ERROR_LOCUS (name
) == NULL_TREE
)
1900 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl
);
1901 cp_error_at (" overriding definition as `%#D'", tmp
);
1902 SET_IDENTIFIER_ERROR_LOCUS (name
, basetype
);
1905 /* FNDECL overrides this function. We continue to
1906 check all the other functions in order to catch
1907 errors; it might be that in some other baseclass
1908 a virtual function was declared with the same
1909 parameter types, but a different return type. */
1919 /* Return the list of virtual functions which are abstract in type
1920 TYPE that come from non virtual base classes. See
1921 expand_direct_vtbls_init for the style of search we do. */
1924 get_abstract_virtuals_1 (binfo
, do_self
, abstract_virtuals
)
1927 tree abstract_virtuals
;
1929 tree binfos
= BINFO_BASETYPES (binfo
);
1930 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1932 for (i
= 0; i
< n_baselinks
; i
++)
1934 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1935 int is_not_base_vtable
1936 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
1937 if (! TREE_VIA_VIRTUAL (base_binfo
))
1939 = get_abstract_virtuals_1 (base_binfo
, is_not_base_vtable
,
1942 /* Should we use something besides CLASSTYPE_VFIELDS? */
1943 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
1945 tree virtuals
= BINFO_VIRTUALS (binfo
);
1947 skip_rtti_stuff (&virtuals
);
1951 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
1952 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
1953 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
1954 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
1955 virtuals
= TREE_CHAIN (virtuals
);
1958 return abstract_virtuals
;
1961 /* Return the list of virtual functions which are abstract in type TYPE.
1962 This information is cached, and so must be built on a
1963 non-temporary obstack. */
1966 get_abstract_virtuals (type
)
1970 tree abstract_virtuals
= NULL
;
1972 /* First get all from non-virtual bases. */
1974 = get_abstract_virtuals_1 (TYPE_BINFO (type
), 1, abstract_virtuals
);
1976 for (vbases
= CLASSTYPE_VBASECLASSES (type
); vbases
; vbases
= TREE_CHAIN (vbases
))
1978 tree virtuals
= BINFO_VIRTUALS (vbases
);
1980 skip_rtti_stuff (&virtuals
);
1984 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
1985 tree base_fndecl
= TREE_OPERAND (base_pfn
, 0);
1986 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl
))
1987 cp_error ("`%#D' needs a final overrider", base_fndecl
);
1988 else if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl
))
1989 abstract_virtuals
= tree_cons (NULL_TREE
, base_fndecl
, abstract_virtuals
);
1990 virtuals
= TREE_CHAIN (virtuals
);
1993 return nreverse (abstract_virtuals
);
1996 /* For the type TYPE, return a list of member functions available from
1997 base classes with name NAME. The TREE_VALUE of the list is a chain of
1998 member functions with name NAME. The TREE_PURPOSE of the list is a
1999 basetype, or a list of base types (in reverse order) which were
2000 traversed to reach the chain of member functions. If we reach a base
2001 type which provides a member function of name NAME, and which has at
2002 most one base type itself, then we can terminate the search. */
2005 get_baselinks (type_as_binfo_list
, type
, name
)
2006 tree type_as_binfo_list
;
2009 int head
= 0, tail
= 0, idx
;
2010 tree rval
= 0, nval
= 0;
2011 tree basetypes
= type_as_binfo_list
;
2012 tree binfo
= TYPE_BINFO (type
);
2014 search_stack
= push_search_level (search_stack
, &search_obstack
);
2018 tree binfos
= BINFO_BASETYPES (binfo
);
2019 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2021 /* Process and/or queue base types. */
2022 for (i
= 0; i
< n_baselinks
; i
++)
2024 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2027 btypes
= hash_tree_cons (TREE_VIA_PUBLIC (base_binfo
),
2028 TREE_VIA_VIRTUAL (base_binfo
),
2029 TREE_VIA_PROTECTED (base_binfo
),
2030 NULL_TREE
, base_binfo
,
2032 obstack_ptr_grow (&search_obstack
, btypes
);
2033 search_stack
->first
= (tree
*)obstack_base (&search_obstack
);
2038 /* Process head of queue, if one exists. */
2042 basetypes
= search_stack
->first
[head
++];
2043 binfo
= TREE_VALUE (basetypes
);
2044 type
= BINFO_TYPE (binfo
);
2045 idx
= lookup_fnfields_1 (type
, name
);
2048 nval
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type
), idx
);
2049 rval
= hash_tree_cons (0, 0, 0, basetypes
, nval
, rval
);
2050 if (TYPE_BINFO_BASETYPES (type
) == 0)
2052 else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
)) == 1)
2054 if (CLASSTYPE_BASELINK_VEC (type
))
2055 TREE_TYPE (rval
) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), idx
);
2062 search_stack
= pop_search_level (search_stack
);
2067 next_baselink (baselink
)
2070 tree tmp
= TREE_TYPE (baselink
);
2071 baselink
= TREE_CHAIN (baselink
);
2074 /* @@ does not yet add previous base types. */
2075 baselink
= tree_cons (TREE_PURPOSE (tmp
), TREE_VALUE (tmp
),
2077 TREE_TYPE (baselink
) = TREE_TYPE (tmp
);
2078 tmp
= TREE_CHAIN (tmp
);
2083 /* DEPTH-FIRST SEARCH ROUTINES. */
2085 /* This routine converts a pointer to be a pointer of an immediate
2086 base class. The normal convert_pointer_to routine would diagnose
2087 the conversion as ambiguous, under MI code that has the base class
2088 as an ambiguous base class. */
2091 convert_pointer_to_single_level (to_type
, expr
)
2094 tree binfo_of_derived
;
2097 binfo_of_derived
= TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr
)));
2098 last
= get_binfo (to_type
, TREE_TYPE (TREE_TYPE (expr
)), 0);
2099 my_friendly_assert (BINFO_INHERITANCE_CHAIN (last
) == binfo_of_derived
,
2101 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo_of_derived
) == NULL_TREE
,
2103 return build_vbase_path (PLUS_EXPR
, build_pointer_type (to_type
), expr
,
2107 /* The main function which implements depth first search.
2109 This routine has to remember the path it walked up, when
2110 dfs_init_vbase_pointers is the work function, as otherwise there
2111 would be no record. */
2114 dfs_walk (binfo
, fn
, qfn
)
2116 void (*fn
) PROTO((tree
));
2117 int (*qfn
) PROTO((tree
));
2119 tree binfos
= BINFO_BASETYPES (binfo
);
2120 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2122 for (i
= 0; i
< n_baselinks
; i
++)
2124 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2126 if (qfn
== 0 || (*qfn
)(base_binfo
))
2128 if (TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TYPE_PARM
2129 || TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TEMPLATE_PARM
)
2131 else if (fn
== dfs_init_vbase_pointers
)
2133 /* When traversing an arbitrary MI hierarchy, we need to keep
2134 a record of the path we took to get down to the final base
2135 type, as otherwise there would be no record of it, and just
2136 trying to blindly convert at the bottom would be ambiguous.
2138 The easiest way is to do the conversions one step at a time,
2139 as we know we want the immediate base class at each step.
2141 The only special trick to converting one step at a time,
2142 is that when we hit the last virtual base class, we must
2143 use the SLOT value for it, and not use the normal convert
2144 routine. We use the last virtual base class, as in our
2145 implementation, we have pointers to all virtual base
2146 classes in the base object. */
2148 tree saved_vbase_decl_ptr_intermediate
2149 = vbase_decl_ptr_intermediate
;
2151 if (TREE_VIA_VIRTUAL (base_binfo
))
2153 /* No need for the conversion here, as we know it is the
2155 vbase_decl_ptr_intermediate
2156 = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
));
2160 vbase_decl_ptr_intermediate
2161 = convert_pointer_to_single_level (BINFO_TYPE (base_binfo
),
2162 vbase_decl_ptr_intermediate
);
2165 dfs_walk (base_binfo
, fn
, qfn
);
2167 vbase_decl_ptr_intermediate
= saved_vbase_decl_ptr_intermediate
;
2170 dfs_walk (base_binfo
, fn
, qfn
);
2177 /* Like dfs_walk, but only walk until fn returns something, and return
2178 that. We also use the real vbase binfos instead of the placeholders
2179 in the normal binfo hierarchy. START is the most-derived type for this
2180 hierarchy, so that we can find the vbase binfos. */
2183 dfs_search (binfo
, fn
, start
)
2185 tree (*fn
) PROTO((tree
));
2187 tree binfos
= BINFO_BASETYPES (binfo
);
2188 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2191 for (i
= 0; i
< n_baselinks
; i
++)
2193 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2195 if (TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TYPE_PARM
2196 || TREE_CODE (BINFO_TYPE (base_binfo
)) == TEMPLATE_TEMPLATE_PARM
)
2200 if (TREE_VIA_VIRTUAL (base_binfo
) && start
)
2201 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
),
2202 CLASSTYPE_VBASECLASSES (start
));
2203 retval
= dfs_search (base_binfo
, fn
, start
);
2212 int markedp (binfo
) tree binfo
;
2213 { return BINFO_MARKED (binfo
); }
2214 static int unmarkedp (binfo
) tree binfo
;
2215 { return BINFO_MARKED (binfo
) == 0; }
2218 static int bfs_markedp (binfo
, i
) tree binfo
; int i
;
2219 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2220 static int bfs_unmarkedp (binfo
, i
) tree binfo
; int i
;
2221 { return BINFO_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2222 static int bfs_marked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2223 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2224 static int bfs_unmarked_vtable_pathp (binfo
, i
) tree binfo
; int i
;
2225 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2226 static int bfs_marked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2227 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)); }
2228 static int bfs_unmarked_new_vtablep (binfo
, i
) tree binfo
; int i
;
2229 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo
, i
)) == 0; }
2232 static int marked_vtable_pathp (binfo
) tree binfo
;
2233 { return BINFO_VTABLE_PATH_MARKED (binfo
); }
2234 static int unmarked_vtable_pathp (binfo
) tree binfo
;
2235 { return BINFO_VTABLE_PATH_MARKED (binfo
) == 0; }
2236 static int marked_new_vtablep (binfo
) tree binfo
;
2237 { return BINFO_NEW_VTABLE_MARKED (binfo
); }
2238 static int unmarked_new_vtablep (binfo
) tree binfo
;
2239 { return BINFO_NEW_VTABLE_MARKED (binfo
) == 0; }
2240 static int marked_pushdecls_p (binfo
) tree binfo
;
2241 { return BINFO_PUSHDECLS_MARKED (binfo
); }
2242 static int unmarked_pushdecls_p (binfo
) tree binfo
;
2243 { return BINFO_PUSHDECLS_MARKED (binfo
) == 0; }
2246 static int dfs_search_slot_nonempty_p (binfo
) tree binfo
;
2247 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) != 0; }
2250 static int dfs_debug_unmarkedp (binfo
) tree binfo
;
2251 { return CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo
)) == 0; }
2253 /* The worker functions for `dfs_walk'. These do not need to
2254 test anything (vis a vis marking) if they are paired with
2255 a predicate function (above). */
2259 dfs_mark (binfo
) tree binfo
;
2260 { SET_BINFO_MARKED (binfo
); }
2264 dfs_unmark (binfo
) tree binfo
;
2265 { CLEAR_BINFO_MARKED (binfo
); }
2269 dfs_mark_vtable_path (binfo
) tree binfo
;
2270 { SET_BINFO_VTABLE_PATH_MARKED (binfo
); }
2273 dfs_unmark_vtable_path (binfo
) tree binfo
;
2274 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
); }
2277 dfs_mark_new_vtable (binfo
) tree binfo
;
2278 { SET_BINFO_NEW_VTABLE_MARKED (binfo
); }
2281 dfs_unmark_new_vtable (binfo
) tree binfo
;
2282 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
); }
2285 dfs_clear_search_slot (binfo
) tree binfo
;
2286 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo
)) = 0; }
2290 dfs_debug_mark (binfo
)
2293 tree t
= BINFO_TYPE (binfo
);
2295 /* Use heuristic that if there are virtual functions,
2296 ignore until we see a non-inline virtual function. */
2297 tree methods
= CLASSTYPE_METHOD_VEC (t
);
2299 CLASSTYPE_DEBUG_REQUESTED (t
) = 1;
2304 /* If interface info is known, either we've already emitted the debug
2305 info or we don't need to. */
2306 if (CLASSTYPE_INTERFACE_KNOWN (t
))
2309 /* If debug info is requested from this context for this type, supply it.
2310 If debug info is requested from another context for this type,
2311 see if some third context can supply it. */
2312 if (current_function_decl
== NULL_TREE
2313 || DECL_CLASS_CONTEXT (current_function_decl
) != t
)
2315 if (TREE_VEC_ELT (methods
, 1))
2316 methods
= TREE_VEC_ELT (methods
, 1);
2317 else if (TREE_VEC_ELT (methods
, 0))
2318 methods
= TREE_VEC_ELT (methods
, 0);
2320 methods
= TREE_VEC_ELT (methods
, 2);
2321 methods
= OVL_CURRENT (methods
);
2324 if (DECL_VINDEX (methods
)
2325 && DECL_THIS_INLINE (methods
) == 0
2326 && DECL_ABSTRACT_VIRTUAL_P (methods
) == 0)
2328 /* Somebody, somewhere is going to have to define this
2329 virtual function. When they do, they will provide
2330 the debugging info. */
2333 methods
= TREE_CHAIN (methods
);
2336 /* We cannot rely on some alien method to solve our problems,
2337 so we must write out the debug info ourselves. */
2338 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t
)) = 0;
2339 rest_of_type_compilation (t
, toplevel_bindings_p ());
2342 /* Attach to the type of the virtual base class, the pointer to the
2343 virtual base class, given the global pointer vbase_decl_ptr.
2345 We use the global vbase_types. ICK! */
2348 dfs_find_vbases (binfo
)
2351 tree binfos
= BINFO_BASETYPES (binfo
);
2352 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2354 for (i
= n_baselinks
-1; i
>= 0; i
--)
2356 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2358 if (TREE_VIA_VIRTUAL (base_binfo
)
2359 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo
)) == 0)
2361 tree vbase
= BINFO_TYPE (base_binfo
);
2362 tree binfo
= binfo_member (vbase
, vbase_types
);
2364 CLASSTYPE_SEARCH_SLOT (vbase
)
2365 = build (PLUS_EXPR
, build_pointer_type (vbase
),
2366 vbase_decl_ptr
, BINFO_OFFSET (binfo
));
2369 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
2370 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
2374 dfs_init_vbase_pointers (binfo
)
2377 tree type
= BINFO_TYPE (binfo
);
2378 tree fields
= TYPE_FIELDS (type
);
2379 tree this_vbase_ptr
;
2381 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2384 /* See finish_struct_1 for when we can enable this. */
2385 /* If we have a vtable pointer first, skip it. */
2386 if (VFIELD_NAME_P (DECL_NAME (fields
)))
2387 fields
= TREE_CHAIN (fields
);
2390 if (fields
== NULL_TREE
2391 || DECL_NAME (fields
) == NULL_TREE
2392 || ! VBASE_NAME_P (DECL_NAME (fields
)))
2395 this_vbase_ptr
= vbase_decl_ptr_intermediate
;
2397 if (build_pointer_type (type
) != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr
)))
2398 my_friendly_abort (125);
2400 while (fields
&& DECL_NAME (fields
)
2401 && VBASE_NAME_P (DECL_NAME (fields
)))
2403 tree ref
= build (COMPONENT_REF
, TREE_TYPE (fields
),
2404 build_indirect_ref (this_vbase_ptr
, NULL_PTR
), fields
);
2405 tree init
= CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields
)));
2406 vbase_init_result
= tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields
)),
2408 build_modify_expr (ref
, NOP_EXPR
, init
),
2410 fields
= TREE_CHAIN (fields
);
2414 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2415 times, just NEW_VTABLE, but optimizer should make both with equal
2416 efficiency (though it does not currently). */
2419 dfs_clear_vbase_slots (binfo
)
2422 tree type
= BINFO_TYPE (binfo
);
2423 CLASSTYPE_SEARCH_SLOT (type
) = 0;
2424 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo
);
2425 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2429 init_vbase_pointers (type
, decl_ptr
)
2433 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2435 int old_flag
= flag_this_is_variable
;
2436 tree binfo
= TYPE_BINFO (type
);
2437 flag_this_is_variable
= -2;
2438 vbase_types
= CLASSTYPE_VBASECLASSES (type
);
2439 vbase_decl_ptr
= vbase_decl_ptr_intermediate
= decl_ptr
;
2440 vbase_init_result
= NULL_TREE
;
2441 dfs_walk (binfo
, dfs_find_vbases
, unmarked_vtable_pathp
);
2442 dfs_walk (binfo
, dfs_init_vbase_pointers
, marked_vtable_pathp
);
2443 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
2444 flag_this_is_variable
= old_flag
;
2445 return vbase_init_result
;
2450 /* get the virtual context (the vbase that directly contains the
2451 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2452 or NULL_TREE if there is none.
2454 FNDECL must come from a virtual table from a virtual base to ensure that
2455 there is only one possible DECL_CLASS_CONTEXT.
2457 We know that if there is more than one place (binfo) the fndecl that the
2458 declared, they all refer to the same binfo. See get_class_offset_1 for
2459 the check that ensures this. */
2462 virtual_context (fndecl
, t
, vbase
)
2463 tree fndecl
, t
, vbase
;
2466 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), t
, 0, &path
) < 0)
2468 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2469 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl
), vbase
, 0, &path
) >= 0)
2473 /* Not sure if checking path == vbase is necessary here, but just in
2475 if (TREE_VIA_VIRTUAL (path
) || path
== vbase
)
2476 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2477 path
= BINFO_INHERITANCE_CHAIN (path
);
2480 /* This shouldn't happen, I don't want errors! */
2481 warning ("recoverable compiler error, fixups for virtual function");
2486 if (TREE_VIA_VIRTUAL (path
))
2487 return binfo_member (BINFO_TYPE (path
), CLASSTYPE_VBASECLASSES (t
));
2488 path
= BINFO_INHERITANCE_CHAIN (path
);
2493 /* Fixups upcast offsets for one vtable.
2494 Entries may stay within the VBASE given, or
2495 they may upcast into a direct base, or
2496 they may upcast into a different vbase.
2498 We only need to do fixups in case 2 and 3. In case 2, we add in
2499 the virtual base offset to effect an upcast, in case 3, we add in
2500 the virtual base offset to effect an upcast, then subtract out the
2501 offset for the other virtual base, to effect a downcast into it.
2503 This routine mirrors fixup_vtable_deltas in functionality, though
2504 this one is runtime based, and the other is compile time based.
2505 Conceivably that routine could be removed entirely, and all fixups
2508 VBASE_OFFSETS is an association list of virtual bases that contains
2509 offset information for the virtual bases, so the offsets are only
2510 calculated once. The offsets are computed by where we think the
2511 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2512 the vbase really is. */
2515 expand_upcast_fixups (binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
,
2517 tree binfo
, addr
, orig_addr
, vbase
, vbase_addr
, t
, *vbase_offsets
;
2519 tree virtuals
= BINFO_VIRTUALS (binfo
);
2522 unsigned HOST_WIDE_INT n
;
2524 delta
= purpose_member (vbase
, *vbase_offsets
);
2527 delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase
));
2528 delta
= build (MINUS_EXPR
, ptrdiff_type_node
, delta
, vbase_addr
);
2529 delta
= save_expr (delta
);
2530 delta
= tree_cons (vbase
, delta
, *vbase_offsets
);
2531 *vbase_offsets
= delta
;
2534 n
= skip_rtti_stuff (&virtuals
);
2538 tree current_fndecl
= TREE_VALUE (virtuals
);
2539 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2540 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2542 && current_fndecl
!= abort_fndecl
2543 && (vc
=virtual_context (current_fndecl
, t
, vbase
)) != vbase
)
2545 /* This may in fact need a runtime fixup. */
2546 tree idx
= build_int_2 (n
, 0);
2547 tree vtbl
= BINFO_VTABLE (binfo
);
2548 tree nvtbl
= lookup_name (DECL_NAME (vtbl
), 0);
2549 tree aref
, ref
, naref
;
2550 tree old_delta
, new_delta
;
2553 if (nvtbl
== NULL_TREE
2554 || nvtbl
== IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl
)))
2556 /* Dup it if it isn't in local scope yet. */
2558 (VAR_DECL
, DECL_NAME (vtbl
),
2559 TYPE_MAIN_VARIANT (TREE_TYPE (vtbl
)));
2560 DECL_ALIGN (nvtbl
) = MAX (TYPE_ALIGN (double_type_node
),
2561 DECL_ALIGN (nvtbl
));
2562 TREE_READONLY (nvtbl
) = 0;
2563 DECL_ARTIFICIAL (nvtbl
) = 1;
2564 nvtbl
= pushdecl (nvtbl
);
2566 cp_finish_decl (nvtbl
, init
, NULL_TREE
, 0,
2567 LOOKUP_ONLYCONVERTING
);
2569 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2570 because they wouldn't be useful; everything that wants to
2571 look at the vtable will look at the decl for the normal
2572 vtable. Setting DECL_CONTEXT also screws up
2573 decl_function_context. */
2575 init
= build (MODIFY_EXPR
, TREE_TYPE (nvtbl
),
2577 TREE_SIDE_EFFECTS (init
) = 1;
2578 expand_expr_stmt (init
);
2579 /* Update the vtable pointers as necessary. */
2580 ref
= build_vfield_ref
2581 (build_indirect_ref (addr
, NULL_PTR
),
2582 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))));
2584 (build_modify_expr (ref
, NOP_EXPR
, nvtbl
));
2586 assemble_external (vtbl
);
2587 aref
= build_array_ref (vtbl
, idx
);
2588 naref
= build_array_ref (nvtbl
, idx
);
2589 old_delta
= build_component_ref (aref
, delta_identifier
,
2591 new_delta
= build_component_ref (naref
, delta_identifier
,
2594 /* This is a upcast, so we have to add the offset for the
2596 old_delta
= build_binary_op (PLUS_EXPR
, old_delta
,
2597 TREE_VALUE (delta
), 0);
2600 /* If this is set, we need to subtract out the delta
2601 adjustments for the other virtual base that we
2603 tree vc_delta
= purpose_member (vc
, *vbase_offsets
);
2606 tree vc_addr
= convert_pointer_to_real (vc
, orig_addr
);
2607 vc_delta
= CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc
));
2608 vc_delta
= build (MINUS_EXPR
, ptrdiff_type_node
,
2610 vc_delta
= save_expr (vc_delta
);
2611 *vbase_offsets
= tree_cons (vc
, vc_delta
, *vbase_offsets
);
2614 vc_delta
= TREE_VALUE (vc_delta
);
2616 /* This is a downcast, so we have to subtract the offset
2617 for the virtual base. */
2618 old_delta
= build_binary_op (MINUS_EXPR
, old_delta
, vc_delta
, 0);
2621 TREE_READONLY (new_delta
) = 0;
2622 TREE_TYPE (new_delta
) =
2623 cp_build_qualified_type (TREE_TYPE (new_delta
),
2624 CP_TYPE_QUALS (TREE_TYPE (new_delta
))
2625 & ~TYPE_QUAL_CONST
);
2626 expand_expr_stmt (build_modify_expr (new_delta
, NOP_EXPR
,
2630 virtuals
= TREE_CHAIN (virtuals
);
2634 /* Fixup upcast offsets for all direct vtables. Patterned after
2635 expand_direct_vtbls_init. */
2638 fixup_virtual_upcast_offsets (real_binfo
, binfo
, init_self
, can_elide
, addr
, orig_addr
, type
, vbase
, vbase_offsets
)
2639 tree real_binfo
, binfo
;
2640 int init_self
, can_elide
;
2641 tree addr
, orig_addr
, type
, vbase
, *vbase_offsets
;
2643 tree real_binfos
= BINFO_BASETYPES (real_binfo
);
2644 tree binfos
= BINFO_BASETYPES (binfo
);
2645 int i
, n_baselinks
= real_binfos
? TREE_VEC_LENGTH (real_binfos
) : 0;
2647 for (i
= 0; i
< n_baselinks
; i
++)
2649 tree real_base_binfo
= TREE_VEC_ELT (real_binfos
, i
);
2650 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2651 int is_not_base_vtable
2652 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo
));
2653 if (! TREE_VIA_VIRTUAL (real_base_binfo
))
2654 fixup_virtual_upcast_offsets (real_base_binfo
, base_binfo
,
2655 is_not_base_vtable
, can_elide
, addr
,
2656 orig_addr
, type
, vbase
, vbase_offsets
);
2659 /* Before turning this on, make sure it is correct. */
2660 if (can_elide
&& ! BINFO_MODIFIED (binfo
))
2663 /* Should we use something besides CLASSTYPE_VFIELDS? */
2664 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo
)))
2666 tree new_addr
= convert_pointer_to_real (binfo
, addr
);
2667 expand_upcast_fixups (real_binfo
, new_addr
, orig_addr
, vbase
, addr
,
2668 type
, vbase_offsets
);
2672 /* Build a COMPOUND_EXPR which when expanded will generate the code
2673 needed to initialize all the virtual function table slots of all
2674 the virtual baseclasses. MAIN_BINFO is the binfo which determines
2675 the virtual baseclasses to use; TYPE is the type of the object to
2676 which the initialization applies. TRUE_EXP is the true object we
2677 are initializing, and DECL_PTR is the pointer to the sub-object we
2680 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
2681 object was laid out by a top-level constructor and the computed
2682 offsets are valid to store vtables. When zero, we must store new
2683 vtables through virtual baseclass pointers.
2685 We setup and use the globals: vbase_decl_ptr, vbase_types
2689 expand_indirect_vtbls_init (binfo
, true_exp
, decl_ptr
)
2691 tree true_exp
, decl_ptr
;
2693 tree type
= BINFO_TYPE (binfo
);
2695 /* This function executes during the finish_function() segment,
2696 AFTER the auto variables and temporary stack space has been marked
2697 unused...If space is needed for the virtual function tables,
2698 some of them might fit within what the compiler now thinks
2699 are available stack slots... These values are actually initialized at
2700 the beginnning of the function, so when the automatics use their space,
2701 they will overwrite the values that are placed here. Marking all
2702 temporary space as unavailable prevents this from happening. */
2704 mark_all_temps_used();
2706 if (TYPE_USES_VIRTUAL_BASECLASSES (type
))
2708 rtx fixup_insns
= NULL_RTX
;
2709 tree vbases
= CLASSTYPE_VBASECLASSES (type
);
2710 vbase_types
= vbases
;
2711 vbase_decl_ptr
= true_exp
? build_unary_op (ADDR_EXPR
, true_exp
, 0) : decl_ptr
;
2713 dfs_walk (binfo
, dfs_find_vbases
, unmarked_new_vtablep
);
2715 /* Initialized with vtables of type TYPE. */
2716 for (; vbases
; vbases
= TREE_CHAIN (vbases
))
2720 addr
= convert_pointer_to_vbase (TREE_TYPE (vbases
), vbase_decl_ptr
);
2722 /* Do all vtables from this virtual base. */
2723 /* This assumes that virtual bases can never serve as parent
2724 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
2725 expand_direct_vtbls_init (vbases
, TYPE_BINFO (BINFO_TYPE (vbases
)),
2728 /* Now we adjust the offsets for virtual functions that
2729 cross virtual boundaries on an implicit upcast on vf call
2730 so that the layout of the most complete type is used,
2731 instead of assuming the layout of the virtual bases from
2732 our current type. */
2734 if (flag_vtable_thunks
)
2736 /* We don't have dynamic thunks yet!
2737 So for now, just fail silently. */
2741 tree vbase_offsets
= NULL_TREE
;
2742 push_to_sequence (fixup_insns
);
2743 fixup_virtual_upcast_offsets (vbases
,
2744 TYPE_BINFO (BINFO_TYPE (vbases
)),
2745 1, 0, addr
, vbase_decl_ptr
,
2746 type
, vbases
, &vbase_offsets
);
2747 fixup_insns
= get_insns ();
2754 extern tree in_charge_identifier
;
2755 tree in_charge_node
= lookup_name (in_charge_identifier
, 0);
2756 if (! in_charge_node
)
2758 warning ("recoverable internal compiler error, nobody's in charge!");
2759 in_charge_node
= integer_zero_node
;
2761 in_charge_node
= build_binary_op (EQ_EXPR
, in_charge_node
, integer_zero_node
, 1);
2762 expand_start_cond (in_charge_node
, 0);
2763 emit_insns (fixup_insns
);
2767 dfs_walk (binfo
, dfs_clear_vbase_slots
, marked_new_vtablep
);
2771 /* get virtual base class types.
2772 This adds type to the vbase_types list in reverse dfs order.
2773 Ordering is very important, so don't change it. */
2776 dfs_get_vbase_types (binfo
)
2779 if (TREE_VIA_VIRTUAL (binfo
) && ! BINFO_VBASE_MARKED (binfo
))
2781 tree new_vbase
= make_binfo (integer_zero_node
, binfo
,
2782 BINFO_VTABLE (binfo
),
2783 BINFO_VIRTUALS (binfo
));
2784 TREE_CHAIN (new_vbase
) = vbase_types
;
2785 TREE_VIA_VIRTUAL (new_vbase
) = 1;
2786 vbase_types
= new_vbase
;
2787 SET_BINFO_VBASE_MARKED (binfo
);
2789 SET_BINFO_MARKED (binfo
);
2792 /* get a list of virtual base classes in dfs order. */
2795 get_vbase_types (type
)
2801 binfo
= TYPE_BINFO (type
);
2802 vbase_types
= NULL_TREE
;
2803 dfs_walk (binfo
, dfs_get_vbase_types
, unmarkedp
);
2804 dfs_walk (binfo
, dfs_unmark
, markedp
);
2805 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2806 reverse it so that we get normal dfs ordering. */
2807 vbase_types
= nreverse (vbase_types
);
2809 /* unmark marked vbases */
2810 for (vbases
= vbase_types
; vbases
; vbases
= TREE_CHAIN (vbases
))
2811 CLEAR_BINFO_VBASE_MARKED (vbases
);
2816 /* If we want debug info for a type TYPE, make sure all its base types
2817 are also marked as being potentially interesting. This avoids
2818 the problem of not writing any debug info for intermediate basetypes
2819 that have abstract virtual functions. Also mark member types. */
2822 note_debug_info_needed (type
)
2827 if (current_template_parms
)
2830 if (TYPE_BEING_DEFINED (type
))
2831 /* We can't go looking for the base types and fields just yet. */
2834 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2835 does not support name references between translation units. Well, we
2836 could, but that would mean putting global labels in the debug output
2837 before each exported type and each of its functions and static data
2839 if (write_symbols
== DWARF_DEBUG
|| write_symbols
== DWARF2_DEBUG
)
2842 dfs_walk (TYPE_BINFO (type
), dfs_debug_mark
, dfs_debug_unmarkedp
);
2843 for (field
= TYPE_FIELDS (type
); field
; field
= TREE_CHAIN (field
))
2846 if (TREE_CODE (field
) == FIELD_DECL
2847 && IS_AGGR_TYPE (ttype
= target_type (TREE_TYPE (field
)))
2848 && dfs_debug_unmarkedp (TYPE_BINFO (ttype
)))
2849 note_debug_info_needed (ttype
);
2853 /* Subroutines of push_class_decls (). */
2855 /* Add in a decl to the envelope. */
2857 envelope_add_decl (type
, decl
, values
)
2858 tree type
, decl
, *values
;
2861 tree name
= DECL_NAME (decl
);
2864 /* Yet Another Implicit Typename Kludge: Since we don't tsubst
2865 the members for partial instantiations, DECL_CONTEXT (decl) is wrong.
2866 But pretend it's right for this function. */
2867 if (processing_template_decl
)
2868 type
= DECL_REAL_CONTEXT (decl
);
2870 /* virtual base names are always unique. */
2871 if (VBASE_NAME_P (name
))
2872 *values
= NULL_TREE
;
2874 /* Possible ambiguity. If its defining type(s)
2875 is (are all) derived from us, no problem. */
2876 else if (*values
&& TREE_CODE (*values
) != TREE_LIST
)
2878 tree value
= *values
;
2879 /* Only complain if we shadow something we can access. */
2880 if (warn_shadow
&& TREE_CODE (decl
) == FUNCTION_DECL
2881 && ((DECL_LANG_SPECIFIC (*values
)
2882 && DECL_CLASS_CONTEXT (value
) == current_class_type
)
2883 || ! TREE_PRIVATE (value
)))
2884 /* Should figure out access control more accurately. */
2886 cp_warning_at ("member `%#D' is shadowed", value
);
2887 cp_warning_at ("by member function `%#D'", decl
);
2888 warning ("in this context");
2891 context
= DECL_REAL_CONTEXT (value
);
2893 if (context
== type
)
2895 if (TREE_CODE (value
) == TYPE_DECL
2896 && DECL_ARTIFICIAL (value
))
2897 *values
= NULL_TREE
;
2901 else if (type
== current_class_type
2902 || DERIVED_FROM_P (context
, type
))
2904 /* Don't add in *values to list */
2905 *values
= NULL_TREE
;
2908 *values
= build_tree_list (NULL_TREE
, value
);
2911 for (tmp
= values
; *tmp
;)
2913 tree value
= TREE_VALUE (*tmp
);
2914 my_friendly_assert (TREE_CODE (value
) != TREE_LIST
, 999);
2915 context
= (TREE_CODE (value
) == FUNCTION_DECL
2916 && DECL_VIRTUAL_P (value
))
2917 ? DECL_CLASS_CONTEXT (value
)
2918 : DECL_CONTEXT (value
);
2920 if (type
== current_class_type
2921 || DERIVED_FROM_P (context
, type
))
2923 /* remove *tmp from list */
2924 *tmp
= TREE_CHAIN (*tmp
);
2927 tmp
= &TREE_CHAIN (*tmp
);
2932 /* Put the new contents in our envelope. */
2933 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2935 *values
= tree_cons (name
, decl
, *values
);
2936 TREE_NONLOCAL_FLAG (*values
) = 1;
2937 TREE_TYPE (*values
) = unknown_type_node
;
2943 *values
= tree_cons (NULL_TREE
, decl
, *values
);
2944 /* Mark this as a potentially ambiguous member. */
2945 /* Leaving TREE_TYPE blank is intentional.
2946 We cannot use `error_mark_node' (lookup_name)
2947 or `unknown_type_node' (all member functions use this). */
2948 TREE_NONLOCAL_FLAG (*values
) = 1;
2956 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2957 because it (or one of the intermediate bases) depends on template parms. */
2960 dependent_base_p (binfo
)
2963 for (; binfo
; binfo
= BINFO_INHERITANCE_CHAIN (binfo
))
2965 if (TREE_TYPE (binfo
) == current_class_type
)
2967 if (uses_template_parms (TREE_TYPE (binfo
)))
2973 /* Add the instance variables which this class contributed to the
2974 current class binding contour. When a redefinition occurs, if the
2975 redefinition is strictly within a single inheritance path, we just
2976 overwrite the old declaration with the new. If the fields are not
2977 within a single inheritance path, we must cons them.
2979 In order to know what decls are new (stemming from the current
2980 invocation of push_class_decls) we enclose them in an "envelope",
2981 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
2982 new decl (or possibly a list of competing ones), the TREE_VALUE slot
2983 points to the old value and the TREE_CHAIN slot chains together all
2984 envelopes which needs to be "opened" in push_class_decls. Opening an
2985 envelope means: push the old value onto the class_shadowed list,
2986 install the new one and if it's a TYPE_DECL do the same to the
2987 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
2988 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
2989 Because if it is, it could be a set of overloaded methods from an
2993 dfs_pushdecls (binfo
)
2996 tree type
= BINFO_TYPE (binfo
);
3001 /* Only record types if we're a template base. */
3002 if (processing_template_decl
&& type
!= current_class_type
3003 && dependent_base_p (binfo
))
3006 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3008 if (dummy
&& TREE_CODE (fields
) != TYPE_DECL
)
3011 /* Unmark so that if we are in a constructor, and then find that
3012 this field was initialized by a base initializer,
3013 we can emit an error message. */
3014 if (TREE_CODE (fields
) == FIELD_DECL
)
3015 TREE_USED (fields
) = 0;
3017 /* Recurse into anonymous unions. */
3018 if (DECL_NAME (fields
) == NULL_TREE
3019 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3021 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields
)));
3025 if (DECL_NAME (fields
))
3027 tree name
= DECL_NAME (fields
);
3028 tree class_value
= IDENTIFIER_CLASS_VALUE (name
);
3030 /* If the class value is not an envelope of the kind described in
3031 the comment above, we create a new envelope. */
3032 maybe_push_cache_obstack ();
3033 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3034 || TREE_PURPOSE (class_value
) == NULL_TREE
3035 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3037 /* See comment above for a description of envelopes. */
3038 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3040 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
3041 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3044 envelope_add_decl (type
, fields
, &TREE_PURPOSE (class_value
));
3049 method_vec
= CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
3050 if (method_vec
&& ! dummy
)
3055 /* Farm out constructors and destructors. */
3056 end
= TREE_VEC_END (method_vec
);
3058 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3059 *methods
&& methods
!= end
;
3062 /* This will cause lookup_name to return a pointer
3063 to the tree_list of possible methods of this name. */
3068 name
= DECL_NAME (OVL_CURRENT (*methods
));
3069 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3071 maybe_push_cache_obstack ();
3073 /* If the class value is not an envelope of the kind described in
3074 the comment above, we create a new envelope. */
3075 if (class_value
== NULL_TREE
|| TREE_CODE (class_value
) != TREE_LIST
3076 || TREE_PURPOSE (class_value
) == NULL_TREE
3077 || TREE_CODE (TREE_PURPOSE (class_value
)) == IDENTIFIER_NODE
)
3079 /* See comment above for a description of envelopes. */
3080 closed_envelopes
= tree_cons (NULL_TREE
, class_value
,
3082 IDENTIFIER_CLASS_VALUE (name
) = closed_envelopes
;
3083 class_value
= IDENTIFIER_CLASS_VALUE (name
);
3086 /* Here we try to rule out possible ambiguities.
3087 If we can't do that, keep a TREE_LIST with possibly ambiguous
3089 /* Arbitrarily choose the first function in the list. This is OK
3090 because this is only used for initial lookup; anything that
3091 actually uses the function will look it up again. */
3092 envelope_add_decl (type
, OVL_CURRENT (*methods
),
3093 &TREE_PURPOSE (class_value
));
3098 /* We can't just use BINFO_MARKED because envelope_add_decl uses
3099 DERIVED_FROM_P, which calls get_base_distance. */
3100 SET_BINFO_PUSHDECLS_MARKED (binfo
);
3103 /* Consolidate unique (by name) member functions. */
3106 dfs_compress_decls (binfo
)
3109 tree type
= BINFO_TYPE (binfo
);
3111 = CLASS_TYPE_P (type
) ? CLASSTYPE_METHOD_VEC (type
) : NULL_TREE
;
3113 if (processing_template_decl
&& type
!= current_class_type
3114 && dependent_base_p (binfo
))
3115 /* We only record types if we're a template base. */;
3116 else if (method_vec
!= 0)
3118 /* Farm out constructors and destructors. */
3120 tree
*end
= TREE_VEC_END (method_vec
);
3122 for (methods
= &TREE_VEC_ELT (method_vec
, 2);
3123 methods
!= end
&& *methods
; methods
++)
3125 /* This is known to be an envelope of the kind described before
3128 IDENTIFIER_CLASS_VALUE (DECL_NAME (OVL_CURRENT (*methods
)));
3129 tree tmp
= TREE_PURPOSE (class_value
);
3131 /* This was replaced in scope by somebody else. Just leave it
3133 if (TREE_CODE (tmp
) != TREE_LIST
)
3136 if (TREE_CHAIN (tmp
) == NULL_TREE
3138 && OVL_NEXT (TREE_VALUE (tmp
)) == NULL_TREE
)
3140 TREE_PURPOSE (class_value
) = TREE_VALUE (tmp
);
3144 CLEAR_BINFO_PUSHDECLS_MARKED (binfo
);
3147 /* When entering the scope of a class, we cache all of the
3148 fields that that class provides within its inheritance
3149 lattice. Where ambiguities result, we mark them
3150 with `error_mark_node' so that if they are encountered
3151 without explicit qualification, we can emit an error
3155 push_class_decls (type
)
3158 struct obstack
*ambient_obstack
= current_obstack
;
3159 search_stack
= push_search_level (search_stack
, &search_obstack
);
3161 /* Build up all the relevant bindings and such on the cache
3162 obstack. That way no memory is wasted when we throw away the
3164 maybe_push_cache_obstack ();
3166 /* Push class fields into CLASS_VALUE scope, and mark. */
3167 dfs_walk (TYPE_BINFO (type
), dfs_pushdecls
, unmarked_pushdecls_p
);
3169 /* Compress fields which have only a single entry
3170 by a given name, and unmark. */
3171 dfs_walk (TYPE_BINFO (type
), dfs_compress_decls
, marked_pushdecls_p
);
3173 /* Open up all the closed envelopes and push the contained decls into
3175 while (closed_envelopes
)
3177 tree
new = TREE_PURPOSE (closed_envelopes
);
3180 /* This is messy because the class value may be a *_DECL, or a
3181 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3182 *_DECLs. The name is stored at different places in these three
3184 if (TREE_CODE (new) == TREE_LIST
)
3186 if (TREE_PURPOSE (new) != NULL_TREE
)
3187 id
= TREE_PURPOSE (new);
3190 tree node
= TREE_VALUE (new);
3192 if (TREE_CODE (node
) == TYPE_DECL
3193 && DECL_ARTIFICIAL (node
)
3194 && IS_AGGR_TYPE (TREE_TYPE (node
))
3195 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (node
)))
3197 tree t
= CLASSTYPE_TI_TEMPLATE (TREE_TYPE (node
));
3200 for (; n
; n
= TREE_CHAIN (n
))
3202 tree d
= TREE_VALUE (n
);
3203 if (TREE_CODE (d
) == TYPE_DECL
3204 && DECL_ARTIFICIAL (node
)
3205 && IS_AGGR_TYPE (TREE_TYPE (d
))
3206 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (d
))
3207 && CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d
)) == t
)
3216 else while (TREE_CODE (node
) == TREE_LIST
)
3217 node
= TREE_VALUE (node
);
3218 id
= DECL_NAME (node
);
3222 id
= DECL_NAME (new);
3224 /* Install the original class value in order to make
3225 pushdecl_class_level work correctly. */
3226 IDENTIFIER_CLASS_VALUE (id
) = TREE_VALUE (closed_envelopes
);
3227 if (TREE_CODE (new) == TREE_LIST
)
3228 push_class_level_binding (id
, new);
3230 pushdecl_class_level (new);
3231 closed_envelopes
= TREE_CHAIN (closed_envelopes
);
3234 /* Undo the call to maybe_push_cache_obstack above. */
3237 current_obstack
= ambient_obstack
;
3240 /* Here's a subroutine we need because C lacks lambdas. */
3243 dfs_unuse_fields (binfo
)
3246 tree type
= TREE_TYPE (binfo
);
3249 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
3251 if (TREE_CODE (fields
) != FIELD_DECL
)
3254 TREE_USED (fields
) = 0;
3255 if (DECL_NAME (fields
) == NULL_TREE
3256 && TREE_CODE (TREE_TYPE (fields
)) == UNION_TYPE
)
3257 unuse_fields (TREE_TYPE (fields
));
3265 dfs_walk (TYPE_BINFO (type
), dfs_unuse_fields
, unmarkedp
);
3271 /* We haven't pushed a search level when dealing with cached classes,
3272 so we'd better not try to pop it. */
3274 search_stack
= pop_search_level (search_stack
);
3278 print_search_statistics ()
3280 #ifdef GATHER_STATISTICS
3281 fprintf (stderr
, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3282 n_fields_searched
, n_calls_lookup_field
, n_calls_lookup_field_1
);
3283 fprintf (stderr
, "%d fnfields searched in %d calls to lookup_fnfields\n",
3284 n_outer_fields_searched
, n_calls_lookup_fnfields
);
3285 fprintf (stderr
, "%d calls to get_base_type\n", n_calls_get_base_type
);
3286 #else /* GATHER_STATISTICS */
3287 fprintf (stderr
, "no search statistics\n");
3288 #endif /* GATHER_STATISTICS */
3292 init_search_processing ()
3294 gcc_obstack_init (&search_obstack
);
3295 _vptr_name
= get_identifier ("_vptr");
3299 reinit_search_statistics ()
3301 #ifdef GATHER_STATISTICS
3302 n_fields_searched
= 0;
3303 n_calls_lookup_field
= 0, n_calls_lookup_field_1
= 0;
3304 n_calls_lookup_fnfields
= 0, n_calls_lookup_fnfields_1
= 0;
3305 n_calls_get_base_type
= 0;
3306 n_outer_fields_searched
= 0;
3307 n_contexts_saved
= 0;
3308 #endif /* GATHER_STATISTICS */
3311 #define scratch_tree_cons expr_tree_cons
3313 static tree conversions
;
3315 add_conversions (binfo
)
3319 tree method_vec
= CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo
));
3321 for (i
= 2; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
3323 tree tmp
= TREE_VEC_ELT (method_vec
, i
);
3326 if (!tmp
|| ! DECL_CONV_FN_P (OVL_CURRENT (tmp
)))
3329 name
= DECL_NAME (OVL_CURRENT (tmp
));
3331 /* Make sure we don't already have this conversion. */
3332 if (! IDENTIFIER_MARKED (name
))
3334 conversions
= scratch_tree_cons (binfo
, tmp
, conversions
);
3335 IDENTIFIER_MARKED (name
) = 1;
3342 lookup_conversions (type
)
3347 conversions
= NULL_TREE
;
3349 if (TYPE_SIZE (type
))
3350 breadth_first_search (TYPE_BINFO (type
), add_conversions
, 0);
3352 for (t
= conversions
; t
; t
= TREE_CHAIN (t
))
3353 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t
)))) = 0;
3358 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3359 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3361 static tree compare_type
;
3362 static int found_overlap
;
3364 dfs_check_overlap (empty_binfo
)
3368 for (binfo
= TYPE_BINFO (compare_type
); ; binfo
= BINFO_BASETYPE (binfo
, 0))
3370 if (BINFO_TYPE (binfo
) == BINFO_TYPE (empty_binfo
))
3375 else if (BINFO_BASETYPES (binfo
) == NULL_TREE
)
3380 /* Trivial function to stop base traversal when we find something. */
3383 dfs_no_overlap_yet (t
)
3384 tree t ATTRIBUTE_UNUSED
;
3386 return found_overlap
== 0;
3389 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3390 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3393 types_overlap_p (empty_type
, next_type
)
3394 tree empty_type
, next_type
;
3396 if (! IS_AGGR_TYPE (next_type
))
3398 compare_type
= next_type
;
3400 dfs_walk (TYPE_BINFO (empty_type
), dfs_check_overlap
, dfs_no_overlap_yet
);
3401 return found_overlap
;
3404 /* Passed to dfs_search by binfo_for_vtable; determine if bvtable comes
3407 static tree bvtable
;
3409 dfs_bfv_helper (binfo
)
3412 if (BINFO_VTABLE (binfo
) == bvtable
)
3417 /* Given a vtable VARS, determine which binfo it comes from. */
3420 binfo_for_vtable (vars
)
3424 return dfs_search (TYPE_BINFO (DECL_CONTEXT (vars
)), dfs_bfv_helper
,
3425 DECL_CONTEXT (vars
));