aboutsummaryrefslogtreecommitdiff
path: root/libcpp/init.c
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-11-19 07:00:51 -0800
committerNathan Sidwell <nathan@acm.org>2020-11-19 07:05:08 -0800
commit9844497a935d5e89dc92539128edccb6bb408bb1 (patch)
tree8556fefb85e32778246020206586c70ff3ffc56c /libcpp/init.c
parentb204d7722d30f44281dea3341070223475f1cff9 (diff)
downloadgcc-9844497a935d5e89dc92539128edccb6bb408bb1.zip
gcc-9844497a935d5e89dc92539128edccb6bb408bb1.tar.gz
gcc-9844497a935d5e89dc92539128edccb6bb408bb1.tar.bz2
preprocessor: main file searching
This adds the capability to locate the main file on the user or system include paths. That's extremely useful to users building header units. Searching has to be requiested (plain header-unit compilation will not search). Also, to make include_next work as expected when building a header unit, we add a mechanism to retrofit a non-searched source file as one on the include path. libcpp/ * include/cpplib.h (enum cpp_main_search): New. (struct cpp_options): Add main_search field. (cpp_main_loc): Declare. (cpp_retrofit_as_include): Declare. * internal.h (struct cpp_reader): Add main_loc field. (_cpp_in_main_source_file): Not main if main is a header. * init.c (cpp_read_main_file): Use main_search option to locate main file. Set main_loc * files.c (cpp_retrofit_as_include): New.
Diffstat (limited to 'libcpp/init.c')
-rw-r--r--libcpp/init.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/libcpp/init.c b/libcpp/init.c
index fc82658..f77dc26 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -675,8 +675,14 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname, bool injecting)
deps_add_default_target (deps, fname);
pfile->main_file
- = _cpp_find_file (pfile, fname, &pfile->no_search_path, /*angle=*/0,
- _cpp_FFK_NORMAL, 0);
+ = _cpp_find_file (pfile, fname,
+ CPP_OPTION (pfile, preprocessed) ? &pfile->no_search_path
+ : CPP_OPTION (pfile, main_search) == CMS_user
+ ? pfile->quote_include
+ : CPP_OPTION (pfile, main_search) == CMS_system
+ ? pfile->bracket_include : &pfile->no_search_path,
+ /*angle=*/0, _cpp_FFK_NORMAL, 0);
+
if (_cpp_find_failed (pfile->main_file))
return NULL;
@@ -698,7 +704,16 @@ cpp_read_main_file (cpp_reader *pfile, const char *fname, bool injecting)
LINEMAP_LINE (last), LINEMAP_SYSP (last));
}
- return ORDINARY_MAP_FILE_NAME (LINEMAPS_LAST_ORDINARY_MAP (pfile->line_table));
+ auto *map = LINEMAPS_LAST_ORDINARY_MAP (pfile->line_table);
+ pfile->main_loc = MAP_START_LOCATION (map);
+
+ return ORDINARY_MAP_FILE_NAME (map);
+}
+
+location_t
+cpp_main_loc (const cpp_reader *pfile)
+{
+ return pfile->main_loc;
}
/* For preprocessed files, if the very first characters are