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]
Other format: [Raw text]

Patch: FYI: gcj lexer fixes


I'm checking this in to the trunk and the 3.3 branch.

This patch fixes a couple of lexer bugs.

First, we would ICE if certain kinds of tokens appeared just before
EOF.  This was caught by a Jacks test.  There are probably other bugs
like this in the lexer not caught by Jacks (parts of the lexer are
pretty ugly, but fixing them all is too much for now).

Second, we would fail to give an error if a \u sequence was
prematurely terminated by EOF.  Again, Jacks caught this.

Tested on x86 Red Hat Linux 7.3.  The patch includes a change to
remove a bunch of Jacks XFAILs; now almost all of the lexer tests
pass.  The remaining one or two, as I recall, touch on buggy areas
outside the lexer.

Tom

Index: gcc/java/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* lex.c (java_lex): Don't include UEOF as part of token.
	(java_read_unicode): Error if \u sequence prematurely terminated.

Index: gcc/java/lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lex.c,v
retrieving revision 1.101
diff -u -r1.101 lex.c
--- gcc/java/lex.c 12 Jan 2003 02:14:55 -0000 1.101
+++ gcc/java/lex.c 28 Jan 2003 18:37:18 -0000
@@ -542,23 +542,31 @@
 	  while ((c = java_read_char (lex)) == 'u')
 	    ;
 
-	  /* Unget the most recent character as it is not a `u'.  */
-	  if (c == UEOF)
-	    return UEOF;
-	  lex->unget_value = c;
-
-	  /* Next should be 4 hex digits, otherwise it's an error.
-	     The hex value is converted into the unicode, pushed into
-	     the Unicode stream.  */
-	  for (shift = 12; shift >= 0; shift -= 4)
+	  shift = 12;
+	  do
 	    {
-	      if ((c = java_read_char (lex)) == UEOF)
-	        return UEOF;
+	      if (c == UEOF)
+		{
+		  java_lex_error ("prematurely terminated \\u sequence", 0);
+		  return UEOF;
+		}
+
 	      if (hex_p (c))
 		unicode |= (unicode_t)(hex_value (c) << shift);
 	      else
-		java_lex_error ("Non hex digit in Unicode escape sequence", 0);
+		{
+		  java_lex_error ("non-hex digit in \\u sequence", 0);
+		  break;
+		}
+
+	      c = java_read_char (lex);
+	      shift -= 4;
 	    }
+	  while (shift >= 0);
+
+	  if (c != UEOF)
+	    lex->unget_value = c;
+
 	  lex->bs_count = 0;
 	  *unicode_escape_p = 1;
 	  return unicode;
@@ -1514,7 +1522,7 @@
   
   /* Keyword, boolean literal or null literal.  */
   for (first_unicode = c, all_ascii = 1, ascii_index = 0; 
-       JAVA_PART_CHAR_P (c); c = java_get_unicode ())
+       c != UEOF && JAVA_PART_CHAR_P (c); c = java_get_unicode ())
     {
       java_unicode_2_utf8 (c);
       if (all_ascii && c >= 128)
@@ -1524,7 +1532,8 @@
 
   obstack_1grow (&temporary_obstack, '\0');
   string = obstack_finish (&temporary_obstack);
-  java_unget_unicode ();
+  if (c != UEOF)
+    java_unget_unicode ();
 
   /* If we have something all ascii, we consider a keyword, a boolean
      literal, a null literal or an all ASCII identifier.  Otherwise,
Index: libjava/testsuite/ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* libjava.jacks/jacks.xfail: More lexer tests now pass.

Index: libjava/testsuite/libjava.jacks/jacks.xfail
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/libjava.jacks/jacks.xfail,v
retrieving revision 1.3
diff -u -r1.3 jacks.xfail
--- libjava/testsuite/libjava.jacks/jacks.xfail 21 Jan 2003 18:50:28 -0000 1.3
+++ libjava/testsuite/libjava.jacks/jacks.xfail 28 Jan 2003 18:37:30 -0000
@@ -611,46 +611,7 @@
 9.2-implicit-17
 9.2-implicit-18
 9.2-implicit-19
-3.7-line-number-1
-3.7-line-number-2
-3.7-line-number-3
-3.7-line-number-4
-3.7-line-number-5
-3.7-line-number-6
-3.7-line-number-7
-3.7-line-number-8
-3.7-line-number-9
-3.7-line-number-10
-3.7-line-number-11
-3.7-line-number-12
-3.7-line-number-13
-3.7-line-number-14
 3.2-valid-1
-3.4-line-number-1
-3.4-line-number-2
-3.4-line-number-3
-3.4-line-number-4
-3.4-line-number-5
-3.4-line-number-6
-3.4-line-number-7
-3.4-line-number-8
-3.4-line-number-9
-3.4-line-number-10
-3.4-line-number-11
-3.4-line-number-12
-3.4-line-number-13
-3.4-line-number-14
-3.4-line-number-15
-3.4-line-number-16
-3.4-line-number-17
-3.4-line-number-18
-3.4-line-number-19
-3.4-line-number-20
-3.4-line-number-21
-3.4-line-number-22
-3.4-line-number-23
-3.4-line-number-24
-3.4-line-number-25
 3.10.2-round-6
 3.10.2-round-7
 3.10.2-round-9
@@ -661,10 +622,6 @@
 3.10.2-double-14
 3.10.1-invalid-3
 3.10.1-invalid-4
-3.3-invalid-5
-3.3-invalid-6
-3.3-invalid-7
-3.3-invalid-8
 6.6.2.2-protected-creation-3
 6.6.2.1-protected-instance-field-3
 6.6.2.1-protected-instance-field-4


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