1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
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)
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.
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* High-level class interface. */
32 #define obstack_chunk_alloc xmalloc
33 #define obstack_chunk_free free
35 extern struct obstack permanent_obstack;
37 /* This is how we tell when two virtual member functions are really the
39 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
41 extern void set_class_shadows PROTO ((tree));
43 /* Way of stacking class types. */
44 static tree *current_class_base, *current_class_stack;
45 static int current_class_stacksize;
46 int current_class_depth;
50 /* The previous class level. */
51 struct class_level *level_chain;
53 /* The class instance variable, as a PARM_DECL. */
55 /* The class instance variable, as an object. */
57 /* The virtual function table pointer
58 for the class instance variable. */
61 /* Name of the current class. */
63 /* Type of the current class. */
66 /* Flags for this class level. */
73 tree current_class_decl, C_C_D; /* PARM_DECL: the class instance variable */
74 tree current_vtable_decl;
76 /* The following two can be derived from the previous one */
77 tree current_class_name; /* IDENTIFIER_NODE: name of current class */
78 tree current_class_type; /* _TYPE: the type of the current class */
79 tree previous_class_type; /* _TYPE: the previous type that was a class */
80 tree previous_class_values; /* TREE_LIST: copy of the class_shadowed list
81 when leaving an outermost class scope. */
82 static tree get_vfield_name PROTO((tree));
83 tree the_null_vtable_entry;
85 /* Way of stacking language names. */
86 tree *current_lang_base, *current_lang_stack;
87 int current_lang_stacksize;
89 /* Names of languages we recognize. */
90 tree lang_name_c, lang_name_cplusplus;
91 tree current_lang_name;
93 /* When layout out an aggregate type, the size of the
94 basetypes (virtual and non-virtual) is passed to layout_record
96 static tree base_layout_decl;
98 /* Variables shared between class.c and call.c. */
101 int n_vtable_entries = 0;
102 int n_vtable_searches = 0;
103 int n_vtable_elems = 0;
104 int n_convert_harshness = 0;
105 int n_compute_conversion_costs = 0;
106 int n_build_method_call = 0;
107 int n_inner_fields_searched = 0;
109 /* Virtual baseclass things. */
111 build_vbase_pointer (exp, type)
116 name = (char *) alloca (TYPE_NAME_LENGTH (type) + sizeof (VBASE_NAME) + 1);
117 sprintf (name, VBASE_NAME_FORMAT, TYPE_NAME_STRING (type));
118 return build_component_ref (exp, get_identifier (name), 0, 0);
121 /* Is the type of the EXPR, the complete type of the object?
122 If we are going to be wrong, we must be conservative, and return 0. */
124 complete_type_p (expr)
127 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
130 switch (TREE_CODE (expr))
137 expr = TREE_OPERAND (expr, 0);
141 if (! TREE_HAS_CONSTRUCTOR (expr))
143 /* fall through... */
146 if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
147 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr)))
148 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
150 /* fall through... */
153 if (IS_AGGR_TYPE (TREE_TYPE (expr))
154 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
156 /* fall through... */
166 /* Build multi-level access to EXPR using hierarchy path PATH.
167 CODE is PLUS_EXPR if we are going with the grain,
168 and MINUS_EXPR if we are not (in which case, we cannot traverse
169 virtual baseclass links).
171 TYPE is the type we want this path to have on exit.
173 ALIAS_THIS is non-zero if EXPR in an expression involving `this'. */
175 build_vbase_path (code, type, expr, path, alias_this)
177 tree type, expr, path;
180 register int changed = 0;
181 tree last = NULL_TREE, last_virtual = NULL_TREE;
183 int fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
184 tree null_expr = 0, nonnull_expr;
186 tree offset = integer_zero_node;
188 /* We need additional logic to convert back to the unconverted type
189 (the static type of the complete object), and then convert back
190 to the type we want. Until that is done, or until we can
191 recognize when that is, we cannot do the short cut logic. (mrs) */
192 /* Do this, until we can undo any previous convertions. See net35.C
194 fixed_type_p = complete_type_p (expr);
196 if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
197 expr = save_expr (expr);
200 if (BINFO_INHERITANCE_CHAIN (path))
202 tree reverse_path = NULL_TREE;
206 tree r = copy_node (path);
207 BINFO_INHERITANCE_CHAIN (r) = reverse_path;
209 path = BINFO_INHERITANCE_CHAIN (path);
214 basetype = BINFO_TYPE (path);
218 if (TREE_VIA_VIRTUAL (path))
220 last_virtual = BINFO_TYPE (path);
221 if (code == PLUS_EXPR)
223 changed = ! fixed_type_p;
227 extern int flag_assume_nonnull_objects;
230 /* We already check for ambiguous things in the caller, just
234 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0);
235 nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr);
237 ind = build_indirect_ref (nonnull_expr, NULL_PTR);
238 nonnull_expr = build_vbase_pointer (ind, last_virtual);
239 if (nonnull == 0 && !flag_assume_nonnull_objects
240 && null_expr == NULL_TREE)
242 null_expr = build1 (NOP_EXPR, TYPE_POINTER_TO (last_virtual), integer_zero_node);
243 expr = build (COND_EXPR, TYPE_POINTER_TO (last_virtual),
244 build (EQ_EXPR, boolean_type_node, expr,
246 null_expr, nonnull_expr);
249 /* else we'll figure out the offset below. */
251 /* Happens in the case of parse errors. */
252 if (nonnull_expr == error_mark_node)
253 return error_mark_node;
257 cp_error ("cannot cast up from virtual baseclass `%T'",
259 return error_mark_node;
263 path = BINFO_INHERITANCE_CHAIN (path);
265 /* LAST is now the last basetype assoc on the path. */
267 /* A pointer to a virtual base member of a non-null object
268 is non-null. Therefore, we only need to test for zeroness once.
269 Make EXPR the canonical expression to deal with here. */
272 TREE_OPERAND (expr, 2) = nonnull_expr;
273 TREE_TYPE (TREE_OPERAND (expr, 1)) = TREE_TYPE (nonnull_expr);
278 /* If we go through any virtual base pointers, make sure that
279 casts to BASETYPE from the last virtual base class use
280 the right value for BASETYPE. */
283 tree intype = TREE_TYPE (TREE_TYPE (expr));
284 if (TYPE_MAIN_VARIANT (intype) == BINFO_TYPE (last))
288 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0);
290 offset = BINFO_OFFSET (binfo);
297 offset = BINFO_OFFSET (binfo_member (last_virtual,
298 CLASSTYPE_VBASECLASSES (basetype)));
299 offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last));
302 offset = BINFO_OFFSET (last);
305 if (TREE_INT_CST_LOW (offset))
307 /* Bash types to make the backend happy. */
308 offset = convert (type, offset);
309 expr = build1 (NOP_EXPR, type, expr);
311 /* For multiple inheritance: if `this' can be set by any
312 function, then it could be 0 on entry to any function.
313 Preserve such zeroness here. Otherwise, only in the
314 case of constructors need we worry, and in those cases,
315 it will be zero, or initialized to some valid value to
317 if (nonnull == 0 && (alias_this == 0 || flag_this_is_variable > 0))
320 TREE_TYPE (null_expr) = type;
322 null_expr = build1 (NOP_EXPR, type, integer_zero_node);
323 if (TREE_SIDE_EFFECTS (expr))
324 expr = save_expr (expr);
326 return build (COND_EXPR, type,
327 build (EQ_EXPR, boolean_type_node, expr, integer_zero_node),
329 build (code, type, expr, offset));
331 else return build (code, type, expr, offset);
334 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
335 be used multiple times in initialization of multiple inheritance. */
338 TREE_TYPE (expr) = type;
342 return build1 (NOP_EXPR, type, expr);
345 /* Virtual function things. */
347 /* Virtual functions to be dealt with after laying out our base
348 classes. We do all overrides after we layout virtual base classes.
350 static tree pending_hard_virtuals;
351 static int doing_hard_virtuals;
353 /* Build an entry in the virtual function table.
354 DELTA is the offset for the `this' pointer.
355 PFN is an ADDR_EXPR containing a pointer to the virtual function.
356 Note that the index (DELTA2) in the virtual function table
359 build_vtable_entry (delta, pfn)
363 if (flag_vtable_thunks)
365 HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta);
366 extern tree make_thunk ();
369 pfn = build1 (ADDR_EXPR, vtable_entry_type,
370 make_thunk (pfn, idelta));
371 TREE_READONLY (pfn) = 1;
372 TREE_CONSTANT (pfn) = 1;
374 #ifdef GATHER_STATISTICS
375 n_vtable_entries += 1;
381 extern int flag_huge_objects;
382 tree elems = tree_cons (NULL_TREE, delta,
383 tree_cons (NULL_TREE, integer_zero_node,
384 build_tree_list (NULL_TREE, pfn)));
385 tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
387 /* DELTA is constructed by `size_int', which means it may be an
388 unsigned quantity on some platforms. Therefore, we cannot use
389 `int_fits_type_p', because when DELTA is really negative,
390 `force_fit_type' will make it look like a very large number. */
392 if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (delta_type_node))
393 < TREE_INT_CST_LOW (delta))
394 || (TREE_INT_CST_LOW (delta)
395 < TREE_INT_CST_LOW (TYPE_MIN_VALUE (delta_type_node))))
396 if (flag_huge_objects)
397 sorry ("object size exceeds built-in limit for virtual function table implementation");
399 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
401 TREE_CONSTANT (entry) = 1;
402 TREE_STATIC (entry) = 1;
403 TREE_READONLY (entry) = 1;
405 #ifdef GATHER_STATISTICS
406 n_vtable_entries += 1;
413 /* Given an object INSTANCE, return an expression which yields the
414 virtual function corresponding to INDEX. There are many special
415 cases for INSTANCE which we take care of here, mainly to avoid
416 creating extra tree nodes when we don't have to. */
418 build_vfn_ref (ptr_to_instptr, instance, idx)
419 tree *ptr_to_instptr, instance;
422 extern int building_cleanup;
424 tree basetype = TREE_TYPE (instance);
426 if (TREE_CODE (basetype) == REFERENCE_TYPE)
427 basetype = TREE_TYPE (basetype);
429 if (instance == C_C_D)
431 if (current_vtable_decl == NULL_TREE
432 || current_vtable_decl == error_mark_node
433 || !UNIQUELY_DERIVED_FROM_P (DECL_FCONTEXT (CLASSTYPE_VFIELD (current_class_type)), basetype))
434 vtbl = build_indirect_ref (build_vfield_ref (instance, basetype), NULL_PTR);
436 vtbl = current_vtable_decl;
442 /* Try to figure out what a reference refers to, and
443 access its virtual function table directly. */
444 tree ref = NULL_TREE;
446 if (TREE_CODE (instance) == INDIRECT_REF
447 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE)
448 ref = TREE_OPERAND (instance, 0);
449 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
452 if (ref && TREE_CODE (ref) == VAR_DECL
453 && DECL_INITIAL (ref))
455 tree init = DECL_INITIAL (ref);
457 while (TREE_CODE (init) == NOP_EXPR
458 || TREE_CODE (init) == NON_LVALUE_EXPR)
459 init = TREE_OPERAND (init, 0);
460 if (TREE_CODE (init) == ADDR_EXPR)
462 init = TREE_OPERAND (init, 0);
463 if (IS_AGGR_TYPE (TREE_TYPE (init))
464 && (TREE_CODE (init) == PARM_DECL
465 || TREE_CODE (init) == VAR_DECL))
471 if (IS_AGGR_TYPE (TREE_TYPE (instance))
472 && !IS_SIGNATURE_POINTER (TREE_TYPE (instance))
473 && !IS_SIGNATURE_REFERENCE (TREE_TYPE (instance))
474 && (TREE_CODE (instance) == RESULT_DECL
475 || TREE_CODE (instance) == PARM_DECL
476 || TREE_CODE (instance) == VAR_DECL))
477 vtbl = TYPE_BINFO_VTABLE (basetype);
479 vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
482 assemble_external (vtbl);
483 aref = build_array_ref (vtbl, idx);
485 /* Save the intermediate result in a SAVE_EXPR so we don't have to
486 compute each component of the virtual function pointer twice. */
487 if (!building_cleanup && TREE_CODE (aref) == INDIRECT_REF)
488 TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
490 if (flag_vtable_thunks)
496 = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
498 convert (ptrdiff_type_node,
499 build_component_ref (aref, delta_identifier, 0, 0)));
500 return build_component_ref (aref, pfn_identifier, 0, 0);
504 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
505 for the given TYPE. */
507 get_vtable_name (type)
510 tree type_id = build_typename_overload (type);
511 char *buf = (char *)alloca (strlen (VTABLE_NAME_FORMAT)
512 + IDENTIFIER_LENGTH (type_id) + 2);
513 char *ptr = IDENTIFIER_POINTER (type_id);
515 for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
517 /* We don't take off the numbers; prepare_fresh_vtable uses the
518 DECL_ASSEMBLER_NAME for the type, which includes the number
519 in `3foo'. If we were to pull them off here, we'd end up with
520 something like `_vt.foo.3bar', instead of a uniform definition. */
521 while (ptr[i] >= '0' && ptr[i] <= '9')
524 sprintf (buf, VTABLE_NAME_FORMAT, ptr+i);
525 return get_identifier (buf);
528 /* Build a virtual function for type TYPE.
529 If BINFO is non-NULL, build the vtable starting with the initial
530 approximation that it is the same as the one which is the head of
531 the association list. */
533 build_vtable (binfo, type)
536 tree name = get_vtable_name (type);
541 virtuals = copy_list (BINFO_VIRTUALS (binfo));
542 decl = build_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo)));
546 virtuals = NULL_TREE;
547 decl = build_decl (VAR_DECL, name, void_type_node);
550 #ifdef GATHER_STATISTICS
552 n_vtable_elems += list_length (virtuals);
555 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
556 import_export_vtable (decl, type, 0);
558 IDENTIFIER_GLOBAL_VALUE (name) = decl = pushdecl_top_level (decl);
559 /* Initialize the association list for this type, based
560 on our first approximation. */
561 TYPE_BINFO_VTABLE (type) = decl;
562 TYPE_BINFO_VIRTUALS (type) = virtuals;
564 TREE_STATIC (decl) = 1;
565 #ifndef WRITABLE_VTABLES
566 /* Make them READONLY by default. (mrs) */
567 TREE_READONLY (decl) = 1;
569 /* At one time the vtable info was grabbed 2 words at a time. This
570 fails on sparc unless you have 8-byte alignment. (tiemann) */
571 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
574 /* Why is this conditional? (mrs) */
575 if (binfo && write_virtuals >= 0)
576 DECL_VIRTUAL_P (decl) = 1;
577 DECL_CONTEXT (decl) = type;
579 binfo = TYPE_BINFO (type);
580 SET_BINFO_NEW_VTABLE_MARKED (binfo);
584 /* Given a base type PARENT, and a derived type TYPE, build
585 a name which distinguishes exactly the PARENT member of TYPE's type.
587 FORMAT is a string which controls how sprintf formats the name
592 class A; class B; class C : A, B;
594 it is possible to distinguish "A" from "C's A". And given
597 class A : L; class B : L; class C : A, B;
599 it is possible to distinguish "L" from "A's L", and also from
602 Make sure to use the DECL_ASSEMBLER_NAME of the TYPE_NAME of the
603 type, as template have DECL_NAMEs like: X<int>, whereas the
604 DECL_ASSEMBLER_NAME is set to be something the assembler can handle.
607 build_type_pathname (format, parent, type)
611 extern struct obstack temporary_obstack;
612 char *first, *base, *name;
616 parent = TYPE_MAIN_VARIANT (parent);
618 /* Remember where to cut the obstack to. */
619 first = obstack_base (&temporary_obstack);
621 /* Put on TYPE+PARENT. */
622 obstack_grow (&temporary_obstack,
623 TYPE_ASSEMBLER_NAME_STRING (type),
624 TYPE_ASSEMBLER_NAME_LENGTH (type));
626 obstack_1grow (&temporary_obstack, JOINER);
628 obstack_1grow (&temporary_obstack, '_');
630 obstack_grow0 (&temporary_obstack,
631 TYPE_ASSEMBLER_NAME_STRING (parent),
632 TYPE_ASSEMBLER_NAME_LENGTH (parent));
633 i = obstack_object_size (&temporary_obstack);
634 base = obstack_base (&temporary_obstack);
635 obstack_finish (&temporary_obstack);
637 /* Put on FORMAT+TYPE+PARENT. */
638 obstack_blank (&temporary_obstack, strlen (format) + i + 1);
639 name = obstack_base (&temporary_obstack);
640 sprintf (name, format, base);
641 id = get_identifier (name);
642 obstack_free (&temporary_obstack, first);
647 /* Give TYPE a new virtual function table which is initialized
648 with a skeleton-copy of its original initialization. The only
649 entry that changes is the `delta' entry, so we can really
650 share a lot of structure.
652 FOR_TYPE is the derived type which caused this table to
655 BINFO is the type association which provided TYPE for FOR_TYPE. */
657 prepare_fresh_vtable (binfo, for_type)
658 tree binfo, for_type;
660 tree basetype = BINFO_TYPE (binfo);
661 tree orig_decl = BINFO_VTABLE (binfo);
662 /* This name is too simplistic. We can have multiple basetypes for
663 for_type, and we really want different names. (mrs) */
664 tree name = build_type_pathname (VTABLE_NAME_FORMAT, basetype, for_type);
665 tree new_decl = build_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
669 /* Remember which class this vtable is really for. */
670 DECL_CONTEXT (new_decl) = for_type;
672 TREE_STATIC (new_decl) = 1;
673 BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
674 DECL_VIRTUAL_P (new_decl) = 1;
675 #ifndef WRITABLE_VTABLES
676 /* Make them READONLY by default. (mrs) */
677 TREE_READONLY (new_decl) = 1;
679 DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
681 /* Make fresh virtual list, so we can smash it later. */
682 BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
684 if (TREE_VIA_VIRTUAL (binfo))
685 offset = BINFO_OFFSET (binfo_member (BINFO_TYPE (binfo),
686 CLASSTYPE_VBASECLASSES (for_type)));
688 offset = BINFO_OFFSET (binfo);
690 /* Install the value for `headof' if that's what we're doing. */
692 TREE_VALUE (BINFO_VIRTUALS (binfo))
693 = build_vtable_entry (size_binop (MINUS_EXPR, integer_zero_node, offset),
694 FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (BINFO_VIRTUALS (binfo))));
696 #ifdef GATHER_STATISTICS
698 n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
701 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
702 import_export_vtable (new_decl, for_type, 0);
704 if (TREE_VIA_VIRTUAL (binfo))
705 my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo),
706 CLASSTYPE_VBASECLASSES (current_class_type)),
708 SET_BINFO_NEW_VTABLE_MARKED (binfo);
711 /* Access the virtual function table entry that logically
712 contains BASE_FNDECL. VIRTUALS is the virtual function table's
713 initializer. We can run off the end, when dealing with virtual
714 destructors in MI situations, return NULL_TREE in that case. */
716 get_vtable_entry (virtuals, base_fndecl)
717 tree virtuals, base_fndecl;
719 unsigned HOST_WIDE_INT i = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
720 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
721 & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1))
722 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)));
724 #ifdef GATHER_STATISTICS
725 n_vtable_searches += i;
728 while (i > 0 && virtuals)
730 virtuals = TREE_CHAIN (virtuals);
736 /* Put new entry ENTRY into virtual function table initializer
739 Also update DECL_VINDEX (FNDECL). */
742 modify_vtable_entry (old_entry_in_list, new_entry, fndecl)
743 tree old_entry_in_list, new_entry, fndecl;
745 tree base_fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list)), 0);
748 cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl),
749 DECL_ASSEMBLER_NAME (fndecl));
751 TREE_VALUE (old_entry_in_list) = new_entry;
753 /* Now assign virtual dispatch information, if unset. */
754 /* We can dispatch this, through any overridden base function. */
755 if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
757 DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
758 DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
762 /* Access the virtual function table entry i. VIRTUALS is the virtual
763 function table's initializer. */
765 get_vtable_entry_n (virtuals, i)
767 unsigned HOST_WIDE_INT i;
771 virtuals = TREE_CHAIN (virtuals);
777 /* Add a virtual function to all the appropriate vtables for the class
778 T. DECL_VINDEX(X) should be error_mark_node, if we want to
779 allocate a new slot in our table. If it is error_mark_node, we
780 know that no other function from another vtable is overridden by X.
781 HAS_VIRTUAL keeps track of how many virtuals there are in our main
782 vtable for the type, and we build upon the PENDING_VIRTUALS list
785 add_virtual_function (pending_virtuals, has_virtual, fndecl, t)
786 tree pending_virtuals;
789 tree t; /* Structure type. */
791 /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
792 convert to void *. Make such a conversion here. */
793 tree vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
794 TREE_CONSTANT (vfn) = 1;
797 if (current_class_type == 0)
798 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
800 if (current_class_type && t != current_class_type)
801 cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
805 /* If the virtual function is a redefinition of a prior one,
806 figure out in which base class the new definition goes,
807 and if necessary, make a fresh virtual function table
808 to hold that entry. */
809 if (DECL_VINDEX (fndecl) == error_mark_node)
813 if (flag_rtti && *has_virtual == 0)
815 /* CLASSTYPE_RTTI is only used as a Boolean (NULL or not). */
816 CLASSTYPE_RTTI (t) = integer_one_node;
822 /* Build a new INT_CST for this DECL_VINDEX. */
824 static tree index_table[256];
826 int i = ++(*has_virtual);
828 if (i >= 256 || index_table[i] == 0)
830 index = build_int_2 (i, 0);
832 index_table[i] = index;
835 index = index_table[i];
837 /* Now assign virtual dispatch information. */
838 DECL_VINDEX (fndecl) = index;
839 DECL_CONTEXT (fndecl) = t;
841 entry = build_vtable_entry (integer_zero_node, vfn);
842 pending_virtuals = tree_cons (DECL_VINDEX (fndecl), entry, pending_virtuals);
844 /* Might already be INTEGER_CST if declared twice in class. We will
845 give error later or we've already given it. */
846 else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
848 /* Need an entry in some other virtual function table.
849 Deal with this after we have laid out our virtual base classes. */
850 pending_hard_virtuals = temp_tree_cons (fndecl, vfn, pending_hard_virtuals);
852 return pending_virtuals;
855 /* Obstack on which to build the vector of class methods. */
856 struct obstack class_obstack;
857 extern struct obstack *current_obstack;
859 /* Add method METHOD to class TYPE. This is used when a method
860 has been defined which did not initially appear in the class definition,
861 and helps cut down on spurious error messages.
863 FIELDS is the entry in the METHOD_VEC vector entry of the class type where
864 the method should be added. */
866 add_method (type, fields, method)
867 tree type, *fields, method;
869 /* We must make a copy of METHOD here, since we must be sure that
870 we have exclusive title to this method's DECL_CHAIN. */
873 push_obstacks (&permanent_obstack, &permanent_obstack);
875 decl = copy_node (method);
876 if (DECL_RTL (decl) == 0
877 && (!processing_template_decl
878 || !uses_template_parms (decl)))
880 make_function_rtl (decl);
881 DECL_RTL (method) = DECL_RTL (decl);
885 if (fields && *fields)
887 /* Take care not to hide destructor. */
888 DECL_CHAIN (decl) = DECL_CHAIN (*fields);
889 DECL_CHAIN (*fields) = decl;
891 else if (CLASSTYPE_METHOD_VEC (type) == 0)
893 tree method_vec = make_node (TREE_VEC);
894 if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
896 TREE_VEC_ELT (method_vec, 0) = decl;
897 TREE_VEC_LENGTH (method_vec) = 1;
901 /* ??? Is it possible for there to have been enough room in the
902 current chunk for the tree_vec structure but not a tree_vec
903 plus a tree*? Will this work in that case? */
904 obstack_free (current_obstack, method_vec);
905 obstack_blank (current_obstack, sizeof (struct tree_vec) + sizeof (tree *));
906 TREE_VEC_ELT (method_vec, 1) = decl;
907 TREE_VEC_LENGTH (method_vec) = 2;
908 obstack_finish (current_obstack);
910 CLASSTYPE_METHOD_VEC (type) = method_vec;
914 tree method_vec = CLASSTYPE_METHOD_VEC (type);
915 int len = TREE_VEC_LENGTH (method_vec);
917 /* Adding a new ctor or dtor. This is easy because our
918 METHOD_VEC always has a slot for such entries. */
919 if (TYPE_IDENTIFIER (type) == DECL_NAME (decl))
921 /* TREE_VEC_ELT (method_vec, 0) = decl; */
922 if (decl != TREE_VEC_ELT (method_vec, 0))
924 DECL_CHAIN (decl) = TREE_VEC_ELT (method_vec, 0);
925 TREE_VEC_ELT (method_vec, 0) = decl;
930 /* This is trickier. We try to extend the TREE_VEC in-place,
931 but if that does not work, we copy all its data to a new
932 TREE_VEC that's large enough. */
933 struct obstack *ob = &class_obstack;
934 tree *end = (tree *)obstack_next_free (ob);
936 if (end != TREE_VEC_END (method_vec))
938 ob = current_obstack;
939 TREE_VEC_LENGTH (method_vec) += 1;
940 TREE_VEC_ELT (method_vec, len) = NULL_TREE;
941 method_vec = copy_node (method_vec);
942 TREE_VEC_LENGTH (method_vec) -= 1;
946 tree tmp_vec = (tree) obstack_base (ob);
947 if (obstack_room (ob) < sizeof (tree))
949 obstack_blank (ob, sizeof (struct tree_common)
950 + tree_code_length[(int) TREE_VEC]
952 + len * sizeof (tree));
953 tmp_vec = (tree) obstack_base (ob);
954 bcopy ((char *) method_vec, (char *) tmp_vec,
955 (sizeof (struct tree_common)
956 + tree_code_length[(int) TREE_VEC] * sizeof (char *)
957 + (len-1) * sizeof (tree)));
958 method_vec = tmp_vec;
961 obstack_blank (ob, sizeof (tree));
965 TREE_VEC_ELT (method_vec, len) = decl;
966 TREE_VEC_LENGTH (method_vec) = len + 1;
967 CLASSTYPE_METHOD_VEC (type) = method_vec;
969 if (TYPE_BINFO_BASETYPES (type) && CLASSTYPE_BASELINK_VEC (type))
971 /* ??? May be better to know whether these can be extended? */
972 tree baselink_vec = CLASSTYPE_BASELINK_VEC (type);
974 TREE_VEC_LENGTH (baselink_vec) += 1;
975 CLASSTYPE_BASELINK_VEC (type) = copy_node (baselink_vec);
976 TREE_VEC_LENGTH (baselink_vec) -= 1;
978 TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), len) = 0;
982 DECL_CONTEXT (decl) = type;
983 DECL_CLASS_CONTEXT (decl) = type;
988 /* Subroutines of finish_struct. */
990 /* Look through the list of fields for this struct, deleting
991 duplicates as we go. This must be recursive to handle
994 FIELD is the field which may not appear anywhere in FIELDS.
995 FIELD_PTR, if non-null, is the starting point at which
996 chained deletions may take place.
997 The value returned is the first acceptable entry found
1000 Note that anonymous fields which are not of UNION_TYPE are
1001 not duplicates, they are just anonymous fields. This happens
1002 when we have unnamed bitfields, for example. */
1004 delete_duplicate_fields_1 (field, fields)
1009 if (DECL_NAME (field) == 0)
1011 if (TREE_CODE (TREE_TYPE (field)) != UNION_TYPE)
1014 for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
1015 fields = delete_duplicate_fields_1 (x, fields);
1020 for (x = fields; x; prev = x, x = TREE_CHAIN (x))
1022 if (DECL_NAME (x) == 0)
1024 if (TREE_CODE (TREE_TYPE (x)) != UNION_TYPE)
1026 TYPE_FIELDS (TREE_TYPE (x))
1027 = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x)));
1028 if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
1031 fields = TREE_CHAIN (fields);
1033 TREE_CHAIN (prev) = TREE_CHAIN (x);
1038 if (DECL_NAME (field) == DECL_NAME (x))
1040 if (TREE_CODE (field) == CONST_DECL
1041 && TREE_CODE (x) == CONST_DECL)
1042 cp_error_at ("duplicate enum value `%D'", x);
1043 else if (TREE_CODE (field) == CONST_DECL
1044 || TREE_CODE (x) == CONST_DECL)
1045 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1047 else if (TREE_CODE (field) == TYPE_DECL
1048 && TREE_CODE (x) == TYPE_DECL)
1049 cp_error_at ("duplicate nested type `%D'", x);
1050 else if (TREE_CODE (field) == TYPE_DECL
1051 || TREE_CODE (x) == TYPE_DECL)
1052 cp_error_at ("duplicate field `%D' (as type and non-type)",
1055 cp_error_at ("duplicate member `%D'", x);
1057 fields = TREE_CHAIN (fields);
1059 TREE_CHAIN (prev) = TREE_CHAIN (x);
1068 delete_duplicate_fields (fields)
1072 for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
1073 TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
1076 /* Change the access of FDECL to ACCESS in T.
1077 Return 1 if change was legit, otherwise return 0. */
1079 alter_access (t, fdecl, access)
1082 enum access_type access;
1084 tree elem = purpose_member (t, DECL_ACCESS (fdecl));
1085 if (elem && TREE_VALUE (elem) != (tree)access)
1087 if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
1089 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
1092 error ("conflicting access specifications for field `%s', ignored",
1093 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
1095 else if (TREE_PRIVATE (fdecl))
1097 if (access != access_private)
1098 cp_error_at ("cannot make private `%D' non-private", fdecl);
1101 else if (TREE_PROTECTED (fdecl))
1103 if (access != access_protected)
1104 cp_error_at ("cannot make protected `%D' non-protected", fdecl);
1107 /* ARM 11.3: an access declaration may not be used to restrict access
1108 to a member that is accessible in the base class. */
1109 else if (access != access_public)
1110 cp_error_at ("cannot reduce access of public member `%D'", fdecl);
1111 else if (elem == NULL_TREE)
1114 DECL_ACCESS (fdecl) = tree_cons (t, (tree)access,
1115 DECL_ACCESS (fdecl));
1121 /* Return the offset to the main vtable for a given base BINFO. */
1123 get_vfield_offset (binfo)
1126 return size_binop (PLUS_EXPR,
1127 size_binop (FLOOR_DIV_EXPR,
1128 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
1129 size_int (BITS_PER_UNIT)),
1130 BINFO_OFFSET (binfo));
1133 /* Get the offset to the start of the original binfo that we derived
1134 this binfo from. If we find TYPE first, return the offset only
1135 that far. The shortened search is useful because the this pointer
1136 on method calling is expected to point to a DECL_CONTEXT (fndecl)
1137 object, and not a baseclass of it. */
1139 get_derived_offset (binfo, type)
1142 tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
1145 while (BINFO_BASETYPES (binfo)
1146 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
1148 tree binfos = BINFO_BASETYPES (binfo);
1149 if (BINFO_TYPE (binfo) == type)
1151 binfo = TREE_VEC_ELT (binfos, i);
1153 offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
1154 return size_binop (MINUS_EXPR, offset1, offset2);
1157 /* If FOR_TYPE needs to reinitialize virtual function table pointers
1158 for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
1159 Returns BASE_INIT_LIST appropriately modified. */
1162 maybe_fixup_vptrs (for_type, binfo, base_init_list)
1163 tree for_type, binfo, base_init_list;
1165 /* Now reinitialize any slots that don't fall under our virtual
1166 function table pointer. */
1167 tree vfields = CLASSTYPE_VFIELDS (BINFO_TYPE (binfo));
1170 tree basetype = VF_NORMAL_VALUE (vfields)
1171 ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields))
1172 : VF_BASETYPE_VALUE (vfields);
1174 tree base_binfo = get_binfo (basetype, for_type, 0);
1175 /* Punt until this is implemented. */
1176 if (1 /* BINFO_MODIFIED (base_binfo) */)
1178 tree base_offset = get_vfield_offset (base_binfo);
1179 if (! tree_int_cst_equal (base_offset, get_vfield_offset (TYPE_BINFO (for_type)))
1180 && ! tree_int_cst_equal (base_offset, get_vfield_offset (binfo)))
1181 base_init_list = tree_cons (error_mark_node, base_binfo,
1184 vfields = TREE_CHAIN (vfields);
1186 return base_init_list;
1189 /* If TYPE does not have a constructor, then the compiler must
1190 manually deal with all of the initialization this type requires.
1192 If a base initializer exists only to fill in the virtual function
1193 table pointer, then we mark that fact with the TREE_VIRTUAL bit.
1194 This way, we avoid multiple initializations of the same field by
1195 each virtual function table up the class hierarchy.
1197 Virtual base class pointers are not initialized here. They are
1198 initialized only at the "top level" of object creation. If we
1199 initialized them here, we would have to skip a lot of work. */
1202 build_class_init_list (type)
1205 tree base_init_list = NULL_TREE;
1206 tree member_init_list = NULL_TREE;
1208 /* Since we build member_init_list and base_init_list using
1209 tree_cons, backwards fields the all through work. */
1211 tree binfos = BINFO_BASETYPES (TYPE_BINFO (type));
1212 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1214 for (x = TYPE_FIELDS (type); x; x = TREE_CHAIN (x))
1216 if (TREE_CODE (x) != FIELD_DECL)
1219 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x))
1220 || DECL_INITIAL (x) != NULL_TREE)
1221 member_init_list = tree_cons (x, type, member_init_list);
1223 member_init_list = nreverse (member_init_list);
1225 /* We will end up doing this last. Need special marker
1226 to avoid infinite regress. */
1227 if (TYPE_VIRTUAL_P (type))
1229 base_init_list = build_tree_list (error_mark_node, TYPE_BINFO (type));
1230 if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type) == 0)
1231 TREE_VALUE (base_init_list) = NULL_TREE;
1232 TREE_ADDRESSABLE (base_init_list) = 1;
1235 /* Each base class which needs to have initialization
1236 of some kind gets to make such requests known here. */
1237 for (i = n_baseclasses-1; i >= 0; i--)
1239 tree base_binfo = TREE_VEC_ELT (binfos, i);
1242 /* Don't initialize virtual baseclasses this way. */
1243 if (TREE_VIA_VIRTUAL (base_binfo))
1246 if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (base_binfo)))
1248 /* ...and the last shall come first... */
1249 base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list);
1250 base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
1254 if ((blist = CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (base_binfo))) == NULL_TREE)
1255 /* Nothing to initialize. */
1259 base_init_list = maybe_fixup_vptrs (type, base_binfo, base_init_list);
1261 /* This is normally true for single inheritance.
1262 The win is we can shrink the chain of initializations
1263 to be done by only converting to the actual type
1264 we are interested in. */
1265 if (TREE_VALUE (blist)
1266 && TREE_CODE (TREE_VALUE (blist)) == TREE_VEC
1267 && tree_int_cst_equal (BINFO_OFFSET (base_binfo),
1268 BINFO_OFFSET (TREE_VALUE (blist))))
1272 /* Does it do more than just fill in a
1273 virtual function table pointer? */
1274 if (! TREE_ADDRESSABLE (blist))
1275 base_init_list = build_tree_list (blist, base_init_list);
1276 /* Can we get by just with the virtual function table
1277 pointer that it fills in? */
1278 else if (TREE_ADDRESSABLE (base_init_list)
1279 && TREE_VALUE (base_init_list) == 0)
1280 base_init_list = blist;
1281 /* Maybe, but it is not obvious as the previous case. */
1282 else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type))
1284 tree last = tree_last (base_init_list);
1285 while (TREE_VALUE (last)
1286 && TREE_CODE (TREE_VALUE (last)) == TREE_LIST)
1287 last = tree_last (TREE_VALUE (last));
1288 if (TREE_VALUE (last) == 0)
1289 base_init_list = build_tree_list (blist, base_init_list);
1293 base_init_list = blist;
1297 /* The function expand_aggr_init knows how to do the
1298 initialization of `basetype' without getting
1299 an explicit `blist'. */
1301 base_init_list = tree_cons (NULL_TREE, base_binfo, base_init_list);
1303 base_init_list = CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo));
1308 if (member_init_list)
1309 CLASSTYPE_BASE_INIT_LIST (type) = build_tree_list (base_init_list, member_init_list);
1311 CLASSTYPE_BASE_INIT_LIST (type) = base_init_list;
1312 else if (member_init_list)
1313 CLASSTYPE_BASE_INIT_LIST (type) = member_init_list;
1319 int max_has_virtual;
1323 char cant_have_default_ctor;
1324 char cant_have_const_ctor;
1325 char cant_synth_copy_ctor;
1326 char cant_synth_asn_ref;
1327 char no_const_asn_ref;
1328 char needs_virtual_dtor;
1331 /* Record information about type T derived from its base classes.
1332 Store most of that information in T itself, and place the
1333 remaining information in the struct BASE_INFO.
1335 Propagate basetype offsets throughout the lattice. Note that the
1336 lattice topped by T is really a pair: it's a DAG that gives the
1337 structure of the derivation hierarchy, and it's a list of the
1338 virtual baseclasses that appear anywhere in the DAG. When a vbase
1339 type appears in the DAG, it's offset is 0, and it's children start
1340 their offsets from that point. When a vbase type appears in the list,
1341 its offset is the offset it has in the hierarchy, and its children's
1342 offsets include that offset in theirs.
1344 Returns the index of the first base class to have virtual functions,
1345 or -1 if no such base class.
1347 Note that at this point TYPE_BINFO (t) != t_binfo. */
1350 finish_base_struct (t, b, t_binfo)
1352 struct base_info *b;
1355 tree binfos = BINFO_BASETYPES (t_binfo);
1356 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1357 int first_vfn_base_index = -1;
1358 bzero ((char *) b, sizeof (struct base_info));
1360 for (i = 0; i < n_baseclasses; i++)
1362 tree base_binfo = TREE_VEC_ELT (binfos, i);
1363 tree basetype = BINFO_TYPE (base_binfo);
1365 /* If the type of basetype is incomplete, then
1366 we already complained about that fact
1367 (and we should have fixed it up as well). */
1368 if (TYPE_SIZE (basetype) == 0)
1371 /* The base type is of incomplete type. It is
1372 probably best to pretend that it does not
1374 if (i == n_baseclasses-1)
1375 TREE_VEC_ELT (binfos, i) = NULL_TREE;
1376 TREE_VEC_LENGTH (binfos) -= 1;
1378 for (j = i; j+1 < n_baseclasses; j++)
1379 TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
1382 if (TYPE_HAS_INIT_REF (basetype)
1383 && !TYPE_HAS_CONST_INIT_REF (basetype))
1384 b->cant_have_const_ctor = 1;
1385 if (! TYPE_HAS_INIT_REF (basetype)
1386 || (TYPE_HAS_NONPUBLIC_CTOR (basetype) == 2
1387 && ! is_friend_type (t, basetype)))
1388 b->cant_synth_copy_ctor = 1;
1390 if (TYPE_HAS_CONSTRUCTOR (basetype)
1391 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
1393 b->cant_have_default_ctor = 1;
1394 if (! TYPE_HAS_CONSTRUCTOR (t))
1396 cp_pedwarn ("base `%T' with only non-default constructor",
1398 cp_pedwarn ("in class without a constructor");
1402 if (TYPE_HAS_ASSIGN_REF (basetype)
1403 && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
1404 b->no_const_asn_ref = 1;
1405 if (! TYPE_HAS_ASSIGN_REF (basetype)
1406 || TYPE_HAS_ABSTRACT_ASSIGN_REF (basetype)
1407 || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (basetype) == 2
1408 && ! is_friend_type (t, basetype)))
1409 b->cant_synth_asn_ref = 1;
1411 b->n_ancestors += CLASSTYPE_N_SUPERCLASSES (basetype);
1412 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
1413 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
1414 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
1415 TYPE_HAS_COMPLEX_INIT_REF (t) |= (TYPE_HAS_COMPLEX_INIT_REF (basetype)
1416 || TYPE_NEEDS_CONSTRUCTING (basetype));
1418 TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
1419 TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
1420 TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
1422 if (! TREE_VIA_VIRTUAL (base_binfo)
1424 /* This cannot be done, as prepare_fresh_vtable wants to modify
1425 binfos associated with vfields anywhere in the hierarchy, not
1426 just immediate base classes. Due to unsharing, the compiler
1427 might consume 3% more memory on a real program.
1429 && ! BINFO_OFFSET_ZEROP (base_binfo)
1431 && BINFO_BASETYPES (base_binfo))
1433 tree base_binfos = BINFO_BASETYPES (base_binfo);
1434 tree chain = NULL_TREE;
1437 /* Now unshare the structure beneath BASE_BINFO. */
1438 for (j = TREE_VEC_LENGTH (base_binfos)-1;
1441 tree base_base_binfo = TREE_VEC_ELT (base_binfos, j);
1442 if (! TREE_VIA_VIRTUAL (base_base_binfo))
1443 TREE_VEC_ELT (base_binfos, j)
1444 = make_binfo (BINFO_OFFSET (base_base_binfo),
1446 BINFO_VTABLE (base_base_binfo),
1447 BINFO_VIRTUALS (base_base_binfo),
1449 chain = TREE_VEC_ELT (base_binfos, j);
1450 TREE_VIA_PUBLIC (chain) = TREE_VIA_PUBLIC (base_base_binfo);
1451 TREE_VIA_PROTECTED (chain) = TREE_VIA_PROTECTED (base_base_binfo);
1452 BINFO_INHERITANCE_CHAIN (chain) = base_binfo;
1455 /* Completely unshare potentially shared data, and
1456 update what is ours. */
1457 propagate_binfo_offsets (base_binfo, BINFO_OFFSET (base_binfo));
1460 if (! TREE_VIA_VIRTUAL (base_binfo))
1461 CLASSTYPE_N_SUPERCLASSES (t) += 1;
1463 if (TYPE_VIRTUAL_P (basetype))
1465 /* If there's going to be a destructor needed, make
1466 sure it will be virtual. */
1467 b->needs_virtual_dtor = 1;
1469 /* Don't borrow virtuals from virtual baseclasses. */
1470 if (TREE_VIA_VIRTUAL (base_binfo))
1473 if (first_vfn_base_index < 0)
1476 first_vfn_base_index = i;
1478 /* Update these two, now that we know what vtable we are
1479 going to extend. This is so that we can add virtual
1480 functions, and override them properly. */
1481 BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype);
1482 BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype);
1483 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1484 b->vfield = CLASSTYPE_VFIELD (basetype);
1485 b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
1486 vfields = b->vfields;
1489 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1490 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1492 tree value = VF_BASETYPE_VALUE (vfields);
1493 if (DECL_NAME (CLASSTYPE_VFIELD (value))
1494 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1495 VF_NORMAL_VALUE (b->vfields) = basetype;
1497 VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
1499 vfields = TREE_CHAIN (vfields);
1501 CLASSTYPE_VFIELD (t) = b->vfield;
1505 /* Only add unique vfields, and flatten them out as we go. */
1506 tree vfields = CLASSTYPE_VFIELDS (basetype);
1509 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1510 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1512 tree value = VF_BASETYPE_VALUE (vfields);
1513 b->vfields = tree_cons (base_binfo, value, b->vfields);
1514 if (DECL_NAME (CLASSTYPE_VFIELD (value))
1515 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1516 VF_NORMAL_VALUE (b->vfields) = basetype;
1518 VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
1520 vfields = TREE_CHAIN (vfields);
1523 if (b->has_virtual == 0)
1525 first_vfn_base_index = i;
1527 /* Update these two, now that we know what vtable we are
1528 going to extend. This is so that we can add virtual
1529 functions, and override them properly. */
1530 BINFO_VTABLE (t_binfo) = TYPE_BINFO_VTABLE (basetype);
1531 BINFO_VIRTUALS (t_binfo) = TYPE_BINFO_VIRTUALS (basetype);
1532 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1533 b->vfield = CLASSTYPE_VFIELD (basetype);
1534 CLASSTYPE_VFIELD (t) = b->vfield;
1535 /* When we install the first one, set the VF_NORMAL_VALUE
1536 to be the current class, as this it is the most derived
1537 class. Hopefully, this is not set to something else
1539 vfields = b->vfields;
1542 if (DECL_NAME (CLASSTYPE_VFIELD (t))
1543 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1545 VF_NORMAL_VALUE (vfields) = t;
1546 /* There should only be one of them! And it should
1547 always be found, if we get into here. (mrs) */
1550 vfields = TREE_CHAIN (vfields);
1557 /* Must come after offsets are fixed for all bases. */
1558 for (i = 0; i < n_baseclasses; i++)
1560 tree base_binfo = TREE_VEC_ELT (binfos, i);
1561 tree basetype = BINFO_TYPE (base_binfo);
1563 if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2)
1565 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
1567 b->cant_synth_asn_ref = 1;
1568 b->cant_synth_copy_ctor = 1;
1572 tree v = get_vbase_types (t_binfo);
1574 for (; v; v = TREE_CHAIN (v))
1576 tree basetype = BINFO_TYPE (v);
1577 if (get_base_distance (basetype, t_binfo, 0, (tree*)0) == -2)
1580 cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
1582 b->cant_synth_asn_ref = 1;
1583 b->cant_synth_copy_ctor = 1;
1590 /* Find the base class with the largest number of virtual functions. */
1591 for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields))
1593 if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual)
1594 b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields));
1595 if (VF_DERIVED_VALUE (vfields)
1596 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
1597 b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
1602 /* If all virtual functions come only from virtual baseclasses. */
1604 return first_vfn_base_index;
1608 typecode_p (type, code)
1610 enum tree_code code;
1612 return (TREE_CODE (type) == code
1613 || (TREE_CODE (type) == REFERENCE_TYPE
1614 && TREE_CODE (TREE_TYPE (type)) == code));
1617 /* Set memoizing fields and bits of T (and its variants) for later use.
1618 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1620 finish_struct_bits (t, max_has_virtual)
1622 int max_has_virtual;
1624 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1625 tree method_vec = CLASSTYPE_METHOD_VEC (t);
1627 /* Fix up variants (if any). */
1628 tree variants = TYPE_NEXT_VARIANT (t);
1631 /* These fields are in the _TYPE part of the node, not in
1632 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1633 TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
1634 TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
1635 TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
1636 TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
1638 TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t);
1639 TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t);
1640 TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
1641 /* Copy whatever these are holding today. */
1642 TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
1643 TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
1644 variants = TYPE_NEXT_VARIANT (variants);
1647 if (n_baseclasses && max_has_virtual)
1649 /* Done by `finish_struct' for classes without baseclasses. */
1650 int might_have_abstract_virtuals = CLASSTYPE_ABSTRACT_VIRTUALS (t) != 0;
1651 tree binfos = TYPE_BINFO_BASETYPES (t);
1652 for (i = n_baseclasses-1; i >= 0; i--)
1654 might_have_abstract_virtuals
1655 |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos, i))) != 0);
1656 if (might_have_abstract_virtuals)
1659 if (might_have_abstract_virtuals)
1661 /* We use error_mark_node from override_one_vtable to signal
1662 an artificial abstract. */
1663 if (CLASSTYPE_ABSTRACT_VIRTUALS (t) == error_mark_node)
1664 CLASSTYPE_ABSTRACT_VIRTUALS (t) = NULL_TREE;
1665 CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t);
1671 /* Notice whether this class has type conversion functions defined. */
1672 tree binfo = TYPE_BINFO (t);
1673 tree binfos = BINFO_BASETYPES (binfo);
1676 for (i = n_baseclasses-1; i >= 0; i--)
1678 basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
1680 if (TYPE_HAS_CONVERSION (basetype))
1682 TYPE_HAS_CONVERSION (t) = 1;
1683 TYPE_HAS_INT_CONVERSION (t) |= TYPE_HAS_INT_CONVERSION (basetype);
1684 TYPE_HAS_REAL_CONVERSION (t) |= TYPE_HAS_REAL_CONVERSION (basetype);
1686 if (CLASSTYPE_MAX_DEPTH (basetype) >= CLASSTYPE_MAX_DEPTH (t))
1687 CLASSTYPE_MAX_DEPTH (t) = CLASSTYPE_MAX_DEPTH (basetype) + 1;
1691 /* If this type has constructors, force its mode to be BLKmode,
1692 and force its TREE_ADDRESSABLE bit to be nonzero. */
1693 if (TYPE_NEEDS_CONSTRUCTING (t) || TYPE_NEEDS_DESTRUCTOR (t))
1697 if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
1698 DECL_MODE (TYPE_NAME (t)) = BLKmode;
1701 TYPE_MODE (variants) = BLKmode;
1702 TREE_ADDRESSABLE (variants) = 1;
1703 variants = TYPE_NEXT_VARIANT (variants);
1708 /* Add FN to the method_vec growing on the class_obstack. Used by
1709 finish_struct_methods. */
1711 grow_method (fn, method_vec_ptr)
1713 tree *method_vec_ptr;
1715 tree method_vec = (tree)obstack_base (&class_obstack);
1716 tree *testp = &TREE_VEC_ELT (method_vec, 0);
1717 if (*testp == NULL_TREE)
1719 while (((HOST_WIDE_INT) testp
1720 < (HOST_WIDE_INT) obstack_next_free (&class_obstack))
1721 && DECL_NAME (*testp) != DECL_NAME (fn))
1723 if ((HOST_WIDE_INT) testp
1724 < (HOST_WIDE_INT) obstack_next_free (&class_obstack))
1728 for (x = *testp; x; x = DECL_CHAIN (x))
1730 if (DECL_NAME (fn) == ansi_opname[(int) DELETE_EXPR]
1731 || DECL_NAME (fn) == ansi_opname[(int) VEC_DELETE_EXPR])
1733 /* ANSI C++ June 5 1992 WP 12.5.5.1 */
1734 cp_error_at ("`%D' overloaded", fn);
1735 cp_error_at ("previous declaration as `%D' here", x);
1737 if (DECL_ASSEMBLER_NAME (fn)==DECL_ASSEMBLER_NAME (x))
1739 /* We complain about multiple destructors on sight,
1740 so we do not repeat the warning here. Friend-friend
1741 ambiguities are warned about outside this loop. */
1742 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn)))
1743 cp_error_at ("ambiguous method `%#D' in structure", fn);
1751 DECL_CHAIN (prev_x) = fn;
1758 obstack_ptr_grow (&class_obstack, fn);
1759 *method_vec_ptr = (tree)obstack_base (&class_obstack);
1763 /* Warn about duplicate methods in fn_fields. Also compact method
1764 lists so that lookup can be made faster.
1766 Algorithm: Outer loop builds lists by method name. Inner loop
1767 checks for redundant method names within a list.
1769 Data Structure: List of method lists. The outer list is a
1770 TREE_LIST, whose TREE_PURPOSE field is the field name and the
1771 TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN
1772 links the entire list of methods for TYPE_METHODS. Friends are
1773 chained in the same way as member functions (? TREE_CHAIN or
1774 DECL_CHAIN), but they live in the TREE_TYPE field of the outer
1775 list. That allows them to be quickly deleted, and requires no
1778 If there are any constructors/destructors, they are moved to the
1779 front of the list. This makes pushclass more efficient.
1781 We also link each field which has shares a name with its baseclass
1782 to the head of the list of fields for that base class. This allows
1783 us to reduce search time in places like `build_method_call' to
1784 consider only reasonably likely functions. */
1787 finish_struct_methods (t, fn_fields, nonprivate_method)
1790 int nonprivate_method;
1793 tree save_fn_fields = tree_cons (NULL_TREE, NULL_TREE, fn_fields);
1795 tree name = constructor_name (t);
1796 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1798 /* Now prepare to gather fn_fields into vector. */
1799 struct obstack *ambient_obstack = current_obstack;
1800 current_obstack = &class_obstack;
1801 method_vec = make_node (TREE_VEC);
1802 /* Room has been saved for constructors and destructors. */
1803 current_obstack = ambient_obstack;
1804 /* Now make this a live vector. */
1805 obstack_free (&class_obstack, method_vec);
1806 obstack_blank (&class_obstack, sizeof (struct tree_vec));
1808 /* First fill in entry 0 with the constructors, and the next few with
1809 type conversion operators (if any). */
1811 for (lastp = save_fn_fields; fn_fields; fn_fields = TREE_CHAIN (lastp))
1813 tree fn_name = DECL_NAME (fn_fields);
1814 if (fn_name == NULL_TREE)
1817 /* Clear out this flag.
1819 @@ Doug may figure out how to break
1820 @@ this with nested classes and friends. */
1821 DECL_IN_AGGR_P (fn_fields) = 0;
1823 /* Note here that a copy ctor is private, so we don't dare generate
1824 a default copy constructor for a class that has a member
1825 of this type without making sure they have access to it. */
1826 if (fn_name == name)
1828 tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields);
1829 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
1831 if (TREE_CODE (parmtype) == REFERENCE_TYPE
1832 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t)
1834 if (TREE_CHAIN (parmtypes) == NULL_TREE
1835 || TREE_CHAIN (parmtypes) == void_list_node
1836 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
1838 if (TREE_PROTECTED (fn_fields))
1839 TYPE_HAS_NONPUBLIC_CTOR (t) = 1;
1840 else if (TREE_PRIVATE (fn_fields))
1841 TYPE_HAS_NONPUBLIC_CTOR (t) = 2;
1844 /* Constructors are handled easily in search routines. */
1845 DECL_CHAIN (fn_fields) = TREE_VEC_ELT (method_vec, 0);
1846 TREE_VEC_ELT (method_vec, 0) = fn_fields;
1848 else if (IDENTIFIER_TYPENAME_P (fn_name))
1850 tree return_type = TREE_TYPE (TREE_TYPE (fn_fields));
1852 if (typecode_p (return_type, INTEGER_TYPE)
1853 || typecode_p (return_type, BOOLEAN_TYPE)
1854 || typecode_p (return_type, ENUMERAL_TYPE))
1855 TYPE_HAS_INT_CONVERSION (t) = 1;
1856 else if (typecode_p (return_type, REAL_TYPE))
1857 TYPE_HAS_REAL_CONVERSION (t) = 1;
1859 grow_method (fn_fields, &method_vec);
1867 TREE_CHAIN (lastp) = TREE_CHAIN (fn_fields);
1868 TREE_CHAIN (fn_fields) = NULL_TREE;
1871 fn_fields = TREE_CHAIN (save_fn_fields);
1875 tree fn_name = DECL_NAME (fn_fields);
1876 if (fn_name == NULL_TREE)
1879 nextp = TREE_CHAIN (fn_fields);
1880 TREE_CHAIN (fn_fields) = NULL_TREE;
1882 if (fn_name == ansi_opname[(int) MODIFY_EXPR])
1884 tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields));
1886 if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields)))
1888 if (TREE_PROTECTED (fn_fields))
1889 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1;
1890 else if (TREE_PRIVATE (fn_fields))
1891 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2;
1895 grow_method (fn_fields, &method_vec);
1899 TREE_VEC_LENGTH (method_vec) = (tree *)obstack_next_free (&class_obstack)
1900 - (&TREE_VEC_ELT (method_vec, 0));
1901 obstack_finish (&class_obstack);
1902 CLASSTYPE_METHOD_VEC (t) = method_vec;
1904 if (nonprivate_method == 0
1905 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
1906 && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
1908 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
1909 for (i = 0; i < n_baseclasses; i++)
1910 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
1911 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
1913 nonprivate_method = 1;
1916 if (nonprivate_method == 0)
1917 cp_warning ("all member functions in class `%T' are private", t);
1920 /* If there are constructors (and destructors), they are at the
1921 front. Place destructors at very front. Also warn if all
1922 constructors and/or destructors are private (in which case this
1923 class is effectively unusable. */
1924 if (TYPE_HAS_DESTRUCTOR (t))
1928 for (dtor = TREE_VEC_ELT (method_vec, 0);
1930 prev = dtor, dtor = DECL_CHAIN (dtor))
1932 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (dtor)))
1934 if (TREE_PRIVATE (dtor)
1935 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
1936 && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE
1937 && warn_ctor_dtor_privacy)
1938 cp_warning ("`%#T' only defines a private destructor and has no friends",
1944 /* Wild parse errors can cause this to happen. */
1945 if (dtor == NULL_TREE)
1946 TYPE_HAS_DESTRUCTOR (t) = 0;
1947 else if (dtor != TREE_VEC_ELT (method_vec, 0))
1949 DECL_CHAIN (prev) = DECL_CHAIN (dtor);
1950 DECL_CHAIN (dtor) = TREE_VEC_ELT (method_vec, 0);
1951 TREE_VEC_ELT (method_vec, 0) = dtor;
1955 /* Now for each member function (except for constructors and
1956 destructors), compute where member functions of the same
1957 name reside in base classes. */
1958 if (n_baseclasses != 0
1959 && TREE_VEC_LENGTH (method_vec) > 1)
1961 int len = TREE_VEC_LENGTH (method_vec);
1962 tree baselink_vec = make_tree_vec (len);
1964 tree baselink_binfo = build_tree_list (NULL_TREE, TYPE_BINFO (t));
1966 for (i = 1; i < len; i++)
1968 TREE_VEC_ELT (baselink_vec, i)
1969 = get_baselinks (baselink_binfo, t, DECL_NAME (TREE_VEC_ELT (method_vec, i)));
1970 if (TREE_VEC_ELT (baselink_vec, i) != 0)
1974 CLASSTYPE_BASELINK_VEC (t) = baselink_vec;
1976 obstack_free (current_obstack, baselink_vec);
1979 /* Now add the methods to the TYPE_METHODS of T, arranged in a chain. */
1981 tree x, last_x = NULL_TREE;
1982 int limit = TREE_VEC_LENGTH (method_vec);
1984 for (i = 1; i < limit; i++)
1986 for (x = TREE_VEC_ELT (method_vec, i); x; x = DECL_CHAIN (x))
1988 if (last_x != NULL_TREE)
1989 TREE_CHAIN (last_x) = x;
1994 /* Put ctors and dtors at the front of the list. */
1995 x = TREE_VEC_ELT (method_vec, 0);
1998 while (DECL_CHAIN (x))
2000 /* Let's avoid being circular about this. */
2001 if (x == DECL_CHAIN (x))
2003 TREE_CHAIN (x) = DECL_CHAIN (x);
2006 if (TREE_VEC_LENGTH (method_vec) > 1)
2007 TREE_CHAIN (x) = TREE_VEC_ELT (method_vec, 1);
2009 TREE_CHAIN (x) = NULL_TREE;
2013 TYPE_METHODS (t) = method_vec;
2018 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2021 duplicate_tag_error (t)
2024 cp_error ("redefinition of `%#T'", t);
2025 cp_error_at ("previous definition here", t);
2027 /* Pretend we haven't defined this type. */
2029 /* All of the component_decl's were TREE_CHAINed together in the parser.
2030 finish_struct_methods walks these chains and assembles all methods with
2031 the same base name into DECL_CHAINs. Now we don't need the parser chains
2032 anymore, so we unravel them.
2035 * This used to be in finish_struct, but it turns out that the
2036 * TREE_CHAIN is used by dbxout_type_methods and perhaps some other things...
2038 if (CLASSTYPE_METHOD_VEC(t))
2040 tree tv = CLASSTYPE_METHOD_VEC(t);
2041 int i, len = TREE_VEC_LENGTH (tv);
2042 for (i = 0; i < len; i++)
2044 tree unchain = TREE_VEC_ELT (tv, i);
2045 while (unchain != NULL_TREE)
2047 TREE_CHAIN (unchain) = NULL_TREE;
2048 unchain = DECL_CHAIN(unchain);
2053 if (TYPE_LANG_SPECIFIC (t))
2055 tree as_list = CLASSTYPE_AS_LIST (t);
2056 tree binfo = TYPE_BINFO (t);
2057 tree binfo_as_list = CLASSTYPE_BINFO_AS_LIST (t);
2058 int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
2059 int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
2061 bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
2062 BINFO_BASETYPES(binfo) = NULL_TREE;
2064 CLASSTYPE_AS_LIST (t) = as_list;
2065 TYPE_BINFO (t) = binfo;
2066 CLASSTYPE_BINFO_AS_LIST (t) = binfo_as_list;
2067 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2068 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
2069 CLASSTYPE_VBASE_SIZE (t) = integer_zero_node;
2070 TYPE_REDEFINED (t) = 1;
2072 TYPE_SIZE (t) = NULL_TREE;
2073 TYPE_MODE (t) = VOIDmode;
2074 TYPE_FIELDS (t) = NULL_TREE;
2075 TYPE_METHODS (t) = NULL_TREE;
2076 TYPE_VFIELD (t) = NULL_TREE;
2077 TYPE_CONTEXT (t) = NULL_TREE;
2080 /* finish up all new vtables. */
2082 finish_vtbls (binfo, do_self, t)
2086 tree binfos = BINFO_BASETYPES (binfo);
2087 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2089 /* Should we use something besides CLASSTYPE_VFIELDS? */
2090 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2092 if (BINFO_NEW_VTABLE_MARKED (binfo))
2096 decl = BINFO_VTABLE (binfo);
2097 context = DECL_CONTEXT (decl);
2098 DECL_CONTEXT (decl) = 0;
2099 if (write_virtuals >= 0
2100 && DECL_INITIAL (decl) != BINFO_VIRTUALS (binfo))
2101 DECL_INITIAL (decl) = build_nt (CONSTRUCTOR, NULL_TREE,
2102 BINFO_VIRTUALS (binfo));
2103 finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0, 0);
2104 DECL_CONTEXT (decl) = context;
2106 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2109 for (i = 0; i < n_baselinks; i++)
2111 tree base_binfo = TREE_VEC_ELT (binfos, i);
2112 int is_not_base_vtable =
2113 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2114 if (TREE_VIA_VIRTUAL (base_binfo))
2116 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2118 finish_vtbls (base_binfo, (is_not_base_vtable || flag_rtti), t);
2122 /* True if we should override the given BASE_FNDECL with the given
2125 overrides (fndecl, base_fndecl)
2126 tree fndecl, base_fndecl;
2128 /* Destructors have special names. */
2129 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) &&
2130 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2132 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl)) ||
2133 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2135 if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
2137 tree rettype, base_rettype, types, base_types;
2139 retypes = TREE_TYPE (TREE_TYPE (fndecl));
2140 base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl));
2142 types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2143 base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
2144 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (base_types)))
2145 == TYPE_READONLY (TREE_TYPE (TREE_VALUE (types))))
2146 && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types), 3))
2153 get_class_offset_1 (parent, binfo, context, t, fndecl)
2154 tree parent, binfo, context, t, fndecl;
2156 tree binfos = BINFO_BASETYPES (binfo);
2157 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2158 tree rval = NULL_TREE;
2160 if (binfo == parent)
2161 return error_mark_node;
2163 for (i = 0; i < n_baselinks; i++)
2165 tree base_binfo = TREE_VEC_ELT (binfos, i);
2168 if (TREE_VIA_VIRTUAL (base_binfo))
2169 base_binfo = binfo_member (BINFO_TYPE (base_binfo),
2170 CLASSTYPE_VBASECLASSES (t));
2171 nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl);
2172 /* See if we have a new value */
2173 if (nrval && (nrval != error_mark_node || rval==0))
2175 /* Only compare if we have two offsets */
2176 if (rval && rval != error_mark_node
2177 && ! tree_int_cst_equal (nrval, rval))
2179 /* Only give error if the two offsets are different */
2180 error ("every virtual function must have a unique final overrider");
2181 cp_error (" found two (or more) `%T' class subobjects in `%T'", context, t);
2182 cp_error (" with virtual `%D' from virtual base class", fndecl);
2188 if (rval && BINFO_TYPE (binfo) == context)
2190 my_friendly_assert (rval == error_mark_node
2191 || tree_int_cst_equal (rval, BINFO_OFFSET (binfo)), 999);
2192 rval = BINFO_OFFSET (binfo);
2198 /* Get the offset to the CONTEXT subobject that is related to the
2201 get_class_offset (context, t, binfo, fndecl)
2202 tree context, t, binfo, fndecl;
2204 tree first_binfo = binfo;
2209 return integer_zero_node;
2211 if (BINFO_TYPE (binfo) == context)
2212 return BINFO_OFFSET (binfo);
2214 /* Check less derived binfos first. */
2215 while (BINFO_BASETYPES (binfo)
2216 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
2218 tree binfos = BINFO_BASETYPES (binfo);
2219 binfo = TREE_VEC_ELT (binfos, i);
2220 if (BINFO_TYPE (binfo) == context)
2221 return BINFO_OFFSET (binfo);
2224 /* Ok, not found in the less derived binfos, now check the more
2226 offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl);
2227 if (offset==0 || TREE_CODE (offset) != INTEGER_CST)
2228 my_friendly_abort (999); /* we have to find it. */
2233 modify_one_vtable (binfo, t, fndecl, pfn)
2234 tree binfo, t, fndecl, pfn;
2236 tree virtuals = BINFO_VIRTUALS (binfo);
2238 unsigned HOST_WIDE_INT n;
2240 /* update rtti entry */
2243 if (binfo == TYPE_BINFO (t))
2245 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2246 build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t))), t);
2250 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2251 prepare_fresh_vtable (binfo, t);
2253 old_rtti = get_vtable_entry_n (BINFO_VIRTUALS (binfo), 0);
2255 TREE_VALUE (old_rtti) = build_vtable_entry (
2256 DELTA_FROM_VTABLE_ENTRY (TREE_VALUE (old_rtti)),
2257 build_t_desc (t, 0));
2259 if (fndecl == NULL_TREE) return;
2261 /* Skip RTTI fake object. */
2264 virtuals = TREE_CHAIN (virtuals);
2267 tree current_fndecl = TREE_VALUE (virtuals);
2268 current_fndecl = FNADDR_FROM_VTABLE_ENTRY (current_fndecl);
2269 current_fndecl = TREE_OPERAND (current_fndecl, 0);
2270 if (current_fndecl && overrides (fndecl, current_fndecl))
2272 tree base_offset, offset;
2273 tree context = DECL_CLASS_CONTEXT (fndecl);
2274 tree vfield = CLASSTYPE_VFIELD (t);
2277 offset = get_class_offset (context, t, binfo, fndecl);
2279 /* Find the right offset for the this pointer based on the
2280 base class we just found. We have to take into
2281 consideration the virtual base class pointers that we
2282 stick in before the virtual function table pointer.
2284 Also, we want just the delta bewteen the most base class
2285 that we derived this vfield from and us. */
2286 base_offset = size_binop (PLUS_EXPR,
2287 get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)),
2288 BINFO_OFFSET (binfo));
2289 this_offset = size_binop (MINUS_EXPR, offset, base_offset);
2291 /* Make sure we can modify the derived association with immunity. */
2292 if (TREE_USED (binfo))
2293 my_friendly_assert (0, 999);
2295 if (binfo == TYPE_BINFO (t))
2297 /* In this case, it is *type*'s vtable we are modifying.
2298 We start with the approximation that it's vtable is that
2299 of the immediate base class. */
2300 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2301 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2305 /* This is our very own copy of `basetype' to play with.
2306 Later, we will fill in all the virtual functions
2307 that override the virtual functions in these base classes
2308 which are not defined by the current type. */
2309 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2310 prepare_fresh_vtable (binfo, t);
2314 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo)));
2316 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2317 build_vtable_entry (this_offset, pfn),
2321 virtuals = TREE_CHAIN (virtuals);
2325 /* These are the ones that are not through virtual base classes. */
2327 modify_all_direct_vtables (binfo, do_self, t, fndecl, pfn)
2328 tree binfo, t, fndecl, pfn;
2331 tree binfos = BINFO_BASETYPES (binfo);
2332 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2334 /* Should we use something besides CLASSTYPE_VFIELDS? */
2335 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2337 modify_one_vtable (binfo, t, fndecl, pfn);
2340 for (i = 0; i < n_baselinks; i++)
2342 tree base_binfo = TREE_VEC_ELT (binfos, i);
2343 int is_not_base_vtable =
2344 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2345 if (! TREE_VIA_VIRTUAL (base_binfo))
2346 modify_all_direct_vtables (base_binfo, (is_not_base_vtable || flag_rtti), t, fndecl, pfn);
2350 /* Fixup all the delta entries in this vtable that need updating.
2351 This happens when we have non-overridden virtual functions from a
2352 virtual base class, that are at a different offset, in the new
2353 hierarchy, because the layout of the virtual bases has changed. */
2355 fixup_vtable_deltas (binfo, t)
2358 tree virtuals = BINFO_VIRTUALS (binfo);
2359 unsigned HOST_WIDE_INT n;
2361 /* Skip RTTI fake object. */
2364 virtuals = TREE_CHAIN (virtuals);
2367 tree fndecl = TREE_VALUE (virtuals);
2368 tree pfn = FNADDR_FROM_VTABLE_ENTRY (fndecl);
2369 tree delta = DELTA_FROM_VTABLE_ENTRY (fndecl);
2370 fndecl = TREE_OPERAND (pfn, 0);
2373 tree base_offset, offset;
2374 tree context = DECL_CLASS_CONTEXT (fndecl);
2375 tree vfield = CLASSTYPE_VFIELD (t);
2378 offset = get_class_offset (context, t, binfo, fndecl);
2380 /* Find the right offset for the this pointer based on the
2381 base class we just found. We have to take into
2382 consideration the virtual base class pointers that we
2383 stick in before the virtual function table pointer.
2385 Also, we want just the delta bewteen the most base class
2386 that we derived this vfield from and us. */
2387 base_offset = size_binop (PLUS_EXPR,
2388 get_derived_offset (binfo, DECL_CONTEXT (fndecl)),
2389 BINFO_OFFSET (binfo));
2390 this_offset = size_binop (MINUS_EXPR, offset, base_offset);
2392 if (! tree_int_cst_equal (this_offset, delta))
2394 /* Make sure we can modify the derived association with immunity. */
2395 if (TREE_USED (binfo))
2396 my_friendly_assert (0, 999);
2398 if (binfo == TYPE_BINFO (t))
2400 /* In this case, it is *type*'s vtable we are modifying.
2401 We start with the approximation that it's vtable is that
2402 of the immediate base class. */
2403 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2404 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2408 /* This is our very own copy of `basetype' to play with.
2409 Later, we will fill in all the virtual functions
2410 that override the virtual functions in these base classes
2411 which are not defined by the current type. */
2412 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2413 prepare_fresh_vtable (binfo, t);
2416 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2417 build_vtable_entry (this_offset, pfn),
2422 virtuals = TREE_CHAIN (virtuals);
2426 /* These are the ones that are through virtual base classes. */
2428 modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl, pfn)
2429 tree binfo, t, fndecl, pfn;
2430 int do_self, via_virtual;
2432 tree binfos = BINFO_BASETYPES (binfo);
2433 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2435 /* Should we use something besides CLASSTYPE_VFIELDS? */
2436 if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2438 modify_one_vtable (binfo, t, fndecl, pfn);
2441 for (i = 0; i < n_baselinks; i++)
2443 tree base_binfo = TREE_VEC_ELT (binfos, i);
2444 int is_not_base_vtable =
2445 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2446 if (TREE_VIA_VIRTUAL (base_binfo))
2449 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2451 modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl, pfn);
2456 modify_all_vtables (t, fndecl, vfn)
2457 tree t, fndecl, vfn;
2459 /* Do these first, so that we will make use of any non-virtual class's
2460 vtable, over a virtual classes vtable. */
2461 modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl, vfn);
2462 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
2463 modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl, vfn);
2466 /* Here, we already know that they match in every respect.
2467 All we have to check is where they had their declarations. */
2469 strictly_overrides (fndecl1, fndecl2)
2470 tree fndecl1, fndecl2;
2472 int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2),
2473 DECL_CLASS_CONTEXT (fndecl1),
2475 if (distance == -2 || distance > 0)
2480 /* Merge overrides for one vtable.
2481 If we want to merge in same function, we are fine.
2483 if one has a DECL_CLASS_CONTEXT that is a parent of the
2484 other, than choose the more derived one
2486 potentially ill-formed (see 10.3 [class.virtual])
2487 we have to check later to see if there was an
2488 override in this class. If there was ok, if not
2489 then it is ill-formed. (mrs)
2491 We take special care to reuse a vtable, if we can. */
2493 override_one_vtable (binfo, old, t)
2496 tree virtuals = BINFO_VIRTUALS (binfo);
2497 tree old_virtuals = BINFO_VIRTUALS (old);
2498 enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
2500 /* If we have already committed to modifying it, then don't try and
2501 reuse another vtable. */
2502 if (BINFO_NEW_VTABLE_MARKED (binfo))
2505 /* Skip RTTI fake object. */
2506 virtuals = TREE_CHAIN (virtuals);
2507 old_virtuals = TREE_CHAIN (old_virtuals);
2511 tree fndecl = TREE_VALUE (virtuals);
2512 tree old_fndecl = TREE_VALUE (old_virtuals);
2513 fndecl = FNADDR_FROM_VTABLE_ENTRY (fndecl);
2514 old_fndecl = FNADDR_FROM_VTABLE_ENTRY (old_fndecl);
2515 fndecl = TREE_OPERAND (fndecl, 0);
2516 old_fndecl = TREE_OPERAND (old_fndecl, 0);
2517 /* First check to see if they are the same. */
2518 if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl))
2520 /* No need to do anything. */
2522 else if (strictly_overrides (fndecl, old_fndecl))
2524 if (choose == UNDECIDED)
2526 else if (choose == REUSE_OLD)
2529 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2531 prepare_fresh_vtable (binfo, t);
2532 override_one_vtable (binfo, old, t);
2537 else if (strictly_overrides (old_fndecl, fndecl))
2539 if (choose == UNDECIDED)
2541 else if (choose == REUSE_NEW)
2544 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2546 prepare_fresh_vtable (binfo, t);
2547 override_one_vtable (binfo, old, t);
2550 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2552 else if (choose == NEITHER)
2554 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2560 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2562 prepare_fresh_vtable (binfo, t);
2563 override_one_vtable (binfo, old, t);
2567 /* This MUST be overriden, or the class is ill-formed. */
2568 /* For now, we just make it abstract. */
2569 tree fndecl = TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals)), 0);
2572 fndecl = copy_node (fndecl);
2573 copy_lang_decl (fndecl);
2574 DECL_ABSTRACT_VIRTUAL_P (fndecl) = 1;
2575 /* Make sure we search for it later. */
2576 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t))
2577 CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node;
2579 vfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
2580 TREE_CONSTANT (vfn) = 1;
2582 /* We can use integer_zero_node, as we will will core dump
2583 if this is used anyway. */
2584 TREE_VALUE (virtuals) = build_vtable_entry (integer_zero_node, vfn);
2587 virtuals = TREE_CHAIN (virtuals);
2588 old_virtuals = TREE_CHAIN (old_virtuals);
2591 /* Let's reuse the old vtable. */
2592 if (choose == REUSE_OLD)
2594 BINFO_VTABLE (binfo) = BINFO_VTABLE (old);
2595 BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old);
2599 /* Merge in overrides for virtual bases.
2600 BINFO is the hierarchy we want to modify, and OLD has the potential
2603 merge_overrides (binfo, old, do_self, t)
2607 tree binfos = BINFO_BASETYPES (binfo);
2608 tree old_binfos = BINFO_BASETYPES (old);
2609 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2611 /* Should we use something besides CLASSTYPE_VFIELDS? */
2612 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2614 override_one_vtable (binfo, old, t);
2617 for (i = 0; i < n_baselinks; i++)
2619 tree base_binfo = TREE_VEC_ELT (binfos, i);
2620 tree old_base_binfo = TREE_VEC_ELT (old_binfos, i);
2621 int is_not_base_vtable =
2622 i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2623 if (! TREE_VIA_VIRTUAL (base_binfo))
2624 merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t);
2628 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
2629 (or C++ class declaration).
2631 For C++, we must handle the building of derived classes.
2632 Also, C++ allows static class members. The way that this is
2633 handled is to keep the field name where it is (as the DECL_NAME
2634 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
2635 of the field. layout_record and layout_union will know about this.
2637 More C++ hair: inline functions have text in their
2638 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
2639 meaningful tree structure. After the struct has been laid out, set
2640 things up so that this can happen.
2642 And still more: virtual functions. In the case of single inheritance,
2643 when a new virtual function is seen which redefines a virtual function
2644 from the base class, the new virtual function is placed into
2645 the virtual function table at exactly the same address that
2646 it had in the base class. When this is extended to multiple
2647 inheritance, the same thing happens, except that multiple virtual
2648 function tables must be maintained. The first virtual function
2649 table is treated in exactly the same way as in the case of single
2650 inheritance. Additional virtual function tables have different
2651 DELTAs, which tell how to adjust `this' to point to the right thing.
2653 LIST_OF_FIELDLISTS is just that. The elements of the list are
2654 TREE_LIST elements, whose TREE_PURPOSE field tells what access
2655 the list has, and the TREE_VALUE slot gives the actual fields.
2657 If flag_all_virtual == 1, then we lay all functions into
2658 the virtual function table, as though they were declared
2659 virtual. Constructors do not lay down in the virtual function table.
2661 If flag_all_virtual == 2, then we lay all functions into
2662 the virtual function table, such that virtual functions
2663 occupy a space by themselves, and then all functions
2664 of the class occupy a space by themselves. This is illustrated
2665 in the following diagram:
2667 class A; class B : A;
2669 Class A's vtbl: Class B's vtbl:
2670 --------------------------------------------------------------------
2671 | A's virtual functions| | B's virtual functions |
2672 | | | (may inherit some from A). |
2673 --------------------------------------------------------------------
2674 | All of A's functions | | All of A's functions |
2675 | (such as a->A::f). | | (such as b->A::f) |
2676 --------------------------------------------------------------------
2677 | B's new virtual functions |
2678 | (not defined in A.) |
2679 -------------------------------
2680 | All of B's functions |
2681 | (such as b->B::f) |
2682 -------------------------------
2684 this allows the program to make references to any function, virtual
2685 or otherwise in a type-consistent manner. */
2688 finish_struct (t, list_of_fieldlists, warn_anon)
2690 tree list_of_fieldlists;
2693 extern int interface_only, interface_unknown;
2696 int round_up_size = 1;
2698 enum tree_code code = TREE_CODE (t);
2699 register tree x, last_x, method_vec;
2700 int needs_virtual_dtor;
2701 tree name = TYPE_NAME (t), fields, fn_fields, *tail;
2702 tree *tail_user_methods = &CLASSTYPE_METHODS (t);
2703 enum access_type access;
2706 int max_has_virtual;
2707 tree pending_virtuals = NULL_TREE;
2708 tree abstract_virtuals = NULL_TREE;
2711 int cant_have_default_ctor;
2712 int cant_have_const_ctor;
2713 int cant_synth_copy_ctor;
2714 int cant_synth_asn_ref;
2715 int no_const_asn_ref;
2717 /* The index of the first base class which has virtual
2718 functions. Only applied to non-virtual baseclasses. */
2719 int first_vfn_base_index;
2722 int any_default_members = 0;
2723 int const_sans_init = 0;
2724 int ref_sans_init = 0;
2725 int nonprivate_method = 0;
2726 tree t_binfo = TYPE_BINFO (t);
2727 tree access_decls = NULL_TREE;
2729 if (TREE_CODE (name) == TYPE_DECL)
2731 #if 0 /* Maybe later. -jason */
2732 struct tinst_level *til = tinst_for_decl();
2736 DECL_SOURCE_FILE (name) = til->file;
2737 if (DECL_SOURCE_LINE (name))
2738 DECL_SOURCE_LINE (name) = til->line;
2745 DECL_SOURCE_FILE (name) = input_filename;
2746 /* For TYPE_DECL that are not typedefs (those marked with a line
2747 number of zero, we don't want to mark them as real typedefs.
2748 If this fails one needs to make sure real typedefs have a
2749 previous line number, even if it is wrong, that way the below
2750 will fill in the right line number. (mrs) */
2751 if (DECL_SOURCE_LINE (name))
2752 DECL_SOURCE_LINE (name) = lineno;
2753 CLASSTYPE_SOURCE_LINE (t) = lineno;
2755 name = DECL_NAME (name);
2758 if (warn_anon && code != UNION_TYPE && ANON_AGGRNAME_P (name))
2759 pedwarn ("anonymous class type not used to declare any objects");
2763 if (IS_AGGR_TYPE (t))
2764 cp_error ("redefinition of `%#T'", t);
2766 my_friendly_abort (172);
2771 /* Append the fields we need for constructing signature tables. */
2772 if (IS_SIGNATURE (t))
2773 append_signature_fields (list_of_fieldlists);
2775 GNU_xref_decl (current_function_decl, t);
2777 /* If this type was previously laid out as a forward reference,
2778 make sure we lay it out again. */
2780 TYPE_SIZE (t) = NULL_TREE;
2781 CLASSTYPE_GOT_SEMICOLON (t) = 0;
2784 /* This is in general too late to do this. I moved the main case up to
2785 left_curly, what else needs to move? */
2786 if (! IS_SIGNATURE (t))
2788 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
2789 my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t) == ! interface_unknown, 999);
2795 build_t_desc (t, 0);
2798 TYPE_BINFO (t) = NULL_TREE;
2800 old = suspend_momentary ();
2802 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
2803 Also process specified field sizes.
2804 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
2805 The specified size is found in the DECL_INITIAL.
2806 Store 0 there, except for ": 0" fields (so we can find them
2807 and delete them, below). */
2809 if (t_binfo && BINFO_BASETYPES (t_binfo))
2810 n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
2814 if (n_baseclasses > 0)
2816 struct base_info base_info;
2818 /* If using multiple inheritance, this may cause variants of our
2819 basetypes to be used (instead of their canonical forms). */
2820 fields = layout_basetypes (t, BINFO_BASETYPES (t_binfo));
2821 last_x = tree_last (fields);
2823 first_vfn_base_index = finish_base_struct (t, &base_info, t_binfo);
2824 /* Remember where we got our vfield from */
2825 CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index;
2826 has_virtual = base_info.has_virtual;
2827 max_has_virtual = base_info.max_has_virtual;
2828 CLASSTYPE_N_SUPERCLASSES (t) += base_info.n_ancestors;
2829 vfield = base_info.vfield;
2830 vfields = base_info.vfields;
2831 cant_have_default_ctor = base_info.cant_have_default_ctor;
2832 cant_have_const_ctor = base_info.cant_have_const_ctor;
2833 cant_synth_copy_ctor = base_info.cant_synth_copy_ctor;
2834 cant_synth_asn_ref = base_info.cant_synth_asn_ref;
2835 no_const_asn_ref = base_info.no_const_asn_ref;
2836 needs_virtual_dtor = base_info.needs_virtual_dtor;
2837 n_baseclasses = TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo));
2841 first_vfn_base_index = -1;
2843 max_has_virtual = has_virtual;
2845 vfields = NULL_TREE;
2848 cant_have_default_ctor = 0;
2849 cant_have_const_ctor = 0;
2850 cant_synth_copy_ctor = 0;
2851 cant_synth_asn_ref = 0;
2852 no_const_asn_ref = 0;
2853 needs_virtual_dtor = 0;
2857 /* Both of these should be done before now. */
2858 if (write_virtuals == 3 && CLASSTYPE_INTERFACE_KNOWN (t)
2859 && ! IS_SIGNATURE (t))
2861 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t) == interface_only, 999);
2862 my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t) == ! interface_only, 999);
2866 /* The three of these are approximations which may later be
2867 modified. Needed at this point to make add_virtual_function
2868 and modify_vtable_entries work. */
2869 TREE_CHAIN (t_binfo) = TYPE_BINFO (t);
2870 TYPE_BINFO (t) = t_binfo;
2871 CLASSTYPE_VFIELDS (t) = vfields;
2872 CLASSTYPE_VFIELD (t) = vfield;
2875 if (last_x && list_of_fieldlists)
2876 TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
2878 if (IS_SIGNATURE (t))
2880 else if (flag_all_virtual == 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t))
2885 /* For signatures, we made all methods `public' in the parser and
2886 reported an error if a access specifier was used. */
2887 if (CLASSTYPE_DECLARED_CLASS (t) == 0)
2889 nonprivate_method = 1;
2890 if (list_of_fieldlists
2891 && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default)
2892 TREE_PURPOSE (list_of_fieldlists) = (tree)access_public;
2894 else if (list_of_fieldlists
2895 && TREE_PURPOSE (list_of_fieldlists) == (tree)access_default)
2896 TREE_PURPOSE (list_of_fieldlists) = (tree)access_private;
2898 while (list_of_fieldlists)
2900 access = (enum access_type)TREE_PURPOSE (list_of_fieldlists);
2902 for (x = TREE_VALUE (list_of_fieldlists); x; x = TREE_CHAIN (x))
2904 TREE_PRIVATE (x) = access == access_private;
2905 TREE_PROTECTED (x) = access == access_protected;
2906 GNU_xref_member (current_class_name, x);
2908 if (TREE_CODE (x) == TYPE_DECL)
2910 /* Make sure we set this up. In find_scoped_type, it explicitly
2911 looks for a TYPE_DECL in the TYPE_FIELDS list. If we don't
2912 do this here, we'll miss including this TYPE_DECL in the
2920 /* Check for inconsistent use of this name in the class body.
2921 Enums, types and static vars have already been checked. */
2922 if (TREE_CODE (x) != CONST_DECL && TREE_CODE (x) != VAR_DECL)
2924 tree name = DECL_NAME (x);
2927 /* Don't get confused by access decls. */
2928 if (name && TREE_CODE (name) == IDENTIFIER_NODE)
2929 icv = IDENTIFIER_CLASS_VALUE (name);
2934 /* Don't complain about constructors. */
2935 && name != constructor_name (current_class_type)
2936 /* Or inherited names. */
2937 && id_in_current_class (name)
2938 /* Or shadowed tags. */
2939 && !(TREE_CODE (icv) == TYPE_DECL
2940 && DECL_CONTEXT (icv) == t))
2942 cp_error_at ("declaration of identifier `%D' as `%+#D'",
2944 cp_error_at ("conflicts with other use in class as `%#D'",
2949 if (TREE_CODE (x) == FUNCTION_DECL)
2951 nonprivate_method |= ! TREE_PRIVATE (x);
2953 /* If this was an evil function, don't keep it in class. */
2954 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
2958 TREE_CHAIN (last_x) = TREE_CHAIN (x);
2959 /* Link x onto end of fn_fields and CLASSTYPE_METHODS. */
2961 tail = &TREE_CHAIN (x);
2962 *tail_user_methods = x;
2963 tail_user_methods = &DECL_NEXT_METHOD (x);
2965 DECL_CLASS_CONTEXT (x) = t;
2967 /* Do both of these, even though they're in the same union;
2968 if the insn `r' member and the size `i' member are
2969 different sizes, as on the alpha, the larger of the two
2970 will end up with garbage in it. */
2971 DECL_SAVED_INSNS (x) = NULL_RTX;
2972 DECL_FIELD_SIZE (x) = 0;
2974 /* The name of the field is the original field name
2975 Save this in auxiliary field for later overloading. */
2977 || (all_virtual == 1 && ! DECL_CONSTRUCTOR_P (x)))
2979 pending_virtuals = add_virtual_function (pending_virtuals,
2980 &has_virtual, x, t);
2981 if (DECL_ABSTRACT_VIRTUAL_P (x))
2982 abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals);
2987 /* Handle access declarations. */
2988 if (DECL_NAME (x) && TREE_CODE (DECL_NAME (x)) == SCOPE_REF)
2990 tree fdecl = TREE_OPERAND (DECL_NAME (x), 1);
2993 TREE_CHAIN (last_x) = TREE_CHAIN (x);
2994 access_decls = tree_cons ((tree) access, fdecl, access_decls);
2998 /* If we've gotten this far, it's a data member, possibly static,
2999 or an enumerator. */
3001 DECL_FIELD_CONTEXT (x) = t;
3003 /* ``A local class cannot have static data members.'' ARM 9.4 */
3004 if (current_function_decl && TREE_STATIC (x))
3005 cp_error_at ("field `%D' in local class cannot be static", x);
3007 /* Perform error checking that did not get done in
3009 if (TREE_CODE (TREE_TYPE (x)) == FUNCTION_TYPE)
3011 cp_error_at ("field `%D' invalidly declared function type",
3013 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3015 else if (TREE_CODE (TREE_TYPE (x)) == METHOD_TYPE)
3017 cp_error_at ("field `%D' invalidly declared method type", x);
3018 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3020 else if (TREE_CODE (TREE_TYPE (x)) == OFFSET_TYPE)
3022 cp_error_at ("field `%D' invalidly declared offset type", x);
3023 TREE_TYPE (x) = build_pointer_type (TREE_TYPE (x));
3026 if (DECL_NAME (x) == constructor_name (t))
3027 cant_have_default_ctor = cant_synth_copy_ctor = 1;
3029 if (TREE_TYPE (x) == error_mark_node)
3036 DECL_SAVED_INSNS (x) = NULL_RTX;
3037 DECL_FIELD_SIZE (x) = 0;
3039 /* When this goes into scope, it will be a non-local reference. */
3040 DECL_NONLOCAL (x) = 1;
3042 if (TREE_CODE (x) == CONST_DECL)
3045 if (TREE_CODE (x) == VAR_DECL)
3047 if (TREE_CODE (t) == UNION_TYPE)
3048 /* Unions cannot have static members. */
3049 cp_error_at ("field `%D' declared static in union", x);
3054 /* Now it can only be a FIELD_DECL. */
3056 /* If this is of reference type, check if it needs an init.
3057 Also do a little ANSI jig if necessary. */
3058 if (TREE_CODE (TREE_TYPE (x)) == REFERENCE_TYPE)
3060 if (DECL_INITIAL (x) == NULL_TREE)
3063 /* ARM $12.6.2: [A member initializer list] (or, for an
3064 aggregate, initialization by a brace-enclosed list) is the
3065 only way to initialize nonstatic const and reference
3067 cant_synth_asn_ref = 1;
3068 cant_have_default_ctor = 1;
3069 TYPE_HAS_COMPLEX_INIT_REF (t) = 1;
3071 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3074 cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
3076 cp_warning_at ("non-static reference in class without a constructor", x);
3080 /* If any field is const, the structure type is pseudo-const. */
3081 if (TREE_READONLY (x))
3083 C_TYPE_FIELDS_READONLY (t) = 1;
3084 if (DECL_INITIAL (x) == NULL_TREE)
3085 const_sans_init = 1;
3087 /* ARM $12.6.2: [A member initializer list] (or, for an
3088 aggregate, initialization by a brace-enclosed list) is the
3089 only way to initialize nonstatic const and reference
3091 cant_synth_asn_ref = 1;
3092 cant_have_default_ctor = 1;
3093 TYPE_HAS_COMPLEX_INIT_REF (t) = 1;
3095 if (! TYPE_HAS_CONSTRUCTOR (t) && !IS_SIGNATURE (t)
3099 cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
3101 cp_warning_at ("non-static const member in class without a constructor", x);
3106 /* A field that is pseudo-const makes the structure
3108 tree t1 = TREE_TYPE (x);
3109 while (TREE_CODE (t1) == ARRAY_TYPE)
3110 t1 = TREE_TYPE (t1);
3111 if (IS_AGGR_TYPE (t1))
3113 if (C_TYPE_FIELDS_READONLY (t1))
3114 C_TYPE_FIELDS_READONLY (t) = 1;
3115 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1))
3116 const_sans_init = 1;
3120 /* We set DECL_BIT_FIELD tentatively in grokbitfield.
3121 If the type and width are valid, we'll keep it set.
3122 Otherwise, the flag is cleared. */
3123 if (DECL_BIT_FIELD (x))
3125 DECL_BIT_FIELD (x) = 0;
3126 /* Invalid bit-field size done by grokfield. */
3127 /* Detect invalid bit-field type. */
3128 if (DECL_INITIAL (x)
3129 && ! INTEGRAL_TYPE_P (TREE_TYPE (x)))
3131 cp_error_at ("bit-field `%#D' with non-integral type", x);
3132 DECL_INITIAL (x) = NULL;
3135 /* Detect and ignore out of range field width. */
3136 if (DECL_INITIAL (x))
3138 register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
3142 DECL_INITIAL (x) = NULL;
3143 cp_error_at ("negative width in bit-field `%D'", x);
3145 else if (width == 0 && DECL_NAME (x) != 0)
3147 DECL_INITIAL (x) = NULL;
3148 cp_error_at ("zero width for bit-field `%D'", x);
3151 > TYPE_PRECISION (long_long_unsigned_type_node))
3153 /* The backend will dump if you try to use something
3154 too big; avoid that. */
3155 DECL_INITIAL (x) = NULL;
3156 sorry ("bit-fields larger than %d bits",
3157 TYPE_PRECISION (long_long_unsigned_type_node));
3158 cp_error_at (" in declaration of `%D'", x);
3160 else if (width > TYPE_PRECISION (TREE_TYPE (x))
3161 && TREE_CODE (TREE_TYPE (x)) != ENUMERAL_TYPE)
3163 cp_warning_at ("width of `%D' exceeds its type", x);
3165 else if (TREE_CODE (TREE_TYPE (x)) == ENUMERAL_TYPE
3166 && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x)),
3167 TREE_UNSIGNED (TREE_TYPE (x))) > width)
3168 || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x)),
3169 TREE_UNSIGNED (TREE_TYPE (x))) > width)))
3171 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3176 /* Process valid field width. */
3177 if (DECL_INITIAL (x))
3179 register int width = TREE_INT_CST_LOW (DECL_INITIAL (x));
3183 #ifdef EMPTY_FIELD_BOUNDARY
3184 /* field size 0 => mark following field as "aligned" */
3186 DECL_ALIGN (TREE_CHAIN (x))
3187 = MAX (DECL_ALIGN (TREE_CHAIN (x)), EMPTY_FIELD_BOUNDARY);
3188 /* field of size 0 at the end => round up the size. */
3190 round_up_size = EMPTY_FIELD_BOUNDARY;
3192 #ifdef PCC_BITFIELD_TYPE_MATTERS
3193 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
3194 TYPE_ALIGN (TREE_TYPE (x)));
3199 DECL_INITIAL (x) = NULL_TREE;
3200 DECL_FIELD_SIZE (x) = width;
3201 DECL_BIT_FIELD (x) = 1;
3202 /* Traditionally a bit field is unsigned
3203 even if declared signed. */
3204 if (flag_traditional
3205 && TREE_CODE (TREE_TYPE (x)) == INTEGER_TYPE)
3206 TREE_TYPE (x) = unsigned_type_node;
3210 /* Non-bit-fields are aligned for their type. */
3211 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (TREE_TYPE (x)));
3215 tree type = TREE_TYPE (x);
3217 if (TREE_CODE (type) == ARRAY_TYPE)
3218 type = TREE_TYPE (type);
3220 if (TYPE_LANG_SPECIFIC (type) && ! ANON_UNION_P (x)
3221 && ! TYPE_PTRMEMFUNC_P (type))
3223 /* Never let anything with uninheritable virtuals
3224 make it through without complaint. */
3225 if (CLASSTYPE_ABSTRACT_VIRTUALS (type))
3226 abstract_virtuals_error (x, type);
3228 /* Don't let signatures make it through either. */
3229 if (IS_SIGNATURE (type))
3230 signature_error (x, type);
3232 if (code == UNION_TYPE)
3235 if (TYPE_NEEDS_CONSTRUCTING (type))
3236 fie = "constructor";
3237 else if (TYPE_NEEDS_DESTRUCTOR (type))
3239 else if (TYPE_HAS_REAL_ASSIGNMENT (type))
3240 fie = "assignment operator";
3242 cp_error_at ("member `%#D' with %s not allowed in union", x,
3247 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
3248 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type);
3249 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
3250 TYPE_HAS_COMPLEX_INIT_REF (t)
3251 |= (TYPE_HAS_COMPLEX_INIT_REF (type)
3252 || TYPE_NEEDS_CONSTRUCTING (type));
3255 if (! TYPE_HAS_INIT_REF (type)
3256 || (TYPE_HAS_NONPUBLIC_CTOR (type)
3257 && ! is_friend (t, type)))
3258 cant_synth_copy_ctor = 1;
3259 else if (!TYPE_HAS_CONST_INIT_REF (type))
3260 cant_have_const_ctor = 1;
3262 if (! TYPE_HAS_ASSIGN_REF (type)
3263 || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (type)
3264 && ! is_friend (t, type)))
3265 cant_synth_asn_ref = 1;
3266 else if (!TYPE_HAS_CONST_ASSIGN_REF (type))
3267 no_const_asn_ref = 1;
3269 if (TYPE_HAS_CONSTRUCTOR (type)
3270 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
3272 cant_have_default_ctor = 1;
3273 if (! TYPE_HAS_CONSTRUCTOR (t))
3276 cp_pedwarn_at ("member `%#D' with only non-default constructor", x);
3278 cp_pedwarn_at ("member with only non-default constructor", x);
3279 cp_pedwarn_at ("in class without a constructor",
3284 if (DECL_INITIAL (x) != NULL_TREE)
3286 /* `build_class_init_list' does not recognize
3288 if (code == UNION_TYPE && any_default_members != 0)
3289 cp_error_at ("multiple fields in union `%T' initialized");
3290 any_default_members = 1;
3294 list_of_fieldlists = TREE_CHAIN (list_of_fieldlists);
3295 /* link the tail while we have it! */
3298 TREE_CHAIN (last_x) = NULL_TREE;
3300 if (list_of_fieldlists
3301 && TREE_VALUE (list_of_fieldlists)
3302 && TREE_CODE (TREE_VALUE (list_of_fieldlists)) != FUNCTION_DECL)
3303 TREE_CHAIN (last_x) = TREE_VALUE (list_of_fieldlists);
3307 /* If this type has any constant members which did not come
3308 with their own initialization, mark that fact here. It is
3309 not an error here, since such types can be saved either by their
3310 constructors, or by fortuitous initialization. */
3311 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init;
3312 CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init;
3313 CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals;
3315 /* Synthesize any needed methods. Note that methods will be synthesized
3316 for anonymous unions; grok_x_components undoes that. */
3318 if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t)
3319 && !IS_SIGNATURE (t))
3321 /* Here we must cons up a destructor on the fly. */
3322 tree dtor = cons_up_default_function (t, name, needs_virtual_dtor != 0);
3324 /* If we couldn't make it work, then pretend we didn't need it. */
3325 if (dtor == void_type_node)
3326 TYPE_NEEDS_DESTRUCTOR (t) = 0;
3329 /* Link dtor onto end of fn_fields. */
3331 tail = &TREE_CHAIN (dtor);
3333 if (DECL_VINDEX (dtor) == NULL_TREE
3334 && (needs_virtual_dtor
3335 || pending_virtuals != NULL_TREE
3336 || pending_hard_virtuals != NULL_TREE))
3337 DECL_VINDEX (dtor) = error_mark_node;
3338 if (DECL_VINDEX (dtor))
3339 pending_virtuals = add_virtual_function (pending_virtuals,
3340 &has_virtual, dtor, t);
3341 nonprivate_method = 1;
3346 *tail_user_methods = NULL_TREE;
3348 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
3349 if (flag_rtti && (max_has_virtual > 0 || needs_virtual_dtor) &&
3354 nonprivate_method = 1;
3356 TYPE_HAS_COMPLEX_INIT_REF (t)
3357 |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3358 || has_virtual || any_default_members || first_vfn_base_index >= 0);
3359 TYPE_NEEDS_CONSTRUCTING (t)
3360 |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3361 || has_virtual || any_default_members || first_vfn_base_index >= 0);
3363 /* ARM $12.1: A default constructor will be generated for a class X
3364 only if no constructor has been declared for class X. So we
3365 check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate
3366 one if they declared a constructor in this class. */
3367 if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor
3368 && ! IS_SIGNATURE (t))
3370 tree default_fn = cons_up_default_function (t, name, 2);
3371 TREE_CHAIN (default_fn) = fn_fields;
3372 fn_fields = default_fn;
3375 /* Create default copy constructor, if needed. */
3376 if (! TYPE_HAS_INIT_REF (t) && ! cant_synth_copy_ctor
3377 && ! IS_SIGNATURE (t))
3379 /* ARM 12.18: You get either X(X&) or X(const X&), but
3381 tree default_fn = cons_up_default_function (t, name,
3382 3 + cant_have_const_ctor);
3383 TREE_CHAIN (default_fn) = fn_fields;
3384 fn_fields = default_fn;
3387 TYPE_HAS_REAL_ASSIGNMENT (t) |= TYPE_HAS_ASSIGNMENT (t);
3388 TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
3389 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
3390 |= (TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3391 || has_virtual || first_vfn_base_index >= 0);
3393 if (! TYPE_HAS_ASSIGN_REF (t) && ! cant_synth_asn_ref
3394 && ! IS_SIGNATURE (t))
3396 tree default_fn = cons_up_default_function (t, name,
3397 5 + no_const_asn_ref);
3398 TREE_CHAIN (default_fn) = fn_fields;
3399 fn_fields = default_fn;
3404 method_vec = finish_struct_methods (t, fn_fields, nonprivate_method);
3406 if (TYPE_HAS_CONSTRUCTOR (t)
3407 && CLASSTYPE_FRIEND_CLASSES (t) == NULL_TREE
3408 && DECL_FRIENDLIST (TYPE_NAME (t)) == NULL_TREE)
3410 int nonprivate_ctor = 0;
3413 for (ctor = TREE_VEC_ELT (method_vec, 0);
3415 ctor = DECL_CHAIN (ctor))
3416 if (! TREE_PRIVATE (ctor))
3418 nonprivate_ctor = 1;
3422 if (nonprivate_ctor == 0 && warn_ctor_dtor_privacy)
3423 cp_warning ("`%#T' only defines private constructors and has no friends",
3431 /* Just in case these got accidentally
3432 filled in by syntax errors. */
3433 TYPE_HAS_CONSTRUCTOR (t) = 0;
3434 TYPE_HAS_DESTRUCTOR (t) = 0;
3438 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3440 for (access_decls = nreverse (access_decls); access_decls;
3441 access_decls = TREE_CHAIN (access_decls))
3443 tree fdecl = TREE_VALUE (access_decls);
3444 tree flist = NULL_TREE;
3446 enum access_type access = (enum access_type)TREE_PURPOSE(access_decls);
3447 int i = TREE_VEC_ELT (method_vec, 0) ? 0 : 1;
3450 if (TREE_CODE (fdecl) == TREE_LIST)
3453 fdecl = TREE_VALUE (flist);
3456 name = DECL_NAME (fdecl);
3458 for (; i < n_methods; i++)
3459 if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name)
3461 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
3462 cp_error_at (" because of local method `%#D' with same name",
3463 TREE_VEC_ELT (method_vec, i));
3471 for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp))
3472 if (DECL_NAME (tmp) == name)
3474 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
3475 cp_error_at (" because of local field `%#D' with same name", tmp);
3483 /* Make type T see field decl FDECL with access ACCESS.*/
3486 fdecl = TREE_VALUE (flist);
3489 if (alter_access (t, fdecl, access) == 0)
3491 fdecl = DECL_CHAIN (fdecl);
3495 alter_access (t, fdecl, access);
3500 if (vfield == NULL_TREE && has_virtual)
3502 /* We build this decl with ptr_type_node, and
3503 change the type when we know what it should be. */
3504 vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t),
3506 /* If you change any of the below, take a look at all the
3507 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3509 DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
3510 CLASSTYPE_VFIELD (t) = vfield;
3511 DECL_VIRTUAL_P (vfield) = 1;
3512 DECL_FIELD_CONTEXT (vfield) = t;
3513 DECL_CLASS_CONTEXT (vfield) = t;
3514 DECL_FCONTEXT (vfield) = t;
3515 DECL_SAVED_INSNS (vfield) = NULL_RTX;
3516 DECL_FIELD_SIZE (vfield) = 0;
3517 DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node);
3518 if (CLASSTYPE_RTTI (t))
3520 /* vfield is always first entry in structure. */
3521 TREE_CHAIN (vfield) = fields;
3526 my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175);
3527 TREE_CHAIN (last_x) = vfield;
3532 vfields = chainon (vfields, CLASSTYPE_AS_LIST (t));
3535 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3536 And they have already done their work.
3538 C++: maybe we will support default field initialization some day... */
3540 /* Delete all zero-width bit-fields from the front of the fieldlist */
3541 while (fields && DECL_BIT_FIELD (fields)
3542 && DECL_INITIAL (fields))
3543 fields = TREE_CHAIN (fields);
3544 /* Delete all such fields from the rest of the fields. */
3545 for (x = fields; x;)
3547 if (TREE_CHAIN (x) && DECL_BIT_FIELD (TREE_CHAIN (x))
3548 && DECL_INITIAL (TREE_CHAIN (x)))
3549 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
3553 /* Delete all duplicate fields from the fields */
3554 delete_duplicate_fields (fields);
3556 /* Catch function/field name conflict. We don't need to do this for a
3557 signature, since it can only contain the fields constructed in
3558 append_signature_fields. */
3559 if (! IS_SIGNATURE (t))
3561 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3562 for (x = fields; x; x = TREE_CHAIN (x))
3564 tree name = DECL_NAME (x);
3565 int i = /*TREE_VEC_ELT (method_vec, 0) ? 0 : */ 1;
3566 for (; i < n_methods; ++i)
3567 if (DECL_NAME (TREE_VEC_ELT (method_vec, i)) == name)
3569 cp_error_at ("data member `%#D' conflicts with", x);
3570 cp_error_at ("function member `%#D'",
3571 TREE_VEC_ELT (method_vec, i));
3577 /* Now we have the final fieldlist for the data fields. Record it,
3578 then lay out the structure or union (including the fields). */
3580 TYPE_FIELDS (t) = fields;
3582 /* If there's a :0 field at the end, round the size to the
3583 EMPTY_FIELD_BOUNDARY. */
3584 TYPE_ALIGN (t) = round_up_size;
3586 /* Pass layout information about base classes to layout_type, if any. */
3589 tree pseudo_basetype = TREE_TYPE (base_layout_decl);
3591 TREE_CHAIN (base_layout_decl) = TYPE_FIELDS (t);
3592 TYPE_FIELDS (t) = base_layout_decl;
3594 TYPE_SIZE (pseudo_basetype) = CLASSTYPE_SIZE (t);
3595 TYPE_MODE (pseudo_basetype) = TYPE_MODE (t);
3596 TYPE_ALIGN (pseudo_basetype) = CLASSTYPE_ALIGN (t);
3597 DECL_ALIGN (base_layout_decl) = TYPE_ALIGN (pseudo_basetype);
3598 /* Don't re-use old size. */
3599 DECL_SIZE (base_layout_decl) = NULL_TREE;
3606 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
3608 if (TREE_STATIC (field))
3610 if (TREE_CODE (field) != FIELD_DECL)
3613 /* If this field is an anonymous union,
3614 give each union-member the same position as the union has.
3616 ??? This is a real kludge because it makes the structure
3617 of the types look strange. This feature is only used by
3618 C++, which should have build_component_ref build two
3619 COMPONENT_REF operations, one for the union and one for
3620 the inner field. We set the offset of this field to zero
3621 so that either the old or the correct method will work.
3622 Setting DECL_FIELD_CONTEXT is wrong unless the inner fields are
3623 moved into the type of this field, but nothing seems to break
3626 if (DECL_NAME (field) == NULL_TREE
3627 && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)
3629 tree uelt = TYPE_FIELDS (TREE_TYPE (field));
3630 for (; uelt; uelt = TREE_CHAIN (uelt))
3632 if (TREE_CODE (uelt) != FIELD_DECL)
3635 DECL_FIELD_CONTEXT (uelt) = DECL_FIELD_CONTEXT (field);
3636 DECL_FIELD_BITPOS (uelt) = DECL_FIELD_BITPOS (field);
3639 DECL_FIELD_BITPOS (field) = integer_zero_node;
3645 TYPE_FIELDS (t) = TREE_CHAIN (TYPE_FIELDS (t));
3647 /* C++: do not let empty structures exist. */
3648 if (integer_zerop (TYPE_SIZE (t)))
3649 TYPE_SIZE (t) = TYPE_SIZE (char_type_node);
3651 /* Set the TYPE_DECL for this type to contain the right
3652 value for DECL_OFFSET, so that we can use it as part
3653 of a COMPONENT_REF for multiple inheritance. */
3655 if (TREE_CODE (TYPE_NAME (t)) == TYPE_DECL)
3656 layout_decl (TYPE_NAME (t), 0);
3658 /* Now fix up any virtual base class types that we left lying
3659 around. We must get these done before we try to lay out the
3660 virtual function table. */
3661 doing_hard_virtuals = 1;
3662 pending_hard_virtuals = nreverse (pending_hard_virtuals);
3664 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
3668 max_has_virtual = layout_vbasetypes (t, max_has_virtual);
3669 vbases = CLASSTYPE_VBASECLASSES (t);
3670 CLASSTYPE_N_VBASECLASSES (t) = list_length (vbases);
3672 /* The rtti code should do this. (mrs) */
3676 /* Update rtti info with offsets for virtual baseclasses. */
3677 if (flag_rtti && ! BINFO_NEW_VTABLE_MARKED (vbases))
3678 prepare_fresh_vtable (vbases, t);
3679 vbases = TREE_CHAIN (vbases);
3684 /* Now fixup overrides of all functions in vtables from all
3685 direct or indirect virtual base classes. */
3686 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
3687 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3689 for (i = 0; i < n_baseclasses; i++)
3691 tree base_binfo = TREE_VEC_ELT (binfos, i);
3692 tree basetype = BINFO_TYPE (base_binfo);
3695 vbases = CLASSTYPE_VBASECLASSES (basetype);
3698 merge_overrides (binfo_member (BINFO_TYPE (vbases),
3699 CLASSTYPE_VBASECLASSES (t)),
3701 vbases = TREE_CHAIN (vbases);
3706 /* Now fixup any virtual function entries from virtual bases
3707 that have different deltas. */
3708 vbases = CLASSTYPE_VBASECLASSES (t);
3711 /* We might be able to shorten the ammount of work we do by
3712 only doing this for vtables that come from virtual bases
3713 that have differing offsets, but don't want to miss any
3715 fixup_vtable_deltas (vbases, t);
3716 vbases = TREE_CHAIN (vbases);
3720 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
3721 might need to know it for setting up the offsets in the vtable
3722 (or in thunks) below. */
3723 if (vfield != NULL_TREE
3724 && DECL_FIELD_CONTEXT (vfield) != t)
3726 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
3727 tree offset = BINFO_OFFSET (binfo);
3729 vfield = copy_node (vfield);
3730 copy_lang_decl (vfield);
3732 if (! integer_zerop (offset))
3733 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
3734 DECL_FIELD_CONTEXT (vfield) = t;
3735 DECL_CLASS_CONTEXT (vfield) = t;
3736 DECL_FIELD_BITPOS (vfield)
3737 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
3738 CLASSTYPE_VFIELD (t) = vfield;
3742 cp_warning ("Doing hard virtuals for %T...", t);
3745 if (has_virtual > max_has_virtual)
3746 max_has_virtual = has_virtual;
3747 if (max_has_virtual > 0)
3748 TYPE_VIRTUAL_P (t) = 1;
3750 if (flag_rtti && TYPE_VIRTUAL_P (t) && !pending_hard_virtuals)
3751 modify_all_vtables (t, NULL_TREE, NULL_TREE);
3753 while (pending_hard_virtuals)
3755 modify_all_vtables (t,
3756 TREE_PURPOSE (pending_hard_virtuals),
3757 TREE_VALUE (pending_hard_virtuals));
3758 pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals);
3760 doing_hard_virtuals = 0;
3762 /* Under our model of GC, every C++ class gets its own virtual
3763 function table, at least virtually. */
3764 if (pending_virtuals || (flag_rtti && TYPE_VIRTUAL_P (t)))
3766 pending_virtuals = nreverse (pending_virtuals);
3767 /* We must enter these virtuals into the table. */
3768 if (first_vfn_base_index < 0)
3771 pending_virtuals = tree_cons (NULL_TREE,
3772 build_vtable_entry (integer_zero_node, build_t_desc (t, 0)),
3775 pending_virtuals = tree_cons (NULL_TREE,
3776 build_vtable_entry (integer_zero_node, integer_zero_node),
3780 /* The size is no longer used. */
3781 /* now we put the size of the vtable as first entry */
3782 pending_virtuals = tree_cons (NULL_TREE, the_null_vtable_entry,
3785 build_vtable (NULL_TREE, t);
3789 /* Here we know enough to change the type of our virtual
3790 function table, but we will wait until later this function. */
3792 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
3793 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t);
3795 /* Update the rtti pointer for this class. */
3797 TREE_VALUE (TYPE_BINFO_VIRTUALS (t))
3798 = build_vtable_entry (integer_zero_node, build_t_desc (t, 0));
3801 /* If this type has basetypes with constructors, then those
3802 constructors might clobber the virtual function table. But
3803 they don't if the derived class shares the exact vtable of the base
3806 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
3808 else if (first_vfn_base_index >= 0)
3810 tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index);
3811 /* This class contributes nothing new to the virtual function
3812 table. However, it may have declared functions which
3813 went into the virtual function table "inherited" from the
3814 base class. If so, we grab a copy of those updated functions,
3815 and pretend they are ours. */
3817 /* See if we should steal the virtual info from base class. */
3818 if (TYPE_BINFO_VTABLE (t) == NULL_TREE)
3819 TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo);
3820 if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE)
3821 TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo);
3822 if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo))
3823 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
3826 if (max_has_virtual || first_vfn_base_index >= 0)
3828 CLASSTYPE_VSIZE (t) = has_virtual;
3829 if (first_vfn_base_index >= 0)
3831 if (pending_virtuals)
3832 TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t),
3835 else if (has_virtual)
3837 TYPE_BINFO_VIRTUALS (t) = pending_virtuals;
3838 if (write_virtuals >= 0)
3839 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1;
3843 /* Now lay out the virtual function table. */
3848 if (TREE_TYPE (vfield) == ptr_type_node)
3850 /* We must create a pointer to this table because
3851 the one inherited from base class does not exist.
3852 We will fill in the type when we know what it
3853 should really be. Use `size_int' so values are memoized
3855 itype = build_index_type (size_int (has_virtual));
3856 atype = build_array_type (vtable_entry_type, itype);
3857 layout_type (atype);
3858 TREE_TYPE (vfield) = build_pointer_type (atype);
3862 atype = TREE_TYPE (TREE_TYPE (vfield));
3864 if (has_virtual != TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))))
3866 /* We must extend (or create) the boundaries on this array,
3867 because we picked up virtual functions from multiple
3869 itype = build_index_type (size_int (has_virtual));
3870 atype = build_array_type (vtable_entry_type, itype);
3871 layout_type (atype);
3872 vfield = copy_node (vfield);
3873 TREE_TYPE (vfield) = build_pointer_type (atype);
3877 CLASSTYPE_VFIELD (t) = vfield;
3878 if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
3880 TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype;
3881 DECL_SIZE (TYPE_BINFO_VTABLE (t)) = 0;
3882 layout_decl (TYPE_BINFO_VTABLE (t), 0);
3883 /* At one time the vtable info was grabbed 2 words at a time. This
3884 fails on sparc unless you have 8-byte alignment. (tiemann) */
3885 DECL_ALIGN (TYPE_BINFO_VTABLE (t))
3886 = MAX (TYPE_ALIGN (double_type_node),
3887 DECL_ALIGN (TYPE_BINFO_VTABLE (t)));
3890 else if (first_vfn_base_index >= 0)
3891 CLASSTYPE_VFIELD (t) = vfield;
3892 CLASSTYPE_VFIELDS (t) = vfields;
3894 finish_struct_bits (t, max_has_virtual);
3896 /* Promote each bit-field's type to int if it is narrower than that.
3897 There's more: complete the rtl for any static member objects which
3898 is of the same type we're working on. */
3899 for (x = fields; x; x = TREE_CHAIN (x))
3901 if (DECL_BIT_FIELD (x)
3902 && (C_PROMOTING_INTEGER_TYPE_P (TREE_TYPE (x))
3903 || DECL_FIELD_SIZE (x) < TYPE_PRECISION (integer_type_node)))
3905 tree type = TREE_TYPE (x);
3907 /* Preserve unsignedness if traditional or if not really getting
3909 if (TREE_UNSIGNED (type)
3910 && (flag_traditional
3912 (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)
3913 && DECL_FIELD_SIZE (x) == TYPE_PRECISION (integer_type_node))))
3914 TREE_TYPE (x) = unsigned_type_node;
3916 TREE_TYPE (x) = integer_type_node;
3919 if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
3920 && TREE_TYPE (x) == t)
3922 DECL_MODE (x) = TYPE_MODE (t);
3923 make_decl_rtl (x, NULL, 0);
3927 /* Now add the tags, if any, to the list of TYPE_DECLs
3928 defined for this type. */
3929 if (CLASSTYPE_TAGS (t))
3931 x = CLASSTYPE_TAGS (t);
3932 last_x = tree_last (TYPE_FIELDS (t));
3935 tree tag = TYPE_NAME (TREE_VALUE (x));
3937 /* Check to see if it is already there. This will be the case if
3938 was do enum { red; } color; */
3939 if (chain_member (tag, TYPE_FIELDS (t)))
3945 #ifdef DWARF_DEBUGGING_INFO
3946 if (write_symbols == DWARF_DEBUG)
3948 /* Notify dwarfout.c that this TYPE_DECL node represent a
3949 gratuitous typedef. */
3950 DECL_IGNORED_P (tag) = 1;
3952 #endif /* DWARF_DEBUGGING_INFO */
3954 TREE_NONLOCAL_FLAG (TREE_VALUE (x)) = 0;
3956 last_x = chainon (last_x, tag);
3958 if (TYPE_FIELDS (t) == NULL_TREE)
3959 TYPE_FIELDS (t) = last_x;
3960 CLASSTYPE_LOCAL_TYPEDECLS (t) = 1;
3963 if (TYPE_HAS_CONSTRUCTOR (t))
3965 tree vfields = CLASSTYPE_VFIELDS (t);
3969 /* Mark the fact that constructor for T
3970 could affect anybody inheriting from T
3971 who wants to initialize vtables for VFIELDS's type. */
3972 if (VF_DERIVED_VALUE (vfields))
3973 TREE_ADDRESSABLE (vfields) = 1;
3974 vfields = TREE_CHAIN (vfields);
3976 if (any_default_members != 0)
3977 build_class_init_list (t);
3979 else if (TYPE_NEEDS_CONSTRUCTING (t))
3980 build_class_init_list (t);
3982 if (! IS_SIGNATURE (t))
3983 embrace_waiting_friends (t);
3985 /* Write out inline function definitions. */
3986 do_inline_function_hair (t, CLASSTYPE_INLINE_FRIENDS (t));
3987 CLASSTYPE_INLINE_FRIENDS (t) = 0;
3989 if (CLASSTYPE_VSIZE (t) != 0)
3991 if ((flag_this_is_variable & 1) == 0)
3993 tree vtbl_ptr = build_decl (VAR_DECL, get_identifier (VPTR_NAME),
3994 TREE_TYPE (vfield));
3995 DECL_REGISTER (vtbl_ptr) = 1;
3996 CLASSTYPE_VTBL_PTR (t) = vtbl_ptr;
3999 /* This is now done above. */
4000 if (DECL_FIELD_CONTEXT (vfield) != t)
4002 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
4003 tree offset = BINFO_OFFSET (binfo);
4005 vfield = copy_node (vfield);
4006 copy_lang_decl (vfield);
4008 if (! integer_zerop (offset))
4009 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
4010 DECL_FIELD_CONTEXT (vfield) = t;
4011 DECL_CLASS_CONTEXT (vfield) = t;
4012 DECL_FIELD_BITPOS (vfield)
4013 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
4014 CLASSTYPE_VFIELD (t) = vfield;
4018 /* In addition to this one, all the other vfields should be listed. */
4019 /* Before that can be done, we have to have FIELD_DECLs for them, and
4020 a place to find them. */
4021 TYPE_NONCOPIED_PARTS (t) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t)), vfield);
4023 if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
4024 && DECL_VINDEX (TREE_VEC_ELT (method_vec, 0)) == NULL_TREE)
4025 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4029 /* Make the rtl for any new vtables we have created, and unmark
4030 the base types we marked. */
4031 finish_vtbls (TYPE_BINFO (t), 1, t);
4032 TYPE_BEING_DEFINED (t) = 0;
4033 hack_incomplete_structures (t);
4036 if (TYPE_NAME (t) && TYPE_IDENTIFIER (t))
4037 undo_template_name_overload (TYPE_IDENTIFIER (t), 1);
4039 if (current_class_type)
4042 error ("trying to finish struct, but kicked out due to previous parse errors.");
4044 resume_momentary (old);
4047 cadillac_finish_struct (t);
4050 /* This has to be done after we have sorted out what to do with
4051 the enclosing type. */
4052 if (write_symbols != DWARF_DEBUG)
4054 /* Be smarter about nested classes here. If a type is nested,
4055 only output it if we would output the enclosing type. */
4056 if (DECL_CONTEXT (TYPE_NAME (t))
4057 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (TYPE_NAME (t)))) == 't')
4058 DECL_IGNORED_P (TYPE_NAME (t)) = TREE_ASM_WRITTEN (TYPE_NAME (t));
4062 if (write_symbols != DWARF_DEBUG)
4064 /* If the type has methods, we want to think about cutting down
4065 the amount of symbol table stuff we output. The value stored in
4066 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4067 For example, if a member function is seen and we decide to
4068 write out that member function, then we can change the value
4069 of the DECL_IGNORED_P slot, and the type will be output when
4070 that member function's debug info is written out. */
4071 if (CLASSTYPE_METHOD_VEC (t))
4073 extern tree pending_vtables;
4075 /* Don't output full info about any type
4076 which does not have its implementation defined here. */
4077 if (TYPE_VIRTUAL_P (t) && write_virtuals == 2)
4078 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t))
4079 = (value_member (TYPE_IDENTIFIER (t), pending_vtables) == 0);
4080 else if (CLASSTYPE_INTERFACE_ONLY (t))
4081 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
4082 else if (CLASSTYPE_INTERFACE_UNKNOWN (t))
4083 /* Only a first approximation! */
4084 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
4086 else if (CLASSTYPE_INTERFACE_ONLY (t))
4087 TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (t)) = 1;
4090 /* Finish debugging output for this type. */
4091 rest_of_type_compilation (t, global_bindings_p ());
4096 /* Return non-zero if the effective type of INSTANCE is static.
4097 Used to determine whether the virtual function table is needed
4100 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4101 of our knowledge of its type. */
4103 resolves_to_fixed_type_p (instance, nonnull)
4107 switch (TREE_CODE (instance))
4110 /* Check that we are not going through a cast of some sort. */
4111 if (TREE_TYPE (instance)
4112 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0))))
4113 instance = TREE_OPERAND (instance, 0);
4114 /* fall through... */
4116 /* This is a call to a constructor, hence it's never zero. */
4117 if (TREE_HAS_CONSTRUCTOR (instance))
4126 /* This is a call to a constructor, hence it's never zero. */
4127 if (TREE_HAS_CONSTRUCTOR (instance))
4133 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4136 /* This is a call to `new', hence it's never zero. */
4137 if (TREE_CALLS_NEW (instance))
4147 if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
4148 /* Propagate nonnull. */
4149 resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4150 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
4151 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4156 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4161 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4164 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 1), nonnull);
4166 case WITH_CLEANUP_EXPR:
4167 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
4168 return resolves_to_fixed_type_p (TREE_OPERAND (instance, 0), nonnull);
4169 /* fall through... */
4172 if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
4173 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
4179 /* fall through... */
4182 if (IS_AGGR_TYPE (TREE_TYPE (instance)))
4190 if (instance == current_class_decl
4191 && flag_this_is_variable <= 0)
4193 /* Some people still use `this = 0' inside destructors. */
4194 *nonnull = ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl));
4195 /* In a constructor, we know our type. */
4196 if (flag_this_is_variable < 0)
4199 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
4200 /* Reference variables should be references to objects. */
4211 init_class_processing ()
4213 current_class_depth = 0;
4214 current_class_stacksize = 10;
4215 current_class_base = (tree *)xmalloc(current_class_stacksize * sizeof (tree));
4216 current_class_stack = current_class_base;
4218 current_lang_stacksize = 10;
4219 current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree));
4220 current_lang_stack = current_lang_base;
4222 /* Keep these values lying around. */
4223 the_null_vtable_entry = build_vtable_entry (integer_zero_node, integer_zero_node);
4224 base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node);
4225 TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE);
4227 gcc_obstack_init (&class_obstack);
4230 /* Set current scope to NAME. CODE tells us if this is a
4231 STRUCT, UNION, or ENUM environment.
4233 NAME may end up being NULL_TREE if this is an anonymous or
4234 late-bound struct (as in "struct { ... } foo;") */
4236 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
4237 appropriate values, found by looking up the type definition of
4240 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
4241 which can be seen locally to the class. They are shadowed by
4242 any subsequent local declaration (including parameter names).
4244 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
4245 which have static meaning (i.e., static members, static
4246 member functions, enum declarations, etc).
4248 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
4249 which can be seen locally to the class (as in 1), but
4250 know that we are doing this for declaration purposes
4251 (i.e. friend foo::bar (int)).
4253 So that we may avoid calls to lookup_name, we cache the _TYPE
4254 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
4256 For multiple inheritance, we perform a two-pass depth-first search
4257 of the type lattice. The first pass performs a pre-order search,
4258 marking types after the type has had its fields installed in
4259 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
4260 unmarks the marked types. If a field or member function name
4261 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4262 that name becomes `error_mark_node'. */
4265 pushclass (type, modify)
4269 push_memoized_context (type, modify);
4271 current_class_depth++;
4272 *current_class_stack++ = current_class_name;
4273 *current_class_stack++ = current_class_type;
4274 if (current_class_stack >= current_class_base + current_class_stacksize)
4276 current_class_base =
4277 (tree *)xrealloc (current_class_base,
4278 sizeof (tree) * (current_class_stacksize + 10));
4279 current_class_stack = current_class_base + current_class_stacksize;
4280 current_class_stacksize += 10;
4283 current_class_name = TYPE_NAME (type);
4284 if (TREE_CODE (current_class_name) == TYPE_DECL)
4285 current_class_name = DECL_NAME (current_class_name);
4286 current_class_type = type;
4288 if (previous_class_type != NULL_TREE
4289 && (type != previous_class_type || TYPE_SIZE (previous_class_type) == NULL_TREE)
4290 && current_class_depth == 1)
4292 /* Forcibly remove any old class remnants. */
4294 previous_class_type = NULL_TREE;
4302 tree this_fndecl = current_function_decl;
4304 if (current_function_decl
4305 && DECL_CONTEXT (current_function_decl)
4306 && TREE_CODE (DECL_CONTEXT (current_function_decl)) == FUNCTION_DECL)
4307 current_function_decl = DECL_CONTEXT (current_function_decl);
4309 current_function_decl = NULL_TREE;
4311 if (TREE_CODE (type) == UNINSTANTIATED_P_TYPE)
4312 declare_uninstantiated_type_level ();
4313 else if (type != previous_class_type || current_class_depth > 1)
4315 build_mi_matrix (type);
4316 push_class_decls (type);
4318 if (current_class_depth == 1)
4319 previous_class_type = type;
4325 /* Hooray, our cacheing was successful, let's just install the
4326 cached class_shadowed list, and walk through it to get the
4327 IDENTIFIER_TYPE_VALUEs correct. */
4328 set_class_shadows (previous_class_values);
4329 for (item = previous_class_values; item; item = TREE_CHAIN (item))
4331 tree id = TREE_PURPOSE (item);
4332 tree decl = IDENTIFIER_CLASS_VALUE (id);
4334 if (TREE_CODE (decl) == TYPE_DECL)
4335 set_identifier_type_value (id, TREE_TYPE (decl));
4337 unuse_fields (type);
4340 if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (type)))
4341 overload_template_name (current_class_name, 0);
4343 for (tags = CLASSTYPE_TAGS (type); tags; tags = TREE_CHAIN (tags))
4345 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 1;
4346 if (! TREE_PURPOSE (tags))
4348 pushtag (TREE_PURPOSE (tags), TREE_VALUE (tags), 0);
4351 current_function_decl = this_fndecl;
4355 cadillac_push_class (type);
4358 /* Get out of the current class scope. If we were in a class scope
4359 previously, that is the one popped to. The flag MODIFY tells whether
4360 the current scope declarations needs to be modified as a result of
4361 popping to the previous scope. 0 is used for class definitions. */
4367 cadillac_pop_class ();
4371 /* Back this old class out completely. */
4372 tree tags = CLASSTYPE_TAGS (previous_class_type);
4375 /* This code can be seen as a cache miss. When we've cached a
4376 class' scope's bindings and we can't use them, we need to reset
4377 them. This is it! */
4378 for (t = previous_class_values; t; t = TREE_CHAIN (t))
4379 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
4382 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
4383 tags = TREE_CHAIN (tags);
4390 /* Just remove from this class what didn't make
4391 it into IDENTIFIER_CLASS_VALUE. */
4392 tree tags = CLASSTYPE_TAGS (current_class_type);
4396 TREE_NONLOCAL_FLAG (TREE_VALUE (tags)) = 0;
4397 tags = TREE_CHAIN (tags);
4399 if (IDENTIFIER_TEMPLATE (TYPE_IDENTIFIER (current_class_type)))
4400 undo_template_name_overload (current_class_name, 0);
4403 /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition,
4404 since not all class decls make it there currently. */
4405 poplevel_class (! modify);
4407 /* Since poplevel_class does the popping of class decls nowadays,
4408 this really only frees the obstack used for these decls.
4409 That's why it had to be moved down here. */
4411 pop_class_decls (current_class_type);
4413 current_class_depth--;
4414 current_class_type = *--current_class_stack;
4415 current_class_name = *--current_class_stack;
4417 if (current_class_type)
4419 if (CLASSTYPE_VTBL_PTR (current_class_type))
4422 = lookup_name (DECL_NAME (CLASSTYPE_VTBL_PTR (current_class_type)),
4424 if (current_vtable_decl)
4425 current_vtable_decl = build_indirect_ref (current_vtable_decl,
4428 current_class_decl = lookup_name (this_identifier, 0);
4429 if (current_class_decl)
4431 if (TREE_CODE (TREE_TYPE (current_class_decl)) == POINTER_TYPE)
4434 if (CLASSTYPE_INST_VAR (current_class_type) == NULL_TREE)
4436 /* Can't call build_indirect_ref here, because it has special
4437 logic to return C_C_D given this argument. */
4438 C_C_D = build1 (INDIRECT_REF, current_class_type, current_class_decl);
4439 CLASSTYPE_INST_VAR (current_class_type) = C_C_D;
4443 C_C_D = CLASSTYPE_INST_VAR (current_class_type);
4444 /* `current_class_decl' is different for every
4445 function we compile. */
4446 TREE_OPERAND (C_C_D, 0) = current_class_decl;
4448 temp = TREE_TYPE (TREE_TYPE (current_class_decl));
4449 TREE_READONLY (C_C_D) = TYPE_READONLY (temp);
4450 TREE_SIDE_EFFECTS (C_C_D) = TYPE_VOLATILE (temp);
4451 TREE_THIS_VOLATILE (C_C_D) = TYPE_VOLATILE (temp);
4454 C_C_D = current_class_decl;
4461 current_class_decl = NULL_TREE;
4462 current_vtable_decl = NULL_TREE;
4466 pop_memoized_context (modify);
4472 /* When entering a class scope, all enclosing class scopes' names with
4473 static meaning (static variables, static functions, types and enumerators)
4474 have to be visible. This recursive function calls pushclass for all
4475 enclosing class contexts until global or a local scope is reached.
4476 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4477 formal of the same name. */
4480 push_nested_class (type, modify)
4486 if (type == error_mark_node || ! IS_AGGR_TYPE (type))
4489 context = DECL_CONTEXT (TYPE_NAME (type));
4491 if (context && TREE_CODE (context) == RECORD_TYPE)
4492 push_nested_class (context, 2);
4493 pushclass (type, modify);
4496 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4499 pop_nested_class (modify)
4502 tree context = DECL_CONTEXT (TYPE_NAME (current_class_type));
4505 if (context && TREE_CODE (context) == RECORD_TYPE)
4506 pop_nested_class (modify);
4509 /* Set global variables CURRENT_LANG_NAME to appropriate value
4510 so that behavior of name-mangling machinery is correct. */
4513 push_lang_context (name)
4516 *current_lang_stack++ = current_lang_name;
4517 if (current_lang_stack >= current_lang_base + current_lang_stacksize)
4520 (tree *)xrealloc (current_lang_base,
4521 sizeof (tree) * (current_lang_stacksize + 10));
4522 current_lang_stack = current_lang_base + current_lang_stacksize;
4523 current_lang_stacksize += 10;
4526 if (name == lang_name_cplusplus)
4528 strict_prototype = strict_prototypes_lang_cplusplus;
4529 current_lang_name = name;
4531 else if (name == lang_name_c)
4533 strict_prototype = strict_prototypes_lang_c;
4534 current_lang_name = name;
4537 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
4540 cadillac_push_lang (name);
4543 /* Get out of the current language scope. */
4548 cadillac_pop_lang ();
4550 current_lang_name = *--current_lang_stack;
4551 if (current_lang_name == lang_name_cplusplus)
4552 strict_prototype = strict_prototypes_lang_cplusplus;
4553 else if (current_lang_name == lang_name_c)
4554 strict_prototype = strict_prototypes_lang_c;
4558 root_lang_context_p ()
4560 return current_lang_stack == current_lang_base;
4563 /* Type instantiation routines. */
4565 /* This function will instantiate the type of the expression given
4566 in RHS to match the type of LHSTYPE. If LHSTYPE is NULL_TREE,
4567 or other errors exist, the TREE_TYPE of RHS will be ERROR_MARK_NODE.
4569 This function is used in build_modify_expr, convert_arguments,
4570 build_c_cast, and compute_conversion_costs. */
4572 instantiate_type (lhstype, rhs, complain)
4576 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
4579 error ("not enough type information");
4580 return error_mark_node;
4583 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
4586 /* This should really only be used when attempting to distinguish
4587 what sort of a pointer to function we have. For now, any
4588 arithmetic operation which is not supported on pointers
4589 is rejected as an error. */
4591 switch (TREE_CODE (rhs))
4598 my_friendly_abort (177);
4599 return error_mark_node;
4603 TREE_TYPE (rhs) = lhstype;
4604 lhstype = build_pointer_type (lhstype);
4605 TREE_OPERAND (rhs, 0)
4606 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
4607 if (TREE_OPERAND (rhs, 0) == error_mark_node)
4608 return error_mark_node;
4613 rhs = copy_node (TREE_OPERAND (rhs, 0));
4614 TREE_TYPE (rhs) = unknown_type_node;
4615 return instantiate_type (lhstype, rhs, complain);
4619 tree field = TREE_OPERAND (rhs, 1);
4620 if (TREE_CODE (field) == TREE_LIST)
4622 tree function = instantiate_type (lhstype, field, complain);
4623 if (function == error_mark_node)
4624 return error_mark_node;
4625 my_friendly_assert (TREE_CODE (function) == FUNCTION_DECL, 185);
4626 if (DECL_VINDEX (function))
4628 tree base = TREE_OPERAND (rhs, 0);
4629 tree base_ptr = build_unary_op (ADDR_EXPR, base, 0);
4630 if (base_ptr == error_mark_node)
4631 return error_mark_node;
4632 base_ptr = convert_pointer_to (DECL_CONTEXT (function), base_ptr);
4633 if (base_ptr == error_mark_node)
4634 return error_mark_node;
4635 return build_vfn_ref (&base_ptr, base, DECL_VINDEX (function));
4640 my_friendly_assert (TREE_CODE (field) == FIELD_DECL, 178);
4641 my_friendly_assert (!(TREE_CODE (TREE_TYPE (field)) == FUNCTION_TYPE
4642 || TREE_CODE (TREE_TYPE (field)) == METHOD_TYPE),
4645 TREE_TYPE (rhs) = lhstype;
4646 /* First look for an exact match */
4648 while (field && TREE_TYPE (field) != lhstype)
4649 field = DECL_CHAIN (field);
4652 TREE_OPERAND (rhs, 1) = field;
4656 /* No exact match found, look for a compatible function. */
4657 field = TREE_OPERAND (rhs, 1);
4658 while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
4659 field = DECL_CHAIN (field);
4662 TREE_OPERAND (rhs, 1) = field;
4663 field = DECL_CHAIN (field);
4664 while (field && ! comptypes (lhstype, TREE_TYPE (field), 0))
4665 field = DECL_CHAIN (field);
4669 error ("ambiguous overload for COMPONENT_REF requested");
4670 return error_mark_node;
4676 error ("no appropriate overload exists for COMPONENT_REF");
4677 return error_mark_node;
4684 tree elem, baselink, name;
4685 int globals = overloaded_globals_p (rhs);
4687 #if 0 /* obsolete */
4688 /* If there's only one function we know about, return that. */
4689 if (globals > 0 && TREE_CHAIN (rhs) == NULL_TREE)
4690 return TREE_VALUE (rhs);
4693 /* First look for an exact match. Search either overloaded
4694 functions or member functions. May have to undo what
4695 `default_conversion' might do to lhstype. */
4697 if (TYPE_PTRMEMFUNC_P (lhstype))
4698 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
4700 if (TREE_CODE (lhstype) == POINTER_TYPE)
4701 if (TREE_CODE (TREE_TYPE (lhstype)) == FUNCTION_TYPE
4702 || TREE_CODE (TREE_TYPE (lhstype)) == METHOD_TYPE)
4703 lhstype = TREE_TYPE (lhstype);
4707 error ("invalid type combination for overload");
4708 return error_mark_node;
4711 if (TREE_CODE (lhstype) != FUNCTION_TYPE && globals > 0)
4714 cp_error ("cannot resolve overloaded function `%D' based on non-function type",
4715 TREE_PURPOSE (rhs));
4716 return error_mark_node;
4721 elem = get_first_fn (rhs);
4723 if (! comptypes (lhstype, TREE_TYPE (elem), 1))
4724 elem = DECL_CHAIN (elem);
4728 /* No exact match found, look for a compatible template. */
4731 for (elem = get_first_fn (rhs); elem; elem = DECL_CHAIN (elem))
4732 if (TREE_CODE (elem) == TEMPLATE_DECL)
4734 int n = TREE_VEC_LENGTH (DECL_TEMPLATE_PARMS (elem));
4735 tree *t = (tree *) alloca (sizeof (tree) * n);
4737 i = type_unification (DECL_TEMPLATE_PARMS (elem), t,
4738 TYPE_ARG_TYPES (TREE_TYPE (elem)),
4739 TYPE_ARG_TYPES (lhstype), &d, 0);
4744 cp_error ("ambiguous template instantiation converting to `%#T'", lhstype);
4745 return error_mark_node;
4747 save_elem = instantiate_template (elem, t);
4748 /* Check the return type. */
4749 if (! comptypes (TREE_TYPE (lhstype),
4750 TREE_TYPE (TREE_TYPE (save_elem)), 1))
4758 /* No match found, look for a compatible function. */
4759 elem = get_first_fn (rhs);
4760 while (elem && comp_target_types (lhstype,
4761 TREE_TYPE (elem), 1) <= 0)
4762 elem = DECL_CHAIN (elem);
4765 tree save_elem = elem;
4766 elem = DECL_CHAIN (elem);
4767 while (elem && comp_target_types (lhstype,
4768 TREE_TYPE (elem), 0) <= 0)
4769 elem = DECL_CHAIN (elem);
4774 cp_error ("cannot resolve overload to target type `%#T'",
4776 cp_error_at (" ambiguity between `%#D'", save_elem);
4777 cp_error_at (" and `%#D', at least", elem);
4779 return error_mark_node;
4785 cp_error ("cannot resolve overload to target type `%#T'",
4787 cp_error (" because no suitable overload of function `%D' exists",
4788 TREE_PURPOSE (rhs));
4790 return error_mark_node;
4793 if (TREE_NONLOCAL_FLAG (rhs))
4795 /* Got to get it as a baselink. */
4796 rhs = lookup_fnfields (TYPE_BINFO (current_class_type),
4797 TREE_PURPOSE (rhs), 0);
4801 my_friendly_assert (TREE_CHAIN (rhs) == NULL_TREE, 181);
4802 if (TREE_CODE (TREE_VALUE (rhs)) == TREE_LIST)
4803 rhs = TREE_VALUE (rhs);
4804 my_friendly_assert (TREE_CODE (TREE_VALUE (rhs)) == FUNCTION_DECL,
4808 for (baselink = rhs; baselink;
4809 baselink = next_baselink (baselink))
4811 elem = TREE_VALUE (baselink);
4813 if (comptypes (lhstype, TREE_TYPE (elem), 1))
4816 elem = DECL_CHAIN (elem);
4819 /* No exact match found, look for a compatible method. */
4820 for (baselink = rhs; baselink;
4821 baselink = next_baselink (baselink))
4823 elem = TREE_VALUE (baselink);
4824 while (elem && comp_target_types (lhstype,
4825 TREE_TYPE (elem), 1) <= 0)
4826 elem = DECL_CHAIN (elem);
4829 tree save_elem = elem;
4830 elem = DECL_CHAIN (elem);
4831 while (elem && comp_target_types (lhstype,
4832 TREE_TYPE (elem), 0) <= 0)
4833 elem = DECL_CHAIN (elem);
4837 error ("ambiguous overload for overloaded method requested");
4838 return error_mark_node;
4842 name = DECL_NAME (TREE_VALUE (rhs));
4844 if (TREE_CODE (lhstype) == FUNCTION_TYPE && globals < 0)
4846 /* Try to instantiate from non-member functions. */
4847 rhs = lookup_name_nonclass (name);
4848 if (rhs && TREE_CODE (rhs) == TREE_LIST)
4850 /* This code seems to be missing a `return'. */
4851 my_friendly_abort (4);
4852 instantiate_type (lhstype, rhs, complain);
4858 cp_error ("no compatible member functions named `%D'", name);
4859 return error_mark_node;
4863 /* This is too hard for now. */
4864 my_friendly_abort (183);
4865 return error_mark_node;
4870 TREE_OPERAND (rhs, 0)
4871 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
4872 if (TREE_OPERAND (rhs, 0) == error_mark_node)
4873 return error_mark_node;
4874 TREE_OPERAND (rhs, 1)
4875 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
4876 if (TREE_OPERAND (rhs, 1) == error_mark_node)
4877 return error_mark_node;
4879 TREE_TYPE (rhs) = lhstype;
4883 case TRUNC_DIV_EXPR:
4884 case FLOOR_DIV_EXPR:
4886 case ROUND_DIV_EXPR:
4888 case TRUNC_MOD_EXPR:
4889 case FLOOR_MOD_EXPR:
4891 case ROUND_MOD_EXPR:
4892 case FIX_ROUND_EXPR:
4893 case FIX_FLOOR_EXPR:
4895 case FIX_TRUNC_EXPR:
4911 case PREINCREMENT_EXPR:
4912 case PREDECREMENT_EXPR:
4913 case POSTINCREMENT_EXPR:
4914 case POSTDECREMENT_EXPR:
4916 error ("invalid operation on uninstantiated type");
4917 return error_mark_node;
4919 case TRUTH_AND_EXPR:
4921 case TRUTH_XOR_EXPR:
4928 case TRUTH_ANDIF_EXPR:
4929 case TRUTH_ORIF_EXPR:
4930 case TRUTH_NOT_EXPR:
4932 error ("not enough type information");
4933 return error_mark_node;
4936 if (type_unknown_p (TREE_OPERAND (rhs, 0)))
4939 error ("not enough type information");
4940 return error_mark_node;
4942 TREE_OPERAND (rhs, 1)
4943 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
4944 if (TREE_OPERAND (rhs, 1) == error_mark_node)
4945 return error_mark_node;
4946 TREE_OPERAND (rhs, 2)
4947 = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), complain);
4948 if (TREE_OPERAND (rhs, 2) == error_mark_node)
4949 return error_mark_node;
4951 TREE_TYPE (rhs) = lhstype;
4955 TREE_OPERAND (rhs, 1)
4956 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), complain);
4957 if (TREE_OPERAND (rhs, 1) == error_mark_node)
4958 return error_mark_node;
4960 TREE_TYPE (rhs) = lhstype;
4964 if (TYPE_PTRMEMFUNC_P (lhstype))
4965 lhstype = TYPE_PTRMEMFUNC_FN_TYPE (lhstype);
4966 else if (TREE_CODE (lhstype) != POINTER_TYPE)
4969 error ("type for resolving address of overloaded function must be pointer type");
4970 return error_mark_node;
4972 TREE_TYPE (rhs) = lhstype;
4973 lhstype = TREE_TYPE (lhstype);
4975 tree fn = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), complain);
4976 if (fn == error_mark_node)
4977 return error_mark_node;
4978 mark_addressable (fn);
4979 TREE_OPERAND (rhs, 0) = fn;
4980 TREE_CONSTANT (rhs) = staticp (fn);
4984 case ENTRY_VALUE_EXPR:
4985 my_friendly_abort (184);
4986 return error_mark_node;
4989 return error_mark_node;
4992 my_friendly_abort (185);
4993 return error_mark_node;
4997 /* Return the name of the virtual function pointer field
4998 (as an IDENTIFIER_NODE) for the given TYPE. Note that
4999 this may have to look back through base types to find the
5000 ultimate field name. (For single inheritance, these could
5001 all be the same name. Who knows for multiple inheritance). */
5003 get_vfield_name (type)
5006 tree binfo = TYPE_BINFO (type);
5009 while (BINFO_BASETYPES (binfo)
5010 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
5011 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
5012 binfo = BINFO_BASETYPE (binfo, 0);
5014 type = BINFO_TYPE (binfo);
5015 buf = (char *)alloca (sizeof (VFIELD_NAME_FORMAT)
5016 + TYPE_NAME_LENGTH (type) + 2);
5017 sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
5018 return get_identifier (buf);
5022 print_class_statistics ()
5024 #ifdef GATHER_STATISTICS
5025 fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
5026 fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
5027 fprintf (stderr, "build_method_call = %d (inner = %d)\n",
5028 n_build_method_call, n_inner_fields_searched);
5031 fprintf (stderr, "vtables = %d; vtable searches = %d\n",
5032 n_vtables, n_vtable_searches);
5033 fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
5034 n_vtable_entries, n_vtable_elems);
5039 /* Push an obstack which is sufficiently long-lived to hold such class
5040 decls that may be cached in the previous_class_values list. For now, let's
5041 use the permanent obstack, later we may create a dedicated obstack just
5042 for this purpose. The effect is undone by pop_obstacks. */
5044 maybe_push_cache_obstack ()
5046 push_obstacks_nochange ();
5047 if (current_class_depth == 1)
5048 current_obstack = &permanent_obstack;