This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
(C++) conversion overloading patch 2
- To: egcs-patches at cygnus dot com
- Subject: (C++) conversion overloading patch 2
- From: Jason Merrill <jason at cygnus dot com>
- Date: Thu, 29 Oct 1998 20:17:48 -0800
Qt found the hole in my last patch; conversions from base and derived
classes are now ambiguous, so I needed to implement hiding...
Fixes g++.other/conv4.C.
1998-10-29 Jason Merrill <jason@yorick.cygnus.com>
* cp-tree.h (IDENTIFIER_MARKED): New macro.
* search.c (lookup_conversions): Use breadth_first_search.
(add_conversions): Avoid adding two conversions to the same type.
(breadth_first_search): Work with base binfos, rather
than binfos and base indices.
(get_virtual_destructor): Adjust.
(tree_has_any_destructor_p): Adjust.
(get_matching_virtual): Adjust.
Index: cp-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.164
diff -c -p -r1.164 cp-tree.h
*** cp-tree.h 1998/10/28 20:29:06 1.164
--- cp-tree.h 1998/10/30 04:10:57
*************** Boston, MA 02111-1307, USA. */
*** 32,38 ****
DELETE_EXPR_USE_GLOBAL (in DELETE_EXPR).
LOOKUP_EXPR_GLOBAL (in LOOKUP_EXPR).
TREE_NEGATED_INT (in INTEGER_CST).
! (TREE_MANGLED) (in IDENTIFIER_NODE) (commented-out).
1: IDENTIFIER_VIRTUAL_P.
TI_PENDING_TEMPLATE_FLAG.
TEMPLATE_PARMS_FOR_INLINE.
--- 32,38 ----
DELETE_EXPR_USE_GLOBAL (in DELETE_EXPR).
LOOKUP_EXPR_GLOBAL (in LOOKUP_EXPR).
TREE_NEGATED_INT (in INTEGER_CST).
! IDENTIFIER_MARKED (used by search routines).
1: IDENTIFIER_VIRTUAL_P.
TI_PENDING_TEMPLATE_FLAG.
TEMPLATE_PARMS_FOR_INLINE.
*************** struct lang_type
*** 1036,1041 ****
--- 1036,1044 ----
#define BINFO_PUSHDECLS_MARKED(NODE) BINFO_VTABLE_PATH_MARKED (NODE)
#define SET_BINFO_PUSHDECLS_MARKED(NODE) SET_BINFO_VTABLE_PATH_MARKED (NODE)
#define CLEAR_BINFO_PUSHDECLS_MARKED(NODE) CLEAR_BINFO_VTABLE_PATH_MARKED (NODE)
+
+ /* Used by various search routines. */
+ #define IDENTIFIER_MARKED(NODE) TREE_LANG_FLAG_0 (NODE)
/* Accessor macros for the vfield slots in structures. */
*************** struct lang_decl
*** 1398,1404 ****
/* Nonzero in IDENTIFIER_NODE means that this name is not the name the user
gave; it's a DECL_NESTED_TYPENAME. Someone may want to set this on
mangled function names, too, but it isn't currently. */
! #define TREE_MANGLED(NODE) (TREE_LANG_FLAG_0 (NODE))
#endif
#if 0 /* UNUSED */
--- 1401,1407 ----
/* Nonzero in IDENTIFIER_NODE means that this name is not the name the user
gave; it's a DECL_NESTED_TYPENAME. Someone may want to set this on
mangled function names, too, but it isn't currently. */
! #define TREE_MANGLED(NODE) (FOO)
#endif
#if 0 /* UNUSED */
Index: search.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/search.c,v
retrieving revision 1.63
diff -c -p -r1.63 search.c
*** search.c 1998/10/28 01:53:50 1.63
--- search.c 1998/10/30 04:10:57
*************** static void dfs_get_vbase_types PROTO((t
*** 116,132 ****
static void dfs_pushdecls PROTO((tree));
static void dfs_compress_decls PROTO((tree));
static void dfs_unuse_fields PROTO((tree));
! static void add_conversions PROTO((tree));
static tree get_virtuals_named_this PROTO((tree));
! static tree get_virtual_destructor PROTO((tree, int));
! static int tree_has_any_destructor_p PROTO((tree, int));
static int covariant_return_p PROTO((tree, tree));
static struct search_level *push_search_level
PROTO((struct stack_level *, struct obstack *));
static struct search_level *pop_search_level
PROTO((struct stack_level *));
! static HOST_WIDE_INT breadth_first_search
! PROTO((tree, int (*) (tree, int), int (*) (tree, int)));
static tree vbase_types;
static tree vbase_decl_ptr_intermediate, vbase_decl_ptr;
--- 116,132 ----
static void dfs_pushdecls PROTO((tree));
static void dfs_compress_decls PROTO((tree));
static void dfs_unuse_fields PROTO((tree));
! static tree add_conversions PROTO((tree));
static tree get_virtuals_named_this PROTO((tree));
! static tree get_virtual_destructor PROTO((tree));
! static int tree_has_any_destructor_p PROTO((tree));
static int covariant_return_p PROTO((tree, tree));
static struct search_level *push_search_level
PROTO((struct stack_level *, struct obstack *));
static struct search_level *pop_search_level
PROTO((struct stack_level *));
! static tree breadth_first_search
! PROTO((tree, tree (*) (tree), int (*) (tree)));
static tree vbase_types;
static tree vbase_decl_ptr_intermediate, vbase_decl_ptr;
*************** lookup_member (xbasetype, name, protect,
*** 1605,1621 ****
QFN, if non-NULL, is a predicate dictating whether the type should
even be queued. */
! static HOST_WIDE_INT
breadth_first_search (binfo, testfn, qfn)
tree binfo;
! int (*testfn) PROTO((tree, int));
! int (*qfn) PROTO((tree, int));
{
int head = 0, tail = 0;
! int rval = 0;
search_stack = push_search_level (search_stack, &search_obstack);
while (1)
{
tree binfos = BINFO_BASETYPES (binfo);
--- 1605,1625 ----
QFN, if non-NULL, is a predicate dictating whether the type should
even be queued. */
! static tree
breadth_first_search (binfo, testfn, qfn)
tree binfo;
! tree (*testfn) PROTO((tree));
! int (*qfn) PROTO((tree));
{
int head = 0, tail = 0;
! tree rval = NULL_TREE;
search_stack = push_search_level (search_stack, &search_obstack);
+ SET_BINFO_MARKED (binfo);
+ obstack_ptr_grow (&search_obstack, binfo);
+ ++tail;
+
while (1)
{
tree binfos = BINFO_BASETYPES (binfo);
*************** breadth_first_search (binfo, testfn, qfn
*** 1628,1639 ****
tree base_binfo = TREE_VEC_ELT (binfos, i);
if (BINFO_MARKED (base_binfo) == 0
! && (qfn == 0 || (*qfn) (binfo, i)))
{
SET_BINFO_MARKED (base_binfo);
! obstack_ptr_grow (&search_obstack, binfo);
! obstack_ptr_grow (&search_obstack, (HOST_WIDE_INT) i);
! tail += 2;
if (tail >= search_stack->limit)
my_friendly_abort (100);
}
--- 1632,1642 ----
tree base_binfo = TREE_VEC_ELT (binfos, i);
if (BINFO_MARKED (base_binfo) == 0
! && (qfn == 0 || (*qfn) (base_binfo)))
{
SET_BINFO_MARKED (base_binfo);
! obstack_ptr_grow (&search_obstack, base_binfo);
! ++tail;
if (tail >= search_stack->limit)
my_friendly_abort (100);
}
*************** breadth_first_search (binfo, testfn, qfn
*** 1646,1655 ****
}
binfo = search_stack->first[head++];
! i = (HOST_WIDE_INT) search_stack->first[head++];
! if ((rval = (*testfn) (binfo, i)))
break;
- binfo = BINFO_BASETYPE (binfo, i);
}
{
tree *tp = search_stack->first;
--- 1649,1656 ----
}
binfo = search_stack->first[head++];
! if ((rval = (*testfn) (binfo)))
break;
}
{
tree *tp = search_stack->first;
*************** breadth_first_search (binfo, testfn, qfn
*** 1657,1664 ****
while (tp < search_tail)
{
tree binfo = *tp++;
! int i = (HOST_WIDE_INT)(*tp++);
! CLEAR_BINFO_MARKED (BINFO_BASETYPE (binfo, i));
}
}
--- 1658,1664 ----
while (tp < search_tail)
{
tree binfo = *tp++;
! CLEAR_BINFO_MARKED (binfo);
}
}
*************** breadth_first_search (binfo, testfn, qfn
*** 1667,1673 ****
}
/* Functions to use in breadth first searches. */
! typedef int (*pfi) PROTO((tree, int));
static tree declarator;
--- 1667,1673 ----
}
/* Functions to use in breadth first searches. */
! typedef tree (*pfi) PROTO((tree));
static tree declarator;
*************** get_virtuals_named_this (binfo)
*** 1698,1710 ****
}
static tree
! get_virtual_destructor (binfo, i)
tree binfo;
- int i;
{
tree type = BINFO_TYPE (binfo);
- if (i >= 0)
- type = BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo), i));
if (TYPE_HAS_DESTRUCTOR (type)
&& DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1)))
return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1);
--- 1698,1707 ----
}
static tree
! get_virtual_destructor (binfo)
tree binfo;
{
tree type = BINFO_TYPE (binfo);
if (TYPE_HAS_DESTRUCTOR (type)
&& DECL_VINDEX (TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1)))
return TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), 1);
*************** get_virtual_destructor (binfo, i)
*** 1712,1724 ****
}
static int
! tree_has_any_destructor_p (binfo, i)
tree binfo;
- int i;
{
tree type = BINFO_TYPE (binfo);
- if (i >= 0)
- type = BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo), i));
return TYPE_NEEDS_DESTRUCTOR (type);
}
--- 1709,1718 ----
}
static int
! tree_has_any_destructor_p (binfo)
tree binfo;
{
tree type = BINFO_TYPE (binfo);
return TYPE_NEEDS_DESTRUCTOR (type);
}
*************** get_matching_virtual (binfo, fndecl, dto
*** 1803,1818 ****
of TYPE, so we must perform first ply of search here. */
if (dtorp)
{
! if (tree_has_any_destructor_p (binfo, -1))
! tmp = get_virtual_destructor (binfo, -1);
!
! if (tmp)
! return tmp;
!
! tmp = (tree) breadth_first_search (binfo,
! (pfi) get_virtual_destructor,
! tree_has_any_destructor_p);
! return tmp;
}
else
{
--- 1797,1805 ----
of TYPE, so we must perform first ply of search here. */
if (dtorp)
{
! return breadth_first_search (binfo,
! get_virtual_destructor,
! tree_has_any_destructor_p);
}
else
{
*************** reinit_search_statistics ()
*** 3284,3290 ****
#define scratch_tree_cons expr_tree_cons
static tree conversions;
! static void
add_conversions (binfo)
tree binfo;
{
--- 3271,3277 ----
#define scratch_tree_cons expr_tree_cons
static tree conversions;
! static tree
add_conversions (binfo)
tree binfo;
{
*************** add_conversions (binfo)
*** 3297,3317 ****
if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp)))
break;
! conversions = scratch_tree_cons (binfo, tmp, conversions);
}
! SET_BINFO_MARKED (binfo);
}
tree
lookup_conversions (type)
tree type;
{
conversions = NULL_TREE;
if (TYPE_SIZE (type))
! {
! dfs_walk (TYPE_BINFO (type), add_conversions, unmarkedp);
! dfs_walk (TYPE_BINFO (type), dfs_unmark, markedp);
! }
return conversions;
}
--- 3284,3314 ----
if (!tmp || ! DECL_CONV_FN_P (OVL_CURRENT (tmp)))
break;
!
! /* Make sure we don't already have this conversion. */
! if (! IDENTIFIER_MARKED (DECL_NAME (tmp)))
! {
! conversions = scratch_tree_cons (binfo, tmp, conversions);
! IDENTIFIER_MARKED (DECL_NAME (tmp)) = 1;
! }
}
! return NULL_TREE;
}
tree
lookup_conversions (type)
tree type;
{
+ tree t;
+
conversions = NULL_TREE;
+
if (TYPE_SIZE (type))
! breadth_first_search (TYPE_BINFO (type), add_conversions, 0);
!
! for (t = conversions; t; t = TREE_CHAIN (t))
! IDENTIFIER_MARKED (DECL_NAME (TREE_VALUE (t))) = 0;
!
return conversions;
}