Lines Matching full:module
25 static void checkModuleImportContext(Sema &S, Module *M,
61 // of the hierarchical access path for a clang module. However for C++20
78 /// the \param Imported module unit is in the same module with the \param
81 /// primary module interface unit corresponding to the module \param
82 /// CurrentModule. Since currently it is expensive to decide whether two module
83 /// units come from the same module by comparing the module name.
85 isImportingModuleUnitFromSameModule(ASTContext &Ctx, Module *Imported,
86 Module *CurrentModule,
87 Module *&FoundPrimaryModuleInterface) {
91 // The a partition unit we're importing must be in the same module of the
92 // current module.
96 // If we found the primary module interface during the search process, we can
104 // Then the imported module must be a primary module interface unit. It
105 // is only allowed to import the primary module interface unit from the same
106 // module in the implementation unit and the implementation partition unit.
123 /// [module.import]p7:
124 /// Additionally, when a module-import-declaration in a module unit of some
125 /// module M imports another module unit U of M, it also imports all
126 /// translation units imported by non-exported module-import-declarations in
127 /// the module unit purview of U. These rules can in turn lead to the
131 Module *Imported, Module *CurrentModule,
138 llvm::SmallVector<Module *, 4> Worklist;
141 Module *FoundPrimaryModuleInterface =
145 Module *Importing = Worklist.pop_back_val();
156 for (Module *TransImported : Importing->Imports)
164 // We start in the global module;
165 Module *GlobalModule =
168 // All declarations created from now on are owned by the global module.
170 // [module.global.frag]p2
171 // A global-module-fragment specifies the contents of the global module
172 // fragment for a module unit. The global module fragment can be used to
173 // provide declarations that are attached to the global module and usable
174 // within the module unit.
176 // So the declations in the global module shouldn't be visible by default.
207 Module::Header H{HUName.str(), HUName.str(), *F};
209 Module *Mod = Map.createHeaderUnit(StartOfTU, HUName, H);
210 assert(Mod && "module creation should not fail");
213 ModuleScopes.back().Module = Mod;
216 // From now on, we have an owning module for all declarations we see.
223 /// Tests whether the given identifier is reserved as a module name and
234 if (II->isStr("module") || II->isStr("import"))
263 "should only have module decl in standard C++ modules");
268 // module state;
284 // A (non-partition) module implementation unit requires that we are not
285 // compiling a module of any kind. A partition implementation emits an
288 // A module interface unit requires that we are not compiling a module map.
291 // It's OK to compile a module interface as a normal translation unit.
298 // We were asked to compile a module interface unit but this is a module
314 assert(ModuleScopes.size() <= 1 && "expected to be at global module scope");
319 // Only one module-declaration is permitted per source file.
322 Diag(VisibleModules.getImportLoc(ModuleScopes.back().Module),
329 "mismatched global module state");
331 // In C++20, the module-declaration must be the first declaration if there
332 // is no global module fragment.
341 << FixItHint::CreateInsertion(BeginLoc, "module;\n");
345 // C++23 [module.unit]p1: ... The identifiers module and import shall not
346 // appear as identifiers in a module-name or module-partition. All
347 // module-names either beginning with an identifier consisting of std
350 // module-declaration; no diagnostic is required.
368 // Flatten the dots in a module name. Unlike Clang's hierarchical module map
370 // module name.
376 // If a module name was explicitly specified on the command line, it must be
390 Module *Mod; // The module we are creating.
391 Module *Interface = nullptr; // The interface for an implementation.
395 // We can't have parsed or imported a definition of this module or parsed a
396 // module map defining it already.
408 // Create a Module for the module that we're defining.
411 Mod->Kind = Module::ModulePartitionInterface;
412 assert(Mod && "module creation should not fail");
417 // C++20 A module-declaration that contains neither an export-
418 // keyword nor a module-partition implicitly imports the primary
419 // module interface unit of the module as if by a module-import-
424 // The module loader will assume we're trying to import the module that
427 // module loader work properly.
430 Module::AllVisible,
436 // Create an empty module interface unit for error recovery.
447 Mod->Kind = Module::ModulePartitionImplementation;
456 // We're done with the global module fragment now.
460 // Switch from the global module fragment (if any) to the named module.
462 ModuleScopes.back().Module = Mod;
465 // From now on, we have an owning module for all declarations we see.
468 // Otherwise, those declarations are module-private unless explicitly
474 // We are in the module purview, but before any other (non import)
483 // We already potentially made an implicit import (in the case of a module
484 // implementation unit importing its interface). Make this module visible
492 // Make the import decl for the interface in the impl module.
497 // Sequence initialization of the imported module before that of the current
498 // module, if any.
499 Context.addModuleInitializer(ModuleScopes.back().Module, Import);
503 // If we made an implicit import of the module interface, then return the
504 // imported module decl.
515 // A private-module-fragment shall appear only in a primary module
517 switch (ModuleScopes.empty() ? Module::ExplicitGlobalModuleFragment
518 : ModuleScopes.back().Module->Kind) {
519 case Module::ModuleMapModule:
520 case Module::ExplicitGlobalModuleFragment:
521 case Module::ImplicitGlobalModuleFragment:
522 case Module::ModulePartitionImplementation:
523 case Module::ModulePartitionInterface:
524 case Module::ModuleHeaderUnit:
528 case Module::PrivateModuleFragment:
533 case Module::ModuleImplementationUnit:
540 case Module::ModuleInterfaceUnit:
545 // such imports would violate [basic.link]/2's "shall be the only module unit"
552 Module *PrivateModuleFragment =
554 ModuleScopes.back().Module, PrivateLoc);
555 assert(PrivateModuleFragment && "module creation should not fail");
557 // Enter the scope of the private module fragment.
560 ModuleScopes.back().Module = PrivateModuleFragment;
563 // All declarations created from now on are scoped to the private module
564 // fragment (and are neither visible nor reachable in importers of the module
581 // For a C++20 module name, flatten into a single identifier with the source
587 // We already checked that we are in a module purview in the parser.
588 assert(!ModuleScopes.empty() && "in a module purview, but no module?");
589 Module *NamedMod = ModuleScopes.back().Module;
590 // If we are importing into a partition, find the owning named module,
591 // otherwise, the name of the importing named module.
604 // [module.import]/9
605 // A module implementation unit of a module M that is not a module partition
606 // shall not contain a module-import-declaration nominating M.
607 // (for an implementation, the module interface is imported implicitly,
608 // but that's handled in the module decl code).
617 Module *Mod = getModuleLoader().loadModule(
618 ImportLoc, Path, Module::AllVisible, /*IsInclusionDirective=*/false);
642 SourceLocation ImportLoc, Module *Mod,
656 // of the same top-level module. Until we do, make it an error rather than
658 // FIXME: Should we warn on a redundant import of the current module?
672 for (Module *ModCheck = Mod; ModCheck; ModCheck = ModCheck->Parent)
678 Module *ModCheck = Mod;
680 // If we've run out of module parents, just drop the remaining
694 // Sequence initialization of the imported module before that of the current
695 // module, if any.
697 Context.addModuleInitializer(ModuleScopes.back().Module, Import);
699 // A module (partition) implementation unit shall not be exported.
701 Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) {
705 // Re-export the module if the imported module is exported.
706 // Note that we don't need to add re-exported module to Imports field
707 // since `Exports` implies the module is imported already.
713 // [module.interface]p1:
715 // purview of a module interface unit.
722 void Sema::ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
727 void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
728 // Determine whether we're in the #include buffer for a module. The #includes
729 // in that buffer do not qualify as module imports; they're just an
730 // implementation detail of us building the module.
737 // If we are really importing a module (not just checking layering) due to an
745 Context.addModuleInitializer(ModuleScopes.back().Module, ImportD);
750 getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, DirectiveLoc);
754 Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
757 assert(ThisModule && "was expecting a module if building one");
761 void Sema::ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod) {
765 ModuleScopes.back().Module = Mod;
771 // The enclosing context is now part of this module.
773 // lexically within the module.
785 void Sema::ActOnAnnotModuleEnd(SourceLocation EomLoc, Module *Mod) {
788 // Leaving a module hides namespace names, so our visible namespace cache
793 assert(!ModuleScopes.empty() && ModuleScopes.back().Module == Mod &&
794 "left the wrong module scope");
797 // We got to the end of processing a local module. Create an
798 // ImportDecl as we would for an imported module.
802 // We reached the end of a #included module header. Use the #include loc.
812 // Any further declarations are in whatever module we returned to.
815 // the module within.
826 Module *Mod) {
827 // Bail if we're not allowed to implicitly import a module here.
839 // Make the module visible.
840 getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, Loc);
854 // C++2a [module.interface]p1:
855 // An export-declaration shall appear only [...] in the purview of a module
857 // indirectly within [...] a private-module-fragment.
870 } else if (ModuleScopes.back().Module->Kind ==
871 Module::PrivateModuleFragment) {
941 // C++20 [module.interface]p3:
956 // C++2a [module.interface]p5:
962 if (Lk == Linkage::Internal || Lk == Linkage::Module) {
1007 // If an inline function or variable that is attached to a named module
1019 // Anything exported from a module should never be considered unused.
1026 Module *Sema::PushGlobalModuleFragment(SourceLocation BeginLoc) {
1027 // We shouldn't create new global module fragment if there is already
1035 assert(TheGlobalModuleFragment && "module creation should not fail");
1037 // Enter the scope of the global module.
1048 "left the wrong module scope, which is not global module fragment");
1052 Module *Sema::PushImplicitGlobalModuleFragment(SourceLocation BeginLoc) {
1059 assert(TheImplicitGlobalModuleFragment && "module creation should not fail");
1061 // Enter the scope of the global module.
1071 "left the wrong module scope, which is not global module fragment");
1079 /// Does this Module scope describe part of the purview of a standard named
1080 /// C++ module?
1082 case Module::ModuleInterfaceUnit:
1083 case Module::ModuleImplementationUnit:
1084 case Module::ModulePartitionInterface:
1085 case Module::ModulePartitionImplementation:
1086 case Module::PrivateModuleFragment:
1087 case Module::ImplicitGlobalModuleFragment: