Commit d2c5305b by Mark Mitchell Committed by Mark Mitchell

class.c (struct base_info): Remove.

	* class.c (struct base_info): Remove.
	(determine_primary_base): Take has_virtual_p rather than a
	base_info as input.  Don't calculate max_has_virtual.
	(finish_struct_bits): Remove max_has_virtual argument.
	(create_vtable_ptr): Remove max_has_virtual_p argument.
	(layout_virtual_bases): Remove max argument.
	(layout_basetypes): Likewise.
	(layout_class_type): Remove max_has_virtual_p argument.
	(finish_struct_1): Remove max_has_virtual.

From-SVN: r31174
parent a71811fe
2000-01-02 Mark Mitchell <mark@codesourcery.com> 2000-01-02 Mark Mitchell <mark@codesourcery.com>
* class.c (struct base_info): Remove.
(determine_primary_base): Take has_virtual_p rather than a
base_info as input. Don't calculate max_has_virtual.
(finish_struct_bits): Remove max_has_virtual argument.
(create_vtable_ptr): Remove max_has_virtual_p argument.
(layout_virtual_bases): Remove max argument.
(layout_basetypes): Likewise.
(layout_class_type): Remove max_has_virtual_p argument.
(finish_struct_1): Remove max_has_virtual.
* cp-tree.h (dfs_mark_primary_bases_queue_p): New function. * cp-tree.h (dfs_mark_primary_bases_queue_p): New function.
(layout_basetypes): Remove. (layout_basetypes): Remove.
* class.c (propagate_binfo_offsets): Moved here from tree.c. * class.c (propagate_binfo_offsets): Moved here from tree.c.
......
/* Functions related to building classes and their related objects. /* Functions related to building classes and their related objects.
Copyright (C) 1987, 92-97, 1998, 1999 Free Software Foundation, Inc. Copyright (C) 1987, 92-97, 1998, 1999, 2000 Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com) Contributed by Michael Tiemann (tiemann@cygnus.com)
This file is part of GNU CC. This file is part of GNU CC.
...@@ -72,8 +72,6 @@ typedef struct class_stack_node { ...@@ -72,8 +72,6 @@ typedef struct class_stack_node {
static int current_class_stack_size; static int current_class_stack_size;
static class_stack_node_t current_class_stack; static class_stack_node_t current_class_stack;
struct base_info;
static tree get_vfield_name PROTO((tree)); static tree get_vfield_name PROTO((tree));
static void finish_struct_anon PROTO((tree)); static void finish_struct_anon PROTO((tree));
static tree build_vbase_pointer PROTO((tree, tree)); static tree build_vbase_pointer PROTO((tree, tree));
...@@ -92,7 +90,7 @@ static tree get_vtable_entry_n PROTO((tree, unsigned HOST_WIDE_INT)); ...@@ -92,7 +90,7 @@ static tree get_vtable_entry_n PROTO((tree, unsigned HOST_WIDE_INT));
static void add_virtual_function PROTO((tree *, tree *, int *, tree, tree)); static void add_virtual_function PROTO((tree *, tree *, int *, tree, tree));
static tree delete_duplicate_fields_1 PROTO((tree, tree)); static tree delete_duplicate_fields_1 PROTO((tree, tree));
static void delete_duplicate_fields PROTO((tree)); static void delete_duplicate_fields PROTO((tree));
static void finish_struct_bits PROTO((tree, int)); static void finish_struct_bits PROTO((tree));
static int alter_access PROTO((tree, tree, tree, tree)); static int alter_access PROTO((tree, tree, tree, tree));
static void handle_using_decl PROTO((tree, tree)); static void handle_using_decl PROTO((tree, tree));
static int overrides PROTO((tree, tree)); static int overrides PROTO((tree, tree));
...@@ -107,7 +105,7 @@ static void modify_one_vtable PROTO((tree, tree, tree)); ...@@ -107,7 +105,7 @@ static void modify_one_vtable PROTO((tree, tree, tree));
static void modify_all_vtables PROTO((tree, tree)); static void modify_all_vtables PROTO((tree, tree));
static void modify_all_direct_vtables PROTO((tree, int, tree, tree)); static void modify_all_direct_vtables PROTO((tree, int, tree, tree));
static void modify_all_indirect_vtables PROTO((tree, int, int, tree, tree)); static void modify_all_indirect_vtables PROTO((tree, int, int, tree, tree));
static void determine_primary_base PROTO((tree, struct base_info *)); static void determine_primary_base PROTO((tree, int *));
static void finish_struct_methods PROTO((tree)); static void finish_struct_methods PROTO((tree));
static void maybe_warn_about_overly_private_class PROTO ((tree)); static void maybe_warn_about_overly_private_class PROTO ((tree));
static int field_decl_cmp PROTO ((const tree *, const tree *)); static int field_decl_cmp PROTO ((const tree *, const tree *));
...@@ -133,15 +131,15 @@ static void check_methods PROTO((tree)); ...@@ -133,15 +131,15 @@ static void check_methods PROTO((tree));
static void remove_zero_width_bit_fields PROTO((tree)); static void remove_zero_width_bit_fields PROTO((tree));
static void check_bases PROTO((tree, int *, int *, int *)); static void check_bases PROTO((tree, int *, int *, int *));
static void check_bases_and_members PROTO((tree, int *)); static void check_bases_and_members PROTO((tree, int *));
static void create_vtable_ptr PROTO((tree, int *, int *, int *, tree *, tree *)); static void create_vtable_ptr PROTO((tree, int *, int *, tree *, tree *));
static void layout_class_type PROTO((tree, int *, int *, int *, tree *, tree *)); static void layout_class_type PROTO((tree, int *, int *, tree *, tree *));
static void fixup_pending_inline PROTO((struct pending_inline *)); static void fixup_pending_inline PROTO((struct pending_inline *));
static void fixup_inline_methods PROTO((tree)); static void fixup_inline_methods PROTO((tree));
static void set_primary_base PROTO((tree, int, int *)); static void set_primary_base PROTO((tree, int, int *));
static void propagate_binfo_offsets PROTO((tree, tree)); static void propagate_binfo_offsets PROTO((tree, tree));
static int layout_basetypes PROTO((tree, int)); static void layout_basetypes PROTO((tree));
static tree dfs_mark_primary_bases_and_set_vbase_offsets PROTO((tree, void *)); static tree dfs_mark_primary_bases_and_set_vbase_offsets PROTO((tree, void *));
static int layout_virtual_bases PROTO((tree, int)); static void layout_virtual_bases PROTO((tree));
static void remove_base_fields PROTO((tree)); static void remove_base_fields PROTO((tree));
/* Variables shared between class.c and call.c. */ /* Variables shared between class.c and call.c. */
...@@ -1501,12 +1499,6 @@ handle_using_decl (using_decl, t) ...@@ -1501,12 +1499,6 @@ handle_using_decl (using_decl, t)
alter_access (t, binfo, fdecl, access); alter_access (t, binfo, fdecl, access);
} }
struct base_info
{
int has_virtual;
int max_has_virtual;
};
/* Run through the base clases of T, updating /* Run through the base clases of T, updating
CANT_HAVE_DEFAULT_CTOR_P, CANT_HAVE_CONST_CTOR_P, and CANT_HAVE_DEFAULT_CTOR_P, CANT_HAVE_CONST_CTOR_P, and
NO_CONST_ASN_REF_P. Also set flag bits in T based on properties of NO_CONST_ASN_REF_P. Also set flag bits in T based on properties of
...@@ -1653,12 +1645,13 @@ set_primary_base (t, i, has_virtual_p) ...@@ -1653,12 +1645,13 @@ set_primary_base (t, i, has_virtual_p)
/* Determine the primary class for T. */ /* Determine the primary class for T. */
static void static void
determine_primary_base (t, b) determine_primary_base (t, has_virtual_p)
tree t; tree t;
struct base_info *b; int *has_virtual_p;
{ {
int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t); int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
bzero ((char *) b, sizeof (struct base_info));
*has_virtual_p = 0;
for (i = 0; i < n_baseclasses; i++) for (i = 0; i < n_baseclasses; i++)
{ {
...@@ -1679,7 +1672,7 @@ determine_primary_base (t, b) ...@@ -1679,7 +1672,7 @@ determine_primary_base (t, b)
if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t)) if (!CLASSTYPE_HAS_PRIMARY_BASE_P (t))
{ {
set_primary_base (t, i, &b->has_virtual); set_primary_base (t, i, has_virtual_p);
CLASSTYPE_VFIELDS (t) = copy_list (CLASSTYPE_VFIELDS (basetype)); CLASSTYPE_VFIELDS (t) = copy_list (CLASSTYPE_VFIELDS (basetype));
} }
else else
...@@ -1697,38 +1690,22 @@ determine_primary_base (t, b) ...@@ -1697,38 +1690,22 @@ determine_primary_base (t, b)
VF_BASETYPE_VALUE (vfields), VF_BASETYPE_VALUE (vfields),
CLASSTYPE_VFIELDS (t)); CLASSTYPE_VFIELDS (t));
if (b->has_virtual == 0) if (*has_virtual_p == 0)
set_primary_base (t, i, &b->has_virtual); set_primary_base (t, i, has_virtual_p);
} }
} }
} }
if (!TYPE_VFIELD (t)) if (!TYPE_VFIELD (t))
CLASSTYPE_VFIELD_PARENT (t) = -1; CLASSTYPE_VFIELD_PARENT (t) = -1;
{
tree vfields;
/* Find the base class with the largest number of virtual functions. */
for (vfields = CLASSTYPE_VFIELDS (t);
vfields;
vfields = TREE_CHAIN (vfields))
{
if (CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields)) > b->max_has_virtual)
b->max_has_virtual = CLASSTYPE_VSIZE (VF_BASETYPE_VALUE (vfields));
if (VF_DERIVED_VALUE (vfields)
&& CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields)) > b->max_has_virtual)
b->max_has_virtual = CLASSTYPE_VSIZE (VF_DERIVED_VALUE (vfields));
}
}
} }
/* Set memoizing fields and bits of T (and its variants) for later use. /* Set memoizing fields and bits of T (and its variants) for later
MAX_HAS_VIRTUAL is the largest size of any T's virtual function tables. */ use. */
static void static void
finish_struct_bits (t, max_has_virtual) finish_struct_bits (t)
tree t; tree t;
int max_has_virtual;
{ {
int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t); int i, n_baseclasses = CLASSTYPE_N_BASECLASSES (t);
...@@ -1756,7 +1733,7 @@ finish_struct_bits (t, max_has_virtual) ...@@ -1756,7 +1733,7 @@ finish_struct_bits (t, max_has_virtual)
variants = TYPE_NEXT_VARIANT (variants); variants = TYPE_NEXT_VARIANT (variants);
} }
if (n_baseclasses && max_has_virtual) if (n_baseclasses && TYPE_POLYMORPHIC_P (t))
/* For a class w/o baseclasses, `finish_struct' has set /* For a class w/o baseclasses, `finish_struct' has set
CLASS_TYPE_ABSTRACT_VIRTUALS correctly (by CLASS_TYPE_ABSTRACT_VIRTUALS correctly (by
definition). Similarly for a class whose base classes do not definition). Similarly for a class whose base classes do not
...@@ -4011,12 +3988,11 @@ check_bases_and_members (t, empty_p) ...@@ -4011,12 +3988,11 @@ check_bases_and_members (t, empty_p)
TYPE_FIELDS list. */ TYPE_FIELDS list. */
static void static void
create_vtable_ptr (t, empty_p, has_virtual_p, max_has_virtual_p, create_vtable_ptr (t, empty_p, has_virtual_p,
pending_virtuals_p, pending_hard_virtuals_p) pending_virtuals_p, pending_hard_virtuals_p)
tree t; tree t;
int *empty_p; int *empty_p;
int *has_virtual_p; int *has_virtual_p;
int *max_has_virtual_p;
tree *pending_virtuals_p; tree *pending_virtuals_p;
tree *pending_hard_virtuals_p; tree *pending_hard_virtuals_p;
{ {
...@@ -4025,14 +4001,8 @@ create_vtable_ptr (t, empty_p, has_virtual_p, max_has_virtual_p, ...@@ -4025,14 +4001,8 @@ create_vtable_ptr (t, empty_p, has_virtual_p, max_has_virtual_p,
/* If possible, we reuse the virtual function table pointer from one /* If possible, we reuse the virtual function table pointer from one
of our base classes. */ of our base classes. */
if (CLASSTYPE_N_BASECLASSES (t)) if (CLASSTYPE_N_BASECLASSES (t))
{ /* Remember where we got our vfield from. */
struct base_info base_info; determine_primary_base (t, has_virtual_p);
/* Remember where we got our vfield from. */
determine_primary_base (t, &base_info);
*has_virtual_p = base_info.has_virtual;
*max_has_virtual_p = base_info.max_has_virtual;
}
/* Loop over the virtual functions, adding them to our various /* Loop over the virtual functions, adding them to our various
vtables. */ vtables. */
...@@ -4333,13 +4303,11 @@ dfs_mark_primary_bases_and_set_vbase_offsets (binfo, data) ...@@ -4333,13 +4303,11 @@ dfs_mark_primary_bases_and_set_vbase_offsets (binfo, data)
} }
/* Set BINFO_OFFSET for all of the virtual bases for T. Update /* Set BINFO_OFFSET for all of the virtual bases for T. Update
TYPE_ALIGN and TYPE_SIZE for T. Return the maximum of MAX and the TYPE_ALIGN and TYPE_SIZE for T. */
largest CLASSTYPE_VSIZE for any of the virtual bases. */
static int static void
layout_virtual_bases (t, max) layout_virtual_bases (t)
tree t; tree t;
int max;
{ {
tree vbase; tree vbase;
int dsize; int dsize;
...@@ -4390,10 +4358,6 @@ layout_virtual_bases (t, max) ...@@ -4390,10 +4358,6 @@ layout_virtual_bases (t, max)
dfs_mark_primary_bases_and_set_vbase_offsets, dfs_mark_primary_bases_and_set_vbase_offsets,
dfs_mark_primary_bases_queue_p, dfs_mark_primary_bases_queue_p,
t); t);
/* While we're here, see if this new virtual base class has
more virtual functions than we expected. */
max = MAX (CLASSTYPE_VSIZE (basetype), max);
} }
/* We're done with the various marks, now, so clear them. */ /* We're done with the various marks, now, so clear them. */
...@@ -4406,22 +4370,16 @@ layout_virtual_bases (t, max) ...@@ -4406,22 +4370,16 @@ layout_virtual_bases (t, max)
TYPE_SIZE (t) = size_int (dsize); TYPE_SIZE (t) = size_int (dsize);
TYPE_SIZE_UNIT (t) = size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (t), TYPE_SIZE_UNIT (t) = size_binop (FLOOR_DIV_EXPR, TYPE_SIZE (t),
size_int (BITS_PER_UNIT)); size_int (BITS_PER_UNIT));
return max;
} }
/* Finish the work of layout_record, now taking virtual bases into account. /* Finish the work of layout_record, now taking virtual bases into account.
Also compute the actual offsets that our base classes will have. Also compute the actual offsets that our base classes will have.
This must be performed after the fields are laid out, since virtual This must be performed after the fields are laid out, since virtual
baseclasses must lay down at the end of the record. baseclasses must lay down at the end of the record. */
Returns the maximum number of virtual functions any of the static void
baseclasses provide. */ layout_basetypes (rec)
static int
layout_basetypes (rec, max)
tree rec; tree rec;
int max;
{ {
tree vbase_types; tree vbase_types;
...@@ -4437,7 +4395,7 @@ layout_basetypes (rec, max) ...@@ -4437,7 +4395,7 @@ layout_basetypes (rec, max)
remove_base_fields (rec); remove_base_fields (rec);
/* Allocate the virtual base classes. */ /* Allocate the virtual base classes. */
max = layout_virtual_bases (rec, max); layout_virtual_bases (rec);
/* Get all the virtual base types that this type uses. The /* Get all the virtual base types that this type uses. The
TREE_VALUE slot holds the virtual baseclass type. Note that TREE_VALUE slot holds the virtual baseclass type. Note that
...@@ -4458,8 +4416,6 @@ layout_basetypes (rec, max) ...@@ -4458,8 +4416,6 @@ layout_basetypes (rec, max)
basetype, rec); basetype, rec);
} }
} }
return max;
} }
/* Calculate the TYPE_SIZE, TYPE_ALIGN, etc for T. Calculate /* Calculate the TYPE_SIZE, TYPE_ALIGN, etc for T. Calculate
...@@ -4467,12 +4423,11 @@ layout_basetypes (rec, max) ...@@ -4467,12 +4423,11 @@ layout_basetypes (rec, max)
pointer. */ pointer. */
static void static void
layout_class_type (t, empty_p, has_virtual_p, max_has_virtual_p, layout_class_type (t, empty_p, has_virtual_p,
pending_virtuals_p, pending_hard_virtuals_p) pending_virtuals_p, pending_hard_virtuals_p)
tree t; tree t;
int *empty_p; int *empty_p;
int *has_virtual_p; int *has_virtual_p;
int *max_has_virtual_p;
tree *pending_virtuals_p; tree *pending_virtuals_p;
tree *pending_hard_virtuals_p; tree *pending_hard_virtuals_p;
{ {
...@@ -4484,7 +4439,7 @@ layout_class_type (t, empty_p, has_virtual_p, max_has_virtual_p, ...@@ -4484,7 +4439,7 @@ layout_class_type (t, empty_p, has_virtual_p, max_has_virtual_p,
TYPE_FIELDS (t)); TYPE_FIELDS (t));
/* Create a pointer to our virtual function table. */ /* Create a pointer to our virtual function table. */
create_vtable_ptr (t, empty_p, has_virtual_p, max_has_virtual_p, create_vtable_ptr (t, empty_p, has_virtual_p,
pending_virtuals_p, pending_hard_virtuals_p); pending_virtuals_p, pending_hard_virtuals_p);
/* CLASSTYPE_INLINE_FRIENDS is really TYPE_NONCOPIED_PARTS. Thus, /* CLASSTYPE_INLINE_FRIENDS is really TYPE_NONCOPIED_PARTS. Thus,
...@@ -4545,7 +4500,7 @@ layout_class_type (t, empty_p, has_virtual_p, max_has_virtual_p, ...@@ -4545,7 +4500,7 @@ layout_class_type (t, empty_p, has_virtual_p, max_has_virtual_p,
virtual function table. */ virtual function table. */
if (CLASSTYPE_N_BASECLASSES (t)) if (CLASSTYPE_N_BASECLASSES (t))
/* layout_basetypes will remove the base subobject fields. */ /* layout_basetypes will remove the base subobject fields. */
*max_has_virtual_p = layout_basetypes (t, *max_has_virtual_p); layout_basetypes (t);
} }
/* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration /* Create a RECORD_TYPE or UNION_TYPE node for a C struct or union declaration
...@@ -4581,7 +4536,6 @@ finish_struct_1 (t) ...@@ -4581,7 +4536,6 @@ finish_struct_1 (t)
{ {
tree x; tree x;
int has_virtual; int has_virtual;
int max_has_virtual;
tree pending_virtuals = NULL_TREE; tree pending_virtuals = NULL_TREE;
tree pending_hard_virtuals = NULL_TREE; tree pending_hard_virtuals = NULL_TREE;
int n_fields = 0; int n_fields = 0;
...@@ -4607,7 +4561,6 @@ finish_struct_1 (t) ...@@ -4607,7 +4561,6 @@ finish_struct_1 (t)
CLASSTYPE_GOT_SEMICOLON (t) = 0; CLASSTYPE_GOT_SEMICOLON (t) = 0;
CLASSTYPE_VFIELD_PARENT (t) = -1; CLASSTYPE_VFIELD_PARENT (t) = -1;
has_virtual = 0; has_virtual = 0;
max_has_virtual = 0;
CLASSTYPE_RTTI (t) = NULL_TREE; CLASSTYPE_RTTI (t) = NULL_TREE;
/* Do end-of-class semantic processing: checking the validity of the /* Do end-of-class semantic processing: checking the validity of the
...@@ -4615,7 +4568,7 @@ finish_struct_1 (t) ...@@ -4615,7 +4568,7 @@ finish_struct_1 (t)
check_bases_and_members (t, &empty); check_bases_and_members (t, &empty);
/* Layout the class itself. */ /* Layout the class itself. */
layout_class_type (t, &empty, &has_virtual, &max_has_virtual, layout_class_type (t, &empty, &has_virtual,
&pending_virtuals, &pending_hard_virtuals); &pending_virtuals, &pending_hard_virtuals);
if (TYPE_USES_VIRTUAL_BASECLASSES (t)) if (TYPE_USES_VIRTUAL_BASECLASSES (t))
...@@ -4670,11 +4623,6 @@ finish_struct_1 (t) ...@@ -4670,11 +4623,6 @@ finish_struct_1 (t)
TYPE_VFIELD (t) = vfield; TYPE_VFIELD (t) = vfield;
} }
if (has_virtual > max_has_virtual)
max_has_virtual = has_virtual;
if (max_has_virtual > 0)
TYPE_POLYMORPHIC_P (t) = 1;
if (flag_rtti && TYPE_POLYMORPHIC_P (t) && !pending_hard_virtuals) if (flag_rtti && TYPE_POLYMORPHIC_P (t) && !pending_hard_virtuals)
modify_all_vtables (t, NULL_TREE); modify_all_vtables (t, NULL_TREE);
...@@ -4756,7 +4704,7 @@ finish_struct_1 (t) ...@@ -4756,7 +4704,7 @@ finish_struct_1 (t)
CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1; CLASSTYPE_NEEDS_VIRTUAL_REINIT (t) = 1;
} }
if (max_has_virtual || CLASSTYPE_HAS_PRIMARY_BASE_P (t)) if (TYPE_POLYMORPHIC_P (t))
{ {
CLASSTYPE_VSIZE (t) = has_virtual; CLASSTYPE_VSIZE (t) = has_virtual;
if (CLASSTYPE_HAS_PRIMARY_BASE_P (t)) if (CLASSTYPE_HAS_PRIMARY_BASE_P (t))
...@@ -4801,7 +4749,7 @@ finish_struct_1 (t) ...@@ -4801,7 +4749,7 @@ finish_struct_1 (t)
CLASSTYPE_VFIELDS (t) CLASSTYPE_VFIELDS (t)
= chainon (CLASSTYPE_VFIELDS (t), build_tree_list (NULL_TREE, t)); = chainon (CLASSTYPE_VFIELDS (t), build_tree_list (NULL_TREE, t));
finish_struct_bits (t, max_has_virtual); finish_struct_bits (t);
/* Complete the rtl for any static member objects of the type we're /* Complete the rtl for any static member objects of the type we're
working on. */ working on. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment