jansvoboda11 created this revision. jansvoboda11 added reviewers: Bigcheese, dexonsmith, arphaman. jansvoboda11 requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D104104 Files: 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 Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -173,11 +173,13 @@ 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}); Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -32,11 +32,12 @@ : 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); } } Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp +++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp @@ -54,10 +54,12 @@ /// 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 @@ 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 @@ 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)); } Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h =================================================================== --- clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h +++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h @@ -34,8 +34,10 @@ 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;
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -173,11 +173,13 @@ 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}); Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -32,11 +32,12 @@ : 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); } } Index: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp +++ clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp @@ -54,10 +54,12 @@ /// 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 @@ 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 @@ 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)); } Index: clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h =================================================================== --- clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h +++ clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h @@ -34,8 +34,10 @@ 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits