[clang] d5fcf8a - [clang][deps] NFC: Move dependency consumer into header file
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 10 15:25:13 PDT 2022
Author: Jan Svoboda
Date: 2022-08-10T15:25:09-07:00
New Revision: d5fcf8a5e2e03c9c8e375876a2127d90db7efe13
URL: https://github.com/llvm/llvm-project/commit/d5fcf8a5e2e03c9c8e375876a2127d90db7efe13
DIFF: https://github.com/llvm/llvm-project/commit/d5fcf8a5e2e03c9c8e375876a2127d90db7efe13.diff
LOG: [clang][deps] NFC: Move dependency consumer into header file
Added:
Modified:
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index 77263cd6233b8..aabc1e6b16678 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -13,8 +13,11 @@
#include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h"
#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
#include "clang/Tooling/JSONCompilationDatabase.h"
+#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/StringMap.h"
#include <string>
+#include <vector>
namespace clang {
namespace tooling {
@@ -101,6 +104,42 @@ class DependencyScanningTool {
DependencyScanningWorker Worker;
};
+class FullDependencyConsumer : public DependencyConsumer {
+public:
+ FullDependencyConsumer(const llvm::StringSet<> &AlreadySeen)
+ : AlreadySeen(AlreadySeen) {}
+
+ void handleDependencyOutputOpts(const DependencyOutputOptions &) override {}
+
+ void handleFileDependency(StringRef File) override {
+ Dependencies.push_back(std::string(File));
+ }
+
+ void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {
+ PrebuiltModuleDeps.emplace_back(std::move(PMD));
+ }
+
+ void handleModuleDependency(ModuleDeps MD) override {
+ ClangModuleDeps[MD.ID.ContextHash + MD.ID.ModuleName] = std::move(MD);
+ }
+
+ void handleContextHash(std::string Hash) override {
+ ContextHash = std::move(Hash);
+ }
+
+ FullDependenciesResult getFullDependencies(
+ const std::vector<std::string> &OriginalCommandLine) const;
+
+private:
+ std::vector<std::string> Dependencies;
+ std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
+ llvm::MapVector<std::string, ModuleDeps, llvm::StringMap<unsigned>>
+ ClangModuleDeps;
+ std::string ContextHash;
+ std::vector<std::string> OutputPaths;
+ const llvm::StringSet<> &AlreadySeen;
+};
+
} // end namespace dependencies
} // end namespace tooling
} // end namespace clang
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
index 03ad6dcc51b30..cf6085857b4d1 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
@@ -114,76 +114,42 @@ DependencyScanningTool::getFullDependencies(
const std::vector<std::string> &CommandLine, StringRef CWD,
const llvm::StringSet<> &AlreadySeen,
llvm::Optional<StringRef> ModuleName) {
- class FullDependencyPrinterConsumer : public DependencyConsumer {
- public:
- FullDependencyPrinterConsumer(const llvm::StringSet<> &AlreadySeen)
- : AlreadySeen(AlreadySeen) {}
-
- void
- handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {}
-
- void handleFileDependency(StringRef File) override {
- Dependencies.push_back(std::string(File));
- }
-
- void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override {
- PrebuiltModuleDeps.emplace_back(std::move(PMD));
- }
-
- void handleModuleDependency(ModuleDeps MD) override {
- ClangModuleDeps[MD.ID.ContextHash + MD.ID.ModuleName] = std::move(MD);
- }
-
- void handleContextHash(std::string Hash) override {
- ContextHash = std::move(Hash);
- }
-
- FullDependenciesResult getFullDependencies(
- const std::vector<std::string> &OriginalCommandLine) const {
- FullDependencies FD;
-
- FD.OriginalCommandLine =
- ArrayRef<std::string>(OriginalCommandLine).slice(1);
+ FullDependencyConsumer Consumer(AlreadySeen);
+ llvm::Error Result =
+ Worker.computeDependencies(CWD, CommandLine, Consumer, ModuleName);
+ if (Result)
+ return std::move(Result);
+ return Consumer.getFullDependencies(CommandLine);
+}
- FD.ID.ContextHash = std::move(ContextHash);
+FullDependenciesResult FullDependencyConsumer::getFullDependencies(
+ const std::vector<std::string> &OriginalCommandLine) const {
+ FullDependencies FD;
- FD.FileDeps.assign(Dependencies.begin(), Dependencies.end());
+ FD.OriginalCommandLine = ArrayRef<std::string>(OriginalCommandLine).slice(1);
- for (auto &&M : ClangModuleDeps) {
- auto &MD = M.second;
- if (MD.ImportedByMainFile)
- FD.ClangModuleDeps.push_back(MD.ID);
- }
+ FD.ID.ContextHash = std::move(ContextHash);
- FD.PrebuiltModuleDeps = std::move(PrebuiltModuleDeps);
+ FD.FileDeps.assign(Dependencies.begin(), Dependencies.end());
- FullDependenciesResult FDR;
+ for (auto &&M : ClangModuleDeps) {
+ auto &MD = M.second;
+ if (MD.ImportedByMainFile)
+ FD.ClangModuleDeps.push_back(MD.ID);
+ }
- for (auto &&M : ClangModuleDeps) {
- // TODO: Avoid handleModuleDependency even being called for modules
- // we've already seen.
- if (AlreadySeen.count(M.first))
- continue;
- FDR.DiscoveredModules.push_back(std::move(M.second));
- }
+ FD.PrebuiltModuleDeps = std::move(PrebuiltModuleDeps);
- FDR.FullDeps = std::move(FD);
- return FDR;
- }
+ FullDependenciesResult FDR;
- private:
- std::vector<std::string> Dependencies;
- std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
- llvm::MapVector<std::string, ModuleDeps, llvm::StringMap<unsigned>> ClangModuleDeps;
- std::string ContextHash;
- std::vector<std::string> OutputPaths;
- const llvm::StringSet<> &AlreadySeen;
- };
+ for (auto &&M : ClangModuleDeps) {
+ // TODO: Avoid handleModuleDependency even being called for modules
+ // we've already seen.
+ if (AlreadySeen.count(M.first))
+ continue;
+ FDR.DiscoveredModules.push_back(std::move(M.second));
+ }
- FullDependencyPrinterConsumer Consumer(AlreadySeen);
- llvm::Error Result =
- Worker.computeDependencies(CWD, CommandLine, Consumer, ModuleName);
- if (Result)
- return std::move(Result);
- return Consumer.getFullDependencies(CommandLine);
+ FDR.FullDeps = std::move(FD);
+ return FDR;
}
More information about the cfe-commits
mailing list