forked from OSchip/llvm-project
[clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble.
Summary: Revision D38639 needs this commit in order to properly make open definition calls on include statements work. Patch by William Enright. Reviewers: malaperle, krasimir, bkramer, ilya-biryukov Reviewed By: malaperle, ilya-biryukov Subscribers: cfe-commits, arphaman, ilya-biryukov Differential Revision: https://reviews.llvm.org/D39375 llvm-svn: 320804
This commit is contained in:
parent
96ca4f5e91
commit
41e90bcb77
|
@ -255,11 +255,9 @@ public:
|
|||
/// 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<PPCallbacks> createPPCallbacks();
|
||||
};
|
||||
|
||||
enum class BuildPreambleError {
|
||||
|
|
|
@ -970,9 +970,8 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void HandleMacroDefined(const Token &MacroNameTok,
|
||||
const MacroDirective *MD) override {
|
||||
AddDefinedMacroToHash(MacroNameTok, Hash);
|
||||
std::unique_ptr<PPCallbacks> createPPCallbacks() override {
|
||||
return llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(Hash);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -115,19 +115,6 @@ void TemporaryFiles::removeFile(StringRef File) {
|
|||
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 @@ PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI,
|
|||
if (!CI.getFrontendOpts().RelocatablePCH)
|
||||
Sysroot.clear();
|
||||
|
||||
CI.getPreprocessor().addPPCallbacks(
|
||||
llvm::make_unique<PreambleMacroCallbacks>(Callbacks));
|
||||
return llvm::make_unique<PrecompilePreambleConsumer>(
|
||||
*this, CI.getPreprocessor(), Sysroot, std::move(OS));
|
||||
}
|
||||
|
@ -351,6 +336,11 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
|
|||
if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
|
||||
return BuildPreambleError::BeginSourceFileFailed;
|
||||
|
||||
std::unique_ptr<PPCallbacks> DelegatedPPCallbacks =
|
||||
Callbacks.createPPCallbacks();
|
||||
if (DelegatedPPCallbacks)
|
||||
Clang->getPreprocessor().addPPCallbacks(std::move(DelegatedPPCallbacks));
|
||||
|
||||
Act->Execute();
|
||||
|
||||
// Run the callbacks.
|
||||
|
@ -707,8 +697,9 @@ void PrecompiledPreamble::setupPreambleStorage(
|
|||
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<PPCallbacks> PreambleCallbacks::createPPCallbacks() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::error_code clang::make_error_code(BuildPreambleError Error) {
|
||||
return std::error_code(static_cast<int>(Error), BuildPreambleErrorCategory());
|
||||
|
|
Loading…
Reference in New Issue