diff options
author | Alexandre Petit-Bianco <apbianco@cygnus.com> | 1999-02-08 11:20:39 +0000 |
---|---|---|
committer | Alexandre Petit-Bianco <apbianco@gcc.gnu.org> | 1999-02-08 03:20:39 -0800 |
commit | acd663ee8d130f87133566064f02b94bedcea9d4 (patch) | |
tree | fe8affd6a54b3a7c6a1eeab7a46a96cb0e85bed2 /gcc/java/parse.y | |
parent | 5f784c1db94c3df95d307b9d0688778e0ed7679a (diff) | |
download | gcc-acd663ee8d130f87133566064f02b94bedcea9d4.zip gcc-acd663ee8d130f87133566064f02b94bedcea9d4.tar.gz gcc-acd663ee8d130f87133566064f02b94bedcea9d4.tar.bz2 |
lex.c (java_read_char): Fixed utf8 decoding.
Fri Jan 29 18:19:02 1999 Alexandre Petit-Bianco <apbianco@cygnus.com>
* lex.c (java_read_char): Fixed utf8 decoding.
(java_unicode_2_utf8): Fixed utf8 encoding in the 0x800-0xffff
range.
* parse.y (valid_builtin_assignconv_identity_widening_p): Fixed
comments. Local variable `all_primitive' is gone. Broadened
acceptance of `0' to floating point targets. `long' can now be
widened to `double' or `float'.
(valid_method_invocation_conversion_p): Added leading
comment. Fixed tabulation.
(build_string_concatenation): Optimize out left or right empty
string constants.
From-SVN: r25078
Diffstat (limited to 'gcc/java/parse.y')
-rw-r--r-- | gcc/java/parse.y | 76 |
1 files changed, 47 insertions, 29 deletions
diff --git a/gcc/java/parse.y b/gcc/java/parse.y index ac8f03e..0dbdc2a 100644 --- a/gcc/java/parse.y +++ b/gcc/java/parse.y @@ -8594,24 +8594,22 @@ static int valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type) tree lhs_type, rhs_type; { - int all_primitive; - + /* 5.1.1: This is the identity conversion part. */ if (lhs_type == rhs_type) return 1; /* Sometimes, instead of passing a type, we pass integer_zero_node - so we know that an integral type can accomodate it */ - if (JINTEGRAL_TYPE_P (lhs_type) && (rhs_type == integer_zero_node)) + so we know that a numeric type can accomodate it */ + if (JNUMERIC_TYPE_P (lhs_type) && (rhs_type == integer_zero_node)) return 1; - all_primitive = - JPRIMITIVE_TYPE_P (lhs_type) && JPRIMITIVE_TYPE_P (rhs_type); - - if (!all_primitive) + /* Reject non primitive types */ + if (!JPRIMITIVE_TYPE_P (lhs_type) || !JPRIMITIVE_TYPE_P (rhs_type)) return 0; - /* byte, even if it's smaller than a char can't be converted into a - char. Short can't too, but the < test below takes care of that */ + /* 5.1.2: widening primitive conversion. byte, even if it's smaller + than a char can't be converted into a char. Short can't too, but + the < test below takes care of that */ if (lhs_type == char_type_node && rhs_type == byte_type_node) return 0; @@ -8625,13 +8623,13 @@ valid_builtin_assignconv_identity_widening_p (lhs_type, rhs_type) || rhs_type == promoted_boolean_type_node)) return 1; - if (JINTEGRAL_TYPE_P (rhs_type) - && ((TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type)) - || (JFLOAT_TYPE_P (lhs_type) && - TYPE_PRECISION (rhs_type) == TYPE_PRECISION (lhs_type)))) - return 1; - else if (JFLOAT_TYPE_P (rhs_type) - && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type))) + /* From here, an integral is widened if its precision is smaller + than the precision of the LHS or if the LHS is a floating point + type, or the RHS is a float and the RHS a double. */ + if ((JINTEGRAL_TYPE_P (rhs_type) && JINTEGRAL_TYPE_P (lhs_type) + && (TYPE_PRECISION (rhs_type) < TYPE_PRECISION (lhs_type))) + || (JINTEGRAL_TYPE_P (rhs_type) && JFLOAT_TYPE_P (lhs_type)) + || (rhs_type == float_type_node && lhs_type == double_type_node)) return 1; return 0; @@ -8780,16 +8778,18 @@ do_unary_numeric_promotion (arg) return arg; } +/* Return a non zero value if SOURCE can be converted into DEST using + the method invocation conversion rule (5.3). */ static int valid_method_invocation_conversion_p (dest, source) tree dest, source; { return (((JPRIMITIVE_TYPE_P (source) || (source == integer_zero_node)) - && JPRIMITIVE_TYPE_P (dest) - && valid_builtin_assignconv_identity_widening_p (dest, source)) - || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source)) - && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest)) - && valid_ref_assignconv_cast_p (source, dest, 0))); + && JPRIMITIVE_TYPE_P (dest) + && valid_builtin_assignconv_identity_widening_p (dest, source)) + || ((JREFERENCE_TYPE_P (source) || JNULLP_TYPE_P (source)) + && (JREFERENCE_TYPE_P (dest) || JNULLP_TYPE_P (dest)) + && valid_ref_assignconv_cast_p (source, dest, 0))); } /* Build an incomplete binop expression. */ @@ -9299,20 +9299,33 @@ build_string_concatenation (op1, op2) if ((result = string_constant_concatenation (op1, op2))) return result; - /* If operands are string constant, turn then into object references */ + /* Discard null constants on either sides of the expression */ + if (TREE_CODE (op1) == STRING_CST && !TREE_STRING_LENGTH (op1)) + { + op1 = op2; + op2 = NULL_TREE; + } + else if (TREE_CODE (op2) == STRING_CST && !TREE_STRING_LENGTH (op2)) + op2 = NULL_TREE; + /* If operands are string constant, turn then into object references */ if (TREE_CODE (op1) == STRING_CST) op1 = patch_string_cst (op1); - if (TREE_CODE (op2) == STRING_CST) + if (op2 && TREE_CODE (op2) == STRING_CST) op2 = patch_string_cst (op2); + /* If either one of the constant is null and the other non null + operand is a String object, return it. */ + if (JSTRING_TYPE_P (TREE_TYPE (op1)) && !op2) + return op1; + /* If OP1 isn't already a StringBuffer, create and initialize a new one */ if (!IS_CRAFTED_STRING_BUFFER_P (op1)) { /* Two solutions here: 1) OP1 is a string reference, we call new StringBuffer(OP1) - 2) Op2 is something else, we call new StringBuffer().append(OP1). */ + 2) OP1 is something else, we call new StringBuffer().append(OP1). */ if (JSTRING_TYPE_P (TREE_TYPE (op1))) op1 = BUILD_STRING_BUFFER (op1); else @@ -9322,10 +9335,15 @@ build_string_concatenation (op1, op2) } } - /* No longer the last node holding a crafted StringBuffer */ - IS_CRAFTED_STRING_BUFFER_P (op1) = 0; - /* Create a node for `{new...,xxx}.append (op2)' */ - op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0); + if (op2) + { + /* OP1 is no longer the last node holding a crafted StringBuffer */ + IS_CRAFTED_STRING_BUFFER_P (op1) = 0; + /* Create a node for `{new...,xxx}.append (op2)' */ + if (op2) + op1 = make_qualified_primary (op1, BUILD_APPEND (op2), 0); + } + /* Mark the last node holding a crafted StringBuffer */ IS_CRAFTED_STRING_BUFFER_P (op1) = 1; |