cppinit.c (cpp_post_options): If preprocessed, turn off traditional.
authorNeil Booth <neil@daikokuya.demon.co.uk>
Sat, 18 May 2002 08:23:20 +0000 (08:23 +0000)
committerNeil Booth <neil@gcc.gnu.org>
Sat, 18 May 2002 08:23:20 +0000 (08:23 +0000)
* cppinit.c (cpp_post_options): If preprocessed, turn off
traditional.  If traditional, turn off column numbers.
* cpplib.c (cpp_push_buffer): Lex from stage 3 if traditional.
* cpptrad.c (handle_newline): Update line_base.
(skip_comment): Handle -Wcomment.

From-SVN: r53582

gcc/ChangeLog
gcc/cppinit.c
gcc/cpplib.c
gcc/cpptrad.c

index 590cf75b36d9675057a41149bea3c86aaaaec48d..cc5d35c496487d61d003a0dc200dde165640b942 100644 (file)
@@ -1,3 +1,11 @@
+2002-05-18  Neil Booth  <neil@daikokuya.demon.co.uk>
+
+       * cppinit.c (cpp_post_options): If preprocessed, turn off
+       traditional.  If traditional, turn off column numbers.
+       * cpplib.c (cpp_push_buffer): Lex from stage 3 if traditional.
+       * cpptrad.c (handle_newline): Update line_base.
+       (skip_comment): Handle -Wcomment.
+
 2002-05-17  Zack Weinberg  <zack@codesourcery.com>
 
        * cppinit.c (struct builtin): Remove unused fields.
index 5d91005755c632dac2745b077ebfc1ac96045fe1..dad255aca8ce9d612d9bdc89236bef48160c5a4b 100644 (file)
@@ -1774,9 +1774,16 @@ cpp_post_options (pfile)
     CPP_OPTION (pfile, warn_traditional) = 0;
 
   /* Permanently disable macro expansion if we are rescanning
-     preprocessed text.  */
+     preprocessed text.  Read preprocesed source in ISO mode.  */
   if (CPP_OPTION (pfile, preprocessed))
-    pfile->state.prevent_expansion = 1;
+    {
+      pfile->state.prevent_expansion = 1;
+      CPP_OPTION (pfile, traditional) = 0;
+    }
+
+  /* Traditional CPP does not accurately track column information.  */
+  if (CPP_OPTION (pfile, traditional))
+    CPP_OPTION (pfile, show_column) = 0;
 
   /* -dM makes no normal output.  This is set here so that -dM -dD
      works as expected.  */
index 2773ed93e4ea82b8474b5edf5c8173cbfaee5c42..f19d34e6df115f6c4f4aaebfbbd5f8b57c81ab36 100644 (file)
@@ -1881,7 +1881,7 @@ cpp_push_buffer (pfile, buffer, len, from_stage3, return_at_eof)
 
   new->line_base = new->buf = new->cur = buffer;
   new->rlimit = buffer + len;
-  new->from_stage3 = from_stage3;
+  new->from_stage3 = from_stage3 || CPP_OPTION (pfile, traditional);
   new->prev = pfile->buffer;
   new->return_at_eof = return_at_eof;
   new->saved_flags = BOL;
index a6178e326d60d8a65f35d8b0d414c67fa5246273..d5c2126a55ac1b49c3d62d94447b29c8fdad6e93 100644 (file)
@@ -21,9 +21,9 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "cpplib.h"
 #include "cpphash.h"
 
-/* Lexing TODO: Handle -Wcomment, -C, maybe -CC, and space in escaped
-   newlines.  Stop cpplex.c from recognizing comments, trigraphs and
-   directives during its lexing pass.  */
+/* Lexing TODO: Handle -C, maybe -CC, and space in escaped newlines.
+   Stop cpplex.c from recognizing comments and directives during its
+   lexing pass.  */
 
 static const uchar *handle_newline PARAMS ((cpp_reader *, const uchar *));
 static const uchar *skip_escaped_newlines PARAMS ((cpp_reader *,
@@ -64,6 +64,7 @@ handle_newline (pfile, cur)
   pfile->line++;
   if (cur[0] + cur[1] == '\r' + '\n')
     cur++;
+  pfile->buffer->line_base = cur + 1;
   return cur + 1;
 }
 
@@ -89,30 +90,31 @@ skip_comment (pfile, cur)
      const uchar *cur;
 {
   unsigned int from_line = pfile->line;
+  unsigned int c = 0, prevc;
+  const uchar *limit = pfile->buffer->rlimit;
 
-  for (;;)
+  while (cur < limit)
     {
-      unsigned int c = *cur++;
-      if (c == '*')
+      prevc = c;
+      c = *cur++;
+
+      if (c == '/')
        {
-         cur = skip_escaped_newlines (pfile, cur);
-         if (*cur == '/')
-           {
-             cur++;
-             break;
-           }
+         if (prevc == '*')
+           break;
+         if (*cur == '*' && cur[1] != '/'
+             && CPP_OPTION (pfile, warn_comments))
+           cpp_error_with_line (pfile, DL_WARNING, pfile->line, 0,
+                                "\"/*\" within comment");
        }
       else if (is_vspace (c))
        cur = handle_newline (pfile, cur - 1);
-      else if (c == '\0' && cur - 1 == pfile->buffer->rlimit)
-       {
-         cur--;
-         cpp_error_with_line (pfile, DL_ERROR, from_line, 0,
-                              "unterminated comment");
-         break;
-       }
     }
 
+  if (c != '/' || prevc != '*')
+    cpp_error_with_line (pfile, DL_ERROR, from_line, 0,
+                        "unterminated comment");
+
   return cur;
 }