Lines Matching full:module

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