This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[C++ patch] cleanup


Hi,
I've installed the attached patch which replaces magic constants 
to instantiate_type with a new enumeration instantiate_type_flags.

[I'm working on getting pointer-to-member syntax fixed, and will
be adding a flag to this.]

built & tested on i686-pc-linux-gnu approved by Mark.

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2000-08-17  Nathan Sidwell  <nathan@codesourcery.com>

	* cp-tree.h (instantiate_type_flags): New enumeration.
	(instantiate_type): Change parameter.
	* class.c (instantiate_type): Adjust prototype. Adjust.
	* call.c (standard_conversion): Adjust instantiate_type call.
	(reference_binding): Likewise.
	(build_op_delete_call): Likewise.
	(convert_like_real): Likewise.
	* cvt.c (cp_convert_to_pointer): Likewise.
	(convert_to_reference): Likewise.
	* pt.c (convert_nontype_argument): Likewise.
	* typeck.c (build_binary_op): Likewise.
	(build_ptrmemfunc): Likewise.
	(convert_for_assignment): Likewise.

Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.228
diff -c -3 -p -r1.228 call.c
*** call.c	2000/07/17 21:35:46	1.228
--- call.c	2000/08/17 12:59:21
*************** standard_conversion (to, from, expr)
*** 657,663 ****
    if ((TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
        && expr && type_unknown_p (expr))
      {
!       expr = instantiate_type (to, expr, 0);
        if (expr == error_mark_node)
  	return NULL_TREE;
        from = TREE_TYPE (expr);
--- 657,663 ----
    if ((TYPE_PTRFN_P (to) || TYPE_PTRMEMFUNC_P (to))
        && expr && type_unknown_p (expr))
      {
!       expr = instantiate_type (to, expr, itf_none);
        if (expr == error_mark_node)
  	return NULL_TREE;
        from = TREE_TYPE (expr);
*************** reference_binding (rto, rfrom, expr, fla
*** 1043,1049 ****
  
    if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
      {
!       expr = instantiate_type (to, expr, 0);
        if (expr == error_mark_node)
  	return NULL_TREE;
        from = TREE_TYPE (expr);
--- 1043,1049 ----
  
    if (TREE_CODE (to) == FUNCTION_TYPE && expr && type_unknown_p (expr))
      {
!       expr = instantiate_type (to, expr, itf_none);
        if (expr == error_mark_node)
  	return NULL_TREE;
        from = TREE_TYPE (expr);
*************** build_op_delete_call (code, addr, size, 
*** 3555,3561 ****
    if (type != TYPE_MAIN_VARIANT (type))
      addr = cp_convert (build_pointer_type (TYPE_MAIN_VARIANT (type)), addr);
  
!   fn = instantiate_type (fntype, fns, 2);
  
    if (fn != error_mark_node)
      {
--- 3555,3561 ----
    if (type != TYPE_MAIN_VARIANT (type))
      addr = cp_convert (build_pointer_type (TYPE_MAIN_VARIANT (type)), addr);
  
!   fn = instantiate_type (fntype, fns, itf_no_attributes);
  
    if (fn != error_mark_node)
      {
*************** build_op_delete_call (code, addr, size, 
*** 3575,3581 ****
  			tree_cons (NULL_TREE, sizetype, void_list_node));
    fntype = build_function_type (void_type_node, argtypes);
  
!   fn = instantiate_type (fntype, fns, 2);
  
    if (fn != error_mark_node)
      {
--- 3575,3581 ----
  			tree_cons (NULL_TREE, sizetype, void_list_node));
    fntype = build_function_type (void_type_node, argtypes);
  
!   fn = instantiate_type (fntype, fns, itf_no_attributes);
  
    if (fn != error_mark_node)
      {
*************** convert_like_real (convs, expr, fn, argn
*** 3694,3700 ****
        }
      case IDENTITY_CONV:
        if (type_unknown_p (expr))
! 	expr = instantiate_type (TREE_TYPE (convs), expr, 1);
        return expr;
      case AMBIG_CONV:
        /* Call build_user_type_conversion again for the error.  */
--- 3694,3700 ----
        }
      case IDENTITY_CONV:
        if (type_unknown_p (expr))
! 	expr = instantiate_type (TREE_TYPE (convs), expr, itf_complain);
        return expr;
      case AMBIG_CONV:
        /* Call build_user_type_conversion again for the error.  */
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/class.c,v
retrieving revision 1.328
diff -c -3 -p -r1.328 class.c
*** class.c	2000/08/04 18:40:59	1.328
--- class.c	2000/08/17 12:59:22
*************** resolve_address_of_overloaded_function (
*** 5977,6000 ****
  
  /* This function will instantiate the type of the expression given in
     RHS to match the type of LHSTYPE.  If errors exist, then return
!    error_mark_node.  We only complain is COMPLAIN is set.  If we are
!    not complaining, never modify rhs, as overload resolution wants to
!    try many possible instantiations, in hopes that at least one will
!    work.
! 
!    FLAGS is a bitmask, as we see at the top of the function.
! 
     For non-recursive calls, LHSTYPE should be a function, pointer to
     function, or a pointer to member function.  */
  
  tree
  instantiate_type (lhstype, rhs, flags)
       tree lhstype, rhs;
!      int flags;
  {
!   int complain = (flags & 1);
!   int strict = (flags & 2) ? COMPARE_NO_ATTRIBUTES : COMPARE_STRICT;
!   tree r;
  
    if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
      {
--- 5977,5998 ----
  
  /* This function will instantiate the type of the expression given in
     RHS to match the type of LHSTYPE.  If errors exist, then return
!    error_mark_node. FLAGS is a bit mask.  If ITF_COMPLAIN is set, then
!    we complain on errors.  If we are not complaining, never modify rhs,
!    as overload resolution wants to try many possible instantiations, in
!    the hope that at least one will work.
!    
     For non-recursive calls, LHSTYPE should be a function, pointer to
     function, or a pointer to member function.  */
  
  tree
  instantiate_type (lhstype, rhs, flags)
       tree lhstype, rhs;
!      enum instantiate_type_flags flags;
  {
!   int complain = (flags & itf_complain);
!   int strict = (flags & itf_no_attributes)
!                ? COMPARE_NO_ATTRIBUTES : COMPARE_STRICT;
  
    if (TREE_CODE (lhstype) == UNKNOWN_TYPE)
      {
Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cp-tree.h,v
retrieving revision 1.511
diff -c -3 -p -r1.511 cp-tree.h
*** cp-tree.h	2000/08/17 12:26:39	1.511
--- cp-tree.h	2000/08/17 12:59:24
*************** typedef enum special_function_kind {
*** 3204,3209 ****
--- 3204,3216 ----
    sfk_conversion           /* A conversion operator.  */
  } special_function_kind;
  
+ /* Bitmask flags to pass to instantiate_type.  */
+ typedef enum instantiate_type_flags {
+   itf_none = 0,               /* nothing special */
+   itf_complain = 1 << 0,      /* complain about errors */
+   itf_no_attributes = 1 << 1  /* ignore attributes on comparisons */
+ } instantiate_type_flags;
+ 
  /* Non-zero means that if a label exists, and no other identifier
     applies, use the value of the label.  */
  extern int flag_labels_ok;
*************** extern void push_nested_class			PARAMS (
*** 3822,3828 ****
  extern void pop_nested_class			PARAMS ((void));
  extern void push_lang_context			PARAMS ((tree));
  extern void pop_lang_context			PARAMS ((void));
! extern tree instantiate_type			PARAMS ((tree, tree, int));
  extern void print_class_statistics		PARAMS ((void));
  extern int first_vfun_index                     PARAMS ((tree));
  extern void build_self_reference		PARAMS ((void));
--- 3829,3835 ----
  extern void pop_nested_class			PARAMS ((void));
  extern void push_lang_context			PARAMS ((tree));
  extern void pop_lang_context			PARAMS ((void));
! extern tree instantiate_type			PARAMS ((tree, tree, enum instantiate_type_flags));
  extern void print_class_statistics		PARAMS ((void));
  extern int first_vfun_index                     PARAMS ((tree));
  extern void build_self_reference		PARAMS ((void));
Index: cp/cvt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cvt.c,v
retrieving revision 1.87
diff -c -3 -p -r1.87 cvt.c
*** cvt.c	2000/08/14 10:18:15	1.87
--- cvt.c	2000/08/17 12:59:24
*************** cp_convert_to_pointer (type, expr)
*** 267,273 ****
      }
  
    if (type_unknown_p (expr))
!     return instantiate_type (type, expr, 1);
  
    cp_error ("cannot convert `%E' from type `%T' to type `%T'",
  	    expr, intype, type);
--- 267,273 ----
      }
  
    if (type_unknown_p (expr))
!     return instantiate_type (type, expr, itf_no_attributes);
  
    cp_error ("cannot convert `%E' from type `%T' to type `%T'",
  	    expr, intype, type);
*************** convert_to_reference (reftype, expr, con
*** 464,470 ****
    if (TREE_CODE (type) == FUNCTION_TYPE && intype == unknown_type_node)
      {
        expr = instantiate_type (type, expr, 
! 			       (flags & LOOKUP_COMPLAIN) != 0);
        if (expr == error_mark_node)
  	return error_mark_node;
  
--- 464,471 ----
    if (TREE_CODE (type) == FUNCTION_TYPE && intype == unknown_type_node)
      {
        expr = instantiate_type (type, expr, 
! 			       (flags & LOOKUP_COMPLAIN)
! 	                       ? itf_complain : itf_none);
        if (expr == error_mark_node)
  	return error_mark_node;
  
Index: cp/pt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/pt.c,v
retrieving revision 1.457
diff -c -3 -p -r1.457 pt.c
*** pt.c	2000/08/17 12:26:39	1.457
--- pt.c	2000/08/17 12:59:27
*************** convert_nontype_argument (type, expr)
*** 2911,2917 ****
  	    else
  	      fns = expr;
  
! 	    fn = instantiate_type (type_pointed_to, fns, 0);
  
  	    if (fn == error_mark_node)
  	      return error_mark_node;
--- 2911,2917 ----
  	    else
  	      fns = expr;
  
! 	    fn = instantiate_type (type_pointed_to, fns, itf_none);
  
  	    if (fn == error_mark_node)
  	      return error_mark_node;
*************** convert_nontype_argument (type, expr)
*** 2976,2982 ****
  	       set (_over.over_).  */
  	    tree fn;
  
! 	    fn = instantiate_type (type_referred_to, expr, 0);
  
  	    if (fn == error_mark_node)
  	      return error_mark_node;
--- 2976,2982 ----
  	       set (_over.over_).  */
  	    tree fn;
  
! 	    fn = instantiate_type (type_referred_to, expr, itf_none);
  
  	    if (fn == error_mark_node)
  	      return error_mark_node;
*************** convert_nontype_argument (type, expr)
*** 3051,3057 ****
  	if (TREE_CODE (expr) != ADDR_EXPR)
  	  return error_mark_node;
  
! 	expr = instantiate_type (type, expr, 0);
  	
  	if (expr == error_mark_node)
  	  return error_mark_node;
--- 3051,3057 ----
  	if (TREE_CODE (expr) != ADDR_EXPR)
  	  return error_mark_node;
  
! 	expr = instantiate_type (type, expr, itf_none);
  	
  	if (expr == error_mark_node)
  	  return error_mark_node;
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.302
diff -c -3 -p -r1.302 typeck.c
*** typeck.c	2000/07/28 06:05:11	1.302
--- typeck.c	2000/08/17 12:59:31
*************** build_binary_op (code, orig_op0, orig_op
*** 3344,3350 ****
    /* DTRT if one side is an overloaded function, but complain about it.  */
    if (type_unknown_p (op0))
      {
!       tree t = instantiate_type (TREE_TYPE (op1), op0, 0);
        if (t != error_mark_node)
  	{
  	  cp_pedwarn ("assuming cast to type `%T' from overloaded function",
--- 3344,3350 ----
    /* DTRT if one side is an overloaded function, but complain about it.  */
    if (type_unknown_p (op0))
      {
!       tree t = instantiate_type (TREE_TYPE (op1), op0, itf_none);
        if (t != error_mark_node)
  	{
  	  cp_pedwarn ("assuming cast to type `%T' from overloaded function",
*************** build_binary_op (code, orig_op0, orig_op
*** 3354,3360 ****
      }
    if (type_unknown_p (op1))
      {
!       tree t = instantiate_type (TREE_TYPE (op0), op1, 0);
        if (t != error_mark_node)
  	{
  	  cp_pedwarn ("assuming cast to type `%T' from overloaded function",
--- 3354,3360 ----
      }
    if (type_unknown_p (op1))
      {
!       tree t = instantiate_type (TREE_TYPE (op0), op1, itf_none);
        if (t != error_mark_node)
  	{
  	  cp_pedwarn ("assuming cast to type `%T' from overloaded function",
*************** build_ptrmemfunc (type, pfn, force)
*** 6199,6205 ****
      }
  
    if (type_unknown_p (pfn))
!     return instantiate_type (type, pfn, 1);
  
    fn = TREE_OPERAND (pfn, 0);
    my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 0);
--- 6199,6205 ----
      }
  
    if (type_unknown_p (pfn))
!     return instantiate_type (type, pfn, itf_complain);
  
    fn = TREE_OPERAND (pfn, 0);
    my_friendly_assert (TREE_CODE (fn) == FUNCTION_DECL, 0);
*************** convert_for_assignment (type, rhs, errty
*** 6464,6470 ****
  	     overloaded function.  Call instantiate_type to get error
  	     messages.  */
  	  if (rhstype == unknown_type_node)
! 	    instantiate_type (type, rhs, 1);
  	  else if (fndecl)
  	    cp_error ("cannot convert `%T' to `%T' for argument `%P' to `%D'",
  		      rhstype, type, parmnum, fndecl);
--- 6464,6470 ----
  	     overloaded function.  Call instantiate_type to get error
  	     messages.  */
  	  if (rhstype == unknown_type_node)
! 	    instantiate_type (type, rhs, itf_complain);
  	  else if (fndecl)
  	    cp_error ("cannot convert `%T' to `%T' for argument `%P' to `%D'",
  		      rhstype, type, parmnum, fndecl);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]