]> gcc.gnu.org Git - gcc.git/blob - gcc/cp/class.c
decl.c (tag_name): New fn.
[gcc.git] / gcc / cp / class.c
1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
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 "flags.h"
30 #include "rtl.h"
31 #include "output.h"
32 #include "toplev.h"
33
34 #include "obstack.h"
35 #define obstack_chunk_alloc xmalloc
36 #define obstack_chunk_free free
37
38 extern struct obstack permanent_obstack;
39
40 /* This is how we tell when two virtual member functions are really the
41 same. */
42 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
43
44 extern void set_class_shadows PROTO ((tree));
45
46 /* The number of nested classes being processed. If we are not in the
47 scope of any class, this is zero. */
48
49 int current_class_depth;
50
51 /* In order to deal with nested classes, we keep a stack of classes.
52 The topmost entry is the innermost class, and is the entry at index
53 CURRENT_CLASS_DEPTH */
54
55 typedef struct class_stack_node {
56 /* The name of the class. */
57 tree name;
58
59 /* The _TYPE node for the class. */
60 tree type;
61
62 /* The access specifier pending for new declarations in the scope of
63 this class. */
64 tree access;
65 }* class_stack_node_t;
66
67 /* The stack itself. This is an dynamically resized array. The
68 number of elements allocated is CURRENT_CLASS_STACK_SIZE. */
69 static int current_class_stack_size;
70 static class_stack_node_t current_class_stack;
71
72 /* When we're processing a member function, current_class_ptr is the
73 PARM_DECL for the `this' pointer. The current_class_ref is an
74 expression for `*this'. */
75 tree current_class_ptr, current_class_ref;
76
77 /* The following two can be derived from the previous one */
78 tree current_class_name; /* IDENTIFIER_NODE: name of current class */
79 tree current_class_type; /* _TYPE: the type of the current class */
80 tree current_access_specifier;
81 tree previous_class_type; /* _TYPE: the previous type that was a class */
82 tree previous_class_values; /* TREE_LIST: copy of the class_shadowed list
83 when leaving an outermost class scope. */
84
85 /* The obstack on which the cached class declarations are kept. */
86 static struct obstack class_cache_obstack;
87 /* The first object allocated on that obstack. We can use
88 obstack_free with tis value to free the entire obstack. */
89 static char *class_cache_firstobj;
90
91 struct base_info;
92
93 static tree get_vfield_name PROTO((tree));
94 static void finish_struct_anon PROTO((tree));
95 static tree build_vbase_pointer PROTO((tree, tree));
96 static tree build_vtable_entry PROTO((tree, tree));
97 static tree get_vtable_name PROTO((tree));
98 static tree get_derived_offset PROTO((tree, tree));
99 static tree get_basefndecls PROTO((tree, tree));
100 static void set_rtti_entry PROTO((tree, tree, tree));
101 static tree build_vtable PROTO((tree, tree));
102 static void prepare_fresh_vtable PROTO((tree, tree));
103 static void fixup_vtable_deltas1 PROTO((tree, tree));
104 static void fixup_vtable_deltas PROTO((tree, int, tree));
105 static void finish_vtbls PROTO((tree, int, tree));
106 static void modify_vtable_entry PROTO((tree, tree, tree));
107 static tree get_vtable_entry_n PROTO((tree, unsigned HOST_WIDE_INT));
108 static void add_virtual_function PROTO((tree *, tree *, int *, tree, tree));
109 static tree delete_duplicate_fields_1 PROTO((tree, tree));
110 static void delete_duplicate_fields PROTO((tree));
111 static void finish_struct_bits PROTO((tree, int));
112 static int alter_access PROTO((tree, tree, tree, tree));
113 static void handle_using_decl PROTO((tree, tree, tree, tree));
114 static int overrides PROTO((tree, tree));
115 static int strictly_overrides PROTO((tree, tree));
116 static void merge_overrides PROTO((tree, tree, int, tree));
117 static void override_one_vtable PROTO((tree, tree, tree));
118 static void mark_overriders PROTO((tree, tree));
119 static void check_for_override PROTO((tree, tree));
120 static tree maybe_fixup_vptrs PROTO((tree, tree, tree));
121 static tree get_class_offset_1 PROTO((tree, tree, tree, tree, tree));
122 static tree get_class_offset PROTO((tree, tree, tree, tree));
123 static void modify_one_vtable PROTO((tree, tree, tree, tree));
124 static void modify_all_vtables PROTO((tree, tree, tree));
125 static void modify_all_direct_vtables PROTO((tree, int, tree, tree,
126 tree));
127 static void modify_all_indirect_vtables PROTO((tree, int, int, tree,
128 tree, tree));
129 static void build_class_init_list PROTO((tree));
130 static int finish_base_struct PROTO((tree, struct base_info *));
131 static void finish_struct_methods PROTO((tree));
132 static void maybe_warn_about_overly_private_class PROTO ((tree));
133 static void check_member_decl_is_same_in_complete_scope PROTO((tree, tree));
134 static tree make_method_vec PROTO((int));
135 static void free_method_vec PROTO((tree));
136 static tree add_implicitly_declared_members PROTO((tree, int, int, int));
137
138 /* Way of stacking language names. */
139 tree *current_lang_base, *current_lang_stack;
140 int current_lang_stacksize;
141
142 /* Names of languages we recognize. */
143 tree lang_name_c, lang_name_cplusplus, lang_name_java;
144 tree current_lang_name;
145
146 /* When layout out an aggregate type, the size of the
147 basetypes (virtual and non-virtual) is passed to layout_record
148 via this node. */
149 static tree base_layout_decl;
150
151 /* Constants used for access control. */
152 tree access_default_node; /* 0 */
153 tree access_public_node; /* 1 */
154 tree access_protected_node; /* 2 */
155 tree access_private_node; /* 3 */
156 tree access_default_virtual_node; /* 4 */
157 tree access_public_virtual_node; /* 5 */
158 tree access_protected_virtual_node; /* 6 */
159 tree access_private_virtual_node; /* 7 */
160
161 /* Variables shared between class.c and call.c. */
162
163 #ifdef GATHER_STATISTICS
164 int n_vtables = 0;
165 int n_vtable_entries = 0;
166 int n_vtable_searches = 0;
167 int n_vtable_elems = 0;
168 int n_convert_harshness = 0;
169 int n_compute_conversion_costs = 0;
170 int n_build_method_call = 0;
171 int n_inner_fields_searched = 0;
172 #endif
173
174 /* Virtual baseclass things. */
175
176 static tree
177 build_vbase_pointer (exp, type)
178 tree exp, type;
179 {
180 char *name;
181 FORMAT_VBASE_NAME (name, type);
182
183 return build_component_ref (exp, get_identifier (name), NULL_TREE, 0);
184 }
185
186 #if 0
187 /* Is the type of the EXPR, the complete type of the object?
188 If we are going to be wrong, we must be conservative, and return 0. */
189
190 static int
191 complete_type_p (expr)
192 tree expr;
193 {
194 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
195 while (1)
196 {
197 switch (TREE_CODE (expr))
198 {
199 case SAVE_EXPR:
200 case INDIRECT_REF:
201 case ADDR_EXPR:
202 case NOP_EXPR:
203 case CONVERT_EXPR:
204 expr = TREE_OPERAND (expr, 0);
205 continue;
206
207 case CALL_EXPR:
208 if (! TREE_HAS_CONSTRUCTOR (expr))
209 break;
210 /* fall through... */
211 case VAR_DECL:
212 case FIELD_DECL:
213 if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
214 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr)))
215 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
216 return 1;
217 /* fall through... */
218 case TARGET_EXPR:
219 case PARM_DECL:
220 if (IS_AGGR_TYPE (TREE_TYPE (expr))
221 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
222 return 1;
223 /* fall through... */
224 case PLUS_EXPR:
225 default:
226 break;
227 }
228 break;
229 }
230 return 0;
231 }
232 #endif
233
234 /* Build multi-level access to EXPR using hierarchy path PATH.
235 CODE is PLUS_EXPR if we are going with the grain,
236 and MINUS_EXPR if we are not (in which case, we cannot traverse
237 virtual baseclass links).
238
239 TYPE is the type we want this path to have on exit.
240
241 NONNULL is non-zero if we know (for any reason) that EXPR is
242 not, in fact, zero. */
243
244 tree
245 build_vbase_path (code, type, expr, path, nonnull)
246 enum tree_code code;
247 tree type, expr, path;
248 int nonnull;
249 {
250 register int changed = 0;
251 tree last = NULL_TREE, last_virtual = NULL_TREE;
252 int fixed_type_p;
253 tree null_expr = 0, nonnull_expr;
254 tree basetype;
255 tree offset = integer_zero_node;
256
257 if (BINFO_INHERITANCE_CHAIN (path) == NULL_TREE)
258 return build1 (NOP_EXPR, type, expr);
259
260 /* If -fthis-is-variable, we might have set nonnull incorrectly. We
261 don't care enough to get this right, so just clear it. */
262 if (flag_this_is_variable > 0)
263 nonnull = 0;
264
265 /* We could do better if we had additional logic to convert back to the
266 unconverted type (the static type of the complete object), and then
267 convert back to the type we want. Until that is done, we only optimize
268 if the complete type is the same type as expr has. */
269 fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
270
271 if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
272 expr = save_expr (expr);
273 nonnull_expr = expr;
274
275 if (BINFO_INHERITANCE_CHAIN (path))
276 path = reverse_path (path);
277
278 basetype = BINFO_TYPE (path);
279
280 while (path)
281 {
282 if (TREE_VIA_VIRTUAL (path))
283 {
284 last_virtual = BINFO_TYPE (path);
285 if (code == PLUS_EXPR)
286 {
287 changed = ! fixed_type_p;
288
289 if (changed)
290 {
291 tree ind;
292
293 /* We already check for ambiguous things in the caller, just
294 find a path. */
295 if (last)
296 {
297 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0);
298 nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr);
299 }
300 ind = build_indirect_ref (nonnull_expr, NULL_PTR);
301 nonnull_expr = build_vbase_pointer (ind, last_virtual);
302 if (nonnull == 0
303 && TREE_CODE (type) == POINTER_TYPE
304 && null_expr == NULL_TREE)
305 {
306 null_expr = build1 (NOP_EXPR, build_pointer_type (last_virtual), integer_zero_node);
307 expr = build (COND_EXPR, build_pointer_type (last_virtual),
308 build (EQ_EXPR, boolean_type_node, expr,
309 integer_zero_node),
310 null_expr, nonnull_expr);
311 }
312 }
313 /* else we'll figure out the offset below. */
314
315 /* Happens in the case of parse errors. */
316 if (nonnull_expr == error_mark_node)
317 return error_mark_node;
318 }
319 else
320 {
321 cp_error ("cannot cast up from virtual baseclass `%T'",
322 last_virtual);
323 return error_mark_node;
324 }
325 }
326 last = path;
327 path = BINFO_INHERITANCE_CHAIN (path);
328 }
329 /* LAST is now the last basetype assoc on the path. */
330
331 /* A pointer to a virtual base member of a non-null object
332 is non-null. Therefore, we only need to test for zeroness once.
333 Make EXPR the canonical expression to deal with here. */
334 if (null_expr)
335 {
336 TREE_OPERAND (expr, 2) = nonnull_expr;
337 TREE_TYPE (expr) = TREE_TYPE (TREE_OPERAND (expr, 1))
338 = TREE_TYPE (nonnull_expr);
339 }
340 else
341 expr = nonnull_expr;
342
343 /* If we go through any virtual base pointers, make sure that
344 casts to BASETYPE from the last virtual base class use
345 the right value for BASETYPE. */
346 if (changed)
347 {
348 tree intype = TREE_TYPE (TREE_TYPE (expr));
349 if (TYPE_MAIN_VARIANT (intype) != BINFO_TYPE (last))
350 {
351 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0);
352 offset = BINFO_OFFSET (binfo);
353 }
354 }
355 else
356 {
357 if (last_virtual)
358 {
359 offset = BINFO_OFFSET (binfo_member (last_virtual,
360 CLASSTYPE_VBASECLASSES (basetype)));
361 offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last));
362 }
363 else
364 offset = BINFO_OFFSET (last);
365 }
366
367 if (TREE_INT_CST_LOW (offset))
368 {
369 /* Bash types to make the backend happy. */
370 offset = cp_convert (type, offset);
371 #if 0
372 /* This shouldn't be necessary. (mrs) */
373 expr = build1 (NOP_EXPR, type, expr);
374 #endif
375
376 /* If expr might be 0, we need to preserve that zeroness. */
377 if (nonnull == 0)
378 {
379 if (null_expr)
380 TREE_TYPE (null_expr) = type;
381 else
382 null_expr = build1 (NOP_EXPR, type, integer_zero_node);
383 if (TREE_SIDE_EFFECTS (expr))
384 expr = save_expr (expr);
385
386 return build (COND_EXPR, type,
387 build (EQ_EXPR, boolean_type_node, expr, integer_zero_node),
388 null_expr,
389 build (code, type, expr, offset));
390 }
391 else return build (code, type, expr, offset);
392 }
393
394 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
395 be used multiple times in initialization of multiple inheritance. */
396 if (null_expr)
397 {
398 TREE_TYPE (expr) = type;
399 return expr;
400 }
401 else
402 return build1 (NOP_EXPR, type, expr);
403 }
404
405 /* Virtual function things. */
406
407 /* Build an entry in the virtual function table.
408 DELTA is the offset for the `this' pointer.
409 PFN is an ADDR_EXPR containing a pointer to the virtual function.
410 Note that the index (DELTA2) in the virtual function table
411 is always 0. */
412
413 static tree
414 build_vtable_entry (delta, pfn)
415 tree delta, pfn;
416 {
417 if (flag_vtable_thunks)
418 {
419 HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta);
420 if (idelta && ! DECL_ABSTRACT_VIRTUAL_P (TREE_OPERAND (pfn, 0)))
421 {
422 pfn = build1 (ADDR_EXPR, vtable_entry_type,
423 make_thunk (pfn, idelta));
424 TREE_READONLY (pfn) = 1;
425 TREE_CONSTANT (pfn) = 1;
426 }
427 #ifdef GATHER_STATISTICS
428 n_vtable_entries += 1;
429 #endif
430 return pfn;
431 }
432 else
433 {
434 extern int flag_huge_objects;
435 tree elems = expr_tree_cons (NULL_TREE, delta,
436 expr_tree_cons (NULL_TREE, integer_zero_node,
437 build_expr_list (NULL_TREE, pfn)));
438 tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
439
440 /* DELTA used to be constructed by `size_int' and/or size_binop,
441 which caused overflow problems when it was negative. That should
442 be fixed now. */
443
444 if (! int_fits_type_p (delta, delta_type_node))
445 {
446 if (flag_huge_objects)
447 sorry ("object size exceeds built-in limit for virtual function table implementation");
448 else
449 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
450 }
451
452 TREE_CONSTANT (entry) = 1;
453 TREE_STATIC (entry) = 1;
454 TREE_READONLY (entry) = 1;
455
456 #ifdef GATHER_STATISTICS
457 n_vtable_entries += 1;
458 #endif
459
460 return entry;
461 }
462 }
463
464 /* We want to give the assembler the vtable identifier as well as
465 the offset to the function pointer. So we generate
466
467 __asm__ __volatile__ (".vtable_entry %c0, %c1"
468 : : "s"(&class_vtable),
469 "i"((long)&vtbl[idx].pfn - (long)&vtbl[0])); */
470
471 static void
472 build_vtable_entry_ref (basetype, vtbl, idx)
473 tree basetype, vtbl, idx;
474 {
475 static char asm_stmt[] = ".vtable_entry %c0, %c1";
476 tree s, i, i2;
477
478 s = build_unary_op (ADDR_EXPR, TYPE_BINFO_VTABLE (basetype), 0);
479 s = build_tree_list (build_string (1, "s"), s);
480
481 i = build_array_ref (vtbl, idx);
482 if (!flag_vtable_thunks)
483 i = build_component_ref (i, pfn_identifier, vtable_entry_type, 0);
484 i = build_c_cast (ptrdiff_type_node, build_unary_op (ADDR_EXPR, i, 0));
485 i2 = build_array_ref (vtbl, build_int_2(0,0));
486 i2 = build_c_cast (ptrdiff_type_node, build_unary_op (ADDR_EXPR, i2, 0));
487 i = build_binary_op (MINUS_EXPR, i, i2, 0);
488 i = build_tree_list (build_string (1, "i"), i);
489
490 expand_asm_operands (build_string (sizeof(asm_stmt)-1, asm_stmt),
491 NULL_TREE, chainon (s, i), NULL_TREE, 1, NULL, 0);
492 }
493
494 /* Given an object INSTANCE, return an expression which yields the
495 virtual function vtable element corresponding to INDEX. There are
496 many special cases for INSTANCE which we take care of here, mainly
497 to avoid creating extra tree nodes when we don't have to. */
498
499 tree
500 build_vtbl_ref (instance, idx)
501 tree instance, idx;
502 {
503 tree vtbl, aref;
504 tree basetype = TREE_TYPE (instance);
505
506 if (TREE_CODE (basetype) == REFERENCE_TYPE)
507 basetype = TREE_TYPE (basetype);
508
509 if (instance == current_class_ref)
510 vtbl = build_vfield_ref (instance, basetype);
511 else
512 {
513 if (optimize)
514 {
515 /* Try to figure out what a reference refers to, and
516 access its virtual function table directly. */
517 tree ref = NULL_TREE;
518
519 if (TREE_CODE (instance) == INDIRECT_REF
520 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE)
521 ref = TREE_OPERAND (instance, 0);
522 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
523 ref = instance;
524
525 if (ref && TREE_CODE (ref) == VAR_DECL
526 && DECL_INITIAL (ref))
527 {
528 tree init = DECL_INITIAL (ref);
529
530 while (TREE_CODE (init) == NOP_EXPR
531 || TREE_CODE (init) == NON_LVALUE_EXPR)
532 init = TREE_OPERAND (init, 0);
533 if (TREE_CODE (init) == ADDR_EXPR)
534 {
535 init = TREE_OPERAND (init, 0);
536 if (IS_AGGR_TYPE (TREE_TYPE (init))
537 && (TREE_CODE (init) == PARM_DECL
538 || TREE_CODE (init) == VAR_DECL))
539 instance = init;
540 }
541 }
542 }
543
544 if (IS_AGGR_TYPE (TREE_TYPE (instance))
545 && (TREE_CODE (instance) == RESULT_DECL
546 || TREE_CODE (instance) == PARM_DECL
547 || TREE_CODE (instance) == VAR_DECL))
548 vtbl = TYPE_BINFO_VTABLE (basetype);
549 else
550 vtbl = build_vfield_ref (instance, basetype);
551 }
552
553 assemble_external (vtbl);
554
555 if (flag_vtable_gc)
556 build_vtable_entry_ref (basetype, vtbl, idx);
557
558 aref = build_array_ref (vtbl, idx);
559
560 return aref;
561 }
562
563 /* Given an object INSTANCE, return an expression which yields the
564 virtual function corresponding to INDEX. There are many special
565 cases for INSTANCE which we take care of here, mainly to avoid
566 creating extra tree nodes when we don't have to. */
567
568 tree
569 build_vfn_ref (ptr_to_instptr, instance, idx)
570 tree *ptr_to_instptr, instance;
571 tree idx;
572 {
573 tree aref = build_vtbl_ref (instance, idx);
574
575 /* When using thunks, there is no extra delta, and we get the pfn
576 directly. */
577 if (flag_vtable_thunks)
578 return aref;
579
580 if (ptr_to_instptr)
581 {
582 /* Save the intermediate result in a SAVE_EXPR so we don't have to
583 compute each component of the virtual function pointer twice. */
584 if (TREE_CODE (aref) == INDIRECT_REF)
585 TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
586
587 *ptr_to_instptr
588 = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
589 *ptr_to_instptr,
590 cp_convert (ptrdiff_type_node,
591 build_component_ref (aref, delta_identifier, NULL_TREE, 0)));
592 }
593
594 return build_component_ref (aref, pfn_identifier, NULL_TREE, 0);
595 }
596
597 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
598 for the given TYPE. */
599
600 static tree
601 get_vtable_name (type)
602 tree type;
603 {
604 tree type_id = build_typename_overload (type);
605 char *buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT)
606 + IDENTIFIER_LENGTH (type_id) + 2);
607 char *ptr = IDENTIFIER_POINTER (type_id);
608 int i;
609 for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
610 #if 0
611 /* We don't take off the numbers; prepare_fresh_vtable uses the
612 DECL_ASSEMBLER_NAME for the type, which includes the number
613 in `3foo'. If we were to pull them off here, we'd end up with
614 something like `_vt.foo.3bar', instead of a uniform definition. */
615 while (ptr[i] >= '0' && ptr[i] <= '9')
616 i += 1;
617 #endif
618 sprintf (buf, VTABLE_NAME_FORMAT, ptr+i);
619 return get_identifier (buf);
620 }
621
622 /* Return the offset to the main vtable for a given base BINFO. */
623
624 tree
625 get_vfield_offset (binfo)
626 tree binfo;
627 {
628 tree tmp
629 = size_binop (FLOOR_DIV_EXPR,
630 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
631 size_int (BITS_PER_UNIT));
632 tmp = convert (sizetype, tmp);
633 return size_binop (PLUS_EXPR, tmp, BINFO_OFFSET (binfo));
634 }
635
636 /* Get the offset to the start of the original binfo that we derived
637 this binfo from. If we find TYPE first, return the offset only
638 that far. The shortened search is useful because the this pointer
639 on method calling is expected to point to a DECL_CONTEXT (fndecl)
640 object, and not a baseclass of it. */
641
642 static tree
643 get_derived_offset (binfo, type)
644 tree binfo, type;
645 {
646 tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
647 tree offset2;
648 int i;
649 while (BINFO_BASETYPES (binfo)
650 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
651 {
652 tree binfos = BINFO_BASETYPES (binfo);
653 if (BINFO_TYPE (binfo) == type)
654 break;
655 binfo = TREE_VEC_ELT (binfos, i);
656 }
657 offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
658 return size_binop (MINUS_EXPR, offset1, offset2);
659 }
660
661 /* Update the rtti info for this class. */
662
663 static void
664 set_rtti_entry (virtuals, offset, type)
665 tree virtuals, offset, type;
666 {
667 tree vfn;
668
669 if (flag_rtti)
670 vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, get_tinfo_fn (type));
671 else
672 vfn = build1 (NOP_EXPR, vfunc_ptr_type_node, size_zero_node);
673 TREE_CONSTANT (vfn) = 1;
674
675 if (! flag_vtable_thunks)
676 TREE_VALUE (virtuals) = build_vtable_entry (offset, vfn);
677 else
678 {
679 tree voff = build1 (NOP_EXPR, vfunc_ptr_type_node, offset);
680 TREE_CONSTANT (voff) = 1;
681
682 TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, voff);
683
684 /* The second slot is for the tdesc pointer when thunks are used. */
685 TREE_VALUE (TREE_CHAIN (virtuals))
686 = build_vtable_entry (integer_zero_node, vfn);
687 }
688 }
689
690 /* Build a virtual function for type TYPE.
691 If BINFO is non-NULL, build the vtable starting with the initial
692 approximation that it is the same as the one which is the head of
693 the association list. */
694
695 static tree
696 build_vtable (binfo, type)
697 tree binfo, type;
698 {
699 tree name = get_vtable_name (type);
700 tree virtuals, decl;
701
702 if (binfo)
703 {
704 tree offset;
705
706 virtuals = copy_list (BINFO_VIRTUALS (binfo));
707 decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo)));
708
709 /* Now do rtti stuff. */
710 offset = get_derived_offset (TYPE_BINFO (type), NULL_TREE);
711 offset = ssize_binop (MINUS_EXPR, integer_zero_node, offset);
712 set_rtti_entry (virtuals, offset, type);
713 }
714 else
715 {
716 virtuals = NULL_TREE;
717 decl = build_decl (VAR_DECL, name, void_type_node);
718 }
719
720 #ifdef GATHER_STATISTICS
721 n_vtables += 1;
722 n_vtable_elems += list_length (virtuals);
723 #endif
724
725 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
726 import_export_vtable (decl, type, 0);
727
728 decl = pushdecl_top_level (decl);
729 SET_IDENTIFIER_GLOBAL_VALUE (name, decl);
730 /* Initialize the association list for this type, based
731 on our first approximation. */
732 TYPE_BINFO_VTABLE (type) = decl;
733 TYPE_BINFO_VIRTUALS (type) = virtuals;
734
735 DECL_ARTIFICIAL (decl) = 1;
736 TREE_STATIC (decl) = 1;
737 #ifndef WRITABLE_VTABLES
738 /* Make them READONLY by default. (mrs) */
739 TREE_READONLY (decl) = 1;
740 #endif
741 /* At one time the vtable info was grabbed 2 words at a time. This
742 fails on sparc unless you have 8-byte alignment. (tiemann) */
743 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
744 DECL_ALIGN (decl));
745
746 DECL_VIRTUAL_P (decl) = 1;
747 DECL_CONTEXT (decl) = type;
748
749 binfo = TYPE_BINFO (type);
750 SET_BINFO_NEW_VTABLE_MARKED (binfo);
751 return decl;
752 }
753
754 extern tree signed_size_zero_node;
755
756 /* Give TYPE a new virtual function table which is initialized
757 with a skeleton-copy of its original initialization. The only
758 entry that changes is the `delta' entry, so we can really
759 share a lot of structure.
760
761 FOR_TYPE is the derived type which caused this table to
762 be needed.
763
764 BINFO is the type association which provided TYPE for FOR_TYPE.
765
766 The order in which vtables are built (by calling this function) for
767 an object must remain the same, otherwise a binary incompatibility
768 can result. */
769
770 static void
771 prepare_fresh_vtable (binfo, for_type)
772 tree binfo, for_type;
773 {
774 tree basetype;
775 tree orig_decl = BINFO_VTABLE (binfo);
776 tree name;
777 tree new_decl;
778 tree offset;
779 tree path = binfo;
780 char *buf, *buf2;
781 char joiner = '_';
782 int i;
783
784 #ifdef JOINER
785 joiner = JOINER;
786 #endif
787
788 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (binfo));
789
790 buf2 = TYPE_ASSEMBLER_NAME_STRING (basetype);
791 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1;
792
793 /* We know that the vtable that we are going to create doesn't exist
794 yet in the global namespace, and when we finish, it will be
795 pushed into the global namespace. In complex MI hierarchies, we
796 have to loop while the name we are thinking of adding is globally
797 defined, adding more name components to the vtable name as we
798 loop, until the name is unique. This is because in complex MI
799 cases, we might have the same base more than once. This means
800 that the order in which this function is called for vtables must
801 remain the same, otherwise binary compatibility can be
802 compromised. */
803
804 while (1)
805 {
806 char *buf1 = (char *) alloca (TYPE_ASSEMBLER_NAME_LENGTH (for_type)
807 + 1 + i);
808 char *new_buf2;
809
810 sprintf (buf1, "%s%c%s", TYPE_ASSEMBLER_NAME_STRING (for_type), joiner,
811 buf2);
812 buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT) + strlen (buf1) + 1);
813 sprintf (buf, VTABLE_NAME_FORMAT, buf1);
814 name = get_identifier (buf);
815
816 /* If this name doesn't clash, then we can use it, otherwise
817 we add more to the name until it is unique. */
818
819 if (! IDENTIFIER_GLOBAL_VALUE (name))
820 break;
821
822 /* Set values for next loop through, if the name isn't unique. */
823
824 path = BINFO_INHERITANCE_CHAIN (path);
825
826 /* We better not run out of stuff to make it unique. */
827 my_friendly_assert (path != NULL_TREE, 368);
828
829 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (path));
830
831 if (for_type == basetype)
832 {
833 /* If we run out of basetypes in the path, we have already
834 found created a vtable with that name before, we now
835 resort to tacking on _%d to distinguish them. */
836 int j = 2;
837 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i + 1 + 3;
838 buf1 = (char *) alloca (i);
839 do {
840 sprintf (buf1, "%s%c%s%c%d",
841 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner,
842 buf2, joiner, j);
843 buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT)
844 + strlen (buf1) + 1);
845 sprintf (buf, VTABLE_NAME_FORMAT, buf1);
846 name = get_identifier (buf);
847
848 /* If this name doesn't clash, then we can use it,
849 otherwise we add something different to the name until
850 it is unique. */
851 } while (++j <= 999 && IDENTIFIER_GLOBAL_VALUE (name));
852
853 /* Hey, they really like MI don't they? Increase the 3
854 above to 6, and the 999 to 999999. :-) */
855 my_friendly_assert (j <= 999, 369);
856
857 break;
858 }
859
860 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i;
861 new_buf2 = (char *) alloca (i);
862 sprintf (new_buf2, "%s%c%s",
863 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner, buf2);
864 buf2 = new_buf2;
865 }
866
867 new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
868 /* Remember which class this vtable is really for. */
869 DECL_CONTEXT (new_decl) = for_type;
870
871 DECL_ARTIFICIAL (new_decl) = 1;
872 TREE_STATIC (new_decl) = 1;
873 BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
874 DECL_VIRTUAL_P (new_decl) = 1;
875 #ifndef WRITABLE_VTABLES
876 /* Make them READONLY by default. (mrs) */
877 TREE_READONLY (new_decl) = 1;
878 #endif
879 DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
880
881 /* Make fresh virtual list, so we can smash it later. */
882 BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
883
884 if (TREE_VIA_VIRTUAL (binfo))
885 {
886 tree binfo1 = binfo_member (BINFO_TYPE (binfo),
887 CLASSTYPE_VBASECLASSES (for_type));
888
889 /* XXX - This should never happen, if it does, the caller should
890 ensure that the binfo is from for_type's binfos, not from any
891 base type's. We can remove all this code after a while. */
892 if (binfo1 != binfo)
893 warning ("internal inconsistency: binfo offset error for rtti");
894
895 offset = BINFO_OFFSET (binfo1);
896 }
897 else
898 offset = BINFO_OFFSET (binfo);
899
900 set_rtti_entry (BINFO_VIRTUALS (binfo),
901 ssize_binop (MINUS_EXPR, integer_zero_node, offset),
902 for_type);
903
904 #ifdef GATHER_STATISTICS
905 n_vtables += 1;
906 n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
907 #endif
908
909 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
910 import_export_vtable (new_decl, for_type, 0);
911
912 if (TREE_VIA_VIRTUAL (binfo))
913 my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo),
914 CLASSTYPE_VBASECLASSES (current_class_type)),
915 170);
916 SET_BINFO_NEW_VTABLE_MARKED (binfo);
917 }
918
919 #if 0
920 /* Access the virtual function table entry that logically
921 contains BASE_FNDECL. VIRTUALS is the virtual function table's
922 initializer. We can run off the end, when dealing with virtual
923 destructors in MI situations, return NULL_TREE in that case. */
924
925 static tree
926 get_vtable_entry (virtuals, base_fndecl)
927 tree virtuals, base_fndecl;
928 {
929 unsigned HOST_WIDE_INT n = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
930 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
931 & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1))
932 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)));
933
934 #ifdef GATHER_STATISTICS
935 n_vtable_searches += n;
936 #endif
937
938 while (n > 0 && virtuals)
939 {
940 --n;
941 virtuals = TREE_CHAIN (virtuals);
942 }
943 return virtuals;
944 }
945 #endif
946
947 /* Put new entry ENTRY into virtual function table initializer
948 VIRTUALS.
949
950 Also update DECL_VINDEX (FNDECL). */
951
952 static void
953 modify_vtable_entry (old_entry_in_list, new_entry, fndecl)
954 tree old_entry_in_list, new_entry, fndecl;
955 {
956 tree base_fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)), 0);
957
958 #ifdef NOTQUITE
959 cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl),
960 DECL_ASSEMBLER_NAME (fndecl));
961 #endif
962 TREE_VALUE (old_entry_in_list) = new_entry;
963
964 /* Now assign virtual dispatch information, if unset. */
965 /* We can dispatch this, through any overridden base function. */
966 if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
967 {
968 DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
969 DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
970 }
971 }
972
973 /* Access the virtual function table entry N. VIRTUALS is the virtual
974 function table's initializer. */
975
976 static tree
977 get_vtable_entry_n (virtuals, n)
978 tree virtuals;
979 unsigned HOST_WIDE_INT n;
980 {
981 while (n > 0)
982 {
983 --n;
984 virtuals = TREE_CHAIN (virtuals);
985 }
986 return virtuals;
987 }
988
989 /* Add a virtual function to all the appropriate vtables for the class
990 T. DECL_VINDEX(X) should be error_mark_node, if we want to
991 allocate a new slot in our table. If it is error_mark_node, we
992 know that no other function from another vtable is overridden by X.
993 HAS_VIRTUAL keeps track of how many virtuals there are in our main
994 vtable for the type, and we build upon the PENDING_VIRTUALS list
995 and return it. */
996
997 static void
998 add_virtual_function (pv, phv, has_virtual, fndecl, t)
999 tree *pv, *phv;
1000 int *has_virtual;
1001 tree fndecl;
1002 tree t; /* Structure type. */
1003 {
1004 tree pending_virtuals = *pv;
1005 tree pending_hard_virtuals = *phv;
1006
1007 /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
1008 convert to void *. Make such a conversion here. */
1009 tree vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
1010 TREE_CONSTANT (vfn) = 1;
1011
1012 #ifndef DUMB_USER
1013 if (current_class_type == 0)
1014 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
1015 fndecl);
1016 if (current_class_type && t != current_class_type)
1017 cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
1018 fndecl);
1019 #endif
1020
1021 /* If the virtual function is a redefinition of a prior one,
1022 figure out in which base class the new definition goes,
1023 and if necessary, make a fresh virtual function table
1024 to hold that entry. */
1025 if (DECL_VINDEX (fndecl) == error_mark_node)
1026 {
1027 tree entry;
1028
1029 /* We remember that this was the base sub-object for rtti. */
1030 CLASSTYPE_RTTI (t) = t;
1031
1032 /* If we are using thunks, use two slots at the front, one
1033 for the offset pointer, one for the tdesc pointer. */
1034 if (*has_virtual == 0 && flag_vtable_thunks)
1035 {
1036 *has_virtual = 1;
1037 }
1038
1039 /* Build a new INT_CST for this DECL_VINDEX. */
1040 {
1041 static tree index_table[256];
1042 tree idx;
1043 /* We skip a slot for the offset/tdesc entry. */
1044 int i = ++(*has_virtual);
1045
1046 if (i >= 256 || index_table[i] == 0)
1047 {
1048 idx = build_int_2 (i, 0);
1049 if (i < 256)
1050 index_table[i] = idx;
1051 }
1052 else
1053 idx = index_table[i];
1054
1055 /* Now assign virtual dispatch information. */
1056 DECL_VINDEX (fndecl) = idx;
1057 DECL_CONTEXT (fndecl) = t;
1058 }
1059 entry = build_vtable_entry (integer_zero_node, vfn);
1060 pending_virtuals = tree_cons (DECL_VINDEX (fndecl), entry, pending_virtuals);
1061 }
1062 /* Might already be INTEGER_CST if declared twice in class. We will
1063 give error later or we've already given it. */
1064 else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
1065 {
1066 /* Need an entry in some other virtual function table.
1067 Deal with this after we have laid out our virtual base classes. */
1068 pending_hard_virtuals = temp_tree_cons (fndecl, vfn, pending_hard_virtuals);
1069 }
1070 *pv = pending_virtuals;
1071 *phv = pending_hard_virtuals;
1072 }
1073 \f
1074 /* Obstack on which to build the vector of class methods. */
1075 struct obstack class_obstack;
1076 extern struct obstack *current_obstack;
1077
1078 /* These are method vectors that were too small for the number of
1079 methods in some class, and so were abandoned. */
1080 static tree free_method_vecs;
1081
1082 /* Returns a method vector with enough room for N methods. N should
1083 be a power of two. */
1084
1085 static tree
1086 make_method_vec (n)
1087 int n;
1088 {
1089 tree new_vec;
1090 tree* t;
1091
1092 for (t = &free_method_vecs; *t; t = &(TREE_CHAIN (*t)))
1093 /* Note that we don't use >= n here because we don't want to
1094 allocate a very large vector where it isn't needed. */
1095 if (TREE_VEC_LENGTH (*t) == n)
1096 {
1097 new_vec = *t;
1098 *t = TREE_CHAIN (new_vec);
1099 TREE_CHAIN (new_vec) = NULL_TREE;
1100 bzero ((PTR) &TREE_VEC_ELT (new_vec, 0), n * sizeof (tree));
1101 return new_vec;
1102 }
1103
1104 new_vec = make_tree_vec (n);
1105 return new_vec;
1106 }
1107
1108 /* Free the method vector VEC. */
1109
1110 static void
1111 free_method_vec (vec)
1112 tree vec;
1113 {
1114 TREE_CHAIN (vec) = free_method_vecs;
1115 free_method_vecs = vec;
1116 }
1117
1118 /* Add method METHOD to class TYPE.
1119
1120 If non-NULL, FIELDS is the entry in the METHOD_VEC vector entry of
1121 the class type where the method should be added. */
1122
1123 void
1124 add_method (type, fields, method)
1125 tree type, *fields, method;
1126 {
1127 push_obstacks (&permanent_obstack, &permanent_obstack);
1128
1129 /* Setting the DECL_CONTEXT and DECL_CLASS_CONTEXT here is probably
1130 redundant. */
1131 DECL_CONTEXT (method) = type;
1132 DECL_CLASS_CONTEXT (method) = type;
1133
1134 if (fields && *fields)
1135 *fields = build_overload (method, *fields);
1136 else
1137 {
1138 int len;
1139 tree method_vec;
1140
1141 if (!CLASSTYPE_METHOD_VEC (type))
1142 /* Make a new method vector. We start with 8 entries. We must
1143 allocate at least two (for constructors and destructors), and
1144 we're going to end up with an assignment operator at some
1145 point as well.
1146
1147 We could use a TREE_LIST for now, and convert it to a
1148 TREE_VEC in finish_struct, but we would probably waste more
1149 memory making the links in the list than we would by
1150 over-allocating the size of the vector here. Furthermore,
1151 we would complicate all the code that expects this to be a
1152 vector. We keep a free list of vectors that we outgrew so
1153 that we don't really waste any memory. */
1154 CLASSTYPE_METHOD_VEC (type) = make_method_vec (8);
1155
1156 method_vec = CLASSTYPE_METHOD_VEC (type);
1157 len = TREE_VEC_LENGTH (method_vec);
1158
1159 if (DECL_NAME (method) == constructor_name (type))
1160 {
1161 /* A new constructor or destructor. Constructors go in
1162 slot 0; destructors go in slot 1. */
1163 int slot
1164 = DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (method)) ? 1 : 0;
1165
1166 TREE_VEC_ELT (method_vec, slot)
1167 = build_overload (method, TREE_VEC_ELT (method_vec, slot));
1168 }
1169 else
1170 {
1171 int i;
1172
1173 /* See if we already have an entry with this name. */
1174 for (i = 2; i < len; ++i)
1175 if (!TREE_VEC_ELT (method_vec, i)
1176 || (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)))
1177 == DECL_NAME (method)))
1178 break;
1179
1180 if (i == len)
1181 {
1182 /* We need a bigger method vector. */
1183 tree new_vec = make_method_vec (2 * len);
1184 bcopy ((PTR) &TREE_VEC_ELT (method_vec, 0),
1185 (PTR) &TREE_VEC_ELT (new_vec, 0),
1186 len * sizeof (tree));
1187 free_method_vec (method_vec);
1188 len = 2 * len;
1189 method_vec = CLASSTYPE_METHOD_VEC (type) = new_vec;
1190 }
1191 else if (template_class_depth (type))
1192 /* TYPE is a template class. Don't issue any errors now;
1193 wait until instantiation time to complain. */
1194 ;
1195 else
1196 {
1197 tree fns;
1198
1199 /* Check to see if we've already got this method. */
1200 for (fns = TREE_VEC_ELT (method_vec, i);
1201 fns;
1202 fns = OVL_NEXT (fns))
1203 {
1204 tree fn = OVL_CURRENT (fns);
1205
1206 if (TREE_CODE (fn) != TREE_CODE (method))
1207 continue;
1208
1209 if (TREE_CODE (method) != TEMPLATE_DECL)
1210 {
1211 /* Since this is an ordinary function in a
1212 non-template class, it's mangled name can be
1213 used as a unique identifier. This technique
1214 is only an optimization; we would get the
1215 same results if we just used decls_match
1216 here. */
1217 if (DECL_ASSEMBLER_NAME (fn)
1218 != DECL_ASSEMBLER_NAME (method))
1219 continue;
1220 }
1221 else if (!decls_match (fn, method))
1222 continue;
1223
1224 /* There has already been a declaration of this
1225 method or member template. */
1226 cp_error_at ("`%D' has already been declared in `%T'",
1227 method, type);
1228
1229 /* We don't call duplicate_decls here to merege the
1230 declarations because that will confuse things if
1231 the methods have inline definitions In
1232 particular, we will crash while processing the
1233 definitions. */
1234 return;
1235 }
1236 }
1237
1238 if (DECL_CONV_FN_P (method))
1239 {
1240 /* Type conversion operators have to come before
1241 ordinary methods; add_conversions depends on this to
1242 speed up looking for conversion operators. So, if
1243 necessary, we slide some of the vector elements up.
1244 In theory, this makes this algorithm O(N^2) but we
1245 don't expect many conversion operators. */
1246 for (i = 2; i < len; ++i)
1247 {
1248 tree fn = TREE_VEC_ELT (method_vec, i);
1249
1250 if (!fn)
1251 /* There are no more entries in the vector, so we
1252 can insert the new conversion operator here. */
1253 break;
1254
1255 if (! DECL_CONV_FN_P (OVL_CURRENT (fn)))
1256 /* We can insert the new function right at the Ith
1257 position. */
1258 break;
1259 }
1260
1261 if (!TREE_VEC_ELT (method_vec, i))
1262 /* There is nothing in the Ith slot, so we can avoid
1263 moving anything. */
1264 ;
1265 else
1266 {
1267 /* We know the last slot in the vector is empty
1268 because we know that at this point there's room for
1269 a new function. */
1270 bcopy ((PTR) &TREE_VEC_ELT (method_vec, i),
1271 (PTR) &TREE_VEC_ELT (method_vec, i + 1),
1272 (len - i - 1) * sizeof (tree));
1273 TREE_VEC_ELT (method_vec, i) = NULL_TREE;
1274 }
1275 }
1276
1277 /* Actually insert the new method. */
1278 TREE_VEC_ELT (method_vec, i)
1279 = build_overload (method, TREE_VEC_ELT (method_vec, i));
1280 }
1281
1282 if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type))
1283 {
1284 /* ??? May be better to know whether these can be extended? */
1285 tree baselink_vec = CLASSTYPE_BASELINK_VEC (type);
1286
1287 TREE_VEC_LENGTH (baselink_vec) += 1;
1288 CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec);
1289 TREE_VEC_LENGTH (baselink_vec) -= 1;
1290
1291 TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0;
1292 }
1293 }
1294 pop_obstacks ();
1295 }
1296
1297 /* Subroutines of finish_struct. */
1298
1299 /* Look through the list of fields for this struct, deleting
1300 duplicates as we go. This must be recursive to handle
1301 anonymous unions.
1302
1303 FIELD is the field which may not appear anywhere in FIELDS.
1304 FIELD_PTR, if non-null, is the starting point at which
1305 chained deletions may take place.
1306 The value returned is the first acceptable entry found
1307 in FIELDS.
1308
1309 Note that anonymous fields which are not of UNION_TYPE are
1310 not duplicates, they are just anonymous fields. This happens
1311 when we have unnamed bitfields, for example. */
1312
1313 static tree
1314 delete_duplicate_fields_1 (field, fields)
1315 tree field, fields;
1316 {
1317 tree x;
1318 tree prev = 0;
1319 if (DECL_NAME (field) == 0)
1320 {
1321 if (TREE_CODE (TREE_TYPE (field)) != UNION_TYPE)
1322 return fields;
1323
1324 for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
1325 fields = delete_duplicate_fields_1 (x, fields);
1326 return fields;
1327 }
1328 else
1329 {
1330 for (x = fields; x; prev = x, x = TREE_CHAIN (x))
1331 {
1332 if (DECL_NAME (x) == 0)
1333 {
1334 if (TREE_CODE (TREE_TYPE (x)) != UNION_TYPE)
1335 continue;
1336 TYPE_FIELDS (TREE_TYPE (x))
1337 = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x)));
1338 if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
1339 {
1340 if (prev == 0)
1341 fields = TREE_CHAIN (fields);
1342 else
1343 TREE_CHAIN (prev) = TREE_CHAIN (x);
1344 }
1345 }
1346 else
1347 {
1348 if (DECL_NAME (field) == DECL_NAME (x))
1349 {
1350 if (TREE_CODE (field) == CONST_DECL
1351 && TREE_CODE (x) == CONST_DECL)
1352 cp_error_at ("duplicate enum value `%D'", x);
1353 else if (TREE_CODE (field) == CONST_DECL
1354 || TREE_CODE (x) == CONST_DECL)
1355 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1356 x);
1357 else if (DECL_DECLARES_TYPE_P (field)
1358 && DECL_DECLARES_TYPE_P (x))
1359 {
1360 if (same_type_p (TREE_TYPE (field), TREE_TYPE (x)))
1361 continue;
1362 cp_error_at ("duplicate nested type `%D'", x);
1363 }
1364 else if (DECL_DECLARES_TYPE_P (field)
1365 || DECL_DECLARES_TYPE_P (x))
1366 {
1367 /* Hide tag decls. */
1368 if ((TREE_CODE (field) == TYPE_DECL
1369 && DECL_ARTIFICIAL (field))
1370 || (TREE_CODE (x) == TYPE_DECL
1371 && DECL_ARTIFICIAL (x)))
1372 continue;
1373 cp_error_at ("duplicate field `%D' (as type and non-type)",
1374 x);
1375 }
1376 else
1377 cp_error_at ("duplicate member `%D'", x);
1378 if (prev == 0)
1379 fields = TREE_CHAIN (fields);
1380 else
1381 TREE_CHAIN (prev) = TREE_CHAIN (x);
1382 }
1383 }
1384 }
1385 }
1386 return fields;
1387 }
1388
1389 static void
1390 delete_duplicate_fields (fields)
1391 tree fields;
1392 {
1393 tree x;
1394 for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
1395 TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
1396 }
1397
1398 /* Change the access of FDECL to ACCESS in T. The access to FDECL is
1399 along the path given by BINFO. Return 1 if change was legit,
1400 otherwise return 0. */
1401
1402 static int
1403 alter_access (t, binfo, fdecl, access)
1404 tree t;
1405 tree binfo;
1406 tree fdecl;
1407 tree access;
1408 {
1409 tree elem = purpose_member (t, DECL_ACCESS (fdecl));
1410 if (elem)
1411 {
1412 if (TREE_VALUE (elem) != access)
1413 {
1414 if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
1415 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
1416 else
1417 error ("conflicting access specifications for field `%s', ignored",
1418 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
1419 }
1420 else
1421 {
1422 /* They're changing the access to the same thing they changed
1423 it to before. That's OK. */
1424 ;
1425 }
1426 }
1427 else
1428 {
1429 enforce_access (binfo, fdecl);
1430
1431 DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
1432 return 1;
1433 }
1434 return 0;
1435 }
1436
1437 /* Process the USING_DECL, which is a member of T. The METHOD_VEC, if
1438 non-NULL, is the methods of T. The FIELDS are the fields of T.
1439 Returns 1 if the USING_DECL was valid, 0 otherwise. */
1440
1441 void
1442 handle_using_decl (using_decl, t, method_vec, fields)
1443 tree using_decl;
1444 tree t;
1445 tree method_vec;
1446 tree fields;
1447 {
1448 tree ctype = DECL_INITIAL (using_decl);
1449 tree name = DECL_NAME (using_decl);
1450 tree access
1451 = TREE_PRIVATE (using_decl) ? access_private_node
1452 : TREE_PROTECTED (using_decl) ? access_protected_node
1453 : access_public_node;
1454 tree fdecl, binfo;
1455 tree flist = NULL_TREE;
1456 tree tmp;
1457 int i;
1458 int n_methods;
1459
1460 binfo = binfo_or_else (ctype, t);
1461 if (! binfo)
1462 return;
1463
1464 if (name == constructor_name (ctype)
1465 || name == constructor_name_full (ctype))
1466 cp_error_at ("using-declaration for constructor", using_decl);
1467
1468 fdecl = lookup_member (binfo, name, 0, 0);
1469
1470 if (!fdecl)
1471 {
1472 cp_error_at ("no members matching `%D' in `%#T'", using_decl, ctype);
1473 return;
1474 }
1475
1476 /* Functions are represented as TREE_LIST, with the purpose
1477 being the type and the value the functions. Other members
1478 come as themselves. */
1479 if (TREE_CODE (fdecl) == TREE_LIST)
1480 /* Ignore base type this came from. */
1481 fdecl = TREE_VALUE (fdecl);
1482
1483 if (TREE_CODE (fdecl) == OVERLOAD)
1484 {
1485 /* We later iterate over all functions. */
1486 flist = fdecl;
1487 fdecl = OVL_FUNCTION (flist);
1488 }
1489
1490 name = DECL_NAME (fdecl);
1491 n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
1492 for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); i++)
1493 if (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)))
1494 == name)
1495 {
1496 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
1497 cp_error_at (" because of local method `%#D' with same name",
1498 OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
1499 return;
1500 }
1501
1502 if (! DECL_LANG_SPECIFIC (fdecl))
1503 /* We don't currently handle DECL_ACCESS for TYPE_DECLs; just return. */
1504 return;
1505
1506 for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp))
1507 if (DECL_NAME (tmp) == name)
1508 {
1509 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
1510 cp_error_at (" because of local field `%#D' with same name", tmp);
1511 return;
1512 }
1513
1514 /* Make type T see field decl FDECL with access ACCESS.*/
1515 if (flist)
1516 {
1517 while (flist)
1518 {
1519 if (alter_access (t, binfo, OVL_FUNCTION (flist),
1520 access) == 0)
1521 return;
1522 flist = OVL_CHAIN (flist);
1523 }
1524 }
1525 else
1526 alter_access (t, binfo, fdecl, access);
1527 }
1528
1529 /* If FOR_TYPE needs to reinitialize virtual function table pointers
1530 for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
1531 Returns BASE_INIT_LIST appropriately modified. */
1532
1533 static tree
1534 maybe_fixup_vptrs (for_type, binfo, base_init_list)
1535 tree for_type, binfo, base_init_list;
1536 {
1537 /* Now reinitialize any slots that don't fall under our virtual
1538 function table pointer. */
1539 tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo));
1540 while (vfields)
1541 {
1542 tree basetype = VF_NORMAL_VALUE (vfields)
1543 ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields))
1544 : VF_BASETYPE_VALUE (vfields);
1545
1546 tree base_binfo = get_binfo (basetype, for_type, 0);
1547 /* Punt until this is implemented. */
1548 if (1 /* BINFO_MODIFIED (base_binfo) */)
1549 {
1550 tree base_offset = get_vfield_offset (base_binfo);
1551 if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type)))
1552 && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo)))
1553 base_init_list = tree_cons (error_mark_node, base_binfo,
1554 base_init_list);
1555 }
1556 vfields = TREE_CHAIN (vfields);
1557 }
1558 return base_init_list;
1559 }
1560
1561 /* If TYPE does not have a constructor, then the compiler must
1562 manually deal with all of the initialization this type requires.
1563
1564 If a base initializer exists only to fill in the virtual function
1565 table pointer, then we mark that fact with the TREE_VIRTUAL bit.
1566 This way, we avoid multiple initializations of the same field by
1567 each virtual function table up the class hierarchy.
1568
1569 Virtual base class pointers are not initialized here. They are
1570 initialized only at the "top level" of object creation. If we
1571 initialized them here, we would have to skip a lot of work. */
1572
1573 static void
1574 build_class_init_list (type)
1575 tree type;
1576 {
1577 tree base_init_list = NULL_TREE;
1578 tree member_init_list = NULL_TREE;
1579
1580 /* Since we build member_init_list and base_init_list using
1581 tree_cons, backwards fields the all through work. */
1582 tree x;
1583 tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
1584 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1585
1586 for (x = TYPE_FIELDS (type); x; x = TREE_CHAIN (x))
1587 {
1588 if (TREE_CODE (x) != FIELD_DECL)
1589 continue;
1590
1591 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x))
1592 || DECL_INITIAL (x) != NULL_TREE)
1593 member_init_list = tree_cons (x, type, member_init_list);
1594 }
1595 member_init_list = nreverse (member_init_list);
1596
1597 /* We will end up doing this last. Need special marker
1598 to avoid infinite regress. */
1599 if (TYPE_VIRTUAL_P (type))
1600 {
1601 base_init_list = build_tree_list (error_mark_node, TYPE_BINFO (type));
1602 if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type) == 0)
1603 TREE_VALUE (base_init_list) = NULL_TREE;
1604 TREE_ADDRESSABLE (base_init_list) = 1;
1605 }
1606
1607 /* Each base class which needs to have initialization
1608 of some kind gets to make such requests known here. */
1609 for (i = n_baseclasses-1; i >= 0; i--)
1610 {
1611 tree base_binfo = TREE_VEC_ELT (binfos, i);
1612 tree blist;
1613
1614 /* Don't initialize virtual baseclasses this way. */
1615 if (TREE_VIA_VIRTUAL (base_binfo))
1616 continue;
1617
1618 if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (base_binfo)))
1619 {
1620 /* ...and the last shall come first... */
1621 base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list);
1622 base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
1623 continue;
1624 }
1625
1626 if ((blist = CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (base_binfo))) == NULL_TREE)
1627 /* Nothing to initialize. */
1628 continue;
1629
1630 /* ...ditto... */
1631 base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list);
1632
1633 /* This is normally true for single inheritance.
1634 The win is we can shrink the chain of initializations
1635 to be done by only converting to the actual type
1636 we are interested in. */
1637 if (TREE_VALUE (blist)
1638 && TREE_CODE (TREE_VALUE (blist)) == TREE_VEC
1639 && tree_int_cst_equal (BINFO_OFFSET (base_binfo),
1640 BINFO_OFFSET (TREE_VALUE (blist))))
1641 {
1642 if (base_init_list)
1643 {
1644 /* Does it do more than just fill in a
1645 virtual function table pointer? */
1646 if (! TREE_ADDRESSABLE (blist))
1647 base_init_list = build_tree_list (blist, base_init_list);
1648 /* Can we get by just with the virtual function table
1649 pointer that it fills in? */
1650 else if (TREE_ADDRESSABLE (base_init_list)
1651 && TREE_VALUE (base_init_list) == 0)
1652 base_init_list = blist;
1653 /* Maybe, but it is not obvious as the previous case. */
1654 else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type))
1655 {
1656 tree last = tree_last (base_init_list);
1657 while (TREE_VALUE (last)
1658 && TREE_CODE (TREE_VALUE (last)) == TREE_LIST)
1659 last = tree_last (TREE_VALUE (last));
1660 if (TREE_VALUE (last) == 0)
1661 base_init_list = build_tree_list (blist, base_init_list);
1662 }
1663 }
1664 else
1665 base_init_list = blist;
1666 }
1667 else
1668 {
1669 /* The function expand_aggr_init knows how to do the
1670 initialization of `basetype' without getting
1671 an explicit `blist'. */
1672 if (base_init_list)
1673 base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
1674 else
1675 base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo));
1676 }
1677 }
1678
1679 if (base_init_list)
1680 {
1681 if (member_init_list)
1682 CLASSTYPE_BASE_INIT_LIST (type) =
1683 build_tree_list (base_init_list, member_init_list);
1684 else
1685 CLASSTYPE_BASE_INIT_LIST (type) = base_init_list;
1686 }
1687 else if (member_init_list)
1688 CLASSTYPE_BASE_INIT_LIST (type) = member_init_list;
1689 }
1690 \f
1691 struct base_info
1692 {
1693 int has_virtual;
1694 int max_has_virtual;
1695 int n_ancestors;
1696 tree vfield;
1697 tree vfields;
1698 tree rtti;
1699 char cant_have_default_ctor;
1700 char cant_have_const_ctor;
1701 char no_const_asn_ref;
1702 };
1703
1704 /* Record information about type T derived from its base classes.
1705 Store most of that information in T itself, and place the
1706 remaining information in the struct BASE_INFO.
1707
1708 Propagate basetype offsets throughout the lattice. Note that the
1709 lattice topped by T is really a pair: it's a DAG that gives the
1710 structure of the derivation hierarchy, and it's a list of the
1711 virtual baseclasses that appear anywhere in the DAG. When a vbase
1712 type appears in the DAG, it's offset is 0, and it's children start
1713 their offsets from that point. When a vbase type appears in the list,
1714 its offset is the offset it has in the hierarchy, and its children's
1715 offsets include that offset in theirs.
1716
1717 Returns the index of the first base class to have virtual functions,
1718 or -1 if no such base class. */
1719
1720 static int
1721 finish_base_struct (t, b)
1722 tree t;
1723 struct base_info *b;
1724 {
1725 tree binfos = TYPE_BINFO_BASETYPES (t);
1726 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1727 int first_vfn_base_index = -1;
1728 bzero ((char *) b, sizeof (struct base_info));
1729
1730 for (i = 0; i < n_baseclasses; i++)
1731 {
1732 tree base_binfo = TREE_VEC_ELT (binfos, i);
1733 tree basetype = BINFO_TYPE (base_binfo);
1734
1735 /* Effective C++ rule 14. We only need to check TYPE_VIRTUAL_P
1736 here because the case of virtual functions but non-virtual
1737 dtor is handled in finish_struct_1. */
1738 if (warn_ecpp && ! TYPE_VIRTUAL_P (basetype)
1739 && TYPE_HAS_DESTRUCTOR (basetype))
1740 cp_warning ("base class `%#T' has a non-virtual destructor", basetype);
1741
1742 /* If the type of basetype is incomplete, then
1743 we already complained about that fact
1744 (and we should have fixed it up as well). */
1745 if (TYPE_SIZE (basetype) == 0)
1746 {
1747 int j;
1748 /* The base type is of incomplete type. It is
1749 probably best to pretend that it does not
1750 exist. */
1751 if (i == n_baseclasses-1)
1752 TREE_VEC_ELT (binfos, i) = NULL_TREE;
1753 TREE_VEC_LENGTH (binfos) -= 1;
1754 n_baseclasses -= 1;
1755 for (j = i; j+1 < n_baseclasses; j++)
1756 TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
1757 }
1758
1759 if (! TYPE_HAS_CONST_INIT_REF (basetype))
1760 b->cant_have_const_ctor = 1;
1761
1762 if (TYPE_HAS_CONSTRUCTOR (basetype)
1763 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
1764 {
1765 b->cant_have_default_ctor = 1;
1766 if (! TYPE_HAS_CONSTRUCTOR (t))
1767 {
1768 cp_pedwarn ("base `%T' with only non-default constructor",
1769 basetype);
1770 cp_pedwarn ("in class without a constructor");
1771 }
1772 }
1773
1774 if (TYPE_HAS_ASSIGN_REF (basetype)
1775 && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
1776 b->no_const_asn_ref = 1;
1777
1778 b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype);
1779 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
1780 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
1781 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
1782 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
1783
1784 TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
1785 TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
1786 TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
1787
1788 if (! TREE_VIA_VIRTUAL (base_binfo))
1789 CLASSTYPE_N_SUPERCLASSES (t) += 1;
1790
1791 if (TYPE_VIRTUAL_P (basetype))
1792 {
1793 /* Ensure that this is set from at least a virtual base
1794 class. */
1795 if (b->rtti == NULL_TREE)
1796 b->rtti = CLASSTYPE_RTTI (basetype);
1797
1798 /* Don't borrow virtuals from virtual baseclasses. */
1799 if (TREE_VIA_VIRTUAL (base_binfo))
1800 continue;
1801
1802 if (first_vfn_base_index < 0)
1803 {
1804 tree vfields;
1805 first_vfn_base_index = i;
1806
1807 /* Update these two, now that we know what vtable we are
1808 going to extend. This is so that we can add virtual
1809 functions, and override them properly. */
1810 TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
1811 TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
1812 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1813 b->vfield = CLASSTYPE_VFIELD (basetype);
1814 b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
1815 vfields = b->vfields;
1816 while (vfields)
1817 {
1818 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1819 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1820 {
1821 tree value = VF_BASETYPE_VALUE (vfields);
1822 if (DECL_NAME (CLASSTYPE_VFIELD (value))
1823 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1824 VF_NORMAL_VALUE (b->vfields) = basetype;
1825 else
1826 VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
1827 }
1828 vfields = TREE_CHAIN (vfields);
1829 }
1830 CLASSTYPE_VFIELD (t) = b->vfield;
1831 }
1832 else
1833 {
1834 /* Only add unique vfields, and flatten them out as we go. */
1835 tree vfields = CLASSTYPE_VFIELDS (basetype);
1836 while (vfields)
1837 {
1838 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1839 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1840 {
1841 tree value = VF_BASETYPE_VALUE (vfields);
1842 b->vfields = tree_cons (base_binfo, value, b->vfields);
1843 if (DECL_NAME (CLASSTYPE_VFIELD (value))
1844 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1845 VF_NORMAL_VALUE (b->vfields) = basetype;
1846 else
1847 VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
1848 }
1849 vfields = TREE_CHAIN (vfields);
1850 }
1851
1852 if (b->has_virtual == 0)
1853 {
1854 first_vfn_base_index = i;
1855
1856 /* Update these two, now that we know what vtable we are
1857 going to extend. This is so that we can add virtual
1858 functions, and override them properly. */
1859 TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
1860 TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
1861 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1862 b->vfield = CLASSTYPE_VFIELD (basetype);
1863 CLASSTYPE_VFIELD (t) = b->vfield;
1864 /* When we install the first one, set the VF_NORMAL_VALUE
1865 to be the current class, as this it is the most derived
1866 class. Hopefully, this is not set to something else
1867 later. (mrs) */
1868 vfields = b->vfields;
1869 while (vfields)
1870 {
1871 if (DECL_NAME (CLASSTYPE_VFIELD (t))
1872 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1873 {
1874 VF_NORMAL_VALUE (vfields) = t;
1875 /* There should only be one of them! And it should
1876 always be found, if we get into here. (mrs) */
1877 break;
1878 }
1879 vfields = TREE_CHAIN (vfields);
1880 }
1881 }
1882 }
1883 }
1884 }
1885
1886 {
1887 tree vfields;
1888 /* Find the base class with the largest number of virtual functions. */
1889 for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields))
1890 {
1891 if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual)
1892 b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields));
1893 if (VF_DERIVED_VALUE (vfields)
1894 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
1895 b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
1896 }
1897 }
1898
1899 if (b->vfield == 0)
1900 /* If all virtual functions come only from virtual baseclasses. */
1901 return -1;
1902
1903 /* Update the rtti base if we have a non-virtual base class version
1904 of it. */
1905 b->rtti = CLASSTYPE_RTTI (BINFO_TYPE (TREE_VEC_ELT (binfos, first_vfn_base_index)));
1906
1907 return first_vfn_base_index;
1908 }
1909 \f
1910 /* Set memoizing fields and bits of T (and its variants) for later use.
1911 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1912
1913 static void
1914 finish_struct_bits (t, max_has_virtual)
1915 tree t;
1916 int max_has_virtual;
1917 {
1918 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1919
1920 /* Fix up variants (if any). */
1921 tree variants = TYPE_NEXT_VARIANT (t);
1922 while (variants)
1923 {
1924 /* These fields are in the _TYPE part of the node, not in
1925 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1926 TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
1927 TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
1928 TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
1929 TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
1930
1931 TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t);
1932 TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t);
1933 TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
1934 /* Copy whatever these are holding today. */
1935 TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
1936 TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
1937 TYPE_FIELDS (variants) = TYPE_FIELDS (t);
1938 TYPE_SIZE (variants) = TYPE_SIZE (t);
1939 TYPE_SIZE_UNIT (variants) = TYPE_SIZE_UNIT (t);
1940 variants = TYPE_NEXT_VARIANT (variants);
1941 }
1942
1943 if (n_baseclasses && max_has_virtual)
1944 {
1945 /* Done by `finish_struct' for classes without baseclasses. */
1946 int might_have_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0;
1947 tree binfos = TYPE_BINFO_BASETYPES (t);
1948 for (i = n_baseclasses-1; i >= 0; i--)
1949 {
1950 might_have_abstract_virtuals
1951 |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0);
1952 if (might_have_abstract_virtuals)
1953 break;
1954 }
1955 if (might_have_abstract_virtuals)
1956 {
1957 /* We use error_mark_node from override_one_vtable to signal
1958 an artificial abstract. */
1959 if (CLASSTYPE_ABSTRACT_VIRTUALS (t) == error_mark_node)
1960 CLASSTYPE_ABSTRACT_VIRTUALS (t) = NULL_TREE;
1961 CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t);
1962 }
1963 }
1964
1965 if (n_baseclasses)
1966 {
1967 /* Notice whether this class has type conversion functions defined. */
1968 tree binfo = TYPE_BINFO (t);
1969 tree binfos = BINFO_BASETYPES (binfo);
1970 tree basetype;
1971
1972 for (i = n_baseclasses-1; i >= 0; i--)
1973 {
1974 basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
1975
1976 TYPE_HAS_CONVERSION (t) |= TYPE_HAS_CONVERSION (basetype);
1977 if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t))
1978 CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1;
1979 }
1980 }
1981
1982 /* If this type has a copy constructor, force its mode to be BLKmode, and
1983 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1984 be passed by invisible reference and prevent it from being returned in
1985 a register.
1986
1987 Also do this if the class has BLKmode but can still be returned in
1988 registers, since function_cannot_inline_p won't let us inline
1989 functions returning such a type. This affects the HP-PA. */
1990 if (! TYPE_HAS_TRIVIAL_INIT_REF (t)
1991 || (TYPE_MODE (t) == BLKmode && ! aggregate_value_p (t)
1992 && CLASSTYPE_NON_AGGREGATE (t)))
1993 {
1994 tree variants;
1995 DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
1996 for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
1997 {
1998 TYPE_MODE (variants) = BLKmode;
1999 TREE_ADDRESSABLE (variants) = 1;
2000 }
2001 }
2002 }
2003
2004 /* Issue warnings about T having private constructors, but no friends,
2005 and so forth.
2006
2007 HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
2008 static members. HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
2009 non-private static member functions. */
2010
2011 static void
2012 maybe_warn_about_overly_private_class (t)
2013 tree t;
2014 {
2015 int has_member_fn = 0;
2016 int has_nonprivate_method = 0;
2017 tree fn;
2018
2019 if (!warn_ctor_dtor_privacy
2020 /* If the class has friends, those entities might create and
2021 access instances, so we should not warn. */
2022 || (CLASSTYPE_FRIEND_CLASSES (t)
2023 || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
2024 /* We will have warned when the template was declared; there's
2025 no need to warn on every instantiation. */
2026 || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
2027 /* There's no reason to even consider warning about this
2028 class. */
2029 return;
2030
2031 /* We only issue one warning, if more than one applies, because
2032 otherwise, on code like:
2033
2034 class A {
2035 // Oops - forgot `public:'
2036 A();
2037 A(const A&);
2038 ~A();
2039 };
2040
2041 we warn several times about essentially the same problem. */
2042
2043 /* Check to see if all (non-constructor, non-destructor) member
2044 functions are private. (Since there are no friends or
2045 non-private statics, we can't ever call any of the private member
2046 functions.) */
2047 for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
2048 /* We're not interested in compiler-generated methods; they don't
2049 provide any way to call private members. */
2050 if (!DECL_ARTIFICIAL (fn))
2051 {
2052 if (!TREE_PRIVATE (fn))
2053 {
2054 if (DECL_STATIC_FUNCTION_P (fn))
2055 /* A non-private static member function is just like a
2056 friend; it can create and invoke private member
2057 functions, and be accessed without a class
2058 instance. */
2059 return;
2060
2061 has_nonprivate_method = 1;
2062 break;
2063 }
2064 else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
2065 has_member_fn = 1;
2066 }
2067
2068 if (!has_nonprivate_method && has_member_fn)
2069 {
2070 /* There are no non-private methods, and there's at least one
2071 private member function that isn't a constructor or
2072 destructor. (If all the private members are
2073 constructors/destructors we want to use the code below that
2074 issues error messages specifically referring to
2075 constructors/destructors.) */
2076 int i;
2077 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2078 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); i++)
2079 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
2080 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
2081 {
2082 has_nonprivate_method = 1;
2083 break;
2084 }
2085 if (!has_nonprivate_method)
2086 {
2087 cp_warning ("all member functions in class `%T' are private", t);
2088 return;
2089 }
2090 }
2091
2092 /* Even if some of the member functions are non-private, the class
2093 won't be useful for much if all the constructors or destructors
2094 are private: such an object can never be created or destroyed. */
2095 if (TYPE_HAS_DESTRUCTOR (t))
2096 {
2097 tree dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1);
2098
2099 if (TREE_PRIVATE (dtor))
2100 {
2101 cp_warning ("`%#T' only defines a private destructor and has no friends",
2102 t);
2103 return;
2104 }
2105 }
2106
2107 if (TYPE_HAS_CONSTRUCTOR (t))
2108 {
2109 int nonprivate_ctor = 0;
2110
2111 /* If a non-template class does not define a copy
2112 constructor, one is defined for it, enabling it to avoid
2113 this warning. For a template class, this does not
2114 happen, and so we would normally get a warning on:
2115
2116 template <class T> class C { private: C(); };
2117
2118 To avoid this asymmetry, we check TYPE_HAS_INIT_REF. All
2119 complete non-template or fully instantiated classes have this
2120 flag set. */
2121 if (!TYPE_HAS_INIT_REF (t))
2122 nonprivate_ctor = 1;
2123 else
2124 for (fn = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 0);
2125 fn;
2126 fn = OVL_NEXT (fn))
2127 {
2128 tree ctor = OVL_CURRENT (fn);
2129 /* Ideally, we wouldn't count copy constructors (or, in
2130 fact, any constructor that takes an argument of the
2131 class type as a parameter) because such things cannot
2132 be used to construct an instance of the class unless
2133 you already have one. But, for now at least, we're
2134 more generous. */
2135 if (! TREE_PRIVATE (ctor))
2136 {
2137 nonprivate_ctor = 1;
2138 break;
2139 }
2140 }
2141
2142 if (nonprivate_ctor == 0)
2143 {
2144 cp_warning ("`%#T' only defines private constructors and has no friends",
2145 t);
2146 return;
2147 }
2148 }
2149 }
2150
2151
2152 /* Warn about duplicate methods in fn_fields. Also compact method
2153 lists so that lookup can be made faster.
2154
2155 Data Structure: List of method lists. The outer list is a
2156 TREE_LIST, whose TREE_PURPOSE field is the field name and the
2157 TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN
2158 links the entire list of methods for TYPE_METHODS. Friends are
2159 chained in the same way as member functions (? TREE_CHAIN or
2160 DECL_CHAIN), but they live in the TREE_TYPE field of the outer
2161 list. That allows them to be quickly deleted, and requires no
2162 extra storage.
2163
2164 If there are any constructors/destructors, they are moved to the
2165 front of the list. This makes pushclass more efficient.
2166
2167 We also link each field which has shares a name with its baseclass
2168 to the head of the list of fields for that base class. This allows
2169 us to reduce search time in places like `build_method_call' to
2170 consider only reasonably likely functions. */
2171
2172 static void
2173 finish_struct_methods (t)
2174 tree t;
2175 {
2176 tree fn_fields;
2177 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2178 tree ctor_name = constructor_name (t);
2179 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
2180
2181 /* First fill in entry 0 with the constructors, entry 1 with destructors,
2182 and the next few with type conversion operators (if any). */
2183 for (fn_fields = TYPE_METHODS (t); fn_fields;
2184 fn_fields = TREE_CHAIN (fn_fields))
2185 {
2186 tree fn_name = DECL_NAME (fn_fields);
2187
2188 /* Clear out this flag.
2189
2190 @@ Doug may figure out how to break
2191 @@ this with nested classes and friends. */
2192 DECL_IN_AGGR_P (fn_fields) = 0;
2193
2194 /* Note here that a copy ctor is private, so we don't dare generate
2195 a default copy constructor for a class that has a member
2196 of this type without making sure they have access to it. */
2197 if (fn_name == ctor_name)
2198 {
2199 tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields);
2200 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
2201
2202 if (TREE_CODE (parmtype) == REFERENCE_TYPE
2203 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t)
2204 {
2205 if (TREE_CHAIN (parmtypes) == NULL_TREE
2206 || TREE_CHAIN (parmtypes) == void_list_node
2207 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
2208 {
2209 if (TREE_PROTECTED (fn_fields))
2210 TYPE_HAS_NONPUBLIC_CTOR (t) = 1;
2211 else if (TREE_PRIVATE (fn_fields))
2212 TYPE_HAS_NONPUBLIC_CTOR (t) = 2;
2213 }
2214 }
2215 }
2216 else if (fn_name == ansi_opname[(int) MODIFY_EXPR])
2217 {
2218 tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields));
2219
2220 if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields)))
2221 {
2222 if (TREE_PROTECTED (fn_fields))
2223 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1;
2224 else if (TREE_PRIVATE (fn_fields))
2225 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2;
2226 }
2227 }
2228 }
2229
2230 if (TYPE_HAS_DESTRUCTOR (t) && !TREE_VEC_ELT (method_vec, 1))
2231 /* We thought there was a destructor, but there wasn't. Some
2232 parse errors cause this anomalous situation. */
2233 TYPE_HAS_DESTRUCTOR (t) = 0;
2234
2235 /* Issue warnings about private constructors and such. If there are
2236 no methods, then some public defaults are generated. */
2237 maybe_warn_about_overly_private_class (t);
2238
2239 /* Now for each member function (except for constructors and
2240 destructors), compute where member functions of the same
2241 name reside in base classes. */
2242 if (n_baseclasses != 0
2243 && method_vec
2244 && TREE_VEC_LENGTH (method_vec) > 2)
2245 {
2246 int len = TREE_VEC_LENGTH (method_vec);
2247 tree baselink_vec = make_tree_vec (len);
2248 int any_links = 0;
2249 tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t));
2250
2251 for (i = 2; i < len && TREE_VEC_ELT (method_vec, i); i++)
2252 {
2253 tree ovl = TREE_VEC_ELT (method_vec, i);
2254
2255 TREE_VEC_ELT (baselink_vec, i)
2256 = get_baselinks (baselink_binfo, t,
2257 DECL_NAME (OVL_CURRENT (ovl)));
2258 if (TREE_VEC_ELT (baselink_vec, i) != 0)
2259 any_links = 1;
2260 }
2261 if (any_links != 0)
2262 CLASSTYPE_BASELINK_VEC (t) = baselink_vec;
2263 else
2264 obstack_free (current_obstack, baselink_vec);
2265 }
2266 }
2267
2268 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2269
2270 void
2271 duplicate_tag_error (t)
2272 tree t;
2273 {
2274 cp_error ("redefinition of `%#T'", t);
2275 cp_error_at ("previous definition here", t);
2276
2277 /* Pretend we haven't defined this type. */
2278
2279 /* All of the component_decl's were TREE_CHAINed together in the parser.
2280 finish_struct_methods walks these chains and assembles all methods with
2281 the same base name into DECL_CHAINs. Now we don't need the parser chains
2282 anymore, so we unravel them. */
2283
2284 /* This used to be in finish_struct, but it turns out that the
2285 TREE_CHAIN is used by dbxout_type_methods and perhaps some other
2286 things... */
2287 if (CLASSTYPE_METHOD_VEC (t))
2288 {
2289 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2290 int i, len = TREE_VEC_LENGTH (method_vec);
2291 for (i = 0; i < len; i++)
2292 {
2293 tree unchain = TREE_VEC_ELT (method_vec, i);
2294 while (unchain != NULL_TREE)
2295 {
2296 TREE_CHAIN (OVL_CURRENT (unchain)) = NULL_TREE;
2297 unchain = OVL_NEXT (unchain);
2298 }
2299 }
2300 }
2301
2302 if (TYPE_LANG_SPECIFIC (t))
2303 {
2304 tree as_list = CLASSTYPE_AS_LIST (t);
2305 tree binfo = TYPE_BINFO (t);
2306 tree binfo_as_list = CLASSTYPE_BINFO_AS_LIST (t);
2307 int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
2308 int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
2309
2310 bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
2311 BINFO_BASETYPES(binfo) = NULL_TREE;
2312
2313 CLASSTYPE_AS_LIST (t) = as_list;
2314 TYPE_BINFO (t) = binfo;
2315 CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list;
2316 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2317 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
2318 TYPE_REDEFINED (t) = 1;
2319 }
2320 TYPE_SIZE (t) = NULL_TREE;
2321 TYPE_MODE (t) = VOIDmode;
2322 TYPE_FIELDS (t) = NULL_TREE;
2323 TYPE_METHODS (t) = NULL_TREE;
2324 TYPE_VFIELD (t) = NULL_TREE;
2325 TYPE_CONTEXT (t) = NULL_TREE;
2326 }
2327
2328 /* finish up all new vtables. */
2329
2330 static void
2331 finish_vtbls (binfo, do_self, t)
2332 tree binfo;
2333 int do_self;
2334 tree t;
2335 {
2336 tree binfos = BINFO_BASETYPES (binfo);
2337 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2338
2339 /* Should we use something besides CLASSTYPE_VFIELDS? */
2340 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2341 {
2342 if (BINFO_NEW_VTABLE_MARKED (binfo))
2343 {
2344 tree decl, context;
2345
2346 decl = BINFO_VTABLE (binfo);
2347 context = DECL_CONTEXT (decl);
2348 DECL_CONTEXT (decl) = 0;
2349 if (DECL_INITIAL (decl) != BINFO_VIRTUALS (binfo))
2350 DECL_INITIAL (decl) = build_nt (CONSTRUCTOR, NULL_TREE,
2351 BINFO_VIRTUALS (binfo));
2352 cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0, 0);
2353 DECL_CONTEXT (decl) = context;
2354 }
2355 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2356 }
2357
2358 for (i = 0; i < n_baselinks; i++)
2359 {
2360 tree base_binfo = TREE_VEC_ELT (binfos, i);
2361 int is_not_base_vtable
2362 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2363 if (TREE_VIA_VIRTUAL (base_binfo))
2364 {
2365 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2366 }
2367 finish_vtbls (base_binfo, is_not_base_vtable, t);
2368 }
2369 }
2370
2371 /* True if we should override the given BASE_FNDECL with the given
2372 FNDECL. */
2373
2374 static int
2375 overrides (fndecl, base_fndecl)
2376 tree fndecl, base_fndecl;
2377 {
2378 /* Destructors have special names. */
2379 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2380 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2381 return 1;
2382 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2383 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2384 return 0;
2385 if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
2386 {
2387 tree types, base_types;
2388 #if 0
2389 retypes = TREE_TYPE (TREE_TYPE (fndecl));
2390 base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl));
2391 #endif
2392 types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2393 base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
2394 if ((TYPE_QUALS (TREE_TYPE (TREE_VALUE (base_types)))
2395 == TYPE_QUALS (TREE_TYPE (TREE_VALUE (types))))
2396 && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types)))
2397 return 1;
2398 }
2399 return 0;
2400 }
2401
2402 static tree
2403 get_class_offset_1 (parent, binfo, context, t, fndecl)
2404 tree parent, binfo, context, t, fndecl;
2405 {
2406 tree binfos = BINFO_BASETYPES (binfo);
2407 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2408 tree rval = NULL_TREE;
2409
2410 if (binfo == parent)
2411 return error_mark_node;
2412
2413 for (i = 0; i < n_baselinks; i++)
2414 {
2415 tree base_binfo = TREE_VEC_ELT (binfos, i);
2416 tree nrval;
2417
2418 if (TREE_VIA_VIRTUAL (base_binfo))
2419 base_binfo = binfo_member (BINFO_TYPE (base_binfo),
2420 CLASSTYPE_VBASECLASSES (t));
2421 nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl);
2422 /* See if we have a new value */
2423 if (nrval && (nrval != error_mark_node || rval==0))
2424 {
2425 /* Only compare if we have two offsets */
2426 if (rval && rval != error_mark_node
2427 && ! tree_int_cst_equal (nrval, rval))
2428 {
2429 /* Only give error if the two offsets are different */
2430 error ("every virtual function must have a unique final overrider");
2431 cp_error (" found two (or more) `%T' class subobjects in `%T'", context, t);
2432 cp_error (" with virtual `%D' from virtual base class", fndecl);
2433 return rval;
2434 }
2435 rval = nrval;
2436 }
2437
2438 if (rval && BINFO_TYPE (binfo) == context)
2439 {
2440 my_friendly_assert (rval == error_mark_node
2441 || tree_int_cst_equal (rval, BINFO_OFFSET (binfo)), 999);
2442 rval = BINFO_OFFSET (binfo);
2443 }
2444 }
2445 return rval;
2446 }
2447
2448 /* Get the offset to the CONTEXT subobject that is related to the
2449 given BINFO. */
2450
2451 static tree
2452 get_class_offset (context, t, binfo, fndecl)
2453 tree context, t, binfo, fndecl;
2454 {
2455 tree first_binfo = binfo;
2456 tree offset;
2457 int i;
2458
2459 if (context == t)
2460 return integer_zero_node;
2461
2462 if (BINFO_TYPE (binfo) == context)
2463 return BINFO_OFFSET (binfo);
2464
2465 /* Check less derived binfos first. */
2466 while (BINFO_BASETYPES (binfo)
2467 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
2468 {
2469 tree binfos = BINFO_BASETYPES (binfo);
2470 binfo = TREE_VEC_ELT (binfos, i);
2471 if (BINFO_TYPE (binfo) == context)
2472 return BINFO_OFFSET (binfo);
2473 }
2474
2475 /* Ok, not found in the less derived binfos, now check the more
2476 derived binfos. */
2477 offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl);
2478 if (offset==0 || TREE_CODE (offset) != INTEGER_CST)
2479 my_friendly_abort (999); /* we have to find it. */
2480 return offset;
2481 }
2482
2483 /* Skip RTTI information at the front of the virtual list. */
2484
2485 unsigned HOST_WIDE_INT
2486 skip_rtti_stuff (virtuals)
2487 tree *virtuals;
2488 {
2489 int n;
2490
2491 n = 0;
2492 if (*virtuals)
2493 {
2494 /* We always reserve a slot for the offset/tdesc entry. */
2495 ++n;
2496 *virtuals = TREE_CHAIN (*virtuals);
2497 }
2498 if (flag_vtable_thunks && *virtuals)
2499 {
2500 /* The second slot is reserved for the tdesc pointer when thunks
2501 are used. */
2502 ++n;
2503 *virtuals = TREE_CHAIN (*virtuals);
2504 }
2505 return n;
2506 }
2507
2508 static void
2509 modify_one_vtable (binfo, t, fndecl, pfn)
2510 tree binfo, t, fndecl, pfn;
2511 {
2512 tree virtuals = BINFO_VIRTUALS (binfo);
2513 unsigned HOST_WIDE_INT n;
2514
2515 /* update rtti entry */
2516 if (flag_rtti)
2517 {
2518 if (binfo == TYPE_BINFO (t))
2519 {
2520 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2521 build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t))), t);
2522 }
2523 else
2524 {
2525 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2526 prepare_fresh_vtable (binfo, t);
2527 }
2528 }
2529 if (fndecl == NULL_TREE)
2530 return;
2531
2532 n = skip_rtti_stuff (&virtuals);
2533
2534 while (virtuals)
2535 {
2536 tree current_fndecl = TREE_VALUE (virtuals);
2537 current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl);
2538 current_fndecl = TREE_OPERAND (current_fndecl, 0);
2539 if (current_fndecl && overrides (fndecl, current_fndecl))
2540 {
2541 tree base_offset, offset;
2542 tree context = DECL_CLASS_CONTEXT (fndecl);
2543 tree vfield = CLASSTYPE_VFIELD (t);
2544 tree this_offset;
2545
2546 offset = get_class_offset (context, t, binfo, fndecl);
2547
2548 /* Find the right offset for the this pointer based on the
2549 base class we just found. We have to take into
2550 consideration the virtual base class pointers that we
2551 stick in before the virtual function table pointer.
2552
2553 Also, we want just the delta between the most base class
2554 that we derived this vfield from and us. */
2555 base_offset = size_binop (PLUS_EXPR,
2556 get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)),
2557 BINFO_OFFSET (binfo));
2558 this_offset = ssize_binop (MINUS_EXPR, offset, base_offset);
2559
2560 if (binfo == TYPE_BINFO (t))
2561 {
2562 /* In this case, it is *type*'s vtable we are modifying.
2563 We start with the approximation that it's vtable is that
2564 of the immediate base class. */
2565 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2566 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2567 }
2568 else
2569 {
2570 /* This is our very own copy of `basetype' to play with.
2571 Later, we will fill in all the virtual functions
2572 that override the virtual functions in these base classes
2573 which are not defined by the current type. */
2574 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2575 prepare_fresh_vtable (binfo, t);
2576 }
2577
2578 #ifdef NOTQUITE
2579 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo)));
2580 #endif
2581 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2582 build_vtable_entry (this_offset, pfn),
2583 fndecl);
2584 }
2585 ++n;
2586 virtuals = TREE_CHAIN (virtuals);
2587 }
2588 }
2589
2590 /* These are the ones that are not through virtual base classes. */
2591
2592 static void
2593 modify_all_direct_vtables (binfo, do_self, t, fndecl, pfn)
2594 tree binfo;
2595 int do_self;
2596 tree t, fndecl, pfn;
2597 {
2598 tree binfos = BINFO_BASETYPES (binfo);
2599 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2600
2601 /* Should we use something besides CLASSTYPE_VFIELDS? */
2602 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2603 {
2604 modify_one_vtable (binfo, t, fndecl, pfn);
2605 }
2606
2607 for (i = 0; i < n_baselinks; i++)
2608 {
2609 tree base_binfo = TREE_VEC_ELT (binfos, i);
2610 int is_not_base_vtable
2611 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2612 if (! TREE_VIA_VIRTUAL (base_binfo))
2613 modify_all_direct_vtables (base_binfo, is_not_base_vtable, t, fndecl, pfn);
2614 }
2615 }
2616
2617 /* Fixup all the delta entries in this one vtable that need updating. */
2618
2619 static void
2620 fixup_vtable_deltas1 (binfo, t)
2621 tree binfo, t;
2622 {
2623 tree virtuals = BINFO_VIRTUALS (binfo);
2624 unsigned HOST_WIDE_INT n;
2625
2626 n = skip_rtti_stuff (&virtuals);
2627
2628 while (virtuals)
2629 {
2630 tree fndecl = TREE_VALUE (virtuals);
2631 tree pfn = FNADDR_FROM_VTABLE_ENTRY (fndecl);
2632 tree delta = DELTA_FROM_VTABLE_ENTRY (fndecl);
2633 fndecl = TREE_OPERAND (pfn, 0);
2634 if (fndecl)
2635 {
2636 tree base_offset, offset;
2637 tree context = DECL_CLASS_CONTEXT (fndecl);
2638 tree vfield = CLASSTYPE_VFIELD (t);
2639 tree this_offset;
2640
2641 offset = get_class_offset (context, t, binfo, fndecl);
2642
2643 /* Find the right offset for the this pointer based on the
2644 base class we just found. We have to take into
2645 consideration the virtual base class pointers that we
2646 stick in before the virtual function table pointer.
2647
2648 Also, we want just the delta between the most base class
2649 that we derived this vfield from and us. */
2650 base_offset = size_binop (PLUS_EXPR,
2651 get_derived_offset (binfo,
2652 DECL_CONTEXT (fndecl)),
2653 BINFO_OFFSET (binfo));
2654 this_offset = ssize_binop (MINUS_EXPR, offset, base_offset);
2655
2656 if (! tree_int_cst_equal (this_offset, delta))
2657 {
2658 /* Make sure we can modify the derived association with immunity. */
2659 if (binfo == TYPE_BINFO (t))
2660 {
2661 /* In this case, it is *type*'s vtable we are modifying.
2662 We start with the approximation that it's vtable is that
2663 of the immediate base class. */
2664 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2665 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2666 }
2667 else
2668 {
2669 /* This is our very own copy of `basetype' to play with.
2670 Later, we will fill in all the virtual functions
2671 that override the virtual functions in these base classes
2672 which are not defined by the current type. */
2673 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2674 prepare_fresh_vtable (binfo, t);
2675 }
2676
2677 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2678 build_vtable_entry (this_offset, pfn),
2679 fndecl);
2680 }
2681 }
2682 ++n;
2683 virtuals = TREE_CHAIN (virtuals);
2684 }
2685 }
2686
2687 /* Fixup all the delta entries in all the direct vtables that need updating.
2688 This happens when we have non-overridden virtual functions from a
2689 virtual base class, that are at a different offset, in the new
2690 hierarchy, because the layout of the virtual bases has changed. */
2691
2692 static void
2693 fixup_vtable_deltas (binfo, init_self, t)
2694 tree binfo;
2695 int init_self;
2696 tree t;
2697 {
2698 tree binfos = BINFO_BASETYPES (binfo);
2699 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2700
2701 for (i = 0; i < n_baselinks; i++)
2702 {
2703 tree base_binfo = TREE_VEC_ELT (binfos, i);
2704 int is_not_base_vtable
2705 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2706 if (! TREE_VIA_VIRTUAL (base_binfo))
2707 fixup_vtable_deltas (base_binfo, is_not_base_vtable, t);
2708 }
2709 /* Should we use something besides CLASSTYPE_VFIELDS? */
2710 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2711 {
2712 fixup_vtable_deltas1 (binfo, t);
2713 }
2714 }
2715
2716 /* These are the ones that are through virtual base classes. */
2717
2718 static void
2719 modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl, pfn)
2720 tree binfo;
2721 int do_self, via_virtual;
2722 tree t, fndecl, pfn;
2723 {
2724 tree binfos = BINFO_BASETYPES (binfo);
2725 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2726
2727 /* Should we use something besides CLASSTYPE_VFIELDS? */
2728 if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2729 {
2730 modify_one_vtable (binfo, t, fndecl, pfn);
2731 }
2732
2733 for (i = 0; i < n_baselinks; i++)
2734 {
2735 tree base_binfo = TREE_VEC_ELT (binfos, i);
2736 int is_not_base_vtable
2737 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2738 if (TREE_VIA_VIRTUAL (base_binfo))
2739 {
2740 via_virtual = 1;
2741 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2742 }
2743 modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl, pfn);
2744 }
2745 }
2746
2747 static void
2748 modify_all_vtables (t, fndecl, vfn)
2749 tree t, fndecl, vfn;
2750 {
2751 /* Do these first, so that we will make use of any non-virtual class's
2752 vtable, over a virtual classes vtable. */
2753 modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl, vfn);
2754 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
2755 modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl, vfn);
2756 }
2757
2758 /* Here, we already know that they match in every respect.
2759 All we have to check is where they had their declarations. */
2760
2761 static int
2762 strictly_overrides (fndecl1, fndecl2)
2763 tree fndecl1, fndecl2;
2764 {
2765 int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2),
2766 DECL_CLASS_CONTEXT (fndecl1),
2767 0, (tree *)0);
2768 if (distance == -2 || distance > 0)
2769 return 1;
2770 return 0;
2771 }
2772
2773 /* Merge overrides for one vtable.
2774 If we want to merge in same function, we are fine.
2775 else
2776 if one has a DECL_CLASS_CONTEXT that is a parent of the
2777 other, than choose the more derived one
2778 else
2779 potentially ill-formed (see 10.3 [class.virtual])
2780 we have to check later to see if there was an
2781 override in this class. If there was ok, if not
2782 then it is ill-formed. (mrs)
2783
2784 We take special care to reuse a vtable, if we can. */
2785
2786 static void
2787 override_one_vtable (binfo, old, t)
2788 tree binfo, old, t;
2789 {
2790 tree virtuals = BINFO_VIRTUALS (binfo);
2791 tree old_virtuals = BINFO_VIRTUALS (old);
2792 enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
2793
2794 /* If we have already committed to modifying it, then don't try and
2795 reuse another vtable. */
2796 if (BINFO_NEW_VTABLE_MARKED (binfo))
2797 choose = NEITHER;
2798
2799 skip_rtti_stuff (&virtuals);
2800 skip_rtti_stuff (&old_virtuals);
2801
2802 while (virtuals)
2803 {
2804 tree fndecl = TREE_VALUE (virtuals);
2805 tree old_fndecl = TREE_VALUE (old_virtuals);
2806 fndecl = FNADDR_FROM_VTABLE_ENTRY (fndecl);
2807 old_fndecl = FNADDR_FROM_VTABLE_ENTRY (old_fndecl);
2808 fndecl = TREE_OPERAND (fndecl, 0);
2809 old_fndecl = TREE_OPERAND (old_fndecl, 0);
2810 /* First check to see if they are the same. */
2811 if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl))
2812 {
2813 /* No need to do anything. */
2814 }
2815 else if (strictly_overrides (fndecl, old_fndecl))
2816 {
2817 if (choose == UNDECIDED)
2818 choose = REUSE_NEW;
2819 else if (choose == REUSE_OLD)
2820 {
2821 choose = NEITHER;
2822 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2823 {
2824 prepare_fresh_vtable (binfo, t);
2825 override_one_vtable (binfo, old, t);
2826 return;
2827 }
2828 }
2829 }
2830 else if (strictly_overrides (old_fndecl, fndecl))
2831 {
2832 if (choose == UNDECIDED)
2833 choose = REUSE_OLD;
2834 else if (choose == REUSE_NEW)
2835 {
2836 choose = NEITHER;
2837 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2838 {
2839 prepare_fresh_vtable (binfo, t);
2840 override_one_vtable (binfo, old, t);
2841 return;
2842 }
2843 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2844 }
2845 else if (choose == NEITHER)
2846 {
2847 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2848 }
2849 }
2850 else
2851 {
2852 choose = NEITHER;
2853 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2854 {
2855 prepare_fresh_vtable (binfo, t);
2856 override_one_vtable (binfo, old, t);
2857 return;
2858 }
2859 {
2860 /* This MUST be overridden, or the class is ill-formed. */
2861 tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
2862 tree vfn;
2863
2864 fndecl = copy_node (fndecl);
2865 copy_lang_decl (fndecl);
2866 DECL_NEEDS_FINAL_OVERRIDER_P (fndecl) = 1;
2867 /* Make sure we search for it later. */
2868 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t))
2869 CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node;
2870
2871 vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
2872 TREE_CONSTANT (vfn) = 1;
2873
2874 /* We can use integer_zero_node, as we will core dump
2875 if this is used anyway. */
2876 TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, vfn);
2877 }
2878 }
2879 virtuals = TREE_CHAIN (virtuals);
2880 old_virtuals = TREE_CHAIN (old_virtuals);
2881 }
2882
2883 /* Let's reuse the old vtable. */
2884 if (choose == REUSE_OLD)
2885 {
2886 BINFO_VTABLE (binfo) = BINFO_VTABLE (old);
2887 BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old);
2888 }
2889 }
2890
2891 /* Merge in overrides for virtual bases.
2892 BINFO is the hierarchy we want to modify, and OLD has the potential
2893 overrides. */
2894
2895 static void
2896 merge_overrides (binfo, old, do_self, t)
2897 tree binfo, old;
2898 int do_self;
2899 tree t;
2900 {
2901 tree binfos = BINFO_BASETYPES (binfo);
2902 tree old_binfos = BINFO_BASETYPES (old);
2903 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2904
2905 /* Should we use something besides CLASSTYPE_VFIELDS? */
2906 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2907 {
2908 override_one_vtable (binfo, old, t);
2909 }
2910
2911 for (i = 0; i < n_baselinks; i++)
2912 {
2913 tree base_binfo = TREE_VEC_ELT (binfos, i);
2914 tree old_base_binfo = TREE_VEC_ELT (old_binfos, i);
2915 int is_not_base_vtable
2916 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2917 if (! TREE_VIA_VIRTUAL (base_binfo))
2918 merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t);
2919 }
2920 }
2921
2922 /* Get the base virtual function declarations in T that are either
2923 overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
2924 the overrider/hider. */
2925
2926 static tree
2927 get_basefndecls (fndecl, t)
2928 tree fndecl, t;
2929 {
2930 tree methods = TYPE_METHODS (t);
2931 tree base_fndecls = NULL_TREE;
2932 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2933 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2934
2935 while (methods)
2936 {
2937 if (TREE_CODE (methods) == FUNCTION_DECL
2938 && DECL_VINDEX (methods) != NULL_TREE
2939 && DECL_NAME (fndecl) == DECL_NAME (methods))
2940 base_fndecls = temp_tree_cons (fndecl, methods, base_fndecls);
2941
2942 methods = TREE_CHAIN (methods);
2943 }
2944
2945 if (base_fndecls)
2946 return base_fndecls;
2947
2948 for (i = 0; i < n_baseclasses; i++)
2949 {
2950 tree base_binfo = TREE_VEC_ELT (binfos, i);
2951 tree basetype = BINFO_TYPE (base_binfo);
2952
2953 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
2954 base_fndecls);
2955 }
2956
2957 return base_fndecls;
2958 }
2959
2960 /* Mark the functions that have been hidden with their overriders.
2961 Since we start out with all functions already marked with a hider,
2962 no need to mark functions that are just hidden. */
2963
2964 static void
2965 mark_overriders (fndecl, base_fndecls)
2966 tree fndecl, base_fndecls;
2967 {
2968 while (base_fndecls)
2969 {
2970 if (overrides (TREE_VALUE (base_fndecls), fndecl))
2971 TREE_PURPOSE (base_fndecls) = fndecl;
2972
2973 base_fndecls = TREE_CHAIN (base_fndecls);
2974 }
2975 }
2976
2977 /* If this declaration supersedes the declaration of
2978 a method declared virtual in the base class, then
2979 mark this field as being virtual as well. */
2980
2981 static void
2982 check_for_override (decl, ctype)
2983 tree decl, ctype;
2984 {
2985 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
2986 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2987 int virtualp = DECL_VIRTUAL_P (decl);
2988
2989 for (i = 0; i < n_baselinks; i++)
2990 {
2991 tree base_binfo = TREE_VEC_ELT (binfos, i);
2992 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)))
2993 {
2994 tree tmp = get_matching_virtual
2995 (base_binfo, decl,
2996 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)));
2997 if (tmp)
2998 {
2999 /* If this function overrides some virtual in some base
3000 class, then the function itself is also necessarily
3001 virtual, even if the user didn't explicitly say so. */
3002 DECL_VIRTUAL_P (decl) = 1;
3003
3004 /* The TMP we really want is the one from the deepest
3005 baseclass on this path, taking care not to
3006 duplicate if we have already found it (via another
3007 path to its virtual baseclass. */
3008 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
3009 {
3010 cp_error_at ("method `%D' may not be declared static",
3011 decl);
3012 cp_error_at ("(since `%D' declared virtual in base class.)",
3013 tmp);
3014 break;
3015 }
3016 virtualp = 1;
3017
3018 #if 0 /* The signature of an overriding function is not changed. */
3019 {
3020 /* The argument types may have changed... */
3021 tree type = TREE_TYPE (decl);
3022 tree argtypes = TYPE_ARG_TYPES (type);
3023 tree base_variant = TREE_TYPE (TREE_VALUE (argtypes));
3024 tree raises = TYPE_RAISES_EXCEPTIONS (type);
3025
3026 argtypes = commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp))),
3027 TREE_CHAIN (argtypes));
3028 /* But the return type has not. */
3029 type = build_cplus_method_type (base_variant, TREE_TYPE (type), argtypes);
3030 if (raises)
3031 type = build_exception_variant (type, raises);
3032 TREE_TYPE (decl) = type;
3033 }
3034 #endif
3035 DECL_VINDEX (decl)
3036 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
3037 break;
3038 }
3039 }
3040 }
3041 if (virtualp)
3042 {
3043 if (DECL_VINDEX (decl) == NULL_TREE)
3044 DECL_VINDEX (decl) = error_mark_node;
3045 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
3046 }
3047 }
3048
3049 /* Warn about hidden virtual functions that are not overridden in t.
3050 We know that constructors and destructors don't apply. */
3051
3052 void
3053 warn_hidden (t)
3054 tree t;
3055 {
3056 tree method_vec = CLASSTYPE_METHOD_VEC (t);
3057 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3058 int i;
3059
3060 /* We go through each separately named virtual function. */
3061 for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); ++i)
3062 {
3063 tree fns = TREE_VEC_ELT (method_vec, i);
3064 tree fndecl;
3065
3066 tree base_fndecls = NULL_TREE;
3067 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
3068 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3069
3070 fndecl = OVL_CURRENT (fns);
3071 if (DECL_VINDEX (fndecl) == NULL_TREE)
3072 continue;
3073
3074 /* First we get a list of all possible functions that might be
3075 hidden from each base class. */
3076 for (i = 0; i < n_baseclasses; i++)
3077 {
3078 tree base_binfo = TREE_VEC_ELT (binfos, i);
3079 tree basetype = BINFO_TYPE (base_binfo);
3080
3081 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
3082 base_fndecls);
3083 }
3084
3085 fns = OVL_NEXT (fns);
3086 if (fns)
3087 fndecl = OVL_CURRENT (fns);
3088 else
3089 fndecl = NULL_TREE;
3090
3091 /* ...then mark up all the base functions with overriders, preferring
3092 overriders to hiders. */
3093 if (base_fndecls)
3094 while (fndecl)
3095 {
3096 mark_overriders (fndecl, base_fndecls);
3097
3098 fns = OVL_NEXT (fns);
3099 if (fns)
3100 fndecl = OVL_CURRENT (fns);
3101 else
3102 fndecl = NULL_TREE;
3103 }
3104
3105 /* Now give a warning for all base functions without overriders,
3106 as they are hidden. */
3107 while (base_fndecls)
3108 {
3109 if (! overrides (TREE_VALUE (base_fndecls),
3110 TREE_PURPOSE (base_fndecls)))
3111 {
3112 /* Here we know it is a hider, and no overrider exists. */
3113 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
3114 cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls));
3115 }
3116
3117 base_fndecls = TREE_CHAIN (base_fndecls);
3118 }
3119 }
3120 }
3121
3122 /* Check for things that are invalid. There are probably plenty of other
3123 things we should check for also. */
3124
3125 static void
3126 finish_struct_anon (t)
3127 tree t;
3128 {
3129 tree field;
3130 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
3131 {
3132 if (TREE_STATIC (field))
3133 continue;
3134 if (TREE_CODE (field) != FIELD_DECL)
3135 continue;
3136
3137 if (DECL_NAME (field) == NULL_TREE
3138 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
3139 {
3140 tree* uelt = &TYPE_FIELDS (TREE_TYPE (field));
3141 for (; *uelt; uelt = &TREE_CHAIN (*uelt))
3142 {
3143 if (DECL_ARTIFICIAL (*uelt))
3144 continue;
3145
3146 if (DECL_NAME (*uelt) == constructor_name (t))
3147 cp_pedwarn_at ("ANSI C++ forbids member `%D' with same name as enclosing class",
3148 *uelt);
3149
3150 if (TREE_CODE (*uelt) != FIELD_DECL)
3151 {
3152 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
3153 *uelt);
3154 continue;
3155 }
3156
3157 if (TREE_PRIVATE (*uelt))
3158 cp_pedwarn_at ("private member `%#D' in anonymous union",
3159 *uelt);
3160 else if (TREE_PROTECTED (*uelt))
3161 cp_pedwarn_at ("protected member `%#D' in anonymous union",
3162 *uelt);
3163
3164 TREE_PRIVATE (*uelt) = TREE_PRIVATE (field);
3165 TREE_PROTECTED (*uelt) = TREE_PROTECTED (field);
3166 }
3167 }
3168 }
3169 }
3170
3171 extern int interface_only, interface_unknown;
3172
3173 /* Create default constructors, assignment operators, and so forth for
3174 the type indicated by T, if they are needed.
3175 CANT_HAVE_DEFAULT_CTOR, CANT_HAVE_CONST_CTOR, and
3176 CANT_HAVE_ASSIGNMENT are nonzero if, for whatever reason, the class
3177 cannot have a default constructor, copy constructor taking a const
3178 reference argument, or an assignment operator, respectively. If a
3179 virtual destructor is created, its DECL is returned; otherwise the
3180 return value is NULL_TREE. */
3181
3182 static tree
3183 add_implicitly_declared_members (t, cant_have_default_ctor,
3184 cant_have_const_cctor,
3185 cant_have_assignment)
3186 tree t;
3187 int cant_have_default_ctor;
3188 int cant_have_const_cctor;
3189 int cant_have_assignment;
3190 {
3191 tree default_fn;
3192 tree implicit_fns = NULL_TREE;
3193 tree name = TYPE_IDENTIFIER (t);
3194 tree virtual_dtor = NULL_TREE;
3195 tree *f;
3196
3197 /* Destructor. */
3198 if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t)
3199 && !IS_SIGNATURE (t))
3200 {
3201 default_fn = cons_up_default_function (t, name, 0);
3202 check_for_override (default_fn, t);
3203
3204 /* If we couldn't make it work, then pretend we didn't need it. */
3205 if (default_fn == void_type_node)
3206 TYPE_NEEDS_DESTRUCTOR (t) = 0;
3207 else
3208 {
3209 TREE_CHAIN (default_fn) = implicit_fns;
3210 implicit_fns = default_fn;
3211
3212 if (DECL_VINDEX (default_fn))
3213 virtual_dtor = default_fn;
3214 }
3215 }
3216 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
3217
3218 /* Default constructor. */
3219 if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor
3220 && ! IS_SIGNATURE (t))
3221 {
3222 default_fn = cons_up_default_function (t, name, 2);
3223 TREE_CHAIN (default_fn) = implicit_fns;
3224 implicit_fns = default_fn;
3225 }
3226
3227 /* Copy constructor. */
3228 if (! TYPE_HAS_INIT_REF (t) && ! IS_SIGNATURE (t) && ! TYPE_FOR_JAVA (t))
3229 {
3230 /* ARM 12.18: You get either X(X&) or X(const X&), but
3231 not both. --Chip */
3232 default_fn = cons_up_default_function (t, name,
3233 3 + cant_have_const_cctor);
3234 TREE_CHAIN (default_fn) = implicit_fns;
3235 implicit_fns = default_fn;
3236 }
3237
3238 /* Assignment operator. */
3239 if (! TYPE_HAS_ASSIGN_REF (t) && ! IS_SIGNATURE (t) && ! TYPE_FOR_JAVA (t))
3240 {
3241 default_fn = cons_up_default_function (t, name,
3242 5 + cant_have_assignment);
3243 TREE_CHAIN (default_fn) = implicit_fns;
3244 implicit_fns = default_fn;
3245 }
3246
3247 /* Now, hook all of the new functions on to TYPE_METHODS,
3248 and add them to the CLASSTYPE_METHOD_VEC. */
3249 for (f = &implicit_fns; *f; f = &TREE_CHAIN (*f))
3250 add_method (t, 0, *f);
3251 *f = TYPE_METHODS (t);
3252 TYPE_METHODS (t) = implicit_fns;
3253
3254 return virtual_dtor;
3255 }
3256
3257 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
3258 (or C++ class declaration).
3259
3260 For C++, we must handle the building of derived classes.
3261 Also, C++ allows static class members. The way that this is
3262 handled is to keep the field name where it is (as the DECL_NAME
3263 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
3264 of the field. layout_record and layout_union will know about this.
3265
3266 More C++ hair: inline functions have text in their
3267 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
3268 meaningful tree structure. After the struct has been laid out, set
3269 things up so that this can happen.
3270
3271 And still more: virtual functions. In the case of single inheritance,
3272 when a new virtual function is seen which redefines a virtual function
3273 from the base class, the new virtual function is placed into
3274 the virtual function table at exactly the same address that
3275 it had in the base class. When this is extended to multiple
3276 inheritance, the same thing happens, except that multiple virtual
3277 function tables must be maintained. The first virtual function
3278 table is treated in exactly the same way as in the case of single
3279 inheritance. Additional virtual function tables have different
3280 DELTAs, which tell how to adjust `this' to point to the right thing.
3281
3282 ATTRIBUTES is the set of decl attributes to be applied, if any. */
3283
3284 tree
3285 finish_struct_1 (t, warn_anon)
3286 tree t;
3287 int warn_anon;
3288 {
3289 int old;
3290 enum tree_code code = TREE_CODE (t);
3291 tree fields = TYPE_FIELDS (t);
3292 tree x, last_x, method_vec;
3293 int has_virtual;
3294 int max_has_virtual;
3295 tree pending_virtuals = NULL_TREE;
3296 tree pending_hard_virtuals = NULL_TREE;
3297 tree abstract_virtuals = NULL_TREE;
3298 tree vfield;
3299 tree vfields;
3300 tree virtual_dtor;
3301 int cant_have_default_ctor;
3302 int cant_have_const_ctor;
3303 int no_const_asn_ref;
3304
3305 /* The index of the first base class which has virtual
3306 functions. Only applied to non-virtual baseclasses. */
3307 int first_vfn_base_index;
3308
3309 int n_baseclasses;
3310 int any_default_members = 0;
3311 int const_sans_init = 0;
3312 int ref_sans_init = 0;
3313 tree access_decls = NULL_TREE;
3314 int aggregate = 1;
3315 int empty = 1;
3316 int has_pointers = 0;
3317
3318 if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (TYPE_IDENTIFIER (t)))
3319 pedwarn ("anonymous class type not used to declare any objects");
3320
3321 if (TYPE_SIZE (t))
3322 {
3323 if (IS_AGGR_TYPE (t))
3324 cp_error ("redefinition of `%#T'", t);
3325 else
3326 my_friendly_abort (172);
3327 popclass (0);
3328 return t;
3329 }
3330
3331 GNU_xref_decl (current_function_decl, t);
3332
3333 /* If this type was previously laid out as a forward reference,
3334 make sure we lay it out again. */
3335
3336 TYPE_SIZE (t) = NULL_TREE;
3337 CLASSTYPE_GOT_SEMICOLON (t) = 0;
3338
3339 #if 0
3340 /* This is in general too late to do this. I moved the main case up to
3341 left_curly, what else needs to move? */
3342 if (! IS_SIGNATURE (t))
3343 {
3344 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
3345 my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t) == ! interface_unknown, 999);
3346 }
3347 #endif
3348
3349 old = suspend_momentary ();
3350
3351 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
3352 Also process specified field sizes.
3353 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
3354 The specified size is found in the DECL_INITIAL.
3355 Store 0 there, except for ": 0" fields (so we can find them
3356 and delete them, below). */
3357
3358 if (TYPE_BINFO_BASETYPES (t))
3359 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t));
3360 else
3361 n_baseclasses = 0;
3362
3363 if (n_baseclasses > 0)
3364 {
3365 struct base_info base_info;
3366
3367 first_vfn_base_index = finish_base_struct (t, &base_info);
3368 /* Remember where we got our vfield from. */
3369 CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index;
3370 has_virtual = base_info.has_virtual;
3371 max_has_virtual = base_info.max_has_virtual;
3372 CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors;
3373 vfield = base_info.vfield;
3374 vfields = base_info.vfields;
3375 CLASSTYPE_RTTI (t) = base_info.rtti;
3376 cant_have_default_ctor = base_info.cant_have_default_ctor;
3377 cant_have_const_ctor = base_info.cant_have_const_ctor;
3378 no_const_asn_ref = base_info.no_const_asn_ref;
3379 aggregate = 0;
3380 }
3381 else
3382 {
3383 first_vfn_base_index = -1;
3384 has_virtual = 0;
3385 max_has_virtual = has_virtual;
3386 vfield = NULL_TREE;
3387 vfields = NULL_TREE;
3388 CLASSTYPE_RTTI (t) = NULL_TREE;
3389 cant_have_default_ctor = 0;
3390 cant_have_const_ctor = 0;
3391 no_const_asn_ref = 0;
3392 }
3393
3394 #if 0
3395 /* Both of these should be done before now. */
3396 if (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t)
3397 && ! IS_SIGNATURE (t))
3398 {
3399 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
3400 my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t) == ! interface_only, 999);
3401 }
3402 #endif
3403
3404 /* The three of these are approximations which may later be
3405 modified. Needed at this point to make add_virtual_function
3406 and modify_vtable_entries work. */
3407 CLASSTYPE_VFIELDS (t) = vfields;
3408 CLASSTYPE_VFIELD (t) = vfield;
3409
3410 for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
3411 {
3412 GNU_xref_member (current_class_name, x);
3413
3414 /* If this was an evil function, don't keep it in class. */
3415 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
3416 continue;
3417
3418 /* Do both of these, even though they're in the same union;
3419 if the insn `r' member and the size `i' member are
3420 different sizes, as on the alpha, the larger of the two
3421 will end up with garbage in it. */
3422 DECL_SAVED_INSNS (x) = NULL_RTX;
3423 DECL_FIELD_SIZE (x) = 0;
3424
3425 check_for_override (x, t);
3426 if (DECL_ABSTRACT_VIRTUAL_P (x) && ! DECL_VINDEX (x))
3427 cp_error_at ("initializer specified for non-virtual method `%D'", x);
3428
3429 /* The name of the field is the original field name
3430 Save this in auxiliary field for later overloading. */
3431 if (DECL_VINDEX (x))
3432 {
3433 add_virtual_function (&pending_virtuals, &pending_hard_virtuals,
3434 &has_virtual, x, t);
3435 if (DECL_ABSTRACT_VIRTUAL_P (x))
3436 abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals);
3437 #if 0
3438 /* XXX Why did I comment this out? (jason) */
3439 else
3440 TREE_USED (x) = 1;
3441 #endif
3442 }
3443 }
3444
3445 if (n_baseclasses)
3446 fields = chainon (build_vbase_pointer_fields (t), fields);
3447
3448 last_x = NULL_TREE;
3449 for (x = fields; x; x = TREE_CHAIN (x))
3450 {
3451 GNU_xref_member (current_class_name, x);
3452
3453 if (TREE_CODE (x) == FIELD_DECL)
3454 {
3455 DECL_PACKED (x) |= TYPE_PACKED (t);
3456 empty = 0;
3457 }
3458
3459 if (TREE_CODE (x) == USING_DECL)
3460 {
3461 /* Save access declarations for later. */
3462 if (last_x)
3463 TREE_CHAIN (last_x) = TREE_CHAIN (x);
3464 else
3465 fields = TREE_CHAIN (x);
3466
3467 access_decls = scratch_tree_cons (NULL_TREE, x, access_decls);
3468 continue;
3469 }
3470
3471 last_x = x;
3472
3473 if (TREE_CODE (x) == TYPE_DECL
3474 || TREE_CODE (x) == TEMPLATE_DECL)
3475 continue;
3476
3477 /* If we've gotten this far, it's a data member, possibly static,
3478 or an enumerator. */
3479
3480 DECL_FIELD_CONTEXT (x) = t;
3481
3482 /* ``A local class cannot have static data members.'' ARM 9.4 */
3483 if (current_function_decl && TREE_STATIC (x))
3484 cp_error_at ("field `%D' in local class cannot be static", x);
3485
3486 /* Perform error checking that did not get done in
3487 grokdeclarator. */
3488 if (TREE_CODE (TREE_TYPE (x)) == FUNCTION_TYPE)
3489 {
3490 cp_error_at ("field `%D' invalidly declared function type",
3491 x);
3492 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3493 }
3494 else if (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE)
3495 {
3496 cp_error_at ("field `%D' invalidly declared method type", x);
3497 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3498 }
3499 else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE)
3500 {
3501 cp_error_at ("field `%D' invalidly declared offset type", x);
3502 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3503 }
3504
3505 #if 0
3506 if (DECL_NAME (x) == constructor_name (t))
3507 cant_have_default_ctor = 1;
3508 #endif
3509
3510 if (TREE_TYPE (x) == error_mark_node)
3511 continue;
3512
3513 DECL_SAVED_INSNS (x) = NULL_RTX;
3514 DECL_FIELD_SIZE (x) = 0;
3515
3516 /* When this goes into scope, it will be a non-local reference. */
3517 DECL_NONLOCAL (x) = 1;
3518
3519 if (TREE_CODE (x) == CONST_DECL)
3520 continue;
3521
3522 if (TREE_CODE (x) == VAR_DECL)
3523 {
3524 if (TREE_CODE (t) == UNION_TYPE)
3525 /* Unions cannot have static members. */
3526 cp_error_at ("field `%D' declared static in union", x);
3527
3528 continue;
3529 }
3530
3531 /* Now it can only be a FIELD_DECL. */
3532
3533 if (TREE_PRIVATE (x) || TREE_PROTECTED (x))
3534 aggregate = 0;
3535
3536 /* If this is of reference type, check if it needs an init.
3537 Also do a little ANSI jig if necessary. */
3538 if (TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE)
3539 {
3540 if (DECL_INITIAL (x) == NULL_TREE)
3541 ref_sans_init = 1;
3542
3543 /* ARM $12.6.2: [A member initializer list] (or, for an
3544 aggregate, initialization by a brace-enclosed list) is the
3545 only way to initialize nonstatic const and reference
3546 members. */
3547 cant_have_default_ctor = 1;
3548 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3549
3550 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3551 {
3552 if (DECL_NAME (x))
3553 cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
3554 else
3555 cp_warning_at ("non-static reference in class without a constructor", x);
3556 }
3557 }
3558
3559 if (TREE_CODE (TREE_TYPE (x)) == POINTER_TYPE)
3560 has_pointers = 1;
3561
3562 /* If any field is const, the structure type is pseudo-const. */
3563 if (TREE_READONLY (x))
3564 {
3565 C_TYPE_FIELDS_READONLY (t) = 1;
3566 if (DECL_INITIAL (x) == NULL_TREE)
3567 const_sans_init = 1;
3568
3569 /* ARM $12.6.2: [A member initializer list] (or, for an
3570 aggregate, initialization by a brace-enclosed list) is the
3571 only way to initialize nonstatic const and reference
3572 members. */
3573 cant_have_default_ctor = 1;
3574 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3575
3576 if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t)
3577 && extra_warnings)
3578 {
3579 if (DECL_NAME (x))
3580 cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
3581 else
3582 cp_warning_at ("non-static const member in class without a constructor", x);
3583 }
3584 }
3585 else
3586 {
3587 /* A field that is pseudo-const makes the structure
3588 likewise. */
3589 tree t1 = TREE_TYPE (x);
3590 while (TREE_CODE (t1) == ARRAY_TYPE)
3591 t1 = TREE_TYPE (t1);
3592 if (IS_AGGR_TYPE (t1))
3593 {
3594 if (C_TYPE_FIELDS_READONLY (t1))
3595 C_TYPE_FIELDS_READONLY (t) = 1;
3596 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1))
3597 const_sans_init = 1;
3598 }
3599 }
3600
3601 /* We set DECL_C_BIT_FIELD in grokbitfield.
3602 If the type and width are valid, we'll also set DECL_BIT_FIELD. */
3603 if (DECL_C_BIT_FIELD (x))
3604 {
3605 /* Invalid bit-field size done by grokfield. */
3606 /* Detect invalid bit-field type. */
3607 if (DECL_INITIAL (x)
3608 && ! INTEGRAL_TYPE_P (TREE_TYPE (x)))
3609 {
3610 cp_error_at ("bit-field `%#D' with non-integral type", x);
3611 DECL_INITIAL (x) = NULL;
3612 }
3613
3614 /* Detect and ignore out of range field width. */
3615 if (DECL_INITIAL (x))
3616 {
3617 tree w = DECL_INITIAL (x);
3618 register int width = 0;
3619
3620 /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */
3621 STRIP_NOPS (w);
3622
3623 /* detect invalid field size. */
3624 if (TREE_CODE (w) == CONST_DECL)
3625 w = DECL_INITIAL (w);
3626 else if (TREE_READONLY_DECL_P (w))
3627 w = decl_constant_value (w);
3628
3629 if (TREE_CODE (w) != INTEGER_CST)
3630 {
3631 cp_error_at ("bit-field `%D' width not an integer constant",
3632 x);
3633 DECL_INITIAL (x) = NULL_TREE;
3634 }
3635 else if (width = TREE_INT_CST_LOW (w),
3636 width < 0)
3637 {
3638 DECL_INITIAL (x) = NULL;
3639 cp_error_at ("negative width in bit-field `%D'", x);
3640 }
3641 else if (width == 0 && DECL_NAME (x) != 0)
3642 {
3643 DECL_INITIAL (x) = NULL;
3644 cp_error_at ("zero width for bit-field `%D'", x);
3645 }
3646 else if (width
3647 > TYPE_PRECISION (long_long_unsigned_type_node))
3648 {
3649 /* The backend will dump if you try to use something
3650 too big; avoid that. */
3651 DECL_INITIAL (x) = NULL;
3652 sorry ("bit-fields larger than %d bits",
3653 TYPE_PRECISION (long_long_unsigned_type_node));
3654 cp_error_at (" in declaration of `%D'", x);
3655 }
3656 else if (width > TYPE_PRECISION (TREE_TYPE (x))
3657 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE
3658 && TREE_CODE (TREE_TYPE (x)) != BOOLEAN_TYPE)
3659 {
3660 cp_warning_at ("width of `%D' exceeds its type", x);
3661 }
3662 else if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
3663 && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
3664 TREE_UNSIGNED (TREE_TYPE (x))) > width)
3665 || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
3666 TREE_UNSIGNED (TREE_TYPE (x))) > width)))
3667 {
3668 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3669 x, TREE_TYPE (x));
3670 }
3671
3672 if (DECL_INITIAL (x) == NULL_TREE)
3673 ;
3674 else if (width == 0)
3675 {
3676 #ifdef EMPTY_FIELD_BOUNDARY
3677 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), EMPTY_FIELD_BOUNDARY);
3678 #endif
3679 #ifdef PCC_BITFIELD_TYPE_MATTERS
3680 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
3681 TYPE_ALIGN (TREE_TYPE (x)));
3682 #endif
3683 }
3684 else
3685 {
3686 DECL_INITIAL (x) = NULL_TREE;
3687 DECL_FIELD_SIZE (x) = width;
3688 DECL_BIT_FIELD (x) = 1;
3689 }
3690 }
3691 else
3692 /* Non-bit-fields are aligned for their type. */
3693 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
3694 }
3695 else
3696 {
3697 tree type = TREE_TYPE (x);
3698
3699 while (TREE_CODE (type) == ARRAY_TYPE)
3700 type = TREE_TYPE (type);
3701
3702 if (TYPE_LANG_SPECIFIC (type) && ! ANON_UNION_P (x)
3703 && ! TYPE_PTRMEMFUNC_P (type))
3704 {
3705 /* Never let anything with uninheritable virtuals
3706 make it through without complaint. */
3707 if (CLASSTYPE_ABSTRACT_VIRTUALS (type))
3708 abstract_virtuals_error (x, type);
3709
3710 /* Don't let signatures make it through either. */
3711 if (IS_SIGNATURE (type))
3712 signature_error (x, type);
3713
3714 if (code == UNION_TYPE)
3715 {
3716 char *fie = NULL;
3717 if (TYPE_NEEDS_CONSTRUCTING (type))
3718 fie = "constructor";
3719 else if (TYPE_NEEDS_DESTRUCTOR (type))
3720 fie = "destructor";
3721 else if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
3722 fie = "copy assignment operator";
3723 if (fie)
3724 cp_error_at ("member `%#D' with %s not allowed in union", x,
3725 fie);
3726 }
3727 else
3728 {
3729 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
3730 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type);
3731 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
3732 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
3733 }
3734
3735 if (!TYPE_HAS_CONST_INIT_REF (type))
3736 cant_have_const_ctor = 1;
3737
3738 if (!TYPE_HAS_CONST_ASSIGN_REF (type))
3739 no_const_asn_ref = 1;
3740
3741 if (TYPE_HAS_CONSTRUCTOR (type)
3742 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
3743 {
3744 cant_have_default_ctor = 1;
3745 #if 0
3746 /* This is wrong for aggregates. */
3747 if (! TYPE_HAS_CONSTRUCTOR (t))
3748 {
3749 if (DECL_NAME (x))
3750 cp_pedwarn_at ("member `%#D' with only non-default constructor", x);
3751 else
3752 cp_pedwarn_at ("member with only non-default constructor", x);
3753 cp_pedwarn_at ("in class without a constructor",
3754 x);
3755 }
3756 #endif
3757 }
3758 }
3759 if (DECL_INITIAL (x) != NULL_TREE)
3760 {
3761 /* `build_class_init_list' does not recognize
3762 non-FIELD_DECLs. */
3763 if (code == UNION_TYPE && any_default_members != 0)
3764 cp_error_at ("multiple fields in union `%T' initialized");
3765 any_default_members = 1;
3766 }
3767 }
3768 }
3769
3770 /* If this type has any constant members which did not come
3771 with their own initialization, mark that fact here. It is
3772 not an error here, since such types can be saved either by their
3773 constructors, or by fortuitous initialization. */
3774 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init;
3775 CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init;
3776 CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals;
3777
3778 /* Effective C++ rule 11. */
3779 if (has_pointers && warn_ecpp && TYPE_HAS_CONSTRUCTOR (t)
3780 && ! (TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
3781 {
3782 cp_warning ("`%#T' has pointer data members", t);
3783
3784 if (! TYPE_HAS_INIT_REF (t))
3785 {
3786 cp_warning (" but does not override `%T(const %T&)'", t, t);
3787 if (! TYPE_HAS_ASSIGN_REF (t))
3788 cp_warning (" or `operator=(const %T&)'", t);
3789 }
3790 else if (! TYPE_HAS_ASSIGN_REF (t))
3791 cp_warning (" but does not override `operator=(const %T&)'", t);
3792 }
3793
3794 /* Do some bookkeeping that will guide the generation of implicitly
3795 declared member functions. */
3796 TYPE_HAS_COMPLEX_INIT_REF (t)
3797 |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3798 || has_virtual || any_default_members);
3799 TYPE_NEEDS_CONSTRUCTING (t)
3800 |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3801 || has_virtual || any_default_members);
3802 if (! IS_SIGNATURE (t))
3803 CLASSTYPE_NON_AGGREGATE (t)
3804 = ! aggregate || has_virtual || TYPE_HAS_CONSTRUCTOR (t);
3805 TYPE_HAS_REAL_ASSIGNMENT (t) |= TYPE_HAS_ASSIGNMENT (t);
3806 TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
3807 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
3808 |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
3809
3810 /* Synthesize any needed methods. Note that methods will be synthesized
3811 for anonymous unions; grok_x_components undoes that. */
3812 virtual_dtor
3813 = add_implicitly_declared_members (t, cant_have_default_ctor,
3814 cant_have_const_ctor,
3815 no_const_asn_ref);
3816 if (virtual_dtor)
3817 add_virtual_function (&pending_virtuals, &pending_hard_virtuals,
3818 &has_virtual, virtual_dtor, t);
3819
3820 if (TYPE_METHODS (t))
3821 {
3822 finish_struct_methods (t);
3823 method_vec = CLASSTYPE_METHOD_VEC (t);
3824 }
3825 else
3826 {
3827 method_vec = 0;
3828
3829 /* Just in case these got accidentally
3830 filled in by syntax errors. */
3831 TYPE_HAS_CONSTRUCTOR (t) = 0;
3832 TYPE_HAS_DESTRUCTOR (t) = 0;
3833 }
3834
3835 for (access_decls = nreverse (access_decls); access_decls;
3836 access_decls = TREE_CHAIN (access_decls))
3837 handle_using_decl (TREE_VALUE (access_decls), t, method_vec, fields);
3838
3839 if (vfield == NULL_TREE && has_virtual)
3840 {
3841 /* We build this decl with vtbl_ptr_type_node, which is a
3842 `vtable_entry_type*'. It might seem more precise to use
3843 `vtable_entry_type (*)[N]' where N is the number of firtual
3844 functions. However, that would require the vtable pointer in
3845 base classes to have a different type than the vtable pointer
3846 in derived classes. We could make that happen, but that
3847 still wouldn't solve all the problems. In particular, the
3848 type-based alias analysis code would decide that assignments
3849 to the base class vtable pointer can't alias assignments to
3850 the derived class vtable pointer, since they have different
3851 types. Thus, in an derived class destructor, where the base
3852 class constructor was inlined, we could generate bad code for
3853 setting up the vtable pointer.
3854
3855 Therefore, we use one type for all vtable pointers. We still
3856 use a type-correct type; it's just doesn't indicate the array
3857 bounds. That's better than using `void*' or some such; it's
3858 cleaner, and it let's the alias analysis code know that these
3859 stores cannot alias stores to void*! */
3860 vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t),
3861 vtbl_ptr_type_node);
3862 /* If you change any of the below, take a look at all the
3863 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3864 them too. */
3865 DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
3866 CLASSTYPE_VFIELD (t) = vfield;
3867 DECL_VIRTUAL_P (vfield) = 1;
3868 DECL_ARTIFICIAL (vfield) = 1;
3869 DECL_FIELD_CONTEXT (vfield) = t;
3870 DECL_CLASS_CONTEXT (vfield) = t;
3871 DECL_FCONTEXT (vfield) = t;
3872 DECL_SAVED_INSNS (vfield) = NULL_RTX;
3873 DECL_FIELD_SIZE (vfield) = 0;
3874 DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node);
3875 #if 0
3876 /* This is more efficient, but breaks binary compatibility, turn
3877 it on sometime when we don't care. If we turn it on, we also
3878 have to enable the code in dfs_init_vbase_pointers. */
3879 /* vfield is always first entry in structure. */
3880 TREE_CHAIN (vfield) = fields;
3881 fields = vfield;
3882 #else
3883 if (last_x)
3884 {
3885 my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175);
3886 TREE_CHAIN (last_x) = vfield;
3887 last_x = vfield;
3888 }
3889 else
3890 fields = vfield;
3891 #endif
3892 empty = 0;
3893 vfields = chainon (vfields, CLASSTYPE_AS_LIST (t));
3894 }
3895
3896 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3897
3898 C++: maybe we will support default field initialization some day... */
3899
3900 /* Delete all duplicate fields from the fields */
3901 delete_duplicate_fields (fields);
3902
3903 /* Catch function/field name conflict. We don't need to do this for a
3904 signature, since it can only contain the fields constructed in
3905 append_signature_fields. */
3906 if (! IS_SIGNATURE (t))
3907 {
3908 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3909 for (x = fields; x; x = TREE_CHAIN (x))
3910 {
3911 tree name = DECL_NAME (x);
3912 int i;
3913
3914 if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x))
3915 continue;
3916
3917 for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); ++i)
3918 if (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)))
3919 == name)
3920 {
3921 cp_error_at ("data member `%#D' conflicts with", x);
3922 cp_error_at ("function member `%#D'",
3923 OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
3924 break;
3925 }
3926 }
3927 }
3928
3929 /* Now we have the nearly final fieldlist for the data fields. Record it,
3930 then lay out the structure or union (including the fields). */
3931
3932 TYPE_FIELDS (t) = fields;
3933
3934 if (n_baseclasses)
3935 {
3936 last_x = build_base_fields (t);
3937
3938 /* If all our bases are empty, we can be empty too. */
3939 for (x = last_x; empty && x; x = TREE_CHAIN (x))
3940 if (DECL_SIZE (x) != integer_zero_node)
3941 empty = 0;
3942 }
3943 if (empty)
3944 {
3945 /* C++: do not let empty structures exist. */
3946 tree decl = build_lang_field_decl
3947 (FIELD_DECL, NULL_TREE, char_type_node);
3948 TREE_CHAIN (decl) = fields;
3949 TYPE_FIELDS (t) = decl;
3950 }
3951 if (n_baseclasses)
3952 TYPE_FIELDS (t) = chainon (last_x, TYPE_FIELDS (t));
3953
3954 layout_type (t);
3955
3956 /* Remember the size and alignment of the class before adding
3957 the virtual bases. */
3958 if (empty && flag_new_abi)
3959 CLASSTYPE_SIZE (t) = integer_zero_node;
3960 else if (flag_new_abi && TYPE_HAS_COMPLEX_INIT_REF (t)
3961 && TYPE_HAS_COMPLEX_ASSIGN_REF (t))
3962 CLASSTYPE_SIZE (t) = TYPE_BINFO_SIZE (t);
3963 else
3964 CLASSTYPE_SIZE (t) = TYPE_SIZE (t);
3965 CLASSTYPE_ALIGN (t) = TYPE_ALIGN (t);
3966
3967 finish_struct_anon (t);
3968
3969 /* Set the TYPE_DECL for this type to contain the right
3970 value for DECL_OFFSET, so that we can use it as part
3971 of a COMPONENT_REF for multiple inheritance. */
3972
3973 layout_decl (TYPE_MAIN_DECL (t), 0);
3974
3975 /* Now fix up any virtual base class types that we left lying
3976 around. We must get these done before we try to lay out the
3977 virtual function table. */
3978 pending_hard_virtuals = nreverse (pending_hard_virtuals);
3979
3980 if (n_baseclasses)
3981 /* layout_basetypes will remove the base subobject fields. */
3982 max_has_virtual = layout_basetypes (t, max_has_virtual);
3983 else if (empty)
3984 TYPE_FIELDS (t) = fields;
3985
3986 my_friendly_assert (TYPE_FIELDS (t) == fields, 981117);
3987
3988 /* Delete all zero-width bit-fields from the front of the fieldlist */
3989 while (fields && DECL_C_BIT_FIELD (fields)
3990 && DECL_INITIAL (fields))
3991 fields = TREE_CHAIN (fields);
3992 /* Delete all such fields from the rest of the fields. */
3993 for (x = fields; x;)
3994 {
3995 if (TREE_CHAIN (x) && DECL_C_BIT_FIELD (TREE_CHAIN (x))
3996 && DECL_INITIAL (TREE_CHAIN (x)))
3997 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
3998 else
3999 x = TREE_CHAIN (x);
4000 }
4001 TYPE_FIELDS (t) = fields;
4002
4003 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
4004 {
4005 tree vbases;
4006
4007 vbases = CLASSTYPE_VBASECLASSES (t);
4008 CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases);
4009
4010 {
4011 /* Now fixup overrides of all functions in vtables from all
4012 direct or indirect virtual base classes. */
4013 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
4014 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
4015
4016 for (i = 0; i < n_baseclasses; i++)
4017 {
4018 tree base_binfo = TREE_VEC_ELT (binfos, i);
4019 tree basetype = BINFO_TYPE (base_binfo);
4020 tree vbases;
4021
4022 vbases = CLASSTYPE_VBASECLASSES (basetype);
4023 while (vbases)
4024 {
4025 merge_overrides (binfo_member (BINFO_TYPE (vbases),
4026 CLASSTYPE_VBASECLASSES (t)),
4027 vbases, 1, t);
4028 vbases = TREE_CHAIN (vbases);
4029 }
4030 }
4031 }
4032 }
4033
4034 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
4035 might need to know it for setting up the offsets in the vtable
4036 (or in thunks) below. */
4037 if (vfield != NULL_TREE
4038 && DECL_FIELD_CONTEXT (vfield) != t)
4039 {
4040 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
4041 tree offset = BINFO_OFFSET (binfo);
4042
4043 vfield = copy_node (vfield);
4044 copy_lang_decl (vfield);
4045
4046 if (! integer_zerop (offset))
4047 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
4048 DECL_FIELD_CONTEXT (vfield) = t;
4049 DECL_CLASS_CONTEXT (vfield) = t;
4050 DECL_FIELD_BITPOS (vfield)
4051 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
4052 CLASSTYPE_VFIELD (t) = vfield;
4053 }
4054
4055 #ifdef NOTQUITE
4056 cp_warning ("Doing hard virtuals for %T...", t);
4057 #endif
4058
4059 if (has_virtual > max_has_virtual)
4060 max_has_virtual = has_virtual;
4061 if (max_has_virtual > 0)
4062 TYPE_VIRTUAL_P (t) = 1;
4063
4064 if (flag_rtti && TYPE_VIRTUAL_P (t) && !pending_hard_virtuals)
4065 modify_all_vtables (t, NULL_TREE, NULL_TREE);
4066
4067 while (pending_hard_virtuals)
4068 {
4069 modify_all_vtables (t,
4070 TREE_PURPOSE (pending_hard_virtuals),
4071 TREE_VALUE (pending_hard_virtuals));
4072 pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals);
4073 }
4074
4075 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
4076 {
4077 tree vbases;
4078 /* Now fixup any virtual function entries from virtual bases
4079 that have different deltas. This has to come after we do the
4080 pending hard virtuals, as we might have a function that comes
4081 from multiple virtual base instances that is only overridden
4082 by a hard virtual above. */
4083 vbases = CLASSTYPE_VBASECLASSES (t);
4084 while (vbases)
4085 {
4086 /* We might be able to shorten the amount of work we do by
4087 only doing this for vtables that come from virtual bases
4088 that have differing offsets, but don't want to miss any
4089 entries. */
4090 fixup_vtable_deltas (vbases, 1, t);
4091 vbases = TREE_CHAIN (vbases);
4092 }
4093 }
4094
4095 /* Under our model of GC, every C++ class gets its own virtual
4096 function table, at least virtually. */
4097 if (pending_virtuals)
4098 {
4099 pending_virtuals = nreverse (pending_virtuals);
4100 /* We must enter these virtuals into the table. */
4101 if (first_vfn_base_index < 0)
4102 {
4103 /* The second slot is for the tdesc pointer when thunks are used. */
4104 if (flag_vtable_thunks)
4105 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
4106
4107 /* The first slot is for the rtti offset. */
4108 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
4109
4110 set_rtti_entry (pending_virtuals,
4111 convert (ssizetype, integer_zero_node), t);
4112 build_vtable (NULL_TREE, t);
4113 }
4114 else
4115 {
4116 /* Here we know enough to change the type of our virtual
4117 function table, but we will wait until later this function. */
4118
4119 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
4120 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t);
4121 }
4122
4123 /* If this type has basetypes with constructors, then those
4124 constructors might clobber the virtual function table. But
4125 they don't if the derived class shares the exact vtable of the base
4126 class. */
4127
4128 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
4129 }
4130 else if (first_vfn_base_index >= 0)
4131 {
4132 tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index);
4133 /* This class contributes nothing new to the virtual function
4134 table. However, it may have declared functions which
4135 went into the virtual function table "inherited" from the
4136 base class. If so, we grab a copy of those updated functions,
4137 and pretend they are ours. */
4138
4139 /* See if we should steal the virtual info from base class. */
4140 if (TYPE_BINFO_VTABLE (t) == NULL_TREE)
4141 TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo);
4142 if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE)
4143 TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo);
4144 if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo))
4145 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
4146 }
4147
4148 if (max_has_virtual || first_vfn_base_index >= 0)
4149 {
4150 CLASSTYPE_VSIZE (t) = has_virtual;
4151 if (first_vfn_base_index >= 0)
4152 {
4153 if (pending_virtuals)
4154 TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t),
4155 pending_virtuals);
4156 }
4157 else if (has_virtual)
4158 {
4159 TYPE_BINFO_VIRTUALS (t) = pending_virtuals;
4160 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1;
4161 }
4162 }
4163
4164 /* Now lay out the virtual function table. */
4165 if (has_virtual)
4166 {
4167 /* Use size_int so values are memoized in common cases. */
4168 tree itype = build_index_type (size_int (has_virtual));
4169 tree atype = build_cplus_array_type (vtable_entry_type, itype);
4170
4171 layout_type (atype);
4172
4173 CLASSTYPE_VFIELD (t) = vfield;
4174
4175 /* We may have to grow the vtable. */
4176 if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
4177 {
4178 TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype;
4179 DECL_SIZE (TYPE_BINFO_VTABLE (t)) = 0;
4180 layout_decl (TYPE_BINFO_VTABLE (t), 0);
4181 /* At one time the vtable info was grabbed 2 words at a time. This
4182 fails on sparc unless you have 8-byte alignment. (tiemann) */
4183 DECL_ALIGN (TYPE_BINFO_VTABLE (t))
4184 = MAX (TYPE_ALIGN (double_type_node),
4185 DECL_ALIGN (TYPE_BINFO_VTABLE (t)));
4186 }
4187 }
4188 else if (first_vfn_base_index >= 0)
4189 CLASSTYPE_VFIELD (t) = vfield;
4190 CLASSTYPE_VFIELDS (t) = vfields;
4191
4192 finish_struct_bits (t, max_has_virtual);
4193
4194 /* Complete the rtl for any static member objects of the type we're
4195 working on. */
4196 for (x = fields; x; x = TREE_CHAIN (x))
4197 {
4198 if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
4199 && TREE_TYPE (x) == t)
4200 {
4201 DECL_MODE (x) = TYPE_MODE (t);
4202 make_decl_rtl (x, NULL, 0);
4203 }
4204 }
4205
4206 if (TYPE_HAS_CONSTRUCTOR (t))
4207 {
4208 tree vfields = CLASSTYPE_VFIELDS (t);
4209
4210 while (vfields)
4211 {
4212 /* Mark the fact that constructor for T
4213 could affect anybody inheriting from T
4214 who wants to initialize vtables for VFIELDS's type. */
4215 if (VF_DERIVED_VALUE (vfields))
4216 TREE_ADDRESSABLE (vfields) = 1;
4217 vfields = TREE_CHAIN (vfields);
4218 }
4219 if (any_default_members != 0)
4220 build_class_init_list (t);
4221 }
4222 else if (TYPE_NEEDS_CONSTRUCTING (t))
4223 build_class_init_list (t);
4224
4225 /* Write out inline function definitions. */
4226 do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t));
4227 CLASSTYPE_INLINE_FRIENDS (t) = 0;
4228
4229 if (CLASSTYPE_VSIZE (t) != 0)
4230 {
4231 #if 0
4232 /* This is now done above. */
4233 if (DECL_FIELD_CONTEXT (vfield) != t)
4234 {
4235 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
4236 tree offset = BINFO_OFFSET (binfo);
4237
4238 vfield = copy_node (vfield);
4239 copy_lang_decl (vfield);
4240
4241 if (! integer_zerop (offset))
4242 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
4243 DECL_FIELD_CONTEXT (vfield) = t;
4244 DECL_CLASS_CONTEXT (vfield) = t;
4245 DECL_FIELD_BITPOS (vfield)
4246 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
4247 CLASSTYPE_VFIELD (t) = vfield;
4248 }
4249 #endif
4250
4251 /* In addition to this one, all the other vfields should be listed. */
4252 /* Before that can be done, we have to have FIELD_DECLs for them, and
4253 a place to find them. */
4254 TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield);
4255
4256 if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
4257 && DECL_VINDEX (TREE_VEC_ELT (method_vec, 1)) == NULL_TREE)
4258 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4259 t);
4260 }
4261
4262 /* Make the rtl for any new vtables we have created, and unmark
4263 the base types we marked. */
4264 finish_vtbls (TYPE_BINFO (t), 1, t);
4265 hack_incomplete_structures (t);
4266
4267 #if 0
4268 if (TYPE_NAME (t) && TYPE_IDENTIFIER (t))
4269 undo_template_name_overload (TYPE_IDENTIFIER (t), 1);
4270 #endif
4271
4272 resume_momentary (old);
4273
4274 if (warn_overloaded_virtual)
4275 warn_hidden (t);
4276
4277 #if 0
4278 /* This has to be done after we have sorted out what to do with
4279 the enclosing type. */
4280 if (write_symbols != DWARF_DEBUG)
4281 {
4282 /* Be smarter about nested classes here. If a type is nested,
4283 only output it if we would output the enclosing type. */
4284 if (DECL_CLASS_SCOPE_P (TYPE_MAIN_DECL (t)))
4285 DECL_IGNORED_P (TYPE_MAIN_DECL (t)) = TREE_ASM_WRITTEN (TYPE_MAIN_DECL (t));
4286 }
4287 #endif
4288
4289 if (write_symbols != DWARF_DEBUG && write_symbols != DWARF2_DEBUG)
4290 {
4291 /* If the type has methods, we want to think about cutting down
4292 the amount of symbol table stuff we output. The value stored in
4293 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4294 For example, if a member function is seen and we decide to
4295 write out that member function, then we can change the value
4296 of the DECL_IGNORED_P slot, and the type will be output when
4297 that member function's debug info is written out.
4298
4299 We can't do this with DWARF, which does not support name
4300 references between translation units. */
4301 if (CLASSTYPE_METHOD_VEC (t))
4302 {
4303 /* Don't output full info about any type
4304 which does not have its implementation defined here. */
4305 if (CLASSTYPE_INTERFACE_ONLY (t))
4306 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4307 #if 0
4308 /* XXX do something about this. */
4309 else if (CLASSTYPE_INTERFACE_UNKNOWN (t))
4310 /* Only a first approximation! */
4311 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4312 #endif
4313 }
4314 else if (CLASSTYPE_INTERFACE_ONLY (t))
4315 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4316 }
4317
4318 /* Finish debugging output for this type. */
4319 rest_of_type_compilation (t, toplevel_bindings_p ());
4320
4321 return t;
4322 }
4323
4324 /* In [basic.scope.class] we have:
4325
4326 A name N used in a class S shall refer to the same declaration in
4327 its context and when re-evaluated in the completed scope of S.
4328
4329 This function checks this condition for X, which is a member of
4330 T. */
4331
4332 static void
4333 check_member_decl_is_same_in_complete_scope (t, x)
4334 tree t;
4335 tree x;
4336 {
4337 /* A name N used in a class S shall refer to the same declaration in
4338 its context and when re-evaluated in the completed scope of S.
4339
4340 Enums, types and static vars have already been checked. */
4341 if (TREE_CODE (x) != USING_DECL
4342 && TREE_CODE (x) != TYPE_DECL && !DECL_CLASS_TEMPLATE_P (x)
4343 && TREE_CODE (x) != CONST_DECL && TREE_CODE (x) != VAR_DECL)
4344 {
4345 tree name = DECL_NAME (x);
4346 tree icv;
4347
4348 /* Don't get confused by access decls. */
4349 if (name && TREE_CODE (name) == IDENTIFIER_NODE)
4350 icv = IDENTIFIER_CLASS_VALUE (name);
4351 else
4352 icv = NULL_TREE;
4353
4354 if (icv
4355 /* Don't complain about constructors. */
4356 && name != constructor_name (current_class_type)
4357 /* Or inherited names. */
4358 && id_in_current_class (name)
4359 /* Or shadowed tags. */
4360 && !(TREE_CODE (icv) == TYPE_DECL && DECL_CONTEXT (icv) == t))
4361 {
4362 cp_pedwarn_at ("declaration of identifier `%D' as `%+#D'",
4363 name, x);
4364 cp_pedwarn_at ("conflicts with other use in class as `%#D'",
4365 icv);
4366 }
4367 }
4368 }
4369
4370 /* When T was built up, the member declarations were added in reverse
4371 order. Rearrange them to declaration order. */
4372
4373 void
4374 unreverse_member_declarations (t)
4375 tree t;
4376 {
4377 tree next;
4378 tree prev;
4379 tree x;
4380
4381 /* The TYPE_FIELDS, TYPE_METHODS, and CLASSTYPE_TAGS are all in
4382 reverse order. Put them in declaration order now. */
4383 TYPE_METHODS (t) = nreverse (TYPE_METHODS (t));
4384 CLASSTYPE_TAGS (t) = nreverse (CLASSTYPE_TAGS (t));
4385
4386 /* Actually, for the TYPE_FIELDS, only the non TYPE_DECLs are in
4387 reverse order, so we can't just use nreverse. */
4388 prev = NULL_TREE;
4389 for (x = TYPE_FIELDS (t);
4390 x && TREE_CODE (x) != TYPE_DECL;
4391 x = next)
4392 {
4393 next = TREE_CHAIN (x);
4394 TREE_CHAIN (x) = prev;
4395 prev = x;
4396 }
4397 if (prev)
4398 {
4399 TREE_CHAIN (TYPE_FIELDS (t)) = x;
4400 if (prev)
4401 TYPE_FIELDS (t) = prev;
4402 }
4403 }
4404
4405 tree
4406 finish_struct (t, attributes, warn_anon)
4407 tree t, attributes;
4408 int warn_anon;
4409 {
4410 tree name = TYPE_NAME (t);
4411 tree x;
4412
4413 if (TREE_CODE (name) == TYPE_DECL)
4414 {
4415 extern int lineno;
4416
4417 DECL_SOURCE_FILE (name) = input_filename;
4418 /* For TYPE_DECL that are not typedefs (those marked with a line
4419 number of zero, we don't want to mark them as real typedefs.
4420 If this fails one needs to make sure real typedefs have a
4421 previous line number, even if it is wrong, that way the below
4422 will fill in the right line number. (mrs) */
4423 if (DECL_SOURCE_LINE (name))
4424 DECL_SOURCE_LINE (name) = lineno;
4425 name = DECL_NAME (name);
4426 }
4427
4428 /* Append the fields we need for constructing signature tables. */
4429 if (IS_SIGNATURE (t))
4430 append_signature_fields (t);
4431
4432 /* Now that we've got all the field declarations, reverse everything
4433 as necessary. */
4434 unreverse_member_declarations (t);
4435
4436 if (flag_optional_diags)
4437 {
4438 for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
4439 check_member_decl_is_same_in_complete_scope (t, x);
4440 for (x = TYPE_FIELDS (t); x; x = TREE_CHAIN (x))
4441 check_member_decl_is_same_in_complete_scope (t, x);
4442 }
4443
4444 /* Mark all the tags in the class as class-local. */
4445 for (x = CLASSTYPE_TAGS (t); x; x = TREE_CHAIN (x))
4446 TREE_NONLOCAL_FLAG (TREE_VALUE (x)) = 0;
4447
4448 cplus_decl_attributes (t, attributes, NULL_TREE);
4449
4450 if (processing_template_decl)
4451 {
4452 tree d = getdecls ();
4453 for (; d; d = TREE_CHAIN (d))
4454 {
4455 /* If this is the decl for the class or one of the template
4456 parms, we've seen all the injected decls. */
4457 if ((TREE_CODE (d) == TYPE_DECL
4458 && (TREE_TYPE (d) == t
4459 || TREE_CODE (TREE_TYPE (d)) == TEMPLATE_TYPE_PARM
4460 || TREE_CODE (TREE_TYPE (d)) == TEMPLATE_TEMPLATE_PARM))
4461 || TREE_CODE (d) == CONST_DECL)
4462 break;
4463 /* Don't inject cache decls. */
4464 else if (IDENTIFIER_TEMPLATE (DECL_NAME (d)))
4465 continue;
4466 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t))
4467 = tree_cons (NULL_TREE, d,
4468 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t)));
4469 }
4470 finish_struct_methods (t);
4471 TYPE_SIZE (t) = integer_zero_node;
4472 }
4473 else
4474 t = finish_struct_1 (t, warn_anon);
4475
4476 TYPE_BEING_DEFINED (t) = 0;
4477 if (current_class_type)
4478 popclass (0);
4479 else
4480 error ("trying to finish struct, but kicked out due to previous parse errors.");
4481
4482 return t;
4483 }
4484 \f
4485 /* Return the dynamic type of INSTANCE, if known.
4486 Used to determine whether the virtual function table is needed
4487 or not.
4488
4489 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4490 of our knowledge of its type. */
4491
4492 tree
4493 fixed_type_or_null (instance, nonnull)
4494 tree instance;
4495 int *nonnull;
4496 {
4497 switch (TREE_CODE (instance))
4498 {
4499 case INDIRECT_REF:
4500 /* Check that we are not going through a cast of some sort. */
4501 if (TREE_TYPE (instance)
4502 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0))))
4503 instance = TREE_OPERAND (instance, 0);
4504 /* fall through... */
4505 case CALL_EXPR:
4506 /* This is a call to a constructor, hence it's never zero. */
4507 if (TREE_HAS_CONSTRUCTOR (instance))
4508 {
4509 if (nonnull)
4510 *nonnull = 1;
4511 return TREE_TYPE (instance);
4512 }
4513 return NULL_TREE;
4514
4515 case SAVE_EXPR:
4516 /* This is a call to a constructor, hence it's never zero. */
4517 if (TREE_HAS_CONSTRUCTOR (instance))
4518 {
4519 if (nonnull)
4520 *nonnull = 1;
4521 return TREE_TYPE (instance);
4522 }
4523 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4524
4525 case RTL_EXPR:
4526 return NULL_TREE;
4527
4528 case PLUS_EXPR:
4529 case MINUS_EXPR:
4530 if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
4531 /* Propagate nonnull. */
4532 fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4533 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
4534 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4535 return NULL_TREE;
4536
4537 case NOP_EXPR:
4538 case CONVERT_EXPR:
4539 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4540
4541 case ADDR_EXPR:
4542 if (nonnull)
4543 *nonnull = 1;
4544 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4545
4546 case COMPONENT_REF:
4547 return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull);
4548
4549 case VAR_DECL:
4550 case FIELD_DECL:
4551 if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
4552 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
4553 {
4554 if (nonnull)
4555 *nonnull = 1;
4556 return TREE_TYPE (TREE_TYPE (instance));
4557 }
4558 /* fall through... */
4559 case TARGET_EXPR:
4560 case PARM_DECL:
4561 if (IS_AGGR_TYPE (TREE_TYPE (instance)))
4562 {
4563 if (nonnull)
4564 *nonnull = 1;
4565 return TREE_TYPE (instance);
4566 }
4567 else if (nonnull)
4568 {
4569 if (instance == current_class_ptr
4570 && flag_this_is_variable <= 0)
4571 {
4572 /* Normally, 'this' must be non-null. */
4573 if (flag_this_is_variable == 0)
4574 *nonnull = 1;
4575
4576 /* <0 means we're in a constructor and we know our type. */
4577 if (flag_this_is_variable < 0)
4578 return TREE_TYPE (TREE_TYPE (instance));
4579 }
4580 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
4581 /* Reference variables should be references to objects. */
4582 *nonnull = 1;
4583 }
4584 return NULL_TREE;
4585
4586 default:
4587 return NULL_TREE;
4588 }
4589 }
4590
4591 /* Return non-zero if the dynamic type of INSTANCE is known, and equivalent
4592 to the static type. We also handle the case where INSTANCE is really
4593 a pointer.
4594
4595 Used to determine whether the virtual function table is needed
4596 or not.
4597
4598 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4599 of our knowledge of its type. */
4600
4601 int
4602 resolves_to_fixed_type_p (instance, nonnull)
4603 tree instance;
4604 int *nonnull;
4605 {
4606 tree t = TREE_TYPE (instance);
4607 tree fixed = fixed_type_or_null (instance, nonnull);
4608 if (fixed == NULL_TREE)
4609 return 0;
4610 if (POINTER_TYPE_P (t))
4611 t = TREE_TYPE (t);
4612 return same_type_p (TYPE_MAIN_VARIANT (t), TYPE_MAIN_VARIANT (fixed));
4613 }
4614
4615 \f
4616 void
4617 init_class_processing ()
4618 {
4619 current_class_depth = 0;
4620 current_class_stack_size = 10;
4621 current_class_stack
4622 = (class_stack_node_t) xmalloc (current_class_stack_size
4623 * sizeof (struct class_stack_node));
4624
4625 current_lang_stacksize = 10;
4626 current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree));
4627 current_lang_stack = current_lang_base;
4628
4629 access_default_node = build_int_2 (0, 0);
4630 access_public_node = build_int_2 (1, 0);
4631 access_protected_node = build_int_2 (2, 0);
4632 access_private_node = build_int_2 (3, 0);
4633 access_default_virtual_node = build_int_2 (4, 0);
4634 access_public_virtual_node = build_int_2 (5, 0);
4635 access_protected_virtual_node = build_int_2 (6, 0);
4636 access_private_virtual_node = build_int_2 (7, 0);
4637
4638 /* Keep these values lying around. */
4639 base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node);
4640 TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE);
4641
4642 gcc_obstack_init (&class_obstack);
4643 }
4644
4645 /* Set current scope to NAME. CODE tells us if this is a
4646 STRUCT, UNION, or ENUM environment.
4647
4648 NAME may end up being NULL_TREE if this is an anonymous or
4649 late-bound struct (as in "struct { ... } foo;") */
4650
4651 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
4652 appropriate values, found by looking up the type definition of
4653 NAME (as a CODE).
4654
4655 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
4656 which can be seen locally to the class. They are shadowed by
4657 any subsequent local declaration (including parameter names).
4658
4659 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
4660 which have static meaning (i.e., static members, static
4661 member functions, enum declarations, etc).
4662
4663 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
4664 which can be seen locally to the class (as in 1), but
4665 know that we are doing this for declaration purposes
4666 (i.e. friend foo::bar (int)).
4667
4668 So that we may avoid calls to lookup_name, we cache the _TYPE
4669 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
4670
4671 For multiple inheritance, we perform a two-pass depth-first search
4672 of the type lattice. The first pass performs a pre-order search,
4673 marking types after the type has had its fields installed in
4674 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
4675 unmarks the marked types. If a field or member function name
4676 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4677 that name becomes `error_mark_node'. */
4678
4679 void
4680 pushclass (type, modify)
4681 tree type;
4682 int modify;
4683 {
4684 type = TYPE_MAIN_VARIANT (type);
4685
4686 /* Make sure there is enough room for the new entry on the stack. */
4687 if (current_class_depth + 1 >= current_class_stack_size)
4688 {
4689 current_class_stack_size *= 2;
4690 current_class_stack
4691 = (class_stack_node_t) xrealloc (current_class_stack,
4692 current_class_stack_size
4693 * sizeof (struct class_stack_node));
4694 }
4695
4696 /* Insert a new entry on the class stack. */
4697 current_class_stack[current_class_depth].name = current_class_name;
4698 current_class_stack[current_class_depth].type = current_class_type;
4699 current_class_stack[current_class_depth].access = current_access_specifier;
4700 current_class_depth++;
4701
4702 /* Now set up the new type. */
4703 current_class_name = TYPE_NAME (type);
4704 if (TREE_CODE (current_class_name) == TYPE_DECL)
4705 current_class_name = DECL_NAME (current_class_name);
4706 current_class_type = type;
4707
4708 /* By default, things in classes are private, while things in
4709 structures or unions are public. */
4710 current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
4711 ? access_private_node
4712 : access_public_node);
4713
4714 if (previous_class_type != NULL_TREE
4715 && (type != previous_class_type || TYPE_SIZE (previous_class_type) == NULL_TREE)
4716 && current_class_depth == 1)
4717 {
4718 /* Forcibly remove any old class remnants. */
4719 popclass (-1);
4720 previous_class_type = NULL_TREE;
4721
4722 /* Now, free the obstack on which we cached all the values. */
4723 obstack_free (&class_cache_obstack, class_cache_firstobj);
4724 class_cache_firstobj
4725 = (char*) obstack_finish (&class_cache_obstack);
4726 }
4727
4728 pushlevel_class ();
4729
4730 #if 0
4731 if (CLASSTYPE_TEMPLATE_INFO (type))
4732 overload_template_name (type);
4733 #endif
4734
4735 if (modify)
4736 {
4737 tree tags;
4738 tree this_fndecl = current_function_decl;
4739
4740 if (current_function_decl
4741 && DECL_CONTEXT (current_function_decl)
4742 && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL)
4743 current_function_decl = DECL_CONTEXT (current_function_decl);
4744 else
4745 current_function_decl = NULL_TREE;
4746
4747 if (type != previous_class_type || current_class_depth > 1)
4748 {
4749 #ifdef MI_MATRIX
4750 build_mi_matrix (type);
4751 push_class_decls (type);
4752 free_mi_matrix ();
4753 #else
4754 push_class_decls (type);
4755 #endif
4756 }
4757 else
4758 {
4759 tree item;
4760
4761 /* Hooray, we successfully cached; let's just install the
4762 cached class_shadowed list, and walk through it to get the
4763 IDENTIFIER_TYPE_VALUEs correct. */
4764 set_class_shadows (previous_class_values);
4765 for (item = previous_class_values; item; item = TREE_CHAIN (item))
4766 {
4767 tree id = TREE_PURPOSE (item);
4768 tree decl = IDENTIFIER_CLASS_VALUE (id);
4769
4770 if (TREE_CODE (decl) == TYPE_DECL)
4771 set_identifier_type_value (id, TREE_TYPE (decl));
4772 }
4773 unuse_fields (type);
4774 }
4775
4776 for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags))
4777 {
4778 tree tag_type = TREE_VALUE (tags);
4779
4780 TREE_NONLOCAL_FLAG (tag_type) = 1;
4781 if (! TREE_PURPOSE (tags))
4782 continue;
4783 if (! (IS_AGGR_TYPE_CODE (TREE_CODE (tag_type))
4784 && CLASSTYPE_IS_TEMPLATE (tag_type)))
4785 pushtag (TREE_PURPOSE (tags), tag_type, 0);
4786 else
4787 pushdecl_class_level (CLASSTYPE_TI_TEMPLATE (tag_type));
4788 }
4789
4790 current_function_decl = this_fndecl;
4791 }
4792 }
4793
4794 /* Get out of the current class scope. If we were in a class scope
4795 previously, that is the one popped to. The flag MODIFY tells whether
4796 the current scope declarations needs to be modified as a result of
4797 popping to the previous scope. 0 is used for class definitions. */
4798
4799 void
4800 popclass (modify)
4801 int modify;
4802 {
4803 if (modify < 0)
4804 {
4805 /* Back this old class out completely. */
4806 tree tags = CLASSTYPE_TAGS (previous_class_type);
4807 tree t;
4808
4809 /* This code can be seen as a cache miss. When we've cached a
4810 class' scope's bindings and we can't use them, we need to reset
4811 them. This is it! */
4812 for (t = previous_class_values; t; t = TREE_CHAIN (t))
4813 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
4814 while (tags)
4815 {
4816 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
4817 tags = TREE_CHAIN (tags);
4818 }
4819
4820 return;
4821 }
4822
4823 if (modify)
4824 {
4825 /* Just remove from this class what didn't make
4826 it into IDENTIFIER_CLASS_VALUE. */
4827 tree tags = CLASSTYPE_TAGS (current_class_type);
4828
4829 while (tags)
4830 {
4831 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
4832 tags = TREE_CHAIN (tags);
4833 }
4834 }
4835
4836 /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition,
4837 since not all class decls make it there currently. */
4838 poplevel_class (! modify);
4839
4840 /* Since poplevel_class does the popping of class decls nowadays,
4841 this really only frees the obstack used for these decls.
4842 That's why it had to be moved down here. */
4843 if (modify)
4844 pop_class_decls ();
4845
4846 current_class_depth--;
4847 current_class_name = current_class_stack[current_class_depth].name;
4848 current_class_type = current_class_stack[current_class_depth].type;
4849 current_access_specifier = current_class_stack[current_class_depth].access;
4850 }
4851
4852 /* Returns 1 if current_class_type is either T or a nested type of T. */
4853
4854 int
4855 currently_open_class (t)
4856 tree t;
4857 {
4858 int i;
4859 if (t == current_class_type)
4860 return 1;
4861 for (i = 0; i < current_class_depth; ++i)
4862 if (current_class_stack [i].type == t)
4863 return 1;
4864 return 0;
4865 }
4866
4867 /* When entering a class scope, all enclosing class scopes' names with
4868 static meaning (static variables, static functions, types and enumerators)
4869 have to be visible. This recursive function calls pushclass for all
4870 enclosing class contexts until global or a local scope is reached.
4871 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4872 formal of the same name. */
4873
4874 void
4875 push_nested_class (type, modify)
4876 tree type;
4877 int modify;
4878 {
4879 tree context;
4880
4881 my_friendly_assert (!type || TREE_CODE (type) != NAMESPACE_DECL, 980711);
4882
4883 if (type == NULL_TREE || type == error_mark_node || ! IS_AGGR_TYPE (type)
4884 || TREE_CODE (type) == TEMPLATE_TYPE_PARM
4885 || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
4886 return;
4887
4888 context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
4889
4890 if (context && TREE_CODE (context) == RECORD_TYPE)
4891 push_nested_class (context, 2);
4892 pushclass (type, modify);
4893 }
4894
4895 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4896
4897 void
4898 pop_nested_class (modify)
4899 int modify;
4900 {
4901 tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
4902
4903 popclass (modify);
4904 if (context && TREE_CODE (context) == RECORD_TYPE)
4905 pop_nested_class (modify);
4906 }
4907
4908 /* Set global variables CURRENT_LANG_NAME to appropriate value
4909 so that behavior of name-mangling machinery is correct. */
4910
4911 void
4912 push_lang_context (name)
4913 tree name;
4914 {
4915 *current_lang_stack++ = current_lang_name;
4916 if (current_lang_stack >= current_lang_base + current_lang_stacksize)
4917 {
4918 current_lang_base
4919 = (tree *)xrealloc (current_lang_base,
4920 sizeof (tree) * (current_lang_stacksize + 10));
4921 current_lang_stack = current_lang_base + current_lang_stacksize;
4922 current_lang_stacksize += 10;
4923 }
4924
4925 if (name == lang_name_cplusplus || name == lang_name_java)
4926 {
4927 strict_prototype = strict_prototypes_lang_cplusplus;
4928 current_lang_name = name;
4929 }
4930 else if (name == lang_name_c)
4931 {
4932 strict_prototype = strict_prototypes_lang_c;
4933 current_lang_name = name;
4934 }
4935 else
4936 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
4937 }
4938
4939 /* Get out of the current language scope. */
4940
4941 void
4942 pop_lang_context ()
4943 {
4944 current_lang_name = *--current_lang_stack;
4945 if (current_lang_name == lang_name_cplusplus
4946 || current_lang_name == lang_name_java)
4947 strict_prototype = strict_prototypes_lang_cplusplus;
4948 else if (current_lang_name == lang_name_c)
4949 strict_prototype = strict_prototypes_lang_c;
4950 }
4951 \f
4952 /* Type instantiation routines. */
4953
4954 static tree
4955 validate_lhs (lhstype, complain)
4956 tree lhstype;
4957 int complain;
4958 {
4959 if (TYPE_PTRMEMFUNC_P (lhstype))
4960 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
4961
4962 if (TREE_CODE (lhstype) == POINTER_TYPE)
4963 {
4964 if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE
4965 || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
4966 lhstype = TREE_TYPE (lhstype);
4967 else
4968 {
4969 if (complain)
4970 error ("invalid type combination for overload");
4971 return error_mark_node;
4972 }
4973 }
4974 return lhstype;
4975 }
4976
4977 /* This function will instantiate the type of the expression given in
4978 RHS to match the type of LHSTYPE. If errors exist, then return
4979 error_mark_node. If only complain is COMPLAIN is set. If we are
4980 not complaining, never modify rhs, as overload resolution wants to
4981 try many possible instantiations, in hopes that at least one will
4982 work.
4983
4984 For non-recursive calls, LHSTYPE should be a function, pointer to
4985 function, or a pointer to member function. */
4986
4987 tree
4988 instantiate_type (lhstype, rhs, complain)
4989 tree lhstype, rhs;
4990 int complain;
4991 {
4992 tree explicit_targs = NULL_TREE;
4993 int template_only = 0;
4994
4995 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
4996 {
4997 if (complain)
4998 error ("not enough type information");
4999 return error_mark_node;
5000 }
5001
5002 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
5003 {
5004 if (same_type_p (lhstype, TREE_TYPE (rhs)))
5005 return rhs;
5006 if (complain)
5007 cp_error ("argument of type `%T' does not match `%T'",
5008 TREE_TYPE (rhs), lhstype);
5009 return error_mark_node;
5010 }
5011
5012 /* We don't overwrite rhs if it is an overloaded function.
5013 Copying it would destroy the tree link. */
5014 if (TREE_CODE (rhs) != OVERLOAD)
5015 rhs = copy_node (rhs);
5016
5017 /* This should really only be used when attempting to distinguish
5018 what sort of a pointer to function we have. For now, any
5019 arithmetic operation which is not supported on pointers
5020 is rejected as an error. */
5021
5022 switch (TREE_CODE (rhs))
5023 {
5024 case TYPE_EXPR:
5025 case CONVERT_EXPR:
5026 case SAVE_EXPR:
5027 case CONSTRUCTOR:
5028 case BUFFER_REF:
5029 my_friendly_abort (177);
5030 return error_mark_node;
5031
5032 case INDIRECT_REF:
5033 case ARRAY_REF:
5034 {
5035 tree new_rhs;
5036
5037 new_rhs = instantiate_type (build_pointer_type (lhstype),
5038 TREE_OPERAND (rhs, 0), complain);
5039 if (new_rhs == error_mark_node)
5040 return error_mark_node;
5041
5042 TREE_TYPE (rhs) = lhstype;
5043 TREE_OPERAND (rhs, 0) = new_rhs;
5044 return rhs;
5045 }
5046
5047 case NOP_EXPR:
5048 rhs = copy_node (TREE_OPERAND (rhs, 0));
5049 TREE_TYPE (rhs) = unknown_type_node;
5050 return instantiate_type (lhstype, rhs, complain);
5051
5052 case COMPONENT_REF:
5053 {
5054 tree field = TREE_OPERAND (rhs, 1);
5055 if (TREE_CODE (field) == TREE_LIST)
5056 {
5057 tree function = instantiate_type (lhstype, field, complain);
5058 if (function == error_mark_node)
5059 return error_mark_node;
5060 my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 185);
5061
5062 if (! DECL_STATIC_FUNCTION_P (function))
5063 {
5064 tree t = TREE_TYPE (TREE_OPERAND (rhs, 0));
5065 if (TYPE_MAIN_VARIANT (t) == current_class_type)
5066 t = constructor_name (t);
5067
5068 cp_error ("object-dependent reference to `%D' can only be used in a call",
5069 function);
5070 cp_error (" to form a pointer to member function, say `&%T::%D'",
5071 t, DECL_NAME (function));
5072 }
5073
5074 mark_used (function);
5075 return function;
5076 }
5077
5078 /* I could not trigger this code. MvL */
5079 my_friendly_abort (980326);
5080 return rhs;
5081 }
5082
5083 case OFFSET_REF:
5084 /* This can happen if we are forming a pointer-to-member for a
5085 member template. */
5086 rhs = TREE_OPERAND (rhs, 1);
5087 my_friendly_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR, 0);
5088
5089 /* Fall through. */
5090
5091 case TEMPLATE_ID_EXPR:
5092 {
5093 explicit_targs = TREE_OPERAND (rhs, 1);
5094 template_only = 1;
5095 rhs = TREE_OPERAND (rhs, 0);
5096 }
5097 /* fall through */
5098 my_friendly_assert (TREE_CODE (rhs) == OVERLOAD, 980401);
5099
5100 case OVERLOAD:
5101 {
5102 tree elem, elems;
5103
5104 /* Check that the LHSTYPE and the RHS are reasonable. */
5105 lhstype = validate_lhs (lhstype, complain);
5106 if (lhstype == error_mark_node)
5107 return lhstype;
5108
5109 if (TREE_CODE (lhstype) != FUNCTION_TYPE
5110 && TREE_CODE (lhstype) != METHOD_TYPE)
5111 {
5112 if (complain)
5113 cp_error("cannot resolve overloaded function `%D' "
5114 "based on non-function type `%T'",
5115 DECL_NAME (OVL_FUNCTION (rhs)), lhstype);
5116 return error_mark_node;
5117 }
5118
5119 /* Look for an exact match, by searching through the
5120 overloaded functions. */
5121 if (template_only)
5122 /* If we're processing a template-id, only a template
5123 function can match, so we don't look through the
5124 overloaded functions. */
5125 ;
5126 else for (elems = rhs; elems; elems = OVL_CHAIN (elems))
5127 {
5128 elem = OVL_FUNCTION (elems);
5129 if (TREE_CODE (elem) == FUNCTION_DECL
5130 && same_type_p (lhstype, TREE_TYPE (elem)))
5131 {
5132 mark_used (elem);
5133 return elem;
5134 }
5135 }
5136
5137 /* No overloaded function was an exact match. See if we can
5138 instantiate some template to match. */
5139 {
5140 tree save_elem = 0;
5141 elems = rhs;
5142 if (TREE_CODE (elems) == TREE_LIST)
5143 elems = TREE_VALUE (rhs);
5144 for (; elems; elems = OVL_NEXT (elems))
5145 if (TREE_CODE (elem = OVL_CURRENT (elems)) == TEMPLATE_DECL)
5146 {
5147 int n = DECL_NTPARMS (elem);
5148 tree t = make_scratch_vec (n);
5149 int i;
5150 i = type_unification
5151 (DECL_INNERMOST_TEMPLATE_PARMS (elem), t,
5152 TYPE_ARG_TYPES (TREE_TYPE (elem)),
5153 TYPE_ARG_TYPES (lhstype), explicit_targs, DEDUCE_EXACT, 1);
5154 if (i == 0)
5155 {
5156 if (save_elem)
5157 {
5158 cp_error ("ambiguous template instantiation converting to `%#T'", lhstype);
5159 return error_mark_node;
5160 }
5161 save_elem = instantiate_template (elem, t);
5162 /* Check the return type. */
5163 if (!same_type_p (TREE_TYPE (lhstype),
5164 TREE_TYPE (TREE_TYPE (save_elem))))
5165 save_elem = 0;
5166 }
5167 }
5168 if (save_elem)
5169 {
5170 mark_used (save_elem);
5171 return save_elem;
5172 }
5173 }
5174
5175 /* There's no exact match, and no templates can be
5176 instantiated to match. The last thing we try is to see if
5177 some ordinary overloaded function is close enough. If
5178 we're only looking for template functions, we don't do
5179 this. */
5180 if (!template_only)
5181 {
5182 for (elems = rhs; elems; elems = OVL_NEXT (elems))
5183 {
5184 elem = OVL_CURRENT (elems);
5185 if (TREE_CODE (elem) == FUNCTION_DECL
5186 && comp_target_types (lhstype, TREE_TYPE (elem), 1) > 0)
5187 break;
5188 }
5189 if (elems)
5190 {
5191 tree save_elem = elem;
5192 for (elems = OVL_CHAIN (elems); elems;
5193 elems = OVL_CHAIN (elems))
5194 {
5195 elem = OVL_FUNCTION (elems);
5196 if (TREE_CODE (elem) == FUNCTION_DECL
5197 && comp_target_types (lhstype, TREE_TYPE (elem), 0) >0)
5198 break;
5199 }
5200 if (elems)
5201 {
5202 if (complain)
5203 {
5204 cp_error
5205 ("cannot resolve overload to target type `%#T'",
5206 lhstype);
5207 cp_error_at (" ambiguity between `%#D'", save_elem);
5208 cp_error_at (" and `%#D', at least", elem);
5209 }
5210 return error_mark_node;
5211 }
5212 mark_used (save_elem);
5213 return save_elem;
5214 }
5215 }
5216
5217 /* We failed to find a match. */
5218 if (complain)
5219 {
5220 cp_error ("cannot resolve overload to target type `%#T'", lhstype);
5221 cp_error
5222 (" because no suitable overload of function `%D' exists",
5223 DECL_NAME (OVL_FUNCTION (rhs)));
5224 }
5225 return error_mark_node;
5226 }
5227
5228 case TREE_LIST:
5229 {
5230 if (TREE_PURPOSE (rhs) == error_mark_node)
5231 {
5232 /* Make sure we don't drop the non-local flag, as the old code
5233 would rely on it. */
5234 int nl = TREE_NONLOCAL_FLAG (rhs);
5235 /* We don't need the type of this node. */
5236 rhs = TREE_VALUE (rhs);
5237 my_friendly_assert (TREE_NONLOCAL_FLAG (rhs) == nl, 980331);
5238 }
5239
5240 /* Now we should have a baselink. */
5241 my_friendly_assert (TREE_CODE (TREE_PURPOSE (rhs)) == TREE_VEC,
5242 980331);
5243 my_friendly_assert (TREE_CHAIN (rhs) == NULL_TREE, 181);
5244 my_friendly_assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL
5245 || TREE_CODE (TREE_VALUE (rhs)) == OVERLOAD,
5246 182);
5247
5248 return instantiate_type (lhstype, TREE_VALUE (rhs), complain);
5249 }
5250
5251 case CALL_EXPR:
5252 /* This is too hard for now. */
5253 my_friendly_abort (183);
5254 return error_mark_node;
5255
5256 case PLUS_EXPR:
5257 case MINUS_EXPR:
5258 case COMPOUND_EXPR:
5259 TREE_OPERAND (rhs, 0)
5260 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
5261 if (TREE_OPERAND (rhs, 0) == error_mark_node)
5262 return error_mark_node;
5263 TREE_OPERAND (rhs, 1)
5264 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
5265 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5266 return error_mark_node;
5267
5268 TREE_TYPE (rhs) = lhstype;
5269 return rhs;
5270
5271 case MULT_EXPR:
5272 case TRUNC_DIV_EXPR:
5273 case FLOOR_DIV_EXPR:
5274 case CEIL_DIV_EXPR:
5275 case ROUND_DIV_EXPR:
5276 case RDIV_EXPR:
5277 case TRUNC_MOD_EXPR:
5278 case FLOOR_MOD_EXPR:
5279 case CEIL_MOD_EXPR:
5280 case ROUND_MOD_EXPR:
5281 case FIX_ROUND_EXPR:
5282 case FIX_FLOOR_EXPR:
5283 case FIX_CEIL_EXPR:
5284 case FIX_TRUNC_EXPR:
5285 case FLOAT_EXPR:
5286 case NEGATE_EXPR:
5287 case ABS_EXPR:
5288 case MAX_EXPR:
5289 case MIN_EXPR:
5290 case FFS_EXPR:
5291
5292 case BIT_AND_EXPR:
5293 case BIT_IOR_EXPR:
5294 case BIT_XOR_EXPR:
5295 case LSHIFT_EXPR:
5296 case RSHIFT_EXPR:
5297 case LROTATE_EXPR:
5298 case RROTATE_EXPR:
5299
5300 case PREINCREMENT_EXPR:
5301 case PREDECREMENT_EXPR:
5302 case POSTINCREMENT_EXPR:
5303 case POSTDECREMENT_EXPR:
5304 if (complain)
5305 error ("invalid operation on uninstantiated type");
5306 return error_mark_node;
5307
5308 case TRUTH_AND_EXPR:
5309 case TRUTH_OR_EXPR:
5310 case TRUTH_XOR_EXPR:
5311 case LT_EXPR:
5312 case LE_EXPR:
5313 case GT_EXPR:
5314 case GE_EXPR:
5315 case EQ_EXPR:
5316 case NE_EXPR:
5317 case TRUTH_ANDIF_EXPR:
5318 case TRUTH_ORIF_EXPR:
5319 case TRUTH_NOT_EXPR:
5320 if (complain)
5321 error ("not enough type information");
5322 return error_mark_node;
5323
5324 case COND_EXPR:
5325 if (type_unknown_p (TREE_OPERAND (rhs, 0)))
5326 {
5327 if (complain)
5328 error ("not enough type information");
5329 return error_mark_node;
5330 }
5331 TREE_OPERAND (rhs, 1)
5332 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
5333 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5334 return error_mark_node;
5335 TREE_OPERAND (rhs, 2)
5336 = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), complain);
5337 if (TREE_OPERAND (rhs, 2) == error_mark_node)
5338 return error_mark_node;
5339
5340 TREE_TYPE (rhs) = lhstype;
5341 return rhs;
5342
5343 case MODIFY_EXPR:
5344 TREE_OPERAND (rhs, 1)
5345 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
5346 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5347 return error_mark_node;
5348
5349 TREE_TYPE (rhs) = lhstype;
5350 return rhs;
5351
5352 case ADDR_EXPR:
5353 if (TYPE_PTRMEMFUNC_P (lhstype))
5354 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
5355 else if (TREE_CODE (lhstype) != POINTER_TYPE)
5356 {
5357 if (complain)
5358 error ("type for resolving address of overloaded function must be pointer type");
5359 return error_mark_node;
5360 }
5361 {
5362 tree fn = instantiate_type (TREE_TYPE (lhstype), TREE_OPERAND (rhs, 0), complain);
5363 if (fn == error_mark_node)
5364 return error_mark_node;
5365 mark_addressable (fn);
5366 TREE_TYPE (rhs) = lhstype;
5367 TREE_OPERAND (rhs, 0) = fn;
5368 TREE_CONSTANT (rhs) = staticp (fn);
5369 if (TREE_CODE (lhstype) == POINTER_TYPE
5370 && TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
5371 {
5372 build_ptrmemfunc_type (lhstype);
5373 rhs = build_ptrmemfunc (lhstype, rhs, 0);
5374 }
5375 }
5376 return rhs;
5377
5378 case ENTRY_VALUE_EXPR:
5379 my_friendly_abort (184);
5380 return error_mark_node;
5381
5382 case ERROR_MARK:
5383 return error_mark_node;
5384
5385 default:
5386 my_friendly_abort (185);
5387 return error_mark_node;
5388 }
5389 }
5390 \f
5391 /* Return the name of the virtual function pointer field
5392 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5393 this may have to look back through base types to find the
5394 ultimate field name. (For single inheritance, these could
5395 all be the same name. Who knows for multiple inheritance). */
5396
5397 static tree
5398 get_vfield_name (type)
5399 tree type;
5400 {
5401 tree binfo = TYPE_BINFO (type);
5402 char *buf;
5403
5404 while (BINFO_BASETYPES (binfo)
5405 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
5406 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
5407 binfo = BINFO_BASETYPE (binfo, 0);
5408
5409 type = BINFO_TYPE (binfo);
5410 buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
5411 + TYPE_NAME_LENGTH (type) + 2);
5412 sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
5413 return get_identifier (buf);
5414 }
5415
5416 void
5417 print_class_statistics ()
5418 {
5419 #ifdef GATHER_STATISTICS
5420 fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
5421 fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
5422 fprintf (stderr, "build_method_call = %d (inner = %d)\n",
5423 n_build_method_call, n_inner_fields_searched);
5424 if (n_vtables)
5425 {
5426 fprintf (stderr, "vtables = %d; vtable searches = %d\n",
5427 n_vtables, n_vtable_searches);
5428 fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
5429 n_vtable_entries, n_vtable_elems);
5430 }
5431 #endif
5432 }
5433
5434 /* Push an obstack which is sufficiently long-lived to hold such class
5435 decls that may be cached in the previous_class_values list. The
5436 effect is undone by pop_obstacks. */
5437
5438 void
5439 maybe_push_cache_obstack ()
5440 {
5441 static int cache_obstack_initialized;
5442
5443 if (!cache_obstack_initialized)
5444 {
5445 gcc_obstack_init (&class_cache_obstack);
5446 class_cache_firstobj
5447 = (char*) obstack_finish (&class_cache_obstack);
5448 cache_obstack_initialized = 1;
5449 }
5450
5451 push_obstacks_nochange ();
5452 current_obstack = &class_cache_obstack;
5453 }
5454
5455 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
5456 according to [class]:
5457 The class-name is also inserted
5458 into the scope of the class itself. For purposes of access checking,
5459 the inserted class name is treated as if it were a public member name. */
5460
5461 tree
5462 build_self_reference ()
5463 {
5464 tree name = constructor_name (current_class_type);
5465 tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
5466 DECL_NONLOCAL (value) = 1;
5467 DECL_CONTEXT (value) = current_class_type;
5468 DECL_CLASS_CONTEXT (value) = current_class_type;
5469 DECL_ARTIFICIAL (value) = 1;
5470
5471 pushdecl_class_level (value);
5472 return value;
5473 }
5474
5475 /* Returns 1 if TYPE contains only padding bytes. */
5476
5477 int
5478 is_empty_class (type)
5479 tree type;
5480 {
5481 tree t;
5482
5483 if (type == error_mark_node)
5484 return 0;
5485
5486 if (! IS_AGGR_TYPE (type))
5487 return 0;
5488
5489 if (flag_new_abi)
5490 return CLASSTYPE_SIZE (type) == integer_zero_node;
5491
5492 if (TYPE_BINFO_BASETYPES (type))
5493 return 0;
5494 t = TYPE_FIELDS (type);
5495 while (t && TREE_CODE (t) != FIELD_DECL)
5496 t = TREE_CHAIN (t);
5497 return (t == NULL_TREE);
5498 }
5499
5500 /* Find the enclosing class of the given NODE. NODE can be a *_DECL or
5501 a *_TYPE node. NODE can also be a local class. */
5502
5503 tree
5504 get_enclosing_class (type)
5505 tree type;
5506 {
5507 tree node = type;
5508
5509 while (node && TREE_CODE (node) != NAMESPACE_DECL)
5510 {
5511 switch (TREE_CODE_CLASS (TREE_CODE (node)))
5512 {
5513 case 'd':
5514 node = DECL_CONTEXT (node);
5515 break;
5516
5517 case 't':
5518 if (node != type)
5519 return node;
5520 node = TYPE_CONTEXT (node);
5521 break;
5522
5523 default:
5524 my_friendly_abort (0);
5525 }
5526 }
5527 return NULL_TREE;
5528 }
5529
5530 /* Return 1 if TYPE or one of its enclosing classes is derived from BASE. */
5531
5532 int
5533 is_base_of_enclosing_class (base, type)
5534 tree base, type;
5535 {
5536 while (type)
5537 {
5538 if (get_binfo (base, type, 0))
5539 return 1;
5540
5541 type = get_enclosing_class (type);
5542 }
5543 return 0;
5544 }
This page took 0.324719 seconds and 6 git commands to generate.