Commit 3ed218d4 by Alexandre Petit-Bianco Committed by Alexandre Petit-Bianco

[multiple changes]

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.

(http://gcc.gnu.org/ml/java-patches/2001-q3/msg00343.html )

From-SVN: r45345
parent dee45a7f
...@@ -41,6 +41,27 @@ ...@@ -41,6 +41,27 @@
* jcf-dump.c (SPECIAL_IINC): Remove unneeded casts to long. * jcf-dump.c (SPECIAL_IINC): Remove unneeded casts to long.
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.
2001-08-28 Per Bothner <per@bothner.com> 2001-08-28 Per Bothner <per@bothner.com>
* jcf-write.c (generate_bytecode_insns): For increments and * jcf-write.c (generate_bytecode_insns): For increments and
......
...@@ -991,6 +991,7 @@ java_lex (java_lval) ...@@ -991,6 +991,7 @@ java_lex (java_lval)
/* End borrowed section */ /* End borrowed section */
char literal_token [256]; char literal_token [256];
int literal_index = 0, radix = 10, long_suffix = 0, overflow = 0, bytes; int literal_index = 0, radix = 10, long_suffix = 0, overflow = 0, bytes;
int found_hex_digits = 0;
int i; int i;
#ifndef JC1_LITE #ifndef JC1_LITE
int number_beginning = ctxp->c_line->current; int number_beginning = ctxp->c_line->current;
...@@ -1060,6 +1061,10 @@ java_lex (java_lval) ...@@ -1060,6 +1061,10 @@ java_lex (java_lval)
int numeric = (RANGE (c, '0', '9') ? c-'0' : 10 +(c|0x20)-'a'); int numeric = (RANGE (c, '0', '9') ? c-'0' : 10 +(c|0x20)-'a');
int count; int count;
/* Remember when we find a valid hexadecimal digit */
if (radix == 16)
found_hex_digits = 1;
literal_token [literal_index++] = c; literal_token [literal_index++] = c;
/* This section of code if borrowed from gcc/c-lex.c */ /* This section of code if borrowed from gcc/c-lex.c */
for (count = 0; count < TOTAL_PARTS; count++) for (count = 0; count < TOTAL_PARTS; count++)
...@@ -1179,6 +1184,10 @@ java_lex (java_lval) ...@@ -1179,6 +1184,10 @@ java_lex (java_lval)
} }
} /* JAVA_ASCCI_FPCHAR (c) */ } /* 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. */ /* Here we get back to converting the integral literal. */
if (c == 'L' || c == 'l') if (c == 'L' || c == 'l')
long_suffix = 1; long_suffix = 1;
......
...@@ -11401,7 +11401,8 @@ java_complete_tree (node) ...@@ -11401,7 +11401,8 @@ java_complete_tree (node)
/* fold_constant_for_init sometimes widen the original type /* fold_constant_for_init sometimes widen the original type
of the constant (i.e. byte to int.) It's not desirable, of the constant (i.e. byte to int.) It's not desirable,
especially if NODE is a function argument. */ 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)) && TREE_TYPE (node) != TREE_TYPE (value))
return convert (TREE_TYPE (node), value); return convert (TREE_TYPE (node), value);
else else
...@@ -11616,6 +11617,9 @@ java_complete_lhs (node) ...@@ -11616,6 +11617,9 @@ java_complete_lhs (node)
cn = fold_constant_for_init (DECL_INITIAL (TREE_OPERAND (cn, 1)), cn = fold_constant_for_init (DECL_INITIAL (TREE_OPERAND (cn, 1)),
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) if (!TREE_CONSTANT (cn) && !flag_emit_xref)
{ {
...@@ -11898,11 +11902,15 @@ java_complete_lhs (node) ...@@ -11898,11 +11902,15 @@ java_complete_lhs (node)
value = fold_constant_for_init (nn, nn); 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); TREE_OPERAND (node, 1) = value;
if (JPRIMITIVE_TYPE_P (type) || if (patch_assignment (node, wfl_op1, value) == error_mark_node)
(type == string_ptr_type_node && ! flag_emit_class_files)) return error_mark_node;
else
return empty_stmt_node; return empty_stmt_node;
} }
if (! flag_emit_class_files) if (! flag_emit_class_files)
...@@ -11986,6 +11994,9 @@ java_complete_lhs (node) ...@@ -11986,6 +11994,9 @@ java_complete_lhs (node)
} }
else 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); node = patch_assignment (node, wfl_op1, wfl_op2);
/* Reorganize the tree if necessary. */ /* Reorganize the tree if necessary. */
if (flag && (!JREFERENCE_TYPE_P (TREE_TYPE (node)) if (flag && (!JREFERENCE_TYPE_P (TREE_TYPE (node))
...@@ -12762,10 +12773,6 @@ patch_assignment (node, wfl_op1, wfl_op2) ...@@ -12762,10 +12773,6 @@ patch_assignment (node, wfl_op1, wfl_op2)
int error_found = 0; int error_found = 0;
int lvalue_from_array = 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); EXPR_WFL_LINECOL (wfl_operator) = EXPR_WFL_LINECOL (node);
/* Lhs can be a named variable */ /* Lhs can be a named variable */
...@@ -13491,8 +13498,8 @@ patch_binop (node, wfl_op1, wfl_op2) ...@@ -13491,8 +13498,8 @@ patch_binop (node, wfl_op1, wfl_op2)
(TREE_CODE (op2) == INTEGER_CST && (TREE_CODE (op2) == INTEGER_CST &&
! TREE_INT_CST_LOW (op2) && ! TREE_INT_CST_HIGH (op2)))) ! TREE_INT_CST_LOW (op2) && ! TREE_INT_CST_HIGH (op2))))
{ {
parse_error_context (wfl_operator, "Arithmetic exception"); parse_warning_context (wfl_operator, "Evaluating this expression will result in an arithmetic exception being thrown.");
error_found = 1; TREE_CONSTANT (node) = 0;
} }
/* Change the division operator if necessary */ /* Change the division operator if necessary */
...@@ -13500,9 +13507,11 @@ patch_binop (node, wfl_op1, wfl_op2) ...@@ -13500,9 +13507,11 @@ patch_binop (node, wfl_op1, wfl_op2)
TREE_SET_CODE (node, TRUNC_DIV_EXPR); TREE_SET_CODE (node, TRUNC_DIV_EXPR);
/* Before divisions as is disapear, try to simplify and bail if /* Before divisions as is disapear, try to simplify and bail if
applicable, otherwise we won't perform even simple simplifications applicable, otherwise we won't perform even simple
like (1-1)/3. */ simplifications like (1-1)/3. We can't do that with floating
if (code == RDIV_EXPR && TREE_CONSTANT (op1) && TREE_CONSTANT (op2)) 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; TREE_TYPE (node) = prom_type;
node = fold (node); node = fold (node);
......
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