Lines Matching full:module

24 static void checkModuleImportContext(Sema &S, Module *M,
60 // of the hierarchical access path for a clang module. However for C++20
77 /// the \param Imported module unit is in the same module with the \param
80 /// primary module interface unit corresponding to the module \param
81 /// CurrentModule. Since currently it is expensive to decide whether two module
82 /// units come from the same module by comparing the module name.
84 isImportingModuleUnitFromSameModule(ASTContext &Ctx, Module *Imported,
85 Module *CurrentModule,
86 Module *&FoundPrimaryModuleInterface) {
90 // The a partition unit we're importing must be in the same module of the
91 // current module.
95 // If we found the primary module interface during the search process, we can
103 // Then the imported module must be a primary module interface unit. It
104 // is only allowed to import the primary module interface unit from the same
105 // module in the implementation unit and the implementation partition unit.
122 /// [module.import]p7:
123 /// Additionally, when a module-import-declaration in a module unit of some
124 /// module M imports another module unit U of M, it also imports all
125 /// translation units imported by non-exported module-import-declarations in
126 /// the module unit purview of U. These rules can in turn lead to the
130 Module *Imported, Module *CurrentModule,
137 llvm::SmallVector<Module *, 4> Worklist;
140 Module *FoundPrimaryModuleInterface =
144 Module *Importing = Worklist.pop_back_val();
155 for (Module *TransImported : Importing->Imports)
163 // We start in the global module;
164 Module *GlobalModule =
167 // All declarations created from now on are owned by the global module.
169 // [module.global.frag]p2
170 // A global-module-fragment specifies the contents of the global module
171 // fragment for a module unit. The global module fragment can be used to
172 // provide declarations that are attached to the global module and usable
173 // within the module unit.
175 // So the declations in the global module shouldn't be visible by default.
206 Module::Header H{HUName.str(), HUName.str(), *F};
208 Module *Mod = Map.createHeaderUnit(StartOfTU, HUName, H);
209 assert(Mod && "module creation should not fail");
212 ModuleScopes.back().Module = Mod;
215 // From now on, we have an owning module for all declarations we see.
222 /// Tests whether the given identifier is reserved as a module name and
233 if (II->isStr("module") || II->isStr("import"))
262 "should only have module decl in standard C++ modules");
267 // module state;
283 // A (non-partition) module implementation unit requires that we are not
284 // compiling a module of any kind. A partition implementation emits an
287 // A module interface unit requires that we are not compiling a module map.
290 // It's OK to compile a module interface as a normal translation unit.
297 // We were asked to compile a module interface unit but this is a module
313 assert(ModuleScopes.size() <= 1 && "expected to be at global module scope");
318 // Only one module-declaration is permitted per source file.
321 Diag(VisibleModules.getImportLoc(ModuleScopes.back().Module),
328 "mismatched global module state");
330 // In C++20, the module-declaration must be the first declaration if there
331 // is no global module fragment.
340 << FixItHint::CreateInsertion(BeginLoc, "module;\n");
344 // C++23 [module.unit]p1: ... The identifiers module and import shall not
345 // appear as identifiers in a module-name or module-partition. All
346 // module-names either beginning with an identifier consisting of std
349 // module-declaration; no diagnostic is required.
367 // Flatten the dots in a module name. Unlike Clang's hierarchical module map
369 // module name.
375 // If a module name was explicitly specified on the command line, it must be
389 Module *Mod; // The module we are creating.
390 Module *Interface = nullptr; // The interface for an implementation.
394 // We can't have parsed or imported a definition of this module or parsed a
395 // module map defining it already.
407 // Create a Module for the module that we're defining.
410 Mod->Kind = Module::ModulePartitionInterface;
411 assert(Mod && "module creation should not fail");
416 // C++20 A module-declaration that contains neither an export-
417 // keyword nor a module-partition implicitly imports the primary
418 // module interface unit of the module as if by a module-import-
423 // The module loader will assume we're trying to import the module that
426 // module loader work properly.
429 Module::AllVisible,
435 // Create an empty module interface unit for error recovery.
446 Mod->Kind = Module::ModulePartitionImplementation;
455 // We're done with the global module fragment now.
459 // Switch from the global module fragment (if any) to the named module.
461 ModuleScopes.back().Module = Mod;
464 // From now on, we have an owning module for all declarations we see.
467 // Otherwise, those declarations are module-private unless explicitly
473 // We are in the module purview, but before any other (non import)
482 // We already potentially made an implicit import (in the case of a module
483 // implementation unit importing its interface). Make this module visible
491 // Make the import decl for the interface in the impl module.
496 // Sequence initialization of the imported module before that of the current
497 // module, if any.
498 Context.addModuleInitializer(ModuleScopes.back().Module, Import);
502 // If we made an implicit import of the module interface, then return the
503 // imported module decl.
514 // A private-module-fragment shall appear only in a primary module
516 switch (ModuleScopes.empty() ? Module::ExplicitGlobalModuleFragment
517 : ModuleScopes.back().Module->Kind) {
518 case Module::ModuleMapModule:
519 case Module::ExplicitGlobalModuleFragment:
520 case Module::ImplicitGlobalModuleFragment:
521 case Module::ModulePartitionImplementation:
522 case Module::ModulePartitionInterface:
523 case Module::ModuleHeaderUnit:
527 case Module::PrivateModuleFragment:
532 case Module::ModuleImplementationUnit:
539 case Module::ModuleInterfaceUnit:
544 // such imports would violate [basic.link]/2's "shall be the only module unit"
551 Module *PrivateModuleFragment =
553 ModuleScopes.back().Module, PrivateLoc);
554 assert(PrivateModuleFragment && "module creation should not fail");
556 // Enter the scope of the private module fragment.
559 ModuleScopes.back().Module = PrivateModuleFragment;
562 // All declarations created from now on are scoped to the private module
563 // fragment (and are neither visible nor reachable in importers of the module
580 // For a C++20 module name, flatten into a single identifier with the source
586 // We already checked that we are in a module purview in the parser.
587 assert(!ModuleScopes.empty() && "in a module purview, but no module?");
588 Module *NamedMod = ModuleScopes.back().Module;
589 // If we are importing into a partition, find the owning named module,
590 // otherwise, the name of the importing named module.
603 // [module.import]/9
604 // A module implementation unit of a module M that is not a module partition
605 // shall not contain a module-import-declaration nominating M.
606 // (for an implementation, the module interface is imported implicitly,
607 // but that's handled in the module decl code).
616 Module *Mod = getModuleLoader().loadModule(
617 ImportLoc, Path, Module::AllVisible, /*IsInclusionDirective=*/false);
641 SourceLocation ImportLoc, Module *Mod,
653 "We can only import a partition unit in a named module.");
663 // of the same top-level module. Until we do, make it an error rather than
665 // FIXME: Should we warn on a redundant import of the current module?
679 for (Module *ModCheck = Mod; ModCheck; ModCheck = ModCheck->Parent)
685 Module *ModCheck = Mod;
687 // If we've run out of module parents, just drop the remaining
701 // Sequence initialization of the imported module before that of the current
702 // module, if any.
704 Context.addModuleInitializer(ModuleScopes.back().Module, Import);
706 // A module (partition) implementation unit shall not be exported.
708 Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) {
712 // Re-export the module if the imported module is exported.
713 // Note that we don't need to add re-exported module to Imports field
714 // since `Exports` implies the module is imported already.
720 // [module.interface]p1:
722 // purview of a module interface unit.
729 void Sema::ActOnAnnotModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
734 void Sema::BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod) {
735 // Determine whether we're in the #include buffer for a module. The #includes
736 // in that buffer do not qualify as module imports; they're just an
737 // implementation detail of us building the module.
744 // If we are really importing a module (not just checking layering) due to an
752 Context.addModuleInitializer(ModuleScopes.back().Module, ImportD);
757 getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, DirectiveLoc);
761 Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
764 assert(ThisModule && "was expecting a module if building one");
768 void Sema::ActOnAnnotModuleBegin(SourceLocation DirectiveLoc, Module *Mod) {
772 ModuleScopes.back().Module = Mod;
778 // The enclosing context is now part of this module.
780 // lexically within the module.
792 void Sema::ActOnAnnotModuleEnd(SourceLocation EomLoc, Module *Mod) {
795 // Leaving a module hides namespace names, so our visible namespace cache
800 assert(!ModuleScopes.empty() && ModuleScopes.back().Module == Mod &&
801 "left the wrong module scope");
804 // We got to the end of processing a local module. Create an
805 // ImportDecl as we would for an imported module.
809 // We reached the end of a #included module header. Use the #include loc.
819 // Any further declarations are in whatever module we returned to.
822 // the module within.
833 Module *Mod) {
834 // Bail if we're not allowed to implicitly import a module here.
846 // Make the module visible.
847 getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, Loc);
861 // C++2a [module.interface]p1:
862 // An export-declaration shall appear only [...] in the purview of a module
864 // indirectly within [...] a private-module-fragment.
877 } else if (ModuleScopes.back().Module->Kind ==
878 Module::PrivateModuleFragment) {
948 // C++20 [module.interface]p3:
963 // C++2a [module.interface]p5:
969 if (Lk == Linkage::Internal || Lk == Linkage::Module) {
1014 // If an inline function or variable that is attached to a named module
1026 // Anything exported from a module should never be considered unused.
1033 Module *Sema::PushGlobalModuleFragment(SourceLocation BeginLoc) {
1034 // We shouldn't create new global module fragment if there is already
1042 assert(TheGlobalModuleFragment && "module creation should not fail");
1044 // Enter the scope of the global module.
1055 "left the wrong module scope, which is not global module fragment");
1059 Module *Sema::PushImplicitGlobalModuleFragment(SourceLocation BeginLoc) {
1066 assert(TheImplicitGlobalModuleFragment && "module creation should not fail");
1068 // Enter the scope of the global module.
1078 "left the wrong module scope, which is not global module fragment");
1086 /// Does this Module scope describe part of the purview of a standard named
1087 /// C++ module?
1089 case Module::ModuleInterfaceUnit:
1090 case Module::ModuleImplementationUnit:
1091 case Module::ModulePartitionInterface:
1092 case Module::ModulePartitionImplementation:
1093 case Module::PrivateModuleFragment:
1094 case Module::ImplicitGlobalModuleFragment: