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


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

[PATCH] Java: misc fixes, fix to PR java/1413.



This fixes a Jacks test case, java/1413, let Mauve build again and
fixes some other issues that were recently brought up:

  http://gcc.gnu.org/ml/java/2001-08/msg00121.html
  http://gcc.gnu.org/ml/java-prs/2000-q4/msg00156.html
  http://gcc.gnu.org/ml/gcc-patches/2001-08/msg01745.html
  http://gcc.gnu.org/ml/gcc-patches/2001-08/msg01643.html

It's been tested, it comes with two new test cases:

  http://gcc.gnu.org/ml/java-patches/2001-q3/msg00342.html

I'm checking this in.

./A

2001-08-30  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* parse.y (patch_assignment): Don't verify final re-assignment here.
	(java_complete_lhs): Verify assignments to finals calling
	patch_assignment. Verify re-assignments to finals before calling
	patch_assignment.

2001-08-29  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* parse.y (java_complete_lhs): Allow final locals in CASE_EXPRs.
	Fixes PR java/1413

2001-08-28  Alexandre Petit-Bianco  <apbianco@redhat.com>

	* lex.c (java_lex): new local found_hex_digits. Set and then used
	in test to reject invalid hexadecimal numbers.
	* parse.y (java_complete_tree): Prevent unwanted cast with
	initialized floating point finals.
	(patch_binop): Emit a warning when detecting a division by zero,
	mark result not constant, don't simplify non integer division.

Index: lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lex.c,v
retrieving revision 1.67
diff -u -p -r1.67 lex.c
--- lex.c	2001/07/18 17:18:55	1.67
+++ lex.c	2001/09/01 04:11:47
@@ -991,6 +991,7 @@ java_lex (java_lval)
       /* End borrowed section  */
       char literal_token [256];
       int  literal_index = 0, radix = 10, long_suffix = 0, overflow = 0, bytes;
+      int  found_hex_digits = 0;
       int  i;
 #ifndef JC1_LITE
       int  number_beginning = ctxp->c_line->current;
@@ -1060,6 +1061,10 @@ java_lex (java_lval)
 	  int numeric = (RANGE (c, '0', '9') ? c-'0' : 10 +(c|0x20)-'a');
 	  int count;
 
+	  /* Remember when we find a valid hexadecimal digit */
+	  if (radix == 16)
+	    found_hex_digits = 1;
+
 	  literal_token [literal_index++] = c;
 	  /* This section of code if borrowed from gcc/c-lex.c  */
 	  for (count = 0; count < TOTAL_PARTS; count++)
@@ -1178,6 +1183,10 @@ java_lex (java_lval)
 		}
 	    }
 	} /* JAVA_ASCCI_FPCHAR (c) */
+
+      if (radix == 16 && ! found_hex_digits)
+	java_lex_error
+	  ("0x must be followed by at least one hexadecimal digit", 0);
 
       /* Here we get back to converting the integral literal.  */
       if (c == 'L' || c == 'l')
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.304
diff -u -p -r1.304 parse.y
--- parse.y	2001/08/29 02:22:52	1.304
+++ parse.y	2001/09/01 04:11:55
@@ -11400,7 +11400,8 @@ java_complete_tree (node)
 	  /* fold_constant_for_init sometimes widen the original type
              of the constant (i.e. byte to int.) It's not desirable,
              especially if NODE is a function argument. */
-	  if (TREE_CODE (value) == INTEGER_CST
+	  if ((TREE_CODE (value) == INTEGER_CST
+	       || TREE_CODE (value) == REAL_CST)
 	      && TREE_TYPE (node) != TREE_TYPE (value))
 	    return convert (TREE_TYPE (node), value);
 	  else
@@ -11615,6 +11616,9 @@ java_complete_lhs (node)
 	  cn = fold_constant_for_init (DECL_INITIAL (TREE_OPERAND (cn, 1)),
 				       TREE_OPERAND (cn, 1));
 	}
+      /* Accept final locals too. */
+      else if (TREE_CODE (cn) == VAR_DECL && LOCAL_FINAL (cn))
+	cn = fold_constant_for_init (DECL_INITIAL (cn), cn);
 
       if (!TREE_CONSTANT (cn) && !flag_emit_xref)
 	{
@@ -11897,11 +11901,15 @@ java_complete_lhs (node)
 	  
 	  value = fold_constant_for_init (nn, nn);
 
-	  if (value != NULL_TREE)
+	  if (value != NULL_TREE &&
+	      (JPRIMITIVE_TYPE_P (TREE_TYPE (value)) || 
+	       (TREE_TYPE (value) == string_ptr_type_node &&
+		! flag_emit_class_files)))
 	    {
-	      tree type = TREE_TYPE (value);
-	      if (JPRIMITIVE_TYPE_P (type) || 
-		  (type == string_ptr_type_node && ! flag_emit_class_files))
+	      TREE_OPERAND (node, 1) = value;
+	      if (patch_assignment (node, wfl_op1, value) == error_mark_node)
+		return error_mark_node;
+	      else
 		return empty_stmt_node;
 	    }
 	  if (! flag_emit_class_files)
@@ -11985,6 +11993,9 @@ java_complete_lhs (node)
 	}
       else
 	{
+	  /* Can't assign to a (blank) final. */
+	  if (check_final_assignment (TREE_OPERAND (node, 0), wfl_op1))
+	    return error_mark_node;
 	  node = patch_assignment (node, wfl_op1, wfl_op2);
 	  /* Reorganize the tree if necessary. */
 	  if (flag && (!JREFERENCE_TYPE_P (TREE_TYPE (node)) 
@@ -12761,10 +12772,6 @@ patch_assignment (node, wfl_op1, wfl_op2
   int error_found = 0;
   int lvalue_from_array = 0;
 
-  /* Can't assign to a (blank) final. */
-  if (check_final_assignment (lvalue, wfl_op1))
-    error_found = 1;
-
   EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
 
   /* Lhs can be a named variable */
@@ -13490,8 +13497,8 @@ patch_binop (node, wfl_op1, wfl_op2)
 	      (TREE_CODE (op2) == INTEGER_CST &&
 	       ! TREE_INT_CST_LOW (op2)  && ! TREE_INT_CST_HIGH (op2))))
 	{
-	  parse_error_context (wfl_operator, "Arithmetic exception");
-	  error_found = 1;
+	  parse_warning_context (wfl_operator, "Evaluating this expression will result in an arithmetic exception being thrown.");
+	  TREE_CONSTANT (node) = 0;
 	}
 	  
       /* Change the division operator if necessary */
@@ -13499,9 +13506,11 @@ patch_binop (node, wfl_op1, wfl_op2)
 	TREE_SET_CODE (node, TRUNC_DIV_EXPR);
 
       /* Before divisions as is disapear, try to simplify and bail if
-         applicable, otherwise we won't perform even simple simplifications
-	 like (1-1)/3. */
-      if (code == RDIV_EXPR && TREE_CONSTANT (op1) && TREE_CONSTANT (op2))
+         applicable, otherwise we won't perform even simple
+         simplifications like (1-1)/3. We can't do that with floating
+         point number, folds can't handle them at this stage. */
+      if (code == RDIV_EXPR && TREE_CONSTANT (op1) && TREE_CONSTANT (op2)
+	  && JINTEGRAL_TYPE_P (op1) && JINTEGRAL_TYPE_P (op2))
 	{
 	  TREE_TYPE (node) = prom_type;
 	  node = fold (node);


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