This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to document TYPE_VFIELD
- To: gcc-patches at gcc dot gnu dot org
- Subject: C++ PATCH to document TYPE_VFIELD
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Wed, 06 Oct 1999 12:09:31 -0700
- Organization: CodeSourcery, LLC
This patch documents/dumps TYPE_VFIELD. I also removed
CLASSTYPE_VFIELD. The comment said "remove when done merging"; we've
been done for years.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
I1999-10-06 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (CLASSTYPE_VFIELD): Remove.
* call.c (build_vfield_ref): Use TYPE_VFIELD, not
CLASSTYPE_VFIELD.
* class.c (get_vfield_offset): Likewise.
(finish_base_struct): Likewise.
(modify_one_vtable): Likewise.
(fixup_vtable_deltas): Likewise.
(finish_struct_1): Likewise.
* init.c (expand_virtual_init): Likewise.
* search.c (lookup_field_1): Likewise.
(expand_upcast_fixups): Likewise.
* typeck.c (build_component_ref): Likewise.
(build_binary_op_nodefault): Likewise.
* dump.c (dqueue_and_dump): Dump TYPE_VFIELD.
* ir.texi: Document TYPE_VFIELD.
ndex: call.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/call.c,v
retrieving revision 1.175
diff -c -p -r1.175 call.c
*** call.c 1999/10/04 09:15:13 1.175
--- call.c 1999/10/06 18:55:45
*************** build_vfield_ref (datum, type)
*** 112,121 ****
datum = convert_from_reference (datum);
if (! TYPE_USES_COMPLEX_INHERITANCE (type))
! rval = build (COMPONENT_REF, TREE_TYPE (CLASSTYPE_VFIELD (type)),
! datum, CLASSTYPE_VFIELD (type));
else
! rval = build_component_ref (datum, DECL_NAME (CLASSTYPE_VFIELD (type)), NULL_TREE, 0);
return rval;
}
--- 112,121 ----
datum = convert_from_reference (datum);
if (! TYPE_USES_COMPLEX_INHERITANCE (type))
! rval = build (COMPONENT_REF, TREE_TYPE (TYPE_VFIELD (type)),
! datum, TYPE_VFIELD (type));
else
! rval = build_component_ref (datum, DECL_NAME (TYPE_VFIELD (type)), NULL_TREE, 0);
return rval;
}
Index: class.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/class.c,v
retrieving revision 1.189
diff -c -p -r1.189 class.c
*** class.c 1999/09/29 22:52:49 1.189
--- class.c 1999/10/06 18:55:48
*************** get_vfield_offset (binfo)
*** 605,611 ****
{
tree tmp
= size_binop (FLOOR_DIV_EXPR,
! DECL_FIELD_BITPOS (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))),
size_int (BITS_PER_UNIT));
tmp = convert (sizetype, tmp);
return size_binop (PLUS_EXPR, tmp, BINFO_OFFSET (binfo));
--- 605,611 ----
{
tree tmp
= size_binop (FLOOR_DIV_EXPR,
! DECL_FIELD_BITPOS (TYPE_VFIELD (BINFO_TYPE (binfo))),
size_int (BITS_PER_UNIT));
tmp = convert (sizetype, tmp);
return size_binop (PLUS_EXPR, tmp, BINFO_OFFSET (binfo));
*************** finish_base_struct (t, b)
*** 1603,1609 ****
TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
b->has_virtual = CLASSTYPE_VSIZE (basetype);
! b->vfield = CLASSTYPE_VFIELD (basetype);
b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
vfields = b->vfields;
while (vfields)
--- 1603,1609 ----
TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
b->has_virtual = CLASSTYPE_VSIZE (basetype);
! b->vfield = TYPE_VFIELD (basetype);
b->vfields = copy_list (CLASSTYPE_VFIELDS (basetype));
vfields = b->vfields;
while (vfields)
*************** finish_base_struct (t, b)
*** 1612,1626 ****
|| ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
{
tree value = VF_BASETYPE_VALUE (vfields);
! if (DECL_NAME (CLASSTYPE_VFIELD (value))
! == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
VF_NORMAL_VALUE (b->vfields) = basetype;
else
VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
}
vfields = TREE_CHAIN (vfields);
}
! CLASSTYPE_VFIELD (t) = b->vfield;
}
else
{
--- 1612,1626 ----
|| ! TREE_VIA_VIRTUAL (VF_BINFO_VALUE (vfields)))
{
tree value = VF_BASETYPE_VALUE (vfields);
! if (DECL_NAME (TYPE_VFIELD (value))
! == DECL_NAME (TYPE_VFIELD (basetype)))
VF_NORMAL_VALUE (b->vfields) = basetype;
else
VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
}
vfields = TREE_CHAIN (vfields);
}
! TYPE_VFIELD (t) = b->vfield;
}
else
{
*************** finish_base_struct (t, b)
*** 1633,1640 ****
{
tree value = VF_BASETYPE_VALUE (vfields);
b->vfields = tree_cons (base_binfo, value, b->vfields);
! if (DECL_NAME (CLASSTYPE_VFIELD (value))
! == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
VF_NORMAL_VALUE (b->vfields) = basetype;
else
VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
--- 1633,1640 ----
{
tree value = VF_BASETYPE_VALUE (vfields);
b->vfields = tree_cons (base_binfo, value, b->vfields);
! if (DECL_NAME (TYPE_VFIELD (value))
! == DECL_NAME (TYPE_VFIELD (basetype)))
VF_NORMAL_VALUE (b->vfields) = basetype;
else
VF_NORMAL_VALUE (b->vfields) = VF_NORMAL_VALUE (vfields);
*************** finish_base_struct (t, b)
*** 1652,1659 ****
TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
b->has_virtual = CLASSTYPE_VSIZE (basetype);
! b->vfield = CLASSTYPE_VFIELD (basetype);
! CLASSTYPE_VFIELD (t) = b->vfield;
/* When we install the first one, set the VF_NORMAL_VALUE
to be the current class, as this it is the most derived
class. Hopefully, this is not set to something else
--- 1652,1659 ----
TYPE_BINFO_VTABLE (t) = TYPE_BINFO_VTABLE (basetype);
TYPE_BINFO_VIRTUALS (t) = TYPE_BINFO_VIRTUALS (basetype);
b->has_virtual = CLASSTYPE_VSIZE (basetype);
! b->vfield = TYPE_VFIELD (basetype);
! TYPE_VFIELD (t) = b->vfield;
/* When we install the first one, set the VF_NORMAL_VALUE
to be the current class, as this it is the most derived
class. Hopefully, this is not set to something else
*************** finish_base_struct (t, b)
*** 1661,1668 ****
vfields = b->vfields;
while (vfields)
{
! if (DECL_NAME (CLASSTYPE_VFIELD (t))
! == DECL_NAME (CLASSTYPE_VFIELD (basetype)))
{
VF_NORMAL_VALUE (vfields) = t;
/* There should only be one of them! And it should
--- 1661,1668 ----
vfields = b->vfields;
while (vfields)
{
! if (DECL_NAME (TYPE_VFIELD (t))
! == DECL_NAME (TYPE_VFIELD (basetype)))
{
VF_NORMAL_VALUE (vfields) = t;
/* There should only be one of them! And it should
*************** modify_one_vtable (binfo, t, fndecl)
*** 2400,2406 ****
if (binfo == TYPE_BINFO (t))
{
if (! BINFO_NEW_VTABLE_MARKED (binfo))
! build_vtable (TYPE_BINFO (DECL_CONTEXT (CLASSTYPE_VFIELD (t))), t);
}
else
{
--- 2400,2406 ----
if (binfo == TYPE_BINFO (t))
{
if (! BINFO_NEW_VTABLE_MARKED (binfo))
! build_vtable (TYPE_BINFO (DECL_CONTEXT (TYPE_VFIELD (t))), t);
}
else
{
*************** modify_one_vtable (binfo, t, fndecl)
*** 2428,2434 ****
{
tree base_offset, offset;
tree context = DECL_CLASS_CONTEXT (fndecl);
! tree vfield = CLASSTYPE_VFIELD (t);
tree this_offset;
offset = get_class_offset (context, t, binfo, fndecl);
--- 2428,2434 ----
{
tree base_offset, offset;
tree context = DECL_CLASS_CONTEXT (fndecl);
! tree vfield = TYPE_VFIELD (t);
tree this_offset;
offset = get_class_offset (context, t, binfo, fndecl);
*************** fixup_vtable_deltas1 (binfo, t)
*** 2520,2526 ****
{
tree base_offset, offset;
tree context = DECL_CLASS_CONTEXT (fndecl);
! tree vfield = CLASSTYPE_VFIELD (t);
tree this_offset;
offset = get_class_offset (context, t, binfo, fndecl);
--- 2520,2526 ----
{
tree base_offset, offset;
tree context = DECL_CLASS_CONTEXT (fndecl);
! tree vfield = TYPE_VFIELD (t);
tree this_offset;
offset = get_class_offset (context, t, binfo, fndecl);
*************** finish_struct_1 (t)
*** 3284,3290 ****
modified. Needed at this point to make add_virtual_function
and modify_vtable_entries work. */
CLASSTYPE_VFIELDS (t) = vfields;
! CLASSTYPE_VFIELD (t) = vfield;
for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
{
--- 3284,3290 ----
modified. Needed at this point to make add_virtual_function
and modify_vtable_entries work. */
CLASSTYPE_VFIELDS (t) = vfields;
! TYPE_VFIELD (t) = vfield;
for (x = TYPE_METHODS (t); x; x = TREE_CHAIN (x))
{
*************** finish_struct_1 (t)
*** 3753,3759 ****
other VFIELD_BASEs and VTABLE_BASEs in the code, and change
them too. */
DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
! CLASSTYPE_VFIELD (t) = vfield;
DECL_VIRTUAL_P (vfield) = 1;
DECL_ARTIFICIAL (vfield) = 1;
DECL_FIELD_CONTEXT (vfield) = t;
--- 3753,3759 ----
other VFIELD_BASEs and VTABLE_BASEs in the code, and change
them too. */
DECL_ASSEMBLER_NAME (vfield) = get_identifier (VFIELD_BASE);
! TYPE_VFIELD (t) = vfield;
DECL_VIRTUAL_P (vfield) = 1;
DECL_ARTIFICIAL (vfield) = 1;
DECL_FIELD_CONTEXT (vfield) = t;
*************** finish_struct_1 (t)
*** 3923,3929 ****
DECL_CLASS_CONTEXT (vfield) = t;
DECL_FIELD_BITPOS (vfield)
= size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
! CLASSTYPE_VFIELD (t) = vfield;
}
#ifdef NOTQUITE
--- 3923,3929 ----
DECL_CLASS_CONTEXT (vfield) = t;
DECL_FIELD_BITPOS (vfield)
= size_binop (PLUS_EXPR, offset, DECL_FIELD_BITPOS (vfield));
! TYPE_VFIELD (t) = vfield;
}
#ifdef NOTQUITE
*************** finish_struct_1 (t)
*** 4046,4052 ****
layout_type (atype);
! CLASSTYPE_VFIELD (t) = vfield;
/* We may have to grow the vtable. */
if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
--- 4046,4052 ----
layout_type (atype);
! TYPE_VFIELD (t) = vfield;
/* We may have to grow the vtable. */
if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
*************** finish_struct_1 (t)
*** 4062,4068 ****
}
}
else if (first_vfn_base_index >= 0)
! CLASSTYPE_VFIELD (t) = vfield;
CLASSTYPE_VFIELDS (t) = vfields;
finish_struct_bits (t, max_has_virtual);
--- 4062,4068 ----
}
}
else if (first_vfn_base_index >= 0)
! TYPE_VFIELD (t) = vfield;
CLASSTYPE_VFIELDS (t) = vfields;
finish_struct_bits (t, max_has_virtual);
Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.328
diff -c -p -r1.328 cp-tree.h
*** cp-tree.h 1999/10/04 09:33:29 1.328
--- cp-tree.h 1999/10/06 18:55:52
*************** struct lang_type
*** 1365,1373 ****
1, if D's vtable came from B2. */
#define CLASSTYPE_VFIELD_PARENT(NODE) (TYPE_LANG_SPECIFIC(NODE)->vfield_parent)
- /* Remove when done merging. */
- #define CLASSTYPE_VFIELD(NODE) TYPE_VFIELD(NODE)
-
/* The number of virtual functions defined for this
_CLASSTYPE node. */
#define CLASSTYPE_VSIZE(NODE) (TYPE_LANG_SPECIFIC(NODE)->vsize)
--- 1365,1370 ----
Index: dump.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/dump.c,v
retrieving revision 1.20
diff -c -p -r1.20 dump.c
*** dump.c 1999/10/06 05:35:38 1.20
--- dump.c 1999/10/06 18:55:52
*************** dequeue_and_dump (di)
*** 530,535 ****
--- 530,536 ----
dump_child ("flds", TYPE_FIELDS (t));
dump_child ("fncs", TYPE_METHODS (t));
+ dump_child ("vfld", TYPE_VFIELD (t));
queue_and_dump_index (di, "binf", TYPE_BINFO (t),
DUMP_BINFO);
}
Index: init.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/init.c,v
retrieving revision 1.144
diff -c -p -r1.144 init.c
*** init.c 1999/10/04 15:13:26 1.144
--- init.c 1999/10/06 18:55:54
*************** expand_virtual_init (binfo, decl)
*** 659,667 ****
/* This code is crusty. Should be simple, like:
vtbl = BINFO_VTABLE (binfo);
*/
! vtype = DECL_CONTEXT (CLASSTYPE_VFIELD (type));
vtype_binfo = get_binfo (vtype, TREE_TYPE (TREE_TYPE (decl)), 0);
! vtbl = BINFO_VTABLE (binfo_value (DECL_FIELD_CONTEXT (CLASSTYPE_VFIELD (type)), binfo));
assemble_external (vtbl);
TREE_USED (vtbl) = 1;
vtbl = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (vtbl)), vtbl);
--- 659,667 ----
/* This code is crusty. Should be simple, like:
vtbl = BINFO_VTABLE (binfo);
*/
! vtype = DECL_CONTEXT (TYPE_VFIELD (type));
vtype_binfo = get_binfo (vtype, TREE_TYPE (TREE_TYPE (decl)), 0);
! vtbl = BINFO_VTABLE (binfo_value (DECL_FIELD_CONTEXT (TYPE_VFIELD (type)), binfo));
assemble_external (vtbl);
TREE_USED (vtbl) = 1;
vtbl = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (vtbl)), vtbl);
Index: ir.texi
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/ir.texi,v
retrieving revision 1.15
diff -c -p -r1.15 ir.texi
*** ir.texi 1999/10/05 23:59:24 1.15
--- ir.texi 1999/10/06 18:55:56
*************** list. In particular, no @code{FIELD_DEC
*** 655,660 ****
--- 655,661 ----
@findex TREE_VIA_PROTECTED
@findex TREE_VIA_PRIVATE
@findex TYPE_FIELDS
+ @findex TYPE_VFIELD
@findex TYPE_METHODS
A class type is represented by either a @code{RECORD_TYPE} or a
*************** macro to discern whether or not a partic
*** 666,673 ****
opposed to a @code{struct}. This macro will be true only for classes
declared with the @code{class} tag.
! All non-function members are available on the @code{TYPE_FIELDS} list.
! Given one member, the next can be found by following the
@code{TREE_CHAIN}. You should not depend in any way on the order in
which fields appear on this list. All nodes on this list will be
@samp{DECL} nodes. A @code{FIELD_DECL} is used to represent a non-static
--- 667,674 ----
opposed to a @code{struct}. This macro will be true only for classes
declared with the @code{class} tag.
! Almost all non-function members are available on the @code{TYPE_FIELDS}
! list. Given one member, the next can be found by following the
@code{TREE_CHAIN}. You should not depend in any way on the order in
which fields appear on this list. All nodes on this list will be
@samp{DECL} nodes. A @code{FIELD_DECL} is used to represent a non-static
*************** the @code{TYPE_DECL} for the enumeration
*** 679,684 ****
--- 680,690 ----
There are no entries for base classes on this list. In particular,
there is no @code{FIELD_DECL} for the ``base-class portion'' of an
object.
+
+ The @code{TYPE_VFIELD} is a compiler-generated field used to point to
+ virtual function tables. It does not appear on the @code{TYPE_FIELDS}
+ list. However, back-ends should handle the @code{TYPE_VFIELD} just like
+ all the entries on the @code{TYPE_FIELDS} list.
The function members are available on the @code{TYPE_METHODS} list.
Again, subsequent members are found by following the @code{TREE_CHAIN}
Index: search.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/search.c,v
retrieving revision 1.128
diff -c -p -r1.128 search.c
*** search.c 1999/10/05 16:19:04 1.128
--- search.c 1999/10/06 18:56:04
*************** lookup_field_1 (type, name)
*** 656,662 ****
{
/* Give the user what s/he thinks s/he wants. */
if (TYPE_VIRTUAL_P (type))
! return CLASSTYPE_VFIELD (type);
}
return NULL_TREE;
}
--- 656,662 ----
{
/* Give the user what s/he thinks s/he wants. */
if (TYPE_VIRTUAL_P (type))
! return TYPE_VFIELD (type);
}
return NULL_TREE;
}
*************** expand_upcast_fixups (binfo, addr, orig_
*** 2685,2691 ****
/* Update the vtable pointers as necessary. */
ref = build_vfield_ref
(build_indirect_ref (addr, NULL_PTR),
! DECL_CONTEXT (CLASSTYPE_VFIELD (BINFO_TYPE (binfo))));
finish_expr_stmt
(build_modify_expr (ref, NOP_EXPR, nvtbl));
}
--- 2685,2691 ----
/* Update the vtable pointers as necessary. */
ref = build_vfield_ref
(build_indirect_ref (addr, NULL_PTR),
! DECL_CONTEXT (TYPE_VFIELD (BINFO_TYPE (binfo))));
finish_expr_stmt
(build_modify_expr (ref, NOP_EXPR, nvtbl));
}
Index: typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/typeck.c,v
retrieving revision 1.221
diff -c -p -r1.221 typeck.c
*** typeck.c 1999/10/04 09:15:17 1.221
--- typeck.c 1999/10/06 18:56:08
*************** build_component_ref (datum, component, b
*** 2094,2105 ****
}
/* Look up component name in the structure type definition. */
! if (CLASSTYPE_VFIELD (basetype)
! && DECL_NAME (CLASSTYPE_VFIELD (basetype)) == component)
/* Special-case this because if we use normal lookups in an ambiguous
hierarchy, the compiler will abort (because vptr lookups are
not supposed to be ambiguous. */
! field = CLASSTYPE_VFIELD (basetype);
else if (TREE_CODE (component) == FIELD_DECL)
field = component;
else if (TREE_CODE (component) == TYPE_DECL)
--- 2094,2105 ----
}
/* Look up component name in the structure type definition. */
! if (TYPE_VFIELD (basetype)
! && DECL_NAME (TYPE_VFIELD (basetype)) == component)
/* Special-case this because if we use normal lookups in an ambiguous
hierarchy, the compiler will abort (because vptr lookups are
not supposed to be ambiguous. */
! field = TYPE_VFIELD (basetype);
else if (TREE_CODE (component) == FIELD_DECL)
field = component;
else if (TREE_CODE (component) == TYPE_DECL)
*************** build_binary_op_nodefault (code, orig_op
*** 3697,3704 ****
DECL_VINDEX (TREE_OPERAND (op1, 0)),
integer_one_node);
op1 = integer_zero_node;
! delta21 = CLASSTYPE_VFIELD (TYPE_METHOD_BASETYPE
! (TREE_TYPE (type1)));
delta21 = DECL_FIELD_BITPOS (delta21);
delta21 = size_binop (FLOOR_DIV_EXPR, delta21,
size_int (BITS_PER_UNIT));
--- 3697,3704 ----
DECL_VINDEX (TREE_OPERAND (op1, 0)),
integer_one_node);
op1 = integer_zero_node;
! delta21 = TYPE_VFIELD (TYPE_METHOD_BASETYPE
! (TREE_TYPE (type1)));
delta21 = DECL_FIELD_BITPOS (delta21);
delta21 = size_binop (FLOOR_DIV_EXPR, delta21,
size_int (BITS_PER_UNIT));