1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 92-97, 1998, 1999 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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* High-level class interface. */
33 #include "splay-tree.h"
36 #define obstack_chunk_alloc xmalloc
37 #define obstack_chunk_free free
39 /* This is how we tell when two virtual member functions are really the
41 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
43 extern void set_class_shadows PROTO ((tree));
45 /* The number of nested classes being processed. If we are not in the
46 scope of any class, this is zero. */
48 int current_class_depth;
50 /* In order to deal with nested classes, we keep a stack of classes.
51 The topmost entry is the innermost class, and is the entry at index
52 CURRENT_CLASS_DEPTH */
54 typedef struct class_stack_node {
55 /* The name of the class. */
58 /* The _TYPE node for the class. */
61 /* The access specifier pending for new declarations in the scope of
65 /* If were defining TYPE, the names used in this class. */
66 splay_tree names_used;
67 }* class_stack_node_t;
69 /* The stack itself. This is an dynamically resized array. The
70 number of elements allocated is CURRENT_CLASS_STACK_SIZE. */
71 static int current_class_stack_size;
72 static class_stack_node_t current_class_stack;
74 /* When we're processing a member function, current_class_ptr is the
75 PARM_DECL for the `this' pointer. The current_class_ref is an
76 expression for `*this'. */
77 tree current_class_ptr, current_class_ref;
79 /* The following two can be derived from the previous one */
80 tree current_class_name; /* IDENTIFIER_NODE: name of current class */
81 tree current_class_type; /* _TYPE: the type of the current class */
82 tree current_access_specifier;
83 tree previous_class_type; /* _TYPE: the previous type that was a class */
84 tree previous_class_values; /* TREE_LIST: copy of the class_shadowed list
85 when leaving an outermost class scope. */
87 /* The obstack on which the cached class declarations are kept. */
88 static struct obstack class_cache_obstack;
89 /* The first object allocated on that obstack. We can use
90 obstack_free with tis value to free the entire obstack. */
91 char *class_cache_firstobj;
95 static tree get_vfield_name PROTO((tree));
96 static void finish_struct_anon PROTO((tree));
97 static tree build_vbase_pointer PROTO((tree, tree));
98 static tree build_vtable_entry PROTO((tree, tree));
99 static tree get_vtable_name PROTO((tree));
100 static tree get_derived_offset PROTO((tree, tree));
101 static tree get_basefndecls PROTO((tree, tree));
102 static void set_rtti_entry PROTO((tree, tree, tree));
103 static tree build_vtable PROTO((tree, tree));
104 static void prepare_fresh_vtable PROTO((tree, tree));
105 static void fixup_vtable_deltas1 PROTO((tree, tree));
106 static void fixup_vtable_deltas PROTO((tree, int, tree));
107 static void finish_vtbls PROTO((tree, int, tree));
108 static void modify_vtable_entry PROTO((tree, tree, tree));
109 static tree get_vtable_entry_n PROTO((tree, unsigned HOST_WIDE_INT));
110 static void add_virtual_function PROTO((tree *, tree *, int *, tree, tree));
111 static tree delete_duplicate_fields_1 PROTO((tree, tree));
112 static void delete_duplicate_fields PROTO((tree));
113 static void finish_struct_bits PROTO((tree, int));
114 static int alter_access PROTO((tree, tree, tree, tree));
115 static void handle_using_decl PROTO((tree, tree, tree, tree));
116 static int overrides PROTO((tree, tree));
117 static int strictly_overrides PROTO((tree, tree));
118 static void merge_overrides PROTO((tree, tree, int, tree));
119 static void override_one_vtable PROTO((tree, tree, tree));
120 static void mark_overriders PROTO((tree, tree));
121 static void check_for_override PROTO((tree, tree));
122 static tree get_class_offset_1 PROTO((tree, tree, tree, tree, tree));
123 static tree get_class_offset PROTO((tree, tree, tree, tree));
124 static void modify_one_vtable PROTO((tree, tree, tree));
125 static void modify_all_vtables PROTO((tree, tree));
126 static void modify_all_direct_vtables PROTO((tree, int, tree, tree));
127 static void modify_all_indirect_vtables PROTO((tree, int, int, tree, tree));
128 static int finish_base_struct PROTO((tree, struct base_info *));
129 static void finish_struct_methods PROTO((tree));
130 static void maybe_warn_about_overly_private_class PROTO ((tree));
131 static int field_decl_cmp PROTO ((const tree *, const tree *));
132 static int method_name_cmp PROTO ((const tree *, const tree *));
133 static tree make_method_vec PROTO((int));
134 static void free_method_vec PROTO((tree));
135 static tree add_implicitly_declared_members PROTO((tree, int, int, int));
136 static tree fixed_type_or_null PROTO((tree, int *));
137 static tree resolve_address_of_overloaded_function PROTO((tree, tree, int,
139 static void build_vtable_entry_ref PROTO((tree, tree, tree));
140 static tree build_vtable_entry_for_fn PROTO((tree, tree));
141 static tree build_vtbl_initializer PROTO((tree));
142 static int count_fields PROTO((tree));
143 static int add_fields_to_vec PROTO((tree, tree, int));
145 /* Way of stacking language names. */
146 tree *current_lang_base, *current_lang_stack;
147 int current_lang_stacksize;
149 /* Names of languages we recognize. */
150 tree lang_name_c, lang_name_cplusplus, lang_name_java;
151 tree current_lang_name;
153 /* When layout out an aggregate type, the size of the
154 basetypes (virtual and non-virtual) is passed to layout_record
156 static tree base_layout_decl;
158 /* Constants used for access control. */
159 tree access_default_node; /* 0 */
160 tree access_public_node; /* 1 */
161 tree access_protected_node; /* 2 */
162 tree access_private_node; /* 3 */
163 tree access_default_virtual_node; /* 4 */
164 tree access_public_virtual_node; /* 5 */
165 tree access_protected_virtual_node; /* 6 */
166 tree access_private_virtual_node; /* 7 */
168 /* Variables shared between class.c and call.c. */
170 #ifdef GATHER_STATISTICS
172 int n_vtable_entries = 0;
173 int n_vtable_searches = 0;
174 int n_vtable_elems = 0;
175 int n_convert_harshness = 0;
176 int n_compute_conversion_costs = 0;
177 int n_build_method_call = 0;
178 int n_inner_fields_searched = 0;
181 /* Virtual baseclass things. */
184 build_vbase_pointer (exp, type)
188 FORMAT_VBASE_NAME (name, type);
190 return build_component_ref (exp, get_identifier (name), NULL_TREE, 0);
194 /* Is the type of the EXPR, the complete type of the object?
195 If we are going to be wrong, we must be conservative, and return 0. */
198 complete_type_p (expr)
201 tree type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
204 switch (TREE_CODE (expr))
211 expr = TREE_OPERAND (expr, 0);
215 if (! TREE_HAS_CONSTRUCTOR (expr))
217 /* fall through... */
220 if (TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE
221 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr)))
222 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
224 /* fall through... */
227 if (IS_AGGR_TYPE (TREE_TYPE (expr))
228 && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) == type)
230 /* fall through... */
241 /* Build multi-level access to EXPR using hierarchy path PATH.
242 CODE is PLUS_EXPR if we are going with the grain,
243 and MINUS_EXPR if we are not (in which case, we cannot traverse
244 virtual baseclass links).
246 TYPE is the type we want this path to have on exit.
248 NONNULL is non-zero if we know (for any reason) that EXPR is
249 not, in fact, zero. */
252 build_vbase_path (code, type, expr, path, nonnull)
254 tree type, expr, path;
257 register int changed = 0;
258 tree last = NULL_TREE, last_virtual = NULL_TREE;
260 tree null_expr = 0, nonnull_expr;
262 tree offset = integer_zero_node;
264 if (BINFO_INHERITANCE_CHAIN (path) == NULL_TREE)
265 return build1 (NOP_EXPR, type, expr);
267 /* If -fthis-is-variable, we might have set nonnull incorrectly. We
268 don't care enough to get this right, so just clear it. */
269 if (flag_this_is_variable > 0)
272 /* We could do better if we had additional logic to convert back to the
273 unconverted type (the static type of the complete object), and then
274 convert back to the type we want. Until that is done, we only optimize
275 if the complete type is the same type as expr has. */
276 fixed_type_p = resolves_to_fixed_type_p (expr, &nonnull);
278 if (!fixed_type_p && TREE_SIDE_EFFECTS (expr))
279 expr = save_expr (expr);
282 if (BINFO_INHERITANCE_CHAIN (path))
283 path = reverse_path (path);
285 basetype = BINFO_TYPE (path);
289 if (TREE_VIA_VIRTUAL (path))
291 last_virtual = BINFO_TYPE (path);
292 if (code == PLUS_EXPR)
294 changed = ! fixed_type_p;
300 /* We already check for ambiguous things in the caller, just
304 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr))), 0);
305 nonnull_expr = convert_pointer_to_real (binfo, nonnull_expr);
307 ind = build_indirect_ref (nonnull_expr, NULL_PTR);
308 nonnull_expr = build_vbase_pointer (ind, last_virtual);
310 && TREE_CODE (type) == POINTER_TYPE
311 && null_expr == NULL_TREE)
313 null_expr = build1 (NOP_EXPR, build_pointer_type (last_virtual), integer_zero_node);
314 expr = build (COND_EXPR, build_pointer_type (last_virtual),
315 build (EQ_EXPR, boolean_type_node, expr,
317 null_expr, nonnull_expr);
320 /* else we'll figure out the offset below. */
322 /* Happens in the case of parse errors. */
323 if (nonnull_expr == error_mark_node)
324 return error_mark_node;
328 cp_error ("cannot cast up from virtual baseclass `%T'",
330 return error_mark_node;
334 path = BINFO_INHERITANCE_CHAIN (path);
336 /* LAST is now the last basetype assoc on the path. */
338 /* A pointer to a virtual base member of a non-null object
339 is non-null. Therefore, we only need to test for zeroness once.
340 Make EXPR the canonical expression to deal with here. */
343 TREE_OPERAND (expr, 2) = nonnull_expr;
344 TREE_TYPE (expr) = TREE_TYPE (TREE_OPERAND (expr, 1))
345 = TREE_TYPE (nonnull_expr);
350 /* If we go through any virtual base pointers, make sure that
351 casts to BASETYPE from the last virtual base class use
352 the right value for BASETYPE. */
355 tree intype = TREE_TYPE (TREE_TYPE (expr));
356 if (TYPE_MAIN_VARIANT (intype) != BINFO_TYPE (last))
358 tree binfo = get_binfo (last, TYPE_MAIN_VARIANT (intype), 0);
359 offset = BINFO_OFFSET (binfo);
366 offset = BINFO_OFFSET (binfo_member (last_virtual,
367 CLASSTYPE_VBASECLASSES (basetype)));
368 offset = size_binop (PLUS_EXPR, offset, BINFO_OFFSET (last));
371 offset = BINFO_OFFSET (last);
374 if (TREE_INT_CST_LOW (offset))
376 /* Bash types to make the backend happy. */
377 offset = cp_convert (type, offset);
379 /* This shouldn't be necessary. (mrs) */
380 expr = build1 (NOP_EXPR, type, expr);
383 /* If expr might be 0, we need to preserve that zeroness. */
387 TREE_TYPE (null_expr) = type;
389 null_expr = build1 (NOP_EXPR, type, integer_zero_node);
390 if (TREE_SIDE_EFFECTS (expr))
391 expr = save_expr (expr);
393 return build (COND_EXPR, type,
394 build (EQ_EXPR, boolean_type_node, expr, integer_zero_node),
396 build (code, type, expr, offset));
398 else return build (code, type, expr, offset);
401 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
402 be used multiple times in initialization of multiple inheritance. */
405 TREE_TYPE (expr) = type;
409 return build1 (NOP_EXPR, type, expr);
412 /* Virtual function things. */
414 /* Build an entry in the virtual function table.
415 DELTA is the offset for the `this' pointer.
416 PFN is an ADDR_EXPR containing a pointer to the virtual function.
417 Note that the index (DELTA2) in the virtual function table
421 build_vtable_entry (delta, pfn)
424 if (flag_vtable_thunks)
426 HOST_WIDE_INT idelta = TREE_INT_CST_LOW (delta);
427 if (idelta && ! DECL_ABSTRACT_VIRTUAL_P (TREE_OPERAND (pfn, 0)))
429 pfn = build1 (ADDR_EXPR, vtable_entry_type,
430 make_thunk (pfn, idelta));
431 TREE_READONLY (pfn) = 1;
432 TREE_CONSTANT (pfn) = 1;
434 #ifdef GATHER_STATISTICS
435 n_vtable_entries += 1;
441 extern int flag_huge_objects;
442 tree elems = expr_tree_cons (NULL_TREE, delta,
443 expr_tree_cons (NULL_TREE, integer_zero_node,
444 build_expr_list (NULL_TREE, pfn)));
445 tree entry = build (CONSTRUCTOR, vtable_entry_type, NULL_TREE, elems);
447 /* DELTA used to be constructed by `size_int' and/or size_binop,
448 which caused overflow problems when it was negative. That should
451 if (! int_fits_type_p (delta, delta_type_node))
453 if (flag_huge_objects)
454 sorry ("object size exceeds built-in limit for virtual function table implementation");
456 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
459 TREE_CONSTANT (entry) = 1;
460 TREE_STATIC (entry) = 1;
461 TREE_READONLY (entry) = 1;
463 #ifdef GATHER_STATISTICS
464 n_vtable_entries += 1;
471 /* Build a vtable entry for FNDECL. DELTA is the amount by which we
472 must adjust the this pointer when calling F. */
475 build_vtable_entry_for_fn (delta, fndecl)
481 /* Take the address of the function, considering it to be of an
482 appropriate generic type. */
483 pfn = build1 (ADDR_EXPR, vfunc_ptr_type_node, fndecl);
484 /* The address of a function can't change. */
485 TREE_CONSTANT (pfn) = 1;
486 /* Now build the vtable entry itself. */
487 return build_vtable_entry (delta, pfn);
490 /* We want to give the assembler the vtable identifier as well as
491 the offset to the function pointer. So we generate
493 __asm__ __volatile__ (".vtable_entry %c0, %c1"
494 : : "s"(&class_vtable),
495 "i"((long)&vtbl[idx].pfn - (long)&vtbl[0])); */
498 build_vtable_entry_ref (basetype, vtbl, idx)
499 tree basetype, vtbl, idx;
501 static char asm_stmt[] = ".vtable_entry %c0, %c1";
504 s = build_unary_op (ADDR_EXPR, TYPE_BINFO_VTABLE (basetype), 0);
505 s = build_tree_list (build_string (1, "s"), s);
507 i = build_array_ref (vtbl, idx);
508 if (!flag_vtable_thunks)
509 i = build_component_ref (i, pfn_identifier, vtable_entry_type, 0);
510 i = build_c_cast (ptrdiff_type_node, build_unary_op (ADDR_EXPR, i, 0));
511 i2 = build_array_ref (vtbl, build_int_2(0,0));
512 i2 = build_c_cast (ptrdiff_type_node, build_unary_op (ADDR_EXPR, i2, 0));
513 i = build_binary_op (MINUS_EXPR, i, i2);
514 i = build_tree_list (build_string (1, "i"), i);
516 expand_asm_operands (build_string (sizeof(asm_stmt)-1, asm_stmt),
517 NULL_TREE, chainon (s, i), NULL_TREE, 1, NULL, 0);
520 /* Given an object INSTANCE, return an expression which yields the
521 virtual function vtable element corresponding to INDEX. There are
522 many special cases for INSTANCE which we take care of here, mainly
523 to avoid creating extra tree nodes when we don't have to. */
526 build_vtbl_ref (instance, idx)
530 tree basetype = TREE_TYPE (instance);
532 if (TREE_CODE (basetype) == REFERENCE_TYPE)
533 basetype = TREE_TYPE (basetype);
535 if (instance == current_class_ref)
536 vtbl = build_vfield_ref (instance, basetype);
541 /* Try to figure out what a reference refers to, and
542 access its virtual function table directly. */
543 tree ref = NULL_TREE;
545 if (TREE_CODE (instance) == INDIRECT_REF
546 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance, 0))) == REFERENCE_TYPE)
547 ref = TREE_OPERAND (instance, 0);
548 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
551 if (ref && TREE_CODE (ref) == VAR_DECL
552 && DECL_INITIAL (ref))
554 tree init = DECL_INITIAL (ref);
556 while (TREE_CODE (init) == NOP_EXPR
557 || TREE_CODE (init) == NON_LVALUE_EXPR)
558 init = TREE_OPERAND (init, 0);
559 if (TREE_CODE (init) == ADDR_EXPR)
561 init = TREE_OPERAND (init, 0);
562 if (IS_AGGR_TYPE (TREE_TYPE (init))
563 && (TREE_CODE (init) == PARM_DECL
564 || TREE_CODE (init) == VAR_DECL))
570 if (IS_AGGR_TYPE (TREE_TYPE (instance))
571 && (TREE_CODE (instance) == RESULT_DECL
572 || TREE_CODE (instance) == PARM_DECL
573 || TREE_CODE (instance) == VAR_DECL))
574 vtbl = TYPE_BINFO_VTABLE (basetype);
576 vtbl = build_vfield_ref (instance, basetype);
579 assemble_external (vtbl);
582 build_vtable_entry_ref (basetype, vtbl, idx);
584 aref = build_array_ref (vtbl, idx);
589 /* Given an object INSTANCE, return an expression which yields the
590 virtual function corresponding to INDEX. There are many special
591 cases for INSTANCE which we take care of here, mainly to avoid
592 creating extra tree nodes when we don't have to. */
595 build_vfn_ref (ptr_to_instptr, instance, idx)
596 tree *ptr_to_instptr, instance;
599 tree aref = build_vtbl_ref (instance, idx);
601 /* When using thunks, there is no extra delta, and we get the pfn
603 if (flag_vtable_thunks)
608 /* Save the intermediate result in a SAVE_EXPR so we don't have to
609 compute each component of the virtual function pointer twice. */
610 if (TREE_CODE (aref) == INDIRECT_REF)
611 TREE_OPERAND (aref, 0) = save_expr (TREE_OPERAND (aref, 0));
614 = build (PLUS_EXPR, TREE_TYPE (*ptr_to_instptr),
616 cp_convert (ptrdiff_type_node,
617 build_component_ref (aref, delta_identifier, NULL_TREE, 0)));
620 return build_component_ref (aref, pfn_identifier, NULL_TREE, 0);
623 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
624 for the given TYPE. */
627 get_vtable_name (type)
630 tree type_id = build_typename_overload (type);
631 char *buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT)
632 + IDENTIFIER_LENGTH (type_id) + 2);
633 const char *ptr = IDENTIFIER_POINTER (type_id);
635 for (i = 0; ptr[i] == OPERATOR_TYPENAME_FORMAT[i]; i++) ;
637 /* We don't take off the numbers; prepare_fresh_vtable uses the
638 DECL_ASSEMBLER_NAME for the type, which includes the number
639 in `3foo'. If we were to pull them off here, we'd end up with
640 something like `_vt.foo.3bar', instead of a uniform definition. */
641 while (ptr[i] >= '0' && ptr[i] <= '9')
644 sprintf (buf, VTABLE_NAME_FORMAT, ptr+i);
645 return get_identifier (buf);
648 /* Return the offset to the main vtable for a given base BINFO. */
651 get_vfield_offset (binfo)
655 = size_binop (FLOOR_DIV_EXPR,
656 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
657 size_int (BITS_PER_UNIT));
658 tmp = convert (sizetype, tmp);
659 return size_binop (PLUS_EXPR, tmp, BINFO_OFFSET (binfo));
662 /* Get the offset to the start of the original binfo that we derived
663 this binfo from. If we find TYPE first, return the offset only
664 that far. The shortened search is useful because the this pointer
665 on method calling is expected to point to a DECL_CONTEXT (fndecl)
666 object, and not a baseclass of it. */
669 get_derived_offset (binfo, type)
672 tree offset1 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
675 while (BINFO_BASETYPES (binfo)
676 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
678 tree binfos = BINFO_BASETYPES (binfo);
679 if (BINFO_TYPE (binfo) == type)
681 binfo = TREE_VEC_ELT (binfos, i);
683 offset2 = get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo)));
684 return size_binop (MINUS_EXPR, offset1, offset2);
687 /* Update the rtti info for this class. */
690 set_rtti_entry (virtuals, offset, type)
691 tree virtuals, offset, type;
695 if (CLASSTYPE_COM_INTERFACE (type))
699 fn = get_tinfo_fn (type);
701 /* If someone tries to get RTTI information for a type compiled
702 without RTTI, they're out of luck. By calling __pure_virtual
703 in this case, we give a small clue as to what went wrong. We
704 could consider having a __no_typeinfo function as well, for a
705 more specific hint. */
708 if (flag_vtable_thunks)
710 /* The first slot holds the offset. */
711 TREE_PURPOSE (virtuals) = offset;
713 /* The next node holds the function. */
714 virtuals = TREE_CHAIN (virtuals);
715 offset = integer_zero_node;
718 /* This slot holds the function to call. */
719 TREE_PURPOSE (virtuals) = offset;
720 TREE_VALUE (virtuals) = fn;
723 /* Build a virtual function for type TYPE.
724 If BINFO is non-NULL, build the vtable starting with the initial
725 approximation that it is the same as the one which is the head of
726 the association list. */
729 build_vtable (binfo, type)
732 tree name = get_vtable_name (type);
739 virtuals = copy_list (BINFO_VIRTUALS (binfo));
740 decl = build_lang_decl (VAR_DECL, name, TREE_TYPE (BINFO_VTABLE (binfo)));
742 /* Now do rtti stuff. */
743 offset = get_derived_offset (TYPE_BINFO (type), NULL_TREE);
744 offset = ssize_binop (MINUS_EXPR, integer_zero_node, offset);
745 set_rtti_entry (virtuals, offset, type);
749 virtuals = NULL_TREE;
750 decl = build_lang_decl (VAR_DECL, name, void_type_node);
753 #ifdef GATHER_STATISTICS
755 n_vtable_elems += list_length (virtuals);
758 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
759 import_export_vtable (decl, type, 0);
761 decl = pushdecl_top_level (decl);
762 SET_IDENTIFIER_GLOBAL_VALUE (name, decl);
763 /* Initialize the association list for this type, based
764 on our first approximation. */
765 TYPE_BINFO_VTABLE (type) = decl;
766 TYPE_BINFO_VIRTUALS (type) = virtuals;
768 DECL_ARTIFICIAL (decl) = 1;
769 TREE_STATIC (decl) = 1;
770 #ifndef WRITABLE_VTABLES
771 /* Make them READONLY by default. (mrs) */
772 TREE_READONLY (decl) = 1;
774 /* At one time the vtable info was grabbed 2 words at a time. This
775 fails on sparc unless you have 8-byte alignment. (tiemann) */
776 DECL_ALIGN (decl) = MAX (TYPE_ALIGN (double_type_node),
779 DECL_VIRTUAL_P (decl) = 1;
780 DECL_CONTEXT (decl) = type;
782 binfo = TYPE_BINFO (type);
783 SET_BINFO_NEW_VTABLE_MARKED (binfo);
787 extern tree signed_size_zero_node;
789 /* Give TYPE a new virtual function table which is initialized
790 with a skeleton-copy of its original initialization. The only
791 entry that changes is the `delta' entry, so we can really
792 share a lot of structure.
794 FOR_TYPE is the derived type which caused this table to
797 BINFO is the type association which provided TYPE for FOR_TYPE.
799 The order in which vtables are built (by calling this function) for
800 an object must remain the same, otherwise a binary incompatibility
804 prepare_fresh_vtable (binfo, for_type)
805 tree binfo, for_type;
808 tree orig_decl = BINFO_VTABLE (binfo);
821 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (binfo));
823 buf2 = TYPE_ASSEMBLER_NAME_STRING (basetype);
824 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1;
826 /* We know that the vtable that we are going to create doesn't exist
827 yet in the global namespace, and when we finish, it will be
828 pushed into the global namespace. In complex MI hierarchies, we
829 have to loop while the name we are thinking of adding is globally
830 defined, adding more name components to the vtable name as we
831 loop, until the name is unique. This is because in complex MI
832 cases, we might have the same base more than once. This means
833 that the order in which this function is called for vtables must
834 remain the same, otherwise binary compatibility can be
839 char *buf1 = (char *) alloca (TYPE_ASSEMBLER_NAME_LENGTH (for_type)
843 sprintf (buf1, "%s%c%s", TYPE_ASSEMBLER_NAME_STRING (for_type), joiner,
845 buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT) + strlen (buf1) + 1);
846 sprintf (buf, VTABLE_NAME_FORMAT, buf1);
847 name = get_identifier (buf);
849 /* If this name doesn't clash, then we can use it, otherwise
850 we add more to the name until it is unique. */
852 if (! IDENTIFIER_GLOBAL_VALUE (name))
855 /* Set values for next loop through, if the name isn't unique. */
857 path = BINFO_INHERITANCE_CHAIN (path);
859 /* We better not run out of stuff to make it unique. */
860 my_friendly_assert (path != NULL_TREE, 368);
862 basetype = TYPE_MAIN_VARIANT (BINFO_TYPE (path));
864 if (for_type == basetype)
866 /* If we run out of basetypes in the path, we have already
867 found created a vtable with that name before, we now
868 resort to tacking on _%d to distinguish them. */
870 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i + 1 + 3;
871 buf1 = (char *) alloca (i);
873 sprintf (buf1, "%s%c%s%c%d",
874 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner,
876 buf = (char *) alloca (strlen (VTABLE_NAME_FORMAT)
877 + strlen (buf1) + 1);
878 sprintf (buf, VTABLE_NAME_FORMAT, buf1);
879 name = get_identifier (buf);
881 /* If this name doesn't clash, then we can use it,
882 otherwise we add something different to the name until
884 } while (++j <= 999 && IDENTIFIER_GLOBAL_VALUE (name));
886 /* Hey, they really like MI don't they? Increase the 3
887 above to 6, and the 999 to 999999. :-) */
888 my_friendly_assert (j <= 999, 369);
893 i = TYPE_ASSEMBLER_NAME_LENGTH (basetype) + 1 + i;
894 new_buf2 = (char *) alloca (i);
895 sprintf (new_buf2, "%s%c%s",
896 TYPE_ASSEMBLER_NAME_STRING (basetype), joiner, buf2);
900 new_decl = build_lang_decl (VAR_DECL, name, TREE_TYPE (orig_decl));
901 /* Remember which class this vtable is really for. */
902 DECL_CONTEXT (new_decl) = for_type;
904 DECL_ARTIFICIAL (new_decl) = 1;
905 TREE_STATIC (new_decl) = 1;
906 BINFO_VTABLE (binfo) = pushdecl_top_level (new_decl);
907 DECL_VIRTUAL_P (new_decl) = 1;
908 #ifndef WRITABLE_VTABLES
909 /* Make them READONLY by default. (mrs) */
910 TREE_READONLY (new_decl) = 1;
912 DECL_ALIGN (new_decl) = DECL_ALIGN (orig_decl);
914 /* Make fresh virtual list, so we can smash it later. */
915 BINFO_VIRTUALS (binfo) = copy_list (BINFO_VIRTUALS (binfo));
917 if (TREE_VIA_VIRTUAL (binfo))
919 tree binfo1 = binfo_member (BINFO_TYPE (binfo),
920 CLASSTYPE_VBASECLASSES (for_type));
922 /* XXX - This should never happen, if it does, the caller should
923 ensure that the binfo is from for_type's binfos, not from any
924 base type's. We can remove all this code after a while. */
926 warning ("internal inconsistency: binfo offset error for rtti");
928 offset = BINFO_OFFSET (binfo1);
931 offset = BINFO_OFFSET (binfo);
933 set_rtti_entry (BINFO_VIRTUALS (binfo),
934 ssize_binop (MINUS_EXPR, integer_zero_node, offset),
937 #ifdef GATHER_STATISTICS
939 n_vtable_elems += list_length (BINFO_VIRTUALS (binfo));
942 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
943 import_export_vtable (new_decl, for_type, 0);
945 if (TREE_VIA_VIRTUAL (binfo))
946 my_friendly_assert (binfo == binfo_member (BINFO_TYPE (binfo),
947 CLASSTYPE_VBASECLASSES (current_class_type)),
949 SET_BINFO_NEW_VTABLE_MARKED (binfo);
953 /* Access the virtual function table entry that logically
954 contains BASE_FNDECL. VIRTUALS is the virtual function table's
955 initializer. We can run off the end, when dealing with virtual
956 destructors in MI situations, return NULL_TREE in that case. */
959 get_vtable_entry (virtuals, base_fndecl)
960 tree virtuals, base_fndecl;
962 unsigned HOST_WIDE_INT n = (HOST_BITS_PER_WIDE_INT >= BITS_PER_WORD
963 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl))
964 & (((unsigned HOST_WIDE_INT)1<<(BITS_PER_WORD-1))-1))
965 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl)));
967 #ifdef GATHER_STATISTICS
968 n_vtable_searches += n;
971 while (n > 0 && virtuals)
974 virtuals = TREE_CHAIN (virtuals);
980 /* Change the offset for the FNDECL entry to NEW_OFFSET. Also update
981 DECL_VINDEX (FNDECL). */
984 modify_vtable_entry (old_entry_in_list, new_offset, fndecl)
985 tree old_entry_in_list, new_offset, fndecl;
987 tree base_fndecl = TREE_VALUE (old_entry_in_list);
989 /* Update the entry. */
990 TREE_PURPOSE (old_entry_in_list) = new_offset;
991 TREE_VALUE (old_entry_in_list) = fndecl;
993 /* Now assign virtual dispatch information, if unset. We can
994 dispatch this, through any overridden base function. */
995 if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
997 DECL_VINDEX (fndecl) = DECL_VINDEX (base_fndecl);
998 DECL_CONTEXT (fndecl) = DECL_CONTEXT (base_fndecl);
1002 /* Access the virtual function table entry N. VIRTUALS is the virtual
1003 function table's initializer. */
1006 get_vtable_entry_n (virtuals, n)
1008 unsigned HOST_WIDE_INT n;
1013 virtuals = TREE_CHAIN (virtuals);
1018 /* Add a virtual function to all the appropriate vtables for the class
1019 T. DECL_VINDEX(X) should be error_mark_node, if we want to
1020 allocate a new slot in our table. If it is error_mark_node, we
1021 know that no other function from another vtable is overridden by X.
1022 HAS_VIRTUAL keeps track of how many virtuals there are in our main
1023 vtable for the type, and we build upon the PENDING_VIRTUALS list
1027 add_virtual_function (pv, phv, has_virtual, fndecl, t)
1031 tree t; /* Structure type. */
1033 tree pending_virtuals = *pv;
1034 tree pending_hard_virtuals = *phv;
1037 if (current_class_type == 0)
1038 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
1040 if (current_class_type && t != current_class_type)
1041 cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
1045 /* If the virtual function is a redefinition of a prior one,
1046 figure out in which base class the new definition goes,
1047 and if necessary, make a fresh virtual function table
1048 to hold that entry. */
1049 if (DECL_VINDEX (fndecl) == error_mark_node)
1051 /* We remember that this was the base sub-object for rtti. */
1052 CLASSTYPE_RTTI (t) = t;
1054 /* If we are using thunks, use two slots at the front, one
1055 for the offset pointer, one for the tdesc pointer.
1056 For ARM-style vtables, use the same slot for both. */
1057 if (*has_virtual == 0 && ! CLASSTYPE_COM_INTERFACE (t))
1059 if (flag_vtable_thunks)
1065 /* Build a new INT_CST for this DECL_VINDEX. */
1067 static tree index_table[256];
1069 /* We skip a slot for the offset/tdesc entry. */
1070 int i = (*has_virtual)++;
1072 if (i >= 256 || index_table[i] == 0)
1074 idx = build_int_2 (i, 0);
1076 index_table[i] = idx;
1079 idx = index_table[i];
1081 /* Now assign virtual dispatch information. */
1082 DECL_VINDEX (fndecl) = idx;
1083 DECL_CONTEXT (fndecl) = t;
1085 /* Save the state we've computed on the PENDING_VIRTUALS list. */
1086 pending_virtuals = tree_cons (integer_zero_node,
1090 /* Might already be INTEGER_CST if declared twice in class. We will
1091 give error later or we've already given it. */
1092 else if (TREE_CODE (DECL_VINDEX (fndecl)) != INTEGER_CST)
1094 /* Need an entry in some other virtual function table.
1095 Deal with this after we have laid out our virtual base classes. */
1096 pending_hard_virtuals = temp_tree_cons (NULL_TREE,
1098 pending_hard_virtuals);
1100 *pv = pending_virtuals;
1101 *phv = pending_hard_virtuals;
1104 /* Obstack on which to build the vector of class methods. */
1105 struct obstack class_obstack;
1106 extern struct obstack *current_obstack;
1108 /* These are method vectors that were too small for the number of
1109 methods in some class, and so were abandoned. */
1110 static tree free_method_vecs;
1112 /* Returns a method vector with enough room for N methods. N should
1113 be a power of two. */
1122 for (t = &free_method_vecs; *t; t = &(TREE_CHAIN (*t)))
1123 /* Note that we don't use >= n here because we don't want to
1124 allocate a very large vector where it isn't needed. */
1125 if (TREE_VEC_LENGTH (*t) == n)
1128 *t = TREE_CHAIN (new_vec);
1129 TREE_CHAIN (new_vec) = NULL_TREE;
1130 bzero ((PTR) &TREE_VEC_ELT (new_vec, 0), n * sizeof (tree));
1134 new_vec = make_tree_vec (n);
1138 /* Free the method vector VEC. */
1141 free_method_vec (vec)
1144 TREE_CHAIN (vec) = free_method_vecs;
1145 free_method_vecs = vec;
1148 /* Add method METHOD to class TYPE.
1150 If non-NULL, FIELDS is the entry in the METHOD_VEC vector entry of
1151 the class type where the method should be added. */
1154 add_method (type, fields, method)
1155 tree type, *fields, method;
1157 push_permanent_obstack ();
1159 /* Setting the DECL_CONTEXT and DECL_CLASS_CONTEXT here is probably
1161 DECL_CONTEXT (method) = type;
1162 DECL_CLASS_CONTEXT (method) = type;
1164 if (fields && *fields)
1165 *fields = build_overload (method, *fields);
1172 if (!CLASSTYPE_METHOD_VEC (type))
1173 /* Make a new method vector. We start with 8 entries. We must
1174 allocate at least two (for constructors and destructors), and
1175 we're going to end up with an assignment operator at some
1178 We could use a TREE_LIST for now, and convert it to a
1179 TREE_VEC in finish_struct, but we would probably waste more
1180 memory making the links in the list than we would by
1181 over-allocating the size of the vector here. Furthermore,
1182 we would complicate all the code that expects this to be a
1183 vector. We keep a free list of vectors that we outgrew so
1184 that we don't really waste any memory. */
1185 CLASSTYPE_METHOD_VEC (type) = make_method_vec (8);
1187 method_vec = CLASSTYPE_METHOD_VEC (type);
1188 len = TREE_VEC_LENGTH (method_vec);
1190 if (DECL_NAME (method) == constructor_name (type))
1191 /* A new constructor or destructor. Constructors go in
1192 slot 0; destructors go in slot 1. */
1193 slot = DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (method)) ? 1 : 0;
1196 /* See if we already have an entry with this name. */
1197 for (slot = 2; slot < len; ++slot)
1198 if (!TREE_VEC_ELT (method_vec, slot)
1199 || (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec,
1201 == DECL_NAME (method)))
1206 /* We need a bigger method vector. */
1207 tree new_vec = make_method_vec (2 * len);
1208 bcopy ((PTR) &TREE_VEC_ELT (method_vec, 0),
1209 (PTR) &TREE_VEC_ELT (new_vec, 0),
1210 len * sizeof (tree));
1211 free_method_vec (method_vec);
1213 method_vec = CLASSTYPE_METHOD_VEC (type) = new_vec;
1216 if (DECL_CONV_FN_P (method) && !TREE_VEC_ELT (method_vec, slot))
1218 /* Type conversion operators have to come before
1219 ordinary methods; add_conversions depends on this to
1220 speed up looking for conversion operators. So, if
1221 necessary, we slide some of the vector elements up.
1222 In theory, this makes this algorithm O(N^2) but we
1223 don't expect many conversion operators. */
1224 for (slot = 2; slot < len; ++slot)
1226 tree fn = TREE_VEC_ELT (method_vec, slot);
1229 /* There are no more entries in the vector, so we
1230 can insert the new conversion operator here. */
1233 if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
1234 /* We can insert the new function right at the
1239 if (!TREE_VEC_ELT (method_vec, slot))
1240 /* There is nothing in the Ith slot, so we can avoid
1245 /* We know the last slot in the vector is empty
1246 because we know that at this point there's room
1247 for a new function. */
1248 bcopy ((PTR) &TREE_VEC_ELT (method_vec, slot),
1249 (PTR) &TREE_VEC_ELT (method_vec, slot + 1),
1250 (len - slot - 1) * sizeof (tree));
1251 TREE_VEC_ELT (method_vec, slot) = NULL_TREE;
1256 if (template_class_depth (type))
1257 /* TYPE is a template class. Don't issue any errors now; wait
1258 until instantiation time to complain. */
1264 /* Check to see if we've already got this method. */
1265 for (fns = TREE_VEC_ELT (method_vec, slot);
1267 fns = OVL_NEXT (fns))
1269 tree fn = OVL_CURRENT (fns);
1271 if (TREE_CODE (fn) != TREE_CODE (method))
1274 if (TREE_CODE (method) != TEMPLATE_DECL)
1276 /* [over.load] Member function declarations with the
1277 same name and the same parameter types cannot be
1278 overloaded if any of them is a static member
1279 function declaration. */
1280 if (DECL_STATIC_FUNCTION_P (fn)
1281 != DECL_STATIC_FUNCTION_P (method))
1283 tree parms1 = TYPE_ARG_TYPES (TREE_TYPE (fn));
1284 tree parms2 = TYPE_ARG_TYPES (TREE_TYPE (method));
1286 if (! DECL_STATIC_FUNCTION_P (fn))
1287 parms1 = TREE_CHAIN (parms1);
1289 parms2 = TREE_CHAIN (parms2);
1291 if (compparms (parms1, parms2))
1292 cp_error ("`%#D' and `%#D' cannot be overloaded",
1296 /* Since this is an ordinary function in a
1297 non-template class, it's mangled name can be used
1298 as a unique identifier. This technique is only
1299 an optimization; we would get the same results if
1300 we just used decls_match here. */
1301 if (DECL_ASSEMBLER_NAME (fn)
1302 != DECL_ASSEMBLER_NAME (method))
1305 else if (!decls_match (fn, method))
1308 /* There has already been a declaration of this method
1309 or member template. */
1310 cp_error_at ("`%D' has already been declared in `%T'",
1313 /* We don't call duplicate_decls here to merge the
1314 declarations because that will confuse things if the
1315 methods have inline definitions. In particular, we
1316 will crash while processing the definitions. */
1321 /* Actually insert the new method. */
1322 TREE_VEC_ELT (method_vec, slot)
1323 = build_overload (method, TREE_VEC_ELT (method_vec, slot));
1325 /* Add the new binding. */
1326 if (!DECL_CONSTRUCTOR_P (method)
1327 && !DECL_DESTRUCTOR_P (method))
1328 push_class_level_binding (DECL_NAME (method),
1329 TREE_VEC_ELT (method_vec, slot));
1334 /* Subroutines of finish_struct. */
1336 /* Look through the list of fields for this struct, deleting
1337 duplicates as we go. This must be recursive to handle
1340 FIELD is the field which may not appear anywhere in FIELDS.
1341 FIELD_PTR, if non-null, is the starting point at which
1342 chained deletions may take place.
1343 The value returned is the first acceptable entry found
1346 Note that anonymous fields which are not of UNION_TYPE are
1347 not duplicates, they are just anonymous fields. This happens
1348 when we have unnamed bitfields, for example. */
1351 delete_duplicate_fields_1 (field, fields)
1356 if (DECL_NAME (field) == 0)
1358 if (! ANON_AGGR_TYPE_P (TREE_TYPE (field)))
1361 for (x = TYPE_FIELDS (TREE_TYPE (field)); x; x = TREE_CHAIN (x))
1362 fields = delete_duplicate_fields_1 (x, fields);
1367 for (x = fields; x; prev = x, x = TREE_CHAIN (x))
1369 if (DECL_NAME (x) == 0)
1371 if (! ANON_AGGR_TYPE_P (TREE_TYPE (x)))
1373 TYPE_FIELDS (TREE_TYPE (x))
1374 = delete_duplicate_fields_1 (field, TYPE_FIELDS (TREE_TYPE (x)));
1375 if (TYPE_FIELDS (TREE_TYPE (x)) == 0)
1378 fields = TREE_CHAIN (fields);
1380 TREE_CHAIN (prev) = TREE_CHAIN (x);
1385 if (DECL_NAME (field) == DECL_NAME (x))
1387 if (TREE_CODE (field) == CONST_DECL
1388 && TREE_CODE (x) == CONST_DECL)
1389 cp_error_at ("duplicate enum value `%D'", x);
1390 else if (TREE_CODE (field) == CONST_DECL
1391 || TREE_CODE (x) == CONST_DECL)
1392 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1394 else if (DECL_DECLARES_TYPE_P (field)
1395 && DECL_DECLARES_TYPE_P (x))
1397 if (same_type_p (TREE_TYPE (field), TREE_TYPE (x)))
1399 cp_error_at ("duplicate nested type `%D'", x);
1401 else if (DECL_DECLARES_TYPE_P (field)
1402 || DECL_DECLARES_TYPE_P (x))
1404 /* Hide tag decls. */
1405 if ((TREE_CODE (field) == TYPE_DECL
1406 && DECL_ARTIFICIAL (field))
1407 || (TREE_CODE (x) == TYPE_DECL
1408 && DECL_ARTIFICIAL (x)))
1410 cp_error_at ("duplicate field `%D' (as type and non-type)",
1414 cp_error_at ("duplicate member `%D'", x);
1416 fields = TREE_CHAIN (fields);
1418 TREE_CHAIN (prev) = TREE_CHAIN (x);
1427 delete_duplicate_fields (fields)
1431 for (x = fields; x && TREE_CHAIN (x); x = TREE_CHAIN (x))
1432 TREE_CHAIN (x) = delete_duplicate_fields_1 (x, TREE_CHAIN (x));
1435 /* Change the access of FDECL to ACCESS in T. The access to FDECL is
1436 along the path given by BINFO. Return 1 if change was legit,
1437 otherwise return 0. */
1440 alter_access (t, binfo, fdecl, access)
1446 tree elem = purpose_member (t, DECL_ACCESS (fdecl));
1449 if (TREE_VALUE (elem) != access)
1451 if (TREE_CODE (TREE_TYPE (fdecl)) == FUNCTION_DECL)
1452 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl));
1454 error ("conflicting access specifications for field `%s', ignored",
1455 IDENTIFIER_POINTER (DECL_NAME (fdecl)));
1459 /* They're changing the access to the same thing they changed
1460 it to before. That's OK. */
1466 enforce_access (binfo, fdecl);
1467 DECL_ACCESS (fdecl) = tree_cons (t, access, DECL_ACCESS (fdecl));
1473 /* Process the USING_DECL, which is a member of T. The METHOD_VEC, if
1474 non-NULL, is the methods of T. The FIELDS are the fields of T. */
1477 handle_using_decl (using_decl, t, method_vec, fields)
1483 tree ctype = DECL_INITIAL (using_decl);
1484 tree name = DECL_NAME (using_decl);
1486 = TREE_PRIVATE (using_decl) ? access_private_node
1487 : TREE_PROTECTED (using_decl) ? access_protected_node
1488 : access_public_node;
1490 tree flist = NULL_TREE;
1495 binfo = binfo_or_else (ctype, t);
1499 if (name == constructor_name (ctype)
1500 || name == constructor_name_full (ctype))
1502 cp_error_at ("using-declaration for constructor", using_decl);
1506 fdecl = lookup_member (binfo, name, 0, 0);
1510 cp_error_at ("no members matching `%D' in `%#T'", using_decl, ctype);
1514 /* Functions are represented as TREE_LIST, with the purpose
1515 being the type and the value the functions. Other members
1516 come as themselves. */
1517 if (TREE_CODE (fdecl) == TREE_LIST)
1518 /* Ignore base type this came from. */
1519 fdecl = TREE_VALUE (fdecl);
1521 if (TREE_CODE (fdecl) == OVERLOAD)
1523 /* We later iterate over all functions. */
1525 fdecl = OVL_FUNCTION (flist);
1528 name = DECL_NAME (fdecl);
1529 n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
1530 for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); i++)
1531 if (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec, i)))
1534 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
1535 cp_error_at (" because of local method `%#D' with same name",
1536 OVL_CURRENT (TREE_VEC_ELT (method_vec, i)));
1540 if (! DECL_LANG_SPECIFIC (fdecl))
1541 /* We don't currently handle DECL_ACCESS for TYPE_DECLs; just return. */
1544 for (tmp = fields; tmp; tmp = TREE_CHAIN (tmp))
1545 if (DECL_NAME (tmp) == name)
1547 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl, t);
1548 cp_error_at (" because of local field `%#D' with same name", tmp);
1552 /* Make type T see field decl FDECL with access ACCESS.*/
1557 if (alter_access (t, binfo, OVL_FUNCTION (flist),
1560 flist = OVL_CHAIN (flist);
1564 alter_access (t, binfo, fdecl, access);
1570 int max_has_virtual;
1574 char cant_have_default_ctor;
1575 char cant_have_const_ctor;
1576 char no_const_asn_ref;
1579 /* Record information about type T derived from its base classes.
1580 Store most of that information in T itself, and place the
1581 remaining information in the struct BASE_INFO.
1583 Propagate basetype offsets throughout the lattice. Note that the
1584 lattice topped by T is really a pair: it's a DAG that gives the
1585 structure of the derivation hierarchy, and it's a list of the
1586 virtual baseclasses that appear anywhere in the DAG. When a vbase
1587 type appears in the DAG, it's offset is 0, and it's children start
1588 their offsets from that point. When a vbase type appears in the list,
1589 its offset is the offset it has in the hierarchy, and its children's
1590 offsets include that offset in theirs.
1592 Returns the index of the first base class to have virtual functions,
1593 or -1 if no such base class. */
1596 finish_base_struct (t, b)
1598 struct base_info *b;
1600 tree binfos = TYPE_BINFO_BASETYPES (t);
1601 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
1602 int first_vfn_base_index = -1;
1603 bzero ((char *) b, sizeof (struct base_info));
1605 for (i = 0; i < n_baseclasses; i++)
1607 tree base_binfo = TREE_VEC_ELT (binfos, i);
1608 tree basetype = BINFO_TYPE (base_binfo);
1610 /* Effective C++ rule 14. We only need to check TYPE_VIRTUAL_P
1611 here because the case of virtual functions but non-virtual
1612 dtor is handled in finish_struct_1. */
1613 if (warn_ecpp && ! TYPE_VIRTUAL_P (basetype)
1614 && TYPE_HAS_DESTRUCTOR (basetype))
1615 cp_warning ("base class `%#T' has a non-virtual destructor", basetype);
1617 /* If the type of basetype is incomplete, then
1618 we already complained about that fact
1619 (and we should have fixed it up as well). */
1620 if (TYPE_SIZE (basetype) == 0)
1623 /* The base type is of incomplete type. It is
1624 probably best to pretend that it does not
1626 if (i == n_baseclasses-1)
1627 TREE_VEC_ELT (binfos, i) = NULL_TREE;
1628 TREE_VEC_LENGTH (binfos) -= 1;
1630 for (j = i; j+1 < n_baseclasses; j++)
1631 TREE_VEC_ELT (binfos, j) = TREE_VEC_ELT (binfos, j+1);
1634 if (! TYPE_HAS_CONST_INIT_REF (basetype))
1635 b->cant_have_const_ctor = 1;
1637 if (TYPE_HAS_CONSTRUCTOR (basetype)
1638 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype))
1640 b->cant_have_default_ctor = 1;
1641 if (! TYPE_HAS_CONSTRUCTOR (t))
1643 cp_pedwarn ("base `%T' with only non-default constructor",
1645 cp_pedwarn ("in class without a constructor");
1649 if (TYPE_HAS_ASSIGN_REF (basetype)
1650 && !TYPE_HAS_CONST_ASSIGN_REF (basetype))
1651 b->no_const_asn_ref = 1;
1653 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (basetype);
1654 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (basetype);
1655 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype);
1656 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (basetype);
1658 TYPE_OVERLOADS_CALL_EXPR (t) |= TYPE_OVERLOADS_CALL_EXPR (basetype);
1659 TYPE_OVERLOADS_ARRAY_REF (t) |= TYPE_OVERLOADS_ARRAY_REF (basetype);
1660 TYPE_OVERLOADS_ARROW (t) |= TYPE_OVERLOADS_ARROW (basetype);
1662 if (CLASSTYPE_COM_INTERFACE (basetype))
1664 CLASSTYPE_COM_INTERFACE (t) = 1;
1667 ("COM interface type `%T' must be the leftmost base class",
1670 else if (CLASSTYPE_COM_INTERFACE (t) && i == 0)
1672 cp_error ("COM interface type `%T' with non-COM base class `%T'",
1674 CLASSTYPE_COM_INTERFACE (t) = 0;
1677 if (TYPE_VIRTUAL_P (basetype))
1679 /* Ensure that this is set from at least a virtual base
1681 if (b->rtti == NULL_TREE)
1682 b->rtti = CLASSTYPE_RTTI (basetype);
1684 /* Don't borrow virtuals from virtual baseclasses. */
1685 if (TREE_VIA_VIRTUAL (base_binfo))
1688 if (first_vfn_base_index < 0)
1691 first_vfn_base_index = i;
1693 /* Update these two, now that we know what vtable we are
1694 going to extend. This is so that we can add virtual
1695 functions, and override them properly. */
1696 TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
1697 TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
1698 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1699 b->vfield = CLASSTYPE_VFIELD (basetype);
1700 b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
1701 vfields = b->vfields;
1704 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1705 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1707 tree value = VF_BASETYPE_VALUE (vfields);
1708 if (DECL_NAME (CLASSTYPE_VFIELD (value))
1709 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1710 VF_NORMAL_VALUE (b->vfields) = basetype;
1712 VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
1714 vfields = TREE_CHAIN (vfields);
1716 CLASSTYPE_VFIELD (t) = b->vfield;
1720 /* Only add unique vfields, and flatten them out as we go. */
1721 tree vfields = CLASSTYPE_VFIELDS (basetype);
1724 if (VF_BINFO_VALUE (vfields) == NULL_TREE
1725 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
1727 tree value = VF_BASETYPE_VALUE (vfields);
1728 b->vfields = tree_cons (base_binfo, value, b->vfields);
1729 if (DECL_NAME (CLASSTYPE_VFIELD (value))
1730 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1731 VF_NORMAL_VALUE (b->vfields) = basetype;
1733 VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
1735 vfields = TREE_CHAIN (vfields);
1738 if (b->has_virtual == 0)
1740 first_vfn_base_index = i;
1742 /* Update these two, now that we know what vtable we are
1743 going to extend. This is so that we can add virtual
1744 functions, and override them properly. */
1745 TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
1746 TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
1747 b->has_virtual = CLASSTYPE_VSIZE (basetype);
1748 b->vfield = CLASSTYPE_VFIELD (basetype);
1749 CLASSTYPE_VFIELD (t) = b->vfield;
1750 /* When we install the first one, set the VF_NORMAL_VALUE
1751 to be the current class, as this it is the most derived
1752 class. Hopefully, this is not set to something else
1754 vfields = b->vfields;
1757 if (DECL_NAME (CLASSTYPE_VFIELD (t))
1758 == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
1760 VF_NORMAL_VALUE (vfields) = t;
1761 /* There should only be one of them! And it should
1762 always be found, if we get into here. (mrs) */
1765 vfields = TREE_CHAIN (vfields);
1774 /* Find the base class with the largest number of virtual functions. */
1775 for (vfields = b->vfields; vfields; vfields = TREE_CHAIN (vfields))
1777 if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual)
1778 b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields));
1779 if (VF_DERIVED_VALUE (vfields)
1780 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
1781 b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
1786 /* If all virtual functions come only from virtual baseclasses. */
1789 /* Update the rtti base if we have a non-virtual base class version
1791 b->rtti = CLASSTYPE_RTTI (BINFO_TYPE (TREE_VEC_ELT (binfos, first_vfn_base_index)));
1793 return first_vfn_base_index;
1796 /* Set memoizing fields and bits of T (and its variants) for later use.
1797 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1800 finish_struct_bits (t, max_has_virtual)
1802 int max_has_virtual;
1804 int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
1806 /* Fix up variants (if any). */
1807 tree variants = TYPE_NEXT_VARIANT (t);
1810 /* These fields are in the _TYPE part of the node, not in
1811 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1812 TYPE_HAS_CONSTRUCTOR (variants) = TYPE_HAS_CONSTRUCTOR (t);
1813 TYPE_HAS_DESTRUCTOR (variants) = TYPE_HAS_DESTRUCTOR (t);
1814 TYPE_NEEDS_CONSTRUCTING (variants) = TYPE_NEEDS_CONSTRUCTING (t);
1815 TYPE_NEEDS_DESTRUCTOR (variants) = TYPE_NEEDS_DESTRUCTOR (t);
1817 TYPE_USES_COMPLEX_INHERITANCE (variants) = TYPE_USES_COMPLEX_INHERITANCE (t);
1818 TYPE_VIRTUAL_P (variants) = TYPE_VIRTUAL_P (t);
1819 TYPE_USES_VIRTUAL_BASECLASSES (variants) = TYPE_USES_VIRTUAL_BASECLASSES (t);
1820 /* Copy whatever these are holding today. */
1821 TYPE_MIN_VALUE (variants) = TYPE_MIN_VALUE (t);
1822 TYPE_MAX_VALUE (variants) = TYPE_MAX_VALUE (t);
1823 TYPE_FIELDS (variants) = TYPE_FIELDS (t);
1824 TYPE_SIZE (variants) = TYPE_SIZE (t);
1825 TYPE_SIZE_UNIT (variants) = TYPE_SIZE_UNIT (t);
1826 variants = TYPE_NEXT_VARIANT (variants);
1829 if (n_baseclasses && max_has_virtual)
1831 /* For a class w/o baseclasses, `finish_struct' has set
1832 CLASS_TYPE_ABSTRACT_VIRTUALS correctly (by definition). Similarly
1833 for a class who's base classes do not have vtables. When neither
1834 of these is true, we might have removed abstract virtuals (by
1835 providing a definition), added some (by declaring new ones), or
1836 redeclared ones from a base class. We need to recalculate what's
1837 really an abstract virtual at this point (by looking in the
1839 CLASSTYPE_ABSTRACT_VIRTUALS (t) = get_abstract_virtuals (t);
1844 /* Notice whether this class has type conversion functions defined. */
1845 tree binfo = TYPE_BINFO (t);
1846 tree binfos = BINFO_BASETYPES (binfo);
1849 for (i = n_baseclasses-1; i >= 0; i--)
1851 basetype = BINFO_TYPE (TREE_VEC_ELT (binfos, i));
1853 TYPE_HAS_CONVERSION (t) |= TYPE_HAS_CONVERSION (basetype);
1857 /* If this type has a copy constructor, force its mode to be BLKmode, and
1858 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1859 be passed by invisible reference and prevent it from being returned in
1862 Also do this if the class has BLKmode but can still be returned in
1863 registers, since function_cannot_inline_p won't let us inline
1864 functions returning such a type. This affects the HP-PA. */
1865 if (! TYPE_HAS_TRIVIAL_INIT_REF (t)
1866 || (TYPE_MODE (t) == BLKmode && ! aggregate_value_p (t)
1867 && CLASSTYPE_NON_AGGREGATE (t)))
1870 DECL_MODE (TYPE_MAIN_DECL (t)) = BLKmode;
1871 for (variants = t; variants; variants = TYPE_NEXT_VARIANT (variants))
1873 TYPE_MODE (variants) = BLKmode;
1874 TREE_ADDRESSABLE (variants) = 1;
1879 /* Issue warnings about T having private constructors, but no friends,
1882 HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
1883 static members. HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
1884 non-private static member functions. */
1887 maybe_warn_about_overly_private_class (t)
1890 int has_member_fn = 0;
1891 int has_nonprivate_method = 0;
1894 if (!warn_ctor_dtor_privacy
1895 /* If the class has friends, those entities might create and
1896 access instances, so we should not warn. */
1897 || (CLASSTYPE_FRIEND_CLASSES (t)
1898 || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
1899 /* We will have warned when the template was declared; there's
1900 no need to warn on every instantiation. */
1901 || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
1902 /* There's no reason to even consider warning about this
1906 /* We only issue one warning, if more than one applies, because
1907 otherwise, on code like:
1910 // Oops - forgot `public:'
1916 we warn several times about essentially the same problem. */
1918 /* Check to see if all (non-constructor, non-destructor) member
1919 functions are private. (Since there are no friends or
1920 non-private statics, we can't ever call any of the private member
1922 for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
1923 /* We're not interested in compiler-generated methods; they don't
1924 provide any way to call private members. */
1925 if (!DECL_ARTIFICIAL (fn))
1927 if (!TREE_PRIVATE (fn))
1929 if (DECL_STATIC_FUNCTION_P (fn))
1930 /* A non-private static member function is just like a
1931 friend; it can create and invoke private member
1932 functions, and be accessed without a class
1936 has_nonprivate_method = 1;
1939 else if (!DECL_CONSTRUCTOR_P (fn) && !DECL_DESTRUCTOR_P (fn))
1943 if (!has_nonprivate_method && has_member_fn)
1945 /* There are no non-private methods, and there's at least one
1946 private member function that isn't a constructor or
1947 destructor. (If all the private members are
1948 constructors/destructors we want to use the code below that
1949 issues error messages specifically referring to
1950 constructors/destructors.) */
1952 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
1953 for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); i++)
1954 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
1955 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
1957 has_nonprivate_method = 1;
1960 if (!has_nonprivate_method)
1962 cp_warning ("all member functions in class `%T' are private", t);
1967 /* Even if some of the member functions are non-private, the class
1968 won't be useful for much if all the constructors or destructors
1969 are private: such an object can never be created or destroyed. */
1970 if (TYPE_HAS_DESTRUCTOR (t))
1972 tree dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1);
1974 if (TREE_PRIVATE (dtor))
1976 cp_warning ("`%#T' only defines a private destructor and has no friends",
1982 if (TYPE_HAS_CONSTRUCTOR (t))
1984 int nonprivate_ctor = 0;
1986 /* If a non-template class does not define a copy
1987 constructor, one is defined for it, enabling it to avoid
1988 this warning. For a template class, this does not
1989 happen, and so we would normally get a warning on:
1991 template <class T> class C { private: C(); };
1993 To avoid this asymmetry, we check TYPE_HAS_INIT_REF. All
1994 complete non-template or fully instantiated classes have this
1996 if (!TYPE_HAS_INIT_REF (t))
1997 nonprivate_ctor = 1;
1999 for (fn = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 0);
2003 tree ctor = OVL_CURRENT (fn);
2004 /* Ideally, we wouldn't count copy constructors (or, in
2005 fact, any constructor that takes an argument of the
2006 class type as a parameter) because such things cannot
2007 be used to construct an instance of the class unless
2008 you already have one. But, for now at least, we're
2010 if (! TREE_PRIVATE (ctor))
2012 nonprivate_ctor = 1;
2017 if (nonprivate_ctor == 0)
2019 cp_warning ("`%#T' only defines private constructors and has no friends",
2026 /* Function to help qsort sort FIELD_DECLs by name order. */
2029 field_decl_cmp (x, y)
2032 if (DECL_NAME (*x) == DECL_NAME (*y))
2034 if (DECL_NAME (*x) == NULL_TREE)
2036 if (DECL_NAME (*y) == NULL_TREE)
2038 if (DECL_NAME (*x) < DECL_NAME (*y))
2043 /* Comparison function to compare two TYPE_METHOD_VEC entries by name. */
2046 method_name_cmp (m1, m2)
2047 const tree *m1, *m2;
2049 if (*m1 == NULL_TREE && *m2 == NULL_TREE)
2051 if (*m1 == NULL_TREE)
2053 if (*m2 == NULL_TREE)
2055 if (DECL_NAME (OVL_CURRENT (*m1)) < DECL_NAME (OVL_CURRENT (*m2)))
2060 /* Warn about duplicate methods in fn_fields. Also compact method
2061 lists so that lookup can be made faster.
2063 Data Structure: List of method lists. The outer list is a
2064 TREE_LIST, whose TREE_PURPOSE field is the field name and the
2065 TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN
2066 links the entire list of methods for TYPE_METHODS. Friends are
2067 chained in the same way as member functions (? TREE_CHAIN or
2068 DECL_CHAIN), but they live in the TREE_TYPE field of the outer
2069 list. That allows them to be quickly deleted, and requires no
2072 If there are any constructors/destructors, they are moved to the
2073 front of the list. This makes pushclass more efficient.
2075 @@ The above comment is obsolete. It mostly describes what add_method
2076 @@ and add_implicitly_declared_members do.
2078 Sort methods that are not special (i.e., constructors, destructors, and
2079 type conversion operators) so that we can find them faster in search. */
2082 finish_struct_methods (t)
2086 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2087 tree ctor_name = constructor_name (t);
2088 int slot, len = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
2090 /* First fill in entry 0 with the constructors, entry 1 with destructors,
2091 and the next few with type conversion operators (if any). */
2092 for (fn_fields = TYPE_METHODS (t); fn_fields;
2093 fn_fields = TREE_CHAIN (fn_fields))
2095 tree fn_name = DECL_NAME (fn_fields);
2097 /* Clear out this flag.
2099 @@ Doug may figure out how to break
2100 @@ this with nested classes and friends. */
2101 DECL_IN_AGGR_P (fn_fields) = 0;
2103 /* Note here that a copy ctor is private, so we don't dare generate
2104 a default copy constructor for a class that has a member
2105 of this type without making sure they have access to it. */
2106 if (fn_name == ctor_name)
2108 tree parmtypes = FUNCTION_ARG_CHAIN (fn_fields);
2109 tree parmtype = parmtypes ? TREE_VALUE (parmtypes) : void_type_node;
2111 if (TREE_CODE (parmtype) == REFERENCE_TYPE
2112 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype)) == t)
2114 if (TREE_CHAIN (parmtypes) == NULL_TREE
2115 || TREE_CHAIN (parmtypes) == void_list_node
2116 || TREE_PURPOSE (TREE_CHAIN (parmtypes)))
2118 if (TREE_PROTECTED (fn_fields))
2119 TYPE_HAS_NONPUBLIC_CTOR (t) = 1;
2120 else if (TREE_PRIVATE (fn_fields))
2121 TYPE_HAS_NONPUBLIC_CTOR (t) = 2;
2125 else if (fn_name == ansi_opname[(int) MODIFY_EXPR])
2127 tree parmtype = TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields));
2129 if (copy_assignment_arg_p (parmtype, DECL_VIRTUAL_P (fn_fields)))
2131 if (TREE_PROTECTED (fn_fields))
2132 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 1;
2133 else if (TREE_PRIVATE (fn_fields))
2134 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t) = 2;
2139 if (TYPE_HAS_DESTRUCTOR (t) && !TREE_VEC_ELT (method_vec, 1))
2140 /* We thought there was a destructor, but there wasn't. Some
2141 parse errors cause this anomalous situation. */
2142 TYPE_HAS_DESTRUCTOR (t) = 0;
2144 /* Issue warnings about private constructors and such. If there are
2145 no methods, then some public defaults are generated. */
2146 maybe_warn_about_overly_private_class (t);
2148 if (method_vec == NULL_TREE)
2151 /* Now sort the methods. */
2152 while (len > 2 && TREE_VEC_ELT (method_vec, len-1) == NULL_TREE)
2154 TREE_VEC_LENGTH (method_vec) = len;
2156 /* The type conversion ops have to live at the front of the vec, so we
2158 for (slot = 2; slot < len; ++slot)
2160 tree fn = TREE_VEC_ELT (method_vec, slot);
2162 if (!DECL_CONV_FN_P (OVL_CURRENT (fn)))
2166 qsort (&TREE_VEC_ELT (method_vec, slot), len-slot, sizeof (tree),
2167 (int (*)(const void *, const void *))method_name_cmp);
2170 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2173 duplicate_tag_error (t)
2176 cp_error ("redefinition of `%#T'", t);
2177 cp_error_at ("previous definition here", t);
2179 /* Pretend we haven't defined this type. */
2181 /* All of the component_decl's were TREE_CHAINed together in the parser.
2182 finish_struct_methods walks these chains and assembles all methods with
2183 the same base name into DECL_CHAINs. Now we don't need the parser chains
2184 anymore, so we unravel them. */
2186 /* This used to be in finish_struct, but it turns out that the
2187 TREE_CHAIN is used by dbxout_type_methods and perhaps some other
2189 if (CLASSTYPE_METHOD_VEC (t))
2191 tree method_vec = CLASSTYPE_METHOD_VEC (t);
2192 int i, len = TREE_VEC_LENGTH (method_vec);
2193 for (i = 0; i < len; i++)
2195 tree unchain = TREE_VEC_ELT (method_vec, i);
2196 while (unchain != NULL_TREE)
2198 TREE_CHAIN (OVL_CURRENT (unchain)) = NULL_TREE;
2199 unchain = OVL_NEXT (unchain);
2204 if (TYPE_LANG_SPECIFIC (t))
2206 tree binfo = TYPE_BINFO (t);
2207 int interface_only = CLASSTYPE_INTERFACE_ONLY (t);
2208 int interface_unknown = CLASSTYPE_INTERFACE_UNKNOWN (t);
2209 tree template_info = CLASSTYPE_TEMPLATE_INFO (t);
2210 int use_template = CLASSTYPE_USE_TEMPLATE (t);
2212 bzero ((char *) TYPE_LANG_SPECIFIC (t), sizeof (struct lang_type));
2213 BINFO_BASETYPES(binfo) = NULL_TREE;
2215 TYPE_BINFO (t) = binfo;
2216 CLASSTYPE_INTERFACE_ONLY (t) = interface_only;
2217 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, interface_unknown);
2218 TYPE_REDEFINED (t) = 1;
2219 CLASSTYPE_TEMPLATE_INFO (t) = template_info;
2220 CLASSTYPE_USE_TEMPLATE (t) = use_template;
2222 TYPE_SIZE (t) = NULL_TREE;
2223 TYPE_MODE (t) = VOIDmode;
2224 TYPE_FIELDS (t) = NULL_TREE;
2225 TYPE_METHODS (t) = NULL_TREE;
2226 TYPE_VFIELD (t) = NULL_TREE;
2227 TYPE_CONTEXT (t) = NULL_TREE;
2228 TYPE_NONCOPIED_PARTS (t) = NULL_TREE;
2231 /* Construct the initializer for BINFOs virtual function table. */
2234 build_vtbl_initializer (binfo)
2237 tree v = BINFO_VIRTUALS (binfo);
2238 tree inits = NULL_TREE;
2240 /* Process the RTTI stuff at the head of the list. If we're not
2241 using vtable thunks, then the RTTI entry is just an ordinary
2242 function, and we can process it just like the other virtual
2243 function entries. */
2244 if (!CLASSTYPE_COM_INTERFACE (BINFO_TYPE (binfo))
2245 && flag_vtable_thunks)
2250 /* The first entry is an offset. */
2251 offset = TREE_PURPOSE (v);
2252 my_friendly_assert (TREE_CODE (offset) == INTEGER_CST,
2255 /* Convert the offset to look like a function pointer, so that
2256 we can put it in the vtable. */
2257 init = build1 (NOP_EXPR, vfunc_ptr_type_node, offset);
2258 TREE_CONSTANT (init) = 1;
2259 init = build_vtable_entry (integer_zero_node, init);
2260 inits = tree_cons (NULL_TREE, init, inits);
2262 /* Even in this case, the second entry (the tdesc pointer) is
2263 just an ordinary function. */
2267 /* Go through all the ordinary virtual functions, building up
2275 /* Pull the offset for `this', and the function to call, out of
2277 delta = TREE_PURPOSE (v);
2278 fn = TREE_VALUE (v);
2279 my_friendly_assert (TREE_CODE (delta) == INTEGER_CST, 19990727);
2280 my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 19990727);
2282 /* You can't call an abstract virtual function; it's abstract.
2283 So, we replace these functions with __pure_virtual. */
2284 if (DECL_ABSTRACT_VIRTUAL_P (fn))
2287 /* Package up that information for the vtable. */
2288 init = build_vtable_entry_for_fn (delta, fn);
2289 /* And add it to the chain of initializers. */
2290 inits = tree_cons (NULL_TREE, init, inits);
2296 /* The initializers were built up in reverse order; straighten them
2298 inits = nreverse (inits);
2299 /* Package all the initializers up as an array initializer. */
2300 return build_nt (CONSTRUCTOR, NULL_TREE, inits);
2303 /* finish up all new vtables. */
2306 finish_vtbls (binfo, do_self, t)
2311 tree binfos = BINFO_BASETYPES (binfo);
2312 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2314 /* Should we use something besides CLASSTYPE_VFIELDS? */
2315 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2317 if (BINFO_NEW_VTABLE_MARKED (binfo))
2321 decl = BINFO_VTABLE (binfo);
2322 context = DECL_CONTEXT (decl);
2323 DECL_CONTEXT (decl) = 0;
2324 DECL_INITIAL (decl) = build_vtbl_initializer (binfo);
2325 cp_finish_decl (decl, DECL_INITIAL (decl), NULL_TREE, 0, 0);
2326 DECL_CONTEXT (decl) = context;
2328 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo);
2331 for (i = 0; i < n_baselinks; i++)
2333 tree base_binfo = TREE_VEC_ELT (binfos, i);
2334 int is_not_base_vtable
2335 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2336 if (TREE_VIA_VIRTUAL (base_binfo))
2337 base_binfo = binfo_member (BINFO_TYPE (base_binfo),
2338 CLASSTYPE_VBASECLASSES (t));
2339 finish_vtbls (base_binfo, is_not_base_vtable, t);
2343 /* True if we should override the given BASE_FNDECL with the given
2347 overrides (fndecl, base_fndecl)
2348 tree fndecl, base_fndecl;
2350 /* Destructors have special names. */
2351 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2352 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2354 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl))
2355 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl)))
2357 if (DECL_NAME (fndecl) == DECL_NAME (base_fndecl))
2359 tree types, base_types;
2361 retypes = TREE_TYPE (TREE_TYPE (fndecl));
2362 base_retypes = TREE_TYPE (TREE_TYPE (base_fndecl));
2364 types = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
2365 base_types = TYPE_ARG_TYPES (TREE_TYPE (base_fndecl));
2366 if ((TYPE_QUALS (TREE_TYPE (TREE_VALUE (base_types)))
2367 == TYPE_QUALS (TREE_TYPE (TREE_VALUE (types))))
2368 && compparms (TREE_CHAIN (base_types), TREE_CHAIN (types)))
2375 get_class_offset_1 (parent, binfo, context, t, fndecl)
2376 tree parent, binfo, context, t, fndecl;
2378 tree binfos = BINFO_BASETYPES (binfo);
2379 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2380 tree rval = NULL_TREE;
2382 if (binfo == parent)
2383 return error_mark_node;
2385 for (i = 0; i < n_baselinks; i++)
2387 tree base_binfo = TREE_VEC_ELT (binfos, i);
2390 if (TREE_VIA_VIRTUAL (base_binfo))
2391 base_binfo = binfo_member (BINFO_TYPE (base_binfo),
2392 CLASSTYPE_VBASECLASSES (t));
2393 nrval = get_class_offset_1 (parent, base_binfo, context, t, fndecl);
2394 /* See if we have a new value */
2395 if (nrval && (nrval != error_mark_node || rval==0))
2397 /* Only compare if we have two offsets */
2398 if (rval && rval != error_mark_node
2399 && ! tree_int_cst_equal (nrval, rval))
2401 /* Only give error if the two offsets are different */
2402 error ("every virtual function must have a unique final overrider");
2403 cp_error (" found two (or more) `%T' class subobjects in `%T'", context, t);
2404 cp_error (" with virtual `%D' from virtual base class", fndecl);
2410 if (rval && BINFO_TYPE (binfo) == context)
2412 my_friendly_assert (rval == error_mark_node
2413 || tree_int_cst_equal (rval, BINFO_OFFSET (binfo)), 999);
2414 rval = BINFO_OFFSET (binfo);
2420 /* Get the offset to the CONTEXT subobject that is related to the
2424 get_class_offset (context, t, binfo, fndecl)
2425 tree context, t, binfo, fndecl;
2427 tree first_binfo = binfo;
2432 return integer_zero_node;
2434 if (BINFO_TYPE (binfo) == context)
2435 return BINFO_OFFSET (binfo);
2437 /* Check less derived binfos first. */
2438 while (BINFO_BASETYPES (binfo)
2439 && (i=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo))) != -1)
2441 tree binfos = BINFO_BASETYPES (binfo);
2442 binfo = TREE_VEC_ELT (binfos, i);
2443 if (BINFO_TYPE (binfo) == context)
2444 return BINFO_OFFSET (binfo);
2447 /* Ok, not found in the less derived binfos, now check the more
2449 offset = get_class_offset_1 (first_binfo, TYPE_BINFO (t), context, t, fndecl);
2450 if (offset==0 || TREE_CODE (offset) != INTEGER_CST)
2451 my_friendly_abort (999); /* we have to find it. */
2455 /* Skip RTTI information at the front of the virtual list. */
2457 unsigned HOST_WIDE_INT
2458 skip_rtti_stuff (virtuals, t)
2463 if (CLASSTYPE_COM_INTERFACE (t))
2469 /* We always reserve a slot for the offset/tdesc entry. */
2471 *virtuals = TREE_CHAIN (*virtuals);
2473 if (flag_vtable_thunks && *virtuals)
2475 /* The second slot is reserved for the tdesc pointer when thunks
2478 *virtuals = TREE_CHAIN (*virtuals);
2484 modify_one_vtable (binfo, t, fndecl)
2485 tree binfo, t, fndecl;
2487 tree virtuals = BINFO_VIRTUALS (binfo);
2488 unsigned HOST_WIDE_INT n;
2490 /* update rtti entry */
2493 if (binfo == TYPE_BINFO (t))
2495 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2496 build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t))), t);
2500 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2501 prepare_fresh_vtable (binfo, t);
2504 if (fndecl == NULL_TREE)
2507 n = skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
2511 tree current_fndecl = TREE_VALUE (virtuals);
2513 /* We should never have an instance of __pure_virtual on the
2514 BINFO_VIRTUALS list. If we do, then we will never notice
2515 that the function that should have been there instead has
2517 my_friendly_assert (current_fndecl != abort_fndecl,
2520 if (current_fndecl && overrides (fndecl, current_fndecl))
2522 tree base_offset, offset;
2523 tree context = DECL_CLASS_CONTEXT (fndecl);
2524 tree vfield = CLASSTYPE_VFIELD (t);
2527 offset = get_class_offset (context, t, binfo, fndecl);
2529 /* Find the right offset for the this pointer based on the
2530 base class we just found. We have to take into
2531 consideration the virtual base class pointers that we
2532 stick in before the virtual function table pointer.
2534 Also, we want just the delta between the most base class
2535 that we derived this vfield from and us. */
2536 base_offset = size_binop (PLUS_EXPR,
2537 get_derived_offset (binfo, DECL_CONTEXT (current_fndecl)),
2538 BINFO_OFFSET (binfo));
2539 this_offset = ssize_binop (MINUS_EXPR, offset, base_offset);
2541 if (binfo == TYPE_BINFO (t))
2543 /* In this case, it is *type*'s vtable we are modifying.
2544 We start with the approximation that it's vtable is that
2545 of the immediate base class. */
2546 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2547 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2551 /* This is our very own copy of `basetype' to play with.
2552 Later, we will fill in all the virtual functions
2553 that override the virtual functions in these base classes
2554 which are not defined by the current type. */
2555 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2556 prepare_fresh_vtable (binfo, t);
2560 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo)));
2562 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2567 virtuals = TREE_CHAIN (virtuals);
2571 /* These are the ones that are not through virtual base classes. */
2574 modify_all_direct_vtables (binfo, do_self, t, fndecl)
2579 tree binfos = BINFO_BASETYPES (binfo);
2580 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2582 /* Should we use something besides CLASSTYPE_VFIELDS? */
2583 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2584 modify_one_vtable (binfo, t, fndecl);
2586 for (i = 0; i < n_baselinks; i++)
2588 tree base_binfo = TREE_VEC_ELT (binfos, i);
2589 int is_not_base_vtable
2590 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2591 if (! TREE_VIA_VIRTUAL (base_binfo))
2592 modify_all_direct_vtables (base_binfo, is_not_base_vtable, t, fndecl);
2596 /* Fixup all the delta entries in this one vtable that need updating. */
2599 fixup_vtable_deltas1 (binfo, t)
2602 tree virtuals = BINFO_VIRTUALS (binfo);
2603 unsigned HOST_WIDE_INT n;
2605 n = skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
2609 tree fndecl = TREE_VALUE (virtuals);
2610 tree delta = TREE_PURPOSE (virtuals);
2614 tree base_offset, offset;
2615 tree context = DECL_CLASS_CONTEXT (fndecl);
2616 tree vfield = CLASSTYPE_VFIELD (t);
2619 offset = get_class_offset (context, t, binfo, fndecl);
2621 /* Find the right offset for the this pointer based on the
2622 base class we just found. We have to take into
2623 consideration the virtual base class pointers that we
2624 stick in before the virtual function table pointer.
2626 Also, we want just the delta between the most base class
2627 that we derived this vfield from and us. */
2628 base_offset = size_binop (PLUS_EXPR,
2629 get_derived_offset (binfo,
2630 DECL_CONTEXT (fndecl)),
2631 BINFO_OFFSET (binfo));
2632 this_offset = ssize_binop (MINUS_EXPR, offset, base_offset);
2634 if (! tree_int_cst_equal (this_offset, delta))
2636 /* Make sure we can modify the derived association with immunity. */
2637 if (binfo == TYPE_BINFO (t))
2639 /* In this case, it is *type*'s vtable we are modifying.
2640 We start with the approximation that it's vtable is that
2641 of the immediate base class. */
2642 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2643 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield)), t);
2647 /* This is our very own copy of `basetype' to play with.
2648 Later, we will fill in all the virtual functions
2649 that override the virtual functions in these base classes
2650 which are not defined by the current type. */
2651 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2652 prepare_fresh_vtable (binfo, t);
2655 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo), n),
2661 virtuals = TREE_CHAIN (virtuals);
2665 /* Fixup all the delta entries in all the direct vtables that need updating.
2666 This happens when we have non-overridden virtual functions from a
2667 virtual base class, that are at a different offset, in the new
2668 hierarchy, because the layout of the virtual bases has changed. */
2671 fixup_vtable_deltas (binfo, init_self, t)
2676 tree binfos = BINFO_BASETYPES (binfo);
2677 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2679 for (i = 0; i < n_baselinks; i++)
2681 tree base_binfo = TREE_VEC_ELT (binfos, i);
2682 int is_not_base_vtable
2683 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2684 if (! TREE_VIA_VIRTUAL (base_binfo))
2685 fixup_vtable_deltas (base_binfo, is_not_base_vtable, t);
2687 /* Should we use something besides CLASSTYPE_VFIELDS? */
2688 if (init_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2689 fixup_vtable_deltas1 (binfo, t);
2692 /* These are the ones that are through virtual base classes. */
2695 modify_all_indirect_vtables (binfo, do_self, via_virtual, t, fndecl)
2697 int do_self, via_virtual;
2700 tree binfos = BINFO_BASETYPES (binfo);
2701 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2703 /* Should we use something besides CLASSTYPE_VFIELDS? */
2704 if (do_self && via_virtual && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2705 modify_one_vtable (binfo, t, fndecl);
2707 for (i = 0; i < n_baselinks; i++)
2709 tree base_binfo = TREE_VEC_ELT (binfos, i);
2710 int is_not_base_vtable
2711 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2712 if (TREE_VIA_VIRTUAL (base_binfo))
2715 base_binfo = binfo_member (BINFO_TYPE (base_binfo), CLASSTYPE_VBASECLASSES (t));
2717 modify_all_indirect_vtables (base_binfo, is_not_base_vtable, via_virtual, t, fndecl);
2722 modify_all_vtables (t, fndecl)
2726 /* Do these first, so that we will make use of any non-virtual class's
2727 vtable, over a virtual classes vtable. */
2728 modify_all_direct_vtables (TYPE_BINFO (t), 1, t, fndecl);
2729 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
2730 modify_all_indirect_vtables (TYPE_BINFO (t), 1, 0, t, fndecl);
2733 /* Here, we already know that they match in every respect.
2734 All we have to check is where they had their declarations. */
2737 strictly_overrides (fndecl1, fndecl2)
2738 tree fndecl1, fndecl2;
2740 int distance = get_base_distance (DECL_CLASS_CONTEXT (fndecl2),
2741 DECL_CLASS_CONTEXT (fndecl1),
2743 if (distance == -2 || distance > 0)
2748 /* Merge overrides for one vtable.
2749 If we want to merge in same function, we are fine.
2751 if one has a DECL_CLASS_CONTEXT that is a parent of the
2752 other, than choose the more derived one
2754 potentially ill-formed (see 10.3 [class.virtual])
2755 we have to check later to see if there was an
2756 override in this class. If there was ok, if not
2757 then it is ill-formed. (mrs)
2759 We take special care to reuse a vtable, if we can. */
2762 override_one_vtable (binfo, old, t)
2765 tree virtuals = BINFO_VIRTUALS (binfo);
2766 tree old_virtuals = BINFO_VIRTUALS (old);
2767 enum { REUSE_NEW, REUSE_OLD, UNDECIDED, NEITHER } choose = UNDECIDED;
2769 /* If we have already committed to modifying it, then don't try and
2770 reuse another vtable. */
2771 if (BINFO_NEW_VTABLE_MARKED (binfo))
2774 skip_rtti_stuff (&virtuals, BINFO_TYPE (binfo));
2775 skip_rtti_stuff (&old_virtuals, BINFO_TYPE (binfo));
2779 tree fndecl = TREE_VALUE (virtuals);
2780 tree old_fndecl = TREE_VALUE (old_virtuals);
2782 /* First check to see if they are the same. */
2783 if (DECL_ASSEMBLER_NAME (fndecl) == DECL_ASSEMBLER_NAME (old_fndecl))
2785 /* No need to do anything. */
2787 else if (strictly_overrides (fndecl, old_fndecl))
2789 if (choose == UNDECIDED)
2791 else if (choose == REUSE_OLD)
2794 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2796 prepare_fresh_vtable (binfo, t);
2797 override_one_vtable (binfo, old, t);
2802 else if (strictly_overrides (old_fndecl, fndecl))
2804 if (choose == UNDECIDED)
2806 else if (choose == REUSE_NEW)
2809 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2811 prepare_fresh_vtable (binfo, t);
2812 override_one_vtable (binfo, old, t);
2815 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2817 else if (choose == NEITHER)
2819 TREE_VALUE (virtuals) = TREE_VALUE (old_virtuals);
2825 if (! BINFO_NEW_VTABLE_MARKED (binfo))
2827 prepare_fresh_vtable (binfo, t);
2828 override_one_vtable (binfo, old, t);
2832 /* This MUST be overridden, or the class is ill-formed. */
2833 tree fndecl = TREE_VALUE (virtuals);
2835 fndecl = copy_node (fndecl);
2836 copy_lang_decl (fndecl);
2837 DECL_NEEDS_FINAL_OVERRIDER_P (fndecl) = 1;
2838 /* Make sure we search for it later. */
2839 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t))
2840 CLASSTYPE_ABSTRACT_VIRTUALS (t) = error_mark_node;
2842 /* We can use integer_zero_node, as we will core dump
2843 if this is used anyway. */
2844 TREE_PURPOSE (virtuals) = integer_zero_node;
2845 TREE_VALUE (virtuals) = fndecl;
2848 virtuals = TREE_CHAIN (virtuals);
2849 old_virtuals = TREE_CHAIN (old_virtuals);
2852 /* Let's reuse the old vtable. */
2853 if (choose == REUSE_OLD)
2855 BINFO_VTABLE (binfo) = BINFO_VTABLE (old);
2856 BINFO_VIRTUALS (binfo) = BINFO_VIRTUALS (old);
2860 /* Merge in overrides for virtual bases.
2861 BINFO is the hierarchy we want to modify, and OLD has the potential
2865 merge_overrides (binfo, old, do_self, t)
2870 tree binfos = BINFO_BASETYPES (binfo);
2871 tree old_binfos = BINFO_BASETYPES (old);
2872 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2874 /* Should we use something besides CLASSTYPE_VFIELDS? */
2875 if (do_self && CLASSTYPE_VFIELDS (BINFO_TYPE (binfo)))
2877 override_one_vtable (binfo, old, t);
2880 for (i = 0; i < n_baselinks; i++)
2882 tree base_binfo = TREE_VEC_ELT (binfos, i);
2883 tree old_base_binfo = TREE_VEC_ELT (old_binfos, i);
2884 int is_not_base_vtable
2885 = i != CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo));
2886 if (! TREE_VIA_VIRTUAL (base_binfo))
2887 merge_overrides (base_binfo, old_base_binfo, is_not_base_vtable, t);
2891 /* Get the base virtual function declarations in T that are either
2892 overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
2893 the overrider/hider. */
2896 get_basefndecls (fndecl, t)
2899 tree methods = TYPE_METHODS (t);
2900 tree base_fndecls = NULL_TREE;
2901 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
2902 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2906 if (TREE_CODE (methods) == FUNCTION_DECL
2907 && DECL_VINDEX (methods) != NULL_TREE
2908 && DECL_NAME (fndecl) == DECL_NAME (methods))
2909 base_fndecls = temp_tree_cons (fndecl, methods, base_fndecls);
2911 methods = TREE_CHAIN (methods);
2915 return base_fndecls;
2917 for (i = 0; i < n_baseclasses; i++)
2919 tree base_binfo = TREE_VEC_ELT (binfos, i);
2920 tree basetype = BINFO_TYPE (base_binfo);
2922 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
2926 return base_fndecls;
2929 /* Mark the functions that have been hidden with their overriders.
2930 Since we start out with all functions already marked with a hider,
2931 no need to mark functions that are just hidden.
2933 Subroutine of warn_hidden. */
2936 mark_overriders (fndecl, base_fndecls)
2937 tree fndecl, base_fndecls;
2939 for (; base_fndecls; base_fndecls = TREE_CHAIN (base_fndecls))
2941 if (overrides (fndecl, TREE_VALUE (base_fndecls)))
2942 TREE_PURPOSE (base_fndecls) = fndecl;
2946 /* If this declaration supersedes the declaration of
2947 a method declared virtual in the base class, then
2948 mark this field as being virtual as well. */
2951 check_for_override (decl, ctype)
2954 tree binfos = BINFO_BASETYPES (TYPE_BINFO (ctype));
2955 int i, n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;
2956 int virtualp = DECL_VIRTUAL_P (decl);
2957 int found_overriden_fn = 0;
2959 for (i = 0; i < n_baselinks; i++)
2961 tree base_binfo = TREE_VEC_ELT (binfos, i);
2962 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo)))
2964 tree tmp = get_matching_virtual
2966 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl)));
2968 if (tmp && !found_overriden_fn)
2970 /* If this function overrides some virtual in some base
2971 class, then the function itself is also necessarily
2972 virtual, even if the user didn't explicitly say so. */
2973 DECL_VIRTUAL_P (decl) = 1;
2975 /* The TMP we really want is the one from the deepest
2976 baseclass on this path, taking care not to
2977 duplicate if we have already found it (via another
2978 path to its virtual baseclass. */
2979 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
2981 cp_error_at ("`static %#D' cannot be declared", decl);
2982 cp_error_at (" since `virtual %#D' declared in base class",
2989 = tree_cons (NULL_TREE, tmp, DECL_VINDEX (decl));
2991 /* We now know that DECL overrides something,
2992 which is all that is important. But, we must
2993 continue to iterate through all the base-classes
2994 in order to allow get_matching_virtual to check for
2995 various illegal overrides. */
2996 found_overriden_fn = 1;
3002 if (DECL_VINDEX (decl) == NULL_TREE)
3003 DECL_VINDEX (decl) = error_mark_node;
3004 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
3008 /* Warn about hidden virtual functions that are not overridden in t.
3009 We know that constructors and destructors don't apply. */
3015 tree method_vec = CLASSTYPE_METHOD_VEC (t);
3016 int n_methods = method_vec ? TREE_VEC_LENGTH (method_vec) : 0;
3019 /* We go through each separately named virtual function. */
3020 for (i = 2; i < n_methods && TREE_VEC_ELT (method_vec, i); ++i)
3022 tree fns = TREE_VEC_ELT (method_vec, i);
3025 tree base_fndecls = NULL_TREE;
3026 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
3027 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3029 /* First see if we have any virtual functions in this batch. */
3030 for (; fns; fns = OVL_NEXT (fns))
3032 fndecl = OVL_CURRENT (fns);
3033 if (DECL_VINDEX (fndecl))
3037 if (fns == NULL_TREE)
3040 /* First we get a list of all possible functions that might be
3041 hidden from each base class. */
3042 for (i = 0; i < n_baseclasses; i++)
3044 tree base_binfo = TREE_VEC_ELT (binfos, i);
3045 tree basetype = BINFO_TYPE (base_binfo);
3047 base_fndecls = chainon (get_basefndecls (fndecl, basetype),
3051 fns = OVL_NEXT (fns);
3053 /* ...then mark up all the base functions with overriders, preferring
3054 overriders to hiders. */
3056 for (; fns; fns = OVL_NEXT (fns))
3058 fndecl = OVL_CURRENT (fns);
3059 if (DECL_VINDEX (fndecl))
3060 mark_overriders (fndecl, base_fndecls);
3063 /* Now give a warning for all base functions without overriders,
3064 as they are hidden. */
3065 for (; base_fndecls; base_fndecls = TREE_CHAIN (base_fndecls))
3067 if (! overrides (TREE_PURPOSE (base_fndecls),
3068 TREE_VALUE (base_fndecls)))
3070 /* Here we know it is a hider, and no overrider exists. */
3071 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls));
3072 cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls));
3078 /* Check for things that are invalid. There are probably plenty of other
3079 things we should check for also. */
3082 finish_struct_anon (t)
3087 for (field = TYPE_FIELDS (t); field; field = TREE_CHAIN (field))
3089 if (TREE_STATIC (field))
3091 if (TREE_CODE (field) != FIELD_DECL)
3094 if (DECL_NAME (field) == NULL_TREE
3095 && ANON_AGGR_TYPE_P (TREE_TYPE (field)))
3097 tree elt = TYPE_FIELDS (TREE_TYPE (field));
3098 for (; elt; elt = TREE_CHAIN (elt))
3100 if (DECL_ARTIFICIAL (elt))
3103 if (DECL_NAME (elt) == constructor_name (t))
3104 cp_pedwarn_at ("ANSI C++ forbids member `%D' with same name as enclosing class",
3107 if (TREE_CODE (elt) != FIELD_DECL)
3109 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
3114 if (TREE_PRIVATE (elt))
3115 cp_pedwarn_at ("private member `%#D' in anonymous union",
3117 else if (TREE_PROTECTED (elt))
3118 cp_pedwarn_at ("protected member `%#D' in anonymous union",
3121 TREE_PRIVATE (elt) = TREE_PRIVATE (field);
3122 TREE_PROTECTED (elt) = TREE_PROTECTED (field);
3128 extern int interface_only, interface_unknown;
3130 /* Create default constructors, assignment operators, and so forth for
3131 the type indicated by T, if they are needed.
3132 CANT_HAVE_DEFAULT_CTOR, CANT_HAVE_CONST_CTOR, and
3133 CANT_HAVE_ASSIGNMENT are nonzero if, for whatever reason, the class
3134 cannot have a default constructor, copy constructor taking a const
3135 reference argument, or an assignment operator, respectively. If a
3136 virtual destructor is created, its DECL is returned; otherwise the
3137 return value is NULL_TREE. */
3140 add_implicitly_declared_members (t, cant_have_default_ctor,
3141 cant_have_const_cctor,
3142 cant_have_assignment)
3144 int cant_have_default_ctor;
3145 int cant_have_const_cctor;
3146 int cant_have_assignment;
3149 tree implicit_fns = NULL_TREE;
3150 tree name = TYPE_IDENTIFIER (t);
3151 tree virtual_dtor = NULL_TREE;
3155 if (TYPE_NEEDS_DESTRUCTOR (t) && !TYPE_HAS_DESTRUCTOR (t))
3157 default_fn = cons_up_default_function (t, name, 0);
3158 check_for_override (default_fn, t);
3160 /* If we couldn't make it work, then pretend we didn't need it. */
3161 if (default_fn == void_type_node)
3162 TYPE_NEEDS_DESTRUCTOR (t) = 0;
3165 TREE_CHAIN (default_fn) = implicit_fns;
3166 implicit_fns = default_fn;
3168 if (DECL_VINDEX (default_fn))
3169 virtual_dtor = default_fn;
3172 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_HAS_DESTRUCTOR (t);
3174 /* Default constructor. */
3175 if (! TYPE_HAS_CONSTRUCTOR (t) && ! cant_have_default_ctor)
3177 default_fn = cons_up_default_function (t, name, 2);
3178 TREE_CHAIN (default_fn) = implicit_fns;
3179 implicit_fns = default_fn;
3182 /* Copy constructor. */
3183 if (! TYPE_HAS_INIT_REF (t) && ! TYPE_FOR_JAVA (t))
3185 /* ARM 12.18: You get either X(X&) or X(const X&), but
3187 default_fn = cons_up_default_function (t, name,
3188 3 + cant_have_const_cctor);
3189 TREE_CHAIN (default_fn) = implicit_fns;
3190 implicit_fns = default_fn;
3193 /* Assignment operator. */
3194 if (! TYPE_HAS_ASSIGN_REF (t) && ! TYPE_FOR_JAVA (t))
3196 default_fn = cons_up_default_function (t, name,
3197 5 + cant_have_assignment);
3198 TREE_CHAIN (default_fn) = implicit_fns;
3199 implicit_fns = default_fn;
3202 /* Now, hook all of the new functions on to TYPE_METHODS,
3203 and add them to the CLASSTYPE_METHOD_VEC. */
3204 for (f = &implicit_fns; *f; f = &TREE_CHAIN (*f))
3205 add_method (t, 0, *f);
3206 *f = TYPE_METHODS (t);
3207 TYPE_METHODS (t) = implicit_fns;
3209 return virtual_dtor;
3212 /* Subroutine of finish_struct_1. Recursively count the number of fields
3213 in TYPE, including anonymous union members. */
3216 count_fields (fields)
3221 for (x = fields; x; x = TREE_CHAIN (x))
3223 if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
3224 n_fields += count_fields (TYPE_FIELDS (TREE_TYPE (x)));
3231 /* Subroutine of finish_struct_1. Recursively add all the fields in the
3232 TREE_LIST FIELDS to the TREE_VEC FIELD_VEC, starting at offset IDX. */
3235 add_fields_to_vec (fields, field_vec, idx)
3236 tree fields, field_vec;
3240 for (x = fields; x; x = TREE_CHAIN (x))
3242 if (TREE_CODE (x) == FIELD_DECL && ANON_AGGR_TYPE_P (TREE_TYPE (x)))
3243 idx = add_fields_to_vec (TYPE_FIELDS (TREE_TYPE (x)), field_vec, idx);
3245 TREE_VEC_ELT (field_vec, idx++) = x;
3250 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
3251 (or C++ class declaration).
3253 For C++, we must handle the building of derived classes.
3254 Also, C++ allows static class members. The way that this is
3255 handled is to keep the field name where it is (as the DECL_NAME
3256 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
3257 of the field. layout_record and layout_union will know about this.
3259 More C++ hair: inline functions have text in their
3260 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
3261 meaningful tree structure. After the struct has been laid out, set
3262 things up so that this can happen.
3264 And still more: virtual functions. In the case of single inheritance,
3265 when a new virtual function is seen which redefines a virtual function
3266 from the base class, the new virtual function is placed into
3267 the virtual function table at exactly the same address that
3268 it had in the base class. When this is extended to multiple
3269 inheritance, the same thing happens, except that multiple virtual
3270 function tables must be maintained. The first virtual function
3271 table is treated in exactly the same way as in the case of single
3272 inheritance. Additional virtual function tables have different
3273 DELTAs, which tell how to adjust `this' to point to the right thing.
3275 ATTRIBUTES is the set of decl attributes to be applied, if any. */
3282 enum tree_code code = TREE_CODE (t);
3283 tree fields = TYPE_FIELDS (t);
3284 tree x, last_x, method_vec;
3286 int max_has_virtual;
3287 tree pending_virtuals = NULL_TREE;
3288 tree pending_hard_virtuals = NULL_TREE;
3289 tree abstract_virtuals = NULL_TREE;
3293 int cant_have_default_ctor;
3294 int cant_have_const_ctor;
3295 int no_const_asn_ref;
3296 int has_mutable = 0;
3298 int non_pod_class = 0;
3300 /* The index of the first base class which has virtual
3301 functions. Only applied to non-virtual baseclasses. */
3302 int first_vfn_base_index;
3305 int any_default_members = 0;
3306 int const_sans_init = 0;
3307 int ref_sans_init = 0;
3308 tree access_decls = NULL_TREE;
3311 int has_pointers = 0;
3312 tree inline_friends;
3316 if (IS_AGGR_TYPE (t))
3317 cp_error ("redefinition of `%#T'", t);
3319 my_friendly_abort (172);
3324 GNU_xref_decl (current_function_decl, t);
3326 /* If this type was previously laid out as a forward reference,
3327 make sure we lay it out again. */
3329 TYPE_SIZE (t) = NULL_TREE;
3330 CLASSTYPE_GOT_SEMICOLON (t) = 0;
3332 old = suspend_momentary ();
3334 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
3335 Also process specified field sizes.
3336 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
3337 The specified size is found in the DECL_INITIAL.
3338 Store 0 there, except for ": 0" fields (so we can find them
3339 and delete them, below). */
3341 if (TYPE_BINFO_BASETYPES (t))
3342 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t));
3346 if (n_baseclasses > 0)
3348 struct base_info base_info;
3350 first_vfn_base_index = finish_base_struct (t, &base_info);
3351 /* Remember where we got our vfield from. */
3352 CLASSTYPE_VFIELD_PARENT (t) = first_vfn_base_index;
3353 has_virtual = base_info.has_virtual;
3354 max_has_virtual = base_info.max_has_virtual;
3355 vfield = base_info.vfield;
3356 vfields = base_info.vfields;
3357 CLASSTYPE_RTTI (t) = base_info.rtti;
3358 cant_have_default_ctor = base_info.cant_have_default_ctor;
3359 cant_have_const_ctor = base_info.cant_have_const_ctor;
3360 no_const_asn_ref = base_info.no_const_asn_ref;
3365 first_vfn_base_index = -1;
3367 max_has_virtual = has_virtual;
3369 vfields = NULL_TREE;
3370 CLASSTYPE_RTTI (t) = NULL_TREE;
3371 cant_have_default_ctor = 0;
3372 cant_have_const_ctor = 0;
3373 no_const_asn_ref = 0;
3376 /* The three of these are approximations which may later be
3377 modified. Needed at this point to make add_virtual_function
3378 and modify_vtable_entries work. */
3379 CLASSTYPE_VFIELDS (t) = vfields;
3380 CLASSTYPE_VFIELD (t) = vfield;
3382 for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
3384 GNU_xref_member (current_class_name, x);
3386 /* If this was an evil function, don't keep it in class. */
3387 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x)))
3390 /* Do both of these, even though they're in the same union;
3391 if the insn `r' member and the size `i' member are
3392 different sizes, as on the alpha, the larger of the two
3393 will end up with garbage in it. */
3394 DECL_SAVED_INSNS (x) = 0;
3395 DECL_FIELD_SIZE (x) = 0;
3397 check_for_override (x, t);
3398 if (DECL_ABSTRACT_VIRTUAL_P (x) && ! DECL_VINDEX (x))
3399 cp_error_at ("initializer specified for non-virtual method `%D'", x);
3401 /* The name of the field is the original field name
3402 Save this in auxiliary field for later overloading. */
3403 if (DECL_VINDEX (x))
3405 add_virtual_function (&pending_virtuals, &pending_hard_virtuals,
3406 &has_virtual, x, t);
3407 if (DECL_ABSTRACT_VIRTUAL_P (x))
3408 abstract_virtuals = tree_cons (NULL_TREE, x, abstract_virtuals);
3410 /* XXX Why did I comment this out? (jason) */
3418 fields = chainon (build_vbase_pointer_fields (t), fields);
3421 for (x = fields; x; x = TREE_CHAIN (x))
3423 tree type = TREE_TYPE (x);
3424 GNU_xref_member (current_class_name, x);
3426 if (TREE_CODE (x) == FIELD_DECL)
3428 DECL_PACKED (x) |= TYPE_PACKED (t);
3430 if (DECL_C_BIT_FIELD (x) && integer_zerop (DECL_INITIAL (x)))
3431 /* A zero-width bitfield doesn't do the trick. */;
3436 if (TREE_CODE (x) == USING_DECL)
3438 /* Save access declarations for later. */
3440 TREE_CHAIN (last_x) = TREE_CHAIN (x);
3442 fields = TREE_CHAIN (x);
3444 access_decls = scratch_tree_cons (NULL_TREE, x, access_decls);
3450 if (TREE_CODE (x) == TYPE_DECL
3451 || TREE_CODE (x) == TEMPLATE_DECL)
3454 /* If we've gotten this far, it's a data member, possibly static,
3455 or an enumerator. */
3457 DECL_FIELD_CONTEXT (x) = t;
3459 /* ``A local class cannot have static data members.'' ARM 9.4 */
3460 if (current_function_decl && TREE_STATIC (x))
3461 cp_error_at ("field `%D' in local class cannot be static", x);
3463 /* Perform error checking that did not get done in
3465 if (TREE_CODE (type) == FUNCTION_TYPE)
3467 cp_error_at ("field `%D' invalidly declared function type",
3469 type = build_pointer_type (type);
3470 TREE_TYPE (x) = type;
3472 else if (TREE_CODE (type) == METHOD_TYPE)
3474 cp_error_at ("field `%D' invalidly declared method type", x);
3475 type = build_pointer_type (type);
3476 TREE_TYPE (x) = type;
3478 else if (TREE_CODE (type) == OFFSET_TYPE)
3480 cp_error_at ("field `%D' invalidly declared offset type", x);
3481 type = build_pointer_type (type);
3482 TREE_TYPE (x) = type;
3486 if (DECL_NAME (x) == constructor_name (t))
3487 cant_have_default_ctor = 1;
3490 if (type == error_mark_node)
3493 DECL_SAVED_INSNS (x) = 0;
3494 DECL_FIELD_SIZE (x) = 0;
3496 /* When this goes into scope, it will be a non-local reference. */
3497 DECL_NONLOCAL (x) = 1;
3499 if (TREE_CODE (x) == CONST_DECL)
3502 if (TREE_CODE (x) == VAR_DECL)
3504 if (TREE_CODE (t) == UNION_TYPE)
3505 /* Unions cannot have static members. */
3506 cp_error_at ("field `%D' declared static in union", x);
3511 /* Now it can only be a FIELD_DECL. */
3513 if (TREE_PRIVATE (x) || TREE_PROTECTED (x))
3516 /* If this is of reference type, check if it needs an init.
3517 Also do a little ANSI jig if necessary. */
3518 if (TREE_CODE (type) == REFERENCE_TYPE)
3522 if (DECL_INITIAL (x) == NULL_TREE)
3525 /* ARM $12.6.2: [A member initializer list] (or, for an
3526 aggregate, initialization by a brace-enclosed list) is the
3527 only way to initialize nonstatic const and reference
3529 cant_have_default_ctor = 1;
3530 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3532 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3535 cp_warning_at ("non-static reference `%#D' in class without a constructor", x);
3537 cp_warning_at ("non-static reference in class without a constructor", x);
3541 while (TREE_CODE (type) == ARRAY_TYPE)
3542 type = TREE_TYPE (type);
3544 if (TREE_CODE (type) == POINTER_TYPE)
3547 if (DECL_MUTABLE_P (x) || TYPE_HAS_MUTABLE_P (type))
3550 if (! pod_type_p (type) || TYPE_PTRMEM_P (type)
3551 || TYPE_PTRMEMFUNC_P (type))
3554 /* If any field is const, the structure type is pseudo-const. */
3555 if (CP_TYPE_CONST_P (type))
3557 C_TYPE_FIELDS_READONLY (t) = 1;
3558 if (DECL_INITIAL (x) == NULL_TREE)
3559 const_sans_init = 1;
3561 /* ARM $12.6.2: [A member initializer list] (or, for an
3562 aggregate, initialization by a brace-enclosed list) is the
3563 only way to initialize nonstatic const and reference
3565 cant_have_default_ctor = 1;
3566 TYPE_HAS_COMPLEX_ASSIGN_REF (t) = 1;
3568 if (! TYPE_HAS_CONSTRUCTOR (t) && extra_warnings)
3571 cp_warning_at ("non-static const member `%#D' in class without a constructor", x);
3573 cp_warning_at ("non-static const member in class without a constructor", x);
3578 /* A field that is pseudo-const makes the structure
3580 if (IS_AGGR_TYPE (type))
3582 if (C_TYPE_FIELDS_READONLY (type))
3583 C_TYPE_FIELDS_READONLY (t) = 1;
3584 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type))
3585 const_sans_init = 1;
3589 /* We set DECL_C_BIT_FIELD in grokbitfield.
3590 If the type and width are valid, we'll also set DECL_BIT_FIELD. */
3591 if (DECL_C_BIT_FIELD (x))
3593 /* Invalid bit-field size done by grokfield. */
3594 /* Detect invalid bit-field type. Simply checking if TYPE is
3595 integral is insufficient, as that is the array core of the
3596 field type. If TREE_TYPE (x) is integral, then TYPE must be
3598 if (DECL_INITIAL (x)
3599 && ! INTEGRAL_TYPE_P (TREE_TYPE (x)))
3601 cp_error_at ("bit-field `%#D' with non-integral type", x);
3602 DECL_INITIAL (x) = NULL;
3605 /* Detect and ignore out of range field width. */
3606 if (DECL_INITIAL (x))
3608 tree w = DECL_INITIAL (x);
3609 register int width = 0;
3611 /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */
3614 /* detect invalid field size. */
3615 if (TREE_CODE (w) == CONST_DECL)
3616 w = DECL_INITIAL (w);
3617 else if (TREE_READONLY_DECL_P (w))
3618 w = decl_constant_value (w);
3620 if (TREE_CODE (w) != INTEGER_CST)
3622 cp_error_at ("bit-field `%D' width not an integer constant",
3624 DECL_INITIAL (x) = NULL_TREE;
3626 else if (width = TREE_INT_CST_LOW (w),
3629 DECL_INITIAL (x) = NULL;
3630 cp_error_at ("negative width in bit-field `%D'", x);
3632 else if (width == 0 && DECL_NAME (x) != 0)
3634 DECL_INITIAL (x) = NULL;
3635 cp_error_at ("zero width for bit-field `%D'", x);
3638 > TYPE_PRECISION (long_long_unsigned_type_node))
3640 /* The backend will dump if you try to use something
3641 too big; avoid that. */
3642 DECL_INITIAL (x) = NULL;
3643 sorry ("bit-fields larger than %d bits",
3644 TYPE_PRECISION (long_long_unsigned_type_node));
3645 cp_error_at (" in declaration of `%D'", x);
3647 else if (width > TYPE_PRECISION (type)
3648 && TREE_CODE (type) != ENUMERAL_TYPE
3649 && TREE_CODE (type) != BOOLEAN_TYPE)
3651 cp_warning_at ("width of `%D' exceeds its type", x);
3653 else if (TREE_CODE (type) == ENUMERAL_TYPE
3654 && ((min_precision (TYPE_MIN_VALUE (type),
3655 TREE_UNSIGNED (type)) > width)
3656 || (min_precision (TYPE_MAX_VALUE (type),
3657 TREE_UNSIGNED (type)) > width)))
3659 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3663 if (DECL_INITIAL (x))
3665 DECL_INITIAL (x) = NULL_TREE;
3666 DECL_FIELD_SIZE (x) = width;
3667 DECL_BIT_FIELD (x) = 1;
3671 #ifdef EMPTY_FIELD_BOUNDARY
3672 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
3673 EMPTY_FIELD_BOUNDARY);
3675 #ifdef PCC_BITFIELD_TYPE_MATTERS
3676 if (PCC_BITFIELD_TYPE_MATTERS)
3677 DECL_ALIGN (x) = MAX (DECL_ALIGN (x),
3684 /* Non-bit-fields are aligned for their type. */
3685 DECL_ALIGN (x) = MAX (DECL_ALIGN (x), TYPE_ALIGN (type));
3689 if (CLASS_TYPE_P (type) && ! ANON_AGGR_TYPE_P (type))
3691 /* Never let anything with uninheritable virtuals
3692 make it through without complaint. */
3693 abstract_virtuals_error (x, type);
3695 if (code == UNION_TYPE)
3697 const char *fie = NULL;
3698 if (TYPE_NEEDS_CONSTRUCTING (type))
3699 fie = "constructor";
3700 else if (TYPE_NEEDS_DESTRUCTOR (type))
3702 else if (TYPE_HAS_COMPLEX_ASSIGN_REF (type))
3703 fie = "copy assignment operator";
3705 cp_error_at ("member `%#D' with %s not allowed in union", x,
3710 TYPE_NEEDS_CONSTRUCTING (t) |= TYPE_NEEDS_CONSTRUCTING (type);
3711 TYPE_NEEDS_DESTRUCTOR (t) |= TYPE_NEEDS_DESTRUCTOR (type);
3712 TYPE_HAS_COMPLEX_ASSIGN_REF (t) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type);
3713 TYPE_HAS_COMPLEX_INIT_REF (t) |= TYPE_HAS_COMPLEX_INIT_REF (type);
3716 if (!TYPE_HAS_CONST_INIT_REF (type))
3717 cant_have_const_ctor = 1;
3719 if (!TYPE_HAS_CONST_ASSIGN_REF (type))
3720 no_const_asn_ref = 1;
3722 if (TYPE_HAS_CONSTRUCTOR (type)
3723 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type))
3725 cant_have_default_ctor = 1;
3727 /* This is wrong for aggregates. */
3728 if (! TYPE_HAS_CONSTRUCTOR (t))
3731 cp_pedwarn_at ("member `%#D' with only non-default constructor", x);
3733 cp_pedwarn_at ("member with only non-default constructor", x);
3734 cp_pedwarn_at ("in class without a constructor",
3740 if (DECL_INITIAL (x) != NULL_TREE)
3742 /* `build_class_init_list' does not recognize
3744 if (code == UNION_TYPE && any_default_members != 0)
3745 cp_error_at ("multiple fields in union `%T' initialized");
3746 any_default_members = 1;
3751 /* If this type has any constant members which did not come
3752 with their own initialization, mark that fact here. It is
3753 not an error here, since such types can be saved either by their
3754 constructors, or by fortuitous initialization. */
3755 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t) = const_sans_init;
3756 CLASSTYPE_REF_FIELDS_NEED_INIT (t) = ref_sans_init;
3757 CLASSTYPE_ABSTRACT_VIRTUALS (t) = abstract_virtuals;
3758 CLASSTYPE_HAS_MUTABLE (t) = has_mutable;
3760 /* Effective C++ rule 11. */
3761 if (has_pointers && warn_ecpp && TYPE_HAS_CONSTRUCTOR (t)
3762 && ! (TYPE_HAS_INIT_REF (t) && TYPE_HAS_ASSIGN_REF (t)))
3764 cp_warning ("`%#T' has pointer data members", t);
3766 if (! TYPE_HAS_INIT_REF (t))
3768 cp_warning (" but does not override `%T(const %T&)'", t, t);
3769 if (! TYPE_HAS_ASSIGN_REF (t))
3770 cp_warning (" or `operator=(const %T&)'", t);
3772 else if (! TYPE_HAS_ASSIGN_REF (t))
3773 cp_warning (" but does not override `operator=(const %T&)'", t);
3776 /* Do some bookkeeping that will guide the generation of implicitly
3777 declared member functions. */
3778 TYPE_HAS_COMPLEX_INIT_REF (t)
3779 |= (TYPE_HAS_INIT_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3780 || has_virtual || any_default_members);
3781 TYPE_NEEDS_CONSTRUCTING (t)
3782 |= (TYPE_HAS_CONSTRUCTOR (t) || TYPE_USES_VIRTUAL_BASECLASSES (t)
3783 || has_virtual || any_default_members);
3784 CLASSTYPE_NON_AGGREGATE (t)
3785 = ! aggregate || has_virtual || TYPE_HAS_CONSTRUCTOR (t);
3786 CLASSTYPE_NON_POD_P (t)
3787 = non_pod_class || CLASSTYPE_NON_AGGREGATE (t)
3788 || TYPE_HAS_DESTRUCTOR (t) || TYPE_HAS_ASSIGN_REF (t);
3789 TYPE_HAS_REAL_ASSIGN_REF (t) |= TYPE_HAS_ASSIGN_REF (t);
3790 TYPE_HAS_COMPLEX_ASSIGN_REF (t)
3791 |= TYPE_HAS_ASSIGN_REF (t) || TYPE_USES_VIRTUAL_BASECLASSES (t);
3793 /* Synthesize any needed methods. Note that methods will be synthesized
3794 for anonymous unions; grok_x_components undoes that. */
3796 = add_implicitly_declared_members (t, cant_have_default_ctor,
3797 cant_have_const_ctor,
3800 add_virtual_function (&pending_virtuals, &pending_hard_virtuals,
3801 &has_virtual, virtual_dtor, t);
3803 if (TYPE_METHODS (t))
3805 finish_struct_methods (t);
3806 method_vec = CLASSTYPE_METHOD_VEC (t);
3812 /* Just in case these got accidentally
3813 filled in by syntax errors. */
3814 TYPE_HAS_CONSTRUCTOR (t) = 0;
3815 TYPE_HAS_DESTRUCTOR (t) = 0;
3818 for (access_decls = nreverse (access_decls); access_decls;
3819 access_decls = TREE_CHAIN (access_decls))
3820 handle_using_decl (TREE_VALUE (access_decls), t, method_vec, fields);
3822 if (vfield == NULL_TREE && has_virtual)
3824 /* We build this decl with vtbl_ptr_type_node, which is a
3825 `vtable_entry_type*'. It might seem more precise to use
3826 `vtable_entry_type (*)[N]' where N is the number of firtual
3827 functions. However, that would require the vtable pointer in
3828 base classes to have a different type than the vtable pointer
3829 in derived classes. We could make that happen, but that
3830 still wouldn't solve all the problems. In particular, the
3831 type-based alias analysis code would decide that assignments
3832 to the base class vtable pointer can't alias assignments to
3833 the derived class vtable pointer, since they have different
3834 types. Thus, in an derived class destructor, where the base
3835 class constructor was inlined, we could generate bad code for
3836 setting up the vtable pointer.
3838 Therefore, we use one type for all vtable pointers. We still
3839 use a type-correct type; it's just doesn't indicate the array
3840 bounds. That's better than using `void*' or some such; it's
3841 cleaner, and it let's the alias analysis code know that these
3842 stores cannot alias stores to void*! */
3843 vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t),
3844 vtbl_ptr_type_node);
3845 /* If you change any of the below, take a look at all the
3846 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3848 DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
3849 CLASSTYPE_VFIELD (t) = vfield;
3850 DECL_VIRTUAL_P (vfield) = 1;
3851 DECL_ARTIFICIAL (vfield) = 1;
3852 DECL_FIELD_CONTEXT (vfield) = t;
3853 DECL_CLASS_CONTEXT (vfield) = t;
3854 DECL_FCONTEXT (vfield) = t;
3855 DECL_SAVED_INSNS (vfield) = 0;
3856 DECL_FIELD_SIZE (vfield) = 0;
3857 DECL_ALIGN (vfield) = TYPE_ALIGN (ptr_type_node);
3859 /* This is more efficient, but breaks binary compatibility, turn
3860 it on sometime when we don't care. If we turn it on, we also
3861 have to enable the code in dfs_init_vbase_pointers. */
3862 /* vfield is always first entry in structure. */
3863 TREE_CHAIN (vfield) = fields;
3868 my_friendly_assert (TREE_CHAIN (last_x) == NULL_TREE, 175);
3869 TREE_CHAIN (last_x) = vfield;
3876 vfields = chainon (vfields, build_tree_list (NULL_TREE, t));
3879 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3881 C++: maybe we will support default field initialization some day... */
3883 /* Delete all duplicate fields from the fields */
3884 delete_duplicate_fields (fields);
3886 /* Now we have the nearly final fieldlist for the data fields. Record it,
3887 then lay out the structure or union (including the fields). */
3889 TYPE_FIELDS (t) = fields;
3893 last_x = build_base_fields (t);
3895 /* If all our bases are empty, we can be empty too. */
3896 for (x = last_x; empty && x; x = TREE_CHAIN (x))
3897 if (DECL_SIZE (x) != integer_zero_node)
3901 /* CLASSTYPE_INLINE_FRIENDS is really TYPE_NONCOPIED_PARTS. Thus,
3902 we have to save this before we start modifying
3903 TYPE_NONCOPIED_PARTS. */
3904 inline_friends = CLASSTYPE_INLINE_FRIENDS (t);
3905 CLASSTYPE_INLINE_FRIENDS (t) = NULL_TREE;
3909 /* C++: do not let empty structures exist. */
3910 tree decl = build_lang_field_decl
3911 (FIELD_DECL, NULL_TREE, char_type_node);
3912 TREE_CHAIN (decl) = fields;
3913 TYPE_FIELDS (t) = decl;
3914 TYPE_NONCOPIED_PARTS (t)
3915 = tree_cons (NULL_TREE, decl, TYPE_NONCOPIED_PARTS (t));
3916 TREE_STATIC (TYPE_NONCOPIED_PARTS (t)) = 1;
3920 TYPE_FIELDS (t) = chainon (last_x, TYPE_FIELDS (t));
3924 /* Remember the size and alignment of the class before adding
3925 the virtual bases. */
3926 if (empty && flag_new_abi)
3927 CLASSTYPE_SIZE (t) = integer_zero_node;
3928 else if (flag_new_abi && TYPE_HAS_COMPLEX_INIT_REF (t)
3929 && TYPE_HAS_COMPLEX_ASSIGN_REF (t))
3930 CLASSTYPE_SIZE (t) = TYPE_BINFO_SIZE (t);
3932 CLASSTYPE_SIZE (t) = TYPE_SIZE (t);
3933 CLASSTYPE_ALIGN (t) = TYPE_ALIGN (t);
3935 finish_struct_anon (t);
3937 /* Set the TYPE_DECL for this type to contain the right
3938 value for DECL_OFFSET, so that we can use it as part
3939 of a COMPONENT_REF for multiple inheritance. */
3941 layout_decl (TYPE_MAIN_DECL (t), 0);
3943 /* Now fix up any virtual base class types that we left lying
3944 around. We must get these done before we try to lay out the
3945 virtual function table. */
3946 pending_hard_virtuals = nreverse (pending_hard_virtuals);
3949 /* layout_basetypes will remove the base subobject fields. */
3950 max_has_virtual = layout_basetypes (t, max_has_virtual);
3952 TYPE_FIELDS (t) = fields;
3954 my_friendly_assert (TYPE_FIELDS (t) == fields, 981117);
3956 /* Delete all zero-width bit-fields from the front of the fieldlist */
3957 while (fields && DECL_C_BIT_FIELD (fields)
3958 && DECL_INITIAL (fields))
3959 fields = TREE_CHAIN (fields);
3960 /* Delete all such fields from the rest of the fields. */
3961 for (x = fields; x;)
3963 if (TREE_CHAIN (x) && DECL_C_BIT_FIELD (TREE_CHAIN (x))
3964 && DECL_INITIAL (TREE_CHAIN (x)))
3965 TREE_CHAIN (x) = TREE_CHAIN (TREE_CHAIN (x));
3969 TYPE_FIELDS (t) = fields;
3971 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
3975 vbases = CLASSTYPE_VBASECLASSES (t);
3978 /* Now fixup overrides of all functions in vtables from all
3979 direct or indirect virtual base classes. */
3980 tree binfos = BINFO_BASETYPES (TYPE_BINFO (t));
3981 int i, n_baseclasses = binfos ? TREE_VEC_LENGTH (binfos) : 0;
3983 for (i = 0; i < n_baseclasses; i++)
3985 tree base_binfo = TREE_VEC_ELT (binfos, i);
3986 tree basetype = BINFO_TYPE (base_binfo);
3989 vbases = CLASSTYPE_VBASECLASSES (basetype);
3992 merge_overrides (binfo_member (BINFO_TYPE (vbases),
3993 CLASSTYPE_VBASECLASSES (t)),
3995 vbases = TREE_CHAIN (vbases);
4001 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
4002 might need to know it for setting up the offsets in the vtable
4003 (or in thunks) below. */
4004 if (vfield != NULL_TREE
4005 && DECL_FIELD_CONTEXT (vfield) != t)
4007 tree binfo = get_binfo (DECL_FIELD_CONTEXT (vfield), t, 0);
4008 tree offset = BINFO_OFFSET (binfo);
4010 vfield = copy_node (vfield);
4011 copy_lang_decl (vfield);
4013 if (! integer_zerop (offset))
4014 offset = size_binop (MULT_EXPR, offset, size_int (BITS_PER_UNIT));
4015 DECL_FIELD_CONTEXT (vfield) = t;
4016 DECL_CLASS_CONTEXT (vfield) = t;
4017 DECL_FIELD_BITPOS (vfield)
4018 = size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
4019 CLASSTYPE_VFIELD (t) = vfield;
4023 cp_warning ("Doing hard virtuals for %T...", t);
4026 if (has_virtual > max_has_virtual)
4027 max_has_virtual = has_virtual;
4028 if (max_has_virtual > 0)
4029 TYPE_VIRTUAL_P (t) = 1;
4031 if (flag_rtti && TYPE_VIRTUAL_P (t) && !pending_hard_virtuals)
4032 modify_all_vtables (t, NULL_TREE);
4034 while (pending_hard_virtuals)
4036 modify_all_vtables (t,
4037 TREE_VALUE (pending_hard_virtuals));
4038 pending_hard_virtuals = TREE_CHAIN (pending_hard_virtuals);
4041 if (TYPE_USES_VIRTUAL_BASECLASSES (t))
4044 /* Now fixup any virtual function entries from virtual bases
4045 that have different deltas. This has to come after we do the
4046 pending hard virtuals, as we might have a function that comes
4047 from multiple virtual base instances that is only overridden
4048 by a hard virtual above. */
4049 vbases = CLASSTYPE_VBASECLASSES (t);
4052 /* We might be able to shorten the amount of work we do by
4053 only doing this for vtables that come from virtual bases
4054 that have differing offsets, but don't want to miss any
4056 fixup_vtable_deltas (vbases, 1, t);
4057 vbases = TREE_CHAIN (vbases);
4061 /* Under our model of GC, every C++ class gets its own virtual
4062 function table, at least virtually. */
4063 if (pending_virtuals)
4065 pending_virtuals = nreverse (pending_virtuals);
4066 /* We must enter these virtuals into the table. */
4067 if (first_vfn_base_index < 0)
4069 if (! CLASSTYPE_COM_INTERFACE (t))
4071 /* The second slot is for the tdesc pointer when thunks are used. */
4072 if (flag_vtable_thunks)
4073 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
4075 /* The first slot is for the rtti offset. */
4076 pending_virtuals = tree_cons (NULL_TREE, NULL_TREE, pending_virtuals);
4078 set_rtti_entry (pending_virtuals,
4079 convert (ssizetype, integer_zero_node), t);
4081 build_vtable (NULL_TREE, t);
4085 /* Here we know enough to change the type of our virtual
4086 function table, but we will wait until later this function. */
4088 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t)))
4089 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index), t);
4092 /* If this type has basetypes with constructors, then those
4093 constructors might clobber the virtual function table. But
4094 they don't if the derived class shares the exact vtable of the base
4097 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
4099 else if (first_vfn_base_index >= 0)
4101 tree binfo = TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t), first_vfn_base_index);
4102 /* This class contributes nothing new to the virtual function
4103 table. However, it may have declared functions which
4104 went into the virtual function table "inherited" from the
4105 base class. If so, we grab a copy of those updated functions,
4106 and pretend they are ours. */
4108 /* See if we should steal the virtual info from base class. */
4109 if (TYPE_BINFO_VTABLE (t) == NULL_TREE)
4110 TYPE_BINFO_VTABLE (t) = BINFO_VTABLE (binfo);
4111 if (TYPE_BINFO_VIRTUALS (t) == NULL_TREE)
4112 TYPE_BINFO_VIRTUALS (t) = BINFO_VIRTUALS (binfo);
4113 if (TYPE_BINFO_VTABLE (t) != BINFO_VTABLE (binfo))
4114 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
4117 if (max_has_virtual || first_vfn_base_index >= 0)
4119 CLASSTYPE_VSIZE (t) = has_virtual;
4120 if (first_vfn_base_index >= 0)
4122 if (pending_virtuals)
4123 TYPE_BINFO_VIRTUALS (t) = chainon (TYPE_BINFO_VIRTUALS (t),
4126 else if (has_virtual)
4128 TYPE_BINFO_VIRTUALS (t) = pending_virtuals;
4129 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t)) = 1;
4133 /* Now lay out the virtual function table. */
4136 /* Use size_int so values are memoized in common cases. */
4137 tree itype = build_index_type (size_int (has_virtual));
4138 tree atype = build_cplus_array_type (vtable_entry_type, itype);
4140 layout_type (atype);
4142 CLASSTYPE_VFIELD (t) = vfield;
4144 /* We may have to grow the vtable. */
4145 if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
4147 TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype;
4148 DECL_SIZE (TYPE_BINFO_VTABLE (t)) = 0;
4149 layout_decl (TYPE_BINFO_VTABLE (t), 0);
4150 /* At one time the vtable info was grabbed 2 words at a time. This
4151 fails on sparc unless you have 8-byte alignment. (tiemann) */
4152 DECL_ALIGN (TYPE_BINFO_VTABLE (t))
4153 = MAX (TYPE_ALIGN (double_type_node),
4154 DECL_ALIGN (TYPE_BINFO_VTABLE (t)));
4157 else if (first_vfn_base_index >= 0)
4158 CLASSTYPE_VFIELD (t) = vfield;
4159 CLASSTYPE_VFIELDS (t) = vfields;
4161 finish_struct_bits (t, max_has_virtual);
4163 /* Complete the rtl for any static member objects of the type we're
4165 for (x = fields; x; x = TREE_CHAIN (x))
4167 if (TREE_CODE (x) == VAR_DECL && TREE_STATIC (x)
4168 && TREE_TYPE (x) == t)
4170 DECL_MODE (x) = TYPE_MODE (t);
4171 make_decl_rtl (x, NULL, 0);
4175 /* Done with FIELDS...now decide whether to sort these for
4176 faster lookups later. Don't worry about optimizing
4177 for structs only declared in inline functions...they're
4178 not going to be referenced anywhere else.
4180 The C front-end only does this when n_fields > 15. We use
4181 a smaller number because most searches fail (succeeding
4182 ultimately as the search bores through the inheritance
4183 hierarchy), and we want this failure to occur quickly. */
4185 n_fields = count_fields (fields);
4186 if (n_fields > 7 && !allocation_temporary_p ())
4188 tree field_vec = make_tree_vec (n_fields);
4189 add_fields_to_vec (fields, field_vec, 0);
4190 qsort (&TREE_VEC_ELT (field_vec, 0), n_fields, sizeof (tree),
4191 (int (*)(const void *, const void *))field_decl_cmp);
4192 if (! DECL_LANG_SPECIFIC (TYPE_MAIN_DECL (t)))
4193 retrofit_lang_decl (TYPE_MAIN_DECL (t));
4194 DECL_SORTED_FIELDS (TYPE_MAIN_DECL (t)) = field_vec;
4197 if (TYPE_HAS_CONSTRUCTOR (t))
4199 tree vfields = CLASSTYPE_VFIELDS (t);
4203 /* Mark the fact that constructor for T
4204 could affect anybody inheriting from T
4205 who wants to initialize vtables for VFIELDS's type. */
4206 if (VF_DERIVED_VALUE (vfields))
4207 TREE_ADDRESSABLE (vfields) = 1;
4208 vfields = TREE_CHAIN (vfields);
4212 /* Write out inline function definitions. */
4213 do_inline_function_hair (t, inline_friends);
4215 if (CLASSTYPE_VSIZE (t) != 0)
4217 /* In addition to this one, all the other vfields should be listed. */
4218 /* Before that can be done, we have to have FIELD_DECLs for them, and
4219 a place to find them. */
4220 TYPE_NONCOPIED_PARTS (t)
4221 = tree_cons (default_conversion (TYPE_BINFO_VTABLE (t)),
4222 vfield, TYPE_NONCOPIED_PARTS (t));
4224 if (warn_nonvdtor && TYPE_HAS_DESTRUCTOR (t)
4225 && DECL_VINDEX (TREE_VEC_ELT (method_vec, 1)) == NULL_TREE)
4226 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4230 /* Make the rtl for any new vtables we have created, and unmark
4231 the base types we marked. */
4232 finish_vtbls (TYPE_BINFO (t), 1, t);
4233 hack_incomplete_structures (t);
4236 if (TYPE_NAME (t) && TYPE_IDENTIFIER (t))
4237 undo_template_name_overload (TYPE_IDENTIFIER (t), 1);
4240 resume_momentary (old);
4242 if (warn_overloaded_virtual)
4246 /* This has to be done after we have sorted out what to do with
4247 the enclosing type. */
4248 if (write_symbols != DWARF_DEBUG)
4250 /* Be smarter about nested classes here. If a type is nested,
4251 only output it if we would output the enclosing type. */
4252 if (DECL_CLASS_SCOPE_P (TYPE_MAIN_DECL (t)))
4253 DECL_IGNORED_P (TYPE_MAIN_DECL (t)) = TREE_ASM_WRITTEN (TYPE_MAIN_DECL (t));
4257 if (write_symbols != DWARF_DEBUG && write_symbols != DWARF2_DEBUG)
4259 /* If the type has methods, we want to think about cutting down
4260 the amount of symbol table stuff we output. The value stored in
4261 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4262 For example, if a member function is seen and we decide to
4263 write out that member function, then we can change the value
4264 of the DECL_IGNORED_P slot, and the type will be output when
4265 that member function's debug info is written out.
4267 We can't do this with DWARF, which does not support name
4268 references between translation units. */
4269 if (CLASSTYPE_METHOD_VEC (t))
4271 /* Don't output full info about any type
4272 which does not have its implementation defined here. */
4273 if (CLASSTYPE_INTERFACE_ONLY (t))
4274 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4276 /* XXX do something about this. */
4277 else if (CLASSTYPE_INTERFACE_UNKNOWN (t))
4278 /* Only a first approximation! */
4279 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4282 else if (CLASSTYPE_INTERFACE_ONLY (t))
4283 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t)) = 1;
4286 /* Finish debugging output for this type. */
4287 rest_of_type_compilation (t, toplevel_bindings_p ());
4292 /* When T was built up, the member declarations were added in reverse
4293 order. Rearrange them to declaration order. */
4296 unreverse_member_declarations (t)
4303 /* The TYPE_FIELDS, TYPE_METHODS, and CLASSTYPE_TAGS are all in
4304 reverse order. Put them in declaration order now. */
4305 TYPE_METHODS (t) = nreverse (TYPE_METHODS (t));
4306 CLASSTYPE_TAGS (t) = nreverse (CLASSTYPE_TAGS (t));
4308 /* Actually, for the TYPE_FIELDS, only the non TYPE_DECLs are in
4309 reverse order, so we can't just use nreverse. */
4311 for (x = TYPE_FIELDS (t);
4312 x && TREE_CODE (x) != TYPE_DECL;
4315 next = TREE_CHAIN (x);
4316 TREE_CHAIN (x) = prev;
4321 TREE_CHAIN (TYPE_FIELDS (t)) = x;
4323 TYPE_FIELDS (t) = prev;
4328 finish_struct (t, attributes)
4331 /* Now that we've got all the field declarations, reverse everything
4333 unreverse_member_declarations (t);
4335 cplus_decl_attributes (t, attributes, NULL_TREE);
4337 if (processing_template_decl)
4339 finish_struct_methods (t);
4340 TYPE_SIZE (t) = integer_zero_node;
4343 finish_struct_1 (t);
4345 TYPE_BEING_DEFINED (t) = 0;
4347 if (current_class_type)
4350 error ("trying to finish struct, but kicked out due to previous parse errors.");
4355 /* Return the dynamic type of INSTANCE, if known.
4356 Used to determine whether the virtual function table is needed
4359 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4360 of our knowledge of its type. */
4363 fixed_type_or_null (instance, nonnull)
4367 switch (TREE_CODE (instance))
4370 /* Check that we are not going through a cast of some sort. */
4371 if (TREE_TYPE (instance)
4372 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance, 0))))
4373 instance = TREE_OPERAND (instance, 0);
4374 /* fall through... */
4376 /* This is a call to a constructor, hence it's never zero. */
4377 if (TREE_HAS_CONSTRUCTOR (instance))
4381 return TREE_TYPE (instance);
4386 /* This is a call to a constructor, hence it's never zero. */
4387 if (TREE_HAS_CONSTRUCTOR (instance))
4391 return TREE_TYPE (instance);
4393 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4400 if (TREE_CODE (TREE_OPERAND (instance, 1)) == INTEGER_CST)
4401 /* Propagate nonnull. */
4402 fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4403 if (TREE_CODE (TREE_OPERAND (instance, 0)) == ADDR_EXPR)
4404 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4409 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4414 return fixed_type_or_null (TREE_OPERAND (instance, 0), nonnull);
4417 return fixed_type_or_null (TREE_OPERAND (instance, 1), nonnull);
4421 if (TREE_CODE (TREE_TYPE (instance)) == ARRAY_TYPE
4422 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance))))
4426 return TREE_TYPE (TREE_TYPE (instance));
4428 /* fall through... */
4431 if (IS_AGGR_TYPE (TREE_TYPE (instance)))
4435 return TREE_TYPE (instance);
4439 if (instance == current_class_ptr
4440 && flag_this_is_variable <= 0)
4442 /* Normally, 'this' must be non-null. */
4443 if (flag_this_is_variable == 0)
4446 /* <0 means we're in a constructor and we know our type. */
4447 if (flag_this_is_variable < 0)
4448 return TREE_TYPE (TREE_TYPE (instance));
4450 else if (TREE_CODE (TREE_TYPE (instance)) == REFERENCE_TYPE)
4451 /* Reference variables should be references to objects. */
4461 /* Return non-zero if the dynamic type of INSTANCE is known, and equivalent
4462 to the static type. We also handle the case where INSTANCE is really
4465 Used to determine whether the virtual function table is needed
4468 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4469 of our knowledge of its type. */
4472 resolves_to_fixed_type_p (instance, nonnull)
4476 tree t = TREE_TYPE (instance);
4477 tree fixed = fixed_type_or_null (instance, nonnull);
4478 if (fixed == NULL_TREE)
4480 if (POINTER_TYPE_P (t))
4482 return same_type_p (TYPE_MAIN_VARIANT (t), TYPE_MAIN_VARIANT (fixed));
4487 init_class_processing ()
4489 current_class_depth = 0;
4490 current_class_stack_size = 10;
4492 = (class_stack_node_t) xmalloc (current_class_stack_size
4493 * sizeof (struct class_stack_node));
4495 current_lang_stacksize = 10;
4496 current_lang_base = (tree *)xmalloc(current_lang_stacksize * sizeof (tree));
4497 current_lang_stack = current_lang_base;
4499 access_default_node = build_int_2 (0, 0);
4500 access_public_node = build_int_2 (1, 0);
4501 access_protected_node = build_int_2 (2, 0);
4502 access_private_node = build_int_2 (3, 0);
4503 access_default_virtual_node = build_int_2 (4, 0);
4504 access_public_virtual_node = build_int_2 (5, 0);
4505 access_protected_virtual_node = build_int_2 (6, 0);
4506 access_private_virtual_node = build_int_2 (7, 0);
4508 /* Keep these values lying around. */
4509 base_layout_decl = build_lang_field_decl (FIELD_DECL, NULL_TREE, error_mark_node);
4510 TREE_TYPE (base_layout_decl) = make_node (RECORD_TYPE);
4512 gcc_obstack_init (&class_obstack);
4515 /* Set current scope to NAME. CODE tells us if this is a
4516 STRUCT, UNION, or ENUM environment.
4518 NAME may end up being NULL_TREE if this is an anonymous or
4519 late-bound struct (as in "struct { ... } foo;") */
4521 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
4522 appropriate values, found by looking up the type definition of
4525 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
4526 which can be seen locally to the class. They are shadowed by
4527 any subsequent local declaration (including parameter names).
4529 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
4530 which have static meaning (i.e., static members, static
4531 member functions, enum declarations, etc).
4533 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
4534 which can be seen locally to the class (as in 1), but
4535 know that we are doing this for declaration purposes
4536 (i.e. friend foo::bar (int)).
4538 So that we may avoid calls to lookup_name, we cache the _TYPE
4539 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
4541 For multiple inheritance, we perform a two-pass depth-first search
4542 of the type lattice. The first pass performs a pre-order search,
4543 marking types after the type has had its fields installed in
4544 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
4545 unmarks the marked types. If a field or member function name
4546 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4547 that name becomes `error_mark_node'. */
4550 pushclass (type, modify)
4554 type = TYPE_MAIN_VARIANT (type);
4556 /* Make sure there is enough room for the new entry on the stack. */
4557 if (current_class_depth + 1 >= current_class_stack_size)
4559 current_class_stack_size *= 2;
4561 = (class_stack_node_t) xrealloc (current_class_stack,
4562 current_class_stack_size
4563 * sizeof (struct class_stack_node));
4566 /* Insert a new entry on the class stack. */
4567 current_class_stack[current_class_depth].name = current_class_name;
4568 current_class_stack[current_class_depth].type = current_class_type;
4569 current_class_stack[current_class_depth].access = current_access_specifier;
4570 current_class_stack[current_class_depth].names_used = 0;
4571 current_class_depth++;
4573 /* Now set up the new type. */
4574 current_class_name = TYPE_NAME (type);
4575 if (TREE_CODE (current_class_name) == TYPE_DECL)
4576 current_class_name = DECL_NAME (current_class_name);
4577 current_class_type = type;
4579 /* By default, things in classes are private, while things in
4580 structures or unions are public. */
4581 current_access_specifier = (CLASSTYPE_DECLARED_CLASS (type)
4582 ? access_private_node
4583 : access_public_node);
4585 if (previous_class_type != NULL_TREE
4586 && (type != previous_class_type
4587 || TYPE_SIZE (previous_class_type) == NULL_TREE)
4588 && current_class_depth == 1)
4590 /* Forcibly remove any old class remnants. */
4591 invalidate_class_lookup_cache ();
4593 /* Now, free the obstack on which we cached all the values. */
4594 if (class_cache_firstobj)
4595 obstack_free (&class_cache_obstack, class_cache_firstobj);
4596 class_cache_firstobj
4597 = (char*) obstack_finish (&class_cache_obstack);
4600 /* If we're about to enter a nested class, clear
4601 IDENTIFIER_CLASS_VALUE for the enclosing classes. */
4602 if (modify && current_class_depth > 1)
4603 clear_identifier_class_values ();
4608 if (CLASSTYPE_TEMPLATE_INFO (type))
4609 overload_template_name (type);
4614 if (type != previous_class_type || current_class_depth > 1)
4615 push_class_decls (type);
4620 /* We are re-entering the same class we just left, so we
4621 don't have to search the whole inheritance matrix to find
4622 all the decls to bind again. Instead, we install the
4623 cached class_shadowed list, and walk through it binding
4624 names and setting up IDENTIFIER_TYPE_VALUEs. */
4625 set_class_shadows (previous_class_values);
4626 for (item = previous_class_values; item; item = TREE_CHAIN (item))
4628 tree id = TREE_PURPOSE (item);
4629 tree decl = TREE_TYPE (item);
4631 push_class_binding (id, decl);
4632 if (TREE_CODE (decl) == TYPE_DECL)
4633 set_identifier_type_value (id, TREE_TYPE (decl));
4635 unuse_fields (type);
4638 storetags (CLASSTYPE_TAGS (type));
4642 /* When we exit a toplevel class scope, we save the
4643 IDENTIFIER_CLASS_VALUEs so that we can restore them quickly if we
4644 reenter the class. Here, we've entered some other class, so we
4645 must invalidate our cache. */
4648 invalidate_class_lookup_cache ()
4652 /* This code can be seen as a cache miss. When we've cached a
4653 class' scope's bindings and we can't use them, we need to reset
4654 them. This is it! */
4655 for (t = previous_class_values; t; t = TREE_CHAIN (t))
4656 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t)) = NULL_TREE;
4658 previous_class_type = NULL_TREE;
4661 /* Get out of the current class scope. If we were in a class scope
4662 previously, that is the one popped to. */
4668 /* Since poplevel_class does the popping of class decls nowadays,
4669 this really only frees the obstack used for these decls. */
4672 current_class_depth--;
4673 current_class_name = current_class_stack[current_class_depth].name;
4674 current_class_type = current_class_stack[current_class_depth].type;
4675 current_access_specifier = current_class_stack[current_class_depth].access;
4676 if (current_class_stack[current_class_depth].names_used)
4677 splay_tree_delete (current_class_stack[current_class_depth].names_used);
4680 /* Returns 1 if current_class_type is either T or a nested type of T. */
4683 currently_open_class (t)
4687 if (t == current_class_type)
4689 for (i = 0; i < current_class_depth; ++i)
4690 if (current_class_stack [i].type == t)
4695 /* When entering a class scope, all enclosing class scopes' names with
4696 static meaning (static variables, static functions, types and enumerators)
4697 have to be visible. This recursive function calls pushclass for all
4698 enclosing class contexts until global or a local scope is reached.
4699 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4700 formal of the same name. */
4703 push_nested_class (type, modify)
4709 /* A namespace might be passed in error cases, like A::B:C. */
4710 if (type == NULL_TREE || type == error_mark_node || ! IS_AGGR_TYPE (type)
4711 || TREE_CODE (type) == NAMESPACE_DECL
4712 || TREE_CODE (type) == TEMPLATE_TYPE_PARM
4713 || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)
4716 context = DECL_CONTEXT (TYPE_MAIN_DECL (type));
4718 if (context && CLASS_TYPE_P (context))
4719 push_nested_class (context, 2);
4720 pushclass (type, modify);
4723 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4728 tree context = DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type));
4731 if (context && CLASS_TYPE_P (context))
4732 pop_nested_class ();
4735 /* Set global variables CURRENT_LANG_NAME to appropriate value
4736 so that behavior of name-mangling machinery is correct. */
4739 push_lang_context (name)
4742 *current_lang_stack++ = current_lang_name;
4743 if (current_lang_stack >= current_lang_base + current_lang_stacksize)
4746 = (tree *)xrealloc (current_lang_base,
4747 sizeof (tree) * (current_lang_stacksize + 10));
4748 current_lang_stack = current_lang_base + current_lang_stacksize;
4749 current_lang_stacksize += 10;
4752 if (name == lang_name_cplusplus)
4754 strict_prototype = strict_prototypes_lang_cplusplus;
4755 current_lang_name = name;
4757 else if (name == lang_name_java)
4759 strict_prototype = strict_prototypes_lang_cplusplus;
4760 current_lang_name = name;
4761 /* DECL_IGNORED_P is initially set for these types, to avoid clutter.
4762 (See record_builtin_java_type in decl.c.) However, that causes
4763 incorrect debug entries if these types are actually used.
4764 So we re-enable debug output after extern "Java". */
4765 DECL_IGNORED_P (java_byte_type_node) = 0;
4766 DECL_IGNORED_P (java_short_type_node) = 0;
4767 DECL_IGNORED_P (java_int_type_node) = 0;
4768 DECL_IGNORED_P (java_long_type_node) = 0;
4769 DECL_IGNORED_P (java_float_type_node) = 0;
4770 DECL_IGNORED_P (java_double_type_node) = 0;
4771 DECL_IGNORED_P (java_char_type_node) = 0;
4772 DECL_IGNORED_P (java_boolean_type_node) = 0;
4774 else if (name == lang_name_c)
4776 strict_prototype = strict_prototypes_lang_c;
4777 current_lang_name = name;
4780 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name));
4783 /* Get out of the current language scope. */
4788 current_lang_name = *--current_lang_stack;
4789 if (current_lang_name == lang_name_cplusplus
4790 || current_lang_name == lang_name_java)
4791 strict_prototype = strict_prototypes_lang_cplusplus;
4792 else if (current_lang_name == lang_name_c)
4793 strict_prototype = strict_prototypes_lang_c;
4796 /* Type instantiation routines. */
4798 /* Given an OVERLOAD and a TARGET_TYPE, return the function that
4799 matches the TARGET_TYPE. If there is no satisfactory match, return
4800 error_mark_node, and issue an error message if COMPLAIN is
4801 non-zero. If TEMPLATE_ONLY, the name of the overloaded function
4802 was a template-id, and EXPLICIT_TARGS are the explicitly provided
4803 template arguments. */
4806 resolve_address_of_overloaded_function (target_type,
4815 tree explicit_targs;
4817 /* Here's what the standard says:
4821 If the name is a function template, template argument deduction
4822 is done, and if the argument deduction succeeds, the deduced
4823 arguments are used to generate a single template function, which
4824 is added to the set of overloaded functions considered.
4826 Non-member functions and static member functions match targets of
4827 type "pointer-to-function" or "reference-to-function." Nonstatic
4828 member functions match targets of type "pointer-to-member
4829 function;" the function type of the pointer to member is used to
4830 select the member function from the set of overloaded member
4831 functions. If a nonstatic member function is selected, the
4832 reference to the overloaded function name is required to have the
4833 form of a pointer to member as described in 5.3.1.
4835 If more than one function is selected, any template functions in
4836 the set are eliminated if the set also contains a non-template
4837 function, and any given template function is eliminated if the
4838 set contains a second template function that is more specialized
4839 than the first according to the partial ordering rules 14.5.5.2.
4840 After such eliminations, if any, there shall remain exactly one
4841 selected function. */
4844 int is_reference = 0;
4845 /* We store the matches in a TREE_LIST rooted here. The functions
4846 are the TREE_PURPOSE, not the TREE_VALUE, in this list, for easy
4847 interoperability with most_specialized_instantiation. */
4848 tree matches = NULL_TREE;
4851 /* By the time we get here, we should be seeing only real
4852 pointer-to-member types, not the internal POINTER_TYPE to
4853 METHOD_TYPE representation. */
4854 my_friendly_assert (!(TREE_CODE (target_type) == POINTER_TYPE
4855 && (TREE_CODE (TREE_TYPE (target_type))
4856 == METHOD_TYPE)), 0);
4858 /* Check that the TARGET_TYPE is reasonable. */
4859 if (TYPE_PTRFN_P (target_type))
4862 else if (TYPE_PTRMEMFUNC_P (target_type))
4863 /* This is OK, too. */
4865 else if (TREE_CODE (target_type) == FUNCTION_TYPE)
4867 /* This is OK, too. This comes from a conversion to reference
4869 target_type = build_reference_type (target_type);
4875 cp_error("cannot resolve overloaded function `%D' based on conversion to type `%T'",
4876 DECL_NAME (OVL_FUNCTION (overload)), target_type);
4877 return error_mark_node;
4880 /* If we can find a non-template function that matches, we can just
4881 use it. There's no point in generating template instantiations
4882 if we're just going to throw them out anyhow. But, of course, we
4883 can only do this when we don't *need* a template function. */
4888 for (fns = overload; fns; fns = OVL_CHAIN (fns))
4890 tree fn = OVL_FUNCTION (fns);
4893 if (TREE_CODE (fn) == TEMPLATE_DECL)
4894 /* We're not looking for templates just yet. */
4897 if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
4899 /* We're looking for a non-static member, and this isn't
4900 one, or vice versa. */
4903 /* See if there's a match. */
4904 fntype = TREE_TYPE (fn);
4906 fntype = build_ptrmemfunc_type (build_pointer_type (fntype));
4907 else if (!is_reference)
4908 fntype = build_pointer_type (fntype);
4910 if (can_convert_arg (target_type, fntype, fn))
4911 matches = scratch_tree_cons (fn, NULL_TREE, matches);
4915 /* Now, if we've already got a match (or matches), there's no need
4916 to proceed to the template functions. But, if we don't have a
4917 match we need to look at them, too. */
4920 tree target_fn_type;
4921 tree target_arg_types;
4926 = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type));
4928 target_fn_type = TREE_TYPE (target_type);
4929 target_arg_types = TYPE_ARG_TYPES (target_fn_type);
4931 for (fns = overload; fns; fns = OVL_CHAIN (fns))
4933 tree fn = OVL_FUNCTION (fns);
4935 tree instantiation_type;
4938 if (TREE_CODE (fn) != TEMPLATE_DECL)
4939 /* We're only looking for templates. */
4942 if ((TREE_CODE (TREE_TYPE (fn)) == METHOD_TYPE)
4944 /* We're not looking for a non-static member, and this is
4945 one, or vice versa. */
4948 /* Try to do argument deduction. */
4949 targs = make_scratch_vec (DECL_NTPARMS (fn));
4950 if (fn_type_unification (fn, explicit_targs, targs,
4951 target_arg_types, NULL_TREE,
4953 /* Argument deduction failed. */
4956 /* Instantiate the template. */
4957 instantiation = instantiate_template (fn, targs);
4958 if (instantiation == error_mark_node)
4959 /* Instantiation failed. */
4962 /* See if there's a match. */
4963 instantiation_type = TREE_TYPE (instantiation);
4965 instantiation_type =
4966 build_ptrmemfunc_type (build_pointer_type (instantiation_type));
4967 else if (!is_reference)
4968 instantiation_type = build_pointer_type (instantiation_type);
4969 if (can_convert_arg (target_type, instantiation_type, instantiation))
4970 matches = scratch_tree_cons (instantiation, fn, matches);
4973 /* Now, remove all but the most specialized of the matches. */
4976 tree match = most_specialized_instantiation (matches,
4979 if (match != error_mark_node)
4980 matches = scratch_tree_cons (match, NULL_TREE, NULL_TREE);
4984 /* Now we should have exactly one function in MATCHES. */
4985 if (matches == NULL_TREE)
4987 /* There were *no* matches. */
4990 cp_error ("no matches converting function `%D' to type `%#T'",
4991 DECL_NAME (OVL_FUNCTION (overload)),
4994 /* print_candidates expects a chain with the functions in
4995 TREE_VALUE slots, so we cons one up here (we're losing anyway,
4996 so why be clever?). */
4997 for (; overload; overload = OVL_NEXT (overload))
4998 matches = scratch_tree_cons (NULL_TREE, OVL_CURRENT (overload),
5001 print_candidates (matches);
5003 return error_mark_node;
5005 else if (TREE_CHAIN (matches))
5007 /* There were too many matches. */
5013 cp_error ("converting overloaded function `%D' to type `%#T' is ambiguous",
5014 DECL_NAME (OVL_FUNCTION (overload)),
5017 /* Since print_candidates expects the functions in the
5018 TREE_VALUE slot, we flip them here. */
5019 for (match = matches; match; match = TREE_CHAIN (match))
5020 TREE_VALUE (match) = TREE_PURPOSE (match);
5022 print_candidates (matches);
5025 return error_mark_node;
5028 /* Good, exactly one match. Now, convert it to the correct type. */
5029 fn = TREE_PURPOSE (matches);
5033 if (TYPE_PTRFN_P (target_type) || TYPE_PTRMEMFUNC_P (target_type))
5034 return build_unary_op (ADDR_EXPR, fn, 0);
5037 /* The target must be a REFERENCE_TYPE. Above, build_unary_op
5038 will mark the function as addressed, but here we must do it
5040 mark_addressable (fn);
5046 /* This function will instantiate the type of the expression given in
5047 RHS to match the type of LHSTYPE. If errors exist, then return
5048 error_mark_node. We only complain is COMPLAIN is set. If we are
5049 not complaining, never modify rhs, as overload resolution wants to
5050 try many possible instantiations, in hopes that at least one will
5053 FLAGS is a bitmask, as we see at the top of the function.
5055 For non-recursive calls, LHSTYPE should be a function, pointer to
5056 function, or a pointer to member function. */
5059 instantiate_type (lhstype, rhs, flags)
5063 int complain = (flags & 1);
5064 int strict = (flags & 2) ? COMPARE_NO_ATTRIBUTES : COMPARE_STRICT;
5066 if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
5069 error ("not enough type information");
5070 return error_mark_node;
5073 if (TREE_TYPE (rhs) != NULL_TREE && ! (type_unknown_p (rhs)))
5075 if (comptypes (lhstype, TREE_TYPE (rhs), strict))
5078 cp_error ("argument of type `%T' does not match `%T'",
5079 TREE_TYPE (rhs), lhstype);
5080 return error_mark_node;
5083 /* We don't overwrite rhs if it is an overloaded function.
5084 Copying it would destroy the tree link. */
5085 if (TREE_CODE (rhs) != OVERLOAD)
5086 rhs = copy_node (rhs);
5088 /* This should really only be used when attempting to distinguish
5089 what sort of a pointer to function we have. For now, any
5090 arithmetic operation which is not supported on pointers
5091 is rejected as an error. */
5093 switch (TREE_CODE (rhs))
5100 my_friendly_abort (177);
5101 return error_mark_node;
5108 new_rhs = instantiate_type (build_pointer_type (lhstype),
5109 TREE_OPERAND (rhs, 0), flags);
5110 if (new_rhs == error_mark_node)
5111 return error_mark_node;
5113 TREE_TYPE (rhs) = lhstype;
5114 TREE_OPERAND (rhs, 0) = new_rhs;
5119 rhs = copy_node (TREE_OPERAND (rhs, 0));
5120 TREE_TYPE (rhs) = unknown_type_node;
5121 return instantiate_type (lhstype, rhs, flags);
5125 tree r = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
5127 if (r != error_mark_node && TYPE_PTRMEMFUNC_P (lhstype)
5128 && complain && !flag_ms_extensions)
5130 /* Note: we check this after the recursive call to avoid
5131 complaining about cases where overload resolution fails. */
5133 tree t = TREE_TYPE (TREE_OPERAND (rhs, 0));
5134 tree fn = PTRMEM_CST_MEMBER (r);
5136 my_friendly_assert (TREE_CODE (r) == PTRMEM_CST, 990811);
5139 ("object-dependent reference to `%E' can only be used in a call",
5142 (" to form a pointer to member function, say `&%T::%E'",
5150 rhs = TREE_OPERAND (rhs, 1);
5151 if (BASELINK_P (rhs))
5152 return instantiate_type (lhstype, TREE_VALUE (rhs), flags);
5154 /* This can happen if we are forming a pointer-to-member for a
5156 my_friendly_assert (TREE_CODE (rhs) == TEMPLATE_ID_EXPR, 0);
5160 case TEMPLATE_ID_EXPR:
5162 resolve_address_of_overloaded_function (lhstype,
5163 TREE_OPERAND (rhs, 0),
5165 /*template_only=*/1,
5166 TREE_OPERAND (rhs, 1));
5170 resolve_address_of_overloaded_function (lhstype,
5173 /*template_only=*/0,
5174 /*explicit_targs=*/NULL_TREE);
5177 /* Now we should have a baselink. */
5178 my_friendly_assert (BASELINK_P (rhs), 990412);
5180 return instantiate_type (lhstype, TREE_VALUE (rhs), flags);
5183 /* This is too hard for now. */
5184 my_friendly_abort (183);
5185 return error_mark_node;
5190 TREE_OPERAND (rhs, 0)
5191 = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
5192 if (TREE_OPERAND (rhs, 0) == error_mark_node)
5193 return error_mark_node;
5194 TREE_OPERAND (rhs, 1)
5195 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
5196 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5197 return error_mark_node;
5199 TREE_TYPE (rhs) = lhstype;
5203 case TRUNC_DIV_EXPR:
5204 case FLOOR_DIV_EXPR:
5206 case ROUND_DIV_EXPR:
5208 case TRUNC_MOD_EXPR:
5209 case FLOOR_MOD_EXPR:
5211 case ROUND_MOD_EXPR:
5212 case FIX_ROUND_EXPR:
5213 case FIX_FLOOR_EXPR:
5215 case FIX_TRUNC_EXPR:
5231 case PREINCREMENT_EXPR:
5232 case PREDECREMENT_EXPR:
5233 case POSTINCREMENT_EXPR:
5234 case POSTDECREMENT_EXPR:
5236 error ("invalid operation on uninstantiated type");
5237 return error_mark_node;
5239 case TRUTH_AND_EXPR:
5241 case TRUTH_XOR_EXPR:
5248 case TRUTH_ANDIF_EXPR:
5249 case TRUTH_ORIF_EXPR:
5250 case TRUTH_NOT_EXPR:
5252 error ("not enough type information");
5253 return error_mark_node;
5256 if (type_unknown_p (TREE_OPERAND (rhs, 0)))
5259 error ("not enough type information");
5260 return error_mark_node;
5262 TREE_OPERAND (rhs, 1)
5263 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
5264 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5265 return error_mark_node;
5266 TREE_OPERAND (rhs, 2)
5267 = instantiate_type (lhstype, TREE_OPERAND (rhs, 2), flags);
5268 if (TREE_OPERAND (rhs, 2) == error_mark_node)
5269 return error_mark_node;
5271 TREE_TYPE (rhs) = lhstype;
5275 TREE_OPERAND (rhs, 1)
5276 = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags);
5277 if (TREE_OPERAND (rhs, 1) == error_mark_node)
5278 return error_mark_node;
5280 TREE_TYPE (rhs) = lhstype;
5284 return instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags);
5286 case ENTRY_VALUE_EXPR:
5287 my_friendly_abort (184);
5288 return error_mark_node;
5291 return error_mark_node;
5294 my_friendly_abort (185);
5295 return error_mark_node;
5299 /* Return the name of the virtual function pointer field
5300 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5301 this may have to look back through base types to find the
5302 ultimate field name. (For single inheritance, these could
5303 all be the same name. Who knows for multiple inheritance). */
5306 get_vfield_name (type)
5309 tree binfo = TYPE_BINFO (type);
5312 while (BINFO_BASETYPES (binfo)
5313 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo, 0)))
5314 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo, 0)))
5315 binfo = BINFO_BASETYPE (binfo, 0);
5317 type = BINFO_TYPE (binfo);
5318 buf = (char *) alloca (sizeof (VFIELD_NAME_FORMAT)
5319 + TYPE_NAME_LENGTH (type) + 2);
5320 sprintf (buf, VFIELD_NAME_FORMAT, TYPE_NAME_STRING (type));
5321 return get_identifier (buf);
5325 print_class_statistics ()
5327 #ifdef GATHER_STATISTICS
5328 fprintf (stderr, "convert_harshness = %d\n", n_convert_harshness);
5329 fprintf (stderr, "compute_conversion_costs = %d\n", n_compute_conversion_costs);
5330 fprintf (stderr, "build_method_call = %d (inner = %d)\n",
5331 n_build_method_call, n_inner_fields_searched);
5334 fprintf (stderr, "vtables = %d; vtable searches = %d\n",
5335 n_vtables, n_vtable_searches);
5336 fprintf (stderr, "vtable entries = %d; vtable elems = %d\n",
5337 n_vtable_entries, n_vtable_elems);
5342 /* Push an obstack which is sufficiently long-lived to hold such class
5343 decls that may be cached in the previous_class_values list. The
5344 effect is undone by pop_obstacks. */
5347 push_cache_obstack ()
5349 static int cache_obstack_initialized;
5351 if (!cache_obstack_initialized)
5353 gcc_obstack_init (&class_cache_obstack);
5354 class_cache_firstobj
5355 = (char*) obstack_finish (&class_cache_obstack);
5356 cache_obstack_initialized = 1;
5359 push_obstacks_nochange ();
5360 current_obstack = &class_cache_obstack;
5363 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
5364 according to [class]:
5365 The class-name is also inserted
5366 into the scope of the class itself. For purposes of access checking,
5367 the inserted class name is treated as if it were a public member name. */
5370 build_self_reference ()
5372 tree name = constructor_name (current_class_type);
5373 tree value = build_lang_decl (TYPE_DECL, name, current_class_type);
5376 DECL_NONLOCAL (value) = 1;
5377 DECL_CONTEXT (value) = current_class_type;
5378 DECL_CLASS_CONTEXT (value) = current_class_type;
5379 DECL_ARTIFICIAL (value) = 1;
5381 if (processing_template_decl)
5382 value = push_template_decl (value);
5384 saved_cas = current_access_specifier;
5385 current_access_specifier = access_public_node;
5386 finish_member_declaration (value);
5387 current_access_specifier = saved_cas;
5390 /* Returns 1 if TYPE contains only padding bytes. */
5393 is_empty_class (type)
5398 if (type == error_mark_node)
5401 if (! IS_AGGR_TYPE (type))
5405 return CLASSTYPE_SIZE (type) == integer_zero_node;
5407 if (TYPE_BINFO_BASETYPES (type))
5409 t = TYPE_FIELDS (type);
5410 while (t && TREE_CODE (t) != FIELD_DECL)
5412 return (t == NULL_TREE);
5415 /* Find the enclosing class of the given NODE. NODE can be a *_DECL or
5416 a *_TYPE node. NODE can also be a local class. */
5419 get_enclosing_class (type)
5424 while (node && TREE_CODE (node) != NAMESPACE_DECL)
5426 switch (TREE_CODE_CLASS (TREE_CODE (node)))
5429 node = DECL_CONTEXT (node);
5435 node = TYPE_CONTEXT (node);
5439 my_friendly_abort (0);
5445 /* Return 1 if TYPE or one of its enclosing classes is derived from BASE. */
5448 is_base_of_enclosing_class (base, type)
5453 if (get_binfo (base, type, 0))
5456 type = get_enclosing_class (type);
5461 /* Note that NAME was looked up while the current class was being
5462 defined and that the result of that lookup was DECL. */
5465 maybe_note_name_used_in_class (name, decl)
5469 splay_tree names_used;
5471 /* If we're not defining a class, there's nothing to do. */
5472 if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
5475 /* If there's already a binding for this NAME, then we don't have
5476 anything to worry about. */
5477 if (IDENTIFIER_CLASS_VALUE (name))
5480 if (!current_class_stack[current_class_depth - 1].names_used)
5481 current_class_stack[current_class_depth - 1].names_used
5482 = splay_tree_new (splay_tree_compare_pointers, 0, 0);
5483 names_used = current_class_stack[current_class_depth - 1].names_used;
5485 splay_tree_insert (names_used,
5486 (splay_tree_key) name,
5487 (splay_tree_value) decl);
5490 /* Note that NAME was declared (as DECL) in the current class. Check
5491 to see that the declaration is legal. */
5494 note_name_declared_in_class (name, decl)
5498 splay_tree names_used;
5501 /* Look to see if we ever used this name. */
5503 = current_class_stack[current_class_depth - 1].names_used;
5507 n = splay_tree_lookup (names_used, (splay_tree_key) name);
5510 /* [basic.scope.class]
5512 A name N used in a class S shall refer to the same declaration
5513 in its context and when re-evaluated in the completed scope of
5515 cp_error ("declaration of `%#D'", decl);
5516 cp_error_at ("changes meaning of `%s' from `%+#D'",
5517 IDENTIFIER_POINTER (DECL_NAME (decl)),