aboutsummaryrefslogtreecommitdiff
path: root/libcpp/files.c
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-11-19 04:43:13 -0800
committerNathan Sidwell <nathan@acm.org>2020-11-19 04:47:00 -0800
commitbf425849f1dfa11f509e9ec251056d1e769b1ac2 (patch)
treed73bb29cb66ee8d64169758fd9f46c9abfe72b91 /libcpp/files.c
parentd84ba819fe2f8bf49eddb7a3f42299a49d0206ea (diff)
downloadgcc-bf425849f1dfa11f509e9ec251056d1e769b1ac2.zip
gcc-bf425849f1dfa11f509e9ec251056d1e769b1ac2.tar.gz
gcc-bf425849f1dfa11f509e9ec251056d1e769b1ac2.tar.bz2
preprocessor: main-file cleanup
In preparing module patch 7 I realized there was a cleanup I could make to simplify it. This is that cleanup. Also, when doing the cleanup I noticed some macros had been turned into inline functions, but not renamed to the preprocessors internal namespace (_cpp_$INTERNAL rather than cpp_$USER). Thus, this renames those functions, deletes an internal field of the file structure, and determines whether we're in the main file by comparing to pfile->main_file, the _cpp_file of the main file. libcpp/ * internal.h (cpp_in_system_header): Rename to ... (_cpp_in_system_header): ... here. (cpp_in_primary_file): Rename to ... (_cpp_in_main_source_file): ... here. Compare main_file equality and check main_search value. * lex.c (maybe_va_opt_error, _cpp_lex_direct): Adjust for rename. * macro.c (_cpp_builtin_macro_text): Likewise. (replace_args): Likewise. * directives.c (do_include_next): Likewise. (do_pragma_once, do_pragma_system_header): Likewise. * files.c (struct _cpp_file): Delete main_file field. (pch_open): Check pfile->main_file equality. (make_cpp_file): Drop cpp_reader parm, don't set main_file. (_cpp_find_file): Adjust. (_cpp_stack_file): Check pfile->main_file equality. (struct report_missing_guard_data): Add cpp_reader field. (report_missing_guard): Check pfile->main_file equality. (_cpp_report_missing_guards): Adjust.
Diffstat (limited to 'libcpp/files.c')
-rw-r--r--libcpp/files.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/libcpp/files.c b/libcpp/files.c
index b5d9f30..ba52d2b 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -103,9 +103,6 @@ struct _cpp_file
/* If read() failed before. */
bool dont_read : 1;
- /* If this file is the main file. */
- bool main_file : 1;
-
/* If BUFFER above contains the true contents of the file. */
bool buffer_valid : 1;
@@ -186,7 +183,7 @@ static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int,
location_t);
static struct cpp_file_hash_entry *search_cache (struct cpp_file_hash_entry *head,
const cpp_dir *start_dir);
-static _cpp_file *make_cpp_file (cpp_reader *, cpp_dir *, const char *fname);
+static _cpp_file *make_cpp_file (cpp_dir *, const char *fname);
static void destroy_cpp_file (_cpp_file *);
static cpp_dir *make_cpp_dir (cpp_reader *, const char *dir_name, int sysp);
static void allocate_file_hash_entries (cpp_reader *pfile);
@@ -299,7 +296,7 @@ pch_open_file (cpp_reader *pfile, _cpp_file *file, bool *invalid_pch)
for (_cpp_file *f = pfile->all_files; f; f = f->next_file)
if (f->implicit_preinclude)
continue;
- else if (f->main_file)
+ else if (pfile->main_file == f)
break;
else
return false;
@@ -528,7 +525,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir,
if (entry)
return entry->u.file;
- _cpp_file *file = make_cpp_file (pfile, start_dir, fname);
+ _cpp_file *file = make_cpp_file (start_dir, fname);
file->implicit_preinclude
= (kind == _cpp_FFK_PRE_INCLUDE
|| (pfile->buffer && pfile->buffer->file->implicit_preinclude));
@@ -865,7 +862,7 @@ has_unique_contents (cpp_reader *pfile, _cpp_file *file, bool import,
{
/* We already have a buffer but it is not valid, because
the file is still stacked. Make a new one. */
- ref_file = make_cpp_file (pfile, f->dir, f->name);
+ ref_file = make_cpp_file (f->dir, f->name);
ref_file->path = f->path;
}
else
@@ -951,7 +948,8 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type,
if (CPP_OPTION (pfile, deps.style) > (sysp != 0)
&& !file->stack_count
&& file->path[0]
- && !(file->main_file && CPP_OPTION (pfile, deps.ignore_main_file)))
+ && !(pfile->main_file == file
+ && CPP_OPTION (pfile, deps.ignore_main_file)))
deps_add_dep (pfile->deps, file->path);
/* Clear buffer_valid since _cpp_clean_line messes it up. */
@@ -1187,12 +1185,9 @@ search_cache (struct cpp_file_hash_entry *head, const cpp_dir *start_dir)
/* Allocate a new _cpp_file structure. */
static _cpp_file *
-make_cpp_file (cpp_reader *pfile, cpp_dir *dir, const char *fname)
+make_cpp_file (cpp_dir *dir, const char *fname)
{
- _cpp_file *file;
-
- file = XCNEW (_cpp_file);
- file->main_file = !pfile->buffer;
+ _cpp_file *file = XCNEW (_cpp_file);
file->fd = -1;
file->dir = dir;
file->name = xstrdup (fname);
@@ -1452,6 +1447,7 @@ cpp_change_file (cpp_reader *pfile, enum lc_reason reason,
struct report_missing_guard_data
{
+ cpp_reader *pfile;
const char **paths;
size_t count;
};
@@ -1470,8 +1466,10 @@ report_missing_guard (void **slot, void *d)
_cpp_file *file = entry->u.file;
/* We don't want MI guard advice for the main file. */
- if (!file->once_only && file->cmacro == NULL
- && file->stack_count == 1 && !file->main_file)
+ if (!file->once_only
+ && file->cmacro == NULL
+ && file->stack_count == 1
+ && data->pfile->main_file != file)
{
if (data->paths == NULL)
{
@@ -1501,6 +1499,7 @@ _cpp_report_missing_guards (cpp_reader *pfile)
{
struct report_missing_guard_data data;
+ data.pfile = pfile;
data.paths = NULL;
data.count = htab_elements (pfile->file_hash);
htab_traverse (pfile->file_hash, report_missing_guard, &data);