Index: include/clang/Frontend/PrecompiledPreamble.h =================================================================== --- include/clang/Frontend/PrecompiledPreamble.h +++ include/clang/Frontend/PrecompiledPreamble.h @@ -260,6 +260,9 @@ /// used instead, but having only this method allows a simpler API. virtual void HandleMacroDefined(const Token &MacroNameTok, const MacroDirective *MD); + /// Adds list of Preprocessor callbacks so we can also process information + /// about includes that are outside of a preamble i.e in the middle of a file + virtual std::unique_ptr createPPCallbacks(); }; enum class BuildPreambleError { Index: lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- lib/Frontend/PrecompiledPreamble.cpp +++ lib/Frontend/PrecompiledPreamble.cpp @@ -351,6 +351,8 @@ if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) return BuildPreambleError::BeginSourceFileFailed; + if (Callbacks.createPPCallbacks()) + Clang->getPreprocessor().addPPCallbacks(std::move(Callbacks.createPPCallbacks())); Act->Execute(); // Run the callbacks. @@ -709,6 +711,7 @@ void PreambleCallbacks::HandleTopLevelDecl(DeclGroupRef DG) {} void PreambleCallbacks::HandleMacroDefined(const Token &MacroNameTok, const MacroDirective *MD) {} +std::unique_ptr PreambleCallbacks::createPPCallbacks() {return nullptr;} std::error_code clang::make_error_code(BuildPreambleError Error) { return std::error_code(static_cast(Error), BuildPreambleErrorCategory());