1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 92, 93, 94, 95, 1996 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. */
34 #define obstack_chunk_alloc xmalloc
35 #define obstack_chunk_free free
37 extern struct obstack permanent_obstack
;
39 /* This is how we tell when two virtual member functions are really the
41 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
43 extern void set_class_shadows
PROTO ((tree
));
45 /* Way of stacking class types. */
46 static tree
*current_class_base
, *current_class_stack
;
47 static int current_class_stacksize
;
48 int current_class_depth
;
52 /* The previous class level. */
53 struct class_level
*level_chain
;
55 /* The class instance variable, as a PARM_DECL. */
57 /* The class instance variable, as an object. */
59 /* The virtual function table pointer
60 for the class instance variable. */
63 /* Name of the current class. */
65 /* Type of the current class. */
68 /* Flags for this class level. */
75 /* The currect_class_ptr is the pointer to the current class.
76 current_class_ref is the actual current class. */
77 tree current_class_ptr
, current_class_ref
;
79 /* The following two can be derived from the previous one */
80 tree current_class_name
; /* IDENTIFIER_NODE: name of current class */
81 tree current_class_type
; /* _TYPE: the type of the current class */
82 tree previous_class_type
; /* _TYPE: the previous type that was a class */
83 tree previous_class_values
; /* TREE_LIST: copy of the class_shadowed list
84 when leaving an outermost class scope. */
88 static tree get_vfield_name
PROTO((tree
));
89 static void finish_struct_anon
PROTO((tree
));
90 static tree build_vbase_pointer
PROTO((tree
, tree
));
91 static int complete_type_p
PROTO((tree
));
92 static int typecode_p
PROTO((tree
, enum tree_code
));
93 static tree build_vtable_entry
PROTO((tree
, tree
));
94 static tree get_vtable_name
PROTO((tree
));
95 static tree get_derived_offset
PROTO((tree
, tree
));
96 static tree get_basefndecls
PROTO((tree
, tree
));
97 static void set_rtti_entry
PROTO((tree
, tree
, tree
));
98 static tree build_vtable
PROTO((tree
, tree
));
99 static void prepare_fresh_vtable
PROTO((tree
, tree
));
100 static void fixup_vtable_deltas1
PROTO((tree
, tree
));
101 static void fixup_vtable_deltas
PROTO((tree
, int, tree
));
102 static void grow_method
PROTO((tree
, tree
*));
103 static void finish_vtbls
PROTO((tree
, int, tree
));
104 static void modify_vtable_entry
PROTO((tree
, tree
, tree
));
105 static tree get_vtable_entry_n
PROTO((tree
, unsigned HOST_WIDE_INT
));
106 static void add_virtual_function
PROTO((tree
*, tree
*, int *, tree
, tree
));
107 static tree delete_duplicate_fields_1
PROTO((tree
, tree
));
108 static void delete_duplicate_fields
PROTO((tree
));
109 static void finish_struct_bits
PROTO((tree
, int));
110 static int alter_access
PROTO((tree
, tree
, tree
));
111 static int overrides
PROTO((tree
, tree
));
112 static int strictly_overrides
PROTO((tree
, tree
));
113 static void merge_overrides
PROTO((tree
, tree
, int, tree
));
114 static void override_one_vtable
PROTO((tree
, tree
, tree
));
115 static void mark_overriders
PROTO((tree
, tree
));
116 static void check_for_override
PROTO((tree
, tree
));
117 static tree maybe_fixup_vptrs
PROTO((tree
, tree
, tree
));
118 static tree get_class_offset_1
PROTO((tree
, tree
, tree
, tree
, tree
));
119 static tree get_class_offset
PROTO((tree
, tree
, tree
, tree
));
120 static void modify_one_vtable
PROTO((tree
, tree
, tree
, tree
));
121 static void modify_all_vtables
PROTO((tree
, tree
, tree
));
122 static void modify_all_direct_vtables
PROTO((tree
, int, tree
, tree
,
124 static void modify_all_indirect_vtables
PROTO((tree
, int, int, tree
,
126 static void build_class_init_list
PROTO((tree
));
127 static int finish_base_struct
PROTO((tree
, struct base_info
*, tree
));
129 /* Way of stacking language names. */
130 tree
*current_lang_base
, *current_lang_stack
;
131 int current_lang_stacksize
;
133 /* Names of languages we recognize. */
134 tree lang_name_c
, lang_name_cplusplus
;
135 tree current_lang_name
;
137 /* When layout out an aggregate type, the size of the
138 basetypes (virtual and non-virtual) is passed to layout_record
140 static tree base_layout_decl
;
142 /* Constants used for access control. */
143 tree access_default_node
; /* 0 */
144 tree access_public_node
; /* 1 */
145 tree access_protected_node
; /* 2 */
146 tree access_private_node
; /* 3 */
147 tree access_default_virtual_node
; /* 4 */
148 tree access_public_virtual_node
; /* 5 */
149 tree access_private_virtual_node
; /* 6 */
151 /* Variables shared between class.c and call.c. */
153 #ifdef GATHER_STATISTICS
155 int n_vtable_entries
= 0;
156 int n_vtable_searches
= 0;
157 int n_vtable_elems
= 0;
158 int n_convert_harshness
= 0;
159 int n_compute_conversion_costs
= 0;
160 int n_build_method_call
= 0;
161 int n_inner_fields_searched
= 0;
164 /* Virtual baseclass things. */
167 build_vbase_pointer (exp
, type
)
172 name
= (char *) alloca (TYPE_NAME_LENGTH (type
) + sizeof (VBASE_NAME
) + 1);
173 sprintf (name
, VBASE_NAME_FORMAT
, TYPE_NAME_STRING (type
));
174 return build_component_ref (exp
, get_identifier (name
), NULL_TREE
, 0);
177 /* Is the type of the EXPR, the complete type of the object?
178 If we are going to be wrong, we must be conservative, and return 0. */
181 complete_type_p (expr
)
184 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
187 switch (TREE_CODE (expr
))
194 expr
= TREE_OPERAND (expr
, 0);
198 if (! TREE_HAS_CONSTRUCTOR (expr
))
200 /* fall through... */
203 if (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
204 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr
)))
205 && TYPE_MAIN_VARIANT (TREE_TYPE (expr
)) == type
)
207 /* fall through... */
210 if (IS_AGGR_TYPE (TREE_TYPE (expr
))
211 && TYPE_MAIN_VARIANT (TREE_TYPE (expr
)) == type
)
213 /* fall through... */
223 /* Build multi-level access to EXPR using hierarchy path PATH.
224 CODE is PLUS_EXPR if we are going with the grain,
225 and MINUS_EXPR if we are not (in which case, we cannot traverse
226 virtual baseclass links).
228 TYPE is the type we want this path to have on exit.
230 ALIAS_THIS is non-zero if EXPR in an expression involving `this'. */
233 build_vbase_path (code
, type
, expr
, path
, alias_this
)
235 tree type
, expr
, path
;
238 register int changed
= 0;
239 tree last
= NULL_TREE
, last_virtual
= NULL_TREE
;
242 tree null_expr
= 0, nonnull_expr
;
244 tree offset
= integer_zero_node
;
246 if (BINFO_INHERITANCE_CHAIN (path
) == NULL_TREE
)
247 return build1 (NOP_EXPR
, type
, expr
);
249 if (nonnull
== 0 && (alias_this
&& flag_this_is_variable
<= 0))
253 /* We need additional logic to convert back to the unconverted type
254 (the static type of the complete object), and then convert back
255 to the type we want. Until that is done, or until we can
256 recognize when that is, we cannot do the short cut logic. (mrs) */
257 fixed_type_p
= resolves_to_fixed_type_p (expr
, &nonnull
);
259 /* Do this, until we can undo any previous conversions. See net35.C
261 fixed_type_p
= complete_type_p (expr
);
264 if (!fixed_type_p
&& TREE_SIDE_EFFECTS (expr
))
265 expr
= save_expr (expr
);
268 if (BINFO_INHERITANCE_CHAIN (path
))
270 tree reverse_path
= NULL_TREE
;
272 push_expression_obstack ();
275 tree r
= copy_node (path
);
276 BINFO_INHERITANCE_CHAIN (r
) = reverse_path
;
278 path
= BINFO_INHERITANCE_CHAIN (path
);
284 basetype
= BINFO_TYPE (path
);
288 if (TREE_VIA_VIRTUAL (path
))
290 last_virtual
= BINFO_TYPE (path
);
291 if (code
== PLUS_EXPR
)
293 changed
= ! fixed_type_p
;
299 /* We already check for ambiguous things in the caller, just
303 tree binfo
= get_binfo (last
, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr
))), 0);
304 nonnull_expr
= convert_pointer_to_real (binfo
, nonnull_expr
);
306 ind
= build_indirect_ref (nonnull_expr
, NULL_PTR
);
307 nonnull_expr
= build_vbase_pointer (ind
, last_virtual
);
309 && (TREE_CODE (type
) == POINTER_TYPE
310 || !flag_assume_nonnull_objects
)
311 && null_expr
== NULL_TREE
)
313 null_expr
= build1 (NOP_EXPR
, build_pointer_type (last_virtual
), integer_zero_node
);
314 expr
= build (COND_EXPR
, build_pointer_type (last_virtual
),
315 build (EQ_EXPR
, boolean_type_node
, expr
,
317 null_expr
, nonnull_expr
);
320 /* else we'll figure out the offset below. */
322 /* Happens in the case of parse errors. */
323 if (nonnull_expr
== error_mark_node
)
324 return error_mark_node
;
328 cp_error ("cannot cast up from virtual baseclass `%T'",
330 return error_mark_node
;
334 path
= BINFO_INHERITANCE_CHAIN (path
);
336 /* LAST is now the last basetype assoc on the path. */
338 /* A pointer to a virtual base member of a non-null object
339 is non-null. Therefore, we only need to test for zeroness once.
340 Make EXPR the canonical expression to deal with here. */
343 TREE_OPERAND (expr
, 2) = nonnull_expr
;
344 TREE_TYPE (expr
) = TREE_TYPE (TREE_OPERAND (expr
, 1))
345 = TREE_TYPE (nonnull_expr
);
350 /* If we go through any virtual base pointers, make sure that
351 casts to BASETYPE from the last virtual base class use
352 the right value for BASETYPE. */
355 tree intype
= TREE_TYPE (TREE_TYPE (expr
));
356 if (TYPE_MAIN_VARIANT (intype
) != BINFO_TYPE (last
))
358 tree binfo
= get_binfo (last
, TYPE_MAIN_VARIANT (intype
), 0);
359 offset
= BINFO_OFFSET (binfo
);
366 offset
= BINFO_OFFSET (binfo_member (last_virtual
,
367 CLASSTYPE_VBASECLASSES (basetype
)));
368 offset
= size_binop (PLUS_EXPR
, offset
, BINFO_OFFSET (last
));
371 offset
= BINFO_OFFSET (last
);
374 if (TREE_INT_CST_LOW (offset
))
376 /* Bash types to make the backend happy. */
377 offset
= cp_convert (type
, offset
);
379 /* This shouldn't be necessary. (mrs) */
380 expr
= build1 (NOP_EXPR
, type
, expr
);
383 /* For multiple inheritance: if `this' can be set by any
384 function, then it could be 0 on entry to any function.
385 Preserve such zeroness here. Otherwise, only in the
386 case of constructors need we worry, and in those cases,
387 it will be zero, or initialized to some valid value to
392 TREE_TYPE (null_expr
) = type
;
394 null_expr
= build1 (NOP_EXPR
, type
, integer_zero_node
);
395 if (TREE_SIDE_EFFECTS (expr
))
396 expr
= save_expr (expr
);
398 return build (COND_EXPR
, type
,
399 build (EQ_EXPR
, boolean_type_node
, expr
, integer_zero_node
),
401 build (code
, type
, expr
, offset
));
403 else return build (code
, type
, expr
, offset
);
406 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
407 be used multiple times in initialization of multiple inheritance. */
410 TREE_TYPE (expr
) = type
;
414 return build1 (NOP_EXPR
, type
, expr
);
417 /* Virtual function things. */
419 /* Build an entry in the virtual function table.
420 DELTA is the offset for the `this' pointer.
421 PFN is an ADDR_EXPR containing a pointer to the virtual function.
422 Note that the index (DELTA2) in the virtual function table
426 build_vtable_entry (delta
, pfn
)
429 if (flag_vtable_thunks
)
431 HOST_WIDE_INT idelta
= TREE_INT_CST_LOW (delta
);
432 if (idelta
&& ! DECL_ABSTRACT_VIRTUAL_P (TREE_OPERAND (pfn
, 0)))
434 pfn
= build1 (ADDR_EXPR
, vtable_entry_type
,
435 make_thunk (pfn
, idelta
));
436 TREE_READONLY (pfn
) = 1;
437 TREE_CONSTANT (pfn
) = 1;
439 #ifdef GATHER_STATISTICS
440 n_vtable_entries
+= 1;
446 extern int flag_huge_objects
;
447 tree elems
= expr_tree_cons (NULL_TREE
, delta
,
448 expr_tree_cons (NULL_TREE
, integer_zero_node
,
449 build_expr_list (NULL_TREE
, pfn
)));
450 tree entry
= build (CONSTRUCTOR
, vtable_entry_type
, NULL_TREE
, elems
);
452 /* DELTA is constructed by `size_int', which means it may be an
453 unsigned quantity on some platforms. Therefore, we cannot use
454 `int_fits_type_p', because when DELTA is really negative,
455 `force_fit_type' will make it look like a very large number. */
457 if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (delta_type_node
))
458 < TREE_INT_CST_LOW (delta
))
459 || (TREE_INT_CST_LOW (delta
)
460 < TREE_INT_CST_LOW (TYPE_MIN_VALUE (delta_type_node
))))
461 if (flag_huge_objects
)
462 sorry ("object size exceeds built-in limit for virtual function table implementation");
464 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
466 TREE_CONSTANT (entry
) = 1;
467 TREE_STATIC (entry
) = 1;
468 TREE_READONLY (entry
) = 1;
470 #ifdef GATHER_STATISTICS
471 n_vtable_entries
+= 1;
478 /* Given an object INSTANCE, return an expression which yields the
479 virtual function vtable element corresponding to INDEX. There are
480 many special cases for INSTANCE which we take care of here, mainly
481 to avoid creating extra tree nodes when we don't have to. */
484 build_vtbl_ref (instance
, idx
)
488 tree basetype
= TREE_TYPE (instance
);
490 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
491 basetype
= TREE_TYPE (basetype
);
493 if (instance
== current_class_ref
)
494 vtbl
= build_indirect_ref (build_vfield_ref (instance
, basetype
),
500 /* Try to figure out what a reference refers to, and
501 access its virtual function table directly. */
502 tree ref
= NULL_TREE
;
504 if (TREE_CODE (instance
) == INDIRECT_REF
505 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance
, 0))) == REFERENCE_TYPE
)
506 ref
= TREE_OPERAND (instance
, 0);
507 else if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
510 if (ref
&& TREE_CODE (ref
) == VAR_DECL
511 && DECL_INITIAL (ref
))
513 tree init
= DECL_INITIAL (ref
);
515 while (TREE_CODE (init
) == NOP_EXPR
516 || TREE_CODE (init
) == NON_LVALUE_EXPR
)
517 init
= TREE_OPERAND (init
, 0);
518 if (TREE_CODE (init
) == ADDR_EXPR
)
520 init
= TREE_OPERAND (init
, 0);
521 if (IS_AGGR_TYPE (TREE_TYPE (init
))
522 && (TREE_CODE (init
) == PARM_DECL
523 || TREE_CODE (init
) == VAR_DECL
))
529 if (IS_AGGR_TYPE (TREE_TYPE (instance
))
530 && (TREE_CODE (instance
) == RESULT_DECL
531 || TREE_CODE (instance
) == PARM_DECL
532 || TREE_CODE (instance
) == VAR_DECL
))
533 vtbl
= TYPE_BINFO_VTABLE (basetype
);
535 vtbl
= build_indirect_ref (build_vfield_ref (instance
, basetype
),
538 assemble_external (vtbl
);
539 aref
= build_array_ref (vtbl
, idx
);
544 /* Given an object INSTANCE, return an expression which yields the
545 virtual function corresponding to INDEX. There are many special
546 cases for INSTANCE which we take care of here, mainly to avoid
547 creating extra tree nodes when we don't have to. */
550 build_vfn_ref (ptr_to_instptr
, instance
, idx
)
551 tree
*ptr_to_instptr
, instance
;
554 tree aref
= build_vtbl_ref (instance
, idx
);
556 /* When using thunks, there is no extra delta, and we get the pfn
558 if (flag_vtable_thunks
)
563 /* Save the intermediate result in a SAVE_EXPR so we don't have to
564 compute each component of the virtual function pointer twice. */
565 if (TREE_CODE (aref
) == INDIRECT_REF
)
566 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
569 = build (PLUS_EXPR
, TREE_TYPE (*ptr_to_instptr
),
571 cp_convert (ptrdiff_type_node
,
572 build_component_ref (aref
, delta_identifier
, NULL_TREE
, 0)));
575 return build_component_ref (aref
, pfn_identifier
, NULL_TREE
, 0);
578 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
579 for the given TYPE. */
582 get_vtable_name (type
)
585 tree type_id
= build_typename_overload (type
);
586 char *buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
)
587 + IDENTIFIER_LENGTH (type_id
) + 2);
588 char *ptr
= IDENTIFIER_POINTER (type_id
);
590 for (i
= 0; ptr
[i
] == OPERATOR_TYPENAME_FORMAT
[i
]; i
++) ;
592 /* We don't take off the numbers; prepare_fresh_vtable uses the
593 DECL_ASSEMBLER_NAME for the type, which includes the number
594 in `3foo'. If we were to pull them off here, we'd end up with
595 something like `_vt.foo.3bar', instead of a uniform definition. */
596 while (ptr
[i
] >= '0' && ptr
[i
] <= '9')
599 sprintf (buf
, VTABLE_NAME_FORMAT
, ptr
+i
);
600 return get_identifier (buf
);
603 /* Return the offset to the main vtable for a given base BINFO. */
606 get_vfield_offset (binfo
)
609 return size_binop (PLUS_EXPR
,
610 size_binop (FLOOR_DIV_EXPR
,
611 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))),
612 size_int (BITS_PER_UNIT
)),
613 BINFO_OFFSET (binfo
));
616 /* Get the offset to the start of the original binfo that we derived
617 this binfo from. If we find TYPE first, return the offset only
618 that far. The shortened search is useful because the this pointer
619 on method calling is expected to point to a DECL_CONTEXT (fndecl)
620 object, and not a baseclass of it. */
623 get_derived_offset (binfo
, type
)
626 tree offset1
= get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo
)));
629 while (BINFO_BASETYPES (binfo
)
630 && (i
=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
))) != -1)
632 tree binfos
= BINFO_BASETYPES (binfo
);
633 if (BINFO_TYPE (binfo
) == type
)
635 binfo
= TREE_VEC_ELT (binfos
, i
);
637 offset2
= get_vfield_offset (TYPE_BINFO (BINFO_TYPE (binfo
)));
638 return size_binop (MINUS_EXPR
, offset1
, offset2
);
641 /* Update the rtti info for this class. */
644 set_rtti_entry (virtuals
, offset
, type
)
645 tree virtuals
, offset
, type
;
650 vfn
= build1 (ADDR_EXPR
, vfunc_ptr_type_node
, get_tinfo_fn (type
));
652 vfn
= build1 (NOP_EXPR
, vfunc_ptr_type_node
, size_zero_node
);
653 TREE_CONSTANT (vfn
) = 1;
655 if (! flag_vtable_thunks
)
656 TREE_VALUE (virtuals
) = build_vtable_entry (offset
, vfn
);
659 tree voff
= build1 (NOP_EXPR
, vfunc_ptr_type_node
, offset
);
660 TREE_CONSTANT (voff
) = 1;
662 TREE_VALUE (virtuals
) = build_vtable_entry (size_zero_node
, voff
);
664 /* The second slot is for the tdesc pointer when thunks are used. */
665 TREE_VALUE (TREE_CHAIN (virtuals
))
666 = build_vtable_entry (size_zero_node
, vfn
);
670 /* Build a virtual function for type TYPE.
671 If BINFO is non-NULL, build the vtable starting with the initial
672 approximation that it is the same as the one which is the head of
673 the association list. */
676 build_vtable (binfo
, type
)
679 tree name
= get_vtable_name (type
);
686 virtuals
= copy_list (BINFO_VIRTUALS (binfo
));
687 decl
= build_decl (VAR_DECL
, name
, TREE_TYPE (BINFO_VTABLE (binfo
)));
689 /* Now do rtti stuff. */
690 offset
= get_derived_offset (TYPE_BINFO (type
), NULL_TREE
);
691 offset
= size_binop (MINUS_EXPR
, size_zero_node
, offset
);
692 set_rtti_entry (virtuals
, offset
, type
);
696 virtuals
= NULL_TREE
;
697 decl
= build_decl (VAR_DECL
, name
, void_type_node
);
700 #ifdef GATHER_STATISTICS
702 n_vtable_elems
+= list_length (virtuals
);
705 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
706 import_export_vtable (decl
, type
, 0);
708 IDENTIFIER_GLOBAL_VALUE (name
) = decl
= pushdecl_top_level (decl
);
709 /* Initialize the association list for this type, based
710 on our first approximation. */
711 TYPE_BINFO_VTABLE (type
) = decl
;
712 TYPE_BINFO_VIRTUALS (type
) = virtuals
;
714 DECL_ARTIFICIAL (decl
) = 1;
715 TREE_STATIC (decl
) = 1;
716 #ifndef WRITABLE_VTABLES
717 /* Make them READONLY by default. (mrs) */
718 TREE_READONLY (decl
) = 1;
720 /* At one time the vtable info was grabbed 2 words at a time. This
721 fails on sparc unless you have 8-byte alignment. (tiemann) */
722 DECL_ALIGN (decl
) = MAX (TYPE_ALIGN (double_type_node
),
725 /* Why is this conditional? (mrs) */
726 if (binfo
&& write_virtuals
>= 0)
727 DECL_VIRTUAL_P (decl
) = 1;
728 DECL_CONTEXT (decl
) = type
;
730 binfo
= TYPE_BINFO (type
);
731 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
735 extern tree signed_size_zero_node
;
737 /* Give TYPE a new virtual function table which is initialized
738 with a skeleton-copy of its original initialization. The only
739 entry that changes is the `delta' entry, so we can really
740 share a lot of structure.
742 FOR_TYPE is the derived type which caused this table to
745 BINFO is the type association which provided TYPE for FOR_TYPE.
747 The order in which vtables are built (by calling this function) for
748 an object must remain the same, otherwise a binary incompatibility
752 prepare_fresh_vtable (binfo
, for_type
)
753 tree binfo
, for_type
;
756 tree orig_decl
= BINFO_VTABLE (binfo
);
769 basetype
= TYPE_MAIN_VARIANT (BINFO_TYPE (binfo
));
771 buf2
= TYPE_ASSEMBLER_NAME_STRING (basetype
);
772 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1;
774 /* We know that the vtable that we are going to create doesn't exist
775 yet in the global namespace, and when we finish, it will be
776 pushed into the global namespace. In complex MI hierarchies, we
777 have to loop while the name we are thinking of adding is globally
778 defined, adding more name components to the vtable name as we
779 loop, until the name is unique. This is because in complex MI
780 cases, we might have the same base more than once. This means
781 that the order in which this function is called for vtables must
782 remain the same, otherwise binary compatibility can be
787 char *buf1
= (char *) alloca (TYPE_ASSEMBLER_NAME_LENGTH (for_type
)
791 sprintf (buf1
, "%s%c%s", TYPE_ASSEMBLER_NAME_STRING (for_type
), joiner
,
793 buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
) + strlen (buf1
) + 1);
794 sprintf (buf
, VTABLE_NAME_FORMAT
, buf1
);
795 name
= get_identifier (buf
);
797 /* If this name doesn't clash, then we can use it, otherwise
798 we add more to the name until it is unique. */
800 if (! IDENTIFIER_GLOBAL_VALUE (name
))
803 /* Set values for next loop through, if the name isn't unique. */
805 path
= BINFO_INHERITANCE_CHAIN (path
);
807 /* We better not run out of stuff to make it unique. */
808 my_friendly_assert (path
!= NULL_TREE
, 368);
810 basetype
= TYPE_MAIN_VARIANT (BINFO_TYPE (path
));
812 if (for_type
== basetype
)
814 /* If we run out of basetypes in the path, we have already
815 found created a vtable with that name before, we now
816 resort to tacking on _%d to distinguish them. */
818 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1 + i
+ 1 + 3;
819 buf1
= (char *) alloca (i
);
821 sprintf (buf1
, "%s%c%s%c%d",
822 TYPE_ASSEMBLER_NAME_STRING (basetype
), joiner
,
824 buf
= (char *) alloca (strlen (VTABLE_NAME_FORMAT
)
825 + strlen (buf1
) + 1);
826 sprintf (buf
, VTABLE_NAME_FORMAT
, buf1
);
827 name
= get_identifier (buf
);
829 /* If this name doesn't clash, then we can use it,
830 otherwise we add something different to the name until
832 } while (++j
<= 999 && IDENTIFIER_GLOBAL_VALUE (name
));
834 /* Hey, they really like MI don't they? Increase the 3
835 above to 6, and the 999 to 999999. :-) */
836 my_friendly_assert (j
<= 999, 369);
841 i
= TYPE_ASSEMBLER_NAME_LENGTH (basetype
) + 1 + i
;
842 new_buf2
= (char *) alloca (i
);
843 sprintf (new_buf2
, "%s%c%s",
844 TYPE_ASSEMBLER_NAME_STRING (basetype
), joiner
, buf2
);
848 new_decl
= build_decl (VAR_DECL
, name
, TREE_TYPE (orig_decl
));
849 /* Remember which class this vtable is really for. */
850 DECL_CONTEXT (new_decl
) = for_type
;
852 DECL_ARTIFICIAL (new_decl
) = 1;
853 TREE_STATIC (new_decl
) = 1;
854 BINFO_VTABLE (binfo
) = pushdecl_top_level (new_decl
);
855 DECL_VIRTUAL_P (new_decl
) = 1;
856 #ifndef WRITABLE_VTABLES
857 /* Make them READONLY by default. (mrs) */
858 TREE_READONLY (new_decl
) = 1;
860 DECL_ALIGN (new_decl
) = DECL_ALIGN (orig_decl
);
862 /* Make fresh virtual list, so we can smash it later. */
863 BINFO_VIRTUALS (binfo
) = copy_list (BINFO_VIRTUALS (binfo
));
865 if (TREE_VIA_VIRTUAL (binfo
))
867 tree binfo1
= binfo_member (BINFO_TYPE (binfo
),
868 CLASSTYPE_VBASECLASSES (for_type
));
870 /* XXX - This should never happen, if it does, the caller should
871 ensure that the binfo is from for_type's binfos, not from any
872 base type's. We can remove all this code after a while. */
874 warning ("internal inconsistency: binfo offset error for rtti");
876 offset
= BINFO_OFFSET (binfo1
);
879 offset
= BINFO_OFFSET (binfo
);
881 set_rtti_entry (BINFO_VIRTUALS (binfo
),
882 size_binop (MINUS_EXPR
, signed_size_zero_node
, offset
),
885 #ifdef GATHER_STATISTICS
887 n_vtable_elems
+= list_length (BINFO_VIRTUALS (binfo
));
890 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
891 import_export_vtable (new_decl
, for_type
, 0);
893 if (TREE_VIA_VIRTUAL (binfo
))
894 my_friendly_assert (binfo
== binfo_member (BINFO_TYPE (binfo
),
895 CLASSTYPE_VBASECLASSES (current_class_type
)),
897 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
901 /* Access the virtual function table entry that logically
902 contains BASE_FNDECL. VIRTUALS is the virtual function table's
903 initializer. We can run off the end, when dealing with virtual
904 destructors in MI situations, return NULL_TREE in that case. */
907 get_vtable_entry (virtuals
, base_fndecl
)
908 tree virtuals
, base_fndecl
;
910 unsigned HOST_WIDE_INT n
= (HOST_BITS_PER_WIDE_INT
>= BITS_PER_WORD
911 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
))
912 & (((unsigned HOST_WIDE_INT
)1<<(BITS_PER_WORD
-1))-1))
913 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
)));
915 #ifdef GATHER_STATISTICS
916 n_vtable_searches
+= n
;
919 while (n
> 0 && virtuals
)
922 virtuals
= TREE_CHAIN (virtuals
);
928 /* Put new entry ENTRY into virtual function table initializer
931 Also update DECL_VINDEX (FNDECL). */
934 modify_vtable_entry (old_entry_in_list
, new_entry
, fndecl
)
935 tree old_entry_in_list
, new_entry
, fndecl
;
937 tree base_fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list
)), 0);
940 cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (base_fndecl
),
941 DECL_ASSEMBLER_NAME (fndecl
));
943 TREE_VALUE (old_entry_in_list
) = new_entry
;
945 /* Now assign virtual dispatch information, if unset. */
946 /* We can dispatch this, through any overridden base function. */
947 if (TREE_CODE (DECL_VINDEX (fndecl
)) != INTEGER_CST
)
949 DECL_VINDEX (fndecl
) = DECL_VINDEX (base_fndecl
);
950 DECL_CONTEXT (fndecl
) = DECL_CONTEXT (base_fndecl
);
954 /* Access the virtual function table entry N. VIRTUALS is the virtual
955 function table's initializer. */
958 get_vtable_entry_n (virtuals
, n
)
960 unsigned HOST_WIDE_INT n
;
965 virtuals
= TREE_CHAIN (virtuals
);
970 /* Add a virtual function to all the appropriate vtables for the class
971 T. DECL_VINDEX(X) should be error_mark_node, if we want to
972 allocate a new slot in our table. If it is error_mark_node, we
973 know that no other function from another vtable is overridden by X.
974 HAS_VIRTUAL keeps track of how many virtuals there are in our main
975 vtable for the type, and we build upon the PENDING_VIRTUALS list
979 add_virtual_function (pv
, phv
, has_virtual
, fndecl
, t
)
983 tree t
; /* Structure type. */
985 tree pending_virtuals
= *pv
;
986 tree pending_hard_virtuals
= *phv
;
988 /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
989 convert to void *. Make such a conversion here. */
990 tree vfn
= build1 (ADDR_EXPR
, vfunc_ptr_type_node
, fndecl
);
991 TREE_CONSTANT (vfn
) = 1;
994 if (current_class_type
== 0)
995 cp_warning ("internal problem, current_class_type is zero when adding `%D', please report",
997 if (current_class_type
&& t
!= current_class_type
)
998 cp_warning ("internal problem, current_class_type differs when adding `%D', please report",
1002 /* If the virtual function is a redefinition of a prior one,
1003 figure out in which base class the new definition goes,
1004 and if necessary, make a fresh virtual function table
1005 to hold that entry. */
1006 if (DECL_VINDEX (fndecl
) == error_mark_node
)
1010 /* We remember that this was the base sub-object for rtti. */
1011 CLASSTYPE_RTTI (t
) = t
;
1013 /* If we are using thunks, use two slots at the front, one
1014 for the offset pointer, one for the tdesc pointer. */
1015 if (*has_virtual
== 0 && flag_vtable_thunks
)
1020 /* Build a new INT_CST for this DECL_VINDEX. */
1022 static tree index_table
[256];
1024 /* We skip a slot for the offset/tdesc entry. */
1025 int i
= ++(*has_virtual
);
1027 if (i
>= 256 || index_table
[i
] == 0)
1029 idx
= build_int_2 (i
, 0);
1031 index_table
[i
] = idx
;
1034 idx
= index_table
[i
];
1036 /* Now assign virtual dispatch information. */
1037 DECL_VINDEX (fndecl
) = idx
;
1038 DECL_CONTEXT (fndecl
) = t
;
1040 entry
= build_vtable_entry (integer_zero_node
, vfn
);
1041 pending_virtuals
= tree_cons (DECL_VINDEX (fndecl
), entry
, pending_virtuals
);
1043 /* Might already be INTEGER_CST if declared twice in class. We will
1044 give error later or we've already given it. */
1045 else if (TREE_CODE (DECL_VINDEX (fndecl
)) != INTEGER_CST
)
1047 /* Need an entry in some other virtual function table.
1048 Deal with this after we have laid out our virtual base classes. */
1049 pending_hard_virtuals
= temp_tree_cons (fndecl
, vfn
, pending_hard_virtuals
);
1051 *pv
= pending_virtuals
;
1052 *phv
= pending_hard_virtuals
;
1055 /* Obstack on which to build the vector of class methods. */
1056 struct obstack class_obstack
;
1057 extern struct obstack
*current_obstack
;
1059 /* Add method METHOD to class TYPE. This is used when a method
1060 has been defined which did not initially appear in the class definition,
1061 and helps cut down on spurious error messages.
1063 FIELDS is the entry in the METHOD_VEC vector entry of the class type where
1064 the method should be added. */
1067 add_method (type
, fields
, method
)
1068 tree type
, *fields
, method
;
1070 /* We must make a copy of METHOD here, since we must be sure that
1071 we have exclusive title to this method's DECL_CHAIN. */
1074 push_obstacks (&permanent_obstack
, &permanent_obstack
);
1076 decl
= copy_node (method
);
1077 if (DECL_RTL (decl
) == 0
1078 && (!processing_template_decl
1079 || !uses_template_parms (decl
)))
1081 make_function_rtl (decl
);
1082 DECL_RTL (method
) = DECL_RTL (decl
);
1086 if (fields
&& *fields
)
1088 /* Take care not to hide destructor. */
1089 DECL_CHAIN (decl
) = DECL_CHAIN (*fields
);
1090 DECL_CHAIN (*fields
) = decl
;
1092 else if (CLASSTYPE_METHOD_VEC (type
) == 0)
1094 tree method_vec
= make_node (TREE_VEC
);
1095 if (TYPE_IDENTIFIER (type
) == DECL_NAME (decl
))
1097 /* ??? Is it possible for there to have been enough room in the
1098 current chunk for the tree_vec structure but not a tree_vec
1099 plus a tree*? Will this work in that case? */
1100 obstack_free (current_obstack
, method_vec
);
1101 obstack_blank (current_obstack
, sizeof (struct tree_vec
) + sizeof (tree
*));
1102 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)))
1103 TREE_VEC_ELT (method_vec
, 1) = decl
;
1105 TREE_VEC_ELT (method_vec
, 0) = decl
;
1106 TREE_VEC_LENGTH (method_vec
) = 2;
1110 /* ??? Is it possible for there to have been enough room in the
1111 current chunk for the tree_vec structure but not a tree_vec
1112 plus a tree*? Will this work in that case? */
1113 obstack_free (current_obstack
, method_vec
);
1114 obstack_blank (current_obstack
, sizeof (struct tree_vec
) + 2*sizeof (tree
*));
1115 TREE_VEC_ELT (method_vec
, 2) = decl
;
1116 TREE_VEC_LENGTH (method_vec
) = 3;
1117 obstack_finish (current_obstack
);
1119 CLASSTYPE_METHOD_VEC (type
) = method_vec
;
1123 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1124 int len
= TREE_VEC_LENGTH (method_vec
);
1126 /* Adding a new ctor or dtor. This is easy because our
1127 METHOD_VEC always has a slot for such entries. */
1128 if (TYPE_IDENTIFIER (type
) == DECL_NAME (decl
))
1130 int idx
= !!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
));
1131 /* TREE_VEC_ELT (method_vec, idx) = decl; */
1132 if (decl
!= TREE_VEC_ELT (method_vec
, idx
))
1134 DECL_CHAIN (decl
) = TREE_VEC_ELT (method_vec
, idx
);
1135 TREE_VEC_ELT (method_vec
, idx
) = decl
;
1140 /* This is trickier. We try to extend the TREE_VEC in-place,
1141 but if that does not work, we copy all its data to a new
1142 TREE_VEC that's large enough. */
1143 struct obstack
*ob
= &class_obstack
;
1144 tree
*end
= (tree
*)obstack_next_free (ob
);
1146 if (end
!= TREE_VEC_END (method_vec
))
1148 ob
= current_obstack
;
1149 TREE_VEC_LENGTH (method_vec
) += 1;
1150 TREE_VEC_ELT (method_vec
, len
) = NULL_TREE
;
1151 method_vec
= copy_node (method_vec
);
1152 TREE_VEC_LENGTH (method_vec
) -= 1;
1156 tree tmp_vec
= (tree
) obstack_base (ob
);
1157 if (obstack_room (ob
) < sizeof (tree
))
1159 obstack_blank (ob
, sizeof (struct tree_common
)
1160 + tree_code_length
[(int) TREE_VEC
]
1162 + len
* sizeof (tree
));
1163 tmp_vec
= (tree
) obstack_base (ob
);
1164 bcopy ((char *) method_vec
, (char *) tmp_vec
,
1165 (sizeof (struct tree_common
)
1166 + tree_code_length
[(int) TREE_VEC
] * sizeof (char *)
1167 + (len
-1) * sizeof (tree
)));
1168 method_vec
= tmp_vec
;
1171 obstack_blank (ob
, sizeof (tree
));
1174 obstack_finish (ob
);
1175 TREE_VEC_ELT (method_vec
, len
) = decl
;
1176 TREE_VEC_LENGTH (method_vec
) = len
+ 1;
1177 CLASSTYPE_METHOD_VEC (type
) = method_vec
;
1179 if (TYPE_BINFO_BASETYPES (type
) && CLASSTYPE_BASELINK_VEC (type
))
1181 /* ??? May be better to know whether these can be extended? */
1182 tree baselink_vec
= CLASSTYPE_BASELINK_VEC (type
);
1184 TREE_VEC_LENGTH (baselink_vec
) += 1;
1185 CLASSTYPE_BASELINK_VEC (type
) = copy_node (baselink_vec
);
1186 TREE_VEC_LENGTH (baselink_vec
) -= 1;
1188 TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), len
) = 0;
1192 DECL_CONTEXT (decl
) = type
;
1193 DECL_CLASS_CONTEXT (decl
) = type
;
1198 /* Subroutines of finish_struct. */
1200 /* Look through the list of fields for this struct, deleting
1201 duplicates as we go. This must be recursive to handle
1204 FIELD is the field which may not appear anywhere in FIELDS.
1205 FIELD_PTR, if non-null, is the starting point at which
1206 chained deletions may take place.
1207 The value returned is the first acceptable entry found
1210 Note that anonymous fields which are not of UNION_TYPE are
1211 not duplicates, they are just anonymous fields. This happens
1212 when we have unnamed bitfields, for example. */
1215 delete_duplicate_fields_1 (field
, fields
)
1220 if (DECL_NAME (field
) == 0)
1222 if (TREE_CODE (TREE_TYPE (field
)) != UNION_TYPE
)
1225 for (x
= TYPE_FIELDS (TREE_TYPE (field
)); x
; x
= TREE_CHAIN (x
))
1226 fields
= delete_duplicate_fields_1 (x
, fields
);
1231 for (x
= fields
; x
; prev
= x
, x
= TREE_CHAIN (x
))
1233 if (DECL_NAME (x
) == 0)
1235 if (TREE_CODE (TREE_TYPE (x
)) != UNION_TYPE
)
1237 TYPE_FIELDS (TREE_TYPE (x
))
1238 = delete_duplicate_fields_1 (field
, TYPE_FIELDS (TREE_TYPE (x
)));
1239 if (TYPE_FIELDS (TREE_TYPE (x
)) == 0)
1242 fields
= TREE_CHAIN (fields
);
1244 TREE_CHAIN (prev
) = TREE_CHAIN (x
);
1249 if (DECL_NAME (field
) == DECL_NAME (x
))
1251 if (TREE_CODE (field
) == CONST_DECL
1252 && TREE_CODE (x
) == CONST_DECL
)
1253 cp_error_at ("duplicate enum value `%D'", x
);
1254 else if (TREE_CODE (field
) == CONST_DECL
1255 || TREE_CODE (x
) == CONST_DECL
)
1256 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1258 else if (TREE_CODE (field
) == TYPE_DECL
1259 && TREE_CODE (x
) == TYPE_DECL
)
1261 if (TREE_TYPE (field
) == TREE_TYPE (x
))
1263 cp_error_at ("duplicate nested type `%D'", x
);
1265 else if (TREE_CODE (field
) == TYPE_DECL
1266 || TREE_CODE (x
) == TYPE_DECL
)
1268 /* Hide tag decls. */
1269 if ((TREE_CODE (field
) == TYPE_DECL
1270 && DECL_ARTIFICIAL (field
))
1271 || (TREE_CODE (x
) == TYPE_DECL
1272 && DECL_ARTIFICIAL (x
)))
1274 cp_error_at ("duplicate field `%D' (as type and non-type)",
1278 cp_error_at ("duplicate member `%D'", x
);
1280 fields
= TREE_CHAIN (fields
);
1282 TREE_CHAIN (prev
) = TREE_CHAIN (x
);
1291 delete_duplicate_fields (fields
)
1295 for (x
= fields
; x
&& TREE_CHAIN (x
); x
= TREE_CHAIN (x
))
1296 TREE_CHAIN (x
) = delete_duplicate_fields_1 (x
, TREE_CHAIN (x
));
1299 /* Change the access of FDECL to ACCESS in T.
1300 Return 1 if change was legit, otherwise return 0. */
1303 alter_access (t
, fdecl
, access
)
1308 tree elem
= purpose_member (t
, DECL_ACCESS (fdecl
));
1309 if (elem
&& TREE_VALUE (elem
) != access
)
1311 if (TREE_CODE (TREE_TYPE (fdecl
)) == FUNCTION_DECL
)
1313 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl
));
1316 error ("conflicting access specifications for field `%s', ignored",
1317 IDENTIFIER_POINTER (DECL_NAME (fdecl
)));
1319 else if (TREE_PRIVATE (fdecl
))
1321 if (access
!= access_private_node
)
1322 cp_error_at ("cannot make private `%D' non-private", fdecl
);
1325 else if (TREE_PROTECTED (fdecl
))
1327 if (access
!= access_protected_node
)
1328 cp_error_at ("cannot make protected `%D' non-protected", fdecl
);
1331 /* ARM 11.3: an access declaration may not be used to restrict access
1332 to a member that is accessible in the base class. */
1333 else if (access
!= access_public_node
)
1334 cp_error_at ("cannot reduce access of public member `%D'", fdecl
);
1335 else if (elem
== NULL_TREE
)
1338 DECL_ACCESS (fdecl
) = tree_cons (t
, access
, DECL_ACCESS (fdecl
));
1344 /* If FOR_TYPE needs to reinitialize virtual function table pointers
1345 for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
1346 Returns BASE_INIT_LIST appropriately modified. */
1349 maybe_fixup_vptrs (for_type
, binfo
, base_init_list
)
1350 tree for_type
, binfo
, base_init_list
;
1352 /* Now reinitialize any slots that don't fall under our virtual
1353 function table pointer. */
1354 tree vfields
= CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
));
1357 tree basetype
= VF_NORMAL_VALUE (vfields
)
1358 ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields
))
1359 : VF_BASETYPE_VALUE (vfields
);
1361 tree base_binfo
= get_binfo (basetype
, for_type
, 0);
1362 /* Punt until this is implemented. */
1363 if (1 /* BINFO_MODIFIED (base_binfo) */)
1365 tree base_offset
= get_vfield_offset (base_binfo
);
1366 if (! tree_int_cst_equal (base_offset
, get_vfield_offset (TYPE_BINFO (for_type
)))
1367 && ! tree_int_cst_equal (base_offset
, get_vfield_offset (binfo
)))
1368 base_init_list
= tree_cons (error_mark_node
, base_binfo
,
1371 vfields
= TREE_CHAIN (vfields
);
1373 return base_init_list
;
1376 /* If TYPE does not have a constructor, then the compiler must
1377 manually deal with all of the initialization this type requires.
1379 If a base initializer exists only to fill in the virtual function
1380 table pointer, then we mark that fact with the TREE_VIRTUAL bit.
1381 This way, we avoid multiple initializations of the same field by
1382 each virtual function table up the class hierarchy.
1384 Virtual base class pointers are not initialized here. They are
1385 initialized only at the "top level" of object creation. If we
1386 initialized them here, we would have to skip a lot of work. */
1389 build_class_init_list (type
)
1392 tree base_init_list
= NULL_TREE
;
1393 tree member_init_list
= NULL_TREE
;
1395 /* Since we build member_init_list and base_init_list using
1396 tree_cons, backwards fields the all through work. */
1398 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (type
));
1399 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1401 for (x
= TYPE_FIELDS (type
); x
; x
= TREE_CHAIN (x
))
1403 if (TREE_CODE (x
) != FIELD_DECL
)
1406 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x
))
1407 || DECL_INITIAL (x
) != NULL_TREE
)
1408 member_init_list
= tree_cons (x
, type
, member_init_list
);
1410 member_init_list
= nreverse (member_init_list
);
1412 /* We will end up doing this last. Need special marker
1413 to avoid infinite regress. */
1414 if (TYPE_VIRTUAL_P (type
))
1416 base_init_list
= build_tree_list (error_mark_node
, TYPE_BINFO (type
));
1417 if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type
) == 0)
1418 TREE_VALUE (base_init_list
) = NULL_TREE
;
1419 TREE_ADDRESSABLE (base_init_list
) = 1;
1422 /* Each base class which needs to have initialization
1423 of some kind gets to make such requests known here. */
1424 for (i
= n_baseclasses
-1; i
>= 0; i
--)
1426 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1429 /* Don't initialize virtual baseclasses this way. */
1430 if (TREE_VIA_VIRTUAL (base_binfo
))
1433 if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (base_binfo
)))
1435 /* ...and the last shall come first... */
1436 base_init_list
= maybe_fixup_vptrs (type
, base_binfo
, base_init_list
);
1437 base_init_list
= tree_cons (NULL_TREE
, base_binfo
, base_init_list
);
1441 if ((blist
= CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (base_binfo
))) == NULL_TREE
)
1442 /* Nothing to initialize. */
1446 base_init_list
= maybe_fixup_vptrs (type
, base_binfo
, base_init_list
);
1448 /* This is normally true for single inheritance.
1449 The win is we can shrink the chain of initializations
1450 to be done by only converting to the actual type
1451 we are interested in. */
1452 if (TREE_VALUE (blist
)
1453 && TREE_CODE (TREE_VALUE (blist
)) == TREE_VEC
1454 && tree_int_cst_equal (BINFO_OFFSET (base_binfo
),
1455 BINFO_OFFSET (TREE_VALUE (blist
))))
1459 /* Does it do more than just fill in a
1460 virtual function table pointer? */
1461 if (! TREE_ADDRESSABLE (blist
))
1462 base_init_list
= build_tree_list (blist
, base_init_list
);
1463 /* Can we get by just with the virtual function table
1464 pointer that it fills in? */
1465 else if (TREE_ADDRESSABLE (base_init_list
)
1466 && TREE_VALUE (base_init_list
) == 0)
1467 base_init_list
= blist
;
1468 /* Maybe, but it is not obvious as the previous case. */
1469 else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type
))
1471 tree last
= tree_last (base_init_list
);
1472 while (TREE_VALUE (last
)
1473 && TREE_CODE (TREE_VALUE (last
)) == TREE_LIST
)
1474 last
= tree_last (TREE_VALUE (last
));
1475 if (TREE_VALUE (last
) == 0)
1476 base_init_list
= build_tree_list (blist
, base_init_list
);
1480 base_init_list
= blist
;
1484 /* The function expand_aggr_init knows how to do the
1485 initialization of `basetype' without getting
1486 an explicit `blist'. */
1488 base_init_list
= tree_cons (NULL_TREE
, base_binfo
, base_init_list
);
1490 base_init_list
= CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo
));
1495 if (member_init_list
)
1496 CLASSTYPE_BASE_INIT_LIST (type
) = build_tree_list (base_init_list
, member_init_list
);
1498 CLASSTYPE_BASE_INIT_LIST (type
) = base_init_list
;
1499 else if (member_init_list
)
1500 CLASSTYPE_BASE_INIT_LIST (type
) = member_init_list
;
1506 int max_has_virtual
;
1511 char cant_have_default_ctor
;
1512 char cant_have_const_ctor
;
1513 char no_const_asn_ref
;
1516 /* Record information about type T derived from its base classes.
1517 Store most of that information in T itself, and place the
1518 remaining information in the struct BASE_INFO.
1520 Propagate basetype offsets throughout the lattice. Note that the
1521 lattice topped by T is really a pair: it's a DAG that gives the
1522 structure of the derivation hierarchy, and it's a list of the
1523 virtual baseclasses that appear anywhere in the DAG. When a vbase
1524 type appears in the DAG, it's offset is 0, and it's children start
1525 their offsets from that point. When a vbase type appears in the list,
1526 its offset is the offset it has in the hierarchy, and its children's
1527 offsets include that offset in theirs.
1529 Returns the index of the first base class to have virtual functions,
1530 or -1 if no such base class.
1532 Note that at this point TYPE_BINFO (t) != t_binfo. */
1535 finish_base_struct (t
, b
, t_binfo
)
1537 struct base_info
*b
;
1540 tree binfos
= BINFO_BASETYPES (t_binfo
);
1541 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1542 int first_vfn_base_index
= -1;
1543 bzero ((char *) b
, sizeof (struct base_info
));
1545 for (i
= 0; i
< n_baseclasses
; i
++)
1547 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1548 tree basetype
= BINFO_TYPE (base_binfo
);
1550 /* If the type of basetype is incomplete, then
1551 we already complained about that fact
1552 (and we should have fixed it up as well). */
1553 if (TYPE_SIZE (basetype
) == 0)
1556 /* The base type is of incomplete type. It is
1557 probably best to pretend that it does not
1559 if (i
== n_baseclasses
-1)
1560 TREE_VEC_ELT (binfos
, i
) = NULL_TREE
;
1561 TREE_VEC_LENGTH (binfos
) -= 1;
1563 for (j
= i
; j
+1 < n_baseclasses
; j
++)
1564 TREE_VEC_ELT (binfos
, j
) = TREE_VEC_ELT (binfos
, j
+1);
1567 if (! TYPE_HAS_CONST_INIT_REF (basetype
))
1568 b
->cant_have_const_ctor
= 1;
1570 if (TYPE_HAS_CONSTRUCTOR (basetype
)
1571 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype
))
1573 b
->cant_have_default_ctor
= 1;
1574 if (! TYPE_HAS_CONSTRUCTOR (t
))
1576 cp_pedwarn ("base `%T' with only non-default constructor",
1578 cp_pedwarn ("in class without a constructor");
1582 if (TYPE_HAS_ASSIGN_REF (basetype
)
1583 && !TYPE_HAS_CONST_ASSIGN_REF (basetype
))
1584 b
->no_const_asn_ref
= 1;
1586 b
->n_ancestors
+= CLASSTYPE_N_SUPERCLASSES (basetype
);
1587 TYPE_NEEDS_CONSTRUCTING (t
) |= TYPE_NEEDS_CONSTRUCTING (basetype
);
1588 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_NEEDS_DESTRUCTOR (basetype
);
1589 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype
);
1590 TYPE_HAS_COMPLEX_INIT_REF (t
) |= TYPE_HAS_COMPLEX_INIT_REF (basetype
);
1592 TYPE_OVERLOADS_CALL_EXPR (t
) |= TYPE_OVERLOADS_CALL_EXPR (basetype
);
1593 TYPE_OVERLOADS_ARRAY_REF (t
) |= TYPE_OVERLOADS_ARRAY_REF (basetype
);
1594 TYPE_OVERLOADS_ARROW (t
) |= TYPE_OVERLOADS_ARROW (basetype
);
1596 if (! TREE_VIA_VIRTUAL (base_binfo
)
1597 && BINFO_BASETYPES (base_binfo
))
1599 tree base_binfos
= BINFO_BASETYPES (base_binfo
);
1600 tree chain
= NULL_TREE
;
1603 /* Now unshare the structure beneath BASE_BINFO. */
1604 for (j
= TREE_VEC_LENGTH (base_binfos
)-1;
1607 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, j
);
1608 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
1609 TREE_VEC_ELT (base_binfos
, j
)
1610 = make_binfo (BINFO_OFFSET (base_base_binfo
),
1612 BINFO_VTABLE (base_base_binfo
),
1613 BINFO_VIRTUALS (base_base_binfo
),
1615 chain
= TREE_VEC_ELT (base_binfos
, j
);
1616 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
1617 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
1618 BINFO_INHERITANCE_CHAIN (chain
) = base_binfo
;
1621 /* Completely unshare potentially shared data, and
1622 update what is ours. */
1623 propagate_binfo_offsets (base_binfo
, BINFO_OFFSET (base_binfo
));
1626 if (! TREE_VIA_VIRTUAL (base_binfo
))
1627 CLASSTYPE_N_SUPERCLASSES (t
) += 1;
1629 if (TYPE_VIRTUAL_P (basetype
))
1631 /* Ensure that this is set from at least a virtual base
1633 if (b
->rtti
== NULL_TREE
)
1634 b
->rtti
= CLASSTYPE_RTTI (basetype
);
1636 /* Don't borrow virtuals from virtual baseclasses. */
1637 if (TREE_VIA_VIRTUAL (base_binfo
))
1640 if (first_vfn_base_index
< 0)
1643 first_vfn_base_index
= i
;
1645 /* Update these two, now that we know what vtable we are
1646 going to extend. This is so that we can add virtual
1647 functions, and override them properly. */
1648 BINFO_VTABLE (t_binfo
) = TYPE_BINFO_VTABLE (basetype
);
1649 BINFO_VIRTUALS (t_binfo
) = TYPE_BINFO_VIRTUALS (basetype
);
1650 b
->has_virtual
= CLASSTYPE_VSIZE (basetype
);
1651 b
->vfield
= CLASSTYPE_VFIELD (basetype
);
1652 b
->vfields
= copy_list (CLASSTYPE_VFIELDS (basetype
));
1653 vfields
= b
->vfields
;
1656 if (VF_BINFO_VALUE (vfields
) == NULL_TREE
1657 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
)))
1659 tree value
= VF_BASETYPE_VALUE (vfields
);
1660 if (DECL_NAME (CLASSTYPE_VFIELD (value
))
1661 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1662 VF_NORMAL_VALUE (b
->vfields
) = basetype
;
1664 VF_NORMAL_VALUE (b
->vfields
) = VF_NORMAL_VALUE (vfields
);
1666 vfields
= TREE_CHAIN (vfields
);
1668 CLASSTYPE_VFIELD (t
) = b
->vfield
;
1672 /* Only add unique vfields, and flatten them out as we go. */
1673 tree vfields
= CLASSTYPE_VFIELDS (basetype
);
1676 if (VF_BINFO_VALUE (vfields
) == NULL_TREE
1677 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
)))
1679 tree value
= VF_BASETYPE_VALUE (vfields
);
1680 b
->vfields
= tree_cons (base_binfo
, value
, b
->vfields
);
1681 if (DECL_NAME (CLASSTYPE_VFIELD (value
))
1682 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1683 VF_NORMAL_VALUE (b
->vfields
) = basetype
;
1685 VF_NORMAL_VALUE (b
->vfields
) = VF_NORMAL_VALUE (vfields
);
1687 vfields
= TREE_CHAIN (vfields
);
1690 if (b
->has_virtual
== 0)
1692 first_vfn_base_index
= i
;
1694 /* Update these two, now that we know what vtable we are
1695 going to extend. This is so that we can add virtual
1696 functions, and override them properly. */
1697 BINFO_VTABLE (t_binfo
) = TYPE_BINFO_VTABLE (basetype
);
1698 BINFO_VIRTUALS (t_binfo
) = TYPE_BINFO_VIRTUALS (basetype
);
1699 b
->has_virtual
= CLASSTYPE_VSIZE (basetype
);
1700 b
->vfield
= CLASSTYPE_VFIELD (basetype
);
1701 CLASSTYPE_VFIELD (t
) = b
->vfield
;
1702 /* When we install the first one, set the VF_NORMAL_VALUE
1703 to be the current class, as this it is the most derived
1704 class. Hopefully, this is not set to something else
1706 vfields
= b
->vfields
;
1709 if (DECL_NAME (CLASSTYPE_VFIELD (t
))
1710 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
1712 VF_NORMAL_VALUE (vfields
) = t
;
1713 /* There should only be one of them! And it should
1714 always be found, if we get into here. (mrs) */
1717 vfields
= TREE_CHAIN (vfields
);
1724 /* Must come after offsets are fixed for all bases. */
1725 for (i
= 0; i
< n_baseclasses
; i
++)
1727 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1728 tree basetype
= BINFO_TYPE (base_binfo
);
1730 if (get_base_distance (basetype
, t_binfo
, 0, (tree
*)0) == -2)
1732 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
1737 tree v
= get_vbase_types (t_binfo
);
1739 for (; v
; v
= TREE_CHAIN (v
))
1741 tree basetype
= BINFO_TYPE (v
);
1742 if (get_base_distance (basetype
, t_binfo
, 0, (tree
*)0) == -2)
1745 cp_warning ("virtual base `%T' inaccessible in `%T' due to ambiguity",
1753 /* Find the base class with the largest number of virtual functions. */
1754 for (vfields
= b
->vfields
; vfields
; vfields
= TREE_CHAIN (vfields
))
1756 if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields
)) > b
->max_has_virtual
)
1757 b
->max_has_virtual
= CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields
));
1758 if (VF_DERIVED_VALUE (vfields
)
1759 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields
)) > b
->max_has_virtual
)
1760 b
->max_has_virtual
= CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields
));
1765 /* If all virtual functions come only from virtual baseclasses. */
1768 /* Update the rtti base if we have a non-virtual base class version
1770 b
->rtti
= CLASSTYPE_RTTI (BINFO_TYPE (TREE_VEC_ELT (binfos
, first_vfn_base_index
)));
1772 return first_vfn_base_index
;
1776 typecode_p (type
, code
)
1778 enum tree_code code
;
1780 return (TREE_CODE (type
) == code
1781 || (TREE_CODE (type
) == REFERENCE_TYPE
1782 && TREE_CODE (TREE_TYPE (type
)) == code
));
1785 /* Set memoizing fields and bits of T (and its variants) for later use.
1786 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
1789 finish_struct_bits (t
, max_has_virtual
)
1791 int max_has_virtual
;
1793 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (t
);
1795 /* Fix up variants (if any). */
1796 tree variants
= TYPE_NEXT_VARIANT (t
);
1799 /* These fields are in the _TYPE part of the node, not in
1800 the TYPE_LANG_SPECIFIC component, so they are not shared. */
1801 TYPE_HAS_CONSTRUCTOR (variants
) = TYPE_HAS_CONSTRUCTOR (t
);
1802 TYPE_HAS_DESTRUCTOR (variants
) = TYPE_HAS_DESTRUCTOR (t
);
1803 TYPE_NEEDS_CONSTRUCTING (variants
) = TYPE_NEEDS_CONSTRUCTING (t
);
1804 TYPE_NEEDS_DESTRUCTOR (variants
) = TYPE_NEEDS_DESTRUCTOR (t
);
1806 TYPE_USES_COMPLEX_INHERITANCE (variants
) = TYPE_USES_COMPLEX_INHERITANCE (t
);
1807 TYPE_VIRTUAL_P (variants
) = TYPE_VIRTUAL_P (t
);
1808 TYPE_USES_VIRTUAL_BASECLASSES (variants
) = TYPE_USES_VIRTUAL_BASECLASSES (t
);
1809 /* Copy whatever these are holding today. */
1810 TYPE_MIN_VALUE (variants
) = TYPE_MIN_VALUE (t
);
1811 TYPE_MAX_VALUE (variants
) = TYPE_MAX_VALUE (t
);
1812 TYPE_FIELDS (variants
) = TYPE_FIELDS (t
);
1813 TYPE_SIZE (variants
) = TYPE_SIZE (t
);
1814 variants
= TYPE_NEXT_VARIANT (variants
);
1817 if (n_baseclasses
&& max_has_virtual
)
1819 /* Done by `finish_struct' for classes without baseclasses. */
1820 int might_have_abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (t
) != 0;
1821 tree binfos
= TYPE_BINFO_BASETYPES (t
);
1822 for (i
= n_baseclasses
-1; i
>= 0; i
--)
1824 might_have_abstract_virtuals
1825 |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos
, i
))) != 0);
1826 if (might_have_abstract_virtuals
)
1829 if (might_have_abstract_virtuals
)
1831 /* We use error_mark_node from override_one_vtable to signal
1832 an artificial abstract. */
1833 if (CLASSTYPE_ABSTRACT_VIRTUALS (t
) == error_mark_node
)
1834 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = NULL_TREE
;
1835 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = get_abstract_virtuals (t
);
1841 /* Notice whether this class has type conversion functions defined. */
1842 tree binfo
= TYPE_BINFO (t
);
1843 tree binfos
= BINFO_BASETYPES (binfo
);
1846 for (i
= n_baseclasses
-1; i
>= 0; i
--)
1848 basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
1850 if (TYPE_HAS_CONVERSION (basetype
))
1852 TYPE_HAS_CONVERSION (t
) = 1;
1853 TYPE_HAS_INT_CONVERSION (t
) |= TYPE_HAS_INT_CONVERSION (basetype
);
1854 TYPE_HAS_REAL_CONVERSION (t
) |= TYPE_HAS_REAL_CONVERSION (basetype
);
1856 if (CLASSTYPE_MAX_DEPTH (basetype
) >= CLASSTYPE_MAX_DEPTH (t
))
1857 CLASSTYPE_MAX_DEPTH (t
) = CLASSTYPE_MAX_DEPTH (basetype
) + 1;
1861 /* If this type has a copy constructor, force its mode to be BLKmode, and
1862 force its TREE_ADDRESSABLE bit to be nonzero. This will cause it to
1863 be passed by invisible reference and prevent it from being returned in
1866 Also do this if the class has BLKmode but can still be returned in
1867 registers, since function_cannot_inline_p won't let us inline
1868 functions returning such a type. This affects the HP-PA. */
1869 if (! TYPE_HAS_TRIVIAL_INIT_REF (t
)
1870 || (TYPE_MODE (t
) == BLKmode
&& ! aggregate_value_p (t
)
1871 && CLASSTYPE_NON_AGGREGATE (t
)))
1874 DECL_MODE (TYPE_MAIN_DECL (t
)) = BLKmode
;
1875 for (variants
= t
; variants
; variants
= TYPE_NEXT_VARIANT (variants
))
1877 TYPE_MODE (variants
) = BLKmode
;
1878 TREE_ADDRESSABLE (variants
) = 1;
1883 /* Add FNDECL to the method_vec growing on the class_obstack. Used by
1884 finish_struct_methods. Note, FNDECL cannot be a constructor or
1885 destructor, those cases are handled by the caller. */
1888 grow_method (fndecl
, method_vec_ptr
)
1890 tree
*method_vec_ptr
;
1892 tree method_vec
= (tree
)obstack_base (&class_obstack
);
1894 /* Start off past the constructors and destructor. */
1895 tree
*testp
= &TREE_VEC_ELT (method_vec
, 2);
1897 while (testp
< (tree
*) obstack_next_free (&class_obstack
)
1898 && (*testp
== NULL_TREE
|| DECL_NAME (*testp
) != DECL_NAME (fndecl
)))
1901 if (testp
< (tree
*) obstack_next_free (&class_obstack
))
1904 for (p
= testp
; *p
; )
1905 p
= &DECL_CHAIN (*p
);
1910 obstack_ptr_grow (&class_obstack
, fndecl
);
1911 *method_vec_ptr
= (tree
)obstack_base (&class_obstack
);
1915 /* Warn about duplicate methods in fn_fields. Also compact method
1916 lists so that lookup can be made faster.
1918 Algorithm: Outer loop builds lists by method name. Inner loop
1919 checks for redundant method names within a list.
1921 Data Structure: List of method lists. The outer list is a
1922 TREE_LIST, whose TREE_PURPOSE field is the field name and the
1923 TREE_VALUE is the DECL_CHAIN of the FUNCTION_DECLs. TREE_CHAIN
1924 links the entire list of methods for TYPE_METHODS. Friends are
1925 chained in the same way as member functions (? TREE_CHAIN or
1926 DECL_CHAIN), but they live in the TREE_TYPE field of the outer
1927 list. That allows them to be quickly deleted, and requires no
1930 If there are any constructors/destructors, they are moved to the
1931 front of the list. This makes pushclass more efficient.
1933 We also link each field which has shares a name with its baseclass
1934 to the head of the list of fields for that base class. This allows
1935 us to reduce search time in places like `build_method_call' to
1936 consider only reasonably likely functions. */
1939 finish_struct_methods (t
, fn_fields
, nonprivate_method
)
1942 int nonprivate_method
;
1945 tree save_fn_fields
= fn_fields
;
1946 tree ctor_name
= constructor_name (t
);
1947 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (t
);
1949 /* Now prepare to gather fn_fields into vector. */
1950 struct obstack
*ambient_obstack
= current_obstack
;
1951 current_obstack
= &class_obstack
;
1952 method_vec
= make_tree_vec (2);
1953 current_obstack
= ambient_obstack
;
1955 /* Now make this a live vector. */
1956 obstack_free (&class_obstack
, method_vec
);
1958 /* Save room for constructors and destructors. */
1959 obstack_blank (&class_obstack
, sizeof (struct tree_vec
) + sizeof (struct tree
*));
1961 /* First fill in entry 0 with the constructors, entry 1 with destructors,
1962 and the next few with type conversion operators (if any). */
1964 for (; fn_fields
; fn_fields
= TREE_CHAIN (fn_fields
))
1966 tree fn_name
= DECL_NAME (fn_fields
);
1968 /* Clear out this flag.
1970 @@ Doug may figure out how to break
1971 @@ this with nested classes and friends. */
1972 DECL_IN_AGGR_P (fn_fields
) = 0;
1974 /* Note here that a copy ctor is private, so we don't dare generate
1975 a default copy constructor for a class that has a member
1976 of this type without making sure they have access to it. */
1977 if (fn_name
== ctor_name
)
1979 tree parmtypes
= FUNCTION_ARG_CHAIN (fn_fields
);
1980 tree parmtype
= parmtypes
? TREE_VALUE (parmtypes
) : void_type_node
;
1982 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
1983 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
)) == t
)
1985 if (TREE_CHAIN (parmtypes
) == NULL_TREE
1986 || TREE_CHAIN (parmtypes
) == void_list_node
1987 || TREE_PURPOSE (TREE_CHAIN (parmtypes
)))
1989 if (TREE_PROTECTED (fn_fields
))
1990 TYPE_HAS_NONPUBLIC_CTOR (t
) = 1;
1991 else if (TREE_PRIVATE (fn_fields
))
1992 TYPE_HAS_NONPUBLIC_CTOR (t
) = 2;
1995 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn_fields
)))
1997 /* Destructors go in slot 1. */
1998 DECL_CHAIN (fn_fields
) = TREE_VEC_ELT (method_vec
, 1);
1999 TREE_VEC_ELT (method_vec
, 1) = fn_fields
;
2003 /* Constructors go in slot 0. */
2004 DECL_CHAIN (fn_fields
) = TREE_VEC_ELT (method_vec
, 0);
2005 TREE_VEC_ELT (method_vec
, 0) = fn_fields
;
2008 else if (IDENTIFIER_TYPENAME_P (fn_name
))
2010 tree return_type
= TREE_TYPE (TREE_TYPE (fn_fields
));
2012 if (typecode_p (return_type
, INTEGER_TYPE
)
2013 || typecode_p (return_type
, BOOLEAN_TYPE
)
2014 || typecode_p (return_type
, ENUMERAL_TYPE
))
2015 TYPE_HAS_INT_CONVERSION (t
) = 1;
2016 else if (typecode_p (return_type
, REAL_TYPE
))
2017 TYPE_HAS_REAL_CONVERSION (t
) = 1;
2019 grow_method (fn_fields
, &method_vec
);
2023 fn_fields
= save_fn_fields
;
2024 for (; fn_fields
; fn_fields
= TREE_CHAIN (fn_fields
))
2026 tree fn_name
= DECL_NAME (fn_fields
);
2028 if (fn_name
== ctor_name
|| IDENTIFIER_TYPENAME_P (fn_name
))
2031 if (fn_name
== ansi_opname
[(int) MODIFY_EXPR
])
2033 tree parmtype
= TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields
));
2035 if (copy_assignment_arg_p (parmtype
, DECL_VIRTUAL_P (fn_fields
)))
2037 if (TREE_PROTECTED (fn_fields
))
2038 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t
) = 1;
2039 else if (TREE_PRIVATE (fn_fields
))
2040 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t
) = 2;
2044 grow_method (fn_fields
, &method_vec
);
2047 TREE_VEC_LENGTH (method_vec
) = (tree
*)obstack_next_free (&class_obstack
)
2048 - (&TREE_VEC_ELT (method_vec
, 0));
2049 obstack_finish (&class_obstack
);
2050 CLASSTYPE_METHOD_VEC (t
) = method_vec
;
2052 if (nonprivate_method
== 0
2053 && CLASSTYPE_FRIEND_CLASSES (t
) == NULL_TREE
2054 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t
)) == NULL_TREE
)
2056 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
2057 for (i
= 0; i
< n_baseclasses
; i
++)
2058 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos
, i
))
2059 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos
, i
)))
2061 nonprivate_method
= 1;
2064 if (nonprivate_method
== 0
2065 && warn_ctor_dtor_privacy
)
2066 cp_warning ("all member functions in class `%T' are private", t
);
2069 /* Warn if all destructors are private (in which case this class is
2070 effectively unusable. */
2071 if (TYPE_HAS_DESTRUCTOR (t
))
2073 tree dtor
= TREE_VEC_ELT (method_vec
, 1);
2075 /* Wild parse errors can cause this to happen. */
2076 if (dtor
== NULL_TREE
)
2077 TYPE_HAS_DESTRUCTOR (t
) = 0;
2078 else if (TREE_PRIVATE (dtor
)
2079 && CLASSTYPE_FRIEND_CLASSES (t
) == NULL_TREE
2080 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t
)) == NULL_TREE
2081 && warn_ctor_dtor_privacy
)
2082 cp_warning ("`%#T' only defines a private destructor and has no friends",
2086 /* Now for each member function (except for constructors and
2087 destructors), compute where member functions of the same
2088 name reside in base classes. */
2089 if (n_baseclasses
!= 0
2090 && TREE_VEC_LENGTH (method_vec
) > 2)
2092 int len
= TREE_VEC_LENGTH (method_vec
);
2093 tree baselink_vec
= make_tree_vec (len
);
2095 tree baselink_binfo
= build_tree_list (NULL_TREE
, TYPE_BINFO (t
));
2097 for (i
= 2; i
< len
; i
++)
2099 TREE_VEC_ELT (baselink_vec
, i
)
2100 = get_baselinks (baselink_binfo
, t
, DECL_NAME (TREE_VEC_ELT (method_vec
, i
)));
2101 if (TREE_VEC_ELT (baselink_vec
, i
) != 0)
2105 CLASSTYPE_BASELINK_VEC (t
) = baselink_vec
;
2107 obstack_free (current_obstack
, baselink_vec
);
2110 /* Now, figure out what any member template specializations were
2112 for (i
= 0; i
< TREE_VEC_LENGTH (method_vec
); ++i
)
2115 for (fn
= TREE_VEC_ELT (method_vec
, i
);
2117 fn
= DECL_CHAIN (fn
))
2118 if (DECL_TEMPLATE_SPECIALIZATION (fn
))
2123 /* If there is a template, and t uses template parms, we
2124 are dealing with a specialization of a member
2125 template in a template class, and we must grab the
2126 template, rather than the function. */
2127 if (DECL_TI_TEMPLATE (fn
) && uses_template_parms (t
))
2128 f
= DECL_TI_TEMPLATE (fn
);
2132 /* We want the specialization arguments, which will be the
2134 if (DECL_TI_ARGS (f
)
2135 && TREE_CODE (DECL_TI_ARGS (f
)) == TREE_VEC
)
2137 = TREE_VEC_ELT (DECL_TI_ARGS (f
), 0);
2139 spec_args
= DECL_TI_ARGS (f
);
2141 check_explicit_specialization
2142 (lookup_template_function (DECL_NAME (f
), spec_args
),
2145 /* Now, the assembler name will be correct for fn, so we
2148 make_decl_rtl (f
, NULL_PTR
, 1);
2152 make_decl_rtl (fn
, NULL_PTR
, 1);
2160 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2163 duplicate_tag_error (t
)
2166 cp_error ("redefinition of `%#T'", t
);
2167 cp_error_at ("previous definition here", t
);
2169 /* Pretend we haven't defined this type. */
2171 /* All of the component_decl's were TREE_CHAINed together in the parser.
2172 finish_struct_methods walks these chains and assembles all methods with
2173 the same base name into DECL_CHAINs. Now we don't need the parser chains
2174 anymore, so we unravel them. */
2176 /* This used to be in finish_struct, but it turns out that the
2177 TREE_CHAIN is used by dbxout_type_methods and perhaps some other
2179 if (CLASSTYPE_METHOD_VEC (t
))
2181 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
2182 int i
, len
= TREE_VEC_LENGTH (method_vec
);
2183 for (i
= 0; i
< len
; i
++)
2185 tree unchain
= TREE_VEC_ELT (method_vec
, i
);
2186 while (unchain
!= NULL_TREE
)
2188 TREE_CHAIN (unchain
) = NULL_TREE
;
2189 unchain
= DECL_CHAIN (unchain
);
2194 if (TYPE_LANG_SPECIFIC (t
))
2196 tree as_list
= CLASSTYPE_AS_LIST (t
);
2197 tree binfo
= TYPE_BINFO (t
);
2198 tree binfo_as_list
= CLASSTYPE_BINFO_AS_LIST (t
);
2199 int interface_only
= CLASSTYPE_INTERFACE_ONLY (t
);
2200 int interface_unknown
= CLASSTYPE_INTERFACE_UNKNOWN (t
);
2202 bzero ((char *) TYPE_LANG_SPECIFIC (t
), sizeof (struct lang_type
));
2203 BINFO_BASETYPES(binfo
) = NULL_TREE
;
2205 CLASSTYPE_AS_LIST (t
) = as_list
;
2206 TYPE_BINFO (t
) = binfo
;
2207 CLASSTYPE_BINFO_AS_LIST (t
) = binfo_as_list
;
2208 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
2209 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t
, interface_unknown
);
2210 CLASSTYPE_VBASE_SIZE (t
) = integer_zero_node
;
2211 TYPE_REDEFINED (t
) = 1;
2213 TYPE_SIZE (t
) = NULL_TREE
;
2214 TYPE_MODE (t
) = VOIDmode
;
2215 TYPE_FIELDS (t
) = NULL_TREE
;
2216 TYPE_METHODS (t
) = NULL_TREE
;
2217 TYPE_VFIELD (t
) = NULL_TREE
;
2218 TYPE_CONTEXT (t
) = NULL_TREE
;
2221 /* finish up all new vtables. */
2224 finish_vtbls (binfo
, do_self
, t
)
2229 tree binfos
= BINFO_BASETYPES (binfo
);
2230 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2232 /* Should we use something besides CLASSTYPE_VFIELDS? */
2233 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2235 if (BINFO_NEW_VTABLE_MARKED (binfo
))
2239 decl
= BINFO_VTABLE (binfo
);
2240 context
= DECL_CONTEXT (decl
);
2241 DECL_CONTEXT (decl
) = 0;
2242 if (write_virtuals
>= 0
2243 && DECL_INITIAL (decl
) != BINFO_VIRTUALS (binfo
))
2244 DECL_INITIAL (decl
) = build_nt (CONSTRUCTOR
, NULL_TREE
,
2245 BINFO_VIRTUALS (binfo
));
2246 cp_finish_decl (decl
, DECL_INITIAL (decl
), NULL_TREE
, 0, 0);
2247 DECL_CONTEXT (decl
) = context
;
2249 CLEAR_BINFO_NEW_VTABLE_MARKED (binfo
);
2252 for (i
= 0; i
< n_baselinks
; i
++)
2254 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2255 int is_not_base_vtable
2256 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2257 if (TREE_VIA_VIRTUAL (base_binfo
))
2259 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
), CLASSTYPE_VBASECLASSES (t
));
2261 finish_vtbls (base_binfo
, is_not_base_vtable
, t
);
2265 /* True if we should override the given BASE_FNDECL with the given
2269 overrides (fndecl
, base_fndecl
)
2270 tree fndecl
, base_fndecl
;
2272 /* Destructors have special names. */
2273 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl
))
2274 && DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2276 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl
))
2277 || DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fndecl
)))
2279 if (DECL_NAME (fndecl
) == DECL_NAME (base_fndecl
))
2281 tree types
, base_types
;
2283 retypes
= TREE_TYPE (TREE_TYPE (fndecl
));
2284 base_retypes
= TREE_TYPE (TREE_TYPE (base_fndecl
));
2286 types
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
2287 base_types
= TYPE_ARG_TYPES (TREE_TYPE (base_fndecl
));
2288 if ((TYPE_READONLY (TREE_TYPE (TREE_VALUE (base_types
)))
2289 == TYPE_READONLY (TREE_TYPE (TREE_VALUE (types
))))
2290 && compparms (TREE_CHAIN (base_types
), TREE_CHAIN (types
), 3))
2297 get_class_offset_1 (parent
, binfo
, context
, t
, fndecl
)
2298 tree parent
, binfo
, context
, t
, fndecl
;
2300 tree binfos
= BINFO_BASETYPES (binfo
);
2301 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2302 tree rval
= NULL_TREE
;
2304 if (binfo
== parent
)
2305 return error_mark_node
;
2307 for (i
= 0; i
< n_baselinks
; i
++)
2309 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2312 if (TREE_VIA_VIRTUAL (base_binfo
))
2313 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
),
2314 CLASSTYPE_VBASECLASSES (t
));
2315 nrval
= get_class_offset_1 (parent
, base_binfo
, context
, t
, fndecl
);
2316 /* See if we have a new value */
2317 if (nrval
&& (nrval
!= error_mark_node
|| rval
==0))
2319 /* Only compare if we have two offsets */
2320 if (rval
&& rval
!= error_mark_node
2321 && ! tree_int_cst_equal (nrval
, rval
))
2323 /* Only give error if the two offsets are different */
2324 error ("every virtual function must have a unique final overrider");
2325 cp_error (" found two (or more) `%T' class subobjects in `%T'", context
, t
);
2326 cp_error (" with virtual `%D' from virtual base class", fndecl
);
2332 if (rval
&& BINFO_TYPE (binfo
) == context
)
2334 my_friendly_assert (rval
== error_mark_node
2335 || tree_int_cst_equal (rval
, BINFO_OFFSET (binfo
)), 999);
2336 rval
= BINFO_OFFSET (binfo
);
2342 /* Get the offset to the CONTEXT subobject that is related to the
2346 get_class_offset (context
, t
, binfo
, fndecl
)
2347 tree context
, t
, binfo
, fndecl
;
2349 tree first_binfo
= binfo
;
2354 return integer_zero_node
;
2356 if (BINFO_TYPE (binfo
) == context
)
2357 return BINFO_OFFSET (binfo
);
2359 /* Check less derived binfos first. */
2360 while (BINFO_BASETYPES (binfo
)
2361 && (i
=CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
))) != -1)
2363 tree binfos
= BINFO_BASETYPES (binfo
);
2364 binfo
= TREE_VEC_ELT (binfos
, i
);
2365 if (BINFO_TYPE (binfo
) == context
)
2366 return BINFO_OFFSET (binfo
);
2369 /* Ok, not found in the less derived binfos, now check the more
2371 offset
= get_class_offset_1 (first_binfo
, TYPE_BINFO (t
), context
, t
, fndecl
);
2372 if (offset
==0 || TREE_CODE (offset
) != INTEGER_CST
)
2373 my_friendly_abort (999); /* we have to find it. */
2377 /* Skip RTTI information at the front of the virtual list. */
2379 unsigned HOST_WIDE_INT
2380 skip_rtti_stuff (virtuals
)
2388 /* We always reserve a slot for the offset/tdesc entry. */
2390 *virtuals
= TREE_CHAIN (*virtuals
);
2392 if (flag_vtable_thunks
&& *virtuals
)
2394 /* The second slot is reserved for the tdesc pointer when thunks
2397 *virtuals
= TREE_CHAIN (*virtuals
);
2403 modify_one_vtable (binfo
, t
, fndecl
, pfn
)
2404 tree binfo
, t
, fndecl
, pfn
;
2406 tree virtuals
= BINFO_VIRTUALS (binfo
);
2407 unsigned HOST_WIDE_INT n
;
2409 /* update rtti entry */
2412 if (binfo
== TYPE_BINFO (t
))
2414 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2415 build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t
))), t
);
2419 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2420 prepare_fresh_vtable (binfo
, t
);
2423 if (fndecl
== NULL_TREE
)
2426 n
= skip_rtti_stuff (&virtuals
);
2430 tree current_fndecl
= TREE_VALUE (virtuals
);
2431 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
2432 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
2433 if (current_fndecl
&& overrides (fndecl
, current_fndecl
))
2435 tree base_offset
, offset
;
2436 tree context
= DECL_CLASS_CONTEXT (fndecl
);
2437 tree vfield
= CLASSTYPE_VFIELD (t
);
2440 offset
= get_class_offset (context
, t
, binfo
, fndecl
);
2442 /* Find the right offset for the this pointer based on the
2443 base class we just found. We have to take into
2444 consideration the virtual base class pointers that we
2445 stick in before the virtual function table pointer.
2447 Also, we want just the delta between the most base class
2448 that we derived this vfield from and us. */
2449 base_offset
= size_binop (PLUS_EXPR
,
2450 get_derived_offset (binfo
, DECL_CONTEXT (current_fndecl
)),
2451 BINFO_OFFSET (binfo
));
2452 this_offset
= size_binop (MINUS_EXPR
, offset
, base_offset
);
2454 /* Make sure we can modify the derived association with immunity. */
2455 if (TREE_USED (binfo
))
2456 my_friendly_assert (0, 999);
2458 if (binfo
== TYPE_BINFO (t
))
2460 /* In this case, it is *type*'s vtable we are modifying.
2461 We start with the approximation that it's vtable is that
2462 of the immediate base class. */
2463 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2464 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield
)), t
);
2468 /* This is our very own copy of `basetype' to play with.
2469 Later, we will fill in all the virtual functions
2470 that override the virtual functions in these base classes
2471 which are not defined by the current type. */
2472 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2473 prepare_fresh_vtable (binfo
, t
);
2477 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo
)));
2479 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo
), n
),
2480 build_vtable_entry (this_offset
, pfn
),
2484 virtuals
= TREE_CHAIN (virtuals
);
2488 /* These are the ones that are not through virtual base classes. */
2491 modify_all_direct_vtables (binfo
, do_self
, t
, fndecl
, pfn
)
2494 tree t
, fndecl
, pfn
;
2496 tree binfos
= BINFO_BASETYPES (binfo
);
2497 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2499 /* Should we use something besides CLASSTYPE_VFIELDS? */
2500 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2502 modify_one_vtable (binfo
, t
, fndecl
, pfn
);
2505 for (i
= 0; i
< n_baselinks
; i
++)
2507 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2508 int is_not_base_vtable
2509 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2510 if (! TREE_VIA_VIRTUAL (base_binfo
))
2511 modify_all_direct_vtables (base_binfo
, is_not_base_vtable
, t
, fndecl
, pfn
);
2515 /* Fixup all the delta entries in this one vtable that need updating. */
2518 fixup_vtable_deltas1 (binfo
, t
)
2521 tree virtuals
= BINFO_VIRTUALS (binfo
);
2522 unsigned HOST_WIDE_INT n
;
2524 n
= skip_rtti_stuff (&virtuals
);
2528 tree fndecl
= TREE_VALUE (virtuals
);
2529 tree pfn
= FNADDR_FROM_VTABLE_ENTRY (fndecl
);
2530 tree delta
= DELTA_FROM_VTABLE_ENTRY (fndecl
);
2531 fndecl
= TREE_OPERAND (pfn
, 0);
2534 tree base_offset
, offset
;
2535 tree context
= DECL_CLASS_CONTEXT (fndecl
);
2536 tree vfield
= CLASSTYPE_VFIELD (t
);
2539 offset
= get_class_offset (context
, t
, binfo
, fndecl
);
2541 /* Find the right offset for the this pointer based on the
2542 base class we just found. We have to take into
2543 consideration the virtual base class pointers that we
2544 stick in before the virtual function table pointer.
2546 Also, we want just the delta between the most base class
2547 that we derived this vfield from and us. */
2548 base_offset
= size_binop (PLUS_EXPR
,
2549 get_derived_offset (binfo
, DECL_CONTEXT (fndecl
)),
2550 BINFO_OFFSET (binfo
));
2551 this_offset
= size_binop (MINUS_EXPR
, offset
, base_offset
);
2553 if (! tree_int_cst_equal (this_offset
, delta
))
2555 /* Make sure we can modify the derived association with immunity. */
2556 if (TREE_USED (binfo
))
2557 my_friendly_assert (0, 999);
2559 if (binfo
== TYPE_BINFO (t
))
2561 /* In this case, it is *type*'s vtable we are modifying.
2562 We start with the approximation that it's vtable is that
2563 of the immediate base class. */
2564 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2565 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield
)), t
);
2569 /* This is our very own copy of `basetype' to play with.
2570 Later, we will fill in all the virtual functions
2571 that override the virtual functions in these base classes
2572 which are not defined by the current type. */
2573 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2574 prepare_fresh_vtable (binfo
, t
);
2577 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo
), n
),
2578 build_vtable_entry (this_offset
, pfn
),
2583 virtuals
= TREE_CHAIN (virtuals
);
2587 /* Fixup all the delta entries in all the direct vtables that need updating.
2588 This happens when we have non-overridden virtual functions from a
2589 virtual base class, that are at a different offset, in the new
2590 hierarchy, because the layout of the virtual bases has changed. */
2593 fixup_vtable_deltas (binfo
, init_self
, t
)
2598 tree binfos
= BINFO_BASETYPES (binfo
);
2599 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2601 for (i
= 0; i
< n_baselinks
; i
++)
2603 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2604 int is_not_base_vtable
2605 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2606 if (! TREE_VIA_VIRTUAL (base_binfo
))
2607 fixup_vtable_deltas (base_binfo
, is_not_base_vtable
, t
);
2609 /* Should we use something besides CLASSTYPE_VFIELDS? */
2610 if (init_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2612 fixup_vtable_deltas1 (binfo
, t
);
2616 /* These are the ones that are through virtual base classes. */
2619 modify_all_indirect_vtables (binfo
, do_self
, via_virtual
, t
, fndecl
, pfn
)
2621 int do_self
, via_virtual
;
2622 tree t
, fndecl
, pfn
;
2624 tree binfos
= BINFO_BASETYPES (binfo
);
2625 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2627 /* Should we use something besides CLASSTYPE_VFIELDS? */
2628 if (do_self
&& via_virtual
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2630 modify_one_vtable (binfo
, t
, fndecl
, pfn
);
2633 for (i
= 0; i
< n_baselinks
; i
++)
2635 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2636 int is_not_base_vtable
2637 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2638 if (TREE_VIA_VIRTUAL (base_binfo
))
2641 base_binfo
= binfo_member (BINFO_TYPE (base_binfo
), CLASSTYPE_VBASECLASSES (t
));
2643 modify_all_indirect_vtables (base_binfo
, is_not_base_vtable
, via_virtual
, t
, fndecl
, pfn
);
2648 modify_all_vtables (t
, fndecl
, vfn
)
2649 tree t
, fndecl
, vfn
;
2651 /* Do these first, so that we will make use of any non-virtual class's
2652 vtable, over a virtual classes vtable. */
2653 modify_all_direct_vtables (TYPE_BINFO (t
), 1, t
, fndecl
, vfn
);
2654 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
2655 modify_all_indirect_vtables (TYPE_BINFO (t
), 1, 0, t
, fndecl
, vfn
);
2658 /* Here, we already know that they match in every respect.
2659 All we have to check is where they had their declarations. */
2662 strictly_overrides (fndecl1
, fndecl2
)
2663 tree fndecl1
, fndecl2
;
2665 int distance
= get_base_distance (DECL_CLASS_CONTEXT (fndecl2
),
2666 DECL_CLASS_CONTEXT (fndecl1
),
2668 if (distance
== -2 || distance
> 0)
2673 /* Merge overrides for one vtable.
2674 If we want to merge in same function, we are fine.
2676 if one has a DECL_CLASS_CONTEXT that is a parent of the
2677 other, than choose the more derived one
2679 potentially ill-formed (see 10.3 [class.virtual])
2680 we have to check later to see if there was an
2681 override in this class. If there was ok, if not
2682 then it is ill-formed. (mrs)
2684 We take special care to reuse a vtable, if we can. */
2687 override_one_vtable (binfo
, old
, t
)
2690 tree virtuals
= BINFO_VIRTUALS (binfo
);
2691 tree old_virtuals
= BINFO_VIRTUALS (old
);
2692 enum { REUSE_NEW
, REUSE_OLD
, UNDECIDED
, NEITHER
} choose
= UNDECIDED
;
2694 /* If we have already committed to modifying it, then don't try and
2695 reuse another vtable. */
2696 if (BINFO_NEW_VTABLE_MARKED (binfo
))
2699 skip_rtti_stuff (&virtuals
);
2700 skip_rtti_stuff (&old_virtuals
);
2704 tree fndecl
= TREE_VALUE (virtuals
);
2705 tree old_fndecl
= TREE_VALUE (old_virtuals
);
2706 fndecl
= FNADDR_FROM_VTABLE_ENTRY (fndecl
);
2707 old_fndecl
= FNADDR_FROM_VTABLE_ENTRY (old_fndecl
);
2708 fndecl
= TREE_OPERAND (fndecl
, 0);
2709 old_fndecl
= TREE_OPERAND (old_fndecl
, 0);
2710 /* First check to see if they are the same. */
2711 if (DECL_ASSEMBLER_NAME (fndecl
) == DECL_ASSEMBLER_NAME (old_fndecl
))
2713 /* No need to do anything. */
2715 else if (strictly_overrides (fndecl
, old_fndecl
))
2717 if (choose
== UNDECIDED
)
2719 else if (choose
== REUSE_OLD
)
2722 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2724 prepare_fresh_vtable (binfo
, t
);
2725 override_one_vtable (binfo
, old
, t
);
2730 else if (strictly_overrides (old_fndecl
, fndecl
))
2732 if (choose
== UNDECIDED
)
2734 else if (choose
== REUSE_NEW
)
2737 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2739 prepare_fresh_vtable (binfo
, t
);
2740 override_one_vtable (binfo
, old
, t
);
2743 TREE_VALUE (virtuals
) = TREE_VALUE (old_virtuals
);
2745 else if (choose
== NEITHER
)
2747 TREE_VALUE (virtuals
) = TREE_VALUE (old_virtuals
);
2753 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
2755 prepare_fresh_vtable (binfo
, t
);
2756 override_one_vtable (binfo
, old
, t
);
2760 /* This MUST be overridden, or the class is ill-formed. */
2761 /* For now, we just make it abstract. */
2762 tree fndecl
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
)), 0);
2765 fndecl
= copy_node (fndecl
);
2766 copy_lang_decl (fndecl
);
2767 DECL_ABSTRACT_VIRTUAL_P (fndecl
) = 1;
2768 /* Make sure we search for it later. */
2769 if (! CLASSTYPE_ABSTRACT_VIRTUALS (t
))
2770 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = error_mark_node
;
2772 vfn
= build1 (ADDR_EXPR
, vfunc_ptr_type_node
, fndecl
);
2773 TREE_CONSTANT (vfn
) = 1;
2775 /* We can use integer_zero_node, as we will will core dump
2776 if this is used anyway. */
2777 TREE_VALUE (virtuals
) = build_vtable_entry (integer_zero_node
, vfn
);
2780 virtuals
= TREE_CHAIN (virtuals
);
2781 old_virtuals
= TREE_CHAIN (old_virtuals
);
2784 /* Let's reuse the old vtable. */
2785 if (choose
== REUSE_OLD
)
2787 BINFO_VTABLE (binfo
) = BINFO_VTABLE (old
);
2788 BINFO_VIRTUALS (binfo
) = BINFO_VIRTUALS (old
);
2792 /* Merge in overrides for virtual bases.
2793 BINFO is the hierarchy we want to modify, and OLD has the potential
2797 merge_overrides (binfo
, old
, do_self
, t
)
2802 tree binfos
= BINFO_BASETYPES (binfo
);
2803 tree old_binfos
= BINFO_BASETYPES (old
);
2804 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2806 /* Should we use something besides CLASSTYPE_VFIELDS? */
2807 if (do_self
&& CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
)))
2809 override_one_vtable (binfo
, old
, t
);
2812 for (i
= 0; i
< n_baselinks
; i
++)
2814 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2815 tree old_base_binfo
= TREE_VEC_ELT (old_binfos
, i
);
2816 int is_not_base_vtable
2817 = i
!= CLASSTYPE_VFIELD_PARENT (BINFO_TYPE (binfo
));
2818 if (! TREE_VIA_VIRTUAL (base_binfo
))
2819 merge_overrides (base_binfo
, old_base_binfo
, is_not_base_vtable
, t
);
2823 /* Get the base virtual function declarations in T that are either
2824 overridden or hidden by FNDECL as a list. We set TREE_PURPOSE with
2825 the overrider/hider. */
2828 get_basefndecls (fndecl
, t
)
2831 tree methods
= TYPE_METHODS (t
);
2832 tree base_fndecls
= NULL_TREE
;
2833 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
2834 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2838 if (TREE_CODE (methods
) == FUNCTION_DECL
2839 && DECL_VINDEX (methods
) != NULL_TREE
2840 && DECL_NAME (fndecl
) == DECL_NAME (methods
))
2841 base_fndecls
= temp_tree_cons (fndecl
, methods
, base_fndecls
);
2843 methods
= TREE_CHAIN (methods
);
2847 return base_fndecls
;
2849 for (i
= 0; i
< n_baseclasses
; i
++)
2851 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2852 tree basetype
= BINFO_TYPE (base_binfo
);
2854 base_fndecls
= chainon (get_basefndecls (fndecl
, basetype
),
2858 return base_fndecls
;
2861 /* Mark the functions that have been hidden with their overriders.
2862 Since we start out with all functions already marked with a hider,
2863 no need to mark functions that are just hidden. */
2866 mark_overriders (fndecl
, base_fndecls
)
2867 tree fndecl
, base_fndecls
;
2869 while (base_fndecls
)
2871 if (overrides (TREE_VALUE (base_fndecls
), fndecl
))
2872 TREE_PURPOSE (base_fndecls
) = fndecl
;
2874 base_fndecls
= TREE_CHAIN (base_fndecls
);
2878 /* If this declaration supersedes the declaration of
2879 a method declared virtual in the base class, then
2880 mark this field as being virtual as well. */
2883 check_for_override (decl
, ctype
)
2886 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (ctype
));
2887 int i
, n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2888 int virtualp
= DECL_VIRTUAL_P (decl
);
2890 for (i
= 0; i
< n_baselinks
; i
++)
2892 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2893 if (TYPE_VIRTUAL_P (BINFO_TYPE (base_binfo
))
2894 || flag_all_virtual
== 1)
2896 tree tmp
= get_matching_virtual
2898 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (decl
)));
2901 /* If this function overrides some virtual in some base
2902 class, then the function itself is also necessarily
2903 virtual, even if the user didn't explicitly say so. */
2904 DECL_VIRTUAL_P (decl
) = 1;
2906 /* The TMP we really want is the one from the deepest
2907 baseclass on this path, taking care not to
2908 duplicate if we have already found it (via another
2909 path to its virtual baseclass. */
2910 if (TREE_CODE (TREE_TYPE (decl
)) == FUNCTION_TYPE
)
2912 cp_error_at ("method `%D' may not be declared static",
2914 cp_error_at ("(since `%D' declared virtual in base class.)",
2920 #if 0 /* The signature of an overriding function is not changed. */
2922 /* The argument types may have changed... */
2923 tree type
= TREE_TYPE (decl
);
2924 tree argtypes
= TYPE_ARG_TYPES (type
);
2925 tree base_variant
= TREE_TYPE (TREE_VALUE (argtypes
));
2926 tree raises
= TYPE_RAISES_EXCEPTIONS (type
);
2928 argtypes
= commonparms (TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (tmp
))),
2929 TREE_CHAIN (argtypes
));
2930 /* But the return type has not. */
2931 type
= build_cplus_method_type (base_variant
, TREE_TYPE (type
), argtypes
);
2933 type
= build_exception_variant (type
, raises
);
2934 TREE_TYPE (decl
) = type
;
2938 = tree_cons (NULL_TREE
, tmp
, DECL_VINDEX (decl
));
2945 if (DECL_VINDEX (decl
) == NULL_TREE
)
2946 DECL_VINDEX (decl
) = error_mark_node
;
2947 IDENTIFIER_VIRTUAL_P (DECL_NAME (decl
)) = 1;
2951 /* Warn about hidden virtual functions that are not overridden in t.
2952 We know that constructors and destructors don't apply. */
2958 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
2959 int n_methods
= method_vec
? TREE_VEC_LENGTH (method_vec
) : 0;
2962 /* We go through each separately named virtual function. */
2963 for (i
= 2; i
< n_methods
; ++i
)
2965 tree fndecl
= TREE_VEC_ELT (method_vec
, i
);
2967 tree base_fndecls
= NULL_TREE
;
2968 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
2969 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
2971 if (DECL_VINDEX (fndecl
) == NULL_TREE
)
2974 /* First we get a list of all possible functions that might be
2975 hidden from each base class. */
2976 for (i
= 0; i
< n_baseclasses
; i
++)
2978 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2979 tree basetype
= BINFO_TYPE (base_binfo
);
2981 base_fndecls
= chainon (get_basefndecls (fndecl
, basetype
),
2985 if (TREE_CHAIN (fndecl
)
2986 && DECL_NAME (TREE_CHAIN (fndecl
)) == DECL_NAME (fndecl
))
2987 fndecl
= TREE_CHAIN (fndecl
);
2991 /* ...then mark up all the base functions with overriders, preferring
2992 overriders to hiders. */
2996 mark_overriders (fndecl
, base_fndecls
);
2998 if (TREE_CHAIN (fndecl
)
2999 && DECL_NAME (TREE_CHAIN (fndecl
)) == DECL_NAME (fndecl
))
3000 fndecl
= TREE_CHAIN (fndecl
);
3005 /* Now give a warning for all base functions without overriders,
3006 as they are hidden. */
3007 while (base_fndecls
)
3009 if (! overrides (TREE_VALUE (base_fndecls
),
3010 TREE_PURPOSE (base_fndecls
)))
3012 /* Here we know it is a hider, and no overrider exists. */
3013 cp_warning_at ("`%D' was hidden", TREE_VALUE (base_fndecls
));
3014 cp_warning_at (" by `%D'", TREE_PURPOSE (base_fndecls
));
3017 base_fndecls
= TREE_CHAIN (base_fndecls
);
3022 /* Check for things that are invalid. There are probably plenty of other
3023 things we should check for also. */
3026 finish_struct_anon (t
)
3030 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
3032 if (TREE_STATIC (field
))
3034 if (TREE_CODE (field
) != FIELD_DECL
)
3037 if (DECL_NAME (field
) == NULL_TREE
3038 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
3040 tree
* uelt
= &TYPE_FIELDS (TREE_TYPE (field
));
3041 for (; *uelt
; uelt
= &TREE_CHAIN (*uelt
))
3043 if (TREE_CODE (*uelt
) != FIELD_DECL
)
3046 if (TREE_PRIVATE (*uelt
))
3047 cp_pedwarn_at ("private member `%#D' in anonymous union",
3049 else if (TREE_PROTECTED (*uelt
))
3050 cp_pedwarn_at ("protected member `%#D' in anonymous union",
3053 TREE_PRIVATE (*uelt
) = TREE_PRIVATE (field
);
3054 TREE_PROTECTED (*uelt
) = TREE_PROTECTED (field
);
3060 extern int interface_only
, interface_unknown
;
3062 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
3063 (or C++ class declaration).
3065 For C++, we must handle the building of derived classes.
3066 Also, C++ allows static class members. The way that this is
3067 handled is to keep the field name where it is (as the DECL_NAME
3068 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
3069 of the field. layout_record and layout_union will know about this.
3071 More C++ hair: inline functions have text in their
3072 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
3073 meaningful tree structure. After the struct has been laid out, set
3074 things up so that this can happen.
3076 And still more: virtual functions. In the case of single inheritance,
3077 when a new virtual function is seen which redefines a virtual function
3078 from the base class, the new virtual function is placed into
3079 the virtual function table at exactly the same address that
3080 it had in the base class. When this is extended to multiple
3081 inheritance, the same thing happens, except that multiple virtual
3082 function tables must be maintained. The first virtual function
3083 table is treated in exactly the same way as in the case of single
3084 inheritance. Additional virtual function tables have different
3085 DELTAs, which tell how to adjust `this' to point to the right thing.
3087 LIST_OF_FIELDLISTS is just that. The elements of the list are
3088 TREE_LIST elements, whose TREE_PURPOSE field tells what access
3089 the list has, and the TREE_VALUE slot gives the actual fields.
3091 ATTRIBUTES is the set of decl attributes to be applied, if any.
3093 If flag_all_virtual == 1, then we lay all functions into
3094 the virtual function table, as though they were declared
3095 virtual. Constructors do not lay down in the virtual function table.
3097 If flag_all_virtual == 2, then we lay all functions into
3098 the virtual function table, such that virtual functions
3099 occupy a space by themselves, and then all functions
3100 of the class occupy a space by themselves. This is illustrated
3101 in the following diagram:
3103 class A; class B : A;
3105 Class A's vtbl: Class B's vtbl:
3106 --------------------------------------------------------------------
3107 | A's virtual functions| | B's virtual functions |
3108 | | | (may inherit some from A). |
3109 --------------------------------------------------------------------
3110 | All of A's functions | | All of A's functions |
3111 | (such as a->A::f). | | (such as b->A::f) |
3112 --------------------------------------------------------------------
3113 | B's new virtual functions |
3114 | (not defined in A.) |
3115 -------------------------------
3116 | All of B's functions |
3117 | (such as b->B::f) |
3118 -------------------------------
3120 this allows the program to make references to any function, virtual
3121 or otherwise in a type-consistent manner. */
3124 finish_struct_1 (t
, warn_anon
)
3129 tree name
= TYPE_IDENTIFIER (t
);
3130 enum tree_code code
= TREE_CODE (t
);
3131 tree fields
= TYPE_FIELDS (t
);
3132 tree fn_fields
= TYPE_METHODS (t
);
3133 tree x
, last_x
, method_vec
;
3136 int max_has_virtual
;
3137 tree pending_virtuals
= NULL_TREE
;
3138 tree pending_hard_virtuals
= NULL_TREE
;
3139 tree abstract_virtuals
= NULL_TREE
;
3142 int cant_have_default_ctor
;
3143 int cant_have_const_ctor
;
3144 int no_const_asn_ref
;
3146 /* The index of the first base class which has virtual
3147 functions. Only applied to non-virtual baseclasses. */
3148 int first_vfn_base_index
;
3151 int any_default_members
= 0;
3152 int const_sans_init
= 0;
3153 int ref_sans_init
= 0;
3154 int nonprivate_method
= 0;
3155 tree t_binfo
= TYPE_BINFO (t
);
3156 tree access_decls
= NULL_TREE
;
3159 int has_pointers
= 0;
3161 if (warn_anon
&& code
!= UNION_TYPE
&& ANON_AGGRNAME_P (TYPE_IDENTIFIER (t
)))
3162 pedwarn ("anonymous class type not used to declare any objects");
3166 if (IS_AGGR_TYPE (t
))
3167 cp_error ("redefinition of `%#T'", t
);
3169 my_friendly_abort (172);
3174 GNU_xref_decl (current_function_decl
, t
);
3176 /* If this type was previously laid out as a forward reference,
3177 make sure we lay it out again. */
3179 TYPE_SIZE (t
) = NULL_TREE
;
3180 CLASSTYPE_GOT_SEMICOLON (t
) = 0;
3183 /* This is in general too late to do this. I moved the main case up to
3184 left_curly, what else needs to move? */
3185 if (! IS_SIGNATURE (t
))
3187 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t
) == interface_only
, 999);
3188 my_friendly_assert (CLASSTYPE_INTERFACE_KNOWN (t
) == ! interface_unknown
, 999);
3194 build_t_desc (t
, 0);
3197 TYPE_BINFO (t
) = NULL_TREE
;
3199 old
= suspend_momentary ();
3201 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
3202 Also process specified field sizes.
3203 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
3204 The specified size is found in the DECL_INITIAL.
3205 Store 0 there, except for ": 0" fields (so we can find them
3206 and delete them, below). */
3208 if (t_binfo
&& BINFO_BASETYPES (t_binfo
))
3209 n_baseclasses
= TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo
));
3213 if (n_baseclasses
> 0)
3215 struct base_info base_info
;
3217 /* If using multiple inheritance, this may cause variants of our
3218 basetypes to be used (instead of their canonical forms). */
3219 tree vf
= layout_basetypes (t
, BINFO_BASETYPES (t_binfo
));
3220 last_x
= tree_last (vf
);
3221 fields
= chainon (vf
, fields
);
3223 first_vfn_base_index
= finish_base_struct (t
, &base_info
, t_binfo
);
3224 /* Remember where we got our vfield from. */
3225 CLASSTYPE_VFIELD_PARENT (t
) = first_vfn_base_index
;
3226 has_virtual
= base_info
.has_virtual
;
3227 max_has_virtual
= base_info
.max_has_virtual
;
3228 CLASSTYPE_N_SUPERCLASSES (t
) += base_info
.n_ancestors
;
3229 vfield
= base_info
.vfield
;
3230 vfields
= base_info
.vfields
;
3231 CLASSTYPE_RTTI (t
) = base_info
.rtti
;
3232 cant_have_default_ctor
= base_info
.cant_have_default_ctor
;
3233 cant_have_const_ctor
= base_info
.cant_have_const_ctor
;
3234 no_const_asn_ref
= base_info
.no_const_asn_ref
;
3235 n_baseclasses
= TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo
));
3240 first_vfn_base_index
= -1;
3242 max_has_virtual
= has_virtual
;
3244 vfields
= NULL_TREE
;
3245 CLASSTYPE_RTTI (t
) = NULL_TREE
;
3247 cant_have_default_ctor
= 0;
3248 cant_have_const_ctor
= 0;
3249 no_const_asn_ref
= 0;
3253 /* Both of these should be done before now. */
3254 if (write_virtuals
== 3 && CLASSTYPE_INTERFACE_KNOWN (t
)
3255 && ! IS_SIGNATURE (t
))
3257 my_friendly_assert (CLASSTYPE_INTERFACE_ONLY (t
) == interface_only
, 999);
3258 my_friendly_assert (CLASSTYPE_VTABLE_NEEDS_WRITING (t
) == ! interface_only
, 999);
3262 /* The three of these are approximations which may later be
3263 modified. Needed at this point to make add_virtual_function
3264 and modify_vtable_entries work. */
3265 TREE_CHAIN (t_binfo
) = TYPE_BINFO (t
);
3266 TYPE_BINFO (t
) = t_binfo
;
3267 CLASSTYPE_VFIELDS (t
) = vfields
;
3268 CLASSTYPE_VFIELD (t
) = vfield
;
3270 if (IS_SIGNATURE (t
))
3272 else if (flag_all_virtual
== 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t
))
3277 for (x
= TYPE_METHODS (t
); x
; x
= TREE_CHAIN (x
))
3279 GNU_xref_member (current_class_name
, x
);
3281 nonprivate_method
|= ! TREE_PRIVATE (x
);
3283 /* If this was an evil function, don't keep it in class. */
3284 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x
)))
3287 DECL_CLASS_CONTEXT (x
) = t
;
3289 /* Do both of these, even though they're in the same union;
3290 if the insn `r' member and the size `i' member are
3291 different sizes, as on the alpha, the larger of the two
3292 will end up with garbage in it. */
3293 DECL_SAVED_INSNS (x
) = NULL_RTX
;
3294 DECL_FIELD_SIZE (x
) = 0;
3296 check_for_override (x
, t
);
3297 if (DECL_ABSTRACT_VIRTUAL_P (x
) && ! DECL_VINDEX (x
))
3298 cp_error_at ("initializer specified for non-virtual method `%D'", x
);
3300 /* The name of the field is the original field name
3301 Save this in auxiliary field for later overloading. */
3303 || (all_virtual
== 1 && ! DECL_CONSTRUCTOR_P (x
)))
3305 add_virtual_function (&pending_virtuals
, &pending_hard_virtuals
,
3306 &has_virtual
, x
, t
);
3307 if (DECL_ABSTRACT_VIRTUAL_P (x
))
3308 abstract_virtuals
= tree_cons (NULL_TREE
, x
, abstract_virtuals
);
3310 /* XXX Why did I comment this out? (jason) */
3317 for (x
= TYPE_FIELDS (t
); x
; x
= TREE_CHAIN (x
))
3319 GNU_xref_member (current_class_name
, x
);
3321 if (TREE_CODE (x
) == FIELD_DECL
)
3323 DECL_PACKED (x
) |= TYPE_PACKED (t
);
3327 /* Handle access declarations. */
3328 if (TREE_CODE (x
) == USING_DECL
)
3330 tree ctype
= DECL_INITIAL (x
);
3331 tree sname
= DECL_NAME (x
);
3333 = TREE_PRIVATE (x
) ? access_private_node
3334 : TREE_PROTECTED (x
) ? access_protected_node
3335 : access_public_node
;
3339 TREE_CHAIN (last_x
) = TREE_CHAIN (x
);
3341 fields
= TREE_CHAIN (x
);
3343 binfo
= binfo_or_else (ctype
, t
);
3347 if (sname
== constructor_name (ctype
)
3348 || sname
== constructor_name_full (ctype
))
3349 cp_error_at ("using-declaration for constructor", x
);
3351 fdecl
= lookup_field (binfo
, sname
, 0, 0);
3353 fdecl
= lookup_fnfields (binfo
, sname
, 0);
3356 access_decls
= scratch_tree_cons (access
, fdecl
, access_decls
);
3358 cp_error_at ("no members matching `%D' in `%#T'", x
, ctype
);
3364 if (TREE_CODE (x
) == TYPE_DECL
)
3367 /* If we've gotten this far, it's a data member, possibly static,
3368 or an enumerator. */
3370 DECL_FIELD_CONTEXT (x
) = t
;
3372 /* ``A local class cannot have static data members.'' ARM 9.4 */
3373 if (current_function_decl
&& TREE_STATIC (x
))
3374 cp_error_at ("field `%D' in local class cannot be static", x
);
3376 /* Perform error checking that did not get done in
3378 if (TREE_CODE (TREE_TYPE (x
)) == FUNCTION_TYPE
)
3380 cp_error_at ("field `%D' invalidly declared function type",
3382 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3384 else if (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
)
3386 cp_error_at ("field `%D' invalidly declared method type", x
);
3387 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3389 else if (TREE_CODE (TREE_TYPE (x
)) == OFFSET_TYPE
)
3391 cp_error_at ("field `%D' invalidly declared offset type", x
);
3392 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3396 if (DECL_NAME (x
) == constructor_name (t
))
3397 cant_have_default_ctor
= 1;
3400 if (TREE_TYPE (x
) == error_mark_node
)
3403 DECL_SAVED_INSNS (x
) = NULL_RTX
;
3404 DECL_FIELD_SIZE (x
) = 0;
3406 /* When this goes into scope, it will be a non-local reference. */
3407 DECL_NONLOCAL (x
) = 1;
3409 if (TREE_CODE (x
) == CONST_DECL
)
3412 if (TREE_CODE (x
) == VAR_DECL
)
3414 if (TREE_CODE (t
) == UNION_TYPE
)
3415 /* Unions cannot have static members. */
3416 cp_error_at ("field `%D' declared static in union", x
);
3421 /* Now it can only be a FIELD_DECL. */
3423 if (TREE_PRIVATE (x
) || TREE_PROTECTED (x
))
3426 /* If this is of reference type, check if it needs an init.
3427 Also do a little ANSI jig if necessary. */
3428 if (TREE_CODE (TREE_TYPE (x
)) == REFERENCE_TYPE
)
3430 if (DECL_INITIAL (x
) == NULL_TREE
)
3433 /* ARM $12.6.2: [A member initializer list] (or, for an
3434 aggregate, initialization by a brace-enclosed list) is the
3435 only way to initialize nonstatic const and reference
3437 cant_have_default_ctor
= 1;
3438 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) = 1;
3440 if (! TYPE_HAS_CONSTRUCTOR (t
) && extra_warnings
)
3443 cp_warning_at ("non-static reference `%#D' in class without a constructor", x
);
3445 cp_warning_at ("non-static reference in class without a constructor", x
);
3449 if (TREE_CODE (TREE_TYPE (x
)) == POINTER_TYPE
)
3452 /* If any field is const, the structure type is pseudo-const. */
3453 if (TREE_READONLY (x
))
3455 C_TYPE_FIELDS_READONLY (t
) = 1;
3456 if (DECL_INITIAL (x
) == NULL_TREE
)
3457 const_sans_init
= 1;
3459 /* ARM $12.6.2: [A member initializer list] (or, for an
3460 aggregate, initialization by a brace-enclosed list) is the
3461 only way to initialize nonstatic const and reference
3463 cant_have_default_ctor
= 1;
3464 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) = 1;
3466 if (! TYPE_HAS_CONSTRUCTOR (t
) && !IS_SIGNATURE (t
)
3470 cp_warning_at ("non-static const member `%#D' in class without a constructor", x
);
3472 cp_warning_at ("non-static const member in class without a constructor", x
);
3477 /* A field that is pseudo-const makes the structure
3479 tree t1
= TREE_TYPE (x
);
3480 while (TREE_CODE (t1
) == ARRAY_TYPE
)
3481 t1
= TREE_TYPE (t1
);
3482 if (IS_AGGR_TYPE (t1
))
3484 if (C_TYPE_FIELDS_READONLY (t1
))
3485 C_TYPE_FIELDS_READONLY (t
) = 1;
3486 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1
))
3487 const_sans_init
= 1;
3491 /* We set DECL_BIT_FIELD tentatively in grokbitfield.
3492 If the type and width are valid, we'll keep it set.
3493 Otherwise, the flag is cleared. */
3494 if (DECL_BIT_FIELD (x
))
3496 DECL_BIT_FIELD (x
) = 0;
3497 /* Invalid bit-field size done by grokfield. */
3498 /* Detect invalid bit-field type. */
3499 if (DECL_INITIAL (x
)
3500 && ! INTEGRAL_TYPE_P (TREE_TYPE (x
)))
3502 cp_error_at ("bit-field `%#D' with non-integral type", x
);
3503 DECL_INITIAL (x
) = NULL
;
3506 /* Detect and ignore out of range field width. */
3507 if (DECL_INITIAL (x
))
3509 tree w
= DECL_INITIAL (x
);
3512 /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */
3515 /* detect invalid field size. */
3516 if (TREE_CODE (w
) == CONST_DECL
)
3517 w
= DECL_INITIAL (w
);
3518 else if (TREE_READONLY_DECL_P (w
))
3519 w
= decl_constant_value (w
);
3521 if (TREE_CODE (w
) != INTEGER_CST
)
3523 cp_error_at ("bit-field `%D' width not an integer constant",
3525 DECL_INITIAL (x
) = NULL_TREE
;
3527 else if (width
= TREE_INT_CST_LOW (w
),
3530 DECL_INITIAL (x
) = NULL
;
3531 cp_error_at ("negative width in bit-field `%D'", x
);
3533 else if (width
== 0 && DECL_NAME (x
) != 0)
3535 DECL_INITIAL (x
) = NULL
;
3536 cp_error_at ("zero width for bit-field `%D'", x
);
3539 > TYPE_PRECISION (long_long_unsigned_type_node
))
3541 /* The backend will dump if you try to use something
3542 too big; avoid that. */
3543 DECL_INITIAL (x
) = NULL
;
3544 sorry ("bit-fields larger than %d bits",
3545 TYPE_PRECISION (long_long_unsigned_type_node
));
3546 cp_error_at (" in declaration of `%D'", x
);
3548 else if (width
> TYPE_PRECISION (TREE_TYPE (x
))
3549 && TREE_CODE (TREE_TYPE (x
)) != ENUMERAL_TYPE
)
3551 cp_warning_at ("width of `%D' exceeds its type", x
);
3553 else if (TREE_CODE (TREE_TYPE (x
)) == ENUMERAL_TYPE
3554 && ((min_precision (TYPE_MIN_VALUE (TREE_TYPE (x
)),
3555 TREE_UNSIGNED (TREE_TYPE (x
))) > width
)
3556 || (min_precision (TYPE_MAX_VALUE (TREE_TYPE (x
)),
3557 TREE_UNSIGNED (TREE_TYPE (x
))) > width
)))
3559 cp_warning_at ("`%D' is too small to hold all values of `%#T'",
3563 if (DECL_INITIAL (x
) == NULL_TREE
)
3565 else if (width
== 0)
3567 #ifdef EMPTY_FIELD_BOUNDARY
3568 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
), EMPTY_FIELD_BOUNDARY
);
3570 #ifdef PCC_BITFIELD_TYPE_MATTERS
3571 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
),
3572 TYPE_ALIGN (TREE_TYPE (x
)));
3577 DECL_INITIAL (x
) = NULL_TREE
;
3578 DECL_FIELD_SIZE (x
) = width
;
3579 DECL_BIT_FIELD (x
) = 1;
3583 /* Non-bit-fields are aligned for their type. */
3584 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
), TYPE_ALIGN (TREE_TYPE (x
)));
3588 tree type
= TREE_TYPE (x
);
3590 while (TREE_CODE (type
) == ARRAY_TYPE
)
3591 type
= TREE_TYPE (type
);
3593 if (TYPE_LANG_SPECIFIC (type
) && ! ANON_UNION_P (x
)
3594 && ! TYPE_PTRMEMFUNC_P (type
))
3596 /* Never let anything with uninheritable virtuals
3597 make it through without complaint. */
3598 if (CLASSTYPE_ABSTRACT_VIRTUALS (type
))
3599 abstract_virtuals_error (x
, type
);
3601 /* Don't let signatures make it through either. */
3602 if (IS_SIGNATURE (type
))
3603 signature_error (x
, type
);
3605 if (code
== UNION_TYPE
)
3608 if (TYPE_NEEDS_CONSTRUCTING (type
))
3609 fie
= "constructor";
3610 else if (TYPE_NEEDS_DESTRUCTOR (type
))
3612 else if (TYPE_HAS_REAL_ASSIGNMENT (type
))
3613 fie
= "assignment operator";
3615 cp_error_at ("member `%#D' with %s not allowed in union", x
,
3620 TYPE_NEEDS_CONSTRUCTING (t
) |= TYPE_NEEDS_CONSTRUCTING (type
);
3621 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_NEEDS_DESTRUCTOR (type
);
3622 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type
);
3623 TYPE_HAS_COMPLEX_INIT_REF (t
) |= TYPE_HAS_COMPLEX_INIT_REF (type
);
3626 if (!TYPE_HAS_CONST_INIT_REF (type
))
3627 cant_have_const_ctor
= 1;
3629 if (!TYPE_HAS_CONST_ASSIGN_REF (type
))
3630 no_const_asn_ref
= 1;
3632 if (TYPE_HAS_CONSTRUCTOR (type
)
3633 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type
))
3635 cant_have_default_ctor
= 1;
3637 /* This is wrong for aggregates. */
3638 if (! TYPE_HAS_CONSTRUCTOR (t
))
3641 cp_pedwarn_at ("member `%#D' with only non-default constructor", x
);
3643 cp_pedwarn_at ("member with only non-default constructor", x
);
3644 cp_pedwarn_at ("in class without a constructor",
3650 if (DECL_INITIAL (x
) != NULL_TREE
)
3652 /* `build_class_init_list' does not recognize
3654 if (code
== UNION_TYPE
&& any_default_members
!= 0)
3655 cp_error_at ("multiple fields in union `%T' initialized");
3656 any_default_members
= 1;
3661 /* If this type has any constant members which did not come
3662 with their own initialization, mark that fact here. It is
3663 not an error here, since such types can be saved either by their
3664 constructors, or by fortuitous initialization. */
3665 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t
) = const_sans_init
;
3666 CLASSTYPE_REF_FIELDS_NEED_INIT (t
) = ref_sans_init
;
3667 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = abstract_virtuals
;
3669 /* Synthesize any needed methods. Note that methods will be synthesized
3670 for anonymous unions; grok_x_components undoes that. */
3673 nonprivate_method
= 1;
3675 if (TYPE_NEEDS_DESTRUCTOR (t
) && !TYPE_HAS_DESTRUCTOR (t
)
3676 && !IS_SIGNATURE (t
))
3678 /* Here we must cons up a destructor on the fly. */
3679 tree dtor
= cons_up_default_function (t
, name
, 0);
3680 check_for_override (dtor
, t
);
3682 /* If we couldn't make it work, then pretend we didn't need it. */
3683 if (dtor
== void_type_node
)
3684 TYPE_NEEDS_DESTRUCTOR (t
) = 0;
3687 /* Link dtor onto end of fn_fields. */
3689 TREE_CHAIN (dtor
) = fn_fields
;
3692 if (DECL_VINDEX (dtor
))
3693 add_virtual_function (&pending_virtuals
, &pending_hard_virtuals
,
3694 &has_virtual
, dtor
, t
);
3695 nonprivate_method
= 1;
3699 /* Effective C++ rule 11. */
3700 if (has_pointers
&& warn_ecpp
&& TYPE_HAS_CONSTRUCTOR (t
)
3701 && ! (TYPE_HAS_INIT_REF (t
) && TYPE_HAS_ASSIGN_REF (t
)))
3703 cp_warning ("`%#T' has pointer data members", t
);
3705 if (! TYPE_HAS_INIT_REF (t
))
3707 cp_warning (" but does not override `%T(const %T&)'", t
, t
);
3708 if (! TYPE_HAS_ASSIGN_REF (t
))
3709 cp_warning (" or `operator=(const %T&)'", t
);
3711 else if (! TYPE_HAS_ASSIGN_REF (t
))
3712 cp_warning (" but does not override `operator=(const %T&)'", t
);
3715 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_HAS_DESTRUCTOR (t
);
3717 TYPE_HAS_COMPLEX_INIT_REF (t
)
3718 |= (TYPE_HAS_INIT_REF (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3719 || has_virtual
|| any_default_members
);
3720 TYPE_NEEDS_CONSTRUCTING (t
)
3721 |= (TYPE_HAS_CONSTRUCTOR (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3722 || has_virtual
|| any_default_members
);
3723 if (! IS_SIGNATURE (t
))
3724 CLASSTYPE_NON_AGGREGATE (t
)
3725 = ! aggregate
|| has_virtual
|| TYPE_HAS_CONSTRUCTOR (t
);
3727 /* ARM $12.1: A default constructor will be generated for a class X
3728 only if no constructor has been declared for class X. So we
3729 check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate
3730 one if they declared a constructor in this class. */
3731 if (! TYPE_HAS_CONSTRUCTOR (t
) && ! cant_have_default_ctor
3732 && ! IS_SIGNATURE (t
))
3734 tree default_fn
= cons_up_default_function (t
, name
, 2);
3735 TREE_CHAIN (default_fn
) = fn_fields
;
3736 fn_fields
= default_fn
;
3739 /* Create default copy constructor, if needed. */
3740 if (! TYPE_HAS_INIT_REF (t
) && ! IS_SIGNATURE (t
))
3742 /* ARM 12.18: You get either X(X&) or X(const X&), but
3744 tree default_fn
= cons_up_default_function (t
, name
,
3745 3 + cant_have_const_ctor
);
3746 TREE_CHAIN (default_fn
) = fn_fields
;
3747 fn_fields
= default_fn
;
3750 TYPE_HAS_REAL_ASSIGNMENT (t
) |= TYPE_HAS_ASSIGNMENT (t
);
3751 TYPE_HAS_REAL_ASSIGN_REF (t
) |= TYPE_HAS_ASSIGN_REF (t
);
3752 TYPE_HAS_COMPLEX_ASSIGN_REF (t
)
3753 |= TYPE_HAS_ASSIGN_REF (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
);
3755 if (! TYPE_HAS_ASSIGN_REF (t
) && ! IS_SIGNATURE (t
))
3757 tree default_fn
= cons_up_default_function (t
, name
,
3758 5 + no_const_asn_ref
);
3759 TREE_CHAIN (default_fn
) = fn_fields
;
3760 fn_fields
= default_fn
;
3765 TYPE_METHODS (t
) = fn_fields
;
3766 method_vec
= finish_struct_methods (t
, fn_fields
, nonprivate_method
);
3768 if (TYPE_HAS_CONSTRUCTOR (t
)
3769 && CLASSTYPE_FRIEND_CLASSES (t
) == NULL_TREE
3770 && DECL_FRIENDLIST (TYPE_MAIN_DECL (t
)) == NULL_TREE
)
3772 int nonprivate_ctor
= 0;
3775 for (ctor
= TREE_VEC_ELT (method_vec
, 0);
3777 ctor
= DECL_CHAIN (ctor
))
3778 if (! TREE_PRIVATE (ctor
))
3780 nonprivate_ctor
= 1;
3784 if (nonprivate_ctor
== 0 && warn_ctor_dtor_privacy
)
3785 cp_warning ("`%#T' only defines private constructors and has no friends",
3793 /* Just in case these got accidentally
3794 filled in by syntax errors. */
3795 TYPE_HAS_CONSTRUCTOR (t
) = 0;
3796 TYPE_HAS_DESTRUCTOR (t
) = 0;
3800 int n_methods
= method_vec
? TREE_VEC_LENGTH (method_vec
) : 0;
3802 for (access_decls
= nreverse (access_decls
); access_decls
;
3803 access_decls
= TREE_CHAIN (access_decls
))
3805 tree fdecl
= TREE_VALUE (access_decls
);
3806 tree flist
= NULL_TREE
;
3808 tree access
= TREE_PURPOSE (access_decls
);
3812 if (TREE_CODE (fdecl
) == TREE_LIST
)
3815 fdecl
= TREE_VALUE (flist
);
3818 name
= DECL_NAME (fdecl
);
3820 for (; i
< n_methods
; i
++)
3821 if (DECL_NAME (TREE_VEC_ELT (method_vec
, i
)) == name
)
3823 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl
, t
);
3824 cp_error_at (" because of local method `%#D' with same name",
3825 TREE_VEC_ELT (method_vec
, i
));
3833 for (tmp
= fields
; tmp
; tmp
= TREE_CHAIN (tmp
))
3834 if (DECL_NAME (tmp
) == name
)
3836 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl
, t
);
3837 cp_error_at (" because of local field `%#D' with same name", tmp
);
3845 /* Make type T see field decl FDECL with access ACCESS.*/
3848 fdecl
= TREE_VALUE (flist
);
3851 if (alter_access (t
, fdecl
, access
) == 0)
3853 fdecl
= DECL_CHAIN (fdecl
);
3857 alter_access (t
, fdecl
, access
);
3862 if (vfield
== NULL_TREE
&& has_virtual
)
3864 /* We build this decl with ptr_type_node, and
3865 change the type when we know what it should be. */
3866 vfield
= build_lang_field_decl (FIELD_DECL
, get_vfield_name (t
),
3868 /* If you change any of the below, take a look at all the
3869 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3871 DECL_ASSEMBLER_NAME (vfield
) = get_identifier (VFIELD_BASE
);
3872 CLASSTYPE_VFIELD (t
) = vfield
;
3873 DECL_VIRTUAL_P (vfield
) = 1;
3874 DECL_ARTIFICIAL (vfield
) = 1;
3875 DECL_FIELD_CONTEXT (vfield
) = t
;
3876 DECL_CLASS_CONTEXT (vfield
) = t
;
3877 DECL_FCONTEXT (vfield
) = t
;
3878 DECL_SAVED_INSNS (vfield
) = NULL_RTX
;
3879 DECL_FIELD_SIZE (vfield
) = 0;
3880 DECL_ALIGN (vfield
) = TYPE_ALIGN (ptr_type_node
);
3882 /* This is more efficient, but breaks binary compatibility, turn
3883 it on sometime when we don't care. If we turn it on, we also
3884 have to enable the code in dfs_init_vbase_pointers. */
3885 /* vfield is always first entry in structure. */
3886 TREE_CHAIN (vfield
) = fields
;
3891 my_friendly_assert (TREE_CHAIN (last_x
) == NULL_TREE
, 175);
3892 TREE_CHAIN (last_x
) = vfield
;
3899 vfields
= chainon (vfields
, CLASSTYPE_AS_LIST (t
));
3902 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3903 And they have already done their work.
3905 C++: maybe we will support default field initialization some day... */
3907 /* Delete all zero-width bit-fields from the front of the fieldlist */
3908 while (fields
&& DECL_BIT_FIELD (fields
)
3909 && DECL_INITIAL (fields
))
3910 fields
= TREE_CHAIN (fields
);
3911 /* Delete all such fields from the rest of the fields. */
3912 for (x
= fields
; x
;)
3914 if (TREE_CHAIN (x
) && DECL_BIT_FIELD (TREE_CHAIN (x
))
3915 && DECL_INITIAL (TREE_CHAIN (x
)))
3916 TREE_CHAIN (x
) = TREE_CHAIN (TREE_CHAIN (x
));
3920 /* Delete all duplicate fields from the fields */
3921 delete_duplicate_fields (fields
);
3923 /* Catch function/field name conflict. We don't need to do this for a
3924 signature, since it can only contain the fields constructed in
3925 append_signature_fields. */
3926 if (! IS_SIGNATURE (t
))
3928 int n_methods
= method_vec
? TREE_VEC_LENGTH (method_vec
) : 0;
3929 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
3931 tree name
= DECL_NAME (x
);
3934 if (TREE_CODE (x
) == TYPE_DECL
&& DECL_ARTIFICIAL (x
))
3937 for (; i
< n_methods
; ++i
)
3938 if (DECL_NAME (TREE_VEC_ELT (method_vec
, i
)) == name
)
3940 cp_error_at ("data member `%#D' conflicts with", x
);
3941 cp_error_at ("function member `%#D'",
3942 TREE_VEC_ELT (method_vec
, i
));
3948 /* Now we have the final fieldlist for the data fields. Record it,
3949 then lay out the structure or union (including the fields). */
3951 TYPE_FIELDS (t
) = fields
;
3953 /* Pass layout information about base classes to layout_type, if any. */
3956 tree pseudo_basetype
= TREE_TYPE (base_layout_decl
);
3958 TREE_CHAIN (base_layout_decl
) = TYPE_FIELDS (t
);
3959 TYPE_FIELDS (t
) = base_layout_decl
;
3961 TYPE_SIZE (pseudo_basetype
) = CLASSTYPE_SIZE (t
);
3962 TYPE_MODE (pseudo_basetype
) = TYPE_MODE (t
);
3963 TYPE_ALIGN (pseudo_basetype
) = CLASSTYPE_ALIGN (t
);
3964 DECL_ALIGN (base_layout_decl
) = TYPE_ALIGN (pseudo_basetype
);
3965 /* Don't re-use old size. */
3966 DECL_SIZE (base_layout_decl
) = NULL_TREE
;
3970 /* C++: do not let empty structures exist. */
3971 tree decl
= build_lang_field_decl
3972 (FIELD_DECL
, NULL_TREE
, char_type_node
);
3973 TREE_CHAIN (decl
) = TYPE_FIELDS (t
);
3974 TYPE_FIELDS (t
) = decl
;
3979 finish_struct_anon (t
);
3981 if (n_baseclasses
|| empty
)
3982 TYPE_FIELDS (t
) = TREE_CHAIN (TYPE_FIELDS (t
));
3984 /* Set the TYPE_DECL for this type to contain the right
3985 value for DECL_OFFSET, so that we can use it as part
3986 of a COMPONENT_REF for multiple inheritance. */
3988 layout_decl (TYPE_MAIN_DECL (t
), 0);
3990 /* Now fix up any virtual base class types that we left lying
3991 around. We must get these done before we try to lay out the
3992 virtual function table. */
3993 pending_hard_virtuals
= nreverse (pending_hard_virtuals
);
3995 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
3999 max_has_virtual
= layout_vbasetypes (t
, max_has_virtual
);
4000 vbases
= CLASSTYPE_VBASECLASSES (t
);
4001 CLASSTYPE_N_VBASECLASSES (t
) = list_length (vbases
);
4004 /* Now fixup overrides of all functions in vtables from all
4005 direct or indirect virtual base classes. */
4006 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
4007 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
4009 for (i
= 0; i
< n_baseclasses
; i
++)
4011 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
4012 tree basetype
= BINFO_TYPE (base_binfo
);
4015 vbases
= CLASSTYPE_VBASECLASSES (basetype
);
4018 merge_overrides (binfo_member (BINFO_TYPE (vbases
),
4019 CLASSTYPE_VBASECLASSES (t
)),
4021 vbases
= TREE_CHAIN (vbases
);
4027 /* Set up the DECL_FIELD_BITPOS of the vfield if we need to, as we
4028 might need to know it for setting up the offsets in the vtable
4029 (or in thunks) below. */
4030 if (vfield
!= NULL_TREE
4031 && 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 cp_warning ("Doing hard virtuals for %T...", t
);
4052 if (has_virtual
> max_has_virtual
)
4053 max_has_virtual
= has_virtual
;
4054 if (max_has_virtual
> 0)
4055 TYPE_VIRTUAL_P (t
) = 1;
4057 if (flag_rtti
&& TYPE_VIRTUAL_P (t
) && !pending_hard_virtuals
)
4058 modify_all_vtables (t
, NULL_TREE
, NULL_TREE
);
4060 while (pending_hard_virtuals
)
4062 modify_all_vtables (t
,
4063 TREE_PURPOSE (pending_hard_virtuals
),
4064 TREE_VALUE (pending_hard_virtuals
));
4065 pending_hard_virtuals
= TREE_CHAIN (pending_hard_virtuals
);
4068 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
4071 /* Now fixup any virtual function entries from virtual bases
4072 that have different deltas. This has to come after we do the
4073 pending hard virtuals, as we might have a function that comes
4074 from multiple virtual base instances that is only overridden
4075 by a hard virtual above. */
4076 vbases
= CLASSTYPE_VBASECLASSES (t
);
4079 /* We might be able to shorten the amount of work we do by
4080 only doing this for vtables that come from virtual bases
4081 that have differing offsets, but don't want to miss any
4083 fixup_vtable_deltas (vbases
, 1, t
);
4084 vbases
= TREE_CHAIN (vbases
);
4088 /* Under our model of GC, every C++ class gets its own virtual
4089 function table, at least virtually. */
4090 if (pending_virtuals
)
4092 pending_virtuals
= nreverse (pending_virtuals
);
4093 /* We must enter these virtuals into the table. */
4094 if (first_vfn_base_index
< 0)
4096 /* The second slot is for the tdesc pointer when thunks are used. */
4097 if (flag_vtable_thunks
)
4098 pending_virtuals
= tree_cons (NULL_TREE
, NULL_TREE
, pending_virtuals
);
4100 /* The first slot is for the rtti offset. */
4101 pending_virtuals
= tree_cons (NULL_TREE
, NULL_TREE
, pending_virtuals
);
4103 set_rtti_entry (pending_virtuals
, size_zero_node
, t
);
4104 build_vtable (NULL_TREE
, t
);
4108 /* Here we know enough to change the type of our virtual
4109 function table, but we will wait until later this function. */
4111 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t
)))
4112 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), first_vfn_base_index
), t
);
4115 /* If this type has basetypes with constructors, then those
4116 constructors might clobber the virtual function table. But
4117 they don't if the derived class shares the exact vtable of the base
4120 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t
) = 1;
4122 else if (first_vfn_base_index
>= 0)
4124 tree binfo
= TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), first_vfn_base_index
);
4125 /* This class contributes nothing new to the virtual function
4126 table. However, it may have declared functions which
4127 went into the virtual function table "inherited" from the
4128 base class. If so, we grab a copy of those updated functions,
4129 and pretend they are ours. */
4131 /* See if we should steal the virtual info from base class. */
4132 if (TYPE_BINFO_VTABLE (t
) == NULL_TREE
)
4133 TYPE_BINFO_VTABLE (t
) = BINFO_VTABLE (binfo
);
4134 if (TYPE_BINFO_VIRTUALS (t
) == NULL_TREE
)
4135 TYPE_BINFO_VIRTUALS (t
) = BINFO_VIRTUALS (binfo
);
4136 if (TYPE_BINFO_VTABLE (t
) != BINFO_VTABLE (binfo
))
4137 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t
) = 1;
4140 if (max_has_virtual
|| first_vfn_base_index
>= 0)
4142 CLASSTYPE_VSIZE (t
) = has_virtual
;
4143 if (first_vfn_base_index
>= 0)
4145 if (pending_virtuals
)
4146 TYPE_BINFO_VIRTUALS (t
) = chainon (TYPE_BINFO_VIRTUALS (t
),
4149 else if (has_virtual
)
4151 TYPE_BINFO_VIRTUALS (t
) = pending_virtuals
;
4152 if (write_virtuals
>= 0)
4153 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t
)) = 1;
4157 /* Now lay out the virtual function table. */
4162 if (TREE_TYPE (vfield
) == ptr_type_node
)
4164 /* We must create a pointer to this table because
4165 the one inherited from base class does not exist.
4166 We will fill in the type when we know what it
4167 should really be. Use `size_int' so values are memoized
4169 itype
= build_index_type (size_int (has_virtual
));
4170 atype
= build_array_type (vtable_entry_type
, itype
);
4171 layout_type (atype
);
4172 TREE_TYPE (vfield
) = build_pointer_type (atype
);
4176 atype
= TREE_TYPE (TREE_TYPE (vfield
));
4178 if (has_virtual
!= TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype
))))
4180 /* We must extend (or create) the boundaries on this array,
4181 because we picked up virtual functions from multiple
4183 itype
= build_index_type (size_int (has_virtual
));
4184 atype
= build_array_type (vtable_entry_type
, itype
);
4185 layout_type (atype
);
4186 vfield
= copy_node (vfield
);
4187 TREE_TYPE (vfield
) = build_pointer_type (atype
);
4191 CLASSTYPE_VFIELD (t
) = vfield
;
4192 if (TREE_TYPE (TYPE_BINFO_VTABLE (t
)) != atype
)
4194 TREE_TYPE (TYPE_BINFO_VTABLE (t
)) = atype
;
4195 DECL_SIZE (TYPE_BINFO_VTABLE (t
)) = 0;
4196 layout_decl (TYPE_BINFO_VTABLE (t
), 0);
4197 /* At one time the vtable info was grabbed 2 words at a time. This
4198 fails on sparc unless you have 8-byte alignment. (tiemann) */
4199 DECL_ALIGN (TYPE_BINFO_VTABLE (t
))
4200 = MAX (TYPE_ALIGN (double_type_node
),
4201 DECL_ALIGN (TYPE_BINFO_VTABLE (t
)));
4204 else if (first_vfn_base_index
>= 0)
4205 CLASSTYPE_VFIELD (t
) = vfield
;
4206 CLASSTYPE_VFIELDS (t
) = vfields
;
4208 finish_struct_bits (t
, max_has_virtual
);
4210 /* Complete the rtl for any static member objects of the type we're
4212 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
4214 if (TREE_CODE (x
) == VAR_DECL
&& TREE_STATIC (x
)
4215 && TREE_TYPE (x
) == t
)
4217 DECL_MODE (x
) = TYPE_MODE (t
);
4218 make_decl_rtl (x
, NULL
, 0);
4222 if (TYPE_HAS_CONSTRUCTOR (t
))
4224 tree vfields
= CLASSTYPE_VFIELDS (t
);
4228 /* Mark the fact that constructor for T
4229 could affect anybody inheriting from T
4230 who wants to initialize vtables for VFIELDS's type. */
4231 if (VF_DERIVED_VALUE (vfields
))
4232 TREE_ADDRESSABLE (vfields
) = 1;
4233 vfields
= TREE_CHAIN (vfields
);
4235 if (any_default_members
!= 0)
4236 build_class_init_list (t
);
4238 else if (TYPE_NEEDS_CONSTRUCTING (t
))
4239 build_class_init_list (t
);
4241 /* Write out inline function definitions. */
4242 do_inline_function_hair (t
, CLASSTYPE_INLINE_FRIENDS (t
));
4243 CLASSTYPE_INLINE_FRIENDS (t
) = 0;
4245 if (CLASSTYPE_VSIZE (t
) != 0)
4248 /* This is now done above. */
4249 if (DECL_FIELD_CONTEXT (vfield
) != t
)
4251 tree binfo
= get_binfo (DECL_FIELD_CONTEXT (vfield
), t
, 0);
4252 tree offset
= BINFO_OFFSET (binfo
);
4254 vfield
= copy_node (vfield
);
4255 copy_lang_decl (vfield
);
4257 if (! integer_zerop (offset
))
4258 offset
= size_binop (MULT_EXPR
, offset
, size_int (BITS_PER_UNIT
));
4259 DECL_FIELD_CONTEXT (vfield
) = t
;
4260 DECL_CLASS_CONTEXT (vfield
) = t
;
4261 DECL_FIELD_BITPOS (vfield
)
4262 = size_binop (PLUS_EXPR
, offset
, DECL_FIELD_BITPOS (vfield
));
4263 CLASSTYPE_VFIELD (t
) = vfield
;
4267 /* In addition to this one, all the other vfields should be listed. */
4268 /* Before that can be done, we have to have FIELD_DECLs for them, and
4269 a place to find them. */
4270 TYPE_NONCOPIED_PARTS (t
) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t
)), vfield
);
4272 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (t
)
4273 && DECL_VINDEX (TREE_VEC_ELT (method_vec
, 1)) == NULL_TREE
)
4274 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4278 /* Make the rtl for any new vtables we have created, and unmark
4279 the base types we marked. */
4280 finish_vtbls (TYPE_BINFO (t
), 1, t
);
4281 hack_incomplete_structures (t
);
4284 if (TYPE_NAME (t
) && TYPE_IDENTIFIER (t
))
4285 undo_template_name_overload (TYPE_IDENTIFIER (t
), 1);
4288 resume_momentary (old
);
4290 if (warn_overloaded_virtual
)
4294 /* This has to be done after we have sorted out what to do with
4295 the enclosing type. */
4296 if (write_symbols
!= DWARF_DEBUG
)
4298 /* Be smarter about nested classes here. If a type is nested,
4299 only output it if we would output the enclosing type. */
4300 if (DECL_CONTEXT (TYPE_MAIN_DECL (t
))
4301 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (TYPE_MAIN_DECL (t
)))) == 't')
4302 DECL_IGNORED_P (TYPE_MAIN_DECL (t
)) = TREE_ASM_WRITTEN (TYPE_MAIN_DECL (t
));
4306 if (write_symbols
!= DWARF_DEBUG
&& write_symbols
!= DWARF2_DEBUG
)
4308 /* If the type has methods, we want to think about cutting down
4309 the amount of symbol table stuff we output. The value stored in
4310 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4311 For example, if a member function is seen and we decide to
4312 write out that member function, then we can change the value
4313 of the DECL_IGNORED_P slot, and the type will be output when
4314 that member function's debug info is written out.
4316 We can't do this with DWARF, which does not support name
4317 references between translation units. */
4318 if (CLASSTYPE_METHOD_VEC (t
))
4320 extern tree pending_vtables
;
4322 /* Don't output full info about any type
4323 which does not have its implementation defined here. */
4324 if (TYPE_VIRTUAL_P (t
) && write_virtuals
== 2)
4325 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
))
4326 = (value_member (TYPE_IDENTIFIER (t
), pending_vtables
) == 0);
4327 else if (CLASSTYPE_INTERFACE_ONLY (t
))
4328 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4330 /* XXX do something about this. */
4331 else if (CLASSTYPE_INTERFACE_UNKNOWN (t
))
4332 /* Only a first approximation! */
4333 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4336 else if (CLASSTYPE_INTERFACE_ONLY (t
))
4337 TYPE_DECL_SUPPRESS_DEBUG (TYPE_MAIN_DECL (t
)) = 1;
4340 /* Finish debugging output for this type. */
4341 rest_of_type_compilation (t
, toplevel_bindings_p ());
4347 finish_struct (t
, list_of_fieldlists
, attributes
, warn_anon
)
4348 tree t
, list_of_fieldlists
, attributes
;
4351 tree fields
= NULL_TREE
;
4352 tree
*tail
= &TYPE_METHODS (t
);
4353 tree name
= TYPE_NAME (t
);
4354 tree x
, last_x
= NULL_TREE
;
4356 tree dummy
= NULL_TREE
;
4358 if (TREE_CODE (name
) == TYPE_DECL
)
4362 DECL_SOURCE_FILE (name
) = input_filename
;
4363 /* For TYPE_DECL that are not typedefs (those marked with a line
4364 number of zero, we don't want to mark them as real typedefs.
4365 If this fails one needs to make sure real typedefs have a
4366 previous line number, even if it is wrong, that way the below
4367 will fill in the right line number. (mrs) */
4368 if (DECL_SOURCE_LINE (name
))
4369 DECL_SOURCE_LINE (name
) = lineno
;
4370 CLASSTYPE_SOURCE_LINE (t
) = lineno
;
4371 name
= DECL_NAME (name
);
4374 /* Append the fields we need for constructing signature tables. */
4375 if (IS_SIGNATURE (t
))
4376 append_signature_fields (list_of_fieldlists
);
4378 /* Move our self-reference declaration to the end of the field list so
4379 any real field with the same name takes precedence. */
4380 if (list_of_fieldlists
4381 && TREE_VALUE (list_of_fieldlists
)
4382 && DECL_ARTIFICIAL (TREE_VALUE (list_of_fieldlists
)))
4384 dummy
= TREE_VALUE (list_of_fieldlists
);
4385 list_of_fieldlists
= TREE_CHAIN (list_of_fieldlists
);
4388 if (last_x
&& list_of_fieldlists
)
4389 TREE_CHAIN (last_x
) = TREE_VALUE (list_of_fieldlists
);
4391 while (list_of_fieldlists
)
4393 access
= TREE_PURPOSE (list_of_fieldlists
);
4395 /* For signatures, we made all methods `public' in the parser and
4396 reported an error if a access specifier was used. */
4397 if (access
== access_default_node
)
4399 if (CLASSTYPE_DECLARED_CLASS (t
) == 0)
4400 access
= access_public_node
;
4402 access
= access_private_node
;
4405 for (x
= TREE_VALUE (list_of_fieldlists
); x
; x
= TREE_CHAIN (x
))
4407 TREE_PRIVATE (x
) = access
== access_private_node
;
4408 TREE_PROTECTED (x
) = access
== access_protected_node
;
4410 /* Check for inconsistent use of this name in the class body.
4411 Enums, types and static vars have already been checked. */
4412 if (TREE_CODE (x
) != TYPE_DECL
&& TREE_CODE (x
) != USING_DECL
4413 && TREE_CODE (x
) != CONST_DECL
&& TREE_CODE (x
) != VAR_DECL
)
4415 tree name
= DECL_NAME (x
);
4418 /* Don't get confused by access decls. */
4419 if (name
&& TREE_CODE (name
) == IDENTIFIER_NODE
)
4420 icv
= IDENTIFIER_CLASS_VALUE (name
);
4425 /* Don't complain about constructors. */
4426 && name
!= constructor_name (current_class_type
)
4427 /* Or inherited names. */
4428 && id_in_current_class (name
)
4429 /* Or shadowed tags. */
4430 && !(TREE_CODE (icv
) == TYPE_DECL
4431 && DECL_CONTEXT (icv
) == t
))
4433 cp_error_at ("declaration of identifier `%D' as `%+#D'",
4435 cp_error_at ("conflicts with other use in class as `%#D'",
4440 if (TREE_CODE (x
) == FUNCTION_DECL
4441 || DECL_FUNCTION_TEMPLATE_P (x
))
4443 DECL_CLASS_CONTEXT (x
) = t
;
4445 TREE_CHAIN (last_x
) = TREE_CHAIN (x
);
4446 /* Link x onto end of TYPE_METHODS. */
4448 tail
= &TREE_CHAIN (x
);
4452 if (TREE_CODE (x
) != TYPE_DECL
)
4453 DECL_FIELD_CONTEXT (x
) = t
;
4459 list_of_fieldlists
= TREE_CHAIN (list_of_fieldlists
);
4460 /* link the tail while we have it! */
4463 TREE_CHAIN (last_x
) = NULL_TREE
;
4465 if (list_of_fieldlists
4466 && TREE_VALUE (list_of_fieldlists
)
4467 && TREE_CODE (TREE_VALUE (list_of_fieldlists
)) != FUNCTION_DECL
)
4468 TREE_CHAIN (last_x
) = TREE_VALUE (list_of_fieldlists
);
4472 /* Now add the tags, if any, to the list of TYPE_DECLs
4473 defined for this type. */
4474 if (CLASSTYPE_TAGS (t
) || dummy
)
4476 /* The list of tags was built up in pushtag in reverse order; we need
4477 to fix that so that enumerators will be processed in forward order
4478 in template instantiation. */
4479 CLASSTYPE_TAGS (t
) = x
= nreverse (CLASSTYPE_TAGS (t
));
4482 tree tag
= TYPE_MAIN_DECL (TREE_VALUE (x
));
4484 TREE_NONLOCAL_FLAG (TREE_VALUE (x
)) = 0;
4486 last_x
= chainon (last_x
, tag
);
4489 last_x
= chainon (last_x
, dummy
);
4490 if (fields
== NULL_TREE
)
4492 CLASSTYPE_LOCAL_TYPEDECLS (t
) = 1;
4496 TYPE_FIELDS (t
) = fields
;
4498 cplus_decl_attributes (t
, attributes
, NULL_TREE
);
4500 if (processing_template_decl
)
4502 tree d
= getdecls ();
4503 for (; d
; d
= TREE_CHAIN (d
))
4505 /* If this is the decl for the class or one of the template
4506 parms, we've seen all the injected decls. */
4507 if ((TREE_CODE (d
) == TYPE_DECL
4508 && (TREE_TYPE (d
) == t
4509 || TREE_CODE (TREE_TYPE (d
)) == TEMPLATE_TYPE_PARM
))
4510 || TREE_CODE (d
) == CONST_DECL
)
4512 /* Don't inject cache decls. */
4513 else if (IDENTIFIER_TEMPLATE (DECL_NAME (d
)))
4515 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t
))
4516 = tree_cons (NULL_TREE
, d
,
4517 DECL_TEMPLATE_INJECT (CLASSTYPE_TI_TEMPLATE (t
)));
4519 CLASSTYPE_METHOD_VEC (t
)
4520 = finish_struct_methods (t
, TYPE_METHODS (t
), 1);
4521 TYPE_SIZE (t
) = integer_zero_node
;
4524 t
= finish_struct_1 (t
, warn_anon
);
4526 TYPE_BEING_DEFINED (t
) = 0;
4528 if (current_class_type
)
4531 error ("trying to finish struct, but kicked out due to previous parse errors.");
4536 /* Return non-zero if the effective type of INSTANCE is static.
4537 Used to determine whether the virtual function table is needed
4540 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4541 of our knowledge of its type. */
4544 resolves_to_fixed_type_p (instance
, nonnull
)
4548 switch (TREE_CODE (instance
))
4551 /* Check that we are not going through a cast of some sort. */
4552 if (TREE_TYPE (instance
)
4553 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance
, 0))))
4554 instance
= TREE_OPERAND (instance
, 0);
4555 /* fall through... */
4557 /* This is a call to a constructor, hence it's never zero. */
4558 if (TREE_HAS_CONSTRUCTOR (instance
))
4567 /* This is a call to a constructor, hence it's never zero. */
4568 if (TREE_HAS_CONSTRUCTOR (instance
))
4574 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4577 /* This is a call to `new', hence it's never zero. */
4578 if (TREE_CALLS_NEW (instance
))
4588 if (TREE_CODE (TREE_OPERAND (instance
, 1)) == INTEGER_CST
)
4589 /* Propagate nonnull. */
4590 resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4591 if (TREE_CODE (TREE_OPERAND (instance
, 0)) == ADDR_EXPR
)
4592 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4597 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4602 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4605 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 1), nonnull
);
4609 if (TREE_CODE (TREE_TYPE (instance
)) == ARRAY_TYPE
4610 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance
))))
4616 /* fall through... */
4619 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
4627 if (instance
== current_class_ptr
4628 && flag_this_is_variable
<= 0)
4630 /* Some people still use `this = 0' inside destructors. */
4631 *nonnull
= ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl
));
4632 /* In a constructor, we know our type. */
4633 if (flag_this_is_variable
< 0)
4636 else if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
4637 /* Reference variables should be references to objects. */
4648 init_class_processing ()
4650 current_class_depth
= 0;
4651 current_class_stacksize
= 10;
4652 current_class_base
= (tree
*)xmalloc(current_class_stacksize
* sizeof (tree
));
4653 current_class_stack
= current_class_base
;
4655 current_lang_stacksize
= 10;
4656 current_lang_base
= (tree
*)xmalloc(current_lang_stacksize
* sizeof (tree
));
4657 current_lang_stack
= current_lang_base
;
4659 access_default_node
= build_int_2 (0, 0);
4660 access_public_node
= build_int_2 (1, 0);
4661 access_protected_node
= build_int_2 (2, 0);
4662 access_private_node
= build_int_2 (3, 0);
4663 access_default_virtual_node
= build_int_2 (4, 0);
4664 access_public_virtual_node
= build_int_2 (5, 0);
4665 access_private_virtual_node
= build_int_2 (6, 0);
4667 /* Keep these values lying around. */
4668 base_layout_decl
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, error_mark_node
);
4669 TREE_TYPE (base_layout_decl
) = make_node (RECORD_TYPE
);
4671 gcc_obstack_init (&class_obstack
);
4674 /* Set current scope to NAME. CODE tells us if this is a
4675 STRUCT, UNION, or ENUM environment.
4677 NAME may end up being NULL_TREE if this is an anonymous or
4678 late-bound struct (as in "struct { ... } foo;") */
4680 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
4681 appropriate values, found by looking up the type definition of
4684 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
4685 which can be seen locally to the class. They are shadowed by
4686 any subsequent local declaration (including parameter names).
4688 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
4689 which have static meaning (i.e., static members, static
4690 member functions, enum declarations, etc).
4692 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
4693 which can be seen locally to the class (as in 1), but
4694 know that we are doing this for declaration purposes
4695 (i.e. friend foo::bar (int)).
4697 So that we may avoid calls to lookup_name, we cache the _TYPE
4698 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
4700 For multiple inheritance, we perform a two-pass depth-first search
4701 of the type lattice. The first pass performs a pre-order search,
4702 marking types after the type has had its fields installed in
4703 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
4704 unmarks the marked types. If a field or member function name
4705 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4706 that name becomes `error_mark_node'. */
4709 pushclass (type
, modify
)
4713 push_memoized_context (type
, modify
);
4715 current_class_depth
++;
4716 *current_class_stack
++ = current_class_name
;
4717 *current_class_stack
++ = current_class_type
;
4718 if (current_class_stack
>= current_class_base
+ current_class_stacksize
)
4721 = (tree
*)xrealloc (current_class_base
,
4722 sizeof (tree
) * (current_class_stacksize
+ 10));
4723 current_class_stack
= current_class_base
+ current_class_stacksize
;
4724 current_class_stacksize
+= 10;
4727 current_class_name
= TYPE_NAME (type
);
4728 if (TREE_CODE (current_class_name
) == TYPE_DECL
)
4729 current_class_name
= DECL_NAME (current_class_name
);
4730 current_class_type
= type
;
4732 if (previous_class_type
!= NULL_TREE
4733 && (type
!= previous_class_type
|| TYPE_SIZE (previous_class_type
) == NULL_TREE
)
4734 && current_class_depth
== 1)
4736 /* Forcibly remove any old class remnants. */
4738 previous_class_type
= NULL_TREE
;
4744 if (CLASSTYPE_TEMPLATE_INFO (type
))
4745 overload_template_name (type
);
4751 tree this_fndecl
= current_function_decl
;
4753 if (current_function_decl
4754 && DECL_CONTEXT (current_function_decl
)
4755 && TREE_CODE (DECL_CONTEXT (current_function_decl
)) == FUNCTION_DECL
)
4756 current_function_decl
= DECL_CONTEXT (current_function_decl
);
4758 current_function_decl
= NULL_TREE
;
4760 if (type
!= previous_class_type
|| current_class_depth
> 1)
4762 build_mi_matrix (type
);
4763 push_class_decls (type
);
4770 /* Hooray, we successfully cached; let's just install the
4771 cached class_shadowed list, and walk through it to get the
4772 IDENTIFIER_TYPE_VALUEs correct. */
4773 set_class_shadows (previous_class_values
);
4774 for (item
= previous_class_values
; item
; item
= TREE_CHAIN (item
))
4776 tree id
= TREE_PURPOSE (item
);
4777 tree decl
= IDENTIFIER_CLASS_VALUE (id
);
4779 if (TREE_CODE (decl
) == TYPE_DECL
)
4780 set_identifier_type_value (id
, TREE_TYPE (decl
));
4782 unuse_fields (type
);
4785 for (tags
= CLASSTYPE_TAGS (type
); tags
; tags
= TREE_CHAIN (tags
))
4787 TREE_NONLOCAL_FLAG (TREE_VALUE (tags
)) = 1;
4788 if (! TREE_PURPOSE (tags
))
4790 pushtag (TREE_PURPOSE (tags
), TREE_VALUE (tags
), 0);
4793 current_function_decl
= this_fndecl
;
4797 /* Get out of the current class scope. If we were in a class scope
4798 previously, that is the one popped to. The flag MODIFY tells whether
4799 the current scope declarations needs to be modified as a result of
4800 popping to the previous scope. 0 is used for class definitions. */
4808 /* Back this old class out completely. */
4809 tree tags
= CLASSTYPE_TAGS (previous_class_type
);
4812 /* This code can be seen as a cache miss. When we've cached a
4813 class' scope's bindings and we can't use them, we need to reset
4814 them. This is it! */
4815 for (t
= previous_class_values
; t
; t
= TREE_CHAIN (t
))
4816 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t
)) = NULL_TREE
;
4819 TREE_NONLOCAL_FLAG (TREE_VALUE (tags
)) = 0;
4820 tags
= TREE_CHAIN (tags
);
4827 /* Just remove from this class what didn't make
4828 it into IDENTIFIER_CLASS_VALUE. */
4829 tree tags
= CLASSTYPE_TAGS (current_class_type
);
4833 TREE_NONLOCAL_FLAG (TREE_VALUE (tags
)) = 0;
4834 tags
= TREE_CHAIN (tags
);
4838 /* Force clearing of IDENTIFIER_CLASS_VALUEs after a class definition,
4839 since not all class decls make it there currently. */
4840 poplevel_class (! modify
);
4842 /* Since poplevel_class does the popping of class decls nowadays,
4843 this really only frees the obstack used for these decls.
4844 That's why it had to be moved down here. */
4848 current_class_depth
--;
4849 current_class_type
= *--current_class_stack
;
4850 current_class_name
= *--current_class_stack
;
4852 pop_memoized_context (modify
);
4858 /* When entering a class scope, all enclosing class scopes' names with
4859 static meaning (static variables, static functions, types and enumerators)
4860 have to be visible. This recursive function calls pushclass for all
4861 enclosing class contexts until global or a local scope is reached.
4862 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4863 formal of the same name. */
4866 push_nested_class (type
, modify
)
4872 if (type
== NULL_TREE
|| type
== error_mark_node
|| ! IS_AGGR_TYPE (type
)
4873 || TREE_CODE (type
) == TEMPLATE_TYPE_PARM
)
4876 context
= DECL_CONTEXT (TYPE_MAIN_DECL (type
));
4878 if (context
&& TREE_CODE (context
) == RECORD_TYPE
)
4879 push_nested_class (context
, 2);
4880 pushclass (type
, modify
);
4883 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4886 pop_nested_class (modify
)
4889 tree context
= DECL_CONTEXT (TYPE_MAIN_DECL (current_class_type
));
4892 if (context
&& TREE_CODE (context
) == RECORD_TYPE
)
4893 pop_nested_class (modify
);
4896 /* Set global variables CURRENT_LANG_NAME to appropriate value
4897 so that behavior of name-mangling machinery is correct. */
4900 push_lang_context (name
)
4903 *current_lang_stack
++ = current_lang_name
;
4904 if (current_lang_stack
>= current_lang_base
+ current_lang_stacksize
)
4907 = (tree
*)xrealloc (current_lang_base
,
4908 sizeof (tree
) * (current_lang_stacksize
+ 10));
4909 current_lang_stack
= current_lang_base
+ current_lang_stacksize
;
4910 current_lang_stacksize
+= 10;
4913 if (name
== lang_name_cplusplus
)
4915 strict_prototype
= strict_prototypes_lang_cplusplus
;
4916 current_lang_name
= name
;
4918 else if (name
== lang_name_c
)
4920 strict_prototype
= strict_prototypes_lang_c
;
4921 current_lang_name
= name
;
4924 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name
));
4927 /* Get out of the current language scope. */
4932 current_lang_name
= *--current_lang_stack
;
4933 if (current_lang_name
== lang_name_cplusplus
)
4934 strict_prototype
= strict_prototypes_lang_cplusplus
;
4935 else if (current_lang_name
== lang_name_c
)
4936 strict_prototype
= strict_prototypes_lang_c
;
4939 /* Type instantiation routines. */
4941 /* This function will instantiate the type of the expression given in
4942 RHS to match the type of LHSTYPE. If errors exist, then return
4943 error_mark_node. If only complain is COMPLAIN is set. If we are
4944 not complaining, never modify rhs, as overload resolution wants to
4945 try many possible instantiations, in hopes that at least one will
4948 This function is used in build_modify_expr, convert_arguments,
4949 build_c_cast, and compute_conversion_costs. */
4952 instantiate_type (lhstype
, rhs
, complain
)
4956 tree explicit_targs
= NULL_TREE
;
4958 if (TREE_CODE (lhstype
) == UNKNOWN_TYPE
)
4961 error ("not enough type information");
4962 return error_mark_node
;
4965 if (TREE_TYPE (rhs
) != NULL_TREE
&& ! (type_unknown_p (rhs
)))
4968 rhs
= copy_node (rhs
);
4970 /* This should really only be used when attempting to distinguish
4971 what sort of a pointer to function we have. For now, any
4972 arithmetic operation which is not supported on pointers
4973 is rejected as an error. */
4975 switch (TREE_CODE (rhs
))
4982 my_friendly_abort (177);
4983 return error_mark_node
;
4990 new_rhs
= instantiate_type (build_pointer_type (lhstype
),
4991 TREE_OPERAND (rhs
, 0), complain
);
4992 if (new_rhs
== error_mark_node
)
4993 return error_mark_node
;
4995 TREE_TYPE (rhs
) = lhstype
;
4996 TREE_OPERAND (rhs
, 0) = new_rhs
;
5001 rhs
= copy_node (TREE_OPERAND (rhs
, 0));
5002 TREE_TYPE (rhs
) = unknown_type_node
;
5003 return instantiate_type (lhstype
, rhs
, complain
);
5007 tree field
= TREE_OPERAND (rhs
, 1);
5008 if (TREE_CODE (field
) == TREE_LIST
)
5010 tree function
= instantiate_type (lhstype
, field
, complain
);
5011 if (function
== error_mark_node
)
5012 return error_mark_node
;
5013 my_friendly_assert (TREE_CODE (function
) == FUNCTION_DECL
, 185);
5014 if (DECL_VINDEX (function
))
5016 tree base
= TREE_OPERAND (rhs
, 0);
5017 tree base_ptr
= build_unary_op (ADDR_EXPR
, base
, 0);
5018 if (base_ptr
== error_mark_node
)
5019 return error_mark_node
;
5020 base_ptr
= convert_pointer_to (DECL_CONTEXT (function
), base_ptr
);
5021 if (base_ptr
== error_mark_node
)
5022 return error_mark_node
;
5023 return build_vfn_ref (&base_ptr
, base
, DECL_VINDEX (function
));
5025 mark_used (function
);
5029 my_friendly_assert (TREE_CODE (field
) == FIELD_DECL
, 178);
5030 my_friendly_assert (!(TREE_CODE (TREE_TYPE (field
)) == FUNCTION_TYPE
5031 || TREE_CODE (TREE_TYPE (field
)) == METHOD_TYPE
),
5034 TREE_TYPE (rhs
) = lhstype
;
5035 /* First look for an exact match */
5037 while (field
&& TREE_TYPE (field
) != lhstype
)
5038 field
= DECL_CHAIN (field
);
5041 TREE_OPERAND (rhs
, 1) = field
;
5046 /* No exact match found, look for a compatible function. */
5047 field
= TREE_OPERAND (rhs
, 1);
5048 while (field
&& ! comptypes (lhstype
, TREE_TYPE (field
), 0))
5049 field
= DECL_CHAIN (field
);
5052 TREE_OPERAND (rhs
, 1) = field
;
5053 field
= DECL_CHAIN (field
);
5054 while (field
&& ! comptypes (lhstype
, TREE_TYPE (field
), 0))
5055 field
= DECL_CHAIN (field
);
5059 error ("ambiguous overload for COMPONENT_REF requested");
5060 return error_mark_node
;
5066 error ("no appropriate overload exists for COMPONENT_REF");
5067 return error_mark_node
;
5072 case TEMPLATE_ID_EXPR
:
5074 explicit_targs
= TREE_OPERAND (rhs
, 1);
5075 rhs
= TREE_OPERAND (rhs
, 0);
5081 tree elem
, baselink
, name
;
5082 int globals
= overloaded_globals_p (rhs
);
5084 /* First look for an exact match. Search either overloaded
5085 functions or member functions. May have to undo what
5086 `default_conversion' might do to lhstype. */
5088 if (TYPE_PTRMEMFUNC_P (lhstype
))
5089 lhstype
= TYPE_PTRMEMFUNC_FN_TYPE (lhstype
);
5091 if (TREE_CODE (lhstype
) == POINTER_TYPE
)
5092 if (TREE_CODE (TREE_TYPE (lhstype
)) == FUNCTION_TYPE
5093 || TREE_CODE (TREE_TYPE (lhstype
)) == METHOD_TYPE
)
5094 lhstype
= TREE_TYPE (lhstype
);
5098 error ("invalid type combination for overload");
5099 return error_mark_node
;
5102 if (TREE_CODE (lhstype
) != FUNCTION_TYPE
&& globals
> 0)
5105 cp_error ("cannot resolve overloaded function `%D' based on non-function type",
5106 TREE_PURPOSE (rhs
));
5107 return error_mark_node
;
5112 elem
= get_first_fn (rhs
);
5113 /* If there are explicit_targs, only a template function
5115 if (explicit_targs
== NULL_TREE
)
5117 if (! comptypes (lhstype
, TREE_TYPE (elem
), 1))
5118 elem
= DECL_CHAIN (elem
);
5125 /* No exact match found, look for a compatible template. */
5128 for (elem
= get_first_fn (rhs
); elem
; elem
= DECL_CHAIN (elem
))
5129 if (TREE_CODE (elem
) == TEMPLATE_DECL
)
5131 int n
= DECL_NTPARMS (elem
);
5132 tree t
= make_scratch_vec (n
);
5134 i
= type_unification
5135 (DECL_INNERMOST_TEMPLATE_PARMS (elem
),
5136 &TREE_VEC_ELT (t
, 0), TYPE_ARG_TYPES (TREE_TYPE (elem
)),
5137 TYPE_ARG_TYPES (lhstype
), explicit_targs
, &d
,
5143 cp_error ("ambiguous template instantiation converting to `%#T'", lhstype
);
5144 return error_mark_node
;
5146 save_elem
= instantiate_template (elem
, t
);
5147 /* Check the return type. */
5148 if (! comptypes (TREE_TYPE (lhstype
),
5149 TREE_TYPE (TREE_TYPE (save_elem
)), 1))
5155 mark_used (save_elem
);
5160 /* If there are explicit_targs, only a template function
5162 if (explicit_targs
== NULL_TREE
)
5164 /* No match found, look for a compatible function. */
5165 elem
= get_first_fn (rhs
);
5166 while (elem
&& comp_target_types (lhstype
,
5167 TREE_TYPE (elem
), 1) <= 0)
5168 elem
= DECL_CHAIN (elem
);
5171 tree save_elem
= elem
;
5172 elem
= DECL_CHAIN (elem
);
5174 && comp_target_types (lhstype
,
5175 TREE_TYPE (elem
), 0) <= 0)
5176 elem
= DECL_CHAIN (elem
);
5182 ("cannot resolve overload to target type `%#T'",
5184 cp_error_at (" ambiguity between `%#D'",
5186 cp_error_at (" and `%#D', at least", elem
);
5188 return error_mark_node
;
5190 mark_used (save_elem
);
5196 cp_error ("cannot resolve overload to target type `%#T'",
5199 (" because no suitable overload of function `%D' exists",
5200 TREE_PURPOSE (rhs
));
5202 return error_mark_node
;
5205 if (TREE_NONLOCAL_FLAG (rhs
))
5207 /* Got to get it as a baselink. */
5208 rhs
= lookup_fnfields (TYPE_BINFO (current_class_type
),
5209 TREE_PURPOSE (rhs
), 0);
5213 my_friendly_assert (TREE_CHAIN (rhs
) == NULL_TREE
, 181);
5214 if (TREE_CODE (TREE_VALUE (rhs
)) == TREE_LIST
)
5215 rhs
= TREE_VALUE (rhs
);
5216 my_friendly_assert (TREE_CODE (TREE_VALUE (rhs
)) == FUNCTION_DECL
,
5220 for (baselink
= rhs
; baselink
;
5221 baselink
= next_baselink (baselink
))
5223 elem
= TREE_VALUE (baselink
);
5225 if (comptypes (lhstype
, TREE_TYPE (elem
), 1))
5231 elem
= DECL_CHAIN (elem
);
5234 /* No exact match found, look for a compatible method. */
5235 for (baselink
= rhs
; baselink
;
5236 baselink
= next_baselink (baselink
))
5238 elem
= TREE_VALUE (baselink
);
5239 while (elem
&& comp_target_types (lhstype
,
5240 TREE_TYPE (elem
), 1) <= 0)
5241 elem
= DECL_CHAIN (elem
);
5244 tree save_elem
= elem
;
5245 elem
= DECL_CHAIN (elem
);
5246 while (elem
&& comp_target_types (lhstype
,
5247 TREE_TYPE (elem
), 0) <= 0)
5248 elem
= DECL_CHAIN (elem
);
5252 error ("ambiguous overload for overloaded method requested");
5253 return error_mark_node
;
5255 mark_used (save_elem
);
5258 name
= DECL_NAME (TREE_VALUE (rhs
));
5260 if (TREE_CODE (lhstype
) == FUNCTION_TYPE
&& globals
< 0)
5262 /* Try to instantiate from non-member functions. */
5263 rhs
= lookup_name_nonclass (name
);
5264 if (rhs
&& TREE_CODE (rhs
) == TREE_LIST
)
5266 /* This code seems to be missing a `return'. */
5267 my_friendly_abort (4);
5268 instantiate_type (lhstype
, rhs
, complain
);
5274 cp_error ("no compatible member functions named `%D'", name
);
5275 return error_mark_node
;
5279 /* This is too hard for now. */
5280 my_friendly_abort (183);
5281 return error_mark_node
;
5286 TREE_OPERAND (rhs
, 0)
5287 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 0), complain
);
5288 if (TREE_OPERAND (rhs
, 0) == error_mark_node
)
5289 return error_mark_node
;
5290 TREE_OPERAND (rhs
, 1)
5291 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), complain
);
5292 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5293 return error_mark_node
;
5295 TREE_TYPE (rhs
) = lhstype
;
5299 case TRUNC_DIV_EXPR
:
5300 case FLOOR_DIV_EXPR
:
5302 case ROUND_DIV_EXPR
:
5304 case TRUNC_MOD_EXPR
:
5305 case FLOOR_MOD_EXPR
:
5307 case ROUND_MOD_EXPR
:
5308 case FIX_ROUND_EXPR
:
5309 case FIX_FLOOR_EXPR
:
5311 case FIX_TRUNC_EXPR
:
5327 case PREINCREMENT_EXPR
:
5328 case PREDECREMENT_EXPR
:
5329 case POSTINCREMENT_EXPR
:
5330 case POSTDECREMENT_EXPR
:
5332 error ("invalid operation on uninstantiated type");
5333 return error_mark_node
;
5335 case TRUTH_AND_EXPR
:
5337 case TRUTH_XOR_EXPR
:
5344 case TRUTH_ANDIF_EXPR
:
5345 case TRUTH_ORIF_EXPR
:
5346 case TRUTH_NOT_EXPR
:
5348 error ("not enough type information");
5349 return error_mark_node
;
5352 if (type_unknown_p (TREE_OPERAND (rhs
, 0)))
5355 error ("not enough type information");
5356 return error_mark_node
;
5358 TREE_OPERAND (rhs
, 1)
5359 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), complain
);
5360 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5361 return error_mark_node
;
5362 TREE_OPERAND (rhs
, 2)
5363 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 2), complain
);
5364 if (TREE_OPERAND (rhs
, 2) == error_mark_node
)
5365 return error_mark_node
;
5367 TREE_TYPE (rhs
) = lhstype
;
5371 TREE_OPERAND (rhs
, 1)
5372 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), complain
);
5373 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
5374 return error_mark_node
;
5376 TREE_TYPE (rhs
) = lhstype
;
5380 if (TYPE_PTRMEMFUNC_P (lhstype
))
5381 lhstype
= TYPE_PTRMEMFUNC_FN_TYPE (lhstype
);
5382 else if (TREE_CODE (lhstype
) != POINTER_TYPE
)
5385 error ("type for resolving address of overloaded function must be pointer type");
5386 return error_mark_node
;
5389 tree fn
= instantiate_type (TREE_TYPE (lhstype
), TREE_OPERAND (rhs
, 0), complain
);
5390 if (fn
== error_mark_node
)
5391 return error_mark_node
;
5392 mark_addressable (fn
);
5393 TREE_TYPE (rhs
) = lhstype
;
5394 TREE_OPERAND (rhs
, 0) = fn
;
5395 TREE_CONSTANT (rhs
) = staticp (fn
);
5396 if (TREE_CODE (lhstype
) == POINTER_TYPE
5397 && TREE_CODE (TREE_TYPE (lhstype
)) == METHOD_TYPE
)
5399 build_ptrmemfunc_type (lhstype
);
5400 rhs
= build_ptrmemfunc (lhstype
, rhs
, 0);
5405 case ENTRY_VALUE_EXPR
:
5406 my_friendly_abort (184);
5407 return error_mark_node
;
5410 return error_mark_node
;
5413 my_friendly_abort (185);
5414 return error_mark_node
;
5418 /* Return the name of the virtual function pointer field
5419 (as an IDENTIFIER_NODE) for the given TYPE. Note that
5420 this may have to look back through base types to find the
5421 ultimate field name. (For single inheritance, these could
5422 all be the same name. Who knows for multiple inheritance). */
5425 get_vfield_name (type
)
5428 tree binfo
= TYPE_BINFO (type
);
5431 while (BINFO_BASETYPES (binfo
)
5432 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo
, 0)))
5433 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo
, 0)))
5434 binfo
= BINFO_BASETYPE (binfo
, 0);
5436 type
= BINFO_TYPE (binfo
);
5437 buf
= (char *) alloca (sizeof (VFIELD_NAME_FORMAT
)
5438 + TYPE_NAME_LENGTH (type
) + 2);
5439 sprintf (buf
, VFIELD_NAME_FORMAT
, TYPE_NAME_STRING (type
));
5440 return get_identifier (buf
);
5444 print_class_statistics ()
5446 #ifdef GATHER_STATISTICS
5447 fprintf (stderr
, "convert_harshness = %d\n", n_convert_harshness
);
5448 fprintf (stderr
, "compute_conversion_costs = %d\n", n_compute_conversion_costs
);
5449 fprintf (stderr
, "build_method_call = %d (inner = %d)\n",
5450 n_build_method_call
, n_inner_fields_searched
);
5453 fprintf (stderr
, "vtables = %d; vtable searches = %d\n",
5454 n_vtables
, n_vtable_searches
);
5455 fprintf (stderr
, "vtable entries = %d; vtable elems = %d\n",
5456 n_vtable_entries
, n_vtable_elems
);
5461 /* Push an obstack which is sufficiently long-lived to hold such class
5462 decls that may be cached in the previous_class_values list. For now, let's
5463 use the permanent obstack, later we may create a dedicated obstack just
5464 for this purpose. The effect is undone by pop_obstacks. */
5467 maybe_push_cache_obstack ()
5469 push_obstacks_nochange ();
5470 if (current_class_depth
== 1)
5471 current_obstack
= &permanent_obstack
;
5474 /* Build a dummy reference to ourselves so Derived::Base (and A::A) works,
5475 according to [class]:
5476 The class-name is also inserted
5477 into the scope of the class itself. For purposes of access checking,
5478 the inserted class name is treated as if it were a public member name. */
5481 build_self_reference ()
5483 tree name
= constructor_name (current_class_type
);
5484 tree value
= build_lang_decl (TYPE_DECL
, name
, current_class_type
);
5485 DECL_NONLOCAL (value
) = 1;
5486 DECL_CONTEXT (value
) = current_class_type
;
5487 DECL_CLASS_CONTEXT (value
) = current_class_type
;
5488 CLASSTYPE_LOCAL_TYPEDECLS (current_class_type
) = 1;
5489 DECL_ARTIFICIAL (value
) = 1;
5491 pushdecl_class_level (value
);