Move directive handling into the lexer itself.
authorNeil Booth <neilb@earthling.net>
Wed, 8 Nov 2000 23:08:07 +0000 (23:08 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Wed, 8 Nov 2000 23:08:07 +0000 (23:08 +0000)
        * cpplex.c (_cpp_lex_token): Handle directives directly.
        In the case of a directive interrupting a function-like
        macro invocation, use extra_char since read_ahead is
        used to store the '#'.  Return a CPP_EOF in this case.
        * cppmacro.c (parse_arg): No need to handle CPP_DHASH any more.
        (cpp_get_token): Don't handle directives here.
        * cpplib.h: Remove CPP_DHASH token type.

From-SVN: r37329

gcc/ChangeLog
gcc/cpplex.c
gcc/cpplib.h
gcc/cppmacro.c

index aa5025d411b7ccc7e1ed6216a54967e24fe57bc7..ef955ac66f8a77c622b403b0af3edcdade9c00f2 100644 (file)
@@ -1,3 +1,15 @@
+2000-11-08  Neil Booth  <neilb@earthling.net>
+
+        Move directive handling into the lexer itself.
+         
+        * cpplex.c (_cpp_lex_token): Handle directives directly.
+        In the case of a directive interrupting a function-like
+        macro invocation, use extra_char since read_ahead is
+        used to store the '#'.  Return a CPP_EOF in this case.
+        * cppmacro.c (parse_arg): No need to handle CPP_DHASH any more.
+        (cpp_get_token): Don't handle directives here.
+        * cpplib.h: Remove CPP_DHASH token type.
+
 Wed Nov  8 21:53:41 MET 2000  Jan Hubicka  <jh@suse.cz>
 
        * regmove.c (combine_stack_adjustments_for_blocks): Recognize pushes
index eab49ffe73af29275b4efdcaf77135e107ece5b8..fb5eec55929e568b70569cfbb28101b518a450e4 100644 (file)
@@ -844,11 +844,13 @@ _cpp_lex_token (pfile, result)
      cpp_token *result;
 {
   cppchar_t c;
-  cpp_buffer *buffer = pfile->buffer;
+  cpp_buffer *buffer;
   const unsigned char *comment_start;
   unsigned char was_skip_newlines = pfile->state.skip_newlines;
   unsigned char newline_in_args = 0;
 
+ done_directive:
+  buffer = pfile->buffer;
   pfile->state.skip_newlines = 0;
   result->flags = 0;
  next_char:
@@ -1160,20 +1162,51 @@ _cpp_lex_token (pfile, result)
       break;
          
     case '#':
-      if (get_effective_char (buffer) == '#')
+      c = buffer->extra_char;  /* Can be set by error condition below.  */
+      if (c != EOF)
+       {
+         buffer->read_ahead = c;
+         buffer->extra_char = EOF;
+       }
+      else
+       c = get_effective_char (buffer);
+
+      if (c == '#')
        ACCEPT_CHAR (CPP_PASTE);
       else
        {
          result->type = CPP_HASH;
        do_hash:
-         /* CPP_DHASH is the hash introducing a directive.  */
-         if (was_skip_newlines || newline_in_args)
+         if (newline_in_args)
            {
-             result->type = CPP_DHASH;
+             /* 6.10.3 paragraph 11: If there are sequences of
+                preprocessing tokens within the list of arguments that
+                would otherwise act as preprocessing directives, the
+                behavior is undefined.
+
+                This implementation will report a hard error, terminate
+                the macro invocation, and proceed to process the
+                directive.  */
+             cpp_error (pfile,
+                        "directives may not be used inside a macro argument");
+
+             /* Put a '#' in lookahead, return CPP_EOF for parse_arg.  */
+             buffer->extra_char = buffer->read_ahead;
+             buffer->read_ahead = '#';
+             pfile->state.skip_newlines = 1;
+             result->type = CPP_EOF;
+
              /* Get whitespace right - newline_in_args sets it.  */
              if (pfile->lexer_pos.col == 1)
                result->flags &= ~PREV_WHITE;
            }
+         else if (was_skip_newlines)
+           {
+             /* This is the hash introducing a directive.  */
+             if (_cpp_handle_directive (pfile, result->flags & PREV_WHITE))
+               goto done_directive; /* was_skip_newlines still 1.  */
+             /* This is in fact an assembler #.  */
+           }
        }
       break;
 
index cc559e1669258c85c2ed6df9b512b911e56b8fc9..742e1a9dd88986bf600cd05c1c4627555a532711 100644 (file)
@@ -139,7 +139,6 @@ struct htab;
   TK(CPP_HEADER_NAME,  SPELL_STRING)   /* <stdio.h> in #include */     \
 \
   TK(CPP_COMMENT,      SPELL_STRING)   /* Only if output comments.  */ \
-  TK(CPP_DHASH,                SPELL_NONE)     /* The # of a directive.  */    \
   TK(CPP_MACRO_ARG,    SPELL_NONE)     /* Macro argument.  */          \
   TK(CPP_PLACEMARKER,  SPELL_NONE)     /* Placemarker token.  */       \
   OP(CPP_EOF,          "EOL")          /* End of line or file.  */
index 24babafeefa6f1332be65c2f1dd20172c2fddfe3..766a71971564c61238be0941fa9b8a72e363b2d1 100644 (file)
@@ -534,21 +534,6 @@ parse_arg (pfile, arg, var_args)
        break;
       else if (result == CPP_EOF)
        break;          /* Error reported by caller.  */
-      else if (result == CPP_DHASH)
-       {
-         /* 6.10.3 paragraph 11: If there are sequences of
-            preprocessing tokens within the list of arguments that
-            would otherwise act as preprocessing directives, the
-            behavior is undefined.
-
-            This implementation will report a hard error, terminate
-            the macro invocation, and proceed to process the
-            directive.  */
-         cpp_error (pfile, "directives may not be used inside a macro argument");
-         _cpp_push_token (pfile, token, &pfile->lexer_pos);
-         result = CPP_EOF;
-         break;
-       }
     }
 
   /* Empty arguments become a single placemarker token.  */
@@ -1019,16 +1004,6 @@ cpp_get_token (pfile, token)
            break;
          continue;
        }
-      else if (token->type == CPP_DHASH)
-       {
-         /* Handle directives.  */
-         if (_cpp_handle_directive (pfile, token->flags & PREV_WHITE))
-           continue;
-         /* This is in fact an assembler #.  */
-         if (pfile->skipping)
-           continue;
-         token->type = CPP_HASH;
-       }
       /* We are not merging the PREV_WHITE of CPP_PLACEMARKERS.  I
          don't think it really matters.  */
       else if (pfile->skipping || token->type == CPP_PLACEMARKER)