OSDN Git Service

Wed May 6 06:35:38 1998 Robert Lipe <robertl@dgii.com>
[pf3gnuchains/gcc-fork.git] / gcc / c-lex.c
index 22e7e5f..66623dd 100644 (file)
@@ -1,5 +1,5 @@
 /* Lexical analyzer for C and Objective C.
-   Copyright (C) 1987, 88, 89, 92, 94-96, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1987, 88, 89, 92, 94-97, 1998 Free Software Foundation, Inc.
 
 This file is part of GNU CC.
 
@@ -19,20 +19,8 @@ the Free Software Foundation, 59 Temple Place - Suite 330,
 Boston, MA 02111-1307, USA.  */
 
 #include "config.h"
-
-#include <stdio.h>
-#include <errno.h>
+#include "system.h"
 #include <setjmp.h>
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 
 #include "rtl.h"
 #include "tree.h"
@@ -42,8 +30,7 @@ Boston, MA 02111-1307, USA.  */
 #include "flags.h"
 #include "c-parse.h"
 #include "c-pragma.h"
-
-#include <ctype.h>
+#include "toplev.h"
 
 /* MULTIBYTE_CHARS support only works for native compilers.
    ??? Ideally what we want is to model widechar support after
@@ -53,19 +40,17 @@ Boston, MA 02111-1307, USA.  */
 #endif
 
 #ifdef MULTIBYTE_CHARS
-#include <stdlib.h>
 #include <locale.h>
 #endif
 
-#ifndef errno
-extern int errno;
-#endif
-
 #if USE_CPPLIB
 #include "cpplib.h"
 cpp_reader parse_in;
 cpp_options parse_options;
 static enum cpp_token cpp_token;
+#else
+/* Stream for reading from the input file.  */
+FILE *finput;
 #endif
 
 /* The elements of `ridpointers' are identifier nodes
@@ -112,8 +97,6 @@ tree lastiddecl;
 
 int doing_objc_thang;
 
-extern tree is_class_name ();
-
 extern int yydebug;
 
 /* File used for outputting assembler code.  */
@@ -148,7 +131,9 @@ static int nextchar = -1;
 #ifdef HANDLE_SYSV_PRAGMA
 static int handle_sysv_pragma          PROTO((int));
 #endif /* HANDLE_SYSV_PRAGMA */
+static int whitespace_cr               PROTO((int));
 static int skip_white_space            PROTO((int));
+static int skip_white_space_on_line    PROTO((void));
 static char *extend_token_buffer       PROTO((char *));
 static int readescape                  PROTO((int *));
 int check_newline ();
@@ -202,12 +187,30 @@ remember_protocol_qualifiers ()
       wordlist[i].name = "oneway";   
 }
 \f
-#if USE_CPPLIB
-void
+char *
 init_parse (filename)
      char *filename;
 {
+#if !USE_CPPLIB
+  /* Open input file.  */
+  if (filename == 0 || !strcmp (filename, "-"))
+    {
+      finput = stdin;
+      filename = "stdin";
+    }
+  else
+    finput = fopen (filename, "r");
+  if (finput == 0)
+    pfatal_with_name (filename);
+
+#ifdef IO_BUFFER_SIZE
+  setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
+#endif
+#endif /* !USE_CPPLIB */
+
   init_lex ();
+
+#if USE_CPPLIB
   yy_cur = "\n";
   yy_lim = yy_cur+1;
 
@@ -218,14 +221,20 @@ init_parse (filename)
   parse_in.show_column = 1;
   if (! cpp_start_read (&parse_in, filename))
     abort ();
+#endif
+
+  return filename;
 }
 
 void
 finish_parse ()
 {
+#if USE_CPPLIB
   cpp_finish (&parse_in);
-}
+#else
+  fclose (finput);
 #endif
+}
 
 void
 init_lex ()
@@ -353,7 +362,7 @@ yyprint (file, yychar, yylval)
 \f
 /* Iff C is a carriage return, warn about it - if appropriate -
    and return nonzero.  */
-int
+static int
 whitespace_cr (c)
      int c;
 {
@@ -1532,8 +1541,8 @@ yylex ()
        if (floatflag != NOT_FLOAT)
          {
            tree type = double_type_node;
-           int exceeds_double = 0;
            int imag = 0;
+           int conversion_errno = 0;
            REAL_VALUE_TYPE value;
            jmp_buf handler;
 
@@ -1562,7 +1571,6 @@ yylex ()
              }
 
            *p = 0;
-           errno = 0;
 
            /* Convert string to a double, checking for overflow.  */
            if (setjmp (handler))
@@ -1632,7 +1640,9 @@ yylex ()
                      error ("both `f' and `l' in floating constant");
 
                    type = float_type_node;
+                   errno = 0;
                    value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
+                   conversion_errno = errno;
                    /* A diagnostic is required here by some ANSI C testsuites.
                       This is not pedwarn, become some people don't want
                       an error for this.  */
@@ -1642,13 +1652,17 @@ yylex ()
                else if (lflag)
                  {
                    type = long_double_type_node;
+                   errno = 0;
                    value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
+                   conversion_errno = errno;
                    if (REAL_VALUE_ISINF (value) && pedantic)
                      warning ("floating point number exceeds range of `long double'");
                  }
                else
                  {
+                   errno = 0;
                    value = REAL_VALUE_ATOF (copy, TYPE_MODE (type));
+                   conversion_errno = errno;
                    if (REAL_VALUE_ISINF (value) && pedantic)
                      warning ("floating point number exceeds range of `double'");
                  }
@@ -1656,17 +1670,12 @@ yylex ()
                set_float_handler (NULL_PTR);
            }
 #ifdef ERANGE
-           if (errno == ERANGE && !flag_traditional && pedantic)
-             {
-               /* ERANGE is also reported for underflow,
-                  so test the value to distinguish overflow from that.  */
-               if (REAL_VALUES_LESS (dconst1, value)
-                   || REAL_VALUES_LESS (value, dconstm1))
-                 {
-                   warning ("floating point number exceeds range of `double'");
-                   exceeds_double = 1;
-                 }
-             }
+           /* ERANGE is also reported for underflow,
+              so test the value to distinguish overflow from that.  */
+           if (conversion_errno == ERANGE && !flag_traditional && pedantic
+               && (REAL_VALUES_LESS (dconst1, value)
+                   || REAL_VALUES_LESS (value, dconstm1)))
+             warning ("floating point number exceeds range of `double'");
 #endif
 
            /* If the result is not a number, assume it must have been
@@ -1693,6 +1702,7 @@ yylex ()
            int spec_imag = 0;
            int bytes, warn, i;
 
+           traditional_type = ansi_type = type = NULL_TREE;
            while (1)
              {
                if (c == 'u' || c == 'U')