aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaModule.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-06-24 15:47:30 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-06-24 15:58:46 +0800
commit790f931886a03324714f31a626eef7e9c609ae97 (patch)
tree8689a3e94f5995fb28d076a04246d17566d72835 /clang/lib/Sema/SemaModule.cpp
parent57f79371a5c08e1328e85b68b757cd5547f2bf62 (diff)
downloadllvm-790f931886a03324714f31a626eef7e9c609ae97.zip
llvm-790f931886a03324714f31a626eef7e9c609ae97.tar.gz
llvm-790f931886a03324714f31a626eef7e9c609ae97.tar.bz2
[NFC] [Modules] Extract the logic to decide whether the module units belongs to the same module
This patch extracts the logci to decide how we decide the module units belongs to the same module into a member function of ASTContext. This is helpful to refactor the implementation in the future.
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r--clang/lib/Sema/SemaModule.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index ad118ac..98e7971 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -82,7 +82,8 @@ static std::string stringFromPath(ModuleIdPath Path) {
/// CurrentModule. Since currently it is expensive to decide whether two module
/// units come from the same module by comparing the module name.
static bool
-isImportingModuleUnitFromSameModule(Module *Imported, Module *CurrentModule,
+isImportingModuleUnitFromSameModule(ASTContext &Ctx, Module *Imported,
+ Module *CurrentModule,
Module *&FoundPrimaryModuleInterface) {
if (!Imported->isNamedModule())
return false;
@@ -109,8 +110,7 @@ isImportingModuleUnitFromSameModule(Module *Imported, Module *CurrentModule,
if (!CurrentModule->isModulePartitionImplementation())
return false;
- if (Imported->getPrimaryModuleInterfaceName() ==
- CurrentModule->getPrimaryModuleInterfaceName()) {
+ if (Ctx.isInSameModule(Imported, CurrentModule)) {
assert(!FoundPrimaryModuleInterface ||
FoundPrimaryModuleInterface == Imported);
FoundPrimaryModuleInterface = Imported;
@@ -127,8 +127,9 @@ isImportingModuleUnitFromSameModule(Module *Imported, Module *CurrentModule,
/// the module unit purview of U. These rules can in turn lead to the
/// importation of yet more translation units.
static void
-makeTransitiveImportsVisible(VisibleModuleSet &VisibleModules, Module *Imported,
- Module *CurrentModule, SourceLocation ImportLoc,
+makeTransitiveImportsVisible(ASTContext &Ctx, VisibleModuleSet &VisibleModules,
+ Module *Imported, Module *CurrentModule,
+ SourceLocation ImportLoc,
bool IsImportingPrimaryModuleInterface = false) {
assert(Imported->isNamedModule() &&
"'makeTransitiveImportsVisible()' is intended for standard C++ named "
@@ -150,7 +151,7 @@ makeTransitiveImportsVisible(VisibleModuleSet &VisibleModules, Module *Imported,
// use the sourcelocation loaded from the visible modules.
VisibleModules.setVisible(Importing, ImportLoc);
- if (isImportingModuleUnitFromSameModule(Importing, CurrentModule,
+ if (isImportingModuleUnitFromSameModule(Ctx, Importing, CurrentModule,
FoundPrimaryModuleInterface))
for (Module *TransImported : Importing->Imports)
if (!VisibleModules.isVisible(TransImported))
@@ -484,7 +485,8 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// and return the import decl to be added to the current TU.
if (Interface) {
- makeTransitiveImportsVisible(VisibleModules, Interface, Mod, ModuleLoc,
+ makeTransitiveImportsVisible(getASTContext(), VisibleModules, Interface,
+ Mod, ModuleLoc,
/*IsImportingPrimaryModuleInterface=*/true);
// Make the import decl for the interface in the impl module.
@@ -643,8 +645,8 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
Diag(ImportLoc, diag::warn_experimental_header_unit);
if (Mod->isNamedModule())
- makeTransitiveImportsVisible(VisibleModules, Mod, getCurrentModule(),
- ImportLoc);
+ makeTransitiveImportsVisible(getASTContext(), VisibleModules, Mod,
+ getCurrentModule(), ImportLoc);
else
VisibleModules.setVisible(Mod, ImportLoc);