Commit ba133c96 by Neil Booth Committed by Neil Booth

cpp.texi: Update documentation for -include and -imacros.

	* cpp.texi: Update documentation for -include and -imacros.
	* cppfiles.c (struct include_file): Remove "defined" memeber.
	(find_or_create_entry): Make a copy of the file name, and
	simplify it.
	(open_file): Update to ensure we use the simplified filename.
	(stack_include_file): Don't set search_from.
	(cpp_included): Don't simplify the path name here.
	(find_include_file): New prototype.  Call search_from to
	get the start of the "" include chain.  Don't simplify the
	filenames here.
	(_cpp_execute_include): New prototype.  Move diagnostics to
	do_include_common.  Update.
	(_cpp_pop_file_buffer): Don't set defined.
	(search_from): New prototype.  Use the preprocessor's cwd
	for files included from the command line.
	(read_name_map): Don't simplify the pathname here.
	* cpphash.h (enum include_type): New.
	(struct buffer): Delete search from.  New search_cached.
	(_cpp_execute_include): Update prototype.
	* cppinit.c (do_includes): Use _cpp_execute_include.
	* cpplib.c (do_include_common): New function.
	(do_include, do_include_next, do_import): Use it.

From-SVN: r40486
parent a3eab619
2001-03-15 Neil Booth <neil@daikokuya.demon.co.uk>
* cpp.texi: Update documentation for -include and -imacros.
* cppfiles.c (struct include_file): Remove "defined" memeber.
(find_or_create_entry): Make a copy of the file name, and
simplify it.
(open_file): Update to ensure we use the simplified filename.
(stack_include_file): Don't set search_from.
(cpp_included): Don't simplify the path name here.
(find_include_file): New prototype. Call search_from to
get the start of the "" include chain. Don't simplify the
filenames here.
(_cpp_execute_include): New prototype. Move diagnostics to
do_include_common. Update.
(_cpp_pop_file_buffer): Don't set defined.
(search_from): New prototype. Use the preprocessor's cwd
for files included from the command line.
(read_name_map): Don't simplify the pathname here.
* cpphash.h (enum include_type): New.
(struct buffer): Delete search from. New search_cached.
(_cpp_execute_include): Update prototype.
* cppinit.c (do_includes): Use _cpp_execute_include.
* cpplib.c (do_include_common): New function.
(do_include, do_include_next, do_import): Use it.
2001-03-14 Mark Mitchell <mark@codesourcery.com> 2001-03-14 Mark Mitchell <mark@codesourcery.com>
* varasm.c (assemble_alias): Use DECL_ASSEMBLER_NAME, not the * varasm.c (assemble_alias): Use DECL_ASSEMBLER_NAME, not the
......
...@@ -3596,16 +3596,31 @@ activities. ...@@ -3596,16 +3596,31 @@ activities.
@item -imacros @var{file} @item -imacros @var{file}
@findex -imacros @findex -imacros
Process @var{file} as input, discarding the resulting output, before Process @var{file} as input and discard the resulting output.
processing the regular input file. Because the output generated from
@var{file} is discarded, the only effect of @samp{-imacros @var{file}} This has all the effects of @code{#include "file"} appearing on the
is to make the macros defined in @var{file} available for use in the first line of the main source file, such as generating dependencies and
main input. being listed with the @samp{-H} option, except that no output is
generated, and that the first directory searched for @var{file} is the
preprocessor's working directory @emph{instead of} the directory
containing the main source file. If not found there, it is searched for
in the remainder of the @code{#include "..."} search chain as normal.
Because the output is discarded, the main effect of @samp{-imacros
@var{file}} is to make the macros defined in @var{file} available for
use in the main input.
@item -include @var{file} @item -include @var{file}
@findex -include @findex -include
Process @var{file} as input, and include all the resulting output, Process @var{file} as input, and include all the resulting output.
before processing the regular input file.
This has all the effects of @code{#include "file"} appearing on the
first line of the main source file, such as generating dependencies and
being listed with the @samp{-H} option, except that the first directory
searched for @var{file} is the preprocessor's working directory
@emph{instead of} the directory containing the main source file. If not
found there, it is searched for in the remainder of the @code{#include
"..."} search chain as normal.
@item -idirafter @var{dir} @item -idirafter @var{dir}
@findex -idirafter @findex -idirafter
......
...@@ -70,18 +70,16 @@ struct include_file ...@@ -70,18 +70,16 @@ struct include_file
unsigned short include_count; /* number of times file has been read */ unsigned short include_count; /* number of times file has been read */
unsigned short refcnt; /* number of stacked buffers using this file */ unsigned short refcnt; /* number of stacked buffers using this file */
unsigned char mapped; /* file buffer is mmapped */ unsigned char mapped; /* file buffer is mmapped */
unsigned char defined; /* cmacro prevents inclusion in this state */
}; };
/* The cmacro works like this: If it's NULL, the file is to be /* The cmacro works like this: If it's NULL, the file is to be
included again. If it's NEVER_REREAD, the file is never to be included again. If it's NEVER_REREAD, the file is never to be
included again. Otherwise it is a macro hashnode, and the file is included again. Otherwise it is a macro hashnode, and the file is
to be included again if the macro is defined or not as specified by to be included again if the macro is defined. */
DEFINED. */
#define NEVER_REREAD ((const cpp_hashnode *)-1) #define NEVER_REREAD ((const cpp_hashnode *)-1)
#define DO_NOT_REREAD(inc) \ #define DO_NOT_REREAD(inc) \
((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \ ((inc)->cmacro && ((inc)->cmacro == NEVER_REREAD \
|| ((inc)->cmacro->type == NT_MACRO) == (inc)->defined)) || (inc)->cmacro->type == NT_MACRO))
#define NO_INCLUDE_PATH ((struct include_file *) -1) #define NO_INCLUDE_PATH ((struct include_file *) -1)
static struct file_name_map *read_name_map static struct file_name_map *read_name_map
...@@ -90,9 +88,10 @@ static char *read_filename_string PARAMS ((int, FILE *)); ...@@ -90,9 +88,10 @@ static char *read_filename_string PARAMS ((int, FILE *));
static char *remap_filename PARAMS ((cpp_reader *, char *, static char *remap_filename PARAMS ((cpp_reader *, char *,
struct search_path *)); struct search_path *));
static struct search_path *search_from PARAMS ((cpp_reader *, static struct search_path *search_from PARAMS ((cpp_reader *,
struct include_file *)); enum include_type));
static struct include_file * static struct include_file *
find_include_file PARAMS ((cpp_reader *, const cpp_token *, int)); find_include_file PARAMS ((cpp_reader *, const cpp_token *,
enum include_type));
static struct include_file *open_file PARAMS ((cpp_reader *, const char *)); static struct include_file *open_file PARAMS ((cpp_reader *, const char *));
static void read_include_file PARAMS ((cpp_reader *, struct include_file *)); static void read_include_file PARAMS ((cpp_reader *, struct include_file *));
static void stack_include_file PARAMS ((cpp_reader *, struct include_file *)); static void stack_include_file PARAMS ((cpp_reader *, struct include_file *));
...@@ -155,7 +154,8 @@ _cpp_never_reread (file) ...@@ -155,7 +154,8 @@ _cpp_never_reread (file)
file->cmacro = NEVER_REREAD; file->cmacro = NEVER_REREAD;
} }
/* Lookup a simplified filename, and create an entry if none exists. */ /* Lookup a filename, which is simplified after making a copy, and
create an entry if none exists. */
static splay_tree_node static splay_tree_node
find_or_create_entry (pfile, fname) find_or_create_entry (pfile, fname)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -163,12 +163,16 @@ find_or_create_entry (pfile, fname) ...@@ -163,12 +163,16 @@ find_or_create_entry (pfile, fname)
{ {
splay_tree_node node; splay_tree_node node;
struct include_file *file; struct include_file *file;
char *name = xstrdup (fname);
node = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) fname); _cpp_simplify_pathname (name);
if (! node) node = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) name);
if (node)
free (name);
else
{ {
file = xcnew (struct include_file); file = xcnew (struct include_file);
file->name = xstrdup (fname); file->name = name;
node = splay_tree_insert (pfile->all_include_files, node = splay_tree_insert (pfile->all_include_files,
(splay_tree_key) file->name, (splay_tree_key) file->name,
(splay_tree_value) file); (splay_tree_value) file);
...@@ -177,8 +181,7 @@ find_or_create_entry (pfile, fname) ...@@ -177,8 +181,7 @@ find_or_create_entry (pfile, fname)
return node; return node;
} }
/* Enter a simplified file name in the splay tree, for the sake of /* Enter a file name in the splay tree, for the sake of cpp_included. */
cpp_included (). */
void void
_cpp_fake_include (pfile, fname) _cpp_fake_include (pfile, fname)
cpp_reader *pfile; cpp_reader *pfile;
...@@ -234,7 +237,7 @@ open_file (pfile, filename) ...@@ -234,7 +237,7 @@ open_file (pfile, filename)
if (filename[0] == '\0') if (filename[0] == '\0')
file->fd = 0; file->fd = 0;
else else
file->fd = open (filename, O_RDONLY | O_NOCTTY | O_BINARY, 0666); file->fd = open (file->name, O_RDONLY | O_NOCTTY | O_BINARY, 0666);
if (file->fd != -1 && fstat (file->fd, &file->st) == 0) if (file->fd != -1 && fstat (file->fd, &file->st) == 0)
{ {
...@@ -251,7 +254,7 @@ open_file (pfile, filename) ...@@ -251,7 +254,7 @@ open_file (pfile, filename)
/* Don't issue an error message if the file doesn't exist. */ /* Don't issue an error message if the file doesn't exist. */
if (errno != ENOENT && errno != ENOTDIR) if (errno != ENOENT && errno != ENOTDIR)
cpp_error_from_errno (pfile, filename); cpp_error_from_errno (pfile, file->name);
/* Create a negative node for this path, and return null. */ /* Create a negative node for this path, and return null. */
file->fd = -2; file->fd = -2;
...@@ -308,7 +311,6 @@ stack_include_file (pfile, inc) ...@@ -308,7 +311,6 @@ stack_include_file (pfile, inc)
fp->inc = inc; fp->inc = inc;
fp->inc->refcnt++; fp->inc->refcnt++;
fp->sysp = sysp; fp->sysp = sysp;
fp->search_from = search_from (pfile, inc);
/* Initialise controlling macro state. */ /* Initialise controlling macro state. */
pfile->mi_state = MI_OUTSIDE; pfile->mi_state = MI_OUTSIDE;
...@@ -487,7 +489,7 @@ cpp_included (pfile, fname) ...@@ -487,7 +489,7 @@ cpp_included (pfile, fname)
if (CPP_OPTION (pfile, remap)) if (CPP_OPTION (pfile, remap))
n = remap_filename (pfile, name, path); n = remap_filename (pfile, name, path);
else else
n = _cpp_simplify_pathname (name); n = name;
nd = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) n); nd = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) n);
if (nd && nd->value) if (nd && nd->value)
...@@ -503,10 +505,10 @@ cpp_included (pfile, fname) ...@@ -503,10 +505,10 @@ cpp_included (pfile, fname)
from a #include_next directive, set INCLUDE_NEXT to true. */ from a #include_next directive, set INCLUDE_NEXT to true. */
static struct include_file * static struct include_file *
find_include_file (pfile, header, include_next) find_include_file (pfile, header, type)
cpp_reader *pfile; cpp_reader *pfile;
const cpp_token *header; const cpp_token *header;
int include_next; enum include_type type;
{ {
const char *fname = (const char *) header->val.str.text; const char *fname = (const char *) header->val.str.text;
struct search_path *path; struct search_path *path;
...@@ -519,12 +521,12 @@ find_include_file (pfile, header, include_next) ...@@ -519,12 +521,12 @@ find_include_file (pfile, header, include_next)
/* For #include_next, skip in the search path past the dir in which /* For #include_next, skip in the search path past the dir in which
the current file was found, but if it was found via an absolute the current file was found, but if it was found via an absolute
path use the normal search logic. */ path use the normal search logic. */
if (include_next && pfile->buffer->inc->foundhere) if (type == IT_INCLUDE_NEXT && pfile->buffer->inc->foundhere)
path = pfile->buffer->inc->foundhere->next; path = pfile->buffer->inc->foundhere->next;
else if (header->type == CPP_HEADER_NAME) else if (header->type == CPP_HEADER_NAME)
path = CPP_OPTION (pfile, bracket_include); path = CPP_OPTION (pfile, bracket_include);
else else
path = pfile->buffer->search_from; path = search_from (pfile, type);
if (path == NULL) if (path == NULL)
{ {
...@@ -542,7 +544,7 @@ find_include_file (pfile, header, include_next) ...@@ -542,7 +544,7 @@ find_include_file (pfile, header, include_next)
if (CPP_OPTION (pfile, remap)) if (CPP_OPTION (pfile, remap))
n = remap_filename (pfile, name, path); n = remap_filename (pfile, name, path);
else else
n = _cpp_simplify_pathname (name); n = name;
file = open_file (pfile, n); file = open_file (pfile, n);
if (file) if (file)
...@@ -653,30 +655,14 @@ handle_missing_header (pfile, fname, angle_brackets) ...@@ -653,30 +655,14 @@ handle_missing_header (pfile, fname, angle_brackets)
cpp_error_from_errno (pfile, fname); cpp_error_from_errno (pfile, fname);
} }
void /* Returns non-zero if a buffer was stacked. */
_cpp_execute_include (pfile, header, no_reinclude, include_next) int
_cpp_execute_include (pfile, header, type)
cpp_reader *pfile; cpp_reader *pfile;
const cpp_token *header; const cpp_token *header;
int no_reinclude; enum include_type type;
int include_next;
{ {
struct include_file *inc; struct include_file *inc = find_include_file (pfile, header, type);
/* Help protect #include or similar from recursion. */
if (pfile->buffer_stack_depth >= CPP_STACK_MAX)
{
cpp_fatal (pfile, "#include nested too deeply");
return;
}
/* Check we've tidied up #include before entering the buffer. */
if (pfile->context->prev)
{
cpp_ice (pfile, "attempt to push file buffer with contexts stacked");
return;
}
inc = find_include_file (pfile, header, include_next);
if (inc == 0) if (inc == 0)
handle_missing_header (pfile, (const char *) header->val.str.text, handle_missing_header (pfile, (const char *) header->val.str.text,
...@@ -688,9 +674,13 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next) ...@@ -688,9 +674,13 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
stack_include_file (pfile, inc); stack_include_file (pfile, inc);
if (no_reinclude) if (type == IT_IMPORT)
_cpp_never_reread (inc); _cpp_never_reread (inc);
return 1;
} }
return 0;
} }
/* Locate HEADER, and determine whether it is newer than the current /* Locate HEADER, and determine whether it is newer than the current
...@@ -749,13 +739,10 @@ _cpp_pop_file_buffer (pfile, buf) ...@@ -749,13 +739,10 @@ _cpp_pop_file_buffer (pfile, buf)
if (pfile->include_depth) if (pfile->include_depth)
pfile->include_depth--; pfile->include_depth--;
/* Record the inclusion-preventing macro and its definedness. */ /* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro, if we haven't got it already. */
if (pfile->mi_state == MI_OUTSIDE && inc->cmacro == NULL) if (pfile->mi_state == MI_OUTSIDE && inc->cmacro == NULL)
{
/* This could be NULL meaning no controlling macro. */
inc->cmacro = pfile->mi_cmacro; inc->cmacro = pfile->mi_cmacro;
inc->defined = 1;
}
/* Invalidate control macros in the #including file. */ /* Invalidate control macros in the #including file. */
pfile->mi_state = MI_FAILED; pfile->mi_state = MI_FAILED;
...@@ -767,31 +754,44 @@ _cpp_pop_file_buffer (pfile, buf) ...@@ -767,31 +754,44 @@ _cpp_pop_file_buffer (pfile, buf)
/* Returns the first place in the include chain to start searching for /* Returns the first place in the include chain to start searching for
"" includes. This involves stripping away the basename of the "" includes. This involves stripping away the basename of the
current file, unless -I- was specified. */ current file, unless -I- was specified.
If we're handling -include or -imacros, use the "" chain, but with
the preprocessor's cwd prepended. */
static struct search_path * static struct search_path *
search_from (pfile, inc) search_from (pfile, type)
cpp_reader *pfile; cpp_reader *pfile;
struct include_file *inc; enum include_type type;
{ {
cpp_buffer *buffer = pfile->buffer; cpp_buffer *buffer = pfile->buffer;
unsigned int dlen; unsigned int dlen;
/* Command line uses the cwd, and does not cache the result. */
if (type == IT_CMDLINE)
goto use_cwd;
/* Ignore the current file's directory if -I- was given. */ /* Ignore the current file's directory if -I- was given. */
if (CPP_OPTION (pfile, ignore_srcdir)) if (CPP_OPTION (pfile, ignore_srcdir))
return CPP_OPTION (pfile, quote_include); return CPP_OPTION (pfile, quote_include);
dlen = lbasename (inc->name) - inc->name; if (! buffer->search_cached)
{
buffer->search_cached = 1;
dlen = lbasename (buffer->inc->name) - buffer->inc->name;
if (dlen) if (dlen)
{ {
/* We don't guarantee NAME is null-terminated. This saves /* We don't guarantee NAME is null-terminated. This saves
allocating and freeing memory, and duplicating it when faking allocating and freeing memory, and duplicating it when faking
buffers in cpp_push_buffer. Drop a trailing '/'. */ buffers in cpp_push_buffer. Drop a trailing '/'. */
buffer->dir.name = inc->name; buffer->dir.name = buffer->inc->name;
if (dlen > 1) if (dlen > 1)
dlen--; dlen--;
} }
else else
{ {
use_cwd:
buffer->dir.name = "."; buffer->dir.name = ".";
dlen = 1; dlen = 1;
} }
...@@ -802,6 +802,7 @@ search_from (pfile, inc) ...@@ -802,6 +802,7 @@ search_from (pfile, inc)
buffer->dir.len = dlen; buffer->dir.len = dlen;
buffer->dir.next = CPP_OPTION (pfile, quote_include); buffer->dir.next = CPP_OPTION (pfile, quote_include);
buffer->dir.sysp = buffer->sysp; buffer->dir.sysp = buffer->sysp;
}
return &buffer->dir; return &buffer->dir;
} }
...@@ -928,8 +929,6 @@ read_name_map (pfile, dirname) ...@@ -928,8 +929,6 @@ read_name_map (pfile, dirname)
strcpy (ptr->map_to + dirlen + 1, to); strcpy (ptr->map_to + dirlen + 1, to);
free (to); free (to);
} }
/* Simplify the result now. */
_cpp_simplify_pathname (ptr->map_to);
ptr->map_next = map_list_ptr->map_list_map; ptr->map_next = map_list_ptr->map_list_map;
map_list_ptr->map_list_map = ptr; map_list_ptr->map_list_map = ptr;
......
...@@ -96,6 +96,9 @@ struct search_path ...@@ -96,6 +96,9 @@ struct search_path
enum mi_state {MI_FAILED = 0, MI_OUTSIDE}; enum mi_state {MI_FAILED = 0, MI_OUTSIDE};
enum mi_ind {MI_IND_NONE = 0, MI_IND_NOT}; enum mi_ind {MI_IND_NONE = 0, MI_IND_NOT};
/* #include types. */
enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE};
typedef struct toklist toklist; typedef struct toklist toklist;
struct toklist struct toklist
{ {
...@@ -222,17 +225,16 @@ struct cpp_buffer ...@@ -222,17 +225,16 @@ struct cpp_buffer
containing files that matches the current status. */ containing files that matches the current status. */
unsigned char include_stack_listed; unsigned char include_stack_listed;
/* Nonzero means that the directory to start searching for ""
include files has been calculated and stored in "dir" below. */
unsigned char search_cached;
/* Buffer type. */ /* Buffer type. */
ENUM_BITFIELD (cpp_buffer_type) type : 8; ENUM_BITFIELD (cpp_buffer_type) type : 8;
/* The directory of the this buffer's file. Its NAME member is not /* The directory of the this buffer's file. Its NAME member is not
allocated, so we don't need to worry about freeing it. */ allocated, so we don't need to worry about freeing it. */
struct search_path dir; struct search_path dir;
/* The directory to start searching for "" include files. Is either
"dir" above, or options.quote_include, depending upon whether -I-
was on the command line. */
struct search_path *search_from;
}; };
/* A cpp_reader encapsulates the "state" of a pre-processor run. /* A cpp_reader encapsulates the "state" of a pre-processor run.
...@@ -411,8 +413,9 @@ extern void _cpp_fake_include PARAMS ((cpp_reader *, const char *)); ...@@ -411,8 +413,9 @@ extern void _cpp_fake_include PARAMS ((cpp_reader *, const char *));
extern void _cpp_never_reread PARAMS ((struct include_file *)); extern void _cpp_never_reread PARAMS ((struct include_file *));
extern char *_cpp_simplify_pathname PARAMS ((char *)); extern char *_cpp_simplify_pathname PARAMS ((char *));
extern int _cpp_read_file PARAMS ((cpp_reader *, const char *)); extern int _cpp_read_file PARAMS ((cpp_reader *, const char *));
extern void _cpp_execute_include PARAMS ((cpp_reader *, extern int _cpp_execute_include PARAMS ((cpp_reader *,
const cpp_token *, int, int)); const cpp_token *,
enum include_type));
extern int _cpp_compare_file_date PARAMS ((cpp_reader *, extern int _cpp_compare_file_date PARAMS ((cpp_reader *,
const cpp_token *)); const cpp_token *));
extern void _cpp_report_missing_guards PARAMS ((cpp_reader *)); extern void _cpp_report_missing_guards PARAMS ((cpp_reader *));
......
...@@ -885,8 +885,15 @@ do_includes (pfile, p, scan) ...@@ -885,8 +885,15 @@ do_includes (pfile, p, scan)
use the #include "" search path if cpp_read_file fails. */ use the #include "" search path if cpp_read_file fails. */
if (CPP_OPTION (pfile, preprocessed)) if (CPP_OPTION (pfile, preprocessed))
cpp_error (pfile, "-include and -imacros cannot be used with -fpreprocessed"); cpp_error (pfile, "-include and -imacros cannot be used with -fpreprocessed");
else if (_cpp_read_file (pfile, p->arg) && scan) else
{
cpp_token header;
header.type = CPP_STRING;
header.val.str.text = (const unsigned char *) p->arg;
header.val.str.len = strlen (p->arg);
if (_cpp_execute_include (pfile, &header, IT_CMDLINE) && scan)
cpp_scan_buffer_nooutput (pfile, 0); cpp_scan_buffer_nooutput (pfile, 0);
}
q = p->next; q = p->next;
free (p); free (p);
p = q; p = q;
......
...@@ -95,6 +95,7 @@ static int strtoul_for_line PARAMS ((const U_CHAR *, unsigned int, ...@@ -95,6 +95,7 @@ static int strtoul_for_line PARAMS ((const U_CHAR *, unsigned int,
unsigned long *)); unsigned long *));
static void do_diagnostic PARAMS ((cpp_reader *, enum error_type, int)); static void do_diagnostic PARAMS ((cpp_reader *, enum error_type, int));
static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *)); static cpp_hashnode *lex_macro_node PARAMS ((cpp_reader *));
static void do_include_common PARAMS ((cpp_reader *, enum include_type));
static void do_pragma_once PARAMS ((cpp_reader *)); static void do_pragma_once PARAMS ((cpp_reader *));
static void do_pragma_poison PARAMS ((cpp_reader *)); static void do_pragma_poison PARAMS ((cpp_reader *));
static void do_pragma_system_header PARAMS ((cpp_reader *)); static void do_pragma_system_header PARAMS ((cpp_reader *));
...@@ -585,22 +586,47 @@ parse_include (pfile, header) ...@@ -585,22 +586,47 @@ parse_include (pfile, header)
return 0; return 0;
} }
/* Handle #include, #include_next and #import. */
static void static void
do_include (pfile) do_include_common (pfile, type)
cpp_reader *pfile; cpp_reader *pfile;
enum include_type type;
{ {
cpp_token header; cpp_token header;
if (!parse_include (pfile, &header)) if (!parse_include (pfile, &header))
_cpp_execute_include (pfile, &header, 0, 0); {
/* Prevent #include recursion. */
if (pfile->buffer_stack_depth >= CPP_STACK_MAX)
cpp_fatal (pfile, "#include nested too deeply");
else if (pfile->context->prev)
cpp_ice (pfile, "attempt to push file buffer with contexts stacked");
else
{
/* For #include_next, if this is the primary source file,
warn and use the normal search logic. */
if (type == IT_INCLUDE_NEXT && ! pfile->buffer->prev)
{
cpp_warning (pfile, "#include_next in primary source file");
type = IT_INCLUDE;
}
_cpp_execute_include (pfile, &header, type);
}
}
} }
static void static void
do_import (pfile) do_include (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_token header; do_include_common (pfile, IT_INCLUDE);
}
static void
do_import (pfile)
cpp_reader *pfile;
{
if (!pfile->import_warning && CPP_OPTION (pfile, warn_import)) if (!pfile->import_warning && CPP_OPTION (pfile, warn_import))
{ {
pfile->import_warning = 1; pfile->import_warning = 1;
...@@ -608,25 +634,14 @@ do_import (pfile) ...@@ -608,25 +634,14 @@ do_import (pfile)
"#import is obsolete, use an #ifndef wrapper in the header file"); "#import is obsolete, use an #ifndef wrapper in the header file");
} }
if (!parse_include (pfile, &header)) do_include_common (pfile, IT_IMPORT);
_cpp_execute_include (pfile, &header, 1, 0);
} }
static void static void
do_include_next (pfile) do_include_next (pfile)
cpp_reader *pfile; cpp_reader *pfile;
{ {
cpp_token header; do_include_common (pfile, IT_INCLUDE_NEXT);
if (!parse_include (pfile, &header))
{
/* If this is the primary source file, warn and use the normal
search logic. */
if (! pfile->buffer->prev)
cpp_warning (pfile, "#include_next in primary source file");
_cpp_execute_include (pfile, &header, 0, pfile->buffer->prev != 0);
}
} }
/* Subroutine of do_line. Read possible flags after file name. LAST /* Subroutine of do_line. Read possible flags after file name. LAST
......
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