+1998-10-07 Mark Mitchell <mark@markmitchell.com>
+
+ * cp-tree.h (vtbl_ptr_type_node): New variable.
+ * class.c (build_vtbl_ref): Don't indirect through the vptr; it's
+ already of the right type.
+ (finish_struct_1): Make the vptr be of type vtbl_ptr_type_node.
+ Simplify code to grow vtable.
+ * decl.c (vtbl_ptr_type_node): Define.
+ (init_decl_processing): Initialize it.
+
1998-10-06 Mark Mitchell <mark@markmitchell.com>
* cp-tree.def (PTRMEM_CST): New tree node.
basetype = TREE_TYPE (basetype);
if (instance == current_class_ref)
- vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
- NULL_PTR);
+ vtbl = build_vfield_ref (instance, basetype);
else
{
if (optimize)
|| TREE_CODE (instance) == VAR_DECL))
vtbl = TYPE_BINFO_VTABLE (basetype);
else
- vtbl = build_indirect_ref (build_vfield_ref (instance, basetype),
- NULL_PTR);
+ vtbl = build_vfield_ref (instance, basetype);
}
assemble_external (vtbl);
/* We build this decl with ptr_type_node, and
change the type when we know what it should be. */
vfield = build_lang_field_decl (FIELD_DECL, get_vfield_name (t),
- ptr_type_node);
+ vtbl_ptr_type_node);
/* If you change any of the below, take a look at all the
other VFIELD_BASEs and VTABLE_BASEs in the code, and change
them too. */
/* Now lay out the virtual function table. */
if (has_virtual)
{
- tree atype, itype;
+ /* Use size_int so values are memoized in common cases. */
+ tree itype = build_index_type (size_int (has_virtual));
+ tree atype = build_array_type (vtable_entry_type, itype);
- if (TREE_TYPE (vfield) == ptr_type_node)
- {
- /* We must create a pointer to this table because
- the one inherited from base class does not exist.
- We will fill in the type when we know what it
- should really be. Use `size_int' so values are memoized
- in common cases. */
- itype = build_index_type (size_int (has_virtual));
- atype = build_array_type (vtable_entry_type, itype);
- layout_type (atype);
- TREE_TYPE (vfield) = build_pointer_type (atype);
- }
- else
- {
- atype = TREE_TYPE (TREE_TYPE (vfield));
-
- if (has_virtual != TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (atype))))
- {
- /* We must extend (or create) the boundaries on this array,
- because we picked up virtual functions from multiple
- base classes. */
- itype = build_index_type (size_int (has_virtual));
- atype = build_array_type (vtable_entry_type, itype);
- layout_type (atype);
- vfield = copy_node (vfield);
- TREE_TYPE (vfield) = build_pointer_type (atype);
- }
- }
+ layout_type (atype);
CLASSTYPE_VFIELD (t) = vfield;
+
+ /* We may have to grow the vtable. */
if (TREE_TYPE (TYPE_BINFO_VTABLE (t)) != atype)
{
TREE_TYPE (TYPE_BINFO_VTABLE (t)) = atype;
#define vfunc_ptr_type_node \
(flag_vtable_thunks ? vtable_entry_type : ptr_type_node)
-/* Array type `(void *)[]' */
+/* The type of a vtbl, i.e., an array of vtable entries. */
extern tree vtbl_type_node;
+/* The type of a class vtbl pointer, i.e., a pointer to a vtable entry. */
+extern tree vtbl_ptr_type_node;
extern tree delta_type_node;
extern tree std_node;
/* Array type `vtable_entry_type[]' */
tree vtbl_type_node;
+tree vtbl_ptr_type_node;
/* namespace std */
tree std_node;
layout_type (vtbl_type_node);
vtbl_type_node = cp_build_type_variant (vtbl_type_node, 1, 0);
record_builtin_type (RID_MAX, NULL_PTR, vtbl_type_node);
+ vtbl_ptr_type_node = build_pointer_type (vtable_entry_type);
+ layout_type (vtbl_ptr_type_node);
+ record_builtin_type (RID_MAX, NULL_PTR, vtbl_ptr_type_node);
/* Simplify life by making a "sigtable_entry_type". Give its
fields names so that the debugger can use them. */