Skip to content

Commit

Permalink
[NFC] [C++20] [Modules] Remove 'ModuleInterface' bit in Sema::ModuleS…
Browse files Browse the repository at this point in the history
…cope

The 'ModuleInterface' in Sema::ModuleScope is confusing. It actually
means 'not implementation'. This patch removes that bit and extract the
information from the recorded clang::Module.
  • Loading branch information
ChuanqiXu9 committed Nov 9, 2023
1 parent e179b12 commit 427f13b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
9 changes: 5 additions & 4 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,6 @@ class Sema final {
struct ModuleScope {
SourceLocation BeginLoc;
clang::Module *Module = nullptr;
bool ModuleInterface = false;
VisibleModuleSet OuterVisibleModules;
};
/// The modules we're currently parsing.
Expand Down Expand Up @@ -2367,9 +2366,11 @@ class Sema final {
return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module;
}

/// Is the module scope we are an interface?
bool currentModuleIsInterface() const {
return ModuleScopes.empty() ? false : ModuleScopes.back().ModuleInterface;
/// Is the module scope we are an implementation unit?
bool currentModuleIsImplementation() const {
return ModuleScopes.empty()
? false
: ModuleScopes.back().Module->isModuleImplementation();
}

/// Is the module scope we are in a C++ Header Unit?
Expand Down
14 changes: 3 additions & 11 deletions clang/lib/Sema/SemaModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ void Sema::HandleStartOfHeaderUnit() {
ModuleScopes.push_back({}); // No GMF
ModuleScopes.back().BeginLoc = StartOfTU;
ModuleScopes.back().Module = Mod;
ModuleScopes.back().ModuleInterface = true;
VisibleModules.setVisible(Mod, StartOfTU);

// From now on, we have an owning module for all declarations we see.
Expand Down Expand Up @@ -375,7 +374,6 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// Switch from the global module fragment (if any) to the named module.
ModuleScopes.back().BeginLoc = StartLoc;
ModuleScopes.back().Module = Mod;
ModuleScopes.back().ModuleInterface = MDK != ModuleDeclKind::Implementation;
VisibleModules.setVisible(Mod, ModuleLoc);

// From now on, we have an owning module for all declarations we see.
Expand Down Expand Up @@ -470,7 +468,6 @@ Sema::ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc,
ModuleScopes.push_back({});
ModuleScopes.back().BeginLoc = ModuleLoc;
ModuleScopes.back().Module = PrivateModuleFragment;
ModuleScopes.back().ModuleInterface = true;
VisibleModules.setVisible(PrivateModuleFragment, ModuleLoc);

// All declarations created from now on are scoped to the private module
Expand Down Expand Up @@ -523,7 +520,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
if (getLangOpts().CPlusPlusModules && isCurrentModulePurview() &&
getCurrentModule()->Name == ModuleName) {
Diag(ImportLoc, diag::err_module_self_import_cxx20)
<< ModuleName << !ModuleScopes.back().ModuleInterface;
<< ModuleName << currentModuleIsImplementation();
return true;
}

Expand Down Expand Up @@ -609,10 +606,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) {
Diag(ExportLoc, diag::err_export_partition_impl)
<< SourceRange(ExportLoc, Path.back().second);
} else if (!ModuleScopes.empty() &&
(ModuleScopes.back().ModuleInterface ||
(getLangOpts().CPlusPlusModules &&
ModuleScopes.back().Module->isGlobalModule()))) {
} else if (!ModuleScopes.empty() && !currentModuleIsImplementation()) {
// Re-export the module if the imported module is exported.
// Note that we don't need to add re-exported module to Imports field
// since `Exports` implies the module is imported already.
Expand Down Expand Up @@ -772,7 +766,7 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc,
Diag(ExportLoc, diag::err_export_not_in_module_interface) << 0;
D->setInvalidDecl();
return D;
} else if (!ModuleScopes.back().ModuleInterface) {
} else if (currentModuleIsImplementation()) {
Diag(ExportLoc, diag::err_export_not_in_module_interface) << 1;
Diag(ModuleScopes.back().BeginLoc,
diag::note_not_module_interface_add_export)
Expand Down Expand Up @@ -932,7 +926,6 @@ Module *Sema::PushGlobalModuleFragment(SourceLocation BeginLoc) {

// Enter the scope of the global module.
ModuleScopes.push_back({BeginLoc, TheGlobalModuleFragment,
/*ModuleInterface=*/false,
/*OuterVisibleModules=*/{}});
VisibleModules.setVisible(TheGlobalModuleFragment, BeginLoc);

Expand All @@ -959,7 +952,6 @@ Module *Sema::PushImplicitGlobalModuleFragment(SourceLocation BeginLoc,

// Enter the scope of the global module.
ModuleScopes.push_back({BeginLoc, *M,
/*ModuleInterface=*/false,
/*OuterVisibleModules=*/{}});
VisibleModules.setVisible(*M, BeginLoc);
return *M;
Expand Down

0 comments on commit 427f13b

Please sign in to comment.