Lines Matching +full:target +full:- +full:module

1 //===- Module.cpp - Describe a module -------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the Module class, which describes a module in the source
12 //===----------------------------------------------------------------------===//
14 #include "clang/Basic/Module.h"
37 Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, in Module() function in Module
49 IsAvailable = Parent->isAvailable(); in Module()
50 IsUnimportable = Parent->isUnimportable(); in Module()
51 IsSystem = Parent->IsSystem; in Module()
52 IsExternC = Parent->IsExternC; in Module()
53 NoUndeclaredIncludes = Parent->NoUndeclaredIncludes; in Module()
54 ModuleMapIsPrivate = Parent->ModuleMapIsPrivate; in Module()
56 Parent->SubModuleIndex[Name] = Parent->SubModules.size(); in Module()
57 Parent->SubModules.push_back(this); in Module()
61 Module::~Module() { in ~Module()
67 static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) { in isPlatformEnvironment() argument
68 StringRef Platform = Target.getPlatformName(); in isPlatformEnvironment()
69 StringRef Env = Target.getTriple().getEnvironmentName(); in isPlatformEnvironment()
72 if (Platform == Feature || Target.getTriple().getOSName() == Feature || in isPlatformEnvironment()
77 auto Pos = LHS.find('-'); in isPlatformEnvironment()
85 SmallString<128> PlatformEnv = Target.getTriple().getOSAndEnvironmentName(); in isPlatformEnvironment()
87 // 1. x86_64-apple-ios-simulator in isPlatformEnvironment()
88 // 2. x86_64-apple-iossimulator in isPlatformEnvironment()
92 if (Target.getTriple().isOSDarwin() && PlatformEnv.ends_with("simulator")) in isPlatformEnvironment()
101 const TargetInfo &Target) { in hasFeature() argument
122 .Case("tls", Target.isTLSSupported()) in hasFeature()
124 .Default(Target.hasFeature(Feature) || in hasFeature()
125 isPlatformEnvironment(Target, Feature)); in hasFeature()
131 bool Module::isUnimportable(const LangOptions &LangOpts, in isUnimportable()
132 const TargetInfo &Target, Requirement &Req, in isUnimportable() argument
133 Module *&ShadowingModule) const { in isUnimportable()
137 for (const Module *Current = this; Current; Current = Current->Parent) { in isUnimportable()
138 if (Current->ShadowingModule) { in isUnimportable()
139 ShadowingModule = Current->ShadowingModule; in isUnimportable()
142 for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) { in isUnimportable()
143 if (hasFeature(Current->Requirements[I].FeatureName, LangOpts, Target) != in isUnimportable()
144 Current->Requirements[I].RequiredState) { in isUnimportable()
145 Req = Current->Requirements[I]; in isUnimportable()
151 llvm_unreachable("could not find a reason why module is unimportable"); in isUnimportable()
154 // The -fmodule-name option tells the compiler to textually include headers in
155 // the specified module, meaning Clang won't build the specified module. This
157 // that vends a module map, one might want to avoid hitting intermediate build
158 // products containing the module map or avoid finding the system installed
160 bool Module::isForBuilding(const LangOptions &LangOpts) const { in isForBuilding()
167 if (!LangOpts.isCompilingModule() && getTopLevelModule()->IsFramework && in isForBuilding()
176 bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target, in isAvailable() argument
179 Module *&ShadowingModule) const { in isAvailable()
183 if (isUnimportable(LangOpts, Target, Req, ShadowingModule)) in isAvailable()
186 // FIXME: All missing headers are listed on the top-level module. Should we in isAvailable()
188 for (const Module *Current = this; Current; Current = Current->Parent) { in isAvailable()
189 if (!Current->MissingHeaders.empty()) { in isAvailable()
190 MissingHeader = Current->MissingHeaders.front(); in isAvailable()
195 llvm_unreachable("could not find a reason why module is unavailable"); in isAvailable()
198 bool Module::isSubModuleOf(const Module *Other) const { in isSubModuleOf()
199 for (auto *Parent = this; Parent; Parent = Parent->Parent) { in isSubModuleOf()
206 const Module *Module::getTopLevelModule() const { in getTopLevelModule()
207 const Module *Result = this; in getTopLevelModule()
208 while (Result->Parent) in getTopLevelModule()
209 Result = Result->Parent; in getTopLevelModule()
244 std::string Module::getFullModuleName(bool AllowStringLiterals) const { in getFullModuleName()
247 // Build up the set of module names (from innermost to outermost). in getFullModuleName()
248 for (const Module *M = this; M; M = M->Parent) in getFullModuleName()
249 Names.push_back(M->Name); in getFullModuleName()
260 bool Module::fullModuleNameIs(ArrayRef<StringRef> nameParts) const { in fullModuleNameIs()
261 for (const Module *M = this; M; M = M->Parent) { in fullModuleNameIs()
262 if (nameParts.empty() || M->Name != nameParts.back()) in fullModuleNameIs()
269 OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const { in getEffectiveUmbrellaDir()
271 return Hdr->getDir(); in getEffectiveUmbrellaDir()
277 void Module::addTopHeader(FileEntryRef File) { in addTopHeader()
282 ArrayRef<FileEntryRef> Module::getTopHeaders(FileManager &FileMgr) { in getTopHeaders()
293 bool Module::directlyUses(const Module *Requested) { in directlyUses()
296 // A top-level module implicitly uses itself. in directlyUses()
297 if (Requested->isSubModuleOf(Top)) in directlyUses()
300 for (auto *Use : Top->DirectUses) in directlyUses()
301 if (Requested->isSubModuleOf(Use)) in directlyUses()
305 if (Requested->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}) || in directlyUses()
306 Requested->fullModuleNameIs({"_Builtin_stddef_wint_t"})) in directlyUses()
309 // module. in directlyUses()
310 if (!Requested->Parent && Requested->Name == "ptrauth") in directlyUses()
319 void Module::addRequirement(StringRef Feature, bool RequiredState, in addRequirement()
321 const TargetInfo &Target) { in addRequirement() argument
325 if (hasFeature(Feature, LangOpts, Target) == RequiredState) in addRequirement()
331 void Module::markUnavailable(bool Unimportable) { in markUnavailable()
332 auto needUpdate = [Unimportable](Module *M) { in markUnavailable()
333 return M->IsAvailable || (!M->IsUnimportable && Unimportable); in markUnavailable()
339 SmallVector<Module *, 2> Stack; in markUnavailable()
342 Module *Current = Stack.back(); in markUnavailable()
348 Current->IsAvailable = false; in markUnavailable()
349 Current->IsUnimportable |= Unimportable; in markUnavailable()
350 for (auto *Submodule : Current->submodules()) { in markUnavailable()
357 Module *Module::findSubmodule(StringRef Name) const { in findSubmodule()
362 return SubModules[Pos->getValue()]; in findSubmodule()
365 Module *Module::findOrInferSubmodule(StringRef Name) { in findOrInferSubmodule()
368 return SubModules[Pos->getValue()]; in findOrInferSubmodule()
371 Module *Result = new Module(Name, SourceLocation(), this, false, InferExplicitSubmodules, 0); in findOrInferSubmodule()
372 Result->InferExplicitSubmodules = InferExplicitSubmodules; in findOrInferSubmodule()
373 Result->InferSubmodules = InferSubmodules; in findOrInferSubmodule()
374 Result->InferExportWildcard = InferExportWildcard; in findOrInferSubmodule()
375 if (Result->InferExportWildcard) in findOrInferSubmodule()
376 Result->Exports.push_back(Module::ExportDecl(nullptr, true)); in findOrInferSubmodule()
380 Module *Module::getGlobalModuleFragment() const { in getGlobalModuleFragment()
381 assert(isNamedModuleUnit() && "We should only query the global module " in getGlobalModuleFragment()
385 if (SubModule->isExplicitGlobalModule()) in getGlobalModuleFragment()
391 Module *Module::getPrivateModuleFragment() const { in getPrivateModuleFragment()
392 assert(isNamedModuleUnit() && "We should only query the private module " in getPrivateModuleFragment()
396 if (SubModule->isPrivateModule()) in getPrivateModuleFragment()
402 void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const { in getExportedModules()
403 // All non-explicit submodules are exported. in getExportedModules()
404 for (std::vector<Module *>::const_iterator I = SubModules.begin(), in getExportedModules()
407 Module *Mod = *I; in getExportedModules()
408 if (!Mod->IsExplicit) in getExportedModules()
412 // Find re-exported modules by filtering the list of imported modules. in getExportedModules()
415 SmallVector<Module *, 4> WildcardRestrictions; in getExportedModules()
417 Module *Mod = Exports[I].getPointer(); in getExportedModules()
419 // Export a named module directly; no wildcards involved. in getExportedModules()
431 if (Module *Restriction = Exports[I].getPointer()) in getExportedModules()
440 // re-exported by the wildcard restriction. in getExportedModules()
445 Module *Mod = Imports[I]; in getExportedModules()
448 // Check whether this module meets one of the restrictions. in getExportedModules()
450 Module *Restriction = WildcardRestrictions[R]; in getExportedModules()
451 if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) { in getExportedModules()
465 void Module::buildVisibleModulesCache() const { in buildVisibleModulesCache()
468 // This module is visible to itself. in buildVisibleModulesCache()
471 // Every imported module is visible. in buildVisibleModulesCache()
472 SmallVector<Module *, 16> Stack(Imports.begin(), Imports.end()); in buildVisibleModulesCache()
474 Module *CurrModule = Stack.pop_back_val(); in buildVisibleModulesCache()
476 // Every module transitively exported by an imported module is visible. in buildVisibleModulesCache()
478 CurrModule->getExportedModules(Stack); in buildVisibleModulesCache()
482 void Module::print(raw_ostream &OS, unsigned Indent, bool Dump) const { in print()
488 OS << "module "; in print()
517 OS.write_escaped(H->NameAsWritten); in print()
522 OS.write_escaped(D->NameAsWritten); in print()
582 // Print inferred subframework modules so that we don't need to re-infer in print()
584 // the module. Regular inferred submodules are OK, as we need to look at all in print()
586 if (!Submodule->IsInferred || Submodule->IsFramework) in print()
587 Submodule->print(OS, Indent + 2, Dump); in print()
592 if (Module *Restriction = Exports[I].getPointer()) { in print()
593 OS << Restriction->getFullModuleName(true); in print()
612 for (Module *M : Imports) { in print()
614 llvm::errs() << "import " << M->getFullModuleName() << "\n"; in print()
621 OS << DirectUses[I]->getFullModuleName(true); in print()
654 OS << Conflicts[I].Other->getFullModuleName(true); in print()
664 OS << "module * {\n"; in print()
677 LLVM_DUMP_METHOD void Module::dump() const { in dump()
681 void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc, in setVisible()
683 // We can't import a global module fragment so the location can be invalid. in setVisible()
684 assert((M->isGlobalModule() || Loc.isValid()) && in setVisible()
692 Module *M; in setVisible()
697 // Nothing to do for a module that's already visible. in setVisible()
698 unsigned ID = V.M->getVisibilityID(); in setVisible()
708 SmallVector<Module *, 16> Exports; in setVisible()
709 V.M->getExportedModules(Exports); in setVisible()
710 for (Module *E : Exports) { in setVisible()
711 // Don't import non-importable modules. in setVisible()
712 if (!E->isUnimportable()) in setVisible()
716 for (auto &C : V.M->Conflicts) { in setVisible()
718 llvm::SmallVector<Module*, 8> Path; in setVisible()
719 for (Visiting *I = &V; I; I = I->ExportedBy) in setVisible()
720 Path.push_back(I->M); in setVisible()