1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 92-97, 1998, 1999 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* High-level class interface. */
33 #include "splay-tree.h"
36 #define obstack_chunk_alloc xmalloc
37 #define obstack_chunk_free free
39 extern struct obstack permanent_obstack
;
41 /* This is how we tell when two virtual member functions are really the
43 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
45 extern void set_class_shadows
PROTO ((tree
));
47 /* The number of nested classes being processed. If we are not in the
48 scope of any class, this is zero. */
50 int current_class_depth
;
52 /* In order to deal with nested classes, we keep a stack of classes.
53 The topmost entry is the innermost class, and is the entry at index
54 CURRENT_CLASS_DEPTH */
56 typedef struct class_stack_node
{
57 /* The name of the class. */
60 /* The _TYPE node for the class. */
63 /* The access specifier pending for new declarations in the scope of
67 /* If were defining TYPE, the names used in this class. */
68 splay_tree names_used
;
69 }* class_stack_node_t
;
71 /* The stack itself. This is an dynamically resized array. The
72 number of elements allocated is CURRENT_CLASS_STACK_SIZE. */
73 static int current_class_stack_size
;
74 static class_stack_node_t current_class_stack
;
76 /* When we're processing a member function, current_class_ptr is the
77 PARM_DECL for the `this' pointer. The current_class_ref is an
78 expression for `*this'. */
79 tree current_class_ptr
, current_class_ref
;
81 /* The following two can be derived from the previous one */
82 tree current_class_name
; /* IDENTIFIER_NODE: name of current class */
83 tree current_class_type
; /* _TYPE: the type of the current class */
84 tree current_access_specifier
;
85 tree previous_class_type
; /* _TYPE: the previous type that was a class */
86 tree previous_class_values
; /* TREE_LIST: copy of the class_shadowed list
87 when leaving an outermost class scope. */
89 /* The obstack on which the cached class declarations are kept. */
90 static struct obstack class_cache_obstack
;
91 /* The first object allocated on that obstack. We can use
92 obstack_free with tis value to free the entire obstack. */
93 static char *class_cache_firstobj
;
97 static tree get_vfield_name
PROTO((tree
));
98 static void finish_struct_anon
PROTO((tree
));
99 static tree build_vbase_pointer
PROTO((tree
, tree
));
100 static tree build_vtable_entry
PROTO((tree
, tree
));
101 static tree get_vtable_name
PROTO((tree
));
102 static tree get_derived_offset
PROTO((tree
, tree
));
103 static tree get_basefndecls
PROTO((tree
, tree
));
104 static void set_rtti_entry
PROTO((tree
, tree
, tree
));
105 static tree build_vtable
PROTO((tree
, tree
));
106 static void prepare_fresh_vtable
PROTO((tree
, tree
));
107 static void fixup_vtable_deltas1
PROTO((tree
, tree
));
108 static void fixup_vtable_deltas
PROTO((tree
, int, tree
));
109 static void finish_vtbls
PROTO((tree
, int, tree
));
110 static void modify_vtable_entry
PROTO((tree
, tree
, tree
));
111 static tree get_vtable_entry_n
PROTO((tree
, unsigned HOST_WIDE_INT
));
112 static void add_virtual_function
PROTO((tree
*, tree
*, int *, tree
, tree
));
113 static tree delete_duplicate_fields_1
PROTO((tree
, tree
));
114 static void delete_duplicate_fields
PROTO((tree
));
115 static void finish_struct_bits
PROTO((tree
, int));
116 static int alter_access
PROTO((tree
, tree
, tree
, tree
));
117 static void handle_using_decl
PROTO((tree
, tree
, tree
, tree
));
118 static int overrides
PROTO((tree
, tree
));
119 static int strictly_overrides
PROTO((tree
, tree
));
120 static void merge_overrides
PROTO((tree
, tree
, int, tree
));
121 static void override_one_vtable
PROTO((tree
, tree
, tree
));
122 static void mark_overriders
PROTO((tree
, tree
));
123 static void check_for_override
PROTO((tree
, tree
));
124 static tree get_class_offset_1
PROTO((tree
, tree
, tree
, tree
, tree
));
125 static tree get_class_offset
PROTO((tree
, tree
, tree
, tree
));
126 static void modify_one_vtable
PROTO((tree
, tree
, tree
, tree
));
127 static void modify_all_vtables
PROTO((tree
, tree
, tree
));
128 static void modify_all_direct_vtables
PROTO((tree
, int, tree
, tree
,
130 static void modify_all_indirect_vtables
PROTO((tree
, int, int, tree
,
132 static int finish_base_struct
PROTO((tree
, struct base_info
*));
133 static void finish_struct_methods
PROTO((tree
));
134 static void maybe_warn_about_overly_private_class
PROTO ((tree
));
135 static tree make_method_vec
PROTO((int));
136 static void free_method_vec
PROTO((tree
));
137 static tree add_implicitly_declared_members
PROTO((tree
, int, int, int));
138 static tree fixed_type_or_null
PROTO((tree
, int *));
139 static tree resolve_address_of_overloaded_function
PROTO((tree
, tree
, int,
141 static void build_vtable_entry_ref
PROTO((tree
, tree
, tree
));
143 /* Way of stacking language names. */
144 tree
*current_lang_base
, *current_lang_stack
;
145 int current_lang_stacksize
;
147 /* Names of languages we recognize. */
148 tree lang_name_c
, lang_name_cplusplus
, lang_name_java
;
149 tree current_lang_name
;
151 /* When layout out an aggregate type, the size of the
152 basetypes (virtual and non-virtual) is passed to layout_record
154 static tree base_layout_decl
;
156 /* Constants used for access control. */
157 tree access_default_node
; /* 0 */
158 tree access_public_node
; /* 1 */
159 tree access_protected_node
; /* 2 */
160 tree access_private_node
; /* 3 */
161 tree access_default_virtual_node
; /* 4 */
162 tree access_public_virtual_node
; /* 5 */
163 tree access_protected_virtual_node
; /* 6 */
164 tree access_private_virtual_node
; /* 7 */
166 /* Variables shared between class.c and call.c. */
168 #ifdef GATHER_STATISTICS
170 int n_vtable_entries
= 0;
171 int n_vtable_searches
= 0;
172 int n_vtable_elems
= 0;
173 int n_convert_harshness
= 0;
174 int n_compute_conversion_costs
= 0;
175 int n_build_method_call
= 0;
176 int n_inner_fields_searched
= 0;
179 /* Virtual baseclass things. */
182 build_vbase_pointer (exp
, type
)
186 FORMAT_VBASE_NAME (name
, type
);
188 return build_component_ref (exp
, get_identifier (name
), NULL_TREE
, 0);
192 /* Is the type of the EXPR, the complete type of the object?
193 If we are going to be wrong, we must be conservative, and return 0. */
196 complete_type_p (expr
)
199 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
202 switch (TREE_CODE (expr
))
209 expr
= TREE_OPERAND (expr
, 0);
213 if (! TREE_HAS_CONSTRUCTOR (expr
))
215 /* fall through... */
218 if (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
219 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr
)))
220 && TYPE_MAIN_VARIANT (TREE_TYPE (expr
)) == type
)
222 /* fall through... */
225 if (IS_AGGR_TYPE (TREE_TYPE (expr
))
226 && TYPE_MAIN_VARIANT (TREE_TYPE (expr
)) == type
)
228 /* fall through... */
239 /* Build multi-level access to EXPR using hierarchy path PATH.
240 CODE is PLUS_EXPR if we are going with the grain,
241 and MINUS_EXPR if we are not (in which case, we cannot traverse
242 virtual baseclass links).
244 TYPE is the type we want this path to have on exit.
246 NONNULL is non-zero if we know (for any reason) that EXPR is
247 not, in fact, zero. */
250 build_vbase_path (code
, type
, expr
, path
, nonnull
)
252 tree type
, expr
, path
;
255 register int changed
= 0;
256 tree last
= NULL_TREE
, last_virtual
= NULL_TREE
;
258 tree null_expr
= 0, nonnull_expr
;
260 tree offset
= integer_zero_node
;
262 if (BINFO_INHERITANCE_CHAIN (path
) == NULL_TREE
)
263 return build1 (NOP_EXPR
, type
, expr
);
265 /* If -fthis-is-variable, we might have set nonnull incorrectly. We
266 don't care enough to get this right, so just clear it. */
267 if (flag_this_is_variable
> 0)
270 /* We could do better if we had additional logic to convert back to the
271 unconverted type (the static type of the complete object), and then
272 convert back to the type we want. Until that is done, we only optimize
273 if the complete type is the same type as expr has. */
274 fixed_type_p
= resolves_to_fixed_type_p (expr
, &nonnull
);
276 if (!fixed_type_p
&& TREE_SIDE_EFFECTS (expr
))
277 expr
= save_expr (expr
);
280 if (BINFO_INHERITANCE_CHAIN (path
))
281 path
= reverse_path (path
);
283 basetype
= BINFO_TYPE (path
);
287 if (TREE_VIA_VIRTUAL (path
))
289 last_virtual
= BINFO_TYPE (path
);
290 if (code
== PLUS_EXPR
)
292 changed
= ! fixed_type_p
;
298 /* We already check for ambiguous things in the caller, just
302 tree binfo
= get_binfo (last
, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr
))), 0);
303 nonnull_expr
= convert_pointer_to_real (binfo
, nonnull_expr
);
305 ind
= build_indirect_ref (nonnull_expr
, NULL_PTR
);
306 nonnull_expr
= build_vbase_pointer (ind
, last_virtual
);
308 && TREE_CODE (type
) == POINTER_TYPE
309 && null_expr
== NULL_TREE
)
311 null_expr
= build1 (NOP_EXPR
, build_pointer_type (last_virtual
), integer_zero_node
);
312 expr
= build (COND_EXPR
, build_pointer_type (last_virtual
),
313 build (EQ_EXPR
, boolean_type_node
, expr
,
315 null_expr
, nonnull_expr
);
318 /* else we'll figure out the offset below. */
320 /* Happens in the case of parse errors. */
321 if (nonnull_expr
== error_mark_node
)
322 return error_mark_node
;
326 cp_error ("cannot cast up from virtual baseclass `%T'",
328 return error_mark_node
;
332 path
= BINFO_INHERITANCE_CHAIN (path
);
334 /* LAST is now the last basetype assoc on the path. */
336 /* A pointer to a virtual base member of a non-null object
337 is non-null. Therefore, we only need to test for zeroness once.
338 Make EXPR the canonical expression to deal with here. */
341 TREE_OPERAND (expr
, 2) = nonnull_expr
;
342 TREE_TYPE (expr
) = TREE_TYPE (TREE_OPERAND (expr
, 1))
343 = TREE_TYPE (nonnull_expr
);
348 /* If we go through any virtual base pointers, make sure that
349 casts to BASETYPE from the last virtual base class use
350 the right value for BASETYPE. */
353 tree intype
= TREE_TYPE (TREE_TYPE (expr
));
354 if (TYPE_MAIN_VARIANT (intype
) != BINFO_TYPE (last
))
356 tree binfo
= get_binfo (last
, TYPE_MAIN_VARIANT (intype
), 0);
357 offset
= BINFO_OFFSET (binfo
);
364 offset
= BINFO_OFFSET (binfo_member (last_virtual
,
365 CLASSTYPE_VBASECLASSES (basetype
)));
366 offset
= size_binop (PLUS_EXPR
, offset
, BINFO_OFFSET (last
));
369 offset
= BINFO_OFFSET (last
);
372 if (TREE_INT_CST_LOW (offset
))
374 /* Bash types to make the backend happy. */
375 offset
= cp_convert (type
, offset
);
377 /* This shouldn't be necessary. (mrs) */
378 expr
= build1 (NOP_EXPR
, type
, expr
);
381 /* If expr might be 0, we need to preserve that zeroness. */
385 TREE_TYPE (null_expr
) = type
;
387 null_expr
= build1 (NOP_EXPR
, type
, integer_zero_node
);
388 if (TREE_SIDE_EFFECTS (expr
))
389 expr
= save_expr (expr
);
391 return build (COND_EXPR
, type
,
392 build (EQ_EXPR
, boolean_type_node
, expr
, integer_zero_node
),
394 build (code
, type
, expr
, offset
));
396 else return build (code
, type
, expr
, offset
);
399 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
400 be used multiple times in initialization of multiple inheritance. */
403 TREE_TYPE (expr
) = type
;
407 return build1 (NOP_EXPR
, type
, expr
);
410 /* Virtual function things. */
412 /* Build an entry in the virtual function table.
413 DELTA is the offset for the `this' pointer.
414 PFN is an ADDR_EXPR containing a pointer to the virtual function.
415 Note that the index (DELTA2) in the virtual function table
419 build_vtable_entry (delta
, pfn
)
422 if (flag_vtable_thunks
)
424 HOST_WIDE_INT idelta
= TREE_INT_CST_LOW (delta
);
425 if (idelta
&& ! DECL_ABSTRACT_VIRTUAL_P (TREE_OPERAND (pfn
, 0)))
427 pfn
= build1 (ADDR_EXPR
, vtable_entry_type
,
428 make_thunk (pfn
, idelta
));
429 TREE_READONLY (pfn
) = 1;
430 TREE_CONSTANT (pfn
) = 1;
432 #ifdef GATHER_STATISTICS
433 n_vtable_entries
+= 1;
439 extern int flag_huge_objects
;
440 tree elems
= expr_tree_cons (NULL_TREE
, delta
,
441 expr_tree_cons (NULL_TREE
, integer_zero_node
,
442 build_expr_list (NULL_TREE
, pfn
)));
443 tree entry
= build (CONSTRUCTOR
, vtable_entry_type
, NULL_TREE
, elems
);
445 /* DELTA used to be constructed by `size_int' and/or size_binop,
446 which caused overflow problems when it was negative. That should
449 if (! int_fits_type_p (delta
, delta_type_node
))
451 if (flag_huge_objects
)
452 sorry ("object size exceeds built-in limit for virtual function table implementation");
454 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
457 TREE_CONSTANT (entry
) = 1;
458 TREE_STATIC (entry
) = 1;
459 TREE_READONLY (entry
) = 1;
461 #ifdef GATHER_STATISTICS
462 n_vtable_entries
+= 1;
469 /* We want to give the assembler the vtable identifier as well as
470 the offset to the function pointer. So we generate
472 __asm__ __volatile__ (".vtable_entry %c0, %c1"
473 : : "s"(&class_vtable),
474 "i"((long)&vtbl[idx].pfn - (long)&vtbl[0])); */
477 build_vtable_entry_ref (basetype
, vtbl
, idx
)
478 tree basetype
, vtbl
, idx
;
480 static char asm_stmt
[] = ".vtable_entry %c0, %c1";
483 s
= build_unary_op (ADDR_EXPR
, TYPE_BINFO_VTABLE (basetype
), 0);
484 s
= build_tree_list (build_string (1, "s"), s
);
486 i
= build_array_ref (vtbl
, idx
);
487 if (!flag_vtable_thunks
)
488 i
= build_component_ref (i
, pfn_identifier
, vtable_entry_type
, 0);
489 i
= build_c_cast (ptrdiff_type_node
, build_unary_op (ADDR_EXPR
, i
, 0));
490 i2
= build_array_ref (vtbl
, build_int_2(0,0));
491 i2
= build_c_cast (ptrdiff_type_node
, build_unary_op (ADDR_EXPR
, i2
, 0));
492 i
= build_binary_op (MINUS_EXPR
, i
, i2
);
493 i
= build_tree_list (build_string (1, "i"), i
);
495 expand_asm_operands (build_string (sizeof(asm_stmt
)-1, asm_stmt
),
496 NULL_TREE
, chainon (s
, i
), NULL_TREE
, 1, NULL
, 0);
499 /* Given an object INSTANCE, return an expression which yields the
500 virtual function vtable element corresponding to INDEX. There are
501 many special cases for INSTANCE which we take care of here, mainly
502 to avoid creating extra tree nodes when we don't have to. */
505 build_vtbl_ref (instance
, idx
)
509 tree basetype
= TREE_TYPE (instance
);
511 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
512 basetype
= TREE_TYPE (basetype
);
514 if (instance
== current_class_ref
)
515 vtbl
= build_vfield_ref (instance
, basetype
);
520 /* Try to figure out what a reference refers to, and
521 access its virtual function table directly. */
522 tree ref
= NULL_TREE
;
524 if (TREE_CODE (instance
) == INDIRECT_REF
525 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance
, 0))) == REFERENCE_TYPE
)
526 ref
= TREE_OPERAND (instance
, 0);
527 else if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
530 if (ref
&& TREE_CODE (ref
) == VAR_DECL
531 && DECL_INITIAL (ref
))
533 tree init
= DECL_INITIAL (ref
);
535 while (TREE_CODE (init
) == NOP_EXPR
536 || TREE_CODE (init
) == NON_LVALUE_EXPR
)
537 init
= TREE_OPERAND (init
, 0);
538 if (TREE_CODE (init
) == ADDR_EXPR
)
540 init
= TREE_OPERAND (init
, 0);
541 if (IS_AGGR_TYPE (TREE_TYPE (init
))
542 && (TREE_CODE (init
) == PARM_DECL
543 || TREE_CODE (init
) == VAR_DECL
))
549 if (IS_AGGR_TYPE (TREE_TYPE (instance
))
550 && (TREE_CODE (instance
) == RESULT_DECL
551 || TREE_CODE (instance
) == PARM_DECL
552 || TREE_CODE (instance
) == VAR_DECL
))
553 vtbl
= TYPE_BINFO_VTABLE (basetype
);
555 vtbl
= build_vfield_ref (instance
, basetype
);
558 assemble_external (vtbl
);
561 build_vtable_entry_ref (basetype
, vtbl
, idx
);
563 aref
= build_array_ref (vtbl
, idx
);
568 /* Given an object INSTANCE, return an expression which yields the
569 virtual function corresponding to INDEX. There are many special
570 cases for INSTANCE which we take care of here, mainly to avoid
571 creating extra tree nodes when we don't have to. */
574 build_vfn_ref (ptr_to_instptr
, instance
, idx
)
575 tree
*ptr_to_instptr
, instance
;
578 tree aref
= build_vtbl_ref (instance
, idx
);
580 /* When using thunks, there is no extra delta, and we get the pfn
582 if (flag_vtable_thunks
)
587 /* Save the intermediate result in a SAVE_EXPR so we don't have to
588 compute each component of the virtual function pointer twice. */
589 if (TREE_CODE (aref
) == INDIRECT_REF
)
590 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
593 = build (PLUS_EXPR
, TREE_TYPE (*ptr_to_instptr
),
595 cp_convert (ptrdiff_type_node
,
596 build_component_ref (aref
, delta_identifier
, NULL_TREE
, 0)));
599 return build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
602 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
603 for the given TYPE. */
606 get_vtable_name (type
)
609 tree type_id
= build_typename_overload (type
);
610 char *buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
)
611 + IDENTIFIER_LENGTH (type_id
) + 2);
612 const char *ptr
= IDENTIFIER_POINTER (type_id
);
614 for (i
= 0; ptr
[i
] == OPERATOR_TYPENAME_FORMAT
[i
]; i
++) ;
616 /* We don't take off the numbers; prepare_fresh_vtable uses the
617 DECL_ASSEMBLER_NAME for the type, which includes the number
618 in `3foo'. If we were to pull them off here, we'd end up with
619 something like `_vt.foo.3bar', instead of a uniform definition. */
620 while (ptr
[i
] >= '0' && ptr
[i
] <= '9')
623 sprintf (buf
, VTABLE_NAME_FORMAT
, ptr
+i
);
624 return get_identifier (buf
);
627 /* Return the offset to the main vtable for a given base BINFO. */
630 get_vfield_offset (binfo
)
634 = size_binop (FLOOR_DIV_EXPR
,
635 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))),
636 size_int (BITS_PER_UNIT
));
637 tmp
= convert (sizetype
, tmp
);
638 return size_binop (PLUS_EXPR
, tmp
, BINFO_OFFSET (binfo
));
641 /* Get the offset to the start of the original binfo that we derived
642 this binfo from. If we find TYPE first, return the offset only
643 that far. The shortened search is useful because the this pointer
644 on method calling is expected to point to a DECL_CONTEXT (fndecl)
645 object, and not a baseclass of it. */
648 get_derived_offset (binfo
, type
)
651 tree offset1
= get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo
)));
654 while (BINFO_BASETYPES (binfo
)
655 && (i
=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
))) != -1)
657 tree binfos
= BINFO_BASETYPES (binfo
);
658 if (BINFO_TYPE (binfo
) == type
)
660 binfo
= TREE_VEC_ELT (binfos
, i
);
662 offset2
= get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo
)));
663 return size_binop (MINUS_EXPR
, offset1
, offset2
);
666 /* Update the rtti info for this class. */
669 set_rtti_entry (virtuals
, offset
, type
)
670 tree virtuals
, offset
, type
;
674 if (CLASSTYPE_COM_INTERFACE (type
))
678 vfn
= build1 (ADDR_EXPR
, vfunc_ptr_type_node
, get_tinfo_fn (type
));
680 vfn
= build1 (NOP_EXPR
, vfunc_ptr_type_node
, size_zero_node
);
681 TREE_CONSTANT (vfn
) = 1;
683 if (! flag_vtable_thunks
)
684 TREE_VALUE (virtuals
) = build_vtable_entry (offset
, vfn
);
687 tree voff
= build1 (NOP_EXPR
, vfunc_ptr_type_node
, offset
);
688 TREE_CONSTANT (voff
) = 1;
690 TREE_VALUE (virtuals
) = build_vtable_entry (integer_zero_node
, voff
);
692 /* The second slot is for the tdesc pointer when thunks are used. */
693 TREE_VALUE (TREE_CHAIN (virtuals
))
694 = build_vtable_entry (integer_zero_node
, vfn
);
698 /* Build a virtual function for type TYPE.
699 If BINFO is non-NULL, build the vtable starting with the initial
700 approximation that it is the same as the one which is the head of
701 the association list. */
704 build_vtable (binfo
, type
)
707 tree name
= get_vtable_name (type
);
714 virtuals
= copy_list (BINFO_VIRTUALS (binfo
));
715 decl
= build_decl (VAR_DECL
, name
, TREE_TYPE (BINFO_VTABLE (binfo
)));
717 /* Now do rtti stuff. */
718 offset
= get_derived_offset (TYPE_BINFO (type
), NULL_TREE
);
719 offset
= ssize_binop (MINUS_EXPR
, integer_zero_node
, offset
);
720 set_rtti_entry (virtuals
, offset
, type
);
724 virtuals
= NULL_TREE
;
725 decl
= build_decl (VAR_DECL
, name
, void_type_node
);
728 #ifdef GATHER_STATISTICS
730 n_vtable_elems
+= list_length (virtuals
);
733 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
734 import_export_vtable (decl
, type
, 0);
736 decl
= pushdecl_top_level (decl
);
737 SET_IDENTIFIER_GLOBAL_VALUE (name
, decl
);
738 /* Initialize the association list for this type, based
739 on our first approximation. */
740 TYPE_BINFO_VTABLE (type
) = decl
;
741 TYPE_BINFO_VIRTUALS (type
) = virtuals
;
743 DECL_ARTIFICIAL (decl
) = 1;
744 TREE_STATIC (decl
) = 1;
745 #ifndef WRITABLE_VTABLES
746 /* Make them READONLY by default. (mrs) */
747 TREE_READONLY (decl
) = 1;
749 /* At one time the vtable info was grabbed 2 words at a time. This
750 fails on sparc unless you have 8-byte alignment. (tiemann) */
751 DECL_ALIGN (decl
) = MAX (TYPE_ALIGN (double_type_node
),
754 DECL_VIRTUAL_P (decl
) = 1;
755 DECL_CONTEXT (decl
) = type
;
757 binfo
= TYPE_BINFO (type
);
758 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
762 extern tree signed_size_zero_node
;
764 /* Give TYPE a new virtual function table which is initialized
765 with a skeleton-copy of its original initialization. The only
766 entry that changes is the `delta' entry, so we can really
767 share a lot of structure.
769 FOR_TYPE is the derived type which caused this table to
772 BINFO is the type association which provided TYPE for FOR_TYPE.
774 The order in which vtables are built (by calling this function) for
775 an object must remain the same, otherwise a binary incompatibility
779 prepare_fresh_vtable (binfo
, for_type
)
780 tree binfo
, for_type
;
783 tree orig_decl
= BINFO_VTABLE (binfo
);
796 basetype
= TYPE_MAIN_VARIANT (BINFO_TYPE (binfo
));
798 buf2
= TYPE_ASSEMBLER_NAME_STRING (basetype
);
799 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1;
801 /* We know that the vtable that we are going to create doesn't exist
802 yet in the global namespace, and when we finish, it will be
803 pushed into the global namespace. In complex MI hierarchies, we
804 have to loop while the name we are thinking of adding is globally
805 defined, adding more name components to the vtable name as we
806 loop, until the name is unique. This is because in complex MI
807 cases, we might have the same base more than once. This means
808 that the order in which this function is called for vtables must
809 remain the same, otherwise binary compatibility can be
814 char *buf1
= (char *) alloca (TYPE_ASSEMBLER_NAME_LENGTH (for_type
)
818 sprintf (buf1
, "%s%c%s", TYPE_ASSEMBLER_NAME_STRING (for_type
), joiner
,
820 buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
) + strlen (buf1
) + 1);
821 sprintf (buf
, VTABLE_NAME_FORMAT
, buf1
);
822 name
= get_identifier (buf
);
824 /* If this name doesn't clash, then we can use it, otherwise
825 we add more to the name until it is unique. */
827 if (! IDENTIFIER_GLOBAL_VALUE (name
))
830 /* Set values for next loop through, if the name isn't unique. */
832 path
= BINFO_INHERITANCE_CHAIN (path
);
834 /* We better not run out of stuff to make it unique. */
835 my_friendly_assert (path
!= NULL_TREE
, 368);
837 basetype
= TYPE_MAIN_VARIANT (BINFO_TYPE (path
));
839 if (for_type
== basetype
)
841 /* If we run out of basetypes in the path, we have already
842 found created a vtable with that name before, we now
843 resort to tacking on _%d to distinguish them. */
845 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1 + i
+ 1 + 3;
846 buf1
= (char *) alloca (i
);
848 sprintf (buf1
, "%s%c%s%c%d",
849 TYPE_ASSEMBLER_NAME_STRING (basetype
), joiner
,
851 buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
)
852 + strlen (buf1
) + 1);
853 sprintf (buf
, VTABLE_NAME_FORMAT
, buf1
);
854 name
= get_identifier (buf
);
856 /* If this name doesn't clash, then we can use it,
857 otherwise we add something different to the name until
859 } while (++j
<= 999 && IDENTIFIER_GLOBAL_VALUE (name
));
861 /* Hey, they really like MI don't they? Increase the 3
862 above to 6, and the 999 to 999999. :-) */
863 my_friendly_assert (j
<= 999, 369);
868 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1 + i
;
869 new_buf2
= (char *) alloca (i
);
870 sprintf (new_buf2
, "%s%c%s",
871 TYPE_ASSEMBLER_NAME_STRING (basetype
), joiner
, buf2
);
875 new_decl
= build_decl (VAR_DECL
, name
, TREE_TYPE (orig_decl
));
876 /* Remember which class this vtable is really for. */
877 DECL_CONTEXT (new_decl
) = for_type
;
879 DECL_ARTIFICIAL (new_decl
) = 1;
880 TREE_STATIC (new_decl
) = 1;
881 BINFO_VTABLE (binfo
) = pushdecl_top_level (new_decl
);
882 DECL_VIRTUAL_P (new_decl
) = 1;
883 #ifndef WRITABLE_VTABLES
884 /* Make them READONLY by default. (mrs) */
885 TREE_READONLY (new_decl
) = 1;
887 DECL_ALIGN (new_decl
) = DECL_ALIGN (orig_decl
);
889 /* Make fresh virtual list, so we can smash it later. */
890 BINFO_VIRTUALS (binfo
) = copy_list (BINFO_VIRTUALS (binfo
));
892 if (TREE_VIA_VIRTUAL (binfo
))
894 tree binfo1
= binfo_member (BINFO_TYPE (binfo
),
895 CLASSTYPE_VBASECLASSES (for_type
));
897 /* XXX - This should never happen, if it does, the caller should
898 ensure that the binfo is from for_type's binfos, not from any
899 base type's. We can remove all this code after a while. */
901 warning ("internal inconsistency: binfo offset error for rtti");
903 offset
= BINFO_OFFSET (binfo1
);
906 offset
= BINFO_OFFSET (binfo
);
908 set_rtti_entry (BINFO_VIRTUALS (binfo
),
909 ssize_binop (MINUS_EXPR
, integer_zero_node
, offset
),
912 #ifdef GATHER_STATISTICS
914 n_vtable_elems
+= list_length (BINFO_VIRTUALS (binfo
));
917 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
918 import_export_vtable (new_decl
, for_type
, 0);
920 if (TREE_VIA_VIRTUAL (binfo
))
921 my_friendly_assert (binfo
== binfo_member (BINFO_TYPE (binfo
),
922 CLASSTYPE_VBASECLASSES (current_class_type
)),
924 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
928 /* Access the virtual function table entry that logically
929 contains BASE_FNDECL. VIRTUALS is the virtual function table's
930 initializer. We can run off the end, when dealing with virtual
931 destructors in MI situations, return NULL_TREE in that case. */
934 get_vtable_entry (virtuals
, base_fndecl
)
935 tree virtuals
, base_fndecl
;
937 unsigned HOST_WIDE_INT n
= (HOST_BITS_PER_WIDE_INT
>= BITS_PER_WORD
938 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
))
939 & (((unsigned HOST_WIDE_INT
)1<<(BITS_PER_WORD
-1))-1))
940 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
)));
942 #ifdef GATHER_STATISTICS
943 n_vtable_searches
+= n
;
946 while (n
> 0 && virtuals
)
949 virtuals
= TREE_CHAIN (virtuals
);
955 /* Put new entry ENTRY into virtual function table initializer
958 Also update DECL_VINDEX (FNDECL). */
961 modify_vtable_entry (old_entry_in_list
, new_entry
, fndecl
)
962 tree old_entry_in_list
, new_entry
, fndecl
;
964 tree base_fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list
)), 0);
967 cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl
),
968 DECL_ASSEMBLER_NAME (fndecl
));
970 TREE_VALUE (old_entry_in_list
) = new_entry
;
972 /* Now assign virtual dispatch information, if unset. */
973 /* We can dispatch this, through any overridden base function. */
974 if (TREE_CODE (DECL_VINDEX (fndecl
)) != INTEGER_CST
)
976 DECL_VINDEX (fndecl
) = DECL_VINDEX (base_fndecl
);
977 DECL_CONTEXT (fndecl
) = DECL_CONTEXT (base_fndecl
);
981 /* Access the virtual function table entry N. VIRTUALS is the virtual
982 function table's initializer. */
985 get_vtable_entry_n (virtuals
, n
)
987 unsigned HOST_WIDE_INT n
;
992 virtuals
= TREE_CHAIN (virtuals
);
997 /* Add a virtual function to all the appropriate vtables for the class
998 T. DECL_VINDEX(X) should be error_mark_node, if we want to
999 allocate a new slot in our table. If it is error_mark_node, we
1000 know that no other function from another vtable is overridden by X.
1001 HAS_VIRTUAL keeps track of how many virtuals there are in our main
1002 vtable for the type, and we build upon the PENDING_VIRTUALS list
1006 add_virtual_function (pv
, phv
, has_virtual
, fndecl
, t
)
1010 tree t
; /* Structure type. */
1012 tree pending_virtuals
= *pv
;
1013 tree pending_hard_virtuals
= *phv
;
1015 /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
1016 convert to void *. Make such a conversion here. */
1017 tree vfn
= build1 (ADDR_EXPR
, vfunc_ptr_type_node
, fndecl
);
1018 TREE_CONSTANT (vfn
) = 1;
1021 if (current_class_type
== 0)
1022 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
1024 if (current_class_type
&& t
!= current_class_type
)
1025 cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
1029 /* If the virtual function is a redefinition of a prior one,
1030 figure out in which base class the new definition goes,
1031 and if necessary, make a fresh virtual function table
1032 to hold that entry. */
1033 if (DECL_VINDEX (fndecl
) == error_mark_node
)
1037 /* We remember that this was the base sub-object for rtti. */
1038 CLASSTYPE_RTTI (t
) = t
;
1040 /* If we are using thunks, use two slots at the front, one
1041 for the offset pointer, one for the tdesc pointer.
1042 For ARM-style vtables, use the same slot for both. */
1043 if (*has_virtual
== 0 && ! CLASSTYPE_COM_INTERFACE (t
))
1045 if (flag_vtable_thunks
)
1051 /* Build a new INT_CST for this DECL_VINDEX. */
1053 static tree index_table
[256];
1055 /* We skip a slot for the offset/tdesc entry. */
1056 int i
= (*has_virtual
)++;
1058 if (i
>= 256 || index_table
[i
] == 0)
1060 idx
= build_int_2 (i
, 0);
1062 index_table
[i
] = idx
;
1065 idx
= index_table
[i
];
1067 /* Now assign virtual dispatch information. */
1068 DECL_VINDEX (fndecl
) = idx
;
1069 DECL_CONTEXT (fndecl
) = t
;
1071 entry
= build_vtable_entry (integer_zero_node
, vfn
);
1072 pending_virtuals
= tree_cons (DECL_VINDEX (fndecl
), entry
, pending_virtuals
);
1074 /* Might already be INTEGER_CST if declared twice in class. We will
1075 give error later or we've already given it. */
1076 else if (TREE_CODE (DECL_VINDEX (fndecl
)) != INTEGER_CST
)
1078 /* Need an entry in some other virtual function table.
1079 Deal with this after we have laid out our virtual base classes. */
1080 pending_hard_virtuals
= temp_tree_cons (fndecl
, vfn
, pending_hard_virtuals
);
1082 *pv
= pending_virtuals
;
1083 *phv
= pending_hard_virtuals
;
1086 /* Obstack on which to build the vector of class methods. */
1087 struct obstack class_obstack
;
1088 extern struct obstack
*current_obstack
;
1090 /* These are method vectors that were too small for the number of
1091 methods in some class, and so were abandoned. */
1092 static tree free_method_vecs
;
1094 /* Returns a method vector with enough room for N methods. N should
1095 be a power of two. */
1104 for (t
= &free_method_vecs
; *t
; t
= &(TREE_CHAIN (*t
)))
1105 /* Note that we don't use >= n here because we don't want to
1106 allocate a very large vector where it isn't needed. */
1107 if (TREE_VEC_LENGTH (*t
) == n
)
1110 *t
= TREE_CHAIN (new_vec
);
1111 TREE_CHAIN (new_vec
) = NULL_TREE
;
1112 bzero ((PTR
) &TREE_VEC_ELT (new_vec
, 0), n
* sizeof (tree
));
1116 new_vec
= make_tree_vec (n
);
1120 /* Free the method vector VEC. */
1123 free_method_vec (vec
)
1126 TREE_CHAIN (vec
) = free_method_vecs
;
1127 free_method_vecs
= vec
;
1130 /* Add method METHOD to class TYPE.
1132 If non-NULL, FIELDS is the entry in the METHOD_VEC vector entry of
1133 the class type where the method should be added. */
1136 add_method (type
, fields
, method
)
1137 tree type
, *fields
, method
;
1139 push_obstacks (&permanent_obstack
, &permanent_obstack
);
1141 /* Setting the DECL_CONTEXT and DECL_CLASS_CONTEXT here is probably
1143 DECL_CONTEXT (method
) = type
;
1144 DECL_CLASS_CONTEXT (method
) = type
;
1146 if (fields
&& *fields
)
1147 *fields
= build_overload (method
, *fields
);
1154 if (!CLASSTYPE_METHOD_VEC (type
))
1155 /* Make a new method vector. We start with 8 entries. We must
1156 allocate at least two (for constructors and destructors), and
1157 we're going to end up with an assignment operator at some
1160 We could use a TREE_LIST for now, and convert it to a
1161 TREE_VEC in finish_struct, but we would probably waste more
1162 memory making the links in the list than we would by
1163 over-allocating the size of the vector here. Furthermore,
1164 we would complicate all the code that expects this to be a
1165 vector. We keep a free list of vectors that we outgrew so
1166 that we don't really waste any memory. */
1167 CLASSTYPE_METHOD_VEC (type
) = make_method_vec (8);
1169 method_vec
= CLASSTYPE_METHOD_VEC (type
);
1170 len
= TREE_VEC_LENGTH (method_vec
);
1172 if (DECL_NAME (method
) == constructor_name (type
))
1173 /* A new constructor or destructor. Constructors go in
1174 slot 0; destructors go in slot 1. */
1175 slot
= DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (method
)) ? 1 : 0;
1178 /* See if we already have an entry with this name. */
1179 for (slot
= 2; slot
< len
; ++slot
)
1180 if (!TREE_VEC_ELT (method_vec
, slot
)
1181 || (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec
,
1183 == DECL_NAME (method
)))
1188 /* We need a bigger method vector. */
1189 tree new_vec
= make_method_vec (2 * len
);
1190 bcopy ((PTR
) &TREE_VEC_ELT (method_vec
, 0),
1191 (PTR
) &TREE_VEC_ELT (new_vec
, 0),
1192 len
* sizeof (tree
));
1193 free_method_vec (method_vec
);
1195 method_vec
= CLASSTYPE_METHOD_VEC (type
) = new_vec
;
1198 if (DECL_CONV_FN_P (method
) && !TREE_VEC_ELT (method_vec
, slot
))
1200 /* Type conversion operators have to come before
1201 ordinary methods; add_conversions depends on this to
1202 speed up looking for conversion operators. So, if
1203 necessary, we slide some of the vector elements up.
1204 In theory, this makes this algorithm O(N^2) but we
1205 don't expect many conversion operators. */
1206 for (slot
= 2; slot
< len
; ++slot
)
1208 tree fn
= TREE_VEC_ELT (method_vec
, slot
);
1211 /* There are no more entries in the vector, so we
1212 can insert the new conversion operator here. */
1215 if (!DECL_CONV_FN_P (OVL_CURRENT (fn
)))
1216 /* We can insert the new function right at the
1221 if (!TREE_VEC_ELT (method_vec
, slot
))
1222 /* There is nothing in the Ith slot, so we can avoid
1227 /* We know the last slot in the vector is empty
1228 because we know that at this point there's room
1229 for a new function. */
1230 bcopy ((PTR
) &TREE_VEC_ELT (method_vec
, slot
),
1231 (PTR
) &TREE_VEC_ELT (method_vec
, slot
+ 1),
1232 (len
- slot
- 1) * sizeof (tree
));
1233 TREE_VEC_ELT (method_vec
, slot
) = NULL_TREE
;
1238 if (template_class_depth (type
))
1239 /* TYPE is a template class. Don't issue any errors now; wait
1240 until instantiation time to complain. */
1246 /* Check to see if we've already got this method. */
1247 for (fns
= TREE_VEC_ELT (method_vec
, slot
);
1249 fns
= OVL_NEXT (fns
))
1251 tree fn
= OVL_CURRENT (fns
);
1253 if (TREE_CODE (fn
) != TREE_CODE (method
))
1256 if (TREE_CODE (method
) != TEMPLATE_DECL
)
1258 /* [over.load] Member function declarations with the
1259 same name and the same parameter types cannot be
1260 overloaded if any of them is a static member
1261 function declaration. */
1262 if (DECL_STATIC_FUNCTION_P (fn
)
1263 != DECL_STATIC_FUNCTION_P (method
))
1265 tree parms1
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
1266 tree parms2
= TYPE_ARG_TYPES (TREE_TYPE (method
));
1268 if (! DECL_STATIC_FUNCTION_P (fn
))
1269 parms1
= TREE_CHAIN (parms1
);
1271 parms2
= TREE_CHAIN (parms2
);
1273 if (compparms (parms1
, parms2
))
1274 cp_error ("`%#D' and `%#D' cannot be overloaded",
1278 /* Since this is an ordinary function in a
1279 non-template class, it's mangled name can be used
1280 as a unique identifier. This technique is only
1281 an optimization; we would get the same results if
1282 we just used decls_match here. */
1283 if (DECL_ASSEMBLER_NAME (fn
)
1284 != DECL_ASSEMBLER_NAME (method
))
1287 else if (!decls_match (fn
, method
))
1290 /* There has already been a declaration of this method
1291 or member template. */
1292 cp_error_at ("`%D' has already been declared in `%T'",
1295 /* We don't call duplicate_decls here to merge the
1296 declarations because that will confuse things if the
1297 methods have inline definitions. In particular, we
1298 will crash while processing the definitions. */
1303 /* Actually insert the new method. */
1304 TREE_VEC_ELT (method_vec
, slot
)
1305 = build_overload (method
, TREE_VEC_ELT (method_vec
, slot
));
1307 /* Add the new binding. */
1308 if (!DECL_CONSTRUCTOR_P (method
)
1309 && !DECL_DESTRUCTOR_P (method
))
1310 push_class_level_binding (DECL_NAME (method
),
1311 TREE_VEC_ELT (method_vec
, slot
));
1316 /* Subroutines of finish_struct. */
1318 /* Look through the list of fields for this struct, deleting
1319 duplicates as we go. This must be recursive to handle
1322 FIELD is the field which may not appear anywhere in FIELDS.
1323 FIELD_PTR, if non-null, is the starting point at which
1324 chained deletions may take place.
1325 The value returned is the first acceptable entry found
1328 Note that anonymous fields which are not of UNION_TYPE are
1329 not duplicates, they are just anonymous fields. This happens
1330 when we have unnamed bitfields, for example. */
1333 delete_duplicate_fields_1 (field
, fields
)
1338 if (DECL_NAME (field
) == 0)
1340 if (TREE_CODE (TREE_TYPE (field
)) != UNION_TYPE
)
1343 for (x
= TYPE_FIELDS (TREE_TYPE (field
)); x
; x
= TREE_CHAIN (x
))
1344 fields
= delete_duplicate_fields_1 (x
, fields
);
1349 for (x
= fields
; x
; prev
= x
, x
= TREE_CHAIN (x
))
1351 if (DECL_NAME (x
) == 0)
1353 if (TREE_CODE (TREE_TYPE (x
)) != UNION_TYPE
)
1355 TYPE_FIELDS (TREE_TYPE (x
))
1356 = delete_duplicate_fields_1 (field
, TYPE_FIELDS (TREE_TYPE (x
)));
1357 if (TYPE_FIELDS (TREE_TYPE (x
)) == 0)
1360 fields
= TREE_CHAIN (fields
);
1362 TREE_CHAIN (prev
) = TREE_CHAIN (x
);
1367 if (DECL_NAME (field
) == DECL_NAME (x
))
1369 if (TREE_CODE (field
) == CONST_DECL
1370 && TREE_CODE (x
) == CONST_DECL
)
1371 cp_error_at ("duplicate enum value `%D'", x
);
1372 else if (TREE_CODE (field
) == CONST_DECL
1373 || TREE_CODE (x
) == CONST_DECL
)
1374 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1376 else if (DECL_DECLARES_TYPE_P (field
)
1377 && DECL_DECLARES_TYPE_P (x
))
1379 if (same_type_p (TREE_TYPE (field
), TREE_TYPE (x
)))
1381 cp_error_at ("duplicate nested type `%D'", x
);
1383 else if (DECL_DECLARES_TYPE_P (field
)
1384 || DECL_DECLARES_TYPE_P (x
))
1386 /* Hide tag decls. */
1387 if ((TREE_CODE (field
) == TYPE_DECL
1388 && DECL_ARTIFICIAL (field
))
1389 || (TREE_CODE (x
) == TYPE_DECL
1390 && DECL_ARTIFICIAL (x
)))
1392 cp_error_at ("duplicate field `%D' (as type and non-type)",
1396 cp_error_at ("duplicate member `%D'", x
);
1398 fields
= TREE_CHAIN (fields
);
1400 TREE_CHAIN (prev
) = TREE_CHAIN (x
);
1409 delete_duplicate_fields (fields
)
1413 for (x
= fields
; x
&& TREE_CHAIN (x
); x
= TREE_CHAIN (x
))
1414 TREE_CHAIN (x
) = delete_duplicate_fields_1 (x
, TREE_CHAIN (x
));
1417 /* Change the access of FDECL to ACCESS in T. The access to FDECL is
1418 along the path given by BINFO. Return 1 if change was legit,
1419 otherwise return 0. */
1422 alter_access (t
, binfo
, fdecl
, access
)
1428 tree elem
= purpose_member (t
, DECL_ACCESS (fdecl
));
1431 if (TREE_VALUE (elem
) != access
)
1433 if (TREE_CODE (TREE_TYPE (fdecl
)) == FUNCTION_DECL
)
1434 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl
));
1436 error ("conflicting access specifications for field `%s', ignored",
1437 IDENTIFIER_POINTER (DECL_NAME (fdecl
)));
1441 /* They're changing the access to the same thing they changed
1442 it to before. That's OK. */
1448 enforce_access (binfo
, fdecl
);
1449 DECL_ACCESS (fdecl
) = tree_cons (t
, access
, DECL_ACCESS (fdecl
));
1455 /* Process the USING_DECL, which is a member of T. The METHOD_VEC, if
1456 non-NULL, is the methods of T. The FIELDS are the fields of T. */
1459 handle_using_decl (using_decl
, t
, method_vec
, fields
)
1465 tree ctype
= DECL_INITIAL (using_decl
);
1466 tree name
= DECL_NAME (using_decl
);
1468 = TREE_PRIVATE (using_decl
) ? access_private_node
1469 : TREE_PROTECTED (using_decl
) ? access_protected_node
1470 : access_public_node
;
1472 tree flist
= NULL_TREE
;
1477 binfo
= binfo_or_else (ctype
, t
);
1481 if (name
== constructor_name (ctype
)
1482 || name
== constructor_name_full (ctype
))
1484 cp_error_at ("using-declaration for constructor", using_decl
);
1488 fdecl
= lookup_member (binfo
, name
, 0, 0);
1492 cp_error_at ("no members matching `%D' in `%#T'", using_decl
, ctype
);
1496 /* Functions are represented as TREE_LIST, with the purpose
1497 being the type and the value the functions. Other members
1498 come as themselves. */
1499 if (TREE_CODE (fdecl
) == TREE_LIST
)
1500 /* Ignore base type this came from. */
1501 fdecl
= TREE_VALUE (fdecl
);
1503 if (TREE_CODE (fdecl
) == OVERLOAD
)
1505 /* We later iterate over all functions. */
1507 fdecl
= OVL_FUNCTION (flist
);
1510 name
= DECL_NAME (fdecl
);
1511 n_methods
= method_vec
? TREE_VEC_LENGTH (method_vec
) : 0;
1512 for (i
= 2; i
< n_methods
&& TREE_VEC_ELT (method_vec
, i
); i
++)
1513 if (DECL_NAME (OVL_CURRENT (TREE_VEC_ELT (method_vec
, i
)))
1516 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl
, t
);
1517 cp_error_at (" because of local method `%#D' with same name",
1518 OVL_CURRENT (TREE_VEC_ELT (method_vec
, i
)));
1522 if (! DECL_LANG_SPECIFIC (fdecl
))
1523 /* We don't currently handle DECL_ACCESS for TYPE_DECLs; just return. */
1526 for (tmp
= fields
; tmp
; tmp
= TREE_CHAIN (tmp
))
1527 if (DECL_NAME (tmp
) == name
)
1529 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl
, t
);
1530 cp_error_at (" because of local field `%#D' with same name", tmp
);
1534 /* Make type T see field decl FDECL with access ACCESS.*/
1539 if (alter_access (t
, binfo
, OVL_FUNCTION (flist
),
1542 flist
= OVL_CHAIN (flist
);
1546 alter_access (t
, binfo
, fdecl
, access
);
1552 int max_has_virtual
;
1556 char cant_have_default_ctor
;
1557 char cant_have_const_ctor
;
1558 char no_const_asn_ref
;
1561 /* Record information about type T derived from its base classes.
1562 Store most of that information in T itself, and place the
1563 remaining information in the struct BASE_INFO.
1565 Propagate basetype offsets throughout the lattice. Note that the
1566 lattice topped by T is really a pair: it's a DAG that gives the
1567 structure of the derivation hierarchy, and it's a list of the
1568 virtual baseclasses that appear anywhere in the DAG. When a vbase
1569 type appears in the DAG, it's offset is 0, and it's children start
1570 their offsets from that point. When a vbase type appears in the list,
1571 its offset is the offset it has in the hierarchy, and its children's
1572 offsets include that offset in theirs.
1574 Returns the index of the first base class to have virtual functions,
1575 or -1 if no such base class. */
1578 finish_base_struct (t
, b
)
1580 struct base_info
*b
;
1582 tree binfos
= TYPE_BINFO_BASETYPES (t
);
1583 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1584 int first_vfn_base_index
= -1;
1585 bzero ((char *) b
, sizeof (struct base_info
));
1587 for (i
= 0; i
< n_baseclasses
; i
++)
1589 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1590 tree basetype
= BINFO_TYPE (base_binfo
);
1592 /* Effective C++ rule 14. We only need to check TYPE_VIRTUAL_P
1593 here because the case of virtual functions but non-virtual
1594 dtor is handled in finish_struct_1. */
1595 if (warn_ecpp
&& ! TYPE_VIRTUAL_P (basetype
)
1596 && TYPE_HAS_DESTRUCTOR (basetype
))
1597 cp_warning ("base class `%#T' has a non-virtual destructor", basetype
);
1599 /* If the type of basetype is incomplete, then
1600 we already complained about that fact
1601 (and we should have fixed it up as well). */
1602 if (TYPE_SIZE (basetype
) == 0)
1605 /* The base type is of incomplete type. It is
1606 probably best to pretend that it does not
1608 if (i
== n_baseclasses
-1)
1609 TREE_VEC_ELT (binfos
, i
) = NULL_TREE
;
1610 TREE_VEC_LENGTH (binfos
) -= 1;
1612 for (j
= i
; j
+1 < n_baseclasses
; j
++)
1613 TREE_VEC_ELT (binfos
, j
) = TREE_VEC_ELT (binfos
, j
+1);
1616 if (! TYPE_HAS_CONST_INIT_REF (basetype
))
1617 b
->cant_have_const_ctor
= 1;
1619 if (TYPE_HAS_CONSTRUCTOR (basetype
)
1620 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype
))
1622 b
->cant_have_default_ctor
= 1;
1623 if (! TYPE_HAS_CONSTRUCTOR (t
))
1625 cp_pedwarn ("base `%T' with only non-default constructor",
1627 cp_pedwarn ("in class without a constructor");
1631 if (TYPE_HAS_ASSIGN_REF (basetype
)
1632 && !TYPE_HAS_CONST_ASSIGN_REF (basetype
))
1633 b
->no_const_asn_ref
= 1;
1635 TYPE_NEEDS_CONSTRUCTING (t
) |= TYPE_NEEDS_CONSTRUCTING (basetype
);
1636 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_NEEDS_DESTRUCTOR (basetype
);
1637 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype
);
1638 TYPE_HAS_COMPLEX_INIT_REF (t
) |= TYPE_HAS_COMPLEX_INIT_REF (basetype
);
1640 TYPE_OVERLOADS_CALL_EXPR (t
) |= TYPE_OVERLOADS_CALL_EXPR (basetype
);
1641 TYPE_OVERLOADS_ARRAY_REF (t
) |= TYPE_OVERLOADS_ARRAY_REF (basetype
);
1642 TYPE_OVERLOADS_ARROW (t
) |= TYPE_OVERLOADS_ARROW (basetype
);
1644 if (CLASSTYPE_COM_INTERFACE (basetype
))
1646 CLASSTYPE_COM_INTERFACE (t
) = 1;
1649 ("COM interface type `%T' must be the leftmost base class",
1652 else if (CLASSTYPE_COM_INTERFACE (t
))
1654 cp_error ("COM interface type `%T' with non-COM base class `%T'",
1656 CLASSTYPE_COM_INTERFACE (t
) = 0;
1659 if (TYPE_VIRTUAL_P (basetype
))
1661 /* Ensure that this is set from at least a virtual base
1663 if (b
->rtti
== NULL_TREE
)
1664 b
->rtti
= CLASSTYPE_RTTI (basetype
);
1666 /* Don't borrow virtuals from virtual baseclasses. */
1667 if (TREE_VIA_VIRTUAL (base_binfo
))
1670 if (first_vfn_base_index
< 0)
1673 first_vfn_base_index
= i
;
1675 /* Update these two, now that we know what vtable we are
1676 going to extend. This is so that we can add virtual
1677 functions, and override them properly. */
1678 TYPE_BINFO_VTABLE (t
) = TYPE_BINFO_VTABLE (basetype
);
1679 TYPE_BINFO_VIRTUALS (t
) = TYPE_BINFO_VIRTUALS (basetype
);
1680 b
->has_virtual
= CLASSTYPE_VSIZE (basetype
);
1681 b
->vfield
= CLASSTYPE_VFIELD (basetype
);
1682 b
->vfields
= copy_list (CLASSTYPE_VFIELDS (basetype
));
1683 vfields
= b
->vfields
;
1686 if (VF_BINFO_VALUE (vfields
) == NULL_TREE
1687 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
)))
1689 tree value
= VF_BASETYPE_VALUE (vfields
);
1690 if (DECL_NAME (CLASSTYPE_VFIELD (value
))
1691 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1692 VF_NORMAL_VALUE (b
->vfields
) = basetype
;
1694 VF_NORMAL_VALUE (b
->vfields
) = VF_NORMAL_VALUE (vfields
);
1696 vfields
= TREE_CHAIN (vfields
);
1698 CLASSTYPE_VFIELD (t
) = b
->vfield
;
1702 /* Only add unique vfields, and flatten them out as we go. */
1703 tree vfields
= CLASSTYPE_VFIELDS (basetype
);
1706 if (VF_BINFO_VALUE (vfields
) == NULL_TREE
1707 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
)))
1709 tree value
= VF_BASETYPE_VALUE (vfields
);
1710 b
->vfields
= tree_cons (base_binfo
, value
, b
->vfields
);
1711 if (DECL_NAME (CLASSTYPE_VFIELD (value
))
1712 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1713 VF_NORMAL_VALUE (b
->vfields
) = basetype
;
1715 VF_NORMAL_VALUE (b
->vfields
) = VF_NORMAL_VALUE (vfields
);
1717 vfields
= TREE_CHAIN (vfields
);
1720 if (b
->has_virtual
== 0)
1722 first_vfn_base_index
= i
;
1724 /* Update these two, now that we know what vtable we are
1725 going to extend. This is so that we can add virtual
1726 functions, and override them properly. */
1727 TYPE_BINFO_VTABLE (t
) = TYPE_BINFO_VTABLE (basetype
);
1728 TYPE_BINFO_VIRTUALS (t
) = TYPE_BINFO_VIRTUALS (basetype
);
1729 b
->has_virtual
= CLASSTYPE_VSIZE (basetype
);
1730 b
->vfield
= CLASSTYPE_VFIELD (basetype
);
1731 CLASSTYPE_VFIELD (t
) = b
->vfield
;
1732 /* When we install the first one, set the VF_NORMAL_VALUE
1733 to be the current class, as this it is the most derived
1734 class. Hopefully, this is not set to something else
1736 vfields
= b
->vfields
;
1739 if (DECL_NAME (CLASSTYPE_VFIELD (t
))
1740 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1742 VF_NORMAL_VALUE (vfields
) = t
;
1743 /* There should only be one of them! And it should
1744 always be found, if we get into here. (mrs) */
1747 vfields
= TREE_CHAIN (vfields
);
1756 /* Find the base class with the largest number of virtual functions. */
1757 for (vfields
= b
->vfields
; vfields
; vfields
= TREE_CHAIN (vfields
))
1759 if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields
)) > b
->max_has_virtual
)
1760 b
->max_has_virtual
= CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields
));
1761 if (VF_DERIVED_VALUE (vfields
)
1762 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields
)) > b
->max_has_virtual
)
1763 b
->max_has_virtual
= CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields
));
1768 /* If all virtual functions come only from virtual baseclasses. */
1771 /* Update the rtti base if we have a non-virtual base class version
1773 b
->rtti
= CLASSTYPE_RTTI (BINFO_TYPE (TREE_VEC_ELT (binfos
, first_vfn_base_index
)));
1775 return first_vfn_base_index
;
1778 /* Set memoizing fields and bits of T (and its variants) for later use.
1779 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1782 finish_struct_bits (t
, max_has_virtual
)
1784 int max_has_virtual
;
1786 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (t
);
1788 /* Fix up variants (if any). */
1789 tree variants
= TYPE_NEXT_VARIANT (t
);
1792 /* These fields are in the _TYPE part of the node, not in
1793 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1794 TYPE_HAS_CONSTRUCTOR (variants
) = TYPE_HAS_CONSTRUCTOR (t
);
1795 TYPE_HAS_DESTRUCTOR (variants
) = TYPE_HAS_DESTRUCTOR (t
);
1796 TYPE_NEEDS_CONSTRUCTING (variants
) = TYPE_NEEDS_CONSTRUCTING (t
);
1797 TYPE_NEEDS_DESTRUCTOR (variants
) = TYPE_NEEDS_DESTRUCTOR (t
);
1799 TYPE_USES_COMPLEX_INHERITANCE (variants
) = TYPE_USES_COMPLEX_INHERITANCE (t
);
1800 TYPE_VIRTUAL_P (variants
) = TYPE_VIRTUAL_P (t
);
1801 TYPE_USES_VIRTUAL_BASECLASSES (variants
) = TYPE_USES_VIRTUAL_BASECLASSES (t
);
1802 /* Copy whatever these are holding today. */
1803 TYPE_MIN_VALUE (variants
) = TYPE_MIN_VALUE (t
);
1804 TYPE_MAX_VALUE (variants
) = TYPE_MAX_VALUE (t
);
1805 TYPE_FIELDS (variants
) = TYPE_FIELDS (t
);
1806 TYPE_SIZE (variants
) = TYPE_SIZE (t
);
1807 TYPE_SIZE_UNIT (variants
) = TYPE_SIZE_UNIT (t
);
1808 variants
= TYPE_NEXT_VARIANT (variants
);
1811 if (n_baseclasses
&& max_has_virtual
)
1813 /* For a class w/o baseclasses, `finish_struct' has set
1814 CLASS_TYPE_ABSTRACT_VIRTUALS correctly (by definition). Similarly
1815 for a class who's base classes do not have vtables. When neither
1816 of these is true, we might have removed abstract virtuals (by
1817 providing a definition), added some (by declaring new ones), or
1818 redeclared ones from a base class. We need to recalculate what's
1819 really an abstract virtual at this point (by looking in the
1821 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = get_abstract_virtuals (t
);
1826 /* Notice whether this class has type conversion functions defined. */
1827 tree binfo
= TYPE_BINFO (t
);
1828 tree binfos
= BINFO_BASETYPES (binfo
);
1831 for (i
= n_baseclasses
-1; i
>= 0; i
--)
1833 basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
1835 TYPE_HAS_CONVERSION (t
) |= TYPE_HAS_CONVERSION (basetype
);
1839 /* If this type has a copy constructor, force its mode to be BLKmode, and
1840 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1841 be passed by invisible reference and prevent it from being returned in
1844 Also do this if the class has BLKmode but can still be returned in
1845 registers, since function_cannot_inline_p won't let us inline
1846 functions returning such a type. This affects the HP-PA. */
1847 if (! TYPE_HAS_TRIVIAL_INIT_REF (t
)
1848 || (TYPE_MODE (t
) == BLKmode
&& ! aggregate_value_p (t
)
1849 && CLASSTYPE_NON_AGGREGATE (t
)))
1852 DECL_MODE (TYPE_MAIN_DECL (t
)) = BLKmode
;
1853 for (variants
= t
; variants
; variants
= TYPE_NEXT_VARIANT (variants
))
1855 TYPE_MODE (variants
) = BLKmode
;
1856 TREE_ADDRESSABLE (variants
) = 1;
1861 /* Issue warnings about T having private constructors, but no friends,
1864 HAS_NONPRIVATE_METHOD is nonzero if T has any non-private methods or
1865 static members. HAS_NONPRIVATE_STATIC_FN is nonzero if T has any
1866 non-private static member functions. */
1869 maybe_warn_about_overly_private_class (t
)
1872 int has_member_fn
= 0;
1873 int has_nonprivate_method
= 0;
1876 if (!warn_ctor_dtor_privacy
1877 /* If the class has friends, those entities might create and
1878 access instances, so we should not warn. */
1879 || (CLASSTYPE_FRIEND_CLASSES (t
)
1880 || DECL_FRIENDLIST (TYPE_MAIN_DECL (t
)))
1881 /* We will have warned when the template was declared; there's
1882 no need to warn on every instantiation. */
1883 || CLASSTYPE_TEMPLATE_INSTANTIATION (t
))
1884 /* There's no reason to even consider warning about this
1888 /* We only issue one warning, if more than one applies, because
1889 otherwise, on code like:
1892 // Oops - forgot `public:'
1898 we warn several times about essentially the same problem. */
1900 /* Check to see if all (non-constructor, non-destructor) member
1901 functions are private. (Since there are no friends or
1902 non-private statics, we can't ever call any of the private member
1904 for (fn
= TYPE_METHODS (t
); fn
; fn
= TREE_CHAIN (fn
))
1905 /* We're not interested in compiler-generated methods; they don't
1906 provide any way to call private members. */
1907 if (!DECL_ARTIFICIAL (fn
))
1909 if (!TREE_PRIVATE (fn
))
1911 if (DECL_STATIC_FUNCTION_P (fn
))
1912 /* A non-private static member function is just like a
1913 friend; it can create and invoke private member
1914 functions, and be accessed without a class
1918 has_nonprivate_method
= 1;
1921 else if (!DECL_CONSTRUCTOR_P (fn
) && !DECL_DESTRUCTOR_P (fn
))
1925 if (!has_nonprivate_method
&& has_member_fn
)
1927 /* There are no non-private methods, and there's at least one
1928 private member function that isn't a constructor or
1929 destructor. (If all the private members are
1930 constructors/destructors we want to use the code below that
1931 issues error messages specifically referring to
1932 constructors/destructors.) */
1934 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
1935 for (i
= 0; i
< CLASSTYPE_N_BASECLASSES (t
); i
++)
1936 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos
, i
))
1937 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos
, i
)))
1939 has_nonprivate_method
= 1;
1942 if (!has_nonprivate_method
)
1944 cp_warning ("all member functions in class `%T' are private", t
);
1949 /* Even if some of the member functions are non-private, the class
1950 won't be useful for much if all the constructors or destructors
1951 are private: such an object can never be created or destroyed. */
1952 if (TYPE_HAS_DESTRUCTOR (t
))
1954 tree dtor
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t
), 1);
1956 if (TREE_PRIVATE (dtor
))
1958 cp_warning ("`%#T' only defines a private destructor and has no friends",
1964 if (TYPE_HAS_CONSTRUCTOR (t
))
1966 int nonprivate_ctor
= 0;
1968 /* If a non-template class does not define a copy
1969 constructor, one is defined for it, enabling it to avoid
1970 this warning. For a template class, this does not
1971 happen, and so we would normally get a warning on:
1973 template <class T> class C { private: C(); };
1975 To avoid this asymmetry, we check TYPE_HAS_INIT_REF. All
1976 complete non-template or fully instantiated classes have this
1978 if (!TYPE_HAS_INIT_REF (t
))
1979 nonprivate_ctor
= 1;
1981 for (fn
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t
), 0);
1985 tree ctor
= OVL_CURRENT (fn
);
1986 /* Ideally, we wouldn't count copy constructors (or, in
1987 fact, any constructor that takes an argument of the
1988 class type as a parameter) because such things cannot
1989 be used to construct an instance of the class unless
1990 you already have one. But, for now at least, we're
1992 if (! TREE_PRIVATE (ctor
))
1994 nonprivate_ctor
= 1;
1999 if (nonprivate_ctor
== 0)
2001 cp_warning ("`%#T' only defines private constructors and has no friends",
2009 /* Warn about duplicate methods in fn_fields. Also compact method
2010 lists so that lookup can be made faster.
2012 Data Structure: List of method lists. The outer list is a
2013 TREE_LIST, whose TREE_PURPOSE field is the field name and the
2014 TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN
2015 links the entire list of methods for TYPE_METHODS. Friends are
2016 chained in the same way as member functions (? TREE_CHAIN or
2017 DECL_CHAIN), but they live in the TREE_TYPE field of the outer
2018 list. That allows them to be quickly deleted, and requires no
2021 If there are any constructors/destructors, they are moved to the
2022 front of the list. This makes pushclass more efficient.
2024 We also link each field which has shares a name with its baseclass
2025 to the head of the list of fields for that base class. This allows
2026 us to reduce search time in places like `build_method_call' to
2027 consider only reasonably likely functions. */
2030 finish_struct_methods (t
)
2034 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
2035 tree ctor_name
= constructor_name (t
);
2037 /* First fill in entry 0 with the constructors, entry 1 with destructors,
2038 and the next few with type conversion operators (if any). */
2039 for (fn_fields
= TYPE_METHODS (t
); fn_fields
;
2040 fn_fields
= TREE_CHAIN (fn_fields
))
2042 tree fn_name
= DECL_NAME (fn_fields
);
2044 /* Clear out this flag.
2046 @@ Doug may figure out how to break
2047 @@ this with nested classes and friends. */
2048 DECL_IN_AGGR_P (fn_fields
) = 0;
2050 /* Note here that a copy ctor is private, so we don't dare generate
2051 a default copy constructor for a class that has a member
2052 of this type without making sure they have access to it. */
2053 if (fn_name
== ctor_name
)
2055 tree parmtypes
= FUNCTION_ARG_CHAIN (fn_fields
);
2056 tree parmtype
= parmtypes
? TREE_VALUE (parmtypes
) : void_type_node
;
2058 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
2059 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
)) == t
)
2061 if (TREE_CHAIN (parmtypes
) == NULL_TREE
2062 || TREE_CHAIN (parmtypes
) == void_list_node
2063 || TREE_PURPOSE (TREE_CHAIN (parmtypes
)))
2065 if (TREE_PROTECTED (fn_fields
))
2066 TYPE_HAS_NONPUBLIC_CTOR (t
) = 1;
2067 else if (TREE_PRIVATE (fn_fields
))
2068 TYPE_HAS_NONPUBLIC_CTOR (t
) = 2;
2072 else if (fn_name
== ansi_opname
[(int) MODIFY_EXPR
])
2074 tree parmtype
= TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields
));
2076 if (copy_assignment_arg_p (parmtype
, DECL_VIRTUAL_P (fn_fields
)))
2078 if (TREE_PROTECTED (fn_fields
))
2079 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t
) = 1;
2080 else if (TREE_PRIVATE (fn_fields
))
2081 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t
) = 2;
2086 if (TYPE_HAS_DESTRUCTOR (t
) && !TREE_VEC_ELT (method_vec
, 1))
2087 /* We thought there was a destructor, but there wasn't. Some
2088 parse errors cause this anomalous situation. */
2089 TYPE_HAS_DESTRUCTOR (t
) = 0;
2091 /* Issue warnings about private constructors and such. If there are
2092 no methods, then some public defaults are generated. */
2093 maybe_warn_about_overly_private_class (t
);
2096 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2099 duplicate_tag_error (t
)
2102 cp_error ("redefinition of `%#T'", t
);
2103 cp_error_at ("previous definition here", t
);
2105 /* Pretend we haven't defined this type. */
2107 /* All of the component_decl's were TREE_CHAINed together in the parser.
2108 finish_struct_methods walks these chains and assembles all methods with
2109 the same base name into DECL_CHAINs. Now we don't need the parser chains
2110 anymore, so we unravel them. */
2112 /* This used to be in finish_struct, but it turns out that the
2113 TREE_CHAIN is used by dbxout_type_methods and perhaps some other
2115 if (CLASSTYPE_METHOD_VEC (t
))
2117 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
2118 int i
, len
= TREE_VEC_LENGTH (method_vec
);
2119 for (i
= 0; i
< len
; i
++)
2121 tree unchain
= TREE_VEC_ELT (method_vec
, i
);
2122 while (unchain
!= NULL_TREE
)
2124 TREE_CHAIN (OVL_CURRENT (unchain
)) = NULL_TREE
;
2125 unchain
= OVL_NEXT (unchain
);
2130 if (TYPE_LANG_SPECIFIC (t
))
2132 tree binfo
= TYPE_BINFO (t
);
2133 int interface_only
= CLASSTYPE_INTERFACE_ONLY (t
);
2134 int interface_unknown
= CLASSTYPE_INTERFACE_UNKNOWN (t
);
2136 bzero ((char *) TYPE_LANG_SPECIFIC (t
), sizeof (struct lang_type
));
2137 BINFO_BASETYPES(binfo
) = NULL_TREE
;
2139 TYPE_BINFO (t
) = binfo
;
2140 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
2141 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t
, interface_unknown
);
2142 TYPE_REDEFINED (t
) = 1;
2144 TYPE_SIZE (t
) = NULL_TREE
;
2145 TYPE_MODE (t
) = VOIDmode
;
2146 TYPE_FIELDS (t
) = NULL_TREE
;
2147 TYPE_METHODS (t
) = NULL_TREE
;
2148 TYPE_VFIELD (t
) = NULL_TREE
;
2149 TYPE_CONTEXT (t
) = NULL_TREE
;
2152 /* finish up all new vtables. */
2155 finish_vtbls (binfo
, do_self
, t
)
2160 tree binfos
= BINFO_BASETYPES (binfo
);
2161 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2163 /* Should we use something besides CLASSTYPE_VFIELDS? */
2164 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2166 if (BINFO_NEW_VTABLE_MARKED (binfo
))
2170 decl
= BINFO_VTABLE (binfo
);
2171 context
= DECL_CONTEXT (decl
);
2172 DECL_CONTEXT (decl
) = 0;
2173 if (DECL_INITIAL (decl
) != BINFO_VIRTUALS (binfo
))
2174 DECL_INITIAL (decl
) = build_nt (CONSTRUCTOR
, NULL_TREE
,
2175 BINFO_VIRTUALS (binfo
));
2176 cp_finish_decl (decl
, DECL_INITIAL (decl
), NULL_TREE
, 0, 0);
2177 DECL_CONTEXT (decl
) = context
;
2179 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2182 for (i
= 0; i
< n_baselinks
; i
++)
2184 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2185 int is_not_base_vtable
2186 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2187 if (TREE_VIA_VIRTUAL (base_binfo
))
2189 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
), CLASSTYPE_VBASECLASSES (t
));
2191 finish_vtbls (base_binfo
, is_not_base_vtable
, t
);
2195 /* True if we should override the given BASE_FNDECL with the given
2199 overrides (fndecl
, base_fndecl
)
2200 tree fndecl
, base_fndecl
;
2202 /* Destructors have special names. */
2203 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl
))
2204 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2206 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl
))
2207 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2209 if (DECL_NAME (fndecl
) == DECL_NAME (base_fndecl
))
2211 tree types
, base_types
;
2213 retypes
= TREE_TYPE (TREE_TYPE (fndecl
));
2214 base_retypes
= TREE_TYPE (TREE_TYPE (base_fndecl
));
2216 types
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2217 base_types
= TYPE_ARG_TYPES (TREE_TYPE (base_fndecl
));
2218 if ((TYPE_QUALS (TREE_TYPE (TREE_VALUE (base_types
)))
2219 == TYPE_QUALS (TREE_TYPE (TREE_VALUE (types
))))
2220 && compparms (TREE_CHAIN (base_types
), TREE_CHAIN (types
)))
2227 get_class_offset_1 (parent
, binfo
, context
, t
, fndecl
)
2228 tree parent
, binfo
, context
, t
, fndecl
;
2230 tree binfos
= BINFO_BASETYPES (binfo
);
2231 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2232 tree rval
= NULL_TREE
;
2234 if (binfo
== parent
)
2235 return error_mark_node
;
2237 for (i
= 0; i
< n_baselinks
; i
++)
2239 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2242 if (TREE_VIA_VIRTUAL (base_binfo
))
2243 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
),
2244 CLASSTYPE_VBASECLASSES (t
));
2245 nrval
= get_class_offset_1 (parent
, base_binfo
, context
, t
, fndecl
);
2246 /* See if we have a new value */
2247 if (nrval
&& (nrval
!= error_mark_node
|| rval
==0))
2249 /* Only compare if we have two offsets */
2250 if (rval
&& rval
!= error_mark_node
2251 && ! tree_int_cst_equal (nrval
, rval
))
2253 /* Only give error if the two offsets are different */
2254 error ("every virtual function must have a unique final overrider");
2255 cp_error (" found two (or more) `%T' class subobjects in `%T'", context
, t
);
2256 cp_error (" with virtual `%D' from virtual base class", fndecl
);
2262 if (rval
&& BINFO_TYPE (binfo
) == context
)
2264 my_friendly_assert (rval
== error_mark_node
2265 || tree_int_cst_equal (rval
, BINFO_OFFSET (binfo
)), 999);
2266 rval
= BINFO_OFFSET (binfo
);
2272 /* Get the offset to the CONTEXT subobject that is related to the
2276 get_class_offset (context
, t
, binfo
, fndecl
)
2277 tree context
, t
, binfo
, fndecl
;
2279 tree first_binfo
= binfo
;
2284 return integer_zero_node
;
2286 if (BINFO_TYPE (binfo
) == context
)
2287 return BINFO_OFFSET (binfo
);
2289 /* Check less derived binfos first. */
2290 while (BINFO_BASETYPES (binfo
)
2291 && (i
=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
))) != -1)
2293 tree binfos
= BINFO_BASETYPES (binfo
);
2294 binfo
= TREE_VEC_ELT (binfos
, i
);
2295 if (BINFO_TYPE (binfo
) == context
)
2296 return BINFO_OFFSET (binfo
);
2299 /* Ok, not found in the less derived binfos, now check the more
2301 offset
= get_class_offset_1 (first_binfo
, TYPE_BINFO (t
), context
, t
, fndecl
);
2302 if (offset
==0 || TREE_CODE (offset
) != INTEGER_CST
)
2303 my_friendly_abort (999); /* we have to find it. */
2307 /* Skip RTTI information at the front of the virtual list. */
2309 unsigned HOST_WIDE_INT
2310 skip_rtti_stuff (virtuals
, t
)
2315 if (CLASSTYPE_COM_INTERFACE (t
))
2321 /* We always reserve a slot for the offset/tdesc entry. */
2323 *virtuals
= TREE_CHAIN (*virtuals
);
2325 if (flag_vtable_thunks
&& *virtuals
)
2327 /* The second slot is reserved for the tdesc pointer when thunks
2330 *virtuals
= TREE_CHAIN (*virtuals
);
2336 modify_one_vtable (binfo
, t
, fndecl
, pfn
)
2337 tree binfo
, t
, fndecl
, pfn
;
2339 tree virtuals
= BINFO_VIRTUALS (binfo
);
2340 unsigned HOST_WIDE_INT n
;
2342 /* update rtti entry */
2345 if (binfo
== TYPE_BINFO (t
))
2347 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2348 build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t
))), t
);
2352 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2353 prepare_fresh_vtable (binfo
, t
);
2356 if (fndecl
== NULL_TREE
)
2359 n
= skip_rtti_stuff (&virtuals
, t
);
2363 tree current_fndecl
= TREE_VALUE (virtuals
);
2364 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2365 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2366 if (current_fndecl
&& overrides (fndecl
, current_fndecl
))
2368 tree base_offset
, offset
;
2369 tree context
= DECL_CLASS_CONTEXT (fndecl
);
2370 tree vfield
= CLASSTYPE_VFIELD (t
);
2373 offset
= get_class_offset (context
, t
, binfo
, fndecl
);
2375 /* Find the right offset for the this pointer based on the
2376 base class we just found. We have to take into
2377 consideration the virtual base class pointers that we
2378 stick in before the virtual function table pointer.
2380 Also, we want just the delta between the most base class
2381 that we derived this vfield from and us. */
2382 base_offset
= size_binop (PLUS_EXPR
,
2383 get_derived_offset (binfo
, DECL_CONTEXT (current_fndecl
)),
2384 BINFO_OFFSET (binfo
));
2385 this_offset
= ssize_binop (MINUS_EXPR
, offset
, base_offset
);
2387 if (binfo
== TYPE_BINFO (t
))
2389 /* In this case, it is *type*'s vtable we are modifying.
2390 We start with the approximation that it's vtable is that
2391 of the immediate base class. */
2392 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2393 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield
)), t
);
2397 /* This is our very own copy of `basetype' to play with.
2398 Later, we will fill in all the virtual functions
2399 that override the virtual functions in these base classes
2400 which are not defined by the current type. */
2401 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2402 prepare_fresh_vtable (binfo
, t
);
2406 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo
)));
2408 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo
), n
),
2409 build_vtable_entry (this_offset
, pfn
),
2413 virtuals
= TREE_CHAIN (virtuals
);
2417 /* These are the ones that are not through virtual base classes. */
2420 modify_all_direct_vtables (binfo
, do_self
, t
, fndecl
, pfn
)
2423 tree t
, fndecl
, pfn
;
2425 tree binfos
= BINFO_BASETYPES (binfo
);
2426 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2428 /* Should we use something besides CLASSTYPE_VFIELDS? */
2429 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2431 modify_one_vtable (binfo
, t
, fndecl
, pfn
);
2434 for (i
= 0; i
< n_baselinks
; i
++)
2436 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2437 int is_not_base_vtable
2438 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2439 if (! TREE_VIA_VIRTUAL (base_binfo
))
2440 modify_all_direct_vtables (base_binfo
, is_not_base_vtable
, t
, fndecl
, pfn
);
2444 /* Fixup all the delta entries in this one vtable that need updating. */
2447 fixup_vtable_deltas1 (binfo
, t
)
2450 tree virtuals
= BINFO_VIRTUALS (binfo
);
2451 unsigned HOST_WIDE_INT n
;
2453 n
= skip_rtti_stuff (&virtuals
, t
);
2457 tree fndecl
= TREE_VALUE (virtuals
);
2458 tree pfn
= FNADDR_FROM_VTABLE_ENTRY (fndecl
);
2459 tree delta
= DELTA_FROM_VTABLE_ENTRY (fndecl
);
2460 fndecl
= TREE_OPERAND (pfn
, 0);
2463 tree base_offset
, offset
;
2464 tree context
= DECL_CLASS_CONTEXT (fndecl
);
2465 tree vfield
= CLASSTYPE_VFIELD (t
);
2468 offset
= get_class_offset (context
, t
, binfo
, fndecl
);
2470 /* Find the right offset for the this pointer based on the
2471 base class we just found. We have to take into
2472 consideration the virtual base class pointers that we
2473 stick in before the virtual function table pointer.
2475 Also, we want just the delta between the most base class
2476 that we derived this vfield from and us. */
2477 base_offset
= size_binop (PLUS_EXPR
,
2478 get_derived_offset (binfo
,
2479 DECL_CONTEXT (fndecl
)),
2480 BINFO_OFFSET (binfo
));
2481 this_offset
= ssize_binop (MINUS_EXPR
, offset
, base_offset
);
2483 if (! tree_int_cst_equal (this_offset
, delta
))
2485 /* Make sure we can modify the derived association with immunity. */
2486 if (binfo
== TYPE_BINFO (t
))
2488 /* In this case, it is *type*'s vtable we are modifying.
2489 We start with the approximation that it's vtable is that
2490 of the immediate base class. */
2491 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2492 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield
)), t
);
2496 /* This is our very own copy of `basetype' to play with.
2497 Later, we will fill in all the virtual functions
2498 that override the virtual functions in these base classes
2499 which are not defined by the current type. */
2500 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2501 prepare_fresh_vtable (binfo
, t
);
2504 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo
), n
),
2505 build_vtable_entry (this_offset
, pfn
),
2510 virtuals
= TREE_CHAIN (virtuals
);
2514 /* Fixup all the delta entries in all the direct vtables that need updating.
2515 This happens when we have non-overridden virtual functions from a
2516 virtual base class, that are at a different offset, in the new
2517 hierarchy, because the layout of the virtual bases has changed. */
2520 fixup_vtable_deltas (binfo
, init_self
, t
)
2525 tree binfos
= BINFO_BASETYPES (binfo
);
2526 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2528 for (i
= 0; i
< n_baselinks
; i
++)
2530 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2531 int is_not_base_vtable
2532 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2533 if (! TREE_VIA_VIRTUAL (base_binfo
))
2534 fixup_vtable_deltas (base_binfo
, is_not_base_vtable
, t
);
2536 /* Should we use something besides CLASSTYPE_VFIELDS? */
2537 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2539 fixup_vtable_deltas1 (binfo
, t
);
2543 /* These are the ones that are through virtual base classes. */
2546 modify_all_indirect_vtables (binfo
, do_self
, via_virtual
, t
, fndecl
, pfn
)
2548 int do_self
, via_virtual
;
2549 tree t
, fndecl
, pfn
;
2551 tree binfos
= BINFO_BASETYPES (binfo
);
2552 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2554 /* Should we use something besides CLASSTYPE_VFIELDS? */
2555 if (do_self
&& via_virtual
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2557 modify_one_vtable (binfo
, t
, fndecl
, pfn
);
2560 for (i
= 0; i
< n_baselinks
; i
++)
2562 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2563 int is_not_base_vtable
2564 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2565 if (TREE_VIA_VIRTUAL (base_binfo
))
2568 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
), CLASSTYPE_VBASECLASSES (t
));
2570 modify_all_indirect_vtables (base_binfo
, is_not_base_vtable
, via_virtual
, t
, fndecl
, pfn
);
2575 modify_all_vtables (t
, fndecl
, vfn
)
2576 tree t
, fndecl
, vfn
;
2578 /* Do these first, so that we will make use of any non-virtual class's
2579 vtable, over a virtual classes vtable. */
2580 modify_all_direct_vtables (TYPE_BINFO (t
), 1, t
, fndecl
, vfn
);
2581 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
2582 modify_all_indirect_vtables (TYPE_BINFO (t
), 1, 0, t
, fndecl
, vfn
);
2585 /* Here, we already know that they match in every respect.
2586 All we have to check is where they had their declarations. */
2589 strictly_overrides (fndecl1
, fndecl2
)
2590 tree fndecl1
, fndecl2
;
2592 int distance
= get_base_distance (DECL_CLASS_CONTEXT (fndecl2
),
2593 DECL_CLASS_CONTEXT (fndecl1
),
2595 if (distance
== -2 || distance
> 0)
2600 /* Merge overrides for one vtable.
2601 If we want to merge in same function, we are fine.
2603 if one has a DECL_CLASS_CONTEXT that is a parent of the
2604 other, than choose the more derived one
2606 potentially ill-formed (see 10.3 [class.virtual])
2607 we have to check later to see if there was an
2608 override in this class. If there was ok, if not
2609 then it is ill-formed. (mrs)
2611 We take special care to reuse a vtable, if we can. */
2614 override_one_vtable (binfo
, old
, t
)
2617 tree virtuals
= BINFO_VIRTUALS (binfo
);
2618 tree old_virtuals
= BINFO_VIRTUALS (old
);
2619 enum { REUSE_NEW
, REUSE_OLD
, UNDECIDED
, NEITHER
} choose
= UNDECIDED
;
2621 /* If we have already committed to modifying it, then don't try and
2622 reuse another vtable. */
2623 if (BINFO_NEW_VTABLE_MARKED (binfo
))
2626 skip_rtti_stuff (&virtuals
, t
);
2627 skip_rtti_stuff (&old_virtuals
, t
);
2631 tree fndecl
= TREE_VALUE (virtuals
);
2632 tree old_fndecl
= TREE_VALUE (old_virtuals
);
2633 fndecl
= FNADDR_FROM_VTABLE_ENTRY (fndecl
);
2634 old_fndecl
= FNADDR_FROM_VTABLE_ENTRY (old_fndecl
);
2635 fndecl
= TREE_OPERAND (fndecl
, 0);
2636 old_fndecl
= TREE_OPERAND (old_fndecl
, 0);
2637 /* First check to see if they are the same. */
2638 if (DECL_ASSEMBLER_NAME (fndecl
) == DECL_ASSEMBLER_NAME (old_fndecl
))
2640 /* No need to do anything. */
2642 else if (strictly_overrides (fndecl
, old_fndecl
))
2644 if (choose
== UNDECIDED
)
2646 else if (choose
== REUSE_OLD
)
2649 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2651 prepare_fresh_vtable (binfo
, t
);
2652 override_one_vtable (binfo
, old
, t
);
2657 else if (strictly_overrides (old_fndecl
, fndecl
))
2659 if (choose
== UNDECIDED
)
2661 else if (choose
== REUSE_NEW
)
2664 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2666 prepare_fresh_vtable (binfo
, t
);
2667 override_one_vtable (binfo
, old
, t
);
2670 TREE_VALUE (virtuals
) = TREE_VALUE (old_virtuals
);
2672 else if (choose
== NEITHER
)
2674 TREE_VALUE (virtuals
) = TREE_VALUE (old_virtuals
);
2680 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2682 prepare_fresh_vtable (binfo
, t
);
2683 override_one_vtable (binfo
, old
, t
);
2687 /* This MUST be overridden, or the class is ill-formed. */
2688 tree fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
2691 fndecl
= copy_node (fndecl
);
2692 copy_lang_decl (fndecl
);
2693 DECL_NEEDS_FINAL_OVERRIDER_P (fndecl
) = 1;
2694 /* Make sure we search for it later. */
2695 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t
))
2696 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = error_mark_node
;
2698 vfn
= build1 (ADDR_EXPR
, vfunc_ptr_type_node
, fndecl
);
2699 TREE_CONSTANT (vfn
) = 1;
2701 /* We can use integer_zero_node, as we will core dump
2702 if this is used anyway. */
2703 TREE_VALUE (virtuals
) = build_vtable_entry (integer_zero_node
, vfn
);
2706 virtuals
= TREE_CHAIN (virtuals
);
2707 old_virtuals
= TREE_CHAIN (old_virtuals
);
2710 /* Let's reuse the old vtable. */
2711 if (choose
== REUSE_OLD
)
2713 BINFO_VTABLE (binfo
) = BINFO_VTABLE (old
);
2714 BINFO_VIRTUALS (binfo
) = BINFO_VIRTUALS (old
);
2718 /* Merge in overrides for virtual bases.
2719 BINFO is the hierarchy we want to modify, and OLD has the potential
2723 merge_overrides (binfo
, old
, do_self
, t
)
2728 tree binfos
= BINFO_BASETYPES (binfo
);
2729 tree old_binfos
= BINFO_BASETYPES (old
);
2730 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2732 /* Should we use something besides CLASSTYPE_VFIELDS? */
2733 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2735 override_one_vtable (binfo
, old
, t
);
2738 for (i
= 0; i
< n_baselinks
; i
++)
2740 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2741 tree old_base_binfo
= TREE_VEC_ELT (old_binfos
, i
);
2742 int is_not_base_vtable
2743 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2744 if (! TREE_VIA_VIRTUAL (base_binfo
))
2745 merge_overrides (base_binfo
, old_base_binfo
, is_not_base_vtable
, t
);
2749 /* Get the base virtual function declarations in T that are either
2750 overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
2751 the overrider/hider. */
2754 get_basefndecls (fndecl
, t
)
2757 tree methods
= TYPE_METHODS (t
);
2758 tree base_fndecls
= NULL_TREE
;
2759 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
2760 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2764 if (TREE_CODE (methods
) == FUNCTION_DECL
2765 && DECL_VINDEX (methods
) != NULL_TREE
2766 && DECL_NAME (fndecl
) == DECL_NAME (methods
))
2767 base_fndecls
= temp_tree_cons (fndecl
, methods
, base_fndecls
);
2769 methods
= TREE_CHAIN (methods
);
2773 return base_fndecls
;
2775 for (i
= 0; i
< n_baseclasses
; i
++)
2777 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2778 tree basetype
= BINFO_TYPE (base_binfo
);
2780 base_fndecls
= chainon (get_basefndecls (fndecl
, basetype
),
2784 return base_fndecls
;
2787 /* Mark the functions that have been hidden with their overriders.
2788 Since we start out with all functions already marked with a hider,
2789 no need to mark functions that are just hidden. */
2792 mark_overriders (fndecl
, base_fndecls
)
2793 tree fndecl
, base_fndecls
;
2795 while (base_fndecls
)
2797 if (overrides (TREE_VALUE (base_fndecls
), fndecl
))
2798 TREE_PURPOSE (base_fndecls
) = fndecl
;
2800 base_fndecls
= TREE_CHAIN (base_fndecls
);
2804 /* If this declaration supersedes the declaration of
2805 a method declared virtual in the base class, then
2806 mark this field as being virtual as well. */
2809 check_for_override (decl
, ctype
)
2812 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (ctype
));
2813 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2814 int virtualp
= DECL_VIRTUAL_P (decl
);
2815 int found_overriden_fn
= 0;
2817 for (i
= 0; i
< n_baselinks
; i
++)
2819 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2820 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo
)))
2822 tree tmp
= get_matching_virtual
2824 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)));
2826 if (tmp
&& !found_overriden_fn
)
2828 /* If this function overrides some virtual in some base
2829 class, then the function itself is also necessarily
2830 virtual, even if the user didn't explicitly say so. */
2831 DECL_VIRTUAL_P (decl
) = 1;
2833 /* The TMP we really want is the one from the deepest
2834 baseclass on this path, taking care not to
2835 duplicate if we have already found it (via another
2836 path to its virtual baseclass. */
2837 if (TREE_CODE (TREE_TYPE (decl
)) == FUNCTION_TYPE
)
2839 cp_error_at ("method `%D' may not be declared static",
2841 cp_error_at ("(since `%D' declared virtual in base class.)",
2848 = tree_cons (NULL_TREE
, tmp
, DECL_VINDEX (decl
));
2850 /* We now know that DECL overrides something,
2851 which is all that is important. But, we must
2852 continue to iterate through all the base-classes
2853 in order to allow get_matching_virtual to check for
2854 various illegal overrides. */
2855 found_overriden_fn
= 1;
2861 if (DECL_VINDEX (decl
) == NULL_TREE
)
2862 DECL_VINDEX (decl
) = error_mark_node
;
2863 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl
)) = 1;
2867 /* Warn about hidden virtual functions that are not overridden in t.
2868 We know that constructors and destructors don't apply. */
2874 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
2875 int n_methods
= method_vec
? TREE_VEC_LENGTH (method_vec
) : 0;
2878 /* We go through each separately named virtual function. */
2879 for (i
= 2; i
< n_methods
&& TREE_VEC_ELT (method_vec
, i
); ++i
)
2881 tree fns
= TREE_VEC_ELT (method_vec
, i
);
2884 tree base_fndecls
= NULL_TREE
;
2885 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
2886 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2888 fndecl
= OVL_CURRENT (fns
);
2889 if (DECL_VINDEX (fndecl
) == NULL_TREE
)
2892 /* First we get a list of all possible functions that might be
2893 hidden from each base class. */
2894 for (i
= 0; i
< n_baseclasses
; i
++)
2896 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2897 tree basetype
= BINFO_TYPE (base_binfo
);
2899 base_fndecls
= chainon (get_basefndecls (fndecl
, basetype
),
2903 fns
= OVL_NEXT (fns
);
2905 fndecl
= OVL_CURRENT (fns
);
2909 /* ...then mark up all the base functions with overriders, preferring
2910 overriders to hiders. */
2914 mark_overriders (fndecl
, base_fndecls
);
2916 fns
= OVL_NEXT (fns
);
2918 fndecl
= OVL_CURRENT (fns
);
2923 /* Now give a warning for all base functions without overriders,
2924 as they are hidden. */
2925 while (base_fndecls
)
2927 if (! overrides (TREE_VALUE (base_fndecls
),
2928 TREE_PURPOSE (base_fndecls
)))
2930 /* Here we know it is a hider, and no overrider exists. */
2931 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls
));
2932 cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls
));
2935 base_fndecls
= TREE_CHAIN (base_fndecls
);
2940 /* Check for things that are invalid. There are probably plenty of other
2941 things we should check for also. */
2944 finish_struct_anon (t
)
2948 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
2950 if (TREE_STATIC (field
))
2952 if (TREE_CODE (field
) != FIELD_DECL
)
2955 if (DECL_NAME (field
) == NULL_TREE
2956 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
2958 tree
* uelt
= &TYPE_FIELDS (TREE_TYPE (field
));
2959 for (; *uelt
; uelt
= &TREE_CHAIN (*uelt
))
2961 if (DECL_ARTIFICIAL (*uelt
))
2964 if (DECL_NAME (*uelt
) == constructor_name (t
))
2965 cp_pedwarn_at ("ANSI C++ forbids member `%D' with same name as enclosing class",
2968 if (TREE_CODE (*uelt
) != FIELD_DECL
)
2970 cp_pedwarn_at ("`%#D' invalid; an anonymous union can only have non-static data members",
2975 if (TREE_PRIVATE (*uelt
))
2976 cp_pedwarn_at ("private member `%#D' in anonymous union",
2978 else if (TREE_PROTECTED (*uelt
))
2979 cp_pedwarn_at ("protected member `%#D' in anonymous union",
2982 TREE_PRIVATE (*uelt
) = TREE_PRIVATE (field
);
2983 TREE_PROTECTED (*uelt
) = TREE_PROTECTED (field
);
2989 extern int interface_only
, interface_unknown
;
2991 /* Create default constructors, assignment operators, and so forth for
2992 the type indicated by T, if they are needed.
2993 CANT_HAVE_DEFAULT_CTOR, CANT_HAVE_CONST_CTOR, and
2994 CANT_HAVE_ASSIGNMENT are nonzero if, for whatever reason, the class
2995 cannot have a default constructor, copy constructor taking a const
2996 reference argument, or an assignment operator, respectively. If a
2997 virtual destructor is created, its DECL is returned; otherwise the
2998 return value is NULL_TREE. */
3001 add_implicitly_declared_members (t
, cant_have_default_ctor
,
3002 cant_have_const_cctor
,
3003 cant_have_assignment
)
3005 int cant_have_default_ctor
;
3006 int cant_have_const_cctor
;
3007 int cant_have_assignment
;
3010 tree implicit_fns
= NULL_TREE
;
3011 tree name
= TYPE_IDENTIFIER (t
);
3012 tree virtual_dtor
= NULL_TREE
;
3016 if (TYPE_NEEDS_DESTRUCTOR (t
) && !TYPE_HAS_DESTRUCTOR (t
)
3017 && !IS_SIGNATURE (t
))
3019 default_fn
= cons_up_default_function (t
, name
, 0);
3020 check_for_override (default_fn
, t
);
3022 /* If we couldn't make it work, then pretend we didn't need it. */
3023 if (default_fn
== void_type_node
)
3024 TYPE_NEEDS_DESTRUCTOR (t
) = 0;
3027 TREE_CHAIN (default_fn
) = implicit_fns
;
3028 implicit_fns
= default_fn
;
3030 if (DECL_VINDEX (default_fn
))
3031 virtual_dtor
= default_fn
;
3034 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_HAS_DESTRUCTOR (t
);
3036 /* Default constructor. */
3037 if (! TYPE_HAS_CONSTRUCTOR (t
) && ! cant_have_default_ctor
3038 && ! IS_SIGNATURE (t
))
3040 default_fn
= cons_up_default_function (t
, name
, 2);
3041 TREE_CHAIN (default_fn
) = implicit_fns
;
3042 implicit_fns
= default_fn
;
3045 /* Copy constructor. */
3046 if (! TYPE_HAS_INIT_REF (t
) && ! IS_SIGNATURE (t
) && ! TYPE_FOR_JAVA (t
))
3048 /* ARM 12.18: You get either X(X&) or X(const X&), but
3050 default_fn
= cons_up_default_function (t
, name
,
3051 3 + cant_have_const_cctor
);
3052 TREE_CHAIN (default_fn
) = implicit_fns
;
3053 implicit_fns
= default_fn
;
3056 /* Assignment operator. */
3057 if (! TYPE_HAS_ASSIGN_REF (t
) && ! IS_SIGNATURE (t
) && ! TYPE_FOR_JAVA (t
))
3059 default_fn
= cons_up_default_function (t
, name
,
3060 5 + cant_have_assignment
);
3061 TREE_CHAIN (default_fn
) = implicit_fns
;
3062 implicit_fns
= default_fn
;
3065 /* Now, hook all of the new functions on to TYPE_METHODS,
3066 and add them to the CLASSTYPE_METHOD_VEC. */
3067 for (f
= &implicit_fns
; *f
; f
= &TREE_CHAIN (*f
))
3068 add_method (t
, 0, *f
);
3069 *f
= TYPE_METHODS (t
);
3070 TYPE_METHODS (t
) = implicit_fns
;
3072 return virtual_dtor
;
3075 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
3076 (or C++ class declaration).
3078 For C++, we must handle the building of derived classes.
3079 Also, C++ allows static class members. The way that this is
3080 handled is to keep the field name where it is (as the DECL_NAME
3081 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
3082 of the field. layout_record and layout_union will know about this.
3084 More C++ hair: inline functions have text in their
3085 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
3086 meaningful tree structure. After the struct has been laid out, set
3087 things up so that this can happen.
3089 And still more: virtual functions. In the case of single inheritance,
3090 when a new virtual function is seen which redefines a virtual function
3091 from the base class, the new virtual function is placed into
3092 the virtual function table at exactly the same address that
3093 it had in the base class. When this is extended to multiple
3094 inheritance, the same thing happens, except that multiple virtual
3095 function tables must be maintained. The first virtual function
3096 table is treated in exactly the same way as in the case of single
3097 inheritance. Additional virtual function tables have different
3098 DELTAs, which tell how to adjust `this' to point to the right thing.
3100 ATTRIBUTES is the set of decl attributes to be applied, if any. */
3103 finish_struct_1 (t
, warn_anon
)
3108 enum tree_code code
= TREE_CODE (t
);
3109 tree fields
= TYPE_FIELDS (t
);
3110 tree x
, last_x
, method_vec
;
3112 int max_has_virtual
;
3113 tree pending_virtuals
= NULL_TREE
;
3114 tree pending_hard_virtuals
= NULL_TREE
;
3115 tree abstract_virtuals
= NULL_TREE
;
3119 int cant_have_default_ctor
;
3120 int cant_have_const_ctor
;
3121 int no_const_asn_ref
;
3122 int has_mutable
= 0;
3124 /* The index of the first base class which has virtual
3125 functions. Only applied to non-virtual baseclasses. */
3126 int first_vfn_base_index
;
3129 int any_default_members
= 0;
3130 int const_sans_init
= 0;
3131 int ref_sans_init
= 0;
3132 tree access_decls
= NULL_TREE
;
3135 int has_pointers
= 0;
3137 if (warn_anon
&& code
!= UNION_TYPE
&& ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))
3138 pedwarn ("anonymous class type not used to declare any objects");
3142 if (IS_AGGR_TYPE (t
))
3143 cp_error ("redefinition of `%#T'", t
);
3145 my_friendly_abort (172);
3150 GNU_xref_decl (current_function_decl
, t
);
3152 /* If this type was previously laid out as a forward reference,
3153 make sure we lay it out again. */
3155 TYPE_SIZE (t
) = NULL_TREE
;
3156 CLASSTYPE_GOT_SEMICOLON (t
) = 0;
3159 /* This is in general too late to do this. I moved the main case up to
3160 left_curly, what else needs to move? */
3161 if (! IS_SIGNATURE (t
))
3163 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t
) == interface_only
, 999);
3164 my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t
) == ! interface_unknown
, 999);
3168 old
= suspend_momentary ();
3170 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
3171 Also process specified field sizes.
3172 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
3173 The specified size is found in the DECL_INITIAL.
3174 Store 0 there, except for ": 0" fields (so we can find them
3175 and delete them, below). */
3177 if (TYPE_BINFO_BASETYPES (t
))
3178 n_baseclasses
= TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (t
));
3182 if (n_baseclasses
> 0)
3184 struct base_info base_info
;
3186 first_vfn_base_index
= finish_base_struct (t
, &base_info
);
3187 /* Remember where we got our vfield from. */
3188 CLASSTYPE_VFIELD_PARENT (t
) = first_vfn_base_index
;
3189 has_virtual
= base_info
.has_virtual
;
3190 max_has_virtual
= base_info
.max_has_virtual
;
3191 vfield
= base_info
.vfield
;
3192 vfields
= base_info
.vfields
;
3193 CLASSTYPE_RTTI (t
) = base_info
.rtti
;
3194 cant_have_default_ctor
= base_info
.cant_have_default_ctor
;
3195 cant_have_const_ctor
= base_info
.cant_have_const_ctor
;
3196 no_const_asn_ref
= base_info
.no_const_asn_ref
;
3201 first_vfn_base_index
= -1;
3203 max_has_virtual
= has_virtual
;
3205 vfields
= NULL_TREE
;
3206 CLASSTYPE_RTTI (t
) = NULL_TREE
;
3207 cant_have_default_ctor
= 0;
3208 cant_have_const_ctor
= 0;
3209 no_const_asn_ref
= 0;
3213 /* Both of these should be done before now. */
3214 if (write_virtuals
== 3 && CLASSTYPE_INTERFACE_KNOWN (t
)
3215 && ! IS_SIGNATURE (t
))
3217 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t
) == interface_only
, 999);
3218 my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t
) == ! interface_only
, 999);
3222 /* The three of these are approximations which may later be
3223 modified. Needed at this point to make add_virtual_function
3224 and modify_vtable_entries work. */
3225 CLASSTYPE_VFIELDS (t
) = vfields
;
3226 CLASSTYPE_VFIELD (t
) = vfield
;
3228 for (x
= TYPE_METHODS (t
); x
; x
= TREE_CHAIN (x
))
3230 GNU_xref_member (current_class_name
, x
);
3232 /* If this was an evil function, don't keep it in class. */
3233 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x
)))
3236 /* Do both of these, even though they're in the same union;
3237 if the insn `r' member and the size `i' member are
3238 different sizes, as on the alpha, the larger of the two
3239 will end up with garbage in it. */
3240 DECL_SAVED_INSNS (x
) = NULL_RTX
;
3241 DECL_FIELD_SIZE (x
) = 0;
3243 check_for_override (x
, t
);
3244 if (DECL_ABSTRACT_VIRTUAL_P (x
) && ! DECL_VINDEX (x
))
3245 cp_error_at ("initializer specified for non-virtual method `%D'", x
);
3247 /* The name of the field is the original field name
3248 Save this in auxiliary field for later overloading. */
3249 if (DECL_VINDEX (x
))
3251 add_virtual_function (&pending_virtuals
, &pending_hard_virtuals
,
3252 &has_virtual
, x
, t
);
3253 if (DECL_ABSTRACT_VIRTUAL_P (x
))
3254 abstract_virtuals
= tree_cons (NULL_TREE
, x
, abstract_virtuals
);
3256 /* XXX Why did I comment this out? (jason) */
3264 fields
= chainon (build_vbase_pointer_fields (t
), fields
);
3267 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
3269 GNU_xref_member (current_class_name
, x
);
3271 if (TREE_CODE (x
) == FIELD_DECL
)
3273 DECL_PACKED (x
) |= TYPE_PACKED (t
);
3275 if (DECL_C_BIT_FIELD (x
) && integer_zerop (DECL_INITIAL (x
)))
3276 /* A zero-width bitfield doesn't do the trick. */;
3281 if (TREE_CODE (x
) == USING_DECL
)
3283 /* Save access declarations for later. */
3285 TREE_CHAIN (last_x
) = TREE_CHAIN (x
);
3287 fields
= TREE_CHAIN (x
);
3289 access_decls
= scratch_tree_cons (NULL_TREE
, x
, access_decls
);
3295 if (TREE_CODE (x
) == TYPE_DECL
3296 || TREE_CODE (x
) == TEMPLATE_DECL
)
3299 /* If we've gotten this far, it's a data member, possibly static,
3300 or an enumerator. */
3302 DECL_FIELD_CONTEXT (x
) = t
;
3304 /* ``A local class cannot have static data members.'' ARM 9.4 */
3305 if (current_function_decl
&& TREE_STATIC (x
))
3306 cp_error_at ("field `%D' in local class cannot be static", x
);
3308 /* Perform error checking that did not get done in
3310 if (TREE_CODE (TREE_TYPE (x
)) == FUNCTION_TYPE
)
3312 cp_error_at ("field `%D' invalidly declared function type",
3314 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3316 else if (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
)
3318 cp_error_at ("field `%D' invalidly declared method type", x
);
3319 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3321 else if (TREE_CODE (TREE_TYPE (x
)) == OFFSET_TYPE
)
3323 cp_error_at ("field `%D' invalidly declared offset type", x
);
3324 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3328 if (DECL_NAME (x
) == constructor_name (t
))
3329 cant_have_default_ctor
= 1;
3332 if (TREE_TYPE (x
) == error_mark_node
)
3335 DECL_SAVED_INSNS (x
) = NULL_RTX
;
3336 DECL_FIELD_SIZE (x
) = 0;
3338 /* When this goes into scope, it will be a non-local reference. */
3339 DECL_NONLOCAL (x
) = 1;
3341 if (TREE_CODE (x
) == CONST_DECL
)
3344 if (TREE_CODE (x
) == VAR_DECL
)
3346 if (TREE_CODE (t
) == UNION_TYPE
)
3347 /* Unions cannot have static members. */
3348 cp_error_at ("field `%D' declared static in union", x
);
3353 /* Now it can only be a FIELD_DECL. */
3355 if (TREE_PRIVATE (x
) || TREE_PROTECTED (x
))
3358 /* If this is of reference type, check if it needs an init.
3359 Also do a little ANSI jig if necessary. */
3360 if (TREE_CODE (TREE_TYPE (x
)) == REFERENCE_TYPE
)
3362 if (DECL_INITIAL (x
) == NULL_TREE
)
3365 /* ARM $12.6.2: [A member initializer list] (or, for an
3366 aggregate, initialization by a brace-enclosed list) is the
3367 only way to initialize nonstatic const and reference
3369 cant_have_default_ctor
= 1;
3370 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) = 1;
3372 if (! TYPE_HAS_CONSTRUCTOR (t
) && extra_warnings
)
3375 cp_warning_at ("non-static reference `%#D' in class without a constructor", x
);
3377 cp_warning_at ("non-static reference in class without a constructor", x
);
3381 if (TREE_CODE (TREE_TYPE (x
)) == POINTER_TYPE
)
3384 if (DECL_MUTABLE_P (x
) || TYPE_HAS_MUTABLE_P (TREE_TYPE (x
)))
3387 /* If any field is const, the structure type is pseudo-const. */
3388 if (CP_TYPE_CONST_P (TREE_TYPE (x
)))
3390 C_TYPE_FIELDS_READONLY (t
) = 1;
3391 if (DECL_INITIAL (x
) == NULL_TREE
)
3392 const_sans_init
= 1;
3394 /* ARM $12.6.2: [A member initializer list] (or, for an
3395 aggregate, initialization by a brace-enclosed list) is the
3396 only way to initialize nonstatic const and reference
3398 cant_have_default_ctor
= 1;
3399 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) = 1;
3401 if (! TYPE_HAS_CONSTRUCTOR (t
) && !IS_SIGNATURE (t
)
3405 cp_warning_at ("non-static const member `%#D' in class without a constructor", x
);
3407 cp_warning_at ("non-static const member in class without a constructor", x
);
3412 /* A field that is pseudo-const makes the structure
3414 tree t1
= TREE_TYPE (x
);
3415 while (TREE_CODE (t1
) == ARRAY_TYPE
)
3416 t1
= TREE_TYPE (t1
);
3417 if (IS_AGGR_TYPE (t1
))
3419 if (C_TYPE_FIELDS_READONLY (t1
))
3420 C_TYPE_FIELDS_READONLY (t
) = 1;
3421 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1
))
3422 const_sans_init
= 1;
3426 /* We set DECL_C_BIT_FIELD in grokbitfield.
3427 If the type and width are valid, we'll also set DECL_BIT_FIELD. */
3428 if (DECL_C_BIT_FIELD (x
))
3430 /* Invalid bit-field size done by grokfield. */
3431 /* Detect invalid bit-field type. */
3432 if (DECL_INITIAL (x
)
3433 && ! INTEGRAL_TYPE_P (TREE_TYPE (x
)))
3435 cp_error_at ("bit-field `%#D' with non-integral type", x
);
3436 DECL_INITIAL (x
) = NULL
;
3439 /* Detect and ignore out of range field width. */
3440 if (DECL_INITIAL (x
))
3442 tree w
= DECL_INITIAL (x
);
3443 register int width
= 0;
3445 /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */
3448 /* detect invalid field size. */
3449 if (TREE_CODE (w
) == CONST_DECL
)
3450 w
= DECL_INITIAL (w
);
3451 else if (TREE_READONLY_DECL_P (w
))
3452 w
= decl_constant_value (w
);
3454 if (TREE_CODE (w
) != INTEGER_CST
)
3456 cp_error_at ("bit-field `%D' width not an integer constant",
3458 DECL_INITIAL (x
) = NULL_TREE
;
3460 else if (width
= TREE_INT_CST_LOW (w
),
3463 DECL_INITIAL (x
) = NULL
;
3464 cp_error_at ("negative width in bit-field `%D'", x
);
3466 else if (width
== 0 && DECL_NAME (x
) != 0)
3468 DECL_INITIAL (x
) = NULL
;
3469 cp_error_at ("zero width for bit-field `%D'", x
);
3472 > TYPE_PRECISION (long_long_unsigned_type_node
))
3474 /* The backend will dump if you try to use something
3475 too big; avoid that. */
3476 DECL_INITIAL (x
) = NULL
;
3477 sorry ("bit-fields larger than %d bits",
3478 TYPE_PRECISION (long_long_unsigned_type_node
));
3479 cp_error_at (" in declaration of `%D'", x
);
3481 else if (width
> TYPE_PRECISION (TREE_TYPE (x
))
3482 && TREE_CODE (TREE_TYPE (x
)) != ENUMERAL_TYPE
3483 && TREE_CODE (TREE_TYPE (x
)) != BOOLEAN_TYPE
)
3485 cp_warning_at ("width of `%D' exceeds its type", x
);
3487 else if (TREE_CODE (TREE_TYPE (x
)) == ENUMERAL_TYPE
3488 && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x
)),
3489 TREE_UNSIGNED (TREE_TYPE (x
))) > width
)
3490 || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x
)),
3491 TREE_UNSIGNED (TREE_TYPE (x
))) > width
)))
3493 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3497 if (DECL_INITIAL (x
))
3499 DECL_INITIAL (x
) = NULL_TREE
;
3500 DECL_FIELD_SIZE (x
) = width
;
3501 DECL_BIT_FIELD (x
) = 1;
3505 #ifdef EMPTY_FIELD_BOUNDARY
3506 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
),
3507 EMPTY_FIELD_BOUNDARY
);
3509 #ifdef PCC_BITFIELD_TYPE_MATTERS
3510 if (PCC_BITFIELD_TYPE_MATTERS
)
3511 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
),
3512 TYPE_ALIGN (TREE_TYPE (x
)));
3518 /* Non-bit-fields are aligned for their type. */
3519 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
), TYPE_ALIGN (TREE_TYPE (x
)));
3523 tree type
= TREE_TYPE (x
);
3525 while (TREE_CODE (type
) == ARRAY_TYPE
)
3526 type
= TREE_TYPE (type
);
3528 if (TYPE_LANG_SPECIFIC (type
) && ! ANON_UNION_P (x
)
3529 && ! TYPE_PTRMEMFUNC_P (type
))
3531 /* Never let anything with uninheritable virtuals
3532 make it through without complaint. */
3533 if (CLASSTYPE_ABSTRACT_VIRTUALS (type
))
3534 abstract_virtuals_error (x
, type
);
3536 /* Don't let signatures make it through either. */
3537 if (IS_SIGNATURE (type
))
3538 signature_error (x
, type
);
3540 if (code
== UNION_TYPE
)
3542 const char *fie
= NULL
;
3543 if (TYPE_NEEDS_CONSTRUCTING (type
))
3544 fie
= "constructor";
3545 else if (TYPE_NEEDS_DESTRUCTOR (type
))
3547 else if (TYPE_HAS_COMPLEX_ASSIGN_REF (type
))
3548 fie
= "copy assignment operator";
3550 cp_error_at ("member `%#D' with %s not allowed in union", x
,
3555 TYPE_NEEDS_CONSTRUCTING (t
) |= TYPE_NEEDS_CONSTRUCTING (type
);
3556 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_NEEDS_DESTRUCTOR (type
);
3557 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type
);
3558 TYPE_HAS_COMPLEX_INIT_REF (t
) |= TYPE_HAS_COMPLEX_INIT_REF (type
);
3561 if (!TYPE_HAS_CONST_INIT_REF (type
))
3562 cant_have_const_ctor
= 1;
3564 if (!TYPE_HAS_CONST_ASSIGN_REF (type
))
3565 no_const_asn_ref
= 1;
3567 if (TYPE_HAS_CONSTRUCTOR (type
)
3568 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type
))
3570 cant_have_default_ctor
= 1;
3572 /* This is wrong for aggregates. */
3573 if (! TYPE_HAS_CONSTRUCTOR (t
))
3576 cp_pedwarn_at ("member `%#D' with only non-default constructor", x
);
3578 cp_pedwarn_at ("member with only non-default constructor", x
);
3579 cp_pedwarn_at ("in class without a constructor",
3585 if (DECL_INITIAL (x
) != NULL_TREE
)
3587 /* `build_class_init_list' does not recognize
3589 if (code
== UNION_TYPE
&& any_default_members
!= 0)
3590 cp_error_at ("multiple fields in union `%T' initialized");
3591 any_default_members
= 1;
3596 /* If this type has any constant members which did not come
3597 with their own initialization, mark that fact here. It is
3598 not an error here, since such types can be saved either by their
3599 constructors, or by fortuitous initialization. */
3600 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t
) = const_sans_init
;
3601 CLASSTYPE_REF_FIELDS_NEED_INIT (t
) = ref_sans_init
;
3602 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = abstract_virtuals
;
3603 CLASSTYPE_HAS_MUTABLE (t
) = has_mutable
;
3605 /* Effective C++ rule 11. */
3606 if (has_pointers
&& warn_ecpp
&& TYPE_HAS_CONSTRUCTOR (t
)
3607 && ! (TYPE_HAS_INIT_REF (t
) && TYPE_HAS_ASSIGN_REF (t
)))
3609 cp_warning ("`%#T' has pointer data members", t
);
3611 if (! TYPE_HAS_INIT_REF (t
))
3613 cp_warning (" but does not override `%T(const %T&)'", t
, t
);
3614 if (! TYPE_HAS_ASSIGN_REF (t
))
3615 cp_warning (" or `operator=(const %T&)'", t
);
3617 else if (! TYPE_HAS_ASSIGN_REF (t
))
3618 cp_warning (" but does not override `operator=(const %T&)'", t
);
3621 /* Do some bookkeeping that will guide the generation of implicitly
3622 declared member functions. */
3623 TYPE_HAS_COMPLEX_INIT_REF (t
)
3624 |= (TYPE_HAS_INIT_REF (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3625 || has_virtual
|| any_default_members
);
3626 TYPE_NEEDS_CONSTRUCTING (t
)
3627 |= (TYPE_HAS_CONSTRUCTOR (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3628 || has_virtual
|| any_default_members
);
3629 if (! IS_SIGNATURE (t
))
3630 CLASSTYPE_NON_AGGREGATE (t
)
3631 = ! aggregate
|| has_virtual
|| TYPE_HAS_CONSTRUCTOR (t
);
3632 TYPE_HAS_REAL_ASSIGN_REF (t
) |= TYPE_HAS_ASSIGN_REF (t
);
3633 TYPE_HAS_COMPLEX_ASSIGN_REF (t
)
3634 |= TYPE_HAS_ASSIGN_REF (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
);
3636 /* Synthesize any needed methods. Note that methods will be synthesized
3637 for anonymous unions; grok_x_components undoes that. */
3639 = add_implicitly_declared_members (t
, cant_have_default_ctor
,
3640 cant_have_const_ctor
,
3643 add_virtual_function (&pending_virtuals
, &pending_hard_virtuals
,
3644 &has_virtual
, virtual_dtor
, t
);
3646 if (TYPE_METHODS (t
))
3648 finish_struct_methods (t
);
3649 method_vec
= CLASSTYPE_METHOD_VEC (t
);
3655 /* Just in case these got accidentally
3656 filled in by syntax errors. */
3657 TYPE_HAS_CONSTRUCTOR (t
) = 0;
3658 TYPE_HAS_DESTRUCTOR (t
) = 0;
3661 for (access_decls
= nreverse (access_decls
); access_decls
;
3662 access_decls
= TREE_CHAIN (access_decls
))
3663 handle_using_decl (TREE_VALUE (access_decls
), t
, method_vec
, fields
);
3665 if (vfield
== NULL_TREE
&& has_virtual
)
3667 /* We build this decl with vtbl_ptr_type_node, which is a
3668 `vtable_entry_type*'. It might seem more precise to use
3669 `vtable_entry_type (*)[N]' where N is the number of firtual
3670 functions. However, that would require the vtable pointer in
3671 base classes to have a different type than the vtable pointer
3672 in derived classes. We could make that happen, but that
3673 still wouldn't solve all the problems. In particular, the
3674 type-based alias analysis code would decide that assignments
3675 to the base class vtable pointer can't alias assignments to
3676 the derived class vtable pointer, since they have different
3677 types. Thus, in an derived class destructor, where the base
3678 class constructor was inlined, we could generate bad code for
3679 setting up the vtable pointer.
3681 Therefore, we use one type for all vtable pointers. We still
3682 use a type-correct type; it's just doesn't indicate the array
3683 bounds. That's better than using `void*' or some such; it's
3684 cleaner, and it let's the alias analysis code know that these
3685 stores cannot alias stores to void*! */
3686 vfield
= build_lang_field_decl (FIELD_DECL
, get_vfield_name (t
),
3687 vtbl_ptr_type_node
);
3688 /* If you change any of the below, take a look at all the
3689 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3691 DECL_ASSEMBLER_NAME (vfield
) = get_identifier (VFIELD_BASE
);
3692 CLASSTYPE_VFIELD (t
) = vfield
;
3693 DECL_VIRTUAL_P (vfield
) = 1;
3694 DECL_ARTIFICIAL (vfield
) = 1;
3695 DECL_FIELD_CONTEXT (vfield
) = t
;
3696 DECL_CLASS_CONTEXT (vfield
) = t
;
3697 DECL_FCONTEXT (vfield
) = t
;
3698 DECL_SAVED_INSNS (vfield
) = NULL_RTX
;
3699 DECL_FIELD_SIZE (vfield
) = 0;
3700 DECL_ALIGN (vfield
) = TYPE_ALIGN (ptr_type_node
);
3702 /* This is more efficient, but breaks binary compatibility, turn
3703 it on sometime when we don't care. If we turn it on, we also
3704 have to enable the code in dfs_init_vbase_pointers. */
3705 /* vfield is always first entry in structure. */
3706 TREE_CHAIN (vfield
) = fields
;
3711 my_friendly_assert (TREE_CHAIN (last_x
) == NULL_TREE
, 175);
3712 TREE_CHAIN (last_x
) = vfield
;
3719 vfields
= chainon (vfields
, build_tree_list (NULL_TREE
, t
));
3722 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3724 C++: maybe we will support default field initialization some day... */
3726 /* Delete all duplicate fields from the fields */
3727 delete_duplicate_fields (fields
);
3729 /* Now we have the nearly final fieldlist for the data fields. Record it,
3730 then lay out the structure or union (including the fields). */
3732 TYPE_FIELDS (t
) = fields
;
3736 last_x
= build_base_fields (t
);
3738 /* If all our bases are empty, we can be empty too. */
3739 for (x
= last_x
; empty
&& x
; x
= TREE_CHAIN (x
))
3740 if (DECL_SIZE (x
) != integer_zero_node
)
3745 /* C++: do not let empty structures exist. */
3746 tree decl
= build_lang_field_decl
3747 (FIELD_DECL
, NULL_TREE
, char_type_node
);
3748 TREE_CHAIN (decl
) = fields
;
3749 TYPE_FIELDS (t
) = decl
;
3752 TYPE_FIELDS (t
) = chainon (last_x
, TYPE_FIELDS (t
));
3756 /* Remember the size and alignment of the class before adding
3757 the virtual bases. */
3758 if (empty
&& flag_new_abi
)
3759 CLASSTYPE_SIZE (t
) = integer_zero_node
;
3760 else if (flag_new_abi
&& TYPE_HAS_COMPLEX_INIT_REF (t
)
3761 && TYPE_HAS_COMPLEX_ASSIGN_REF (t
))
3762 CLASSTYPE_SIZE (t
) = TYPE_BINFO_SIZE (t
);
3764 CLASSTYPE_SIZE (t
) = TYPE_SIZE (t
);
3765 CLASSTYPE_ALIGN (t
) = TYPE_ALIGN (t
);
3767 finish_struct_anon (t
);
3769 /* Set the TYPE_DECL for this type to contain the right
3770 value for DECL_OFFSET, so that we can use it as part
3771 of a COMPONENT_REF for multiple inheritance. */
3773 layout_decl (TYPE_MAIN_DECL (t
), 0);
3775 /* Now fix up any virtual base class types that we left lying
3776 around. We must get these done before we try to lay out the
3777 virtual function table. */
3778 pending_hard_virtuals
= nreverse (pending_hard_virtuals
);
3781 /* layout_basetypes will remove the base subobject fields. */
3782 max_has_virtual
= layout_basetypes (t
, max_has_virtual
);
3784 TYPE_FIELDS (t
) = fields
;
3786 my_friendly_assert (TYPE_FIELDS (t
) == fields
, 981117);
3788 /* Delete all zero-width bit-fields from the front of the fieldlist */
3789 while (fields
&& DECL_C_BIT_FIELD (fields
)
3790 && DECL_INITIAL (fields
))
3791 fields
= TREE_CHAIN (fields
);
3792 /* Delete all such fields from the rest of the fields. */
3793 for (x
= fields
; x
;)
3795 if (TREE_CHAIN (x
) && DECL_C_BIT_FIELD (TREE_CHAIN (x
))
3796 && DECL_INITIAL (TREE_CHAIN (x
)))
3797 TREE_CHAIN (x
) = TREE_CHAIN (TREE_CHAIN (x
));
3801 TYPE_FIELDS (t
) = fields
;
3803 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
3807 vbases
= CLASSTYPE_VBASECLASSES (t
);
3810 /* Now fixup overrides of all functions in vtables from all
3811 direct or indirect virtual base classes. */
3812 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
3813 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
3815 for (i
= 0; i
< n_baseclasses
; i
++)
3817 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
3818 tree basetype
= BINFO_TYPE (base_binfo
);
3821 vbases
= CLASSTYPE_VBASECLASSES (basetype
);
3824 merge_overrides (binfo_member (BINFO_TYPE (vbases
),
3825 CLASSTYPE_VBASECLASSES (t
)),
3827 vbases
= TREE_CHAIN (vbases
);
3833 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
3834 might need to know it for setting up the offsets in the vtable
3835 (or in thunks) below. */
3836 if (vfield
!= NULL_TREE
3837 && DECL_FIELD_CONTEXT (vfield
) != t
)
3839 tree binfo
= get_binfo (DECL_FIELD_CONTEXT (vfield
), t
, 0);
3840 tree offset
= BINFO_OFFSET (binfo
);
3842 vfield
= copy_node (vfield
);
3843 copy_lang_decl (vfield
);
3845 if (! integer_zerop (offset
))
3846 offset
= size_binop (MULT_EXPR
, offset
, size_int (BITS_PER_UNIT
));
3847 DECL_FIELD_CONTEXT (vfield
) = t
;
3848 DECL_CLASS_CONTEXT (vfield
) = t
;
3849 DECL_FIELD_BITPOS (vfield
)
3850 = size_binop (PLUS_EXPR
, offset
, DECL_FIELD_BITPOS (vfield
));
3851 CLASSTYPE_VFIELD (t
) = vfield
;
3855 cp_warning ("Doing hard virtuals for %T...", t
);
3858 if (has_virtual
> max_has_virtual
)
3859 max_has_virtual
= has_virtual
;
3860 if (max_has_virtual
> 0)
3861 TYPE_VIRTUAL_P (t
) = 1;
3863 if (flag_rtti
&& TYPE_VIRTUAL_P (t
) && !pending_hard_virtuals
)
3864 modify_all_vtables (t
, NULL_TREE
, NULL_TREE
);
3866 while (pending_hard_virtuals
)
3868 modify_all_vtables (t
,
3869 TREE_PURPOSE (pending_hard_virtuals
),
3870 TREE_VALUE (pending_hard_virtuals
));
3871 pending_hard_virtuals
= TREE_CHAIN (pending_hard_virtuals
);
3874 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
3877 /* Now fixup any virtual function entries from virtual bases
3878 that have different deltas. This has to come after we do the
3879 pending hard virtuals, as we might have a function that comes
3880 from multiple virtual base instances that is only overridden
3881 by a hard virtual above. */
3882 vbases
= CLASSTYPE_VBASECLASSES (t
);
3885 /* We might be able to shorten the amount of work we do by
3886 only doing this for vtables that come from virtual bases
3887 that have differing offsets, but don't want to miss any
3889 fixup_vtable_deltas (vbases
, 1, t
);
3890 vbases
= TREE_CHAIN (vbases
);
3894 /* Under our model of GC, every C++ class gets its own virtual
3895 function table, at least virtually. */
3896 if (pending_virtuals
)
3898 pending_virtuals
= nreverse (pending_virtuals
);
3899 /* We must enter these virtuals into the table. */
3900 if (first_vfn_base_index
< 0)
3902 if (! CLASSTYPE_COM_INTERFACE (t
))
3904 /* The second slot is for the tdesc pointer when thunks are used. */
3905 if (flag_vtable_thunks
)
3906 pending_virtuals
= tree_cons (NULL_TREE
, NULL_TREE
, pending_virtuals
);
3908 /* The first slot is for the rtti offset. */
3909 pending_virtuals
= tree_cons (NULL_TREE
, NULL_TREE
, pending_virtuals
);
3911 set_rtti_entry (pending_virtuals
,
3912 convert (ssizetype
, integer_zero_node
), t
);
3914 build_vtable (NULL_TREE
, t
);
3918 /* Here we know enough to change the type of our virtual
3919 function table, but we will wait until later this function. */
3921 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t
)))
3922 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), first_vfn_base_index
), t
);
3925 /* If this type has basetypes with constructors, then those
3926 constructors might clobber the virtual function table. But
3927 they don't if the derived class shares the exact vtable of the base
3930 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t
) = 1;
3932 else if (first_vfn_base_index
>= 0)
3934 tree binfo
= TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), first_vfn_base_index
);
3935 /* This class contributes nothing new to the virtual function
3936 table. However, it may have declared functions which
3937 went into the virtual function table "inherited" from the
3938 base class. If so, we grab a copy of those updated functions,
3939 and pretend they are ours. */
3941 /* See if we should steal the virtual info from base class. */
3942 if (TYPE_BINFO_VTABLE (t
) == NULL_TREE
)
3943 TYPE_BINFO_VTABLE (t
) = BINFO_VTABLE (binfo
);
3944 if (TYPE_BINFO_VIRTUALS (t
) == NULL_TREE
)
3945 TYPE_BINFO_VIRTUALS (t
) = BINFO_VIRTUALS (binfo
);
3946 if (TYPE_BINFO_VTABLE (t
) != BINFO_VTABLE (binfo
))
3947 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t
) = 1;
3950 if (max_has_virtual
|| first_vfn_base_index
>= 0)
3952 CLASSTYPE_VSIZE (t
) = has_virtual
;
3953 if (first_vfn_base_index
>= 0)
3955 if (pending_virtuals
)
3956 TYPE_BINFO_VIRTUALS (t
) = chainon (TYPE_BINFO_VIRTUALS (t
),
3959 else if (has_virtual
)
3961 TYPE_BINFO_VIRTUALS (t
) = pending_virtuals
;
3962 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t
)) = 1;
3966 /* Now lay out the virtual function table. */
3969 /* Use size_int so values are memoized in common cases. */
3970 tree itype
= build_index_type (size_int (has_virtual
));
3971 tree atype
= build_cplus_array_type (vtable_entry_type
, itype
);
3973 layout_type (atype
);
3975 CLASSTYPE_VFIELD (t
) = vfield
;
3977 /* We may have to grow the vtable. */
3978 if (TREE_TYPE (TYPE_BINFO_VTABLE (t
)) != atype
)
3980 TREE_TYPE (TYPE_BINFO_VTABLE (t
)) = atype
;
3981 DECL_SIZE (TYPE_BINFO_VTABLE (t
)) = 0;
3982 layout_decl (TYPE_BINFO_VTABLE (t
), 0);
3983 /* At one time the vtable info was grabbed 2 words at a time. This
3984 fails on sparc unless you have 8-byte alignment. (tiemann) */
3985 DECL_ALIGN (TYPE_BINFO_VTABLE (t
))
3986 = MAX (TYPE_ALIGN (double_type_node
),
3987 DECL_ALIGN (TYPE_BINFO_VTABLE (t
)));
3990 else if (first_vfn_base_index
>= 0)
3991 CLASSTYPE_VFIELD (t
) = vfield
;
3992 CLASSTYPE_VFIELDS (t
) = vfields
;
3994 finish_struct_bits (t
, max_has_virtual
);
3996 /* Complete the rtl for any static member objects of the type we're
3998 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
4000 if (TREE_CODE (x
) == VAR_DECL
&& TREE_STATIC (x
)
4001 && TREE_TYPE (x
) == t
)
4003 DECL_MODE (x
) = TYPE_MODE (t
);
4004 make_decl_rtl (x
, NULL
, 0);
4008 if (TYPE_HAS_CONSTRUCTOR (t
))
4010 tree vfields
= CLASSTYPE_VFIELDS (t
);
4014 /* Mark the fact that constructor for T
4015 could affect anybody inheriting from T
4016 who wants to initialize vtables for VFIELDS's type. */
4017 if (VF_DERIVED_VALUE (vfields
))
4018 TREE_ADDRESSABLE (vfields
) = 1;
4019 vfields
= TREE_CHAIN (vfields
);
4023 /* Write out inline function definitions. */
4024 do_inline_function_hair (t
, CLASSTYPE_INLINE_FRIENDS (t
));
4025 CLASSTYPE_INLINE_FRIENDS (t
) = 0;
4027 if (CLASSTYPE_VSIZE (t
) != 0)
4030 /* This is now done above. */
4031 if (DECL_FIELD_CONTEXT (vfield
) != t
)
4033 tree binfo
= get_binfo (DECL_FIELD_CONTEXT (vfield
), t
, 0);
4034 tree offset
= BINFO_OFFSET (binfo
);
4036 vfield
= copy_node (vfield
);
4037 copy_lang_decl (vfield
);
4039 if (! integer_zerop (offset
))
4040 offset
= size_binop (MULT_EXPR
, offset
, size_int (BITS_PER_UNIT
));
4041 DECL_FIELD_CONTEXT (vfield
) = t
;
4042 DECL_CLASS_CONTEXT (vfield
) = t
;
4043 DECL_FIELD_BITPOS (vfield
)
4044 = size_binop (PLUS_EXPR
, offset
, DECL_FIELD_BITPOS (vfield
));
4045 CLASSTYPE_VFIELD (t
) = vfield
;
4049 /* In addition to this one, all the other vfields should be listed. */
4050 /* Before that can be done, we have to have FIELD_DECLs for them, and
4051 a place to find them. */
4052 TYPE_NONCOPIED_PARTS (t
) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t
)), vfield
);
4054 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (t
)
4055 && DECL_VINDEX (TREE_VEC_ELT (method_vec
, 1)) == NULL_TREE
)
4056 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4060 /* Make the rtl for any new vtables we have created, and unmark
4061 the base types we marked. */
4062 finish_vtbls (TYPE_BINFO (t
), 1, t
);
4063 hack_incomplete_structures (t
);
4066 if (TYPE_NAME (t
) && TYPE_IDENTIFIER (t
))
4067 undo_template_name_overload (TYPE_IDENTIFIER (t
), 1);
4070 resume_momentary (old
);
4072 if (warn_overloaded_virtual
)
4076 /* This has to be done after we have sorted out what to do with
4077 the enclosing type. */
4078 if (write_symbols
!= DWARF_DEBUG
)
4080 /* Be smarter about nested classes here. If a type is nested,
4081 only output it if we would output the enclosing type. */
4082 if (DECL_CLASS_SCOPE_P (TYPE_MAIN_DECL (t
)))
4083 DECL_IGNORED_P (TYPE_MAIN_DECL (t
)) = TREE_ASM_WRITTEN (TYPE_MAIN_DECL (t
));
4087 if (write_symbols
!= DWARF_DEBUG
&& write_symbols
!= DWARF2_DEBUG
)
4089 /* If the type has methods, we want to think about cutting down
4090 the amount of symbol table stuff we output. The value stored in
4091 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4092 For example, if a member function is seen and we decide to
4093 write out that member function, then we can change the value
4094 of the DECL_IGNORED_P slot, and the type will be output when
4095 that member function's debug info is written out.
4097 We can't do this with DWARF, which does not support name
4098 references between translation units. */
4099 if (CLASSTYPE_METHOD_VEC (t
))
4101 /* Don't output full info about any type
4102 which does not have its implementation defined here. */
4103 if (CLASSTYPE_INTERFACE_ONLY (t
))
4104 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4106 /* XXX do something about this. */
4107 else if (CLASSTYPE_INTERFACE_UNKNOWN (t
))
4108 /* Only a first approximation! */
4109 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4112 else if (CLASSTYPE_INTERFACE_ONLY (t
))
4113 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4116 /* Finish debugging output for this type. */
4117 rest_of_type_compilation (t
, toplevel_bindings_p ());
4122 /* When T was built up, the member declarations were added in reverse
4123 order. Rearrange them to declaration order. */
4126 unreverse_member_declarations (t
)
4133 /* The TYPE_FIELDS, TYPE_METHODS, and CLASSTYPE_TAGS are all in
4134 reverse order. Put them in declaration order now. */
4135 TYPE_METHODS (t
) = nreverse (TYPE_METHODS (t
));
4136 CLASSTYPE_TAGS (t
) = nreverse (CLASSTYPE_TAGS (t
));
4138 /* Actually, for the TYPE_FIELDS, only the non TYPE_DECLs are in
4139 reverse order, so we can't just use nreverse. */
4141 for (x
= TYPE_FIELDS (t
);
4142 x
&& TREE_CODE (x
) != TYPE_DECL
;
4145 next
= TREE_CHAIN (x
);
4146 TREE_CHAIN (x
) = prev
;
4151 TREE_CHAIN (TYPE_FIELDS (t
)) = x
;
4153 TYPE_FIELDS (t
) = prev
;
4158 finish_struct (t
, attributes
, warn_anon
)
4162 tree name
= TYPE_NAME (t
);
4164 if (TREE_CODE (name
) == TYPE_DECL
)
4168 DECL_SOURCE_FILE (name
) = input_filename
;
4169 /* For TYPE_DECL that are not typedefs (those marked with a line
4170 number of zero, we don't want to mark them as real typedefs.
4171 If this fails one needs to make sure real typedefs have a
4172 previous line number, even if it is wrong, that way the below
4173 will fill in the right line number. (mrs) */
4174 if (DECL_SOURCE_LINE (name
))
4175 DECL_SOURCE_LINE (name
) = lineno
;
4176 name
= DECL_NAME (name
);
4179 /* Append the fields we need for constructing signature tables. */
4180 if (IS_SIGNATURE (t
))
4181 append_signature_fields (t
);
4183 /* Now that we've got all the field declarations, reverse everything
4185 unreverse_member_declarations (t
);
4187 cplus_decl_attributes (t
, attributes
, NULL_TREE
);
4189 if (processing_template_decl
)
4191 tree d
= getdecls ();
4192 for (; d
; d
= TREE_CHAIN (d
))
4194 /* If this is the decl for the class or one of the template
4195 parms, we've seen all the injected decls. */
4196 if ((TREE_CODE (d
) == TYPE_DECL
4197 && (TREE_TYPE (d
) == t
4198 || TREE_CODE (TREE_TYPE (d
)) == TEMPLATE_TYPE_PARM
4199 || TREE_CODE (TREE_TYPE (d
)) == TEMPLATE_TEMPLATE_PARM
))
4200 || TREE_CODE (d
) == CONST_DECL
)
4202 /* Don't inject cache decls. */
4203 else if (IDENTIFIER_TEMPLATE (DECL_NAME (d
)))
4205 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t
))
4206 = tree_cons (NULL_TREE
, d
,
4207 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t
)));
4209 finish_struct_methods (t
);
4210 TYPE_SIZE (t
) = integer_zero_node
;
4213 t
= finish_struct_1 (t
, warn_anon
);
4215 TYPE_BEING_DEFINED (t
) = 0;
4217 if (current_class_type
)
4220 error ("trying to finish struct, but kicked out due to previous parse errors.");
4225 /* Return the dynamic type of INSTANCE, if known.
4226 Used to determine whether the virtual function table is needed
4229 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4230 of our knowledge of its type. */
4233 fixed_type_or_null (instance
, nonnull
)
4237 switch (TREE_CODE (instance
))
4240 /* Check that we are not going through a cast of some sort. */
4241 if (TREE_TYPE (instance
)
4242 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance
, 0))))
4243 instance
= TREE_OPERAND (instance
, 0);
4244 /* fall through... */
4246 /* This is a call to a constructor, hence it's never zero. */
4247 if (TREE_HAS_CONSTRUCTOR (instance
))
4251 return TREE_TYPE (instance
);
4256 /* This is a call to a constructor, hence it's never zero. */
4257 if (TREE_HAS_CONSTRUCTOR (instance
))
4261 return TREE_TYPE (instance
);
4263 return fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4270 if (TREE_CODE (TREE_OPERAND (instance
, 1)) == INTEGER_CST
)
4271 /* Propagate nonnull. */
4272 fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4273 if (TREE_CODE (TREE_OPERAND (instance
, 0)) == ADDR_EXPR
)
4274 return fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4279 return fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4284 return fixed_type_or_null (TREE_OPERAND (instance
, 0), nonnull
);
4287 return fixed_type_or_null (TREE_OPERAND (instance
, 1), nonnull
);
4291 if (TREE_CODE (TREE_TYPE (instance
)) == ARRAY_TYPE
4292 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance
))))
4296 return TREE_TYPE (TREE_TYPE (instance
));
4298 /* fall through... */
4301 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
4305 return TREE_TYPE (instance
);
4309 if (instance
== current_class_ptr
4310 && flag_this_is_variable
<= 0)
4312 /* Normally, 'this' must be non-null. */
4313 if (flag_this_is_variable
== 0)
4316 /* <0 means we're in a constructor and we know our type. */
4317 if (flag_this_is_variable
< 0)
4318 return TREE_TYPE (TREE_TYPE (instance
));
4320 else if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
4321 /* Reference variables should be references to objects. */
4331 /* Return non-zero if the dynamic type of INSTANCE is known, and equivalent
4332 to the static type. We also handle the case where INSTANCE is really
4335 Used to determine whether the virtual function table is needed
4338 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4339 of our knowledge of its type. */
4342 resolves_to_fixed_type_p (instance
, nonnull
)
4346 tree t
= TREE_TYPE (instance
);
4347 tree fixed
= fixed_type_or_null (instance
, nonnull
);
4348 if (fixed
== NULL_TREE
)
4350 if (POINTER_TYPE_P (t
))
4352 return same_type_p (TYPE_MAIN_VARIANT (t
), TYPE_MAIN_VARIANT (fixed
));
4357 init_class_processing ()
4359 current_class_depth
= 0;
4360 current_class_stack_size
= 10;
4362 = (class_stack_node_t
) xmalloc (current_class_stack_size
4363 * sizeof (struct class_stack_node
));
4365 current_lang_stacksize
= 10;
4366 current_lang_base
= (tree
*)xmalloc(current_lang_stacksize
* sizeof (tree
));
4367 current_lang_stack
= current_lang_base
;
4369 access_default_node
= build_int_2 (0, 0);
4370 access_public_node
= build_int_2 (1, 0);
4371 access_protected_node
= build_int_2 (2, 0);
4372 access_private_node
= build_int_2 (3, 0);
4373 access_default_virtual_node
= build_int_2 (4, 0);
4374 access_public_virtual_node
= build_int_2 (5, 0);
4375 access_protected_virtual_node
= build_int_2 (6, 0);
4376 access_private_virtual_node
= build_int_2 (7, 0);
4378 /* Keep these values lying around. */
4379 base_layout_decl
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, error_mark_node
);
4380 TREE_TYPE (base_layout_decl
) = make_node (RECORD_TYPE
);
4382 gcc_obstack_init (&class_obstack
);
4385 /* Set current scope to NAME. CODE tells us if this is a
4386 STRUCT, UNION, or ENUM environment.
4388 NAME may end up being NULL_TREE if this is an anonymous or
4389 late-bound struct (as in "struct { ... } foo;") */
4391 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
4392 appropriate values, found by looking up the type definition of
4395 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
4396 which can be seen locally to the class. They are shadowed by
4397 any subsequent local declaration (including parameter names).
4399 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
4400 which have static meaning (i.e., static members, static
4401 member functions, enum declarations, etc).
4403 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
4404 which can be seen locally to the class (as in 1), but
4405 know that we are doing this for declaration purposes
4406 (i.e. friend foo::bar (int)).
4408 So that we may avoid calls to lookup_name, we cache the _TYPE
4409 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
4411 For multiple inheritance, we perform a two-pass depth-first search
4412 of the type lattice. The first pass performs a pre-order search,
4413 marking types after the type has had its fields installed in
4414 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
4415 unmarks the marked types. If a field or member function name
4416 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4417 that name becomes `error_mark_node'. */
4420 pushclass (type
, modify
)
4424 type
= TYPE_MAIN_VARIANT (type
);
4426 /* Make sure there is enough room for the new entry on the stack. */
4427 if (current_class_depth
+ 1 >= current_class_stack_size
)
4429 current_class_stack_size
*= 2;
4431 = (class_stack_node_t
) xrealloc (current_class_stack
,
4432 current_class_stack_size
4433 * sizeof (struct class_stack_node
));
4436 /* Insert a new entry on the class stack. */
4437 current_class_stack
[current_class_depth
].name
= current_class_name
;
4438 current_class_stack
[current_class_depth
].type
= current_class_type
;
4439 current_class_stack
[current_class_depth
].access
= current_access_specifier
;
4440 current_class_stack
[current_class_depth
].names_used
= 0;
4441 current_class_depth
++;
4443 /* Now set up the new type. */
4444 current_class_name
= TYPE_NAME (type
);
4445 if (TREE_CODE (current_class_name
) == TYPE_DECL
)
4446 current_class_name
= DECL_NAME (current_class_name
);
4447 current_class_type
= type
;
4449 /* By default, things in classes are private, while things in
4450 structures or unions are public. */
4451 current_access_specifier
= (CLASSTYPE_DECLARED_CLASS (type
)
4452 ? access_private_node
4453 : access_public_node
);
4455 if (previous_class_type
!= NULL_TREE
4456 && (type
!= previous_class_type
4457 || TYPE_SIZE (previous_class_type
) == NULL_TREE
)
4458 && current_class_depth
== 1)
4460 /* Forcibly remove any old class remnants. */
4461 invalidate_class_lookup_cache ();
4463 /* Now, free the obstack on which we cached all the values. */
4464 obstack_free (&class_cache_obstack
, class_cache_firstobj
);
4465 class_cache_firstobj
4466 = (char*) obstack_finish (&class_cache_obstack
);
4469 /* If we're about to enter a nested class, clear
4470 IDENTIFIER_CLASS_VALUE for the enclosing classes. */
4471 if (modify
&& current_class_depth
> 1)
4472 clear_identifier_class_values ();
4477 if (CLASSTYPE_TEMPLATE_INFO (type
))
4478 overload_template_name (type
);
4483 if (type
!= previous_class_type
|| current_class_depth
> 1)
4484 push_class_decls (type
);
4489 /* We are re-entering the same class we just left, so we
4490 don't have to search the whole inheritance matrix to find
4491 all the decls to bind again. Instead, we install the
4492 cached class_shadowed list, and walk through it binding
4493 names and setting up IDENTIFIER_TYPE_VALUEs. */
4494 set_class_shadows (previous_class_values
);
4495 for (item
= previous_class_values
; item
; item
= TREE_CHAIN (item
))
4497 tree id
= TREE_PURPOSE (item
);
4498 tree decl
= TREE_TYPE (item
);
4500 push_class_binding (id
, decl
);
4501 if (TREE_CODE (decl
) == TYPE_DECL
)
4502 set_identifier_type_value (id
, TREE_TYPE (decl
));
4504 unuse_fields (type
);
4507 storetags (CLASSTYPE_TAGS (type
));
4511 /* When we exit a toplevel class scope, we save the
4512 IDENTIFIER_CLASS_VALUEs so that we can restore them quickly if we
4513 reenter the class. Here, we've entered some other class, so we
4514 must invalidate our cache. */
4517 invalidate_class_lookup_cache ()
4521 /* This code can be seen as a cache miss. When we've cached a
4522 class' scope's bindings and we can't use them, we need to reset
4523 them. This is it! */
4524 for (t
= previous_class_values
; t
; t
= TREE_CHAIN (t
))
4525 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t
)) = NULL_TREE
;
4527 previous_class_type
= NULL_TREE
;
4530 /* Get out of the current class scope. If we were in a class scope
4531 previously, that is the one popped to. */
4537 /* Since poplevel_class does the popping of class decls nowadays,
4538 this really only frees the obstack used for these decls. */
4541 current_class_depth
--;
4542 current_class_name
= current_class_stack
[current_class_depth
].name
;
4543 current_class_type
= current_class_stack
[current_class_depth
].type
;
4544 current_access_specifier
= current_class_stack
[current_class_depth
].access
;
4545 if (current_class_stack
[current_class_depth
].names_used
)
4546 splay_tree_delete (current_class_stack
[current_class_depth
].names_used
);
4549 /* Returns 1 if current_class_type is either T or a nested type of T. */
4552 currently_open_class (t
)
4556 if (t
== current_class_type
)
4558 for (i
= 0; i
< current_class_depth
; ++i
)
4559 if (current_class_stack
[i
].type
== t
)
4564 /* When entering a class scope, all enclosing class scopes' names with
4565 static meaning (static variables, static functions, types and enumerators)
4566 have to be visible. This recursive function calls pushclass for all
4567 enclosing class contexts until global or a local scope is reached.
4568 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4569 formal of the same name. */
4572 push_nested_class (type
, modify
)
4578 /* A namespace might be passed in error cases, like A::B:C. */
4579 if (type
== NULL_TREE
|| type
== error_mark_node
|| ! IS_AGGR_TYPE (type
)
4580 || TREE_CODE (type
) == NAMESPACE_DECL
4581 || TREE_CODE (type
) == TEMPLATE_TYPE_PARM
4582 || TREE_CODE (type
) == TEMPLATE_TEMPLATE_PARM
)
4585 context
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
4587 if (context
&& CLASS_TYPE_P (context
))
4588 push_nested_class (context
, 2);
4589 pushclass (type
, modify
);
4592 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4597 tree context
= DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type
));
4600 if (context
&& CLASS_TYPE_P (context
))
4601 pop_nested_class ();
4604 /* Set global variables CURRENT_LANG_NAME to appropriate value
4605 so that behavior of name-mangling machinery is correct. */
4608 push_lang_context (name
)
4611 *current_lang_stack
++ = current_lang_name
;
4612 if (current_lang_stack
>= current_lang_base
+ current_lang_stacksize
)
4615 = (tree
*)xrealloc (current_lang_base
,
4616 sizeof (tree
) * (current_lang_stacksize
+ 10));
4617 current_lang_stack
= current_lang_base
+ current_lang_stacksize
;
4618 current_lang_stacksize
+= 10;
4621 if (name
== lang_name_cplusplus
|| name
== lang_name_java
)
4623 strict_prototype
= strict_prototypes_lang_cplusplus
;
4624 current_lang_name
= name
;
4626 else if (name
== lang_name_c
)
4628 strict_prototype
= strict_prototypes_lang_c
;
4629 current_lang_name
= name
;
4632 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name
));
4635 /* Get out of the current language scope. */
4640 current_lang_name
= *--current_lang_stack
;
4641 if (current_lang_name
== lang_name_cplusplus
4642 || current_lang_name
== lang_name_java
)
4643 strict_prototype
= strict_prototypes_lang_cplusplus
;
4644 else if (current_lang_name
== lang_name_c
)
4645 strict_prototype
= strict_prototypes_lang_c
;
4648 /* Type instantiation routines. */
4650 /* Given an OVERLOAD and a TARGET_TYPE, return the function that
4651 matches the TARGET_TYPE. If there is no satisfactory match, return
4652 error_mark_node, and issue an error message if COMPLAIN is
4653 non-zero. If TEMPLATE_ONLY, the name of the overloaded function
4654 was a template-id, and EXPLICIT_TARGS are the explicitly provided
4655 template arguments. */
4658 resolve_address_of_overloaded_function (target_type
,
4667 tree explicit_targs
;
4669 /* Here's what the standard says:
4673 If the name is a function template, template argument deduction
4674 is done, and if the argument deduction succeeds, the deduced
4675 arguments are used to generate a single template function, which
4676 is added to the set of overloaded functions considered.
4678 Non-member functions and static member functions match targets of
4679 type "pointer-to-function" or "reference-to-function." Nonstatic
4680 member functions match targets of type "pointer-to-member
4681 function;" the function type of the pointer to member is used to
4682 select the member function from the set of overloaded member
4683 functions. If a nonstatic member function is selected, the
4684 reference to the overloaded function name is required to have the
4685 form of a pointer to member as described in 5.3.1.
4687 If more than one function is selected, any template functions in
4688 the set are eliminated if the set also contains a non-template
4689 function, and any given template function is eliminated if the
4690 set contains a second template function that is more specialized
4691 than the first according to the partial ordering rules 14.5.5.2.
4692 After such eliminations, if any, there shall remain exactly one
4693 selected function. */
4696 int is_reference
= 0;
4697 /* We store the matches in a TREE_LIST rooted here. The functions
4698 are the TREE_PURPOSE, not the TREE_VALUE, in this list, for easy
4699 interoperability with most_specialized_instantiation. */
4700 tree matches
= NULL_TREE
;
4703 /* By the time we get here, we should be seeing only real
4704 pointer-to-member types, not the internal POINTER_TYPE to
4705 METHOD_TYPE representation. */
4706 my_friendly_assert (!(TREE_CODE (target_type
) == POINTER_TYPE
4707 && (TREE_CODE (TREE_TYPE (target_type
))
4708 == METHOD_TYPE
)), 0);
4710 /* Check that the TARGET_TYPE is reasonable. */
4711 if (TYPE_PTRFN_P (target_type
))
4714 else if (TYPE_PTRMEMFUNC_P (target_type
))
4715 /* This is OK, too. */
4717 else if (TREE_CODE (target_type
) == FUNCTION_TYPE
)
4719 /* This is OK, too. This comes from a conversion to reference
4721 target_type
= build_reference_type (target_type
);
4727 cp_error("cannot resolve overloaded function `%D' based on conversion to type `%T'",
4728 DECL_NAME (OVL_FUNCTION (overload
)), target_type
);
4729 return error_mark_node
;
4732 /* If we can find a non-template function that matches, we can just
4733 use it. There's no point in generating template instantiations
4734 if we're just going to throw them out anyhow. But, of course, we
4735 can only do this when we don't *need* a template function. */
4740 for (fns
= overload
; fns
; fns
= OVL_CHAIN (fns
))
4742 tree fn
= OVL_FUNCTION (fns
);
4745 if (TREE_CODE (fn
) == TEMPLATE_DECL
)
4746 /* We're not looking for templates just yet. */
4749 if ((TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
4751 /* We're looking for a non-static member, and this isn't
4752 one, or vice versa. */
4755 /* See if there's a match. */
4756 fntype
= TREE_TYPE (fn
);
4758 fntype
= build_ptrmemfunc_type (build_pointer_type (fntype
));
4759 else if (!is_reference
)
4760 fntype
= build_pointer_type (fntype
);
4762 if (can_convert_arg (target_type
, fntype
, fn
))
4763 matches
= scratch_tree_cons (fn
, NULL_TREE
, matches
);
4767 /* Now, if we've already got a match (or matches), there's no need
4768 to proceed to the template functions. But, if we don't have a
4769 match we need to look at them, too. */
4772 tree target_fn_type
;
4773 tree target_arg_types
;
4778 = TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (target_type
));
4780 target_fn_type
= TREE_TYPE (target_type
);
4781 target_arg_types
= TYPE_ARG_TYPES (target_fn_type
);
4783 for (fns
= overload
; fns
; fns
= OVL_CHAIN (fns
))
4785 tree fn
= OVL_FUNCTION (fns
);
4787 tree instantiation_type
;
4790 if (TREE_CODE (fn
) != TEMPLATE_DECL
)
4791 /* We're only looking for templates. */
4794 if ((TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
4796 /* We're not looking for a non-static member, and this is
4797 one, or vice versa. */
4800 /* Try to do argument deduction. */
4801 targs
= make_scratch_vec (DECL_NTPARMS (fn
));
4802 if (fn_type_unification (fn
, explicit_targs
, targs
,
4803 target_arg_types
, NULL_TREE
,
4805 /* Argument deduction failed. */
4808 /* Instantiate the template. */
4809 instantiation
= instantiate_template (fn
, targs
);
4810 if (instantiation
== error_mark_node
)
4811 /* Instantiation failed. */
4814 /* See if there's a match. */
4815 instantiation_type
= TREE_TYPE (instantiation
);
4817 instantiation_type
=
4818 build_ptrmemfunc_type (build_pointer_type (instantiation_type
));
4819 else if (!is_reference
)
4820 instantiation_type
= build_pointer_type (instantiation_type
);
4821 if (can_convert_arg (target_type
, instantiation_type
, instantiation
))
4822 matches
= scratch_tree_cons (instantiation
, fn
, matches
);
4825 /* Now, remove all but the most specialized of the matches. */
4828 tree match
= most_specialized_instantiation (matches
,
4831 if (match
!= error_mark_node
)
4832 matches
= scratch_tree_cons (match
, NULL_TREE
, NULL_TREE
);
4836 /* Now we should have exactly one function in MATCHES. */
4837 if (matches
== NULL_TREE
)
4839 /* There were *no* matches. */
4842 cp_error ("no matches converting function `%D' to type `%#T'",
4843 DECL_NAME (OVL_FUNCTION (overload
)),
4846 /* print_candidates expects a chain with the functions in
4847 TREE_VALUE slots, so we cons one up here (we're losing anyway,
4848 so why be clever?). */
4849 for (; overload
; overload
= OVL_NEXT (overload
))
4850 matches
= scratch_tree_cons (NULL_TREE
, OVL_CURRENT (overload
),
4853 print_candidates (matches
);
4855 return error_mark_node
;
4857 else if (TREE_CHAIN (matches
))
4859 /* There were too many matches. */
4865 cp_error ("converting overloaded function `%D' to type `%#T' is ambiguous",
4866 DECL_NAME (OVL_FUNCTION (overload
)),
4869 /* Since print_candidates expects the functions in the
4870 TREE_VALUE slot, we flip them here. */
4871 for (match
= matches
; match
; match
= TREE_CHAIN (match
))
4872 TREE_VALUE (match
) = TREE_PURPOSE (match
);
4874 print_candidates (matches
);
4877 return error_mark_node
;
4880 /* Good, exactly one match. Now, convert it to the correct type. */
4881 fn
= TREE_PURPOSE (matches
);
4885 if (TYPE_PTRFN_P (target_type
) || TYPE_PTRMEMFUNC_P (target_type
))
4886 return build_unary_op (ADDR_EXPR
, fn
, 0);
4889 /* The target must be a REFERENCE_TYPE. Above, build_unary_op
4890 will mark the function as addressed, but here we must do it
4892 mark_addressable (fn
);
4898 /* This function will instantiate the type of the expression given in
4899 RHS to match the type of LHSTYPE. If errors exist, then return
4900 error_mark_node. We only complain is COMPLAIN is set. If we are
4901 not complaining, never modify rhs, as overload resolution wants to
4902 try many possible instantiations, in hopes that at least one will
4905 FLAGS is a bitmask, as we see at the top of the function.
4907 For non-recursive calls, LHSTYPE should be a function, pointer to
4908 function, or a pointer to member function. */
4911 instantiate_type (lhstype
, rhs
, flags
)
4915 int complain
= (flags
& 1);
4916 int strict
= (flags
& 2) ? COMPARE_NO_ATTRIBUTES
: COMPARE_STRICT
;
4918 if (TREE_CODE (lhstype
) == UNKNOWN_TYPE
)
4921 error ("not enough type information");
4922 return error_mark_node
;
4925 if (TREE_TYPE (rhs
) != NULL_TREE
&& ! (type_unknown_p (rhs
)))
4927 if (comptypes (lhstype
, TREE_TYPE (rhs
), strict
))
4930 cp_error ("argument of type `%T' does not match `%T'",
4931 TREE_TYPE (rhs
), lhstype
);
4932 return error_mark_node
;
4935 /* We don't overwrite rhs if it is an overloaded function.
4936 Copying it would destroy the tree link. */
4937 if (TREE_CODE (rhs
) != OVERLOAD
)
4938 rhs
= copy_node (rhs
);
4940 /* This should really only be used when attempting to distinguish
4941 what sort of a pointer to function we have. For now, any
4942 arithmetic operation which is not supported on pointers
4943 is rejected as an error. */
4945 switch (TREE_CODE (rhs
))
4952 my_friendly_abort (177);
4953 return error_mark_node
;
4960 new_rhs
= instantiate_type (build_pointer_type (lhstype
),
4961 TREE_OPERAND (rhs
, 0), flags
);
4962 if (new_rhs
== error_mark_node
)
4963 return error_mark_node
;
4965 TREE_TYPE (rhs
) = lhstype
;
4966 TREE_OPERAND (rhs
, 0) = new_rhs
;
4971 rhs
= copy_node (TREE_OPERAND (rhs
, 0));
4972 TREE_TYPE (rhs
) = unknown_type_node
;
4973 return instantiate_type (lhstype
, rhs
, flags
);
4977 tree field
= TREE_OPERAND (rhs
, 1);
4980 r
= instantiate_type (lhstype
, field
, flags
);
4982 if (r
!= error_mark_node
&& TYPE_PTRMEMFUNC_P (lhstype
))
4986 tree t
= TYPE_PTRMEMFUNC_OBJECT_TYPE (lhstype
);
4988 if (TREE_CODE (field
) == OVERLOAD
)
4989 field
= OVL_FUNCTION (field
);
4990 if (TREE_CODE (field
) == FUNCTION_DECL
)
4992 cp_error ("object-dependent reference `%E' can only be used in a call",
4994 cp_error (" to form a pointer to member function, say `&%T::%E'",
4995 t
, DECL_NAME (field
));
4998 cp_error ("object-dependent reference can only be used in a call");
5000 return error_mark_node
;
5007 /* This can happen if we are forming a pointer-to-member for a
5009 rhs
= TREE_OPERAND (rhs
, 1);
5010 my_friendly_assert (TREE_CODE (rhs
) == TEMPLATE_ID_EXPR
, 0);
5014 case TEMPLATE_ID_EXPR
:
5016 resolve_address_of_overloaded_function (lhstype
,
5017 TREE_OPERAND (rhs
, 0),
5019 /*template_only=*/1,
5020 TREE_OPERAND (rhs
, 1));
5024 resolve_address_of_overloaded_function (lhstype
,
5027 /*template_only=*/0,
5028 /*explicit_targs=*/NULL_TREE
);
5031 /* Now we should have a baselink. */
5032 my_friendly_assert (BASELINK_P (rhs
), 990412);
5034 return instantiate_type (lhstype
, TREE_VALUE (rhs
), flags
);
5037 /* This is too hard for now. */
5038 my_friendly_abort (183);
5039 return error_mark_node
;
5044 TREE_OPERAND (rhs
, 0)
5045 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 0), flags
);
5046 if (TREE_OPERAND (rhs
, 0) == error_mark_node
)
5047 return error_mark_node
;
5048 TREE_OPERAND (rhs
, 1)
5049 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), flags
);
5050 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5051 return error_mark_node
;
5053 TREE_TYPE (rhs
) = lhstype
;
5057 case TRUNC_DIV_EXPR
:
5058 case FLOOR_DIV_EXPR
:
5060 case ROUND_DIV_EXPR
:
5062 case TRUNC_MOD_EXPR
:
5063 case FLOOR_MOD_EXPR
:
5065 case ROUND_MOD_EXPR
:
5066 case FIX_ROUND_EXPR
:
5067 case FIX_FLOOR_EXPR
:
5069 case FIX_TRUNC_EXPR
:
5085 case PREINCREMENT_EXPR
:
5086 case PREDECREMENT_EXPR
:
5087 case POSTINCREMENT_EXPR
:
5088 case POSTDECREMENT_EXPR
:
5090 error ("invalid operation on uninstantiated type");
5091 return error_mark_node
;
5093 case TRUTH_AND_EXPR
:
5095 case TRUTH_XOR_EXPR
:
5102 case TRUTH_ANDIF_EXPR
:
5103 case TRUTH_ORIF_EXPR
:
5104 case TRUTH_NOT_EXPR
:
5106 error ("not enough type information");
5107 return error_mark_node
;
5110 if (type_unknown_p (TREE_OPERAND (rhs
, 0)))
5113 error ("not enough type information");
5114 return error_mark_node
;
5116 TREE_OPERAND (rhs
, 1)
5117 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), flags
);
5118 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5119 return error_mark_node
;
5120 TREE_OPERAND (rhs
, 2)
5121 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 2), flags
);
5122 if (TREE_OPERAND (rhs
, 2) == error_mark_node
)
5123 return error_mark_node
;
5125 TREE_TYPE (rhs
) = lhstype
;
5129 TREE_OPERAND (rhs
, 1)
5130 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), flags
);
5131 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5132 return error_mark_node
;
5134 TREE_TYPE (rhs
) = lhstype
;
5138 return instantiate_type (lhstype
, TREE_OPERAND (rhs
, 0), flags
);
5140 case ENTRY_VALUE_EXPR
:
5141 my_friendly_abort (184);
5142 return error_mark_node
;
5145 return error_mark_node
;
5148 my_friendly_abort (185);
5149 return error_mark_node
;
5153 /* Return the name of the virtual function pointer field
5154 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5155 this may have to look back through base types to find the
5156 ultimate field name. (For single inheritance, these could
5157 all be the same name. Who knows for multiple inheritance). */
5160 get_vfield_name (type
)
5163 tree binfo
= TYPE_BINFO (type
);
5166 while (BINFO_BASETYPES (binfo
)
5167 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo
, 0)))
5168 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo
, 0)))
5169 binfo
= BINFO_BASETYPE (binfo
, 0);
5171 type
= BINFO_TYPE (binfo
);
5172 buf
= (char *) alloca (sizeof (VFIELD_NAME_FORMAT
)
5173 + TYPE_NAME_LENGTH (type
) + 2);
5174 sprintf (buf
, VFIELD_NAME_FORMAT
, TYPE_NAME_STRING (type
));
5175 return get_identifier (buf
);
5179 print_class_statistics ()
5181 #ifdef GATHER_STATISTICS
5182 fprintf (stderr
, "convert_harshness = %d\n", n_convert_harshness
);
5183 fprintf (stderr
, "compute_conversion_costs = %d\n", n_compute_conversion_costs
);
5184 fprintf (stderr
, "build_method_call = %d (inner = %d)\n",
5185 n_build_method_call
, n_inner_fields_searched
);
5188 fprintf (stderr
, "vtables = %d; vtable searches = %d\n",
5189 n_vtables
, n_vtable_searches
);
5190 fprintf (stderr
, "vtable entries = %d; vtable elems = %d\n",
5191 n_vtable_entries
, n_vtable_elems
);
5196 /* Push an obstack which is sufficiently long-lived to hold such class
5197 decls that may be cached in the previous_class_values list. The
5198 effect is undone by pop_obstacks. */
5201 maybe_push_cache_obstack ()
5203 static int cache_obstack_initialized
;
5205 if (!cache_obstack_initialized
)
5207 gcc_obstack_init (&class_cache_obstack
);
5208 class_cache_firstobj
5209 = (char*) obstack_finish (&class_cache_obstack
);
5210 cache_obstack_initialized
= 1;
5213 push_obstacks_nochange ();
5214 current_obstack
= &class_cache_obstack
;
5217 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
5218 according to [class]:
5219 The class-name is also inserted
5220 into the scope of the class itself. For purposes of access checking,
5221 the inserted class name is treated as if it were a public member name. */
5224 build_self_reference ()
5226 tree name
= constructor_name (current_class_type
);
5227 tree value
= build_lang_decl (TYPE_DECL
, name
, current_class_type
);
5230 DECL_NONLOCAL (value
) = 1;
5231 DECL_CONTEXT (value
) = current_class_type
;
5232 DECL_CLASS_CONTEXT (value
) = current_class_type
;
5233 DECL_ARTIFICIAL (value
) = 1;
5235 saved_cas
= current_access_specifier
;
5236 current_access_specifier
= access_public_node
;
5237 finish_member_declaration (value
);
5238 current_access_specifier
= saved_cas
;
5241 /* Returns 1 if TYPE contains only padding bytes. */
5244 is_empty_class (type
)
5249 if (type
== error_mark_node
)
5252 if (! IS_AGGR_TYPE (type
))
5256 return CLASSTYPE_SIZE (type
) == integer_zero_node
;
5258 if (TYPE_BINFO_BASETYPES (type
))
5260 t
= TYPE_FIELDS (type
);
5261 while (t
&& TREE_CODE (t
) != FIELD_DECL
)
5263 return (t
== NULL_TREE
);
5266 /* Find the enclosing class of the given NODE. NODE can be a *_DECL or
5267 a *_TYPE node. NODE can also be a local class. */
5270 get_enclosing_class (type
)
5275 while (node
&& TREE_CODE (node
) != NAMESPACE_DECL
)
5277 switch (TREE_CODE_CLASS (TREE_CODE (node
)))
5280 node
= DECL_CONTEXT (node
);
5286 node
= TYPE_CONTEXT (node
);
5290 my_friendly_abort (0);
5296 /* Return 1 if TYPE or one of its enclosing classes is derived from BASE. */
5299 is_base_of_enclosing_class (base
, type
)
5304 if (get_binfo (base
, type
, 0))
5307 type
= get_enclosing_class (type
);
5312 /* Note that NAME was looked up while the current class was being
5313 defined and that the result of that lookup was DECL. */
5316 maybe_note_name_used_in_class (name
, decl
)
5320 splay_tree names_used
;
5322 /* If we're not defining a class, there's nothing to do. */
5323 if (!current_class_type
|| !TYPE_BEING_DEFINED (current_class_type
))
5326 /* If there's already a binding for this NAME, then we don't have
5327 anything to worry about. */
5328 if (IDENTIFIER_CLASS_VALUE (name
))
5331 if (!current_class_stack
[current_class_depth
- 1].names_used
)
5332 current_class_stack
[current_class_depth
- 1].names_used
5333 = splay_tree_new (splay_tree_compare_pointers
, 0, 0);
5334 names_used
= current_class_stack
[current_class_depth
- 1].names_used
;
5336 splay_tree_insert (names_used
,
5337 (splay_tree_key
) name
,
5338 (splay_tree_value
) decl
);
5341 /* Note that NAME was declared (as DECL) in the current class. Check
5342 to see that the declaration is legal. */
5345 note_name_declared_in_class (name
, decl
)
5349 splay_tree names_used
;
5352 /* Look to see if we ever used this name. */
5354 = current_class_stack
[current_class_depth
- 1].names_used
;
5358 n
= splay_tree_lookup (names_used
, (splay_tree_key
) name
);
5361 /* [basic.scope.class]
5363 A name N used in a class S shall refer to the same declaration
5364 in its context and when re-evaluated in the completed scope of
5366 cp_error ("declaration of `%#D'", decl
);
5367 cp_error_at ("changes meaning of `%s' from `%+#D'",
5368 IDENTIFIER_POINTER (DECL_NAME (decl
)),