Lines Matching full:module

10 // of a module as it relates to headers.
20 #include "clang/Basic/Module.h"
58 void ModuleMap::resolveLinkAsDependencies(Module *Mod) {
69 void ModuleMap::addLinkAsDependency(Module *Mod) {
76 Module::HeaderKind ModuleMap::headerRoleToKind(ModuleHeaderRole Role) {
79 return Module::HK_Normal;
81 return Module::HK_Private;
83 return Module::HK_Textual;
85 return Module::HK_PrivateTextual;
87 return Module::HK_Excluded;
93 ModuleMap::headerKindToRole(Module::HeaderKind Kind) {
95 case Module::HK_Normal:
97 case Module::HK_Private:
99 case Module::HK_Textual:
101 case Module::HK_PrivateTextual:
103 case Module::HK_Excluded:
113 Module::ExportDecl
114 ModuleMap::resolveExport(Module *Mod,
115 const Module::UnresolvedExportDecl &Unresolved,
120 return Module::ExportDecl(nullptr, true);
123 // Resolve the module-id.
124 Module *Context = resolveModuleId(Unresolved.Id, Mod, Complain);
128 return Module::ExportDecl(Context, Unresolved.Wildcard);
131 Module *ModuleMap::resolveModuleId(const ModuleId &Id, Module *Mod,
133 // Find the starting module.
134 Module *Context = lookupModuleUnqualified(Id[0].first, Mod);
143 // Dig into the module path.
145 Module *Sub = lookupModuleQualified(Id[I].first, Context);
162 /// subframework in which the given module lives.
163 static void appendSubframeworkPaths(Module *Mod,
165 // Collect the framework names from the given module to the top-level module.
181 Module *M, const Module::UnresolvedHeaderDirective &Header,
183 // Search for the header file within the module's home directory.
209 // be defined as 'module FrameworkName.Private', and not as
210 // 'framework module FrameworkName.Private', since a 'Private.Framework'
239 // The lack of 'framework' keyword in a module declaration it's a simple
275 /// Determine whether the given module name is the name of a builtin
276 /// module that is cyclic with a system module on some platforms.
295 void ModuleMap::resolveHeader(Module *Mod,
296 const Module::UnresolvedHeaderDirective &Header,
303 if (Module *UmbrellaMod = UmbrellaDirs[UmbrellaDir])
311 Module::Header H = {Header.FileName, std::string(RelativePathName),
318 } else if (Header.Kind == Module::HK_Excluded) {
321 // If we find a module that has a missing header, we mark this module as
324 // A missing header with stat information doesn't make the module
326 // resolved. (Such a module still can't be built though, except from
334 Module *Mod, const Module::UnresolvedHeaderDirective &Header) {
335 if (Header.Kind == Module::HK_Excluded ||
342 // This is a system module with a top-level header. This header
351 Module::Header H = {Header.FileName, Header.FileName, *File};
421 Module *Module) const {
423 Module->IsSystem && !Module->isPartOfFramework() &&
471 static bool violatesPrivateInclude(Module *RequestingModule,
476 // Check for consistency between the module header role
477 // as obtained from the lookup and as obtained from the module.
480 SmallVectorImpl<Module::Header> *HeaderList[] = {
481 &Header.getModule()->Headers[Module::HK_Private],
482 &Header.getModule()->Headers[Module::HK_PrivateTextual]};
485 *Hs, [&](const Module::Header &H) { return H.Entry == IncFileEnt; });
492 static Module *getTopLevelOrNull(Module *M) {
496 void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
511 Module *Private = nullptr;
512 Module *NotUsed = nullptr;
517 // Excluded headers don't really belong to a module.
530 // modules that are explicitly used by the requesting module.
537 // We have found a module that we can happily use.
551 // We have found a module, but we don't use it.
569 // Do not diagnose when we are not compiling a module.
581 // FIXME: Considering whether the module is available rather than merely
620 // Cannot use a module if the header is excluded in it.
623 // Prefer a header from the source module over all others.
637 assert(!Headers.count(File) && "already have a module for this header");
642 Module *Result = H.getModule();
644 // Search up the module stack until we find a module with an umbrella
646 Module *UmbrellaModule = Result;
659 // Find or create the module that corresponds to this directory name.
668 // Associate the module and the directory.
674 Result->Exports.push_back(Module::ExportDecl(nullptr, true));
690 Result->Exports.push_back(Module::ExportDecl(nullptr, true));
693 // the module we found, since the umbrella header covers them all.
733 FileEntryRef Header, const Module *RequestingModule) const {
748 // When no requesting module is available, the caller is looking if a
749 // header is part a module by only looking into the module map. This is
765 auto IsUnavailable = [&](const Module *M) {
775 Module *Found = KnownDir->second;
779 // Search up the module stack until we find a module with an umbrella
781 Module *UmbrellaModule = Found;
788 // Find or create the module that corresponds to this directory name.
826 Module *ModuleMap::findModule(StringRef Name) const {
827 llvm::StringMap<Module *>::const_iterator Known = Modules.find(Name);
834 Module *ModuleMap::lookupModuleUnqualified(StringRef Name,
835 Module *Context) const {
837 if (Module *Sub = lookupModuleQualified(Name, Context))
844 Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) const{
851 std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name,
852 Module *Parent,
855 // Try to find an existing module with this name.
856 if (Module *Sub = lookupModuleQualified(Name, Parent))
859 // Create a new module with this name.
860 Module *Result = new Module(Name, SourceLocation(), Parent, IsFramework,
871 Module *ModuleMap::createGlobalModuleFragmentForModuleUnit(SourceLocation Loc,
872 Module *Parent) {
873 auto *Result = new Module("<global>", Loc, Parent, /*IsFramework*/ false,
875 Result->Kind = Module::ExplicitGlobalModuleFragment;
876 // If the created module isn't owned by a parent, send it to PendingSubmodules
883 Module *
885 Module *Parent) {
886 assert(Parent && "We should only create an implicit global module fragment "
887 "in a module purview");
892 new Module("<implicit global>", Loc, Parent, /*IsFramework=*/false,
894 Result->Kind = Module::ImplicitGlobalModuleFragment;
898 Module *
899 ModuleMap::createPrivateModuleFragmentForInterfaceUnit(Module *Parent,
902 new Module("<private>", Loc, Parent, /*IsFramework*/ false,
904 Result->Kind = Module::PrivateModuleFragment;
908 Module *ModuleMap::createModuleUnitWithKind(SourceLocation Loc, StringRef Name,
909 Module::ModuleKind Kind) {
911 new Module(Name, Loc, nullptr, /*IsFramework*/ false,
915 // Reparent any current global module fragment as a submodule of this module.
924 Module *ModuleMap::createModuleForInterfaceUnit(SourceLocation Loc,
926 assert(LangOpts.CurrentModule == Name && "module name mismatch");
927 assert(!Modules[Name] && "redefining existing module");
930 createModuleUnitWithKind(Loc, Name, Module::ModuleInterfaceUnit);
933 // Mark the main source file as being within the newly-created module so that
936 assert(MainFile && "no input file for module interface");
942 Module *ModuleMap::createModuleForImplementationUnit(SourceLocation Loc,
944 assert(LangOpts.CurrentModule == Name && "module name mismatch");
946 assert(Modules[Name] && Modules[Name]->Kind == Module::ModuleInterfaceUnit &&
947 "creating implementation module without an interface");
949 // Create an entry in the modules map to own the implementation unit module.
950 // User module names must not start with a period (so that this cannot clash
951 // with any legal user-defined module name).
956 createModuleUnitWithKind(Loc, Name, Module::ModuleImplementationUnit);
961 "no input file for module implementation");
966 Module *ModuleMap::createHeaderUnit(SourceLocation Loc, StringRef Name,
967 Module::Header H) {
968 assert(LangOpts.CurrentModule == Name && "module name mismatch");
969 assert(!Modules[Name] && "redefining existing module");
971 auto *Result = new Module(Name, Loc, nullptr, /*IsFramework*/ false,
973 Result->Kind = Module::ModuleHeaderUnit;
979 /// For a framework module, infer the framework against which we
981 static void inferFrameworkLink(Module *Mod) {
988 Mod->LinkLibraries.push_back(Module::LinkLibrary(FrameworkName.str(),
992 Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir,
993 bool IsSystem, Module *Parent) {
999 Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir,
1000 Attributes Attrs, Module *Parent) {
1015 // Check whether we've already found this module.
1016 if (Module *Mod = lookupModuleQualified(ModuleName, Parent))
1022 // a framework module, do so.
1025 // Determine whether we're allowed to infer a module map.
1032 // for a module map.
1036 // We haven't looked here before. Load a module map, if there is
1052 // to infer this particular module.
1067 // If we're not allowed to infer a framework module, don't.
1085 Module *Result = new Module(ModuleName, SourceLocation(), Parent,
1113 Result->Exports.push_back(Module::ExportDecl(nullptr, true));
1115 // module * { export * }
1163 // If the module is a top-level framework, automatically link against the
1171 Module *ModuleMap::createShadowedModule(StringRef Name, bool IsFramework,
1172 Module *ShadowingModule) {
1174 // Create a new module with this name.
1175 Module *Result =
1176 new Module(Name, SourceLocation(), /*Parent=*/nullptr, IsFramework,
1187 Module *Mod, FileEntryRef UmbrellaHeader, const Twine &NameAsWritten,
1202 Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine &NameAsWritten,
1211 void ModuleMap::addUnresolvedHeader(Module *Mod,
1212 Module::UnresolvedHeaderDirective Header,
1231 Header.Kind != Module::HK_Excluded) {
1264 Module *Mod, std::optional<const FileEntry *> File) const {
1266 SmallVector<Module::UnresolvedHeaderDirective, 1> NewHeaders;
1282 void ModuleMap::addHeader(Module *Mod, Module::Header Header,
1288 // same module definition?
1309 FileID ModuleMap::getContainingModuleMapFileID(const Module *Module) const {
1310 if (Module->DefinitionLoc.isInvalid())
1313 return SourceMgr.getFileID(Module->DefinitionLoc);
1317 ModuleMap::getContainingModuleMapFile(const Module *Module) const {
1318 return SourceMgr.getFileEntryRefForID(getContainingModuleMapFileID(Module));
1321 FileID ModuleMap::getModuleMapFileIDForUniquing(const Module *M) const {
1323 assert(InferredModuleAllowedBy.count(M) && "missing inferred module map");
1330 ModuleMap::getModuleMapFileForUniquing(const Module *M) const {
1334 void ModuleMap::setInferredModuleAllowedBy(Module *M, FileID ModMapFID) {
1335 assert(M->IsInferred && "module not inferred");
1343 // Do not canonicalize within the framework; the module map parser expects
1372 void ModuleMap::addAdditionalModuleMapFile(const Module *M,
1379 for (llvm::StringMap<Module *>::iterator M = Modules.begin(),
1399 bool ModuleMap::resolveExports(Module *Mod, bool Complain) {
1403 Module::ExportDecl Export = resolveExport(Mod, UE, Complain);
1412 bool ModuleMap::resolveUses(Module *Mod, bool Complain) {
1417 Module *DirectUse = resolveModuleId(UDU, Top, Complain);
1426 bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
1430 if (Module *OtherMod = resolveModuleId(UC.Id, Mod, Complain)) {
1431 Module::Conflict Conflict;
1442 // Module map file parser
1447 /// A token in a module map file.
1524 /// The current module map file.
1527 /// Source location of most recent parsed module declaration
1530 /// The directory that file names in this module map file should
1534 /// Whether this module map is in a system header directory.
1547 /// The active module.
1548 Module *ActiveModule = nullptr;
1550 /// Whether a module uses the 'requires excluded' hack to mark its
1558 llvm::SmallPtrSet<Module *, 2> UsesRequiresExcludedHack;
1582 /// module map search logic to find the appropriate private module when PCH
1583 /// is used with implicit module maps. Warn when private modules are written
1635 .Case("module", MMToken::ModuleKeyword)
1730 // A module map can be terminated prematurely by
1731 // #pragma clang module contents
1732 // When building the module, we'll treat the rest of the file as the
1733 // contents of the module.
1741 NextIsIdent("module") && NextIsIdent("contents")) {
1803 /// Parse a module-id.
1805 /// module-id:
1807 /// identifier '.' module-id
1854 /// module map search logic to find the appropriate private module when PCH
1855 /// is used with implicit module maps. Warn when private modules are written
1860 const Module *M, SourceRange ReplLoc) {
1894 FixedPrivModDecl.append("module ");
1914 /// Parse a module declaration.
1916 /// module-declaration:
1917 /// 'extern' 'module' module-id string-literal
1918 /// 'explicit'[opt] 'framework'[opt] 'module' module-id attributes[opt]
1919 /// { module-member* }
1921 /// module-member:
1930 /// module-declaration
1958 // Parse 'module' keyword.
1965 CurrModuleDeclLoc = consumeToken(); // 'module' keyword
1967 // If we have a wildcard for the module name, this is an inferred submodule.
1972 // Parse the module name.
1995 Module *PreviousActiveModule = ActiveModule;
1997 // This module map defines a submodule. Go find the module of which it
2000 const Module *TopLevelModule = nullptr;
2002 if (Module *Next = Map.lookupModuleQualified(Id[I].first, ActiveModule)) {
2021 "submodule defined in same file as 'module *' that allowed its "
2022 "top-level module");
2045 // Determine whether this (sub)module has already been defined.
2046 Module *ShadowingModule = nullptr;
2047 if (Module *Existing = Map.lookupModuleQualified(ModuleName, ActiveModule)) {
2048 // We might see a (re)definition of a module that we already have a
2051 // corresponding definition in a module map file, or
2053 // - If we previously inferred this module from different module map file.
2055 // - If we're building a framework that vends a module map, we might've
2058 // FIXME: If we're parsing module map file that looks like this:
2059 // framework module FW { ... }
2060 // module FW.Sub { ... }
2064 // module FW { ... }
2065 // module FW.Sub { ... }
2071 // - If we're building a (preprocessed) module and we've just loaded the
2072 // module map file from which it was created.
2080 // Skip the module definition.
2095 // This is not a shawdowed module decl, it is an illegal redefinition.
2100 // Skip the module definition.
2110 // Start defining this module.
2131 if (MapFileName.ends_with("module.private.modulemap") ||
2232 // If the active module is a top-level framework, and there are no link
2238 // If the module meets all requirements but is still unavailable, mark the
2247 // We're done parsing this module. Pop back to the previous module.
2251 /// Parse an extern module declaration.
2253 /// extern module-declaration:
2254 /// 'extern' 'module' module-id string-literal
2259 // Parse 'module' keyword.
2266 consumeToken(); // 'module' keyword
2268 // Parse the module name.
2275 // Parse the referenced module map file name.
2300 /// Whether to add the requirement \p Feature to the module \p M.
2303 /// module map files:
2309 /// module to 'textual'.
2315 static bool shouldAddRequirement(Module *M, StringRef Feature,
2415 // Module::UsesRequiresExcludedHack).
2437 Module::UnresolvedHeaderDirective Header;
2510 // always had its own module.
2519 << FixItHint::CreateReplacement(CurrModuleDeclLoc, "framework module");
2522 static bool compareModuleHeaders(const Module::Header &A,
2523 const Module::Header &B) {
2573 // uncommonly used Tcl module on Darwin platforms.
2575 SmallVector<Module::Header, 6> Headers;
2581 Module::Header Header = {"", std::string(I->path()), *FE};
2594 if (Module *OwningModule = Map.UmbrellaDirs[*Dir]) {
2605 /// Parse a module export declaration.
2608 /// 'export' wildcard-module-id
2610 /// wildcard-module-id:
2613 /// identifier '.' wildcard-module-id
2618 // Parse the module-id with an optional wildcard at the end.
2622 // FIXME: Support string-literal module names here.
2647 Module::UnresolvedExportDecl Unresolved = {
2653 /// Parse a module export_as declaration.
2690 /// Parse a module use declaration.
2693 /// 'use' wildcard-module-id
2697 // Parse the module-id.
2709 /// module-declaration:
2732 ActiveModule->LinkLibraries.push_back(Module::LinkLibrary(LibraryName,
2738 /// module-declaration:
2793 /// Format a module-id into a string.
2811 /// module-declaration:
2812 /// 'conflict' module-id ',' string-literal
2816 Module::UnresolvedConflict Conflict;
2818 // Parse the module-id.
2843 /// Parse an inferred module declaration (wildcard modules).
2845 /// module-declaration:
2846 /// 'explicit'[opt] 'framework'[opt] 'module' * attributes[opt]
2847 /// { inferred-module-member* }
2849 /// inferred-module-member:
2871 // Check for redefinition of an inferred module.
2946 // FIXME: Support string-literal module names here.
3071 /// Parse a module map file.
3073 /// module-map-file:
3074 /// module-declaration*
3129 // If the module map file wasn't already entered, do so now.
3143 // Parse this module map file.