]> gcc.gnu.org Git - gcc.git/blobdiff - gcc/c-lex.c
[multiple changes]
[gcc.git] / gcc / c-lex.c
index 2f225282e7e52550c14c64ef23fd11d1658458b1..b6d8295606c21bbb8b1cdecb17f0011d11d3b03f 100644 (file)
@@ -36,10 +36,6 @@ Boston, MA 02111-1307, USA.  */
 #ifdef MULTIBYTE_CHARS
 #include "mbchar.h"
 #include <locale.h>
-
-#ifndef GET_ENVIRONMENT
-#define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ((ENV_VALUE) = getenv (ENV_NAME))
-#endif
 #endif /* MULTIBYTE_CHARS */
 
 #if USE_CPPLIB
@@ -114,9 +110,9 @@ static int end_of_file;
 static int nextchar = -1;
 #endif
 
-#ifdef HANDLE_SYSV_PRAGMA
-static int handle_sysv_pragma          PROTO((int));
-#endif /* HANDLE_SYSV_PRAGMA */
+#ifdef HANDLE_GENERIC_PRAGMAS
+static int handle_generic_pragma       PROTO((int));
+#endif /* HANDLE_GENERIC_PRAGMAS */
 static int whitespace_cr               PROTO((int));
 static int skip_white_space            PROTO((int));
 static int skip_white_space_on_line    PROTO((void));
@@ -168,6 +164,8 @@ remember_protocol_qualifiers ()
       wordlist[i].name = "inout";
     else if (wordlist[i].rid == RID_BYCOPY)
       wordlist[i].name = "bycopy";
+    else if (wordlist[i].rid == RID_BYREF)
+      wordlist[i].name = "byref";
     else if (wordlist[i].rid == RID_ONEWAY)
       wordlist[i].name = "oneway";   
 }
@@ -196,12 +194,14 @@ init_parse (filename)
   init_lex ();
 
 #if USE_CPPLIB
-  yy_cur = "\n";
-  yy_lim = yy_cur+1;
-
   parse_in.show_column = 1;
   if (! cpp_start_read (&parse_in, filename))
     abort ();
+
+  /* cpp_start_read always puts at least one line directive into the
+     token buffer.  We must arrange to read it out here. */
+  yy_cur = parse_in.token_buffer;
+  yy_lim = CPP_PWRITTEN (&parse_in);
 #endif
 
   return filename;
@@ -230,7 +230,7 @@ init_lex ()
 #ifdef MULTIBYTE_CHARS
   /* Change to the native locale for multibyte conversions.  */
   setlocale (LC_CTYPE, "");
-  GET_ENVIRONMENT (literal_codeset, "LANG");
+  literal_codeset = getenv ("LANG");
 #endif
 
   maxtoken = 40;
@@ -247,6 +247,7 @@ init_lex ()
   ridpointers[(int) RID_SIGNED] = get_identifier ("signed");
   ridpointers[(int) RID_INLINE] = get_identifier ("inline");
   ridpointers[(int) RID_CONST] = get_identifier ("const");
+  ridpointers[(int) RID_RESTRICT] = get_identifier ("restrict");
   ridpointers[(int) RID_VOLATILE] = get_identifier ("volatile");
   ridpointers[(int) RID_AUTO] = get_identifier ("auto");
   ridpointers[(int) RID_STATIC] = get_identifier ("static");
@@ -260,6 +261,7 @@ init_lex ()
   ridpointers[(int) RID_OUT] = get_identifier ("out");
   ridpointers[(int) RID_INOUT] = get_identifier ("inout");
   ridpointers[(int) RID_BYCOPY] = get_identifier ("bycopy");
+  ridpointers[(int) RID_BYREF] = get_identifier ("byref");
   ridpointers[(int) RID_ONEWAY] = get_identifier ("oneway");
   forget_protocol_qualifiers();
 
@@ -275,6 +277,7 @@ init_lex ()
   if (flag_traditional)
     {
       UNSET_RESERVED_WORD ("const");
+      UNSET_RESERVED_WORD ("restrict");
       UNSET_RESERVED_WORD ("volatile");
       UNSET_RESERVED_WORD ("typeof");
       UNSET_RESERVED_WORD ("signed");
@@ -282,6 +285,9 @@ init_lex ()
       UNSET_RESERVED_WORD ("iterator");
       UNSET_RESERVED_WORD ("complex");
     }
+  else if (!flag_isoc9x)
+    UNSET_RESERVED_WORD ("restrict");
+
   if (flag_no_asm)
     {
       UNSET_RESERVED_WORD ("asm");
@@ -547,34 +553,37 @@ check_newline ()
              if (c == '\n')
                return c;
 
-#if defined HANDLE_PRAGMA || defined HANDLE_SYSV_PRAGMA              
+#if defined HANDLE_PRAGMA || defined HANDLE_GENERIC_PRAGMAS
              UNGETC (c);
              token = yylex ();
              if (token != IDENTIFIER)
                goto skipline;
+#endif /* HANDLE_PRAGMA || HANDLE_GENERIC_PRAGMAS */
              
 #ifdef HANDLE_PRAGMA
-             /* We invoke HANDLE_PRAGMA before HANDLE_SYSV_PRAGMA
-                (if both are defined), in order to give the back
-                end a chance to override the interpretation of
-                SYSV style pragmas.  */
+             /* We invoke HANDLE_PRAGMA before HANDLE_GENERIC_PRAGMAS (if
+                both are defined), in order to give the back end a chance to
+                override the interpretation of generic style pragmas.  */
 #if !USE_CPPLIB
              if (nextchar >= 0)
                {
                  c = nextchar, nextchar = -1;
                  UNGETC (c);
                }
-#endif
+#endif /* !USE_CPPLIB */
+             
+             if (TREE_CODE (yylval.ttype) != IDENTIFIER_NODE)
+               goto skipline;
+
              if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
                                 IDENTIFIER_POINTER (yylval.ttype)))
                return GETC ();
 #endif /* HANDLE_PRAGMA */
              
-#ifdef HANDLE_SYSV_PRAGMA
-             if (handle_sysv_pragma (token))
+#ifdef HANDLE_GENERIC_PRAGMAS
+             if (handle_generic_pragma (token))
                return GETC ();
-#endif /* !HANDLE_SYSV_PRAGMA */
-#endif /* HANDLE_PRAGMA || HANDLE_SYSV_PRAGMA */
+#endif /* HANDLE_GENERIC_PRAGMAS */
              
              /* Issue a warning message if we have been asked to do so.
                 Ignoring unknown pragmas in system header file unless
@@ -841,17 +850,17 @@ linenum:
   return c;
 }
 \f
-#ifdef HANDLE_SYSV_PRAGMA
+#ifdef HANDLE_GENERIC_PRAGMAS
 
 /* Handle a #pragma directive.
    TOKEN is the token we read after `#pragma'.  Processes the entire input
-   line and returns a character for the caller to reread: either \n or EOF.  */
+   line and return non-zero iff the pragma has been successfully parsed.  */
 
 /* This function has to be in this file, in order to get at
    the token types.  */
 
 static int
-handle_sysv_pragma (token)
+handle_generic_pragma (token)
      register int token;
 {
   register int c;
@@ -887,7 +896,7 @@ handle_sysv_pragma (token)
     }
 }
 
-#endif /* HANDLE_SYSV_PRAGMA */
+#endif /* HANDLE_GENERIC_PRAGMAS */
 \f
 #define ENDFILE -1  /* token that represents end-of-file */
 
@@ -948,7 +957,7 @@ readescape (ignore_ptr)
        ;
       else if ((count - 1) * 4 >= TYPE_PRECISION (integer_type_node)
               || (count > 1
-                  && ((1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
+                  && (((unsigned)1 << (TYPE_PRECISION (integer_type_node) - (count - 1) * 4))
                       <= firstdig)))
        pedwarn ("hex escape out of range");
       return code;
@@ -1646,7 +1655,7 @@ yylex ()
                      {
                        if (spec_long_long)
                          error ("three `l's in integer constant");
-                       else if (pedantic)
+                       else if (pedantic && ! in_system_header && warn_long_long)
                          pedwarn ("ANSI C forbids long long integer constants");
                        spec_long_long = 1;
                      }
@@ -1846,7 +1855,7 @@ yylex ()
                if (ignore)
                  goto tryagain;
                if (width < HOST_BITS_PER_INT
-                   && (unsigned) c >= (1 << width))
+                   && (unsigned) c >= ((unsigned)1 << width))
                  pedwarn ("escape sequence out of range for character");
 #ifdef MAP_CHARACTER
                if (ISPRINT (c))
@@ -2001,7 +2010,7 @@ yylex ()
                if (ignore)
                  goto skipnewline;
                if (width < HOST_BITS_PER_INT
-                   && (unsigned) c >= (1 << width))
+                   && (unsigned) c >= ((unsigned)1 << width))
                  pedwarn ("escape sequence out of range for character");
              }
            else if (c == '\n')
@@ -2034,15 +2043,13 @@ yylex ()
                    /* mbtowc sometimes needs an extra char before accepting */
                    if (char_len <= i)
                      UNGETC (c);
-                   if (wide_flag)
+                   if (wide_flag)
                      {
-                       *(wchar_t *)p = wc;
-                       p += sizeof (wc);
+                       p += (i + 1);
+                       c = GETC ();
+                       continue;
                      }
-                   else
-                     p += (i + 1);
-                   c = GETC ();
-                   continue;
+                   c = wc;
                  }
 #endif /* MULTIBYTE_CHARS */
              }
@@ -2061,7 +2068,7 @@ yylex ()
                for (byte = 0; byte < WCHAR_BYTES; ++byte)
                  {
                    int value;
-                   if (byte >= sizeof (c))
+                   if (byte >= (int) sizeof (c))
                      value = 0;
                    else
                      value = (c >> (byte * width)) & bytemask;
This page took 0.034252 seconds and 5 git commands to generate.