This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
PR 5902: Parse errors
- From: Eric Blake <ebb9 at email dot byu dot edu>
- To: java-patches at gcc dot gnu dot org
- Date: Sun, 10 Mar 2002 19:27:51 -0700
- Subject: PR 5902: Parse errors
- Organization: BYU Student
OK to commit mainline and branch? This fixes PR 5902, and as a result,
exposed PR 5913. I've tested it on
i686-pc-linux-gnu. I also verified that PR 5913 was pre-existing before
this patch, at least as early as 3.0.2. By the way, should I look into
getting GNATS write access?
--
This signature intentionally left boring.
Eric Blake ebb9@email.byu.edu
BYU student, free software programmer
2002-03-10 Eric Blake <ebb9@email.byu.edu>
Fix for PR java/5902:
* lex.c (java_lex): Fix parsing of literals.
Index: lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lex.c,v
retrieving revision 1.81
diff -u -r1.81 lex.c
--- lex.c 2002/03/03 21:10:09 1.81
+++ lex.c 2002/03/11 01:15:11
@@ -1,5 +1,5 @@
/* Language lexer for the GNU compiler for the Java(TM) language.
- Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation,
Inc.
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software
Foundation, Inc.
Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
This file is part of GNU CC.
@@ -959,7 +959,7 @@
if ((c = java_get_unicode ()) == '*')
{
if ((c = java_get_unicode ()) == '/')
- goto step1; /* Empy documentation comment */
+ goto step1; /* Empty documentation comment. */
else if (java_parse_doc_section (c))
goto step1;
}
@@ -990,7 +990,7 @@
/* 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 found_hex_digits = 0, found_non_octal_digits = 0;
int i;
#ifndef JC1_LITE
int number_beginning = ctxp->c_line->current;
@@ -1052,18 +1052,20 @@
}
/* Parse the first part of the literal, until we find something
which is not a number. */
- while ((radix == 10 && JAVA_ASCII_DIGIT (c)) ||
- (radix == 16 && JAVA_ASCII_HEXDIGIT (c)) ||
- (radix == 8 && JAVA_ASCII_OCTDIGIT (c)))
+ while ((radix == 16 && JAVA_ASCII_HEXDIGIT (c)) ||
+ JAVA_ASCII_DIGIT (c))
{
/* We store in a string (in case it turns out to be a FP) and in
PARTS if we have to process a integer literal. */
int numeric = hex_value (c);
int count;
- /* Remember when we find a valid hexadecimal digit */
+ /* Remember when we find a valid hexadecimal digit. */
if (radix == 16)
found_hex_digits = 1;
+ /* Remember when we find an invalid octal digit. */
+ else if (radix == 8 && !JAVA_ASCII_OCTDIGIT (c))
+ found_non_octal_digits = 1;
literal_token [literal_index++] = c;
/* This section of code if borrowed from gcc/c-lex.c */
@@ -1118,9 +1120,10 @@
{
if (stage < 2)
{
- /* {E,e} must have seen at list a digit */
+ /* {E,e} must have seen at list a digit. */
if (!seen_digit)
- java_lex_error ("Invalid FP literal", 0);
+ java_lex_error
+ ("Invalid FP literal, mantissa must have
digit", 0);
seen_digit = 0;
seen_exponent = 1;
stage = 2;
@@ -1133,7 +1136,7 @@
if ( c == 'f' || c == 'F' || c == 'd' || c == 'D')
{
fflag = ((c == 'd') || (c == 'D')) ? 0 : 1;
- stage = 4; /* So we fall through */
+ stage = 4; /* So we fall through. */
}
if ((c=='-' || c =='+') && stage == 2)
@@ -1163,7 +1166,8 @@
/* An exponent (if any) must have seen a digit. */
if (seen_exponent && !seen_digit)
- java_lex_error ("Invalid FP literal", 0);
+ java_lex_error
+ ("Invalid FP literal, exponent must have digit",
0);
literal_token [literal_index] = '\0';
JAVA_LEX_LIT (literal_token, radix);
@@ -1182,21 +1186,16 @@
#endif
}
}
- } /* JAVA_ASCCI_FPCHAR (c) */
+ } /* JAVA_ASCII_FPCHAR (c) */
+ /* Here we get back to converting the integral literal. */
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')
+ else if (radix == 8 && found_non_octal_digits)
+ java_lex_error ("Octal literal contains digit out of range", 0);
+ else if (c == 'L' || c == 'l')
long_suffix = 1;
- else if (radix == 16 && JAVA_ASCII_LETTER (c))
- java_lex_error ("Digit out of range in hexadecimal literal", 0);
- else if (radix == 8 && JAVA_ASCII_DIGIT (c))
- java_lex_error ("Digit out of range in octal literal", 0);
- else if (radix == 16 && !literal_index)
- java_lex_error ("No digit specified for hexadecimal literal", 0);
else
java_unget_unicode ();
@@ -1230,7 +1229,7 @@
{
/* 9223372036854775808L is valid if operand of a '-'. Otherwise
9223372036854775807L is the biggest `long' literal that can be
- expressed using a 10 radix. For other radixes, everything that
+ expressed using a 10 radix. For other radices, everything that
fits withing 64 bits is OK. */
int hb = (high >> 31);
if (overflow || (hb && low && radix == 10)
@@ -1241,7 +1240,7 @@
{
/* 2147483648 is valid if operand of a '-'. Otherwise,
2147483647 is the biggest `int' literal that can be
- expressed using a 10 radix. For other radixes, everything
+ expressed using a 10 radix. For other radices, everything
that fits within 32 bits is OK. As all literals are
signed, we sign extend here. */
int hb = (low >> 31) & 0x1;
@@ -1260,7 +1259,7 @@
return INT_LIT_TK;
}
- /* Character literals */
+ /* Character literals. */
if (c == '\'')
{
int char_lit;
@@ -1281,14 +1280,14 @@
java_lex_error ("Syntax error in character literal", 0);
if (char_lit == JAVA_CHAR_ERROR)
- char_lit = 0; /* We silently convert it to zero */
+ char_lit = 0; /* We silently convert it to zero. */
JAVA_LEX_CHAR_LIT (char_lit);
SET_LVAL_NODE_TYPE (build_int_2 (char_lit, 0), char_type_node);
return CHAR_LIT_TK;
}
- /* String literals */
+ /* String literals. */
if (c == '"')
{
int no_error;
@@ -1308,7 +1307,7 @@
}
if (c == '\n' || c == UEOF) /* ULT */
{
- lineno--; /* Refer to the line the terminator was seen */
+ lineno--; /* Refer to the line the terminator was seen. */
java_lex_error ("String not terminated at end of line", 0);
lineno++;
}
@@ -1325,7 +1324,7 @@
return STRING_LIT_TK;
}
- /* Separator */
+ /* Separator. */
switch (c)
{
case '(':
@@ -1364,7 +1363,7 @@
/* return DOT_TK; */
}
- /* Operators */
+ /* Operators. */
switch (c)
{
case '=':