diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-10-28 22:18:19 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-10-28 22:18:19 +0000 |
| commit | 5794b53ad5b38b53c9eaf3a172354e63081ceb2f (patch) | |
| tree | 30b7cd56aa93e5528a8ad1cd5571efb221afd443 /lib/Basic/Module.cpp | |
| parent | 961d0573487933199cb287ce8c472121812b3c78 (diff) | |
| download | clang-5794b53ad5b38b53c9eaf3a172354e63081ceb2f.tar.gz clang-5794b53ad5b38b53c9eaf3a172354e63081ceb2f.tar.bz2 clang-5794b53ad5b38b53c9eaf3a172354e63081ceb2f.tar.xz | |
Allow a new syntax in a module requires-declaration:
requires ! feature
The purpose of this is to allow (for instance) the module map for /usr/include
to exclude <tgmath.h> and <complex.h> when building in C++ (these headers are
instead provided by the C++ standard library in this case, and the glibc C
<tgmath.h> header would otherwise try to include <complex.h>, resulting in a
module cycle).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193549 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/Module.cpp')
| -rw-r--r-- | lib/Basic/Module.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/Basic/Module.cpp b/lib/Basic/Module.cpp index 8c35b342ec..481537788e 100644 --- a/lib/Basic/Module.cpp +++ b/lib/Basic/Module.cpp @@ -11,6 +11,7 @@ // code. // //===----------------------------------------------------------------------===// + #include "clang/Basic/Module.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/LangOptions.h" @@ -20,6 +21,7 @@ #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" + using namespace clang; Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, @@ -65,16 +67,17 @@ static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, .Default(Target.hasFeature(Feature)); } -bool +bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target, - StringRef &Feature) const { + Requirement &Req) const { if (IsAvailable) return true; for (const Module *Current = this; Current; Current = Current->Parent) { - for (unsigned I = 0, N = Current->Requires.size(); I != N; ++I) { - if (!hasFeature(Current->Requires[I], LangOpts, Target)) { - Feature = Current->Requires[I]; + 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; } } @@ -143,12 +146,13 @@ ArrayRef<const FileEntry *> Module::getTopHeaders(FileManager &FileMgr) { return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end()); } -void Module::addRequirement(StringRef Feature, const LangOptions &LangOpts, +void Module::addRequirement(StringRef Feature, bool RequiredState, + const LangOptions &LangOpts, const TargetInfo &Target) { - Requires.push_back(Feature); + Requirements.push_back(Requirement(Feature, RequiredState)); // If this feature is currently available, we're done. - if (hasFeature(Feature, LangOpts, Target)) + if (hasFeature(Feature, LangOpts, Target) == RequiredState) return; if (!IsAvailable) @@ -275,13 +279,15 @@ void Module::print(raw_ostream &OS, unsigned Indent) const { OS << " {\n"; - if (!Requires.empty()) { + if (!Requirements.empty()) { OS.indent(Indent + 2); OS << "requires "; - for (unsigned I = 0, N = Requires.size(); I != N; ++I) { + for (unsigned I = 0, N = Requirements.size(); I != N; ++I) { if (I) OS << ", "; - OS << Requires[I]; + if (!Requirements[I].second) + OS << "!"; + OS << Requirements[I].first; } OS << "\n"; } |
