Index: cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h =================================================================== --- cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h +++ cfe/trunk/include/clang/Frontend/PrecompiledPreamble.h @@ -255,11 +255,9 @@ /// NOTE: To allow more flexibility a custom ASTConsumer could probably be /// used instead, but having only this method allows a simpler API. virtual void HandleTopLevelDecl(DeclGroupRef DG); - /// Called for each macro defined in the Preamble. - /// NOTE: To allow more flexibility a custom PPCallbacks could probably be - /// used instead, but having only this method allows a simpler API. - virtual void HandleMacroDefined(const Token &MacroNameTok, - const MacroDirective *MD); + /// Creates wrapper class for PPCallbacks so we can also process information + /// about includes that are inside of a preamble + virtual std::unique_ptr createPPCallbacks(); }; enum class BuildPreambleError { Index: cfe/trunk/lib/Frontend/ASTUnit.cpp =================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp +++ cfe/trunk/lib/Frontend/ASTUnit.cpp @@ -970,9 +970,8 @@ } } - void HandleMacroDefined(const Token &MacroNameTok, - const MacroDirective *MD) override { - AddDefinedMacroToHash(MacroNameTok, Hash); + std::unique_ptr createPPCallbacks() override { + return llvm::make_unique(Hash); } private: Index: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp =================================================================== --- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp +++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp @@ -115,19 +115,6 @@ llvm::sys::fs::remove(File); } -class PreambleMacroCallbacks : public PPCallbacks { -public: - PreambleMacroCallbacks(PreambleCallbacks &Callbacks) : Callbacks(Callbacks) {} - - void MacroDefined(const Token &MacroNameTok, - const MacroDirective *MD) override { - Callbacks.HandleMacroDefined(MacroNameTok, MD); - } - -private: - PreambleCallbacks &Callbacks; -}; - class PrecompilePreambleAction : public ASTFrontendAction { public: PrecompilePreambleAction(std::string *InMemStorage, @@ -213,8 +200,6 @@ if (!CI.getFrontendOpts().RelocatablePCH) Sysroot.clear(); - CI.getPreprocessor().addPPCallbacks( - llvm::make_unique(Callbacks)); return llvm::make_unique( *this, CI.getPreprocessor(), Sysroot, std::move(OS)); } @@ -351,6 +336,11 @@ if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0])) return BuildPreambleError::BeginSourceFileFailed; + std::unique_ptr DelegatedPPCallbacks = + Callbacks.createPPCallbacks(); + if (DelegatedPPCallbacks) + Clang->getPreprocessor().addPPCallbacks(std::move(DelegatedPPCallbacks)); + Act->Execute(); // Run the callbacks. @@ -707,8 +697,9 @@ void PreambleCallbacks::AfterExecute(CompilerInstance &CI) {} void PreambleCallbacks::AfterPCHEmitted(ASTWriter &Writer) {} 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());