Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 0546169

Browse files
committedDec 15, 2017
[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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320804 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 61ab19d commit 0546169

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed
 

‎include/clang/Frontend/PrecompiledPreamble.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,9 @@ class PreambleCallbacks {
255255
/// NOTE: To allow more flexibility a custom ASTConsumer could probably be
256256
/// used instead, but having only this method allows a simpler API.
257257
virtual void HandleTopLevelDecl(DeclGroupRef DG);
258-
/// Called for each macro defined in the Preamble.
259-
/// NOTE: To allow more flexibility a custom PPCallbacks could probably be
260-
/// used instead, but having only this method allows a simpler API.
261-
virtual void HandleMacroDefined(const Token &MacroNameTok,
262-
const MacroDirective *MD);
258+
/// Creates wrapper class for PPCallbacks so we can also process information
259+
/// about includes that are inside of a preamble
260+
virtual std::unique_ptr<PPCallbacks> createPPCallbacks();
263261
};
264262

265263
enum class BuildPreambleError {

‎lib/Frontend/ASTUnit.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -970,9 +970,8 @@ class ASTUnitPreambleCallbacks : public PreambleCallbacks {
970970
}
971971
}
972972

973-
void HandleMacroDefined(const Token &MacroNameTok,
974-
const MacroDirective *MD) override {
975-
AddDefinedMacroToHash(MacroNameTok, Hash);
973+
std::unique_ptr<PPCallbacks> createPPCallbacks() override {
974+
return llvm::make_unique<MacroDefinitionTrackerPPCallbacks>(Hash);
976975
}
977976

978977
private:

‎lib/Frontend/PrecompiledPreamble.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,6 @@ void TemporaryFiles::removeFile(StringRef File) {
115115
llvm::sys::fs::remove(File);
116116
}
117117

118-
class PreambleMacroCallbacks : public PPCallbacks {
119-
public:
120-
PreambleMacroCallbacks(PreambleCallbacks &Callbacks) : Callbacks(Callbacks) {}
121-
122-
void MacroDefined(const Token &MacroNameTok,
123-
const MacroDirective *MD) override {
124-
Callbacks.HandleMacroDefined(MacroNameTok, MD);
125-
}
126-
127-
private:
128-
PreambleCallbacks &Callbacks;
129-
};
130-
131118
class PrecompilePreambleAction : public ASTFrontendAction {
132119
public:
133120
PrecompilePreambleAction(std::string *InMemStorage,
@@ -213,8 +200,6 @@ PrecompilePreambleAction::CreateASTConsumer(CompilerInstance &CI,
213200
if (!CI.getFrontendOpts().RelocatablePCH)
214201
Sysroot.clear();
215202

216-
CI.getPreprocessor().addPPCallbacks(
217-
llvm::make_unique<PreambleMacroCallbacks>(Callbacks));
218203
return llvm::make_unique<PrecompilePreambleConsumer>(
219204
*this, CI.getPreprocessor(), Sysroot, std::move(OS));
220205
}
@@ -351,6 +336,11 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build(
351336
if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
352337
return BuildPreambleError::BeginSourceFileFailed;
353338

339+
std::unique_ptr<PPCallbacks> DelegatedPPCallbacks =
340+
Callbacks.createPPCallbacks();
341+
if (DelegatedPPCallbacks)
342+
Clang->getPreprocessor().addPPCallbacks(std::move(DelegatedPPCallbacks));
343+
354344
Act->Execute();
355345

356346
// Run the callbacks.
@@ -707,8 +697,9 @@ void PrecompiledPreamble::setupPreambleStorage(
707697
void PreambleCallbacks::AfterExecute(CompilerInstance &CI) {}
708698
void PreambleCallbacks::AfterPCHEmitted(ASTWriter &Writer) {}
709699
void PreambleCallbacks::HandleTopLevelDecl(DeclGroupRef DG) {}
710-
void PreambleCallbacks::HandleMacroDefined(const Token &MacroNameTok,
711-
const MacroDirective *MD) {}
700+
std::unique_ptr<PPCallbacks> PreambleCallbacks::createPPCallbacks() {
701+
return nullptr;
702+
}
712703

713704
std::error_code clang::make_error_code(BuildPreambleError Error) {
714705
return std::error_code(static_cast<int>(Error), BuildPreambleErrorCategory());

0 commit comments

Comments
 (0)
This repository has been archived.