Move CompilerOpts to use a bitfield for easier additions.
Signed-off-by: Vassil Vassilev <vvasilev@cern.ch>
This commit is contained in:
parent
f80ca90232
commit
c29c79b9de
@ -470,33 +470,48 @@ namespace {
|
||||
}
|
||||
|
||||
struct CompilerOpts {
|
||||
bool hasMinusX, noBuiltinInc, noCXXIncludes, haveRsrcPath, haveSysRoot;
|
||||
enum {
|
||||
kHasMinusX = 1,
|
||||
kHasNoBultinInc = 2,
|
||||
kHasNoCXXInc = 4,
|
||||
kHasResourceDir = 8,
|
||||
kHasSysRoot = 16,
|
||||
|
||||
kAllFlags = kHasMinusX|kHasNoBultinInc|kHasNoCXXInc|
|
||||
kHasResourceDir|kHasSysRoot,
|
||||
};
|
||||
unsigned m_Flags;
|
||||
|
||||
static bool strEqual(const char* a, const char* b, size_t n) {
|
||||
return !strncmp(a, b, n) && !a[n];
|
||||
}
|
||||
|
||||
void parse(const char* arg) {
|
||||
if (!hasMinusX && !strncmp(arg, "-x", 2))
|
||||
hasMinusX = true;
|
||||
else if (!noBuiltinInc && strEqual(arg, "-nobuiltininc", 13))
|
||||
noBuiltinInc = true;
|
||||
else if (!noCXXIncludes && strEqual(arg, "-nostdinc++", 11))
|
||||
noCXXIncludes = true;
|
||||
else if (!haveRsrcPath && strEqual(arg, "-resource-dir", 13))
|
||||
haveRsrcPath = true;
|
||||
if (!hasMinusX() && !strncmp(arg, "-x", 2))
|
||||
m_Flags |= kHasMinusX;
|
||||
else if (!noBuiltinInc() && strEqual(arg, "-nobuiltininc", 13))
|
||||
m_Flags |= kHasNoBultinInc;
|
||||
else if (!noCXXIncludes() && strEqual(arg, "-nostdinc++", 11))
|
||||
m_Flags |= kHasNoCXXInc;
|
||||
else if (!hasRsrcPath() && strEqual(arg, "-resource-dir", 13))
|
||||
m_Flags |= kHasResourceDir;
|
||||
#ifdef __APPLE__
|
||||
else if (!haveSysRoot && strEqual(arg, "-isysroot", 9))
|
||||
haveSysRoot = true;
|
||||
else if (!hasSysRoot() && strEqual(arg, "-isysroot", 9))
|
||||
m_Flags |= kHasSysRoot;
|
||||
#endif
|
||||
}
|
||||
|
||||
CompilerOpts(const char* const* iarg, const char* const* earg) :
|
||||
hasMinusX(false), noBuiltinInc(false), noCXXIncludes(false),
|
||||
haveRsrcPath(false), haveSysRoot(false) {
|
||||
public:
|
||||
bool hasMinusX() const { return m_Flags & kHasMinusX; }
|
||||
bool hasRsrcPath() const { return m_Flags & kHasResourceDir; }
|
||||
bool hasSysRoot() const { return m_Flags & kHasSysRoot; }
|
||||
bool noBuiltinInc() const { return m_Flags & kHasNoBultinInc; }
|
||||
bool noCXXIncludes() const { return m_Flags & kHasNoCXXInc; }
|
||||
|
||||
while (iarg < earg && (!hasMinusX || !noBuiltinInc || !noCXXIncludes ||
|
||||
!haveRsrcPath || !haveSysRoot)) {
|
||||
CompilerOpts(const char* const* iarg, const char* const* earg)
|
||||
: m_Flags(0) {
|
||||
|
||||
while (iarg < earg && (m_Flags != kAllFlags)) {
|
||||
if (strEqual(*iarg, "-Xclang", 7)) {
|
||||
// goto next arg if there is one
|
||||
if (++iarg < earg)
|
||||
@ -587,10 +602,10 @@ namespace {
|
||||
// When built with access to the proper Windows APIs, try to actually find
|
||||
// the correct include paths first.
|
||||
if (getVisualStudioDir(VSDir)) {
|
||||
if (!opts.noCXXIncludes) {
|
||||
if (!opts.noCXXIncludes()) {
|
||||
sArguments.addArgument("-I", VSDir + "\\VC\\include");
|
||||
}
|
||||
if (!opts.noBuiltinInc) {
|
||||
if (!opts.noBuiltinInc()) {
|
||||
if (getWindowsSDKDir(WindowsSDKDir)) {
|
||||
sArguments.addArgument("-I", WindowsSDKDir + "\\include");
|
||||
}
|
||||
@ -609,7 +624,7 @@ namespace {
|
||||
#else // _MSC_VER
|
||||
|
||||
// Skip LLVM_CXX execution if -nostdinc++ was provided.
|
||||
if (!opts.noCXXIncludes) {
|
||||
if (!opts.noCXXIncludes()) {
|
||||
// Need sArguments.empty as a check condition later
|
||||
assert(sArguments.empty() && "Arguments not empty");
|
||||
|
||||
@ -648,7 +663,7 @@ namespace {
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
if (!opts.noBuiltinInc && !opts.haveSysRoot) {
|
||||
if (!opts.noBuiltinInc() && !opts.hasSysRoot()) {
|
||||
std::string sysRoot;
|
||||
if (getISysRoot(sysRoot))
|
||||
sArguments.addArgument("-isysroot", std::move(sysRoot));
|
||||
@ -674,7 +689,7 @@ namespace {
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
if (!opts.haveRsrcPath && !opts.noBuiltinInc) {
|
||||
if (!opts.hasRsrcPath() && !opts.noBuiltinInc()) {
|
||||
std::string resourcePath;
|
||||
if (!llvmdir) {
|
||||
// FIXME: The first arg really does need to be argv[0] on FreeBSD.
|
||||
@ -911,7 +926,7 @@ namespace {
|
||||
|
||||
std::vector<const char*> argvCompile(argv, argv+1);
|
||||
argvCompile.reserve(argc+5);
|
||||
if (!copts.hasMinusX) {
|
||||
if (!copts.hasMinusX()) {
|
||||
// We do C++ by default; append right after argv[0] if no "-x" given
|
||||
argvCompile.push_back("-x");
|
||||
argvCompile.push_back( "c++");
|
||||
|
Loading…
x
Reference in New Issue
Block a user