aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/Module.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2023-09-28 14:02:05 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2023-09-28 14:06:02 +0800
commit9744909a126ead515c433097c0b5f76c98e9a5b4 (patch)
tree0c3f9bf2956ed76fdef3fc76a1138df15f5517b2 /clang/lib/Basic/Module.cpp
parent34ee53c9e390019d757b453ceba9cc3e47ab0df1 (diff)
downloadllvm-9744909a126ead515c433097c0b5f76c98e9a5b4.zip
llvm-9744909a126ead515c433097c0b5f76c98e9a5b4.tar.gz
llvm-9744909a126ead515c433097c0b5f76c98e9a5b4.tar.bz2
[NFC] [C++20] [Modules] Refactor Module::getGlobalModuleFragment and Module::getPrivateModuleFragment
The original implementation of `Module::getGlobalModuleFragment` and `Module::getPrivateModuleFragment` tried to find the global module fragment and the private module fragment by comparing strings, which smells bad. This patch tries to improve this.
Diffstat (limited to 'clang/lib/Basic/Module.cpp')
-rw-r--r--clang/lib/Basic/Module.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 4ffdb6a..4e6fbfc 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -370,6 +370,28 @@ Module *Module::findOrInferSubmodule(StringRef Name) {
return Result;
}
+Module *Module::getGlobalModuleFragment() const {
+ assert(isNamedModuleUnit() && "We should only query the global module "
+ "fragment from the C++ 20 Named modules");
+
+ for (auto *SubModule : SubModules)
+ if (SubModule->isExplicitGlobalModule())
+ return SubModule;
+
+ return nullptr;
+}
+
+Module *Module::getPrivateModuleFragment() const {
+ assert(isNamedModuleUnit() && "We should only query the private module "
+ "fragment from the C++ 20 Named modules");
+
+ for (auto *SubModule : SubModules)
+ if (SubModule->isPrivateModule())
+ return SubModule;
+
+ return nullptr;
+}
+
void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const {
// All non-explicit submodules are exported.
for (std::vector<Module *>::const_iterator I = SubModules.begin(),