Author: Jan Svoboda Date: 2021-06-14T15:16:08+02:00 New Revision: f95ff81627212a8db9f942aafa91392096538847
URL: https://github.com/llvm/llvm-project/commit/f95ff81627212a8db9f942aafa91392096538847 DIFF: https://github.com/llvm/llvm-project/commit/f95ff81627212a8db9f942aafa91392096538847.diff LOG: [clang][deps] NFC: Handle `DependencyOutputOptions` only once There's no need to pass `DependencyOutputOptions` to each call of `handleFileDependency`, since the options don't ever change. This patch adds new `handleDependencyOutputOpts` method to the `DependencyConsumer` interface and the dependency scanner uses it to report the options only once. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D104104 Added: Modified: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h index e51040d2c0f5..5903ad13c1d8 100644 --- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h +++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h @@ -34,8 +34,10 @@ class DependencyConsumer { public: virtual ~DependencyConsumer() {} - virtual void handleFileDependency(const DependencyOutputOptions &Opts, - StringRef Filename) = 0; + virtual void + handleDependencyOutputOpts(const DependencyOutputOptions &Opts) = 0; + + virtual void handleFileDependency(StringRef Filename) = 0; virtual void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) = 0; diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp index 409ccd393e78..2fd12f7e12b1 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp @@ -54,10 +54,12 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile( /// Prints out all of the gathered dependencies into a string. class MakeDependencyPrinterConsumer : public DependencyConsumer { public: - void handleFileDependency(const DependencyOutputOptions &Opts, - StringRef File) override { - if (!this->Opts) - this->Opts = std::make_unique<DependencyOutputOptions>(Opts); + void + handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override { + this->Opts = std::make_unique<DependencyOutputOptions>(Opts); + } + + void handleFileDependency(StringRef File) override { Dependencies.push_back(std::string(File)); } @@ -74,8 +76,7 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile( void handleContextHash(std::string Hash) override {} void printDependencies(std::string &S) { - if (!Opts) - return; + assert(Opts && "Handled dependency output options."); class DependencyPrinter : public DependencyFileGenerator { public: @@ -128,8 +129,10 @@ DependencyScanningTool::getFullDependencies( FullDependencyPrinterConsumer(const llvm::StringSet<> &AlreadySeen) : AlreadySeen(AlreadySeen) {} - void handleFileDependency(const DependencyOutputOptions &Opts, - StringRef File) override { + void + handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {} + + void handleFileDependency(StringRef File) override { Dependencies.push_back(std::string(File)); } diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp index bbe498d12f15..48abc095231f 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -32,11 +32,12 @@ class DependencyConsumerForwarder : public DependencyFileGenerator { : DependencyFileGenerator(*Opts), Opts(std::move(Opts)), C(C) {} void finishedMainFile(DiagnosticsEngine &Diags) override { + C.handleDependencyOutputOpts(*Opts); llvm::SmallString<256> CanonPath; for (const auto &File : getDependencies()) { CanonPath = File; llvm::sys::path::remove_dots(CanonPath, /*remove_dot_dot=*/true); - C.handleFileDependency(*Opts, CanonPath); + C.handleFileDependency(CanonPath); } } diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 21770540c100..690bd6d476e5 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -173,11 +173,13 @@ void ModuleDepCollectorPP::EndOfMainFile() { for (const Module *M : DirectModularDeps) handleTopLevelModule(M); + MDC.Consumer.handleDependencyOutputOpts(*MDC.Opts); + for (auto &&I : MDC.ModularDeps) MDC.Consumer.handleModuleDependency(I.second); for (auto &&I : MDC.FileDeps) - MDC.Consumer.handleFileDependency(*MDC.Opts, I); + MDC.Consumer.handleFileDependency(I); for (auto &&I : DirectPrebuiltModularDeps) MDC.Consumer.handlePrebuiltModuleDependency(PrebuiltModuleDep{I}); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits