aboutsummaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-05-20 06:21:10 -0700
committerNathan Sidwell <nathan@acm.org>2020-05-20 06:23:24 -0700
commit4623a6f2d026b6b6dcd4c9b6f26e96cf5e52b4ac (patch)
tree802098af1ee0bf4645320883d7675976d0dbfac4 /libcpp
parent610ae2dbbf98a291782cb05c0fb31e056193e5e2 (diff)
preprocessor: Replace some flags with a single enum
_cpp_find_file has 3 bool arguments, at most one of which is ever set. Ripe for replacing with a 4-state enum. Also, this is C++, so 'typedef struct Foo Foo' is unnecessary. * internal.h (typedef _cpp_file): Delete, unnecessary in C++. (enum _cpp_find_file_kind): New. (_cpp_find_file): Use it, not 3 bools. * files.c (_cpp_find_file): Use _cpp_find_file_kind enum, not bools. (cpp_make_system_header): Break overly long line. (_cpp_stack_include, _cpp_fake_include) (_cpp_do_file_change, _cpp_compare_file_date, _cpp_has_header): Adjust. * init.c (cpp_read_main): Adjust _cpp_find_file call.
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog12
-rw-r--r--libcpp/files.c48
-rw-r--r--libcpp/init.c5
-rw-r--r--libcpp/internal.h6
4 files changed, 36 insertions, 35 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 040de527b72..622260391da 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,15 @@
+2020-05-20 Nathan Sidwell <nathan@acm.org>
+
+ * internal.h (typedef _cpp_file): Delete, unnecessary in C++.
+ (enum _cpp_find_file_kind): New.
+ (_cpp_find_file): Use it, not 3 bools.
+ * files.c (_cpp_find_file): Use _cpp_find_file_kind enum, not
+ bools.
+ (cpp_make_system_header): Break overly long line.
+ (_cpp_stack_include, _cpp_fake_include)
+ (_cpp_do_file_change, _cpp_compare_file_date, _cpp_has_header): Adjust.
+ * init.c (cpp_read_main): Adjust _cpp_find_file call.
+
2020-05-18 Nathan Sidwell <nathan@acm.org>
* include/cpplib.h (cpp_get_otions, cpp_get_callbacks)
diff --git a/libcpp/files.c b/libcpp/files.c
index f25b58dc394..85c79a1ef93 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -496,21 +496,16 @@ _cpp_find_failed (_cpp_file *file)
had previously been closed. To open it again pass the return value
to open_file().
- If IMPLICIT_PREINCLUDE then it is OK for the file to be missing.
- If present, it is OK for a precompiled header to be included after
- it.
+ If KIND is _cpp_FFK_PRE_INCLUDE then it is OK for the file to be
+ missing. If present, it is OK for a precompiled header to be
+ included after it.
Use LOC as the location for any errors. */
_cpp_file *
_cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir,
- int angle_brackets,
- bool fake, bool implicit_preinclude, bool has_include,
- location_t loc)
+ int angle_brackets, _cpp_find_file_kind kind, location_t loc)
{
- struct cpp_file_hash_entry *entry;
- void **hash_slot;
- _cpp_file *file;
bool invalid_pch = false;
bool saw_bracket_include = false;
bool saw_quote_include = false;
@@ -520,22 +515,22 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir,
if (start_dir == NULL)
cpp_error_at (pfile, CPP_DL_ICE, loc, "NULL directory in find_file");
- hash_slot
+ void **hash_slot
= htab_find_slot_with_hash (pfile->file_hash, fname,
htab_hash_string (fname), INSERT);
/* First check the cache before we resort to memory allocation. */
- entry = search_cache ((struct cpp_file_hash_entry *) *hash_slot, start_dir);
+ cpp_file_hash_entry *entry
+ = search_cache ((struct cpp_file_hash_entry *) *hash_slot, start_dir);
if (entry)
return entry->u.file;
- file = make_cpp_file (pfile, start_dir, fname);
+ _cpp_file *file = make_cpp_file (pfile, start_dir, fname);
file->implicit_preinclude
- = (implicit_preinclude
- || (pfile->buffer
- && pfile->buffer->file->implicit_preinclude));
+ = (kind == _cpp_FFK_PRE_INCLUDE
+ || (pfile->buffer && pfile->buffer->file->implicit_preinclude));
- if (!fake)
+ if (kind != _cpp_FFK_FAKE)
/* Try each path in the include chain. */
for (;;)
{
@@ -580,7 +575,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir,
"use -Winvalid-pch for more information");
}
- if (implicit_preinclude)
+ if (kind == _cpp_FFK_PRE_INCLUDE)
{
free ((char *) file->name);
free (file);
@@ -593,7 +588,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir,
return NULL;
}
- if (!has_include)
+ if (kind != _cpp_FFK_HAS_INCLUDE)
open_file_failed (pfile, file, angle_brackets, loc);
break;
}
@@ -1049,7 +1044,8 @@ _cpp_stack_include (cpp_reader *pfile, const char *fname, int angle_brackets,
return false;
_cpp_file *file = _cpp_find_file (pfile, fname, dir, angle_brackets,
- false, type == IT_DEFAULT, false, loc);
+ type == IT_DEFAULT ? _cpp_FFK_PRE_INCLUDE
+ : _cpp_FFK_NORMAL, loc);
if (type == IT_DEFAULT && file == NULL)
return false;
@@ -1342,8 +1338,7 @@ cpp_clear_file_cache (cpp_reader *pfile)
void
_cpp_fake_include (cpp_reader *pfile, const char *fname)
{
- _cpp_find_file (pfile, fname, pfile->buffer->file->dir,
- 0, true, false, false, 0);
+ _cpp_find_file (pfile, fname, pfile->buffer->file->dir, 0, _cpp_FFK_FAKE, 0);
}
/* Not everyone who wants to set system-header-ness on a buffer can
@@ -1360,7 +1355,8 @@ cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc)
flags = 1 + (externc != 0);
pfile->buffer->sysp = flags;
_cpp_do_file_change (pfile, LC_RENAME, ORDINARY_MAP_FILE_NAME (map),
- SOURCE_LINE (map, pfile->line_table->highest_line), flags);
+ SOURCE_LINE (map, pfile->line_table->highest_line),
+ flags);
}
/* Allow the client to change the current file. Used by the front end
@@ -1461,8 +1457,7 @@ _cpp_compare_file_date (cpp_reader *pfile, const char *fname,
if (!dir)
return -1;
- file = _cpp_find_file (pfile, fname, dir, angle_brackets,
- false, false, false, 0);
+ file = _cpp_find_file (pfile, fname, dir, angle_brackets, _cpp_FFK_NORMAL, 0);
if (file->err_no)
return -1;
@@ -2006,10 +2001,7 @@ _cpp_has_header (cpp_reader *pfile, const char *fname, int angle_brackets,
{
cpp_dir *start_dir = search_path_head (pfile, fname, angle_brackets, type);
_cpp_file *file = _cpp_find_file (pfile, fname, start_dir, angle_brackets,
- /*fake=*/false,
- /*implicit_preinclude=*/false,
- /*has_include=*/true,
- 0);
+ _cpp_FFK_HAS_INCLUDE, 0);
return file->err_no != ENOENT;
}
diff --git a/libcpp/init.c b/libcpp/init.c
index 1f8996af47f..63124c8161e 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -662,8 +662,6 @@ cpp_post_options (cpp_reader *pfile)
const char *
cpp_read_main_file (cpp_reader *pfile, const char *fname)
{
- const location_t loc = 0;
-
if (CPP_OPTION (pfile, deps.style) != DEPS_NONE)
{
if (!pfile->deps)
@@ -675,8 +673,7 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname)
pfile->main_file
= _cpp_find_file (pfile, fname, &pfile->no_search_path, /*angle=*/0,
- /*fake=*/false, /*preinclude=*/false, /*hasinclude=*/false,
- loc);
+ _cpp_FFK_NORMAL, 0);
if (_cpp_find_failed (pfile->main_file))
return NULL;
diff --git a/libcpp/internal.h b/libcpp/internal.h
index 765ff9d8206..049ee175317 100644
--- a/libcpp/internal.h
+++ b/libcpp/internal.h
@@ -677,10 +677,10 @@ extern void _cpp_init_hashtable (cpp_reader *, cpp_hash_table *);
extern void _cpp_destroy_hashtable (cpp_reader *);
/* In files.c */
-typedef struct _cpp_file _cpp_file;
+enum _cpp_find_file_kind
+ { _cpp_FFK_NORMAL, _cpp_FFK_FAKE, _cpp_FFK_PRE_INCLUDE, _cpp_FFK_HAS_INCLUDE };
extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *,
- int angle, bool fake, bool preinclude,
- bool has_include, location_t);
+ int angle, _cpp_find_file_kind, location_t);
extern bool _cpp_find_failed (_cpp_file *);
extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
extern void _cpp_fake_include (cpp_reader *, const char *);