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). llvm-svn: 193549
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user