diff options
author | Richard Smith <richard@metafoo.co.uk> | 2020-04-17 16:23:41 -0700 |
---|---|---|
committer | Richard Smith <richard@metafoo.co.uk> | 2020-04-17 22:48:56 -0700 |
commit | fc76b4ad3da3c1f5fdc34370a55d613b3ca7af73 (patch) | |
tree | 1341b19511318fd1b81294c5686570ae624dc32b /clang/lib/Basic/Module.cpp | |
parent | c8248dc3bb36bea61ac6d87bd02c39c6a781b011 (diff) | |
download | llvm-fc76b4ad3da3c1f5fdc34370a55d613b3ca7af73.zip llvm-fc76b4ad3da3c1f5fdc34370a55d613b3ca7af73.tar.gz llvm-fc76b4ad3da3c1f5fdc34370a55d613b3ca7af73.tar.bz2 |
Rename IsMissingRequirement to IsUnimportable and set it for shadowed
modules too.
This more accurately reflects the semantics of this flag, as distinct
from "IsAvailable", which (in an explicit modules world) only describes
whether a module is buildable, not whether it's importable.
Diffstat (limited to 'clang/lib/Basic/Module.cpp')
-rw-r--r-- | clang/lib/Basic/Module.cpp | 62 |
1 files changed, 37 insertions, 25 deletions
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index 5fd7d30..22e1da4 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -37,7 +37,7 @@ using namespace clang; Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID) : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), - VisibilityID(VisibilityID), IsMissingRequirement(false), + VisibilityID(VisibilityID), IsUnimportable(false), HasIncompatibleModuleFile(false), IsAvailable(true), IsFromModuleFile(false), IsFramework(IsFramework), IsExplicit(IsExplicit), IsSystem(false), IsExternC(false), IsInferred(false), @@ -46,17 +46,12 @@ Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, NoUndeclaredIncludes(false), ModuleMapIsPrivate(false), HasUmbrellaDir(false), NameVisibility(Hidden) { if (Parent) { - if (!Parent->isAvailable()) - IsAvailable = false; - if (Parent->IsSystem) - IsSystem = true; - if (Parent->IsExternC) - IsExternC = true; - if (Parent->NoUndeclaredIncludes) - NoUndeclaredIncludes = true; - if (Parent->ModuleMapIsPrivate) - ModuleMapIsPrivate = true; - IsMissingRequirement = Parent->IsMissingRequirement; + IsAvailable = Parent->isAvailable(); + IsUnimportable = Parent->isUnimportable(); + IsSystem = Parent->IsSystem; + IsExternC = Parent->IsExternC; + NoUndeclaredIncludes = Parent->NoUndeclaredIncludes; + ModuleMapIsPrivate = Parent->ModuleMapIsPrivate; Parent->SubModuleIndex[Name] = Parent->SubModules.size(); Parent->SubModules.push_back(this); @@ -132,25 +127,42 @@ static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, return HasFeature; } -bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target, - Requirement &Req, - UnresolvedHeaderDirective &MissingHeader, - Module *&ShadowingModule) const { - if (IsAvailable) - return true; +bool Module::isUnimportable(const LangOptions &LangOpts, + const TargetInfo &Target, Requirement &Req, + Module *&ShadowingModule) const { + if (!IsUnimportable) + return false; for (const Module *Current = this; Current; Current = Current->Parent) { if (Current->ShadowingModule) { ShadowingModule = Current->ShadowingModule; - return false; + return true; } for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) { if (hasFeature(Current->Requirements[I].first, LangOpts, Target) != Current->Requirements[I].second) { Req = Current->Requirements[I]; - return false; + return true; } } + } + + llvm_unreachable("could not find a reason why module is unimportable"); +} + +bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target, + Requirement &Req, + UnresolvedHeaderDirective &MissingHeader, + Module *&ShadowingModule) const { + if (IsAvailable) + return true; + + if (isUnimportable(LangOpts, Target, Req, ShadowingModule)) + return false; + + // FIXME: All missing headers are listed on the top-level module. Should we + // just look there? + for (const Module *Current = this; Current; Current = Current->Parent) { if (!Current->MissingHeaders.empty()) { MissingHeader = Current->MissingHeaders.front(); return false; @@ -287,12 +299,12 @@ void Module::addRequirement(StringRef Feature, bool RequiredState, if (hasFeature(Feature, LangOpts, Target) == RequiredState) return; - markUnavailable(/*MissingRequirement*/true); + markUnavailable(/*Unimportable*/true); } -void Module::markUnavailable(bool MissingRequirement) { - auto needUpdate = [MissingRequirement](Module *M) { - return M->IsAvailable || (!M->IsMissingRequirement && MissingRequirement); +void Module::markUnavailable(bool Unimportable) { + auto needUpdate = [Unimportable](Module *M) { + return M->IsAvailable || (!M->IsUnimportable && Unimportable); }; if (!needUpdate(this)) @@ -308,7 +320,7 @@ void Module::markUnavailable(bool MissingRequirement) { continue; Current->IsAvailable = false; - Current->IsMissingRequirement |= MissingRequirement; + Current->IsUnimportable |= Unimportable; for (submodule_iterator Sub = Current->submodule_begin(), SubEnd = Current->submodule_end(); Sub != SubEnd; ++Sub) { |