1 /* Functions related to building classes and their related objects.
2 Copyright (C) 1987, 1992, 1993, 1994 Free Software Foundation, Inc.
3 Contributed by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* High-level class interface. */
31 #define obstack_chunk_alloc xmalloc
32 #define obstack_chunk_free free
34 extern struct obstack permanent_obstack
;
36 /* This is how we tell when two virtual member functions are really the
38 #define SAME_FN(FN1DECL, FN2DECL) (DECL_ASSEMBLER_NAME (FN1DECL) == DECL_ASSEMBLER_NAME (FN2DECL))
40 extern void set_class_shadows
PROTO ((tree
));
42 /* Way of stacking class types. */
43 static tree
*current_class_base
, *current_class_stack
;
44 static int current_class_stacksize
;
45 int current_class_depth
;
49 /* The previous class level. */
50 struct class_level
*level_chain
;
52 /* The class instance variable, as a PARM_DECL. */
54 /* The class instance variable, as an object. */
56 /* The virtual function table pointer
57 for the class instance variable. */
60 /* Name of the current class. */
62 /* Type of the current class. */
65 /* Flags for this class level. */
72 tree current_class_decl
, C_C_D
; /* PARM_DECL: the class instance variable */
73 tree current_vtable_decl
;
75 /* The following two can be derived from the previous one */
76 tree current_class_name
; /* IDENTIFIER_NODE: name of current class */
77 tree current_class_type
; /* _TYPE: the type of the current class */
78 tree previous_class_type
; /* _TYPE: the previous type that was a class */
79 tree previous_class_values
; /* TREE_LIST: copy of the class_shadowed list
80 when leaving an outermost class scope. */
81 static tree get_vfield_name
PROTO((tree
));
82 tree the_null_vtable_entry
;
84 /* Way of stacking language names. */
85 tree
*current_lang_base
, *current_lang_stack
;
86 static int current_lang_stacksize
;
88 /* Names of languages we recognize. */
89 tree lang_name_c
, lang_name_cplusplus
;
90 tree current_lang_name
;
92 /* When layout out an aggregate type, the size of the
93 basetypes (virtual and non-virtual) is passed to layout_record
95 static tree base_layout_decl
;
97 /* Variables shared between cp-class.c and cp-call.c. */
100 int n_vtable_entries
= 0;
101 int n_vtable_searches
= 0;
102 int n_vtable_elems
= 0;
103 int n_convert_harshness
= 0;
104 int n_compute_conversion_costs
= 0;
105 int n_build_method_call
= 0;
106 int n_inner_fields_searched
= 0;
108 /* Virtual baseclass things. */
110 build_vbase_pointer (exp
, type
)
115 name
= (char *) alloca (TYPE_NAME_LENGTH (type
) + sizeof (VBASE_NAME
) + 1);
116 sprintf (name
, VBASE_NAME_FORMAT
, TYPE_NAME_STRING (type
));
117 return build_component_ref (exp
, get_identifier (name
), 0, 0);
120 /* Is the type of the EXPR, the complete type of the object?
121 If we are going to be wrong, we must be conservative, and return 0. */
123 complete_type_p (expr
)
126 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
129 switch (TREE_CODE (expr
))
136 expr
= TREE_OPERAND (expr
, 0);
140 if (! TREE_HAS_CONSTRUCTOR (expr
))
142 /* fall through... */
145 if (TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
146 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (expr
)))
147 && TYPE_MAIN_VARIANT (TREE_TYPE (expr
)) == type
)
149 /* fall through... */
152 if (IS_AGGR_TYPE (TREE_TYPE (expr
))
153 && TYPE_MAIN_VARIANT (TREE_TYPE (expr
)) == type
)
155 /* fall through... */
165 /* Build multi-level access to EXPR using hierarchy path PATH.
166 CODE is PLUS_EXPR if we are going with the grain,
167 and MINUS_EXPR if we are not (in which case, we cannot traverse
168 virtual baseclass links).
170 TYPE is the type we want this path to have on exit.
172 ALIAS_THIS is non-zero if EXPR in an expression involving `this'. */
174 build_vbase_path (code
, type
, expr
, path
, alias_this
)
176 tree type
, expr
, path
;
179 register int changed
= 0;
180 tree last
= NULL_TREE
, last_virtual
= NULL_TREE
;
182 int fixed_type_p
= resolves_to_fixed_type_p (expr
, &nonnull
);
183 tree null_expr
= 0, nonnull_expr
;
185 tree offset
= integer_zero_node
;
187 /* We need additional logic to convert back to the unconverted type
188 (the static type of the complete object), and then convert back
189 to the type we want. Until that is done, or until we can
190 recognize when that is, we cannot do the short cut logic. (mrs) */
191 /* Do this, until we can undo any previous convertions. See net35.C
193 fixed_type_p
= complete_type_p (expr
);
195 if (!fixed_type_p
&& TREE_SIDE_EFFECTS (expr
))
196 expr
= save_expr (expr
);
199 if (BINFO_INHERITANCE_CHAIN (path
))
201 tree reverse_path
= NULL_TREE
;
205 tree r
= copy_node (path
);
206 BINFO_INHERITANCE_CHAIN (r
) = reverse_path
;
208 path
= BINFO_INHERITANCE_CHAIN (path
);
213 basetype
= BINFO_TYPE (path
);
217 if (TREE_VIA_VIRTUAL (path
))
219 last_virtual
= BINFO_TYPE (path
);
220 if (code
== PLUS_EXPR
)
222 changed
= ! fixed_type_p
;
226 extern int flag_assume_nonnull_objects
;
229 /* We already check for ambiguous things in the caller, just
233 tree binfo
= get_binfo (last
, TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (nonnull_expr
))), 0);
234 nonnull_expr
= convert_pointer_to_real (binfo
, nonnull_expr
);
236 ind
= build_indirect_ref (nonnull_expr
, NULL_PTR
);
237 nonnull_expr
= build_vbase_pointer (ind
, last_virtual
);
238 if (nonnull
== 0 && !flag_assume_nonnull_objects
239 && null_expr
== NULL_TREE
)
241 null_expr
= build1 (NOP_EXPR
, TYPE_POINTER_TO (last_virtual
), integer_zero_node
);
242 expr
= build (COND_EXPR
, TYPE_POINTER_TO (last_virtual
),
243 build (EQ_EXPR
, integer_type_node
, expr
,
245 null_expr
, nonnull_expr
);
248 /* else we'll figure out the offset below. */
250 /* Happens in the case of parse errors. */
251 if (nonnull_expr
== error_mark_node
)
252 return error_mark_node
;
256 cp_error ("cannot cast up from virtual baseclass `%T'",
258 return error_mark_node
;
262 path
= BINFO_INHERITANCE_CHAIN (path
);
264 /* LAST is now the last basetype assoc on the path. */
266 /* A pointer to a virtual base member of a non-null object
267 is non-null. Therefore, we only need to test for zeroness once.
268 Make EXPR the canonical expression to deal with here. */
271 TREE_OPERAND (expr
, 2) = nonnull_expr
;
272 TREE_TYPE (TREE_OPERAND (expr
, 1)) = TREE_TYPE (nonnull_expr
);
277 /* If we go through any virtual base pointers, make sure that
278 casts to BASETYPE from the last virtual base class use
279 the right value for BASETYPE. */
282 tree intype
= TREE_TYPE (TREE_TYPE (expr
));
283 if (TYPE_MAIN_VARIANT (intype
) == BINFO_TYPE (last
))
287 tree binfo
= get_binfo (last
, TYPE_MAIN_VARIANT (intype
), 0);
289 offset
= BINFO_OFFSET (binfo
);
296 offset
= BINFO_OFFSET (binfo_member (last_virtual
,
297 CLASSTYPE_VBASECLASSES (basetype
)));
298 offset
= size_binop (PLUS_EXPR
, offset
, BINFO_OFFSET (last
));
301 offset
= BINFO_OFFSET (last
);
304 if (TREE_INT_CST_LOW (offset
))
306 /* For multiple inheritance: if `this' can be set by any
307 function, then it could be 0 on entry to any function.
308 Preserve such zeroness here. Otherwise, only in the
309 case of constructors need we worry, and in those cases,
310 it will be zero, or initialized to some legal value to
312 if (nonnull
== 0 && (alias_this
== 0 || flag_this_is_variable
> 0))
315 TREE_TYPE (null_expr
) = type
;
317 null_expr
= build1 (NOP_EXPR
, type
, integer_zero_node
);
318 if (TREE_SIDE_EFFECTS (expr
))
319 expr
= save_expr (expr
);
321 return build (COND_EXPR
, type
,
322 build (EQ_EXPR
, integer_type_node
, expr
, integer_zero_node
),
324 build (code
, type
, expr
, offset
));
326 else return build (code
, type
, expr
, offset
);
329 /* Cannot change the TREE_TYPE of a NOP_EXPR here, since it may
330 be used multiple times in initialization of multiple inheritance. */
333 TREE_TYPE (expr
) = type
;
337 return build1 (NOP_EXPR
, type
, expr
);
340 /* Virtual function things. */
342 /* Virtual functions to be dealt with after laying out our
343 base classes. Usually this is used only when classes have virtual
344 baseclasses, but it can happen also when classes have non-virtual
345 baseclasses if the derived class overrides baseclass functions
346 at different offsets. */
347 static tree pending_hard_virtuals
;
348 static int doing_hard_virtuals
;
350 /* XXX This is set but never used. (bpk) */
352 /* Temporary binfo list to memoize lookups of the left-most non-virtual
353 baseclass B in a lattice topped by T. B can appear multiple times
355 TREE_PURPOSE is B's TYPE_MAIN_VARIANT.
356 TREE_VALUE is the path by which B is reached from T.
357 TREE_TYPE is B's real type.
359 If TREE_TYPE is NULL_TREE, it means that B was reached via
361 N.B.: This list consists of nodes on the temporary obstack. */
362 static tree leftmost_baseclasses
;
365 /* Build an entry in the virtual function table.
366 DELTA is the offset for the `this' pointer.
367 PFN is an ADDR_EXPR containing a pointer to the virtual function.
368 Note that the index (DELTA2) in the virtual function table
371 build_vtable_entry (delta
, pfn
)
374 extern int flag_huge_objects
;
375 tree elems
= tree_cons (NULL_TREE
, delta
,
376 tree_cons (NULL_TREE
, integer_zero_node
,
377 build_tree_list (NULL_TREE
, pfn
)));
378 tree entry
= build (CONSTRUCTOR
, vtable_entry_type
, NULL_TREE
, elems
);
380 /* DELTA is constructed by `size_int', which means it may be an
381 unsigned quantity on some platforms. Therefore, we cannot use
382 `int_fits_type_p', because when DELTA is really negative,
383 `force_fit_type' will make it look like a very large number. */
385 if ((TREE_INT_CST_LOW (TYPE_MAX_VALUE (delta_type_node
))
386 < TREE_INT_CST_LOW (delta
))
387 || (TREE_INT_CST_LOW (delta
)
388 < TREE_INT_CST_LOW (TYPE_MIN_VALUE (delta_type_node
))))
389 if (flag_huge_objects
)
390 sorry ("object size exceeds built-in limit for virtual function table implementation");
392 sorry ("object size exceeds normal limit for virtual function table implementation, recompile all source and use -fhuge-objects");
394 TREE_CONSTANT (entry
) = 1;
395 TREE_STATIC (entry
) = 1;
396 TREE_READONLY (entry
) = 1;
398 #ifdef GATHER_STATISTICS
399 n_vtable_entries
+= 1;
405 /* Given an object INSTANCE, return an expression which yields the
406 virtual function corresponding to INDEX. There are many special
407 cases for INSTANCE which we take care of here, mainly to avoid
408 creating extra tree nodes when we don't have to. */
410 build_vfn_ref (ptr_to_instptr
, instance
, idx
)
411 tree
*ptr_to_instptr
, instance
;
414 extern int building_cleanup
;
416 tree basetype
= TREE_TYPE (instance
);
418 if (TREE_CODE (basetype
) == REFERENCE_TYPE
)
419 basetype
= TREE_TYPE (basetype
);
421 if (instance
== C_C_D
)
423 if (current_vtable_decl
== NULL_TREE
424 || current_vtable_decl
== error_mark_node
425 || !UNIQUELY_DERIVED_FROM_P (DECL_FCONTEXT (CLASSTYPE_VFIELD (current_class_type
)), basetype
))
426 vtbl
= build_indirect_ref (build_vfield_ref (instance
, basetype
), NULL_PTR
);
428 vtbl
= current_vtable_decl
;
434 /* Try to figure out what a reference refers to, and
435 access its virtual function table directly. */
436 tree ref
= NULL_TREE
;
438 if (TREE_CODE (instance
) == INDIRECT_REF
439 && TREE_CODE (TREE_TYPE (TREE_OPERAND (instance
, 0))) == REFERENCE_TYPE
)
440 ref
= TREE_OPERAND (instance
, 0);
441 else if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
444 if (ref
&& TREE_CODE (ref
) == VAR_DECL
445 && DECL_INITIAL (ref
))
447 tree init
= DECL_INITIAL (ref
);
449 while (TREE_CODE (init
) == NOP_EXPR
450 || TREE_CODE (init
) == NON_LVALUE_EXPR
)
451 init
= TREE_OPERAND (init
, 0);
452 if (TREE_CODE (init
) == ADDR_EXPR
)
454 init
= TREE_OPERAND (init
, 0);
455 if (IS_AGGR_TYPE (TREE_TYPE (init
))
456 && (TREE_CODE (init
) == PARM_DECL
457 || TREE_CODE (init
) == VAR_DECL
))
463 if (IS_AGGR_TYPE (TREE_TYPE (instance
))
464 && !IS_SIGNATURE_POINTER (TREE_TYPE (instance
))
465 && !IS_SIGNATURE_REFERENCE (TREE_TYPE (instance
))
466 && (TREE_CODE (instance
) == RESULT_DECL
467 || TREE_CODE (instance
) == PARM_DECL
468 || TREE_CODE (instance
) == VAR_DECL
))
469 vtbl
= TYPE_BINFO_VTABLE (basetype
);
471 vtbl
= build_indirect_ref (build_vfield_ref (instance
, basetype
),
474 assemble_external (vtbl
);
475 aref
= build_array_ref (vtbl
, idx
);
477 /* Save the intermediate result in a SAVE_EXPR so we don't have to
478 compute each component of the virtual function pointer twice. */
479 if (!building_cleanup
&& TREE_CODE (aref
) == INDIRECT_REF
)
480 TREE_OPERAND (aref
, 0) = save_expr (TREE_OPERAND (aref
, 0));
483 = build (PLUS_EXPR
, TREE_TYPE (*ptr_to_instptr
),
485 convert (ptrdiff_type_node
,
486 build_component_ref (aref
, delta_identifier
, 0, 0)));
487 return build_component_ref (aref
, pfn_identifier
, 0, 0);
490 /* Set TREE_PUBLIC and/or TREE_EXTERN on the vtable DECL,
491 based on TYPE and other static flags.
493 Note that anything public is tagged TREE_PUBLIC, whether
494 it's public in this file or in another one. */
497 import_export_vtable (decl
, type
)
500 if (write_virtuals
>= 2)
502 if (CLASSTYPE_INTERFACE_KNOWN (type
))
504 TREE_PUBLIC (decl
) = 1;
505 DECL_EXTERNAL (decl
) = ! CLASSTYPE_VTABLE_NEEDS_WRITING (type
);
508 else if (write_virtuals
!= 0)
510 TREE_PUBLIC (decl
) = 1;
511 if (write_virtuals
< 0)
512 DECL_EXTERNAL (decl
) = 1;
516 /* Return the name of the virtual function table (as an IDENTIFIER_NODE)
517 for the given TYPE. */
519 get_vtable_name (type
)
522 tree type_id
= build_typename_overload (type
);
523 char *buf
= (char *)alloca (sizeof (VTABLE_NAME_FORMAT
)
524 + IDENTIFIER_LENGTH (type_id
) + 2);
525 char *ptr
= IDENTIFIER_POINTER (type_id
);
527 for (i
= 0; ptr
[i
] == OPERATOR_TYPENAME_FORMAT
[i
]; i
++) ;
529 /* We don't take off the numbers; prepare_fresh_vtable uses the
530 DECL_ASSEMBLER_NAME for the type, which includes the number
531 in `3foo'. If we were to pull them off here, we'd end up with
532 something like `_vt.foo.3bar', instead of a uniform definition. */
533 while (ptr
[i
] >= '0' && ptr
[i
] <= '9')
536 sprintf (buf
, VTABLE_NAME_FORMAT
, ptr
+i
);
537 return get_identifier (buf
);
540 /* Build a virtual function for type TYPE.
541 If BINFO is non-NULL, build the vtable starting with the initial
542 approximation that it is the same as the one which is the head of
543 the association list. */
545 build_vtable (binfo
, type
)
548 tree name
= get_vtable_name (type
);
553 virtuals
= copy_list (BINFO_VIRTUALS (binfo
));
554 decl
= build_decl (VAR_DECL
, name
, TREE_TYPE (BINFO_VTABLE (binfo
)));
558 virtuals
= NULL_TREE
;
559 decl
= build_decl (VAR_DECL
, name
, void_type_node
);
562 #ifdef GATHER_STATISTICS
564 n_vtable_elems
+= list_length (virtuals
);
567 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
568 import_export_vtable (decl
, type
);
570 IDENTIFIER_GLOBAL_VALUE (name
) = decl
= pushdecl_top_level (decl
);
571 /* Initialize the association list for this type, based
572 on our first approximation. */
573 TYPE_BINFO_VTABLE (type
) = decl
;
574 TYPE_BINFO_VIRTUALS (type
) = virtuals
;
576 TREE_STATIC (decl
) = 1;
577 #ifndef WRITABLE_VTABLES
578 /* Make them READONLY by default. (mrs) */
579 TREE_READONLY (decl
) = 1;
581 /* At one time the vtable info was grabbed 2 words at a time. This
582 fails on sparc unless you have 8-byte alignment. (tiemann) */
583 DECL_ALIGN (decl
) = MAX (TYPE_ALIGN (double_type_node
),
586 /* Why is this conditional? (mrs) */
587 if (binfo
&& write_virtuals
>= 0)
588 DECL_VIRTUAL_P (decl
) = 1;
590 /* Remember which class this vtable is really for. */
592 DECL_VPARENT (decl
) = BINFO_TYPE (binfo
);
594 DECL_VPARENT (decl
) = type
;
596 DECL_CONTEXT (decl
) = type
;
598 binfo
= TYPE_BINFO (type
);
599 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
600 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
604 /* Given a base type PARENT, and a derived type TYPE, build
605 a name which distinguishes exactly the PARENT member of TYPE's type.
607 FORMAT is a string which controls how sprintf formats the name
612 class A; class B; class C : A, B;
614 it is possible to distinguish "A" from "C's A". And given
617 class A : L; class B : L; class C : A, B;
619 it is possible to distinguish "L" from "A's L", and also from
622 Make sure to use the DECL_ASSEMBLER_NAME of the TYPE_NAME of the
623 type, as template have DECL_NAMEs like: X<int>, whereas the
624 DECL_ASSEMBLER_NAME is set to be something the assembler can handle.
627 build_type_pathname (format
, parent
, type
)
631 extern struct obstack temporary_obstack
;
632 char *first
, *base
, *name
;
636 parent
= TYPE_MAIN_VARIANT (parent
);
638 /* Remember where to cut the obstack to. */
639 first
= obstack_base (&temporary_obstack
);
641 /* Put on TYPE+PARENT. */
642 obstack_grow (&temporary_obstack
,
643 TYPE_ASSEMBLER_NAME_STRING (type
),
644 TYPE_ASSEMBLER_NAME_LENGTH (type
));
646 obstack_1grow (&temporary_obstack
, JOINER
);
648 obstack_1grow (&temporary_obstack
, '_');
650 obstack_grow0 (&temporary_obstack
,
651 TYPE_ASSEMBLER_NAME_STRING (parent
),
652 TYPE_ASSEMBLER_NAME_LENGTH (parent
));
653 i
= obstack_object_size (&temporary_obstack
);
654 base
= obstack_base (&temporary_obstack
);
655 obstack_finish (&temporary_obstack
);
657 /* Put on FORMAT+TYPE+PARENT. */
658 obstack_blank (&temporary_obstack
, strlen (format
) + i
+ 1);
659 name
= obstack_base (&temporary_obstack
);
660 sprintf (name
, format
, base
);
661 id
= get_identifier (name
);
662 obstack_free (&temporary_obstack
, first
);
667 /* Give TYPE a new virtual function table which is initialized
668 with a skeleton-copy of its original initialization. The only
669 entry that changes is the `delta' entry, so we can really
670 share a lot of structure.
672 FOR_TYPE is the derived type which caused this table to
675 BINFO is the type association which provided TYPE for FOR_TYPE.
677 The way we update BASE_BINFO's vtable information is just to change the
678 association information in FOR_TYPE's association list. */
680 prepare_fresh_vtable (binfo
, base_binfo
, for_type
)
681 tree binfo
, base_binfo
, for_type
;
683 tree basetype
= BINFO_TYPE (binfo
);
684 tree orig_decl
= BINFO_VTABLE (binfo
);
685 tree name
= build_type_pathname (VTABLE_NAME_FORMAT
, basetype
, for_type
);
686 tree new_decl
= build_decl (VAR_DECL
, name
, TREE_TYPE (orig_decl
));
690 /* Remember which class this vtable is really for. */
692 DECL_VPARENT (new_decl
) = BINFO_TYPE (base_binfo
);
694 DECL_CONTEXT (new_decl
) = for_type
;
696 TREE_STATIC (new_decl
) = 1;
697 BINFO_VTABLE (binfo
) = pushdecl_top_level (new_decl
);
698 DECL_VIRTUAL_P (new_decl
) = 1;
699 #ifndef WRITABLE_VTABLES
700 /* Make them READONLY by default. (mrs) */
701 TREE_READONLY (new_decl
) = 1;
703 DECL_ALIGN (new_decl
) = DECL_ALIGN (orig_decl
);
705 /* Make fresh virtual list, so we can smash it later. */
706 BINFO_VIRTUALS (binfo
) = copy_list (BINFO_VIRTUALS (binfo
));
707 /* Install the value for `headof' if that's what we're doing. */
709 TREE_VALUE (TREE_CHAIN (BINFO_VIRTUALS (binfo
)))
710 = build_vtable_entry (size_binop (MINUS_EXPR
, integer_zero_node
, BINFO_OFFSET (binfo
)),
711 FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (TREE_CHAIN (BINFO_VIRTUALS (binfo
)))));
713 #ifdef GATHER_STATISTICS
715 n_vtable_elems
+= list_length (BINFO_VIRTUALS (binfo
));
718 /* Set TREE_PUBLIC and TREE_EXTERN as appropriate. */
719 import_export_vtable (new_decl
, for_type
);
721 if (TREE_VIA_VIRTUAL (binfo
))
722 my_friendly_assert (binfo
== binfo_member (BINFO_TYPE (binfo
),
723 CLASSTYPE_VBASECLASSES (current_class_type
)),
725 SET_BINFO_NEW_VTABLE_MARKED (binfo
);
726 SET_BINFO_VTABLE_PATH_MARKED (binfo
);
728 /* Mark all types between FOR_TYPE and TYPE as having been
729 touched, so that if we change virtual function table entries,
730 new vtables will be initialized. We may reach the virtual
731 baseclass via ambiguous intervening baseclasses. This
732 loop makes sure we get through to the actual baseclass we marked.
734 Also, update the vtable entries to reflect the overrides
735 of the top-most class (short of the top type). */
739 result
= get_base_distance (basetype
, for_type
, 0, &path
);
743 tree path_binfo
= path
;
744 tree path_type
= BINFO_TYPE (path
);
746 if (TREE_VIA_VIRTUAL (path
))
747 path_binfo
= binfo_member (path_type
,
748 CLASSTYPE_VBASECLASSES (current_class_type
));
750 SET_BINFO_VTABLE_PATH_MARKED (path_binfo
);
751 if (BINFO_INHERITANCE_CHAIN (path
)
752 && CLASSTYPE_VFIELD (path_type
) != NULL_TREE
753 && (DECL_NAME (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
)))
754 == DECL_NAME (CLASSTYPE_VFIELD (path_type
)))
755 /* This is the baseclass just before the original FOR_TYPE. */
756 && BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (path
)) == NULL_TREE
)
758 tree old_virtuals
= TREE_CHAIN (BINFO_VIRTUALS (binfo
));
759 tree new_virtuals
= TREE_CHAIN (BINFO_VIRTUALS (path_binfo
));
762 old_virtuals
= TREE_CHAIN (old_virtuals
);
763 new_virtuals
= TREE_CHAIN (new_virtuals
);
767 TREE_VALUE (old_virtuals
) = TREE_VALUE (new_virtuals
);
768 old_virtuals
= TREE_CHAIN (old_virtuals
);
769 new_virtuals
= TREE_CHAIN (new_virtuals
);
772 path
= BINFO_INHERITANCE_CHAIN (path
);
775 while (result
== -2);
778 /* Access the virtual function table entry that logically
779 contains BASE_FNDECL. VIRTUALS is the virtual function table's
782 get_vtable_entry (virtuals
, base_fndecl
)
783 tree virtuals
, base_fndecl
;
785 unsigned HOST_WIDE_INT i
= (HOST_BITS_PER_WIDE_INT
>= BITS_PER_WORD
786 #ifdef VTABLE_USES_MASK
789 ? (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
))
790 & (((unsigned HOST_WIDE_INT
)1<<(BITS_PER_WORD
-1))-1))
791 : TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
)));
793 #ifdef GATHER_STATISTICS
794 n_vtable_searches
+= i
;
799 virtuals
= TREE_CHAIN (virtuals
);
805 /* Put new entry ENTRY into virtual function table initializer
808 Also update DECL_VINDEX (FNDECL). */
811 modify_vtable_entry (old_entry_in_list
, new_entry
, fndecl
)
812 tree old_entry_in_list
, new_entry
, fndecl
;
814 tree base_pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (old_entry_in_list
));
818 cp_warning ("replaced %D with %D", DECL_ASSEMBLER_NAME (TREE_OPERAND (base_pfn
, 0)), DECL_ASSEMBLER_NAME (fndecl
));
820 /* We can't put in the really right offset information
821 here, since we have not yet laid out the class to
822 take into account virtual base classes. */
823 TREE_VALUE (old_entry_in_list
) = new_entry
;
824 vindex
= DECL_VINDEX (TREE_OPERAND (base_pfn
, 0));
825 if (TREE_CODE (DECL_VINDEX (fndecl
)) != INTEGER_CST
)
826 DECL_VINDEX (fndecl
) = vindex
;
829 if (! tree_int_cst_equal (DECL_VINDEX (fndecl
), vindex
))
831 tree elts
= CONSTRUCTOR_ELTS (new_entry
);
833 if (! doing_hard_virtuals
)
835 pending_hard_virtuals
836 = tree_cons (fndecl
, FNADDR_FROM_VTABLE_ENTRY (new_entry
),
837 pending_hard_virtuals
);
838 TREE_TYPE (pending_hard_virtuals
) = TREE_OPERAND (base_pfn
, 0);
845 /* Check to ensure that the virtual function table slot in VFIELD,
846 found by DECL_VINDEX of the BASE_FNDECL is in fact from a parent
847 virtual function table that is the same parent as for the
848 BASE_FNDECL given to us. */
851 related_vslot (base_fndecl
, vfields
, type
)
852 tree base_fndecl
, vfields
, type
;
854 tree base_context
= TYPE_MAIN_VARIANT (DECL_CONTEXT (base_fndecl
));
859 if (TREE_CODE (vfields
) != TREE_LIST
)
861 base
= VF_NORMAL_VALUE (vfields
);
862 if (base
== NULL_TREE
)
863 base
= VF_BASETYPE_VALUE (vfields
);
865 /* The simple right way to do this is to ensure that the context of
866 the base virtual function is found along the leftmost path
867 between the most derived type associated with the vfield and the
869 distance
= get_base_distance (base
, type
, 0, &path
);
874 if (BINFO_TYPE (path
) == base_context
)
876 path
= BINFO_INHERITANCE_CHAIN (path
);
886 make sure we fill in P's vtable for H with overrides of r,
887 but be cautious of virtual base classes. */
888 /* Combine the two below after debugging. */
889 if (get_base_distance (base_context
, base
, 0, &path
) != -1)
893 if (TREE_VIA_VIRTUAL (path
))
895 path
= BINFO_INHERITANCE_CHAIN (path
);
907 returns 0. VF_BASETYPE_VALUE is RL, base_context is RRB, type is C,
908 and the vfield we are checking is R. */
909 if (VF_BASETYPE_VALUE (vfields
)
910 && get_base_distance (base_context
, VF_BASETYPE_VALUE (vfields
), 0, &path
) == -1
911 && get_base_distance (VF_BASETYPE_VALUE (vfields
), base_context
, 0, &path
) == -1)
918 static void modify_vtable_entries ();
920 /* Access the virtual function table entry i. VIRTUALS is the virtual
921 function table's initializer. */
923 get_vtable_entry_n (virtuals
, i
)
925 unsigned HOST_WIDE_INT i
;
929 virtuals
= TREE_CHAIN (virtuals
);
936 /* Find the vfield (in the CLASSTYPE_VFIELDS chain) of the given binfo. */
938 find_associated_vfield (binfo
, t
)
942 tree save_vfields
= 0;
943 for (vfields
= CLASSTYPE_VFIELDS (t
); vfields
; vfields
= TREE_CHAIN (vfields
))
945 if (VF_BINFO_VALUE (vfields
) == binfo
)
948 for (vfields
= CLASSTYPE_VFIELDS (t
); vfields
; vfields
= TREE_CHAIN (vfields
))
951 get_base_distance (VF_BASETYPE_VALUE (vfields
), t
, 0, &path
);
956 path
= BINFO_INHERITANCE_CHAIN (path
);
959 /* This is from a virtual base class's vtable, hopefully. */
965 /* Returns != 0 is the BINFO is the normal one for the main vfield, 0
966 otherwise. We don't have to worry about the finding BINFO in
967 CLASSTYPE_VBASECLASSES, if it is virtual, as we never inherit
968 vtables from virtual base classes. */
974 int i
= CLASSTYPE_VFIELD_PARENT (t
);
977 tree base_binfo
= TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (t
)), i
);
978 if (base_binfo
== binfo
)
984 /* Modify virtual function tables in lattice topped by T to place
985 FNDECL in tables which previously held BASE_FNDECL. This marches
986 through the vtables directly, looking for exact mactes to
989 modify_other_vtable_entries (t
, binfo
, fndecl
, base_fndecl
, pfn
)
991 tree fndecl
, base_fndecl
, pfn
;
993 tree vfields
, virtuals
;
996 unsigned HOST_WIDE_INT n
;
998 virtuals
= BINFO_VIRTUALS (binfo
);
1002 tree current_fndecl
= TREE_VALUE (virtuals
);
1004 current_fndecl
= FNADDR_FROM_VTABLE_ENTRY (current_fndecl
);
1005 current_fndecl
= TREE_OPERAND (current_fndecl
, 0);
1006 if (current_fndecl
&& SAME_FN (current_fndecl
, base_fndecl
))
1008 /* Most of the below was copied from
1009 modify_vtable_entries (t, fndecl, base_fndecl, pfn); */
1010 tree base_offset
, offset
;
1011 tree context
= DECL_CLASS_CONTEXT (fndecl
);
1012 tree vfield
= CLASSTYPE_VFIELD (t
);
1014 tree binfo2
, this_offset
;
1017 offset
= integer_zero_node
;
1018 if (context
!= t
&& TYPE_USES_COMPLEX_INHERITANCE (t
))
1020 offset
= virtual_offset (context
, CLASSTYPE_VBASECLASSES (t
), offset
);
1021 if (offset
== NULL_TREE
)
1023 tree binfo
= get_binfo (context
, t
, 0);
1024 offset
= BINFO_OFFSET (binfo
);
1028 /* Get the path starting from the deepest base class CONTEXT
1029 of T (i.e., first defn of BASE_FNDECL). */
1030 get_base_distance (binfo
, t
, 0, &path
);
1033 /* Get our best approximation of what to use for constructing
1034 the virtual function table for T. */
1037 /* Walk from base toward derived, stopping at the
1038 most derived baseclass that matters. That baseclass
1039 is exactly the one which provides the vtable along
1040 the VFIELD spine, but no more. */
1041 if (TREE_VIA_VIRTUAL (path
))
1044 binfo2
= binfo_member (BINFO_TYPE (base
), CLASSTYPE_VBASECLASSES (t
));
1045 /* This should never have TREE_USED set. */
1049 if (BINFO_INHERITANCE_CHAIN (path
) == NULL_TREE
1050 || (BINFO_TYPE (BINFO_BASETYPE (BINFO_INHERITANCE_CHAIN (path
), 0))
1051 != BINFO_TYPE (path
))
1052 || BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (path
)) == NULL_TREE
)
1059 path
= BINFO_INHERITANCE_CHAIN (path
);
1060 binfo2_ptr
= &BINFO_INHERITANCE_CHAIN (path
);
1064 /* Find the right offset for the this pointer based on the base
1065 class we just found. */
1066 base_offset
= BINFO_OFFSET (binfo2
);
1067 this_offset
= size_binop (MINUS_EXPR
, offset
, base_offset
);
1069 /* Make sure we can modify the derived association with immunity. */
1070 if (TREE_USED (binfo2
)) {
1071 my_friendly_assert (*binfo2_ptr
== binfo2
, 999);
1072 *binfo2_ptr
= copy_binfo (binfo2
);
1076 vfields
= find_associated_vfield (binfo2
, t
);
1078 /* We call this case NORMAL iff this virtual function table
1079 pointer field has its storage reserved in this class.
1080 This is normally the case without virtual baseclasses
1081 or off-center multiple baseclasses. */
1082 normal
= (vfields
&& vfield
!= NULL_TREE
1083 && VF_BASETYPE_VALUE (vfields
) == DECL_FCONTEXT (vfield
)
1084 && (VF_BINFO_VALUE (vfields
) == NULL_TREE
1085 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
))));
1087 if (normal
&& VF_BINFO_VALUE (vfields
))
1088 /* Everything looks normal so far...check that we are really
1089 working from VFIELD's basetype, and not some other appearance
1090 of that basetype in the lattice. */
1091 normal
= (VF_BINFO_VALUE (vfields
)
1092 == get_binfo (VF_BASETYPE_VALUE (vfields
), t
, 0));
1094 normal
= is_normal (binfo2
, t
);
1099 /* In this case, it is *type*'s vtable we are modifying.
1100 We start with the approximation that it's vtable is that
1101 of the immediate base class. */
1102 binfo2
= TYPE_BINFO (t
);
1103 if (! BINFO_NEW_VTABLE_MARKED (binfo2
))
1104 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield
)), t
);
1108 /* This is our very own copy of `basetype' to play with.
1109 Later, we will fill in all the virtual functions
1110 that override the virtual functions in these base classes
1111 which are not defined by the current type. */
1112 if (! BINFO_NEW_VTABLE_MARKED (binfo2
))
1113 prepare_fresh_vtable (binfo2
, base
, t
);
1117 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo2
)));
1119 modify_vtable_entry (get_vtable_entry_n (BINFO_VIRTUALS (binfo2
), n
),
1120 build_vtable_entry (this_offset
, pfn
),
1122 } else if (current_fndecl
&& DECL_NAME (current_fndecl
) == DECL_NAME (base_fndecl
))
1125 cp_warning ("%D not replaced (looking for %D) in %D", DECL_ASSEMBLER_NAME (current_fndecl
), DECL_ASSEMBLER_NAME (base_fndecl
), DECL_NAME (BINFO_VTABLE (binfo
)));
1129 virtuals
= TREE_CHAIN (virtuals
);
1131 binfos
= BINFO_BASETYPES (binfo
);
1132 n_baselinks
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1133 for (i
= 0; i
< n_baselinks
; i
++)
1135 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1136 /* Don't modify virtual bases, as we share them down this way. */
1137 /* We hope that other places will get things down this direction. */
1138 if (TREE_VIA_VIRTUAL (base_binfo
))
1140 modify_other_vtable_entries (t
, base_binfo
, fndecl
, base_fndecl
, pfn
);
1144 /* Modify virtual function tables in lattice topped by T to
1145 place FNDECL in tables which previously held BASE_FNDECL.
1146 PFN is just FNDECL wrapped in an ADDR_EXPR, so that it
1147 is suitable for placement directly into an initializer.
1149 All distinct virtual function tables that this type uses
1152 modify_vtable_entries (t
, fndecl
, base_fndecl
, pfn
)
1154 tree fndecl
, base_fndecl
, pfn
;
1156 tree base_offset
, offset
;
1157 tree base_context
= DECL_CONTEXT (base_fndecl
);
1158 tree context
= DECL_CLASS_CONTEXT (fndecl
);
1159 tree vfield
= CLASSTYPE_VFIELD (t
);
1160 tree vfields
, vbases
;
1164 cp_warning ("modifing all %D into %D for %T", base_fndecl
, fndecl
, t
);
1165 if (DECL_CONTEXT (fndecl
) != DECL_CONTEXT (base_fndecl
))
1167 cp_warning ("switching contexts from %T to %T for %x",
1168 DECL_CONTEXT (fndecl
),
1169 DECL_CONTEXT (base_fndecl
), fndecl
);
1170 cp_warning ("base was %D, new is %D", DECL_ASSEMBLER_NAME (base_fndecl
),
1171 DECL_ASSEMBLER_NAME(fndecl
));
1174 DECL_CONTEXT (fndecl
) = DECL_CONTEXT (base_fndecl
);
1176 offset
= integer_zero_node
;
1177 if (context
!= t
&& TYPE_USES_COMPLEX_INHERITANCE (t
))
1179 offset
= virtual_offset (context
, CLASSTYPE_VBASECLASSES (t
), offset
);
1180 if (offset
== NULL_TREE
)
1182 tree binfo
= get_binfo (context
, t
, 0);
1183 offset
= BINFO_OFFSET (binfo
);
1187 /* For each layer of base class (i.e., the first base class, and each
1188 virtual base class from that one), modify the virtual function table
1189 of the derived class to contain the new virtual function.
1190 A class has as many vfields as it has virtual base classes (total). */
1191 for (vfields
= CLASSTYPE_VFIELDS (t
); vfields
; vfields
= TREE_CHAIN (vfields
))
1194 tree binfo
, this_offset
;
1197 if (!related_vslot (base_fndecl
, vfields
, t
))
1200 /* Find the right base class for this derived class, call it BASE. */
1201 base
= VF_BASETYPE_VALUE (vfields
);
1203 /* Get the path starting from the deepest base class CONTEXT
1204 of T (i.e., first defn of BASE_FNDECL). */
1205 get_base_distance (DECL_CONTEXT (base_fndecl
), t
, 0, &path
);
1207 /* Get our best approximation of what to use for constructing
1208 the virtual function table for T. */
1211 /* Walk from base toward derived, stopping at the
1212 most derived baseclass that matters. That baseclass
1213 is exactly the one which provides the vtable along
1214 the VFIELD spine, but no more. */
1215 if (TREE_VIA_VIRTUAL (path
))
1218 binfo
= binfo_member (BINFO_TYPE (base
), CLASSTYPE_VBASECLASSES (t
));
1221 if (BINFO_INHERITANCE_CHAIN (path
) == NULL_TREE
1222 || (BINFO_TYPE (BINFO_BASETYPE (BINFO_INHERITANCE_CHAIN (path
), 0))
1223 != BINFO_TYPE (path
))
1224 || BINFO_INHERITANCE_CHAIN (BINFO_INHERITANCE_CHAIN (path
)) == NULL_TREE
)
1230 path
= BINFO_INHERITANCE_CHAIN (path
);
1234 /* Find the right offset for the this pointer based on the base
1235 class we just found. */
1236 base_offset
= BINFO_OFFSET (binfo
);
1237 this_offset
= size_binop (MINUS_EXPR
, offset
, base_offset
);
1239 /* Make sure we can modify the derived association with immunity. */
1240 if (TREE_USED (TYPE_BINFO (t
)))
1241 TYPE_BINFO (t
) = copy_binfo (TYPE_BINFO (t
));
1243 /* We call this case NORMAL iff this virtual function table
1244 pointer field has its storage reserved in this class.
1245 This is normally the case without virtual baseclasses
1246 or off-center multiple baseclasses. */
1247 normal
= (vfield
!= NULL_TREE
1248 && VF_BASETYPE_VALUE (vfields
) == DECL_FCONTEXT (vfield
)
1249 && (VF_BINFO_VALUE (vfields
) == NULL_TREE
1250 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
))));
1252 if (normal
&& VF_BINFO_VALUE (vfields
))
1253 /* Everything looks normal so far...check that we are really
1254 working from VFIELD's basetype, and not some other appearance
1255 of that basetype in the lattice. */
1256 normal
= (VF_BINFO_VALUE (vfields
)
1257 == get_binfo (VF_BASETYPE_VALUE (vfields
), t
, 0));
1261 /* In this case, it is *type*'s vtable we are modifying.
1262 We start with the approximation that it's vtable is that
1263 of the immediate base class. */
1265 binfo
= TYPE_BINFO (t
);
1266 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
1267 build_vtable (TYPE_BINFO (DECL_CONTEXT (vfield
)), t
);
1271 /* This is our very own copy of `basetype' to play with.
1272 Later, we will fill in all the virtual functions
1273 that override the virtual functions in these base classes
1274 which are not defined by the current type. */
1275 if (! BINFO_NEW_VTABLE_MARKED (binfo
))
1276 prepare_fresh_vtable (binfo
, base
, t
);
1279 saved_pfn
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (get_vtable_entry (BINFO_VIRTUALS (binfo
), base_fndecl
))), 0);
1281 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (binfo
)));
1283 /* The this_offset can be wrong, if we try and modify an entry
1284 that had been modified once before. */
1285 if (! SAME_FN (saved_pfn
, fndecl
))
1287 modify_vtable_entry (get_vtable_entry (BINFO_VIRTUALS (binfo
), base_fndecl
),
1288 build_vtable_entry (this_offset
, pfn
),
1290 modify_other_vtable_entries (t
, TYPE_BINFO (t
), fndecl
, saved_pfn
, pfn
);
1293 for (vbases
= CLASSTYPE_VBASECLASSES (t
); vbases
; vbases
= TREE_CHAIN (vbases
))
1298 if (! BINFO_VTABLE (vbases
))
1299 /* There are only two ways that a type can fail to have
1300 virtual functions: neither it nor any of its base
1301 types define virtual functions (in which case
1302 no updating need be done), or virtual functions
1303 accessible to it come from virtual base classes
1304 (in which case we have or will get them modified
1305 in other passes of this loop). */
1308 base
= BINFO_TYPE (vbases
);
1311 if (base
!= base_context
1312 && get_base_distance (base_context
, base
, 0, &path
) == -1)
1316 this_offset
= size_binop (MINUS_EXPR
, offset
, BINFO_OFFSET (path
));
1318 this_offset
= offset
;
1320 /* Doesn't matter if not actually from this virtual base class,
1321 but shouldn't come from deeper virtual baseclasses. The enclosing
1322 loop should take care of such baseclasses. */
1325 if (TREE_VIA_VIRTUAL (path
))
1327 path
= BINFO_INHERITANCE_CHAIN (path
);
1330 base_offset
= BINFO_OFFSET (vbases
);
1331 this_offset
= size_binop (MINUS_EXPR
, this_offset
, base_offset
);
1333 /* Make sure we can modify the derived association with immunity. */
1334 if (TREE_USED (TYPE_BINFO (t
)))
1335 TYPE_BINFO (t
) = copy_binfo (TYPE_BINFO (t
));
1337 /* This is our very own copy of `basetype' to play with. */
1338 if (! BINFO_NEW_VTABLE_MARKED (vbases
))
1340 tree context_binfo
= binfo_value (base_context
, base
);
1341 prepare_fresh_vtable (vbases
, context_binfo
, t
);
1343 saved_pfn
= TREE_OPERAND (FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (get_vtable_entry (BINFO_VIRTUALS (vbases
), base_fndecl
))), 0);
1345 cp_warning ("in %D", DECL_NAME (BINFO_VTABLE (vbases
)));
1347 /* The this_offset can be wrong, if we try and modify an entry
1348 that had been modified once before. */
1349 if (! SAME_FN (saved_pfn
, fndecl
))
1351 modify_vtable_entry (get_vtable_entry (BINFO_VIRTUALS (vbases
),
1353 build_vtable_entry (this_offset
, pfn
),
1355 modify_other_vtable_entries (t
, TYPE_BINFO (t
), fndecl
, saved_pfn
, pfn
);
1362 add_virtual_function (pending_virtuals
, has_virtual
, x
, t
)
1363 tree pending_virtuals
;
1366 tree t
; /* Structure type. */
1368 int debug_vbase
= 1;
1370 /* FUNCTION_TYPEs and OFFSET_TYPEs no longer freely
1371 convert to void *. Make such a conversion here. */
1372 tree vfn
= build1 (ADDR_EXPR
, ptr_type_node
, x
);
1373 TREE_CONSTANT (vfn
) = 1;
1375 /* current_class_type may be NULL_TREE in case of error. */
1376 if (current_class_type
)
1377 TREE_ADDRESSABLE (x
) = CLASSTYPE_VTABLE_NEEDS_WRITING (current_class_type
);
1379 /* If the virtual function is a redefinition of a prior one,
1380 figure out in which base class the new definition goes,
1381 and if necessary, make a fresh virtual function table
1382 to hold that entry. */
1383 if (DECL_VINDEX (x
) == error_mark_node
)
1385 tree entry
= build_vtable_entry (integer_zero_node
, vfn
);
1387 if (flag_dossier
&& *has_virtual
== 0)
1389 /* CLASSTYPE_DOSSIER is only used as a Boolean (NULL or not). */
1390 CLASSTYPE_DOSSIER (t
) = integer_one_node
;
1394 /* Build a new INT_CST for this DECL_VINDEX. */
1395 #ifdef VTABLE_USES_MASK
1396 SET_DECL_VINDEX (x
, build_int_2 (++(*has_virtual
), 0));
1399 static tree index_table
[256];
1401 int i
= ++(*has_virtual
);
1403 if (i
>= 256 || index_table
[i
] == 0)
1405 index
= build_int_2 (i
, 0);
1407 index_table
[i
] = index
;
1410 index
= index_table
[i
];
1412 DECL_VINDEX (x
) = index
;
1415 pending_virtuals
= tree_cons (DECL_VINDEX (x
), entry
, pending_virtuals
);
1417 /* Happens if declared twice in class or we're not in a class definition.
1418 We will give error later or we've already given it. */
1419 else if (TREE_CODE (DECL_VINDEX (x
)) == INTEGER_CST
1420 || current_class_type
== NULL_TREE
)
1421 return pending_virtuals
;
1422 else if (debug_vbase
&& TYPE_USES_VIRTUAL_BASECLASSES (current_class_type
))
1424 /* Need an entry in some other virtual function table.
1425 Deal with this after we have laid out our virtual base classes. */
1426 pending_hard_virtuals
= temp_tree_cons (x
, vfn
, pending_hard_virtuals
);
1430 /* Need an entry in some other virtual function table.
1431 We can do this now. */
1432 tree base_fndecl_list
= DECL_VINDEX (x
), base_fndecls
, prev
= 0;
1433 tree vtable_context
= DECL_FCONTEXT (CLASSTYPE_VFIELD (current_class_type
));
1434 tree true_base_fndecl
= 0;
1436 /* First assign DECL_VINDEX from the base vfn with which
1437 we share our vtable. */
1438 base_fndecls
= base_fndecl_list
;
1439 while (base_fndecls
)
1441 if (TREE_CHAIN (base_fndecls
) == NULL_TREE
1442 || DECL_FCONTEXT (CLASSTYPE_VFIELD (DECL_CLASS_CONTEXT (TREE_VALUE (base_fndecls
)))) == vtable_context
)
1444 true_base_fndecl
= TREE_VALUE (base_fndecls
);
1445 modify_vtable_entries (current_class_type
, x
,
1446 true_base_fndecl
, vfn
);
1448 TREE_CHAIN (prev
) = TREE_CHAIN (base_fndecls
);
1450 base_fndecl_list
= prev
;
1453 prev
= base_fndecls
;
1454 base_fndecls
= TREE_CHAIN (base_fndecls
);
1457 /* Now fill in the rest of the vtables. */
1458 base_fndecls
= base_fndecl_list
;
1459 while (base_fndecls
)
1461 /* If we haven't found one we like, first one wins. */
1462 if (true_base_fndecl
== 0)
1463 true_base_fndecl
= TREE_VALUE (base_fndecls
);
1465 modify_vtable_entries (current_class_type
, x
,
1466 TREE_VALUE (base_fndecls
), vfn
);
1467 base_fndecls
= TREE_CHAIN (base_fndecls
);
1470 DECL_CONTEXT (x
) = DECL_CONTEXT (true_base_fndecl
);
1472 return pending_virtuals
;
1475 /* Obstack on which to build the vector of class methods. */
1476 struct obstack class_obstack
;
1477 extern struct obstack
*current_obstack
;
1479 /* Add method METHOD to class TYPE. This is used when a method
1480 has been defined which did not initially appear in the class definition,
1481 and helps cut down on spurious error messages.
1483 FIELDS is the entry in the METHOD_VEC vector entry of the class type where
1484 the method should be added. */
1486 add_method (type
, fields
, method
)
1487 tree type
, *fields
, method
;
1489 /* We must make a copy of METHOD here, since we must be sure that
1490 we have exclusive title to this method's DECL_CHAIN. */
1493 push_obstacks (&permanent_obstack
, &permanent_obstack
);
1495 decl
= copy_node (method
);
1496 if (DECL_RTL (decl
) == 0
1497 && (!processing_template_decl
1498 || !uses_template_parms (decl
)))
1500 make_function_rtl (decl
);
1501 DECL_RTL (method
) = DECL_RTL (decl
);
1505 if (fields
&& *fields
)
1507 /* Take care not to hide destructor. */
1508 DECL_CHAIN (decl
) = DECL_CHAIN (*fields
);
1509 DECL_CHAIN (*fields
) = decl
;
1511 else if (CLASSTYPE_METHOD_VEC (type
) == 0)
1513 tree method_vec
= make_node (TREE_VEC
);
1514 if (TYPE_IDENTIFIER (type
) == DECL_NAME (decl
))
1516 TREE_VEC_ELT (method_vec
, 0) = decl
;
1517 TREE_VEC_LENGTH (method_vec
) = 1;
1521 /* ??? Is it possible for there to have been enough room in the
1522 current chunk for the tree_vec structure but not a tree_vec
1523 plus a tree*? Will this work in that case? */
1524 obstack_free (current_obstack
, method_vec
);
1525 obstack_blank (current_obstack
, sizeof (struct tree_vec
) + sizeof (tree
*));
1526 TREE_VEC_ELT (method_vec
, 1) = decl
;
1527 TREE_VEC_LENGTH (method_vec
) = 2;
1528 obstack_finish (current_obstack
);
1530 CLASSTYPE_METHOD_VEC (type
) = method_vec
;
1534 tree method_vec
= CLASSTYPE_METHOD_VEC (type
);
1535 int len
= TREE_VEC_LENGTH (method_vec
);
1537 /* Adding a new ctor or dtor. This is easy because our
1538 METHOD_VEC always has a slot for such entries. */
1539 if (TYPE_IDENTIFIER (type
) == DECL_NAME (decl
))
1541 /* TREE_VEC_ELT (method_vec, 0) = decl; */
1542 if (decl
!= TREE_VEC_ELT (method_vec
, 0))
1544 DECL_CHAIN (decl
) = TREE_VEC_ELT (method_vec
, 0);
1545 TREE_VEC_ELT (method_vec
, 0) = decl
;
1550 /* This is trickier. We try to extend the TREE_VEC in-place,
1551 but if that does not work, we copy all its data to a new
1552 TREE_VEC that's large enough. */
1553 struct obstack
*ob
= &class_obstack
;
1554 tree
*end
= (tree
*)obstack_next_free (ob
);
1556 if (end
!= TREE_VEC_END (method_vec
))
1558 ob
= current_obstack
;
1559 TREE_VEC_LENGTH (method_vec
) += 1;
1560 TREE_VEC_ELT (method_vec
, len
) = NULL_TREE
;
1561 method_vec
= copy_node (method_vec
);
1562 TREE_VEC_LENGTH (method_vec
) -= 1;
1566 tree tmp_vec
= (tree
) obstack_base (ob
);
1567 if (obstack_room (ob
) < sizeof (tree
))
1569 obstack_blank (ob
, sizeof (struct tree_common
)
1570 + tree_code_length
[(int) TREE_VEC
]
1572 + len
* sizeof (tree
));
1573 tmp_vec
= (tree
) obstack_base (ob
);
1574 bcopy (method_vec
, tmp_vec
,
1575 (sizeof (struct tree_common
)
1576 + tree_code_length
[(int) TREE_VEC
] * sizeof (char *)
1577 + (len
-1) * sizeof (tree
)));
1578 method_vec
= tmp_vec
;
1581 obstack_blank (ob
, sizeof (tree
));
1584 obstack_finish (ob
);
1585 TREE_VEC_ELT (method_vec
, len
) = decl
;
1586 TREE_VEC_LENGTH (method_vec
) = len
+ 1;
1587 CLASSTYPE_METHOD_VEC (type
) = method_vec
;
1589 if (TYPE_BINFO_BASETYPES (type
) && CLASSTYPE_BASELINK_VEC (type
))
1591 /* ??? May be better to know whether these can be extended? */
1592 tree baselink_vec
= CLASSTYPE_BASELINK_VEC (type
);
1594 TREE_VEC_LENGTH (baselink_vec
) += 1;
1595 CLASSTYPE_BASELINK_VEC (type
) = copy_node (baselink_vec
);
1596 TREE_VEC_LENGTH (baselink_vec
) -= 1;
1598 TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type
), len
) = 0;
1602 DECL_CONTEXT (decl
) = type
;
1603 DECL_CLASS_CONTEXT (decl
) = type
;
1608 /* Subroutines of finish_struct. */
1610 /* Look through the list of fields for this struct, deleting
1611 duplicates as we go. This must be recursive to handle
1614 FIELD is the field which may not appear anywhere in FIELDS.
1615 FIELD_PTR, if non-null, is the starting point at which
1616 chained deletions may take place.
1617 The value returned is the first acceptable entry found
1620 Note that anonymous fields which are not of UNION_TYPE are
1621 not duplicates, they are just anonymous fields. This happens
1622 when we have unnamed bitfields, for example. */
1624 delete_duplicate_fields_1 (field
, field_ptr
, fields
)
1625 tree field
, *field_ptr
, fields
;
1628 tree prev
= field_ptr
? *field_ptr
: 0;
1629 if (DECL_NAME (field
) == 0)
1631 if (TREE_CODE (TREE_TYPE (field
)) != UNION_TYPE
)
1634 for (x
= TYPE_FIELDS (TREE_TYPE (field
)); x
; x
= TREE_CHAIN (x
))
1635 fields
= delete_duplicate_fields_1 (x
, field_ptr
, fields
);
1637 TREE_CHAIN (prev
) = fields
;
1642 for (x
= fields
; x
; prev
= x
, x
= TREE_CHAIN (x
))
1644 if (DECL_NAME (x
) == 0)
1646 if (TREE_CODE (TREE_TYPE (x
)) != UNION_TYPE
)
1648 TYPE_FIELDS (TREE_TYPE (x
))
1649 = delete_duplicate_fields_1 (field
, (tree
*)0, TYPE_FIELDS (TREE_TYPE (x
)));
1650 if (TYPE_FIELDS (TREE_TYPE (x
)) == 0)
1653 fields
= TREE_CHAIN (fields
);
1655 TREE_CHAIN (prev
) = TREE_CHAIN (x
);
1660 if (DECL_NAME (field
) == DECL_NAME (x
))
1662 if (TREE_CODE (field
) == CONST_DECL
1663 && TREE_CODE (x
) == CONST_DECL
)
1664 cp_error_at ("duplicate enum value `%D'", x
);
1665 else if (TREE_CODE (field
) == CONST_DECL
1666 || TREE_CODE (x
) == CONST_DECL
)
1667 cp_error_at ("duplicate field `%D' (as enum and non-enum)",
1669 else if (TREE_CODE (field
) == TYPE_DECL
1670 && TREE_CODE (x
) == TYPE_DECL
)
1671 cp_error_at ("duplicate class scope type `%D'", x
);
1672 else if (TREE_CODE (field
) == TYPE_DECL
1673 || TREE_CODE (x
) == TYPE_DECL
)
1674 cp_error_at ("duplicate field `%D' (as type and non-type)",
1677 cp_error_at ("duplicate member `%D'", x
);
1679 fields
= TREE_CHAIN (fields
);
1681 TREE_CHAIN (prev
) = TREE_CHAIN (x
);
1690 delete_duplicate_fields (fields
)
1694 for (x
= fields
; x
&& TREE_CHAIN (x
); x
= TREE_CHAIN (x
))
1695 TREE_CHAIN (x
) = delete_duplicate_fields_1 (x
, &x
, TREE_CHAIN (x
));
1698 /* Change the access of FDECL to ACCESS in T.
1699 Return 1 if change was legit, otherwise return 0. */
1701 alter_access (t
, fdecl
, access
)
1704 enum access_type access
;
1706 tree elem
= purpose_member (t
, DECL_ACCESS (fdecl
));
1707 if (elem
&& TREE_VALUE (elem
) != (tree
)access
)
1709 if (TREE_CODE (TREE_TYPE (fdecl
)) == FUNCTION_DECL
)
1711 cp_error_at ("conflicting access specifications for method `%D', ignored", TREE_TYPE (fdecl
));
1714 error ("conflicting access specifications for field `%s', ignored",
1715 IDENTIFIER_POINTER (DECL_NAME (fdecl
)));
1717 else if (TREE_PRIVATE (fdecl
) && access
!= access_private
)
1718 cp_error_at ("cannot make private `%D' non-private", fdecl
);
1719 else if (TREE_PROTECTED (fdecl
))
1721 if (access
== access_public
)
1722 cp_error_at ("cannot make protected `%D' public", fdecl
);
1725 /* ARM 11.3: an access declaration may not be used to restrict access
1726 to a member that is accessible in the base class. */
1727 else if (TREE_PUBLIC (fdecl
)
1728 && (access
== access_private
1729 || access
== access_protected
))
1730 cp_error_at ("cannot reduce access of public member `%D'", fdecl
);
1731 else if (elem
== NULL_TREE
)
1734 DECL_ACCESS (fdecl
) = tree_cons (t
, (tree
)access
,
1735 DECL_ACCESS (fdecl
));
1742 get_vfield_offset (binfo
)
1745 return size_binop (PLUS_EXPR
,
1746 DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo
))),
1747 BINFO_OFFSET (binfo
));
1750 /* If FOR_TYPE needs to reinitialize virtual function table pointers
1751 for TYPE's sub-objects, add such reinitializations to BASE_INIT_LIST.
1752 Returns BASE_INIT_LIST appropriately modified. */
1755 maybe_fixup_vptrs (for_type
, binfo
, base_init_list
)
1756 tree for_type
, binfo
, base_init_list
;
1758 /* Now reinitialize any slots that don't fall under our virtual
1759 function table pointer. */
1760 tree vfields
= CLASSTYPE_VFIELDS (BINFO_TYPE (binfo
));
1763 tree basetype
= VF_NORMAL_VALUE (vfields
)
1764 ? TYPE_MAIN_VARIANT (VF_NORMAL_VALUE (vfields
))
1765 : VF_BASETYPE_VALUE (vfields
);
1767 tree base_binfo
= get_binfo (basetype
, for_type
, 0);
1768 /* Punt until this is implemented. */
1769 if (1 /* BINFO_MODIFIED (base_binfo) */)
1771 tree base_offset
= get_vfield_offset (base_binfo
);
1772 if (! tree_int_cst_equal (base_offset
, get_vfield_offset (TYPE_BINFO (for_type
)))
1773 && ! tree_int_cst_equal (base_offset
, get_vfield_offset (binfo
)))
1774 base_init_list
= tree_cons (error_mark_node
, base_binfo
,
1777 vfields
= TREE_CHAIN (vfields
);
1779 return base_init_list
;
1782 /* If TYPE does not have a constructor, then the compiler must
1783 manually deal with all of the initialization this type requires.
1785 If a base initializer exists only to fill in the virtual function
1786 table pointer, then we mark that fact with the TREE_VIRTUAL bit.
1787 This way, we avoid multiple initializations of the same field by
1788 each virtual function table up the class hierarchy.
1790 Virtual base class pointers are not initialized here. They are
1791 initialized only at the "top level" of object creation. If we
1792 initialized them here, we would have to skip a lot of work. */
1795 build_class_init_list (type
)
1798 tree base_init_list
= NULL_TREE
;
1799 tree member_init_list
= NULL_TREE
;
1801 /* Since we build member_init_list and base_init_list using
1802 tree_cons, backwards fields the all through work. */
1804 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (type
));
1805 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1807 for (x
= TYPE_FIELDS (type
); x
; x
= TREE_CHAIN (x
))
1809 if (TREE_CODE (x
) != FIELD_DECL
)
1812 if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (x
))
1813 || DECL_INITIAL (x
) != NULL_TREE
)
1814 member_init_list
= tree_cons (x
, type
, member_init_list
);
1816 member_init_list
= nreverse (member_init_list
);
1818 /* We will end up doing this last. Need special marker
1819 to avoid infinite regress. */
1820 if (TYPE_VIRTUAL_P (type
))
1822 base_init_list
= build_tree_list (error_mark_node
, TYPE_BINFO (type
));
1823 if (CLASSTYPE_NEEDS_VIRTUAL_REINIT (type
) == 0)
1824 TREE_VALUE (base_init_list
) = NULL_TREE
;
1825 TREE_ADDRESSABLE (base_init_list
) = 1;
1828 /* Each base class which needs to have initialization
1829 of some kind gets to make such requests known here. */
1830 for (i
= n_baseclasses
-1; i
>= 0; i
--)
1832 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1835 /* Don't initialize virtual baseclasses this way. */
1836 if (TREE_VIA_VIRTUAL (base_binfo
))
1839 if (TYPE_HAS_CONSTRUCTOR (BINFO_TYPE (base_binfo
)))
1841 /* ...and the last shall come first... */
1842 base_init_list
= maybe_fixup_vptrs (type
, base_binfo
, base_init_list
);
1843 base_init_list
= tree_cons (NULL_TREE
, base_binfo
, base_init_list
);
1847 if ((blist
= CLASSTYPE_BASE_INIT_LIST (BINFO_TYPE (base_binfo
))) == NULL_TREE
)
1848 /* Nothing to initialize. */
1852 base_init_list
= maybe_fixup_vptrs (type
, base_binfo
, base_init_list
);
1854 /* This is normally true for single inheritance.
1855 The win is we can shrink the chain of initializations
1856 to be done by only converting to the actual type
1857 we are interested in. */
1858 if (TREE_VALUE (blist
)
1859 && TREE_CODE (TREE_VALUE (blist
)) == TREE_VEC
1860 && tree_int_cst_equal (BINFO_OFFSET (base_binfo
),
1861 BINFO_OFFSET (TREE_VALUE (blist
))))
1865 /* Does it do more than just fill in a
1866 virtual function table pointer? */
1867 if (! TREE_ADDRESSABLE (blist
))
1868 base_init_list
= build_tree_list (blist
, base_init_list
);
1869 /* Can we get by just with the virtual function table
1870 pointer that it fills in? */
1871 else if (TREE_ADDRESSABLE (base_init_list
)
1872 && TREE_VALUE (base_init_list
) == 0)
1873 base_init_list
= blist
;
1874 /* Maybe, but it is not obvious as the previous case. */
1875 else if (! CLASSTYPE_NEEDS_VIRTUAL_REINIT (type
))
1877 tree last
= tree_last (base_init_list
);
1878 while (TREE_VALUE (last
)
1879 && TREE_CODE (TREE_VALUE (last
)) == TREE_LIST
)
1880 last
= tree_last (TREE_VALUE (last
));
1881 if (TREE_VALUE (last
) == 0)
1882 base_init_list
= build_tree_list (blist
, base_init_list
);
1886 base_init_list
= blist
;
1890 /* The function expand_aggr_init knows how to do the
1891 initialization of `basetype' without getting
1892 an explicit `blist'. */
1894 base_init_list
= tree_cons (NULL_TREE
, base_binfo
, base_init_list
);
1896 base_init_list
= CLASSTYPE_BINFO_AS_LIST (BINFO_TYPE (base_binfo
));
1901 if (member_init_list
)
1902 CLASSTYPE_BASE_INIT_LIST (type
) = build_tree_list (base_init_list
, member_init_list
);
1904 CLASSTYPE_BASE_INIT_LIST (type
) = base_init_list
;
1905 else if (member_init_list
)
1906 CLASSTYPE_BASE_INIT_LIST (type
) = member_init_list
;
1912 int max_has_virtual
;
1916 char cant_have_default_ctor
;
1917 char cant_have_const_ctor
;
1918 char cant_synth_copy_ctor
;
1919 char cant_synth_asn_ref
;
1920 char no_const_asn_ref
;
1921 char needs_virtual_dtor
;
1924 /* Record information about type T derived from its base classes.
1925 Store most of that information in T itself, and place the
1926 remaining information in the struct BASE_INFO.
1928 Propagate basetype offsets throughout the lattice. Note that the
1929 lattice topped by T is really a pair: it's a DAG that gives the
1930 structure of the derivation hierarchy, and it's a list of the
1931 virtual baseclasses that appear anywhere in the DAG. When a vbase
1932 type appears in the DAG, it's offset is 0, and it's children start
1933 their offsets from that point. When a vbase type appears in the list,
1934 its offset is the offset it has in the hierarchy, and its children's
1935 offsets include that offset in theirs.
1937 Returns the index of the first base class to have virtual functions,
1938 or -1 if no such base class.
1940 Note that at this point TYPE_BINFO (t) != t_binfo. */
1943 finish_base_struct (t
, b
, t_binfo
)
1945 struct base_info
*b
;
1948 tree binfos
= BINFO_BASETYPES (t_binfo
);
1949 int i
, n_baseclasses
= binfos
? TREE_VEC_LENGTH (binfos
) : 0;
1950 int first_vfn_base_index
= -1;
1951 bzero (b
, sizeof (struct base_info
));
1953 for (i
= 0; i
< n_baseclasses
; i
++)
1955 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
1956 tree basetype
= BINFO_TYPE (base_binfo
);
1958 /* If the type of basetype is incomplete, then
1959 we already complained about that fact
1960 (and we should have fixed it up as well). */
1961 if (TYPE_SIZE (basetype
) == 0)
1964 /* The base type is of incomplete type. It is
1965 probably best to pretend that it does not
1967 if (i
== n_baseclasses
-1)
1968 TREE_VEC_ELT (binfos
, i
) = NULL_TREE
;
1969 TREE_VEC_LENGTH (binfos
) -= 1;
1971 for (j
= i
; j
+1 < n_baseclasses
; j
++)
1972 TREE_VEC_ELT (binfos
, j
) = TREE_VEC_ELT (binfos
, j
+1);
1975 if (TYPE_HAS_INIT_REF (basetype
)
1976 && !TYPE_HAS_CONST_INIT_REF (basetype
))
1977 b
->cant_have_const_ctor
= 1;
1978 if (! TYPE_HAS_INIT_REF (basetype
)
1979 || (TYPE_HAS_NONPUBLIC_CTOR (basetype
) == 2
1980 && ! is_friend_type (t
, basetype
)))
1981 b
->cant_synth_copy_ctor
= 1;
1983 if (TYPE_HAS_CONSTRUCTOR (basetype
)
1984 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype
))
1986 b
->cant_have_default_ctor
= 1;
1987 if (! TYPE_HAS_CONSTRUCTOR (t
))
1989 cp_pedwarn ("base `%T' with only non-default constructor",
1991 cp_pedwarn ("in class without a constructor");
1995 if (TYPE_HAS_ASSIGN_REF (basetype
)
1996 && !TYPE_HAS_CONST_ASSIGN_REF (basetype
))
1997 b
->no_const_asn_ref
= 1;
1998 if (! TYPE_HAS_ASSIGN_REF (basetype
)
1999 || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (basetype
) == 2
2000 && ! is_friend_type (t
, basetype
)))
2001 b
->cant_synth_asn_ref
= 1;
2003 b
->n_ancestors
+= CLASSTYPE_N_SUPERCLASSES (basetype
);
2004 TYPE_NEEDS_CONSTRUCTING (t
) |= TYPE_NEEDS_CONSTRUCTING (basetype
);
2005 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_NEEDS_DESTRUCTOR (basetype
);
2006 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) |= TYPE_HAS_COMPLEX_ASSIGN_REF (basetype
);
2007 TYPE_HAS_COMPLEX_INIT_REF (t
) |= (TYPE_HAS_COMPLEX_INIT_REF (basetype
)
2008 || TYPE_NEEDS_CONSTRUCTING (basetype
));
2010 TYPE_OVERLOADS_CALL_EXPR (t
) |= TYPE_OVERLOADS_CALL_EXPR (basetype
);
2011 TYPE_OVERLOADS_ARRAY_REF (t
) |= TYPE_OVERLOADS_ARRAY_REF (basetype
);
2012 TYPE_OVERLOADS_ARROW (t
) |= TYPE_OVERLOADS_ARROW (basetype
);
2014 if (! TREE_VIA_VIRTUAL (base_binfo
)
2016 /* This cannot be done, as prepare_fresh_vtable wants to modify
2017 binfos associated with vfields anywhere in the hierarchy, not
2018 just immediate base classes. Due to unsharing, the compiler
2019 might consume 3% more memory on a real program.
2021 && ! BINFO_OFFSET_ZEROP (base_binfo
)
2023 && BINFO_BASETYPES (base_binfo
))
2025 tree base_binfos
= BINFO_BASETYPES (base_binfo
);
2026 tree chain
= NULL_TREE
;
2029 /* Now unshare the structure beneath BASE_BINFO. */
2030 for (j
= TREE_VEC_LENGTH (base_binfos
)-1;
2033 tree base_base_binfo
= TREE_VEC_ELT (base_binfos
, j
);
2034 if (! TREE_VIA_VIRTUAL (base_base_binfo
))
2035 TREE_VEC_ELT (base_binfos
, j
)
2036 = make_binfo (BINFO_OFFSET (base_base_binfo
),
2037 BINFO_TYPE (base_base_binfo
),
2038 BINFO_VTABLE (base_base_binfo
),
2039 BINFO_VIRTUALS (base_base_binfo
),
2041 chain
= TREE_VEC_ELT (base_binfos
, j
);
2042 TREE_VIA_PUBLIC (chain
) = TREE_VIA_PUBLIC (base_base_binfo
);
2043 TREE_VIA_PROTECTED (chain
) = TREE_VIA_PROTECTED (base_base_binfo
);
2046 /* Completely unshare potentially shared data, and
2047 update what is ours. */
2048 propagate_binfo_offsets (base_binfo
, BINFO_OFFSET (base_binfo
));
2051 if (! TREE_VIA_VIRTUAL (base_binfo
))
2052 CLASSTYPE_N_SUPERCLASSES (t
) += 1;
2054 if (TYPE_VIRTUAL_P (basetype
))
2056 /* If there's going to be a destructor needed, make
2057 sure it will be virtual. */
2058 b
->needs_virtual_dtor
= 1;
2060 /* Don't borrow virtuals from virtual baseclasses. */
2061 if (TREE_VIA_VIRTUAL (base_binfo
))
2064 if (first_vfn_base_index
< 0)
2067 first_vfn_base_index
= i
;
2069 b
->has_virtual
= CLASSTYPE_VSIZE (basetype
);
2070 b
->vfield
= CLASSTYPE_VFIELD (basetype
);
2071 b
->vfields
= copy_list (CLASSTYPE_VFIELDS (basetype
));
2072 vfields
= b
->vfields
;
2075 if (VF_BINFO_VALUE (vfields
) == NULL_TREE
2076 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
)))
2078 tree value
= VF_BASETYPE_VALUE (vfields
);
2079 if (DECL_NAME (CLASSTYPE_VFIELD (value
))
2080 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
2081 VF_NORMAL_VALUE (b
->vfields
) = basetype
;
2083 VF_NORMAL_VALUE (b
->vfields
) = VF_NORMAL_VALUE (vfields
);
2085 vfields
= TREE_CHAIN (vfields
);
2087 CLASSTYPE_VFIELD (t
) = b
->vfield
;
2091 /* Only add unique vfields, and flatten them out as we go. */
2092 tree vfields
= CLASSTYPE_VFIELDS (basetype
);
2095 if (VF_BINFO_VALUE (vfields
) == NULL_TREE
2096 || ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields
)))
2098 tree value
= VF_BASETYPE_VALUE (vfields
);
2099 b
->vfields
= tree_cons (base_binfo
, value
, b
->vfields
);
2100 if (DECL_NAME (CLASSTYPE_VFIELD (value
))
2101 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
2102 VF_NORMAL_VALUE (b
->vfields
) = basetype
;
2104 VF_NORMAL_VALUE (b
->vfields
) = VF_NORMAL_VALUE (vfields
);
2106 vfields
= TREE_CHAIN (vfields
);
2109 if (b
->has_virtual
== 0)
2111 first_vfn_base_index
= i
;
2112 b
->has_virtual
= CLASSTYPE_VSIZE (basetype
);
2113 b
->vfield
= CLASSTYPE_VFIELD (basetype
);
2114 CLASSTYPE_VFIELD (t
) = b
->vfield
;
2115 /* When we install the first one, set the VF_NORMAL_VALUE
2116 to be the current class, as this it is the most derived
2117 class. Hopefully, this is not set to something else
2119 vfields
= b
->vfields
;
2122 if (DECL_NAME (CLASSTYPE_VFIELD (t
))
2123 == DECL_NAME (CLASSTYPE_VFIELD (basetype
)))
2125 VF_NORMAL_VALUE (vfields
) = t
;
2126 /* There should only be one of them! And it should
2127 always be found, if we get into here. (mrs) */
2130 vfields
= TREE_CHAIN (vfields
);
2137 /* Must come after offsets are fixed for all bases. */
2138 for (i
= 0; i
< n_baseclasses
; i
++)
2140 tree base_binfo
= TREE_VEC_ELT (binfos
, i
);
2141 tree basetype
= BINFO_TYPE (base_binfo
);
2143 if (get_base_distance (basetype
, t_binfo
, 0, (tree
*)0) == -2)
2145 cp_warning ("direct base `%T' inaccessible in `%T' due to ambiguity",
2147 b
->cant_synth_asn_ref
= 1;
2148 b
->cant_synth_copy_ctor
= 1;
2154 /* Find the base class with the largest number of virtual functions. */
2155 for (vfields
= b
->vfields
; vfields
; vfields
= TREE_CHAIN (vfields
))
2157 if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields
)) > b
->max_has_virtual
)
2158 b
->max_has_virtual
= CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields
));
2159 if (VF_DERIVED_VALUE (vfields
)
2160 && CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields
)) > b
->max_has_virtual
)
2161 b
->max_has_virtual
= CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields
));
2166 /* If all virtual functions come only from virtual baseclasses. */
2168 return first_vfn_base_index
;
2172 typecode_p (type
, code
)
2174 enum tree_code code
;
2176 return (TREE_CODE (type
) == code
2177 || (TREE_CODE (type
) == REFERENCE_TYPE
2178 && TREE_CODE (TREE_TYPE (type
)) == code
));
2181 /* Set memoizing fields and bits of T (and its variants) for later use.
2182 MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */
2184 finish_struct_bits (t
, max_has_virtual
)
2186 int max_has_virtual
;
2188 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (t
);
2189 tree method_vec
= CLASSTYPE_METHOD_VEC (t
);
2191 /* Fix up variants (if any). */
2192 tree variants
= TYPE_NEXT_VARIANT (t
);
2195 /* These fields are in the _TYPE part of the node, not in
2196 the TYPE_LANG_SPECIFIC component, so they are not shared. */
2197 TYPE_HAS_CONSTRUCTOR (variants
) = TYPE_HAS_CONSTRUCTOR (t
);
2198 TYPE_HAS_DESTRUCTOR (variants
) = TYPE_HAS_DESTRUCTOR (t
);
2199 TYPE_NEEDS_CONSTRUCTING (variants
) = TYPE_NEEDS_CONSTRUCTING (t
);
2200 TYPE_NEEDS_DESTRUCTOR (variants
) = TYPE_NEEDS_DESTRUCTOR (t
);
2202 TYPE_USES_COMPLEX_INHERITANCE (variants
) = TYPE_USES_COMPLEX_INHERITANCE (t
);
2203 TYPE_VIRTUAL_P (variants
) = TYPE_VIRTUAL_P (t
);
2204 TYPE_USES_VIRTUAL_BASECLASSES (variants
) = TYPE_USES_VIRTUAL_BASECLASSES (t
);
2205 /* Copy whatever these are holding today. */
2206 TYPE_MIN_VALUE (variants
) = TYPE_MIN_VALUE (t
);
2207 TYPE_MAX_VALUE (variants
) = TYPE_MAX_VALUE (t
);
2208 variants
= TYPE_NEXT_VARIANT (variants
);
2211 if (n_baseclasses
&& max_has_virtual
)
2213 /* Done by `finish_struct' for classes without baseclasses. */
2214 int has_abstract_virtuals
= CLASSTYPE_ABSTRACT_VIRTUALS (t
) != 0;
2215 tree binfos
= TYPE_BINFO_BASETYPES (t
);
2216 for (i
= n_baseclasses
-1; i
>= 0; i
--)
2218 has_abstract_virtuals
2219 |= (CLASSTYPE_ABSTRACT_VIRTUALS (BINFO_TYPE (TREE_VEC_ELT (binfos
, i
))) != 0);
2220 if (has_abstract_virtuals
)
2223 if (has_abstract_virtuals
)
2224 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = get_abstract_virtuals (t
);
2229 /* Notice whether this class has type conversion functions defined. */
2230 tree binfo
= TYPE_BINFO (t
);
2231 tree binfos
= BINFO_BASETYPES (binfo
);
2234 for (i
= n_baseclasses
-1; i
>= 0; i
--)
2236 basetype
= BINFO_TYPE (TREE_VEC_ELT (binfos
, i
));
2238 if (TYPE_HAS_CONVERSION (basetype
))
2240 TYPE_HAS_CONVERSION (t
) = 1;
2241 TYPE_HAS_INT_CONVERSION (t
) |= TYPE_HAS_INT_CONVERSION (basetype
);
2242 TYPE_HAS_REAL_CONVERSION (t
) |= TYPE_HAS_REAL_CONVERSION (basetype
);
2244 if (CLASSTYPE_MAX_DEPTH (basetype
) >= CLASSTYPE_MAX_DEPTH (t
))
2245 CLASSTYPE_MAX_DEPTH (t
) = CLASSTYPE_MAX_DEPTH (basetype
) + 1;
2249 /* Need to test METHOD_VEC here in case all methods
2250 (conversions and otherwise) are inherited. */
2251 if (TYPE_HAS_CONVERSION (t
) && method_vec
!= NULL_TREE
)
2253 tree first_conversions
[last_conversion_type
];
2254 tree last_conversions
[last_conversion_type
];
2255 enum conversion_type conv_index
;
2259 bzero (first_conversions
, sizeof (first_conversions
));
2260 bzero (last_conversions
, sizeof (last_conversions
));
2261 for (tmp
= &TREE_VEC_ELT (method_vec
, 1);
2262 tmp
!= TREE_VEC_END (method_vec
); tmp
+= 1)
2264 /* ??? This should compare DECL_NAME (*tmp) == ansi_opname[TYPE_EXPR]. */
2265 if (IDENTIFIER_TYPENAME_P (DECL_ASSEMBLER_NAME (*tmp
)))
2267 tree fntype
= TREE_TYPE (*tmp
);
2268 tree return_type
= TREE_TYPE (fntype
);
2269 my_friendly_assert (TREE_CODE (fntype
) == METHOD_TYPE
, 171);
2271 if (typecode_p (return_type
, POINTER_TYPE
))
2273 if (TYPE_READONLY (TREE_TYPE (return_type
)))
2274 conv_index
= constptr_conv
;
2276 conv_index
= ptr_conv
;
2278 else if (typecode_p (return_type
, INTEGER_TYPE
))
2280 TYPE_HAS_INT_CONVERSION (t
) = 1;
2281 conv_index
= int_conv
;
2283 else if (typecode_p (return_type
, REAL_TYPE
))
2285 TYPE_HAS_REAL_CONVERSION (t
) = 1;
2286 conv_index
= real_conv
;
2291 if (first_conversions
[(int) conv_index
] == NULL_TREE
)
2292 first_conversions
[(int) conv_index
] = *tmp
;
2293 last_conversions
[(int) conv_index
] = *tmp
;
2297 for (i
= 0; i
< (int) last_conversion_type
; i
++)
2298 if (first_conversions
[i
] != last_conversions
[i
])
2299 CLASSTYPE_CONVERSION (t
, i
) = error_mark_node
;
2301 CLASSTYPE_CONVERSION (t
, i
) = first_conversions
[i
];
2304 /* If this type has constructors, force its mode to be BLKmode,
2305 and force its TREE_ADDRESSABLE bit to be nonzero. */
2306 if (TYPE_NEEDS_CONSTRUCTING (t
) || TYPE_NEEDS_DESTRUCTOR (t
))
2310 if (TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
)
2311 DECL_MODE (TYPE_NAME (t
)) = BLKmode
;
2314 TYPE_MODE (variants
) = BLKmode
;
2315 TREE_ADDRESSABLE (variants
) = 1;
2316 variants
= TYPE_NEXT_VARIANT (variants
);
2321 /* Warn about duplicate methods in fn_fields. Also compact method
2322 lists so that lookup can be made faster.
2324 Algorithm: Outer loop builds lists by method name. Inner loop
2325 checks for redundant method names within a list.
2327 Data Structure: List of method lists. The outer list is a
2328 TREE_LIST, whose TREE_PURPOSE field is the field name and the
2329 TREE_VALUE is the TREE_CHAIN of the FUNCTION_DECLs. Friends are
2330 chained in the same way as member functions, but they live in the
2331 TREE_TYPE field of the outer list. That allows them to be quickly
2332 deleted, and requires no extra storage.
2334 If there are any constructors/destructors, they are moved to the
2335 front of the list. This makes pushclass more efficient.
2337 We also link each field which has shares a name with its baseclass
2338 to the head of the list of fields for that base class. This allows
2339 us to reduce search time in places like `build_method_call' to
2340 consider only reasonably likely functions. */
2343 finish_struct_methods (t
, fn_fields
, nonprivate_method
)
2346 int nonprivate_method
;
2349 tree name
= constructor_name (t
);
2350 int i
, n_baseclasses
= CLASSTYPE_N_BASECLASSES (t
);
2352 /* Now prepare to gather fn_fields into vector. */
2353 struct obstack
*ambient_obstack
= current_obstack
;
2354 current_obstack
= &class_obstack
;
2355 method_vec
= make_node (TREE_VEC
);
2356 /* Room has been saved for constructors and destructors. */
2357 current_obstack
= ambient_obstack
;
2358 /* Now make this a live vector. */
2359 obstack_free (&class_obstack
, method_vec
);
2360 obstack_blank (&class_obstack
, sizeof (struct tree_vec
));
2364 /* NEXT Pointer, TEST Pointer, and BASE Pointer. */
2366 tree fn_name
= DECL_NAME (fn_fields
);
2367 if (fn_name
== NULL_TREE
)
2370 nextp
= TREE_CHAIN (fn_fields
);
2371 TREE_CHAIN (fn_fields
) = NULL_TREE
;
2373 /* Clear out this flag.
2375 @@ Doug may figure out how to break
2376 @@ this with nested classes and friends. */
2377 DECL_IN_AGGR_P (fn_fields
) = 0;
2379 /* Note here that a copy ctor is private, so we don't dare generate
2380 a default copy constructor for a class that has a member
2381 of this type without making sure they have access to it. */
2382 if (fn_name
== name
)
2384 tree parmtypes
= FUNCTION_ARG_CHAIN (fn_fields
);
2385 tree parmtype
= parmtypes
? TREE_VALUE (parmtypes
) : void_type_node
;
2387 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
2388 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
)) == t
)
2390 if (TREE_CHAIN (parmtypes
) == NULL_TREE
2391 || TREE_CHAIN (parmtypes
) == void_list_node
2392 || TREE_PURPOSE (TREE_CHAIN (parmtypes
)))
2394 if (TREE_PROTECTED (fn_fields
))
2395 TYPE_HAS_NONPUBLIC_CTOR (t
) = 1;
2396 else if (TREE_PRIVATE (fn_fields
))
2397 TYPE_HAS_NONPUBLIC_CTOR (t
) = 2;
2401 else if (fn_name
== ansi_opname
[(int) MODIFY_EXPR
])
2403 tree parmtype
= TREE_VALUE (FUNCTION_ARG_CHAIN (fn_fields
));
2405 if (TREE_CODE (parmtype
) == REFERENCE_TYPE
2406 && TYPE_MAIN_VARIANT (TREE_TYPE (parmtype
)) == t
)
2408 if (TREE_PROTECTED (fn_fields
))
2409 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t
) = 1;
2410 else if (TREE_PRIVATE (fn_fields
))
2411 TYPE_HAS_NONPUBLIC_ASSIGN_REF (t
) = 2;
2415 /* Constructors are handled easily in search routines.
2416 Besides, we know we won't find any, so do not bother looking. */
2417 if (fn_name
== name
&& TREE_VEC_ELT (method_vec
, 0) == 0)
2418 TREE_VEC_ELT (method_vec
, 0) = fn_fields
;
2421 testp
= &TREE_VEC_ELT (method_vec
, 0);
2422 if (*testp
== NULL_TREE
)
2424 while (((HOST_WIDE_INT
) testp
2425 < (HOST_WIDE_INT
) obstack_next_free (&class_obstack
))
2426 && DECL_NAME (*testp
) != fn_name
)
2428 if ((HOST_WIDE_INT
) testp
2429 < (HOST_WIDE_INT
) obstack_next_free (&class_obstack
))
2433 for (x
= *testp
; x
; x
= DECL_CHAIN (x
))
2435 if (DECL_NAME (fn_fields
) == ansi_opname
[(int) DELETE_EXPR
])
2437 /* ANSI C++ June 5 1992 WP 12.5.5.1 */
2438 cp_error_at ("`%D' overloaded", fn_fields
);
2439 cp_error_at ("previous declaration as `%D' here", x
);
2441 if (DECL_ASSEMBLER_NAME (fn_fields
)==DECL_ASSEMBLER_NAME (x
))
2443 /* We complain about multiple destructors on sight,
2444 so we do not repeat the warning here. Friend-friend
2445 ambiguities are warned about outside this loop. */
2446 if (!DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (fn_fields
)))
2447 cp_error_at ("ambiguous method `%#D' in structure",
2456 DECL_CHAIN (prev_x
) = fn_fields
;
2463 obstack_ptr_grow (&class_obstack
, fn_fields
);
2464 method_vec
= (tree
)obstack_base (&class_obstack
);
2470 TREE_VEC_LENGTH (method_vec
) = (tree
*)obstack_next_free (&class_obstack
)
2471 - (&TREE_VEC_ELT (method_vec
, 0));
2472 obstack_finish (&class_obstack
);
2473 CLASSTYPE_METHOD_VEC (t
) = method_vec
;
2475 if (nonprivate_method
== 0
2476 && CLASSTYPE_FRIEND_CLASSES (t
) == NULL_TREE
2477 && DECL_FRIENDLIST (TYPE_NAME (t
)) == NULL_TREE
)
2479 tree binfos
= BINFO_BASETYPES (TYPE_BINFO (t
));
2480 for (i
= 0; i
< n_baseclasses
; i
++)
2481 if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos
, i
))
2482 || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos
, i
)))
2484 nonprivate_method
= 1;
2487 if (nonprivate_method
== 0)
2488 cp_warning ("all member functions in class `%T' are private", t
);
2491 /* If there are constructors (and destructors), they are at the
2492 front. Place destructors at very front. Also warn if all
2493 constructors and/or destructors are private (in which case this
2494 class is effectively unusable. */
2495 if (TYPE_HAS_DESTRUCTOR (t
))
2499 for (dtor
= TREE_VEC_ELT (method_vec
, 0);
2501 prev
= dtor
, dtor
= DECL_CHAIN (dtor
))
2503 if (DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (dtor
)))
2505 if (TREE_PRIVATE (dtor
)
2506 && CLASSTYPE_FRIEND_CLASSES (t
) == NULL_TREE
2507 && DECL_FRIENDLIST (TYPE_NAME (t
)) == NULL_TREE
2508 && warn_ctor_dtor_privacy
)
2509 warning ("class `%s' only defines a private destructor and has no friends",
2510 TYPE_NAME_STRING (t
));
2515 /* Wild parse errors can cause this to happen. */
2516 if (dtor
== NULL_TREE
)
2517 TYPE_HAS_DESTRUCTOR (t
) = 0;
2518 else if (dtor
!= TREE_VEC_ELT (method_vec
, 0))
2520 DECL_CHAIN (prev
) = DECL_CHAIN (dtor
);
2521 DECL_CHAIN (dtor
) = TREE_VEC_ELT (method_vec
, 0);
2522 TREE_VEC_ELT (method_vec
, 0) = dtor
;
2526 /* Now for each member function (except for constructors and
2527 destructors), compute where member functions of the same
2528 name reside in base classes. */
2529 if (n_baseclasses
!= 0
2530 && TREE_VEC_LENGTH (method_vec
) > 1)
2532 int len
= TREE_VEC_LENGTH (method_vec
);
2533 tree baselink_vec
= make_tree_vec (len
);
2535 tree baselink_binfo
= build_tree_list (NULL_TREE
, TYPE_BINFO (t
));
2537 for (i
= 1; i
< len
; i
++)
2539 TREE_VEC_ELT (baselink_vec
, i
)
2540 = get_baselinks (baselink_binfo
, t
, DECL_NAME (TREE_VEC_ELT (method_vec
, i
)));
2541 if (TREE_VEC_ELT (baselink_vec
, i
) != 0)
2545 CLASSTYPE_BASELINK_VEC (t
) = baselink_vec
;
2547 obstack_free (current_obstack
, baselink_vec
);
2550 /* Now add the methods to the TYPE_METHODS of T, arranged in a chain. */
2552 tree x
, last_x
= NULL_TREE
;
2553 int limit
= TREE_VEC_LENGTH (method_vec
);
2555 for (i
= 1; i
< limit
; i
++)
2557 for (x
= TREE_VEC_ELT (method_vec
, i
); x
; x
= DECL_CHAIN (x
))
2559 if (last_x
!= NULL_TREE
)
2560 TREE_CHAIN (last_x
) = x
;
2565 /* Put ctors and dtors at the front of the list. */
2566 x
= TREE_VEC_ELT (method_vec
, 0);
2569 while (DECL_CHAIN (x
))
2571 /* Let's avoid being circular about this. */
2572 if (x
== DECL_CHAIN (x
))
2574 TREE_CHAIN (x
) = DECL_CHAIN (x
);
2577 if (TREE_VEC_LENGTH (method_vec
) > 1)
2578 TREE_CHAIN (x
) = TREE_VEC_ELT (method_vec
, 1);
2580 TREE_CHAIN (x
) = NULL_TREE
;
2585 TYPE_METHODS (t
) = TREE_VEC_ELT (method_vec
, 0)
2586 ? TREE_VEC_ELT (method_vec
, 0) : TREE_VEC_ELT (method_vec
, 1);
2588 TYPE_METHODS (t
) = method_vec
;
2594 /* Emit error when a duplicate definition of a type is seen. Patch up. */
2597 duplicate_tag_error (t
)
2600 cp_error ("redefinition of `%#T'", t
);
2602 /* Pretend we haven't defined this type. */
2604 /* All of the component_decl's were TREE_CHAINed together in the parser.
2605 finish_struct_methods walks these chains and assembles all methods with
2606 the same base name into DECL_CHAINs. Now we don't need the parser chains
2607 anymore, so we unravel them.
2610 * This used to be in finish_struct, but it turns out that the
2611 * TREE_CHAIN is used by dbxout_type_methods and perhaps some other things...
2613 if (CLASSTYPE_METHOD_VEC(t
))
2615 tree tv
= CLASSTYPE_METHOD_VEC(t
);
2616 int i
, len
= TREE_VEC_LENGTH (tv
);
2617 for (i
= 0; i
< len
; i
++)
2619 tree unchain
= TREE_VEC_ELT (tv
, i
);
2620 while (unchain
!= NULL_TREE
)
2622 TREE_CHAIN (unchain
) = NULL_TREE
;
2623 unchain
= DECL_CHAIN(unchain
);
2628 if (TYPE_LANG_SPECIFIC (t
))
2630 tree as_list
= CLASSTYPE_AS_LIST (t
);
2631 tree binfo
= TYPE_BINFO (t
);
2632 tree binfo_as_list
= CLASSTYPE_BINFO_AS_LIST (t
);
2633 int interface_only
= CLASSTYPE_INTERFACE_ONLY (t
);
2634 int interface_unknown
= CLASSTYPE_INTERFACE_UNKNOWN (t
);
2636 bzero (TYPE_LANG_SPECIFIC (t
), sizeof (struct lang_type
));
2637 BINFO_BASETYPES(binfo
) = NULL_TREE
;
2639 CLASSTYPE_AS_LIST (t
) = as_list
;
2640 TYPE_BINFO (t
) = binfo
;
2641 CLASSTYPE_BINFO_AS_LIST (t
) = binfo_as_list
;
2642 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
2643 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t
, interface_unknown
);
2644 CLASSTYPE_VBASE_SIZE (t
) = integer_zero_node
;
2645 TYPE_REDEFINED (t
) = 1;
2647 TYPE_SIZE (t
) = NULL_TREE
;
2648 TYPE_MODE (t
) = VOIDmode
;
2649 TYPE_FIELDS (t
) = NULL_TREE
;
2650 TYPE_METHODS (t
) = NULL_TREE
;
2651 TYPE_VFIELD (t
) = NULL_TREE
;
2652 TYPE_CONTEXT (t
) = NULL_TREE
;
2655 /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
2656 (or C++ class declaration).
2658 For C++, we must handle the building of derived classes.
2659 Also, C++ allows static class members. The way that this is
2660 handled is to keep the field name where it is (as the DECL_NAME
2661 of the field), and place the overloaded decl in the DECL_FIELD_BITPOS
2662 of the field. layout_record and layout_union will know about this.
2664 More C++ hair: inline functions have text in their
2665 DECL_PENDING_INLINE_INFO nodes which must somehow be parsed into
2666 meaningful tree structure. After the struct has been laid out, set
2667 things up so that this can happen.
2669 And still more: virtual functions. In the case of single inheritance,
2670 when a new virtual function is seen which redefines a virtual function
2671 from the base class, the new virtual function is placed into
2672 the virtual function table at exactly the same address that
2673 it had in the base class. When this is extended to multiple
2674 inheritance, the same thing happens, except that multiple virtual
2675 function tables must be maintained. The first virtual function
2676 table is treated in exactly the same way as in the case of single
2677 inheritance. Additional virtual function tables have different
2678 DELTAs, which tell how to adjust `this' to point to the right thing.
2680 LIST_OF_FIELDLISTS is just that. The elements of the list are
2681 TREE_LIST elements, whose TREE_PURPOSE field tells what access
2682 the list has, and the TREE_VALUE slot gives the actual fields.
2684 If flag_all_virtual == 1, then we lay all functions into
2685 the virtual function table, as though they were declared
2686 virtual. Constructors do not lay down in the virtual function table.
2688 If flag_all_virtual == 2, then we lay all functions into
2689 the virtual function table, such that virtual functions
2690 occupy a space by themselves, and then all functions
2691 of the class occupy a space by themselves. This is illustrated
2692 in the following diagram:
2694 class A; class B : A;
2696 Class A's vtbl: Class B's vtbl:
2697 --------------------------------------------------------------------
2698 | A's virtual functions| | B's virtual functions |
2699 | | | (may inherit some from A). |
2700 --------------------------------------------------------------------
2701 | All of A's functions | | All of A's functions |
2702 | (such as a->A::f). | | (such as b->A::f) |
2703 --------------------------------------------------------------------
2704 | B's new virtual functions |
2705 | (not defined in A.) |
2706 -------------------------------
2707 | All of B's functions |
2708 | (such as b->B::f) |
2709 -------------------------------
2711 this allows the program to make references to any function, virtual
2712 or otherwise in a type-consistent manner. */
2715 finish_struct (t
, list_of_fieldlists
, warn_anon
)
2717 tree list_of_fieldlists
;
2720 extern int interface_only
, interface_unknown
;
2721 extern tree EHS_type
;
2724 int round_up_size
= 1;
2726 enum tree_code code
= TREE_CODE (t
);
2727 register tree x
, last_x
, method_vec
;
2728 int needs_virtual_dtor
;
2729 tree name
= TYPE_NAME (t
), fields
, fn_fields
, tail
;
2730 enum access_type access
;
2733 int max_has_virtual
;
2734 tree pending_virtuals
= NULL_TREE
;
2735 tree abstract_virtuals
= NULL_TREE
;
2738 int cant_have_default_ctor
;
2739 int cant_have_const_ctor
;
2740 int cant_synth_copy_ctor
;
2741 int cant_synth_asn_ref
;
2742 int no_const_asn_ref
;
2744 /* The index of the first base class which has virtual
2745 functions. Only applied to non-virtual baseclasses. */
2746 int first_vfn_base_index
;
2749 int any_default_members
= 0;
2750 int const_sans_init
= 0;
2751 int ref_sans_init
= 0;
2752 int do_mem_init
= 0;
2753 int nonprivate_method
= 0;
2754 tree t_binfo
= TYPE_BINFO (t
);
2755 tree access_decls
= 0;
2757 if (TREE_CODE (name
) == TYPE_DECL
)
2759 #if 0 /* Maybe later. -jason */
2760 struct tinst_level
*til
= tinst_for_decl();
2764 DECL_SOURCE_FILE (name
) = til
->file
;
2765 if (DECL_SOURCE_LINE (name
))
2766 DECL_SOURCE_LINE (name
) = til
->line
;
2773 DECL_SOURCE_FILE (name
) = input_filename
;
2774 /* For TYPE_DECL that are not typedefs (those marked with a line
2775 number of zero, we don't want to mark them as real typedefs.
2776 If this fails one needs to make sure real typedefs have a
2777 previous line number, even if it is wrong, that way the below
2778 will fill in the right line number. (mrs) */
2779 if (DECL_SOURCE_LINE (name
))
2780 DECL_SOURCE_LINE (name
) = lineno
;
2782 name
= DECL_NAME (name
);
2785 if (warn_anon
&& code
!= UNION_TYPE
&& ANON_AGGRNAME_P (name
))
2786 warning ("anonymous class type not used to declare any objects");
2789 /* This is set here, but it's never actually used anywhere. (bpk) */
2790 leftmost_baseclasses
= NULL_TREE
;
2794 if (IS_AGGR_TYPE (t
))
2795 cp_error ("redefinition of `%#T'", t
);
2797 my_friendly_abort (172);
2802 /* Append the fields we need for constructing signature tables. */
2803 if (IS_SIGNATURE (t
))
2804 append_signature_fields (list_of_fieldlists
);
2806 GNU_xref_decl (current_function_decl
, t
);
2808 /* If this type was previously laid out as a forward reference,
2809 make sure we lay it out again. */
2812 CLASSTYPE_GOT_SEMICOLON (t
) = 0;
2814 /* A signature type will contain the fields of the signature table.
2815 Therefore, it's not only an interface. */
2816 if (IS_SIGNATURE (t
))
2818 CLASSTYPE_INTERFACE_ONLY (t
) = 0;
2819 SET_CLASSTYPE_INTERFACE_KNOWN (t
);
2823 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
2824 SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t
, interface_unknown
);
2828 build_t_desc (t
, 0);
2830 TYPE_BINFO (t
) = NULL_TREE
;
2832 old
= suspend_momentary ();
2834 /* Install struct as DECL_FIELD_CONTEXT of each field decl.
2835 Also process specified field sizes.
2836 Set DECL_FIELD_SIZE to the specified size, or 0 if none specified.
2837 The specified size is found in the DECL_INITIAL.
2838 Store 0 there, except for ": 0" fields (so we can find them
2839 and delete them, below). */
2841 if (t_binfo
&& BINFO_BASETYPES (t_binfo
))
2842 n_baseclasses
= TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo
));
2846 if (n_baseclasses
> 0)
2848 struct base_info base_info
;
2850 /* If using multiple inheritance, this may cause variants of our
2851 basetypes to be used (instead of their canonical forms). */
2852 fields
= layout_basetypes (t
, BINFO_BASETYPES (t_binfo
));
2853 last_x
= tree_last (fields
);
2855 first_vfn_base_index
= finish_base_struct (t
, &base_info
, t_binfo
);
2856 /* Remember where we got our vfield from */
2857 CLASSTYPE_VFIELD_PARENT (t
) = first_vfn_base_index
;
2858 has_virtual
= base_info
.has_virtual
;
2859 max_has_virtual
= base_info
.max_has_virtual
;
2860 CLASSTYPE_N_SUPERCLASSES (t
) += base_info
.n_ancestors
;
2861 vfield
= base_info
.vfield
;
2862 vfields
= base_info
.vfields
;
2863 cant_have_default_ctor
= base_info
.cant_have_default_ctor
;
2864 cant_have_const_ctor
= base_info
.cant_have_const_ctor
;
2865 cant_synth_copy_ctor
= base_info
.cant_synth_copy_ctor
;
2866 cant_synth_asn_ref
= base_info
.cant_synth_asn_ref
;
2867 no_const_asn_ref
= base_info
.no_const_asn_ref
;
2868 needs_virtual_dtor
= base_info
.needs_virtual_dtor
;
2869 n_baseclasses
= TREE_VEC_LENGTH (BINFO_BASETYPES (t_binfo
));
2873 first_vfn_base_index
= -1;
2875 max_has_virtual
= has_virtual
;
2877 vfields
= NULL_TREE
;
2880 cant_have_default_ctor
= 0;
2881 cant_have_const_ctor
= 0;
2882 cant_synth_copy_ctor
= 0;
2883 cant_synth_asn_ref
= 0;
2884 no_const_asn_ref
= 0;
2885 needs_virtual_dtor
= 0;
2888 if (write_virtuals
== 3 && CLASSTYPE_INTERFACE_KNOWN (t
)
2889 && current_lang_name
== lang_name_cplusplus
&& ! IS_SIGNATURE (t
))
2891 CLASSTYPE_INTERFACE_ONLY (t
) = interface_only
;
2892 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = ! interface_only
;
2894 else if (IS_SIGNATURE (t
))
2895 CLASSTYPE_VTABLE_NEEDS_WRITING (t
) = 0;
2897 /* The three of these are approximations which may later be
2898 modified. Needed at this point to make add_virtual_function
2899 and modify_vtable_entries work. */
2900 TREE_CHAIN (t_binfo
) = TYPE_BINFO (t
);
2901 TYPE_BINFO (t
) = t_binfo
;
2902 CLASSTYPE_VFIELDS (t
) = vfields
;
2903 CLASSTYPE_VFIELD (t
) = vfield
;
2905 fn_fields
= NULL_TREE
;
2907 if (last_x
&& list_of_fieldlists
)
2908 TREE_CHAIN (last_x
) = TREE_VALUE (list_of_fieldlists
);
2910 if (IS_SIGNATURE (t
))
2912 else if (flag_all_virtual
== 1 && TYPE_OVERLOADS_METHOD_CALL_EXPR (t
))
2917 /* For signatures, we made all methods `public' in the parser and
2918 reported an error if a access specifier was used. */
2919 if (CLASSTYPE_DECLARED_CLASS (t
) == 0)
2921 nonprivate_method
= 1;
2922 if (list_of_fieldlists
2923 && TREE_PURPOSE (list_of_fieldlists
) == (tree
)access_default
)
2924 TREE_PURPOSE (list_of_fieldlists
) = (tree
)access_public
;
2926 else if (list_of_fieldlists
2927 && TREE_PURPOSE (list_of_fieldlists
) == (tree
)access_default
)
2928 TREE_PURPOSE (list_of_fieldlists
) = (tree
)access_private
;
2930 while (list_of_fieldlists
)
2932 access
= (enum access_type
)TREE_PURPOSE (list_of_fieldlists
);
2934 for (x
= TREE_VALUE (list_of_fieldlists
); x
; x
= TREE_CHAIN (x
))
2936 TREE_PRIVATE (x
) = access
== access_private
;
2937 TREE_PROTECTED (x
) = access
== access_protected
;
2938 GNU_xref_member (current_class_name
, x
);
2940 if (TREE_CODE (x
) == TYPE_DECL
)
2942 /* Make sure we set this up. In find_scoped_type, it explicitly
2943 looks for a TYPE_DECL in the TYPE_FIELDS list. If we don't
2944 do this here, we'll miss including this TYPE_DECL in the
2949 DECL_CONTEXT (x
) = t
;
2954 if (TREE_CODE (x
) == FUNCTION_DECL
)
2956 nonprivate_method
|= ! TREE_PRIVATE (x
);
2958 /* If this was an evil function, don't keep it in class. */
2959 if (IDENTIFIER_ERROR_LOCUS (DECL_ASSEMBLER_NAME (x
)))
2963 TREE_CHAIN (last_x
) = TREE_CHAIN (x
);
2967 TREE_CHAIN (tail
) = x
;
2971 /* ??? What if we have duplicate declarations
2972 in T's definition? */
2973 if (DECL_CLASS_CONTEXT (x
))
2976 DECL_CLASS_CONTEXT (x
) = t
;
2978 DECL_FIELD_SIZE (x
) = 0;
2980 /* The name of the field is the original field name
2981 Save this in auxiliary field for later overloading. */
2983 || (all_virtual
== 1 && ! DECL_CONSTRUCTOR_P (x
)))
2985 pending_virtuals
= add_virtual_function (pending_virtuals
,
2986 &has_virtual
, x
, t
);
2987 if (DECL_ABSTRACT_VIRTUAL_P (x
))
2988 abstract_virtuals
= tree_cons (NULL_TREE
, x
, abstract_virtuals
);
2993 /* Handle access declarations. */
2994 if (DECL_NAME (x
) && TREE_CODE (DECL_NAME (x
)) == SCOPE_REF
)
2996 tree fdecl
= TREE_OPERAND (DECL_NAME (x
), 1);
2999 TREE_CHAIN (last_x
) = TREE_CHAIN (x
);
3000 access_decls
= tree_cons ((tree
) access
, fdecl
, access_decls
);
3004 /* If we've gotten this far, it's a data member, possibly static,
3005 or an enumerator. */
3007 DECL_FIELD_CONTEXT (x
) = t
;
3009 /* ``A local class cannot have static data members.'' ARM 9.4 */
3010 if (current_function_decl
&& TREE_STATIC (x
))
3011 cp_error_at ("field `%D' in local class cannot be static", x
);
3013 /* Perform error checking that did not get done in
3015 if (TREE_CODE (TREE_TYPE (x
)) == FUNCTION_TYPE
)
3017 cp_error_at ("field `%D' invalidly declared function type",
3019 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3021 else if (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
)
3023 cp_error_at ("field `%D' invalidly declared method type", x
);
3024 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3026 else if (TREE_CODE (TREE_TYPE (x
)) == OFFSET_TYPE
)
3028 cp_error_at ("field `%D' invalidly declared offset type", x
);
3029 TREE_TYPE (x
) = build_pointer_type (TREE_TYPE (x
));
3032 if (TREE_TYPE (x
) == error_mark_node
)
3039 DECL_FIELD_SIZE (x
) = 0;
3041 /* When this goes into scope, it will be a non-local reference. */
3042 DECL_NONLOCAL (x
) = 1;
3044 if (TREE_CODE (x
) == CONST_DECL
)
3047 if (TREE_CODE (x
) == VAR_DECL
)
3049 if (TREE_CODE (t
) == UNION_TYPE
)
3050 /* Unions cannot have static members. */
3051 cp_error_at ("field `%D' declared static in union", x
);
3056 /* Now it can only be a FIELD_DECL. */
3058 /* If this is of reference type, check if it needs an init.
3059 Also do a little ANSI jig if necessary. */
3060 if (TREE_CODE (TREE_TYPE (x
)) == REFERENCE_TYPE
)
3062 if (DECL_INITIAL (x
) == NULL_TREE
)
3065 /* ARM $12.6.2: [A member initializer list] is the only
3066 way to initialize a nonstatic const and reference
3068 cant_synth_asn_ref
= 1;
3069 cant_have_default_ctor
= 1;
3070 TYPE_HAS_COMPLEX_INIT_REF (t
) = 1;
3072 if (! TYPE_HAS_CONSTRUCTOR (t
))
3075 cp_pedwarn_at ("non-static reference `%#D' in class without a constructor", x
);
3077 cp_pedwarn_at ("non-static reference in class without a constructor", x
);
3081 /* If any field is const, the structure type is pseudo-const. */
3082 if (TREE_READONLY (x
))
3084 C_TYPE_FIELDS_READONLY (t
) = 1;
3085 if (DECL_INITIAL (x
) == NULL_TREE
)
3086 const_sans_init
= 1;
3088 /* ARM $12.6.2: [A member initializer list] is the only
3089 way to initialize a nonstatic const and reference
3091 cant_synth_asn_ref
= 1;
3092 cant_have_default_ctor
= 1;
3093 TYPE_HAS_COMPLEX_INIT_REF (t
) = 1;
3095 if (! TYPE_HAS_CONSTRUCTOR (t
) && !IS_SIGNATURE (t
))
3098 cp_pedwarn_at ("non-static const member `%#D' in class without a constructor", x
);
3100 cp_pedwarn_at ("non-static const member in class without a constructor", x
);
3105 /* A field that is pseudo-const makes the structure
3107 tree t1
= TREE_TYPE (x
);
3108 while (TREE_CODE (t1
) == ARRAY_TYPE
)
3109 t1
= TREE_TYPE (t1
);
3110 if (IS_AGGR_TYPE (t1
))
3112 if (C_TYPE_FIELDS_READONLY (t1
))
3113 C_TYPE_FIELDS_READONLY (t
) = 1;
3114 if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (t1
))
3115 const_sans_init
= 1;
3119 /* We set DECL_BIT_FIELD tentatively in grokbitfield.
3120 If the type and width are valid, we'll keep it set.
3121 Otherwise, the flag is cleared. */
3122 if (DECL_BIT_FIELD (x
))
3124 DECL_BIT_FIELD (x
) = 0;
3125 /* Invalid bit-field size done by grokfield. */
3126 /* Detect invalid bit-field type. */
3127 if (DECL_INITIAL (x
)
3128 && TREE_CODE (TREE_TYPE (x
)) != INTEGER_TYPE
3129 && TREE_CODE (TREE_TYPE (x
)) != ENUMERAL_TYPE
)
3131 cp_error_at ("bit-field `%D' has invalid type", x
);
3132 DECL_INITIAL (x
) = NULL
;
3135 /* Detect and ignore out of range field width. */
3136 if (DECL_INITIAL (x
))
3138 register int width
= TREE_INT_CST_LOW (DECL_INITIAL (x
));
3142 DECL_INITIAL (x
) = NULL
;
3143 cp_error_at ("negative width in bit-field `%D'", x
);
3145 else if (width
== 0 && DECL_NAME (x
) != 0)
3147 DECL_INITIAL (x
) = NULL
;
3148 cp_error_at ("zero width for bit-field `%D'", x
);
3150 else if ((unsigned)width
> TYPE_PRECISION (TREE_TYPE (x
)))
3152 DECL_INITIAL (x
) = NULL
;
3153 cp_error_at ("width of `%D' exceeds its type", x
);
3157 /* Process valid field width. */
3158 if (DECL_INITIAL (x
))
3160 register int width
= TREE_INT_CST_LOW (DECL_INITIAL (x
));
3164 #ifdef EMPTY_FIELD_BOUNDARY
3165 /* field size 0 => mark following field as "aligned" */
3167 DECL_ALIGN (TREE_CHAIN (x
))
3168 = MAX (DECL_ALIGN (TREE_CHAIN (x
)), EMPTY_FIELD_BOUNDARY
);
3169 /* field of size 0 at the end => round up the size. */
3171 round_up_size
= EMPTY_FIELD_BOUNDARY
;
3173 #ifdef PCC_BITFIELD_TYPE_MATTERS
3174 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
),
3175 TYPE_ALIGN (TREE_TYPE (x
)));
3180 DECL_INITIAL (x
) = NULL_TREE
;
3181 DECL_FIELD_SIZE (x
) = width
;
3182 DECL_BIT_FIELD (x
) = 1;
3183 /* Traditionally a bit field is unsigned
3184 even if declared signed. */
3185 if (flag_traditional
3186 && TREE_CODE (TREE_TYPE (x
)) == INTEGER_TYPE
)
3187 TREE_TYPE (x
) = unsigned_type_node
;
3191 /* Non-bit-fields are aligned for their type. */
3192 DECL_ALIGN (x
) = MAX (DECL_ALIGN (x
), TYPE_ALIGN (TREE_TYPE (x
)));
3196 tree type
= TREE_TYPE (x
);
3198 if (TREE_CODE (type
) == ARRAY_TYPE
)
3199 type
= TREE_TYPE (type
);
3201 if (TYPE_LANG_SPECIFIC (type
) && ! ANON_UNION_P (x
))
3203 /* Never let anything with uninheritable virtuals
3204 make it through without complaint. */
3205 if (CLASSTYPE_ABSTRACT_VIRTUALS (type
))
3206 abstract_virtuals_error (x
, type
);
3208 /* Don't let signatures make it through either. */
3209 if (IS_SIGNATURE (type
))
3210 signature_error (x
, type
);
3212 if (code
== UNION_TYPE
)
3215 if (TYPE_NEEDS_CONSTRUCTING (type
))
3216 fie
= "constructor";
3217 else if (TYPE_NEEDS_DESTRUCTOR (type
))
3219 else if (TYPE_HAS_REAL_ASSIGNMENT (type
))
3220 fie
= "assignment operator";
3222 cp_error_at ("member `%#D' with %s not allowed in union", x
,
3227 TYPE_NEEDS_CONSTRUCTING (t
) |= TYPE_NEEDS_CONSTRUCTING (type
);
3228 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_NEEDS_DESTRUCTOR (type
);
3229 TYPE_HAS_COMPLEX_ASSIGN_REF (t
) |= TYPE_HAS_COMPLEX_ASSIGN_REF (type
);
3230 TYPE_HAS_COMPLEX_INIT_REF (t
)
3231 |= (TYPE_HAS_COMPLEX_INIT_REF (type
)
3232 || TYPE_NEEDS_CONSTRUCTING (type
));
3235 if (! TYPE_HAS_INIT_REF (type
)
3236 || (TYPE_HAS_NONPUBLIC_CTOR (type
)
3237 && ! is_friend (t
, type
)))
3238 cant_synth_copy_ctor
= 1;
3239 else if (!TYPE_HAS_CONST_INIT_REF (type
))
3240 cant_have_const_ctor
= 1;
3242 if (! TYPE_HAS_ASSIGN_REF (type
)
3243 || (TYPE_HAS_NONPUBLIC_ASSIGN_REF (type
)
3244 && ! is_friend (t
, type
)))
3245 cant_synth_asn_ref
= 1;
3246 else if (!TYPE_HAS_CONST_ASSIGN_REF (type
))
3247 no_const_asn_ref
= 1;
3249 if (TYPE_HAS_CONSTRUCTOR (type
)
3250 && ! TYPE_HAS_DEFAULT_CONSTRUCTOR (type
))
3252 cant_have_default_ctor
= 1;
3253 if (! TYPE_HAS_CONSTRUCTOR (t
))
3256 cp_pedwarn_at ("member `%#D' with only non-default constructor", x
);
3258 cp_pedwarn_at ("member with only non-default constructor", x
);
3259 cp_pedwarn_at ("in class without a constructor",
3264 if (DECL_INITIAL (x
) != NULL_TREE
)
3266 /* `build_class_init_list' does not recognize
3268 if (code
== UNION_TYPE
&& any_default_members
!= 0)
3269 cp_error_at ("multiple fields in union `%T' initialized");
3270 any_default_members
= 1;
3274 list_of_fieldlists
= TREE_CHAIN (list_of_fieldlists
);
3275 /* link the tail while we have it! */
3278 TREE_CHAIN (last_x
) = NULL_TREE
;
3280 if (list_of_fieldlists
3281 && TREE_VALUE (list_of_fieldlists
)
3282 && TREE_CODE (TREE_VALUE (list_of_fieldlists
)) != FUNCTION_DECL
)
3283 TREE_CHAIN (last_x
) = TREE_VALUE (list_of_fieldlists
);
3287 if (tail
) TREE_CHAIN (tail
) = NULL_TREE
;
3289 /* If this type has any constant members which did not come
3290 with their own initialization, mark that fact here. It is
3291 not an error here, since such types can be saved either by their
3292 constructors, or by fortuitous initialization. */
3293 CLASSTYPE_READONLY_FIELDS_NEED_INIT (t
) = const_sans_init
;
3294 CLASSTYPE_REF_FIELDS_NEED_INIT (t
) = ref_sans_init
;
3295 CLASSTYPE_ABSTRACT_VIRTUALS (t
) = abstract_virtuals
;
3297 if (TYPE_NEEDS_DESTRUCTOR (t
) && !TYPE_HAS_DESTRUCTOR (t
)
3298 && !IS_SIGNATURE (t
))
3300 /* Here we must cons up a destructor on the fly. */
3301 tree dtor
= cons_up_default_function (t
, name
, fields
,
3302 needs_virtual_dtor
!= 0);
3304 /* If we couldn't make it work, then pretend we didn't need it. */
3305 if (dtor
== void_type_node
)
3306 TYPE_NEEDS_DESTRUCTOR (t
) = 0;
3312 TREE_CHAIN (tail
) = dtor
;
3315 if (DECL_VINDEX (dtor
) == NULL_TREE
3316 && ! CLASSTYPE_DECLARED_EXCEPTION (t
)
3317 && (needs_virtual_dtor
3318 || pending_virtuals
!= NULL_TREE
3319 || pending_hard_virtuals
!= NULL_TREE
))
3320 DECL_VINDEX (dtor
) = error_mark_node
;
3321 if (DECL_VINDEX (dtor
))
3322 pending_virtuals
= add_virtual_function (pending_virtuals
,
3323 &has_virtual
, dtor
, NULL_TREE
);
3324 nonprivate_method
= 1;
3328 TYPE_NEEDS_DESTRUCTOR (t
) |= TYPE_HAS_DESTRUCTOR (t
);
3330 /* Synthesize any needed methods. Note that methods will be synthesized
3331 for anonymous unions; grok_x_components undoes that. */
3334 nonprivate_method
= 1;
3336 TYPE_HAS_COMPLEX_INIT_REF (t
)
3337 |= (TYPE_HAS_INIT_REF (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3338 || has_virtual
|| any_default_members
|| first_vfn_base_index
>= 0);
3339 TYPE_NEEDS_CONSTRUCTING (t
)
3340 |= (TYPE_HAS_CONSTRUCTOR (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3341 || has_virtual
|| any_default_members
|| first_vfn_base_index
>= 0);
3343 /* ARM $12.1: A default constructor will be generated for a class X
3344 only if no constructor has been declared for class X. So we
3345 check TYPE_HAS_CONSTRUCTOR also, to make sure we don't generate
3346 one if they declared a constructor in this class. */
3347 if (! TYPE_HAS_CONSTRUCTOR (t
) && ! cant_have_default_ctor
)
3349 tree default_fn
= cons_up_default_function (t
, name
, fields
, 2);
3350 TREE_CHAIN (default_fn
) = fn_fields
;
3351 fn_fields
= default_fn
;
3354 /* Create default copy constructor, if needed. Don't do it for
3355 the exception handler. */
3356 if (! TYPE_HAS_INIT_REF (t
) && ! cant_synth_copy_ctor
&& t
!= EHS_type
)
3358 /* ARM 12.18: You get either X(X&) or X(const X&), but
3361 cons_up_default_function (t
, name
, fields
,
3362 cant_have_const_ctor
? 4 : 3);
3363 TREE_CHAIN (default_fn
) = fn_fields
;
3364 fn_fields
= default_fn
;
3367 TYPE_HAS_REAL_ASSIGNMENT (t
) |= TYPE_HAS_ASSIGNMENT (t
);
3368 TYPE_HAS_REAL_ASSIGN_REF (t
) |= TYPE_HAS_ASSIGN_REF (t
);
3369 TYPE_HAS_COMPLEX_ASSIGN_REF (t
)
3370 |= (TYPE_HAS_ASSIGN_REF (t
) || TYPE_USES_VIRTUAL_BASECLASSES (t
)
3371 || has_virtual
|| first_vfn_base_index
>= 0);
3373 if (! TYPE_HAS_ASSIGN_REF (t
) && ! cant_synth_asn_ref
)
3376 cons_up_default_function (t
, name
, fields
,
3377 no_const_asn_ref
? 6 : 5);
3378 TREE_CHAIN (default_fn
) = fn_fields
;
3379 fn_fields
= default_fn
;
3384 method_vec
= finish_struct_methods (t
, fn_fields
, nonprivate_method
);
3386 if (TYPE_HAS_CONSTRUCTOR (t
)
3387 && ! CLASSTYPE_DECLARED_EXCEPTION (t
)
3388 && CLASSTYPE_FRIEND_CLASSES (t
) == NULL_TREE
3389 && DECL_FRIENDLIST (TYPE_NAME (t
)) == NULL_TREE
)
3391 int nonprivate_ctor
= 0;
3394 for (ctor
= TREE_VEC_ELT (method_vec
, 0);
3396 ctor
= DECL_CHAIN (ctor
))
3397 if (! TREE_PRIVATE (ctor
))
3399 nonprivate_ctor
= 1;
3403 if (nonprivate_ctor
== 0 && warn_ctor_dtor_privacy
)
3404 cp_warning ("`%#T' only defines private constructors and has no friends",
3412 /* Just in case these got accidentally
3413 filled in by syntax errors. */
3414 TYPE_HAS_CONSTRUCTOR (t
) = 0;
3415 TYPE_HAS_DESTRUCTOR (t
) = 0;
3419 int n_methods
= TREE_VEC_LENGTH (method_vec
);
3421 for (access_decls
= nreverse (access_decls
); access_decls
;
3422 access_decls
= TREE_CHAIN (access_decls
))
3424 tree fdecl
= TREE_VALUE (access_decls
);
3425 tree flist
= NULL_TREE
;
3427 enum access_type access
= (enum access_type
)TREE_PURPOSE(access_decls
);
3431 if (TREE_CODE (fdecl
) == TREE_LIST
)
3434 fdecl
= TREE_VALUE (flist
);
3437 name
= DECL_NAME (fdecl
);
3439 for (; i
< n_methods
; i
++)
3440 if (DECL_NAME (TREE_VEC_ELT (method_vec
, i
)) == name
)
3442 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl
, t
);
3443 cp_error_at ("because of local method `%#D' with same name",
3444 TREE_VEC_ELT (method_vec
, i
));
3452 for (tmp
= fields
; tmp
; tmp
= TREE_CHAIN (tmp
))
3453 if (DECL_NAME (tmp
) == name
)
3455 cp_error ("cannot adjust access to `%#D' in `%#T'", fdecl
, t
);
3456 cp_error_at ("because of local field `%#D' with same name", tmp
);
3464 /* Make type T see field decl FDECL with access ACCESS.*/
3467 fdecl
= TREE_VALUE (flist
);
3470 if (alter_access (t
, fdecl
, access
) == 0)
3472 fdecl
= DECL_CHAIN (fdecl
);
3476 alter_access (t
, fdecl
, access
);
3481 if (vfield
== NULL_TREE
&& has_virtual
)
3483 /* We build this decl with ptr_type_node, and
3484 change the type when we know what it should be. */
3485 vfield
= build_lang_field_decl (FIELD_DECL
, get_vfield_name (t
),
3487 /* If you change any of the below, take a look at all the
3488 other VFIELD_BASEs and VTABLE_BASEs in the code, and change
3490 DECL_ASSEMBLER_NAME (vfield
) = get_identifier (VFIELD_BASE
);
3491 CLASSTYPE_VFIELD (t
) = vfield
;
3492 DECL_VIRTUAL_P (vfield
) = 1;
3493 DECL_FIELD_CONTEXT (vfield
) = t
;
3494 DECL_CLASS_CONTEXT (vfield
) = t
;
3495 DECL_FCONTEXT (vfield
) = t
;
3496 DECL_FIELD_SIZE (vfield
) = 0;
3497 DECL_ALIGN (vfield
) = TYPE_ALIGN (ptr_type_node
);
3498 if (CLASSTYPE_DOSSIER (t
))
3500 /* vfield is always first entry in structure. */
3501 TREE_CHAIN (vfield
) = fields
;
3506 my_friendly_assert (TREE_CHAIN (last_x
) == 0, 175);
3507 TREE_CHAIN (last_x
) = vfield
;
3512 vfields
= chainon (vfields
, CLASSTYPE_AS_LIST (t
));
3515 /* Now DECL_INITIAL is null on all members except for zero-width bit-fields.
3516 And they have already done their work.
3518 C++: maybe we will support default field initialization some day... */
3520 /* Delete all zero-width bit-fields from the front of the fieldlist */
3521 while (fields
&& DECL_BIT_FIELD (fields
)
3522 && DECL_INITIAL (fields
))
3523 fields
= TREE_CHAIN (fields
);
3524 /* Delete all such fields from the rest of the fields. */
3525 for (x
= fields
; x
;)
3527 if (TREE_CHAIN (x
) && DECL_BIT_FIELD (TREE_CHAIN (x
))
3528 && DECL_INITIAL (TREE_CHAIN (x
)))
3529 TREE_CHAIN (x
) = TREE_CHAIN (TREE_CHAIN (x
));
3533 /* Delete all duplicate fields from the fields */
3534 delete_duplicate_fields (fields
);
3536 /* Now we have the final fieldlist for the data fields. Record it,
3537 then lay out the structure or union (including the fields). */
3539 TYPE_FIELDS (t
) = fields
;
3541 /* If there's a :0 field at the end, round the size to the
3542 EMPTY_FIELD_BOUNDARY. */
3543 TYPE_ALIGN (t
) = round_up_size
;
3545 /* Pass layout information about base classes to layout_type, if any. */
3549 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
3551 if (TREE_STATIC (field
))
3553 if (TREE_CODE (field
) != FIELD_DECL
)
3556 /* If this field is an anonymous union,
3557 give each union-member the same position as the union has.
3559 ??? This is a real kludge because it makes the structure
3560 of the types look strange. This feature is only used by
3561 C++, which should have build_component_ref build two
3562 COMPONENT_REF operations, one for the union and one for
3563 the inner field. We set the offset of this field to zero
3564 so that either the old or the correct method will work.
3565 Setting DECL_FIELD_CONTEXT is wrong unless the inner fields are
3566 moved into the type of this field, but nothing seems to break
3569 if (DECL_NAME (field
) == 0
3570 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
3572 tree uelt
= TYPE_FIELDS (TREE_TYPE (field
));
3573 for (; uelt
; uelt
= TREE_CHAIN (uelt
))
3575 DECL_FIELD_CONTEXT (uelt
) = DECL_FIELD_CONTEXT (field
);
3576 DECL_FIELD_BITPOS (uelt
) = DECL_FIELD_BITPOS (field
);
3579 DECL_FIELD_BITPOS (field
) = integer_zero_node
;
3586 tree pseudo_basetype
= TREE_TYPE (base_layout_decl
);
3588 TREE_CHAIN (base_layout_decl
) = TYPE_FIELDS (t
);
3589 TYPE_FIELDS (t
) = base_layout_decl
;
3591 TYPE_SIZE (pseudo_basetype
) = CLASSTYPE_SIZE (t
);
3592 TYPE_MODE (pseudo_basetype
) = TYPE_MODE (t
);
3593 TYPE_ALIGN (pseudo_basetype
) = CLASSTYPE_ALIGN (t
);
3594 DECL_ALIGN (base_layout_decl
) = TYPE_ALIGN (pseudo_basetype
);
3595 /* Don't re-use old size. */
3596 DECL_SIZE (base_layout_decl
) = 0;
3603 for (field
= TYPE_FIELDS (t
); field
; field
= TREE_CHAIN (field
))
3605 if (TREE_STATIC (field
))
3607 if (TREE_CODE (field
) != FIELD_DECL
)
3610 /* If this field is an anonymous union,
3611 give each union-member the same position as the union has.
3613 ??? This is a real kludge because it makes the structure
3614 of the types look strange. This feature is only used by
3615 C++, which should have build_component_ref build two
3616 COMPONENT_REF operations, one for the union and one for
3617 the inner field. We set the offset of this field to zero
3618 so that either the old or the correct method will work.
3619 Setting DECL_FIELD_CONTEXT is wrong unless the inner fields are
3620 moved into the type of this field, but nothing seems to break
3623 if (DECL_NAME (field
) == 0
3624 && TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
)
3626 tree uelt
= TYPE_FIELDS (TREE_TYPE (field
));
3627 for (; uelt
; uelt
= TREE_CHAIN (uelt
))
3629 DECL_FIELD_CONTEXT (uelt
) = DECL_FIELD_CONTEXT (field
);
3630 DECL_FIELD_BITPOS (uelt
) = DECL_FIELD_BITPOS (field
);
3633 DECL_FIELD_BITPOS (field
) = integer_zero_node
;
3639 TYPE_FIELDS (t
) = TREE_CHAIN (TYPE_FIELDS (t
));
3641 /* C++: do not let empty structures exist. */
3642 if (integer_zerop (TYPE_SIZE (t
)))
3643 TYPE_SIZE (t
) = TYPE_SIZE (char_type_node
);
3645 /* Set the TYPE_DECL for this type to contain the right
3646 value for DECL_OFFSET, so that we can use it as part
3647 of a COMPONENT_REF for multiple inheritance. */
3649 if (TREE_CODE (TYPE_NAME (t
)) == TYPE_DECL
)
3650 layout_decl (TYPE_NAME (t
), 0);
3652 /* Now fix up any virtual base class types that we
3653 left lying around. We must get these done
3654 before we try to lay out the virtual function table. */
3655 doing_hard_virtuals
= 1;
3656 pending_hard_virtuals
= nreverse (pending_hard_virtuals
);
3658 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
3662 max_has_virtual
= layout_vbasetypes (t
, max_has_virtual
);
3663 vbases
= CLASSTYPE_VBASECLASSES (t
);
3664 CLASSTYPE_N_VBASECLASSES (t
) = list_length (vbases
);
3668 /* Update dossier info with offsets for virtual baseclasses. */
3669 if (flag_dossier
&& ! BINFO_NEW_VTABLE_MARKED (vbases
))
3670 prepare_fresh_vtable (vbases
, vbases
, t
);
3672 vbases
= TREE_CHAIN (vbases
);
3677 cp_warning ("Doing hard virtuals for %T...", t
);
3679 while (pending_hard_virtuals
)
3681 /* Need an entry in some other virtual function table. */
3682 if (TREE_TYPE (pending_hard_virtuals
))
3684 /* This is how we modify entries when a vfn's index changes
3685 between derived and base type. */
3686 modify_vtable_entries (t
, TREE_PURPOSE (pending_hard_virtuals
),
3687 TREE_TYPE (pending_hard_virtuals
),
3688 TREE_VALUE (pending_hard_virtuals
));
3692 /* This is how we modify entries when a vfn comes from
3693 a virtual baseclass. */
3694 tree base_fndecls
= DECL_VINDEX (TREE_PURPOSE (pending_hard_virtuals
));
3695 /* Only do this, if it was missed before. */
3696 if (TREE_CODE (base_fndecls
) != INTEGER_CST
)
3698 my_friendly_assert (base_fndecls
!= error_mark_node
, 176);
3699 while (base_fndecls
)
3701 modify_vtable_entries (t
, TREE_PURPOSE (pending_hard_virtuals
),
3702 TREE_VALUE (base_fndecls
),
3703 TREE_VALUE (pending_hard_virtuals
));
3704 modify_other_vtable_entries (t
, TYPE_BINFO (t
),
3705 TREE_PURPOSE (pending_hard_virtuals
),
3706 TREE_VALUE (base_fndecls
),
3707 TREE_VALUE (pending_hard_virtuals
));
3708 base_fndecls
= TREE_CHAIN (base_fndecls
);
3712 cp_warning ("missed bases for `%D'", TREE_PURPOSE (pending_hard_virtuals
));
3716 pending_hard_virtuals
= TREE_CHAIN (pending_hard_virtuals
);
3719 if (TYPE_USES_VIRTUAL_BASECLASSES (t
))
3723 vbases
= CLASSTYPE_VBASECLASSES (t
);
3724 CLASSTYPE_N_VBASECLASSES (t
) = list_length (vbases
);
3726 /* This loop makes all the entries in the virtual function tables
3727 of interest contain the "latest" version of the functions
3732 tree virtuals
= BINFO_VIRTUALS (vbases
);
3736 /* Get past the `null' vtable entry... */
3737 virtuals
= TREE_CHAIN (virtuals
);
3738 /* and the `dossier' vtable entry if we're doing dossiers. */
3740 virtuals
= TREE_CHAIN (virtuals
);
3743 while (virtuals
!= NULL_TREE
)
3745 tree pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (virtuals
));
3746 tree base_fndecl
= TREE_OPERAND (pfn
, 0);
3747 tree decl
= get_first_matching_virtual (TYPE_BINFO (t
), base_fndecl
,
3748 DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (base_fndecl
)));
3749 tree context
= DECL_CLASS_CONTEXT (decl
);
3750 if (! SAME_FN (decl
, base_fndecl
))
3752 tree base_context
= DECL_CLASS_CONTEXT (base_fndecl
);
3753 tree binfo
= NULL_TREE
, these_virtuals
;
3755 unsigned HOST_WIDE_INT i
3756 = (TREE_INT_CST_LOW (DECL_VINDEX (base_fndecl
))
3757 & (((unsigned HOST_WIDE_INT
)1<<(BITS_PER_WORD
-1))-1));
3760 if (TYPE_USES_VIRTUAL_BASECLASSES (context
))
3761 binfo
= virtual_member (base_context
,
3762 CLASSTYPE_VBASECLASSES (context
));
3763 if (binfo
== NULL_TREE
)
3764 binfo
= binfo_value (base_context
, context
);
3765 if (binfo
!= NULL_TREE
)
3768 pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (get_vtable_entry (BINFO_VIRTUALS (binfo
), base_fndecl
)));
3770 these_virtuals
= BINFO_VIRTUALS (binfo
);
3773 these_virtuals
= TREE_CHAIN (these_virtuals
);
3774 pfn
= FNADDR_FROM_VTABLE_ENTRY (TREE_VALUE (these_virtuals
));
3776 pfn
= build1 (ADDR_EXPR
, ptr_type_node
, decl
);
3777 TREE_CONSTANT (pfn
) = 1;
3778 modify_vtable_entries (t
, decl
, base_fndecl
, pfn
);
3781 virtuals
= TREE_CHAIN (virtuals
);
3784 vbases
= TREE_CHAIN (vbases
);
3787 doing_hard_virtuals
= 0;
3789 /* Under our model of GC, every C++ class gets its own virtual
3790 function table, at least virtually. */
3791 if (pending_virtuals
|| CLASSTYPE_DOSSIER (t
))
3793 pending_virtuals
= nreverse (pending_virtuals
);
3794 /* We must enter these virtuals into the table. */
3795 if (first_vfn_base_index
< 0)
3798 pending_virtuals
= tree_cons (NULL_TREE
,
3799 build_vtable_entry (integer_zero_node
,
3800 build_t_desc (t
, 0)),
3802 pending_virtuals
= tree_cons (NULL_TREE
, the_null_vtable_entry
,
3804 build_vtable (NULL_TREE
, t
);
3808 /* Here we know enough to change the type of our virtual
3809 function table, but we will wait until later this function. */
3811 if (! BINFO_NEW_VTABLE_MARKED (TYPE_BINFO (t
)))
3812 build_vtable (TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), first_vfn_base_index
), t
);
3814 /* Update the dossier pointer for this class. */
3816 TREE_VALUE (TREE_CHAIN (TYPE_BINFO_VIRTUALS (t
)))
3817 = build_vtable_entry (integer_zero_node
, build_t_desc (t
, 0));
3820 /* If this type has basetypes with constructors, then those
3821 constructors might clobber the virtual function table. But
3822 they don't if the derived class shares the exact vtable of the base
3825 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t
) = 1;
3827 else if (first_vfn_base_index
>= 0)
3829 tree binfo
= TREE_VEC_ELT (TYPE_BINFO_BASETYPES (t
), first_vfn_base_index
);
3832 tree binfo1
= get_binfo (DECL_FIELD_CONTEXT (vfield
), t
, 0);
3833 if (binfo
!= binfo1
)
3834 warning ("binfos are different in vtable creation");
3837 /* This class contributes nothing new to the virtual function
3838 table. However, it may have declared functions which
3839 went into the virtual function table "inherited" from the
3840 base class. If so, we grab a copy of those updated functions,
3841 and pretend they are ours. */
3843 /* See if we should steal the virtual info from base class. */
3844 if (TYPE_BINFO_VTABLE (t
) == NULL_TREE
)
3845 TYPE_BINFO_VTABLE (t
) = BINFO_VTABLE (binfo
);
3846 if (TYPE_BINFO_VIRTUALS (t
) == NULL_TREE
)
3847 TYPE_BINFO_VIRTUALS (t
) = BINFO_VIRTUALS (binfo
);
3848 if (TYPE_BINFO_VTABLE (t
) != BINFO_VTABLE (binfo
))
3849 CLASSTYPE_NEEDS_VIRTUAL_REINIT (t
) = 1;
3852 if (has_virtual
> max_has_virtual
)
3853 max_has_virtual
= has_virtual
;
3854 if (max_has_virtual
|| first_vfn_base_index
>= 0)
3856 #ifdef VTABLE_USES_MASK
3857 if (max_has_virtual
>= VINDEX_MAX
)
3859 cp_error ("too many virtual functions for `%#T' (VINDEX_MAX < %d)",
3863 TYPE_VIRTUAL_P (t
) = 1;
3864 CLASSTYPE_VSIZE (t
) = has_virtual
;
3865 if (first_vfn_base_index
>= 0)
3867 if (pending_virtuals
)
3868 TYPE_BINFO_VIRTUALS (t
) = chainon (TYPE_BINFO_VIRTUALS (t
),
3871 else if (has_virtual
)
3873 TYPE_BINFO_VIRTUALS (t
) = pending_virtuals
;
3874 if (write_virtuals
>= 0)
3875 DECL_VIRTUAL_P (TYPE_BINFO_VTABLE (t
)) = 1;
3879 /* Now lay out the virtual function table. */
3884 if (TREE_TYPE (vfield
) == ptr_type_node
)
3886 /* We must create a pointer to this table because
3887 the one inherited from base class does not exist.
3888 We will fill in the type when we know what it
3889 should really be. Use `size_int' so values are memoized
3891 itype
= build_index_type (size_int (has_virtual
));
3892 atype
= build_array_type (vtable_entry_type
, itype
);
3893 layout_type (atype
);
3894 TREE_TYPE (vfield
) = build_pointer_type (atype
);
3898 atype
= TREE_TYPE (TREE_TYPE (vfield
));
3900 if (has_virtual
!= TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype
))))
3902 /* We must extend (or create) the boundaries on this array,
3903 because we picked up virtual functions from multiple
3905 itype
= build_index_type (size_int (has_virtual
));
3906 atype
= build_array_type (vtable_entry_type
, itype
);
3907 layout_type (atype
);
3908 vfield
= copy_node (vfield
);
3909 TREE_TYPE (vfield
) = build_pointer_type (atype
);
3913 CLASSTYPE_VFIELD (t
) = vfield
;
3914 if (TREE_TYPE (TYPE_BINFO_VTABLE (t
)) != atype
)
3916 TREE_TYPE (TYPE_BINFO_VTABLE (t
)) = atype
;
3917 layout_decl (TYPE_BINFO_VTABLE (t
), 0);
3918 /* At one time the vtable info was grabbed 2 words at a time. This
3919 fails on sparc unless you have 8-byte alignment. (tiemann) */
3920 DECL_ALIGN (TYPE_BINFO_VTABLE (t
))
3921 = MAX (TYPE_ALIGN (double_type_node
),
3922 DECL_ALIGN (TYPE_BINFO_VTABLE (t
)));
3925 else if (first_vfn_base_index
>= 0)
3926 CLASSTYPE_VFIELD (t
) = vfield
;
3927 CLASSTYPE_VFIELDS (t
) = vfields
;
3929 finish_struct_bits (t
, max_has_virtual
);
3931 /* Promote each bit-field's type to int if it is narrower than that.
3932 There's more: complete the rtl for any static member objects which
3933 is of the same type we're working on. */
3934 for (x
= fields
; x
; x
= TREE_CHAIN (x
))
3936 if (DECL_BIT_FIELD (x
)
3937 && (C_PROMOTING_INTEGER_TYPE_P (TREE_TYPE (x
))
3938 || DECL_FIELD_SIZE (x
) < TYPE_PRECISION (integer_type_node
)))
3940 tree type
= TREE_TYPE (x
);
3942 /* Preserve unsignedness if traditional or if not really getting
3944 if (TREE_UNSIGNED (type
)
3945 && (flag_traditional
3947 (TYPE_PRECISION (type
) == TYPE_PRECISION (integer_type_node
)
3948 && DECL_FIELD_SIZE (x
) == TYPE_PRECISION (integer_type_node
))))
3949 TREE_TYPE (x
) = unsigned_type_node
;
3951 TREE_TYPE (x
) = integer_type_node
;
3954 if (TREE_CODE (x
) == VAR_DECL
&& TREE_STATIC (x
)
3955 && TREE_TYPE (x
) == t
)
3957 DECL_MODE (x
) = TYPE_MODE (t
);
3958 make_decl_rtl (x
, NULL
, 0);
3962 /* Now add the tags, if any, to the list of TYPE_DECLs
3963 defined for this type. */
3964 if (CLASSTYPE_TAGS (t
))
3966 x
= CLASSTYPE_TAGS (t
);
3967 last_x
= tree_last (TYPE_FIELDS (t
));
3970 tree tag
= build_lang_decl (TYPE_DECL
, TREE_PURPOSE (x
), TREE_VALUE (x
));
3971 #ifdef DWARF_DEBUGGING_INFO
3972 if (write_symbols
== DWARF_DEBUG
)
3974 /* Notify dwarfout.c that this TYPE_DECL node represent a
3975 gratuitous typedef. */
3976 DECL_IGNORED_P (tag
) = 1;
3978 #endif /* DWARF_DEBUGGING_INFO */
3979 DECL_CONTEXT (tag
) = t
;
3980 DECL_CLASS_CONTEXT (tag
) = t
;
3982 last_x
= chainon (last_x
, tag
);
3984 if (TYPE_FIELDS (t
) == 0)
3985 TYPE_FIELDS (t
) = last_x
;
3986 CLASSTYPE_LOCAL_TYPEDECLS (t
) = 1;
3989 if (TYPE_HAS_CONSTRUCTOR (t
))
3991 tree vfields
= CLASSTYPE_VFIELDS (t
);
3995 /* Mark the fact that constructor for T
3996 could affect anybody inheriting from T
3997 who wants to initialize vtables for VFIELDS's type. */
3998 if (VF_DERIVED_VALUE (vfields
))
3999 TREE_ADDRESSABLE (vfields
) = 1;
4000 vfields
= TREE_CHAIN (vfields
);
4002 if (any_default_members
!= 0)
4003 build_class_init_list (t
);
4005 else if (TYPE_NEEDS_CONSTRUCTING (t
))
4006 build_class_init_list (t
);
4008 if (current_lang_name
== lang_name_cplusplus
)
4010 if (! CLASSTYPE_DECLARED_EXCEPTION (t
)
4011 && ! IS_SIGNATURE (t
))
4012 embrace_waiting_friends (t
);
4014 /* Write out inline function definitions. */
4015 do_inline_function_hair (t
, CLASSTYPE_INLINE_FRIENDS (t
));
4016 CLASSTYPE_INLINE_FRIENDS (t
) = 0;
4019 if (CLASSTYPE_VSIZE (t
) != 0)
4021 if ((flag_this_is_variable
& 1) == 0)
4023 tree vtbl_ptr
= build_decl (VAR_DECL
, get_identifier (VPTR_NAME
),
4024 TREE_TYPE (vfield
));
4025 DECL_REGISTER (vtbl_ptr
) = 1;
4026 CLASSTYPE_VTBL_PTR (t
) = vtbl_ptr
;
4028 if (DECL_FIELD_CONTEXT (vfield
) != t
)
4030 tree binfo
= get_binfo (DECL_FIELD_CONTEXT (vfield
), t
, 0);
4031 tree offset
= BINFO_OFFSET (binfo
);
4033 vfield
= copy_node (vfield
);
4034 copy_lang_decl (vfield
);
4036 if (! integer_zerop (offset
))
4037 offset
= size_binop (MULT_EXPR
, offset
, size_int (BITS_PER_UNIT
));
4038 DECL_FIELD_CONTEXT (vfield
) = t
;
4039 DECL_CLASS_CONTEXT (vfield
) = t
;
4040 DECL_FIELD_BITPOS (vfield
)
4041 = size_binop (PLUS_EXPR
, offset
, DECL_FIELD_BITPOS (vfield
));
4042 CLASSTYPE_VFIELD (t
) = vfield
;
4045 /* In addition to this one, all the other vfields should be listed. */
4046 /* Before that can be done, we have to have FIELD_DECLs for them, and
4047 a place to find them. */
4048 TYPE_NONCOPIED_PARTS (t
) = build_tree_list (default_conversion (TYPE_BINFO_VTABLE (t
)), vfield
);
4050 if (warn_nonvdtor
&& TYPE_HAS_DESTRUCTOR (t
)
4051 && DECL_VINDEX (TREE_VEC_ELT (method_vec
, 0)) == NULL_TREE
)
4052 cp_warning ("`%#T' has virtual functions but non-virtual destructor",
4056 /* Make the rtl for any new vtables we have created, and unmark
4057 the base types we marked. */
4058 unmark_finished_struct (t
);
4059 TYPE_BEING_DEFINED (t
) = 0;
4061 if (flag_dossier
&& CLASSTYPE_VTABLE_NEEDS_WRITING (t
))
4066 /* Now instantiate its type descriptors. */
4067 tdecl
= TREE_OPERAND (build_t_desc (t
, 1), 0);
4068 variants
= TYPE_POINTER_TO (t
);
4069 build_type_variant (variants
, 1, 0);
4072 build_t_desc (variants
, 1);
4073 variants
= TYPE_NEXT_VARIANT (variants
);
4075 variants
= build_reference_type (t
);
4076 build_type_variant (variants
, 1, 0);
4079 build_t_desc (variants
, 1);
4080 variants
= TYPE_NEXT_VARIANT (variants
);
4083 DECL_VPARENT (tdecl
) = t
;
4085 DECL_CONTEXT (tdecl
) = t
;
4087 /* Still need to instantiate this C struct's type descriptor. */
4088 else if (flag_dossier
&& ! CLASSTYPE_DOSSIER (t
))
4089 build_t_desc (t
, 1);
4091 if (TYPE_NAME (t
) && TYPE_IDENTIFIER (t
))
4092 undo_template_name_overload (TYPE_IDENTIFIER (t
), 1);
4093 if (current_class_type
)
4096 error ("trying to finish struct, but kicked out due to previous parse errors.");
4098 hack_incomplete_structures (t
);
4100 resume_momentary (old
);
4103 cadillac_finish_struct (t
);
4106 /* This has to be done after we have sorted out what to do with
4107 the enclosing type. */
4108 if (write_symbols
!= DWARF_DEBUG
)
4110 /* Be smarter about nested classes here. If a type is nested,
4111 only output it if we would output the enclosing type. */
4112 if (DECL_CONTEXT (TYPE_NAME (t
))
4113 && TREE_CODE_CLASS (TREE_CODE (DECL_CONTEXT (TYPE_NAME (t
)))) == 't')
4114 DECL_IGNORED_P (TYPE_NAME (t
)) = TREE_ASM_WRITTEN (TYPE_NAME (t
));
4118 if (write_symbols
!= DWARF_DEBUG
)
4120 /* If the type has methods, we want to think about cutting down
4121 the amount of symbol table stuff we output. The value stored in
4122 the TYPE_DECL's DECL_IGNORED_P slot is a first approximation.
4123 For example, if a member function is seen and we decide to
4124 write out that member function, then we can change the value
4125 of the DECL_IGNORED_P slot, and the type will be output when
4126 that member function's debug info is written out. */
4127 if (CLASSTYPE_METHOD_VEC (t
))
4129 extern tree pending_vtables
;
4131 /* Don't output full info about any type
4132 which does not have its implementation defined here. */
4133 if (TYPE_VIRTUAL_P (t
) && write_virtuals
== 2)
4134 DECL_IGNORED_P (TYPE_NAME (t
))
4135 = (value_member (TYPE_IDENTIFIER (t
), pending_vtables
) == 0);
4136 else if (CLASSTYPE_INTERFACE_ONLY (t
))
4137 DECL_IGNORED_P (TYPE_NAME (t
)) = 1;
4138 else if (CLASSTYPE_INTERFACE_UNKNOWN (t
))
4139 /* Only a first approximation! */
4140 DECL_IGNORED_P (TYPE_NAME (t
)) = 1;
4142 else if (CLASSTYPE_INTERFACE_ONLY (t
))
4143 DECL_IGNORED_P (TYPE_NAME (t
)) = 1;
4146 /* Finish debugging output for this type. */
4147 rest_of_type_compilation (t
, global_bindings_p ());
4152 /* Return non-zero if the effective type of INSTANCE is static.
4153 Used to determine whether the virtual function table is needed
4156 *NONNULL is set iff INSTANCE can be known to be nonnull, regardless
4157 of our knowledge of its type. */
4159 resolves_to_fixed_type_p (instance
, nonnull
)
4163 switch (TREE_CODE (instance
))
4166 /* Check that we are not going through a cast of some sort. */
4167 if (TREE_TYPE (instance
)
4168 == TREE_TYPE (TREE_TYPE (TREE_OPERAND (instance
, 0))))
4169 instance
= TREE_OPERAND (instance
, 0);
4170 /* fall through... */
4172 /* This is a call to a constructor, hence it's never zero. */
4173 if (TREE_HAS_CONSTRUCTOR (instance
))
4182 /* This is a call to a constructor, hence it's never zero. */
4183 if (TREE_HAS_CONSTRUCTOR (instance
))
4189 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4192 /* This is a call to `new', hence it's never zero. */
4193 if (TREE_CALLS_NEW (instance
))
4203 if (TREE_CODE (TREE_OPERAND (instance
, 1)) == INTEGER_CST
)
4204 /* Propagate nonnull. */
4205 resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4206 if (TREE_CODE (TREE_OPERAND (instance
, 0)) == ADDR_EXPR
)
4207 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4212 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4217 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4220 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 1), nonnull
);
4222 case WITH_CLEANUP_EXPR
:
4223 if (TREE_CODE (TREE_OPERAND (instance
, 0)) == ADDR_EXPR
)
4224 return resolves_to_fixed_type_p (TREE_OPERAND (instance
, 0), nonnull
);
4225 /* fall through... */
4228 if (TREE_CODE (TREE_TYPE (instance
)) == ARRAY_TYPE
4229 && IS_AGGR_TYPE (TREE_TYPE (TREE_TYPE (instance
))))
4235 /* fall through... */
4238 if (IS_AGGR_TYPE (TREE_TYPE (instance
)))
4246 if (instance
== current_class_decl
4247 && flag_this_is_variable
<= 0)
4249 /* Some people still use `this = 0' inside destructors. */
4250 *nonnull
= ! DESTRUCTOR_NAME_P (DECL_ASSEMBLER_NAME (current_function_decl
));
4251 /* In a constructor, we know our type. */
4252 if (flag_this_is_variable
< 0)
4255 else if (TREE_CODE (TREE_TYPE (instance
)) == REFERENCE_TYPE
)
4256 /* Reference variables should be references to objects. */
4267 init_class_processing ()
4269 current_class_depth
= 0;
4270 current_class_stacksize
= 10;
4271 current_class_base
= (tree
*)xmalloc(current_class_stacksize
* sizeof (tree
));
4272 current_class_stack
= current_class_base
;
4274 current_lang_stacksize
= 10;
4275 current_lang_base
= (tree
*)xmalloc(current_lang_stacksize
* sizeof (tree
));
4276 current_lang_stack
= current_lang_base
;
4278 /* Keep these values lying around. */
4279 the_null_vtable_entry
= build_vtable_entry (integer_zero_node
, integer_zero_node
);
4280 base_layout_decl
= build_lang_field_decl (FIELD_DECL
, NULL_TREE
, error_mark_node
);
4281 TREE_TYPE (base_layout_decl
) = make_node (RECORD_TYPE
);
4283 gcc_obstack_init (&class_obstack
);
4286 /* Set current scope to NAME. CODE tells us if this is a
4287 STRUCT, UNION, or ENUM environment.
4289 NAME may end up being NULL_TREE if this is an anonymous or
4290 late-bound struct (as in "struct { ... } foo;") */
4292 /* Set global variables CURRENT_CLASS_NAME and CURRENT_CLASS_TYPE to
4293 appropriate values, found by looking up the type definition of
4296 If MODIFY is 1, we set IDENTIFIER_CLASS_VALUE's of names
4297 which can be seen locally to the class. They are shadowed by
4298 any subsequent local declaration (including parameter names).
4300 If MODIFY is 2, we set IDENTIFIER_CLASS_VALUE's of names
4301 which have static meaning (i.e., static members, static
4302 member functions, enum declarations, etc).
4304 If MODIFY is 3, we set IDENTIFIER_CLASS_VALUE of names
4305 which can be seen locally to the class (as in 1), but
4306 know that we are doing this for declaration purposes
4307 (i.e. friend foo::bar (int)).
4309 So that we may avoid calls to lookup_name, we cache the _TYPE
4310 nodes of local TYPE_DECLs in the TREE_TYPE field of the name.
4312 For multiple inheritance, we perform a two-pass depth-first search
4313 of the type lattice. The first pass performs a pre-order search,
4314 marking types after the type has had its fields installed in
4315 the appropriate IDENTIFIER_CLASS_VALUE slot. The second pass merely
4316 unmarks the marked types. If a field or member function name
4317 appears in an ambiguous way, the IDENTIFIER_CLASS_VALUE of
4318 that name becomes `error_mark_node'. */
4321 pushclass (type
, modify
)
4325 push_memoized_context (type
, modify
);
4327 current_class_depth
++;
4328 *current_class_stack
++ = current_class_name
;
4329 *current_class_stack
++ = current_class_type
;
4330 if (current_class_stack
>= current_class_base
+ current_class_stacksize
)
4332 current_class_base
=
4333 (tree
*)xrealloc (current_class_base
,
4334 sizeof (tree
) * (current_class_stacksize
+ 10));
4335 current_class_stack
= current_class_base
+ current_class_stacksize
;
4336 current_class_stacksize
+= 10;
4339 current_class_name
= TYPE_NAME (type
);
4340 if (TREE_CODE (current_class_name
) == TYPE_DECL
)
4341 current_class_name
= DECL_NAME (current_class_name
);
4342 current_class_type
= type
;
4344 if (previous_class_type
!= NULL_TREE
4345 && (type
!= previous_class_type
|| TYPE_SIZE (previous_class_type
) == NULL_TREE
)
4346 && current_class_depth
== 1)
4348 /* Forcibly remove any old class remnants. */
4350 previous_class_type
= NULL_TREE
;
4358 tree this_fndecl
= current_function_decl
;
4360 if (current_function_decl
4361 && DECL_CONTEXT (current_function_decl
)
4362 && TREE_CODE (DECL_CONTEXT (current_function_decl
)) == FUNCTION_DECL
)
4363 current_function_decl
= DECL_CONTEXT (current_function_decl
);
4365 current_function_decl
= NULL_TREE
;
4367 if (TREE_CODE (type
) == UNINSTANTIATED_P_TYPE
)
4369 declare_uninstantiated_type_level ();
4370 overload_template_name (current_class_name
, 0);
4372 else if (type
!= previous_class_type
|| current_class_depth
> 1)
4374 build_mi_matrix (type
);
4375 push_class_decls (type
);
4377 if (current_class_depth
== 1)
4378 previous_class_type
= type
;
4384 /* Hooray, our cacheing was successful, let's just install the
4385 cached class_shadowed list, and walk through it to get the
4386 IDENTIFIER_TYPE_VALUEs correct. */
4387 set_class_shadows (previous_class_values
);
4388 for (item
= previous_class_values
; item
; item
= TREE_CHAIN (item
))
4390 tree id
= TREE_PURPOSE (item
);
4391 tree decl
= IDENTIFIER_CLASS_VALUE (id
);
4393 if (TREE_CODE (decl
) == TYPE_DECL
)
4394 set_identifier_type_value (id
, TREE_TYPE (decl
));
4396 unuse_fields (type
);
4399 for (tags
= CLASSTYPE_TAGS (type
); tags
; tags
= TREE_CHAIN (tags
))
4401 TREE_NONLOCAL_FLAG (TREE_VALUE (tags
)) = 1;
4402 if (! TREE_PURPOSE (tags
))
4404 pushtag (TREE_PURPOSE (tags
), TREE_VALUE (tags
), 0);
4407 current_function_decl
= this_fndecl
;
4411 cadillac_push_class (type
);
4414 /* Get out of the current class scope. If we were in a class scope
4415 previously, that is the one popped to. The flag MODIFY tells
4416 whether the current scope declarations needs to be modified
4417 as a result of popping to the previous scope. */
4423 cadillac_pop_class ();
4427 /* Back this old class out completely. */
4428 tree tags
= CLASSTYPE_TAGS (previous_class_type
);
4431 /* This code can be seen as a cache miss. When we've cached a
4432 class' scope's bindings and we can't use them, we need to reset
4433 them. This is it! */
4434 for (t
= previous_class_values
; t
; t
= TREE_CHAIN(t
))
4435 IDENTIFIER_CLASS_VALUE (TREE_PURPOSE (t
)) = NULL_TREE
;
4438 TREE_NONLOCAL_FLAG (TREE_VALUE (tags
)) = 0;
4439 tags
= TREE_CHAIN (tags
);
4446 /* Just remove from this class what didn't make
4447 it into IDENTIFIER_CLASS_VALUE. */
4448 tree tags
= CLASSTYPE_TAGS (current_class_type
);
4452 TREE_NONLOCAL_FLAG (TREE_VALUE (tags
)) = 0;
4453 tags
= TREE_CHAIN (tags
);
4456 if (TREE_CODE (current_class_type
) == UNINSTANTIATED_P_TYPE
)
4457 undo_template_name_overload (current_class_name
, 0);
4461 /* Since poplevel_class does the popping of class decls nowadays,
4462 this really only frees the obstack used for these decls.
4463 That's why it had to be moved down here. */
4465 pop_class_decls (current_class_type
);
4467 current_class_depth
--;
4468 current_class_type
= *--current_class_stack
;
4469 current_class_name
= *--current_class_stack
;
4471 if (current_class_type
)
4473 if (CLASSTYPE_VTBL_PTR (current_class_type
))
4475 current_vtable_decl
= lookup_name (DECL_NAME (CLASSTYPE_VTBL_PTR (current_class_type
)), 0);
4476 if (current_vtable_decl
)
4477 current_vtable_decl
= build_indirect_ref (current_vtable_decl
,
4480 current_class_decl
= lookup_name (this_identifier
, 0);
4481 if (current_class_decl
)
4483 if (TREE_CODE (TREE_TYPE (current_class_decl
)) == POINTER_TYPE
)
4486 /* Can't call build_indirect_ref here, because it has special
4487 logic to return C_C_D given this argument. */
4488 C_C_D
= build1 (INDIRECT_REF
, current_class_type
, current_class_decl
);
4489 temp
= TREE_TYPE (TREE_TYPE (current_class_decl
));
4490 TREE_READONLY (C_C_D
) = TYPE_READONLY (temp
);
4491 TREE_SIDE_EFFECTS (C_C_D
) = TYPE_VOLATILE (temp
);
4492 TREE_THIS_VOLATILE (C_C_D
) = TYPE_VOLATILE (temp
);
4495 C_C_D
= current_class_decl
;
4502 current_class_decl
= NULL_TREE
;
4503 current_vtable_decl
= NULL_TREE
;
4507 pop_memoized_context (modify
);
4513 /* When entering a class scope, all enclosing class scopes' names with
4514 static meaning (static variables, static functions, types and enumerators)
4515 have to be visible. This recursive function calls pushclass for all
4516 enclosing class contexts until global or a local scope is reached.
4517 TYPE is the enclosed class and MODIFY is equivalent with the pushclass
4518 formal of the same name. */
4521 push_nested_class (type
, modify
)
4525 tree context
= DECL_CONTEXT (TYPE_NAME (type
));
4527 if (context
&& TREE_CODE (context
) == RECORD_TYPE
)
4528 push_nested_class (context
, 2);
4529 pushclass (type
, modify
);
4532 /* Undoes a push_nested_class call. MODIFY is passed on to popclass. */
4535 pop_nested_class (modify
)
4538 tree context
= DECL_CONTEXT (TYPE_NAME (current_class_type
));
4541 if (context
&& TREE_CODE (context
) == RECORD_TYPE
)
4542 pop_nested_class (modify
);
4545 /* Set global variables CURRENT_LANG_NAME to appropriate value
4546 so that behavior of name-mangling machinery is correct. */
4549 push_lang_context (name
)
4552 *current_lang_stack
++ = current_lang_name
;
4553 if (current_lang_stack
>= current_lang_base
+ current_lang_stacksize
)
4556 (tree
*)xrealloc (current_lang_base
,
4557 sizeof (tree
) * (current_lang_stacksize
+ 10));
4558 current_lang_stack
= current_lang_base
+ current_lang_stacksize
;
4559 current_lang_stacksize
+= 10;
4562 if (name
== lang_name_cplusplus
)
4564 strict_prototype
= strict_prototypes_lang_cplusplus
;
4565 current_lang_name
= name
;
4567 else if (name
== lang_name_c
)
4569 strict_prototype
= strict_prototypes_lang_c
;
4570 current_lang_name
= name
;
4573 error ("language string `\"%s\"' not recognized", IDENTIFIER_POINTER (name
));
4576 cadillac_push_lang (name
);
4579 /* Get out of the current language scope. */
4584 cadillac_pop_lang ();
4586 current_lang_name
= *--current_lang_stack
;
4587 if (current_lang_name
== lang_name_cplusplus
)
4588 strict_prototype
= strict_prototypes_lang_cplusplus
;
4589 else if (current_lang_name
== lang_name_c
)
4590 strict_prototype
= strict_prototypes_lang_c
;
4594 root_lang_context_p ()
4596 return current_lang_stack
== current_lang_base
;
4599 /* Type instantiation routines. */
4601 /* This function will instantiate the type of the expression given
4602 in RHS to match the type of LHSTYPE. If LHSTYPE is NULL_TREE,
4603 or other errors exist, the TREE_TYPE of RHS will be ERROR_MARK_NODE.
4605 This function is used in build_modify_expr, convert_arguments,
4606 build_c_cast, and compute_conversion_costs. */
4608 instantiate_type (lhstype
, rhs
, complain
)
4612 if (TREE_CODE (lhstype
) == UNKNOWN_TYPE
)
4615 error ("not enough type information");
4616 return error_mark_node
;
4619 if (TREE_TYPE (rhs
) != NULL_TREE
&& ! (type_unknown_p (rhs
)))
4622 /* This should really only be used when attempting to distinguish
4623 what sort of a pointer to function we have. For now, any
4624 arithmetic operation which is not supported on pointers
4625 is rejected as an error. */
4627 switch (TREE_CODE (rhs
))
4634 my_friendly_abort (177);
4635 return error_mark_node
;
4639 TREE_TYPE (rhs
) = lhstype
;
4640 lhstype
= build_pointer_type (lhstype
);
4641 TREE_OPERAND (rhs
, 0)
4642 = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 0), complain
);
4643 if (TREE_OPERAND (rhs
, 0) == error_mark_node
)
4644 return error_mark_node
;
4649 rhs
= copy_node (TREE_OPERAND (rhs
, 0));
4650 TREE_TYPE (rhs
) = unknown_type_node
;
4651 return instantiate_type (lhstype
, rhs
, complain
);
4655 tree field
= TREE_OPERAND (rhs
, 1);
4656 if (TREE_CODE (field
) == TREE_LIST
)
4658 tree function
= instantiate_type (lhstype
, field
, complain
);
4659 if (function
== error_mark_node
)
4660 return error_mark_node
;
4661 my_friendly_assert (TREE_CODE (function
) == FUNCTION_DECL
, 185);
4662 if (DECL_VINDEX (function
))
4664 tree base
= TREE_OPERAND (rhs
, 0);
4665 tree base_ptr
= build_unary_op (ADDR_EXPR
, base
, 0);
4666 if (base_ptr
== error_mark_node
)
4667 return error_mark_node
;
4668 base_ptr
= convert_pointer_to (DECL_CONTEXT (function
), base_ptr
);
4669 if (base_ptr
== error_mark_node
)
4670 return error_mark_node
;
4671 return build_vfn_ref (&base_ptr
, base
, DECL_VINDEX (function
));
4676 my_friendly_assert (TREE_CODE (field
) == FIELD_DECL
, 178);
4677 my_friendly_assert (!(TREE_CODE (TREE_TYPE (field
)) == FUNCTION_TYPE
4678 || TREE_CODE (TREE_TYPE (field
)) == METHOD_TYPE
),
4681 TREE_TYPE (rhs
) = lhstype
;
4682 /* First look for an exact match */
4684 while (field
&& TREE_TYPE (field
) != lhstype
)
4685 field
= TREE_CHAIN (field
);
4688 TREE_OPERAND (rhs
, 1) = field
;
4692 /* No exact match found, look for a compatible function. */
4693 field
= TREE_OPERAND (rhs
, 1);
4694 while (field
&& ! comptypes (lhstype
, TREE_TYPE (field
), 0))
4695 field
= TREE_CHAIN (field
);
4698 TREE_OPERAND (rhs
, 1) = field
;
4699 field
= TREE_CHAIN (field
);
4700 while (field
&& ! comptypes (lhstype
, TREE_TYPE (field
), 0))
4701 field
= TREE_CHAIN (field
);
4705 error ("ambiguous overload for COMPONENT_REF requested");
4706 return error_mark_node
;
4712 error ("no appropriate overload exists for COMPONENT_REF");
4713 return error_mark_node
;
4720 tree elem
, baselink
, name
;
4721 int globals
= overloaded_globals_p (rhs
);
4723 #if 0 /* obsolete */
4724 /* If there's only one function we know about, return that. */
4725 if (globals
> 0 && TREE_CHAIN (rhs
) == NULL_TREE
)
4726 return TREE_VALUE (rhs
);
4729 /* First look for an exact match. Search either overloaded
4730 functions or member functions. May have to undo what
4731 `default_conversion' might do to lhstype. */
4733 if (TREE_CODE (lhstype
) == POINTER_TYPE
)
4734 if (TREE_CODE (TREE_TYPE (lhstype
)) == FUNCTION_TYPE
4735 || TREE_CODE (TREE_TYPE (lhstype
)) == METHOD_TYPE
)
4736 lhstype
= TREE_TYPE (lhstype
);
4740 error ("invalid type combination for overload");
4741 return error_mark_node
;
4744 if (TREE_CODE (lhstype
) != FUNCTION_TYPE
&& globals
> 0)
4747 cp_error ("cannot resolve overloaded function `%D' based on non-function type",
4748 TREE_PURPOSE (rhs
));
4749 return error_mark_node
;
4754 elem
= get_first_fn (rhs
);
4756 if (TREE_TYPE (elem
) != lhstype
)
4757 elem
= DECL_CHAIN (elem
);
4760 /* No exact match found, look for a compatible function. */
4761 elem
= get_first_fn (rhs
);
4762 while (elem
&& ! comp_target_types (lhstype
, TREE_TYPE (elem
), 1))
4763 elem
= DECL_CHAIN (elem
);
4766 tree save_elem
= elem
;
4767 elem
= DECL_CHAIN (elem
);
4768 while (elem
&& ! comp_target_types (lhstype
, TREE_TYPE (elem
),
4770 elem
= DECL_CHAIN (elem
);
4775 cp_error ("cannot resolve overload to target type `%#T';", lhstype
);
4776 cp_error_at ("ambiguity between `%#D'", save_elem
);
4777 cp_error_at ("and `%#D', at least", elem
);
4779 return error_mark_node
;
4781 if (TREE_CODE (save_elem
) == TEMPLATE_DECL
)
4783 int ntparms
= TREE_VEC_LENGTH
4784 (DECL_TEMPLATE_PARMS (save_elem
));
4785 tree
*targs
= (tree
*) alloca (sizeof (tree
) * ntparms
);
4787 i
= type_unification
4788 (DECL_TEMPLATE_PARMS (save_elem
), targs
,
4789 TYPE_ARG_TYPES (TREE_TYPE (save_elem
)),
4790 TYPE_ARG_TYPES (lhstype
), &dummy
, 0);
4791 save_elem
= instantiate_template (save_elem
, targs
);
4797 cp_error ("cannot resolve overload to target type `%#T';",
4799 cp_error ("no suitable overload of function `%D' exists",
4800 TREE_PURPOSE (rhs
));
4802 return error_mark_node
;
4805 if (TREE_NONLOCAL_FLAG (rhs
))
4807 /* Got to get it as a baselink. */
4808 rhs
= lookup_fnfields (TYPE_BINFO (current_class_type
),
4809 TREE_PURPOSE (rhs
), 0);
4813 my_friendly_assert (TREE_CHAIN (rhs
) == NULL_TREE
, 181);
4814 if (TREE_CODE (TREE_VALUE (rhs
)) == TREE_LIST
)
4815 rhs
= TREE_VALUE (rhs
);
4816 my_friendly_assert (TREE_CODE (TREE_VALUE (rhs
)) == FUNCTION_DECL
,
4820 for (baselink
= rhs
; baselink
;
4821 baselink
= next_baselink (baselink
))
4823 elem
= TREE_VALUE (baselink
);
4825 if (TREE_TYPE (elem
) != lhstype
)
4826 elem
= TREE_CHAIN (elem
);
4831 /* No exact match found, look for a compatible method. */
4832 for (baselink
= rhs
; baselink
;
4833 baselink
= next_baselink (baselink
))
4835 elem
= TREE_VALUE (baselink
);
4836 while (elem
&& ! comp_target_types (lhstype
, TREE_TYPE (elem
), 1))
4837 elem
= TREE_CHAIN (elem
);
4840 tree save_elem
= elem
;
4841 elem
= TREE_CHAIN (elem
);
4842 while (elem
&& ! comp_target_types (lhstype
, TREE_TYPE (elem
), 0))
4843 elem
= TREE_CHAIN (elem
);
4847 error ("ambiguous overload for overloaded method requested");
4848 return error_mark_node
;
4852 name
= DECL_NAME (TREE_VALUE (rhs
));
4853 if (TREE_CODE (lhstype
) == FUNCTION_TYPE
&& globals
< 0)
4855 /* Try to instantiate from non-member functions. */
4856 rhs
= IDENTIFIER_GLOBAL_VALUE (name
);
4857 if (rhs
&& TREE_CODE (rhs
) == TREE_LIST
)
4859 /* This code seems to be missing a `return'. */
4860 my_friendly_abort (4);
4861 instantiate_type (lhstype
, rhs
, complain
);
4866 error ("no static member functions named `%s'",
4867 IDENTIFIER_POINTER (name
));
4868 return error_mark_node
;
4872 /* This is too hard for now. */
4873 my_friendly_abort (183);
4874 return error_mark_node
;
4879 TREE_OPERAND (rhs
, 0) = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 0), complain
);
4880 if (TREE_OPERAND (rhs
, 0) == error_mark_node
)
4881 return error_mark_node
;
4882 TREE_OPERAND (rhs
, 1) = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), complain
);
4883 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
4884 return error_mark_node
;
4886 TREE_TYPE (rhs
) = lhstype
;
4890 case TRUNC_DIV_EXPR
:
4891 case FLOOR_DIV_EXPR
:
4893 case ROUND_DIV_EXPR
:
4895 case TRUNC_MOD_EXPR
:
4896 case FLOOR_MOD_EXPR
:
4898 case ROUND_MOD_EXPR
:
4899 case FIX_ROUND_EXPR
:
4900 case FIX_FLOOR_EXPR
:
4902 case FIX_TRUNC_EXPR
:
4918 case PREINCREMENT_EXPR
:
4919 case PREDECREMENT_EXPR
:
4920 case POSTINCREMENT_EXPR
:
4921 case POSTDECREMENT_EXPR
:
4923 error ("illegal operation on uninstantiated type");
4924 return error_mark_node
;
4926 case TRUTH_AND_EXPR
:
4928 case TRUTH_XOR_EXPR
:
4935 case TRUTH_ANDIF_EXPR
:
4936 case TRUTH_ORIF_EXPR
:
4937 case TRUTH_NOT_EXPR
:
4939 error ("not enough type information");
4940 return error_mark_node
;
4943 if (type_unknown_p (TREE_OPERAND (rhs
, 0)))
4946 error ("not enough type information");
4947 return error_mark_node
;
4949 TREE_OPERAND (rhs
, 1) = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), complain
);
4950 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
4951 return error_mark_node
;
4952 TREE_OPERAND (rhs
, 2) = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 2), complain
);
4953 if (TREE_OPERAND (rhs
, 2) == error_mark_node
)
4954 return error_mark_node
;
4956 TREE_TYPE (rhs
) = lhstype
;
4960 TREE_OPERAND (rhs
, 1) = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 1), complain
);
4961 if (TREE_OPERAND (rhs
, 1) == error_mark_node
)
4962 return error_mark_node
;
4964 TREE_TYPE (rhs
) = lhstype
;
4968 if (TREE_CODE (lhstype
) != POINTER_TYPE
)
4971 error ("type for resolving address of overloaded function must be pointer type");
4972 return error_mark_node
;
4974 TREE_TYPE (rhs
) = lhstype
;
4975 lhstype
= TREE_TYPE (lhstype
);
4976 TREE_OPERAND (rhs
, 0) = instantiate_type (lhstype
, TREE_OPERAND (rhs
, 0), complain
);
4977 if (TREE_OPERAND (rhs
, 0) == error_mark_node
)
4978 return error_mark_node
;
4980 mark_addressable (TREE_OPERAND (rhs
, 0));
4983 case ENTRY_VALUE_EXPR
:
4984 my_friendly_abort (184);
4985 return error_mark_node
;
4988 return error_mark_node
;
4991 my_friendly_abort (185);
4992 return error_mark_node
;
4996 /* Return the name of the virtual function pointer field
4997 (as an IDENTIFIER_NODE) for the given TYPE. Note that
4998 this may have to look back through base types to find the
4999 ultimate field name. (For single inheritance, these could
5000 all be the same name. Who knows for multiple inheritance). */
5002 get_vfield_name (type
)
5005 tree binfo
= TYPE_BINFO (type
);
5008 while (BINFO_BASETYPES (binfo
)
5009 && TYPE_VIRTUAL_P (BINFO_TYPE (BINFO_BASETYPE (binfo
, 0)))
5010 && ! TREE_VIA_VIRTUAL (BINFO_BASETYPE (binfo
, 0)))
5011 binfo
= BINFO_BASETYPE (binfo
, 0);
5013 type
= BINFO_TYPE (binfo
);
5014 buf
= (char *)alloca (sizeof (VFIELD_NAME_FORMAT
)
5015 + TYPE_NAME_LENGTH (type
) + 2);
5016 sprintf (buf
, VFIELD_NAME_FORMAT
, TYPE_NAME_STRING (type
));
5017 return get_identifier (buf
);
5021 print_class_statistics ()
5023 #ifdef GATHER_STATISTICS
5024 fprintf (stderr
, "convert_harshness = %d\n", n_convert_harshness
);
5025 fprintf (stderr
, "compute_conversion_costs = %d\n", n_compute_conversion_costs
);
5026 fprintf (stderr
, "build_method_call = %d (inner = %d)\n",
5027 n_build_method_call
, n_inner_fields_searched
);
5030 fprintf (stderr
, "vtables = %d; vtable searches = %d\n",
5031 n_vtables
, n_vtable_searches
);
5032 fprintf (stderr
, "vtable entries = %d; vtable elems = %d\n",
5033 n_vtable_entries
, n_vtable_elems
);
5038 /* Push an obstack which is sufficiently long-lived to hold such class
5039 decls that may be cached in the previous_class_values list. For now, let's
5040 use the permanent obstack, later we may create a dedicated obstack just
5041 for this purpose. The effect is undone by pop_obstacks. */
5043 maybe_push_cache_obstack ()
5045 push_obstacks_nochange ();
5046 if (current_class_depth
== 1)
5047 current_obstack
= &permanent_obstack
;