From 8a97aed0d290bc12b91091703444546d9b3edba7 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Tue, 17 Nov 2020 06:07:30 -0800 Subject: 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. --- gcc/langhooks.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'gcc/langhooks.h') diff --git a/gcc/langhooks.h b/gcc/langhooks.h index a35cf21..f12589e 100644 --- a/gcc/langhooks.h +++ b/gcc/langhooks.h @@ -356,6 +356,24 @@ struct lang_hooks global diagnostic context structure. */ void (*initialize_diagnostics) (diagnostic_context *); + /* Beginning the main source file. */ + void (*preprocess_main_file) (cpp_reader *, line_maps *, + const line_map_ordinary *); + + /* Adjust libcpp options and callbacks. */ + void (*preprocess_options) (cpp_reader *); + + /* Undefining a macro. */ + void (*preprocess_undef) (cpp_reader *, location_t, cpp_hashnode *); + + /* Observer for preprocessing stream. */ + uintptr_t (*preprocess_token) (cpp_reader *, const cpp_token *, uintptr_t); + /* Various flags it can return about the token. */ + enum PT_flags + { + PT_begin_pragma = 1 << 0 + }; + /* Register language-specific dumps. */ void (*register_dumps) (gcc::dump_manager *); -- cgit v1.1