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: Java: Improve character encoding error messages


This patch improves GCJ's error message when a character in the source file is not recognised in the encoding being used. It prints the name of the encoding being used, which should help people figure out what is going on a little easier.

OK to commit?

Bryce

2004-05-21  Bryce McKinlay  <mckinlay@redhat.com>

	* lex.c (java_new_lexer): Set `encoding'.
	(java_read_char): Improve error message for unrecognized characters.
	* lex.h (struct java_lexer): New field `encoding'.

Index: lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lex.c,v
retrieving revision 1.107
diff -u -r1.107 lex.c
--- lex.c	22 Oct 2003 18:00:06 -0000	1.107
+++ lex.c	22 May 2004 00:24:34 -0000
@@ -228,6 +228,7 @@
   lex->bs_count = 0;
   lex->unget_value = 0;
   lex->hit_eof = 0;
+  lex->encoding = encoding;
 
 #ifdef HAVE_ICONV
   lex->handle = iconv_open ("UCS-2", encoding);
@@ -295,7 +296,10 @@
 	enc_error = 1;
 #ifdef HAVE_ICONV
       else
-	lex->use_fallback = 1;
+        {
+	  lex->use_fallback = 1;
+	  lex->encoding = "UTF-8";
+	}
 #endif /* HAVE_ICONV */
     }
 
@@ -430,8 +434,11 @@
 		  else
 		    {
 		      /* A more serious error.  */
-		      java_lex_error ("unrecognized character in input stream",
-				      0);
+		      char buffer[128];
+		      sprintf (buffer,
+			       "Unrecognized character for encoding `%s'", 
+		               lex->encoding);
+		      java_lex_error (buffer, 0);
 		      return UEOF;
 		    }
 		}
Index: lex.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/lex.h,v
retrieving revision 1.36
diff -u -r1.36 lex.h
--- lex.h	3 Dec 2003 16:48:20 -0000	1.36
+++ lex.h	22 May 2004 00:24:34 -0000
@@ -116,6 +116,9 @@
 
   /* If nonzero, we've hit EOF.  Used only by java_get_unicode().  */
   int hit_eof : 1;
+  
+  /* Name of the character encoding we're using.  */
+  const char *encoding;
 
 #ifdef HAVE_ICONV
   /* Nonzero if we've read any bytes.  We only recognize the

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