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]

Patch: revised PR gcj/307 patch


Yesterday's patch for PR gcj/307 had a serious bug.
Here is the revised patch.  I tested this patch by doing a clean
rebuild of libjava.

2000-09-07  Tom Tromey  <tromey@cygnus.com>

	Fix for PR gcj/307:
	* parse.y (patch_binop): Use JNUMERIC_TYPE_P, not
	JPRIMITIVE_TYPE_P, for arithmetic operators.
	(patch_method_invocation): Indentation fix.
	(try_builtin_assignconv): Handle boolean specially.  Fixed typo.
	(valid_builtin_assignconv_identity_widening_p): Handle boolean.
	(do_unary_numeric_promotion): Cleaned up code.
	(valid_cast_to_p): Handle boolean correctly.

Tom

Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.207
diff -u -r1.207 parse.y
--- parse.y	2000/09/06 02:37:09	1.207
+++ parse.y	2000/09/08 19:08:00
@@ -9618,13 +9619,13 @@
       
       if (JPRIMITIVE_TYPE_P (type))
         {
-        parse_error_context
-          (identifier_wfl,
-          "Can't invoke a method on primitive type `%s'",
-          IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
-        PATCH_METHOD_RETURN_ERROR ();         
-      }      
-      
+	  parse_error_context
+	    (identifier_wfl,
+	     "Can't invoke a method on primitive type `%s'",
+	     IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
+	  PATCH_METHOD_RETURN_ERROR ();         
+	}
+
       list = lookup_method_invoke (0, identifier_wfl, type, identifier, args);
       args = nreverse (args);
 
@@ -12140,8 +12141,17 @@
   tree new_rhs = NULL_TREE;
   tree rhs_type = TREE_TYPE (rhs);
 
+  /* Handle boolean specially.  */
+  if (TREE_CODE (rhs_type) == BOOLEAN_TYPE
+      || TREE_CODE (lhs_type) == BOOLEAN_TYPE)
+    {
+      if (TREE_CODE (rhs_type) == BOOLEAN_TYPE
+	  && TREE_CODE (lhs_type) == BOOLEAN_TYPE)
+	new_rhs = rhs;
+    }
+
   /* Zero accepted everywhere */
-  if (TREE_CODE (rhs) == INTEGER_CST 
+  else if (TREE_CODE (rhs) == INTEGER_CST 
       && TREE_INT_CST_HIGH (rhs) == 0 && TREE_INT_CST_LOW (rhs) == 0
       && JPRIMITIVE_TYPE_P (rhs_type))
     new_rhs = convert (lhs_type, rhs);
@@ -12164,7 +12174,7 @@
         new_rhs = convert (lhs_type, rhs);
       else if (wfl_op1)		/* Might be called with a NULL */
 	parse_warning_context 
-	  (wfl_op1, "Constant expression `%s' to wide for narrowing primitive conversion to `%s'", 
+	  (wfl_op1, "Constant expression `%s' too wide for narrowing primitive conversion to `%s'", 
 	   print_int_node (rhs), lang_printable_name (lhs_type, 0));
       /* Reported a warning that will turn into an error further
 	 down, so we don't return */
@@ -12186,8 +12196,8 @@
   if (lhs_type == rhs_type)
     return 1;
 
-  /* Reject non primitive types */
-  if (!JPRIMITIVE_TYPE_P (lhs_type) || !JPRIMITIVE_TYPE_P (rhs_type))
+  /* Reject non primitive types and boolean conversions.  */
+  if (!JNUMERIC_TYPE_P (lhs_type) || !JNUMERIC_TYPE_P (rhs_type))
     return 0;
 
   /* 5.1.2: widening primitive conversion. byte, even if it's smaller
@@ -12350,20 +12360,20 @@
   else if (JNUMERIC_TYPE_P (source) && JNUMERIC_TYPE_P (dest))
     return 1;
 
+  else if (TREE_CODE (source) == BOOLEAN_TYPE
+	   && TREE_CODE (dest) == BOOLEAN_TYPE)
+    return 1;
+
   return 0;
 }
 
-/* Method invocation conversion test. Return 1 if type SOURCE can be
-   converted to type DEST through the methond invocation conversion
-   process (5.3) */
-
 static tree
 do_unary_numeric_promotion (arg)
      tree arg;
 {
   tree type = TREE_TYPE (arg);
-  if (TREE_CODE (type) == INTEGER_TYPE ? TYPE_PRECISION (type) < 32
-      : TREE_CODE (type) == CHAR_TYPE)
+  if ((TREE_CODE (type) == INTEGER_TYPE && TYPE_PRECISION (type) < 32)
+      || TREE_CODE (type) == CHAR_TYPE)
     arg = convert (int_type_node, arg);
   return arg;
 }
@@ -12558,11 +12568,11 @@
     case RDIV_EXPR:		/* 15.16.2 Division Operator / */
     case TRUNC_DIV_EXPR:	/* 15.16.2 Integral type Division Operator / */
     case TRUNC_MOD_EXPR:	/* 15.16.3 Remainder operator % */
-      if (!JPRIMITIVE_TYPE_P (op1_type) || !JPRIMITIVE_TYPE_P (op2_type))
+      if (!JNUMERIC_TYPE_P (op1_type) || !JNUMERIC_TYPE_P (op2_type))
 	{
-	  if (!JPRIMITIVE_TYPE_P (op1_type))
+	  if (!JNUMERIC_TYPE_P (op1_type))
 	    ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
-	  if (!JPRIMITIVE_TYPE_P (op2_type) && (op1_type != op2_type))
+	  if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
 	    ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
 	  TREE_TYPE (node) = error_mark_node;
 	  error_found = 1;
@@ -12610,11 +12620,11 @@
 
     case MINUS_EXPR:		/* 15.17.2 Additive Operators (+ and -) for
 				   Numeric Types */
-      if (!JPRIMITIVE_TYPE_P (op1_type) || !JPRIMITIVE_TYPE_P (op2_type))
+      if (!JNUMERIC_TYPE_P (op1_type) || !JNUMERIC_TYPE_P (op2_type))
 	{
-	  if (!JPRIMITIVE_TYPE_P (op1_type))
+	  if (!JNUMERIC_TYPE_P (op1_type))
 	    ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op1_type);
-	  if (!JPRIMITIVE_TYPE_P (op2_type) && (op1_type != op2_type))
+	  if (!JNUMERIC_TYPE_P (op2_type) && (op1_type != op2_type))
 	    ERROR_CANT_CONVERT_TO_NUMERIC (wfl_operator, node, op2_type);
 	  TREE_TYPE (node) = error_mark_node;
 	  error_found = 1;
@@ -12633,7 +12643,7 @@
 	    ERROR_CAST_NEEDED_TO_INTEGRAL (wfl_operator, node, op1_type);
 	  else
 	    {
-	      if (JPRIMITIVE_TYPE_P (op2_type))
+	      if (JNUMERIC_TYPE_P (op2_type))
 		parse_error_context (wfl_operator,
 				     "Incompatible type for `%s'. Explicit cast needed to convert shift distance from `%s' to integral",
 				     operator_string (node),

Index: typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/typeck.c,v
retrieving revision 1.29
diff -u -r1.29 typeck.c
--- typeck.c	2000/08/29 22:15:21	1.29
+++ typeck.c	2000/09/07 22:38:49
@@ -874,7 +874,7 @@
 
 /* Return a type which is the Binary Numeric Promotion of the pair T1,
    T2 and convert EXP1 and/or EXP2. See 5.6.2 Binary Numeric
-   Promotion. It assumes that both T1 and T2 are elligible to BNP. */
+   Promotion. It assumes that both T1 and T2 are eligible to BNP. */
 
 tree
 binary_numeric_promotion (t1, t2, exp1, exp2)

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