diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d6da9906639..217ac93f8ab 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,20 @@ +Tue Jul 20 12:12:27 1999 Jason Merrill + + * 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 + + * 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 ->*, .*, ? operators. + * c-common.c (cpp_token): Make non-static. + Tue Jul 20 11:24:19 1999 Bernd Schmidt * c-common.h: New file. diff --git a/gcc/c-common.c b/gcc/c-common.c index 7abfad237cc..fca01233694 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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 diff --git a/gcc/cppinit.c b/gcc/cppinit.c index f9bc306bd52..7269c569c31 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -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. */ diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 25b57c6c3c5..efd87e1ccaa 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -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 ?. */ + 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; diff --git a/gcc/cpplib.h b/gcc/cpplib.h index aadec44eb86..d92228e6a03 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -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. */ diff --git a/gcc/gcc.c b/gcc/gcc.c index 287641ac355..b5910c54b1b 100644 --- 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\ diff --git a/gcc/toplev.c b/gcc/toplev.c index d60c206aa31..ff7457c1941 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -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