Lines Matching +full:sub +full:- +full:modules

1 //===- ModuleMap.cpp - Describe the layout of modules ---------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
59 auto PendingLinkAs = PendingLinkAsModule.find(Mod->Name);
61 for (auto &Name : PendingLinkAs->second) {
64 M->UseExportAsModuleLinkName = true;
70 if (findModule(Mod->ExportAsModule))
71 Mod->UseExportAsModuleLinkName = true;
73 PendingLinkAsModule[Mod->ExportAsModule].insert(Mod->Name);
123 // Resolve the module-id.
138 << Id[0].first << Mod->getFullModuleName();
145 Module *Sub = lookupModuleQualified(Id[I].first, Context);
146 if (!Sub) {
149 << Id[I].first << Context->getFullModuleName()
150 << SourceRange(Id[0].second, Id[I-1].second);
155 Context = Sub;
165 // Collect the framework names from the given module to the top-level module.
167 for (; Mod; Mod = Mod->Parent) {
168 if (Mod->IsFramework)
169 Paths.push_back(Mod->Name);
184 auto Directory = M->Directory;
185 SmallString<128> FullPathName(Directory->getName());
187 auto GetFile = [&](StringRef Filename) -> OptionalFileEntryRef {
190 if (!File || (Header.Size && File->getSize() != *Header.Size) ||
191 (Header.ModTime && File->getModificationTime() != *Header.ModTime))
196 auto GetFrameworkFile = [&]() -> OptionalFileEntryRef {
208 // Ideally, private modules in the form 'FrameworkName.Private' should
212 // for private modules, make sure we find the right path in both cases.
213 if (M->IsFramework && M->Name == "Private")
230 if (M->isPartOfFramework())
238 if (!NormalHdrFile && Directory->getName().ends_with(".framework")) {
242 FullPathName.assign(Directory->getName());
247 << Header.FileName << M->getFullModuleName();
302 const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry();
305 << UmbrellaMod->getFullModuleName();
316 // There's a builtin header but no corresponding on-disk header. Assume
323 Mod->MissingHeaders.push_back(Header);
329 Mod->markUnavailable(/*Unimportable=*/false);
337 Mod->isPartOfFramework() || !Mod->IsSystem || Header.IsUmbrella ||
338 !BuiltinIncludeDir || BuiltinIncludeDir == Mod->Directory ||
342 // This is a system module with a top-level header. This header
346 llvm::sys::path::append(Path, BuiltinIncludeDir->getName(), Header.FileName);
366 for (auto &M : Modules)
373 assert((!this->Target || this->Target == &Target) &&
375 this->Target = &Target;
423 Module->IsSystem && !Module->isPartOfFramework() &&
446 // frameworks moving from top-level frameworks to embedded frameworks tend
447 // to be symlinked from the top-level location to the embedded location,
456 return KnownHeader(KnownDir->second, NormalHeader);
481 &Header.getModule()->Headers[Module::HK_Private],
482 &Header.getModule()->Headers[Module::HK_PrivateTextual]};
493 return M ? M->getTopLevelModule() : nullptr;
500 // No errors for indirect modules. This may be a bit of a problem for modules
516 for (const KnownHeader &Header : Known->second) {
530 // modules that are explicitly used by the requesting module.
532 !RequestingModule->directlyUses(Header.getModule())) {
554 << RequestingModule->getTopLevelModule()->Name << Filename
555 << NotUsed->Name;
562 // At this point, only non-modular includes remain.
566 << RequestingModule->getTopLevelModule()->Name << Filename;
570 diag::kind DiagID = RequestingModule->getTopLevelModule()->IsFramework ?
573 Diags.Report(FilenameLoc, DiagID) << RequestingModule->getFullModuleName()
580 // Prefer available modules.
582 // importable is non-hermetic and can result in surprising behavior for
583 // prebuilt modules. Consider only checking for importability here.
584 if (New.getModule()->isAvailable() && !Old.getModule()->isAvailable())
592 // Prefer a non-textual header over a textual header.
597 // Prefer a non-excluded header over an excluded header.
609 auto MakeResult = [&](ModuleMap::KnownHeader R) -> ModuleMap::KnownHeader {
618 // Iterate over all modules that 'File' is part of to find the best fit.
619 for (KnownHeader &H : Known->second) {
624 if (H.getModule()->getTopLevelModule() == SourceModule)
647 while (!UmbrellaModule->getEffectiveUmbrellaDir() && UmbrellaModule->Parent)
648 UmbrellaModule = UmbrellaModule->Parent;
650 if (UmbrellaModule->InferSubmodules) {
656 bool Explicit = UmbrellaModule->InferExplicitSubmodules;
666 Result->IsInferred = true;
673 if (UmbrellaModule->InferExportWildcard && Result->Exports.empty())
674 Result->Exports.push_back(Module::ExportDecl(nullptr, true));
684 Result->IsInferred = true;
685 Result->addTopHeader(File);
689 if (UmbrellaModule->InferExportWildcard && Result->Exports.empty())
690 Result->Exports.push_back(Module::ExportDecl(nullptr, true));
710 return Known->second;
713 return Headers.find(File)->second;
725 return It->second;
738 I = Known->second.begin(),
739 E = Known->second.end();
742 if (I->getRole() == ModuleMap::ExcludedHeader)
745 if (I->isAvailable() &&
747 I->getModule()->isSubModuleOf(RequestingModule))) {
753 if (!RequestingModule && I->getRole() == ModuleMap::TextualHeader)
763 StringRef DirName = Dir->getName();
766 return !M->isAvailable() && (!RequestingModule ||
767 M->isSubModuleOf(RequestingModule));
775 Module *Found = KnownDir->second;
782 while (!UmbrellaModule->getEffectiveUmbrellaDir() &&
783 UmbrellaModule->Parent)
784 UmbrellaModule = UmbrellaModule->Parent;
786 if (UmbrellaModule->InferSubmodules) {
827 llvm::StringMap<Module *>::const_iterator Known = Modules.find(Name);
828 if (Known != Modules.end())
829 return Known->getValue();
836 for(; Context; Context = Context->Parent) {
837 if (Module *Sub = lookupModuleQualified(Name, Context))
838 return Sub;
848 return Context->findSubmodule(Name);
856 if (Module *Sub = lookupModuleQualified(Name, Parent))
857 return std::make_pair(Sub, false);
865 Modules[Name] = Result;
875 Result->Kind = Module::ExplicitGlobalModuleFragment;
878 if (!Result->Parent)
889 // modules. All the non-explicit submodules in clang modules will be exported
894 Result->Kind = Module::ImplicitGlobalModuleFragment;
904 Result->Kind = Module::PrivateModuleFragment;
913 Result->Kind = Kind;
917 Submodule->setParent(Result);
927 assert(!Modules[Name] && "redefining existing module");
931 Modules[Name] = SourceModule = Result;
933 // Mark the main source file as being within the newly-created module so that
934 // declarations and macros are properly visibility-restricted to it.
946 assert(Modules[Name] && Modules[Name]->Kind == Module::ModuleInterfaceUnit &&
949 // Create an entry in the modules map to own the implementation unit module.
951 // with any legal user-defined module name).
953 assert(!Modules[IName] && "multiple implementation units?");
957 Modules[IName] = SourceModule = Result;
969 assert(!Modules[Name] && "redefining existing module");
973 Result->Kind = Module::ModuleHeaderUnit;
974 Modules[Name] = SourceModule = Result;
982 assert(Mod->IsFramework && "Can only infer linking for framework modules");
983 assert(!Mod->isSubFramework() &&
984 "Can only infer linking for top-level frameworks");
986 StringRef FrameworkName(Mod->Name);
988 Mod->LinkLibraries.push_back(Module::LinkLibrary(FrameworkName.str(),
1003 // top-level framework, and we need to infer as if we were naming the
1004 // top-level framework.
1008 // In case this is a case-insensitive filesystem, use the canonical
1009 // directory name as the ModuleName, since modules are case-sensitive.
1010 // FIXME: we should be able to give a fix-it hint for the correct spelling.
1050 if (inferred->second.InferModules) {
1055 !llvm::is_contained(inferred->second.ExcludedModules, Name);
1057 Attrs.IsSystem |= inferred->second.Attrs.IsSystem;
1058 Attrs.IsExternC |= inferred->second.Attrs.IsExternC;
1059 Attrs.IsExhaustive |= inferred->second.Attrs.IsExhaustive;
1061 inferred->second.Attrs.NoUndeclaredIncludes;
1062 ModuleMapFID = inferred->second.ModuleMapFID;
1089 Result->IsInferred = true;
1093 Modules[ModuleName] = Result;
1097 Result->IsSystem |= Attrs.IsSystem;
1098 Result->IsExternC |= Attrs.IsExternC;
1099 Result->ConfigMacrosExhaustive |= Attrs.IsExhaustive;
1100 Result->NoUndeclaredIncludes |= Attrs.NoUndeclaredIncludes;
1101 Result->Directory = FrameworkDir;
1105 Result->getTopLevelModule()->Directory->getName().size());
1108 // umbrella header "umbrella-header-name"
1113 Result->Exports.push_back(Module::ExportDecl(nullptr, true));
1116 Result->InferSubmodules = true;
1117 Result->InferExportWildcard = true;
1129 if (!StringRef(Dir->path()).ends_with(".framework"))
1132 if (auto SubframeworkDir = FileMgr.getOptionalDirectoryRef(Dir->path())) {
1136 // out to a top-level framework.
1163 // If the module is a top-level framework, automatically link against the
1165 if (!Result->isSubFramework())
1178 Result->ShadowingModule = ShadowingModule;
1179 Result->markUnavailable(/*Unimportable*/true);
1190 Mod->Umbrella = UmbrellaHeader;
1191 Mod->UmbrellaAsWritten = NameAsWritten.str();
1192 Mod->UmbrellaRelativeToRootModuleDirectory =
1198 Cb->moduleMapAddUmbrellaHeader(UmbrellaHeader);
1204 Mod->Umbrella = UmbrellaDir;
1205 Mod->UmbrellaAsWritten = NameAsWritten.str();
1206 Mod->UmbrellaRelativeToRootModuleDirectory =
1238 Mod->UnresolvedHeaders.push_back(Header);
1248 auto BySize = LazyHeadersBySize.find(File->getSize());
1250 for (auto *M : BySize->second)
1255 auto ByModTime = LazyHeadersByModTime.find(File->getModificationTime());
1257 for (auto *M : ByModTime->second)
1267 const auto Size = File ? (*File)->getSize() : 0;
1268 const auto ModTime = File ? (*File)->getModificationTime() : 0;
1270 for (auto &Header : Mod->UnresolvedHeaders) {
1277 const_cast<ModuleMap *>(this)->resolveHeader(Mod, Header, NeedsFramework);
1279 Mod->UnresolvedHeaders.swap(NewHeaders);
1294 Mod->Headers[headerRoleToKind(Role)].push_back(Header);
1296 bool isCompilingModuleHeader = Mod->isForBuilding(LangOpts);
1306 Cb->moduleMapAddHeader(Header.Entry.getName());
1310 if (Module->DefinitionLoc.isInvalid())
1313 return SourceMgr.getFileID(Module->DefinitionLoc);
1322 if (M->IsInferred) {
1324 return InferredModuleAllowedBy.find(M)->second;
1335 assert(M->IsInferred && "module not inferred");
1344 // Modules/ not Versions/A/Modules.
1345 if (llvm::sys::path::filename(Dir) == "Modules") {
1362 // on a case-insensitive filesystem. However, the extra canonicalization is
1378 llvm::errs() << "Modules:";
1379 for (llvm::StringMap<Module *>::iterator M = Modules.begin(),
1380 MEnd = Modules.end();
1382 M->getValue()->print(llvm::errs(), 2);
1387 llvm::errs() << " \"" << H->first.getName() << "\" -> ";
1388 for (SmallVectorImpl<KnownHeader>::const_iterator I = H->second.begin(),
1389 E = H->second.end();
1391 if (I != H->second.begin())
1393 llvm::errs() << I->getModule()->getFullModuleName();
1400 auto Unresolved = std::move(Mod->UnresolvedExports);
1401 Mod->UnresolvedExports.clear();
1405 Mod->Exports.push_back(Export);
1407 Mod->UnresolvedExports.push_back(UE);
1409 return !Mod->UnresolvedExports.empty();
1413 auto *Top = Mod->getTopLevelModule();
1414 auto Unresolved = std::move(Top->UnresolvedDirectUses);
1415 Top->UnresolvedDirectUses.clear();
1419 Top->DirectUses.push_back(DirectUse);
1421 Top->UnresolvedDirectUses.push_back(UDU);
1423 return !Top->UnresolvedDirectUses.empty();
1427 auto Unresolved = std::move(Mod->UnresolvedConflicts);
1428 Mod->UnresolvedConflicts.clear();
1434 Mod->Conflicts.push_back(Conflict);
1436 Mod->UnresolvedConflicts.push_back(UC);
1438 return !Mod->UnresolvedConflicts.empty();
1441 //----------------------------------------------------------------------------//
1443 //----------------------------------------------------------------------------//
1554 /// contents of the Darwin.C.excluded (assert.h) and Tcl.Private modules as
1555 /// non-modular headers. For backwards compatibility, we continue to
1556 /// support this idiom for just these modules, and map the headers to
1581 /// Private modules are canonicalized as Foo_Private. Clang provides extra
1583 /// is used with implicit module maps. Warn when private modules are written
1735 auto NextIsIdent = [&](StringRef Str) -> bool {
1781 --braceDepth;
1788 --squareDepth;
1803 /// Parse a module-id.
1805 /// module-id:
1807 /// identifier '.' module-id
1853 /// Private modules are canonicalized as Foo_Private. Clang provides extra
1855 /// is used with implicit module maps. Warn when private modules are written
1861 auto D = Diags.Report(ActiveModule->DefinitionLoc,
1863 D << BadName << M->Name;
1868 auto const *M = E->getValue();
1869 if (M->Directory != ActiveModule->Directory)
1872 SmallString<128> FullName(ActiveModule->getFullModuleName());
1873 if (!FullName.starts_with(M->Name) && !FullName.ends_with("Private"))
1876 SmallString<128> Canonical(M->Name);
1879 // Foo.Private -> Foo_Private
1880 if (ActiveModule->Parent && ActiveModule->Name == "Private" && !M->Parent &&
1881 M->Name == ActiveModule->Parent->Name) {
1882 Diags.Report(ActiveModule->DefinitionLoc,
1892 if (FrameworkLoc.isValid() || ActiveModule->Parent->IsFramework)
1898 SourceRange(FixItInitBegin, ActiveModule->DefinitionLoc));
1902 // FooPrivate and whatnots -> Foo_Private
1903 if (!ActiveModule->Parent && !M->Parent && M->Name != ActiveModule->Name &&
1904 ActiveModule->Name != Canonical) {
1905 Diags.Report(ActiveModule->DefinitionLoc,
1907 << ActiveModule->Name;
1908 GenNoteAndFixIt(ActiveModule->Name, Canonical, M,
1909 SourceRange(ActiveModule->DefinitionLoc));
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:
1922 /// requires-declaration
1923 /// header-declaration
1924 /// submodule-declaration
1925 /// export-declaration
1926 /// export-as-declaration
1927 /// link-declaration
1929 /// submodule-declaration:
1930 /// module-declaration
1931 /// inferred-submodule-declaration
1988 // Top-level modules can't be explicit.
2001 for (unsigned I = 0, N = Id.size() - 1; I != N; ++I) {
2012 ? ActiveModule->getTopLevelModule()->getFullModuleName()
2022 "top-level module");
2045 // Determine whether this (sub)module has already been defined.
2050 // - If we loaded one definition from an AST file and we've just found a
2052 bool LoadedFromASTFile = Existing->IsFromModuleFile;
2053 // - If we previously inferred this module from different module map file.
2054 bool Inferred = Existing->IsInferred;
2055 // - If we're building a framework that vends a module map, we might've
2060 // module FW.Sub { ... }
2062 // the definition of Sub. Checking that qualifier on \c Existing is
2065 // module FW.Sub { ... }
2070 bool PartOfFramework = Framework || Existing->isPartOfFramework();
2071 // - If we're building a (preprocessed) module and we've just loaded the
2077 SourceMgr.getDecomposedLoc(Existing->DefinitionLoc).first;
2092 if (!Existing->Parent && Map.mayShadowNewModule(Existing)) {
2098 Diags.Report(Existing->DefinitionLoc, diag::note_mmap_prev_definition);
2120 ActiveModule->DefinitionLoc = ModuleNameLoc;
2122 ActiveModule->IsSystem = true;
2124 ActiveModule->IsExternC = true;
2126 ActiveModule->NoUndeclaredIncludes = true;
2127 ActiveModule->Directory = Directory;
2130 SourceMgr.getFileEntryRefForID(ModuleMapFID)->getName());
2133 ActiveModule->ModuleMapIsPrivate = true;
2136 // Private modules named as FooPrivate, Foo.Private or similar are likely a
2146 ActiveModule->ModuleMapIsPrivate)
2232 // If the active module is a top-level framework, and there are no link
2234 if (ActiveModule->IsFramework && !ActiveModule->isSubFramework() &&
2235 ActiveModule->LinkLibraries.empty())
2240 if (!ActiveModule->IsAvailable && !ActiveModule->IsUnimportable &&
2241 ActiveModule->Parent) {
2242 ActiveModule->getTopLevelModule()->markUnavailable(/*Unimportable=*/false);
2243 ActiveModule->getTopLevelModule()->MissingHeaders.append(
2244 ActiveModule->MissingHeaders.begin(), ActiveModule->MissingHeaders.end());
2253 /// extern module-declaration:
2254 /// 'extern' 'module' module-id string-literal
2296 : File->getDir(),
2305 /// 1. The use of 'requires excluded' to make headers non-modular, which
2318 (M->fullModuleNameIs({"Darwin", "C", "excluded"}) ||
2319 M->fullModuleNameIs({"Tcl", "Private"}))) {
2322 } else if (Feature == "cplusplus" && M->fullModuleNameIs({"IOKit", "avc"})) {
2331 /// requires-declaration:
2332 /// 'requires' feature-list
2334 /// feature-list:
2335 /// feature ',' feature-list
2346 // Parse the feature-list.
2373 ActiveModule->addRequirement(Feature, RequiredState, Map.LangOpts,
2387 /// header-declaration:
2388 /// 'textual'[opt] 'header' string-literal
2389 /// 'private' 'textual'[opt] 'header' string-literal
2390 /// 'exclude' 'header' string-literal
2391 /// 'umbrella' 'header' string-literal
2445 !std::holds_alternative<std::monostate>(ActiveModule->Umbrella)) {
2447 << ActiveModule->getFullModuleName();
2508 // Don't add headers to the builtin modules if the builtin headers belong to
2509 // the system modules, with the exception of __stddef_max_align_t.h which
2512 !isBuiltInModuleName(ActiveModule->getTopLevelModuleName()) ||
2513 ActiveModule->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}))
2518 << ActiveModule->getFullModuleName()
2529 /// umbrella-dir-declaration:
2530 /// umbrella string-literal
2545 if (!std::holds_alternative<std::monostate>(ActiveModule->Umbrella)) {
2547 << ActiveModule->getFullModuleName();
2578 for (llvm::vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E;
2580 if (auto FE = SourceMgr.getFileManager().getOptionalFileRef(I->path())) {
2581 Module::Header Header = {"", std::string(I->path()), *FE};
2596 << OwningModule->getFullModuleName();
2607 /// 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.
2650 ActiveModule->UnresolvedExports.push_back(Unresolved);
2655 /// export-as-declaration:
2667 if (ActiveModule->Parent) {
2673 if (!ActiveModule->ExportAsModule.empty()) {
2674 if (ActiveModule->ExportAsModule == Tok.getString()) {
2676 << ActiveModule->Name << Tok.getString();
2679 << ActiveModule->Name << ActiveModule->ExportAsModule
2684 ActiveModule->ExportAsModule = std::string(Tok.getString());
2692 /// use-declaration:
2693 /// 'use' wildcard-module-id
2697 // Parse the module-id.
2701 if (ActiveModule->Parent)
2704 ActiveModule->UnresolvedDirectUses.push_back(ParsedModuleId);
2709 /// module-declaration:
2710 /// 'link' 'framework'[opt] string-literal
2732 ActiveModule->LinkLibraries.push_back(Module::LinkLibrary(LibraryName,
2738 /// module-declaration:
2739 /// 'config_macros' attributes[opt] config-macro-list?
2741 /// config-macro-list:
2747 // Only top-level modules can have configuration macros.
2748 if (ActiveModule->Parent) {
2757 if (Attrs.IsExhaustive && !ActiveModule->Parent) {
2758 ActiveModule->ConfigMacrosExhaustive = true;
2767 if (!ActiveModule->Parent) {
2768 ActiveModule->ConfigMacros.push_back(Tok.getString().str());
2786 if (!ActiveModule->Parent) {
2787 ActiveModule->ConfigMacros.push_back(Tok.getString().str());
2793 /// Format a module-id into a string.
2811 /// module-declaration:
2812 /// 'conflict' module-id ',' string-literal
2818 // Parse the module-id.
2840 ActiveModule->UnresolvedConflicts.push_back(Conflict);
2843 /// Parse an inferred module declaration (wildcard modules).
2845 /// module-declaration:
2847 /// { inferred-module-member* }
2849 /// inferred-module-member:
2857 // Inferred modules must be submodules.
2864 // Inferred modules must have umbrella directories.
2865 if (!Failed && ActiveModule->IsAvailable &&
2866 !ActiveModule->getEffectiveUmbrellaDir()) {
2872 if (!Failed && ActiveModule->InferSubmodules) {
2874 if (ActiveModule->InferredSubmoduleLoc.isValid())
2875 Diags.Report(ActiveModule->InferredSubmoduleLoc,
2909 ActiveModule->InferSubmodules = true;
2910 ActiveModule->InferredSubmoduleLoc = StarLoc;
2911 ActiveModule->InferExplicitSubmodules = Explicit;
2913 // We'll be inferring framework modules for this directory.
2946 // FIXME: Support string-literal module names here.
2967 ActiveModule->InferExportWildcard = true;
3073 /// module-map-file:
3074 /// module-declaration*
3127 return Known->second;
3140 assert((!Offset || *Offset <= Buffer->getBufferSize()) &&
3145 Buffer->getBufferStart(),
3146 Buffer->getBufferStart() + (Offset ? *Offset : 0),
3147 Buffer->getBufferEnd());
3161 Cb->moduleMapFileRead(Start, File, IsSystem);