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"
37 #define obstack_chunk_alloc xmalloc
38 #define obstack_chunk_free free
40 /* This is how we tell when two virtual member functions are really the
42 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
44 extern void set_class_shadows
PROTO ((tree
));
46 /* The number of nested classes being processed. If we are not in the
47 scope of any class, this is zero. */
49 int current_class_depth
;
51 /* In order to deal with nested classes, we keep a stack of classes.
52 The topmost entry is the innermost class, and is the entry at index
53 CURRENT_CLASS_DEPTH */
55 typedef struct class_stack_node
{
56 /* The name of the class. */
59 /* The _TYPE node for the class. */
62 /* The access specifier pending for new declarations in the scope of
66 /* If were defining TYPE, the names used in this class. */
67 splay_tree names_used
;
68 }* class_stack_node_t
;
70 /* The stack itself. This is an dynamically resized array. The
71 number of elements allocated is CURRENT_CLASS_STACK_SIZE. */
72 static int current_class_stack_size
;
73 static class_stack_node_t current_class_stack
;
75 /* The obstack on which the cached class declarations are kept. */
76 static struct obstack class_cache_obstack
;
80 static tree get_vfield_name
PROTO((tree
));
81 static void finish_struct_anon
PROTO((tree
));
82 static tree build_vbase_pointer
PROTO((tree
, tree
));
83 static tree build_vtable_entry
PROTO((tree
, tree
));
84 static tree get_vtable_name
PROTO((tree
));
85 static tree get_derived_offset
PROTO((tree
, tree
));
86 static tree get_basefndecls
PROTO((tree
, tree
));
87 static void set_rtti_entry
PROTO((tree
, tree
, tree
));
88 static tree build_vtable
PROTO((tree
, tree
));
89 static void prepare_fresh_vtable
PROTO((tree
, tree
));
90 static void fixup_vtable_deltas1
PROTO((tree
, tree
));
91 static void fixup_vtable_deltas
PROTO((tree
, int, tree
));
92 static void finish_vtbls
PROTO((tree
, int, tree
));
93 static void modify_vtable_entry
PROTO((tree
, tree
, tree
));
94 static tree get_vtable_entry_n
PROTO((tree
, unsigned HOST_WIDE_INT
));
95 static void add_virtual_function
PROTO((tree
*, tree
*, int *, tree
, tree
));
96 static tree delete_duplicate_fields_1
PROTO((tree
, tree
));
97 static void delete_duplicate_fields
PROTO((tree
));
98 static void finish_struct_bits
PROTO((tree
, int));
99 static int alter_access
PROTO((tree
, tree
, tree
, tree
));
100 static void handle_using_decl
PROTO((tree
, tree
, tree
, tree
));
101 static int overrides
PROTO((tree
, tree
));
102 static int strictly_overrides
PROTO((tree
, tree
));
103 static void merge_overrides
PROTO((tree
, tree
, int, tree
));
104 static void override_one_vtable
PROTO((tree
, tree
, tree
));
105 static void mark_overriders
PROTO((tree
, tree
));
106 static void check_for_override
PROTO((tree
, tree
));
107 static tree get_class_offset_1
PROTO((tree
, tree
, tree
, tree
, tree
));
108 static tree get_class_offset
PROTO((tree
, tree
, tree
, tree
));
109 static void modify_one_vtable
PROTO((tree
, tree
, tree
));
110 static void modify_all_vtables
PROTO((tree
, tree
));
111 static void modify_all_direct_vtables
PROTO((tree
, int, tree
, tree
));
112 static void modify_all_indirect_vtables
PROTO((tree
, int, int, tree
, tree
));
113 static int finish_base_struct
PROTO((tree
, struct base_info
*));
114 static void finish_struct_methods
PROTO((tree
));
115 static void maybe_warn_about_overly_private_class
PROTO ((tree
));
116 static int field_decl_cmp
PROTO ((const tree
*, const tree
*));
117 static int method_name_cmp
PROTO ((const tree
*, const tree
*));
118 static tree add_implicitly_declared_members
PROTO((tree
, int, int, int));
119 static tree fixed_type_or_null
PROTO((tree
, int *));
120 static tree resolve_address_of_overloaded_function
PROTO((tree
, tree
, int,
122 static void build_vtable_entry_ref
PROTO((tree
, tree
, tree
));
123 static tree build_vtable_entry_for_fn
PROTO((tree
, tree
));
124 static tree build_vtbl_initializer
PROTO((tree
));
125 static int count_fields
PROTO((tree
));
126 static int add_fields_to_vec
PROTO((tree
, tree
, int));
128 /* Variables shared between class.c and call.c. */
130 #ifdef GATHER_STATISTICS
132 int n_vtable_entries
= 0;
133 int n_vtable_searches
= 0;
134 int n_vtable_elems
= 0;
135 int n_convert_harshness
= 0;
136 int n_compute_conversion_costs
= 0;
137 int n_build_method_call
= 0;
138 int n_inner_fields_searched
= 0;
141 /* Virtual baseclass things. */
144 build_vbase_pointer (exp
, type
)
148 FORMAT_VBASE_NAME (name
, type
);
150 return build_component_ref (exp
, get_identifier (name
), NULL_TREE
, 0);
154 /* Is the type of the EXPR, the complete type of the object?
155 If we are going to be wrong, we must be conservative, and return 0. */
158 complete_type_p (expr
)
161 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
164 switch (TREE_CODE (expr
))
171 expr
= TREE_OPERAND (expr
, 0);
175 if (! TREE_HAS_CONSTRUCTOR (expr
))
177 /* fall through... */
180 if (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
181 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr
)))
182 && TYPE_MAIN_VARIANT (TREE_TYPE (expr
)) == type
)
184 /* fall through... */
187 if (IS_AGGR_TYPE (TREE_TYPE (expr
))
188 && TYPE_MAIN_VARIANT (TREE_TYPE (expr
)) == type
)
190 /* fall through... */
201 /* Build multi-level access to EXPR using hierarchy path PATH.
202 CODE is PLUS_EXPR if we are going with the grain,
203 and MINUS_EXPR if we are not (in which case, we cannot traverse
204 virtual baseclass links).
206 TYPE is the type we want this path to have on exit.
208 NONNULL is non-zero if we know (for any reason) that EXPR is
209 not, in fact, zero. */
212 build_vbase_path (code
, type
, expr
, path
, nonnull
)
214 tree type
, expr
, path
;
217 register int changed
= 0;
218 tree last
= NULL_TREE
, last_virtual
= NULL_TREE
;
220 tree null_expr
= 0, nonnull_expr
;
222 tree offset
= integer_zero_node
;
224 if (BINFO_INHERITANCE_CHAIN (path
) == NULL_TREE
)
225 return build1 (NOP_EXPR
, type
, expr
);
227 /* We could do better if we had additional logic to convert back to the
228 unconverted type (the static type of the complete object), and then
229 convert back to the type we want. Until that is done, we only optimize
230 if the complete type is the same type as expr has. */
231 fixed_type_p
= resolves_to_fixed_type_p (expr
, &nonnull
);
233 if (!fixed_type_p
&& TREE_SIDE_EFFECTS (expr
))
234 expr
= save_expr (expr
);
237 if (BINFO_INHERITANCE_CHAIN (path
))
238 path
= reverse_path (path
);
240 basetype
= BINFO_TYPE (path
);
244 if (TREE_VIA_VIRTUAL (path
))
246 last_virtual
= BINFO_TYPE (path
);
247 if (code
== PLUS_EXPR
)
249 changed
= ! fixed_type_p
;
255 /* We already check for ambiguous things in the caller, just
259 tree binfo
= get_binfo (last
, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr
))), 0);
260 nonnull_expr
= convert_pointer_to_real (binfo
, nonnull_expr
);
262 ind
= build_indirect_ref (nonnull_expr
, NULL_PTR
);
263 nonnull_expr
= build_vbase_pointer (ind
, last_virtual
);
265 && TREE_CODE (type
) == POINTER_TYPE
266 && null_expr
== NULL_TREE
)
268 null_expr
= build1 (NOP_EXPR
, build_pointer_type (last_virtual
), integer_zero_node
);
269 expr
= build (COND_EXPR
, build_pointer_type (last_virtual
),
270 build (EQ_EXPR
, boolean_type_node
, expr
,
272 null_expr
, nonnull_expr
);
275 /* else we'll figure out the offset below. */
277 /* Happens in the case of parse errors. */
278 if (nonnull_expr
== error_mark_node
)
279 return error_mark_node
;
283 cp_error ("cannot cast up from virtual baseclass `%T'",
285 return error_mark_node
;
289 path
= BINFO_INHERITANCE_CHAIN (path
);
291 /* LAST is now the last basetype assoc on the path. */
293 /* A pointer to a virtual base member of a non-null object
294 is non-null. Therefore, we only need to test for zeroness once.
295 Make EXPR the canonical expression to deal with here. */
298 TREE_OPERAND (expr
, 2) = nonnull_expr
;
299 TREE_TYPE (expr
) = TREE_TYPE (TREE_OPERAND (expr
, 1))
300 = TREE_TYPE (nonnull_expr
);
305 /* If we go through any virtual base pointers, make sure that
306 casts to BASETYPE from the last virtual base class use
307 the right value for BASETYPE. */
310 tree intype
= TREE_TYPE (TREE_TYPE (expr
));
311 if (TYPE_MAIN_VARIANT (intype
) != BINFO_TYPE (last
))
313 tree binfo
= get_binfo (last
, TYPE_MAIN_VARIANT (intype
), 0);
314 offset
= BINFO_OFFSET (binfo
);
321 offset
= BINFO_OFFSET (binfo_member (last_virtual
,
322 CLASSTYPE_VBASECLASSES (basetype
)));
323 offset
= size_binop (PLUS_EXPR
, offset
, BINFO_OFFSET (last
));
326 offset
= BINFO_OFFSET (last
);
329 if (TREE_INT_CST_LOW (offset
))
331 /* Bash types to make the backend happy. */
332 offset
= cp_convert (type
, offset
);
334 /* This shouldn't be necessary. (mrs) */
335 expr
= build1 (NOP_EXPR
, type
, expr
);
338 /* If expr might be 0, we need to preserve that zeroness. */
342 TREE_TYPE (null_expr
) = type
;
344 null_expr
= build1 (NOP_EXPR
, type
, integer_zero_node
);
345 if (TREE_SIDE_EFFECTS (expr
))
346 expr
= save_expr (expr
);
348 return build (COND_EXPR
, type
,
349 build (EQ_EXPR
, boolean_type_node
, expr
, integer_zero_node
),
351 build (code
, type
, expr
, offset
));
353 else return build (code
, type
, expr
, offset
);
356 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
357 be used multiple times in initialization of multiple inheritance. */
360 TREE_TYPE (expr
) = type
;
364 return build1 (NOP_EXPR
, type
, expr
);
367 /* Virtual function things. */
369 /* Build an entry in the virtual function table.
370 DELTA is the offset for the `this' pointer.
371 PFN is an ADDR_EXPR containing a pointer to the virtual function.
372 Note that the index (DELTA2) in the virtual function table
376 build_vtable_entry (delta
, pfn
)
379 if (flag_vtable_thunks
)
381 HOST_WIDE_INT idelta
= TREE_INT_CST_LOW (delta
);
382 if (idelta
&& ! DECL_ABSTRACT_VIRTUAL_P (TREE_OPERAND (pfn
, 0)))
384 pfn
= build1 (ADDR_EXPR
, vtable_entry_type
,
385 make_thunk (pfn
, idelta
));
386 TREE_READONLY (pfn
) = 1;
387 TREE_CONSTANT (pfn
) = 1;
389 #ifdef GATHER_STATISTICS
390 n_vtable_entries
+= 1;
396 extern int flag_huge_objects
;
397 tree elems
= tree_cons (NULL_TREE
, delta
,
398 tree_cons (NULL_TREE
, integer_zero_node
,
399 build_expr_list (NULL_TREE
, pfn
)));
400 tree entry
= build (CONSTRUCTOR
, vtable_entry_type
, NULL_TREE
, elems
);
402 /* DELTA used to be constructed by `size_int' and/or size_binop,
403 which caused overflow problems when it was negative. That should
406 if (! int_fits_type_p (delta
, delta_type_node
))
408 if (flag_huge_objects
)
409 sorry ("object size exceeds built-in limit for virtual function table implementation");
411 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
414 TREE_CONSTANT (entry
) = 1;
415 TREE_STATIC (entry
) = 1;
416 TREE_READONLY (entry
) = 1;
418 #ifdef GATHER_STATISTICS
419 n_vtable_entries
+= 1;
426 /* Build a vtable entry for FNDECL. DELTA is the amount by which we
427 must adjust the this pointer when calling F. */
430 build_vtable_entry_for_fn (delta
, fndecl
)
436 /* Take the address of the function, considering it to be of an
437 appropriate generic type. */
438 pfn
= build1 (ADDR_EXPR
, vfunc_ptr_type_node
, fndecl
);
439 /* The address of a function can't change. */
440 TREE_CONSTANT (pfn
) = 1;
441 /* Now build the vtable entry itself. */
442 return build_vtable_entry (delta
, pfn
);
445 /* We want to give the assembler the vtable identifier as well as
446 the offset to the function pointer. So we generate
448 __asm__ __volatile__ (".vtable_entry %c0, %c1"
449 : : "s"(&class_vtable),
450 "i"((long)&vtbl[idx].pfn - (long)&vtbl[0])); */
453 build_vtable_entry_ref (basetype
, vtbl
, idx
)
454 tree basetype
, vtbl
, idx
;
456 static char asm_stmt
[] = ".vtable_entry %c0, %c1";
459 s
= build_unary_op (ADDR_EXPR
, TYPE_BINFO_VTABLE (basetype
), 0);
460 s
= build_tree_list (build_string (1, "s"), s
);
462 i
= build_array_ref (vtbl
, idx
);
463 if (!flag_vtable_thunks
)
464 i
= build_component_ref (i
, pfn_identifier
, vtable_entry_type
, 0);
465 i
= build_c_cast (ptrdiff_type_node
, build_unary_op (ADDR_EXPR
, i
, 0));
466 i2
= build_array_ref (vtbl
, build_int_2(0,0));
467 i2
= build_c_cast (ptrdiff_type_node
, build_unary_op (ADDR_EXPR
, i2
, 0));
468 i
= build_binary_op (MINUS_EXPR
, i
, i2
);
469 i
= build_tree_list (build_string (1, "i"), i
);
471 expand_asm_operands (build_string (sizeof(asm_stmt
)-1, asm_stmt
),
472 NULL_TREE
, chainon (s
, i
), NULL_TREE
, 1, NULL
, 0);
475 /* Given an object INSTANCE, return an expression which yields the
476 virtual function vtable element corresponding to INDEX. There are
477 many special cases for INSTANCE which we take care of here, mainly
478 to avoid creating extra tree nodes when we don't have to. */
481 build_vtbl_ref (instance
, idx
)
485 tree basetype
= TREE_TYPE (instance
);
487 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
488 basetype
= TREE_TYPE (basetype
);
490 if (instance
== current_class_ref
)
491 vtbl
= build_vfield_ref (instance
, basetype
);
496 /* Try to figure out what a reference refers to, and
497 access its virtual function table directly. */
498 tree ref
= NULL_TREE
;
500 if (TREE_CODE (instance
) == INDIRECT_REF
501 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance
, 0))) == REFERENCE_TYPE
)
502 ref
= TREE_OPERAND (instance
, 0);
503 else if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
506 if (ref
&& TREE_CODE (ref
) == VAR_DECL
507 && DECL_INITIAL (ref
))
509 tree init
= DECL_INITIAL (ref
);
511 while (TREE_CODE (init
) == NOP_EXPR
512 || TREE_CODE (init
) == NON_LVALUE_EXPR
)
513 init
= TREE_OPERAND (init
, 0);
514 if (TREE_CODE (init
) == ADDR_EXPR
)
516 init
= TREE_OPERAND (init
, 0);
517 if (IS_AGGR_TYPE (TREE_TYPE (init
))
518 && (TREE_CODE (init
) == PARM_DECL
519 || TREE_CODE (init
) == VAR_DECL
))
525 if (IS_AGGR_TYPE (TREE_TYPE (instance
))
526 && (TREE_CODE (instance
) == RESULT_DECL
527 || TREE_CODE (instance
) == PARM_DECL
528 || TREE_CODE (instance
) == VAR_DECL
))
529 vtbl
= TYPE_BINFO_VTABLE (basetype
);
531 vtbl
= build_vfield_ref (instance
, basetype
);
534 assemble_external (vtbl
);
537 build_vtable_entry_ref (basetype
, vtbl
, idx
);
539 aref
= build_array_ref (vtbl
, idx
);
544 /* Given an object INSTANCE, return an expression which yields the
545 virtual function corresponding to INDEX. There are many special
546 cases for INSTANCE which we take care of here, mainly to avoid
547 creating extra tree nodes when we don't have to. */
550 build_vfn_ref (ptr_to_instptr
, instance
, idx
)
551 tree
*ptr_to_instptr
, instance
;
554 tree aref
= build_vtbl_ref (instance
, idx
);
556 /* When using thunks, there is no extra delta, and we get the pfn
558 if (flag_vtable_thunks
)
563 /* Save the intermediate result in a SAVE_EXPR so we don't have to
564 compute each component of the virtual function pointer twice. */
565 if (TREE_CODE (aref
) == INDIRECT_REF
)
566 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
569 = build (PLUS_EXPR
, TREE_TYPE (*ptr_to_instptr
),
571 cp_convert (ptrdiff_type_node
,
572 build_component_ref (aref
, delta_identifier
, NULL_TREE
, 0)));
575 return build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
578 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
579 for the given TYPE. */
582 get_vtable_name (type
)
585 tree type_id
= build_typename_overload (type
);
586 char *buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
)
587 + IDENTIFIER_LENGTH (type_id
) + 2);
588 const char *ptr
= IDENTIFIER_POINTER (type_id
);
590 for (i
= 0; ptr
[i
] == OPERATOR_TYPENAME_FORMAT
[i
]; i
++) ;
592 /* We don't take off the numbers; prepare_fresh_vtable uses the
593 DECL_ASSEMBLER_NAME for the type, which includes the number
594 in `3foo'. If we were to pull them off here, we'd end up with
595 something like `_vt.foo.3bar', instead of a uniform definition. */
596 while (ptr
[i
] >= '0' && ptr
[i
] <= '9')
599 sprintf (buf
, VTABLE_NAME_FORMAT
, ptr
+i
);
600 return get_identifier (buf
);
603 /* Return the offset to the main vtable for a given base BINFO. */
606 get_vfield_offset (binfo
)
610 = size_binop (FLOOR_DIV_EXPR
,
611 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))),
612 size_int (BITS_PER_UNIT
));
613 tmp
= convert (sizetype
, tmp
);
614 return size_binop (PLUS_EXPR
, tmp
, BINFO_OFFSET (binfo
));
617 /* Get the offset to the start of the original binfo that we derived
618 this binfo from. If we find TYPE first, return the offset only
619 that far. The shortened search is useful because the this pointer
620 on method calling is expected to point to a DECL_CONTEXT (fndecl)
621 object, and not a baseclass of it. */
624 get_derived_offset (binfo
, type
)
627 tree offset1
= get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo
)));
630 while (BINFO_BASETYPES (binfo
)
631 && (i
=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
))) != -1)
633 tree binfos
= BINFO_BASETYPES (binfo
);
634 if (BINFO_TYPE (binfo
) == type
)
636 binfo
= TREE_VEC_ELT (binfos
, i
);
638 offset2
= get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo
)));
639 return size_binop (MINUS_EXPR
, offset1
, offset2
);
642 /* Update the rtti info for this class. */
645 set_rtti_entry (virtuals
, offset
, type
)
646 tree virtuals
, offset
, type
;
650 if (CLASSTYPE_COM_INTERFACE (type
))
654 fn
= get_tinfo_fn (type
);
656 /* If someone tries to get RTTI information for a type compiled
657 without RTTI, they're out of luck. By calling __pure_virtual
658 in this case, we give a small clue as to what went wrong. We
659 could consider having a __no_typeinfo function as well, for a
660 more specific hint. */
663 if (flag_vtable_thunks
)
665 /* The first slot holds the offset. */
666 TREE_PURPOSE (virtuals
) = offset
;
668 /* The next node holds the function. */
669 virtuals
= TREE_CHAIN (virtuals
);
670 offset
= integer_zero_node
;
673 /* This slot holds the function to call. */
674 TREE_PURPOSE (virtuals
) = offset
;
675 TREE_VALUE (virtuals
) = fn
;
678 /* Build a virtual function for type TYPE.
679 If BINFO is non-NULL, build the vtable starting with the initial
680 approximation that it is the same as the one which is the head of
681 the association list. */
684 build_vtable (binfo
, type
)
687 tree name
= get_vtable_name (type
);
694 virtuals
= copy_list (BINFO_VIRTUALS (binfo
));
695 decl
= build_lang_decl (VAR_DECL
, name
,
696 TREE_TYPE (BINFO_VTABLE (binfo
)));
698 /* Now do rtti stuff. */
699 offset
= get_derived_offset (TYPE_BINFO (type
), NULL_TREE
);
700 offset
= ssize_binop (MINUS_EXPR
, integer_zero_node
, offset
);
701 set_rtti_entry (virtuals
, offset
, type
);
705 virtuals
= NULL_TREE
;
706 decl
= build_lang_decl (VAR_DECL
, name
, void_type_node
);
709 #ifdef GATHER_STATISTICS
711 n_vtable_elems
+= list_length (virtuals
);
714 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
715 import_export_vtable (decl
, type
, 0);
717 decl
= pushdecl_top_level (decl
);
718 SET_IDENTIFIER_GLOBAL_VALUE (name
, decl
);
719 /* Initialize the association list for this type, based
720 on our first approximation. */
721 TYPE_BINFO_VTABLE (type
) = decl
;
722 TYPE_BINFO_VIRTUALS (type
) = virtuals
;
724 DECL_ARTIFICIAL (decl
) = 1;
725 TREE_STATIC (decl
) = 1;
726 #ifndef WRITABLE_VTABLES
727 /* Make them READONLY by default. (mrs) */
728 TREE_READONLY (decl
) = 1;
730 /* At one time the vtable info was grabbed 2 words at a time. This
731 fails on sparc unless you have 8-byte alignment. (tiemann) */
732 DECL_ALIGN (decl
) = MAX (TYPE_ALIGN (double_type_node
),
735 DECL_VIRTUAL_P (decl
) = 1;
736 DECL_CONTEXT (decl
) = type
;
738 binfo
= TYPE_BINFO (type
);
739 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
743 /* Give TYPE a new virtual function table which is initialized
744 with a skeleton-copy of its original initialization. The only
745 entry that changes is the `delta' entry, so we can really
746 share a lot of structure.
748 FOR_TYPE is the derived type which caused this table to
751 BINFO is the type association which provided TYPE for FOR_TYPE.
753 The order in which vtables are built (by calling this function) for
754 an object must remain the same, otherwise a binary incompatibility
758 prepare_fresh_vtable (binfo
, for_type
)
759 tree binfo
, for_type
;
762 tree orig_decl
= BINFO_VTABLE (binfo
);
775 basetype
= TYPE_MAIN_VARIANT (BINFO_TYPE (binfo
));
777 buf2
= TYPE_ASSEMBLER_NAME_STRING (basetype
);
778 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1;
780 /* We know that the vtable that we are going to create doesn't exist
781 yet in the global namespace, and when we finish, it will be
782 pushed into the global namespace. In complex MI hierarchies, we
783 have to loop while the name we are thinking of adding is globally
784 defined, adding more name components to the vtable name as we
785 loop, until the name is unique. This is because in complex MI
786 cases, we might have the same base more than once. This means
787 that the order in which this function is called for vtables must
788 remain the same, otherwise binary compatibility can be
793 char *buf1
= (char *) alloca (TYPE_ASSEMBLER_NAME_LENGTH (for_type
)
797 sprintf (buf1
, "%s%c%s", TYPE_ASSEMBLER_NAME_STRING (for_type
), joiner
,
799 buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
) + strlen (buf1
) + 1);
800 sprintf (buf
, VTABLE_NAME_FORMAT
, buf1
);
801 name
= get_identifier (buf
);
803 /* If this name doesn't clash, then we can use it, otherwise
804 we add more to the name until it is unique. */
806 if (! IDENTIFIER_GLOBAL_VALUE (name
))
809 /* Set values for next loop through, if the name isn't unique. */
811 path
= BINFO_INHERITANCE_CHAIN (path
);
813 /* We better not run out of stuff to make it unique. */
814 my_friendly_assert (path
!= NULL_TREE
, 368);
816 basetype
= TYPE_MAIN_VARIANT (BINFO_TYPE (path
));
818 if (for_type
== basetype
)
820 /* If we run out of basetypes in the path, we have already
821 found created a vtable with that name before, we now
822 resort to tacking on _%d to distinguish them. */
824 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1 + i
+ 1 + 3;
825 buf1
= (char *) alloca (i
);
827 sprintf (buf1
, "%s%c%s%c%d",
828 TYPE_ASSEMBLER_NAME_STRING (basetype
), joiner
,
830 buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
)
831 + strlen (buf1
) + 1);
832 sprintf (buf
, VTABLE_NAME_FORMAT
, buf1
);
833 name
= get_identifier (buf
);
835 /* If this name doesn't clash, then we can use it,
836 otherwise we add something different to the name until
838 } while (++j
<= 999 && IDENTIFIER_GLOBAL_VALUE (name
));
840 /* Hey, they really like MI don't they? Increase the 3
841 above to 6, and the 999 to 999999. :-) */
842 my_friendly_assert (j
<= 999, 369);
847 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1 + i
;
848 new_buf2
= (char *) alloca (i
);
849 sprintf (new_buf2
, "%s%c%s",
850 TYPE_ASSEMBLER_NAME_STRING (basetype
), joiner
, buf2
);
854 new_decl
= build_lang_decl (VAR_DECL
, name
, TREE_TYPE (orig_decl
));
855 /* Remember which class this vtable is really for. */
856 DECL_CONTEXT (new_decl
) = for_type
;
858 DECL_ARTIFICIAL (new_decl
) = 1;
859 TREE_STATIC (new_decl
) = 1;
860 BINFO_VTABLE (binfo
) = pushdecl_top_level (new_decl
);
861 DECL_VIRTUAL_P (new_decl
) = 1;
862 #ifndef WRITABLE_VTABLES
863 /* Make them READONLY by default. (mrs) */
864 TREE_READONLY (new_decl
) = 1;
866 DECL_ALIGN (new_decl
) = DECL_ALIGN (orig_decl
);
868 /* Make fresh virtual list, so we can smash it later. */
869 BINFO_VIRTUALS (binfo
) = copy_list (BINFO_VIRTUALS (binfo
));
871 if (TREE_VIA_VIRTUAL (binfo
))
873 tree binfo1
= binfo_member (BINFO_TYPE (binfo
),
874 CLASSTYPE_VBASECLASSES (for_type
));
876 /* XXX - This should never happen, if it does, the caller should
877 ensure that the binfo is from for_type's binfos, not from any
878 base type's. We can remove all this code after a while. */
880 warning ("internal inconsistency: binfo offset error for rtti");
882 offset
= BINFO_OFFSET (binfo1
);
885 offset
= BINFO_OFFSET (binfo
);
887 set_rtti_entry (BINFO_VIRTUALS (binfo
),
888 ssize_binop (MINUS_EXPR
, integer_zero_node
, offset
),
891 #ifdef GATHER_STATISTICS
893 n_vtable_elems
+= list_length (BINFO_VIRTUALS (binfo
));
896 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
897 import_export_vtable (new_decl
, for_type
, 0);
899 if (TREE_VIA_VIRTUAL (binfo
))
900 my_friendly_assert (binfo
== binfo_member (BINFO_TYPE (binfo
),
901 CLASSTYPE_VBASECLASSES (current_class_type
)),
903 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
907 /* Access the virtual function table entry that logically
908 contains BASE_FNDECL. VIRTUALS is the virtual function table's
909 initializer. We can run off the end, when dealing with virtual
910 destructors in MI situations, return NULL_TREE in that case. */
913 get_vtable_entry (virtuals
, base_fndecl
)
914 tree virtuals
, base_fndecl
;
916 unsigned HOST_WIDE_INT n
= (HOST_BITS_PER_WIDE_INT
>= BITS_PER_WORD
917 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
))
918 & (((unsigned HOST_WIDE_INT
)1<<(BITS_PER_WORD
-1))-1))
919 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
)));
921 #ifdef GATHER_STATISTICS
922 n_vtable_searches
+= n
;
925 while (n
> 0 && virtuals
)
928 virtuals
= TREE_CHAIN (virtuals
);
934 /* Change the offset for the FNDECL entry to NEW_OFFSET. Also update
935 DECL_VINDEX (FNDECL). */
938 modify_vtable_entry (old_entry_in_list
, new_offset
, fndecl
)
939 tree old_entry_in_list
, new_offset
, fndecl
;
941 tree base_fndecl
= TREE_VALUE (old_entry_in_list
);
943 /* Update the entry. */
944 TREE_PURPOSE (old_entry_in_list
) = new_offset
;
945 TREE_VALUE (old_entry_in_list
) = fndecl
;
947 /* Now assign virtual dispatch information, if unset. We can
948 dispatch this, through any overridden base function. */
949 if (TREE_CODE (DECL_VINDEX (fndecl
)) != INTEGER_CST
)
951 DECL_VINDEX (fndecl
) = DECL_VINDEX (base_fndecl
);
952 DECL_CONTEXT (fndecl
) = DECL_CONTEXT (base_fndecl
);
956 /* Access the virtual function table entry N. VIRTUALS is the virtual
957 function table's initializer. */
960 get_vtable_entry_n (virtuals
, n
)
962 unsigned HOST_WIDE_INT n
;
967 virtuals
= TREE_CHAIN (virtuals
);
972 /* Add a virtual function to all the appropriate vtables for the class
973 T. DECL_VINDEX(X) should be error_mark_node, if we want to
974 allocate a new slot in our table. If it is error_mark_node, we
975 know that no other function from another vtable is overridden by X.
976 HAS_VIRTUAL keeps track of how many virtuals there are in our main
977 vtable for the type, and we build upon the PENDING_VIRTUALS list
981 add_virtual_function (pv
, phv
, has_virtual
, fndecl
, t
)
985 tree t
; /* Structure type. */
987 tree pending_virtuals
= *pv
;
988 tree pending_hard_virtuals
= *phv
;
991 if (current_class_type
== 0)
992 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
994 if (current_class_type
&& t
!= current_class_type
)
995 cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
999 /* If the virtual function is a redefinition of a prior one,
1000 figure out in which base class the new definition goes,
1001 and if necessary, make a fresh virtual function table
1002 to hold that entry. */
1003 if (DECL_VINDEX (fndecl
) == error_mark_node
)
1005 /* We remember that this was the base sub-object for rtti. */
1006 CLASSTYPE_RTTI (t
) = t
;
1008 /* If we are using thunks, use two slots at the front, one
1009 for the offset pointer, one for the tdesc pointer.
1010 For ARM-style vtables, use the same slot for both. */
1011 if (*has_virtual
== 0 && ! CLASSTYPE_COM_INTERFACE (t
))
1013 if (flag_vtable_thunks
)
1019 /* Build a new INT_CST for this DECL_VINDEX. */
1021 static tree index_table
[256];
1023 /* We skip a slot for the offset/tdesc entry. */
1024 int i
= (*has_virtual
)++;
1026 if (i
>= 256 || index_table
[i
] == 0)
1028 idx
= build_int_2 (i
, 0);
1030 index_table
[i
] = idx
;
1033 idx
= index_table
[i
];
1035 /* Now assign virtual dispatch information. */
1036 DECL_VINDEX (fndecl
) = idx
;
1037 DECL_CONTEXT (fndecl
) = t
;
1039 /* Save the state we've computed on the PENDING_VIRTUALS list. */
1040 pending_virtuals
= tree_cons (integer_zero_node
,
1044 /* Might already be INTEGER_CST if declared twice in class. We will
1045 give error later or we've already given it. */
1046 else if (TREE_CODE (DECL_VINDEX (fndecl
)) != INTEGER_CST
)
1048 /* Need an entry in some other virtual function table.
1049 Deal with this after we have laid out our virtual base classes. */
1050 pending_hard_virtuals
= temp_tree_cons (NULL_TREE
,
1052 pending_hard_virtuals
);
1054 *pv
= pending_virtuals
;
1055 *phv
= pending_hard_virtuals
;
1058 /* Obstack on which to build the vector of class methods. */
1059 struct obstack class_obstack
;
1060 extern struct obstack
*current_obstack
;
1062 /* Add method METHOD to class TYPE.
1064 If non-NULL, FIELDS is the entry in the METHOD_VEC vector entry of
1065 the class type where the method should be added. */
1068 add_method (type
, fields
, method
)
1069 tree type
, *fields
, method
;
1071 push_permanent_obstack ();
1073 /* Setting the DECL_CONTEXT and DECL_CLASS_CONTEXT here is probably
1075 DECL_CONTEXT (method
) = type
;
1076 DECL_CLASS_CONTEXT (method
) = type
;
1078 if (fields
&& *fields
)
1079 *fields
= build_overload (method
, *fields
);
1086 if (!CLASSTYPE_METHOD_VEC (type
))
1087 /* Make a new method vector. We start with 8 entries. We must
1088 allocate at least two (for constructors and destructors), and
1089 we're going to end up with an assignment operator at some
1092 We could use a TREE_LIST for now, and convert it to a
1093 TREE_VEC in finish_struct, but we would probably waste more
1094 memory making the links in the list than we would by
1095 over-allocating the size of the vector here. Furthermore,
1096 we would complicate all the code that expects this to be a
1098 CLASSTYPE_METHOD_VEC (type
) = make_tree_vec (8);
1100 method_vec
= CLASSTYPE_METHOD_VEC (type
);
1101 len
= TREE_VEC_LENGTH (method_vec
);
1103 if (DECL_NAME (method
) == constructor_name (type
))
1104 /* A new constructor or destructor. Constructors go in
1105 slot 0; destructors go in slot 1. */
1106 slot
= DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (method
)) ? 1 : 0;
1109 /* See if we already have an entry with this name. */
1110 for (slot
= 2; slot
< len
; ++slot
)
1111 if (!TREE_VEC_ELT (method_vec
, slot
)
1112 || (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec
,
1114 == DECL_NAME (method
)))
1119 /* We need a bigger method vector. */
1120 tree new_vec
= make_tree_vec (2 * len
);
1121 bcopy ((PTR
) &TREE_VEC_ELT (method_vec
, 0),
1122 (PTR
) &TREE_VEC_ELT (new_vec
, 0),
1123 len
* sizeof (tree
));
1125 method_vec
= CLASSTYPE_METHOD_VEC (type
) = new_vec
;
1128 if (DECL_CONV_FN_P (method
) && !TREE_VEC_ELT (method_vec
, slot
))
1130 /* Type conversion operators have to come before
1131 ordinary methods; add_conversions depends on this to
1132 speed up looking for conversion operators. So, if
1133 necessary, we slide some of the vector elements up.
1134 In theory, this makes this algorithm O(N^2) but we
1135 don't expect many conversion operators. */
1136 for (slot
= 2; slot
< len
; ++slot
)
1138 tree fn
= TREE_VEC_ELT (method_vec
, slot
);
1141 /* There are no more entries in the vector, so we
1142 can insert the new conversion operator here. */
1145 if (!DECL_CONV_FN_P (OVL_CURRENT (fn
)))
1146 /* We can insert the new function right at the
1151 if (!TREE_VEC_ELT (method_vec
, slot
))
1152 /* There is nothing in the Ith slot, so we can avoid
1157 /* We know the last slot in the vector is empty
1158 because we know that at this point there's room
1159 for a new function. */
1160 bcopy ((PTR
) &TREE_VEC_ELT (method_vec
, slot
),
1161 (PTR
) &TREE_VEC_ELT (method_vec
, slot
+ 1),
1162 (len
- slot
- 1) * sizeof (tree
));
1163 TREE_VEC_ELT (method_vec
, slot
) = NULL_TREE
;
1168 if (template_class_depth (type
))
1169 /* TYPE is a template class. Don't issue any errors now; wait
1170 until instantiation time to complain. */
1176 /* Check to see if we've already got this method. */
1177 for (fns
= TREE_VEC_ELT (method_vec
, slot
);
1179 fns
= OVL_NEXT (fns
))
1181 tree fn
= OVL_CURRENT (fns
);
1183 if (TREE_CODE (fn
) != TREE_CODE (method
))
1186 if (TREE_CODE (method
) != TEMPLATE_DECL
)
1188 /* [over.load] Member function declarations with the
1189 same name and the same parameter types cannot be
1190 overloaded if any of them is a static member
1191 function declaration. */
1192 if (DECL_STATIC_FUNCTION_P (fn
)
1193 != DECL_STATIC_FUNCTION_P (method
))
1195 tree parms1
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1196 tree parms2
= TYPE_ARG_TYPES (TREE_TYPE (method
));
1198 if (! DECL_STATIC_FUNCTION_P (fn
))
1199 parms1
= TREE_CHAIN (parms1
);
1201 parms2
= TREE_CHAIN (parms2
);
1203 if (compparms (parms1
, parms2
))
1204 cp_error ("`%#D' and `%#D' cannot be overloaded",
1208 /* Since this is an ordinary function in a
1209 non-template class, it's mangled name can be used
1210 as a unique identifier. This technique is only
1211 an optimization; we would get the same results if
1212 we just used decls_match here. */
1213 if (DECL_ASSEMBLER_NAME (fn
)
1214 != DECL_ASSEMBLER_NAME (method
))
1217 else if (!decls_match (fn
, method
))
1220 /* There has already been a declaration of this method
1221 or member template. */
1222 cp_error_at ("`%D' has already been declared in `%T'",
1225 /* We don't call duplicate_decls here to merge the
1226 declarations because that will confuse things if the
1227 methods have inline definitions. In particular, we
1228 will crash while processing the definitions. */
1233 /* Actually insert the new method. */
1234 TREE_VEC_ELT (method_vec
, slot
)
1235 = build_overload (method
, TREE_VEC_ELT (method_vec
, slot
));
1237 /* Add the new binding. */
1238 if (!DECL_CONSTRUCTOR_P (method
)
1239 && !DECL_DESTRUCTOR_P (method
))
1240 push_class_level_binding (DECL_NAME (method
),
1241 TREE_VEC_ELT (method_vec
, slot
));
1246 /* Subroutines of finish_struct. */
1248 /* Look through the list of fields for this struct, deleting
1249 duplicates as we go. This must be recursive to handle
1252 FIELD is the field which may not appear anywhere in FIELDS.
1253 FIELD_PTR, if non-null, is the starting point at which
1254 chained deletions may take place.
1255 The value returned is the first acceptable entry found
1258 Note that anonymous fields which are not of UNION_TYPE are
1259 not duplicates, they are just anonymous fields. This happens
1260 when we have unnamed bitfields, for example. */
1263 delete_duplicate_fields_1 (field
, fields
)
1268 if (DECL_NAME (field
) == 0)
1270 if (! ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
1273 for (x
= TYPE_FIELDS (TREE_TYPE (field
)); x
; x
= TREE_CHAIN (x
))
1274 fields
= delete_duplicate_fields_1 (x
, fields
);
1279 for (x
= fields
; x
; prev
= x
, x
= TREE_CHAIN (x
))
1281 if (DECL_NAME (x
) == 0)
1283 if (! ANON_AGGR_TYPE_P (TREE_TYPE (x
)))
1285 TYPE_FIELDS (TREE_TYPE (x
))
1286 = delete_duplicate_fields_1 (field
, TYPE_FIELDS (TREE_TYPE (x
)));
1287 if (TYPE_FIELDS (TREE_TYPE (x
)) == 0)
1290 fields
= TREE_CHAIN (fields
);
1292 TREE_CHAIN (prev
) = TREE_CHAIN (x
);
1297 if (DECL_NAME (field
) == DECL_NAME (x
))
1299 if (TREE_CODE (field
) == CONST_DECL
1300 && TREE_CODE (x
) == CONST_DECL
)
1301 cp_error_at ("duplicate enum value `%D'", x
);
1302 else if (TREE_CODE (field
) == CONST_DECL
1303 || TREE_CODE (x
) == CONST_DECL
)
1304 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1306 else if (DECL_DECLARES_TYPE_P (field
)
1307 && DECL_DECLARES_TYPE_P (x
))
1309 if (same_type_p (TREE_TYPE (field
), TREE_TYPE (x
)))
1311 cp_error_at ("duplicate nested type `%D'", x
);
1313 else if (DECL_DECLARES_TYPE_P (field
)
1314 || DECL_DECLARES_TYPE_P (x
))
1316 /* Hide tag decls. */
1317 if ((TREE_CODE (field
) == TYPE_DECL
1318 && DECL_ARTIFICIAL (field
))
1319 || (TREE_CODE (x
) == TYPE_DECL
1320 && DECL_ARTIFICIAL (x
)))
1322 cp_error_at ("duplicate field `%D' (as type and non-type)",
1326 cp_error_at ("duplicate member `%D'", x
);
1328 fields
= TREE_CHAIN (fields
);
1330 TREE_CHAIN (prev
) = TREE_CHAIN (x
);
1339 delete_duplicate_fields (fields
)
1343 for (x
= fields
; x
&& TREE_CHAIN (x
); x
= TREE_CHAIN (x
))
1344 TREE_CHAIN (x
) = delete_duplicate_fields_1 (x
, TREE_CHAIN (x
));
1347 /* Change the access of FDECL to ACCESS in T. The access to FDECL is
1348 along the path given by BINFO. Return 1 if change was legit,
1349 otherwise return 0. */
1352 alter_access (t
, binfo
, fdecl
, access
)
1358 tree elem
= purpose_member (t
, DECL_ACCESS (fdecl
));
1361 if (TREE_VALUE (elem
) != access
)
1363 if (TREE_CODE (TREE_TYPE (fdecl
)) == FUNCTION_DECL
)
1364 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl
));
1366 error ("conflicting access specifications for field `%s', ignored",
1367 IDENTIFIER_POINTER (DECL_NAME (fdecl
)));
1371 /* They're changing the access to the same thing they changed
1372 it to before. That's OK. */
1378 enforce_access (binfo
, fdecl
);
1379 DECL_ACCESS (fdecl
) = tree_cons (t
, access
, DECL_ACCESS (fdecl
));
1385 /* Process the USING_DECL, which is a member of T. The METHOD_VEC, if
1386 non-NULL, is the methods of T. The FIELDS are the fields of T. */
1389 handle_using_decl (using_decl
, t
, method_vec
, fields
)
1395 tree ctype
= DECL_INITIAL (using_decl
);
1396 tree name
= DECL_NAME (using_decl
);
1398 = TREE_PRIVATE (using_decl
) ? access_private_node
1399 : TREE_PROTECTED (using_decl
) ? access_protected_node
1400 : access_public_node
;
1402 tree flist
= NULL_TREE
;
1407 binfo
= binfo_or_else (ctype
, t
);
1411 if (name
== constructor_name (ctype
)
1412 || name
== constructor_name_full (ctype
))
1414 cp_error_at ("using-declaration for constructor", using_decl
);
1418 fdecl
= lookup_member (binfo
, name
, 0, 0);
1422 cp_error_at ("no members matching `%D' in `%#T'", using_decl
, ctype
);
1426 /* Functions are represented as TREE_LIST, with the purpose
1427 being the type and the value the functions. Other members
1428 come as themselves. */
1429 if (TREE_CODE (fdecl
) == TREE_LIST
)
1430 /* Ignore base type this came from. */
1431 fdecl
= TREE_VALUE (fdecl
);
1433 if (TREE_CODE (fdecl
) == OVERLOAD
)
1435 /* We later iterate over all functions. */
1437 fdecl
= OVL_FUNCTION (flist
);
1440 name
= DECL_NAME (fdecl
);
1441 n_methods
= method_vec
? TREE_VEC_LENGTH (method_vec
) : 0;
1442 for (i
= 2; i
< n_methods
&& TREE_VEC_ELT (method_vec
, i
); i
++)
1443 if (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec
, i
)))
1446 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl
, t
);
1447 cp_error_at (" because of local method `%#D' with same name",
1448 OVL_CURRENT (TREE_VEC_ELT (method_vec
, i
)));
1452 if (! DECL_LANG_SPECIFIC (fdecl
))
1453 /* We don't currently handle DECL_ACCESS for TYPE_DECLs; just return. */
1456 for (tmp
= fields
; tmp
; tmp
= TREE_CHAIN (tmp
))
1457 if (DECL_NAME (tmp
) == name
)
1459 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl
, t
);
1460 cp_error_at (" because of local field `%#D' with same name", tmp
);
1464 /* Make type T see field decl FDECL with access ACCESS.*/
1469 if (alter_access (t
, binfo
, OVL_FUNCTION (flist
),
1472 flist
= OVL_CHAIN (flist
);
1476 alter_access (t
, binfo
, fdecl
, access
);
1482 int max_has_virtual
;
1486 char cant_have_default_ctor
;
1487 char cant_have_const_ctor
;
1488 char no_const_asn_ref
;
1491 /* Record information about type T derived from its base classes.
1492 Store most of that information in T itself, and place the
1493 remaining information in the struct BASE_INFO.
1495 Propagate basetype offsets throughout the lattice. Note that the
1496 lattice topped by T is really a pair: it's a DAG that gives the
1497 structure of the derivation hierarchy, and it's a list of the
1498 virtual baseclasses that appear anywhere in the DAG. When a vbase
1499 type appears in the DAG, it's offset is 0, and it's children start
1500 their offsets from that point. When a vbase type appears in the list,
1501 its offset is the offset it has in the hierarchy, and its children's
1502 offsets include that offset in theirs.
1504 Returns the index of the first base class to have virtual functions,
1505 or -1 if no such base class. */
1508 finish_base_struct (t
, b
)
1510 struct base_info
*b
;
1512 tree binfos
= TYPE_BINFO_BASETYPES (t
);
1513 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1514 int first_vfn_base_index
= -1;
1515 bzero ((char *) b
, sizeof (struct base_info
));
1517 for (i
= 0; i
< n_baseclasses
; i
++)
1519 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1520 tree basetype
= BINFO_TYPE (base_binfo
);
1522 /* Effective C++ rule 14. We only need to check TYPE_VIRTUAL_P
1523 here because the case of virtual functions but non-virtual
1524 dtor is handled in finish_struct_1. */
1525 if (warn_ecpp
&& ! TYPE_VIRTUAL_P (basetype
)
1526 && TYPE_HAS_DESTRUCTOR (basetype
))
1527 cp_warning ("base class `%#T' has a non-virtual destructor", basetype
);
1529 /* If the type of basetype is incomplete, then
1530 we already complained about that fact
1531 (and we should have fixed it up as well). */
1532 if (TYPE_SIZE (basetype
) == 0)
1535 /* The base type is of incomplete type. It is
1536 probably best to pretend that it does not
1538 if (i
== n_baseclasses
-1)
1539 TREE_VEC_ELT (binfos
, i
) = NULL_TREE
;
1540 TREE_VEC_LENGTH (binfos
) -= 1;
1542 for (j
= i
; j
+1 < n_baseclasses
; j
++)
1543 TREE_VEC_ELT (binfos
, j
) = TREE_VEC_ELT (binfos
, j
+1);
1546 if (! TYPE_HAS_CONST_INIT_REF (basetype
))
1547 b
->cant_have_const_ctor
= 1;
1549 if (TYPE_HAS_CONSTRUCTOR (basetype
)
1550 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype
))
1552 b
->cant_have_default_ctor
= 1;
1553 if (! TYPE_HAS_CONSTRUCTOR (t
))
1555 cp_pedwarn ("base `%T' with only non-default constructor",
1557 cp_pedwarn ("in class without a constructor");
1561 if (TYPE_HAS_ASSIGN_REF (basetype
)
1562 && !TYPE_HAS_CONST_ASSIGN_REF (basetype
))
1563 b
->no_const_asn_ref
= 1;
1565 TYPE_NEEDS_CONSTRUCTING (t
) |= TYPE_NEEDS_CONSTRUCTING (basetype
);
1566 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_NEEDS_DESTRUCTOR (basetype
);
1567 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype
);
1568 TYPE_HAS_COMPLEX_INIT_REF (t
) |= TYPE_HAS_COMPLEX_INIT_REF (basetype
);
1570 TYPE_OVERLOADS_CALL_EXPR (t
) |= TYPE_OVERLOADS_CALL_EXPR (basetype
);
1571 TYPE_OVERLOADS_ARRAY_REF (t
) |= TYPE_OVERLOADS_ARRAY_REF (basetype
);
1572 TYPE_OVERLOADS_ARROW (t
) |= TYPE_OVERLOADS_ARROW (basetype
);
1574 if (CLASSTYPE_COM_INTERFACE (basetype
))
1576 CLASSTYPE_COM_INTERFACE (t
) = 1;
1579 ("COM interface type `%T' must be the leftmost base class",
1582 else if (CLASSTYPE_COM_INTERFACE (t
) && i
== 0)
1584 cp_error ("COM interface type `%T' with non-COM base class `%T'",
1586 CLASSTYPE_COM_INTERFACE (t
) = 0;
1589 if (TYPE_VIRTUAL_P (basetype
))
1591 /* Ensure that this is set from at least a virtual base
1593 if (b
->rtti
== NULL_TREE
)
1594 b
->rtti
= CLASSTYPE_RTTI (basetype
);
1596 /* Don't borrow virtuals from virtual baseclasses. */
1597 if (TREE_VIA_VIRTUAL (base_binfo
))
1600 if (first_vfn_base_index
< 0)
1603 first_vfn_base_index
= i
;
1605 /* Update these two, now that we know what vtable we are
1606 going to extend. This is so that we can add virtual
1607 functions, and override them properly. */
1608 TYPE_BINFO_VTABLE (t
) = TYPE_BINFO_VTABLE (basetype
);
1609 TYPE_BINFO_VIRTUALS (t
) = TYPE_BINFO_VIRTUALS (basetype
);
1610 b
->has_virtual
= CLASSTYPE_VSIZE (basetype
);
1611 b
->vfield
= CLASSTYPE_VFIELD (basetype
);
1612 b
->vfields
= copy_list (CLASSTYPE_VFIELDS (basetype
));
1613 vfields
= b
->vfields
;
1616 if (VF_BINFO_VALUE (vfields
) == NULL_TREE
1617 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
)))
1619 tree value
= VF_BASETYPE_VALUE (vfields
);
1620 if (DECL_NAME (CLASSTYPE_VFIELD (value
))
1621 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1622 VF_NORMAL_VALUE (b
->vfields
) = basetype
;
1624 VF_NORMAL_VALUE (b
->vfields
) = VF_NORMAL_VALUE (vfields
);
1626 vfields
= TREE_CHAIN (vfields
);
1628 CLASSTYPE_VFIELD (t
) = b
->vfield
;
1632 /* Only add unique vfields, and flatten them out as we go. */
1633 tree vfields
= CLASSTYPE_VFIELDS (basetype
);
1636 if (VF_BINFO_VALUE (vfields
) == NULL_TREE
1637 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
)))
1639 tree value
= VF_BASETYPE_VALUE (vfields
);
1640 b
->vfields
= tree_cons (base_binfo
, value
, b
->vfields
);
1641 if (DECL_NAME (CLASSTYPE_VFIELD (value
))
1642 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1643 VF_NORMAL_VALUE (b
->vfields
) = basetype
;
1645 VF_NORMAL_VALUE (b
->vfields
) = VF_NORMAL_VALUE (vfields
);
1647 vfields
= TREE_CHAIN (vfields
);
1650 if (b
->has_virtual
== 0)
1652 first_vfn_base_index
= i
;
1654 /* Update these two, now that we know what vtable we are
1655 going to extend. This is so that we can add virtual
1656 functions, and override them properly. */
1657 TYPE_BINFO_VTABLE (t
) = TYPE_BINFO_VTABLE (basetype
);
1658 TYPE_BINFO_VIRTUALS (t
) = TYPE_BINFO_VIRTUALS (basetype
);
1659 b
->has_virtual
= CLASSTYPE_VSIZE (basetype
);
1660 b
->vfield
= CLASSTYPE_VFIELD (basetype
);
1661 CLASSTYPE_VFIELD (t
) = b
->vfield
;
1662 /* When we install the first one, set the VF_NORMAL_VALUE
1663 to be the current class, as this it is the most derived
1664 class. Hopefully, this is not set to something else
1666 vfields
= b
->vfields
;
1669 if (DECL_NAME (CLASSTYPE_VFIELD (t
))
1670 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1672 VF_NORMAL_VALUE (vfields
) = t
;
1673 /* There should only be one of them! And it should
1674 always be found, if we get into here. (mrs) */
1677 vfields
= TREE_CHAIN (vfields
);
1686 /* Find the base class with the largest number of virtual functions. */
1687 for (vfields
= b
->vfields
; vfields
; vfields
= TREE_CHAIN (vfields
))
1689 if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields
)) > b
->max_has_virtual
)
1690 b
->max_has_virtual
= CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields
));
1691 if (VF_DERIVED_VALUE (vfields
)
1692 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields
)) > b
->max_has_virtual
)
1693 b
->max_has_virtual
= CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields
));
1698 /* If all virtual functions come only from virtual baseclasses. */
1701 /* Update the rtti base if we have a non-virtual base class version
1703 b
->rtti
= CLASSTYPE_RTTI (BINFO_TYPE (TREE_VEC_ELT (binfos
, first_vfn_base_index
)));
1705 return first_vfn_base_index
;
1708 /* Set memoizing fields and bits of T (and its variants) for later use.
1709 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1712 finish_struct_bits (t
, max_has_virtual
)
1714 int max_has_virtual
;
1716 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (t
);
1718 /* Fix up variants (if any). */
1719 tree variants
= TYPE_NEXT_VARIANT (t
);
1722 /* These fields are in the _TYPE part of the node, not in
1723 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1724 TYPE_HAS_CONSTRUCTOR (variants
) = TYPE_HAS_CONSTRUCTOR (t
);
1725 TYPE_HAS_DESTRUCTOR (variants
) = TYPE_HAS_DESTRUCTOR (t
);
1726 TYPE_NEEDS_CONSTRUCTING (variants
) = TYPE_NEEDS_CONSTRUCTING (t
);
1727 TYPE_NEEDS_DESTRUCTOR (variants
) = TYPE_NEEDS_DESTRUCTOR (t
);
1729 TYPE_USES_COMPLEX_INHERITANCE (variants
) = TYPE_USES_COMPLEX_INHERITANCE (t
);
1730 TYPE_VIRTUAL_P (variants
) = TYPE_VIRTUAL_P (t
);
1731 TYPE_USES_VIRTUAL_BASECLASSES (variants
) = TYPE_USES_VIRTUAL_BASECLASSES (t
);
1732 /* Copy whatever these are holding today. */
1733 TYPE_MIN_VALUE (variants
) = TYPE_MIN_VALUE (t
);
1734 TYPE_MAX_VALUE (variants
) = TYPE_MAX_VALUE (t
);
1735 TYPE_FIELDS (variants
) = TYPE_FIELDS (t
);
1736 TYPE_SIZE (variants
) = TYPE_SIZE (t
);
1737 TYPE_SIZE_UNIT (variants
) = TYPE_SIZE_UNIT (t
);
1738 variants
= TYPE_NEXT_VARIANT (variants
);
1741 if (n_baseclasses
&& max_has_virtual
)
1743 /* For a class w/o baseclasses, `finish_struct' has set
1744 CLASS_TYPE_ABSTRACT_VIRTUALS correctly (by definition). Similarly
1745 for a class who's base classes do not have vtables. When neither
1746 of these is true, we might have removed abstract virtuals (by
1747 providing a definition), added some (by declaring new ones), or
1748 redeclared ones from a base class. We need to recalculate what's
1749 really an abstract virtual at this point (by looking in the
1751 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = get_abstract_virtuals (t
);
1756 /* Notice whether this class has type conversion functions defined. */
1757 tree binfo
= TYPE_BINFO (t
);
1758 tree binfos
= BINFO_BASETYPES (binfo
);
1761 for (i
= n_baseclasses
-1; i
>= 0; i
--)
1763 basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
1765 TYPE_HAS_CONVERSION (t
) |= TYPE_HAS_CONVERSION (basetype
);
1769 /* If this type has a copy constructor, force its mode to be BLKmode, and
1770 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1771 be passed by invisible reference and prevent it from being returned in
1774 Also do this if the class has BLKmode but can still be returned in
1775 registers, since function_cannot_inline_p won't let us inline
1776 functions returning such a type. This affects the HP-PA. */
1777 if (! TYPE_HAS_TRIVIAL_INIT_REF (t
)
1778 || (TYPE_MODE (t
) == BLKmode
&& ! aggregate_value_p (t
)
1779 && CLASSTYPE_NON_AGGREGATE (t
)))
1782 DECL_MODE (TYPE_MAIN_DECL (t
)) = BLKmode
;
1783 for (variants
= t
; variants
; variants
= TYPE_NEXT_VARIANT (variants
))
1785 TYPE_MODE (variants
) = BLKmode
;
1786 TREE_ADDRESSABLE (variants
) = 1;
1791 /* Issue warnings about T having private constructors, but no friends,
1794 HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
1795 static members. HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
1796 non-private static member functions. */
1799 maybe_warn_about_overly_private_class (t
)
1802 int has_member_fn
= 0;
1803 int has_nonprivate_method
= 0;
1806 if (!warn_ctor_dtor_privacy
1807 /* If the class has friends, those entities might create and
1808 access instances, so we should not warn. */
1809 || (CLASSTYPE_FRIEND_CLASSES (t
)
1810 || DECL_FRIENDLIST (TYPE_MAIN_DECL (t
)))
1811 /* We will have warned when the template was declared; there's
1812 no need to warn on every instantiation. */
1813 || CLASSTYPE_TEMPLATE_INSTANTIATION (t
))
1814 /* There's no reason to even consider warning about this
1818 /* We only issue one warning, if more than one applies, because
1819 otherwise, on code like:
1822 // Oops - forgot `public:'
1828 we warn several times about essentially the same problem. */
1830 /* Check to see if all (non-constructor, non-destructor) member
1831 functions are private. (Since there are no friends or
1832 non-private statics, we can't ever call any of the private member
1834 for (fn
= TYPE_METHODS (t
); fn
; fn
= TREE_CHAIN (fn
))
1835 /* We're not interested in compiler-generated methods; they don't
1836 provide any way to call private members. */
1837 if (!DECL_ARTIFICIAL (fn
))
1839 if (!TREE_PRIVATE (fn
))
1841 if (DECL_STATIC_FUNCTION_P (fn
))
1842 /* A non-private static member function is just like a
1843 friend; it can create and invoke private member
1844 functions, and be accessed without a class
1848 has_nonprivate_method
= 1;
1851 else if (!DECL_CONSTRUCTOR_P (fn
) && !DECL_DESTRUCTOR_P (fn
))
1855 if (!has_nonprivate_method
&& has_member_fn
)
1857 /* There are no non-private methods, and there's at least one
1858 private member function that isn't a constructor or
1859 destructor. (If all the private members are
1860 constructors/destructors we want to use the code below that
1861 issues error messages specifically referring to
1862 constructors/destructors.) */
1864 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
1865 for (i
= 0; i
< CLASSTYPE_N_BASECLASSES (t
); i
++)
1866 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos
, i
))
1867 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos
, i
)))
1869 has_nonprivate_method
= 1;
1872 if (!has_nonprivate_method
)
1874 cp_warning ("all member functions in class `%T' are private", t
);
1879 /* Even if some of the member functions are non-private, the class
1880 won't be useful for much if all the constructors or destructors
1881 are private: such an object can never be created or destroyed. */
1882 if (TYPE_HAS_DESTRUCTOR (t
))
1884 tree dtor
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t
), 1);
1886 if (TREE_PRIVATE (dtor
))
1888 cp_warning ("`%#T' only defines a private destructor and has no friends",
1894 if (TYPE_HAS_CONSTRUCTOR (t
))
1896 int nonprivate_ctor
= 0;
1898 /* If a non-template class does not define a copy
1899 constructor, one is defined for it, enabling it to avoid
1900 this warning. For a template class, this does not
1901 happen, and so we would normally get a warning on:
1903 template <class T> class C { private: C(); };
1905 To avoid this asymmetry, we check TYPE_HAS_INIT_REF. All
1906 complete non-template or fully instantiated classes have this
1908 if (!TYPE_HAS_INIT_REF (t
))
1909 nonprivate_ctor
= 1;
1911 for (fn
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t
), 0);
1915 tree ctor
= OVL_CURRENT (fn
);
1916 /* Ideally, we wouldn't count copy constructors (or, in
1917 fact, any constructor that takes an argument of the
1918 class type as a parameter) because such things cannot
1919 be used to construct an instance of the class unless
1920 you already have one. But, for now at least, we're
1922 if (! TREE_PRIVATE (ctor
))
1924 nonprivate_ctor
= 1;
1929 if (nonprivate_ctor
== 0)
1931 cp_warning ("`%#T' only defines private constructors and has no friends",
1938 /* Function to help qsort sort FIELD_DECLs by name order. */
1941 field_decl_cmp (x
, y
)
1944 if (DECL_NAME (*x
) == DECL_NAME (*y
))
1946 if (DECL_NAME (*x
) == NULL_TREE
)
1948 if (DECL_NAME (*y
) == NULL_TREE
)
1950 if (DECL_NAME (*x
) < DECL_NAME (*y
))
1955 /* Comparison function to compare two TYPE_METHOD_VEC entries by name. */
1958 method_name_cmp (m1
, m2
)
1959 const tree
*m1
, *m2
;
1961 if (*m1
== NULL_TREE
&& *m2
== NULL_TREE
)
1963 if (*m1
== NULL_TREE
)
1965 if (*m2
== NULL_TREE
)
1967 if (DECL_NAME (OVL_CURRENT (*m1
)) < DECL_NAME (OVL_CURRENT (*m2
)))
1972 /* Warn about duplicate methods in fn_fields. Also compact method
1973 lists so that lookup can be made faster.
1975 Data Structure: List of method lists. The outer list is a
1976 TREE_LIST, whose TREE_PURPOSE field is the field name and the
1977 TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN
1978 links the entire list of methods for TYPE_METHODS. Friends are
1979 chained in the same way as member functions (? TREE_CHAIN or
1980 DECL_CHAIN), but they live in the TREE_TYPE field of the outer
1981 list. That allows them to be quickly deleted, and requires no
1984 If there are any constructors/destructors, they are moved to the
1985 front of the list. This makes pushclass more efficient.
1987 @@ The above comment is obsolete. It mostly describes what add_method
1988 @@ and add_implicitly_declared_members do.
1990 Sort methods that are not special (i.e., constructors, destructors, and
1991 type conversion operators) so that we can find them faster in search. */
1994 finish_struct_methods (t
)
1998 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
1999 tree ctor_name
= constructor_name (t
);
2000 int slot
, len
= method_vec
? TREE_VEC_LENGTH (method_vec
) : 0;
2002 /* First fill in entry 0 with the constructors, entry 1 with destructors,
2003 and the next few with type conversion operators (if any). */
2004 for (fn_fields
= TYPE_METHODS (t
); fn_fields
;
2005 fn_fields
= TREE_CHAIN (fn_fields
))
2007 tree fn_name
= DECL_NAME (fn_fields
);
2009 /* Clear out this flag.
2011 @@ Doug may figure out how to break
2012 @@ this with nested classes and friends. */
2013 DECL_IN_AGGR_P (fn_fields
) = 0;
2015 /* Note here that a copy ctor is private, so we don't dare generate
2016 a default copy constructor for a class that has a member
2017 of this type without making sure they have access to it. */
2018 if (fn_name
== ctor_name
)
2020 tree parmtypes
= FUNCTION_ARG_CHAIN (fn_fields
);
2021 tree parmtype
= parmtypes
? TREE_VALUE (parmtypes
) : void_type_node
;
2023 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
2024 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
)) == t
)
2026 if (TREE_CHAIN (parmtypes
) == NULL_TREE
2027 || TREE_CHAIN (parmtypes
) == void_list_node
2028 || TREE_PURPOSE (TREE_CHAIN (parmtypes
)))
2030 if (TREE_PROTECTED (fn_fields
))
2031 TYPE_HAS_NONPUBLIC_CTOR (t
) = 1;
2032 else if (TREE_PRIVATE (fn_fields
))
2033 TYPE_HAS_NONPUBLIC_CTOR (t
) = 2;
2037 else if (fn_name
== ansi_opname
[(int) MODIFY_EXPR
])
2039 tree parmtype
= TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields
));
2041 if (copy_assignment_arg_p (parmtype
, DECL_VIRTUAL_P (fn_fields
)))
2043 if (TREE_PROTECTED (fn_fields
))
2044 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t
) = 1;
2045 else if (TREE_PRIVATE (fn_fields
))
2046 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t
) = 2;
2051 if (TYPE_HAS_DESTRUCTOR (t
) && !TREE_VEC_ELT (method_vec
, 1))
2052 /* We thought there was a destructor, but there wasn't. Some
2053 parse errors cause this anomalous situation. */
2054 TYPE_HAS_DESTRUCTOR (t
) = 0;
2056 /* Issue warnings about private constructors and such. If there are
2057 no methods, then some public defaults are generated. */
2058 maybe_warn_about_overly_private_class (t
);
2060 if (method_vec
== NULL_TREE
)
2063 /* Now sort the methods. */
2064 while (len
> 2 && TREE_VEC_ELT (method_vec
, len
-1) == NULL_TREE
)
2066 TREE_VEC_LENGTH (method_vec
) = len
;
2068 /* The type conversion ops have to live at the front of the vec, so we
2070 for (slot
= 2; slot
< len
; ++slot
)
2072 tree fn
= TREE_VEC_ELT (method_vec
, slot
);
2074 if (!DECL_CONV_FN_P (OVL_CURRENT (fn
)))
2078 qsort (&TREE_VEC_ELT (method_vec
, slot
), len
-slot
, sizeof (tree
),
2079 (int (*)(const void *, const void *))method_name_cmp
);
2082 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2085 duplicate_tag_error (t
)
2088 cp_error ("redefinition of `%#T'", t
);
2089 cp_error_at ("previous definition here", t
);
2091 /* Pretend we haven't defined this type. */
2093 /* All of the component_decl's were TREE_CHAINed together in the parser.
2094 finish_struct_methods walks these chains and assembles all methods with
2095 the same base name into DECL_CHAINs. Now we don't need the parser chains
2096 anymore, so we unravel them. */
2098 /* This used to be in finish_struct, but it turns out that the
2099 TREE_CHAIN is used by dbxout_type_methods and perhaps some other
2101 if (CLASSTYPE_METHOD_VEC (t
))
2103 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
2104 int i
, len
= TREE_VEC_LENGTH (method_vec
);
2105 for (i
= 0; i
< len
; i
++)
2107 tree unchain
= TREE_VEC_ELT (method_vec
, i
);
2108 while (unchain
!= NULL_TREE
)
2110 TREE_CHAIN (OVL_CURRENT (unchain
)) = NULL_TREE
;
2111 unchain
= OVL_NEXT (unchain
);
2116 if (TYPE_LANG_SPECIFIC (t
))
2118 tree binfo
= TYPE_BINFO (t
);
2119 int interface_only
= CLASSTYPE_INTERFACE_ONLY (t
);
2120 int interface_unknown
= CLASSTYPE_INTERFACE_UNKNOWN (t
);
2121 tree template_info
= CLASSTYPE_TEMPLATE_INFO (t
);
2122 int use_template
= CLASSTYPE_USE_TEMPLATE (t
);
2124 bzero ((char *) TYPE_LANG_SPECIFIC (t
), sizeof (struct lang_type
));
2125 BINFO_BASETYPES(binfo
) = NULL_TREE
;
2127 TYPE_BINFO (t
) = binfo
;
2128 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
2129 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t
, interface_unknown
);
2130 TYPE_REDEFINED (t
) = 1;
2131 CLASSTYPE_TEMPLATE_INFO (t
) = template_info
;
2132 CLASSTYPE_USE_TEMPLATE (t
) = use_template
;
2134 TYPE_SIZE (t
) = NULL_TREE
;
2135 TYPE_MODE (t
) = VOIDmode
;
2136 TYPE_FIELDS (t
) = NULL_TREE
;
2137 TYPE_METHODS (t
) = NULL_TREE
;
2138 TYPE_VFIELD (t
) = NULL_TREE
;
2139 TYPE_CONTEXT (t
) = NULL_TREE
;
2140 TYPE_NONCOPIED_PARTS (t
) = NULL_TREE
;
2143 /* Construct the initializer for BINFOs virtual function table. */
2146 build_vtbl_initializer (binfo
)
2149 tree v
= BINFO_VIRTUALS (binfo
);
2150 tree inits
= NULL_TREE
;
2152 /* Process the RTTI stuff at the head of the list. If we're not
2153 using vtable thunks, then the RTTI entry is just an ordinary
2154 function, and we can process it just like the other virtual
2155 function entries. */
2156 if (!CLASSTYPE_COM_INTERFACE (BINFO_TYPE (binfo
))
2157 && flag_vtable_thunks
)
2162 /* The first entry is an offset. */
2163 offset
= TREE_PURPOSE (v
);
2164 my_friendly_assert (TREE_CODE (offset
) == INTEGER_CST
,
2167 /* Convert the offset to look like a function pointer, so that
2168 we can put it in the vtable. */
2169 init
= build1 (NOP_EXPR
, vfunc_ptr_type_node
, offset
);
2170 TREE_CONSTANT (init
) = 1;
2171 init
= build_vtable_entry (integer_zero_node
, init
);
2172 inits
= tree_cons (NULL_TREE
, init
, inits
);
2174 /* Even in this case, the second entry (the tdesc pointer) is
2175 just an ordinary function. */
2179 /* Go through all the ordinary virtual functions, building up
2187 /* Pull the offset for `this', and the function to call, out of
2189 delta
= TREE_PURPOSE (v
);
2190 fn
= TREE_VALUE (v
);
2191 my_friendly_assert (TREE_CODE (delta
) == INTEGER_CST
, 19990727);
2192 my_friendly_assert (TREE_CODE (fn
) == FUNCTION_DECL
, 19990727);
2194 /* You can't call an abstract virtual function; it's abstract.
2195 So, we replace these functions with __pure_virtual. */
2196 if (DECL_ABSTRACT_VIRTUAL_P (fn
))
2199 /* Package up that information for the vtable. */
2200 init
= build_vtable_entry_for_fn (delta
, fn
);
2201 /* And add it to the chain of initializers. */
2202 inits
= tree_cons (NULL_TREE
, init
, inits
);
2208 /* The initializers were built up in reverse order; straighten them
2210 inits
= nreverse (inits
);
2211 /* Package all the initializers up as an array initializer. */
2212 return build_nt (CONSTRUCTOR
, NULL_TREE
, inits
);
2215 /* finish up all new vtables. */
2218 finish_vtbls (binfo
, do_self
, t
)
2223 tree binfos
= BINFO_BASETYPES (binfo
);
2224 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2226 /* Should we use something besides CLASSTYPE_VFIELDS? */
2227 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2229 if (BINFO_NEW_VTABLE_MARKED (binfo
))
2233 decl
= BINFO_VTABLE (binfo
);
2234 context
= DECL_CONTEXT (decl
);
2235 DECL_CONTEXT (decl
) = 0;
2236 DECL_INITIAL (decl
) = build_vtbl_initializer (binfo
);
2237 cp_finish_decl (decl
, DECL_INITIAL (decl
), NULL_TREE
, 0, 0);
2238 DECL_CONTEXT (decl
) = context
;
2240 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2243 for (i
= 0; i
< n_baselinks
; i
++)
2245 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2246 int is_not_base_vtable
2247 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2248 if (TREE_VIA_VIRTUAL (base_binfo
))
2249 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
),
2250 CLASSTYPE_VBASECLASSES (t
));
2251 finish_vtbls (base_binfo
, is_not_base_vtable
, t
);
2255 /* True if we should override the given BASE_FNDECL with the given
2259 overrides (fndecl
, base_fndecl
)
2260 tree fndecl
, base_fndecl
;
2262 /* Destructors have special names. */
2263 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl
))
2264 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2266 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl
))
2267 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2269 if (DECL_NAME (fndecl
) == DECL_NAME (base_fndecl
))
2271 tree types
, base_types
;
2273 retypes
= TREE_TYPE (TREE_TYPE (fndecl
));
2274 base_retypes
= TREE_TYPE (TREE_TYPE (base_fndecl
));
2276 types
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2277 base_types
= TYPE_ARG_TYPES (TREE_TYPE (base_fndecl
));
2278 if ((TYPE_QUALS (TREE_TYPE (TREE_VALUE (base_types
)))
2279 == TYPE_QUALS (TREE_TYPE (TREE_VALUE (types
))))
2280 && compparms (TREE_CHAIN (base_types
), TREE_CHAIN (types
)))
2287 get_class_offset_1 (parent
, binfo
, context
, t
, fndecl
)
2288 tree parent
, binfo
, context
, t
, fndecl
;
2290 tree binfos
= BINFO_BASETYPES (binfo
);
2291 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2292 tree rval
= NULL_TREE
;
2294 if (binfo
== parent
)
2295 return error_mark_node
;
2297 for (i
= 0; i
< n_baselinks
; i
++)
2299 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2302 if (TREE_VIA_VIRTUAL (base_binfo
))
2303 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
),
2304 CLASSTYPE_VBASECLASSES (t
));
2305 nrval
= get_class_offset_1 (parent
, base_binfo
, context
, t
, fndecl
);
2306 /* See if we have a new value */
2307 if (nrval
&& (nrval
!= error_mark_node
|| rval
==0))
2309 /* Only compare if we have two offsets */
2310 if (rval
&& rval
!= error_mark_node
2311 && ! tree_int_cst_equal (nrval
, rval
))
2313 /* Only give error if the two offsets are different */
2314 error ("every virtual function must have a unique final overrider");
2315 cp_error (" found two (or more) `%T' class subobjects in `%T'", context
, t
);
2316 cp_error (" with virtual `%D' from virtual base class", fndecl
);
2322 if (rval
&& BINFO_TYPE (binfo
) == context
)
2324 my_friendly_assert (rval
== error_mark_node
2325 || tree_int_cst_equal (rval
, BINFO_OFFSET (binfo
)), 999);
2326 rval
= BINFO_OFFSET (binfo
);
2332 /* Get the offset to the CONTEXT subobject that is related to the
2336 get_class_offset (context
, t
, binfo
, fndecl
)
2337 tree context
, t
, binfo
, fndecl
;
2339 tree first_binfo
= binfo
;
2344 return integer_zero_node
;
2346 if (BINFO_TYPE (binfo
) == context
)
2347 return BINFO_OFFSET (binfo
);
2349 /* Check less derived binfos first. */
2350 while (BINFO_BASETYPES (binfo
)
2351 && (i
=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
))) != -1)
2353 tree binfos
= BINFO_BASETYPES (binfo
);
2354 binfo
= TREE_VEC_ELT (binfos
, i
);
2355 if (BINFO_TYPE (binfo
) == context
)
2356 return BINFO_OFFSET (binfo
);
2359 /* Ok, not found in the less derived binfos, now check the more
2361 offset
= get_class_offset_1 (first_binfo
, TYPE_BINFO (t
), context
, t
, fndecl
);
2362 if (offset
==0 || TREE_CODE (offset
) != INTEGER_CST
)
2363 my_friendly_abort (999); /* we have to find it. */
2367 /* Skip RTTI information at the front of the virtual list. */
2369 unsigned HOST_WIDE_INT
2370 skip_rtti_stuff (virtuals
, t
)
2375 if (CLASSTYPE_COM_INTERFACE (t
))
2381 /* We always reserve a slot for the offset/tdesc entry. */
2383 *virtuals
= TREE_CHAIN (*virtuals
);
2385 if (flag_vtable_thunks
&& *virtuals
)
2387 /* The second slot is reserved for the tdesc pointer when thunks
2390 *virtuals
= TREE_CHAIN (*virtuals
);
2396 modify_one_vtable (binfo
, t
, fndecl
)
2397 tree binfo
, t
, fndecl
;
2399 tree virtuals
= BINFO_VIRTUALS (binfo
);
2400 unsigned HOST_WIDE_INT n
;
2402 /* update rtti entry */
2405 if (binfo
== TYPE_BINFO (t
))
2407 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2408 build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t
))), t
);
2412 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2413 prepare_fresh_vtable (binfo
, t
);
2416 if (fndecl
== NULL_TREE
)
2419 n
= skip_rtti_stuff (&virtuals
, BINFO_TYPE (binfo
));
2423 tree current_fndecl
= TREE_VALUE (virtuals
);
2425 /* We should never have an instance of __pure_virtual on the
2426 BINFO_VIRTUALS list. If we do, then we will never notice
2427 that the function that should have been there instead has
2429 my_friendly_assert (current_fndecl
!= abort_fndecl
,
2432 if (current_fndecl
&& overrides (fndecl
, current_fndecl
))
2434 tree base_offset
, offset
;
2435 tree context
= DECL_CLASS_CONTEXT (fndecl
);
2436 tree vfield
= CLASSTYPE_VFIELD (t
);
2439 offset
= get_class_offset (context
, t
, binfo
, fndecl
);
2441 /* Find the right offset for the this pointer based on the
2442 base class we just found. We have to take into
2443 consideration the virtual base class pointers that we
2444 stick in before the virtual function table pointer.
2446 Also, we want just the delta between the most base class
2447 that we derived this vfield from and us. */
2448 base_offset
= size_binop (PLUS_EXPR
,
2449 get_derived_offset (binfo
, DECL_CONTEXT (current_fndecl
)),
2450 BINFO_OFFSET (binfo
));
2451 this_offset
= ssize_binop (MINUS_EXPR
, offset
, base_offset
);
2453 if (binfo
== TYPE_BINFO (t
))
2455 /* In this case, it is *type*'s vtable we are modifying.
2456 We start with the approximation that it's vtable is that
2457 of the immediate base class. */
2458 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2459 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield
)), t
);
2463 /* This is our very own copy of `basetype' to play with.
2464 Later, we will fill in all the virtual functions
2465 that override the virtual functions in these base classes
2466 which are not defined by the current type. */
2467 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2468 prepare_fresh_vtable (binfo
, t
);
2472 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo
)));
2474 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo
), n
),
2479 virtuals
= TREE_CHAIN (virtuals
);
2483 /* These are the ones that are not through virtual base classes. */
2486 modify_all_direct_vtables (binfo
, do_self
, t
, fndecl
)
2491 tree binfos
= BINFO_BASETYPES (binfo
);
2492 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2494 /* Should we use something besides CLASSTYPE_VFIELDS? */
2495 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2496 modify_one_vtable (binfo
, t
, fndecl
);
2498 for (i
= 0; i
< n_baselinks
; i
++)
2500 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2501 int is_not_base_vtable
2502 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2503 if (! TREE_VIA_VIRTUAL (base_binfo
))
2504 modify_all_direct_vtables (base_binfo
, is_not_base_vtable
, t
, fndecl
);
2508 /* Fixup all the delta entries in this one vtable that need updating. */
2511 fixup_vtable_deltas1 (binfo
, t
)
2514 tree virtuals
= BINFO_VIRTUALS (binfo
);
2515 unsigned HOST_WIDE_INT n
;
2517 n
= skip_rtti_stuff (&virtuals
, BINFO_TYPE (binfo
));
2521 tree fndecl
= TREE_VALUE (virtuals
);
2522 tree delta
= TREE_PURPOSE (virtuals
);
2526 tree base_offset
, offset
;
2527 tree context
= DECL_CLASS_CONTEXT (fndecl
);
2528 tree vfield
= CLASSTYPE_VFIELD (t
);
2531 offset
= get_class_offset (context
, t
, binfo
, fndecl
);
2533 /* Find the right offset for the this pointer based on the
2534 base class we just found. We have to take into
2535 consideration the virtual base class pointers that we
2536 stick in before the virtual function table pointer.
2538 Also, we want just the delta between the most base class
2539 that we derived this vfield from and us. */
2540 base_offset
= size_binop (PLUS_EXPR
,
2541 get_derived_offset (binfo
,
2542 DECL_CONTEXT (fndecl
)),
2543 BINFO_OFFSET (binfo
));
2544 this_offset
= ssize_binop (MINUS_EXPR
, offset
, base_offset
);
2546 if (! tree_int_cst_equal (this_offset
, delta
))
2548 /* Make sure we can modify the derived association with immunity. */
2549 if (binfo
== TYPE_BINFO (t
))
2551 /* In this case, it is *type*'s vtable we are modifying.
2552 We start with the approximation that it's vtable is that
2553 of the immediate base class. */
2554 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2555 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield
)), t
);
2559 /* This is our very own copy of `basetype' to play with.
2560 Later, we will fill in all the virtual functions
2561 that override the virtual functions in these base classes
2562 which are not defined by the current type. */
2563 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2564 prepare_fresh_vtable (binfo
, t
);
2567 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo
), n
),
2573 virtuals
= TREE_CHAIN (virtuals
);
2577 /* Fixup all the delta entries in all the direct vtables that need updating.
2578 This happens when we have non-overridden virtual functions from a
2579 virtual base class, that are at a different offset, in the new
2580 hierarchy, because the layout of the virtual bases has changed. */
2583 fixup_vtable_deltas (binfo
, init_self
, t
)
2588 tree binfos
= BINFO_BASETYPES (binfo
);
2589 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2591 for (i
= 0; i
< n_baselinks
; i
++)
2593 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2594 int is_not_base_vtable
2595 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2596 if (! TREE_VIA_VIRTUAL (base_binfo
))
2597 fixup_vtable_deltas (base_binfo
, is_not_base_vtable
, t
);
2599 /* Should we use something besides CLASSTYPE_VFIELDS? */
2600 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2601 fixup_vtable_deltas1 (binfo
, t
);
2604 /* These are the ones that are through virtual base classes. */
2607 modify_all_indirect_vtables (binfo
, do_self
, via_virtual
, t
, fndecl
)
2609 int do_self
, via_virtual
;
2612 tree binfos
= BINFO_BASETYPES (binfo
);
2613 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2615 /* Should we use something besides CLASSTYPE_VFIELDS? */
2616 if (do_self
&& via_virtual
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2617 modify_one_vtable (binfo
, t
, fndecl
);
2619 for (i
= 0; i
< n_baselinks
; i
++)
2621 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2622 int is_not_base_vtable
2623 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2624 if (TREE_VIA_VIRTUAL (base_binfo
))
2627 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
), CLASSTYPE_VBASECLASSES (t
));
2629 modify_all_indirect_vtables (base_binfo
, is_not_base_vtable
, via_virtual
, t
, fndecl
);
2634 modify_all_vtables (t
, fndecl
)
2638 /* Do these first, so that we will make use of any non-virtual class's
2639 vtable, over a virtual classes vtable. */
2640 modify_all_direct_vtables (TYPE_BINFO (t
), 1, t
, fndecl
);
2641 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
2642 modify_all_indirect_vtables (TYPE_BINFO (t
), 1, 0, t
, fndecl
);
2645 /* Here, we already know that they match in every respect.
2646 All we have to check is where they had their declarations. */
2649 strictly_overrides (fndecl1
, fndecl2
)
2650 tree fndecl1
, fndecl2
;
2652 int distance
= get_base_distance (DECL_CLASS_CONTEXT (fndecl2
),
2653 DECL_CLASS_CONTEXT (fndecl1
),
2655 if (distance
== -2 || distance
> 0)
2660 /* Merge overrides for one vtable.
2661 If we want to merge in same function, we are fine.
2663 if one has a DECL_CLASS_CONTEXT that is a parent of the
2664 other, than choose the more derived one
2666 potentially ill-formed (see 10.3 [class.virtual])
2667 we have to check later to see if there was an
2668 override in this class. If there was ok, if not
2669 then it is ill-formed. (mrs)
2671 We take special care to reuse a vtable, if we can. */
2674 override_one_vtable (binfo
, old
, t
)
2677 tree virtuals
= BINFO_VIRTUALS (binfo
);
2678 tree old_virtuals
= BINFO_VIRTUALS (old
);
2679 enum { REUSE_NEW
, REUSE_OLD
, UNDECIDED
, NEITHER
} choose
= UNDECIDED
;
2681 /* If we have already committed to modifying it, then don't try and
2682 reuse another vtable. */
2683 if (BINFO_NEW_VTABLE_MARKED (binfo
))
2686 skip_rtti_stuff (&virtuals
, BINFO_TYPE (binfo
));
2687 skip_rtti_stuff (&old_virtuals
, BINFO_TYPE (binfo
));
2691 tree fndecl
= TREE_VALUE (virtuals
);
2692 tree old_fndecl
= TREE_VALUE (old_virtuals
);
2694 /* First check to see if they are the same. */
2695 if (DECL_ASSEMBLER_NAME (fndecl
) == DECL_ASSEMBLER_NAME (old_fndecl
))
2697 /* No need to do anything. */
2699 else if (strictly_overrides (fndecl
, old_fndecl
))
2701 if (choose
== UNDECIDED
)
2703 else if (choose
== REUSE_OLD
)
2706 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2708 prepare_fresh_vtable (binfo
, t
);
2709 override_one_vtable (binfo
, old
, t
);
2714 else if (strictly_overrides (old_fndecl
, fndecl
))
2716 if (choose
== UNDECIDED
)
2718 else if (choose
== REUSE_NEW
)
2721 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2723 prepare_fresh_vtable (binfo
, t
);
2724 override_one_vtable (binfo
, old
, t
);
2727 TREE_VALUE (virtuals
) = TREE_VALUE (old_virtuals
);
2729 else if (choose
== NEITHER
)
2731 TREE_VALUE (virtuals
) = TREE_VALUE (old_virtuals
);
2737 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2739 prepare_fresh_vtable (binfo
, t
);
2740 override_one_vtable (binfo
, old
, t
);
2744 /* This MUST be overridden, or the class is ill-formed. */
2745 tree fndecl
= TREE_VALUE (virtuals
);
2747 fndecl
= copy_node (fndecl
);
2748 copy_lang_decl (fndecl
);
2749 DECL_NEEDS_FINAL_OVERRIDER_P (fndecl
) = 1;
2750 /* Make sure we search for it later. */
2751 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t
))
2752 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = error_mark_node
;
2754 /* We can use integer_zero_node, as we will core dump
2755 if this is used anyway. */
2756 TREE_PURPOSE (virtuals
) = integer_zero_node
;
2757 TREE_VALUE (virtuals
) = fndecl
;
2760 virtuals
= TREE_CHAIN (virtuals
);
2761 old_virtuals
= TREE_CHAIN (old_virtuals
);
2764 /* Let's reuse the old vtable. */
2765 if (choose
== REUSE_OLD
)
2767 BINFO_VTABLE (binfo
) = BINFO_VTABLE (old
);
2768 BINFO_VIRTUALS (binfo
) = BINFO_VIRTUALS (old
);
2772 /* Merge in overrides for virtual bases.
2773 BINFO is the hierarchy we want to modify, and OLD has the potential
2777 merge_overrides (binfo
, old
, do_self
, t
)
2782 tree binfos
= BINFO_BASETYPES (binfo
);
2783 tree old_binfos
= BINFO_BASETYPES (old
);
2784 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2786 /* Should we use something besides CLASSTYPE_VFIELDS? */
2787 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2789 override_one_vtable (binfo
, old
, t
);
2792 for (i
= 0; i
< n_baselinks
; i
++)
2794 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2795 tree old_base_binfo
= TREE_VEC_ELT (old_binfos
, i
);
2796 int is_not_base_vtable
2797 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2798 if (! TREE_VIA_VIRTUAL (base_binfo
))
2799 merge_overrides (base_binfo
, old_base_binfo
, is_not_base_vtable
, t
);
2803 /* Get the base virtual function declarations in T that are either
2804 overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
2805 the overrider/hider. */
2808 get_basefndecls (fndecl
, t
)
2811 tree methods
= TYPE_METHODS (t
);
2812 tree base_fndecls
= NULL_TREE
;
2813 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
2814 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2818 if (TREE_CODE (methods
) == FUNCTION_DECL
2819 && DECL_VINDEX (methods
) != NULL_TREE
2820 && DECL_NAME (fndecl
) == DECL_NAME (methods
))
2821 base_fndecls
= temp_tree_cons (fndecl
, methods
, base_fndecls
);
2823 methods
= TREE_CHAIN (methods
);
2827 return base_fndecls
;
2829 for (i
= 0; i
< n_baseclasses
; i
++)
2831 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2832 tree basetype
= BINFO_TYPE (base_binfo
);
2834 base_fndecls
= chainon (get_basefndecls (fndecl
, basetype
),
2838 return base_fndecls
;
2841 /* Mark the functions that have been hidden with their overriders.
2842 Since we start out with all functions already marked with a hider,
2843 no need to mark functions that are just hidden.
2845 Subroutine of warn_hidden. */
2848 mark_overriders (fndecl
, base_fndecls
)
2849 tree fndecl
, base_fndecls
;
2851 for (; base_fndecls
; base_fndecls
= TREE_CHAIN (base_fndecls
))
2853 if (overrides (fndecl
, TREE_VALUE (base_fndecls
)))
2854 TREE_PURPOSE (base_fndecls
) = fndecl
;
2858 /* If this declaration supersedes the declaration of
2859 a method declared virtual in the base class, then
2860 mark this field as being virtual as well. */
2863 check_for_override (decl
, ctype
)
2866 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (ctype
));
2867 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2868 int virtualp
= DECL_VIRTUAL_P (decl
);
2869 int found_overriden_fn
= 0;
2871 for (i
= 0; i
< n_baselinks
; i
++)
2873 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2874 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo
)))
2876 tree tmp
= get_matching_virtual
2878 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)));
2880 if (tmp
&& !found_overriden_fn
)
2882 /* If this function overrides some virtual in some base
2883 class, then the function itself is also necessarily
2884 virtual, even if the user didn't explicitly say so. */
2885 DECL_VIRTUAL_P (decl
) = 1;
2887 /* The TMP we really want is the one from the deepest
2888 baseclass on this path, taking care not to
2889 duplicate if we have already found it (via another
2890 path to its virtual baseclass. */
2891 if (TREE_CODE (TREE_TYPE (decl
)) == FUNCTION_TYPE
)
2893 cp_error_at ("`static %#D' cannot be declared", decl
);
2894 cp_error_at (" since `virtual %#D' declared in base class",
2901 = tree_cons (NULL_TREE
, tmp
, DECL_VINDEX (decl
));
2903 /* We now know that DECL overrides something,
2904 which is all that is important. But, we must
2905 continue to iterate through all the base-classes
2906 in order to allow get_matching_virtual to check for
2907 various illegal overrides. */
2908 found_overriden_fn
= 1;
2914 if (DECL_VINDEX (decl
) == NULL_TREE
)
2915 DECL_VINDEX (decl
) = error_mark_node
;
2916 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl
)) = 1;
2920 /* Warn about hidden virtual functions that are not overridden in t.
2921 We know that constructors and destructors don't apply. */
2927 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
2928 int n_methods
= method_vec
? TREE_VEC_LENGTH (method_vec
) : 0;
2931 /* We go through each separately named virtual function. */
2932 for (i
= 2; i
< n_methods
&& TREE_VEC_ELT (method_vec
, i
); ++i
)
2934 tree fns
= TREE_VEC_ELT (method_vec
, i
);
2937 tree base_fndecls
= NULL_TREE
;
2938 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
2939 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2941 /* First see if we have any virtual functions in this batch. */
2942 for (; fns
; fns
= OVL_NEXT (fns
))
2944 fndecl
= OVL_CURRENT (fns
);
2945 if (DECL_VINDEX (fndecl
))
2949 if (fns
== NULL_TREE
)
2952 /* First we get a list of all possible functions that might be
2953 hidden from each base class. */
2954 for (i
= 0; i
< n_baseclasses
; i
++)
2956 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2957 tree basetype
= BINFO_TYPE (base_binfo
);
2959 base_fndecls
= chainon (get_basefndecls (fndecl
, basetype
),
2963 fns
= OVL_NEXT (fns
);
2965 /* ...then mark up all the base functions with overriders, preferring
2966 overriders to hiders. */
2968 for (; fns
; fns
= OVL_NEXT (fns
))
2970 fndecl
= OVL_CURRENT (fns
);
2971 if (DECL_VINDEX (fndecl
))
2972 mark_overriders (fndecl
, base_fndecls
);
2975 /* Now give a warning for all base functions without overriders,
2976 as they are hidden. */
2977 for (; base_fndecls
; base_fndecls
= TREE_CHAIN (base_fndecls
))
2979 if (! overrides (TREE_PURPOSE (base_fndecls
),
2980 TREE_VALUE (base_fndecls
)))
2982 /* Here we know it is a hider, and no overrider exists. */
2983 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls
));
2984 cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls
));
2990 /* Check for things that are invalid. There are probably plenty of other
2991 things we should check for also. */
2994 finish_struct_anon (t
)
2999 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
3001 if (TREE_STATIC (field
))
3003 if (TREE_CODE (field
) != FIELD_DECL
)
3006 if (DECL_NAME (field
) == NULL_TREE
3007 && ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
3009 tree elt
= TYPE_FIELDS (TREE_TYPE (field
));
3010 for (; elt
; elt
= TREE_CHAIN (elt
))
3012 if (DECL_ARTIFICIAL (elt
))
3015 if (DECL_NAME (elt
) == constructor_name (t
))
3016 cp_pedwarn_at ("ANSI C++ forbids member `%D' with same name as enclosing class",
3019 if (TREE_CODE (elt
) != FIELD_DECL
)
3021 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
3026 if (TREE_PRIVATE (elt
))
3027 cp_pedwarn_at ("private member `%#D' in anonymous union",
3029 else if (TREE_PROTECTED (elt
))
3030 cp_pedwarn_at ("protected member `%#D' in anonymous union",
3033 TREE_PRIVATE (elt
) = TREE_PRIVATE (field
);
3034 TREE_PROTECTED (elt
) = TREE_PROTECTED (field
);
3040 extern int interface_only
, interface_unknown
;
3042 /* Create default constructors, assignment operators, and so forth for
3043 the type indicated by T, if they are needed.
3044 CANT_HAVE_DEFAULT_CTOR, CANT_HAVE_CONST_CTOR, and
3045 CANT_HAVE_ASSIGNMENT are nonzero if, for whatever reason, the class
3046 cannot have a default constructor, copy constructor taking a const
3047 reference argument, or an assignment operator, respectively. If a
3048 virtual destructor is created, its DECL is returned; otherwise the
3049 return value is NULL_TREE. */
3052 add_implicitly_declared_members (t
, cant_have_default_ctor
,
3053 cant_have_const_cctor
,
3054 cant_have_assignment
)
3056 int cant_have_default_ctor
;
3057 int cant_have_const_cctor
;
3058 int cant_have_assignment
;
3061 tree implicit_fns
= NULL_TREE
;
3062 tree name
= TYPE_IDENTIFIER (t
);
3063 tree virtual_dtor
= NULL_TREE
;
3067 if (TYPE_NEEDS_DESTRUCTOR (t
) && !TYPE_HAS_DESTRUCTOR (t
))
3069 default_fn
= cons_up_default_function (t
, name
, 0);
3070 check_for_override (default_fn
, t
);
3072 /* If we couldn't make it work, then pretend we didn't need it. */
3073 if (default_fn
== void_type_node
)
3074 TYPE_NEEDS_DESTRUCTOR (t
) = 0;
3077 TREE_CHAIN (default_fn
) = implicit_fns
;
3078 implicit_fns
= default_fn
;
3080 if (DECL_VINDEX (default_fn
))
3081 virtual_dtor
= default_fn
;
3084 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_HAS_DESTRUCTOR (t
);
3086 /* Default constructor. */
3087 if (! TYPE_HAS_CONSTRUCTOR (t
) && ! cant_have_default_ctor
)
3089 default_fn
= cons_up_default_function (t
, name
, 2);
3090 TREE_CHAIN (default_fn
) = implicit_fns
;
3091 implicit_fns
= default_fn
;
3094 /* Copy constructor. */
3095 if (! TYPE_HAS_INIT_REF (t
) && ! TYPE_FOR_JAVA (t
))
3097 /* ARM 12.18: You get either X(X&) or X(const X&), but
3099 default_fn
= cons_up_default_function (t
, name
,
3100 3 + cant_have_const_cctor
);
3101 TREE_CHAIN (default_fn
) = implicit_fns
;
3102 implicit_fns
= default_fn
;
3105 /* Assignment operator. */
3106 if (! TYPE_HAS_ASSIGN_REF (t
) && ! TYPE_FOR_JAVA (t
))
3108 default_fn
= cons_up_default_function (t
, name
,
3109 5 + cant_have_assignment
);
3110 TREE_CHAIN (default_fn
) = implicit_fns
;
3111 implicit_fns
= default_fn
;
3114 /* Now, hook all of the new functions on to TYPE_METHODS,
3115 and add them to the CLASSTYPE_METHOD_VEC. */
3116 for (f
= &implicit_fns
; *f
; f
= &TREE_CHAIN (*f
))
3117 add_method (t
, 0, *f
);
3118 *f
= TYPE_METHODS (t
);
3119 TYPE_METHODS (t
) = implicit_fns
;
3121 return virtual_dtor
;
3124 /* Subroutine of finish_struct_1. Recursively count the number of fields
3125 in TYPE, including anonymous union members. */
3128 count_fields (fields
)
3133 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
3135 if (TREE_CODE (x
) == FIELD_DECL
&& ANON_AGGR_TYPE_P (TREE_TYPE (x
)))
3136 n_fields
+= count_fields (TYPE_FIELDS (TREE_TYPE (x
)));
3143 /* Subroutine of finish_struct_1. Recursively add all the fields in the
3144 TREE_LIST FIELDS to the TREE_VEC FIELD_VEC, starting at offset IDX. */
3147 add_fields_to_vec (fields
, field_vec
, idx
)
3148 tree fields
, field_vec
;
3152 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
3154 if (TREE_CODE (x
) == FIELD_DECL
&& ANON_AGGR_TYPE_P (TREE_TYPE (x
)))
3155 idx
= add_fields_to_vec (TYPE_FIELDS (TREE_TYPE (x
)), field_vec
, idx
);
3157 TREE_VEC_ELT (field_vec
, idx
++) = x
;
3162 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
3163 (or C++ class declaration).
3165 For C++, we must handle the building of derived classes.
3166 Also, C++ allows static class members. The way that this is
3167 handled is to keep the field name where it is (as the DECL_NAME
3168 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
3169 of the field. layout_record and layout_union will know about this.
3171 More C++ hair: inline functions have text in their
3172 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
3173 meaningful tree structure. After the struct has been laid out, set
3174 things up so that this can happen.
3176 And still more: virtual functions. In the case of single inheritance,
3177 when a new virtual function is seen which redefines a virtual function
3178 from the base class, the new virtual function is placed into
3179 the virtual function table at exactly the same address that
3180 it had in the base class. When this is extended to multiple
3181 inheritance, the same thing happens, except that multiple virtual
3182 function tables must be maintained. The first virtual function
3183 table is treated in exactly the same way as in the case of single
3184 inheritance. Additional virtual function tables have different
3185 DELTAs, which tell how to adjust `this' to point to the right thing.
3187 ATTRIBUTES is the set of decl attributes to be applied, if any. */
3194 enum tree_code code
= TREE_CODE (t
);
3195 tree fields
= TYPE_FIELDS (t
);
3196 tree x
, last_x
, method_vec
;
3198 int max_has_virtual
;
3199 tree pending_virtuals
= NULL_TREE
;
3200 tree pending_hard_virtuals
= NULL_TREE
;
3201 tree abstract_virtuals
= NULL_TREE
;
3205 int cant_have_default_ctor
;
3206 int cant_have_const_ctor
;
3207 int no_const_asn_ref
;
3208 int has_mutable
= 0;
3210 int non_pod_class
= 0;
3212 /* The index of the first base class which has virtual
3213 functions. Only applied to non-virtual baseclasses. */
3214 int first_vfn_base_index
;
3217 int any_default_members
= 0;
3218 int const_sans_init
= 0;
3219 int ref_sans_init
= 0;
3220 tree access_decls
= NULL_TREE
;
3223 int has_pointers
= 0;
3224 tree inline_friends
;
3228 if (IS_AGGR_TYPE (t
))
3229 cp_error ("redefinition of `%#T'", t
);
3231 my_friendly_abort (172);
3236 GNU_xref_decl (current_function_decl
, t
);
3238 /* If this type was previously laid out as a forward reference,
3239 make sure we lay it out again. */
3241 TYPE_SIZE (t
) = NULL_TREE
;
3242 CLASSTYPE_GOT_SEMICOLON (t
) = 0;
3244 old
= suspend_momentary ();
3246 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
3247 Also process specified field sizes.
3248 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
3249 The specified size is found in the DECL_INITIAL.
3250 Store 0 there, except for ": 0" fields (so we can find them
3251 and delete them, below). */
3253 if (TYPE_BINFO_BASETYPES (t
))
3254 n_baseclasses
= TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t
));
3258 if (n_baseclasses
> 0)
3260 struct base_info base_info
;
3262 first_vfn_base_index
= finish_base_struct (t
, &base_info
);
3263 /* Remember where we got our vfield from. */
3264 CLASSTYPE_VFIELD_PARENT (t
) = first_vfn_base_index
;
3265 has_virtual
= base_info
.has_virtual
;
3266 max_has_virtual
= base_info
.max_has_virtual
;
3267 vfield
= base_info
.vfield
;
3268 vfields
= base_info
.vfields
;
3269 CLASSTYPE_RTTI (t
) = base_info
.rtti
;
3270 cant_have_default_ctor
= base_info
.cant_have_default_ctor
;
3271 cant_have_const_ctor
= base_info
.cant_have_const_ctor
;
3272 no_const_asn_ref
= base_info
.no_const_asn_ref
;
3277 first_vfn_base_index
= -1;
3279 max_has_virtual
= has_virtual
;
3281 vfields
= NULL_TREE
;
3282 CLASSTYPE_RTTI (t
) = NULL_TREE
;
3283 cant_have_default_ctor
= 0;
3284 cant_have_const_ctor
= 0;
3285 no_const_asn_ref
= 0;
3288 /* The three of these are approximations which may later be
3289 modified. Needed at this point to make add_virtual_function
3290 and modify_vtable_entries work. */
3291 CLASSTYPE_VFIELDS (t
) = vfields
;
3292 CLASSTYPE_VFIELD (t
) = vfield
;
3294 for (x
= TYPE_METHODS (t
); x
; x
= TREE_CHAIN (x
))
3296 GNU_xref_member (current_class_name
, x
);
3298 /* If this was an evil function, don't keep it in class. */
3299 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x
)))
3302 /* Do both of these, even though they're in the same union;
3303 if the insn `r' member and the size `i' member are
3304 different sizes, as on the alpha, the larger of the two
3305 will end up with garbage in it. */
3306 DECL_SAVED_INSNS (x
) = 0;
3307 DECL_FIELD_SIZE (x
) = 0;
3309 check_for_override (x
, t
);
3310 if (DECL_ABSTRACT_VIRTUAL_P (x
) && ! DECL_VINDEX (x
))
3311 cp_error_at ("initializer specified for non-virtual method `%D'", x
);
3313 /* The name of the field is the original field name
3314 Save this in auxiliary field for later overloading. */
3315 if (DECL_VINDEX (x
))
3317 add_virtual_function (&pending_virtuals
, &pending_hard_virtuals
,
3318 &has_virtual
, x
, t
);
3319 if (DECL_ABSTRACT_VIRTUAL_P (x
))
3320 abstract_virtuals
= tree_cons (NULL_TREE
, x
, abstract_virtuals
);
3322 /* XXX Why did I comment this out? (jason) */
3330 fields
= chainon (build_vbase_pointer_fields (t
), fields
);
3333 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
3335 tree type
= TREE_TYPE (x
);
3336 GNU_xref_member (current_class_name
, x
);
3338 if (TREE_CODE (x
) == FIELD_DECL
)
3340 DECL_PACKED (x
) |= TYPE_PACKED (t
);
3342 if (DECL_C_BIT_FIELD (x
) && integer_zerop (DECL_INITIAL (x
)))
3343 /* A zero-width bitfield doesn't do the trick. */;
3348 if (TREE_CODE (x
) == USING_DECL
)
3350 /* Save access declarations for later. */
3352 TREE_CHAIN (last_x
) = TREE_CHAIN (x
);
3354 fields
= TREE_CHAIN (x
);
3356 access_decls
= tree_cons (NULL_TREE
, x
, access_decls
);
3362 if (TREE_CODE (x
) == TYPE_DECL
3363 || TREE_CODE (x
) == TEMPLATE_DECL
)
3366 /* If we've gotten this far, it's a data member, possibly static,
3367 or an enumerator. */
3369 DECL_FIELD_CONTEXT (x
) = t
;
3371 /* ``A local class cannot have static data members.'' ARM 9.4 */
3372 if (current_function_decl
&& TREE_STATIC (x
))
3373 cp_error_at ("field `%D' in local class cannot be static", x
);
3375 /* Perform error checking that did not get done in
3377 if (TREE_CODE (type
) == FUNCTION_TYPE
)
3379 cp_error_at ("field `%D' invalidly declared function type",
3381 type
= build_pointer_type (type
);
3382 TREE_TYPE (x
) = type
;
3384 else if (TREE_CODE (type
) == METHOD_TYPE
)
3386 cp_error_at ("field `%D' invalidly declared method type", x
);
3387 type
= build_pointer_type (type
);
3388 TREE_TYPE (x
) = type
;
3390 else if (TREE_CODE (type
) == OFFSET_TYPE
)
3392 cp_error_at ("field `%D' invalidly declared offset type", x
);
3393 type
= build_pointer_type (type
);
3394 TREE_TYPE (x
) = type
;
3398 if (DECL_NAME (x
) == constructor_name (t
))
3399 cant_have_default_ctor
= 1;
3402 if (type
== error_mark_node
)
3405 DECL_SAVED_INSNS (x
) = 0;
3406 DECL_FIELD_SIZE (x
) = 0;
3408 /* When this goes into scope, it will be a non-local reference. */
3409 DECL_NONLOCAL (x
) = 1;
3411 if (TREE_CODE (x
) == CONST_DECL
)
3414 if (TREE_CODE (x
) == VAR_DECL
)
3416 if (TREE_CODE (t
) == UNION_TYPE
)
3417 /* Unions cannot have static members. */
3418 cp_error_at ("field `%D' declared static in union", x
);
3423 /* Now it can only be a FIELD_DECL. */
3425 if (TREE_PRIVATE (x
) || TREE_PROTECTED (x
))
3428 /* If this is of reference type, check if it needs an init.
3429 Also do a little ANSI jig if necessary. */
3430 if (TREE_CODE (type
) == REFERENCE_TYPE
)
3434 if (DECL_INITIAL (x
) == NULL_TREE
)
3437 /* ARM $12.6.2: [A member initializer list] (or, for an
3438 aggregate, initialization by a brace-enclosed list) is the
3439 only way to initialize nonstatic const and reference
3441 cant_have_default_ctor
= 1;
3442 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) = 1;
3444 if (! TYPE_HAS_CONSTRUCTOR (t
) && extra_warnings
)
3447 cp_warning_at ("non-static reference `%#D' in class without a constructor", x
);
3449 cp_warning_at ("non-static reference in class without a constructor", x
);
3453 while (TREE_CODE (type
) == ARRAY_TYPE
)
3454 type
= TREE_TYPE (type
);
3456 if (TREE_CODE (type
) == POINTER_TYPE
)
3459 if (DECL_MUTABLE_P (x
) || TYPE_HAS_MUTABLE_P (type
))
3462 if (! pod_type_p (type
) || TYPE_PTRMEM_P (type
)
3463 || TYPE_PTRMEMFUNC_P (type
))
3466 /* If any field is const, the structure type is pseudo-const. */
3467 if (CP_TYPE_CONST_P (type
))
3469 C_TYPE_FIELDS_READONLY (t
) = 1;
3470 if (DECL_INITIAL (x
) == NULL_TREE
)
3471 const_sans_init
= 1;
3473 /* ARM $12.6.2: [A member initializer list] (or, for an
3474 aggregate, initialization by a brace-enclosed list) is the
3475 only way to initialize nonstatic const and reference
3477 cant_have_default_ctor
= 1;
3478 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) = 1;
3480 if (! TYPE_HAS_CONSTRUCTOR (t
) && extra_warnings
)
3483 cp_warning_at ("non-static const member `%#D' in class without a constructor", x
);
3485 cp_warning_at ("non-static const member in class without a constructor", x
);
3490 /* A field that is pseudo-const makes the structure
3492 if (IS_AGGR_TYPE (type
))
3494 if (C_TYPE_FIELDS_READONLY (type
))
3495 C_TYPE_FIELDS_READONLY (t
) = 1;
3496 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (type
))
3497 const_sans_init
= 1;
3501 /* We set DECL_C_BIT_FIELD in grokbitfield.
3502 If the type and width are valid, we'll also set DECL_BIT_FIELD. */
3503 if (DECL_C_BIT_FIELD (x
))
3505 /* Invalid bit-field size done by grokfield. */
3506 /* Detect invalid bit-field type. Simply checking if TYPE is
3507 integral is insufficient, as that is the array core of the
3508 field type. If TREE_TYPE (x) is integral, then TYPE must be
3510 if (DECL_INITIAL (x
)
3511 && ! INTEGRAL_TYPE_P (TREE_TYPE (x
)))
3513 cp_error_at ("bit-field `%#D' with non-integral type", x
);
3514 DECL_INITIAL (x
) = NULL
;
3517 /* Detect and ignore out of range field width. */
3518 if (DECL_INITIAL (x
))
3520 tree w
= DECL_INITIAL (x
);
3521 register int width
= 0;
3523 /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */
3526 /* detect invalid field size. */
3527 if (TREE_CODE (w
) == CONST_DECL
)
3528 w
= DECL_INITIAL (w
);
3529 else if (TREE_READONLY_DECL_P (w
))
3530 w
= decl_constant_value (w
);
3532 if (TREE_CODE (w
) != INTEGER_CST
)
3534 cp_error_at ("bit-field `%D' width not an integer constant",
3536 DECL_INITIAL (x
) = NULL_TREE
;
3538 else if (width
= TREE_INT_CST_LOW (w
),
3541 DECL_INITIAL (x
) = NULL
;
3542 cp_error_at ("negative width in bit-field `%D'", x
);
3544 else if (width
== 0 && DECL_NAME (x
) != 0)
3546 DECL_INITIAL (x
) = NULL
;
3547 cp_error_at ("zero width for bit-field `%D'", x
);
3550 > TYPE_PRECISION (long_long_unsigned_type_node
))
3552 /* The backend will dump if you try to use something
3553 too big; avoid that. */
3554 DECL_INITIAL (x
) = NULL
;
3555 sorry ("bit-fields larger than %d bits",
3556 TYPE_PRECISION (long_long_unsigned_type_node
));
3557 cp_error_at (" in declaration of `%D'", x
);
3559 else if (width
> TYPE_PRECISION (type
)
3560 && TREE_CODE (type
) != ENUMERAL_TYPE
3561 && TREE_CODE (type
) != BOOLEAN_TYPE
)
3563 cp_warning_at ("width of `%D' exceeds its type", x
);
3565 else if (TREE_CODE (type
) == ENUMERAL_TYPE
3566 && ((min_precision (TYPE_MIN_VALUE (type
),
3567 TREE_UNSIGNED (type
)) > width
)
3568 || (min_precision (TYPE_MAX_VALUE (type
),
3569 TREE_UNSIGNED (type
)) > width
)))
3571 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3575 if (DECL_INITIAL (x
))
3577 DECL_INITIAL (x
) = NULL_TREE
;
3578 DECL_FIELD_SIZE (x
) = width
;
3579 DECL_BIT_FIELD (x
) = 1;
3583 #ifdef EMPTY_FIELD_BOUNDARY
3584 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
),
3585 EMPTY_FIELD_BOUNDARY
);
3587 #ifdef PCC_BITFIELD_TYPE_MATTERS
3588 if (PCC_BITFIELD_TYPE_MATTERS
)
3589 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
),
3596 /* Non-bit-fields are aligned for their type. */
3597 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
), TYPE_ALIGN (type
));
3601 if (CLASS_TYPE_P (type
) && ! ANON_AGGR_TYPE_P (type
))
3603 /* Never let anything with uninheritable virtuals
3604 make it through without complaint. */
3605 abstract_virtuals_error (x
, type
);
3607 if (code
== UNION_TYPE
)
3609 const char *fie
= NULL
;
3610 if (TYPE_NEEDS_CONSTRUCTING (type
))
3611 fie
= "constructor";
3612 else if (TYPE_NEEDS_DESTRUCTOR (type
))
3614 else if (TYPE_HAS_COMPLEX_ASSIGN_REF (type
))
3615 fie
= "copy assignment operator";
3617 cp_error_at ("member `%#D' with %s not allowed in union", x
,
3622 TYPE_NEEDS_CONSTRUCTING (t
) |= TYPE_NEEDS_CONSTRUCTING (type
);
3623 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_NEEDS_DESTRUCTOR (type
);
3624 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type
);
3625 TYPE_HAS_COMPLEX_INIT_REF (t
) |= TYPE_HAS_COMPLEX_INIT_REF (type
);
3628 if (!TYPE_HAS_CONST_INIT_REF (type
))
3629 cant_have_const_ctor
= 1;
3631 if (!TYPE_HAS_CONST_ASSIGN_REF (type
))
3632 no_const_asn_ref
= 1;
3634 if (TYPE_HAS_CONSTRUCTOR (type
)
3635 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type
))
3637 cant_have_default_ctor
= 1;
3639 /* This is wrong for aggregates. */
3640 if (! TYPE_HAS_CONSTRUCTOR (t
))
3643 cp_pedwarn_at ("member `%#D' with only non-default constructor", x
);
3645 cp_pedwarn_at ("member with only non-default constructor", x
);
3646 cp_pedwarn_at ("in class without a constructor",
3652 if (DECL_INITIAL (x
) != NULL_TREE
)
3654 /* `build_class_init_list' does not recognize
3656 if (code
== UNION_TYPE
&& any_default_members
!= 0)
3657 cp_error_at ("multiple fields in union `%T' initialized");
3658 any_default_members
= 1;
3663 /* If this type has any constant members which did not come
3664 with their own initialization, mark that fact here. It is
3665 not an error here, since such types can be saved either by their
3666 constructors, or by fortuitous initialization. */
3667 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t
) = const_sans_init
;
3668 CLASSTYPE_REF_FIELDS_NEED_INIT (t
) = ref_sans_init
;
3669 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = abstract_virtuals
;
3670 CLASSTYPE_HAS_MUTABLE (t
) = has_mutable
;
3672 /* Effective C++ rule 11. */
3673 if (has_pointers
&& warn_ecpp
&& TYPE_HAS_CONSTRUCTOR (t
)
3674 && ! (TYPE_HAS_INIT_REF (t
) && TYPE_HAS_ASSIGN_REF (t
)))
3676 cp_warning ("`%#T' has pointer data members", t
);
3678 if (! TYPE_HAS_INIT_REF (t
))
3680 cp_warning (" but does not override `%T(const %T&)'", t
, t
);
3681 if (! TYPE_HAS_ASSIGN_REF (t
))
3682 cp_warning (" or `operator=(const %T&)'", t
);
3684 else if (! TYPE_HAS_ASSIGN_REF (t
))
3685 cp_warning (" but does not override `operator=(const %T&)'", t
);
3688 /* Do some bookkeeping that will guide the generation of implicitly
3689 declared member functions. */
3690 TYPE_HAS_COMPLEX_INIT_REF (t
)
3691 |= (TYPE_HAS_INIT_REF (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3692 || has_virtual
|| any_default_members
);
3693 TYPE_NEEDS_CONSTRUCTING (t
)
3694 |= (TYPE_HAS_CONSTRUCTOR (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3695 || has_virtual
|| any_default_members
);
3696 CLASSTYPE_NON_AGGREGATE (t
)
3697 = ! aggregate
|| has_virtual
|| TYPE_HAS_CONSTRUCTOR (t
);
3698 CLASSTYPE_NON_POD_P (t
)
3699 = non_pod_class
|| CLASSTYPE_NON_AGGREGATE (t
)
3700 || TYPE_HAS_DESTRUCTOR (t
) || TYPE_HAS_ASSIGN_REF (t
);
3701 TYPE_HAS_REAL_ASSIGN_REF (t
) |= TYPE_HAS_ASSIGN_REF (t
);
3702 TYPE_HAS_COMPLEX_ASSIGN_REF (t
)
3703 |= TYPE_HAS_ASSIGN_REF (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
);
3705 /* Synthesize any needed methods. Note that methods will be synthesized
3706 for anonymous unions; grok_x_components undoes that. */
3708 = add_implicitly_declared_members (t
, cant_have_default_ctor
,
3709 cant_have_const_ctor
,
3712 add_virtual_function (&pending_virtuals
, &pending_hard_virtuals
,
3713 &has_virtual
, virtual_dtor
, t
);
3715 if (TYPE_METHODS (t
))
3717 finish_struct_methods (t
);
3718 method_vec
= CLASSTYPE_METHOD_VEC (t
);
3724 /* Just in case these got accidentally
3725 filled in by syntax errors. */
3726 TYPE_HAS_CONSTRUCTOR (t
) = 0;
3727 TYPE_HAS_DESTRUCTOR (t
) = 0;
3730 for (access_decls
= nreverse (access_decls
); access_decls
;
3731 access_decls
= TREE_CHAIN (access_decls
))
3732 handle_using_decl (TREE_VALUE (access_decls
), t
, method_vec
, fields
);
3734 if (vfield
== NULL_TREE
&& has_virtual
)
3736 /* We build this decl with vtbl_ptr_type_node, which is a
3737 `vtable_entry_type*'. It might seem more precise to use
3738 `vtable_entry_type (*)[N]' where N is the number of firtual
3739 functions. However, that would require the vtable pointer in
3740 base classes to have a different type than the vtable pointer
3741 in derived classes. We could make that happen, but that
3742 still wouldn't solve all the problems. In particular, the
3743 type-based alias analysis code would decide that assignments
3744 to the base class vtable pointer can't alias assignments to
3745 the derived class vtable pointer, since they have different
3746 types. Thus, in an derived class destructor, where the base
3747 class constructor was inlined, we could generate bad code for
3748 setting up the vtable pointer.
3750 Therefore, we use one type for all vtable pointers. We still
3751 use a type-correct type; it's just doesn't indicate the array
3752 bounds. That's better than using `void*' or some such; it's
3753 cleaner, and it let's the alias analysis code know that these
3754 stores cannot alias stores to void*! */
3755 vfield
= build_lang_decl (FIELD_DECL
, get_vfield_name (t
),
3756 vtbl_ptr_type_node
);
3757 /* If you change any of the below, take a look at all the
3758 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3760 DECL_ASSEMBLER_NAME (vfield
) = get_identifier (VFIELD_BASE
);
3761 CLASSTYPE_VFIELD (t
) = vfield
;
3762 DECL_VIRTUAL_P (vfield
) = 1;
3763 DECL_ARTIFICIAL (vfield
) = 1;
3764 DECL_FIELD_CONTEXT (vfield
) = t
;
3765 DECL_CLASS_CONTEXT (vfield
) = t
;
3766 DECL_FCONTEXT (vfield
) = t
;
3767 DECL_SAVED_INSNS (vfield
) = 0;
3768 DECL_FIELD_SIZE (vfield
) = 0;
3769 DECL_ALIGN (vfield
) = TYPE_ALIGN (ptr_type_node
);
3771 /* This is more efficient, but breaks binary compatibility, turn
3772 it on sometime when we don't care. If we turn it on, we also
3773 have to enable the code in dfs_init_vbase_pointers. */
3774 /* vfield is always first entry in structure. */
3775 TREE_CHAIN (vfield
) = fields
;
3780 my_friendly_assert (TREE_CHAIN (last_x
) == NULL_TREE
, 175);
3781 TREE_CHAIN (last_x
) = vfield
;
3788 vfields
= chainon (vfields
, build_tree_list (NULL_TREE
, t
));
3791 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3793 C++: maybe we will support default field initialization some day... */
3795 /* Delete all duplicate fields from the fields */
3796 delete_duplicate_fields (fields
);
3798 /* Now we have the nearly final fieldlist for the data fields. Record it,
3799 then lay out the structure or union (including the fields). */
3801 TYPE_FIELDS (t
) = fields
;
3805 last_x
= build_base_fields (t
);
3807 /* If all our bases are empty, we can be empty too. */
3808 for (x
= last_x
; empty
&& x
; x
= TREE_CHAIN (x
))
3809 if (DECL_SIZE (x
) != integer_zero_node
)
3813 /* CLASSTYPE_INLINE_FRIENDS is really TYPE_NONCOPIED_PARTS. Thus,
3814 we have to save this before we start modifying
3815 TYPE_NONCOPIED_PARTS. */
3816 inline_friends
= CLASSTYPE_INLINE_FRIENDS (t
);
3817 CLASSTYPE_INLINE_FRIENDS (t
) = NULL_TREE
;
3821 /* C++: do not let empty structures exist. */
3822 tree decl
= build_lang_decl
3823 (FIELD_DECL
, NULL_TREE
, char_type_node
);
3824 TREE_CHAIN (decl
) = fields
;
3825 TYPE_FIELDS (t
) = decl
;
3826 TYPE_NONCOPIED_PARTS (t
)
3827 = tree_cons (NULL_TREE
, decl
, TYPE_NONCOPIED_PARTS (t
));
3828 TREE_STATIC (TYPE_NONCOPIED_PARTS (t
)) = 1;
3832 TYPE_FIELDS (t
) = chainon (last_x
, TYPE_FIELDS (t
));
3836 /* Remember the size and alignment of the class before adding
3837 the virtual bases. */
3838 if (empty
&& flag_new_abi
)
3839 CLASSTYPE_SIZE (t
) = integer_zero_node
;
3840 else if (flag_new_abi
&& TYPE_HAS_COMPLEX_INIT_REF (t
)
3841 && TYPE_HAS_COMPLEX_ASSIGN_REF (t
))
3842 CLASSTYPE_SIZE (t
) = TYPE_BINFO_SIZE (t
);
3844 CLASSTYPE_SIZE (t
) = TYPE_SIZE (t
);
3845 CLASSTYPE_ALIGN (t
) = TYPE_ALIGN (t
);
3847 finish_struct_anon (t
);
3849 /* Set the TYPE_DECL for this type to contain the right
3850 value for DECL_OFFSET, so that we can use it as part
3851 of a COMPONENT_REF for multiple inheritance. */
3853 layout_decl (TYPE_MAIN_DECL (t
), 0);
3855 /* Now fix up any virtual base class types that we left lying
3856 around. We must get these done before we try to lay out the
3857 virtual function table. */
3858 pending_hard_virtuals
= nreverse (pending_hard_virtuals
);
3861 /* layout_basetypes will remove the base subobject fields. */
3862 max_has_virtual
= layout_basetypes (t
, max_has_virtual
);
3864 TYPE_FIELDS (t
) = fields
;
3866 my_friendly_assert (TYPE_FIELDS (t
) == fields
, 981117);
3868 /* Delete all zero-width bit-fields from the front of the fieldlist */
3869 while (fields
&& DECL_C_BIT_FIELD (fields
)
3870 && DECL_INITIAL (fields
))
3871 fields
= TREE_CHAIN (fields
);
3872 /* Delete all such fields from the rest of the fields. */
3873 for (x
= fields
; x
;)
3875 if (TREE_CHAIN (x
) && DECL_C_BIT_FIELD (TREE_CHAIN (x
))
3876 && DECL_INITIAL (TREE_CHAIN (x
)))
3877 TREE_CHAIN (x
) = TREE_CHAIN (TREE_CHAIN (x
));
3881 TYPE_FIELDS (t
) = fields
;
3883 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
3887 vbases
= CLASSTYPE_VBASECLASSES (t
);
3890 /* Now fixup overrides of all functions in vtables from all
3891 direct or indirect virtual base classes. */
3892 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
3893 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3895 for (i
= 0; i
< n_baseclasses
; i
++)
3897 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3898 tree basetype
= BINFO_TYPE (base_binfo
);
3901 vbases
= CLASSTYPE_VBASECLASSES (basetype
);
3904 merge_overrides (binfo_member (BINFO_TYPE (vbases
),
3905 CLASSTYPE_VBASECLASSES (t
)),
3907 vbases
= TREE_CHAIN (vbases
);
3913 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
3914 might need to know it for setting up the offsets in the vtable
3915 (or in thunks) below. */
3916 if (vfield
!= NULL_TREE
3917 && DECL_FIELD_CONTEXT (vfield
) != t
)
3919 tree binfo
= get_binfo (DECL_FIELD_CONTEXT (vfield
), t
, 0);
3920 tree offset
= BINFO_OFFSET (binfo
);
3922 vfield
= copy_node (vfield
);
3923 copy_lang_decl (vfield
);
3925 if (! integer_zerop (offset
))
3926 offset
= size_binop (MULT_EXPR
, offset
, size_int (BITS_PER_UNIT
));
3927 DECL_FIELD_CONTEXT (vfield
) = t
;
3928 DECL_CLASS_CONTEXT (vfield
) = t
;
3929 DECL_FIELD_BITPOS (vfield
)
3930 = size_binop (PLUS_EXPR
, offset
, DECL_FIELD_BITPOS (vfield
));
3931 CLASSTYPE_VFIELD (t
) = vfield
;
3935 cp_warning ("Doing hard virtuals for %T...", t
);
3938 if (has_virtual
> max_has_virtual
)
3939 max_has_virtual
= has_virtual
;
3940 if (max_has_virtual
> 0)
3941 TYPE_VIRTUAL_P (t
) = 1;
3943 if (flag_rtti
&& TYPE_VIRTUAL_P (t
) && !pending_hard_virtuals
)
3944 modify_all_vtables (t
, NULL_TREE
);
3946 while (pending_hard_virtuals
)
3948 modify_all_vtables (t
,
3949 TREE_VALUE (pending_hard_virtuals
));
3950 pending_hard_virtuals
= TREE_CHAIN (pending_hard_virtuals
);
3953 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
3956 /* Now fixup any virtual function entries from virtual bases
3957 that have different deltas. This has to come after we do the
3958 pending hard virtuals, as we might have a function that comes
3959 from multiple virtual base instances that is only overridden
3960 by a hard virtual above. */
3961 vbases
= CLASSTYPE_VBASECLASSES (t
);
3964 /* We might be able to shorten the amount of work we do by
3965 only doing this for vtables that come from virtual bases
3966 that have differing offsets, but don't want to miss any
3968 fixup_vtable_deltas (vbases
, 1, t
);
3969 vbases
= TREE_CHAIN (vbases
);
3973 /* Under our model of GC, every C++ class gets its own virtual
3974 function table, at least virtually. */
3975 if (pending_virtuals
)
3977 pending_virtuals
= nreverse (pending_virtuals
);
3978 /* We must enter these virtuals into the table. */
3979 if (first_vfn_base_index
< 0)
3981 if (! CLASSTYPE_COM_INTERFACE (t
))
3983 /* The second slot is for the tdesc pointer when thunks are used. */
3984 if (flag_vtable_thunks
)
3985 pending_virtuals
= tree_cons (NULL_TREE
, NULL_TREE
, pending_virtuals
);
3987 /* The first slot is for the rtti offset. */
3988 pending_virtuals
= tree_cons (NULL_TREE
, NULL_TREE
, pending_virtuals
);
3990 set_rtti_entry (pending_virtuals
,
3991 convert (ssizetype
, integer_zero_node
), t
);
3993 build_vtable (NULL_TREE
, t
);
3997 /* Here we know enough to change the type of our virtual
3998 function table, but we will wait until later this function. */
4000 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t
)))
4001 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), first_vfn_base_index
), t
);
4004 /* If this type has basetypes with constructors, then those
4005 constructors might clobber the virtual function table. But
4006 they don't if the derived class shares the exact vtable of the base
4009 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t
) = 1;
4011 else if (first_vfn_base_index
>= 0)
4013 tree binfo
= TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), first_vfn_base_index
);
4014 /* This class contributes nothing new to the virtual function
4015 table. However, it may have declared functions which
4016 went into the virtual function table "inherited" from the
4017 base class. If so, we grab a copy of those updated functions,
4018 and pretend they are ours. */
4020 /* See if we should steal the virtual info from base class. */
4021 if (TYPE_BINFO_VTABLE (t
) == NULL_TREE
)
4022 TYPE_BINFO_VTABLE (t
) = BINFO_VTABLE (binfo
);
4023 if (TYPE_BINFO_VIRTUALS (t
) == NULL_TREE
)
4024 TYPE_BINFO_VIRTUALS (t
) = BINFO_VIRTUALS (binfo
);
4025 if (TYPE_BINFO_VTABLE (t
) != BINFO_VTABLE (binfo
))
4026 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t
) = 1;
4029 if (max_has_virtual
|| first_vfn_base_index
>= 0)
4031 CLASSTYPE_VSIZE (t
) = has_virtual
;
4032 if (first_vfn_base_index
>= 0)
4034 if (pending_virtuals
)
4035 TYPE_BINFO_VIRTUALS (t
) = chainon (TYPE_BINFO_VIRTUALS (t
),
4038 else if (has_virtual
)
4040 TYPE_BINFO_VIRTUALS (t
) = pending_virtuals
;
4041 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t
)) = 1;
4045 /* Now lay out the virtual function table. */
4048 /* Use size_int so values are memoized in common cases. */
4049 tree itype
= build_index_type (size_int (has_virtual
));
4050 tree atype
= build_cplus_array_type (vtable_entry_type
, itype
);
4052 layout_type (atype
);
4054 CLASSTYPE_VFIELD (t
) = vfield
;
4056 /* We may have to grow the vtable. */
4057 if (TREE_TYPE (TYPE_BINFO_VTABLE (t
)) != atype
)
4059 TREE_TYPE (TYPE_BINFO_VTABLE (t
)) = atype
;
4060 DECL_SIZE (TYPE_BINFO_VTABLE (t
)) = 0;
4061 layout_decl (TYPE_BINFO_VTABLE (t
), 0);
4062 /* At one time the vtable info was grabbed 2 words at a time. This
4063 fails on sparc unless you have 8-byte alignment. (tiemann) */
4064 DECL_ALIGN (TYPE_BINFO_VTABLE (t
))
4065 = MAX (TYPE_ALIGN (double_type_node
),
4066 DECL_ALIGN (TYPE_BINFO_VTABLE (t
)));
4069 else if (first_vfn_base_index
>= 0)
4070 CLASSTYPE_VFIELD (t
) = vfield
;
4071 CLASSTYPE_VFIELDS (t
) = vfields
;
4073 finish_struct_bits (t
, max_has_virtual
);
4075 /* Complete the rtl for any static member objects of the type we're
4077 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
4079 if (TREE_CODE (x
) == VAR_DECL
&& TREE_STATIC (x
)
4080 && TREE_TYPE (x
) == t
)
4082 DECL_MODE (x
) = TYPE_MODE (t
);
4083 make_decl_rtl (x
, NULL
, 0);
4087 /* Done with FIELDS...now decide whether to sort these for
4088 faster lookups later. Don't worry about optimizing
4089 for structs only declared in inline functions...they're
4090 not going to be referenced anywhere else.
4092 The C front-end only does this when n_fields > 15. We use
4093 a smaller number because most searches fail (succeeding
4094 ultimately as the search bores through the inheritance
4095 hierarchy), and we want this failure to occur quickly. */
4097 n_fields
= count_fields (fields
);
4098 if (n_fields
> 7 && !allocation_temporary_p ())
4100 tree field_vec
= make_tree_vec (n_fields
);
4101 add_fields_to_vec (fields
, field_vec
, 0);
4102 qsort (&TREE_VEC_ELT (field_vec
, 0), n_fields
, sizeof (tree
),
4103 (int (*)(const void *, const void *))field_decl_cmp
);
4104 if (! DECL_LANG_SPECIFIC (TYPE_MAIN_DECL (t
)))
4105 retrofit_lang_decl (TYPE_MAIN_DECL (t
));
4106 DECL_SORTED_FIELDS (TYPE_MAIN_DECL (t
)) = field_vec
;
4109 if (TYPE_HAS_CONSTRUCTOR (t
))
4111 tree vfields
= CLASSTYPE_VFIELDS (t
);
4115 /* Mark the fact that constructor for T
4116 could affect anybody inheriting from T
4117 who wants to initialize vtables for VFIELDS's type. */
4118 if (VF_DERIVED_VALUE (vfields
))
4119 TREE_ADDRESSABLE (vfields
) = 1;
4120 vfields
= TREE_CHAIN (vfields
);
4124 /* Write out inline function definitions. */
4125 do_inline_function_hair (t
, inline_friends
);
4127 if (CLASSTYPE_VSIZE (t
) != 0)
4129 /* In addition to this one, all the other vfields should be listed. */
4130 /* Before that can be done, we have to have FIELD_DECLs for them, and
4131 a place to find them. */
4132 TYPE_NONCOPIED_PARTS (t
)
4133 = tree_cons (default_conversion (TYPE_BINFO_VTABLE (t
)),
4134 vfield
, TYPE_NONCOPIED_PARTS (t
));
4136 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (t
)
4137 && DECL_VINDEX (TREE_VEC_ELT (method_vec
, 1)) == NULL_TREE
)
4138 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4142 /* Make the rtl for any new vtables we have created, and unmark
4143 the base types we marked. */
4144 finish_vtbls (TYPE_BINFO (t
), 1, t
);
4145 hack_incomplete_structures (t
);
4148 if (TYPE_NAME (t
) && TYPE_IDENTIFIER (t
))
4149 undo_template_name_overload (TYPE_IDENTIFIER (t
), 1);
4152 resume_momentary (old
);
4154 if (warn_overloaded_virtual
)
4158 /* This has to be done after we have sorted out what to do with
4159 the enclosing type. */
4160 if (write_symbols
!= DWARF_DEBUG
)
4162 /* Be smarter about nested classes here. If a type is nested,
4163 only output it if we would output the enclosing type. */
4164 if (DECL_CLASS_SCOPE_P (TYPE_MAIN_DECL (t
)))
4165 DECL_IGNORED_P (TYPE_MAIN_DECL (t
)) = TREE_ASM_WRITTEN (TYPE_MAIN_DECL (t
));
4169 if (write_symbols
!= DWARF_DEBUG
&& write_symbols
!= DWARF2_DEBUG
)
4171 /* If the type has methods, we want to think about cutting down
4172 the amount of symbol table stuff we output. The value stored in
4173 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4174 For example, if a member function is seen and we decide to
4175 write out that member function, then we can change the value
4176 of the DECL_IGNORED_P slot, and the type will be output when
4177 that member function's debug info is written out.
4179 We can't do this with DWARF, which does not support name
4180 references between translation units. */
4181 if (CLASSTYPE_METHOD_VEC (t
))
4183 /* Don't output full info about any type
4184 which does not have its implementation defined here. */
4185 if (CLASSTYPE_INTERFACE_ONLY (t
))
4186 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4188 /* XXX do something about this. */
4189 else if (CLASSTYPE_INTERFACE_UNKNOWN (t
))
4190 /* Only a first approximation! */
4191 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4194 else if (CLASSTYPE_INTERFACE_ONLY (t
))
4195 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4198 /* Finish debugging output for this type. */
4199 rest_of_type_compilation (t
, toplevel_bindings_p ());
4204 /* When T was built up, the member declarations were added in reverse
4205 order. Rearrange them to declaration order. */
4208 unreverse_member_declarations (t
)
4215 /* The TYPE_FIELDS, TYPE_METHODS, and CLASSTYPE_TAGS are all in
4216 reverse order. Put them in declaration order now. */
4217 TYPE_METHODS (t
) = nreverse (TYPE_METHODS (t
));
4218 CLASSTYPE_TAGS (t
) = nreverse (CLASSTYPE_TAGS (t
));
4220 /* Actually, for the TYPE_FIELDS, only the non TYPE_DECLs are in
4221 reverse order, so we can't just use nreverse. */
4223 for (x
= TYPE_FIELDS (t
);
4224 x
&& TREE_CODE (x
) != TYPE_DECL
;
4227 next
= TREE_CHAIN (x
);
4228 TREE_CHAIN (x
) = prev
;
4233 TREE_CHAIN (TYPE_FIELDS (t
)) = x
;
4235 TYPE_FIELDS (t
) = prev
;
4240 finish_struct (t
, attributes
)
4243 /* Now that we've got all the field declarations, reverse everything
4245 unreverse_member_declarations (t
);
4247 cplus_decl_attributes (t
, attributes
, NULL_TREE
);
4249 if (processing_template_decl
)
4251 finish_struct_methods (t
);
4252 TYPE_SIZE (t
) = integer_zero_node
;
4255 finish_struct_1 (t
);
4257 TYPE_BEING_DEFINED (t
) = 0;
4259 if (current_class_type
)
4262 error ("trying to finish struct, but kicked out due to previous parse errors.");
4267 /* Return the dynamic type of INSTANCE, if known.
4268 Used to determine whether the virtual function table is needed
4271 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4272 of our knowledge of its type. */
4275 fixed_type_or_null (instance
, nonnull
)
4279 switch (TREE_CODE (instance
))
4282 /* Check that we are not going through a cast of some sort. */
4283 if (TREE_TYPE (instance
)
4284 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance
, 0))))
4285 instance
= TREE_OPERAND (instance
, 0);
4286 /* fall through... */
4288 /* This is a call to a constructor, hence it's never zero. */
4289 if (TREE_HAS_CONSTRUCTOR (instance
))
4293 return TREE_TYPE (instance
);
4298 /* This is a call to a constructor, hence it's never zero. */
4299 if (TREE_HAS_CONSTRUCTOR (instance
))
4303 return TREE_TYPE (instance
);
4305 return fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4312 if (TREE_CODE (TREE_OPERAND (instance
, 1)) == INTEGER_CST
)
4313 /* Propagate nonnull. */
4314 fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4315 if (TREE_CODE (TREE_OPERAND (instance
, 0)) == ADDR_EXPR
)
4316 return fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4321 return fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4326 return fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4329 return fixed_type_or_null (TREE_OPERAND (instance
, 1), nonnull
);
4333 if (TREE_CODE (TREE_TYPE (instance
)) == ARRAY_TYPE
4334 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance
))))
4338 return TREE_TYPE (TREE_TYPE (instance
));
4340 /* fall through... */
4343 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
4347 return TREE_TYPE (instance
);
4351 if (instance
== current_class_ptr
4352 && flag_this_is_variable
<= 0)
4354 /* Normally, 'this' must be non-null. */
4355 if (flag_this_is_variable
== 0)
4358 /* <0 means we're in a constructor and we know our type. */
4359 if (flag_this_is_variable
< 0)
4360 return TREE_TYPE (TREE_TYPE (instance
));
4362 else if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
4363 /* Reference variables should be references to objects. */
4373 /* Return non-zero if the dynamic type of INSTANCE is known, and equivalent
4374 to the static type. We also handle the case where INSTANCE is really
4377 Used to determine whether the virtual function table is needed
4380 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4381 of our knowledge of its type. */
4384 resolves_to_fixed_type_p (instance
, nonnull
)
4388 tree t
= TREE_TYPE (instance
);
4389 tree fixed
= fixed_type_or_null (instance
, nonnull
);
4390 if (fixed
== NULL_TREE
)
4392 if (POINTER_TYPE_P (t
))
4394 return same_type_p (TYPE_MAIN_VARIANT (t
), TYPE_MAIN_VARIANT (fixed
));
4399 init_class_processing ()
4401 current_class_depth
= 0;
4402 current_class_stack_size
= 10;
4404 = (class_stack_node_t
) xmalloc (current_class_stack_size
4405 * sizeof (struct class_stack_node
));
4407 access_default_node
= build_int_2 (0, 0);
4408 access_public_node
= build_int_2 (1, 0);
4409 access_protected_node
= build_int_2 (2, 0);
4410 access_private_node
= build_int_2 (3, 0);
4411 access_default_virtual_node
= build_int_2 (4, 0);
4412 access_public_virtual_node
= build_int_2 (5, 0);
4413 access_protected_virtual_node
= build_int_2 (6, 0);
4414 access_private_virtual_node
= build_int_2 (7, 0);
4416 gcc_obstack_init (&class_obstack
);
4419 /* Set current scope to NAME. CODE tells us if this is a
4420 STRUCT, UNION, or ENUM environment.
4422 NAME may end up being NULL_TREE if this is an anonymous or
4423 late-bound struct (as in "struct { ... } foo;") */
4425 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
4426 appropriate values, found by looking up the type definition of
4429 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
4430 which can be seen locally to the class. They are shadowed by
4431 any subsequent local declaration (including parameter names).
4433 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
4434 which have static meaning (i.e., static members, static
4435 member functions, enum declarations, etc).
4437 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
4438 which can be seen locally to the class (as in 1), but
4439 know that we are doing this for declaration purposes
4440 (i.e. friend foo::bar (int)).
4442 So that we may avoid calls to lookup_name, we cache the _TYPE
4443 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
4445 For multiple inheritance, we perform a two-pass depth-first search
4446 of the type lattice. The first pass performs a pre-order search,
4447 marking types after the type has had its fields installed in
4448 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
4449 unmarks the marked types. If a field or member function name
4450 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4451 that name becomes `error_mark_node'. */
4454 pushclass (type
, modify
)
4458 type
= TYPE_MAIN_VARIANT (type
);
4460 /* Make sure there is enough room for the new entry on the stack. */
4461 if (current_class_depth
+ 1 >= current_class_stack_size
)
4463 current_class_stack_size
*= 2;
4465 = (class_stack_node_t
) xrealloc (current_class_stack
,
4466 current_class_stack_size
4467 * sizeof (struct class_stack_node
));
4470 /* Insert a new entry on the class stack. */
4471 current_class_stack
[current_class_depth
].name
= current_class_name
;
4472 current_class_stack
[current_class_depth
].type
= current_class_type
;
4473 current_class_stack
[current_class_depth
].access
= current_access_specifier
;
4474 current_class_stack
[current_class_depth
].names_used
= 0;
4475 current_class_depth
++;
4477 /* Now set up the new type. */
4478 current_class_name
= TYPE_NAME (type
);
4479 if (TREE_CODE (current_class_name
) == TYPE_DECL
)
4480 current_class_name
= DECL_NAME (current_class_name
);
4481 current_class_type
= type
;
4483 /* By default, things in classes are private, while things in
4484 structures or unions are public. */
4485 current_access_specifier
= (CLASSTYPE_DECLARED_CLASS (type
)
4486 ? access_private_node
4487 : access_public_node
);
4489 if (previous_class_type
!= NULL_TREE
4490 && (type
!= previous_class_type
4491 || TYPE_SIZE (previous_class_type
) == NULL_TREE
)
4492 && current_class_depth
== 1)
4494 /* Forcibly remove any old class remnants. */
4495 invalidate_class_lookup_cache ();
4497 /* Now, free the obstack on which we cached all the values. */
4498 if (class_cache_firstobj
)
4499 obstack_free (&class_cache_obstack
, class_cache_firstobj
);
4500 class_cache_firstobj
4501 = (char*) obstack_finish (&class_cache_obstack
);
4504 /* If we're about to enter a nested class, clear
4505 IDENTIFIER_CLASS_VALUE for the enclosing classes. */
4506 if (modify
&& current_class_depth
> 1)
4507 clear_identifier_class_values ();
4512 if (CLASSTYPE_TEMPLATE_INFO (type
))
4513 overload_template_name (type
);
4518 if (type
!= previous_class_type
|| current_class_depth
> 1)
4519 push_class_decls (type
);
4524 /* We are re-entering the same class we just left, so we
4525 don't have to search the whole inheritance matrix to find
4526 all the decls to bind again. Instead, we install the
4527 cached class_shadowed list, and walk through it binding
4528 names and setting up IDENTIFIER_TYPE_VALUEs. */
4529 set_class_shadows (previous_class_values
);
4530 for (item
= previous_class_values
; item
; item
= TREE_CHAIN (item
))
4532 tree id
= TREE_PURPOSE (item
);
4533 tree decl
= TREE_TYPE (item
);
4535 push_class_binding (id
, decl
);
4536 if (TREE_CODE (decl
) == TYPE_DECL
)
4537 set_identifier_type_value (id
, TREE_TYPE (decl
));
4539 unuse_fields (type
);
4542 storetags (CLASSTYPE_TAGS (type
));
4546 /* When we exit a toplevel class scope, we save the
4547 IDENTIFIER_CLASS_VALUEs so that we can restore them quickly if we
4548 reenter the class. Here, we've entered some other class, so we
4549 must invalidate our cache. */
4552 invalidate_class_lookup_cache ()
4556 /* This code can be seen as a cache miss. When we've cached a
4557 class' scope's bindings and we can't use them, we need to reset
4558 them. This is it! */
4559 for (t
= previous_class_values
; t
; t
= TREE_CHAIN (t
))
4560 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t
)) = NULL_TREE
;
4562 previous_class_type
= NULL_TREE
;
4565 /* Get out of the current class scope. If we were in a class scope
4566 previously, that is the one popped to. */
4572 /* Since poplevel_class does the popping of class decls nowadays,
4573 this really only frees the obstack used for these decls. */
4576 current_class_depth
--;
4577 current_class_name
= current_class_stack
[current_class_depth
].name
;
4578 current_class_type
= current_class_stack
[current_class_depth
].type
;
4579 current_access_specifier
= current_class_stack
[current_class_depth
].access
;
4580 if (current_class_stack
[current_class_depth
].names_used
)
4581 splay_tree_delete (current_class_stack
[current_class_depth
].names_used
);
4584 /* Returns 1 if current_class_type is either T or a nested type of T. */
4587 currently_open_class (t
)
4591 if (t
== current_class_type
)
4593 for (i
= 0; i
< current_class_depth
; ++i
)
4594 if (current_class_stack
[i
].type
== t
)
4599 /* When entering a class scope, all enclosing class scopes' names with
4600 static meaning (static variables, static functions, types and enumerators)
4601 have to be visible. This recursive function calls pushclass for all
4602 enclosing class contexts until global or a local scope is reached.
4603 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4604 formal of the same name. */
4607 push_nested_class (type
, modify
)
4613 /* A namespace might be passed in error cases, like A::B:C. */
4614 if (type
== NULL_TREE
|| type
== error_mark_node
|| ! IS_AGGR_TYPE (type
)
4615 || TREE_CODE (type
) == NAMESPACE_DECL
4616 || TREE_CODE (type
) == TEMPLATE_TYPE_PARM
4617 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
4620 context
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
4622 if (context
&& CLASS_TYPE_P (context
))
4623 push_nested_class (context
, 2);
4624 pushclass (type
, modify
);
4627 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4632 tree context
= DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type
));
4635 if (context
&& CLASS_TYPE_P (context
))
4636 pop_nested_class ();
4639 /* Set global variables CURRENT_LANG_NAME to appropriate value
4640 so that behavior of name-mangling machinery is correct. */
4643 push_lang_context (name
)
4646 *current_lang_stack
++ = current_lang_name
;
4647 if (current_lang_stack
- &VARRAY_TREE (current_lang_base
, 0)
4648 >= (ptrdiff_t) VARRAY_SIZE (current_lang_base
))
4650 size_t old_size
= VARRAY_SIZE (current_lang_base
);
4652 VARRAY_GROW (current_lang_base
, old_size
+ 10);
4653 current_lang_stack
= &VARRAY_TREE (current_lang_base
, old_size
);
4656 if (name
== lang_name_cplusplus
)
4658 strict_prototype
= strict_prototypes_lang_cplusplus
;
4659 current_lang_name
= name
;
4661 else if (name
== lang_name_java
)
4663 strict_prototype
= strict_prototypes_lang_cplusplus
;
4664 current_lang_name
= name
;
4665 /* DECL_IGNORED_P is initially set for these types, to avoid clutter.
4666 (See record_builtin_java_type in decl.c.) However, that causes
4667 incorrect debug entries if these types are actually used.
4668 So we re-enable debug output after extern "Java". */
4669 DECL_IGNORED_P (java_byte_type_node
) = 0;
4670 DECL_IGNORED_P (java_short_type_node
) = 0;
4671 DECL_IGNORED_P (java_int_type_node
) = 0;
4672 DECL_IGNORED_P (java_long_type_node
) = 0;
4673 DECL_IGNORED_P (java_float_type_node
) = 0;
4674 DECL_IGNORED_P (java_double_type_node
) = 0;
4675 DECL_IGNORED_P (java_char_type_node
) = 0;
4676 DECL_IGNORED_P (java_boolean_type_node
) = 0;
4678 else if (name
== lang_name_c
)
4680 strict_prototype
= strict_prototypes_lang_c
;
4681 current_lang_name
= name
;
4684 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name
));
4687 /* Get out of the current language scope. */
4692 /* Clear the current entry so that garbage collector won't hold on
4694 *current_lang_stack
= NULL_TREE
;
4695 current_lang_name
= *--current_lang_stack
;
4696 if (current_lang_name
== lang_name_cplusplus
4697 || current_lang_name
== lang_name_java
)
4698 strict_prototype
= strict_prototypes_lang_cplusplus
;
4699 else if (current_lang_name
== lang_name_c
)
4700 strict_prototype
= strict_prototypes_lang_c
;
4703 /* Type instantiation routines. */
4705 /* Given an OVERLOAD and a TARGET_TYPE, return the function that
4706 matches the TARGET_TYPE. If there is no satisfactory match, return
4707 error_mark_node, and issue an error message if COMPLAIN is
4708 non-zero. If TEMPLATE_ONLY, the name of the overloaded function
4709 was a template-id, and EXPLICIT_TARGS are the explicitly provided
4710 template arguments. */
4713 resolve_address_of_overloaded_function (target_type
,
4722 tree explicit_targs
;
4724 /* Here's what the standard says:
4728 If the name is a function template, template argument deduction
4729 is done, and if the argument deduction succeeds, the deduced
4730 arguments are used to generate a single template function, which
4731 is added to the set of overloaded functions considered.
4733 Non-member functions and static member functions match targets of
4734 type "pointer-to-function" or "reference-to-function." Nonstatic
4735 member functions match targets of type "pointer-to-member
4736 function;" the function type of the pointer to member is used to
4737 select the member function from the set of overloaded member
4738 functions. If a nonstatic member function is selected, the
4739 reference to the overloaded function name is required to have the
4740 form of a pointer to member as described in 5.3.1.
4742 If more than one function is selected, any template functions in
4743 the set are eliminated if the set also contains a non-template
4744 function, and any given template function is eliminated if the
4745 set contains a second template function that is more specialized
4746 than the first according to the partial ordering rules 14.5.5.2.
4747 After such eliminations, if any, there shall remain exactly one
4748 selected function. */
4751 int is_reference
= 0;
4752 /* We store the matches in a TREE_LIST rooted here. The functions
4753 are the TREE_PURPOSE, not the TREE_VALUE, in this list, for easy
4754 interoperability with most_specialized_instantiation. */
4755 tree matches
= NULL_TREE
;
4758 /* By the time we get here, we should be seeing only real
4759 pointer-to-member types, not the internal POINTER_TYPE to
4760 METHOD_TYPE representation. */
4761 my_friendly_assert (!(TREE_CODE (target_type
) == POINTER_TYPE
4762 && (TREE_CODE (TREE_TYPE (target_type
))
4763 == METHOD_TYPE
)), 0);
4765 /* Check that the TARGET_TYPE is reasonable. */
4766 if (TYPE_PTRFN_P (target_type
))
4769 else if (TYPE_PTRMEMFUNC_P (target_type
))
4770 /* This is OK, too. */
4772 else if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
4774 /* This is OK, too. This comes from a conversion to reference
4776 target_type
= build_reference_type (target_type
);
4782 cp_error("cannot resolve overloaded function `%D' based on conversion to type `%T'",
4783 DECL_NAME (OVL_FUNCTION (overload
)), target_type
);
4784 return error_mark_node
;
4787 /* If we can find a non-template function that matches, we can just
4788 use it. There's no point in generating template instantiations
4789 if we're just going to throw them out anyhow. But, of course, we
4790 can only do this when we don't *need* a template function. */
4795 for (fns
= overload
; fns
; fns
= OVL_CHAIN (fns
))
4797 tree fn
= OVL_FUNCTION (fns
);
4800 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4801 /* We're not looking for templates just yet. */
4804 if ((TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
4806 /* We're looking for a non-static member, and this isn't
4807 one, or vice versa. */
4810 /* See if there's a match. */
4811 fntype
= TREE_TYPE (fn
);
4813 fntype
= build_ptrmemfunc_type (build_pointer_type (fntype
));
4814 else if (!is_reference
)
4815 fntype
= build_pointer_type (fntype
);
4817 if (can_convert_arg (target_type
, fntype
, fn
))
4818 matches
= tree_cons (fn
, NULL_TREE
, matches
);
4822 /* Now, if we've already got a match (or matches), there's no need
4823 to proceed to the template functions. But, if we don't have a
4824 match we need to look at them, too. */
4827 tree target_fn_type
;
4828 tree target_arg_types
;
4833 = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type
));
4835 target_fn_type
= TREE_TYPE (target_type
);
4836 target_arg_types
= TYPE_ARG_TYPES (target_fn_type
);
4838 for (fns
= overload
; fns
; fns
= OVL_CHAIN (fns
))
4840 tree fn
= OVL_FUNCTION (fns
);
4842 tree instantiation_type
;
4845 if (TREE_CODE (fn
) != TEMPLATE_DECL
)
4846 /* We're only looking for templates. */
4849 if ((TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
4851 /* We're not looking for a non-static member, and this is
4852 one, or vice versa. */
4855 /* Try to do argument deduction. */
4856 targs
= make_scratch_vec (DECL_NTPARMS (fn
));
4857 if (fn_type_unification (fn
, explicit_targs
, targs
,
4858 target_arg_types
, NULL_TREE
,
4860 /* Argument deduction failed. */
4863 /* Instantiate the template. */
4864 instantiation
= instantiate_template (fn
, targs
);
4865 if (instantiation
== error_mark_node
)
4866 /* Instantiation failed. */
4869 /* See if there's a match. */
4870 instantiation_type
= TREE_TYPE (instantiation
);
4872 instantiation_type
=
4873 build_ptrmemfunc_type (build_pointer_type (instantiation_type
));
4874 else if (!is_reference
)
4875 instantiation_type
= build_pointer_type (instantiation_type
);
4876 if (can_convert_arg (target_type
, instantiation_type
, instantiation
))
4877 matches
= tree_cons (instantiation
, fn
, matches
);
4880 /* Now, remove all but the most specialized of the matches. */
4883 tree match
= most_specialized_instantiation (matches
,
4886 if (match
!= error_mark_node
)
4887 matches
= tree_cons (match
, NULL_TREE
, NULL_TREE
);
4891 /* Now we should have exactly one function in MATCHES. */
4892 if (matches
== NULL_TREE
)
4894 /* There were *no* matches. */
4897 cp_error ("no matches converting function `%D' to type `%#T'",
4898 DECL_NAME (OVL_FUNCTION (overload
)),
4901 /* print_candidates expects a chain with the functions in
4902 TREE_VALUE slots, so we cons one up here (we're losing anyway,
4903 so why be clever?). */
4904 for (; overload
; overload
= OVL_NEXT (overload
))
4905 matches
= tree_cons (NULL_TREE
, OVL_CURRENT (overload
),
4908 print_candidates (matches
);
4910 return error_mark_node
;
4912 else if (TREE_CHAIN (matches
))
4914 /* There were too many matches. */
4920 cp_error ("converting overloaded function `%D' to type `%#T' is ambiguous",
4921 DECL_NAME (OVL_FUNCTION (overload
)),
4924 /* Since print_candidates expects the functions in the
4925 TREE_VALUE slot, we flip them here. */
4926 for (match
= matches
; match
; match
= TREE_CHAIN (match
))
4927 TREE_VALUE (match
) = TREE_PURPOSE (match
);
4929 print_candidates (matches
);
4932 return error_mark_node
;
4935 /* Good, exactly one match. Now, convert it to the correct type. */
4936 fn
= TREE_PURPOSE (matches
);
4940 if (TYPE_PTRFN_P (target_type
) || TYPE_PTRMEMFUNC_P (target_type
))
4941 return build_unary_op (ADDR_EXPR
, fn
, 0);
4944 /* The target must be a REFERENCE_TYPE. Above, build_unary_op
4945 will mark the function as addressed, but here we must do it
4947 mark_addressable (fn
);
4953 /* This function will instantiate the type of the expression given in
4954 RHS to match the type of LHSTYPE. If errors exist, then return
4955 error_mark_node. We only complain is COMPLAIN is set. If we are
4956 not complaining, never modify rhs, as overload resolution wants to
4957 try many possible instantiations, in hopes that at least one will
4960 FLAGS is a bitmask, as we see at the top of the function.
4962 For non-recursive calls, LHSTYPE should be a function, pointer to
4963 function, or a pointer to member function. */
4966 instantiate_type (lhstype
, rhs
, flags
)
4970 int complain
= (flags
& 1);
4971 int strict
= (flags
& 2) ? COMPARE_NO_ATTRIBUTES
: COMPARE_STRICT
;
4973 if (TREE_CODE (lhstype
) == UNKNOWN_TYPE
)
4976 error ("not enough type information");
4977 return error_mark_node
;
4980 if (TREE_TYPE (rhs
) != NULL_TREE
&& ! (type_unknown_p (rhs
)))
4982 if (comptypes (lhstype
, TREE_TYPE (rhs
), strict
))
4985 cp_error ("argument of type `%T' does not match `%T'",
4986 TREE_TYPE (rhs
), lhstype
);
4987 return error_mark_node
;
4990 /* We don't overwrite rhs if it is an overloaded function.
4991 Copying it would destroy the tree link. */
4992 if (TREE_CODE (rhs
) != OVERLOAD
)
4993 rhs
= copy_node (rhs
);
4995 /* This should really only be used when attempting to distinguish
4996 what sort of a pointer to function we have. For now, any
4997 arithmetic operation which is not supported on pointers
4998 is rejected as an error. */
5000 switch (TREE_CODE (rhs
))
5007 my_friendly_abort (177);
5008 return error_mark_node
;
5015 new_rhs
= instantiate_type (build_pointer_type (lhstype
),
5016 TREE_OPERAND (rhs
, 0), flags
);
5017 if (new_rhs
== error_mark_node
)
5018 return error_mark_node
;
5020 TREE_TYPE (rhs
) = lhstype
;
5021 TREE_OPERAND (rhs
, 0) = new_rhs
;
5026 rhs
= copy_node (TREE_OPERAND (rhs
, 0));
5027 TREE_TYPE (rhs
) = unknown_type_node
;
5028 return instantiate_type (lhstype
, rhs
, flags
);
5032 tree r
= instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), flags
);
5034 if (r
!= error_mark_node
&& TYPE_PTRMEMFUNC_P (lhstype
)
5035 && complain
&& !flag_ms_extensions
)
5037 /* Note: we check this after the recursive call to avoid
5038 complaining about cases where overload resolution fails. */
5040 tree t
= TREE_TYPE (TREE_OPERAND (rhs
, 0));
5041 tree fn
= PTRMEM_CST_MEMBER (r
);
5043 my_friendly_assert (TREE_CODE (r
) == PTRMEM_CST
, 990811);
5046 ("object-dependent reference to `%E' can only be used in a call",
5049 (" to form a pointer to member function, say `&%T::%E'",
5057 rhs
= TREE_OPERAND (rhs
, 1);
5058 if (BASELINK_P (rhs
))
5059 return instantiate_type (lhstype
, TREE_VALUE (rhs
), flags
);
5061 /* This can happen if we are forming a pointer-to-member for a
5063 my_friendly_assert (TREE_CODE (rhs
) == TEMPLATE_ID_EXPR
, 0);
5067 case TEMPLATE_ID_EXPR
:
5069 resolve_address_of_overloaded_function (lhstype
,
5070 TREE_OPERAND (rhs
, 0),
5072 /*template_only=*/1,
5073 TREE_OPERAND (rhs
, 1));
5077 resolve_address_of_overloaded_function (lhstype
,
5080 /*template_only=*/0,
5081 /*explicit_targs=*/NULL_TREE
);
5084 /* Now we should have a baselink. */
5085 my_friendly_assert (BASELINK_P (rhs
), 990412);
5087 return instantiate_type (lhstype
, TREE_VALUE (rhs
), flags
);
5090 /* This is too hard for now. */
5091 my_friendly_abort (183);
5092 return error_mark_node
;
5097 TREE_OPERAND (rhs
, 0)
5098 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 0), flags
);
5099 if (TREE_OPERAND (rhs
, 0) == error_mark_node
)
5100 return error_mark_node
;
5101 TREE_OPERAND (rhs
, 1)
5102 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), flags
);
5103 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5104 return error_mark_node
;
5106 TREE_TYPE (rhs
) = lhstype
;
5110 case TRUNC_DIV_EXPR
:
5111 case FLOOR_DIV_EXPR
:
5113 case ROUND_DIV_EXPR
:
5115 case TRUNC_MOD_EXPR
:
5116 case FLOOR_MOD_EXPR
:
5118 case ROUND_MOD_EXPR
:
5119 case FIX_ROUND_EXPR
:
5120 case FIX_FLOOR_EXPR
:
5122 case FIX_TRUNC_EXPR
:
5138 case PREINCREMENT_EXPR
:
5139 case PREDECREMENT_EXPR
:
5140 case POSTINCREMENT_EXPR
:
5141 case POSTDECREMENT_EXPR
:
5143 error ("invalid operation on uninstantiated type");
5144 return error_mark_node
;
5146 case TRUTH_AND_EXPR
:
5148 case TRUTH_XOR_EXPR
:
5155 case TRUTH_ANDIF_EXPR
:
5156 case TRUTH_ORIF_EXPR
:
5157 case TRUTH_NOT_EXPR
:
5159 error ("not enough type information");
5160 return error_mark_node
;
5163 if (type_unknown_p (TREE_OPERAND (rhs
, 0)))
5166 error ("not enough type information");
5167 return error_mark_node
;
5169 TREE_OPERAND (rhs
, 1)
5170 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), flags
);
5171 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5172 return error_mark_node
;
5173 TREE_OPERAND (rhs
, 2)
5174 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 2), flags
);
5175 if (TREE_OPERAND (rhs
, 2) == error_mark_node
)
5176 return error_mark_node
;
5178 TREE_TYPE (rhs
) = lhstype
;
5182 TREE_OPERAND (rhs
, 1)
5183 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), flags
);
5184 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5185 return error_mark_node
;
5187 TREE_TYPE (rhs
) = lhstype
;
5191 return instantiate_type (lhstype
, TREE_OPERAND (rhs
, 0), flags
);
5193 case ENTRY_VALUE_EXPR
:
5194 my_friendly_abort (184);
5195 return error_mark_node
;
5198 return error_mark_node
;
5201 my_friendly_abort (185);
5202 return error_mark_node
;
5206 /* Return the name of the virtual function pointer field
5207 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5208 this may have to look back through base types to find the
5209 ultimate field name. (For single inheritance, these could
5210 all be the same name. Who knows for multiple inheritance). */
5213 get_vfield_name (type
)
5216 tree binfo
= TYPE_BINFO (type
);
5219 while (BINFO_BASETYPES (binfo
)
5220 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo
, 0)))
5221 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo
, 0)))
5222 binfo
= BINFO_BASETYPE (binfo
, 0);
5224 type
= BINFO_TYPE (binfo
);
5225 buf
= (char *) alloca (sizeof (VFIELD_NAME_FORMAT
)
5226 + TYPE_NAME_LENGTH (type
) + 2);
5227 sprintf (buf
, VFIELD_NAME_FORMAT
, TYPE_NAME_STRING (type
));
5228 return get_identifier (buf
);
5232 print_class_statistics ()
5234 #ifdef GATHER_STATISTICS
5235 fprintf (stderr
, "convert_harshness = %d\n", n_convert_harshness
);
5236 fprintf (stderr
, "compute_conversion_costs = %d\n", n_compute_conversion_costs
);
5237 fprintf (stderr
, "build_method_call = %d (inner = %d)\n",
5238 n_build_method_call
, n_inner_fields_searched
);
5241 fprintf (stderr
, "vtables = %d; vtable searches = %d\n",
5242 n_vtables
, n_vtable_searches
);
5243 fprintf (stderr
, "vtable entries = %d; vtable elems = %d\n",
5244 n_vtable_entries
, n_vtable_elems
);
5249 /* Push an obstack which is sufficiently long-lived to hold such class
5250 decls that may be cached in the previous_class_values list. The
5251 effect is undone by pop_obstacks. */
5254 push_cache_obstack ()
5256 static int cache_obstack_initialized
;
5258 if (!cache_obstack_initialized
)
5260 gcc_obstack_init (&class_cache_obstack
);
5261 class_cache_firstobj
5262 = (char*) obstack_finish (&class_cache_obstack
);
5263 cache_obstack_initialized
= 1;
5266 push_obstacks_nochange ();
5267 current_obstack
= &class_cache_obstack
;
5270 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
5271 according to [class]:
5272 The class-name is also inserted
5273 into the scope of the class itself. For purposes of access checking,
5274 the inserted class name is treated as if it were a public member name. */
5277 build_self_reference ()
5279 tree name
= constructor_name (current_class_type
);
5280 tree value
= build_lang_decl (TYPE_DECL
, name
, current_class_type
);
5283 DECL_NONLOCAL (value
) = 1;
5284 DECL_CONTEXT (value
) = current_class_type
;
5285 DECL_CLASS_CONTEXT (value
) = current_class_type
;
5286 DECL_ARTIFICIAL (value
) = 1;
5288 if (processing_template_decl
)
5289 value
= push_template_decl (value
);
5291 saved_cas
= current_access_specifier
;
5292 current_access_specifier
= access_public_node
;
5293 finish_member_declaration (value
);
5294 current_access_specifier
= saved_cas
;
5297 /* Returns 1 if TYPE contains only padding bytes. */
5300 is_empty_class (type
)
5305 if (type
== error_mark_node
)
5308 if (! IS_AGGR_TYPE (type
))
5312 return CLASSTYPE_SIZE (type
) == integer_zero_node
;
5314 if (TYPE_BINFO_BASETYPES (type
))
5316 t
= TYPE_FIELDS (type
);
5317 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
5319 return (t
== NULL_TREE
);
5322 /* Find the enclosing class of the given NODE. NODE can be a *_DECL or
5323 a *_TYPE node. NODE can also be a local class. */
5326 get_enclosing_class (type
)
5331 while (node
&& TREE_CODE (node
) != NAMESPACE_DECL
)
5333 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
5336 node
= DECL_CONTEXT (node
);
5342 node
= TYPE_CONTEXT (node
);
5346 my_friendly_abort (0);
5352 /* Return 1 if TYPE or one of its enclosing classes is derived from BASE. */
5355 is_base_of_enclosing_class (base
, type
)
5360 if (get_binfo (base
, type
, 0))
5363 type
= get_enclosing_class (type
);
5368 /* Note that NAME was looked up while the current class was being
5369 defined and that the result of that lookup was DECL. */
5372 maybe_note_name_used_in_class (name
, decl
)
5376 splay_tree names_used
;
5378 /* If we're not defining a class, there's nothing to do. */
5379 if (!current_class_type
|| !TYPE_BEING_DEFINED (current_class_type
))
5382 /* If there's already a binding for this NAME, then we don't have
5383 anything to worry about. */
5384 if (IDENTIFIER_CLASS_VALUE (name
))
5387 if (!current_class_stack
[current_class_depth
- 1].names_used
)
5388 current_class_stack
[current_class_depth
- 1].names_used
5389 = splay_tree_new (splay_tree_compare_pointers
, 0, 0);
5390 names_used
= current_class_stack
[current_class_depth
- 1].names_used
;
5392 splay_tree_insert (names_used
,
5393 (splay_tree_key
) name
,
5394 (splay_tree_value
) decl
);
5397 /* Note that NAME was declared (as DECL) in the current class. Check
5398 to see that the declaration is legal. */
5401 note_name_declared_in_class (name
, decl
)
5405 splay_tree names_used
;
5408 /* Look to see if we ever used this name. */
5410 = current_class_stack
[current_class_depth
- 1].names_used
;
5414 n
= splay_tree_lookup (names_used
, (splay_tree_key
) name
);
5417 /* [basic.scope.class]
5419 A name N used in a class S shall refer to the same declaration
5420 in its context and when re-evaluated in the completed scope of
5422 cp_error ("declaration of `%#D'", decl
);
5423 cp_error_at ("changes meaning of `%s' from `%+#D'",
5424 IDENTIFIER_POINTER (DECL_NAME (decl
)),