Skip to content

Commit 0403d3f

Browse files
committed
Remove the getPPCallbacks interface from DependencyCollector.
1 parent 6161886 commit 0403d3f

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

clang/include/clang/Frontend/Utils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class DiagnosticsEngine;
4040
class ExternalSemaSource;
4141
class FrontendOptions;
4242
class PCHContainerReader;
43-
class PPCallbacks;
4443
class Preprocessor;
4544
class PreprocessorOptions;
4645
class PreprocessorOutputOptions;
@@ -88,9 +87,6 @@ class DependencyCollector {
8887
bool IsSystem, bool IsModuleFile,
8988
bool IsMissing);
9089

91-
/// @return the PPCallback this collector added to the Preprocessor.
92-
virtual PPCallbacks *getPPCallbacks() { return nullptr; };
93-
9490
protected:
9591
/// Return true if the filename was added to the list of dependencies, false
9692
/// otherwise.

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class ModuleDepCollector final : public DependencyCollector {
288288
void attachToPreprocessor(Preprocessor &PP) override;
289289
void attachToASTReader(ASTReader &R) override;
290290

291-
PPCallbacks *getPPCallbacks() override { return CollectorPPPtr; }
291+
PPCallbacks *getPPCallbacks() { return CollectorPPPtr; }
292292

293293
/// Apply any changes implied by the discovered dependencies to the given
294294
/// invocation, (e.g. disable implicit modules, add explicit module paths).

clang/lib/Tooling/DependencyScanning/DependencyScannerImpl.cpp

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -814,26 +814,24 @@ llvm::Error CompilerInstanceWithContext::computeDependencies(
814814
FileID MainFileID = SM.getMainFileID();
815815
SourceLocation FileStart = SM.getLocForStartOfFile(MainFileID);
816816
SourceLocation IDLocation = FileStart.getLocWithOffset(SrcLocOffset);
817+
PPCallbacks *CB = nullptr;
817818
if (!SrcLocOffset) {
818819
// We need to call EnterSourceFile when SrcLocOffset is zero to initialize
819820
// the preprocessor.
820821
PP.EnterSourceFile(MainFileID, nullptr, SourceLocation());
822+
CB = MDC->getPPCallbacks();
821823
} else {
822824
// When SrcLocOffset is non-zero, the preprocessor has already been
823825
// initialized through a previous call of computeDependencies. We want to
824826
// preserve the PP's state, hence we do not call EnterSourceFile again.
825-
auto DCs = CI.getDependencyCollectors();
826-
for (auto &DC : DCs) {
827-
DC->attachToPreprocessor(PP);
828-
auto *CB = DC->getPPCallbacks();
829-
830-
FileID PrevFID;
831-
SrcMgr::CharacteristicKind FileType =
832-
SM.getFileCharacteristic(IDLocation);
833-
CB->LexedFileChanged(MainFileID,
834-
PPChainedCallbacks::LexedFileChangeReason::EnterFile,
835-
FileType, PrevFID, IDLocation);
836-
}
827+
MDC->attachToPreprocessor(PP);
828+
CB = MDC->getPPCallbacks();
829+
830+
FileID PrevFID;
831+
SrcMgr::CharacteristicKind FileType = SM.getFileCharacteristic(IDLocation);
832+
CB->LexedFileChanged(MainFileID,
833+
PPChainedCallbacks::LexedFileChangeReason::EnterFile,
834+
FileType, PrevFID, IDLocation);
837835
}
838836

839837
SrcLocOffset++;
@@ -842,18 +840,12 @@ llvm::Error CompilerInstanceWithContext::computeDependencies(
842840
Path.emplace_back(IDLocation, ModuleID);
843841
auto ModResult = CI.loadModule(IDLocation, Path, Module::Hidden, false);
844842

845-
auto DCs = CI.getDependencyCollectors();
846-
for (auto &DC : DCs) {
847-
auto *CB = DC->getPPCallbacks();
848-
if (CB) {
849-
CB->moduleImport(SourceLocation(), Path, ModResult);
850-
851-
// Note that we are calling the CB's EndOfMainFile function, which
852-
// forwards the results to the dependency consumer.
853-
// It does not indicate the end of processing the fake file.
854-
CB->EndOfMainFile();
855-
}
856-
}
843+
assert(CB && "Must have PPCallbacks after module loading");
844+
CB->moduleImport(SourceLocation(), Path, ModResult);
845+
// Note that we are calling the CB's EndOfMainFile function, which
846+
// forwards the results to the dependency consumer.
847+
// It does not indicate the end of processing the fake file.
848+
CB->EndOfMainFile();
857849

858850
CompilerInvocation ModuleInvocation(*OriginalInvocation);
859851
MDC->applyDiscoveredDependencies(ModuleInvocation);

0 commit comments

Comments
 (0)