Skip to content

Commit 3ba28c0

Browse files
committed
[clang][deps] NFC: Remove redundant CompilerInstance reference
The `ModuleDepCollectorPP` class holds a reference to `ModuleDepCollector` as well as `ModuleDepCollector`'s `CompilerInstance`. The fact that these refer to the same object is non-obvious. This patch removes the `CompilerInvocation` reference from `ModuleDepCollectorPP` and accesses it through `ModuleDepCollector` instead. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D111724
1 parent 601c9c5 commit 3ba28c0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ class ModuleDepCollector;
147147
/// \c DependencyConsumer of the parent \c ModuleDepCollector.
148148
class ModuleDepCollectorPP final : public PPCallbacks {
149149
public:
150-
ModuleDepCollectorPP(CompilerInstance &I, ModuleDepCollector &MDC)
151-
: Instance(I), MDC(MDC) {}
150+
ModuleDepCollectorPP(ModuleDepCollector &MDC) : MDC(MDC) {}
152151

153152
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
154153
SrcMgr::CharacteristicKind FileType,
@@ -165,8 +164,6 @@ class ModuleDepCollectorPP final : public PPCallbacks {
165164
void EndOfMainFile() override;
166165

167166
private:
168-
/// The compiler instance for the current translation unit.
169-
CompilerInstance &Instance;
170167
/// The parent dependency collector.
171168
ModuleDepCollector &MDC;
172169
/// Working set of direct modular dependencies.

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
155155
// This has to be delayed as the context hash can change at the start of
156156
// `CompilerInstance::ExecuteAction`.
157157
if (MDC.ContextHash.empty()) {
158-
MDC.ContextHash =
159-
Instance.getInvocation().getModuleHash(Instance.getDiagnostics());
158+
MDC.ContextHash = MDC.Instance.getInvocation().getModuleHash(
159+
MDC.Instance.getDiagnostics());
160160
MDC.Consumer.handleContextHash(MDC.ContextHash);
161161
}
162162

163-
SourceManager &SM = Instance.getSourceManager();
163+
SourceManager &SM = MDC.Instance.getSourceManager();
164164

165165
// Dependency generation really does want to go all the way to the
166166
// file entry for a source location to find out what is depended on.
@@ -203,12 +203,13 @@ void ModuleDepCollectorPP::handleImport(const Module *Imported) {
203203
}
204204

205205
void ModuleDepCollectorPP::EndOfMainFile() {
206-
FileID MainFileID = Instance.getSourceManager().getMainFileID();
206+
FileID MainFileID = MDC.Instance.getSourceManager().getMainFileID();
207207
MDC.MainFile = std::string(
208-
Instance.getSourceManager().getFileEntryForID(MainFileID)->getName());
208+
MDC.Instance.getSourceManager().getFileEntryForID(MainFileID)->getName());
209209

210-
if (!Instance.getPreprocessorOpts().ImplicitPCHInclude.empty())
211-
MDC.FileDeps.push_back(Instance.getPreprocessorOpts().ImplicitPCHInclude);
210+
if (!MDC.Instance.getPreprocessorOpts().ImplicitPCHInclude.empty())
211+
MDC.FileDeps.push_back(
212+
MDC.Instance.getPreprocessorOpts().ImplicitPCHInclude);
212213

213214
for (const Module *M : DirectModularDeps) {
214215
// A top-level module might not be actually imported as a module when
@@ -247,7 +248,7 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
247248
MD.ImplicitModulePCMPath = std::string(M->getASTFile()->getName());
248249
MD.IsSystem = M->IsSystem;
249250

250-
const FileEntry *ModuleMap = Instance.getPreprocessor()
251+
const FileEntry *ModuleMap = MDC.Instance.getPreprocessor()
251252
.getHeaderSearchInfo()
252253
.getModuleMap()
253254
.getModuleMapFileForUniquing(M);
@@ -337,7 +338,7 @@ ModuleDepCollector::ModuleDepCollector(
337338
OriginalInvocation(std::move(OriginalCI)), OptimizeArgs(OptimizeArgs) {}
338339

339340
void ModuleDepCollector::attachToPreprocessor(Preprocessor &PP) {
340-
PP.addPPCallbacks(std::make_unique<ModuleDepCollectorPP>(Instance, *this));
341+
PP.addPPCallbacks(std::make_unique<ModuleDepCollectorPP>(*this));
341342
}
342343

343344
void ModuleDepCollector::attachToASTReader(ASTReader &R) {}

0 commit comments

Comments
 (0)