Commit c45da1ca by Zack Weinberg Committed by Zack Weinberg

cppfiles.c (cpp_read_file): New function.

	* 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.

From-SVN: r32293
parent e97f22c9
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> 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 * c-common.c (c_common_nodes_and_builtins): Make sizetype_endlink
......
...@@ -609,6 +609,62 @@ remap_filename (pfile, name, loc) ...@@ -609,6 +609,62 @@ remap_filename (pfile, name, loc)
return name; 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. /* 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 IHASH points to the include hash entry for the file associated with
FD. FD.
......
...@@ -424,6 +424,7 @@ collect_expansion (pfile, arglist) ...@@ -424,6 +424,7 @@ collect_expansion (pfile, arglist)
continue; continue;
maybe_trad_stringify: maybe_trad_stringify:
last_token = NORM;
{ {
U_CHAR *base, *p, *limit; U_CHAR *base, *p, *limit;
struct reflist *tpat; struct reflist *tpat;
...@@ -487,6 +488,14 @@ collect_expansion (pfile, arglist) ...@@ -487,6 +488,14 @@ collect_expansion (pfile, arglist)
else if (last_token == PASTE) else if (last_token == PASTE)
cpp_error (pfile, "`##' at end of macro definition"); cpp_error (pfile, "`##' at end of macro definition");
if (last_token == START)
{
/* Empty macro definition. */
exp = xstrdup ("\r \r ");
len = 1;
}
else
{
/* Trim trailing white space from definition. */ /* Trim trailing white space from definition. */
here = CPP_WRITTEN (pfile); here = CPP_WRITTEN (pfile);
while (here > last && is_hspace (pfile->token_buffer [here-1])) while (here > last && is_hspace (pfile->token_buffer [here-1]))
...@@ -502,6 +511,8 @@ collect_expansion (pfile, arglist) ...@@ -502,6 +511,8 @@ collect_expansion (pfile, arglist)
exp[len + 2] = ' '; exp[len + 2] = ' ';
exp[len + 3] = '\0'; exp[len + 3] = '\0';
memcpy (&exp[2], pfile->token_buffer + start, len - 1); memcpy (&exp[2], pfile->token_buffer + start, len - 1);
}
CPP_SET_WRITTEN (pfile, start); CPP_SET_WRITTEN (pfile, start);
defn = (DEFINITION *) xmalloc (sizeof (DEFINITION)); defn = (DEFINITION *) xmalloc (sizeof (DEFINITION));
...@@ -700,6 +711,7 @@ create_definition (pfile, funlike) ...@@ -700,6 +711,7 @@ create_definition (pfile, funlike)
pfile->no_macro_expand++; pfile->no_macro_expand++;
pfile->parsing_define_directive++; pfile->parsing_define_directive++;
CPP_OPTIONS (pfile)->discard_comments++; CPP_OPTIONS (pfile)->discard_comments++;
CPP_OPTIONS (pfile)->no_line_commands++;
if (funlike) if (funlike)
{ {
...@@ -719,12 +731,14 @@ create_definition (pfile, funlike) ...@@ -719,12 +731,14 @@ create_definition (pfile, funlike)
pfile->no_macro_expand--; pfile->no_macro_expand--;
pfile->parsing_define_directive--; pfile->parsing_define_directive--;
CPP_OPTIONS (pfile)->discard_comments--; CPP_OPTIONS (pfile)->discard_comments--;
CPP_OPTIONS (pfile)->no_line_commands--;
return defn; return defn;
err: err:
pfile->no_macro_expand--; pfile->no_macro_expand--;
pfile->parsing_define_directive--; pfile->parsing_define_directive--;
CPP_OPTIONS (pfile)->discard_comments--; CPP_OPTIONS (pfile)->discard_comments--;
CPP_OPTIONS (pfile)->no_line_commands--;
return 0; return 0;
} }
...@@ -1560,6 +1574,9 @@ dump_definition (pfile, sym, len, defn) ...@@ -1560,6 +1574,9 @@ dump_definition (pfile, sym, len, defn)
long len; long len;
DEFINITION *defn; DEFINITION *defn;
{ {
if (pfile->lineno == 0)
output_line_command (pfile, same_file);
CPP_RESERVE (pfile, len + sizeof "#define "); CPP_RESERVE (pfile, len + sizeof "#define ");
CPP_PUTS_Q (pfile, "#define ", sizeof "#define " -1); CPP_PUTS_Q (pfile, "#define ", sizeof "#define " -1);
CPP_PUTS_Q (pfile, sym, len); CPP_PUTS_Q (pfile, sym, len);
...@@ -1573,7 +1590,6 @@ dump_definition (pfile, sym, len, defn) ...@@ -1573,7 +1590,6 @@ dump_definition (pfile, sym, len, defn)
So we need length-4 chars of space, plus one for the NUL. */ So we need length-4 chars of space, plus one for the NUL. */
CPP_RESERVE (pfile, defn->length - 4 + 1); CPP_RESERVE (pfile, defn->length - 4 + 1);
CPP_PUTS_Q (pfile, defn->expansion + 2, defn->length - 4); CPP_PUTS_Q (pfile, defn->expansion + 2, defn->length - 4);
CPP_NUL_TERMINATE_Q (pfile);
} }
else else
{ {
...@@ -1644,6 +1660,9 @@ dump_definition (pfile, sym, len, defn) ...@@ -1644,6 +1660,9 @@ dump_definition (pfile, sym, len, defn)
i = defn->length - (x - defn->expansion) - 2; i = defn->length - (x - defn->expansion) - 2;
if (*x == '\r') x += 2, i -= 2; if (*x == '\r') x += 2, i -= 2;
if (i > 0) CPP_PUTS (pfile, x, i); if (i > 0) CPP_PUTS (pfile, x, i);
CPP_NUL_TERMINATE (pfile);
} }
if (pfile->lineno == 0)
CPP_PUTC (pfile, '\n');
CPP_NUL_TERMINATE (pfile);
} }
...@@ -111,7 +111,7 @@ static struct default_include ...@@ -111,7 +111,7 @@ static struct default_include
int cplusplus; /* Only look here if we're compiling C++. */ int cplusplus; /* Only look here if we're compiling C++. */
int cxx_aware; /* Includes in this directory don't need to int cxx_aware; /* Includes in this directory don't need to
be wrapped in extern "C" when compiling be wrapped in extern "C" when compiling
C++. This is not used anymore. */ C++. */
} }
include_defaults_array[] include_defaults_array[]
#ifdef INCLUDE_DEFAULTS #ifdef INCLUDE_DEFAULTS
...@@ -193,14 +193,15 @@ static void path_include PARAMS ((cpp_reader *, ...@@ -193,14 +193,15 @@ static void path_include PARAMS ((cpp_reader *,
static void initialize_builtins PARAMS ((cpp_reader *)); static void initialize_builtins PARAMS ((cpp_reader *));
static void append_include_chain PARAMS ((cpp_reader *, static void append_include_chain PARAMS ((cpp_reader *,
struct cpp_pending *, struct cpp_pending *,
char *, int)); char *, int, int));
static char *base_name PARAMS ((const char *)); static char *base_name PARAMS ((const char *));
static void dump_special_to_buffer PARAMS ((cpp_reader *, const char *)); static void dump_special_to_buffer PARAMS ((cpp_reader *, const char *));
static void initialize_dependency_output PARAMS ((cpp_reader *)); 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 *, static void new_pending_define PARAMS ((struct cpp_options *,
const char *)); 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 }; enum { QUOTE = 0, BRACKET, SYSTEM, AFTER };
/* If gcc is in use (stage2/stage3) we can make this table initialized data. */ /* If gcc is in use (stage2/stage3) we can make this table initialized data. */
...@@ -289,7 +290,7 @@ path_include (pfile, pend, list, path) ...@@ -289,7 +290,7 @@ path_include (pfile, pend, list, path)
name[q - p] = 0; name[q - p] = 0;
} }
append_include_chain (pfile, pend, name, path); append_include_chain (pfile, pend, name, path, 0);
/* Advance past this name. */ /* Advance past this name. */
if (*q == 0) if (*q == 0)
...@@ -325,11 +326,12 @@ base_name (fname) ...@@ -325,11 +326,12 @@ base_name (fname)
/* Append DIR to include path PATH. DIR must be permanently allocated /* Append DIR to include path PATH. DIR must be permanently allocated
and writable. */ and writable. */
static void static void
append_include_chain (pfile, pend, dir, path) append_include_chain (pfile, pend, dir, path, cxx_aware)
cpp_reader *pfile; cpp_reader *pfile;
struct cpp_pending *pend; struct cpp_pending *pend;
char *dir; char *dir;
int path; int path;
int cxx_aware;
{ {
struct file_name_list *new; struct file_name_list *new;
struct stat st; struct stat st;
...@@ -361,7 +363,10 @@ append_include_chain (pfile, pend, dir, path) ...@@ -361,7 +363,10 @@ append_include_chain (pfile, pend, dir, path)
new->nlen = len; new->nlen = len;
new->ino = st.st_ino; new->ino = st.st_ino;
new->dev = st.st_dev; 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->name_map = NULL;
new->next = NULL; new->next = NULL;
new->alloc = NULL; new->alloc = NULL;
...@@ -384,7 +389,7 @@ dump_special_to_buffer (pfile, macro_name) ...@@ -384,7 +389,7 @@ dump_special_to_buffer (pfile, macro_name)
cpp_reader *pfile; cpp_reader *pfile;
const char *macro_name; const char *macro_name;
{ {
static char define_directive[] = "#define "; static const char define_directive[] = "#define ";
int macro_name_length = strlen (macro_name); int macro_name_length = strlen (macro_name);
output_line_command (pfile, same_file); output_line_command (pfile, same_file);
CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length); CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length);
...@@ -513,7 +518,7 @@ static const struct builtin builtin_array[] = ...@@ -513,7 +518,7 @@ static const struct builtin builtin_array[] =
{ "__TIME__", 0, T_TIME, DUMP }, { "__TIME__", 0, T_TIME, DUMP },
{ "__DATE__", 0, T_DATE, DUMP }, { "__DATE__", 0, T_DATE, DUMP },
{ "__FILE__", 0, T_FILE, 0 }, { "__FILE__", 0, T_FILE, 0 },
{ "__BASE_FILE__", 0, T_BASE_FILE, DUMP }, { "__BASE_FILE__", 0, T_BASE_FILE, 0 },
{ "__LINE__", 0, T_SPECLINE, 0 }, { "__LINE__", 0, T_SPECLINE, 0 },
{ "__INCLUDE_LEVEL__", 0, T_INCLUDE_LEVEL, 0 }, { "__INCLUDE_LEVEL__", 0, T_INCLUDE_LEVEL, 0 },
{ "__VERSION__", 0, T_VERSION, DUMP }, { "__VERSION__", 0, T_VERSION, DUMP },
...@@ -656,113 +661,22 @@ initialize_dependency_output (pfile) ...@@ -656,113 +661,22 @@ initialize_dependency_output (pfile)
} }
} }
/* This is called after options have been processed. /* And another subroutine. This one sets up the standard include path. */
* Check options for consistency, and setup for processing input static void
* from the file named FNAME. (Use standard input if FNAME==NULL.) initialize_standard_includes (pfile)
* Return 1 on success, 0 on failure.
*/
int
cpp_start_read (pfile, fname)
cpp_reader *pfile; cpp_reader *pfile;
char *fname;
{ {
struct cpp_options *opts = CPP_OPTIONS (pfile); cpp_options *opts = CPP_OPTIONS (pfile);
struct pending_option *p, *q; char *path;
int f; struct default_include *p = include_defaults_array;
cpp_buffer *fp; char *specd_prefix = opts->include_prefix;
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
inhibit compilation. */
if (opts->print_deps_missing_files
&& (opts->print_deps == 0 || !opts->no_output))
{
cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
return 0;
}
/* Chill should not be used with -trigraphs. */
if (opts->chill && opts->trigraphs)
{
cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive");
opts->trigraphs = 0;
}
/* Set this if it hasn't been set already. */
if (user_label_prefix == NULL)
user_label_prefix = USER_LABEL_PREFIX;
/* Now that we know dollars_in_ident, we can initialize the syntax
tables. */
init_IStable ();
/* XXX Get rid of code that depends on this, then IStable can
be truly const. */
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;
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. */
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
cpp_define (pfile, p->arg);
q = p->next;
free (p);
p = q;
}
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
cpp_assert (pfile, p->arg);
q = p->next;
free (p);
p = q;
}
opts->done_initializing = 1;
/* Several environment variables may add to the include search path. /* Several environment variables may add to the include search path.
CPATH specifies an additional list of directories to be searched CPATH specifies an additional list of directories to be searched
as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, as if specified with -I, while C_INCLUDE_PATH, CPLUS_INCLUDE_PATH,
etc. specify an additional list of directories to be searched as etc. specify an additional list of directories to be searched as
if specified with -isystem, for the language indicated. 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"); GET_ENV_PATH_LIST (path, "CPATH");
if (path != 0 && *path != 0) if (path != 0 && *path != 0)
path_include (pfile, opts->pending, path, BRACKET); path_include (pfile, opts->pending, path, BRACKET);
...@@ -784,14 +698,6 @@ cpp_start_read (pfile, fname) ...@@ -784,14 +698,6 @@ cpp_start_read (pfile, fname)
} }
if (path != 0 && *path != 0) if (path != 0 && *path != 0)
path_include (pfile, opts->pending, path, SYSTEM); 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. /* Search "translated" versions of GNU directories.
These have /usr/local/lib/gcc... replaced by specd_prefix. */ These have /usr/local/lib/gcc... replaced by specd_prefix. */
...@@ -826,7 +732,7 @@ cpp_start_read (pfile, fname) ...@@ -826,7 +732,7 @@ cpp_start_read (pfile, fname)
flen - default_len + 1); flen - default_len + 1);
append_include_chain (pfile, opts->pending, append_include_chain (pfile, opts->pending,
str, SYSTEM); str, SYSTEM, p->cxx_aware);
} }
} }
} }
...@@ -842,62 +748,132 @@ cpp_start_read (pfile, fname) ...@@ -842,62 +748,132 @@ cpp_start_read (pfile, fname)
{ {
/* XXX Potential memory leak! */ /* XXX Potential memory leak! */
char *str = xstrdup (update_path (p->fname, p->component)); char *str = xstrdup (update_path (p->fname, p->component));
append_include_chain (pfile, opts->pending, str, SYSTEM); 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.)
* Return 1 on success, 0 on failure.
*/
int
cpp_start_read (pfile, fname)
cpp_reader *pfile;
char *fname;
{
struct cpp_options *opts = CPP_OPTIONS (pfile);
struct pending_option *p, *q;
/* -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
inhibit compilation. */
if (opts->print_deps_missing_files
&& (opts->print_deps == 0 || !opts->no_output))
{
cpp_fatal (pfile, "-MG must be specified with one of -M or -MM");
return 0;
} }
/* Chill should not be used with -trigraphs. */
if (opts->chill && opts->trigraphs)
{
cpp_warning (pfile, "-lang-chill and -trigraphs are mutually exclusive");
opts->trigraphs = 0;
} }
/* 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. */
init_IStable ();
/* XXX Get rid of code that depends on this, then IStable can
be truly const. */
if (opts->dollars_in_ident)
IStable['$'] = ISidstart|ISidnum;
/* Set up the include search path now. */
if (! opts->no_standard_includes)
initialize_standard_includes (pfile);
merge_include_chains (opts); merge_include_chains (opts);
/* With -v, print the list of dirs to search. */ /* With -v, print the list of dirs to search. */
if (opts->verbose) if (opts->verbose)
{ {
struct file_name_list *p; struct file_name_list *l;
fprintf (stderr, _("#include \"...\" search starts here:\n")); fprintf (stderr, _("#include \"...\" search starts here:\n"));
for (p = opts->quote_include; p; p = p->next) for (l = opts->quote_include; l; l = l->next)
{ {
if (p == opts->bracket_include) if (l == opts->bracket_include)
fprintf (stderr, _("#include <...> search starts here:\n")); fprintf (stderr, _("#include <...> search starts here:\n"));
fprintf (stderr, " %s\n", p->name); fprintf (stderr, " %s\n", l->name);
} }
fprintf (stderr, _("End of search list.\n")); fprintf (stderr, _("End of search list.\n"));
} }
/* Don't bother trying to do macro expansion if we've already done initialize_dependency_output (pfile);
preprocessing. */
if (opts->preprocessed)
pfile->no_macro_expand++;
/* Open the main input file. /* Open the main input file. This must be done before -D processing
We do this in nonblocking mode so we don't get stuck here if so we have a buffer to stand on. */
someone clever has asked cpp to process /dev/rmt0; if (opts->in_fname == NULL || *opts->in_fname == 0)
finclude() will check that we have a real file to work with. */
if (fname == NULL || *fname == 0)
{ {
fname = ""; opts->in_fname = fname;
f = 0; if (opts->in_fname == NULL)
opts->in_fname = "";
} }
else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0)
{ if (!cpp_read_file (pfile, fname))
cpp_notice_from_errno (pfile, fname);
return 0; 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 (p->undef)
cpp_undef (pfile, p->arg);
else
cpp_define (pfile, p->arg);
q = p->next;
free (p);
p = q;
} }
initialize_dependency_output (pfile); p = opts->pending->assert_head;
while (p)
{
if (p->undef)
cpp_unassert (pfile, p->arg);
else
cpp_assert (pfile, p->arg);
q = p->next;
free (p);
p = q;
}
opts->done_initializing = 1;
CPP_BUFFER (pfile)->lineno = 1;
/* 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 (opts->preprocessed)
/* If we've already processed this code, we want to trust the #line /* 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 directives in the input. But we still need to update our line
...@@ -911,82 +887,29 @@ cpp_start_read (pfile, fname) ...@@ -911,82 +887,29 @@ cpp_start_read (pfile, fname)
have to be pushed onto the include stack and processed later, have to be pushed onto the include stack and processed later,
in the main loop calling cpp_get_token. */ in the main loop calling cpp_get_token. */
pfile->no_record_file++;
opts->no_output++; opts->no_output++;
p = opts->pending->imacros_head; p = opts->pending->imacros_head;
while (p) while (p)
{ {
int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666); if (cpp_read_file (pfile, p->arg))
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); cpp_scan_buffer (pfile);
}
else
cpp_pop_buffer (pfile);
free (ih_fake);
q = p->next; q = p->next;
free (p); free (p);
p = q; p = q;
} }
opts->no_output--; opts->no_output--;
p = opts->pending->include_head; p = opts->pending->include_head;
while (p) while (p)
{ {
int fd = open (p->arg, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666); if (cpp_read_file (pfile, p->arg))
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); output_line_command (pfile, enter_file);
}
else
cpp_pop_buffer (pfile);
q = p->next; q = p->next;
free (p); free (p);
p = q; p = q;
} }
pfile->no_record_file--;
free (opts->pending); free (opts->pending);
opts->pending = NULL; opts->pending = NULL;
...@@ -1141,7 +1064,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1141,7 +1064,7 @@ cpp_handle_option (pfile, argc, argv)
else else
fname = argv[++i]; fname = argv[++i];
append_include_chain (pfile, opts->pending, append_include_chain (pfile, opts->pending,
xstrdup (fname), BRACKET); xstrdup (fname), BRACKET, 0);
} }
break; break;
...@@ -1153,7 +1076,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1153,7 +1076,7 @@ cpp_handle_option (pfile, argc, argv)
if (i + 1 == argc) if (i + 1 == argc)
goto missing_filename; goto missing_filename;
append_include_chain (pfile, opts->pending, append_include_chain (pfile, opts->pending,
xstrdup (argv[++i]), SYSTEM); xstrdup (argv[++i]), SYSTEM, 0);
} }
else if (!strcmp (argv[i], "-include")) else if (!strcmp (argv[i], "-include"))
{ {
...@@ -1210,7 +1133,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1210,7 +1133,7 @@ cpp_handle_option (pfile, argc, argv)
memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1); 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, /* Add directory to main path for includes,
with the default prefix at the front of its name. */ with the default prefix at the front of its name. */
...@@ -1236,7 +1159,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1236,7 +1159,7 @@ cpp_handle_option (pfile, argc, argv)
memcpy (fname + sizeof GCC_INCLUDE_DIR - 9, argv[i], len + 1); 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. */ /* Add directory to end of path for includes. */
else if (!strcmp (argv[i], "-idirafter")) else if (!strcmp (argv[i], "-idirafter"))
...@@ -1244,7 +1167,7 @@ cpp_handle_option (pfile, argc, argv) ...@@ -1244,7 +1167,7 @@ cpp_handle_option (pfile, argc, argv)
if (i + 1 == argc) if (i + 1 == argc)
goto missing_dirname; goto missing_dirname;
append_include_chain (pfile, opts->pending, append_include_chain (pfile, opts->pending,
xstrdup (argv[++i]), AFTER); xstrdup (argv[++i]), AFTER, 0);
} }
else if (!strcmp (argv[i], "-iprefix")) else if (!strcmp (argv[i], "-iprefix"))
{ {
......
...@@ -654,7 +654,7 @@ get_macro_name (pfile) ...@@ -654,7 +654,7 @@ get_macro_name (pfile)
static int static int
do_define (pfile, keyword) do_define (pfile, keyword)
cpp_reader *pfile; cpp_reader *pfile;
const struct directive *keyword; const struct directive *keyword ATTRIBUTE_UNUSED;
{ {
HASHNODE *hp; HASHNODE *hp;
DEFINITION *def; DEFINITION *def;
...@@ -728,14 +728,11 @@ do_define (pfile, keyword) ...@@ -728,14 +728,11 @@ do_define (pfile, keyword)
else else
cpp_install (pfile, sym, len, T_MACRO, (char *) def); cpp_install (pfile, sym, len, T_MACRO, (char *) def);
if (keyword != NULL && keyword->type == T_DEFINE)
{
if (CPP_OPTIONS (pfile)->debug_output if (CPP_OPTIONS (pfile)->debug_output
|| CPP_OPTIONS (pfile)->dump_macros == dump_definitions) || CPP_OPTIONS (pfile)->dump_macros == dump_definitions)
dump_definition (pfile, sym, len, def); dump_definition (pfile, sym, len, def);
else if (CPP_OPTIONS (pfile)->dump_macros == dump_names) else if (CPP_OPTIONS (pfile)->dump_macros == dump_names)
pass_thru_directive (sym, len, pfile, keyword); pass_thru_directive (sym, len, pfile, keyword);
}
return 0; return 0;
} }
...@@ -876,7 +873,9 @@ cpp_expand_to_buffer (pfile, buf, length) ...@@ -876,7 +873,9 @@ cpp_expand_to_buffer (pfile, buf, length)
/* Scan the input, create the output. */ /* Scan the input, create the output. */
save_no_output = CPP_OPTIONS (pfile)->no_output; save_no_output = CPP_OPTIONS (pfile)->no_output;
CPP_OPTIONS (pfile)->no_output = 0; CPP_OPTIONS (pfile)->no_output = 0;
CPP_OPTIONS (pfile)->no_line_commands++;
cpp_scan_buffer (pfile); cpp_scan_buffer (pfile);
CPP_OPTIONS (pfile)->no_line_commands--;
CPP_OPTIONS (pfile)->no_output = save_no_output; CPP_OPTIONS (pfile)->no_output = save_no_output;
CPP_NUL_TERMINATE (pfile); CPP_NUL_TERMINATE (pfile);
...@@ -926,16 +925,14 @@ output_line_command (pfile, file_change) ...@@ -926,16 +925,14 @@ output_line_command (pfile, file_change)
enum file_change_code file_change; enum file_change_code file_change;
{ {
long line; long line;
cpp_buffer *ip = CPP_BUFFER (pfile); cpp_buffer *ip;
if (ip->fname == NULL)
return;
if (CPP_OPTIONS (pfile)->no_line_commands if (CPP_OPTIONS (pfile)->no_line_commands
|| CPP_OPTIONS (pfile)->no_output) || CPP_OPTIONS (pfile)->no_output)
return; 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 /* 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 appear to be a no-op, and we output a few newlines instead
......
...@@ -34,7 +34,8 @@ typedef struct cpp_reader cpp_reader; ...@@ -34,7 +34,8 @@ typedef struct cpp_reader cpp_reader;
typedef struct cpp_buffer cpp_buffer; typedef struct cpp_buffer cpp_buffer;
typedef struct cpp_options cpp_options; typedef struct cpp_options cpp_options;
enum cpp_token { enum cpp_token
{
CPP_EOF = -1, CPP_EOF = -1,
CPP_OTHER = 0, CPP_OTHER = 0,
CPP_COMMENT = 1, CPP_COMMENT = 1,
...@@ -222,11 +223,6 @@ struct cpp_reader ...@@ -222,11 +223,6 @@ struct cpp_reader
2: Only seen white space so far in this file. */ 2: Only seen white space so far in this file. */
char only_seen_white; 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;
long lineno; long lineno;
struct tm *timebuf; struct tm *timebuf;
...@@ -432,7 +428,6 @@ struct cpp_options { ...@@ -432,7 +428,6 @@ struct cpp_options {
char remap; char remap;
/* Nonzero means don't output line number information. */ /* Nonzero means don't output line number information. */
char no_line_commands; char no_line_commands;
/* Nonzero means -I- has been seen, /* Nonzero means -I- has been seen,
...@@ -713,6 +708,7 @@ extern int find_include_file PARAMS ((cpp_reader *, const char *, ...@@ -713,6 +708,7 @@ extern int find_include_file PARAMS ((cpp_reader *, const char *,
int *)); int *));
extern int finclude PARAMS ((cpp_reader *, int, extern int finclude PARAMS ((cpp_reader *, int,
struct include_hash *)); struct include_hash *));
extern int cpp_read_file PARAMS ((cpp_reader *, const char *));
extern void deps_output PARAMS ((cpp_reader *, extern void deps_output PARAMS ((cpp_reader *,
const char *, int)); const char *, int));
extern struct include_hash *include_hash PARAMS ((cpp_reader *, const char *, int)); extern struct include_hash *include_hash PARAMS ((cpp_reader *, const char *, int));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment