]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/search.c
typo typo fixes fixes
[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-96, 1997 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
35 #define obstack_chunk_alloc xmalloc
36 #define obstack_chunk_free free
37
38 extern struct obstack *current_obstack;
39 extern tree abort_fndecl;
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 void clear_memoized_cache PROTO((void));
80 static tree make_memoized_table_entry PROTO((tree, tree, int));
81 static tree get_abstract_virtuals_1 PROTO((tree, int, tree));
82 static tree get_vbase_1 PROTO((tree, tree, unsigned int *));
83 static tree convert_pointer_to_vbase PROTO((tree, tree));
84 static tree lookup_field_1 PROTO((tree, tree));
85 static tree convert_pointer_to_single_level PROTO((tree, tree));
86 static int lookup_fnfields_1 PROTO((tree, tree));
87 static int lookup_fnfields_here PROTO((tree, tree));
88 static int is_subobject_of_p PROTO((tree, tree));
89 static int hides PROTO((tree, tree));
90 static tree virtual_context PROTO((tree, tree, tree));
91 static tree get_template_base_recursive
92 PROTO((tree, tree, tree, int));
93 static void dfs_walk PROTO((tree, void (*) (tree), int (*) (tree)));
94 static void dfs_check_overlap PROTO((tree));
95 static int dfs_no_overlap_yet PROTO((tree));
96 static void envelope_add_decl PROTO((tree, tree, tree *));
97 static int get_base_distance_recursive
98 PROTO((tree, int, int, int, int *, tree *, tree, tree *,
99 int, int *, int, int));
100 static void expand_upcast_fixups
101 PROTO((tree, tree, tree, tree, tree, tree, tree *));
102 static void fixup_virtual_upcast_offsets
103 PROTO((tree, tree, int, int, tree, tree, tree, tree,
104 tree *));
105 static int markedp PROTO((tree));
106 static int unmarkedp PROTO((tree));
107 #ifdef MI_MATRIX
108 static int numberedp PROTO((tree));
109 static int unnumberedp PROTO((tree));
110 #endif
111 static int marked_vtable_pathp PROTO((tree));
112 static int unmarked_vtable_pathp PROTO((tree));
113 static int marked_new_vtablep PROTO((tree));
114 static int unmarked_new_vtablep PROTO((tree));
115 static int dfs_debug_unmarkedp PROTO((tree));
116 #ifdef MI_MATRIX
117 static void dfs_number PROTO((tree));
118 static void dfs_unnumber PROTO((tree));
119 static void dfs_record_inheritance PROTO((tree));
120 #endif
121 static void dfs_debug_mark PROTO((tree));
122 static void dfs_find_vbases PROTO((tree));
123 static void dfs_clear_vbase_slots PROTO((tree));
124 static void dfs_unmark PROTO((tree));
125 static void dfs_init_vbase_pointers PROTO((tree));
126 static void dfs_get_vbase_types PROTO((tree));
127 static void dfs_pushdecls PROTO((tree));
128 static void dfs_compress_decls PROTO((tree));
129 static void dfs_unuse_fields PROTO((tree));
130 static void add_conversions PROTO((tree));
131 static tree get_virtuals_named_this PROTO((tree));
132 static tree get_virtual_destructor PROTO((tree, int));
133 static int tree_has_any_destructor_p PROTO((tree, int));
134 static struct search_level *push_search_level
135 PROTO((struct stack_level *, struct obstack *));
136 static struct search_level *pop_search_level
137 PROTO((struct stack_level *));
138 static struct type_level *push_type_level
139 PROTO((struct stack_level *, struct obstack *));
140 static struct type_level *pop_type_level
141 PROTO((struct type_level *));
142 static tree my_tree_cons PROTO((tree, tree, tree));
143 static tree my_build_string PROTO((char *));
144 static struct memoized_entry * my_new_memoized_entry
145 PROTO((struct memoized_entry *));
146 static HOST_WIDE_INT breadth_first_search
147 PROTO((tree, int (*) (tree, int), int (*) (tree, int)));
148
149 static tree vbase_types;
150 static tree vbase_decl_ptr_intermediate, vbase_decl_ptr;
151 static tree vbase_init_result;
152
153 /* Allocate a level of searching. */
154
155 static struct search_level *
156 push_search_level (stack, obstack)
157 struct stack_level *stack;
158 struct obstack *obstack;
159 {
160 struct search_level tem;
161
162 tem.prev = stack;
163 return push_stack_level (obstack, (char *)&tem, sizeof (tem));
164 }
165
166 /* Discard a level of search allocation. */
167
168 static struct search_level *
169 pop_search_level (obstack)
170 struct stack_level *obstack;
171 {
172 register struct search_level *stack = pop_stack_level (obstack);
173
174 return stack;
175 }
176 \f
177 /* Search memoization. */
178
179 struct type_level
180 {
181 struct stack_level base;
182
183 /* First object allocated in obstack of entries. */
184 char *entries;
185
186 /* Number of types memoized in this context. */
187 int len;
188
189 /* Type being memoized; save this if we are saving
190 memoized contexts. */
191 tree type;
192 };
193
194 /* Obstack used for memoizing member and member function lookup. */
195
196 static struct obstack type_obstack, type_obstack_entries;
197 static struct type_level *type_stack;
198 static tree _vptr_name;
199
200 /* Make things that look like tree nodes, but allocate them
201 on type_obstack_entries. */
202 static int my_tree_node_counter;
203
204 extern int flag_memoize_lookups, flag_save_memoized_contexts;
205
206 /* Variables for gathering statistics. */
207 static int my_memoized_entry_counter;
208 static int memoized_fast_finds[2], memoized_adds[2], memoized_fast_rejects[2];
209 static int memoized_fields_searched[2];
210 #ifdef GATHER_STATISTICS
211 static int n_fields_searched;
212 static int n_calls_lookup_field, n_calls_lookup_field_1;
213 static int n_calls_lookup_fnfields, n_calls_lookup_fnfields_1;
214 static int n_calls_get_base_type;
215 static int n_outer_fields_searched;
216 static int n_contexts_saved;
217 #endif /* GATHER_STATISTICS */
218
219 /* Local variables to help save memoization contexts. */
220 static tree prev_type_memoized;
221 static struct type_level *prev_type_stack;
222
223 /* This list is used by push_class_decls to know what decls need to
224 be pushed into class scope. */
225 static tree closed_envelopes = NULL_TREE;
226
227 /* Allocate a level of type memoization context. */
228
229 static struct type_level *
230 push_type_level (stack, obstack)
231 struct stack_level *stack;
232 struct obstack *obstack;
233 {
234 struct type_level tem;
235
236 tem.base.prev = stack;
237
238 obstack_finish (&type_obstack_entries);
239 tem.entries = (char *) obstack_base (&type_obstack_entries);
240 tem.len = 0;
241 tem.type = NULL_TREE;
242
243 return (struct type_level *)push_stack_level (obstack, (char *)&tem, sizeof (tem));
244 }
245
246 /* Discard a level of type memoization context. */
247
248 static struct type_level *
249 pop_type_level (stack)
250 struct type_level *stack;
251 {
252 obstack_free (&type_obstack_entries, stack->entries);
253 return (struct type_level *)pop_stack_level ((struct stack_level *)stack);
254 }
255
256 /* Make something that looks like a TREE_LIST, but
257 do it on the type_obstack_entries obstack. */
258
259 static tree
260 my_tree_cons (purpose, value, chain)
261 tree purpose, value, chain;
262 {
263 tree p = (tree)obstack_alloc (&type_obstack_entries, sizeof (struct tree_list));
264 ++my_tree_node_counter;
265 TREE_TYPE (p) = NULL_TREE;
266 /* The type of the last on the LHS of this statement must be a pointer
267 to the same type as the bitfields in struct tree_common. Otherwise
268 we may write beyond our intended area. */
269 ((unsigned *)p)[3] = 0;
270 TREE_SET_CODE (p, TREE_LIST);
271 TREE_PURPOSE (p) = purpose;
272 TREE_VALUE (p) = value;
273 TREE_CHAIN (p) = chain;
274 return p;
275 }
276
277 static tree
278 my_build_string (str)
279 char *str;
280 {
281 tree p = (tree)obstack_alloc (&type_obstack_entries, sizeof (struct tree_string));
282 ++my_tree_node_counter;
283 TREE_TYPE (p) = 0;
284 ((int *)p)[3] = 0;
285 TREE_SET_CODE (p, STRING_CST);
286 TREE_STRING_POINTER (p) = str;
287 TREE_STRING_LENGTH (p) = strlen (str);
288 return p;
289 }
290 \f
291 /* Memoizing machinery to make searches for multiple inheritance
292 reasonably efficient. */
293
294 #define MEMOIZE_HASHSIZE 8
295 typedef struct memoized_entry
296 {
297 struct memoized_entry *chain;
298 int uid;
299 tree data_members[MEMOIZE_HASHSIZE];
300 tree function_members[MEMOIZE_HASHSIZE];
301 } *ME;
302
303 #define MEMOIZED_CHAIN(ENTRY) (((ME)ENTRY)->chain)
304 #define MEMOIZED_UID(ENTRY) (((ME)ENTRY)->uid)
305 #define MEMOIZED_FIELDS(ENTRY,INDEX) (((ME)ENTRY)->data_members[INDEX])
306 #define MEMOIZED_FNFIELDS(ENTRY,INDEX) (((ME)ENTRY)->function_members[INDEX])
307 /* The following is probably a lousy hash function. */
308 #define MEMOIZED_HASH_FN(NODE) (((long)(NODE)>>4)&(MEMOIZE_HASHSIZE - 1))
309
310 static struct memoized_entry *
311 my_new_memoized_entry (chain)
312 struct memoized_entry *chain;
313 {
314 struct memoized_entry *p
315 = (struct memoized_entry *)obstack_alloc (&type_obstack_entries,
316 sizeof (struct memoized_entry));
317 bzero ((char *) p, sizeof (struct memoized_entry));
318 MEMOIZED_CHAIN (p) = chain;
319 MEMOIZED_UID (p) = ++my_memoized_entry_counter;
320 return p;
321 }
322
323 /* Clears the deferred pop from pop_memoized_context, if any. */
324
325 static void
326 clear_memoized_cache ()
327 {
328 if (prev_type_stack)
329 {
330 type_stack = pop_type_level (prev_type_stack);
331 prev_type_memoized = 0;
332 prev_type_stack = 0;
333 }
334 }
335
336 /* Make an entry in the memoized table for type TYPE
337 that the entry for NAME is FIELD. */
338
339 static tree
340 make_memoized_table_entry (type, name, function_p)
341 tree type, name;
342 int function_p;
343 {
344 int idx = MEMOIZED_HASH_FN (name);
345 tree entry, *prev_entry;
346
347 /* Since we allocate from the type_obstack, we must pop any deferred
348 levels. */
349 clear_memoized_cache ();
350
351 memoized_adds[function_p] += 1;
352 if (CLASSTYPE_MTABLE_ENTRY (type) == 0)
353 {
354 obstack_ptr_grow (&type_obstack, type);
355 obstack_blank (&type_obstack, sizeof (struct memoized_entry *));
356 CLASSTYPE_MTABLE_ENTRY (type) = (char *)my_new_memoized_entry ((struct memoized_entry *)0);
357 type_stack->len++;
358 if (type_stack->len * 2 >= type_stack->base.limit)
359 my_friendly_abort (88);
360 }
361 if (function_p)
362 prev_entry = &MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type), idx);
363 else
364 prev_entry = &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type), idx);
365
366 entry = my_tree_cons (name, NULL_TREE, *prev_entry);
367 *prev_entry = entry;
368
369 /* Don't know the error message to give yet. */
370 TREE_TYPE (entry) = error_mark_node;
371
372 return entry;
373 }
374
375 /* When a new function or class context is entered, we build
376 a table of types which have been searched for members.
377 The table is an array (obstack) of types. When a type is
378 entered into the obstack, its CLASSTYPE_MTABLE_ENTRY
379 field is set to point to a new record, of type struct memoized_entry.
380
381 A non-NULL TREE_TYPE of the entry contains an access control error message.
382
383 The slots for the data members are arrays of tree nodes.
384 These tree nodes are lists, with the TREE_PURPOSE
385 of this list the known member name, and the TREE_VALUE
386 as the FIELD_DECL for the member.
387
388 For member functions, the TREE_PURPOSE is again the
389 name of the member functions for that class,
390 and the TREE_VALUE of the list is a pairs
391 whose TREE_PURPOSE is a member functions of this name,
392 and whose TREE_VALUE is a list of known argument lists this
393 member function has been called with. The TREE_TYPE of the pair,
394 if non-NULL, is an error message to print. */
395
396 /* Tell search machinery that we are entering a new context, and
397 to update tables appropriately.
398
399 TYPE is the type of the context we are entering, which can
400 be NULL_TREE if we are not in a class's scope.
401
402 USE_OLD, if nonzero tries to use previous context. */
403
404 void
405 push_memoized_context (type, use_old)
406 tree type;
407 int use_old;
408 {
409 int len;
410 tree *tem;
411
412 if (prev_type_stack)
413 {
414 if (use_old && prev_type_memoized == type)
415 {
416 #ifdef GATHER_STATISTICS
417 n_contexts_saved++;
418 #endif /* GATHER_STATISTICS */
419 type_stack = prev_type_stack;
420 prev_type_stack = 0;
421
422 tem = &type_stack->base.first[0];
423 len = type_stack->len;
424 while (len--)
425 CLASSTYPE_MTABLE_ENTRY (tem[len*2]) = (char *)tem[len*2+1];
426 return;
427 }
428 /* Otherwise, need to pop old stack here. */
429 clear_memoized_cache ();
430 }
431
432 type_stack = push_type_level ((struct stack_level *)type_stack,
433 &type_obstack);
434 type_stack->type = type;
435 }
436
437 /* Tell search machinery that we have left a context.
438 We do not currently save these contexts for later use.
439 If we wanted to, we could not use pop_search_level, since
440 poping that level allows the data we have collected to
441 be clobbered; a stack of obstacks would be needed. */
442
443 void
444 pop_memoized_context (use_old)
445 int use_old;
446 {
447 int len;
448 tree *tem = &type_stack->base.first[0];
449
450 if (! flag_save_memoized_contexts)
451 use_old = 0;
452 else if (use_old)
453 {
454 len = type_stack->len;
455 while (len--)
456 tem[len*2+1] = (tree)CLASSTYPE_MTABLE_ENTRY (tem[len*2]);
457
458 /* If there was a deferred pop, we need to pop it now. */
459 clear_memoized_cache ();
460
461 prev_type_stack = type_stack;
462 prev_type_memoized = type_stack->type;
463 }
464
465 if (flag_memoize_lookups)
466 {
467 len = type_stack->len;
468 while (len--)
469 CLASSTYPE_MTABLE_ENTRY (tem[len*2])
470 = (char *)MEMOIZED_CHAIN (CLASSTYPE_MTABLE_ENTRY (tem[len*2]));
471 }
472 if (! use_old)
473 type_stack = pop_type_level (type_stack);
474 else
475 type_stack = (struct type_level *)type_stack->base.prev;
476 }
477 \f
478 /* Get a virtual binfo that is found inside BINFO's hierarchy that is
479 the same type as the type given in PARENT. To be optimal, we want
480 the first one that is found by going through the least number of
481 virtual bases. */
482
483 static tree
484 get_vbase_1 (parent, binfo, depth)
485 tree parent, binfo;
486 unsigned int *depth;
487 {
488 tree binfos;
489 int i, n_baselinks;
490 tree rval = NULL_TREE;
491
492 if (BINFO_TYPE (binfo) == parent && TREE_VIA_VIRTUAL (binfo))
493 {
494 *depth = 0;
495 return binfo;
496 }
497
498 *depth = *depth - 1;
499
500 binfos = BINFO_BASETYPES (binfo);
501 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
502
503 /* Process base types. */
504 for (i = 0; i < n_baselinks; i++)
505 {
506 tree base_binfo = TREE_VEC_ELT (binfos, i);
507 tree nrval;
508
509 if (*depth == 0)
510 break;
511
512 nrval = get_vbase_1 (parent, base_binfo, depth);
513 if (nrval)
514 rval = nrval;
515 }
516 *depth = *depth+1;
517 return rval;
518 }
519
520 tree
521 get_vbase (parent, binfo)
522 tree parent;
523 tree binfo;
524 {
525 unsigned int d = (unsigned int)-1;
526 return get_vbase_1 (parent, binfo, &d);
527 }
528
529 /* Convert EXPR to a virtual base class of type TYPE. We know that
530 EXPR is a non-null POINTER_TYPE to RECORD_TYPE. We also know that
531 the type of what expr points to has a virtual base of type TYPE. */
532
533 static tree
534 convert_pointer_to_vbase (type, expr)
535 tree type;
536 tree expr;
537 {
538 tree vb = get_vbase (type, TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr))));
539 return convert_pointer_to_real (vb, expr);
540 }
541
542 /* Check whether the type given in BINFO is derived from PARENT. If
543 it isn't, return 0. If it is, but the derivation is MI-ambiguous
544 AND protect != 0, emit an error message and return error_mark_node.
545
546 Otherwise, if TYPE is derived from PARENT, return the actual base
547 information, unless a one of the protection violations below
548 occurs, in which case emit an error message and return error_mark_node.
549
550 If PROTECT is 1, then check if access to a public field of PARENT
551 would be private. Also check for ambiguity. */
552
553 tree
554 get_binfo (parent, binfo, protect)
555 register tree parent, binfo;
556 int protect;
557 {
558 tree type = NULL_TREE;
559 int dist;
560 tree rval = NULL_TREE;
561
562 if (TREE_CODE (parent) == TREE_VEC)
563 parent = BINFO_TYPE (parent);
564 else if (! IS_AGGR_TYPE_CODE (TREE_CODE (parent)))
565 my_friendly_abort (89);
566
567 if (TREE_CODE (binfo) == TREE_VEC)
568 type = BINFO_TYPE (binfo);
569 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo)))
570 type = binfo;
571 else
572 my_friendly_abort (90);
573
574 dist = get_base_distance (parent, binfo, protect, &rval);
575
576 if (dist == -3)
577 {
578 cp_error ("fields of `%T' are inaccessible in `%T' due to private inheritance",
579 parent, type);
580 return error_mark_node;
581 }
582 else if (dist == -2 && protect)
583 {
584 cp_error ("type `%T' is ambiguous base class for type `%T'", parent,
585 type);
586 return error_mark_node;
587 }
588
589 return rval;
590 }
591
592 /* This is the newer depth first get_base_distance routine. */
593
594 static int
595 get_base_distance_recursive (binfo, depth, is_private, rval,
596 rval_private_ptr, new_binfo_ptr, parent, path_ptr,
597 protect, via_virtual_ptr, via_virtual,
598 current_scope_in_chain)
599 tree binfo;
600 int depth, is_private, rval;
601 int *rval_private_ptr;
602 tree *new_binfo_ptr, parent, *path_ptr;
603 int protect, *via_virtual_ptr, via_virtual;
604 int current_scope_in_chain;
605 {
606 tree binfos;
607 int i, n_baselinks;
608
609 if (protect
610 && !current_scope_in_chain
611 && is_friend (BINFO_TYPE (binfo), current_scope ()))
612 current_scope_in_chain = 1;
613
614 if (BINFO_TYPE (binfo) == parent || binfo == parent)
615 {
616 if (rval == -1)
617 {
618 rval = depth;
619 *rval_private_ptr = is_private;
620 *new_binfo_ptr = binfo;
621 *via_virtual_ptr = via_virtual;
622 }
623 else
624 {
625 int same_object = (tree_int_cst_equal (BINFO_OFFSET (*new_binfo_ptr),
626 BINFO_OFFSET (binfo))
627 && *via_virtual_ptr && via_virtual);
628
629 if (*via_virtual_ptr && via_virtual==0)
630 {
631 *rval_private_ptr = is_private;
632 *new_binfo_ptr = binfo;
633 *via_virtual_ptr = via_virtual;
634 }
635 else if (same_object)
636 {
637 if (*rval_private_ptr && ! is_private)
638 {
639 *rval_private_ptr = is_private;
640 *new_binfo_ptr = binfo;
641 *via_virtual_ptr = via_virtual;
642 }
643 return rval;
644 }
645
646 rval = -2;
647 }
648 return rval;
649 }
650
651 binfos = BINFO_BASETYPES (binfo);
652 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
653 depth += 1;
654
655 /* Process base types. */
656 for (i = 0; i < n_baselinks; i++)
657 {
658 tree base_binfo = TREE_VEC_ELT (binfos, i);
659
660 /* Find any specific instance of a virtual base, when searching with
661 a binfo... */
662 if (BINFO_MARKED (base_binfo) == 0 || TREE_CODE (parent) == TREE_VEC)
663 {
664 int via_private
665 = (protect
666 && (is_private
667 || (!TREE_VIA_PUBLIC (base_binfo)
668 && !(TREE_VIA_PROTECTED (base_binfo)
669 && current_scope_in_chain)
670 && !is_friend (BINFO_TYPE (binfo), current_scope ()))));
671 int this_virtual = via_virtual || TREE_VIA_VIRTUAL (base_binfo);
672 int was;
673
674 /* When searching for a non-virtual, we cannot mark
675 virtually found binfos. */
676 if (! this_virtual)
677 SET_BINFO_MARKED (base_binfo);
678
679 #define WATCH_VALUES(rval, via_private) (rval == -1 ? 3 : via_private)
680
681 was = WATCH_VALUES (rval, *via_virtual_ptr);
682 rval = get_base_distance_recursive (base_binfo, depth, via_private,
683 rval, rval_private_ptr,
684 new_binfo_ptr, parent, path_ptr,
685 protect, via_virtual_ptr,
686 this_virtual,
687 current_scope_in_chain);
688 /* watch for updates; only update if path is good. */
689 if (path_ptr && WATCH_VALUES (rval, *via_virtual_ptr) != was)
690 BINFO_INHERITANCE_CHAIN (base_binfo) = binfo;
691 if (rval == -2 && *via_virtual_ptr == 0)
692 return rval;
693
694 #undef WATCH_VALUES
695
696 }
697 }
698
699 return rval;
700 }
701
702 /* Return the number of levels between type PARENT and the type given
703 in BINFO, following the leftmost path to PARENT not found along a
704 virtual path, if there are no real PARENTs (all come from virtual
705 base classes), then follow the leftmost path to PARENT.
706
707 Return -1 if TYPE is not derived from PARENT.
708 Return -2 if PARENT is an ambiguous base class of TYPE, and PROTECT is
709 non-negative.
710 Return -3 if PARENT is private to TYPE, and PROTECT is non-zero.
711
712 If PATH_PTR is non-NULL, then also build the list of types
713 from PARENT to TYPE, with TREE_VIA_VIRTUAL and TREE_VIA_PUBLIC
714 set.
715
716 PARENT can also be a binfo, in which case that exact parent is found
717 and no other. convert_pointer_to_real uses this functionality.
718
719 If BINFO is a binfo, its BINFO_INHERITANCE_CHAIN will be left alone. */
720
721 int
722 get_base_distance (parent, binfo, protect, path_ptr)
723 register tree parent, binfo;
724 int protect;
725 tree *path_ptr;
726 {
727 int rval;
728 int rval_private = 0;
729 tree type = NULL_TREE;
730 tree new_binfo = NULL_TREE;
731 int via_virtual;
732 int watch_access = protect;
733
734 /* Should we be completing types here? */
735 if (TREE_CODE (parent) != TREE_VEC)
736 parent = complete_type (TYPE_MAIN_VARIANT (parent));
737 else
738 complete_type (TREE_TYPE (parent));
739
740 if (TREE_CODE (binfo) == TREE_VEC)
741 type = BINFO_TYPE (binfo);
742 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo)))
743 {
744 type = complete_type (binfo);
745 binfo = TYPE_BINFO (type);
746
747 if (path_ptr)
748 BINFO_INHERITANCE_CHAIN (binfo) = NULL_TREE;
749 }
750 else
751 my_friendly_abort (92);
752
753 if (parent == type || parent == binfo)
754 {
755 /* If the distance is 0, then we don't really need
756 a path pointer, but we shouldn't let garbage go back. */
757 if (path_ptr)
758 *path_ptr = binfo;
759 return 0;
760 }
761
762 if (path_ptr)
763 watch_access = 1;
764
765 rval = get_base_distance_recursive (binfo, 0, 0, -1,
766 &rval_private, &new_binfo, parent,
767 path_ptr, watch_access, &via_virtual, 0,
768 0);
769
770 dfs_walk (binfo, dfs_unmark, markedp);
771
772 /* Access restrictions don't count if we found an ambiguous basetype. */
773 if (rval == -2 && protect >= 0)
774 rval_private = 0;
775
776 if (rval && protect && rval_private)
777 return -3;
778
779 /* find real virtual base classes. */
780 if (rval == -1 && TREE_CODE (parent) == TREE_VEC
781 && parent == binfo_member (BINFO_TYPE (parent),
782 CLASSTYPE_VBASECLASSES (type)))
783 {
784 BINFO_INHERITANCE_CHAIN (parent) = binfo;
785 new_binfo = parent;
786 rval = 1;
787 }
788
789 if (path_ptr)
790 *path_ptr = new_binfo;
791 return rval;
792 }
793
794 /* Search for a member with name NAME in a multiple inheritance lattice
795 specified by TYPE. If it does not exist, return NULL_TREE.
796 If the member is ambiguously referenced, return `error_mark_node'.
797 Otherwise, return the FIELD_DECL. */
798
799 /* Do a 1-level search for NAME as a member of TYPE. The caller must
800 figure out whether it can access this field. (Since it is only one
801 level, this is reasonable.) */
802
803 static tree
804 lookup_field_1 (type, name)
805 tree type, name;
806 {
807 register tree field;
808
809 if (TREE_CODE (type) == TEMPLATE_TYPE_PARM
810 || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
811 /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;
812 instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX. (Miraculously,
813 the code often worked even when we treated the index as a list
814 of fields!) */
815 return NULL_TREE;
816
817 field = TYPE_FIELDS (type);
818
819 #ifdef GATHER_STATISTICS
820 n_calls_lookup_field_1++;
821 #endif /* GATHER_STATISTICS */
822 while (field)
823 {
824 #ifdef GATHER_STATISTICS
825 n_fields_searched++;
826 #endif /* GATHER_STATISTICS */
827 my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field)) == 'd', 0);
828 if (DECL_NAME (field) == NULL_TREE
829 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
830 {
831 tree temp = lookup_field_1 (TREE_TYPE (field), name);
832 if (temp)
833 return temp;
834 }
835 if (DECL_NAME (field) == name)
836 {
837 if ((TREE_CODE(field) == VAR_DECL || TREE_CODE(field) == CONST_DECL)
838 && DECL_ASSEMBLER_NAME (field) != NULL)
839 GNU_xref_ref(current_function_decl,
840 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field)));
841 return field;
842 }
843 field = TREE_CHAIN (field);
844 }
845 /* Not found. */
846 if (name == _vptr_name)
847 {
848 /* Give the user what s/he thinks s/he wants. */
849 if (TYPE_VIRTUAL_P (type))
850 return CLASSTYPE_VFIELD (type);
851 }
852 return NULL_TREE;
853 }
854
855 /* There are a number of cases we need to be aware of here:
856 current_class_type current_function_decl
857 global NULL NULL
858 fn-local NULL SET
859 class-local SET NULL
860 class->fn SET SET
861 fn->class SET SET
862
863 Those last two make life interesting. If we're in a function which is
864 itself inside a class, we need decls to go into the fn's decls (our
865 second case below). But if we're in a class and the class itself is
866 inside a function, we need decls to go into the decls for the class. To
867 achieve this last goal, we must see if, when both current_class_ptr and
868 current_function_decl are set, the class was declared inside that
869 function. If so, we know to put the decls into the class's scope. */
870
871 tree
872 current_scope ()
873 {
874 if (current_function_decl == NULL_TREE)
875 return current_class_type;
876 if (current_class_type == NULL_TREE)
877 return current_function_decl;
878 if (DECL_CLASS_CONTEXT (current_function_decl) == current_class_type)
879 return current_function_decl;
880
881 return current_class_type;
882 }
883
884 /* Compute the access of FIELD. This is done by computing
885 the access available to each type in BASETYPES (which comes
886 as a list of [via_public/basetype] in reverse order, namely base
887 class before derived class). The first one which defines a
888 access defines the access for the field. Otherwise, the
889 access of the field is that which occurs normally.
890
891 Uses global variables CURRENT_CLASS_TYPE and
892 CURRENT_FUNCTION_DECL to use friend relationships
893 if necessary.
894
895 This will be static when lookup_fnfield comes into this file.
896
897 access_public_node means that the field can be accessed by the current lexical
898 scope.
899
900 access_protected_node means that the field cannot be accessed by the current
901 lexical scope because it is protected.
902
903 access_private_node means that the field cannot be accessed by the current
904 lexical scope because it is private. */
905
906 #if 0
907 #define PUBLIC_RETURN return (DECL_PUBLIC (field) = 1), access_public_node
908 #define PROTECTED_RETURN return (DECL_PROTECTED (field) = 1), access_protected_node
909 #define PRIVATE_RETURN return (DECL_PRIVATE (field) = 1), access_private_node
910 #else
911 #define PUBLIC_RETURN return access_public_node
912 #define PROTECTED_RETURN return access_protected_node
913 #define PRIVATE_RETURN return access_private_node
914 #endif
915
916 #if 0
917 /* Disabled with DECL_PUBLIC &c. */
918 static tree previous_scope = NULL_TREE;
919 #endif
920
921 tree
922 compute_access (basetype_path, field)
923 tree basetype_path, field;
924 {
925 tree access;
926 tree types;
927 tree context;
928 int protected_ok, via_protected;
929 extern int flag_access_control;
930 #if 1
931 /* Replaces static decl above. */
932 tree previous_scope;
933 #endif
934 int static_mem
935 = ((TREE_CODE (field) == FUNCTION_DECL && DECL_STATIC_FUNCTION_P (field))
936 || (TREE_CODE (field) != FUNCTION_DECL && TREE_STATIC (field)));
937
938 if (! flag_access_control)
939 return access_public_node;
940
941 /* The field lives in the current class. */
942 if (BINFO_TYPE (basetype_path) == current_class_type)
943 return access_public_node;
944
945 #if 0
946 /* Disabled until pushing function scope clears these out. If ever. */
947 /* Make these special cases fast. */
948 if (current_scope () == previous_scope)
949 {
950 if (DECL_PUBLIC (field))
951 return access_public_node;
952 if (DECL_PROTECTED (field))
953 return access_protected_node;
954 if (DECL_PRIVATE (field))
955 return access_private_node;
956 }
957 #endif
958
959 /* We don't currently support access control on nested types. */
960 if (TREE_CODE (field) == TYPE_DECL)
961 return access_public_node;
962
963 previous_scope = current_scope ();
964
965 context = DECL_CLASS_CONTEXT (field);
966 if (context == NULL_TREE)
967 context = DECL_CONTEXT (field);
968
969 /* Fields coming from nested anonymous unions have their DECL_CLASS_CONTEXT
970 slot set to the union type rather than the record type containing
971 the anonymous union. */
972 if (context && TREE_CODE (context) == UNION_TYPE
973 && ANON_AGGRNAME_P (TYPE_IDENTIFIER (context)))
974 context = TYPE_CONTEXT (context);
975
976 /* Virtual function tables are never private. But we should know that
977 we are looking for this, and not even try to hide it. */
978 if (DECL_NAME (field) && VFIELD_NAME_P (DECL_NAME (field)) == 1)
979 PUBLIC_RETURN;
980
981 /* Member found immediately within object. */
982 if (BINFO_INHERITANCE_CHAIN (basetype_path) == NULL_TREE)
983 {
984 /* Are we (or an enclosing scope) friends with the class that has
985 FIELD? */
986 if (is_friend (context, previous_scope))
987 PUBLIC_RETURN;
988
989 /* If it's private, it's private, you letch. */
990 if (TREE_PRIVATE (field))
991 PRIVATE_RETURN;
992
993 /* ARM $11.5. Member functions of a derived class can access the
994 non-static protected members of a base class only through a
995 pointer to the derived class, a reference to it, or an object
996 of it. Also any subsequently derived classes also have
997 access. */
998 else if (TREE_PROTECTED (field))
999 {
1000 if (current_class_type
1001 && (static_mem || DECL_CONSTRUCTOR_P (field))
1002 && ACCESSIBLY_DERIVED_FROM_P (context, current_class_type))
1003 PUBLIC_RETURN;
1004 else
1005 PROTECTED_RETURN;
1006 }
1007 else
1008 PUBLIC_RETURN;
1009 }
1010
1011 /* must reverse more than one element */
1012 basetype_path = reverse_path (basetype_path);
1013 types = basetype_path;
1014 via_protected = 0;
1015 access = access_default_node;
1016 protected_ok = static_mem && current_class_type
1017 && ACCESSIBLY_DERIVED_FROM_P (BINFO_TYPE (types), current_class_type);
1018
1019 while (1)
1020 {
1021 tree member;
1022 tree binfo = types;
1023 tree type = BINFO_TYPE (binfo);
1024 int private_ok = 0;
1025
1026 /* Friends of a class can see protected members of its bases.
1027 Note that classes are their own friends. */
1028 if (is_friend (type, previous_scope))
1029 {
1030 protected_ok = 1;
1031 private_ok = 1;
1032 }
1033
1034 member = purpose_member (type, DECL_ACCESS (field));
1035 if (member)
1036 {
1037 access = TREE_VALUE (member);
1038 break;
1039 }
1040
1041 types = BINFO_INHERITANCE_CHAIN (types);
1042
1043 /* If the next type was VIA_PROTECTED, then fields of all remaining
1044 classes past that one are *at least* protected. */
1045 if (types)
1046 {
1047 if (TREE_VIA_PROTECTED (types))
1048 via_protected = 1;
1049 else if (! TREE_VIA_PUBLIC (types) && ! private_ok)
1050 {
1051 access = access_private_node;
1052 break;
1053 }
1054 }
1055 else
1056 break;
1057 }
1058 reverse_path (basetype_path);
1059
1060 /* No special visibilities apply. Use normal rules. */
1061
1062 if (access == access_default_node)
1063 {
1064 if (is_friend (context, previous_scope))
1065 access = access_public_node;
1066 else if (TREE_PRIVATE (field))
1067 access = access_private_node;
1068 else if (TREE_PROTECTED (field))
1069 access = access_protected_node;
1070 else
1071 access = access_public_node;
1072 }
1073
1074 if (access == access_public_node && via_protected)
1075 access = access_protected_node;
1076
1077 if (access == access_protected_node && protected_ok)
1078 access = access_public_node;
1079
1080 #if 0
1081 if (access == access_public_node)
1082 DECL_PUBLIC (field) = 1;
1083 else if (access == access_protected_node)
1084 DECL_PROTECTED (field) = 1;
1085 else if (access == access_private_node)
1086 DECL_PRIVATE (field) = 1;
1087 else my_friendly_abort (96);
1088 #endif
1089 return access;
1090 }
1091
1092 /* Routine to see if the sub-object denoted by the binfo PARENT can be
1093 found as a base class and sub-object of the object denoted by
1094 BINFO. This routine relies upon binfos not being shared, except
1095 for binfos for virtual bases. */
1096
1097 static int
1098 is_subobject_of_p (parent, binfo)
1099 tree parent, binfo;
1100 {
1101 tree binfos = BINFO_BASETYPES (binfo);
1102 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1103
1104 if (parent == binfo)
1105 return 1;
1106
1107 /* Process and/or queue base types. */
1108 for (i = 0; i < n_baselinks; i++)
1109 {
1110 tree base_binfo = TREE_VEC_ELT (binfos, i);
1111 if (TREE_VIA_VIRTUAL (base_binfo))
1112 base_binfo = TYPE_BINFO (BINFO_TYPE (base_binfo));
1113 if (is_subobject_of_p (parent, base_binfo))
1114 return 1;
1115 }
1116 return 0;
1117 }
1118
1119 /* See if a one FIELD_DECL hides another. This routine is meant to
1120 correspond to ANSI working paper Sept 17, 1992 10p4. The two
1121 binfos given are the binfos corresponding to the particular places
1122 the FIELD_DECLs are found. This routine relies upon binfos not
1123 being shared, except for virtual bases. */
1124
1125 static int
1126 hides (hider_binfo, hidee_binfo)
1127 tree hider_binfo, hidee_binfo;
1128 {
1129 /* hider hides hidee, if hider has hidee as a base class and
1130 the instance of hidee is a sub-object of hider. The first
1131 part is always true is the second part is true.
1132
1133 When hider and hidee are the same (two ways to get to the exact
1134 same member) we consider either one as hiding the other. */
1135 return is_subobject_of_p (hidee_binfo, hider_binfo);
1136 }
1137
1138 /* Very similar to lookup_fnfields_1 but it ensures that at least one
1139 function was declared inside the class given by TYPE. It really should
1140 only return functions that match the given TYPE. */
1141
1142 static int
1143 lookup_fnfields_here (type, name)
1144 tree type, name;
1145 {
1146 int idx = lookup_fnfields_1 (type, name);
1147 tree fndecls;
1148
1149 /* ctors and dtors are always only in the right class. */
1150 if (idx <= 1)
1151 return idx;
1152 fndecls = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1153 while (fndecls)
1154 {
1155 if (TYPE_MAIN_VARIANT (DECL_CLASS_CONTEXT (fndecls))
1156 == TYPE_MAIN_VARIANT (type))
1157 return idx;
1158 fndecls = TREE_CHAIN (fndecls);
1159 }
1160 return -1;
1161 }
1162
1163 /* Look for a field named NAME in an inheritance lattice dominated by
1164 XBASETYPE. PROTECT is zero if we can avoid computing access
1165 information, otherwise it is 1. WANT_TYPE is 1 when we should only
1166 return TYPE_DECLs, if no TYPE_DECL can be found return NULL_TREE.
1167
1168 It was not clear what should happen if WANT_TYPE is set, and an
1169 ambiguity is found. At least one use (lookup_name) to not see
1170 the error. */
1171
1172 tree
1173 lookup_field (xbasetype, name, protect, want_type)
1174 register tree xbasetype, name;
1175 int protect, want_type;
1176 {
1177 int head = 0, tail = 0;
1178 tree rval, rval_binfo = NULL_TREE, rval_binfo_h = NULL_TREE;
1179 tree type = NULL_TREE, basetype_chain, basetype_path = NULL_TREE;
1180 tree this_v = access_default_node;
1181 tree entry, binfo, binfo_h;
1182 tree own_access = access_default_node;
1183 int vbase_name_p = VBASE_NAME_P (name);
1184
1185 /* rval_binfo is the binfo associated with the found member, note,
1186 this can be set with useful information, even when rval is not
1187 set, because it must deal with ALL members, not just non-function
1188 members. It is used for ambiguity checking and the hidden
1189 checks. Whereas rval is only set if a proper (not hidden)
1190 non-function member is found. */
1191
1192 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1193 hiding checks, as virtual base classes may not be shared. The strategy
1194 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1195 virtual base classes, as we cross virtual base class lines. This way
1196 we know that binfo of a virtual base class will always == itself when
1197 found along any line. (mrs) */
1198
1199 char *errstr = 0;
1200
1201 /* Set this to nonzero if we don't know how to compute
1202 accurate error messages for access control. */
1203 int idx = MEMOIZED_HASH_FN (name);
1204
1205 #if 0
1206 /* We cannot search for constructor/destructor names like this. */
1207 /* This can't go here, but where should it go? */
1208 /* If we are looking for a constructor in a templated type, use the
1209 unspecialized name, as that is how we store it. */
1210 if (IDENTIFIER_TEMPLATE (name))
1211 name = constructor_name (name);
1212 #endif
1213
1214 if (xbasetype == current_class_type && TYPE_BEING_DEFINED (xbasetype)
1215 && IDENTIFIER_CLASS_VALUE (name))
1216 {
1217 tree field = IDENTIFIER_CLASS_VALUE (name);
1218 if (TREE_CODE (field) != FUNCTION_DECL
1219 && ! (want_type && TREE_CODE (field) != TYPE_DECL))
1220 return field;
1221 }
1222
1223 if (TREE_CODE (xbasetype) == TREE_VEC)
1224 {
1225 type = BINFO_TYPE (xbasetype);
1226 basetype_path = xbasetype;
1227 }
1228 else if (IS_AGGR_TYPE_CODE (TREE_CODE (xbasetype)))
1229 {
1230 type = xbasetype;
1231 basetype_path = TYPE_BINFO (type);
1232 BINFO_VIA_PUBLIC (basetype_path) = 1;
1233 BINFO_INHERITANCE_CHAIN (basetype_path) = NULL_TREE;
1234 }
1235 else
1236 my_friendly_abort (97);
1237
1238 complete_type (type);
1239
1240 if (CLASSTYPE_MTABLE_ENTRY (type))
1241 {
1242 tree tem = MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type), idx);
1243
1244 while (tem && TREE_PURPOSE (tem) != name)
1245 {
1246 memoized_fields_searched[0]++;
1247 tem = TREE_CHAIN (tem);
1248 }
1249 if (tem)
1250 {
1251 if (protect && TREE_TYPE (tem))
1252 {
1253 error (TREE_STRING_POINTER (TREE_TYPE (tem)),
1254 IDENTIFIER_POINTER (name),
1255 TYPE_NAME_STRING (DECL_FIELD_CONTEXT (TREE_VALUE (tem))));
1256 return error_mark_node;
1257 }
1258 if (TREE_VALUE (tem) == NULL_TREE)
1259 memoized_fast_rejects[0] += 1;
1260 else
1261 memoized_fast_finds[0] += 1;
1262 return TREE_VALUE (tem);
1263 }
1264 }
1265
1266 #ifdef GATHER_STATISTICS
1267 n_calls_lookup_field++;
1268 #endif /* GATHER_STATISTICS */
1269 if (protect && flag_memoize_lookups && ! global_bindings_p ())
1270 entry = make_memoized_table_entry (type, name, 0);
1271 else
1272 entry = 0;
1273
1274 rval = lookup_field_1 (type, name);
1275
1276 if (rval || lookup_fnfields_here (type, name) >= 0)
1277 {
1278 if (entry)
1279 TREE_VALUE (entry) = rval;
1280
1281 if (rval)
1282 {
1283 if (want_type)
1284 {
1285 if (TREE_CODE (rval) != TYPE_DECL)
1286 {
1287 rval = purpose_member (name, CLASSTYPE_TAGS (type));
1288 if (rval)
1289 rval = TYPE_MAIN_DECL (TREE_VALUE (rval));
1290 }
1291 }
1292 else
1293 {
1294 if (TREE_CODE (rval) == TYPE_DECL
1295 && lookup_fnfields_here (type, name) >= 0)
1296 rval = NULL_TREE;
1297 }
1298 }
1299
1300 if (protect && rval)
1301 {
1302 if (TREE_PRIVATE (rval) | TREE_PROTECTED (rval))
1303 this_v = compute_access (basetype_path, rval);
1304 if (TREE_CODE (rval) == CONST_DECL)
1305 {
1306 if (this_v == access_private_node)
1307 errstr = "enum `%D' is a private value of class `%T'";
1308 else if (this_v == access_protected_node)
1309 errstr = "enum `%D' is a protected value of class `%T'";
1310 }
1311 else
1312 {
1313 if (this_v == access_private_node)
1314 errstr = "member `%D' is a private member of class `%T'";
1315 else if (this_v == access_protected_node)
1316 errstr = "member `%D' is a protected member of class `%T'";
1317 }
1318 }
1319
1320 rval_binfo = basetype_path;
1321 goto out;
1322 }
1323
1324 basetype_chain = build_expr_list (NULL_TREE, basetype_path);
1325 TREE_VIA_PUBLIC (basetype_chain) = TREE_VIA_PUBLIC (basetype_path);
1326 TREE_VIA_PROTECTED (basetype_chain) = TREE_VIA_PROTECTED (basetype_path);
1327 TREE_VIA_VIRTUAL (basetype_chain) = TREE_VIA_VIRTUAL (basetype_path);
1328
1329 /* The ambiguity check relies upon breadth first searching. */
1330
1331 search_stack = push_search_level (search_stack, &search_obstack);
1332 binfo = basetype_path;
1333 binfo_h = binfo;
1334
1335 while (1)
1336 {
1337 tree binfos = BINFO_BASETYPES (binfo);
1338 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1339 tree nval;
1340
1341 /* Process and/or queue base types. */
1342 for (i = 0; i < n_baselinks; i++)
1343 {
1344 tree base_binfo = TREE_VEC_ELT (binfos, i);
1345 if (BINFO_FIELDS_MARKED (base_binfo) == 0)
1346 {
1347 tree btypes;
1348
1349 SET_BINFO_FIELDS_MARKED (base_binfo);
1350 btypes = my_tree_cons (NULL_TREE, base_binfo, basetype_chain);
1351 TREE_VIA_PUBLIC (btypes) = TREE_VIA_PUBLIC (base_binfo);
1352 TREE_VIA_PROTECTED (btypes) = TREE_VIA_PROTECTED (base_binfo);
1353 TREE_VIA_VIRTUAL (btypes) = TREE_VIA_VIRTUAL (base_binfo);
1354 if (TREE_VIA_VIRTUAL (base_binfo))
1355 btypes = my_tree_cons (NULL_TREE,
1356 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i))),
1357 btypes);
1358 else
1359 btypes = my_tree_cons (NULL_TREE,
1360 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i),
1361 btypes);
1362 obstack_ptr_grow (&search_obstack, btypes);
1363 tail += 1;
1364 if (tail >= search_stack->limit)
1365 my_friendly_abort (98);
1366 }
1367 }
1368
1369 /* Process head of queue, if one exists. */
1370 if (head >= tail)
1371 break;
1372
1373 basetype_chain = search_stack->first[head++];
1374 binfo_h = TREE_VALUE (basetype_chain);
1375 basetype_chain = TREE_CHAIN (basetype_chain);
1376 basetype_path = TREE_VALUE (basetype_chain);
1377 if (TREE_CHAIN (basetype_chain))
1378 BINFO_INHERITANCE_CHAIN (basetype_path) = TREE_VALUE (TREE_CHAIN (basetype_chain));
1379 else
1380 BINFO_INHERITANCE_CHAIN (basetype_path) = NULL_TREE;
1381
1382 binfo = basetype_path;
1383 type = BINFO_TYPE (binfo);
1384
1385 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1386 and we do find NAME in TYPE, verify that such a second
1387 sighting is in fact valid. */
1388
1389 nval = lookup_field_1 (type, name);
1390
1391 if (nval || lookup_fnfields_here (type, name)>=0)
1392 {
1393 if (nval && nval == rval && SHARED_MEMBER_P (nval))
1394 {
1395 /* This is ok, the member found is the same [class.ambig] */
1396 }
1397 else if (rval_binfo && hides (rval_binfo_h, binfo_h))
1398 {
1399 /* This is ok, the member found is in rval_binfo, not
1400 here (binfo). */
1401 }
1402 else if (rval_binfo==NULL_TREE || hides (binfo_h, rval_binfo_h))
1403 {
1404 /* This is ok, the member found is here (binfo), not in
1405 rval_binfo. */
1406 if (nval)
1407 {
1408 rval = nval;
1409 if (entry || protect)
1410 this_v = compute_access (basetype_path, rval);
1411 /* These may look ambiguous, but they really are not. */
1412 if (vbase_name_p)
1413 break;
1414 }
1415 else
1416 {
1417 /* Undo finding it before, as something else hides it. */
1418 rval = NULL_TREE;
1419 }
1420 rval_binfo = binfo;
1421 rval_binfo_h = binfo_h;
1422 }
1423 else
1424 {
1425 /* This is ambiguous. */
1426 errstr = "request for member `%D' is ambiguous";
1427 protect += 2;
1428 break;
1429 }
1430 }
1431 }
1432 {
1433 tree *tp = search_stack->first;
1434 tree *search_tail = tp + tail;
1435
1436 if (entry)
1437 TREE_VALUE (entry) = rval;
1438
1439 if (rval_binfo)
1440 {
1441 type = BINFO_TYPE (rval_binfo);
1442
1443 if (rval)
1444 {
1445 if (want_type)
1446 {
1447 if (TREE_CODE (rval) != TYPE_DECL)
1448 {
1449 rval = purpose_member (name, CLASSTYPE_TAGS (type));
1450 if (rval)
1451 rval = TYPE_MAIN_DECL (TREE_VALUE (rval));
1452 }
1453 }
1454 else
1455 {
1456 if (TREE_CODE (rval) == TYPE_DECL
1457 && lookup_fnfields_here (type, name) >= 0)
1458 rval = NULL_TREE;
1459 }
1460 }
1461 }
1462
1463 if (rval == NULL_TREE)
1464 errstr = 0;
1465
1466 /* If this FIELD_DECL defines its own access level, deal with that. */
1467 if (rval && errstr == 0
1468 && ((protect&1) || entry)
1469 && DECL_LANG_SPECIFIC (rval)
1470 && DECL_ACCESS (rval))
1471 {
1472 while (tp < search_tail)
1473 {
1474 /* If is possible for one of the derived types on the path to
1475 have defined special access for this field. Look for such
1476 declarations and report an error if a conflict is found. */
1477 tree new_v = NULL_TREE;
1478
1479 if (this_v != access_default_node)
1480 new_v = compute_access (TREE_VALUE (TREE_CHAIN (*tp)), rval);
1481 if (this_v != access_default_node && new_v != this_v)
1482 {
1483 errstr = "conflicting access to member `%D'";
1484 this_v = access_default_node;
1485 }
1486 own_access = new_v;
1487 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp)));
1488 tp += 1;
1489 }
1490 }
1491 else
1492 {
1493 while (tp < search_tail)
1494 {
1495 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp)));
1496 tp += 1;
1497 }
1498 }
1499 }
1500 search_stack = pop_search_level (search_stack);
1501
1502 if (errstr == 0)
1503 {
1504 if (own_access == access_private_node)
1505 errstr = "member `%D' declared private";
1506 else if (own_access == access_protected_node)
1507 errstr = "member `%D' declared protected";
1508 else if (this_v == access_private_node)
1509 errstr = TREE_PRIVATE (rval)
1510 ? "member `%D' is private"
1511 : "member `%D' is from private base class";
1512 else if (this_v == access_protected_node)
1513 errstr = TREE_PROTECTED (rval)
1514 ? "member `%D' is protected"
1515 : "member `%D' is from protected base class";
1516 }
1517
1518 out:
1519 if (entry)
1520 {
1521 if (errstr)
1522 {
1523 tree error_string = my_build_string (errstr);
1524 /* Save error message with entry. */
1525 TREE_TYPE (entry) = error_string;
1526 }
1527 else
1528 {
1529 /* Mark entry as having no error string. */
1530 TREE_TYPE (entry) = NULL_TREE;
1531 }
1532 }
1533
1534 if (protect == 2)
1535 {
1536 /* If we are not interested in ambiguities, don't report them,
1537 just return NULL_TREE. */
1538 rval = NULL_TREE;
1539 protect = 0;
1540 }
1541
1542 if (errstr && protect)
1543 {
1544 cp_error (errstr, name, type);
1545 rval = error_mark_node;
1546 }
1547
1548 /* Do implicit typename stuff. */
1549 if (rval && TREE_CODE (rval) == TYPE_DECL
1550 && ! DECL_ARTIFICIAL (rval)
1551 && processing_template_decl
1552 && BINFO_TYPE (rval_binfo) != current_class_type
1553 && uses_template_parms (type))
1554 {
1555 binfo = rval_binfo;
1556 for (; ; binfo = BINFO_INHERITANCE_CHAIN (binfo))
1557 if (BINFO_INHERITANCE_CHAIN (binfo) == NULL_TREE
1558 || (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo))
1559 == current_class_type))
1560 break;
1561
1562 entry = make_typename_type (BINFO_TYPE (binfo), name);
1563 TREE_TYPE (entry) = TREE_TYPE (rval);
1564 rval = TYPE_MAIN_DECL (entry);
1565 }
1566
1567 return rval;
1568 }
1569
1570 /* Try to find NAME inside a nested class. */
1571
1572 tree
1573 lookup_nested_field (name, complain)
1574 tree name;
1575 int complain;
1576 {
1577 register tree t;
1578
1579 tree id = NULL_TREE;
1580 if (TREE_CHAIN (current_class_type))
1581 {
1582 /* Climb our way up the nested ladder, seeing if we're trying to
1583 modify a field in an enclosing class. If so, we should only
1584 be able to modify if it's static. */
1585 for (t = TREE_CHAIN (current_class_type);
1586 t && DECL_CONTEXT (t);
1587 t = TREE_CHAIN (DECL_CONTEXT (t)))
1588 {
1589 if (TREE_CODE (DECL_CONTEXT (t)) != RECORD_TYPE)
1590 break;
1591
1592 /* N.B.: lookup_field will do the access checking for us */
1593 id = lookup_field (DECL_CONTEXT (t), name, complain, 0);
1594 if (id == error_mark_node)
1595 {
1596 id = NULL_TREE;
1597 continue;
1598 }
1599
1600 if (id != NULL_TREE)
1601 {
1602 if (TREE_CODE (id) == FIELD_DECL
1603 && ! TREE_STATIC (id)
1604 && TREE_TYPE (id) != error_mark_node)
1605 {
1606 if (complain)
1607 {
1608 /* At parse time, we don't want to give this error, since
1609 we won't have enough state to make this kind of
1610 decision properly. But there are times (e.g., with
1611 enums in nested classes) when we do need to call
1612 this fn at parse time. So, in those cases, we pass
1613 complain as a 0 and just return a NULL_TREE. */
1614 cp_error ("assignment to non-static member `%D' of enclosing class `%T'",
1615 id, DECL_CONTEXT (t));
1616 /* Mark this for do_identifier(). It would otherwise
1617 claim that the variable was undeclared. */
1618 TREE_TYPE (id) = error_mark_node;
1619 }
1620 else
1621 {
1622 id = NULL_TREE;
1623 continue;
1624 }
1625 }
1626 break;
1627 }
1628 }
1629 }
1630
1631 return id;
1632 }
1633
1634 /* TYPE is a class type. Return the index of the fields within
1635 the method vector with name NAME, or -1 is no such field exists. */
1636
1637 static int
1638 lookup_fnfields_1 (type, name)
1639 tree type, name;
1640 {
1641 register tree method_vec = CLASSTYPE_METHOD_VEC (type);
1642
1643 if (method_vec != 0)
1644 {
1645 register tree *methods = &TREE_VEC_ELT (method_vec, 0);
1646 register tree *end = TREE_VEC_END (method_vec);
1647
1648 #ifdef GATHER_STATISTICS
1649 n_calls_lookup_fnfields_1++;
1650 #endif /* GATHER_STATISTICS */
1651
1652 /* Constructors are first... */
1653 if (*methods && name == ctor_identifier)
1654 return 0;
1655
1656 /* and destructors are second. */
1657 if (*++methods && name == dtor_identifier)
1658 return 1;
1659
1660 while (++methods != end)
1661 {
1662 #ifdef GATHER_STATISTICS
1663 n_outer_fields_searched++;
1664 #endif /* GATHER_STATISTICS */
1665 if (DECL_NAME (*methods) == name)
1666 break;
1667 }
1668
1669 /* If we didn't find it, it might have been a template
1670 conversion operator. (Note that we don't look for this case
1671 above so that we will always find specializations first.) */
1672 if (methods == end
1673 && IDENTIFIER_TYPENAME_P (name))
1674 {
1675 methods = &TREE_VEC_ELT (method_vec, 0) + 1;
1676
1677 while (++methods != end)
1678 {
1679 if (TREE_CODE (*methods) == TEMPLATE_DECL
1680 && IDENTIFIER_TYPENAME_P (DECL_NAME (*methods)))
1681 break;
1682 }
1683 }
1684
1685 if (methods != end)
1686 return methods - &TREE_VEC_ELT (method_vec, 0);
1687 }
1688
1689 return -1;
1690 }
1691
1692 /* Starting from BASETYPE, return a TREE_BASELINK-like object
1693 which gives the following information (in a list):
1694
1695 TREE_TYPE: list of basetypes needed to get to...
1696 TREE_VALUE: list of all functions in a given type
1697 which have name NAME.
1698
1699 No access information is computed by this function,
1700 other then to adorn the list of basetypes with
1701 TREE_VIA_PUBLIC.
1702
1703 If there are two ways to find a name (two members), if COMPLAIN is
1704 non-zero, then error_mark_node is returned, and an error message is
1705 printed, otherwise, just an error_mark_node is returned.
1706
1707 As a special case, is COMPLAIN is -1, we don't complain, and we
1708 don't return error_mark_node, but rather the complete list of
1709 virtuals. This is used by get_virtuals_named_this. */
1710
1711 tree
1712 lookup_fnfields (basetype_path, name, complain)
1713 tree basetype_path, name;
1714 int complain;
1715 {
1716 int head = 0, tail = 0;
1717 tree type, rval, rval_binfo = NULL_TREE, rvals = NULL_TREE;
1718 tree rval_binfo_h = NULL_TREE, entry, binfo, basetype_chain, binfo_h;
1719 int find_all = 0;
1720
1721 /* rval_binfo is the binfo associated with the found member, note,
1722 this can be set with useful information, even when rval is not
1723 set, because it must deal with ALL members, not just function
1724 members. It is used for ambiguity checking and the hidden
1725 checks. Whereas rval is only set if a proper (not hidden)
1726 function member is found. */
1727
1728 /* rval_binfo_h and binfo_h are binfo values used when we perform the
1729 hiding checks, as virtual base classes may not be shared. The strategy
1730 is we always go into the binfo hierarchy owned by TYPE_BINFO of
1731 virtual base classes, as we cross virtual base class lines. This way
1732 we know that binfo of a virtual base class will always == itself when
1733 found along any line. (mrs) */
1734
1735 /* For now, don't try this. */
1736 int protect = complain;
1737
1738 char *errstr = 0;
1739
1740 /* Set this to nonzero if we don't know how to compute
1741 accurate error messages for access control. */
1742 int idx = MEMOIZED_HASH_FN (name);
1743
1744 if (complain == -1)
1745 {
1746 find_all = 1;
1747 protect = complain = 0;
1748 }
1749
1750 #if 0
1751 /* We cannot search for constructor/destructor names like this. */
1752 /* This can't go here, but where should it go? */
1753 /* If we are looking for a constructor in a templated type, use the
1754 unspecialized name, as that is how we store it. */
1755 if (IDENTIFIER_TEMPLATE (name))
1756 name = constructor_name (name);
1757 #endif
1758
1759 binfo = basetype_path;
1760 binfo_h = binfo;
1761 type = complete_type (BINFO_TYPE (basetype_path));
1762
1763 /* The memoization code is in need of maintenance. */
1764 if (!find_all && CLASSTYPE_MTABLE_ENTRY (type))
1765 {
1766 tree tem = MEMOIZED_FNFIELDS (CLASSTYPE_MTABLE_ENTRY (type), idx);
1767
1768 while (tem && TREE_PURPOSE (tem) != name)
1769 {
1770 memoized_fields_searched[1]++;
1771 tem = TREE_CHAIN (tem);
1772 }
1773 if (tem)
1774 {
1775 if (protect && TREE_TYPE (tem))
1776 {
1777 error (TREE_STRING_POINTER (TREE_TYPE (tem)),
1778 IDENTIFIER_POINTER (name),
1779 TYPE_NAME_STRING (DECL_CLASS_CONTEXT (TREE_VALUE (TREE_VALUE (tem)))));
1780 return error_mark_node;
1781 }
1782 if (TREE_VALUE (tem) == NULL_TREE)
1783 {
1784 memoized_fast_rejects[1] += 1;
1785 return NULL_TREE;
1786 }
1787 else
1788 {
1789 /* Want to return this, but we must make sure
1790 that access information is consistent. */
1791 tree baselink = TREE_VALUE (tem);
1792 tree memoized_basetypes = TREE_PURPOSE (baselink);
1793 tree these_basetypes = basetype_path;
1794 while (memoized_basetypes && these_basetypes)
1795 {
1796 memoized_fields_searched[1]++;
1797 if (TREE_VALUE (memoized_basetypes) != these_basetypes)
1798 break;
1799 memoized_basetypes = TREE_CHAIN (memoized_basetypes);
1800 these_basetypes = BINFO_INHERITANCE_CHAIN (these_basetypes);
1801 }
1802 /* The following statement is true only when both are NULL. */
1803 if (memoized_basetypes == these_basetypes)
1804 {
1805 memoized_fast_finds[1] += 1;
1806 return TREE_VALUE (tem);
1807 }
1808 /* else, we must re-find this field by hand. */
1809 baselink = tree_cons (basetype_path, TREE_VALUE (baselink), TREE_CHAIN (baselink));
1810 return baselink;
1811 }
1812 }
1813 }
1814
1815 #ifdef GATHER_STATISTICS
1816 n_calls_lookup_fnfields++;
1817 #endif /* GATHER_STATISTICS */
1818 if (protect && flag_memoize_lookups && ! global_bindings_p ())
1819 entry = make_memoized_table_entry (type, name, 1);
1820 else
1821 entry = 0;
1822
1823 idx = lookup_fnfields_here (type, name);
1824 if (idx >= 0 || lookup_field_1 (type, name))
1825 {
1826 rval_binfo = basetype_path;
1827 rval_binfo_h = rval_binfo;
1828 }
1829
1830 if (idx >= 0)
1831 {
1832 rval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1833 rvals = my_tree_cons (basetype_path, rval, rvals);
1834 if (BINFO_BASETYPES (binfo) && CLASSTYPE_BASELINK_VEC (type))
1835 TREE_TYPE (rvals) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), idx);
1836
1837 if (entry)
1838 {
1839 TREE_VALUE (entry) = rvals;
1840 TREE_TYPE (entry) = NULL_TREE;
1841 }
1842
1843 return rvals;
1844 }
1845 rval = NULL_TREE;
1846
1847 if (name == ctor_identifier || name == dtor_identifier)
1848 {
1849 /* Don't allow lookups of constructors and destructors to go
1850 deeper than the first place we look. */
1851 if (entry)
1852 TREE_TYPE (entry) = TREE_VALUE (entry) = NULL_TREE;
1853
1854 return NULL_TREE;
1855 }
1856
1857 if (basetype_path == TYPE_BINFO (type))
1858 {
1859 basetype_chain = CLASSTYPE_BINFO_AS_LIST (type);
1860 TREE_VIA_PUBLIC (basetype_chain) = 1;
1861 BINFO_VIA_PUBLIC (basetype_path) = 1;
1862 BINFO_INHERITANCE_CHAIN (basetype_path) = NULL_TREE;
1863 }
1864 else
1865 {
1866 basetype_chain = build_expr_list (NULL_TREE, basetype_path);
1867 TREE_VIA_PUBLIC (basetype_chain) = TREE_VIA_PUBLIC (basetype_path);
1868 TREE_VIA_PROTECTED (basetype_chain) = TREE_VIA_PROTECTED (basetype_path);
1869 TREE_VIA_VIRTUAL (basetype_chain) = TREE_VIA_VIRTUAL (basetype_path);
1870 }
1871
1872 /* The ambiguity check relies upon breadth first searching. */
1873
1874 search_stack = push_search_level (search_stack, &search_obstack);
1875 binfo = basetype_path;
1876 binfo_h = binfo;
1877
1878 while (1)
1879 {
1880 tree binfos = BINFO_BASETYPES (binfo);
1881 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1882 int idx;
1883
1884 /* Process and/or queue base types. */
1885 for (i = 0; i < n_baselinks; i++)
1886 {
1887 tree base_binfo = TREE_VEC_ELT (binfos, i);
1888 if (BINFO_FIELDS_MARKED (base_binfo) == 0)
1889 {
1890 tree btypes;
1891
1892 SET_BINFO_FIELDS_MARKED (base_binfo);
1893 btypes = my_tree_cons (NULL_TREE, base_binfo, basetype_chain);
1894 TREE_VIA_PUBLIC (btypes) = TREE_VIA_PUBLIC (base_binfo);
1895 TREE_VIA_PROTECTED (btypes) = TREE_VIA_PROTECTED (base_binfo);
1896 TREE_VIA_VIRTUAL (btypes) = TREE_VIA_VIRTUAL (base_binfo);
1897 if (TREE_VIA_VIRTUAL (base_binfo))
1898 btypes = my_tree_cons (NULL_TREE,
1899 TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i))),
1900 btypes);
1901 else
1902 btypes = my_tree_cons (NULL_TREE,
1903 TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i),
1904 btypes);
1905 obstack_ptr_grow (&search_obstack, btypes);
1906 tail += 1;
1907 if (tail >= search_stack->limit)
1908 my_friendly_abort (99);
1909 }
1910 }
1911
1912 /* Process head of queue, if one exists. */
1913 if (head >= tail)
1914 break;
1915
1916 basetype_chain = search_stack->first[head++];
1917 binfo_h = TREE_VALUE (basetype_chain);
1918 basetype_chain = TREE_CHAIN (basetype_chain);
1919 basetype_path = TREE_VALUE (basetype_chain);
1920 if (TREE_CHAIN (basetype_chain))
1921 BINFO_INHERITANCE_CHAIN (basetype_path) = TREE_VALUE (TREE_CHAIN (basetype_chain));
1922 else
1923 BINFO_INHERITANCE_CHAIN (basetype_path) = NULL_TREE;
1924
1925 binfo = basetype_path;
1926 type = BINFO_TYPE (binfo);
1927
1928 /* See if we can find NAME in TYPE. If RVAL is nonzero,
1929 and we do find NAME in TYPE, verify that such a second
1930 sighting is in fact valid. */
1931
1932 idx = lookup_fnfields_here (type, name);
1933
1934 if (idx >= 0 || (lookup_field_1 (type, name)!=NULL_TREE && !find_all))
1935 {
1936 if (rval_binfo && !find_all && hides (rval_binfo_h, binfo_h))
1937 {
1938 /* This is ok, the member found is in rval_binfo, not
1939 here (binfo). */
1940 }
1941 else if (rval_binfo==NULL_TREE || find_all || hides (binfo_h, rval_binfo_h))
1942 {
1943 /* This is ok, the member found is here (binfo), not in
1944 rval_binfo. */
1945 if (idx >= 0)
1946 {
1947 rval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
1948 /* Note, rvals can only be previously set if find_all is
1949 true. */
1950 rvals = my_tree_cons (basetype_path, rval, rvals);
1951 if (TYPE_BINFO_BASETYPES (type)
1952 && CLASSTYPE_BASELINK_VEC (type))
1953 TREE_TYPE (rvals) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), idx);
1954 }
1955 else
1956 {
1957 /* Undo finding it before, as something else hides it. */
1958 rval = NULL_TREE;
1959 rvals = NULL_TREE;
1960 }
1961 rval_binfo = binfo;
1962 rval_binfo_h = binfo_h;
1963 }
1964 else
1965 {
1966 /* This is ambiguous. */
1967 errstr = "request for method `%D' is ambiguous";
1968 rvals = error_mark_node;
1969 break;
1970 }
1971 }
1972 }
1973 {
1974 tree *tp = search_stack->first;
1975 tree *search_tail = tp + tail;
1976
1977 while (tp < search_tail)
1978 {
1979 CLEAR_BINFO_FIELDS_MARKED (TREE_VALUE (TREE_CHAIN (*tp)));
1980 tp += 1;
1981 }
1982 }
1983 search_stack = pop_search_level (search_stack);
1984
1985 if (entry)
1986 {
1987 if (errstr)
1988 {
1989 tree error_string = my_build_string (errstr);
1990 /* Save error message with entry. */
1991 TREE_TYPE (entry) = error_string;
1992 }
1993 else
1994 {
1995 /* Mark entry as having no error string. */
1996 TREE_TYPE (entry) = NULL_TREE;
1997 TREE_VALUE (entry) = rvals;
1998 }
1999 }
2000
2001 if (errstr && protect)
2002 {
2003 cp_error (errstr, name);
2004 rvals = error_mark_node;
2005 }
2006
2007 return rvals;
2008 }
2009 \f
2010 /* BREADTH-FIRST SEARCH ROUTINES. */
2011
2012 /* Search a multiple inheritance hierarchy by breadth-first search.
2013
2014 BINFO is an aggregate type, possibly in a multiple-inheritance hierarchy.
2015 TESTFN is a function, which, if true, means that our condition has been met,
2016 and its return value should be returned.
2017 QFN, if non-NULL, is a predicate dictating whether the type should
2018 even be queued. */
2019
2020 static HOST_WIDE_INT
2021 breadth_first_search (binfo, testfn, qfn)
2022 tree binfo;
2023 int (*testfn) PROTO((tree, int));
2024 int (*qfn) PROTO((tree, int));
2025 {
2026 int head = 0, tail = 0;
2027 int rval = 0;
2028
2029 search_stack = push_search_level (search_stack, &search_obstack);
2030
2031 while (1)
2032 {
2033 tree binfos = BINFO_BASETYPES (binfo);
2034 int n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2035 int i;
2036
2037 /* Process and/or queue base types. */
2038 for (i = 0; i < n_baselinks; i++)
2039 {
2040 tree base_binfo = TREE_VEC_ELT (binfos, i);
2041
2042 if (BINFO_MARKED (base_binfo) == 0
2043 && (qfn == 0 || (*qfn) (binfo, i)))
2044 {
2045 SET_BINFO_MARKED (base_binfo);
2046 obstack_ptr_grow (&search_obstack, binfo);
2047 obstack_ptr_grow (&search_obstack, (HOST_WIDE_INT) i);
2048 tail += 2;
2049 if (tail >= search_stack->limit)
2050 my_friendly_abort (100);
2051 }
2052 }
2053 /* Process head of queue, if one exists. */
2054 if (head >= tail)
2055 {
2056 rval = 0;
2057 break;
2058 }
2059
2060 binfo = search_stack->first[head++];
2061 i = (HOST_WIDE_INT) search_stack->first[head++];
2062 if ((rval = (*testfn) (binfo, i)))
2063 break;
2064 binfo = BINFO_BASETYPE (binfo, i);
2065 }
2066 {
2067 tree *tp = search_stack->first;
2068 tree *search_tail = tp + tail;
2069 while (tp < search_tail)
2070 {
2071 tree binfo = *tp++;
2072 int i = (HOST_WIDE_INT)(*tp++);
2073 CLEAR_BINFO_MARKED (BINFO_BASETYPE (binfo, i));
2074 }
2075 }
2076
2077 search_stack = pop_search_level (search_stack);
2078 return rval;
2079 }
2080
2081 /* Functions to use in breadth first searches. */
2082 typedef int (*pfi) PROTO((tree, int));
2083
2084 static tree declarator;
2085
2086 static tree
2087 get_virtuals_named_this (binfo)
2088 tree binfo;
2089 {
2090 tree fields;
2091
2092 fields = lookup_fnfields (binfo, declarator, -1);
2093 /* fields cannot be error_mark_node */
2094
2095 if (fields == 0)
2096 return 0;
2097
2098 /* Get to the function decls, and return the first virtual function
2099 with this name, if there is one. */
2100 while (fields)
2101 {
2102 tree fndecl;
2103
2104 for (fndecl = TREE_VALUE (fields); fndecl; fndecl = DECL_CHAIN (fndecl))
2105 if (DECL_VINDEX (fndecl))
2106 return fields;
2107 fields = next_baselink (fields);
2108 }
2109 return NULL_TREE;
2110 }
2111
2112 static tree
2113 get_virtual_destructor (binfo, i)
2114 tree binfo;
2115 int i;
2116 {
2117 tree type = BINFO_TYPE (binfo);
2118 if (i >= 0)
2119 type = BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo), i));
2120 if (TYPE_HAS_DESTRUCTOR (type)
2121 && DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1)))
2122 return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1);
2123 return 0;
2124 }
2125
2126 static int
2127 tree_has_any_destructor_p (binfo, i)
2128 tree binfo;
2129 int i;
2130 {
2131 tree type = BINFO_TYPE (binfo);
2132 if (i >= 0)
2133 type = BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo), i));
2134 return TYPE_NEEDS_DESTRUCTOR (type);
2135 }
2136
2137 /* Given a class type TYPE, and a function decl FNDECL, look for a
2138 virtual function in TYPE's hierarchy which FNDECL could match as a
2139 virtual function. It doesn't matter which one we find.
2140
2141 DTORP is nonzero if we are looking for a destructor. Destructors
2142 need special treatment because they do not match by name. */
2143
2144 tree
2145 get_matching_virtual (binfo, fndecl, dtorp)
2146 tree binfo, fndecl;
2147 int dtorp;
2148 {
2149 tree tmp = NULL_TREE;
2150
2151 /* Breadth first search routines start searching basetypes
2152 of TYPE, so we must perform first ply of search here. */
2153 if (dtorp)
2154 {
2155 if (tree_has_any_destructor_p (binfo, -1))
2156 tmp = get_virtual_destructor (binfo, -1);
2157
2158 if (tmp)
2159 return tmp;
2160
2161 tmp = (tree) breadth_first_search (binfo,
2162 (pfi) get_virtual_destructor,
2163 tree_has_any_destructor_p);
2164 return tmp;
2165 }
2166 else
2167 {
2168 tree drettype, dtypes, btypes, instptr_type;
2169 tree basetype = DECL_CLASS_CONTEXT (fndecl);
2170 tree baselink, best = NULL_TREE;
2171 tree name = DECL_ASSEMBLER_NAME (fndecl);
2172
2173 declarator = DECL_NAME (fndecl);
2174 if (IDENTIFIER_VIRTUAL_P (declarator) == 0)
2175 return NULL_TREE;
2176
2177 baselink = get_virtuals_named_this (binfo);
2178 if (baselink == NULL_TREE)
2179 return NULL_TREE;
2180
2181 drettype = TREE_TYPE (TREE_TYPE (fndecl));
2182 dtypes = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2183 if (DECL_STATIC_FUNCTION_P (fndecl))
2184 instptr_type = NULL_TREE;
2185 else
2186 instptr_type = TREE_TYPE (TREE_VALUE (dtypes));
2187
2188 for (; baselink; baselink = next_baselink (baselink))
2189 {
2190 for (tmp = TREE_VALUE (baselink); tmp; tmp = DECL_CHAIN (tmp))
2191 {
2192 if (! DECL_VINDEX (tmp))
2193 continue;
2194
2195 btypes = TYPE_ARG_TYPES (TREE_TYPE (tmp));
2196 if (instptr_type == NULL_TREE)
2197 {
2198 if (compparms (TREE_CHAIN (btypes), dtypes, 3))
2199 /* Caller knows to give error in this case. */
2200 return tmp;
2201 return NULL_TREE;
2202 }
2203
2204 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (btypes)))
2205 == TYPE_READONLY (instptr_type))
2206 && compparms (TREE_CHAIN (btypes), TREE_CHAIN (dtypes), 3))
2207 {
2208 tree brettype = TREE_TYPE (TREE_TYPE (tmp));
2209 if (comptypes (brettype, drettype, 1))
2210 /* OK */;
2211 else if
2212 (TREE_CODE (brettype) == TREE_CODE (drettype)
2213 && (TREE_CODE (brettype) == POINTER_TYPE
2214 || TREE_CODE (brettype) == REFERENCE_TYPE)
2215 && comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (brettype)),
2216 TYPE_MAIN_VARIANT (TREE_TYPE (drettype)),
2217 0))
2218 /* covariant return type */
2219 {
2220 tree b = TREE_TYPE (brettype), d = TREE_TYPE (drettype);
2221 if (TYPE_MAIN_VARIANT (b) != TYPE_MAIN_VARIANT (d))
2222 {
2223 tree binfo = get_binfo (b, d, 1);
2224 if (binfo != error_mark_node
2225 && (! BINFO_OFFSET_ZEROP (binfo)
2226 || TREE_VIA_VIRTUAL (binfo)))
2227 sorry ("adjusting pointers for covariant returns");
2228 }
2229 if (TYPE_READONLY (d) > TYPE_READONLY (b))
2230 {
2231 cp_error_at ("return type of `%#D' adds const", fndecl);
2232 cp_error_at (" overriding definition as `%#D'",
2233 tmp);
2234 }
2235 else if (TYPE_VOLATILE (d) > TYPE_VOLATILE (b))
2236 {
2237 cp_error_at ("return type of `%#D' adds volatile",
2238 fndecl);
2239 cp_error_at (" overriding definition as `%#D'",
2240 tmp);
2241 }
2242 }
2243 else if (IS_AGGR_TYPE_2 (brettype, drettype)
2244 && comptypes (brettype, drettype, 0))
2245 {
2246 error ("invalid covariant return type (must use pointer or reference)");
2247 cp_error_at (" overriding `%#D'", tmp);
2248 cp_error_at (" with `%#D'", fndecl);
2249 }
2250 else if (IDENTIFIER_ERROR_LOCUS (name) == NULL_TREE)
2251 {
2252 cp_error_at ("conflicting return type specified for virtual function `%#D'", fndecl);
2253 cp_error_at (" overriding definition as `%#D'", tmp);
2254 SET_IDENTIFIER_ERROR_LOCUS (name, basetype);
2255 }
2256 break;
2257 }
2258 }
2259 if (tmp)
2260 {
2261 best = tmp;
2262 break;
2263 }
2264 }
2265
2266 return best;
2267 }
2268 }
2269
2270 /* Return the list of virtual functions which are abstract in type
2271 TYPE that come from non virtual base classes. See
2272 expand_direct_vtbls_init for the style of search we do. */
2273
2274 static tree
2275 get_abstract_virtuals_1 (binfo, do_self, abstract_virtuals)
2276 tree binfo;
2277 int do_self;
2278 tree abstract_virtuals;
2279 {
2280 tree binfos = BINFO_BASETYPES (binfo);
2281 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2282
2283 for (i = 0; i < n_baselinks; i++)
2284 {
2285 tree base_binfo = TREE_VEC_ELT (binfos, i);
2286 int is_not_base_vtable
2287 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2288 if (! TREE_VIA_VIRTUAL (base_binfo))
2289 abstract_virtuals
2290 = get_abstract_virtuals_1 (base_binfo, is_not_base_vtable,
2291 abstract_virtuals);
2292 }
2293 /* Should we use something besides CLASSTYPE_VFIELDS? */
2294 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2295 {
2296 tree virtuals = BINFO_VIRTUALS (binfo);
2297
2298 skip_rtti_stuff (&virtuals);
2299
2300 while (virtuals)
2301 {
2302 tree base_pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals));
2303 tree base_fndecl = TREE_OPERAND (base_pfn, 0);
2304 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl))
2305 abstract_virtuals = tree_cons (NULL_TREE, base_fndecl, abstract_virtuals);
2306 virtuals = TREE_CHAIN (virtuals);
2307 }
2308 }
2309 return abstract_virtuals;
2310 }
2311
2312 /* Return the list of virtual functions which are abstract in type TYPE.
2313 This information is cached, and so must be built on a
2314 non-temporary obstack. */
2315
2316 tree
2317 get_abstract_virtuals (type)
2318 tree type;
2319 {
2320 tree vbases;
2321 tree abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (type);
2322
2323 /* First get all from non-virtual bases. */
2324 abstract_virtuals
2325 = get_abstract_virtuals_1 (TYPE_BINFO (type), 1, abstract_virtuals);
2326
2327 for (vbases = CLASSTYPE_VBASECLASSES (type); vbases; vbases = TREE_CHAIN (vbases))
2328 {
2329 tree virtuals = BINFO_VIRTUALS (vbases);
2330
2331 skip_rtti_stuff (&virtuals);
2332
2333 while (virtuals)
2334 {
2335 tree base_pfn = FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals));
2336 tree base_fndecl = TREE_OPERAND (base_pfn, 0);
2337 if (DECL_ABSTRACT_VIRTUAL_P (base_fndecl))
2338 abstract_virtuals = tree_cons (NULL_TREE, base_fndecl, abstract_virtuals);
2339 virtuals = TREE_CHAIN (virtuals);
2340 }
2341 }
2342 return nreverse (abstract_virtuals);
2343 }
2344
2345 /* For the type TYPE, return a list of member functions available from
2346 base classes with name NAME. The TREE_VALUE of the list is a chain of
2347 member functions with name NAME. The TREE_PURPOSE of the list is a
2348 basetype, or a list of base types (in reverse order) which were
2349 traversed to reach the chain of member functions. If we reach a base
2350 type which provides a member function of name NAME, and which has at
2351 most one base type itself, then we can terminate the search. */
2352
2353 tree
2354 get_baselinks (type_as_binfo_list, type, name)
2355 tree type_as_binfo_list;
2356 tree type, name;
2357 {
2358 int head = 0, tail = 0, idx;
2359 tree rval = 0, nval = 0;
2360 tree basetypes = type_as_binfo_list;
2361 tree binfo = TYPE_BINFO (type);
2362
2363 search_stack = push_search_level (search_stack, &search_obstack);
2364
2365 while (1)
2366 {
2367 tree binfos = BINFO_BASETYPES (binfo);
2368 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2369
2370 /* Process and/or queue base types. */
2371 for (i = 0; i < n_baselinks; i++)
2372 {
2373 tree base_binfo = TREE_VEC_ELT (binfos, i);
2374 tree btypes;
2375
2376 btypes = hash_tree_cons (TREE_VIA_PUBLIC (base_binfo),
2377 TREE_VIA_VIRTUAL (base_binfo),
2378 TREE_VIA_PROTECTED (base_binfo),
2379 NULL_TREE, base_binfo,
2380 basetypes);
2381 obstack_ptr_grow (&search_obstack, btypes);
2382 search_stack->first = (tree *)obstack_base (&search_obstack);
2383 tail += 1;
2384 }
2385
2386 dont_queue:
2387 /* Process head of queue, if one exists. */
2388 if (head >= tail)
2389 break;
2390
2391 basetypes = search_stack->first[head++];
2392 binfo = TREE_VALUE (basetypes);
2393 type = BINFO_TYPE (binfo);
2394 idx = lookup_fnfields_1 (type, name);
2395 if (idx >= 0)
2396 {
2397 nval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
2398 rval = hash_tree_cons (0, 0, 0, basetypes, nval, rval);
2399 if (TYPE_BINFO_BASETYPES (type) == 0)
2400 goto dont_queue;
2401 else if (TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)) == 1)
2402 {
2403 if (CLASSTYPE_BASELINK_VEC (type))
2404 TREE_TYPE (rval) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), idx);
2405 goto dont_queue;
2406 }
2407 }
2408 nval = NULL_TREE;
2409 }
2410
2411 search_stack = pop_search_level (search_stack);
2412 return rval;
2413 }
2414
2415 tree
2416 next_baselink (baselink)
2417 tree baselink;
2418 {
2419 tree tmp = TREE_TYPE (baselink);
2420 baselink = TREE_CHAIN (baselink);
2421 while (tmp)
2422 {
2423 /* @@ does not yet add previous base types. */
2424 baselink = tree_cons (TREE_PURPOSE (tmp), TREE_VALUE (tmp),
2425 baselink);
2426 TREE_TYPE (baselink) = TREE_TYPE (tmp);
2427 tmp = TREE_CHAIN (tmp);
2428 }
2429 return baselink;
2430 }
2431 \f
2432 /* DEPTH-FIRST SEARCH ROUTINES. */
2433
2434 #ifdef MI_MATRIX
2435 /* Assign unique numbers to _CLASSTYPE members of the lattice
2436 specified by TYPE. The root nodes are marked first; the nodes
2437 are marked depth-fisrt, left-right. */
2438
2439 static int cid;
2440
2441 /* Matrix implementing a relation from CLASSTYPE X CLASSTYPE => INT.
2442 Relation yields 1 if C1 <= C2, 0 otherwise. */
2443 typedef char mi_boolean;
2444 static mi_boolean *mi_matrix;
2445
2446 /* Type for which this matrix is defined. */
2447 static tree mi_type;
2448
2449 /* Size of the matrix for indexing purposes. */
2450 static int mi_size;
2451
2452 /* Return nonzero if class C2 derives from class C1. */
2453 #define BINFO_DERIVES_FROM(C1, C2) \
2454 ((mi_matrix+mi_size*(BINFO_CID (C1)-1))[BINFO_CID (C2)-1])
2455 #define TYPE_DERIVES_FROM(C1, C2) \
2456 ((mi_matrix+mi_size*(CLASSTYPE_CID (C1)-1))[CLASSTYPE_CID (C2)-1])
2457 #define BINFO_DERIVES_FROM_STAR(C) \
2458 (mi_matrix+(BINFO_CID (C)-1))
2459 #endif
2460
2461 /* This routine converts a pointer to be a pointer of an immediate
2462 base class. The normal convert_pointer_to routine would diagnose
2463 the conversion as ambiguous, under MI code that has the base class
2464 as an ambiguous base class. */
2465
2466 static tree
2467 convert_pointer_to_single_level (to_type, expr)
2468 tree to_type, expr;
2469 {
2470 tree binfo_of_derived;
2471 tree last;
2472
2473 binfo_of_derived = TYPE_BINFO (TREE_TYPE (TREE_TYPE (expr)));
2474 last = get_binfo (to_type, TREE_TYPE (TREE_TYPE (expr)), 0);
2475 BINFO_INHERITANCE_CHAIN (last) = binfo_of_derived;
2476 BINFO_INHERITANCE_CHAIN (binfo_of_derived) = NULL_TREE;
2477 return build_vbase_path (PLUS_EXPR, build_pointer_type (to_type), expr, last, 1);
2478 }
2479
2480 /* The main function which implements depth first search.
2481
2482 This routine has to remember the path it walked up, when
2483 dfs_init_vbase_pointers is the work function, as otherwise there
2484 would be no record. */
2485
2486 static void
2487 dfs_walk (binfo, fn, qfn)
2488 tree binfo;
2489 void (*fn) PROTO((tree));
2490 int (*qfn) PROTO((tree));
2491 {
2492 tree binfos = BINFO_BASETYPES (binfo);
2493 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2494
2495 for (i = 0; i < n_baselinks; i++)
2496 {
2497 tree base_binfo = TREE_VEC_ELT (binfos, i);
2498
2499 if (qfn == 0 || (*qfn)(base_binfo))
2500 {
2501 if (TREE_CODE (BINFO_TYPE (base_binfo)) == TEMPLATE_TYPE_PARM
2502 || TREE_CODE (BINFO_TYPE (base_binfo)) == TEMPLATE_TEMPLATE_PARM)
2503 /* Pass */;
2504 else if (fn == dfs_init_vbase_pointers)
2505 {
2506 /* When traversing an arbitrary MI hierarchy, we need to keep
2507 a record of the path we took to get down to the final base
2508 type, as otherwise there would be no record of it, and just
2509 trying to blindly convert at the bottom would be ambiguous.
2510
2511 The easiest way is to do the conversions one step at a time,
2512 as we know we want the immediate base class at each step.
2513
2514 The only special trick to converting one step at a time,
2515 is that when we hit the last virtual base class, we must
2516 use the SLOT value for it, and not use the normal convert
2517 routine. We use the last virtual base class, as in our
2518 implementation, we have pointers to all virtual base
2519 classes in the base object. */
2520
2521 tree saved_vbase_decl_ptr_intermediate
2522 = vbase_decl_ptr_intermediate;
2523
2524 if (TREE_VIA_VIRTUAL (base_binfo))
2525 {
2526 /* No need for the conversion here, as we know it is the
2527 right type. */
2528 vbase_decl_ptr_intermediate
2529 = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo));
2530 }
2531 else
2532 {
2533 vbase_decl_ptr_intermediate
2534 = convert_pointer_to_single_level (BINFO_TYPE (base_binfo),
2535 vbase_decl_ptr_intermediate);
2536 }
2537
2538 dfs_walk (base_binfo, fn, qfn);
2539
2540 vbase_decl_ptr_intermediate = saved_vbase_decl_ptr_intermediate;
2541 }
2542 else
2543 dfs_walk (base_binfo, fn, qfn);
2544 }
2545 }
2546
2547 fn (binfo);
2548 }
2549
2550 #ifdef MI_MATRIX
2551 /* Predicate functions which serve for dfs_walk. */
2552 static int numberedp (binfo) tree binfo;
2553 { return BINFO_CID (binfo); }
2554 static int unnumberedp (binfo) tree binfo;
2555 { return BINFO_CID (binfo) == 0; }
2556 #endif
2557
2558 static int markedp (binfo) tree binfo;
2559 { return BINFO_MARKED (binfo); }
2560 static int unmarkedp (binfo) tree binfo;
2561 { return BINFO_MARKED (binfo) == 0; }
2562
2563 #if 0
2564 static int bfs_markedp (binfo, i) tree binfo; int i;
2565 { return BINFO_MARKED (BINFO_BASETYPE (binfo, i)); }
2566 static int bfs_unmarkedp (binfo, i) tree binfo; int i;
2567 { return BINFO_MARKED (BINFO_BASETYPE (binfo, i)) == 0; }
2568 static int bfs_marked_vtable_pathp (binfo, i) tree binfo; int i;
2569 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo, i)); }
2570 static int bfs_unmarked_vtable_pathp (binfo, i) tree binfo; int i;
2571 { return BINFO_VTABLE_PATH_MARKED (BINFO_BASETYPE (binfo, i)) == 0; }
2572 static int bfs_marked_new_vtablep (binfo, i) tree binfo; int i;
2573 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo, i)); }
2574 static int bfs_unmarked_new_vtablep (binfo, i) tree binfo; int i;
2575 { return BINFO_NEW_VTABLE_MARKED (BINFO_BASETYPE (binfo, i)) == 0; }
2576 #endif
2577
2578 static int marked_vtable_pathp (binfo) tree binfo;
2579 { return BINFO_VTABLE_PATH_MARKED (binfo); }
2580 static int unmarked_vtable_pathp (binfo) tree binfo;
2581 { return BINFO_VTABLE_PATH_MARKED (binfo) == 0; }
2582 static int marked_new_vtablep (binfo) tree binfo;
2583 { return BINFO_NEW_VTABLE_MARKED (binfo); }
2584 static int unmarked_new_vtablep (binfo) tree binfo;
2585 { return BINFO_NEW_VTABLE_MARKED (binfo) == 0; }
2586
2587 #if 0
2588 static int dfs_search_slot_nonempty_p (binfo) tree binfo;
2589 { return CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo)) != 0; }
2590 #endif
2591
2592 static int dfs_debug_unmarkedp (binfo) tree binfo;
2593 { return CLASSTYPE_DEBUG_REQUESTED (BINFO_TYPE (binfo)) == 0; }
2594
2595 /* The worker functions for `dfs_walk'. These do not need to
2596 test anything (vis a vis marking) if they are paired with
2597 a predicate function (above). */
2598
2599 #ifdef MI_MATRIX
2600 /* Assign each type within the lattice a number which is unique
2601 in the lattice. The first number assigned is 1. */
2602
2603 static void
2604 dfs_number (binfo)
2605 tree binfo;
2606 {
2607 BINFO_CID (binfo) = ++cid;
2608 }
2609
2610 static void
2611 dfs_unnumber (binfo)
2612 tree binfo;
2613 {
2614 BINFO_CID (binfo) = 0;
2615 }
2616 #endif
2617
2618 #if 0
2619 static void
2620 dfs_mark (binfo) tree binfo;
2621 { SET_BINFO_MARKED (binfo); }
2622 #endif
2623
2624 static void
2625 dfs_unmark (binfo) tree binfo;
2626 { CLEAR_BINFO_MARKED (binfo); }
2627
2628 #if 0
2629 static void
2630 dfs_mark_vtable_path (binfo) tree binfo;
2631 { SET_BINFO_VTABLE_PATH_MARKED (binfo); }
2632
2633 static void
2634 dfs_unmark_vtable_path (binfo) tree binfo;
2635 { CLEAR_BINFO_VTABLE_PATH_MARKED (binfo); }
2636
2637 static void
2638 dfs_mark_new_vtable (binfo) tree binfo;
2639 { SET_BINFO_NEW_VTABLE_MARKED (binfo); }
2640
2641 static void
2642 dfs_unmark_new_vtable (binfo) tree binfo;
2643 { CLEAR_BINFO_NEW_VTABLE_MARKED (binfo); }
2644
2645 static void
2646 dfs_clear_search_slot (binfo) tree binfo;
2647 { CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (binfo)) = 0; }
2648 #endif
2649
2650 static void
2651 dfs_debug_mark (binfo)
2652 tree binfo;
2653 {
2654 tree t = BINFO_TYPE (binfo);
2655
2656 /* Use heuristic that if there are virtual functions,
2657 ignore until we see a non-inline virtual function. */
2658 tree methods = CLASSTYPE_METHOD_VEC (t);
2659
2660 CLASSTYPE_DEBUG_REQUESTED (t) = 1;
2661
2662 if (methods == 0)
2663 return;
2664
2665 /* If interface info is known, either we've already emitted the debug
2666 info or we don't need to. */
2667 if (CLASSTYPE_INTERFACE_KNOWN (t)
2668 || (write_virtuals == 2 && TYPE_VIRTUAL_P (t)))
2669 return;
2670
2671 /* If debug info is requested from this context for this type, supply it.
2672 If debug info is requested from another context for this type,
2673 see if some third context can supply it. */
2674 if (current_function_decl == NULL_TREE
2675 || DECL_CLASS_CONTEXT (current_function_decl) != t)
2676 {
2677 if (TREE_VEC_ELT (methods, 1))
2678 methods = TREE_VEC_ELT (methods, 1);
2679 else if (TREE_VEC_ELT (methods, 0))
2680 methods = TREE_VEC_ELT (methods, 0);
2681 else
2682 methods = TREE_VEC_ELT (methods, 2);
2683 while (methods)
2684 {
2685 if (DECL_VINDEX (methods)
2686 && DECL_THIS_INLINE (methods) == 0
2687 && DECL_ABSTRACT_VIRTUAL_P (methods) == 0)
2688 {
2689 /* Somebody, somewhere is going to have to define this
2690 virtual function. When they do, they will provide
2691 the debugging info. */
2692 return;
2693 }
2694 methods = TREE_CHAIN (methods);
2695 }
2696 }
2697 /* We cannot rely on some alien method to solve our problems,
2698 so we must write out the debug info ourselves. */
2699 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 0;
2700 rest_of_type_compilation (t, global_bindings_p ());
2701 }
2702 \f
2703 /* Attach to the type of the virtual base class, the pointer to the
2704 virtual base class, given the global pointer vbase_decl_ptr.
2705
2706 We use the global vbase_types. ICK! */
2707
2708 static void
2709 dfs_find_vbases (binfo)
2710 tree binfo;
2711 {
2712 tree binfos = BINFO_BASETYPES (binfo);
2713 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2714
2715 for (i = n_baselinks-1; i >= 0; i--)
2716 {
2717 tree base_binfo = TREE_VEC_ELT (binfos, i);
2718
2719 if (TREE_VIA_VIRTUAL (base_binfo)
2720 && CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (base_binfo)) == 0)
2721 {
2722 tree vbase = BINFO_TYPE (base_binfo);
2723 tree binfo = binfo_member (vbase, vbase_types);
2724
2725 CLASSTYPE_SEARCH_SLOT (vbase)
2726 = build (PLUS_EXPR, build_pointer_type (vbase),
2727 vbase_decl_ptr, BINFO_OFFSET (binfo));
2728 }
2729 }
2730 SET_BINFO_VTABLE_PATH_MARKED (binfo);
2731 SET_BINFO_NEW_VTABLE_MARKED (binfo);
2732 }
2733
2734 static void
2735 dfs_init_vbase_pointers (binfo)
2736 tree binfo;
2737 {
2738 tree type = BINFO_TYPE (binfo);
2739 tree fields = TYPE_FIELDS (type);
2740 tree this_vbase_ptr;
2741
2742 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo);
2743
2744 #if 0
2745 /* See finish_struct_1 for when we can enable this. */
2746 /* If we have a vtable pointer first, skip it. */
2747 if (VFIELD_NAME_P (DECL_NAME (fields)))
2748 fields = TREE_CHAIN (fields);
2749 #endif
2750
2751 if (fields == NULL_TREE
2752 || DECL_NAME (fields) == NULL_TREE
2753 || ! VBASE_NAME_P (DECL_NAME (fields)))
2754 return;
2755
2756 this_vbase_ptr = vbase_decl_ptr_intermediate;
2757
2758 if (build_pointer_type (type) != TYPE_MAIN_VARIANT (TREE_TYPE (this_vbase_ptr)))
2759 my_friendly_abort (125);
2760
2761 while (fields && DECL_NAME (fields)
2762 && VBASE_NAME_P (DECL_NAME (fields)))
2763 {
2764 tree ref = build (COMPONENT_REF, TREE_TYPE (fields),
2765 build_indirect_ref (this_vbase_ptr, NULL_PTR), fields);
2766 tree init = CLASSTYPE_SEARCH_SLOT (TREE_TYPE (TREE_TYPE (fields)));
2767 vbase_init_result = tree_cons (binfo_member (TREE_TYPE (TREE_TYPE (fields)),
2768 vbase_types),
2769 build_modify_expr (ref, NOP_EXPR, init),
2770 vbase_init_result);
2771 fields = TREE_CHAIN (fields);
2772 }
2773 }
2774
2775 /* Sometimes this needs to clear both VTABLE_PATH and NEW_VTABLE. Other
2776 times, just NEW_VTABLE, but optimizer should make both with equal
2777 efficiency (though it does not currently). */
2778
2779 static void
2780 dfs_clear_vbase_slots (binfo)
2781 tree binfo;
2782 {
2783 tree type = BINFO_TYPE (binfo);
2784 CLASSTYPE_SEARCH_SLOT (type) = 0;
2785 CLEAR_BINFO_VTABLE_PATH_MARKED (binfo);
2786 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2787 }
2788
2789 tree
2790 init_vbase_pointers (type, decl_ptr)
2791 tree type;
2792 tree decl_ptr;
2793 {
2794 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
2795 {
2796 int old_flag = flag_this_is_variable;
2797 tree binfo = TYPE_BINFO (type);
2798 flag_this_is_variable = -2;
2799 vbase_types = CLASSTYPE_VBASECLASSES (type);
2800 vbase_decl_ptr = vbase_decl_ptr_intermediate = decl_ptr;
2801 vbase_init_result = NULL_TREE;
2802 dfs_walk (binfo, dfs_find_vbases, unmarked_vtable_pathp);
2803 dfs_walk (binfo, dfs_init_vbase_pointers, marked_vtable_pathp);
2804 dfs_walk (binfo, dfs_clear_vbase_slots, marked_new_vtablep);
2805 flag_this_is_variable = old_flag;
2806 return vbase_init_result;
2807 }
2808 return 0;
2809 }
2810
2811 /* get the virtual context (the vbase that directly contains the
2812 DECL_CLASS_CONTEXT of the FNDECL) that the given FNDECL is declared in,
2813 or NULL_TREE if there is none.
2814
2815 FNDECL must come from a virtual table from a virtual base to ensure that
2816 there is only one possible DECL_CLASS_CONTEXT.
2817
2818 We know that if there is more than one place (binfo) the fndecl that the
2819 declared, they all refer to the same binfo. See get_class_offset_1 for
2820 the check that ensures this. */
2821
2822 static tree
2823 virtual_context (fndecl, t, vbase)
2824 tree fndecl, t, vbase;
2825 {
2826 tree path;
2827 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl), t, 0, &path) < 0)
2828 {
2829 /* DECL_CLASS_CONTEXT can be ambiguous in t. */
2830 if (get_base_distance (DECL_CLASS_CONTEXT (fndecl), vbase, 0, &path) >= 0)
2831 {
2832 while (path)
2833 {
2834 /* Not sure if checking path == vbase is necessary here, but just in
2835 case it is. */
2836 if (TREE_VIA_VIRTUAL (path) || path == vbase)
2837 return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t));
2838 path = BINFO_INHERITANCE_CHAIN (path);
2839 }
2840 }
2841 /* This shouldn't happen, I don't want errors! */
2842 warning ("recoverable compiler error, fixups for virtual function");
2843 return vbase;
2844 }
2845 while (path)
2846 {
2847 if (TREE_VIA_VIRTUAL (path))
2848 return binfo_member (BINFO_TYPE (path), CLASSTYPE_VBASECLASSES (t));
2849 path = BINFO_INHERITANCE_CHAIN (path);
2850 }
2851 return 0;
2852 }
2853
2854 /* Fixups upcast offsets for one vtable.
2855 Entries may stay within the VBASE given, or
2856 they may upcast into a direct base, or
2857 they may upcast into a different vbase.
2858
2859 We only need to do fixups in case 2 and 3. In case 2, we add in
2860 the virtual base offset to effect an upcast, in case 3, we add in
2861 the virtual base offset to effect an upcast, then subtract out the
2862 offset for the other virtual base, to effect a downcast into it.
2863
2864 This routine mirrors fixup_vtable_deltas in functionality, though
2865 this one is runtime based, and the other is compile time based.
2866 Conceivably that routine could be removed entirely, and all fixups
2867 done at runtime.
2868
2869 VBASE_OFFSETS is an association list of virtual bases that contains
2870 offset information for the virtual bases, so the offsets are only
2871 calculated once. The offsets are computed by where we think the
2872 vbase should be (as noted by the CLASSTYPE_SEARCH_SLOT) minus where
2873 the vbase really is. */
2874
2875 static void
2876 expand_upcast_fixups (binfo, addr, orig_addr, vbase, vbase_addr, t,
2877 vbase_offsets)
2878 tree binfo, addr, orig_addr, vbase, vbase_addr, t, *vbase_offsets;
2879 {
2880 tree virtuals = BINFO_VIRTUALS (binfo);
2881 tree vc;
2882 tree delta;
2883 unsigned HOST_WIDE_INT n;
2884
2885 delta = purpose_member (vbase, *vbase_offsets);
2886 if (! delta)
2887 {
2888 delta = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vbase));
2889 delta = build (MINUS_EXPR, ptrdiff_type_node, delta, vbase_addr);
2890 delta = save_expr (delta);
2891 delta = tree_cons (vbase, delta, *vbase_offsets);
2892 *vbase_offsets = delta;
2893 }
2894
2895 n = skip_rtti_stuff (&virtuals);
2896
2897 while (virtuals)
2898 {
2899 tree current_fndecl = TREE_VALUE (virtuals);
2900 current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl);
2901 current_fndecl = TREE_OPERAND (current_fndecl, 0);
2902 if (current_fndecl
2903 && current_fndecl != abort_fndecl
2904 && (vc=virtual_context (current_fndecl, t, vbase)) != vbase)
2905 {
2906 /* This may in fact need a runtime fixup. */
2907 tree idx = build_int_2 (n, 0);
2908 tree vtbl = BINFO_VTABLE (binfo);
2909 tree nvtbl = lookup_name (DECL_NAME (vtbl), 0);
2910 tree aref, ref, naref;
2911 tree old_delta, new_delta;
2912 tree init;
2913
2914 if (nvtbl == NULL_TREE
2915 || nvtbl == IDENTIFIER_GLOBAL_VALUE (DECL_NAME (vtbl)))
2916 {
2917 /* Dup it if it isn't in local scope yet. */
2918 nvtbl = build_decl (VAR_DECL,
2919 DECL_NAME (vtbl),
2920 TYPE_MAIN_VARIANT (TREE_TYPE (BINFO_VTABLE (binfo))));
2921 DECL_ALIGN (nvtbl) = MAX (TYPE_ALIGN (double_type_node),
2922 DECL_ALIGN (nvtbl));
2923 TREE_READONLY (nvtbl) = 0;
2924 DECL_ARTIFICIAL (nvtbl) = 1;
2925 nvtbl = pushdecl (nvtbl);
2926 init = NULL_TREE;
2927 cp_finish_decl (nvtbl, init, NULL_TREE, 0, LOOKUP_ONLYCONVERTING);
2928 DECL_VIRTUAL_P (nvtbl) = 1;
2929 DECL_CONTEXT (nvtbl) = t;
2930 init = build (MODIFY_EXPR, TREE_TYPE (nvtbl),
2931 nvtbl, vtbl);
2932 TREE_SIDE_EFFECTS (init) = 1;
2933 expand_expr_stmt (init);
2934 /* Update the vtable pointers as necessary. */
2935 ref = build_vfield_ref (build_indirect_ref (addr, NULL_PTR), DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))));
2936 expand_expr_stmt (build_modify_expr (ref, NOP_EXPR,
2937 build_unary_op (ADDR_EXPR, nvtbl, 0)));
2938 }
2939 assemble_external (vtbl);
2940 aref = build_array_ref (vtbl, idx);
2941 naref = build_array_ref (nvtbl, idx);
2942 old_delta = build_component_ref (aref, delta_identifier, NULL_TREE, 0);
2943 new_delta = build_component_ref (naref, delta_identifier, NULL_TREE, 0);
2944
2945 /* This is a upcast, so we have to add the offset for the
2946 virtual base. */
2947 old_delta = build_binary_op (PLUS_EXPR, old_delta,
2948 TREE_VALUE (delta), 0);
2949 if (vc)
2950 {
2951 /* If this is set, we need to subtract out the delta
2952 adjustments for the other virtual base that we
2953 downcast into. */
2954 tree vc_delta = purpose_member (vc, *vbase_offsets);
2955 if (! vc_delta)
2956 {
2957 tree vc_addr = convert_pointer_to_real (vc, orig_addr);
2958 vc_delta = CLASSTYPE_SEARCH_SLOT (BINFO_TYPE (vc));
2959 vc_delta = build (MINUS_EXPR, ptrdiff_type_node,
2960 vc_delta, vc_addr);
2961 vc_delta = save_expr (vc_delta);
2962 *vbase_offsets = tree_cons (vc, vc_delta, *vbase_offsets);
2963 }
2964 else
2965 vc_delta = TREE_VALUE (vc_delta);
2966
2967 /* This is a downcast, so we have to subtract the offset
2968 for the virtual base. */
2969 old_delta = build_binary_op (MINUS_EXPR, old_delta, vc_delta, 0);
2970 }
2971
2972 TREE_READONLY (new_delta) = 0;
2973 expand_expr_stmt (build_modify_expr (new_delta, NOP_EXPR,
2974 old_delta));
2975 }
2976 ++n;
2977 virtuals = TREE_CHAIN (virtuals);
2978 }
2979 }
2980
2981 /* Fixup upcast offsets for all direct vtables. Patterned after
2982 expand_direct_vtbls_init. */
2983
2984 static void
2985 fixup_virtual_upcast_offsets (real_binfo, binfo, init_self, can_elide, addr, orig_addr, type, vbase, vbase_offsets)
2986 tree real_binfo, binfo;
2987 int init_self, can_elide;
2988 tree addr, orig_addr, type, vbase, *vbase_offsets;
2989 {
2990 tree real_binfos = BINFO_BASETYPES (real_binfo);
2991 tree binfos = BINFO_BASETYPES (binfo);
2992 int i, n_baselinks = real_binfos ? TREE_VEC_LENGTH (real_binfos) : 0;
2993
2994 for (i = 0; i < n_baselinks; i++)
2995 {
2996 tree real_base_binfo = TREE_VEC_ELT (real_binfos, i);
2997 tree base_binfo = TREE_VEC_ELT (binfos, i);
2998 int is_not_base_vtable
2999 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (real_binfo));
3000 if (! TREE_VIA_VIRTUAL (real_base_binfo))
3001 fixup_virtual_upcast_offsets (real_base_binfo, base_binfo,
3002 is_not_base_vtable, can_elide, addr,
3003 orig_addr, type, vbase, vbase_offsets);
3004 }
3005 #if 0
3006 /* Before turning this on, make sure it is correct. */
3007 if (can_elide && ! BINFO_MODIFIED (binfo))
3008 return;
3009 #endif
3010 /* Should we use something besides CLASSTYPE_VFIELDS? */
3011 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (real_binfo)))
3012 {
3013 tree new_addr = convert_pointer_to_real (binfo, addr);
3014 expand_upcast_fixups (real_binfo, new_addr, orig_addr, vbase, addr,
3015 type, vbase_offsets);
3016 }
3017 }
3018
3019 /* Build a COMPOUND_EXPR which when expanded will generate the code
3020 needed to initialize all the virtual function table slots of all
3021 the virtual baseclasses. MAIN_BINFO is the binfo which determines
3022 the virtual baseclasses to use; TYPE is the type of the object to
3023 which the initialization applies. TRUE_EXP is the true object we
3024 are initializing, and DECL_PTR is the pointer to the sub-object we
3025 are initializing.
3026
3027 When USE_COMPUTED_OFFSETS is non-zero, we can assume that the
3028 object was laid out by a top-level constructor and the computed
3029 offsets are valid to store vtables. When zero, we must store new
3030 vtables through virtual baseclass pointers.
3031
3032 We setup and use the globals: vbase_decl_ptr, vbase_types
3033 ICK! */
3034
3035 void
3036 expand_indirect_vtbls_init (binfo, true_exp, decl_ptr)
3037 tree binfo;
3038 tree true_exp, decl_ptr;
3039 {
3040 tree type = BINFO_TYPE (binfo);
3041
3042 if (TYPE_USES_VIRTUAL_BASECLASSES (type))
3043 {
3044 rtx fixup_insns = NULL_RTX;
3045 tree vbases = CLASSTYPE_VBASECLASSES (type);
3046 vbase_types = vbases;
3047 vbase_decl_ptr = true_exp ? build_unary_op (ADDR_EXPR, true_exp, 0) : decl_ptr;
3048
3049 dfs_walk (binfo, dfs_find_vbases, unmarked_new_vtablep);
3050
3051 /* Initialized with vtables of type TYPE. */
3052 for (; vbases; vbases = TREE_CHAIN (vbases))
3053 {
3054 tree addr;
3055
3056 addr = convert_pointer_to_vbase (TREE_TYPE (vbases), vbase_decl_ptr);
3057
3058 /* Do all vtables from this virtual base. */
3059 /* This assumes that virtual bases can never serve as parent
3060 binfos. (in the CLASSTYPE_VFIELD_PARENT sense) */
3061 expand_direct_vtbls_init (vbases, TYPE_BINFO (BINFO_TYPE (vbases)),
3062 1, 0, addr);
3063
3064 /* Now we adjust the offsets for virtual functions that
3065 cross virtual boundaries on an implicit upcast on vf call
3066 so that the layout of the most complete type is used,
3067 instead of assuming the layout of the virtual bases from
3068 our current type. */
3069
3070 if (flag_vtable_thunks)
3071 {
3072 /* We don't have dynamic thunks yet!
3073 So for now, just fail silently. */
3074 }
3075 else
3076 {
3077 tree vbase_offsets = NULL_TREE;
3078 push_to_sequence (fixup_insns);
3079 fixup_virtual_upcast_offsets (vbases,
3080 TYPE_BINFO (BINFO_TYPE (vbases)),
3081 1, 0, addr, vbase_decl_ptr,
3082 type, vbases, &vbase_offsets);
3083 fixup_insns = get_insns ();
3084 end_sequence ();
3085 }
3086 }
3087
3088 if (fixup_insns)
3089 {
3090 extern tree in_charge_identifier;
3091 tree in_charge_node = lookup_name (in_charge_identifier, 0);
3092 if (! in_charge_node)
3093 {
3094 warning ("recoverable internal compiler error, nobody's in charge!");
3095 in_charge_node = integer_zero_node;
3096 }
3097 in_charge_node = build_binary_op (EQ_EXPR, in_charge_node, integer_zero_node, 1);
3098 expand_start_cond (in_charge_node, 0);
3099 emit_insns (fixup_insns);
3100 expand_end_cond ();
3101 }
3102
3103 dfs_walk (binfo, dfs_clear_vbase_slots, marked_new_vtablep);
3104 }
3105 }
3106
3107 /* get virtual base class types.
3108 This adds type to the vbase_types list in reverse dfs order.
3109 Ordering is very important, so don't change it. */
3110
3111 static void
3112 dfs_get_vbase_types (binfo)
3113 tree binfo;
3114 {
3115 if (TREE_VIA_VIRTUAL (binfo) && ! BINFO_VBASE_MARKED (binfo))
3116 {
3117 vbase_types = make_binfo (integer_zero_node, binfo,
3118 BINFO_VTABLE (binfo),
3119 BINFO_VIRTUALS (binfo), vbase_types);
3120 TREE_VIA_VIRTUAL (vbase_types) = 1;
3121 SET_BINFO_VBASE_MARKED (binfo);
3122 }
3123 SET_BINFO_MARKED (binfo);
3124 }
3125
3126 /* get a list of virtual base classes in dfs order. */
3127
3128 tree
3129 get_vbase_types (type)
3130 tree type;
3131 {
3132 tree vbases;
3133 tree binfo;
3134
3135 if (TREE_CODE (type) == TREE_VEC)
3136 binfo = type;
3137 else
3138 binfo = TYPE_BINFO (type);
3139
3140 vbase_types = NULL_TREE;
3141 dfs_walk (binfo, dfs_get_vbase_types, unmarkedp);
3142 dfs_walk (binfo, dfs_unmark, markedp);
3143 /* Rely upon the reverse dfs ordering from dfs_get_vbase_types, and now
3144 reverse it so that we get normal dfs ordering. */
3145 vbase_types = nreverse (vbase_types);
3146
3147 /* unmark marked vbases */
3148 for (vbases = vbase_types; vbases; vbases = TREE_CHAIN (vbases))
3149 CLEAR_BINFO_VBASE_MARKED (vbases);
3150
3151 return vbase_types;
3152 }
3153 \f
3154 #ifdef MI_MATRIX
3155 static void
3156 dfs_record_inheritance (binfo)
3157 tree binfo;
3158 {
3159 tree binfos = BINFO_BASETYPES (binfo);
3160 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3161 mi_boolean *derived_row = BINFO_DERIVES_FROM_STAR (binfo);
3162
3163 for (i = n_baselinks-1; i >= 0; i--)
3164 {
3165 int j;
3166 tree base_binfo = TREE_VEC_ELT (binfos, i);
3167 tree baseclass = BINFO_TYPE (base_binfo);
3168 mi_boolean *base_row = BINFO_DERIVES_FROM_STAR (base_binfo);
3169
3170 if (TREE_CODE (baseclass) == TEMPLATE_TYPE_PARM
3171 || TREE_CODE (baseclass) == TEMPLATE_TEMPLATE_PARM)
3172 continue;
3173 my_friendly_assert (CLASSTYPE_CID (baseclass) != 0, 2365);
3174
3175 /* Don't search if there's nothing there! MI_SIZE can be
3176 zero as a result of parse errors. */
3177 if (TYPE_BINFO_BASETYPES (baseclass) && mi_size > 0)
3178 for (j = mi_size*(CLASSTYPE_CID (baseclass)-1); j >= 0; j -= mi_size)
3179 derived_row[j] |= base_row[j];
3180 TYPE_DERIVES_FROM (baseclass, BINFO_TYPE (binfo)) = 1;
3181 }
3182
3183 SET_BINFO_MARKED (binfo);
3184 }
3185
3186 /* Given a _CLASSTYPE node in a multiple inheritance lattice,
3187 convert the lattice into a simple relation such that,
3188 given to CIDs, C1 and C2, one can determine if C1 <= C2
3189 or C2 <= C1 or C1 <> C2.
3190
3191 Once constructed, we walk the lattice depth fisrt,
3192 applying various functions to elements as they are encountered.
3193
3194 We use xmalloc here, in case we want to randomly free these tables. */
3195
3196 #define SAVE_MI_MATRIX
3197
3198 void
3199 build_mi_matrix (type)
3200 tree type;
3201 {
3202 tree binfo = TYPE_BINFO (type);
3203 cid = 0;
3204
3205 #ifdef SAVE_MI_MATRIX
3206 if (CLASSTYPE_MI_MATRIX (type))
3207 {
3208 mi_size = CLASSTYPE_N_SUPERCLASSES (type) + CLASSTYPE_N_VBASECLASSES (type);
3209 mi_matrix = CLASSTYPE_MI_MATRIX (type);
3210 mi_type = type;
3211 dfs_walk (binfo, dfs_number, unnumberedp);
3212 return;
3213 }
3214 #endif
3215
3216 dfs_walk (binfo, dfs_number, unnumberedp);
3217
3218 mi_size = CLASSTYPE_N_SUPERCLASSES (type) + CLASSTYPE_N_VBASECLASSES (type);
3219 if (mi_size < (cid-1))
3220 mi_size = cid-1;
3221 mi_matrix = (char *)xmalloc ((mi_size + 1) * (mi_size + 1));
3222 mi_type = type;
3223 bzero (mi_matrix, (mi_size + 1) * (mi_size + 1));
3224 dfs_walk (binfo, dfs_record_inheritance, unmarkedp);
3225 dfs_walk (binfo, dfs_unmark, markedp);
3226 }
3227
3228 void
3229 free_mi_matrix ()
3230 {
3231 dfs_walk (TYPE_BINFO (mi_type), dfs_unnumber, numberedp);
3232
3233 #ifdef SAVE_MI_MATRIX
3234 CLASSTYPE_MI_MATRIX (mi_type) = mi_matrix;
3235 #else
3236 free (mi_matrix);
3237 mi_size = 0;
3238 cid = 0;
3239 #endif
3240 }
3241 #endif
3242 \f
3243 /* If we want debug info for a type TYPE, make sure all its base types
3244 are also marked as being potentially interesting. This avoids
3245 the problem of not writing any debug info for intermediate basetypes
3246 that have abstract virtual functions. Also mark member types. */
3247
3248 void
3249 note_debug_info_needed (type)
3250 tree type;
3251 {
3252 tree field;
3253
3254 if (current_template_parms)
3255 return;
3256
3257 if (TYPE_BEING_DEFINED (type))
3258 /* We can't go looking for the base types and fields just yet. */
3259 return;
3260
3261 /* We can't do the TYPE_DECL_SUPPRESS_DEBUG thing with DWARF, which
3262 does not support name references between translation units. Well, we
3263 could, but that would mean putting global labels in the debug output
3264 before each exported type and each of its functions and static data
3265 members. */
3266 if (write_symbols == DWARF_DEBUG || write_symbols == DWARF2_DEBUG)
3267 return;
3268
3269 dfs_walk (TYPE_BINFO (type), dfs_debug_mark, dfs_debug_unmarkedp);
3270 for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
3271 {
3272 tree ttype;
3273 if (TREE_CODE (field) == FIELD_DECL
3274 && IS_AGGR_TYPE (ttype = target_type (TREE_TYPE (field)))
3275 && dfs_debug_unmarkedp (TYPE_BINFO (ttype)))
3276 note_debug_info_needed (ttype);
3277 }
3278 }
3279 \f
3280 /* Subroutines of push_class_decls (). */
3281
3282 /* Add in a decl to the envelope. */
3283 static void
3284 envelope_add_decl (type, decl, values)
3285 tree type, decl, *values;
3286 {
3287 tree context, *tmp;
3288 tree name = DECL_NAME (decl);
3289 int dont_add = 0;
3290
3291 /* virtual base names are always unique. */
3292 if (VBASE_NAME_P (name))
3293 *values = NULL_TREE;
3294
3295 /* Possible ambiguity. If its defining type(s)
3296 is (are all) derived from us, no problem. */
3297 else if (*values && TREE_CODE (*values) != TREE_LIST)
3298 {
3299 tree value = *values;
3300 /* Only complain if we shadow something we can access. */
3301 if (warn_shadow && TREE_CODE (decl) == FUNCTION_DECL
3302 && ((DECL_LANG_SPECIFIC (*values)
3303 && DECL_CLASS_CONTEXT (value) == current_class_type)
3304 || ! TREE_PRIVATE (value)))
3305 /* Should figure out access control more accurately. */
3306 {
3307 cp_warning_at ("member `%#D' is shadowed", value);
3308 cp_warning_at ("by member function `%#D'", decl);
3309 warning ("in this context");
3310 }
3311
3312 context = (TREE_CODE (value) == FUNCTION_DECL
3313 && DECL_VIRTUAL_P (value))
3314 ? DECL_CLASS_CONTEXT (value)
3315 : DECL_CONTEXT (value);
3316
3317 if (context == type)
3318 {
3319 if (TREE_CODE (value) == TYPE_DECL
3320 && DECL_ARTIFICIAL (value))
3321 *values = NULL_TREE;
3322 else
3323 dont_add = 1;
3324 }
3325 else if (type == current_class_type
3326 #ifdef MI_MATRIX
3327 /* If we don't check CLASSTYPE_CID on CONTEXT right now,
3328 we'll end up subtracting from the address of MI_MATRIX,
3329 putting us off in la la land. */
3330 || (CLASSTYPE_CID (type)
3331 && TYPE_DERIVES_FROM (context, type))
3332 #else
3333 || DERIVED_FROM_P (context, type)
3334 #endif
3335 )
3336 {
3337 /* Don't add in *values to list */
3338 *values = NULL_TREE;
3339 }
3340 else
3341 *values = build_tree_list (NULL_TREE, value);
3342 }
3343 else
3344 for (tmp = values; *tmp;)
3345 {
3346 tree value = TREE_VALUE (*tmp);
3347 my_friendly_assert (TREE_CODE (value) != TREE_LIST, 999);
3348 context = (TREE_CODE (value) == FUNCTION_DECL
3349 && DECL_VIRTUAL_P (value))
3350 ? DECL_CLASS_CONTEXT (value)
3351 : DECL_CONTEXT (value);
3352
3353 if (type == current_class_type
3354 #ifdef MI_MATRIX
3355 /* If we don't check CLASSTYPE_CID on CONTEXT right now,
3356 we'll end up subtracting from the address of MI_MATRIX,
3357 putting us off in la la land. */
3358 || (CLASSTYPE_CID (type)
3359 && TYPE_DERIVES_FROM (context, type))
3360 #else
3361 || DERIVED_FROM_P (context, type)
3362 #endif
3363 )
3364 {
3365 /* remove *tmp from list */
3366 *tmp = TREE_CHAIN (*tmp);
3367 }
3368 else
3369 tmp = &TREE_CHAIN (*tmp);
3370 }
3371
3372 if (! dont_add)
3373 {
3374 /* Put the new contents in our envelope. */
3375 if (TREE_CODE (decl) == FUNCTION_DECL)
3376 {
3377 *values = tree_cons (name, decl, *values);
3378 TREE_NONLOCAL_FLAG (*values) = 1;
3379 TREE_TYPE (*values) = unknown_type_node;
3380 }
3381 else
3382 {
3383 if (*values)
3384 {
3385 *values = tree_cons (NULL_TREE, decl, *values);
3386 /* Mark this as a potentially ambiguous member. */
3387 /* Leaving TREE_TYPE blank is intentional.
3388 We cannot use `error_mark_node' (lookup_name)
3389 or `unknown_type_node' (all member functions use this). */
3390 TREE_NONLOCAL_FLAG (*values) = 1;
3391 }
3392 else
3393 *values = decl;
3394 }
3395 }
3396 }
3397
3398 /* Add the instance variables which this class contributed to the
3399 current class binding contour. When a redefinition occurs, if the
3400 redefinition is strictly within a single inheritance path, we just
3401 overwrite the old declaration with the new. If the fields are not
3402 within a single inheritance path, we must cons them.
3403
3404 In order to know what decls are new (stemming from the current
3405 invocation of push_class_decls) we enclose them in an "envelope",
3406 which is a TREE_LIST node where the TREE_PURPOSE slot contains the
3407 new decl (or possibly a list of competing ones), the TREE_VALUE slot
3408 points to the old value and the TREE_CHAIN slot chains together all
3409 envelopes which needs to be "opened" in push_class_decls. Opening an
3410 envelope means: push the old value onto the class_shadowed list,
3411 install the new one and if it's a TYPE_DECL do the same to the
3412 IDENTIFIER_TYPE_VALUE. Such an envelope is recognized by seeing that
3413 the TREE_PURPOSE slot is non-null, and that it is not an identifier.
3414 Because if it is, it could be a set of overloaded methods from an
3415 outer scope. */
3416
3417 static void
3418 dfs_pushdecls (binfo)
3419 tree binfo;
3420 {
3421 tree type = BINFO_TYPE (binfo);
3422 tree fields, *methods, *end;
3423 tree method_vec;
3424
3425 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
3426 {
3427 /* Unmark so that if we are in a constructor, and then find that
3428 this field was initialized by a base initializer,
3429 we can emit an error message. */
3430 if (TREE_CODE (fields) == FIELD_DECL)
3431 TREE_USED (fields) = 0;
3432
3433 /* Recurse into anonymous unions. */
3434 if (DECL_NAME (fields) == NULL_TREE
3435 && TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE)
3436 {
3437 dfs_pushdecls (TYPE_BINFO (TREE_TYPE (fields)));
3438 continue;
3439 }
3440
3441 if (DECL_NAME (fields))
3442 {
3443 tree name = DECL_NAME (fields);
3444 tree class_value = IDENTIFIER_CLASS_VALUE (name);
3445
3446 /* If the class value is not an envelope of the kind described in
3447 the comment above, we create a new envelope. */
3448 if (class_value == NULL_TREE || TREE_CODE (class_value) != TREE_LIST
3449 || TREE_PURPOSE (class_value) == NULL_TREE
3450 || TREE_CODE (TREE_PURPOSE (class_value)) == IDENTIFIER_NODE)
3451 {
3452 /* See comment above for a description of envelopes. */
3453 closed_envelopes = tree_cons (NULL_TREE, class_value,
3454 closed_envelopes);
3455 IDENTIFIER_CLASS_VALUE (name) = closed_envelopes;
3456 class_value = IDENTIFIER_CLASS_VALUE (name);
3457 }
3458
3459 envelope_add_decl (type, fields, &TREE_PURPOSE (class_value));
3460 }
3461 }
3462
3463 method_vec = CLASSTYPE_METHOD_VEC (type);
3464 if (method_vec)
3465 {
3466 /* Farm out constructors and destructors. */
3467 methods = &TREE_VEC_ELT (method_vec, 2);
3468 end = TREE_VEC_END (method_vec);
3469
3470 while (methods != end)
3471 {
3472 /* This will cause lookup_name to return a pointer
3473 to the tree_list of possible methods of this name. */
3474 tree name = DECL_NAME (*methods);
3475 tree class_value = IDENTIFIER_CLASS_VALUE (name);
3476
3477 /* If the class value is not an envelope of the kind described in
3478 the comment above, we create a new envelope. */
3479 if (class_value == NULL_TREE || TREE_CODE (class_value) != TREE_LIST
3480 || TREE_PURPOSE (class_value) == NULL_TREE
3481 || TREE_CODE (TREE_PURPOSE (class_value)) == IDENTIFIER_NODE)
3482 {
3483 /* See comment above for a description of envelopes. */
3484 closed_envelopes = tree_cons (NULL_TREE, class_value,
3485 closed_envelopes);
3486 IDENTIFIER_CLASS_VALUE (name) = closed_envelopes;
3487 class_value = IDENTIFIER_CLASS_VALUE (name);
3488 }
3489
3490 /* Here we try to rule out possible ambiguities.
3491 If we can't do that, keep a TREE_LIST with possibly ambiguous
3492 decls in there. */
3493 maybe_push_cache_obstack ();
3494 envelope_add_decl (type, *methods, &TREE_PURPOSE (class_value));
3495 pop_obstacks ();
3496
3497 methods++;
3498 }
3499 }
3500 SET_BINFO_MARKED (binfo);
3501 }
3502
3503 /* Consolidate unique (by name) member functions. */
3504
3505 static void
3506 dfs_compress_decls (binfo)
3507 tree binfo;
3508 {
3509 tree type = BINFO_TYPE (binfo);
3510 tree method_vec = CLASSTYPE_METHOD_VEC (type);
3511
3512 if (method_vec != 0)
3513 {
3514 /* Farm out constructors and destructors. */
3515 tree *methods = &TREE_VEC_ELT (method_vec, 2);
3516 tree *end = TREE_VEC_END (method_vec);
3517
3518 for (; methods != end; methods++)
3519 {
3520 /* This is known to be an envelope of the kind described before
3521 dfs_pushdecls. */
3522 tree class_value = IDENTIFIER_CLASS_VALUE (DECL_NAME (*methods));
3523 tree tmp = TREE_PURPOSE (class_value);
3524
3525 /* This was replaced in scope by somebody else. Just leave it
3526 alone. */
3527 if (TREE_CODE (tmp) != TREE_LIST)
3528 continue;
3529
3530 if (TREE_CHAIN (tmp) == NULL_TREE
3531 && TREE_VALUE (tmp)
3532 && DECL_CHAIN (TREE_VALUE (tmp)) == NULL_TREE)
3533 {
3534 TREE_PURPOSE (class_value) = TREE_VALUE (tmp);
3535 }
3536 }
3537 }
3538 CLEAR_BINFO_MARKED (binfo);
3539 }
3540
3541 /* When entering the scope of a class, we cache all of the
3542 fields that that class provides within its inheritance
3543 lattice. Where ambiguities result, we mark them
3544 with `error_mark_node' so that if they are encountered
3545 without explicit qualification, we can emit an error
3546 message. */
3547
3548 void
3549 push_class_decls (type)
3550 tree type;
3551 {
3552 struct obstack *ambient_obstack = current_obstack;
3553 search_stack = push_search_level (search_stack, &search_obstack);
3554
3555 /* Push class fields into CLASS_VALUE scope, and mark. */
3556 dfs_walk (TYPE_BINFO (type), dfs_pushdecls, unmarkedp);
3557
3558 /* Compress fields which have only a single entry
3559 by a given name, and unmark. */
3560 dfs_walk (TYPE_BINFO (type), dfs_compress_decls, markedp);
3561
3562 /* Open up all the closed envelopes and push the contained decls into
3563 class scope. */
3564 while (closed_envelopes)
3565 {
3566 tree new = TREE_PURPOSE (closed_envelopes);
3567 tree id;
3568
3569 /* This is messy because the class value may be a *_DECL, or a
3570 TREE_LIST of overloaded *_DECLs or even a TREE_LIST of ambiguous
3571 *_DECLs. The name is stored at different places in these three
3572 cases. */
3573 if (TREE_CODE (new) == TREE_LIST)
3574 {
3575 if (TREE_PURPOSE (new) != NULL_TREE)
3576 id = TREE_PURPOSE (new);
3577 else
3578 {
3579 tree node = TREE_VALUE (new);
3580
3581 if (TREE_CODE (node) == TYPE_DECL
3582 && DECL_ARTIFICIAL (node)
3583 && IS_AGGR_TYPE (TREE_TYPE (node))
3584 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (node)))
3585 {
3586 tree t = CLASSTYPE_TI_TEMPLATE (TREE_TYPE (node));
3587 tree n = new;
3588
3589 for (; n; n = TREE_CHAIN (n))
3590 {
3591 tree d = TREE_VALUE (n);
3592 if (TREE_CODE (d) == TYPE_DECL
3593 && DECL_ARTIFICIAL (node)
3594 && IS_AGGR_TYPE (TREE_TYPE (d))
3595 && CLASSTYPE_TEMPLATE_INFO (TREE_TYPE (d))
3596 && CLASSTYPE_TI_TEMPLATE (TREE_TYPE (d)) == t)
3597 /* OK */;
3598 else
3599 break;
3600 }
3601
3602 if (n == NULL_TREE)
3603 new = t;
3604 }
3605 else while (TREE_CODE (node) == TREE_LIST)
3606 node = TREE_VALUE (node);
3607 id = DECL_NAME (node);
3608 }
3609 }
3610 else
3611 id = DECL_NAME (new);
3612
3613 /* Install the original class value in order to make
3614 pushdecl_class_level work correctly. */
3615 IDENTIFIER_CLASS_VALUE (id) = TREE_VALUE (closed_envelopes);
3616 if (TREE_CODE (new) == TREE_LIST)
3617 push_class_level_binding (id, new);
3618 else
3619 pushdecl_class_level (new);
3620 closed_envelopes = TREE_CHAIN (closed_envelopes);
3621 }
3622 current_obstack = ambient_obstack;
3623 }
3624
3625 /* Here's a subroutine we need because C lacks lambdas. */
3626
3627 static void
3628 dfs_unuse_fields (binfo)
3629 tree binfo;
3630 {
3631 tree type = TREE_TYPE (binfo);
3632 tree fields;
3633
3634 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
3635 {
3636 if (TREE_CODE (fields) != FIELD_DECL)
3637 continue;
3638
3639 TREE_USED (fields) = 0;
3640 if (DECL_NAME (fields) == NULL_TREE
3641 && TREE_CODE (TREE_TYPE (fields)) == UNION_TYPE)
3642 unuse_fields (TREE_TYPE (fields));
3643 }
3644 }
3645
3646 void
3647 unuse_fields (type)
3648 tree type;
3649 {
3650 dfs_walk (TYPE_BINFO (type), dfs_unuse_fields, unmarkedp);
3651 }
3652
3653 void
3654 pop_class_decls ()
3655 {
3656 /* We haven't pushed a search level when dealing with cached classes,
3657 so we'd better not try to pop it. */
3658 if (search_stack)
3659 search_stack = pop_search_level (search_stack);
3660 }
3661
3662 void
3663 print_search_statistics ()
3664 {
3665 #ifdef GATHER_STATISTICS
3666 if (flag_memoize_lookups)
3667 {
3668 fprintf (stderr, "%d memoized contexts saved\n",
3669 n_contexts_saved);
3670 fprintf (stderr, "%d local tree nodes made\n", my_tree_node_counter);
3671 fprintf (stderr, "%d local hash nodes made\n", my_memoized_entry_counter);
3672 fprintf (stderr, "fields statistics:\n");
3673 fprintf (stderr, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3674 memoized_fast_finds[0], memoized_fast_rejects[0],
3675 memoized_fields_searched[0]);
3676 fprintf (stderr, " memoized_adds = %d\n", memoized_adds[0]);
3677 fprintf (stderr, "fnfields statistics:\n");
3678 fprintf (stderr, " memoized finds = %d; rejects = %d; (searches = %d)\n",
3679 memoized_fast_finds[1], memoized_fast_rejects[1],
3680 memoized_fields_searched[1]);
3681 fprintf (stderr, " memoized_adds = %d\n", memoized_adds[1]);
3682 }
3683 fprintf (stderr, "%d fields searched in %d[%d] calls to lookup_field[_1]\n",
3684 n_fields_searched, n_calls_lookup_field, n_calls_lookup_field_1);
3685 fprintf (stderr, "%d fnfields searched in %d calls to lookup_fnfields\n",
3686 n_outer_fields_searched, n_calls_lookup_fnfields);
3687 fprintf (stderr, "%d calls to get_base_type\n", n_calls_get_base_type);
3688 #else /* GATHER_STATISTICS */
3689 fprintf (stderr, "no search statistics\n");
3690 #endif /* GATHER_STATISTICS */
3691 }
3692
3693 void
3694 init_search_processing ()
3695 {
3696 gcc_obstack_init (&search_obstack);
3697 gcc_obstack_init (&type_obstack);
3698 gcc_obstack_init (&type_obstack_entries);
3699
3700 /* This gives us room to build our chains of basetypes,
3701 whether or not we decide to memoize them. */
3702 type_stack = push_type_level ((struct stack_level *)0, &type_obstack);
3703 _vptr_name = get_identifier ("_vptr");
3704 }
3705
3706 void
3707 reinit_search_statistics ()
3708 {
3709 my_memoized_entry_counter = 0;
3710 memoized_fast_finds[0] = 0;
3711 memoized_fast_finds[1] = 0;
3712 memoized_adds[0] = 0;
3713 memoized_adds[1] = 0;
3714 memoized_fast_rejects[0] = 0;
3715 memoized_fast_rejects[1] = 0;
3716 memoized_fields_searched[0] = 0;
3717 memoized_fields_searched[1] = 0;
3718 #ifdef GATHER_STATISTICS
3719 n_fields_searched = 0;
3720 n_calls_lookup_field = 0, n_calls_lookup_field_1 = 0;
3721 n_calls_lookup_fnfields = 0, n_calls_lookup_fnfields_1 = 0;
3722 n_calls_get_base_type = 0;
3723 n_outer_fields_searched = 0;
3724 n_contexts_saved = 0;
3725 #endif /* GATHER_STATISTICS */
3726 }
3727
3728 #define scratch_tree_cons expr_tree_cons
3729
3730 static tree conversions;
3731 static void
3732 add_conversions (binfo)
3733 tree binfo;
3734 {
3735 int i;
3736 tree method_vec = CLASSTYPE_METHOD_VEC (BINFO_TYPE (binfo));
3737
3738 for (i = 2; i < TREE_VEC_LENGTH (method_vec); ++i)
3739 {
3740 tree tmp = TREE_VEC_ELT (method_vec, i);
3741 if (! IDENTIFIER_TYPENAME_P (DECL_NAME (tmp)))
3742 break;
3743 conversions = scratch_tree_cons (binfo, tmp, conversions);
3744 }
3745 SET_BINFO_MARKED (binfo);
3746 }
3747
3748 tree
3749 lookup_conversions (type)
3750 tree type;
3751 {
3752 conversions = NULL_TREE;
3753 if (TYPE_SIZE (type))
3754 {
3755 dfs_walk (TYPE_BINFO (type), add_conversions, unmarkedp);
3756 dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp);
3757 }
3758 return conversions;
3759 }
3760
3761 /* Subroutine of get_template_base. */
3762
3763 static tree
3764 get_template_base_recursive (binfo, rval, template, via_virtual)
3765 tree binfo, template, rval;
3766 int via_virtual;
3767 {
3768 tree binfos;
3769 int i, n_baselinks;
3770 tree type = BINFO_TYPE (binfo);
3771
3772 if (CLASSTYPE_TEMPLATE_INFO (type)
3773 && CLASSTYPE_TI_TEMPLATE (type) == template)
3774 {
3775 if (rval == NULL_TREE || rval == type)
3776 return type;
3777 else
3778 return error_mark_node;
3779 }
3780
3781 binfos = BINFO_BASETYPES (binfo);
3782 n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3783
3784 /* Process base types. */
3785 for (i = 0; i < n_baselinks; i++)
3786 {
3787 tree base_binfo = TREE_VEC_ELT (binfos, i);
3788
3789 /* Find any specific instance of a virtual base, when searching with
3790 a binfo... */
3791 if (BINFO_MARKED (base_binfo) == 0)
3792 {
3793 int this_virtual = via_virtual || TREE_VIA_VIRTUAL (base_binfo);
3794
3795 /* When searching for a non-virtual, we cannot mark
3796 virtually found binfos. */
3797 if (! this_virtual)
3798 SET_BINFO_MARKED (base_binfo);
3799
3800 rval = get_template_base_recursive
3801 (base_binfo, rval, template, this_virtual);
3802 if (rval == error_mark_node)
3803 return rval;
3804 }
3805 }
3806
3807 return rval;
3808 }
3809
3810 /* Given a class template TEMPLATE and a class type or binfo node BINFO,
3811 find the unique base type in BINFO that is an instance of TEMPLATE.
3812 If there are more than one, return error_mark_node. Used by unify. */
3813
3814 tree
3815 get_template_base (template, binfo)
3816 register tree template, binfo;
3817 {
3818 tree type = NULL_TREE, rval;
3819
3820 if (TREE_CODE (binfo) == TREE_VEC)
3821 type = BINFO_TYPE (binfo);
3822 else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo)))
3823 {
3824 type = complete_type (binfo);
3825 binfo = TYPE_BINFO (type);
3826 }
3827 else
3828 my_friendly_abort (92);
3829
3830 if (CLASSTYPE_TEMPLATE_INFO (type)
3831 && CLASSTYPE_TI_TEMPLATE (type) == template)
3832 return type;
3833
3834 rval = get_template_base_recursive (binfo, NULL_TREE, template, 0);
3835 dfs_walk (binfo, dfs_unmark, markedp);
3836
3837 return rval;
3838 }
3839
3840 /* Check whether the empty class indicated by EMPTY_BINFO is also present
3841 at offset 0 in COMPARE_TYPE, and set found_overlap if so. */
3842
3843 static tree compare_type;
3844 static int found_overlap;
3845 static void
3846 dfs_check_overlap (empty_binfo)
3847 tree empty_binfo;
3848 {
3849 tree binfo;
3850 for (binfo = TYPE_BINFO (compare_type); ; binfo = BINFO_BASETYPE (binfo, 0))
3851 {
3852 if (BINFO_TYPE (binfo) == BINFO_TYPE (empty_binfo))
3853 {
3854 found_overlap = 1;
3855 break;
3856 }
3857 else if (BINFO_BASETYPES (binfo) == NULL_TREE)
3858 break;
3859 }
3860 }
3861
3862 /* Trivial function to stop base traversal when we find something. */
3863
3864 static int
3865 dfs_no_overlap_yet (t)
3866 tree t;
3867 {
3868 return found_overlap == 0;
3869 }
3870
3871 /* Returns nonzero if EMPTY_TYPE or any of its bases can also be found at
3872 offset 0 in NEXT_TYPE. Used in laying out empty base class subobjects. */
3873
3874 int
3875 types_overlap_p (empty_type, next_type)
3876 tree empty_type, next_type;
3877 {
3878 if (! IS_AGGR_TYPE (next_type))
3879 return 0;
3880 compare_type = next_type;
3881 found_overlap = 0;
3882 dfs_walk (TYPE_BINFO (empty_type), dfs_check_overlap, dfs_no_overlap_yet);
3883 return found_overlap;
3884 }
This page took 0.18742 seconds and 6 git commands to generate.