Commit c0bbf652 by Mark Mitchell Committed by Mark Mitchell

cp-tree.def (THUNK_DECL): Discuss vcall indices.

	* cp-tree.def (THUNK_DECL): Discuss vcall indices.
	* cp-tree.h (BINFO_VIRTUALS): Update documentation.
	(BF_DELTA): New macro.
	(BF_VCALL_INDEX): Likewise.
	(BF_FN): Likewise.
	(THUNK_VCALL_OFFSET): Likewise.
	(make_thunk): Change prototype.
	* class.c (build_vtable_entry): Integrate
	build_vtable_entry_for_fn.  Handle vcall indices.
	(build_vtable_entry_for_fn): Remove.
	(set_rtti_entry): Handle vcall indices.  Use BF_DELTA,
	BF_VCALL_INDEX, BF_FN.
	(modify_vtable_entry): Integrate common code from
	modify_one_vtable and dfs_fixup_vtable_deltas.
	(add_virtual_function): Set BF_VCALL_INDEX.
	(build_vtbl_initializer): Simplify.  Use BF_DELTA, BF_VCALL_INDEX,
	and BF_FN.
	(modify_one_vtable): Simplify.
	(dfs_fixup_vtable_deltas): Likewise.
	(override_one_vtable): Use BF_DELTA, BF_VCALL_INDEX, BF_FN.
	* method.c (make_thunk): Handle vcall indices.

From-SVN: r31684
parent 4fda2521
2000-01-27 Mark Mitchell <mark@codesourcery.com>
* cp-tree.def (THUNK_DECL): Discuss vcall indices.
* cp-tree.h (BINFO_VIRTUALS): Update documentation.
(BF_DELTA): New macro.
(BF_VCALL_INDEX): Likewise.
(BF_FN): Likewise.
(THUNK_VCALL_OFFSET): Likewise.
(make_thunk): Change prototype.
* class.c (build_vtable_entry): Integrate
build_vtable_entry_for_fn. Handle vcall indices.
(build_vtable_entry_for_fn): Remove.
(set_rtti_entry): Handle vcall indices. Use BF_DELTA,
BF_VCALL_INDEX, BF_FN.
(modify_vtable_entry): Integrate common code from
modify_one_vtable and dfs_fixup_vtable_deltas.
(add_virtual_function): Set BF_VCALL_INDEX.
(build_vtbl_initializer): Simplify. Use BF_DELTA, BF_VCALL_INDEX,
and BF_FN.
(modify_one_vtable): Simplify.
(dfs_fixup_vtable_deltas): Likewise.
(override_one_vtable): Use BF_DELTA, BF_VCALL_INDEX, BF_FN.
* method.c (make_thunk): Handle vcall indices.
2000-01-28 Nathan Sidwell <sidwell@codesourcery.com> 2000-01-28 Nathan Sidwell <sidwell@codesourcery.com>
Compiler side new abi rtti (not enabled). Compiler side new abi rtti (not enabled).
......
/* This file contains the definitions and documentation for the /* This file contains the definitions and documentation for the
additional tree codes used in the GNU C++ compiler (see tree.def additional tree codes used in the GNU C++ compiler (see tree.def
for the standard codes). for the standard codes).
Copyright (C) 1987,88,90,93,97-8,1999 Free Software Foundation, Inc. Copyright (C) 1987,88,90,93,97-8,1999, 2000 Free Software Foundation, Inc.
Hacked by Michael Tiemann (tiemann@cygnus.com) Hacked by Michael Tiemann (tiemann@cygnus.com)
This file is part of GNU CC. This file is part of GNU CC.
...@@ -159,12 +159,22 @@ DEFTREECODE (TYPEOF_TYPE, "typeof_type", 't', 0) ...@@ -159,12 +159,22 @@ DEFTREECODE (TYPEOF_TYPE, "typeof_type", 't', 0)
/* A thunk is a stub function. /* A thunk is a stub function.
Thunks are used to implement multiple inheritance: A THUNK_DECL is an alternate entry point for an ordinary
At run-time, such a thunk subtracts THUNK_DELTA (an int, not a tree) FUNCTION_DECL. It's job is to adjust the `this' poitner before
from the this pointer, and then jumps to DECL_INITIAL transferring control to the FUNCTION_DECL.
(which is an ADDR_EXPR whose operand is a FUNCTION_DECL).
Other kinds of thunks may be defined later. */ A thunk may perform either, or both, of the following operations:
o Adjust the `this' pointer by a constant offset.
o Adjust the `this' pointer by looking up a vcall-offset
in the vtable.
If both operations are performed, then the constant adjument to
`this' is performed first.
The constant adjustment is given by THUNK_DELTA. If the
vcall-offset is required, the index into the vtable is given by
THUNK_VCALL_OFFSET. */
DEFTREECODE (THUNK_DECL, "thunk_decl", 'd', 0) DEFTREECODE (THUNK_DECL, "thunk_decl", 'd', 0)
/* A using declaration. DECL_INITIAL contains the specified scope. /* A using declaration. DECL_INITIAL contains the specified scope.
......
...@@ -115,15 +115,18 @@ Boston, MA 02111-1307, USA. */ ...@@ -115,15 +115,18 @@ Boston, MA 02111-1307, USA. */
For a static VAR_DECL, this is DECL_INIT_PRIORITY. For a static VAR_DECL, this is DECL_INIT_PRIORITY.
BINFO_VIRTUALS BINFO_VIRTUALS
For a binfo, this is a TREE_LIST. The TREE_PURPOSE of each node For a binfo, this is a TREE_LIST. The BF_DELTA of each node
gives the amount by which to adjust the `this' pointer when gives the amount by which to adjust the `this' pointer when
calling the function. If the method is an overriden version of a calling the function. If the method is an overriden version of a
base class method, then it is assumed that, prior to adjustment, base class method, then it is assumed that, prior to adjustment,
the this pointer points to an object of the base class. the this pointer points to an object of the base class.
The TREE_VALUE is the declaration for the virtual function The BF_VCALL_INDEX of each node, if non-NULL, gives the vtable
itself. When CLASSTYPE_COM_INTERFACE_P does not hold, the first index of the vcall offset for this entry.
entry does not have a TREE_VALUE; it is just an offset.
The BF_FN is the declaration for the virtual function itself.
When CLASSTYPE_COM_INTERFACE_P does not hold, the first entry
does not have a BF_FN; it is just an offset.
DECL_ARGUMENTS DECL_ARGUMENTS
For a VAR_DECL this is DECL_ANON_UNION_ELEMS. For a VAR_DECL this is DECL_ANON_UNION_ELEMS.
...@@ -1720,6 +1723,18 @@ struct lang_type ...@@ -1720,6 +1723,18 @@ struct lang_type
/* Get the value of the top-most type dominating the non-`normal' vfields. */ /* Get the value of the top-most type dominating the non-`normal' vfields. */
#define VF_DERIVED_VALUE(NODE) (VF_BINFO_VALUE (NODE) ? BINFO_TYPE (VF_BINFO_VALUE (NODE)) : NULL_TREE) #define VF_DERIVED_VALUE(NODE) (VF_BINFO_VALUE (NODE) ? BINFO_TYPE (VF_BINFO_VALUE (NODE)) : NULL_TREE)
/* The number of bytes by which to adjust the `this' pointer when
calling this virtual function. */
#define BF_DELTA(NODE) (TREE_PURPOSE (NODE))
/* If non-NULL, the vtable index at which to find the vcall offset
when calling this virtual function. */
#define BF_VCALL_INDEX(NODE) (TREE_TYPE (NODE))
/* The function to call. */
#define BF_FN(NODE) (TREE_VALUE (NODE))
/* Nonzero for TREE_LIST node means that this list of things /* Nonzero for TREE_LIST node means that this list of things
is a list of parameters, as opposed to a list of expressions. */ is a list of parameters, as opposed to a list of expressions. */
...@@ -2789,8 +2804,16 @@ extern int flag_new_for_scope; ...@@ -2789,8 +2804,16 @@ extern int flag_new_for_scope;
#define DECL_REALLY_EXTERN(NODE) \ #define DECL_REALLY_EXTERN(NODE) \
(DECL_EXTERNAL (NODE) && ! DECL_NOT_REALLY_EXTERN (NODE)) (DECL_EXTERNAL (NODE) && ! DECL_NOT_REALLY_EXTERN (NODE))
/* An integer indicating how many bytes should be subtracted from the
`this' pointer when this function is called. */
#define THUNK_DELTA(DECL) ((DECL)->decl.frame_size.i) #define THUNK_DELTA(DECL) ((DECL)->decl.frame_size.i)
/* An integer indicating how many bytes should be subtracted from the
vtable for the `this' pointer to find the vcall offset. (The vptr
is always located at offset zero from the `this' pointer.) If
zero, then there is no vcall offset. */
#define THUNK_VCALL_OFFSET(DECL) (DECL_FIELD_SIZE (DECL))
/* DECL_NEEDED_P holds of a declaration when we need to emit its /* DECL_NEEDED_P holds of a declaration when we need to emit its
definition. This is true when the back-end tells us that definition. This is true when the back-end tells us that
the symbol has been referenced in the generated code. If, however, the symbol has been referenced in the generated code. If, however,
...@@ -3918,7 +3941,7 @@ extern tree build_overload_with_type PARAMS ((tree, tree)); ...@@ -3918,7 +3941,7 @@ extern tree build_overload_with_type PARAMS ((tree, tree));
extern tree build_destructor_name PARAMS ((tree)); extern tree build_destructor_name PARAMS ((tree));
extern tree build_opfncall PARAMS ((enum tree_code, int, tree, tree, tree)); extern tree build_opfncall PARAMS ((enum tree_code, int, tree, tree, tree));
extern tree hack_identifier PARAMS ((tree, tree)); extern tree hack_identifier PARAMS ((tree, tree));
extern tree make_thunk PARAMS ((tree, int)); extern tree make_thunk PROTO((tree, int, int));
extern void emit_thunk PARAMS ((tree)); extern void emit_thunk PARAMS ((tree));
extern void synthesize_method PARAMS ((tree)); extern void synthesize_method PARAMS ((tree));
extern tree get_id_2 PARAMS ((const char *, tree)); extern tree get_id_2 PARAMS ((const char *, tree));
......
...@@ -2008,9 +2008,10 @@ hack_identifier (value, name) ...@@ -2008,9 +2008,10 @@ hack_identifier (value, name)
tree tree
make_thunk (function, delta) make_thunk (function, delta, vcall_index)
tree function; tree function;
int delta; int delta;
int vcall_index;
{ {
tree thunk_id; tree thunk_id;
tree thunk; tree thunk;
...@@ -2033,6 +2034,11 @@ make_thunk (function, delta) ...@@ -2033,6 +2034,11 @@ make_thunk (function, delta)
icat (-delta); icat (-delta);
OB_PUTC ('_'); OB_PUTC ('_');
OB_PUTID (DECL_ASSEMBLER_NAME (func_decl)); OB_PUTID (DECL_ASSEMBLER_NAME (func_decl));
if (vcall_index)
{
OB_PUTC ('_');
icat (vcall_index);
}
OB_FINISH (); OB_FINISH ();
thunk_id = get_identifier (obstack_base (&scratch_obstack)); thunk_id = get_identifier (obstack_base (&scratch_obstack));
...@@ -2052,6 +2058,8 @@ make_thunk (function, delta) ...@@ -2052,6 +2058,8 @@ make_thunk (function, delta)
TREE_SET_CODE (thunk, THUNK_DECL); TREE_SET_CODE (thunk, THUNK_DECL);
DECL_INITIAL (thunk) = function; DECL_INITIAL (thunk) = function;
THUNK_DELTA (thunk) = delta; THUNK_DELTA (thunk) = delta;
THUNK_VCALL_OFFSET (thunk)
= vcall_index * TREE_INT_CST_LOW (TYPE_SIZE (vtable_entry_type));
DECL_EXTERNAL (thunk) = 1; DECL_EXTERNAL (thunk) = 1;
DECL_ARTIFICIAL (thunk) = 1; DECL_ARTIFICIAL (thunk) = 1;
/* So that finish_file can write out any thunks that need to be: */ /* So that finish_file can write out any thunks that need to be: */
......
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