diff options
author | Nathan Sidwell <nathan@acm.org> | 2020-11-17 06:07:30 -0800 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2020-11-17 06:12:01 -0800 |
commit | 8a97aed0d290bc12b91091703444546d9b3edba7 (patch) | |
tree | eaa8646dd871f738feb30a5df76996329da161a6 /gcc/c-family/c-opts.c | |
parent | e3b55ce50ec294f30106947bd819f12a98069c57 (diff) | |
download | gcc-8a97aed0d290bc12b91091703444546d9b3edba7.tar.gz |
langhooks: preprocessor hooks for c++ modules
This is a slightly modified version of 01-langhooks.def. I realized I
didn't need the deferred macro langhook -- that can be directly
installed into the preprocessor callbacks via preprocess_options lang
hook.
gcc/
* langhooks-def.h (LANG_HOOKS_PREPROCESS_MAIN_FILE)
(LANG_HOOKS_PREPROCESS_OPTIONS, LANG_HOOKS_PREPROCESS_UNDEF)
(LANG_HOOKS_PREPROCESS_TOKEN): New.
(LANG_HOOKS_INITIALIZER): Add them.
* langhooks.h (struct lang_hooks): Add preprocess_main_file,
preprocess_options, preprocess_undef, preprocess_token hooks. Add
enum PT_flags.
gcc/c-family/
* c-lex.c: #include "langhooks.h".
(cb_undef): Maybe call preprocess_undef lang hook.
* c-opts.c (c_common_post_options): Maybe call preprocess_options
lang hook.
(push_command_line_include): Maybe call preprocess_main_file lang
hook.
(cb_file_change): Likewise.
* c-ppoutput.c: #include "langhooks.h.
(scan_translation_unit): Maybe call preprocess_token lang hook.
(class do_streamer): New, derive from token_streamer.
(directives_only_cb): Data pointer is do_streamer, call
preprocess_token lang hook.
(scan_translation_unit_directives_only): Use do_streamer.
(print_line_1): Move src_line recording to after string output.
(cb_undef): Maybe call preprocess_undef lang hook.
Diffstat (limited to 'gcc/c-family/c-opts.c')
-rw-r--r-- | gcc/c-family/c-opts.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 40e92229d8a..77844d7daf1 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -1106,6 +1106,8 @@ c_common_post_options (const char **pfilename) struct cpp_callbacks *cb = cpp_get_callbacks (parse_in); cb->file_change = cb_file_change; cb->dir_change = cb_dir_change; + if (lang_hooks.preprocess_options) + lang_hooks.preprocess_options (parse_in); cpp_post_options (parse_in); init_global_opts_from_cpp (&global_options, cpp_get_options (parse_in)); @@ -1548,7 +1550,13 @@ push_command_line_include (void) cpp_opts->warn_unused_macros = cpp_warn_unused_macros; /* Restore the line map back to the main file. */ if (!cpp_opts->preprocessed) - cpp_change_file (parse_in, LC_RENAME, this_input_filename); + { + cpp_change_file (parse_in, LC_RENAME, this_input_filename); + if (lang_hooks.preprocess_main_file) + /* We're starting the main file. Inform the FE of that. */ + lang_hooks.preprocess_main_file + (parse_in, line_table, LINEMAPS_LAST_ORDINARY_MAP (line_table)); + } /* Set this here so the client can change the option if it wishes, and after stacking the main file so we don't trace the main file. */ @@ -1558,14 +1566,19 @@ push_command_line_include (void) /* File change callback. Has to handle -include files. */ static void -cb_file_change (cpp_reader * ARG_UNUSED (pfile), - const line_map_ordinary *new_map) +cb_file_change (cpp_reader *reader, const line_map_ordinary *new_map) { if (flag_preprocess_only) pp_file_change (new_map); else fe_file_change (new_map); + if (new_map && cpp_opts->preprocessed + && lang_hooks.preprocess_main_file && MAIN_FILE_P (new_map) + && ORDINARY_MAP_STARTING_LINE_NUMBER (new_map)) + /* We're starting the main file. Inform the FE of that. */ + lang_hooks.preprocess_main_file (reader, line_table, new_map); + if (new_map && (new_map->reason == LC_ENTER || new_map->reason == LC_RENAME)) { |