diff options
-rw-r--r-- | gcc/ChangeLog | 31 | ||||
-rw-r--r-- | gcc/cppfiles.c | 56 | ||||
-rw-r--r-- | gcc/cpphash.c | 51 | ||||
-rw-r--r-- | gcc/cppinit.c | 387 | ||||
-rw-r--r-- | gcc/cpplib.c | 25 | ||||
-rw-r--r-- | gcc/cpplib.h | 26 |
6 files changed, 299 insertions, 277 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0d08e6b6971..00485c66359 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,34 @@ +2000-03-02 Zack Weinberg <zack@wolery.cumb.org> + + * cppfiles.c (cpp_read_file): New function. + + * cpphash.c (collect_expansion): Make sure to reset last_token + to NORM when we hit a string. Handle trailing whitespace + properly when the expansion is empty. + (create_definition): Disable line commands while parsing the + directive line. + (dump_definition): If pfile->lineno == 0, output a line + command ahead of the dump, and add a trailing newline. + + * cppinit.c (append_include_chain): Add fifth argument, which + indicates whether or not system headers are C++ aware. + (initialize_standard_includes): New function, + broken out of read_and_prescan. Pass 'cxx_aware' value from + the include_defaults_array on to append_include_chain. + (dump_special_to_buffer): Const-ify char array. + (builtin_array): Don't dump __BASE_FILE__. + (cpp_start_read): Use cpp_read_file. Reorder code for + clarity. Don't output line commands here for -D/-A/-U + switches. Don't call deps_output for files included with + -include or -imacros. + + * cpplib.c (do_define): Don't pay any attention to the second + argument. + (cpp_expand_to_buffer): Disable line commands while scanning. + (output_line_command): Work in the file buffer. + * cpplib.h: Remove no_record_file flag from struct cpp_reader. + Fix formatting of comments. Prototype cpp_read_file. + Thu Mar 2 13:29:46 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> * c-common.c (c_common_nodes_and_builtins): Make sizetype_endlink diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c index 6b0d919b070..add627208e2 100644 --- a/gcc/cppfiles.c +++ b/gcc/cppfiles.c @@ -609,6 +609,62 @@ remap_filename (pfile, name, loc) return name; } +/* Push an input buffer and load it up with the contents of FNAME. + If FNAME is "" or NULL, read standard input. */ +int +cpp_read_file (pfile, fname) + cpp_reader *pfile; + const char *fname; +{ + struct include_hash *ih_fake; + int f; + + if (fname == NULL || *fname == 0) + { + fname = ""; + f = 0; + } + + /* Open the file in nonblocking mode, so we don't get stuck if + someone clever has asked cpp to process /dev/rmt0. finclude() + will check that we have a real file to work with. Also take + care not to acquire a controlling terminal by mistake (this can't + happen on sane systems, but paranoia is a virtue). */ + else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0) + { + cpp_notice_from_errno (pfile, fname); + return 0; + } + + /* Push the buffer. */ + if (!cpp_push_buffer (pfile, NULL, 0)) + goto failed_push; + + /* Gin up an include_hash structure for this file and feed it + to finclude. */ + + ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash)); + ih_fake->next = 0; + ih_fake->next_this_file = 0; + ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */ + ih_fake->name = fname; + ih_fake->control_macro = 0; + ih_fake->buf = (char *)-1; + ih_fake->limit = 0; + if (!finclude (pfile, f, ih_fake)) + goto failed_finclude; + + return 1; + + failed_finclude: + /* If finclude fails, it pops the buffer. */ + free (ih_fake); + failed_push: + if (f) + close (f); + return 0; +} + /* Read the contents of FD into the buffer on the top of PFILE's stack. IHASH points to the include hash entry for the file associated with FD. diff --git a/gcc/cpphash.c b/gcc/cpphash.c index d44bdcb48c9..ae5df165468 100644 --- a/gcc/cpphash.c +++ b/gcc/cpphash.c @@ -424,6 +424,7 @@ collect_expansion (pfile, arglist) continue; maybe_trad_stringify: + last_token = NORM; { U_CHAR *base, *p, *limit; struct reflist *tpat; @@ -487,21 +488,31 @@ collect_expansion (pfile, arglist) else if (last_token == PASTE) cpp_error (pfile, "`##' at end of macro definition"); - /* Trim trailing white space from definition. */ - here = CPP_WRITTEN (pfile); - while (here > last && is_hspace (pfile->token_buffer [here-1])) - here--; - CPP_SET_WRITTEN (pfile, here); + if (last_token == START) + { + /* Empty macro definition. */ + exp = xstrdup ("\r \r "); + len = 1; + } + else + { + /* Trim trailing white space from definition. */ + here = CPP_WRITTEN (pfile); + while (here > last && is_hspace (pfile->token_buffer [here-1])) + here--; + CPP_SET_WRITTEN (pfile, here); - CPP_NUL_TERMINATE (pfile); - len = CPP_WRITTEN (pfile) - start + 1; - exp = xmalloc (len + 4); /* space for no-concat markers at either end */ - exp[0] = '\r'; - exp[1] = ' '; - exp[len + 1] = '\r'; - exp[len + 2] = ' '; - exp[len + 3] = '\0'; - memcpy (&exp[2], pfile->token_buffer + start, len - 1); + CPP_NUL_TERMINATE (pfile); + len = CPP_WRITTEN (pfile) - start + 1; + exp = xmalloc (len + 4); /* space for no-concat markers at either end */ + exp[0] = '\r'; + exp[1] = ' '; + exp[len + 1] = '\r'; + exp[len + 2] = ' '; + exp[len + 3] = '\0'; + memcpy (&exp[2], pfile->token_buffer + start, len - 1); + } + CPP_SET_WRITTEN (pfile, start); defn = (DEFINITION *) xmalloc (sizeof (DEFINITION)); @@ -700,6 +711,7 @@ create_definition (pfile, funlike) pfile->no_macro_expand++; pfile->parsing_define_directive++; CPP_OPTIONS (pfile)->discard_comments++; + CPP_OPTIONS (pfile)->no_line_commands++; if (funlike) { @@ -719,12 +731,14 @@ create_definition (pfile, funlike) pfile->no_macro_expand--; pfile->parsing_define_directive--; CPP_OPTIONS (pfile)->discard_comments--; + CPP_OPTIONS (pfile)->no_line_commands--; return defn; err: pfile->no_macro_expand--; pfile->parsing_define_directive--; CPP_OPTIONS (pfile)->discard_comments--; + CPP_OPTIONS (pfile)->no_line_commands--; return 0; } @@ -1560,6 +1574,9 @@ dump_definition (pfile, sym, len, defn) long len; DEFINITION *defn; { + if (pfile->lineno == 0) + output_line_command (pfile, same_file); + CPP_RESERVE (pfile, len + sizeof "#define "); CPP_PUTS_Q (pfile, "#define ", sizeof "#define " -1); CPP_PUTS_Q (pfile, sym, len); @@ -1573,7 +1590,6 @@ dump_definition (pfile, sym, len, defn) So we need length-4 chars of space, plus one for the NUL. */ CPP_RESERVE (pfile, defn->length - 4 + 1); CPP_PUTS_Q (pfile, defn->expansion + 2, defn->length - 4); - CPP_NUL_TERMINATE_Q (pfile); } else { @@ -1644,6 +1660,9 @@ dump_definition (pfile, sym, len, defn) i = defn->length - (x - defn->expansion) - 2; if (*x == '\r') x += 2, i -= 2; if (i > 0) CPP_PUTS (pfile, x, i); - CPP_NUL_TERMINATE (pfile); } + + if (pfile->lineno == 0) + CPP_PUTC (pfile, '\n'); + CPP_NUL_TERMINATE (pfile); } diff --git a/gcc/cppinit.c b/gcc/cppinit.c index d6fbad2247e..4ec4ea58b26 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -111,7 +111,7 @@ static struct default_include int cplusplus; /* Only look here if we're compiling C++. */ int cxx_aware; /* Includes in this directory don't need to be wrapped in extern "C" when compiling - C++. This is not used anymore. */ + C++. */ } include_defaults_array[] #ifdef INCLUDE_DEFAULTS @@ -193,14 +193,15 @@ static void path_include PARAMS ((cpp_reader *, static void initialize_builtins PARAMS ((cpp_reader *)); static void append_include_chain PARAMS ((cpp_reader *, struct cpp_pending *, - char *, int)); + char *, int, int)); static char *base_name PARAMS ((const char *)); static void dump_special_to_buffer PARAMS ((cpp_reader *, const char *)); static void initialize_dependency_output PARAMS ((cpp_reader *)); +static void initialize_standard_includes PARAMS ((cpp_reader *)); static void new_pending_define PARAMS ((struct cpp_options *, const char *)); -/* Last argument to append_include_chain: chain to use */ +/* Fourth argument to append_include_chain: chain to use */ enum { QUOTE = 0, BRACKET, SYSTEM, AFTER }; /* If gcc is in use (stage2/stage3) we can make this table initialized data. */ @@ -289,7 +290,7 @@ path_include (pfile, pend, list, path) name[q - p] = 0; } - append_include_chain (pfile, pend, name, path); + append_include_chain (pfile, pend, name, path, 0); /* Advance past this name. */ if (*q == 0) @@ -325,11 +326,12 @@ base_name (fname) /* Append DIR to include path PATH. DIR must be permanently allocated and writable. */ static void -append_include_chain (pfile, pend, dir, path) +append_include_chain (pfile, pend, dir, path, cxx_aware) cpp_reader *pfile; struct cpp_pending *pend; char *dir; int path; + int cxx_aware; { struct file_name_list *new; struct stat st; @@ -361,7 +363,10 @@ append_include_chain (pfile, pend, dir, path) new->nlen = len; new->ino = st.st_ino; new->dev = st.st_dev; - new->sysp = (path == SYSTEM); + if (path == SYSTEM) + new->sysp = cxx_aware ? 1 : 2; + else + new->sysp = 0; new->name_map = NULL; new->next = NULL; new->alloc = NULL; @@ -384,7 +389,7 @@ dump_special_to_buffer (pfile, macro_name) cpp_reader *pfile; const char *macro_name; { - static char define_directive[] = "#define "; + static const char define_directive[] = "#define "; int macro_name_length = strlen (macro_name); output_line_command (pfile, same_file); CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length); @@ -513,7 +518,7 @@ static const struct builtin builtin_array[] = { "__TIME__", 0, T_TIME, DUMP }, { "__DATE__", 0, T_DATE, DUMP }, { "__FILE__", 0, T_FILE, 0 }, - { "__BASE_FILE__", 0, T_BASE_FILE, DUMP }, + { "__BASE_FILE__", 0, T_BASE_FILE, 0 }, { "__LINE__", 0, T_SPECLINE, 0 }, { "__INCLUDE_LEVEL__", 0, T_INCLUDE_LEVEL, 0 }, { "__VERSION__", 0, T_VERSION, DUMP }, @@ -656,6 +661,99 @@ initialize_dependency_output (pfile) } } +/* And another subroutine. This one sets up the standard include path. */ +static void +initialize_standard_includes (pfile) + cpp_reader *pfile; +{ + cpp_options *opts = CPP_OPTIONS (pfile); + char *path; + struct default_include *p = include_defaults_array; + char *specd_prefix = opts->include_prefix; + + /* Several environment variables may add to the include search path. + CPATH specifies an additional list of directories to be searched + as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, + etc. specify an additional list of directories to be searched as + if specified with -isystem, for the language indicated. */ + + GET_ENV_PATH_LIST (path, "CPATH"); + if (path != 0 && *path != 0) + path_include (pfile, opts->pending, path, BRACKET); + + switch ((opts->objc << 1) + opts->cplusplus) + { + case 0: + GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH"); + break; + case 1: + GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH"); + break; + case 2: + GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH"); + break; + case 3: + GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH"); + break; + } + if (path != 0 && *path != 0) + path_include (pfile, opts->pending, path, SYSTEM); + + /* Search "translated" versions of GNU directories. + These have /usr/local/lib/gcc... replaced by specd_prefix. */ + if (specd_prefix != 0) + { + char *default_prefix = alloca (sizeof GCC_INCLUDE_DIR - 7); + /* Remove the `include' from /usr/local/lib/gcc.../include. + GCC_INCLUDE_DIR will always end in /include. */ + int default_len = sizeof GCC_INCLUDE_DIR - 8; + int specd_len = strlen (specd_prefix); + + memcpy (default_prefix, GCC_INCLUDE_DIR, default_len); + default_prefix[default_len] = '\0'; + + for (p = include_defaults_array; p->fname; p++) + { + /* Some standard dirs are only for C++. */ + if (!p->cplusplus + || (opts->cplusplus + && !opts->no_standard_cplusplus_includes)) + { + /* Does this dir start with the prefix? */ + if (!strncmp (p->fname, default_prefix, default_len)) + { + /* Yes; change prefix and add to search list. */ + int flen = strlen (p->fname); + int this_len = specd_len + flen - default_len; + char *str = (char *) xmalloc (this_len + 1); + memcpy (str, specd_prefix, specd_len); + memcpy (str + specd_len, + p->fname + default_len, + flen - default_len + 1); + + append_include_chain (pfile, opts->pending, + str, SYSTEM, p->cxx_aware); + } + } + } + } + + /* Search ordinary names for GNU include directories. */ + for (p = include_defaults_array; p->fname; p++) + { + /* Some standard dirs are only for C++. */ + if (!p->cplusplus + || (opts->cplusplus + && !opts->no_standard_cplusplus_includes)) + { + /* XXX Potential memory leak! */ + char *str = xstrdup (update_path (p->fname, p->component)); + append_include_chain (pfile, opts->pending, str, SYSTEM, + p->cxx_aware); + } + } +} + /* This is called after options have been processed. * Check options for consistency, and setup for processing input * from the file named FNAME. (Use standard input if FNAME==NULL.) @@ -669,9 +767,6 @@ cpp_start_read (pfile, fname) { struct cpp_options *opts = CPP_OPTIONS (pfile); struct pending_option *p, *q; - int f; - cpp_buffer *fp; - struct include_hash *ih_fake; /* -MG doesn't select the form of output and must be specified with one of -M or -MM. -MG doesn't make sense with -MD or -MMD since they don't @@ -693,6 +788,11 @@ cpp_start_read (pfile, fname) /* Set this if it hasn't been set already. */ if (user_label_prefix == NULL) user_label_prefix = USER_LABEL_PREFIX; + + /* Don't bother trying to do macro expansion if we've already done + preprocessing. */ + if (opts->preprocessed) + pfile->no_macro_expand++; /* Now that we know dollars_in_ident, we can initialize the syntax tables. */ @@ -702,30 +802,52 @@ cpp_start_read (pfile, fname) if (opts->dollars_in_ident) IStable['$'] = ISidstart|ISidnum; - /* Do partial setup of input buffer for the sake of generating - early #line directives (when -g is in effect). */ - fp = cpp_push_buffer (pfile, NULL, 0); - if (!fp) - return 0; + /* Set up the include search path now. */ + if (! opts->no_standard_includes) + initialize_standard_includes (pfile); + + merge_include_chains (opts); + + /* With -v, print the list of dirs to search. */ + if (opts->verbose) + { + struct file_name_list *l; + fprintf (stderr, _("#include \"...\" search starts here:\n")); + for (l = opts->quote_include; l; l = l->next) + { + if (l == opts->bracket_include) + fprintf (stderr, _("#include <...> search starts here:\n")); + fprintf (stderr, " %s\n", l->name); + } + fprintf (stderr, _("End of search list.\n")); + } + + initialize_dependency_output (pfile); + + /* Open the main input file. This must be done before -D processing + so we have a buffer to stand on. */ if (opts->in_fname == NULL || *opts->in_fname == 0) { opts->in_fname = fname; if (opts->in_fname == NULL) opts->in_fname = ""; } - fp->nominal_fname = fp->fname = opts->in_fname; - fp->lineno = 0; - /* Install __LINE__, etc. Must follow initialize_char_syntax - and option processing. */ + if (!cpp_read_file (pfile, fname)) + return 0; + + /* -D and friends may produce output, which should be identified + as line 0. */ + + CPP_BUFFER (pfile)->lineno = 0; + + /* Install __LINE__, etc. */ initialize_builtins (pfile); /* Do -U's, -D's and -A's in the order they were seen. */ p = opts->pending->define_head; while (p) { - if (opts->debug_output) - output_line_command (pfile, same_file); if (p->undef) cpp_undef (pfile, p->arg); else @@ -739,8 +861,6 @@ cpp_start_read (pfile, fname) p = opts->pending->assert_head; while (p) { - if (opts->debug_output) - output_line_command (pfile, same_file); if (p->undef) cpp_unassert (pfile, p->arg); else @@ -752,152 +872,8 @@ cpp_start_read (pfile, fname) } opts->done_initializing = 1; + CPP_BUFFER (pfile)->lineno = 1; - /* Several environment variables may add to the include search path. - CPATH specifies an additional list of directories to be searched - as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, - etc. specify an additional list of directories to be searched as - if specified with -isystem, for the language indicated. - - These variables are ignored if -nostdinc is on. */ - if (! opts->no_standard_includes) - { - char *path; - GET_ENV_PATH_LIST (path, "CPATH"); - if (path != 0 && *path != 0) - path_include (pfile, opts->pending, path, BRACKET); - - switch ((opts->objc << 1) + opts->cplusplus) - { - case 0: - GET_ENV_PATH_LIST (path, "C_INCLUDE_PATH"); - break; - case 1: - GET_ENV_PATH_LIST (path, "CPLUS_INCLUDE_PATH"); - break; - case 2: - GET_ENV_PATH_LIST (path, "OBJC_INCLUDE_PATH"); - break; - case 3: - GET_ENV_PATH_LIST (path, "OBJCPLUS_INCLUDE_PATH"); - break; - } - if (path != 0 && *path != 0) - path_include (pfile, opts->pending, path, SYSTEM); - } - - /* Unless -nostdinc, add the compiled-in include path to the list, - translating prefixes. */ - if (!opts->no_standard_includes) - { - struct default_include *p = include_defaults_array; - char *specd_prefix = opts->include_prefix; - - /* Search "translated" versions of GNU directories. - These have /usr/local/lib/gcc... replaced by specd_prefix. */ - if (specd_prefix != 0) - { - char *default_prefix = alloca (sizeof GCC_INCLUDE_DIR - 7); - /* Remove the `include' from /usr/local/lib/gcc.../include. - GCC_INCLUDE_DIR will always end in /include. */ - int default_len = sizeof GCC_INCLUDE_DIR - 8; - int specd_len = strlen (specd_prefix); - - memcpy (default_prefix, GCC_INCLUDE_DIR, default_len); - default_prefix[default_len] = '\0'; - - for (p = include_defaults_array; p->fname; p++) - { - /* Some standard dirs are only for C++. */ - if (!p->cplusplus - || (opts->cplusplus - && !opts->no_standard_cplusplus_includes)) - { - /* Does this dir start with the prefix? */ - if (!strncmp (p->fname, default_prefix, default_len)) - { - /* Yes; change prefix and add to search list. */ - int flen = strlen (p->fname); - int this_len = specd_len + flen - default_len; - char *str = (char *) xmalloc (this_len + 1); - memcpy (str, specd_prefix, specd_len); - memcpy (str + specd_len, - p->fname + default_len, - flen - default_len + 1); - - append_include_chain (pfile, opts->pending, - str, SYSTEM); - } - } - } - } - - /* Search ordinary names for GNU include directories. */ - for (p = include_defaults_array; p->fname; p++) - { - /* Some standard dirs are only for C++. */ - if (!p->cplusplus - || (opts->cplusplus - && !opts->no_standard_cplusplus_includes)) - { - /* XXX Potential memory leak! */ - char *str = xstrdup (update_path (p->fname, p->component)); - append_include_chain (pfile, opts->pending, str, SYSTEM); - } - } - } - - merge_include_chains (opts); - - /* With -v, print the list of dirs to search. */ - if (opts->verbose) - { - struct file_name_list *p; - fprintf (stderr, _("#include \"...\" search starts here:\n")); - for (p = opts->quote_include; p; p = p->next) - { - if (p == opts->bracket_include) - fprintf (stderr, _("#include <...> search starts here:\n")); - fprintf (stderr, " %s\n", p->name); - } - fprintf (stderr, _("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; - finclude() will check that we have a real file to work with. */ - if (fname == NULL || *fname == 0) - { - fname = ""; - f = 0; - } - else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0) - { - cpp_notice_from_errno (pfile, fname); - return 0; - } - - initialize_dependency_output (pfile); - - /* Must call finclude() on the main input before processing - -include switches; otherwise the -included text winds up - after the main input. */ - ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash)); - ih_fake->next = 0; - ih_fake->next_this_file = 0; - ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */ - ih_fake->name = fname; - ih_fake->control_macro = 0; - ih_fake->buf = (char *)-1; - ih_fake->limit = 0; - if (!finclude (pfile, f, ih_fake)) - return 0; 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 @@ -911,82 +887,29 @@ cpp_start_read (pfile, fname) have to be pushed onto the include stack and processed later, in the main loop calling cpp_get_token. */ - pfile->no_record_file++; opts->no_output++; p = opts->pending->imacros_head; while (p) { - int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666); - if (fd < 0) - { - cpp_notice_from_errno (pfile, p->arg); - return 0; - } - if (!cpp_push_buffer (pfile, NULL, 0)) - return 0; - - ih_fake = (struct include_hash *) - xmalloc (sizeof (struct include_hash)); - ih_fake->next = 0; - ih_fake->next_this_file = 0; - ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */ - ih_fake->name = p->arg; - ih_fake->control_macro = 0; - ih_fake->buf = (char *)-1; - ih_fake->limit = 0; - if (finclude (pfile, fd, ih_fake)) - { - if (CPP_PRINT_DEPS (pfile)) - deps_output (pfile, ih_fake->name, ' '); - - cpp_scan_buffer (pfile); - } - else - cpp_pop_buffer (pfile); - free (ih_fake); + if (cpp_read_file (pfile, p->arg)) + cpp_scan_buffer (pfile); q = p->next; free (p); p = q; } - opts->no_output--; p = opts->pending->include_head; while (p) { - int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666); - if (fd < 0) - { - cpp_notice_from_errno (pfile, p->arg); - return 0; - } - if (!cpp_push_buffer (pfile, NULL, 0)) - return 0; - - ih_fake = (struct include_hash *) - xmalloc (sizeof (struct include_hash)); - ih_fake->next = 0; - ih_fake->next_this_file = 0; - ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */ - ih_fake->name = p->arg; - ih_fake->control_macro = 0; - ih_fake->buf = (char *)-1; - ih_fake->limit = 0; - if (finclude (pfile, fd, ih_fake)) - { - if (CPP_PRINT_DEPS (pfile)) - deps_output (pfile, ih_fake->name, ' '); - - output_line_command (pfile, enter_file); - } - else - cpp_pop_buffer (pfile); + if (cpp_read_file (pfile, p->arg)) + output_line_command (pfile, enter_file); + q = p->next; free (p); p = q; } - pfile->no_record_file--; free (opts->pending); opts->pending = NULL; @@ -1141,7 +1064,7 @@ cpp_handle_option (pfile, argc, argv) else fname = argv[++i]; append_include_chain (pfile, opts->pending, - xstrdup (fname), BRACKET); + xstrdup (fname), BRACKET, 0); } break; @@ -1153,7 +1076,7 @@ cpp_handle_option (pfile, argc, argv) if (i + 1 == argc) goto missing_filename; append_include_chain (pfile, opts->pending, - xstrdup (argv[++i]), SYSTEM); + xstrdup (argv[++i]), SYSTEM, 0); } else if (!strcmp (argv[i], "-include")) { @@ -1210,7 +1133,7 @@ cpp_handle_option (pfile, argc, argv) memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1); } - append_include_chain (pfile, opts->pending, fname, SYSTEM); + append_include_chain (pfile, opts->pending, fname, SYSTEM, 0); } /* Add directory to main path for includes, with the default prefix at the front of its name. */ @@ -1236,7 +1159,7 @@ cpp_handle_option (pfile, argc, argv) memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1); } - append_include_chain (pfile, opts->pending, fname, BRACKET); + append_include_chain (pfile, opts->pending, fname, BRACKET, 0); } /* Add directory to end of path for includes. */ else if (!strcmp (argv[i], "-idirafter")) @@ -1244,7 +1167,7 @@ cpp_handle_option (pfile, argc, argv) if (i + 1 == argc) goto missing_dirname; append_include_chain (pfile, opts->pending, - xstrdup (argv[++i]), AFTER); + xstrdup (argv[++i]), AFTER, 0); } else if (!strcmp (argv[i], "-iprefix")) { diff --git a/gcc/cpplib.c b/gcc/cpplib.c index 8cdc241573e..c5cf6743624 100644 --- a/gcc/cpplib.c +++ b/gcc/cpplib.c @@ -654,7 +654,7 @@ get_macro_name (pfile) static int do_define (pfile, keyword) cpp_reader *pfile; - const struct directive *keyword; + const struct directive *keyword ATTRIBUTE_UNUSED; { HASHNODE *hp; DEFINITION *def; @@ -728,14 +728,11 @@ do_define (pfile, keyword) else cpp_install (pfile, sym, len, T_MACRO, (char *) def); - if (keyword != NULL && keyword->type == T_DEFINE) - { - if (CPP_OPTIONS (pfile)->debug_output - || CPP_OPTIONS (pfile)->dump_macros == dump_definitions) - dump_definition (pfile, sym, len, def); - else if (CPP_OPTIONS (pfile)->dump_macros == dump_names) - pass_thru_directive (sym, len, pfile, keyword); - } + if (CPP_OPTIONS (pfile)->debug_output + || CPP_OPTIONS (pfile)->dump_macros == dump_definitions) + dump_definition (pfile, sym, len, def); + else if (CPP_OPTIONS (pfile)->dump_macros == dump_names) + pass_thru_directive (sym, len, pfile, keyword); return 0; } @@ -876,7 +873,9 @@ cpp_expand_to_buffer (pfile, buf, length) /* Scan the input, create the output. */ save_no_output = CPP_OPTIONS (pfile)->no_output; CPP_OPTIONS (pfile)->no_output = 0; + CPP_OPTIONS (pfile)->no_line_commands++; cpp_scan_buffer (pfile); + CPP_OPTIONS (pfile)->no_line_commands--; CPP_OPTIONS (pfile)->no_output = save_no_output; CPP_NUL_TERMINATE (pfile); @@ -926,16 +925,14 @@ output_line_command (pfile, file_change) enum file_change_code file_change; { long line; - cpp_buffer *ip = CPP_BUFFER (pfile); - - if (ip->fname == NULL) - return; + cpp_buffer *ip; if (CPP_OPTIONS (pfile)->no_line_commands || CPP_OPTIONS (pfile)->no_output) return; - cpp_buf_line_and_col (CPP_BUFFER (pfile), &line, NULL); + ip = cpp_file_buffer (pfile); + cpp_buf_line_and_col (ip, &line, NULL); /* If the current file has not changed, we omit the #line if it would appear to be a no-op, and we output a few newlines instead diff --git a/gcc/cpplib.h b/gcc/cpplib.h index 6c16494ddfc..60d0eed1e14 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -34,7 +34,8 @@ typedef struct cpp_reader cpp_reader; typedef struct cpp_buffer cpp_buffer; typedef struct cpp_options cpp_options; -enum cpp_token { +enum cpp_token +{ CPP_EOF = -1, CPP_OTHER = 0, CPP_COMMENT = 1, @@ -188,23 +189,23 @@ struct cpp_reader struct if_stack *if_stack; /* Nonzero means we have printed (while error reporting) a list of - containing files that matches the current status. */ + containing files that matches the current status. */ char input_stack_listing_current; - /* If non-zero, macros are not expanded. */ + /* If non-zero, macros are not expanded. */ char no_macro_expand; /* If non-zero, directives cause a hard error. Used when parsing macro arguments. */ char no_directives; - /* Print column number in error messages. */ + /* Print column number in error messages. */ char show_column; - /* We're printed a warning recommending against using #import. */ + /* We're printed a warning recommending against using #import. */ char import_warning; - /* If true, character between '<' and '>' are a single (string) token. */ + /* If true, character between '<' and '>' are a single (string) token. */ char parsing_include_directive; /* If true, # introduces an assertion (see do_assert) */ @@ -214,18 +215,13 @@ struct cpp_reader char parsing_define_directive; /* True if escape sequences (as described for has_escapes in - parse_buffer) should be emitted. */ + parse_buffer) should be emitted. */ char output_escapes; /* 0: Have seen non-white-space on this line. 1: Only seen white space so far on this line. - 2: Only seen white space so far in this file. */ - char only_seen_white; - - /* Nonzero means this file was included with a -imacros or -include - command line and should not be recorded as an include file. */ - - char no_record_file; + 2: Only seen white space so far in this file. */ + char only_seen_white; long lineno; @@ -432,7 +428,6 @@ struct cpp_options { char remap; /* Nonzero means don't output line number information. */ - char no_line_commands; /* Nonzero means -I- has been seen, @@ -713,6 +708,7 @@ extern int find_include_file PARAMS ((cpp_reader *, const char *, int *)); extern int finclude PARAMS ((cpp_reader *, int, struct include_hash *)); +extern int cpp_read_file PARAMS ((cpp_reader *, const char *)); extern void deps_output PARAMS ((cpp_reader *, const char *, int)); extern struct include_hash *include_hash PARAMS ((cpp_reader *, const char *, int)); |