Commit 427f13bd authored by Chuanqi Xu's avatar Chuanqi Xu
Browse files

[NFC] [C++20] [Modules] Remove 'ModuleInterface' bit in Sema::ModuleScope

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.
parent e179b125
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -2303,7 +2303,6 @@ private:
  struct ModuleScope {
    SourceLocation BeginLoc;
    clang::Module *Module = nullptr;
    bool ModuleInterface = false;
    VisibleModuleSet OuterVisibleModules;
  };
  /// The modules we're currently parsing.
@@ -2367,9 +2366,11 @@ public:
    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?
+3 −11
Original line number Diff line number Diff line
@@ -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.
@@ -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.
@@ -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
@@ -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;
  }

@@ -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.
@@ -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)
@@ -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);

@@ -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;