OSDN Git Service

* boehm.c (set_bit): Improve type safety wrt unsignedness.
[pf3gnuchains/gcc-fork.git] / gcc / java / lex.c
index 4f7f8f7..77e38f8 100644 (file)
@@ -1,21 +1,22 @@
 /* Language lexer for the GNU compiler for the Java(TM) language.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   Free Software Foundation, Inc.
    Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
 
-This file is part of GNU CC.
+This file is part of GCC.
 
-GNU CC is free software; you can redistribute it and/or modify
+GCC is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
-GNU CC is distributed in the hope that it will be useful,
+GCC is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING.  If not, write to
+along with GCC; see the file COPYING.  If not, write to
 the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA. 
 
@@ -37,37 +38,42 @@ The Free Software Foundation is independent of Sun Microsystems, Inc.  */
 #include "keyword.h"
 #include "flags.h"
 #include "chartables.h"
+#ifndef JC1_LITE
+#include "timevar.h"
+#endif
 
 /* Function declarations.  */
-static char *java_sprint_unicode PARAMS ((struct java_line *, int));
-static void java_unicode_2_utf8 PARAMS ((unicode_t));
-static void java_lex_error PARAMS ((const char *, int));
+static char *java_sprint_unicode (struct java_line *, int);
+static void java_unicode_2_utf8 (unicode_t);
+static void java_lex_error (const char *, int);
 #ifndef JC1_LITE
-static int java_is_eol PARAMS ((FILE *, int));
-static tree build_wfl_node PARAMS ((tree));
+static int do_java_lex (YYSTYPE *);
+static int java_lex (YYSTYPE *);
+static int java_is_eol (FILE *, int);
+static tree build_wfl_node (tree);
 #endif
-static void java_store_unicode PARAMS ((struct java_line *, unicode_t, int));
-static int java_parse_escape_sequence PARAMS ((void));
-static int java_start_char_p PARAMS ((unicode_t));
-static int java_part_char_p PARAMS ((unicode_t));
-static int java_parse_doc_section PARAMS ((int));
-static void java_parse_end_comment PARAMS ((int));
-static int java_get_unicode PARAMS ((void));
-static int java_read_unicode PARAMS ((java_lexer *, int *));
-static int java_read_unicode_collapsing_terminators PARAMS ((java_lexer *,
-                                                            int *));
-static void java_store_unicode PARAMS ((struct java_line *, unicode_t, int));
-static int java_read_char PARAMS ((java_lexer *));
-static void java_allocate_new_line PARAMS ((void));
-static void java_unget_unicode PARAMS ((void));
-static unicode_t java_sneak_unicode PARAMS ((void));
+static void java_store_unicode (struct java_line *, unicode_t, int);
+static int java_parse_escape_sequence (void);
+static int java_start_char_p (unicode_t);
+static int java_part_char_p (unicode_t);
+static int java_space_char_p (unicode_t);
+static void java_parse_doc_section (int);
+static void java_parse_end_comment (int);
+static int java_get_unicode (void);
+static int java_read_unicode (java_lexer *, int *);
+static int java_read_unicode_collapsing_terminators (java_lexer *, int *);
+static void java_store_unicode (struct java_line *, unicode_t, int);
+static int java_read_char (java_lexer *);
+static void java_allocate_new_line (void);
+static void java_unget_unicode (void);
+static unicode_t java_sneak_unicode (void);
 #ifndef JC1_LITE
-static int utf8_cmp PARAMS ((const unsigned char *, int, const char *));
+static int utf8_cmp (const unsigned char *, int, const char *);
 #endif
 
-java_lexer *java_new_lexer PARAMS ((FILE *, const char *));
+java_lexer *java_new_lexer (FILE *, const char *);
 #ifndef JC1_LITE
-static void error_if_numeric_overflow PARAMS ((tree));
+static void error_if_numeric_overflow (tree);
 #endif
 
 #ifdef HAVE_ICONV
@@ -82,19 +88,13 @@ static int need_byteswap = 0;
 #endif
 
 void
-java_init_lex (finput, encoding)
-     FILE *finput;
-     const char *encoding;
+java_init_lex (FILE *finput, const char *encoding)
 {
 #ifndef JC1_LITE
   int java_lang_imported = 0;
 
   if (!java_lang_id)
     java_lang_id = get_identifier ("java.lang");
-  if (!java_lang_cloneable)
-    java_lang_cloneable = get_identifier ("java.lang.Cloneable");
-  if (!java_io_serializable)
-    java_io_serializable = get_identifier ("java.io.Serializable");
   if (!inst_id)
     inst_id = get_identifier ("inst$");
   if (!wpv_id)
@@ -128,14 +128,14 @@ java_init_lex (finput, encoding)
   CPC_INITIALIZER_LIST (ctxp) = CPC_STATIC_INITIALIZER_LIST (ctxp) =
     CPC_INSTANCE_INITIALIZER_LIST (ctxp) = NULL_TREE;
 
-  memset ((PTR) ctxp->modifier_ctx, 0, 11*sizeof (ctxp->modifier_ctx[0]));
-  memset ((PTR) current_jcf, 0, sizeof (JCF));
+  memset (ctxp->modifier_ctx, 0, sizeof (ctxp->modifier_ctx));
+  current_jcf = ggc_alloc_cleared (sizeof (JCF));
   ctxp->current_parsed_class = NULL;
   ctxp->package = NULL_TREE;
 #endif
 
   ctxp->filename = input_filename;
-  ctxp->lineno = lineno = 0;
+  ctxp->lineno = input_line = 0;
   ctxp->p_line = NULL;
   ctxp->c_line = NULL;
   ctxp->java_error_flag = 0;
@@ -143,9 +143,7 @@ java_init_lex (finput, encoding)
 }
 
 static char *
-java_sprint_unicode (line, i)
-    struct java_line *line;
-    int i;
+java_sprint_unicode (struct java_line *line, int i)
 {
   static char buffer [10];
   if (line->unicode_escape_p [i] || line->line [i] > 128)
@@ -159,13 +157,13 @@ java_sprint_unicode (line, i)
 }
 
 static unicode_t
-java_sneak_unicode ()
+java_sneak_unicode (void)
 {
   return (ctxp->c_line->line [ctxp->c_line->current]);
 }
 
 static void
-java_unget_unicode ()
+java_unget_unicode (void)
 {
   if (!ctxp->c_line->current)
     /* Can't unget unicode.  */
@@ -176,7 +174,7 @@ java_unget_unicode ()
 }
 
 static void
-java_allocate_new_line ()
+java_allocate_new_line (void)
 {
   unicode_t ahead = (ctxp->c_line ? ctxp->c_line->ahead[0] : '\0');
   char ahead_escape_p = (ctxp->c_line ? 
@@ -196,12 +194,11 @@ java_allocate_new_line ()
 
   if (!ctxp->c_line)
     {
-      ctxp->c_line = (struct java_line *)xmalloc (sizeof (struct java_line));
+      ctxp->c_line = xmalloc (sizeof (struct java_line));
       ctxp->c_line->max = JAVA_LINE_MAX;
-      ctxp->c_line->line = (unicode_t *)xmalloc 
-       (sizeof (unicode_t)*ctxp->c_line->max);
+      ctxp->c_line->line = xmalloc (sizeof (unicode_t)*ctxp->c_line->max);
       ctxp->c_line->unicode_escape_p = 
-         (char *)xmalloc (sizeof (char)*ctxp->c_line->max);
+       xmalloc (sizeof (char)*ctxp->c_line->max);
       ctxp->c_line->white_space_only = 0;
     }
 
@@ -215,24 +212,23 @@ java_allocate_new_line ()
     }
   ctxp->c_line->ahead [0] = 0;
   ctxp->c_line->unicode_escape_ahead_p = 0;
-  ctxp->c_line->lineno = ++lineno;
+  ctxp->c_line->lineno = ++input_line;
   ctxp->c_line->white_space_only = 1;
 }
 
 /* Create a new lexer object.  */
 
 java_lexer *
-java_new_lexer (finput, encoding)
-     FILE *finput;
-     const char *encoding;
+java_new_lexer (FILE *finput, const char *encoding)
 {
-  java_lexer *lex = (java_lexer *) xmalloc (sizeof (java_lexer));
+  java_lexer *lex = xmalloc (sizeof (java_lexer));
   int enc_error = 0;
 
   lex->finput = finput;
   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);
@@ -268,7 +264,7 @@ java_new_lexer (finput, encoding)
              in[1] = 0xbb;
              in[2] = 0xbf;
 
-             inp = in;
+             inp = (char *) in;
              inc = 3;
              outp = (char *) &result;
              outc = 2;
@@ -290,12 +286,20 @@ java_new_lexer (finput, encoding)
       /* If iconv failed, use the internal decoder if the default
         encoding was requested.  This code is used on platforms where
         iconv exists but is insufficient for our needs.  For
-        instance, on Solaris 2.5 iconv cannot handle UTF-8 or UCS-2.  */
-      if (strcmp (encoding, DEFAULT_ENCODING))
+        instance, on Solaris 2.5 iconv cannot handle UTF-8 or UCS-2.
+
+        On Solaris the default encoding, as returned by nl_langinfo(),
+        is `646' (aka ASCII), but the Solaris iconv_open() doesn't
+        understand that.  We work around that by pretending
+        `646' to be the same as UTF-8.   */
+      if (strcmp (encoding, DEFAULT_ENCODING) && strcmp (encoding, "646"))
        enc_error = 1;
 #ifdef HAVE_ICONV
       else
-       lex->use_fallback = 1;
+        {
+         lex->use_fallback = 1;
+         lex->encoding = "UTF-8";
+       }
 #endif /* HAVE_ICONV */
     }
 
@@ -306,8 +310,7 @@ java_new_lexer (finput, encoding)
 }
 
 void
-java_destroy_lexer (lex)
-     java_lexer *lex;
+java_destroy_lexer (java_lexer *lex)
 {
 #ifdef HAVE_ICONV
   if (! lex->use_fallback)
@@ -317,8 +320,7 @@ java_destroy_lexer (lex)
 }
 
 static int
-java_read_char (lex)
-     java_lexer *lex;
+java_read_char (java_lexer *lex)
 {
   if (lex->unget_value)
     {
@@ -375,7 +377,7 @@ java_read_char (lex)
              in_save = inbytesleft;
              out_save = out_count;
              inp = &lex->buffer[lex->first];
-             outp = &lex->out_buffer[lex->out_last];
+             outp = (char *) &lex->out_buffer[lex->out_last];
              ir = iconv (lex->handle, (ICONV_CONST char **) &inp,
                          &inbytesleft, &outp, &out_count);
 
@@ -432,8 +434,11 @@ java_read_char (lex)
                  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;
                    }
                }
@@ -489,8 +494,8 @@ java_read_char (lex)
                                                 + (c2 & 0x3f));
                      /* Check for valid 3-byte characters.
                         Don't allow surrogate, \ufffe or \uffff.  */
-                     if (r >= 0x800 && r <= 0xffff
-                         && ! (r >= 0xd800 && r <= 0xdfff)
+                     if (IN_RANGE (r, 0x800, 0xffff)
+                         && ! IN_RANGE (r, 0xd800, 0xdfff)
                          && r != 0xfffe && r != 0xffff)
                        return r;
                    }
@@ -509,26 +514,21 @@ java_read_char (lex)
 }
 
 static void
-java_store_unicode (l, c, unicode_escape_p)
-    struct java_line *l;
-    unicode_t c;
-    int unicode_escape_p;
+java_store_unicode (struct java_line *l, unicode_t c, int unicode_escape_p)
 {
   if (l->size == l->max)
     {
       l->max += JAVA_LINE_MAX;
-      l->line = (unicode_t *) xrealloc (l->line, sizeof (unicode_t)*l->max);
-      l->unicode_escape_p = (char *) xrealloc (l->unicode_escape_p, 
-                                              sizeof (char)*l->max);
+      l->line = xrealloc (l->line, sizeof (unicode_t)*l->max);
+      l->unicode_escape_p = xrealloc (l->unicode_escape_p, 
+                                     sizeof (char)*l->max);
     }
   l->line [l->size] = c;
   l->unicode_escape_p [l->size++] = unicode_escape_p;
 }
 
 static int
-java_read_unicode (lex, unicode_escape_p)
-     java_lexer *lex;
-     int *unicode_escape_p;
+java_read_unicode (java_lexer *lex, int *unicode_escape_p)
 {
   int c;
 
@@ -555,23 +555,31 @@ java_read_unicode (lex, unicode_escape_p)
          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;
@@ -582,9 +590,8 @@ java_read_unicode (lex, unicode_escape_p)
 }
 
 static int
-java_read_unicode_collapsing_terminators (lex, unicode_escape_p)
-     java_lexer *lex;
-     int *unicode_escape_p;
+java_read_unicode_collapsing_terminators (java_lexer *lex,
+                                         int *unicode_escape_p)
 {
   int c = java_read_unicode (lex, unicode_escape_p);
 
@@ -594,7 +601,7 @@ java_read_unicode_collapsing_terminators (lex, unicode_escape_p)
         return a single line terminator.  */
       int dummy;
       c = java_read_unicode (lex, &dummy);
-      if (c != '\n')
+      if (c != '\n' && c != UEOF)
        lex->unget_value = c;
       /* In either case we must return a newline.  */
       c = '\n';
@@ -604,7 +611,7 @@ java_read_unicode_collapsing_terminators (lex, unicode_escape_p)
 }
 
 static int
-java_get_unicode ()
+java_get_unicode (void)
 {
   /* It's time to read a line when...  */
   if (!ctxp->c_line || ctxp->c_line->current == ctxp->c_line->size)
@@ -651,8 +658,7 @@ java_get_unicode ()
 /* Parse the end of a C style comment.
  * C is the first character following the '/' and '*'.  */
 static void
-java_parse_end_comment (c)
-     int c;
+java_parse_end_comment (int c)
 {
   for ( ;; c = java_get_unicode ())
     {
@@ -680,69 +686,106 @@ java_parse_end_comment (c)
    of a documentation comment line (ignoring white space and any `*'
    character). Parsed keyword(s): @DEPRECATED.  */
 
-static int
-java_parse_doc_section (c)
-     int c;
+static void
+java_parse_doc_section (int c)
 {
-  int valid_tag = 0, seen_star = 0;
+  int last_was_star;
+
+  /* We reset this here, because only the most recent doc comment
+     applies to the following declaration.  */
+  ctxp->deprecated = 0;
 
-  while (JAVA_WHITE_SPACE_P (c) || (c == '*') || c == '\n')
+  /* We loop over all the lines of the comment.  We'll eventually exit
+     if we hit EOF prematurely, or when we see the comment
+     terminator.  */
+  while (1)
     {
-      switch (c)
+      /* These first steps need only be done if we're still looking
+        for the deprecated tag.  If we've already seen it, we might
+        as well skip looking for it again.  */
+      if (! ctxp->deprecated)
        {
-       case '*':
-         seen_star = 1;
-         break;
-       case '\n': /* ULT */
-         valid_tag = 1;
-       default:
-         seen_star = 0;
-       }
-      c = java_get_unicode();
-    }
+         /* Skip whitespace and '*'s.  We must also check for the end
+            of the comment here.  */
+         while (JAVA_WHITE_SPACE_P (c) || c == '*')
+           {
+             last_was_star = (c == '*');
+             c = java_get_unicode ();
+             if (last_was_star && c == '/')
+               {
+                 /* We just saw the comment terminator.  */
+                 return;
+               }
+           }
 
-  if (c == UEOF)
-    java_lex_error ("Comment not terminated at end of input", 0);
+         if (c == UEOF)
+           goto eof;
 
-  if (seen_star && (c == '/'))
-    return 1;                  /* Goto step1 in caller.  */
+         if (c == '@')
+           {
+             const char *deprecated = "@deprecated";
+             int i;
 
-  /* We're parsing `@deprecated'.  */
-  if (valid_tag && (c == '@'))
-    {
-      char tag [11];
-      int  tag_index = 0;
+             for (i = 0; deprecated[i]; ++i)
+               {
+                 if (c != deprecated[i])
+                   break;
+                 /* We write the code in this way, with the
+                    update at the end, so that after the loop
+                    we're left with the next character in C.  */
+                 c = java_get_unicode ();
+               }
+
+             if (c == UEOF)
+               goto eof;
+
+             /* @deprecated must be followed by a space or newline.
+                We also allow a '*' in case it appears just before
+                the end of a comment.  In this position only we also
+                must allow any Unicode space character.  */
+             if (c == ' ' || c == '\n' || c == '*' || java_space_char_p (c))
+               {
+                 if (! deprecated[i])
+                   ctxp->deprecated = 1;
+               }
+           }
+       }
 
-      while (tag_index < 10 && c != UEOF && c != ' ' && c != '\n')
+      /* We've examined the relevant content from this line.  Now we
+        skip the remaining characters and start over with the next
+        line.  We also check for end of comment here.  */
+      while (c != '\n' && c != UEOF)
        {
+         last_was_star = (c == '*');
          c = java_get_unicode ();
-         tag [tag_index++] = c;
+         if (last_was_star && c == '/')
+           return;
        }
 
       if (c == UEOF)
-       java_lex_error ("Comment not terminated at end of input", 0);
-      tag [tag_index] = '\0';
-
-      if (!strcmp (tag, "deprecated"))
-       ctxp->deprecated = 1;
+       goto eof;
+      /* We have to advance past the \n.  */
+      c = java_get_unicode ();
+      if (c == UEOF)
+       goto eof;
     }
-  java_unget_unicode ();
-  return 0;
+
+ eof:
+  java_lex_error ("Comment not terminated at end of input", 0);
 }
 
 /* Return true if C is a valid start character for a Java identifier.
    This is only called if C >= 128 -- smaller values are handled
    inline.  However, this function handles all values anyway.  */
 static int
-java_start_char_p (c)
-     unicode_t c;
+java_start_char_p (unicode_t c)
 {
   unsigned int hi = c / 256;
   const char *const page = type_table[hi];
   unsigned long val = (unsigned long) page;
   int flags;
 
-  if ((val & ~ (LETTER_PART | LETTER_START)) != 0)
+  if ((val & ~ LETTER_MASK) != 0)
     flags = page[c & 255];
   else
     flags = val;
@@ -754,15 +797,14 @@ java_start_char_p (c)
    This is only called if C >= 128 -- smaller values are handled
    inline.  However, this function handles all values anyway.  */
 static int
-java_part_char_p (c)
-     unicode_t c;
+java_part_char_p (unicode_t c)
 {
   unsigned int hi = c / 256;
   const char *const page = type_table[hi];
   unsigned long val = (unsigned long) page;
   int flags;
 
-  if ((val & ~ (LETTER_PART | LETTER_START)) != 0)
+  if ((val & ~ LETTER_MASK) != 0)
     flags = page[c & 255];
   else
     flags = val;
@@ -770,8 +812,25 @@ java_part_char_p (c)
   return flags & LETTER_PART;
 }
 
+/* Return true if C is whitespace.  */
 static int
-java_parse_escape_sequence ()
+java_space_char_p (unicode_t c)
+{
+  unsigned int hi = c / 256;
+  const char *const page = type_table[hi];
+  unsigned long val = (unsigned long) page;
+  int flags;
+
+  if ((val & ~ LETTER_MASK) != 0)
+    flags = page[c & 255];
+  else
+    flags = val;
+
+  return flags & LETTER_SPACE;
+}
+
+static int
+java_parse_escape_sequence (void)
 {
   unicode_t char_lit;
   int c;
@@ -828,38 +887,30 @@ java_parse_escape_sequence ()
     }
 }
 
-/* Isolate the code which may raise an arithmetic exception in its
-   own function.  */
-
 #ifndef JC1_LITE
-struct jpa_args
-{
-  YYSTYPE *java_lval;
-  char *literal_token;
-  int fflag;
-  int number_beginning;
-};
+#define IS_ZERO(X) REAL_VALUES_EQUAL (X, dconst0)
 
-#define IS_ZERO(X) (ereal_cmp (X, dconst0) == 0)
+/* Subroutine of java_lex: converts floating-point literals to tree
+   nodes.  LITERAL_TOKEN is the input literal, JAVA_LVAL is where to
+   store the result.  FFLAG indicates whether the literal was tagged
+   with an 'f', indicating it is of type 'float'; NUMBER_BEGINNING
+   is the line number on which to report any error.  */
 
-static void java_perform_atof  PARAMS ((PTR));
+static void java_perform_atof (YYSTYPE *, char *, int, int);
 
 static void
-java_perform_atof (av)
-     PTR av;
+java_perform_atof (YYSTYPE *java_lval, char *literal_token, int fflag,
+                  int number_beginning)
 {
-  struct jpa_args *a = (struct jpa_args *)av;
-  YYSTYPE *java_lval = a->java_lval;
-  int number_beginning = a->number_beginning;
   REAL_VALUE_TYPE value;
-  tree type = (a->fflag ? FLOAT_TYPE_NODE : DOUBLE_TYPE_NODE);
+  tree type = (fflag ? FLOAT_TYPE_NODE : DOUBLE_TYPE_NODE);
 
   SET_REAL_VALUE_ATOF (value,
-                      REAL_VALUE_ATOF (a->literal_token, TYPE_MODE (type)));
+                      REAL_VALUE_ATOF (literal_token, TYPE_MODE (type)));
 
   if (REAL_VALUE_ISINF (value) || REAL_VALUE_ISNAN (value))
     {
-      JAVA_FLOAT_RANGE_ERROR ((a->fflag ? "float" : "double"));
+      JAVA_FLOAT_RANGE_ERROR (fflag ? "float" : "double");
       value = DCONST0;
     }
   else if (IS_ZERO (value))
@@ -867,7 +918,7 @@ java_perform_atof (av)
       /* We check to see if the value is really 0 or if we've found an
         underflow.  We do this in the most primitive imaginable way.  */
       int really_zero = 1;
-      char *p = a->literal_token;
+      char *p = literal_token;
       if (*p == '-')
        ++p;
       while (*p && *p != 'e' && *p != 'E')
@@ -892,15 +943,14 @@ java_perform_atof (av)
 }
 #endif
 
-static int yylex               PARAMS ((YYSTYPE *));
+static int yylex (YYSTYPE *);
 
 static int
 #ifdef JC1_LITE
-yylex (java_lval)
+yylex (YYSTYPE *java_lval)
 #else
-java_lex (java_lval)
+do_java_lex (YYSTYPE *java_lval)
 #endif
-     YYSTYPE *java_lval;
 {
   int c;
   unicode_t first_unicode;
@@ -959,13 +1009,19 @@ java_lex (java_lval)
        case '*':
          if ((c = java_get_unicode ()) == '*')
            {
-             if ((c = java_get_unicode ()) == '/')
-               goto step1;     /* Empty documentation comment.  */
-             else if (java_parse_doc_section (c))
-               goto step1;
+             c = java_get_unicode ();
+             if (c == '/')
+               {
+                 /* Empty documentation comment.  We have to reset
+                    the deprecation marker as only the most recent
+                    doc comment applies.  */
+                 ctxp->deprecated = 0;
+               }
+             else
+               java_parse_doc_section (c);
            }
-
-         java_parse_end_comment ((c = java_get_unicode ()));
+         else
+           java_parse_end_comment ((c = java_get_unicode ()));
          goto step1;
          break;
        default:
@@ -1023,9 +1079,10 @@ java_lex (java_lval)
            }
          else if (JAVA_ASCII_DIGIT (c))
            radix = 8;
-         else if (c == '.')
+         else if (c == '.' || c == 'e' || c =='E')
            {
-             /* Push the '.' back and prepare for a FP parsing...  */
+             /* Push the '.', 'e', or 'E' back and prepare for a FP
+                parsing...  */
              java_unget_unicode ();
              c = '0';
            }
@@ -1154,14 +1211,13 @@ java_lex (java_lval)
                {
                  if (JAVA_ASCII_DIGIT (c))
                    seen_digit = 1;
+                  if (stage == 2)
+                    stage = 3;
                  literal_token [literal_index++ ] = c;
                  c = java_get_unicode ();
                }
              else
                {
-#ifndef JC1_LITE
-                 struct jpa_args a;
-#endif
                  if (stage != 4) /* Don't push back fF/dD.  */
                    java_unget_unicode ();
                  
@@ -1174,17 +1230,10 @@ java_lex (java_lval)
                  JAVA_LEX_LIT (literal_token, radix);
 
 #ifndef JC1_LITE
-                 a.literal_token = literal_token;
-                 a.fflag = fflag;
-                 a.java_lval = java_lval;
-                 a.number_beginning = number_beginning;
-                 if (do_float_handler (java_perform_atof, (PTR) &a))
-                   return FP_LIT_TK;
-
-                 JAVA_FLOAT_RANGE_ERROR ((fflag ? "float" : "double"));
-#else
-                 return FP_LIT_TK;
+                 java_perform_atof (java_lval, literal_token,
+                                    fflag, number_beginning);
 #endif
+                 return FP_LIT_TK;
                }
            }
        } /* JAVA_ASCII_FPCHAR (c) */
@@ -1225,34 +1274,35 @@ java_lex (java_lval)
        }
       /* End borrowed section.  */
 
+#ifndef JC1_LITE
       /* Range checking.  */
-      if (long_suffix)
+      value = build_int_2 (low, high);
+      /* Temporarily set type to unsigned.  */
+      SET_LVAL_NODE_TYPE (value, (long_suffix
+                                 ? unsigned_long_type_node
+                                 : unsigned_int_type_node));
+
+      /* For base 10 numbers, only values up to the highest value
+        (plus one) can be written.  For instance, only ints up to
+        2147483648 can be written.  The special case of the largest
+        negative value is handled elsewhere.  For other bases, any
+        number can be represented.  */
+      if (overflow || (radix == 10
+                      && tree_int_cst_lt (long_suffix
+                                          ? decimal_long_max
+                                          : decimal_int_max,
+                                          value)))
        {
-         /* 9223372036854775808L is valid if operand of a '-'. Otherwise
-            9223372036854775807L is the biggest `long' literal that can be
-            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)
-             || (hb && high & 0x7fffffff && radix == 10))
+         if (long_suffix)
            JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `long' literal");
-       }
-      else
-       {
-         /* 2147483648 is valid if operand of a '-'. Otherwise,
-            2147483647 is the biggest `int' literal that can be
-            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;
-         if (overflow || high || (hb && low & 0x7fffffff && radix == 10))
+         else
            JAVA_INTEGRAL_RANGE_ERROR ("Numeric overflow for `int' literal");
-         high = -hb;
        }
-#ifndef JC1_LITE
-      value = build_int_2 (low, high);
+
+      /* Sign extend the value.  */
+      SET_LVAL_NODE_TYPE (value, (long_suffix ? long_type_node : int_type_node));
+      force_fit_type (value, 0);
       JAVA_RADIX10_FLAG (value) = radix == 10;
-      SET_LVAL_NODE_TYPE (value, long_suffix ? long_type_node : int_type_node);
 #else
       SET_LVAL_NODE_TYPE (build_int_2 (low, high),
                          long_suffix ? long_type_node : int_type_node);
@@ -1308,16 +1358,16 @@ java_lex (java_lval)
        }
       if (c == '\n' || c == UEOF) /* ULT.  */
        {
-         lineno--;     /* Refer to the line where the terminator was seen.  */
+         input_line--; /* Refer to the line where the terminator was seen.  */
          java_lex_error ("String not terminated at end of line", 0);
-         lineno++;
+         input_line++;
        }
 
       obstack_1grow (&temporary_obstack, '\0');
       string = obstack_finish (&temporary_obstack);
 #ifndef JC1_LITE
       if (!no_error || (c != '"'))
-       java_lval->node = error_mark_node; /* FIXME: Requires futher
+       java_lval->node = error_mark_node; /* FIXME: Requires further
                                               testing.  */
       else
        java_lval->node = build_string (strlen (string), string);
@@ -1338,14 +1388,14 @@ java_lex (java_lval)
     case '{':
       JAVA_LEX_SEP (c);
       if (ctxp->ccb_indent == 1)
-       ctxp->first_ccb_indent1 = lineno;
+       ctxp->first_ccb_indent1 = input_line;
       ctxp->ccb_indent++;
       BUILD_OPERATOR (OCB_TK);
     case '}':
       JAVA_LEX_SEP (c);
       ctxp->ccb_indent--;
       if (ctxp->ccb_indent == 1)
-        ctxp->last_ccb_indent1 = lineno;
+        ctxp->last_ccb_indent1 = input_line;
       BUILD_OPERATOR (CCB_TK);
     case '[':
       JAVA_LEX_SEP (c);
@@ -1547,7 +1597,7 @@ java_lex (java_lval)
   
   /* 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)
@@ -1557,7 +1607,8 @@ java_lex (java_lval)
 
   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,
@@ -1611,6 +1662,15 @@ java_lex (java_lval)
              SET_LVAL_NODE (null_pointer_node);
              return NULL_TK;
 
+           case ASSERT_TK:
+             if (flag_assert)
+               {
+                 BUILD_OPERATOR (kw->token);
+                 return kw->token;
+               }
+             else
+               break;
+
              /* Some keyword we want to retain information on the location
                 they where found.  */
            case CASE_TK:
@@ -1651,39 +1711,41 @@ java_lex (java_lval)
 }
 
 #ifndef JC1_LITE
+
+/* The exported interface to the lexer.  */
+static int
+java_lex (YYSTYPE *java_lval)
+{
+  int r;
+
+  timevar_push (TV_LEX);
+  r = do_java_lex (java_lval);
+  timevar_pop (TV_LEX);
+  return r;
+}
+
 /* This is called by the parser to see if an error should be generated
    due to numeric overflow.  This function only handles the particular
    case of the largest negative value, and is only called in the case
    where this value is not preceded by `-'.  */
 static void
-error_if_numeric_overflow (value)
-     tree value;
+error_if_numeric_overflow (tree value)
 {
-  if (TREE_CODE (value) == INTEGER_CST && JAVA_RADIX10_FLAG (value))
+  if (TREE_CODE (value) == INTEGER_CST
+      && JAVA_RADIX10_FLAG (value)
+      && tree_int_cst_sgn (value) < 0)
     {
-      unsigned HOST_WIDE_INT lo, hi;
-
-      lo = TREE_INT_CST_LOW (value);
-      hi = TREE_INT_CST_HIGH (value);
       if (TREE_TYPE (value) == long_type_node)
-       {
-         int hb = (hi >> 31);
-         if (hb && !(hi & 0x7fffffff))
-           java_lex_error ("Numeric overflow for `long' literal", 0);
-       }
+       java_lex_error ("Numeric overflow for `long' literal", 0);
       else
-       {
-         int hb = (lo >> 31) & 0x1;
-         if (hb && !(lo & 0x7fffffff))
-           java_lex_error ("Numeric overflow for `int' literal", 0);
-       }
+       java_lex_error ("Numeric overflow for `int' literal", 0);
     }
 }
+
 #endif /* JC1_LITE */
 
 static void
-java_unicode_2_utf8 (unicode)
-    unicode_t unicode;
+java_unicode_2_utf8 (unicode_t unicode)
 {
   if (RANGE (unicode, 0x01, 0x7f))
     obstack_1grow (&temporary_obstack, (char)unicode);
@@ -1707,8 +1769,7 @@ java_unicode_2_utf8 (unicode)
 
 #ifndef JC1_LITE
 static tree
-build_wfl_node (node)
-     tree node;
+build_wfl_node (tree node)
 {
   node = build_expr_wfl (node, ctxp->filename, ctxp->elc.line, ctxp->elc.col);
   /* Prevent java_complete_lhs from short-circuiting node (if constant).  */
@@ -1718,9 +1779,7 @@ build_wfl_node (node)
 #endif
 
 static void
-java_lex_error (msg, forward)
-     const char *msg ATTRIBUTE_UNUSED;
-     int forward ATTRIBUTE_UNUSED;
+java_lex_error (const char *msg ATTRIBUTE_UNUSED, int forward ATTRIBUTE_UNUSED)
 {
 #ifndef JC1_LITE
   ctxp->elc.line = ctxp->c_line->lineno;
@@ -1735,9 +1794,7 @@ java_lex_error (msg, forward)
 
 #ifndef JC1_LITE
 static int
-java_is_eol (fp, c)
-  FILE *fp;
-  int c;
+java_is_eol (FILE *fp, int c)
 {
   int next;
   switch (c)
@@ -1756,9 +1813,8 @@ java_is_eol (fp, c)
 #endif
 
 char *
-java_get_line_col (filename, line, col)
-     const char *filename ATTRIBUTE_UNUSED;
-     int line ATTRIBUTE_UNUSED, col ATTRIBUTE_UNUSED;
+java_get_line_col (const char *filename ATTRIBUTE_UNUSED,
+                  int line ATTRIBUTE_UNUSED, int col ATTRIBUTE_UNUSED)
 {
 #ifdef JC1_LITE
   return 0;
@@ -1776,7 +1832,7 @@ java_get_line_col (filename, line, col)
   char *base;
 
   if (!(fp = fopen (filename, "r")))
-    fatal_io_error ("can't open %s", filename);
+    fatal_error ("can't open %s: %m", filename);
 
   while (cline != line)
     {
@@ -1834,10 +1890,7 @@ java_get_line_col (filename, line, col)
 
 #ifndef JC1_LITE
 static int
-utf8_cmp (str, length, name)
-     const unsigned char *str;
-     int length;
-     const char *name;
+utf8_cmp (const unsigned char *str, int length, const char *name)
 {
   const unsigned char *limit = str + length;
   int i;
@@ -1965,9 +2018,7 @@ static const char *const cxx_keywords[] =
 /* Return true if NAME is a C++ keyword.  */
 
 int
-cxx_keyword_p (name, length)
-     const char *name;
-     int length;
+cxx_keyword_p (const char *name, int length)
 {
   int last = ARRAY_SIZE (cxx_keywords);
   int first = 0;
@@ -1980,7 +2031,7 @@ cxx_keyword_p (name, length)
     {
       int kwl = strlen (cxx_keywords[mid]);
       int min_length = kwl > length ? length : kwl;
-      int r = utf8_cmp (name, min_length, cxx_keywords[mid]);
+      int r = utf8_cmp ((const unsigned char *) name, min_length, cxx_keywords[mid]);
 
       if (r == 0)
        {