================
@@ -0,0 +1,78 @@
+//===-------------- ModuleDependencyScanner.h --------------------*-
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULEDEPENDENCYSCANNER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_MODULEDEPENDENCYSCANNER_H
+
+#include "GlobalCompilationDatabase.h"
+#include "support/Path.h"
+#include "support/ThreadsafeFS.h"
+
+#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
+
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringMap.h"
+
+namespace clang {
+namespace clangd {
+
+/// A scanner to produce P1689 format for C++20 Modules.
+///
+/// The scanner can scan a single file with `scan(PathRef)` member function
+/// or scan the whole project with `globalScan(PathRef)` member function. See
+/// the comments of `globalScan` to see the details.
+class ModuleDependencyScanner {
+public:
+ ModuleDependencyScanner(const GlobalCompilationDatabase &CDB,
+ const ThreadsafeFS *TFS)
+ : CDB(CDB), TFS(TFS),
+ Service(tooling::dependencies::ScanningMode::CanonicalPreprocessing,
+ tooling::dependencies::ScanningOutputFormat::P1689) {}
+
+ /// Scanning the single file specified by \param FilePath.
+ std::optional<clang::tooling::dependencies::P1689Rule> scan(PathRef
FilePath);
----------------
ChuanqiXu9 wrote:
Yeah, I added `ModuleDependencyInfo` struct.
```
struct ModuleDependencyInfo {
// The name of the module if the file is a module unit.
std::optional<std::string> ModuleName;
// A list of names for the modules that the file directly depends.
std::vector<std::string> RequiredModules;
};
```
The complete P1689 information may be redundant for us.
I didn't add the suggested interfaces. Since I found the following two
interfaces are sufficient and more straight forward in practice (from my mind.
I feel like we don't need to look at the definition of `ModuleNode` now when we
use the scanner):
```
PathRef getSourceForModuleName(StringRef ModuleName);
std::vector<std::string> getRequiredModules(PathRef File);
```
https://github.com/llvm/llvm-project/pull/66462
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits