Commit c8a209ca by Nathan Sidwell Committed by Nathan Sidwell

cp-tree.h (COMPARE_RELAXED): Rename to ...

	* cp-tree.h (COMPARE_RELAXED): Rename to ...
	(COMPARE_DERIVED): ... here. Adjust comment.
	(resolve_typename_type_in_current_instantiation): Remove.
	(cp_tree_equal, comptypes): Return a bool.
	* cvt.c (convert_to_reference): Adjust comptypes call.
	* pt.c (template_args_equal, unify,): Adjust cp_tree_equal call.
	(resolve_typename_type_in_current_instantiation): Remove.
	* tree.c (cp_tree_equal): Return bool. Cope with TEMPLATE_DECLs and
	IDENTIFIER_NODEs. Abort if undeciderable. Adjust recursive
	calls. Refactor code.
	* typeck.c (comp_array_types): Return bool. Lose callback.
	parameter. Adjust cp_tree_equal calls.
	(comptypes): Return bool. Adjust strict handling. Remove relaxed
	enumeration and java type handling. Deal with typename types here.
	Adjust recursive and cp_tree_equals calls. Adjust base and derived
	checking.
	(comp_target_types): Remove unreachable code. Adjust
	same_or_base_type_p calls.
	(ptr_reasonably_similar): Adjust base and derived check.

	* typeck.c (maybe_warn_about_returning_address_of_local): Remove
	unused calculation.
	(check_return_expr): Adjust error messages.
	* cp-tree.def (SCOPE_REF): Correct comment.

From-SVN: r68155
parent c76abc12
2003-06-18 Nathan Sidwell <nathan@codesourcery.com>
* cp-tree.h (COMPARE_RELAXED): Rename to ...
(COMPARE_DERIVED): ... here. Adjust comment.
(resolve_typename_type_in_current_instantiation): Remove.
(cp_tree_equal, comptypes): Return a bool.
* cvt.c (convert_to_reference): Adjust comptypes call.
* pt.c (template_args_equal, unify,): Adjust cp_tree_equal call.
(resolve_typename_type_in_current_instantiation): Remove.
* tree.c (cp_tree_equal): Return bool. Cope with TEMPLATE_DECLs and
IDENTIFIER_NODEs. Abort if undeciderable. Adjust recursive
calls. Refactor code.
* typeck.c (comp_array_types): Return bool. Lose callback.
parameter. Adjust cp_tree_equal calls.
(comptypes): Return bool. Adjust strict handling. Remove relaxed
enumeration and java type handling. Deal with typename types here.
Adjust recursive and cp_tree_equals calls. Adjust base and derived
checking.
(comp_target_types): Remove unreachable code. Adjust
same_or_base_type_p calls.
(ptr_reasonably_similar): Adjust base and derived check.
* typeck.c (maybe_warn_about_returning_address_of_local): Remove
unused calculation.
(check_return_expr): Adjust error messages.
* cp-tree.def (SCOPE_REF): Correct comment.
2003-06-17 Mark Mitchell <mark@codesourcery.com>
* mangle.c (mangle_conv_op_name_for_type): Correct sprintf format
......
......@@ -62,8 +62,7 @@ DEFTREECODE (DELETE_EXPR, "dl_expr", 'e', 2)
DEFTREECODE (VEC_DELETE_EXPR, "vec_dl_expr", 'e', 2)
/* Value is reference to particular overloaded class method.
Operand 0 is the class name (an IDENTIFIER_NODE);
operand 1 is the field (also an IDENTIFIER_NODE).
Operand 0 is the class, operand 1 is the field
The COMPLEXITY field holds the class level (usually 0). */
DEFTREECODE (SCOPE_REF, "scope_ref", 'r', 2)
......
......@@ -3367,15 +3367,9 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, OP_FLAG, TYPENAME_FLAG };
#define COMPARE_STRICT 0 /* Just check if the types are the
same. */
#define COMPARE_BASE 1 /* Check to see if the second type is
derived from the first, or if both
are pointers (or references) and
the types pointed to by the second
type is derived from the pointed to
by the first. */
#define COMPARE_RELAXED 2 /* Like COMPARE_DERIVED, but in
reverse. Also treat enumeration
types as the same as integer types
of the same width. */
derived from the first. */
#define COMPARE_DERIVED 2 /* Like COMPARE_BASE, but in
reverse. */
#define COMPARE_REDECLARATION 4 /* The comparsion is being done when
another declaration of an existing
entity is seen. */
......@@ -3982,7 +3976,6 @@ extern bool dependent_template_p (tree);
extern bool type_dependent_expression_p (tree);
extern bool value_dependent_expression_p (tree);
extern tree resolve_typename_type (tree, bool);
extern tree resolve_typename_type_in_current_instantiation (tree);
extern tree template_for_substitution (tree);
/* in repo.c */
......@@ -4204,7 +4197,7 @@ extern tree error_type (tree);
extern tree build_zc_wrapper (struct z_candidate *);
extern int varargs_function_p (tree);
extern int really_overloaded_fn (tree);
extern int cp_tree_equal (tree, tree);
extern bool cp_tree_equal (tree, tree);
extern tree no_linkage_check (tree);
extern void debug_binfo (tree);
extern tree build_dummy_object (tree);
......@@ -4247,7 +4240,7 @@ extern int type_unknown_p (tree);
extern tree commonparms (tree, tree);
extern tree original_type (tree);
extern int comp_except_specs (tree, tree, int);
extern int comptypes (tree, tree, int);
extern bool comptypes (tree, tree, int);
extern int comp_target_types (tree, tree, int);
extern int compparms (tree, tree);
extern int comp_cv_qualification (tree, tree);
......
......@@ -507,10 +507,10 @@ convert_to_reference (tree reftype, tree expr, int convtype,
/* B* bp; A& ar = (A&)bp; is valid, but it's probably not what they
meant. */
if (TREE_CODE (intype) == POINTER_TYPE
&& (comptypes (TREE_TYPE (intype), type,
COMPARE_BASE | COMPARE_RELAXED )))
&& (comptypes (TREE_TYPE (intype), type,
COMPARE_BASE | COMPARE_DERIVED)))
warning ("casting `%T' to `%T' does not dereference pointer",
intype, reftype);
intype, reftype);
rval = build_unary_op (ADDR_EXPR, expr, 0);
if (rval != error_mark_node)
......
......@@ -3811,7 +3811,7 @@ template_args_equal (ot, nt)
else if (TREE_CODE (ot) == TREE_VEC || TYPE_P (ot))
return 0;
else
return (cp_tree_equal (ot, nt) > 0);
return cp_tree_equal (ot, nt);
}
/* Returns 1 iff the OLDARGS and NEWARGS are in fact identical sets
......@@ -9638,22 +9638,14 @@ unify (tparms, targs, parm, arg, strict)
!= template_decl_level (tparm))
/* The PARM is not one we're trying to unify. Just check
to see if it matches ARG. */
return (TREE_CODE (arg) == TREE_CODE (parm)
&& cp_tree_equal (parm, arg) > 0) ? 0 : 1;
return !(TREE_CODE (arg) == TREE_CODE (parm)
&& cp_tree_equal (parm, arg));
idx = TEMPLATE_PARM_IDX (parm);
targ = TREE_VEC_ELT (targs, idx);
if (targ)
{
int i = (cp_tree_equal (targ, arg) > 0);
if (i == 1)
return 0;
else if (i == 0)
return 1;
else
abort ();
}
return !cp_tree_equal (targ, arg);
/* [temp.deduct.type] If, in the declaration of a function template
with a non-type template-parameter, the non-type
......@@ -11798,13 +11790,4 @@ resolve_typename_type (tree type, bool only_current_p)
return type;
}
tree
resolve_typename_type_in_current_instantiation (tree type)
{
tree t;
t = resolve_typename_type (type, /*only_current_p=*/true);
return (t != error_mark_node) ? t : type;
}
#include "gt-cp-pt.h"
......@@ -1552,38 +1552,35 @@ decl_namespace_context (tree decl)
}
/* Return truthvalue of whether T1 is the same tree structure as T2.
Return 1 if they are the same.
Return 0 if they are understandably different.
Return -1 if either contains tree structure not understood by
this function. */
Return 1 if they are the same. Return 0 if they are different. */
int
bool
cp_tree_equal (tree t1, tree t2)
{
register enum tree_code code1, code2;
int cmp;
if (t1 == t2)
return 1;
if (t1 == 0 || t2 == 0)
return 0;
code1 = TREE_CODE (t1);
code2 = TREE_CODE (t2);
if (code1 == NOP_EXPR || code1 == CONVERT_EXPR || code1 == NON_LVALUE_EXPR)
{
if (code2 == NOP_EXPR || code2 == CONVERT_EXPR || code2 == NON_LVALUE_EXPR)
return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
else
return cp_tree_equal (TREE_OPERAND (t1, 0), t2);
}
else if (code2 == NOP_EXPR || code2 == CONVERT_EXPR
|| code2 == NON_LVALUE_EXPR)
return cp_tree_equal (t1, TREE_OPERAND (t2, 0));
return true;
if (!t1 || !t2)
return false;
for (code1 = TREE_CODE (t1);
code1 == NOP_EXPR || code1 == CONVERT_EXPR
|| code1 == NON_LVALUE_EXPR;
code1 = TREE_CODE (t1))
t1 = TREE_OPERAND (t1, 0);
for (code2 = TREE_CODE (t2);
code2 == NOP_EXPR || code2 == CONVERT_EXPR
|| code1 == NON_LVALUE_EXPR;
code2 = TREE_CODE (t2))
t2 = TREE_OPERAND (t2, 0);
/* They might have become equal now. */
if (t1 == t2)
return true;
if (code1 != code2)
return 0;
return false;
switch (code1)
{
......@@ -1597,7 +1594,7 @@ cp_tree_equal (tree t1, tree t2)
case STRING_CST:
return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
&& !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
TREE_STRING_LENGTH (t1));
TREE_STRING_LENGTH (t1));
case CONSTRUCTOR:
/* We need to do this when determining whether or not two
......@@ -1606,61 +1603,62 @@ cp_tree_equal (tree t1, tree t2)
if (!(same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))
/* The first operand is RTL. */
&& TREE_OPERAND (t1, 0) == TREE_OPERAND (t2, 0)))
return 0;
return false;
return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
case TREE_LIST:
cmp = cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2));
if (cmp <= 0)
return cmp;
cmp = cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2));
if (cmp <= 0)
return cmp;
if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2)))
return false;
if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2)))
return false;
return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2));
case SAVE_EXPR:
return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
case CALL_EXPR:
cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
if (cmp <= 0)
return cmp;
return simple_cst_list_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
case TARGET_EXPR:
/* Special case: if either target is an unallocated VAR_DECL,
it means that it's going to be unified with whatever the
TARGET_EXPR is really supposed to initialize, so treat it
as being equivalent to anything. */
if ((TREE_CODE (TREE_OPERAND (t1, 0)) == VAR_DECL
&& DECL_NAME (TREE_OPERAND (t1, 0)) == NULL_TREE
&& !DECL_RTL_SET_P (TREE_OPERAND (t1, 0)))
|| (TREE_CODE (TREE_OPERAND (t2, 0)) == VAR_DECL
&& DECL_NAME (TREE_OPERAND (t2, 0)) == NULL_TREE
&& !DECL_RTL_SET_P (TREE_OPERAND (t2, 0))))
cmp = 1;
else
cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
if (cmp <= 0)
return cmp;
if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
return false;
return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
case TARGET_EXPR:
{
tree o1 = TREE_OPERAND (t1, 0);
tree o2 = TREE_OPERAND (t2, 0);
/* Special case: if either target is an unallocated VAR_DECL,
it means that it's going to be unified with whatever the
TARGET_EXPR is really supposed to initialize, so treat it
as being equivalent to anything. */
if (TREE_CODE (o1) == VAR_DECL && DECL_NAME (o1) == NULL_TREE
&& !DECL_RTL_SET_P (o1))
/*Nop*/;
else if (TREE_CODE (o2) == VAR_DECL && DECL_NAME (o2) == NULL_TREE
&& !DECL_RTL_SET_P (o2))
/*Nop*/;
else if (!cp_tree_equal (o1, o2))
return false;
return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1));
}
case WITH_CLEANUP_EXPR:
cmp = cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
if (cmp <= 0)
return cmp;
if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)))
return false;
return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1));
case COMPONENT_REF:
if (TREE_OPERAND (t1, 1) == TREE_OPERAND (t2, 1))
return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
return 0;
if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1))
return false;
return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
case VAR_DECL:
case PARM_DECL:
case CONST_DECL:
case FUNCTION_DECL:
return 0;
case TEMPLATE_DECL:
case IDENTIFIER_NODE:
return false;
case TEMPLATE_PARM_INDEX:
return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2)
......@@ -1670,17 +1668,25 @@ cp_tree_equal (tree t1, tree t2)
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
if (TREE_CODE (TREE_OPERAND (t1, 0)) != TREE_CODE (TREE_OPERAND (t2, 0)))
return 0;
if (TYPE_P (TREE_OPERAND (t1, 0)))
return same_type_p (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
break;
{
tree o1 = TREE_OPERAND (t1, 0);
tree o2 = TREE_OPERAND (t2, 0);
if (TREE_CODE (o1) != TREE_CODE (o2))
return false;
if (TYPE_P (o1))
return same_type_p (o1, o2);
else
return cp_tree_equal (o1, o2);
}
case PTRMEM_CST:
/* Two pointer-to-members are the same if they point to the same
field or function in the same class. */
return (PTRMEM_CST_MEMBER (t1) == PTRMEM_CST_MEMBER (t2)
&& same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2)));
if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2))
return false;
return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2));
default:
break;
......@@ -1697,21 +1703,19 @@ cp_tree_equal (tree t1, tree t2)
{
int i;
cmp = 1;
for (i = 0; i < TREE_CODE_LENGTH (code1); ++i)
{
cmp = cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i));
if (cmp <= 0)
return cmp;
}
return cmp;
if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i)))
return false;
return true;
}
case 't':
return same_type_p (t1, t2) ? 1 : 0;
case 't':
return same_type_p (t1, t2);
}
return -1;
my_friendly_assert (0, 20030617);
return false;
}
/* Build a wrapper around a 'struct z_candidate' so we can use it as a
......
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