diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2023-11-09 17:15:55 +0800 |
---|---|---|
committer | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2023-11-09 17:44:41 +0800 |
commit | 0f7aaeb3241c3803489a45753190e82dbc7fd5fa (patch) | |
tree | 241536efd4dd2fece6917eaeb4bbfd56056c776c /clang/lib/Sema/SemaModule.cpp | |
parent | e3d750cc40e4cea281924142859dd4b9a6465f99 (diff) | |
download | llvm-0f7aaeb3241c3803489a45753190e82dbc7fd5fa.zip llvm-0f7aaeb3241c3803489a45753190e82dbc7fd5fa.tar.gz llvm-0f7aaeb3241c3803489a45753190e82dbc7fd5fa.tar.bz2 |
[C++20] [Modules] Allow export from language linkage
Close https://github.com/llvm/llvm-project/issues/71347
Previously I misread the concept of module purview. I thought if a
declaration attached to a unnamed module, it can't be part of the module
purview. But after the issue report, I recognized that module purview is
more of a concept about locations instead of semantics.
Concretely, the things in the language linkage after module declarations
can be exported.
This patch refactors `Module::isModulePurview()` and introduces some
possible code cleanups.
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r-- | clang/lib/Sema/SemaModule.cpp | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 99b4d7d..9282ceb 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -939,22 +939,20 @@ void Sema::PopGlobalModuleFragment() { ModuleScopes.pop_back(); } -Module *Sema::PushImplicitGlobalModuleFragment(SourceLocation BeginLoc, - bool IsExported) { - Module **M = IsExported ? &TheExportedImplicitGlobalModuleFragment - : &TheImplicitGlobalModuleFragment; - if (!*M) { +Module *Sema::PushImplicitGlobalModuleFragment(SourceLocation BeginLoc) { + if (!TheImplicitGlobalModuleFragment) { ModuleMap &Map = PP.getHeaderSearchInfo().getModuleMap(); - *M = Map.createImplicitGlobalModuleFragmentForModuleUnit( - BeginLoc, IsExported, getCurrentModule()); + TheImplicitGlobalModuleFragment = + Map.createImplicitGlobalModuleFragmentForModuleUnit(BeginLoc, + getCurrentModule()); } - assert(*M && "module creation should not fail"); + assert(TheImplicitGlobalModuleFragment && "module creation should not fail"); // Enter the scope of the global module. - ModuleScopes.push_back({BeginLoc, *M, + ModuleScopes.push_back({BeginLoc, TheImplicitGlobalModuleFragment, /*OuterVisibleModules=*/{}}); - VisibleModules.setVisible(*M, BeginLoc); - return *M; + VisibleModules.setVisible(TheImplicitGlobalModuleFragment, BeginLoc); + return TheImplicitGlobalModuleFragment; } void Sema::PopImplicitGlobalModuleFragment() { @@ -963,3 +961,22 @@ void Sema::PopImplicitGlobalModuleFragment() { "left the wrong module scope, which is not global module fragment"); ModuleScopes.pop_back(); } + +bool Sema::isCurrentModulePurview() const { + if (!getCurrentModule()) + return false; + + /// Does this Module scope describe part of the purview of a standard named + /// C++ module? + switch (getCurrentModule()->Kind) { + case Module::ModuleInterfaceUnit: + case Module::ModuleImplementationUnit: + case Module::ModulePartitionInterface: + case Module::ModulePartitionImplementation: + case Module::PrivateModuleFragment: + case Module::ImplicitGlobalModuleFragment: + return true; + default: + return false; + } +} |