Commit e5eba70a by Neil Booth Committed by Neil Booth

cppfiles.c (stack_include_file): Harmonize system headerness tests.

	* cppfiles.c (stack_include_file): Harmonize system headerness tests.
	* cppfiles.c (stack_include_file): Only stack a file if there
	is something to do.  Return a boolean indicating whether a
	buffer was stacked or not.
	(_cpp_execute_include): Similarly.
	(_cpp_read_file): Similarly.
	* cpphash.h (_cpp_read_file, _cpp_execute_include): Update prototypes.

From-SVN: r45083
parent c1a6a8dc
2001-08-21 Neil Booth <neil@daikokuya.demon.co.uk>
* cppfiles.c (stack_include_file): Harmonize system headerness tests.
* cppfiles.c (stack_include_file): Only stack a file if there
is something to do. Return a boolean indicating whether a
buffer was stacked or not.
(_cpp_execute_include): Similarly.
(_cpp_read_file): Similarly.
* cpphash.h (_cpp_read_file, _cpp_execute_include): Update prototypes.
2001-08-21 Sam Steingold <sds@gnu.org> 2001-08-21 Sam Steingold <sds@gnu.org>
* tradcpp.c (rescan): define obufp_before_macroname before RECACHE * tradcpp.c (rescan): define obufp_before_macroname before RECACHE
......
...@@ -95,7 +95,7 @@ static struct include_file * ...@@ -95,7 +95,7 @@ static struct include_file *
enum include_type)); 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 int read_include_file PARAMS ((cpp_reader *, struct include_file *)); static int read_include_file PARAMS ((cpp_reader *, struct include_file *));
static void stack_include_file PARAMS ((cpp_reader *, struct include_file *)); static bool stack_include_file PARAMS ((cpp_reader *, struct include_file *));
static void purge_cache PARAMS ((struct include_file *)); static void purge_cache PARAMS ((struct include_file *));
static void destroy_node PARAMS ((splay_tree_value)); static void destroy_node PARAMS ((splay_tree_value));
static int report_missing_guard PARAMS ((splay_tree_node, void *)); static int report_missing_guard PARAMS ((splay_tree_node, void *));
...@@ -275,59 +275,59 @@ open_file (pfile, filename) ...@@ -275,59 +275,59 @@ open_file (pfile, filename)
return 0; return 0;
} }
/* Place the file referenced by INC into a new buffer on PFILE's /* Place the file referenced by INC into a new buffer on the buffer
stack. If there are errors, or the file should not be re-included, stack, unless there are errors, or the file is not re-included
a null (zero-length) buffer is pushed. */ because of e.g. multiple-include guards. Returns true if a buffer
is stacked. */
static void static bool
stack_include_file (pfile, inc) stack_include_file (pfile, inc)
cpp_reader *pfile; cpp_reader *pfile;
struct include_file *inc; struct include_file *inc;
{ {
size_t len = 0;
cpp_buffer *fp; cpp_buffer *fp;
int sysp, deps_sysp; int sysp;
const char *filename; const char *filename;
/* We'll try removing deps_sysp after the release of 3.0. */ if (DO_NOT_REREAD (inc))
deps_sysp = pfile->system_include_depth != 0; return false;
sysp = MAX ((pfile->map ? pfile->map->sysp : 0), sysp = MAX ((pfile->map ? pfile->map->sysp : 0),
(inc->foundhere ? inc->foundhere->sysp : 0)); (inc->foundhere ? inc->foundhere->sysp : 0));
/* For -M, add the file to the dependencies on its first inclusion. */ /* For -M, add the file to the dependencies on its first inclusion. */
if (CPP_OPTION (pfile, print_deps) > deps_sysp && !inc->include_count) if (CPP_OPTION (pfile, print_deps) > sysp && !inc->include_count)
deps_add_dep (pfile->deps, inc->name); deps_add_dep (pfile->deps, inc->name);
/* Not in cache? */ /* Not in cache? */
if (! DO_NOT_REREAD (inc) && ! inc->buffer) if (! inc->buffer)
{ {
/* If an error occurs, do not try to read this file again. */ /* If an error occurs, do not try to read this file again. */
if (read_include_file (pfile, inc)) if (read_include_file (pfile, inc))
_cpp_never_reread (inc); {
_cpp_never_reread (inc);
return false;
}
close (inc->fd); close (inc->fd);
inc->fd = -1; inc->fd = -1;
} }
if (! DO_NOT_REREAD (inc)) if (pfile->buffer)
{ {
len = inc->st.st_size; /* We don't want MI guard advice for the main file. */
if (pfile->buffer) inc->include_count++;
{
/* We don't want MI guard advice for the main file. */
inc->include_count++;
/* Handle -H option. */ /* Handle -H option. */
if (CPP_OPTION (pfile, print_include_names)) if (CPP_OPTION (pfile, print_include_names))
{ {
for (fp = pfile->buffer; fp; fp = fp->prev) for (fp = pfile->buffer; fp; fp = fp->prev)
putc ('.', stderr); putc ('.', stderr);
fprintf (stderr, " %s\n", inc->name); fprintf (stderr, " %s\n", inc->name);
}
} }
} }
/* Push a buffer. */ /* Push a buffer. */
fp = cpp_push_buffer (pfile, inc->buffer, len, BUF_FILE, 0); fp = cpp_push_buffer (pfile, inc->buffer, inc->st.st_size, BUF_FILE, 0);
fp->inc = inc; fp->inc = inc;
fp->inc->refcnt++; fp->inc->refcnt++;
...@@ -341,6 +341,8 @@ stack_include_file (pfile, inc) ...@@ -341,6 +341,8 @@ stack_include_file (pfile, inc)
if (*filename == '\0') if (*filename == '\0')
filename = _("<stdin>"); filename = _("<stdin>");
_cpp_do_file_change (pfile, LC_ENTER, filename, 1, sysp); _cpp_do_file_change (pfile, LC_ENTER, filename, 1, sysp);
return true;
} }
/* Read the file referenced by INC into the file cache. /* Read the file referenced by INC into the file cache.
...@@ -663,13 +665,15 @@ handle_missing_header (pfile, fname, angle_brackets) ...@@ -663,13 +665,15 @@ handle_missing_header (pfile, fname, angle_brackets)
cpp_error_from_errno (pfile, fname); cpp_error_from_errno (pfile, fname);
} }
/* Returns non-zero if a buffer was stacked. */ /* Handles #include-family directives, and the command line -imacros
int and -include. Returns true if a buffer was stacked. */
bool
_cpp_execute_include (pfile, header, type) _cpp_execute_include (pfile, header, type)
cpp_reader *pfile; cpp_reader *pfile;
const cpp_token *header; const cpp_token *header;
enum include_type type; enum include_type type;
{ {
bool stacked = false;
struct include_file *inc = find_include_file (pfile, header, type); struct include_file *inc = find_include_file (pfile, header, type);
if (inc == 0) if (inc == 0)
...@@ -680,15 +684,13 @@ _cpp_execute_include (pfile, header, type) ...@@ -680,15 +684,13 @@ _cpp_execute_include (pfile, header, type)
if (header->type == CPP_HEADER_NAME) if (header->type == CPP_HEADER_NAME)
pfile->system_include_depth++; pfile->system_include_depth++;
stack_include_file (pfile, inc); stacked = stack_include_file (pfile, inc);
if (type == IT_IMPORT) if (type == IT_IMPORT)
_cpp_never_reread (inc); _cpp_never_reread (inc);
return 1;
} }
return 0; return stacked;
} }
/* Locate HEADER, and determine whether it is newer than the current /* Locate HEADER, and determine whether it is newer than the current
...@@ -714,23 +716,23 @@ _cpp_compare_file_date (pfile, header) ...@@ -714,23 +716,23 @@ _cpp_compare_file_date (pfile, header)
} }
/* Push an input buffer and load it up with the contents of FNAME. /* Push an input buffer and load it up with the contents of FNAME. If
If FNAME is "", read standard input. */ FNAME is "", read standard input. Return true if a buffer was
int stacked. */
bool
_cpp_read_file (pfile, fname) _cpp_read_file (pfile, fname)
cpp_reader *pfile; cpp_reader *pfile;
const char *fname; const char *fname;
{ {
struct include_file *f = open_file (pfile, fname); struct include_file *f = open_file (pfile, fname);
bool stacked = false;
if (f == NULL) if (f == NULL)
{ cpp_error_from_errno (pfile, fname);
cpp_error_from_errno (pfile, fname); else
return 0; stacked = stack_include_file (pfile, f);
}
stack_include_file (pfile, f); return stacked;
return 1;
} }
/* Do appropriate cleanup when a file buffer is popped off the input /* Do appropriate cleanup when a file buffer is popped off the input
......
...@@ -391,8 +391,8 @@ extern void _cpp_destroy_hashtable PARAMS ((cpp_reader *)); ...@@ -391,8 +391,8 @@ extern void _cpp_destroy_hashtable PARAMS ((cpp_reader *));
extern void _cpp_fake_include PARAMS ((cpp_reader *, const char *)); 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 bool _cpp_read_file PARAMS ((cpp_reader *, const char *));
extern int _cpp_execute_include PARAMS ((cpp_reader *, extern bool _cpp_execute_include PARAMS ((cpp_reader *,
const cpp_token *, const cpp_token *,
enum include_type)); enum include_type));
extern int _cpp_compare_file_date PARAMS ((cpp_reader *, extern int _cpp_compare_file_date PARAMS ((cpp_reader *,
......
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