gcc.c (default_compilers, cpp-output): Pass -fpreprocessed.
authorJason Merrill <jason@gcc.gnu.org>
Tue, 20 Jul 1999 19:13:01 +0000 (15:13 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 20 Jul 1999 19:13:01 +0000 (15:13 -0400)
* gcc.c (default_compilers, cpp-output): Pass -fpreprocessed.
* toplev.c (documented_lang_options): Add -fpreprocessed.
* cpplib.h (struct cpp_buffer): Add preprocessed.
* cppinit.c (cpp_handle_option): Handle -fpreprocessed.
(cpp_start_read): Don't expand macros or emit an initial #line
directive if -fpreprocessed.

* cpplib.h (struct cpp_buffer): Added manual_pop for
better C++ tokenization.
* cpplib.c (cpp_get_token): Return CPP_EOF if manual_pop.
Also, support C++ tokenization for ->*, .*, <?, and >? operators.
* c-common.c (cpp_token): Make non-static.

From-SVN: r28190

gcc/ChangeLog
gcc/c-common.c
gcc/cppinit.c
gcc/cpplib.c
gcc/cpplib.h
gcc/gcc.c
gcc/toplev.c

index d6da990663955521a5bdb4d3fda750d20bbc77db..217ac93f8ab956259852c8c2b9be3c381d34b53a 100644 (file)
@@ -1,3 +1,20 @@
+Tue Jul 20 12:12:27 1999  Jason Merrill  <jason@yorick.cygnus.com>
+
+       * gcc.c (default_compilers, cpp-output): Pass -fpreprocessed.
+       * toplev.c (documented_lang_options): Add -fpreprocessed.
+       * cpplib.h (struct cpp_buffer): Add preprocessed.
+       * cppinit.c (cpp_handle_option): Handle -fpreprocessed.
+       (cpp_start_read): Don't expand macros or emit an initial #line
+       directive if -fpreprocessed.
+
+Tue Jul 20 12:12:09 1999  Michael Tiemann  <tiemann@holodeck.cygnus.com>
+
+       * cpplib.h (struct cpp_buffer): Added manual_pop for
+       better C++ tokenization.
+       * cpplib.c (cpp_get_token): Return CPP_EOF if manual_pop.
+       Also, support C++ tokenization for ->*, .*, <?, and >? operators.
+       * c-common.c (cpp_token): Make non-static.
+
 Tue Jul 20 11:24:19 1999  Bernd Schmidt  <bernds@cygnus.co.uk>
 
        * c-common.h: New file.
index 7abfad237cc5ebc4895bc564bde2e59207fd9c50..fca01233694a726bbc940656820efad333ab3c90 100644 (file)
@@ -34,7 +34,7 @@ Boston, MA 02111-1307, USA.  */
 #include "cpplib.h"
 cpp_reader  parse_in;
 cpp_options parse_options;
-static enum cpp_token cpp_token;
+enum cpp_token cpp_token;
 #endif
 
 #ifndef WCHAR_TYPE_SIZE
index f9bc306bd52fcf7101353ee849f09a80c8734224..7269c569c31d11cafef43f16fd8b311e4610253a 100644 (file)
@@ -961,6 +961,11 @@ cpp_start_read (pfile, fname)
       cpp_message (pfile, -1, "End of search list.\n");
     }
 
+  /* Don't bother trying to do macro expansion if we've already done
+     preprocessing.  */
+  if (opts->preprocessed)
+    pfile->no_macro_expand++;
+
   /* Open the main input file.
      We do this in nonblocking mode so we don't get stuck here if
      someone clever has asked cpp to process /dev/rmt0;
@@ -988,7 +993,13 @@ cpp_start_read (pfile, fname)
   ih_fake->limit = 0;
   if (!finclude (pfile, f, ih_fake))
     return 0;
-  output_line_command (pfile, same_file);
+  if (opts->preprocessed)
+    /* If we've already processed this code, we want to trust the #line
+       directives in the input.  But we still need to update our line
+       counter accordingly.  */
+    pfile->lineno = CPP_BUFFER (pfile)->lineno;
+  else
+    output_line_command (pfile, same_file);
   pfile->only_seen_white = 2;
 
   /* The -imacros files can be scanned now, but the -include files
@@ -1155,6 +1166,10 @@ cpp_handle_option (pfile, argc, argv)
          user_label_prefix = "_";
        else if (!strcmp (argv[i], "-fno-leading-underscore"))
          user_label_prefix = "";
+       else if (!strcmp (argv[i], "-fpreprocessed"))
+         opts->preprocessed = 1;
+       else if (!strcmp (argv[i], "-fno-preprocessed"))
+         opts->preprocessed = 0;
        break;
 
       case 'I':                        /* Add directory to path for includes.  */
index 25b57c6c3c58a73ce74d0d4607ba09e414130390..efd87e1ccaa22814dad1c0612fafdc12e926c55b 100644 (file)
@@ -2029,7 +2029,10 @@ cpp_get_token (pfile)
     handle_eof:
       if (CPP_BUFFER (pfile)->seen_eof)
        {
-         if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) == CPP_NULL_BUFFER (pfile))
+         if (CPP_PREV_BUFFER (CPP_BUFFER (pfile)) == CPP_NULL_BUFFER (pfile)
+             /* If we've been reading from redirected input, the
+                frontend will pop the buffer.  */
+             || CPP_BUFFER (pfile)->manual_pop)
            return CPP_EOF;
 
          cpp_pop_buffer (pfile);
@@ -2172,8 +2175,25 @@ cpp_get_token (pfile)
          c2 = PEEKC ();
          if (c2 == '-' && opts->chill)
            goto comment;  /* Chill style comment */
-         if (c2 == '-' || c2 == '=' || c2 == '>')
+         if (c2 == '-' || c2 == '=')
            goto op2;
+         if (c2 == '>')
+           {
+             if (opts->cplusplus && PEEKN (1) == '*')
+               {
+                 /* In C++, there's a ->* operator.  */
+               op3:
+                 token = CPP_OTHER;
+                 pfile->only_seen_white = 0;
+                 CPP_RESERVE (pfile, 4);
+                 CPP_PUTC_Q (pfile, c);
+                 CPP_PUTC_Q (pfile, GETC ());
+                 CPP_PUTC_Q (pfile, GETC ());
+                 CPP_NUL_TERMINATE_Q (pfile);
+                 return token;
+               }
+             goto op2;
+           }
          goto randomchar;
 
        case '<':
@@ -2219,7 +2239,8 @@ cpp_get_token (pfile)
          c2 = PEEKC ();
          if (c2 == '=')
            goto op2;
-         if (c2 != c)
+         /* GNU C++ supports MIN and MAX operators <? and >?.  */
+         if (c2 != c && (!opts->cplusplus || c2 != '?'))
            goto randomchar;
          FORWARD(1);
          CPP_RESERVE (pfile, 4);
@@ -2241,6 +2262,11 @@ cpp_get_token (pfile)
              c = GETC ();
              goto number;
            }
+
+         /* In C++ there's a .* operator.  */
+         if (opts->cplusplus && c2 == '*')
+           goto op2;
+
          if (c2 == '.' && PEEKN(1) == '.')
            {
              CPP_RESERVE(pfile, 4);
@@ -2549,7 +2575,7 @@ parse_name (pfile, c)
 /* Parse a string starting with C.  A single quoted string is treated
    like a double -- some programs (e.g., troff) are perverse this way.
    (However, a single quoted string is not allowed to extend over
-   multiple lines.  */
+   multiple lines.)  */
 static void
 parse_string (pfile, c)
      cpp_reader *pfile;
index aadec44eb8657bd7444f0dcfc756147a901db1b4..d92228e6a035e29d9145cf8c08a1b91e3c093b75 100644 (file)
@@ -136,6 +136,10 @@ struct cpp_buffer
      escapes are used only in macro buffers, and backslash-newline is removed
      from macro expansion text in collect_expansion and/or macarg.  */
   char has_escapes;
+
+  /* Used by the C++ frontend to implement redirected input (such as for
+     default argument and/or template parsing).  */
+  char manual_pop;
 };
 
 struct file_name_map_list;
@@ -454,6 +458,10 @@ struct cpp_options {
   /* Nonzero means give all the error messages the ANSI standard requires.  */
   char pedantic;
 
+  /* Nonzero means we're looking at already preprocessed code, so don't
+     bother trying to do macro expansion and whatnot.  */
+  char preprocessed;
+
   char done_initializing;
 
   /* Search paths for include files.  */
index 287641ac3557f4f2e3c22a78940ebdda87a04acc..b5910c54b1b1271afc5954febf3aebb796bebc0f 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -694,7 +694,7 @@ static struct compiler default_compilers[] =
    {"%{!M:%{!MM:%{!E:cc1 %i %1 %{!Q:-quiet} %{d*} %{m*} %{a*}\
                        %{g*} %{O*} %{W*} %{w} %{pedantic*} %{std*}\
                        %{traditional} %{v:-version} %{pg:-p} %{p} %{f*}\
-                       %{aux-info*} %{Qn:-fno-ident}\
+                       %{aux-info*} %{Qn:-fno-ident} -fpreprocessed\
                        %{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
                        %{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
                     %{!S:as %a %Y\
index d60c206aa31ca7a3b2962d3d0e703c77493cddcc..ff7457c194112b7c9ef4f22e459ece55d268650f 100644 (file)
@@ -1028,6 +1028,8 @@ documented_lang_options[] =
   { "-fno-cond-mismatch", "" },
   { "-fdollars-in-identifiers", "Allow the use of $ inside identifiers" },
   { "-fno-dollars-in-identifiers", "" },
+  { "-fpreprocessed", "" },
+  { "-fno-preprocessed", "" },
   { "-fshort-double", "Use the same size for double as for float" },
   { "-fno-short-double", "" },
   { "-fshort-enums", "Use the smallest fitting integer to hold enums"},
@@ -2299,6 +2301,14 @@ botch (s)
   abort ();
 }
 
+#ifdef __GNUC__
+void
+(abort) ()
+{
+  raise (6);
+}
+#endif
+
 /* Same as `malloc' but report error if no memory available.  */
 
 PTR