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.
This commit is contained in:
parent
b204d7722d
commit
9844497a93
4 changed files with 70 additions and 4 deletions
|
@ -308,6 +308,15 @@ enum cpp_normalize_level {
|
|||
normalized_none
|
||||
};
|
||||
|
||||
enum cpp_main_search
|
||||
{
|
||||
CMS_none, /* A regular source file. */
|
||||
CMS_header, /* Is a directly-specified header file (eg PCH or
|
||||
header-unit). */
|
||||
CMS_user, /* Search the user INCLUDE path. */
|
||||
CMS_system, /* Search the system INCLUDE path. */
|
||||
};
|
||||
|
||||
/* This structure is nested inside struct cpp_reader, and
|
||||
carries all the options visible to the command line. */
|
||||
struct cpp_options
|
||||
|
@ -566,6 +575,8 @@ struct cpp_options
|
|||
|
||||
/* The maximum depth of the nested #include. */
|
||||
unsigned int max_include_depth;
|
||||
|
||||
cpp_main_search main_search : 8;
|
||||
};
|
||||
|
||||
/* Diagnostic levels. To get a diagnostic without associating a
|
||||
|
@ -997,6 +1008,10 @@ extern const char *cpp_find_header_unit (cpp_reader *, const char *file,
|
|||
too. If there was an error opening the file, it returns NULL. */
|
||||
extern const char *cpp_read_main_file (cpp_reader *, const char *,
|
||||
bool injecting = false);
|
||||
extern location_t cpp_main_loc (const cpp_reader *);
|
||||
|
||||
/* Adjust for the main file to be an include. */
|
||||
extern void cpp_retrofit_as_include (cpp_reader *);
|
||||
|
||||
/* Set up built-ins with special behavior. Use cpp_init_builtins()
|
||||
instead unless your know what you are doing. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue