/* If this is the primary source file, warn and use the normal
search logic. */
- if (cpp_in_primary_file (pfile))
+ if (_cpp_in_main_source_file (pfile))
{
cpp_error (pfile, CPP_DL_WARNING,
"#include_next in primary source file");
static void
do_pragma_once (cpp_reader *pfile)
{
- if (cpp_in_primary_file (pfile))
+ if (_cpp_in_main_source_file (pfile))
cpp_error (pfile, CPP_DL_WARNING, "#pragma once in main file");
check_eol (pfile, false);
static void
do_pragma_system_header (cpp_reader *pfile)
{
- if (cpp_in_primary_file (pfile))
+ if (_cpp_in_main_source_file (pfile))
cpp_error (pfile, CPP_DL_WARNING,
"#pragma system_header ignored outside include file");
else
/* 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;
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);
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;
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));
{
/* 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
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. */
/* 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);
struct report_missing_guard_data
{
+ cpp_reader *pfile;
const char **paths;
size_t count;
};
_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)
{
{
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);
#define UC (const uchar *) /* Intended use: UC"string" */
-/* Macros. */
+/* Accessors. */
-static inline int cpp_in_system_header (cpp_reader *);
-static inline int
-cpp_in_system_header (cpp_reader *pfile)
+inline int
+_cpp_in_system_header (cpp_reader *pfile)
{
return pfile->buffer ? pfile->buffer->sysp : 0;
}
#define CPP_PEDANTIC(PF) CPP_OPTION (PF, cpp_pedantic)
#define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, cpp_warn_traditional)
-static inline int cpp_in_primary_file (cpp_reader *);
-static inline int
-cpp_in_primary_file (cpp_reader *pfile)
+/* Return true if we're in the main file (unless it's considered to be
+ an include file in its own right. */
+inline int
+_cpp_in_main_source_file (cpp_reader *pfile)
{
- return pfile->line_table->depth == 1;
+ return pfile->buffer->file == pfile->main_file;
}
/* True if NODE is a macro for the purposes of ifdef, defined etc. */
{
/* __VA_OPT__ should not be accepted at all, but allow it in
system headers. */
- if (!cpp_in_system_header (pfile))
+ if (!_cpp_in_system_header (pfile))
cpp_error (pfile, CPP_DL_PEDWARN,
"__VA_OPT__ is not available until C++20");
}
else if (c == '/' && ! CPP_OPTION (pfile, traditional))
{
/* Don't warn for system headers. */
- if (cpp_in_system_header (pfile))
+ if (_cpp_in_system_header (pfile))
;
/* Warn about comments if pedantically GNUC89, and not
in system headers. */
(c) we are not in strictly conforming mode, then it has the
value 0. (b) and (c) are already checked in cpp_init_builtins. */
case BT_STDC:
- if (cpp_in_system_header (pfile))
+ if (_cpp_in_system_header (pfile))
number = 0;
else
number = 1;
= (const cpp_token **) tokens_buff_last_token_ptr (buff);
}
else if (CPP_PEDANTIC (pfile) && ! CPP_OPTION (pfile, c99)
- && ! macro->syshdr && ! cpp_in_system_header (pfile))
+ && ! macro->syshdr && ! _cpp_in_system_header (pfile))
{
if (CPP_OPTION (pfile, cplusplus))
cpp_pedwarning (pfile, CPP_W_PEDANTIC,
}
else if (CPP_OPTION (pfile, cpp_warn_c90_c99_compat) > 0
&& ! CPP_OPTION (pfile, cplusplus)
- && ! macro->syshdr && ! cpp_in_system_header (pfile))
+ && ! macro->syshdr && ! _cpp_in_system_header (pfile))
cpp_warning (pfile, CPP_W_C90_C99_COMPAT,
"invoking macro %s argument %d: "
"empty macro arguments are undefined"