]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/search.c
search.c (setup_class_bindings): Robustify.
[gcc.git] / gcc / cp / search.c
1 /* Breadth-first and depth-first routines for
2 searching multiple-inheritance lattice for GNU C++.
3 Copyright (C) 1987, 89, 92-97, 1998, 1999 Free Software Foundation, Inc.
4 Contributed by Michael Tiemann (tiemann@cygnus.com)
5
6 This file is part of GNU CC.
7
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)
11 any later version.
12
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.
17
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. */
22
23 /* High-level class interface. */
24
25 #include "config.h"
26 #include "system.h"
27 #include "tree.h"
28 #include "cp-tree.h"
29 #include "obstack.h"
30 #include "flags.h"
31 #include "rtl.h"
32 #include "output.h"
33 #include "toplev.h"
34 #include "varray.h"
35
36 #define obstack_chunk_alloc xmalloc
37 #define obstack_chunk_free free
38
39 extern struct obstack *current_obstack;
40
41 #include "stack.h"
42
43 /* Obstack used for remembering decision points of breadth-first. */
44
45 static struct obstack search_obstack;
46
47 /* Methods for pushing and popping objects to and from obstacks. */
48
49 struct stack_level *
50 push_stack_level (obstack, tp, size)
51 struct obstack *obstack;
52 char *tp; /* Sony NewsOS 5.0 compiler doesn't like void * here. */
53 int size;
54 {
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 *);
62 return stack;
63 }
64
65 struct stack_level *
66 pop_stack_level (stack)
67 struct stack_level *stack;
68 {
69 struct stack_level *tem = stack;
70 struct obstack *obstack = tem->obstack;
71 stack = tem->prev;
72 obstack_free (obstack, tem);
73 return stack;
74 }
75
76 #define search_level stack_level
77 static struct search_level *search_stack;
78
79 static tree get_abstract_virtuals_1 PROTO((tree, int, tree));
80 static tree next_baselink PROTO((tree));
81 static tree get_vbase_1 PROTO((tree, tree, unsigned int *));
82 static tree convert_pointer_to_vbase PROTO((tree, tree));
83 static tree lookup_field_1 PROTO((tree, tree));
84 static tree convert_pointer_to_single_level PROTO((tree, tree));
85 static int lookup_fnfields_here PROTO((tree, tree));
86 static int is_subobject_of_p PROTO((tree, tree));
87 static int hides PROTO((tree, tree));
88 static tree virtual_context PROTO((tree, tree, tree));
89 static tree dfs_check_overlap PROTO((tree, void *));
90 static tree dfs_no_overlap_yet PROTO((tree, void *));
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,
98 tree *));
99 static tree unmarkedp PROTO((tree, void *));
100 static tree marked_vtable_pathp PROTO((tree, void *));
101 static tree unmarked_vtable_pathp PROTO((tree, void *));
102 static tree marked_new_vtablep PROTO((tree, void *));
103 static tree unmarked_new_vtablep PROTO((tree, void *));
104 static tree marked_pushdecls_p PROTO((tree, void *));
105 static tree unmarked_pushdecls_p PROTO((tree, void *));
106 static tree dfs_debug_unmarkedp PROTO((tree, void *));
107 static tree dfs_debug_mark PROTO((tree, void *));
108 static tree dfs_find_vbases PROTO((tree, void *));
109 static tree dfs_clear_vbase_slots PROTO((tree, void *));
110 static tree dfs_init_vbase_pointers PROTO((tree, void *));
111 static tree dfs_get_vbase_types PROTO((tree, void *));
112 static tree dfs_push_type_decls PROTO((tree, void *));
113 static tree dfs_push_decls PROTO((tree, void *));
114 static tree dfs_unuse_fields PROTO((tree, void *));
115 static tree add_conversions PROTO((tree, void *));
116 static tree get_virtuals_named_this PROTO((tree, tree));
117 static tree get_virtual_destructor PROTO((tree, void *));
118 static tree tree_has_any_destructor_p PROTO((tree, void *));
119 static int covariant_return_p PROTO((tree, tree));
120 static int check_final_overrider PROTO((tree, tree));
121 static struct search_level *push_search_level
122 PROTO((struct stack_level *, struct obstack *));
123 static struct search_level *pop_search_level
124 PROTO((struct stack_level *));
125 static tree bfs_walk
126 PROTO((tree, tree (*) (tree, void *), tree (*) (tree, void *),
127 void *));
128 static tree lookup_field_queue_p PROTO((tree, void *));
129 static tree lookup_field_r PROTO((tree, void *));
130 static tree dfs_walk_real PROTO ((tree,
131 tree (*) (tree, void *),
132 tree (*) (tree, void *),
133 tree (*) (tree, void *),
134 void *));
135 static tree dfs_bfv_queue_p PROTO ((tree, void *));
136 static tree dfs_bfv_helper PROTO ((tree, void *));
137 static tree get_virtuals_named_this_r PROTO ((tree, void *));
138 static tree context_for_name_lookup PROTO ((tree));
139 static tree canonical_binfo PROTO ((tree));
140 static tree shared_marked_p PROTO ((tree, void *));
141 static tree shared_unmarked_p PROTO ((tree, void *));
142 static int dependent_base_p PROTO ((tree));
143 static tree dfs_accessible_queue_p PROTO ((tree, void *));
144 static tree dfs_accessible_p PROTO ((tree, void *));
145 static tree dfs_access_in_type PROTO ((tree, void *));
146 static tree access_in_type PROTO ((tree, tree));
147 static tree dfs_canonical_queue PROTO ((tree, void *));
148 static tree dfs_assert_unmarked_p PROTO ((tree, void *));
149 static void assert_canonical_unmarked PROTO ((tree));
150 static int protected_accessible_p PROTO ((tree, tree, tree, tree));
151 static int friend_accessible_p PROTO ((tree, tree, tree, tree));
152 static void setup_class_bindings PROTO ((tree, int));
153 static int template_self_reference_p PROTO ((tree, tree));
154
155 /* Allocate a level of searching. */
156
157 static struct search_level *
158 push_search_level (stack, obstack)
159 struct stack_level *stack;
160 struct obstack *obstack;
161 {
162 struct search_level tem;
163
164 tem.prev = stack;
165 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
166 }
167
168 /* Discard a level of search allocation. */
169
170 static struct search_level *
171 pop_search_level (obstack)
172 struct stack_level *obstack;
173 {
174 register struct search_level *stack = pop_stack_level (obstack);
175
176 return stack;
177 }
178 \f
179 static tree _vptr_name;
180
181 /* Variables for gathering statistics. */
182 #ifdef GATHER_STATISTICS
183 static int n_fields_searched;
184 static int n_calls_lookup_field, n_calls_lookup_field_1;
185 static int n_calls_lookup_fnfields, n_calls_lookup_fnfields_1;
186 static int n_calls_get_base_type;
187 static int n_outer_fields_searched;
188 static int n_contexts_saved;
189 #endif /* GATHER_STATISTICS */
190
191 \f
192 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
193 the same type as the type given in PARENT. To be optimal, we want
194 the first one that is found by going through the least number of
195 virtual bases.
196
197 This uses a clever algorithm that updates *depth when we find the vbase,
198 and cuts off other paths of search when they reach that depth. */
199
200 static tree
201 get_vbase_1 (parent, binfo, depth)
202 tree parent, binfo;
203 unsigned int *depth;
204 {
205 tree binfos;
206 int i, n_baselinks;
207 tree rval = NULL_TREE;
208
209 if (BINFO_TYPE (binfo) == parent && TREE_VIA_VIRTUAL (binfo))
210 {
211 *depth = 0;
212 return binfo;
213 }
214
215 *depth = *depth - 1;
216
217 binfos = BINFO_BASETYPES (binfo);
218 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
219
220 /* Process base types. */
221 for (i = 0; i < n_baselinks; i++)
222 {
223 tree base_binfo = TREE_VEC_ELT (binfos, i);
224 tree nrval;
225
226 if (*depth == 0)
227 break;
228
229 nrval = get_vbase_1 (parent, base_binfo, depth);
230 if (nrval)
231 rval = nrval;
232 }
233 *depth = *depth+1;
234 return rval;
235 }
236
237 /* Return the shortest path to vbase PARENT within BINFO, ignoring
238 access and ambiguity. */
239
240 tree
241 get_vbase (parent, binfo)
242 tree parent;
243 tree binfo;
244 {
245 unsigned int d = (unsigned int)-1;
246 return get_vbase_1 (parent, binfo, &d);
247 }
248
249 /* Convert EXPR to a virtual base class of type TYPE. We know that
250 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
251 the type of what expr points to has a virtual base of type TYPE. */
252
253 static tree
254 convert_pointer_to_vbase (type, expr)
255 tree type;
256 tree expr;
257 {
258 tree vb = get_vbase (type, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr))));
259 return convert_pointer_to_real (vb, expr);
260 }
261
262 /* Check whether the type given in BINFO is derived from PARENT. If
263 it isn't, return 0. If it is, but the derivation is MI-ambiguous
264 AND protect != 0, emit an error message and return error_mark_node.
265
266 Otherwise, if TYPE is derived from PARENT, return the actual base
267 information, unless a one of the protection violations below
268 occurs, in which case emit an error message and return error_mark_node.
269
270 If PROTECT is 1, then check if access to a public field of PARENT
271 would be private. Also check for ambiguity. */
272
273 tree
274 get_binfo (parent, binfo, protect)
275 register tree parent, binfo;
276 int protect;
277 {
278 tree type = NULL_TREE;
279 int dist;
280 tree rval = NULL_TREE;
281
282 if (TREE_CODE (parent) == TREE_VEC)
283 parent = BINFO_TYPE (parent);
284 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent)))
285 my_friendly_abort (89);
286
287 if (TREE_CODE (binfo) == TREE_VEC)
288 type = BINFO_TYPE (binfo);
289 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo)))
290 type = binfo;
291 else
292 my_friendly_abort (90);
293
294 dist = get_base_distance (parent, binfo, protect, &rval);
295
296 if (dist == -3)
297 {
298 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
299 parent, type);
300 return error_mark_node;
301 }
302 else if (dist == -2 && protect)
303 {
304 cp_error ("type `%T' is ambiguous base class for type `%T'", parent,
305 type);
306 return error_mark_node;
307 }
308
309 return rval;
310 }
311
312 /* This is the newer depth first get_base_distance routine. */
313
314 static int
315 get_base_distance_recursive (binfo, depth, is_private, rval,
316 rval_private_ptr, new_binfo_ptr, parent,
317 protect, via_virtual_ptr, via_virtual,
318 current_scope_in_chain)
319 tree binfo;
320 int depth, is_private, rval;
321 int *rval_private_ptr;
322 tree *new_binfo_ptr, parent;
323 int protect, *via_virtual_ptr, via_virtual;
324 int current_scope_in_chain;
325 {
326 tree binfos;
327 int i, n_baselinks;
328
329 if (protect
330 && !current_scope_in_chain
331 && is_friend (BINFO_TYPE (binfo), current_scope ()))
332 current_scope_in_chain = 1;
333
334 if (BINFO_TYPE (binfo) == parent || binfo == parent)
335 {
336 int better = 0;
337
338 if (rval == -1)
339 /* This is the first time we've found parent. */
340 better = 1;
341 else if (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr),
342 BINFO_OFFSET (binfo))
343 && *via_virtual_ptr && via_virtual)
344 {
345 /* A new path to the same vbase. If this one has better
346 access or is shorter, take it. */
347
348 if (protect)
349 better = *rval_private_ptr - is_private;
350 if (better == 0)
351 better = rval - depth;
352 }
353 else
354 {
355 /* Ambiguous base class. */
356 rval = depth = -2;
357
358 /* If we get an ambiguity between virtual and non-virtual base
359 class, return the non-virtual in case we are ignoring
360 ambiguity. */
361 better = *via_virtual_ptr - via_virtual;
362 }
363
364 if (better > 0)
365 {
366 rval = depth;
367 *rval_private_ptr = is_private;
368 *new_binfo_ptr = binfo;
369 *via_virtual_ptr = via_virtual;
370 }
371
372 return rval;
373 }
374
375 binfos = BINFO_BASETYPES (binfo);
376 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
377 depth += 1;
378
379 /* Process base types. */
380 for (i = 0; i < n_baselinks; i++)
381 {
382 tree base_binfo = TREE_VEC_ELT (binfos, i);
383
384 int via_private
385 = (protect
386 && (is_private
387 || (!TREE_VIA_PUBLIC (base_binfo)
388 && !(TREE_VIA_PROTECTED (base_binfo)
389 && current_scope_in_chain)
390 && !is_friend (BINFO_TYPE (binfo), current_scope ()))));
391 int this_virtual = via_virtual || TREE_VIA_VIRTUAL (base_binfo);
392
393 rval = get_base_distance_recursive (base_binfo, depth, via_private,
394 rval, rval_private_ptr,
395 new_binfo_ptr, parent,
396 protect, via_virtual_ptr,
397 this_virtual,
398 current_scope_in_chain);
399
400 /* If we've found a non-virtual, ambiguous base class, we don't need
401 to keep searching. */
402 if (rval == -2 && *via_virtual_ptr == 0)
403 return rval;
404 }
405
406 return rval;
407 }
408
409 /* Return the number of levels between type PARENT and the type given
410 in BINFO, following the leftmost path to PARENT not found along a
411 virtual path, if there are no real PARENTs (all come from virtual
412 base classes), then follow the shortest public path to PARENT.
413
414 Return -1 if TYPE is not derived from PARENT.
415 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
416 non-negative.
417 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
418
419 If PATH_PTR is non-NULL, then also build the list of types
420 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
421 set.
422
423 PARENT can also be a binfo, in which case that exact parent is found
424 and no other. convert_pointer_to_real uses this functionality.
425
426 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
427
428 int
429 get_base_distance (parent, binfo, protect, path_ptr)
430 register tree parent, binfo;
431 int protect;
432 tree *path_ptr;
433 {
434 int rval;
435 int rval_private = 0;
436 tree type = NULL_TREE;
437 tree new_binfo = NULL_TREE;
438 int via_virtual;
439 int watch_access = protect;
440
441 /* Should we be completing types here? */
442 if (TREE_CODE (parent) != TREE_VEC)
443 parent = complete_type (TYPE_MAIN_VARIANT (parent));
444 else
445 complete_type (TREE_TYPE (parent));
446
447 if (TREE_CODE (binfo) == TREE_VEC)
448 type = BINFO_TYPE (binfo);
449 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo)))
450 {
451 type = complete_type (binfo);
452 binfo = TYPE_BINFO (type);
453
454 if (path_ptr)
455 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo) == NULL_TREE,
456 980827);
457 }
458 else
459 my_friendly_abort (92);
460
461 if (parent == type || parent == binfo)
462 {
463 /* If the distance is 0, then we don't really need
464 a path pointer, but we shouldn't let garbage go back. */
465 if (path_ptr)
466 *path_ptr = binfo;
467 return 0;
468 }
469
470 if (path_ptr)
471 watch_access = 1;
472
473 rval = get_base_distance_recursive (binfo, 0, 0, -1,
474 &rval_private, &new_binfo, parent,
475 watch_access, &via_virtual, 0,
476 0);
477
478 /* Access restrictions don't count if we found an ambiguous basetype. */
479 if (rval == -2 && protect >= 0)
480 rval_private = 0;
481
482 if (rval && protect && rval_private)
483 return -3;
484
485 /* If they gave us the real vbase binfo, which isn't in the main binfo
486 tree, deal with it. This happens when we are called from
487 expand_upcast_fixups. */
488 if (rval == -1 && TREE_CODE (parent) == TREE_VEC
489 && parent == binfo_member (BINFO_TYPE (parent),
490 CLASSTYPE_VBASECLASSES (type)))
491 {
492 my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent) == binfo, 980827);
493 new_binfo = parent;
494 rval = 1;
495 }
496
497 if (path_ptr)
498 *path_ptr = new_binfo;
499 return rval;
500 }
501
502 /* Search for a member with name NAME in a multiple inheritance lattice
503 specified by TYPE. If it does not exist, return NULL_TREE.
504 If the member is ambiguously referenced, return `error_mark_node'.
505 Otherwise, return the FIELD_DECL. */
506
507 /* Do a 1-level search for NAME as a member of TYPE. The caller must
508 figure out whether it can access this field. (Since it is only one
509 level, this is reasonable.) */
510
511 static tree
512 lookup_field_1 (type, name)
513 tree type, name;
514 {
515 register tree field;
516
517 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
518 || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
519 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
520 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
521 the code often worked even when we treated the index as a list
522 of fields!) */
523 return NULL_TREE;
524
525 if (TYPE_NAME (type)
526 && DECL_LANG_SPECIFIC (TYPE_NAME (type))
527 && DECL_SORTED_FIELDS (TYPE_NAME (type)))
528 {
529 tree *fields = &TREE_VEC_ELT (DECL_SORTED_FIELDS (TYPE_NAME (type)), 0);
530 int lo = 0, hi = TREE_VEC_LENGTH (DECL_SORTED_FIELDS (TYPE_NAME (type)));
531 int i;
532
533 while (lo < hi)
534 {
535 i = (lo + hi) / 2;
536
537 #ifdef GATHER_STATISTICS
538 n_fields_searched++;
539 #endif /* GATHER_STATISTICS */
540
541 if (DECL_NAME (fields[i]) > name)
542 hi = i;
543 else if (DECL_NAME (fields[i]) < name)
544 lo = i + 1;
545 else
546 return fields[i];
547 }
548 return NULL_TREE;
549 }
550
551 field = TYPE_FIELDS (type);
552
553 #ifdef GATHER_STATISTICS
554 n_calls_lookup_field_1++;
555 #endif /* GATHER_STATISTICS */
556 while (field)
557 {
558 #ifdef GATHER_STATISTICS
559 n_fields_searched++;
560 #endif /* GATHER_STATISTICS */
561 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field)) == 'd', 0);
562 if (DECL_NAME (field) == NULL_TREE
563 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
564 {
565 tree temp = lookup_field_1 (TREE_TYPE (field), name);
566 if (temp)
567 return temp;
568 }
569 if (TREE_CODE (field) == USING_DECL)
570 /* For now, we're just treating member using declarations as
571 old ARM-style access declarations. Thus, there's no reason
572 to return a USING_DECL, and the rest of the compiler can't
573 handle it. Once the class is defined, these are purged
574 from TYPE_FIELDS anyhow; see handle_using_decl. */
575 ;
576 else if (DECL_NAME (field) == name)
577 {
578 if ((TREE_CODE(field) == VAR_DECL || TREE_CODE(field) == CONST_DECL)
579 && DECL_ASSEMBLER_NAME (field) != NULL)
580 GNU_xref_ref(current_function_decl,
581 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field)));
582 return field;
583 }
584 field = TREE_CHAIN (field);
585 }
586 /* Not found. */
587 if (name == _vptr_name)
588 {
589 /* Give the user what s/he thinks s/he wants. */
590 if (TYPE_VIRTUAL_P (type))
591 return CLASSTYPE_VFIELD (type);
592 }
593 return NULL_TREE;
594 }
595
596 /* There are a number of cases we need to be aware of here:
597 current_class_type current_function_decl
598 global NULL NULL
599 fn-local NULL SET
600 class-local SET NULL
601 class->fn SET SET
602 fn->class SET SET
603
604 Those last two make life interesting. If we're in a function which is
605 itself inside a class, we need decls to go into the fn's decls (our
606 second case below). But if we're in a class and the class itself is
607 inside a function, we need decls to go into the decls for the class. To
608 achieve this last goal, we must see if, when both current_class_ptr and
609 current_function_decl are set, the class was declared inside that
610 function. If so, we know to put the decls into the class's scope. */
611
612 tree
613 current_scope ()
614 {
615 if (current_function_decl == NULL_TREE)
616 return current_class_type;
617 if (current_class_type == NULL_TREE)
618 return current_function_decl;
619 if (DECL_CLASS_CONTEXT (current_function_decl) == current_class_type)
620 return current_function_decl;
621
622 return current_class_type;
623 }
624
625 /* Returns non-zero if we are currently in a function scope. Note
626 that this function returns zero if we are within a local class, but
627 not within a member function body of the local class. */
628
629 int
630 at_function_scope_p ()
631 {
632 tree cs = current_scope ();
633 return cs && TREE_CODE (cs) == FUNCTION_DECL;
634 }
635
636 /* Return the scope of DECL, as appropriate when doing name-lookup. */
637
638 static tree
639 context_for_name_lookup (decl)
640 tree decl;
641 {
642 /* [class.union]
643
644 For the purposes of name lookup, after the anonymous union
645 definition, the members of the anonymous union are considered to
646 have been defined in the scope in which teh anonymous union is
647 declared. */
648 tree context = DECL_REAL_CONTEXT (decl);
649
650 while (TYPE_P (context) && ANON_AGGR_TYPE_P (context))
651 context = TYPE_CONTEXT (context);
652 if (!context)
653 context = global_namespace;
654
655 return context;
656 }
657
658 /* Return a canonical BINFO if BINFO is a virtual base, or just BINFO
659 otherwise. */
660
661 static tree
662 canonical_binfo (binfo)
663 tree binfo;
664 {
665 return (TREE_VIA_VIRTUAL (binfo)
666 ? TYPE_BINFO (BINFO_TYPE (binfo)) : binfo);
667 }
668
669 /* A queue function that simply ensures that we walk into the
670 canonical versions of virtual bases. */
671
672 static tree
673 dfs_canonical_queue (binfo, data)
674 tree binfo;
675 void *data ATTRIBUTE_UNUSED;
676 {
677 return canonical_binfo (binfo);
678 }
679
680 /* Called via dfs_walk from assert_canonical_unmarked. */
681
682 static tree
683 dfs_assert_unmarked_p (binfo, data)
684 tree binfo;
685 void *data ATTRIBUTE_UNUSED;
686 {
687 my_friendly_assert (!BINFO_MARKED (binfo), 0);
688 return NULL_TREE;
689 }
690
691 /* Asserts that all the nodes below BINFO (using the canonical
692 versions of virtual bases) are unmarked. */
693
694 static void
695 assert_canonical_unmarked (binfo)
696 tree binfo;
697 {
698 dfs_walk (binfo, dfs_assert_unmarked_p, dfs_canonical_queue, 0);
699 }
700
701 /* If BINFO is marked, return a canonical version of BINFO.
702 Otherwise, return NULL_TREE. */
703
704 static tree
705 shared_marked_p (binfo, data)
706 tree binfo;
707 void *data;
708 {
709 binfo = canonical_binfo (binfo);
710 return markedp (binfo, data) ? binfo : NULL_TREE;
711 }
712
713 /* If BINFO is not marked, return a canonical version of BINFO.
714 Otherwise, return NULL_TREE. */
715
716 static tree
717 shared_unmarked_p (binfo, data)
718 tree binfo;
719 void *data;
720 {
721 binfo = canonical_binfo (binfo);
722 return unmarkedp (binfo, data) ? binfo : NULL_TREE;
723 }
724
725 /* Called from access_in_type via dfs_walk. Calculate the access to
726 DATA (which is really a DECL) in BINFO. */
727
728 static tree
729 dfs_access_in_type (binfo, data)
730 tree binfo;
731 void *data;
732 {
733 tree decl = (tree) data;
734 tree type = BINFO_TYPE (binfo);
735 tree access = NULL_TREE;
736
737 if (context_for_name_lookup (decl) == type)
738 {
739 /* If we have desceneded to the scope of DECL, just note the
740 appropriate access. */
741 if (TREE_PRIVATE (decl))
742 access = access_private_node;
743 else if (TREE_PROTECTED (decl))
744 access = access_protected_node;
745 else
746 access = access_public_node;
747 }
748 else
749 {
750 /* First, check for an access-declaration that gives us more
751 access to the DECL. The CONST_DECL for an enumeration
752 constant will not have DECL_LANG_SPECIFIC, and thus no
753 DECL_ACCESS. */
754 if (DECL_LANG_SPECIFIC (decl))
755 {
756 access = purpose_member (type, DECL_ACCESS (decl));
757 if (access)
758 access = TREE_VALUE (access);
759 }
760
761 if (!access)
762 {
763 int i;
764 int n_baselinks;
765 tree binfos;
766
767 /* Otherwise, scan our baseclasses, and pick the most favorable
768 access. */
769 binfos = BINFO_BASETYPES (binfo);
770 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
771 for (i = 0; i < n_baselinks; ++i)
772 {
773 tree base_binfo = TREE_VEC_ELT (binfos, i);
774 tree base_access = TREE_CHAIN (canonical_binfo (base_binfo));
775
776 if (!base_access || base_access == access_private_node)
777 /* If it was not accessible in the base, or only
778 accessible as a private member, we can't access it
779 all. */
780 base_access = NULL_TREE;
781 else if (TREE_VIA_PROTECTED (base_binfo))
782 /* Public and protected members in the base are
783 protected here. */
784 base_access = access_protected_node;
785 else if (!TREE_VIA_PUBLIC (base_binfo))
786 /* Public and protected members in the base are
787 private here. */
788 base_access = access_private_node;
789
790 /* See if the new access, via this base, gives more
791 access than our previous best access. */
792 if (base_access &&
793 (base_access == access_public_node
794 || (base_access == access_protected_node
795 && access != access_public_node)
796 || (base_access == access_private_node
797 && !access)))
798 {
799 access = base_access;
800
801 /* If the new access is public, we can't do better. */
802 if (access == access_public_node)
803 break;
804 }
805 }
806 }
807 }
808
809 /* Note the access to DECL in TYPE. */
810 TREE_CHAIN (binfo) = access;
811
812 /* Mark TYPE as visited so that if we reach it again we do not
813 duplicate our efforts here. */
814 SET_BINFO_MARKED (binfo);
815
816 return NULL_TREE;
817 }
818
819 /* Return the access to DECL in TYPE. */
820
821 static tree
822 access_in_type (type, decl)
823 tree type;
824 tree decl;
825 {
826 tree binfo = TYPE_BINFO (type);
827
828 /* We must take into account
829
830 [class.paths]
831
832 If a name can be reached by several paths through a multiple
833 inheritance graph, the access is that of the path that gives
834 most access.
835
836 The algorithm we use is to make a post-order depth-first traversal
837 of the base-class hierarchy. As we come up the tree, we annotate
838 each node with the most lenient access. */
839 dfs_walk_real (binfo, 0, dfs_access_in_type, shared_unmarked_p, decl);
840 dfs_walk (binfo, dfs_unmark, shared_marked_p, 0);
841 assert_canonical_unmarked (binfo);
842
843 return TREE_CHAIN (binfo);
844 }
845
846 /* Called from dfs_accessible_p via dfs_walk. */
847
848 static tree
849 dfs_accessible_queue_p (binfo, data)
850 tree binfo;
851 void *data ATTRIBUTE_UNUSED;
852 {
853 if (BINFO_MARKED (binfo))
854 return NULL_TREE;
855
856 /* If this class is inherited via private or protected inheritance,
857 then we can't see it, unless we are a friend of the subclass. */
858 if (!TREE_VIA_PUBLIC (binfo)
859 && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo)),
860 current_scope ()))
861 return NULL_TREE;
862
863 return canonical_binfo (binfo);
864 }
865
866 /* Called from dfs_accessible_p via dfs_walk. */
867
868 static tree
869 dfs_accessible_p (binfo, data)
870 tree binfo;
871 void *data;
872 {
873 int protected_ok = data != 0;
874 tree access;
875
876 /* We marked the binfos while computing the access in each type.
877 So, we unmark as we go now. */
878 SET_BINFO_MARKED (binfo);
879
880 access = TREE_CHAIN (binfo);
881 if (access == access_public_node
882 || (access == access_protected_node && protected_ok))
883 return binfo;
884 else if (access && is_friend (BINFO_TYPE (binfo), current_scope ()))
885 return binfo;
886
887 return NULL_TREE;
888 }
889
890 /* Returns non-zero if it is OK to access DECL when named in TYPE
891 through an object indiated by BINFO in the context of DERIVED. */
892
893 static int
894 protected_accessible_p (type, decl, derived, binfo)
895 tree type;
896 tree decl;
897 tree derived;
898 tree binfo;
899 {
900 tree access;
901
902 /* We're checking this clause from [class.access.base]
903
904 m as a member of N is protected, and the reference occurs in a
905 member or friend of class N, or in a member or friend of a
906 class P derived from N, where m as a member of P is private or
907 protected.
908
909 If DERIVED isn't derived from TYPE, then it certainly does not
910 apply. */
911 if (!DERIVED_FROM_P (type, derived))
912 return 0;
913
914 access = access_in_type (derived, decl);
915 if (same_type_p (derived, type))
916 {
917 if (access != access_private_node)
918 return 0;
919 }
920 else if (access != access_private_node
921 && access != access_protected_node)
922 return 0;
923
924 /* [class.protected]
925
926 When a friend or a member function of a derived class references
927 a protected nonstatic member of a base class, an access check
928 applies in addition to those described earlier in clause
929 _class.access_.4) Except when forming a pointer to member
930 (_expr.unary.op_), the access must be through a pointer to,
931 reference to, or object of the derived class itself (or any class
932 derived from that class) (_expr.ref_). If the access is to form
933 a pointer to member, the nested-name-specifier shall name the
934 derived class (or any class derived from that class). */
935 if (DECL_NONSTATIC_MEMBER_P (decl))
936 {
937 /* We can tell through what the reference is occurring by
938 chasing BINFO up to the root. */
939 tree t = binfo;
940 while (BINFO_INHERITANCE_CHAIN (t))
941 t = BINFO_INHERITANCE_CHAIN (t);
942
943 if (!DERIVED_FROM_P (derived, BINFO_TYPE (t)))
944 return 0;
945 }
946
947 return 1;
948 }
949
950 /* Returns non-zero if SCOPE is a friend of a type which would be able
951 to acces DECL, named in TYPE, through the object indicated by
952 BINFO. */
953
954 static int
955 friend_accessible_p (scope, type, decl, binfo)
956 tree scope;
957 tree type;
958 tree decl;
959 tree binfo;
960 {
961 tree befriending_classes;
962 tree t;
963
964 if (!scope)
965 return 0;
966
967 if (TREE_CODE (scope) == FUNCTION_DECL
968 || DECL_FUNCTION_TEMPLATE_P (scope))
969 befriending_classes = DECL_BEFRIENDING_CLASSES (scope);
970 else if (TYPE_P (scope))
971 befriending_classes = CLASSTYPE_BEFRIENDING_CLASSES (scope);
972 else
973 return 0;
974
975 for (t = befriending_classes; t; t = TREE_CHAIN (t))
976 if (protected_accessible_p (type, decl, TREE_VALUE (t), binfo))
977 return 1;
978
979 if (TREE_CODE (scope) == FUNCTION_DECL
980 || DECL_FUNCTION_TEMPLATE_P (scope))
981 {
982 /* Perhaps this SCOPE is a member of a class which is a
983 friend. */
984 if (friend_accessible_p (DECL_CLASS_CONTEXT (scope), type,
985 decl, binfo))
986 return 1;
987
988 /* Or an instantiation of something which is a friend. */
989 if (DECL_TEMPLATE_INFO (scope))
990 return friend_accessible_p (DECL_TI_TEMPLATE (scope),
991 type, decl, binfo);
992 }
993 else if (CLASSTYPE_TEMPLATE_INFO (scope))
994 return friend_accessible_p (CLASSTYPE_TI_TEMPLATE (scope),
995 type, decl, binfo);
996
997 return 0;
998 }
999
1000 /* DECL is a declaration from a base class of TYPE, which was the
1001 classs used to name DECL. Return non-zero if, in the current
1002 context, DECL is accessible. If TYPE is actually a BINFO node,
1003 then we can tell in what context the access is occurring by looking
1004 at the most derived class along the path indicated by BINFO. */
1005
1006 int
1007 accessible_p (type, decl)
1008 tree type;
1009 tree decl;
1010
1011 {
1012 tree binfo;
1013 tree t;
1014
1015 /* Non-zero if it's OK to access DECL if it has protected
1016 accessibility in TYPE. */
1017 int protected_ok = 0;
1018
1019 /* If we're not checking access, everything is accessible. */
1020 if (!flag_access_control)
1021 return 1;
1022
1023 /* If this declaration is in a block or namespace scope, there's no
1024 access control. */
1025 if (!TYPE_P (context_for_name_lookup (decl)))
1026 return 1;
1027
1028 /* We don't do access control for types yet. */
1029 if (TREE_CODE (decl) == TYPE_DECL)
1030 return 1;
1031
1032 if (!TYPE_P (type))
1033 {
1034 binfo = type;
1035 type = BINFO_TYPE (type);
1036 }
1037 else
1038 binfo = TYPE_BINFO (type);
1039
1040 /* [class.access.base]
1041
1042 A member m is accessible when named in class N if
1043
1044 --m as a member of N is public, or
1045
1046 --m as a member of N is private, and the reference occurs in a
1047 member or friend of class N, or
1048
1049 --m as a member of N is protected, and the reference occurs in a
1050 member or friend of class N, or in a member or friend of a
1051 class P derived from N, where m as a member of P is private or
1052 protected, or
1053
1054 --there exists a base class B of N that is accessible at the point
1055 of reference, and m is accessible when named in class B.
1056
1057 We walk the base class hierarchy, checking these conditions. */
1058
1059 /* Figure out where the reference is occurring. Check to see if
1060 DECL is private or protected in this scope, since that will
1061 determine whether protected access in TYPE allowed. */
1062 if (current_class_type)
1063 protected_ok
1064 = protected_accessible_p (type, decl, current_class_type,
1065 binfo);
1066
1067 /* Now, loop through the classes of which we are a friend. */
1068 if (!protected_ok)
1069 protected_ok = friend_accessible_p (current_scope (),
1070 type, decl, binfo);
1071
1072 /* Standardize on the same that will access_in_type will use. We
1073 don't need to know what path was chosen from this point onwards. */
1074 binfo = TYPE_BINFO (type);
1075
1076 /* Compute the accessibility of DECL in the class hierarchy
1077 dominated by type. */
1078 access_in_type (type, decl);
1079 /* Walk the hierarchy again, looking for a base class that allows
1080 access. */
1081 t = dfs_walk (binfo, dfs_accessible_p,
1082 dfs_accessible_queue_p,
1083 protected_ok ? &protected_ok : 0);
1084 /* Clear any mark bits. Note that we have to walk the whole tree
1085 here, since we have aborted the previous walk from some point
1086 deep in the tree. */
1087 dfs_walk (binfo, dfs_unmark, dfs_canonical_queue, 0);
1088 assert_canonical_unmarked (binfo);
1089
1090 return t != NULL_TREE;
1091 }
1092
1093 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1094 found as a base class and sub-object of the object denoted by
1095 BINFO. This routine relies upon binfos not being shared, except
1096 for binfos for virtual bases. */
1097
1098 static int
1099 is_subobject_of_p (parent, binfo)
1100 tree parent, binfo;
1101 {
1102 tree binfos;
1103 int i, n_baselinks;
1104
1105 /* We want to canonicalize for comparison purposes. But, when we
1106 iterate through basetypes later, we want the binfos from the
1107 original hierarchy. That's why we have to calculate BINFOS
1108 first, and then canonicalize. */
1109 binfos = BINFO_BASETYPES (binfo);
1110 parent = canonical_binfo (parent);
1111 binfo = canonical_binfo (binfo);
1112
1113 if (parent == binfo)
1114 return 1;
1115
1116 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1117
1118 /* Process and/or queue base types. */
1119 for (i = 0; i < n_baselinks; i++)
1120 {
1121 tree base_binfo = TREE_VEC_ELT (binfos, i);
1122 if (!CLASS_TYPE_P (TREE_TYPE (base_binfo)))
1123 /* If we see a TEMPLATE_TYPE_PARM, or some such, as a base
1124 class there's no way to descend into it. */
1125 continue;
1126
1127 if (is_subobject_of_p (parent, base_binfo))
1128 return 1;
1129 }
1130 return 0;
1131 }
1132
1133 /* See if a one FIELD_DECL hides another. This routine is meant to
1134 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1135 binfos given are the binfos corresponding to the particular places
1136 the FIELD_DECLs are found. This routine relies upon binfos not
1137 being shared, except for virtual bases. */
1138
1139 static int
1140 hides (hider_binfo, hidee_binfo)
1141 tree hider_binfo, hidee_binfo;
1142 {
1143 /* hider hides hidee, if hider has hidee as a base class and
1144 the instance of hidee is a sub-object of hider. The first
1145 part is always true is the second part is true.
1146
1147 When hider and hidee are the same (two ways to get to the exact
1148 same member) we consider either one as hiding the other. */
1149 return is_subobject_of_p (hidee_binfo, hider_binfo);
1150 }
1151
1152 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1153 function was declared inside the class given by TYPE. It really should
1154 only return functions that match the given TYPE. */
1155
1156 static int
1157 lookup_fnfields_here (type, name)
1158 tree type, name;
1159 {
1160 int idx = lookup_fnfields_1 (type, name);
1161 tree fndecls;
1162
1163 /* ctors and dtors are always only in the right class. */
1164 if (idx <= 1)
1165 return idx;
1166 fndecls = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1167 while (fndecls)
1168 {
1169 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (OVL_CURRENT (fndecls)))
1170 == TYPE_MAIN_VARIANT (type))
1171 return idx;
1172 fndecls = OVL_CHAIN (fndecls);
1173 }
1174 return -1;
1175 }
1176
1177 struct lookup_field_info {
1178 /* The type in which we're looking. */
1179 tree type;
1180 /* The name of the field for which we're looking. */
1181 tree name;
1182 /* If non-NULL, the current result of the lookup. */
1183 tree rval;
1184 /* The path to RVAL. */
1185 tree rval_binfo;
1186 /* If non-NULL, the lookup was ambiguous, and this is a list of the
1187 candidates. */
1188 tree ambiguous;
1189 /* If non-zero, we are looking for types, not data members. */
1190 int want_type;
1191 /* If non-zero, RVAL was found by looking through a dependent base. */
1192 int from_dep_base_p;
1193 /* If something went wrong, a message indicating what. */
1194 const char *errstr;
1195 };
1196
1197 /* Returns non-zero if BINFO is not hidden by the value found by the
1198 lookup so far. If BINFO is hidden, then there's no need to look in
1199 it. DATA is really a struct lookup_field_info. Called from
1200 lookup_field via breadth_first_search. */
1201
1202 static tree
1203 lookup_field_queue_p (binfo, data)
1204 tree binfo;
1205 void *data;
1206 {
1207 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1208
1209 /* Don't look for constructors or destructors in base classes. */
1210 if (lfi->name == ctor_identifier || lfi->name == dtor_identifier)
1211 return NULL_TREE;
1212
1213 /* If this base class is hidden by the best-known value so far, we
1214 don't need to look. */
1215 if (!lfi->from_dep_base_p && lfi->rval_binfo
1216 && hides (lfi->rval_binfo, binfo))
1217 return NULL_TREE;
1218
1219 if (TREE_VIA_VIRTUAL (binfo))
1220 return binfo_member (BINFO_TYPE (binfo),
1221 CLASSTYPE_VBASECLASSES (lfi->type));
1222 else
1223 return binfo;
1224 }
1225
1226 /* Within the scope of a template class, you can refer to the to the
1227 current specialization with the name of the template itself. For
1228 example:
1229
1230 template <typename T> struct S { S* sp; }
1231
1232 Returns non-zero if DECL is such a declaration in a class TYPE. */
1233
1234 static int
1235 template_self_reference_p (type, decl)
1236 tree type;
1237 tree decl;
1238 {
1239 return (CLASSTYPE_USE_TEMPLATE (type)
1240 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type))
1241 && TREE_CODE (decl) == TYPE_DECL
1242 && DECL_ARTIFICIAL (decl)
1243 && DECL_NAME (decl) == constructor_name (type));
1244 }
1245
1246 /* DATA is really a struct lookup_field_info. Look for a field with
1247 the name indicated there in BINFO. If this function returns a
1248 non-NULL value it is the result of the lookup. Called from
1249 lookup_field via breadth_first_search. */
1250
1251 static tree
1252 lookup_field_r (binfo, data)
1253 tree binfo;
1254 void *data;
1255 {
1256 struct lookup_field_info *lfi = (struct lookup_field_info *) data;
1257 tree type = BINFO_TYPE (binfo);
1258 tree nval = NULL_TREE;
1259 int from_dep_base_p;
1260
1261 /* First, look for a function. There can't be a function and a data
1262 member with the same name, and if there's a function and a type
1263 with the same name, the type is hidden by the function. */
1264 if (!lfi->want_type)
1265 {
1266 int idx = lookup_fnfields_here (type, lfi->name);
1267 if (idx >= 0)
1268 nval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1269 }
1270
1271 if (!nval)
1272 /* Look for a data member or type. */
1273 nval = lookup_field_1 (type, lfi->name);
1274
1275 /* If there is no declaration with the indicated name in this type,
1276 then there's nothing to do. */
1277 if (!nval)
1278 return NULL_TREE;
1279
1280 /* If we're looking up a type (as with an elaborated type specifier)
1281 we ignore all non-types we find. */
1282 if (lfi->want_type && TREE_CODE (nval) != TYPE_DECL)
1283 {
1284 nval = purpose_member (lfi->name, CLASSTYPE_TAGS (type));
1285 if (nval)
1286 nval = TYPE_MAIN_DECL (TREE_VALUE (nval));
1287 else
1288 return NULL_TREE;
1289 }
1290
1291 /* You must name a template base class with a template-id. */
1292 if (!same_type_p (type, lfi->type)
1293 && template_self_reference_p (type, nval))
1294 return NULL_TREE;
1295
1296 from_dep_base_p = dependent_base_p (binfo);
1297 if (lfi->from_dep_base_p && !from_dep_base_p)
1298 {
1299 /* If the new declaration is not found via a dependent base, and
1300 the old one was, then we must prefer the new one. We weren't
1301 really supposed to be able to find the old one, so we don't
1302 want to be affected by a specialization. Consider:
1303
1304 struct B { typedef int I; };
1305 template <typename T> struct D1 : virtual public B {};
1306 template <typename T> struct D :
1307 public D1, virtual pubic B { I i; };
1308
1309 The `I' in `D<T>' is unambigousuly `B::I', regardless of how
1310 D1 is specialized. */
1311 lfi->from_dep_base_p = 0;
1312 lfi->rval = NULL_TREE;
1313 lfi->rval_binfo = NULL_TREE;
1314 lfi->ambiguous = NULL_TREE;
1315 lfi->errstr = 0;
1316 }
1317 else if (lfi->rval_binfo && !lfi->from_dep_base_p && from_dep_base_p)
1318 /* Similarly, if the old declaration was not found via a dependent
1319 base, and the new one is, ignore the new one. */
1320 return NULL_TREE;
1321
1322 /* If the lookup already found a match, and the new value doesn't
1323 hide the old one, we might have an ambiguity. */
1324 if (lfi->rval_binfo && !hides (binfo, lfi->rval_binfo))
1325 {
1326 if (nval == lfi->rval && SHARED_MEMBER_P (nval))
1327 /* The two things are really the same. */
1328 ;
1329 else if (hides (lfi->rval_binfo, binfo))
1330 /* The previous value hides the new one. */
1331 ;
1332 else
1333 {
1334 /* We have a real ambiguity. We keep a chain of all the
1335 candidates. */
1336 if (!lfi->ambiguous && lfi->rval)
1337 {
1338 /* This is the first time we noticed an ambiguity. Add
1339 what we previously thought was a reasonable candidate
1340 to the list. */
1341 lfi->ambiguous = scratch_tree_cons (NULL_TREE, lfi->rval,
1342 NULL_TREE);
1343 TREE_TYPE (lfi->ambiguous) = error_mark_node;
1344 }
1345
1346 /* Add the new value. */
1347 lfi->ambiguous = scratch_tree_cons (NULL_TREE, nval,
1348 lfi->ambiguous);
1349 TREE_TYPE (lfi->ambiguous) = error_mark_node;
1350 lfi->errstr = "request for member `%D' is ambiguous";
1351 }
1352 }
1353 else
1354 {
1355 /* If the thing we're looking for is a virtual base class, then
1356 we know we've got what we want at this point; there's no way
1357 to get an ambiguity. */
1358 if (VBASE_NAME_P (lfi->name))
1359 {
1360 lfi->rval = nval;
1361 return nval;
1362 }
1363
1364 if (from_dep_base_p && TREE_CODE (nval) != TYPE_DECL
1365 /* We need to return a member template class so we can
1366 define partial specializations. Is there a better
1367 way? */
1368 && !DECL_CLASS_TEMPLATE_P (nval))
1369 /* The thing we're looking for isn't a type, so the implicit
1370 typename extension doesn't apply, so we just pretend we
1371 didn't find anything. */
1372 return NULL_TREE;
1373
1374 lfi->rval = nval;
1375 lfi->from_dep_base_p = from_dep_base_p;
1376 lfi->rval_binfo = binfo;
1377 }
1378
1379 return NULL_TREE;
1380 }
1381
1382 /* Look for a memer named NAME in an inheritance lattice dominated by
1383 XBASETYPE. PROTECT is 0 or two, we do not check access. If it is
1384 1, we enforce accessibility. If PROTECT is zero, then, for an
1385 ambiguous lookup, we return NULL. If PROTECT is 1, we issue an
1386 error message. If PROTECT is 2, we return a TREE_LIST whose
1387 TREEE_TYPE is error_mark_node and whose TREE_VALUEs are the list of
1388 ambiguous candidates.
1389
1390 WANT_TYPE is 1 when we should only return TYPE_DECLs, if no
1391 TYPE_DECL can be found return NULL_TREE. */
1392
1393 tree
1394 lookup_member (xbasetype, name, protect, want_type)
1395 register tree xbasetype, name;
1396 int protect, want_type;
1397 {
1398 tree rval, rval_binfo = NULL_TREE;
1399 tree type = NULL_TREE, basetype_path = NULL_TREE;
1400 struct lookup_field_info lfi;
1401
1402 /* rval_binfo is the binfo associated with the found member, note,
1403 this can be set with useful information, even when rval is not
1404 set, because it must deal with ALL members, not just non-function
1405 members. It is used for ambiguity checking and the hidden
1406 checks. Whereas rval is only set if a proper (not hidden)
1407 non-function member is found. */
1408
1409 const char *errstr = 0;
1410
1411 if (xbasetype == current_class_type && TYPE_BEING_DEFINED (xbasetype)
1412 && IDENTIFIER_CLASS_VALUE (name))
1413 {
1414 tree field = IDENTIFIER_CLASS_VALUE (name);
1415 if (TREE_CODE (field) != FUNCTION_DECL
1416 && ! (want_type && TREE_CODE (field) != TYPE_DECL))
1417 /* We're in the scope of this class, and the value has already
1418 been looked up. Just return the cached value. */
1419 return field;
1420 }
1421
1422 if (TREE_CODE (xbasetype) == TREE_VEC)
1423 {
1424 type = BINFO_TYPE (xbasetype);
1425 basetype_path = xbasetype;
1426 }
1427 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)))
1428 {
1429 type = xbasetype;
1430 basetype_path = TYPE_BINFO (type);
1431 my_friendly_assert (BINFO_INHERITANCE_CHAIN (basetype_path) == NULL_TREE,
1432 980827);
1433 }
1434 else
1435 my_friendly_abort (97);
1436
1437 complete_type (type);
1438
1439 #ifdef GATHER_STATISTICS
1440 n_calls_lookup_field++;
1441 #endif /* GATHER_STATISTICS */
1442
1443 bzero ((PTR) &lfi, sizeof (lfi));
1444 lfi.type = type;
1445 lfi.name = name;
1446 lfi.want_type = want_type;
1447 bfs_walk (basetype_path, &lookup_field_r, &lookup_field_queue_p, &lfi);
1448 rval = lfi.rval;
1449 rval_binfo = lfi.rval_binfo;
1450 if (rval_binfo)
1451 type = BINFO_TYPE (rval_binfo);
1452 errstr = lfi.errstr;
1453
1454 /* If we are not interested in ambiguities, don't report them;
1455 just return NULL_TREE. */
1456 if (!protect && lfi.ambiguous)
1457 return NULL_TREE;
1458
1459 if (protect == 2)
1460 {
1461 if (lfi.ambiguous)
1462 return lfi.ambiguous;
1463 else
1464 protect = 0;
1465 }
1466
1467 /* [class.access]
1468
1469 In the case of overloaded function names, access control is
1470 applied to the function selected by overloaded resolution. */
1471 if (rval && protect && !is_overloaded_fn (rval)
1472 && !enforce_access (xbasetype, rval))
1473 return error_mark_node;
1474
1475 if (errstr && protect)
1476 {
1477 cp_error (errstr, name, type);
1478 if (lfi.ambiguous)
1479 print_candidates (lfi.ambiguous);
1480 rval = error_mark_node;
1481 }
1482
1483 /* If the thing we found was found via the implicit typename
1484 extension, build the typename type. */
1485 if (rval && lfi.from_dep_base_p && !DECL_CLASS_TEMPLATE_P (rval))
1486 rval = TYPE_STUB_DECL (build_typename_type (BINFO_TYPE (basetype_path),
1487 name, name,
1488 TREE_TYPE (rval)));
1489
1490 if (rval && is_overloaded_fn (rval))
1491 {
1492 rval = scratch_tree_cons (basetype_path, rval, NULL_TREE);
1493 SET_BASELINK_P (rval);
1494 }
1495
1496 return rval;
1497 }
1498
1499 /* Like lookup_member, except that if we find a function member we
1500 return NULL_TREE. */
1501
1502 tree
1503 lookup_field (xbasetype, name, protect, want_type)
1504 register tree xbasetype, name;
1505 int protect, want_type;
1506 {
1507 tree rval = lookup_member (xbasetype, name, protect, want_type);
1508
1509 /* Ignore functions. */
1510 if (rval && TREE_CODE (rval) == TREE_LIST)
1511 return NULL_TREE;
1512
1513 return rval;
1514 }
1515
1516 /* Like lookup_member, except that if we find a non-function member we
1517 return NULL_TREE. */
1518
1519 tree
1520 lookup_fnfields (xbasetype, name, protect)
1521 register tree xbasetype, name;
1522 int protect;
1523 {
1524 tree rval = lookup_member (xbasetype, name, protect, /*want_type=*/0);
1525
1526 /* Ignore non-functions. */
1527 if (rval && TREE_CODE (rval) != TREE_LIST)
1528 return NULL_TREE;
1529
1530 return rval;
1531 }
1532
1533 /* TYPE is a class type. Return the index of the fields within
1534 the method vector with name NAME, or -1 is no such field exists. */
1535
1536 int
1537 lookup_fnfields_1 (type, name)
1538 tree type, name;
1539 {
1540 tree method_vec
1541 = CLASS_TYPE_P (type) ? CLASSTYPE_METHOD_VEC (type) : NULL_TREE;
1542
1543 if (method_vec != 0)
1544 {
1545 register int i;
1546 register tree *methods = &TREE_VEC_ELT (method_vec, 0);
1547 int len = TREE_VEC_LENGTH (method_vec);
1548 tree tmp;
1549
1550 #ifdef GATHER_STATISTICS
1551 n_calls_lookup_fnfields_1++;
1552 #endif /* GATHER_STATISTICS */
1553
1554 /* Constructors are first... */
1555 if (name == ctor_identifier)
1556 return methods[0] ? 0 : -1;
1557
1558 /* and destructors are second. */
1559 if (name == dtor_identifier)
1560 return methods[1] ? 1 : -1;
1561
1562 for (i = 2; i < len && methods[i]; ++i)
1563 {
1564 #ifdef GATHER_STATISTICS
1565 n_outer_fields_searched++;
1566 #endif /* GATHER_STATISTICS */
1567
1568 tmp = OVL_CURRENT (methods[i]);
1569 if (DECL_NAME (tmp) == name)
1570 return i;
1571
1572 /* If the type is complete and we're past the conversion ops,
1573 switch to binary search. */
1574 if (! DECL_CONV_FN_P (tmp)
1575 && TYPE_SIZE (type))
1576 {
1577 int lo = i + 1, hi = len;
1578
1579 while (lo < hi)
1580 {
1581 i = (lo + hi) / 2;
1582
1583 #ifdef GATHER_STATISTICS
1584 n_outer_fields_searched++;
1585 #endif /* GATHER_STATISTICS */
1586
1587 tmp = DECL_NAME (OVL_CURRENT (methods[i]));
1588
1589 if (tmp > name)
1590 hi = i;
1591 else if (tmp < name)
1592 lo = i + 1;
1593 else
1594 return i;
1595 }
1596 break;
1597 }
1598 }
1599
1600 /* If we didn't find it, it might have been a template
1601 conversion operator. (Note that we don't look for this case
1602 above so that we will always find specializations first.) */
1603 if (IDENTIFIER_TYPENAME_P (name))
1604 {
1605 for (i = 2; i < len && methods[i]; ++i)
1606 {
1607 tmp = OVL_CURRENT (methods[i]);
1608 if (! DECL_CONV_FN_P (tmp))
1609 {
1610 /* Since all conversion operators come first, we know
1611 there is no such operator. */
1612 break;
1613 }
1614 else if (TREE_CODE (tmp) == TEMPLATE_DECL)
1615 return i;
1616 }
1617 }
1618 }
1619
1620 return -1;
1621 }
1622 \f
1623 /* Walk the class hierarchy dominated by TYPE. FN is called for each
1624 type in the hierarchy, in a breadth-first preorder traversal. .
1625 If it ever returns a non-NULL value, that value is immediately
1626 returned and the walk is terminated. At each node FN, is passed a
1627 BINFO indicating the path from the curently visited base-class to
1628 TYPE. The TREE_CHAINs of the BINFOs may be used for scratch space;
1629 they are otherwise unused. Before each base-class is walked QFN is
1630 called. If the value returned is non-zero, the base-class is
1631 walked; otherwise it is not. If QFN is NULL, it is treated as a
1632 function which always returns 1. Both FN and QFN are passed the
1633 DATA whenever they are called. */
1634
1635 static tree
1636 bfs_walk (binfo, fn, qfn, data)
1637 tree binfo;
1638 tree (*fn) PROTO((tree, void *));
1639 tree (*qfn) PROTO((tree, void *));
1640 void *data;
1641 {
1642 size_t head;
1643 size_t tail;
1644 tree rval = NULL_TREE;
1645 /* An array of the base classes of BINFO. These will be built up in
1646 breadth-first order, except where QFN prunes the search. */
1647 varray_type bfs_bases;
1648
1649 /* Start with enough room for ten base classes. That will be enough
1650 for most hierarchies. */
1651 VARRAY_TREE_INIT (bfs_bases, 10, "search_stack");
1652
1653 /* Put the first type into the stack. */
1654 VARRAY_TREE (bfs_bases, 0) = binfo;
1655 tail = 1;
1656
1657 for (head = 0; head < tail; ++head)
1658 {
1659 int i;
1660 int n_baselinks;
1661 tree binfos;
1662
1663 /* Pull the next type out of the queue. */
1664 binfo = VARRAY_TREE (bfs_bases, head);
1665
1666 /* If this is the one we're looking for, we're done. */
1667 rval = (*fn) (binfo, data);
1668 if (rval)
1669 break;
1670
1671 /* Queue up the base types. */
1672 binfos = BINFO_BASETYPES (binfo);
1673 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos): 0;
1674 for (i = 0; i < n_baselinks; i++)
1675 {
1676 tree base_binfo = TREE_VEC_ELT (binfos, i);
1677
1678 if (qfn)
1679 base_binfo = (*qfn) (base_binfo, data);
1680
1681 if (base_binfo)
1682 {
1683 if (tail == VARRAY_SIZE (bfs_bases))
1684 VARRAY_GROW (bfs_bases, 2 * VARRAY_SIZE (bfs_bases));
1685 VARRAY_TREE (bfs_bases, tail) = base_binfo;
1686 ++tail;
1687 }
1688 }
1689 }
1690
1691 /* Clean up. */
1692 VARRAY_FREE (bfs_bases);
1693
1694 return rval;
1695 }
1696
1697 /* Exactly like bfs_walk, except that a depth-first traversal is
1698 performed, and PREFN is called in preorder, while POSTFN is called
1699 in postorder. */
1700
1701 static tree
1702 dfs_walk_real (binfo, prefn, postfn, qfn, data)
1703 tree binfo;
1704 tree (*prefn) PROTO((tree, void *));
1705 tree (*postfn) PROTO((tree, void *));
1706 tree (*qfn) PROTO((tree, void *));
1707 void *data;
1708 {
1709 int i;
1710 int n_baselinks;
1711 tree binfos;
1712 tree rval = NULL_TREE;
1713
1714 /* Call the pre-order walking function. */
1715 if (prefn)
1716 {
1717 rval = (*prefn) (binfo, data);
1718 if (rval)
1719 return rval;
1720 }
1721
1722 /* Process the basetypes. */
1723 binfos = BINFO_BASETYPES (binfo);
1724 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos): 0;
1725 for (i = 0; i < n_baselinks; i++)
1726 {
1727 tree base_binfo = TREE_VEC_ELT (binfos, i);
1728
1729 if (qfn)
1730 base_binfo = (*qfn) (base_binfo, data);
1731
1732 if (base_binfo)
1733 {
1734 rval = dfs_walk_real (base_binfo, prefn, postfn, qfn, data);
1735 if (rval)
1736 return rval;
1737 }
1738 }
1739
1740 /* Call the post-order walking function. */
1741 if (postfn)
1742 rval = (*postfn) (binfo, data);
1743
1744 return rval;
1745 }
1746
1747 /* Exactly like bfs_walk, except that a depth-first post-order traversal is
1748 performed. */
1749
1750 tree
1751 dfs_walk (binfo, fn, qfn, data)
1752 tree binfo;
1753 tree (*fn) PROTO((tree, void *));
1754 tree (*qfn) PROTO((tree, void *));
1755 void *data;
1756 {
1757 return dfs_walk_real (binfo, 0, fn, qfn, data);
1758 }
1759
1760 struct gvnt_info
1761 {
1762 /* The name of the function we are looking for. */
1763 tree name;
1764 /* The overloaded functions we have found. */
1765 tree fields;
1766 };
1767
1768 /* Called from get_virtuals_named_this via bfs_walk. */
1769
1770 static tree
1771 get_virtuals_named_this_r (binfo, data)
1772 tree binfo;
1773 void *data;
1774 {
1775 struct gvnt_info *gvnti = (struct gvnt_info *) data;
1776 tree type = BINFO_TYPE (binfo);
1777 int idx;
1778
1779 idx = lookup_fnfields_here (BINFO_TYPE (binfo), gvnti->name);
1780 if (idx >= 0)
1781 gvnti->fields
1782 = scratch_tree_cons (binfo,
1783 TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type),
1784 idx),
1785 gvnti->fields);
1786
1787 return NULL_TREE;
1788 }
1789
1790 /* Return the virtual functions with the indicated NAME in the type
1791 indicated by BINFO. The result is a TREE_LIST whose TREE_PURPOSE
1792 indicates the base class from which the TREE_VALUE (an OVERLOAD or
1793 just a FUNCTION_DECL) originated. */
1794
1795 static tree
1796 get_virtuals_named_this (binfo, name)
1797 tree binfo;
1798 tree name;
1799 {
1800 struct gvnt_info gvnti;
1801 tree fields;
1802
1803 gvnti.name = name;
1804 gvnti.fields = NULL_TREE;
1805
1806 bfs_walk (binfo, get_virtuals_named_this_r, 0, &gvnti);
1807
1808 /* Get to the function decls, and return the first virtual function
1809 with this name, if there is one. */
1810 for (fields = gvnti.fields; fields; fields = next_baselink (fields))
1811 {
1812 tree fndecl;
1813
1814 for (fndecl = TREE_VALUE (fields); fndecl; fndecl = OVL_NEXT (fndecl))
1815 if (DECL_VINDEX (OVL_CURRENT (fndecl)))
1816 return fields;
1817 }
1818 return NULL_TREE;
1819 }
1820
1821 static tree
1822 get_virtual_destructor (binfo, data)
1823 tree binfo;
1824 void *data ATTRIBUTE_UNUSED;
1825 {
1826 tree type = BINFO_TYPE (binfo);
1827 if (TYPE_HAS_DESTRUCTOR (type)
1828 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1)))
1829 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1);
1830 return 0;
1831 }
1832
1833 static tree
1834 tree_has_any_destructor_p (binfo, data)
1835 tree binfo;
1836 void *data ATTRIBUTE_UNUSED;
1837 {
1838 tree type = BINFO_TYPE (binfo);
1839 return TYPE_NEEDS_DESTRUCTOR (type) ? binfo : NULL_TREE;
1840 }
1841
1842 /* Returns > 0 if a function with type DRETTYPE overriding a function
1843 with type BRETTYPE is covariant, as defined in [class.virtual].
1844
1845 Returns 1 if trivial covariance, 2 if non-trivial (requiring runtime
1846 adjustment), or -1 if pedantically invalid covariance. */
1847
1848 static int
1849 covariant_return_p (brettype, drettype)
1850 tree brettype, drettype;
1851 {
1852 tree binfo;
1853
1854 if (TREE_CODE (brettype) == FUNCTION_DECL
1855 || TREE_CODE (brettype) == THUNK_DECL)
1856 {
1857 brettype = TREE_TYPE (TREE_TYPE (brettype));
1858 drettype = TREE_TYPE (TREE_TYPE (drettype));
1859 }
1860 else if (TREE_CODE (brettype) == METHOD_TYPE)
1861 {
1862 brettype = TREE_TYPE (brettype);
1863 drettype = TREE_TYPE (drettype);
1864 }
1865
1866 if (same_type_p (brettype, drettype))
1867 return 0;
1868
1869 if (! (TREE_CODE (brettype) == TREE_CODE (drettype)
1870 && (TREE_CODE (brettype) == POINTER_TYPE
1871 || TREE_CODE (brettype) == REFERENCE_TYPE)
1872 && TYPE_QUALS (brettype) == TYPE_QUALS (drettype)))
1873 return 0;
1874
1875 if (! can_convert (brettype, drettype))
1876 return 0;
1877
1878 brettype = TREE_TYPE (brettype);
1879 drettype = TREE_TYPE (drettype);
1880
1881 /* If not pedantic, allow any standard pointer conversion. */
1882 if (! IS_AGGR_TYPE (drettype) || ! IS_AGGR_TYPE (brettype))
1883 return -1;
1884
1885 binfo = get_binfo (brettype, drettype, 1);
1886
1887 /* If we get an error_mark_node from get_binfo, it already complained,
1888 so let's just succeed. */
1889 if (binfo == error_mark_node)
1890 return 1;
1891
1892 if (! BINFO_OFFSET_ZEROP (binfo) || TREE_VIA_VIRTUAL (binfo))
1893 return 2;
1894 return 1;
1895 }
1896
1897 /* Check that virtual overrider OVERRIDER is acceptable for base function
1898 BASEFN. Issue diagnostic, and return zero, if unacceptable. */
1899
1900 static int
1901 check_final_overrider (overrider, basefn)
1902 tree overrider, basefn;
1903 {
1904 tree over_type = TREE_TYPE (overrider);
1905 tree base_type = TREE_TYPE (basefn);
1906 tree over_return = TREE_TYPE (over_type);
1907 tree base_return = TREE_TYPE (base_type);
1908 tree over_throw = TYPE_RAISES_EXCEPTIONS (over_type);
1909 tree base_throw = TYPE_RAISES_EXCEPTIONS (base_type);
1910 int i;
1911
1912 if (same_type_p (base_return, over_return))
1913 /* OK */;
1914 else if ((i = covariant_return_p (base_return, over_return)))
1915 {
1916 if (i == 2)
1917 sorry ("adjusting pointers for covariant returns");
1918
1919 if (pedantic && i == -1)
1920 {
1921 cp_pedwarn_at ("invalid covariant return type for `virtual %#D'", overrider);
1922 cp_pedwarn_at (" overriding `virtual %#D' (must be pointer or reference to class)", basefn);
1923 }
1924 }
1925 else if (IS_AGGR_TYPE_2 (base_return, over_return)
1926 && same_or_base_type_p (base_return, over_return))
1927 {
1928 cp_error_at ("invalid covariant return type for `virtual %#D'", overrider);
1929 cp_error_at (" overriding `virtual %#D' (must use pointer or reference)", basefn);
1930 return 0;
1931 }
1932 else if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider)) == NULL_TREE)
1933 {
1934 cp_error_at ("conflicting return type specified for `virtual %#D'", overrider);
1935 cp_error_at (" overriding `virtual %#D'", basefn);
1936 SET_IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (overrider),
1937 DECL_CLASS_CONTEXT (overrider));
1938 return 0;
1939 }
1940
1941 /* Check throw specifier is subset. */
1942 /* XXX At the moment, punt on an overriding artificial function. We
1943 don't generate its exception specifier, so can't check it properly. */
1944 if (! DECL_ARTIFICIAL (overrider)
1945 && !comp_except_specs (base_throw, over_throw, 0))
1946 {
1947 cp_error_at ("looser throw specifier for `virtual %#F'", overrider);
1948 cp_error_at (" overriding `virtual %#F'", basefn);
1949 return 0;
1950 }
1951 return 1;
1952 }
1953
1954 /* Given a class type TYPE, and a function decl FNDECL, look for a
1955 virtual function in TYPE's hierarchy which FNDECL could match as a
1956 virtual function. It doesn't matter which one we find.
1957
1958 DTORP is nonzero if we are looking for a destructor. Destructors
1959 need special treatment because they do not match by name. */
1960
1961 tree
1962 get_matching_virtual (binfo, fndecl, dtorp)
1963 tree binfo, fndecl;
1964 int dtorp;
1965 {
1966 tree tmp = NULL_TREE;
1967
1968 if (TREE_CODE (fndecl) == TEMPLATE_DECL)
1969 /* In [temp.mem] we have:
1970
1971 A specialization of a member function template does not
1972 override a virtual function from a base class. */
1973 return NULL_TREE;
1974
1975 /* Breadth first search routines start searching basetypes
1976 of TYPE, so we must perform first ply of search here. */
1977 if (dtorp)
1978 return bfs_walk (binfo, get_virtual_destructor,
1979 tree_has_any_destructor_p, 0);
1980 else
1981 {
1982 tree drettype, dtypes, btypes, instptr_type;
1983 tree baselink, best = NULL_TREE;
1984 tree declarator = DECL_NAME (fndecl);
1985 if (IDENTIFIER_VIRTUAL_P (declarator) == 0)
1986 return NULL_TREE;
1987
1988 baselink = get_virtuals_named_this (binfo, declarator);
1989 if (baselink == NULL_TREE)
1990 return NULL_TREE;
1991
1992 drettype = TREE_TYPE (TREE_TYPE (fndecl));
1993 dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1994 if (DECL_STATIC_FUNCTION_P (fndecl))
1995 instptr_type = NULL_TREE;
1996 else
1997 instptr_type = TREE_TYPE (TREE_VALUE (dtypes));
1998
1999 for (; baselink; baselink = next_baselink (baselink))
2000 {
2001 tree tmps;
2002 for (tmps = TREE_VALUE (baselink); tmps; tmps = OVL_NEXT (tmps))
2003 {
2004 tmp = OVL_CURRENT (tmps);
2005 if (! DECL_VINDEX (tmp))
2006 continue;
2007
2008 btypes = TYPE_ARG_TYPES (TREE_TYPE (tmp));
2009 if (instptr_type == NULL_TREE)
2010 {
2011 if (compparms (TREE_CHAIN (btypes), dtypes))
2012 /* Caller knows to give error in this case. */
2013 return tmp;
2014 return NULL_TREE;
2015 }
2016
2017 if (/* The first parameter is the `this' parameter,
2018 which has POINTER_TYPE, and we can therefore
2019 safely use TYPE_QUALS, rather than
2020 CP_TYPE_QUALS. */
2021 (TYPE_QUALS (TREE_TYPE (TREE_VALUE (btypes)))
2022 == TYPE_QUALS (instptr_type))
2023 && compparms (TREE_CHAIN (btypes), TREE_CHAIN (dtypes)))
2024 {
2025 check_final_overrider (fndecl, tmp);
2026
2027 /* FNDECL overrides this function. We continue to
2028 check all the other functions in order to catch
2029 errors; it might be that in some other baseclass
2030 a virtual function was declared with the same
2031 parameter types, but a different return type. */
2032 best = tmp;
2033 }
2034 }
2035 }
2036
2037 return best;
2038 }
2039 }
2040
2041 /* Return the list of virtual functions which are abstract in type
2042 TYPE that come from non virtual base classes. See
2043 expand_direct_vtbls_init for the style of search we do. */
2044
2045 static tree
2046 get_abstract_virtuals_1 (binfo, do_self, abstract_virtuals)
2047 tree binfo;
2048 int do_self;
2049 tree abstract_virtuals;
2050 {
2051 tree binfos = BINFO_BASETYPES (binfo);
2052 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2053
2054 for (i = 0; i < n_baselinks; i++)
2055 {
2056 tree base_binfo = TREE_VEC_ELT (binfos, i);
2057 int is_not_base_vtable
2058 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2059 if (! TREE_VIA_VIRTUAL (base_binfo))
2060 abstract_virtuals
2061 = get_abstract_virtuals_1 (base_binfo, is_not_base_vtable,
2062 abstract_virtuals);
2063 }
2064 /* Should we use something besides CLASSTYPE_VFIELDS? */
2065 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2066 {
2067 tree virtuals = BINFO_VIRTUALS (binfo);
2068
2069 skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
2070
2071 while (virtuals)
2072 {
2073 tree base_fndecl = TREE_VALUE (virtuals);
2074 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl))
2075 abstract_virtuals = tree_cons (NULL_TREE, base_fndecl,
2076 abstract_virtuals);
2077 virtuals = TREE_CHAIN (virtuals);
2078 }
2079 }
2080 return abstract_virtuals;
2081 }
2082
2083 /* Return the list of virtual functions which are abstract in type TYPE.
2084 This information is cached, and so must be built on a
2085 non-temporary obstack. */
2086
2087 tree
2088 get_abstract_virtuals (type)
2089 tree type;
2090 {
2091 tree vbases;
2092 tree abstract_virtuals = NULL;
2093
2094 /* First get all from non-virtual bases. */
2095 abstract_virtuals
2096 = get_abstract_virtuals_1 (TYPE_BINFO (type), 1, abstract_virtuals);
2097
2098 for (vbases = CLASSTYPE_VBASECLASSES (type); vbases; vbases = TREE_CHAIN (vbases))
2099 {
2100 tree virtuals = BINFO_VIRTUALS (vbases);
2101
2102 skip_rtti_stuff (&virtuals, BINFO_TYPE (vbases));
2103
2104 while (virtuals)
2105 {
2106 tree base_fndecl = TREE_VALUE (virtuals);
2107 if (DECL_NEEDS_FINAL_OVERRIDER_P (base_fndecl))
2108 cp_error ("`%#D' needs a final overrider", base_fndecl);
2109 else if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl))
2110 abstract_virtuals = tree_cons (NULL_TREE, base_fndecl,
2111 abstract_virtuals);
2112 virtuals = TREE_CHAIN (virtuals);
2113 }
2114 }
2115 return nreverse (abstract_virtuals);
2116 }
2117
2118 static tree
2119 next_baselink (baselink)
2120 tree baselink;
2121 {
2122 tree tmp = TREE_TYPE (baselink);
2123 baselink = TREE_CHAIN (baselink);
2124 while (tmp)
2125 {
2126 /* @@ does not yet add previous base types. */
2127 baselink = tree_cons (TREE_PURPOSE (tmp), TREE_VALUE (tmp),
2128 baselink);
2129 TREE_TYPE (baselink) = TREE_TYPE (tmp);
2130 tmp = TREE_CHAIN (tmp);
2131 }
2132 return baselink;
2133 }
2134 \f
2135 /* DEPTH-FIRST SEARCH ROUTINES. */
2136
2137 /* This routine converts a pointer to be a pointer of an immediate
2138 base class. The normal convert_pointer_to routine would diagnose
2139 the conversion as ambiguous, under MI code that has the base class
2140 as an ambiguous base class. */
2141
2142 static tree
2143 convert_pointer_to_single_level (to_type, expr)
2144 tree to_type, expr;
2145 {
2146 tree derived;
2147 tree binfo_of_derived;
2148 int i;
2149
2150 derived = TREE_TYPE (TREE_TYPE (expr));
2151 binfo_of_derived = TYPE_BINFO (derived);
2152 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo_of_derived) == NULL_TREE,
2153 980827);
2154 for (i = CLASSTYPE_N_BASECLASSES (derived) - 1; i >= 0; --i)
2155 {
2156 tree binfo = BINFO_BASETYPE (binfo_of_derived, i);
2157 my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo) == binfo_of_derived,
2158 980827);
2159 if (same_type_p (BINFO_TYPE (binfo), to_type))
2160 return build_vbase_path (PLUS_EXPR,
2161 build_pointer_type (to_type),
2162 expr, binfo, 1);
2163 }
2164
2165 my_friendly_abort (19990607);
2166
2167 /* NOTREACHED */
2168 return NULL_TREE;
2169 }
2170
2171 tree markedp (binfo, data)
2172 tree binfo;
2173 void *data ATTRIBUTE_UNUSED;
2174 {
2175 return BINFO_MARKED (binfo) ? binfo : NULL_TREE;
2176 }
2177
2178 static tree
2179 unmarkedp (binfo, data)
2180 tree binfo;
2181 void *data ATTRIBUTE_UNUSED;
2182 {
2183 return !BINFO_MARKED (binfo) ? binfo : NULL_TREE;
2184 }
2185
2186 static tree
2187 marked_vtable_pathp (binfo, data)
2188 tree binfo;
2189 void *data ATTRIBUTE_UNUSED;
2190 {
2191 return BINFO_VTABLE_PATH_MARKED (binfo) ? binfo : NULL_TREE;
2192 }
2193
2194 static tree
2195 unmarked_vtable_pathp (binfo, data)
2196 tree binfo;
2197 void *data ATTRIBUTE_UNUSED;
2198 {
2199 return !BINFO_VTABLE_PATH_MARKED (binfo) ? binfo : NULL_TREE;
2200 }
2201
2202 static tree
2203 marked_new_vtablep (binfo, data)
2204 tree binfo;
2205 void *data ATTRIBUTE_UNUSED;
2206 {
2207 return BINFO_NEW_VTABLE_MARKED (binfo) ? binfo : NULL_TREE;
2208 }
2209
2210 static tree
2211 unmarked_new_vtablep (binfo, data)
2212 tree binfo;
2213 void *data ATTRIBUTE_UNUSED;
2214 {
2215 return !BINFO_NEW_VTABLE_MARKED (binfo) ? binfo : NULL_TREE;
2216 }
2217
2218 static tree
2219 marked_pushdecls_p (binfo, data)
2220 tree binfo;
2221 void *data ATTRIBUTE_UNUSED;
2222 {
2223 return (CLASS_TYPE_P (BINFO_TYPE (binfo))
2224 && BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
2225 }
2226
2227 static tree
2228 unmarked_pushdecls_p (binfo, data)
2229 tree binfo;
2230 void *data ATTRIBUTE_UNUSED;
2231 {
2232 return (CLASS_TYPE_P (BINFO_TYPE (binfo))
2233 && !BINFO_PUSHDECLS_MARKED (binfo)) ? binfo : NULL_TREE;
2234 }
2235
2236 #if 0
2237 static int dfs_search_slot_nonempty_p (binfo) tree binfo;
2238 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo)) != 0; }
2239 #endif
2240
2241 static tree
2242 dfs_debug_unmarkedp (binfo, data)
2243 tree binfo;
2244 void *data ATTRIBUTE_UNUSED;
2245 {
2246 return (!CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo))
2247 ? binfo : NULL_TREE);
2248 }
2249
2250 /* The worker functions for `dfs_walk'. These do not need to
2251 test anything (vis a vis marking) if they are paired with
2252 a predicate function (above). */
2253
2254 #if 0
2255 static void
2256 dfs_mark (binfo) tree binfo;
2257 { SET_BINFO_MARKED (binfo); }
2258 #endif
2259
2260 tree
2261 dfs_unmark (binfo, data)
2262 tree binfo;
2263 void *data ATTRIBUTE_UNUSED;
2264 {
2265 CLEAR_BINFO_MARKED (binfo);
2266 return NULL_TREE;
2267 }
2268
2269 #if 0
2270 static void
2271 dfs_mark_vtable_path (binfo) tree binfo;
2272 { SET_BINFO_VTABLE_PATH_MARKED (binfo); }
2273
2274 static void
2275 dfs_unmark_vtable_path (binfo) tree binfo;
2276 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo); }
2277
2278 static void
2279 dfs_mark_new_vtable (binfo) tree binfo;
2280 { SET_BINFO_NEW_VTABLE_MARKED (binfo); }
2281
2282 static void
2283 dfs_unmark_new_vtable (binfo) tree binfo;
2284 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo); }
2285
2286 static void
2287 dfs_clear_search_slot (binfo) tree binfo;
2288 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo)) = 0; }
2289 #endif
2290
2291 static tree
2292 dfs_debug_mark (binfo, data)
2293 tree binfo;
2294 void *data ATTRIBUTE_UNUSED;
2295 {
2296 tree t = BINFO_TYPE (binfo);
2297
2298 /* Use heuristic that if there are virtual functions,
2299 ignore until we see a non-inline virtual function. */
2300 tree methods = CLASSTYPE_METHOD_VEC (t);
2301
2302 CLASSTYPE_DEBUG_REQUESTED (t) = 1;
2303
2304 if (methods == 0)
2305 return NULL_TREE;
2306
2307 /* If interface info is known, either we've already emitted the debug
2308 info or we don't need to. */
2309 if (CLASSTYPE_INTERFACE_KNOWN (t))
2310 return NULL_TREE;
2311
2312 /* If debug info is requested from this context for this type, supply it.
2313 If debug info is requested from another context for this type,
2314 see if some third context can supply it. */
2315 if (current_function_decl == NULL_TREE
2316 || DECL_CLASS_CONTEXT (current_function_decl) != t)
2317 {
2318 if (TREE_VEC_ELT (methods, 1))
2319 methods = TREE_VEC_ELT (methods, 1);
2320 else if (TREE_VEC_ELT (methods, 0))
2321 methods = TREE_VEC_ELT (methods, 0);
2322 else
2323 methods = TREE_VEC_ELT (methods, 2);
2324 methods = OVL_CURRENT (methods);
2325 while (methods)
2326 {
2327 if (DECL_VINDEX (methods)
2328 && DECL_THIS_INLINE (methods) == 0
2329 && DECL_ABSTRACT_VIRTUAL_P (methods) == 0)
2330 {
2331 /* Somebody, somewhere is going to have to define this
2332 virtual function. When they do, they will provide
2333 the debugging info. */
2334 return NULL_TREE;
2335 }
2336 methods = TREE_CHAIN (methods);
2337 }
2338 }
2339 /* We cannot rely on some alien method to solve our problems,
2340 so we must write out the debug info ourselves. */
2341 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 0;
2342 rest_of_type_compilation (t, toplevel_bindings_p ());
2343
2344 return NULL_TREE;
2345 }
2346 \f
2347 struct vbase_info
2348 {
2349 tree decl_ptr;
2350 tree inits;
2351 tree vbase_types;
2352 };
2353
2354 /* Attach to the type of the virtual base class, the pointer to the
2355 virtual base class. */
2356
2357 static tree
2358 dfs_find_vbases (binfo, data)
2359 tree binfo;
2360 void *data;
2361 {
2362 struct vbase_info *vi = (struct vbase_info *) data;
2363 tree binfos = BINFO_BASETYPES (binfo);
2364 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2365
2366 for (i = n_baselinks-1; i >= 0; i--)
2367 {
2368 tree base_binfo = TREE_VEC_ELT (binfos, i);
2369
2370 if (TREE_VIA_VIRTUAL (base_binfo)
2371 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo)) == 0)
2372 {
2373 tree vbase = BINFO_TYPE (base_binfo);
2374 tree binfo = binfo_member (vbase, vi->vbase_types);
2375
2376 CLASSTYPE_SEARCH_SLOT (vbase)
2377 = build (PLUS_EXPR, build_pointer_type (vbase),
2378 vi->decl_ptr, BINFO_OFFSET (binfo));
2379 }
2380 }
2381 SET_BINFO_VTABLE_PATH_MARKED (binfo);
2382 SET_BINFO_NEW_VTABLE_MARKED (binfo);
2383
2384 return NULL_TREE;
2385 }
2386
2387 static tree
2388 dfs_init_vbase_pointers (binfo, data)
2389 tree binfo;
2390 void *data;
2391 {
2392 struct vbase_info *vi = (struct vbase_info *) data;
2393 tree type = BINFO_TYPE (binfo);
2394 tree fields = TYPE_FIELDS (type);
2395 tree this_vbase_ptr;
2396
2397 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo);
2398
2399 #if 0
2400 /* See finish_struct_1 for when we can enable this. */
2401 /* If we have a vtable pointer first, skip it. */
2402 if (VFIELD_NAME_P (DECL_NAME (fields)))
2403 fields = TREE_CHAIN (fields);
2404 #endif
2405
2406 if (BINFO_INHERITANCE_CHAIN (binfo))
2407 {
2408 this_vbase_ptr = TREE_CHAIN (BINFO_INHERITANCE_CHAIN (binfo));
2409 if (TREE_VIA_VIRTUAL (binfo))
2410 this_vbase_ptr = CLASSTYPE_SEARCH_SLOT (type);
2411 else
2412 this_vbase_ptr = convert_pointer_to_single_level (type,
2413 this_vbase_ptr);
2414 TREE_CHAIN (binfo) = this_vbase_ptr;
2415 }
2416 else
2417 this_vbase_ptr = TREE_CHAIN (binfo);
2418
2419 if (fields == NULL_TREE
2420 || DECL_NAME (fields) == NULL_TREE
2421 || ! VBASE_NAME_P (DECL_NAME (fields)))
2422 return NULL_TREE;
2423
2424 if (build_pointer_type (type)
2425 != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr)))
2426 my_friendly_abort (125);
2427
2428 while (fields && DECL_NAME (fields) && VBASE_NAME_P (DECL_NAME (fields)))
2429 {
2430 tree ref = build (COMPONENT_REF, TREE_TYPE (fields),
2431 build_indirect_ref (this_vbase_ptr, NULL_PTR), fields);
2432 tree init = CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields)));
2433 vi->inits = tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields)),
2434 vi->vbase_types),
2435 build_modify_expr (ref, NOP_EXPR, init),
2436 vi->inits);
2437 fields = TREE_CHAIN (fields);
2438 }
2439
2440 return NULL_TREE;
2441 }
2442
2443 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2444 times, just NEW_VTABLE, but optimizer should make both with equal
2445 efficiency (though it does not currently). */
2446
2447 static tree
2448 dfs_clear_vbase_slots (binfo, data)
2449 tree binfo;
2450 void *data ATTRIBUTE_UNUSED;
2451 {
2452 tree type = BINFO_TYPE (binfo);
2453 CLASSTYPE_SEARCH_SLOT (type) = 0;
2454 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo);
2455 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2456 return NULL_TREE;
2457 }
2458
2459 tree
2460 init_vbase_pointers (type, decl_ptr)
2461 tree type;
2462 tree decl_ptr;
2463 {
2464 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
2465 {
2466 struct vbase_info vi;
2467 int old_flag = flag_this_is_variable;
2468 tree binfo = TYPE_BINFO (type);
2469 flag_this_is_variable = -2;
2470
2471 /* Find all the virtual base classes, marking them for later
2472 initialization. */
2473 vi.decl_ptr = decl_ptr;
2474 vi.vbase_types = CLASSTYPE_VBASECLASSES (type);
2475 vi.inits = NULL_TREE;
2476
2477 dfs_walk (binfo, dfs_find_vbases, unmarked_vtable_pathp, &vi);
2478
2479 /* Build up a list of the initializers. */
2480 TREE_CHAIN (binfo) = decl_ptr;
2481 dfs_walk_real (binfo,
2482 dfs_init_vbase_pointers, 0,
2483 marked_vtable_pathp,
2484 &vi);
2485
2486 dfs_walk (binfo, dfs_clear_vbase_slots, marked_new_vtablep, 0);
2487 flag_this_is_variable = old_flag;
2488 return vi.inits;
2489 }
2490 return 0;
2491 }
2492
2493 /* get the virtual context (the vbase that directly contains the
2494 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2495 or NULL_TREE if there is none.
2496
2497 FNDECL must come from a virtual table from a virtual base to ensure that
2498 there is only one possible DECL_CLASS_CONTEXT.
2499
2500 We know that if there is more than one place (binfo) the fndecl that the
2501 declared, they all refer to the same binfo. See get_class_offset_1 for
2502 the check that ensures this. */
2503
2504 static tree
2505 virtual_context (fndecl, t, vbase)
2506 tree fndecl, t, vbase;
2507 {
2508 tree path;
2509 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl), t, 0, &path) < 0)
2510 {
2511 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2512 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl), vbase, 0, &path) >= 0)
2513 {
2514 while (path)
2515 {
2516 /* Not sure if checking path == vbase is necessary here, but just in
2517 case it is. */
2518 if (TREE_VIA_VIRTUAL (path) || path == vbase)
2519 return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t));
2520 path = BINFO_INHERITANCE_CHAIN (path);
2521 }
2522 }
2523 /* This shouldn't happen, I don't want errors! */
2524 warning ("recoverable compiler error, fixups for virtual function");
2525 return vbase;
2526 }
2527 while (path)
2528 {
2529 if (TREE_VIA_VIRTUAL (path))
2530 return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t));
2531 path = BINFO_INHERITANCE_CHAIN (path);
2532 }
2533 return 0;
2534 }
2535
2536 /* Fixups upcast offsets for one vtable.
2537 Entries may stay within the VBASE given, or
2538 they may upcast into a direct base, or
2539 they may upcast into a different vbase.
2540
2541 We only need to do fixups in case 2 and 3. In case 2, we add in
2542 the virtual base offset to effect an upcast, in case 3, we add in
2543 the virtual base offset to effect an upcast, then subtract out the
2544 offset for the other virtual base, to effect a downcast into it.
2545
2546 This routine mirrors fixup_vtable_deltas in functionality, though
2547 this one is runtime based, and the other is compile time based.
2548 Conceivably that routine could be removed entirely, and all fixups
2549 done at runtime.
2550
2551 VBASE_OFFSETS is an association list of virtual bases that contains
2552 offset information for the virtual bases, so the offsets are only
2553 calculated once. The offsets are computed by where we think the
2554 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2555 the vbase really is. */
2556
2557 static void
2558 expand_upcast_fixups (binfo, addr, orig_addr, vbase, vbase_addr, t,
2559 vbase_offsets)
2560 tree binfo, addr, orig_addr, vbase, vbase_addr, t, *vbase_offsets;
2561 {
2562 tree virtuals = BINFO_VIRTUALS (binfo);
2563 tree vc;
2564 tree delta;
2565 unsigned HOST_WIDE_INT n;
2566
2567 delta = purpose_member (vbase, *vbase_offsets);
2568 if (! delta)
2569 {
2570 delta = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase));
2571 delta = build (MINUS_EXPR, ptrdiff_type_node, delta, vbase_addr);
2572 delta = save_expr (delta);
2573 delta = tree_cons (vbase, delta, *vbase_offsets);
2574 *vbase_offsets = delta;
2575 }
2576
2577 n = skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
2578
2579 while (virtuals)
2580 {
2581 tree current_fndecl = TREE_VALUE (virtuals);
2582
2583 if (current_fndecl
2584 && current_fndecl != abort_fndecl
2585 && (vc=virtual_context (current_fndecl, t, vbase)) != vbase)
2586 {
2587 /* This may in fact need a runtime fixup. */
2588 tree idx = build_int_2 (n, 0);
2589 tree vtbl = BINFO_VTABLE (binfo);
2590 tree nvtbl = lookup_name (DECL_NAME (vtbl), 0);
2591 tree aref, ref, naref;
2592 tree old_delta, new_delta;
2593 tree init;
2594
2595 if (nvtbl == NULL_TREE
2596 || nvtbl == IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl)))
2597 {
2598 /* Dup it if it isn't in local scope yet. */
2599 nvtbl = build_decl
2600 (VAR_DECL, DECL_NAME (vtbl),
2601 TYPE_MAIN_VARIANT (TREE_TYPE (vtbl)));
2602 DECL_ALIGN (nvtbl) = MAX (TYPE_ALIGN (double_type_node),
2603 DECL_ALIGN (nvtbl));
2604 TREE_READONLY (nvtbl) = 0;
2605 DECL_ARTIFICIAL (nvtbl) = 1;
2606 nvtbl = pushdecl (nvtbl);
2607 init = NULL_TREE;
2608 cp_finish_decl (nvtbl, init, NULL_TREE, 0,
2609 LOOKUP_ONLYCONVERTING);
2610
2611 /* We don't set DECL_VIRTUAL_P and DECL_CONTEXT on nvtbl
2612 because they wouldn't be useful; everything that wants to
2613 look at the vtable will look at the decl for the normal
2614 vtable. Setting DECL_CONTEXT also screws up
2615 decl_function_context. */
2616
2617 init = build (MODIFY_EXPR, TREE_TYPE (nvtbl),
2618 nvtbl, vtbl);
2619 TREE_SIDE_EFFECTS (init) = 1;
2620 expand_expr_stmt (init);
2621 /* Update the vtable pointers as necessary. */
2622 ref = build_vfield_ref
2623 (build_indirect_ref (addr, NULL_PTR),
2624 DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))));
2625 expand_expr_stmt
2626 (build_modify_expr (ref, NOP_EXPR, nvtbl));
2627 }
2628 assemble_external (vtbl);
2629 aref = build_array_ref (vtbl, idx);
2630 naref = build_array_ref (nvtbl, idx);
2631 old_delta = build_component_ref (aref, delta_identifier,
2632 NULL_TREE, 0);
2633 new_delta = build_component_ref (naref, delta_identifier,
2634 NULL_TREE, 0);
2635
2636 /* This is a upcast, so we have to add the offset for the
2637 virtual base. */
2638 old_delta = build_binary_op (PLUS_EXPR, old_delta,
2639 TREE_VALUE (delta));
2640 if (vc)
2641 {
2642 /* If this is set, we need to subtract out the delta
2643 adjustments for the other virtual base that we
2644 downcast into. */
2645 tree vc_delta = purpose_member (vc, *vbase_offsets);
2646 if (! vc_delta)
2647 {
2648 tree vc_addr = convert_pointer_to_real (vc, orig_addr);
2649 vc_delta = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc));
2650 vc_delta = build (MINUS_EXPR, ptrdiff_type_node,
2651 vc_delta, vc_addr);
2652 vc_delta = save_expr (vc_delta);
2653 *vbase_offsets = tree_cons (vc, vc_delta, *vbase_offsets);
2654 }
2655 else
2656 vc_delta = TREE_VALUE (vc_delta);
2657
2658 /* This is a downcast, so we have to subtract the offset
2659 for the virtual base. */
2660 old_delta = build_binary_op (MINUS_EXPR, old_delta, vc_delta);
2661 }
2662
2663 TREE_READONLY (new_delta) = 0;
2664 TREE_TYPE (new_delta) =
2665 cp_build_qualified_type (TREE_TYPE (new_delta),
2666 CP_TYPE_QUALS (TREE_TYPE (new_delta))
2667 & ~TYPE_QUAL_CONST);
2668 expand_expr_stmt (build_modify_expr (new_delta, NOP_EXPR,
2669 old_delta));
2670 }
2671 ++n;
2672 virtuals = TREE_CHAIN (virtuals);
2673 }
2674 }
2675
2676 /* Fixup upcast offsets for all direct vtables. Patterned after
2677 expand_direct_vtbls_init. */
2678
2679 static void
2680 fixup_virtual_upcast_offsets (real_binfo, binfo, init_self, can_elide, addr, orig_addr, type, vbase, vbase_offsets)
2681 tree real_binfo, binfo;
2682 int init_self, can_elide;
2683 tree addr, orig_addr, type, vbase, *vbase_offsets;
2684 {
2685 tree real_binfos = BINFO_BASETYPES (real_binfo);
2686 tree binfos = BINFO_BASETYPES (binfo);
2687 int i, n_baselinks = real_binfos ? TREE_VEC_LENGTH (real_binfos) : 0;
2688
2689 for (i = 0; i < n_baselinks; i++)
2690 {
2691 tree real_base_binfo = TREE_VEC_ELT (real_binfos, i);
2692 tree base_binfo = TREE_VEC_ELT (binfos, i);
2693 int is_not_base_vtable
2694 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo));
2695 if (! TREE_VIA_VIRTUAL (real_base_binfo))
2696 fixup_virtual_upcast_offsets (real_base_binfo, base_binfo,
2697 is_not_base_vtable, can_elide, addr,
2698 orig_addr, type, vbase, vbase_offsets);
2699 }
2700 #if 0
2701 /* Before turning this on, make sure it is correct. */
2702 if (can_elide && ! BINFO_MODIFIED (binfo))
2703 return;
2704 #endif
2705 /* Should we use something besides CLASSTYPE_VFIELDS? */
2706 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo)))
2707 {
2708 tree new_addr = convert_pointer_to_real (binfo, addr);
2709 expand_upcast_fixups (real_binfo, new_addr, orig_addr, vbase, addr,
2710 type, vbase_offsets);
2711 }
2712 }
2713
2714 /* Build a COMPOUND_EXPR which when expanded will generate the code
2715 needed to initialize all the virtual function table slots of all
2716 the virtual baseclasses. MAIN_BINFO is the binfo which determines
2717 the virtual baseclasses to use; TYPE is the type of the object to
2718 which the initialization applies. TRUE_EXP is the true object we
2719 are initializing, and DECL_PTR is the pointer to the sub-object we
2720 are initializing.
2721
2722 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
2723 object was laid out by a top-level constructor and the computed
2724 offsets are valid to store vtables. When zero, we must store new
2725 vtables through virtual baseclass pointers. */
2726
2727 void
2728 expand_indirect_vtbls_init (binfo, true_exp, decl_ptr)
2729 tree binfo;
2730 tree true_exp, decl_ptr;
2731 {
2732 tree type = BINFO_TYPE (binfo);
2733
2734 /* This function executes during the finish_function() segment,
2735 AFTER the auto variables and temporary stack space has been marked
2736 unused...If space is needed for the virtual function tables,
2737 some of them might fit within what the compiler now thinks
2738 are available stack slots... These values are actually initialized at
2739 the beginnning of the function, so when the automatics use their space,
2740 they will overwrite the values that are placed here. Marking all
2741 temporary space as unavailable prevents this from happening. */
2742
2743 mark_all_temps_used();
2744
2745 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
2746 {
2747 rtx fixup_insns = NULL_RTX;
2748 tree vbases = CLASSTYPE_VBASECLASSES (type);
2749 struct vbase_info vi;
2750 vi.decl_ptr = (true_exp ? build_unary_op (ADDR_EXPR, true_exp, 0)
2751 : decl_ptr);
2752 vi.vbase_types = vbases;
2753
2754 dfs_walk (binfo, dfs_find_vbases, unmarked_new_vtablep, &vi);
2755
2756 /* Initialized with vtables of type TYPE. */
2757 for (; vbases; vbases = TREE_CHAIN (vbases))
2758 {
2759 tree addr;
2760
2761 addr = convert_pointer_to_vbase (TREE_TYPE (vbases), vi.decl_ptr);
2762
2763 /* Do all vtables from this virtual base. */
2764 /* This assumes that virtual bases can never serve as parent
2765 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
2766 expand_direct_vtbls_init (vbases, TYPE_BINFO (BINFO_TYPE (vbases)),
2767 1, 0, addr);
2768
2769 /* Now we adjust the offsets for virtual functions that
2770 cross virtual boundaries on an implicit upcast on vf call
2771 so that the layout of the most complete type is used,
2772 instead of assuming the layout of the virtual bases from
2773 our current type. */
2774
2775 if (flag_vtable_thunks)
2776 {
2777 /* We don't have dynamic thunks yet!
2778 So for now, just fail silently. */
2779 }
2780 else
2781 {
2782 tree vbase_offsets = NULL_TREE;
2783 push_to_sequence (fixup_insns);
2784 fixup_virtual_upcast_offsets (vbases,
2785 TYPE_BINFO (BINFO_TYPE (vbases)),
2786 1, 0, addr, vi.decl_ptr,
2787 type, vbases, &vbase_offsets);
2788 fixup_insns = get_insns ();
2789 end_sequence ();
2790 }
2791 }
2792
2793 if (fixup_insns)
2794 {
2795 extern tree in_charge_identifier;
2796 tree in_charge_node = lookup_name (in_charge_identifier, 0);
2797 if (! in_charge_node)
2798 {
2799 warning ("recoverable internal compiler error, nobody's in charge!");
2800 in_charge_node = integer_zero_node;
2801 }
2802 in_charge_node = build_binary_op (EQ_EXPR, in_charge_node, integer_zero_node);
2803 expand_start_cond (in_charge_node, 0);
2804 emit_insns (fixup_insns);
2805 expand_end_cond ();
2806 }
2807
2808 dfs_walk (binfo, dfs_clear_vbase_slots, marked_new_vtablep, 0);
2809 }
2810 }
2811
2812 /* get virtual base class types.
2813 This adds type to the vbase_types list in reverse dfs order.
2814 Ordering is very important, so don't change it. */
2815
2816 static tree
2817 dfs_get_vbase_types (binfo, data)
2818 tree binfo;
2819 void *data;
2820 {
2821 tree *vbase_types = (tree *) data;
2822
2823 if (TREE_VIA_VIRTUAL (binfo) && ! BINFO_VBASE_MARKED (binfo))
2824 {
2825 tree new_vbase = make_binfo (integer_zero_node, binfo,
2826 BINFO_VTABLE (binfo),
2827 BINFO_VIRTUALS (binfo));
2828 TREE_CHAIN (new_vbase) = *vbase_types;
2829 TREE_VIA_VIRTUAL (new_vbase) = 1;
2830 *vbase_types = new_vbase;
2831 SET_BINFO_VBASE_MARKED (binfo);
2832 }
2833 SET_BINFO_MARKED (binfo);
2834 return NULL_TREE;
2835 }
2836
2837 /* Return a list of binfos for the virtual base classes for TYPE, in
2838 depth-first search order. The list is freshly allocated, so
2839 no modification is made to the current binfo hierarchy. */
2840
2841 tree
2842 get_vbase_types (type)
2843 tree type;
2844 {
2845 tree vbase_types;
2846 tree vbases;
2847 tree binfo;
2848
2849 binfo = TYPE_BINFO (type);
2850 vbase_types = NULL_TREE;
2851 dfs_walk (binfo, dfs_get_vbase_types, unmarkedp, &vbase_types);
2852 dfs_walk (binfo, dfs_unmark, markedp, 0);
2853 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
2854 reverse it so that we get normal dfs ordering. */
2855 vbase_types = nreverse (vbase_types);
2856
2857 /* unmark marked vbases */
2858 for (vbases = vbase_types; vbases; vbases = TREE_CHAIN (vbases))
2859 CLEAR_BINFO_VBASE_MARKED (vbases);
2860
2861 return vbase_types;
2862 }
2863 \f
2864 /* If we want debug info for a type TYPE, make sure all its base types
2865 are also marked as being potentially interesting. This avoids
2866 the problem of not writing any debug info for intermediate basetypes
2867 that have abstract virtual functions. Also mark member types. */
2868
2869 void
2870 note_debug_info_needed (type)
2871 tree type;
2872 {
2873 tree field;
2874
2875 if (current_template_parms)
2876 return;
2877
2878 if (TYPE_BEING_DEFINED (type))
2879 /* We can't go looking for the base types and fields just yet. */
2880 return;
2881
2882 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
2883 does not support name references between translation units. Well, we
2884 could, but that would mean putting global labels in the debug output
2885 before each exported type and each of its functions and static data
2886 members. */
2887 if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG
2888 || write_symbols == NO_DEBUG)
2889 return;
2890
2891 dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp, 0);
2892 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
2893 {
2894 tree ttype;
2895 if (TREE_CODE (field) == FIELD_DECL
2896 && IS_AGGR_TYPE (ttype = target_type (TREE_TYPE (field)))
2897 && dfs_debug_unmarkedp (TYPE_BINFO (ttype), 0))
2898 note_debug_info_needed (ttype);
2899 }
2900 }
2901 \f
2902 /* Subroutines of push_class_decls (). */
2903
2904 /* Returns 1 iff BINFO is a base we shouldn't really be able to see into,
2905 because it (or one of the intermediate bases) depends on template parms. */
2906
2907 static int
2908 dependent_base_p (binfo)
2909 tree binfo;
2910 {
2911 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
2912 {
2913 if (currently_open_class (TREE_TYPE (binfo)))
2914 break;
2915 if (uses_template_parms (TREE_TYPE (binfo)))
2916 return 1;
2917 }
2918 return 0;
2919 }
2920
2921 static void
2922 setup_class_bindings (name, type_binding_p)
2923 tree name;
2924 int type_binding_p;
2925 {
2926 tree type_binding = NULL_TREE;
2927 tree value_binding;
2928
2929 /* If we've already done the lookup for this declaration, we're
2930 done. */
2931 if (IDENTIFIER_CLASS_VALUE (name))
2932 return;
2933
2934 /* First, deal with the type binding. */
2935 if (type_binding_p)
2936 {
2937 type_binding = lookup_member (current_class_type, name,
2938 /*protect=*/2,
2939 /*want_type=*/1);
2940 if (TREE_CODE (type_binding) == TREE_LIST
2941 && TREE_TYPE (type_binding) == error_mark_node)
2942 /* NAME is ambiguous. */
2943 push_class_level_binding (name, type_binding);
2944 else
2945 pushdecl_class_level (type_binding);
2946 }
2947
2948 /* Now, do the value binding. */
2949 value_binding = lookup_member (current_class_type, name,
2950 /*protect=*/2,
2951 /*want_type=*/0);
2952
2953 if (type_binding_p
2954 && (TREE_CODE (value_binding) == TYPE_DECL
2955 || (TREE_CODE (value_binding) == TREE_LIST
2956 && TREE_TYPE (value_binding) == error_mark_node
2957 && (TREE_CODE (TREE_VALUE (value_binding))
2958 == TYPE_DECL))))
2959 /* We found a type-binding, even when looking for a non-type
2960 binding. This means that we already processed this binding
2961 above. */
2962 my_friendly_assert (type_binding_p, 19990401);
2963 else if (value_binding)
2964 {
2965 if (TREE_CODE (value_binding) == TREE_LIST
2966 && TREE_TYPE (value_binding) == error_mark_node)
2967 /* NAME is ambiguous. */
2968 push_class_level_binding (name, value_binding);
2969 else
2970 {
2971 if (BASELINK_P (value_binding))
2972 /* NAME is some overloaded functions. */
2973 value_binding = TREE_VALUE (value_binding);
2974 pushdecl_class_level (value_binding);
2975 }
2976 }
2977 }
2978
2979 /* Push class-level declarations for any names appearing in BINFO that
2980 are TYPE_DECLS. */
2981
2982 static tree
2983 dfs_push_type_decls (binfo, data)
2984 tree binfo;
2985 void *data ATTRIBUTE_UNUSED;
2986 {
2987 tree type;
2988 tree fields;
2989
2990 type = BINFO_TYPE (binfo);
2991 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2992 if (DECL_NAME (fields) && TREE_CODE (fields) == TYPE_DECL
2993 && !(!same_type_p (type, current_class_type)
2994 && template_self_reference_p (type, fields)))
2995 setup_class_bindings (DECL_NAME (fields), /*type_binding_p=*/1);
2996
2997 /* We can't just use BINFO_MARKED because envelope_add_decl uses
2998 DERIVED_FROM_P, which calls get_base_distance. */
2999 SET_BINFO_PUSHDECLS_MARKED (binfo);
3000
3001 return NULL_TREE;
3002 }
3003
3004 /* Push class-level declarations for any names appearing in BINFO that
3005 are not TYPE_DECLS. */
3006
3007 static tree
3008 dfs_push_decls (binfo, data)
3009 tree binfo;
3010 void *data;
3011 {
3012 tree type;
3013 tree method_vec;
3014 int dep_base_p;
3015
3016 type = BINFO_TYPE (binfo);
3017 dep_base_p = (processing_template_decl && type != current_class_type
3018 && dependent_base_p (binfo));
3019 if (!dep_base_p)
3020 {
3021 tree fields;
3022 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
3023 if (DECL_NAME (fields)
3024 && TREE_CODE (fields) != TYPE_DECL
3025 && TREE_CODE (fields) != USING_DECL)
3026 setup_class_bindings (DECL_NAME (fields), /*type_binding_p=*/0);
3027 else if (TREE_CODE (fields) == FIELD_DECL
3028 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
3029 dfs_push_decls (TYPE_BINFO (TREE_TYPE (fields)), data);
3030
3031 method_vec = (CLASS_TYPE_P (type)
3032 ? CLASSTYPE_METHOD_VEC (type) : NULL_TREE);
3033 if (method_vec)
3034 {
3035 tree *methods;
3036 tree *end;
3037
3038 /* Farm out constructors and destructors. */
3039 end = TREE_VEC_END (method_vec);
3040
3041 for (methods = &TREE_VEC_ELT (method_vec, 2);
3042 *methods && methods != end;
3043 methods++)
3044 setup_class_bindings (DECL_NAME (OVL_CURRENT (*methods)),
3045 /*type_binding_p=*/0);
3046 }
3047 }
3048
3049 CLEAR_BINFO_PUSHDECLS_MARKED (binfo);
3050
3051 return NULL_TREE;
3052 }
3053
3054 /* When entering the scope of a class, we cache all of the
3055 fields that that class provides within its inheritance
3056 lattice. Where ambiguities result, we mark them
3057 with `error_mark_node' so that if they are encountered
3058 without explicit qualification, we can emit an error
3059 message. */
3060
3061 void
3062 push_class_decls (type)
3063 tree type;
3064 {
3065 struct obstack *ambient_obstack = current_obstack;
3066 search_stack = push_search_level (search_stack, &search_obstack);
3067
3068 /* Build up all the relevant bindings and such on the cache
3069 obstack. That way no memory is wasted when we throw away the
3070 cache later. */
3071 push_cache_obstack ();
3072
3073 /* Enter type declarations and mark. */
3074 dfs_walk (TYPE_BINFO (type), dfs_push_type_decls, unmarked_pushdecls_p, 0);
3075
3076 /* Enter non-type declarations and unmark. */
3077 dfs_walk (TYPE_BINFO (type), dfs_push_decls, marked_pushdecls_p, 0);
3078
3079 /* Undo the call to push_cache_obstack above. */
3080 pop_obstacks ();
3081
3082 current_obstack = ambient_obstack;
3083 }
3084
3085 /* Here's a subroutine we need because C lacks lambdas. */
3086
3087 static tree
3088 dfs_unuse_fields (binfo, data)
3089 tree binfo;
3090 void *data ATTRIBUTE_UNUSED;
3091 {
3092 tree type = TREE_TYPE (binfo);
3093 tree fields;
3094
3095 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
3096 {
3097 if (TREE_CODE (fields) != FIELD_DECL)
3098 continue;
3099
3100 TREE_USED (fields) = 0;
3101 if (DECL_NAME (fields) == NULL_TREE
3102 && ANON_AGGR_TYPE_P (TREE_TYPE (fields)))
3103 unuse_fields (TREE_TYPE (fields));
3104 }
3105
3106 return NULL_TREE;
3107 }
3108
3109 void
3110 unuse_fields (type)
3111 tree type;
3112 {
3113 dfs_walk (TYPE_BINFO (type), dfs_unuse_fields, unmarkedp, 0);
3114 }
3115
3116 void
3117 pop_class_decls ()
3118 {
3119 /* We haven't pushed a search level when dealing with cached classes,
3120 so we'd better not try to pop it. */
3121 if (search_stack)
3122 search_stack = pop_search_level (search_stack);
3123 }
3124
3125 void
3126 print_search_statistics ()
3127 {
3128 #ifdef GATHER_STATISTICS
3129 fprintf (stderr, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3130 n_fields_searched, n_calls_lookup_field, n_calls_lookup_field_1);
3131 fprintf (stderr, "%d fnfields searched in %d calls to lookup_fnfields\n",
3132 n_outer_fields_searched, n_calls_lookup_fnfields);
3133 fprintf (stderr, "%d calls to get_base_type\n", n_calls_get_base_type);
3134 #else /* GATHER_STATISTICS */
3135 fprintf (stderr, "no search statistics\n");
3136 #endif /* GATHER_STATISTICS */
3137 }
3138
3139 void
3140 init_search_processing ()
3141 {
3142 gcc_obstack_init (&search_obstack);
3143 _vptr_name = get_identifier ("_vptr");
3144 }
3145
3146 void
3147 reinit_search_statistics ()
3148 {
3149 #ifdef GATHER_STATISTICS
3150 n_fields_searched = 0;
3151 n_calls_lookup_field = 0, n_calls_lookup_field_1 = 0;
3152 n_calls_lookup_fnfields = 0, n_calls_lookup_fnfields_1 = 0;
3153 n_calls_get_base_type = 0;
3154 n_outer_fields_searched = 0;
3155 n_contexts_saved = 0;
3156 #endif /* GATHER_STATISTICS */
3157 }
3158
3159 #define scratch_tree_cons expr_tree_cons
3160
3161 static tree
3162 add_conversions (binfo, data)
3163 tree binfo;
3164 void *data;
3165 {
3166 int i;
3167 tree method_vec = CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo));
3168 tree *conversions = (tree *) data;
3169
3170 /* Some builtin types have no method vector, not even an empty one. */
3171 if (!method_vec)
3172 return NULL_TREE;
3173
3174 for (i = 2; i < TREE_VEC_LENGTH (method_vec); ++i)
3175 {
3176 tree tmp = TREE_VEC_ELT (method_vec, i);
3177 tree name;
3178
3179 if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp)))
3180 break;
3181
3182 name = DECL_NAME (OVL_CURRENT (tmp));
3183
3184 /* Make sure we don't already have this conversion. */
3185 if (! IDENTIFIER_MARKED (name))
3186 {
3187 *conversions = scratch_tree_cons (binfo, tmp, *conversions);
3188 IDENTIFIER_MARKED (name) = 1;
3189 }
3190 }
3191 return NULL_TREE;
3192 }
3193
3194 /* Return a TREE_LIST containing all the non-hidden user-defined
3195 conversion functions for TYPE (and its base-classes). The
3196 TREE_VALUE of each node is a FUNCTION_DECL or an OVERLOAD
3197 containing the conversion functions. The TREE_PURPOSE is the BINFO
3198 from which the conversion functions in this node were selected. */
3199
3200 tree
3201 lookup_conversions (type)
3202 tree type;
3203 {
3204 tree t;
3205 tree conversions = NULL_TREE;
3206
3207 if (TYPE_SIZE (type))
3208 bfs_walk (TYPE_BINFO (type), add_conversions, 0, &conversions);
3209
3210 for (t = conversions; t; t = TREE_CHAIN (t))
3211 IDENTIFIER_MARKED (DECL_NAME (OVL_CURRENT (TREE_VALUE (t)))) = 0;
3212
3213 return conversions;
3214 }
3215
3216 struct overlap_info
3217 {
3218 tree compare_type;
3219 int found_overlap;
3220 };
3221
3222 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3223 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3224
3225 static tree
3226 dfs_check_overlap (empty_binfo, data)
3227 tree empty_binfo;
3228 void *data;
3229 {
3230 struct overlap_info *oi = (struct overlap_info *) data;
3231 tree binfo;
3232 for (binfo = TYPE_BINFO (oi->compare_type);
3233 ;
3234 binfo = BINFO_BASETYPE (binfo, 0))
3235 {
3236 if (BINFO_TYPE (binfo) == BINFO_TYPE (empty_binfo))
3237 {
3238 oi->found_overlap = 1;
3239 break;
3240 }
3241 else if (BINFO_BASETYPES (binfo) == NULL_TREE)
3242 break;
3243 }
3244
3245 return NULL_TREE;
3246 }
3247
3248 /* Trivial function to stop base traversal when we find something. */
3249
3250 static tree
3251 dfs_no_overlap_yet (binfo, data)
3252 tree binfo;
3253 void *data;
3254 {
3255 struct overlap_info *oi = (struct overlap_info *) data;
3256 return !oi->found_overlap ? binfo : NULL_TREE;
3257 }
3258
3259 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3260 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3261
3262 int
3263 types_overlap_p (empty_type, next_type)
3264 tree empty_type, next_type;
3265 {
3266 struct overlap_info oi;
3267
3268 if (! IS_AGGR_TYPE (next_type))
3269 return 0;
3270 oi.compare_type = next_type;
3271 oi.found_overlap = 0;
3272 dfs_walk (TYPE_BINFO (empty_type), dfs_check_overlap,
3273 dfs_no_overlap_yet, &oi);
3274 return oi.found_overlap;
3275 }
3276
3277 struct bfv_info {
3278 tree vbases;
3279 tree var;
3280 };
3281
3282 static tree
3283 dfs_bfv_queue_p (binfo, data)
3284 tree binfo;
3285 void *data;
3286 {
3287 struct bfv_info *bfvi = (struct bfv_info *) data;
3288
3289 /* Use the real virtual base class objects, not the placeholders in
3290 the usual hierarchy. */
3291 if (TREE_VIA_VIRTUAL (binfo))
3292 return binfo_member (BINFO_TYPE (binfo), bfvi->vbases);
3293
3294 return binfo;
3295 }
3296
3297 /* Passed to dfs_walk_real by binfo_for_vtable; determine if bvtable
3298 comes from BINFO. */
3299
3300 static tree
3301 dfs_bfv_helper (binfo, data)
3302 tree binfo;
3303 void *data;
3304 {
3305 struct bfv_info *bfvi = (struct bfv_info *) data;
3306
3307 if (BINFO_VTABLE (binfo) == bfvi->var)
3308 return binfo;
3309 return NULL_TREE;
3310 }
3311
3312 /* Given a vtable VAR, determine which binfo it comes from. */
3313
3314 tree
3315 binfo_for_vtable (var)
3316 tree var;
3317 {
3318 tree type;
3319 struct bfv_info bfvi;
3320
3321 type = DECL_CONTEXT (var);
3322 bfvi.vbases = CLASSTYPE_VBASECLASSES (type);
3323 bfvi.var = var;
3324 return dfs_walk_real (TYPE_BINFO (type),
3325 0, dfs_bfv_helper, dfs_bfv_queue_p, &bfvi);
3326 }
3327
3328 /* Returns 1 iff BINFO is from a direct or indirect virtual base. */
3329
3330 int
3331 binfo_from_vbase (binfo)
3332 tree binfo;
3333 {
3334 for (; binfo; binfo = BINFO_INHERITANCE_CHAIN (binfo))
3335 {
3336 if (TREE_VIA_VIRTUAL (binfo))
3337 return 1;
3338 }
3339 return 0;
3340 }
This page took 0.183861 seconds and 6 git commands to generate.