From: Alexandre Petit-Bianco Date: Sat, 1 Sep 2001 04:42:50 +0000 (-0700) Subject: [multiple changes] X-Git-Tag: prereleases/libstdc++-3.0.95~2299 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ed218d4c9adf0c215dfe307f7ec6fce9838ca3b;p=thirdparty%2Fgcc.git [multiple changes] 2001-08-30 Alexandre Petit-Bianco * 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 * parse.y (java_complete_lhs): Allow final locals in CASE_EXPRs. Fixes PR java/1413 2001-08-28 Alexandre Petit-Bianco * 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 --- diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 2a89caeefdd0..3a92114ba54b 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -41,6 +41,27 @@ * jcf-dump.c (SPECIAL_IINC): Remove unneeded casts to long. +2001-08-30 Alexandre Petit-Bianco + + * 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 + + * parse.y (java_complete_lhs): Allow final locals in CASE_EXPRs. + Fixes PR java/1413 + +2001-08-28 Alexandre Petit-Bianco + + * 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 * jcf-write.c (generate_bytecode_insns): For increments and diff --git a/gcc/java/lex.c b/gcc/java/lex.c index 861b6eb54ef5..d22147626326 100644 --- a/gcc/java/lex.c +++ b/gcc/java/lex.c @@ -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++) @@ -1179,6 +1184,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') long_suffix = 1; diff --git a/gcc/java/parse.y b/gcc/java/parse.y index 3f1cfa7f3baa..09a4dcd6ce00 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -11401,7 +11401,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 @@ -11616,6 +11617,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) { @@ -11898,11 +11902,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) @@ -11986,6 +11994,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)) @@ -12762,10 +12773,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 */ @@ -13491,8 +13498,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 */ @@ -13500,9 +13507,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);