X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FOption%2FOptTable.cpp;h=ef9a3e75a155d4f8b60dc1d06be843c9cdaf1c44;hb=0acd42142a8cbc7e1ca9b13df3e64e8dc727b51e;hp=78c5ea2c4419bcf0e80ba2d862e6eb5aee97c7b3;hpb=add560eee426339135fbabcad764b2afad46285e;p=oota-llvm.git diff --git a/lib/Option/OptTable.cpp b/lib/Option/OptTable.cpp index 78c5ea2c441..ef9a3e75a15 100644 --- a/lib/Option/OptTable.cpp +++ b/lib/Option/OptTable.cpp @@ -62,7 +62,7 @@ static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) { for (const char * const *APre = A.Prefixes, * const *BPre = B.Prefixes; - *APre != 0 && *BPre != 0; ++APre, ++BPre) { + *APre != nullptr && *BPre != nullptr; ++APre, ++BPre){ if (int N = StrCmpOptionName(*APre, *BPre)) return N < 0; } @@ -136,7 +136,7 @@ OptTable::OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos, for (unsigned i = FirstSearchableIndex + 1, e = getNumOptions() + 1; i != e; ++i) { if (const char *const *P = getInfo(i).Prefixes) { - for (; *P != 0; ++P) { + for (; *P != nullptr; ++P) { PrefixesUnion.insert(*P); } } @@ -160,7 +160,7 @@ OptTable::~OptTable() { const Option OptTable::getOption(OptSpecifier Opt) const { unsigned id = Opt.getID(); if (id == 0) - return Option(0, 0); + return Option(nullptr, nullptr); assert((unsigned) (id - 1) < getNumOptions() && "Invalid ID."); return Option(&getInfo(id), this); } @@ -175,22 +175,15 @@ static bool isInput(const llvm::StringSet<> &Prefixes, StringRef Arg) { return true; } -// Returns true if X starts with Y, ignoring case. -static bool startsWithIgnoreCase(StringRef X, StringRef Y) { - if (X.size() < Y.size()) - return false; - return X.substr(0, Y.size()).equals_lower(Y); -} - /// \returns Matched size. 0 means no match. static unsigned matchOption(const OptTable::Info *I, StringRef Str, bool IgnoreCase) { - for (const char * const *Pre = I->Prefixes; *Pre != 0; ++Pre) { + for (const char * const *Pre = I->Prefixes; *Pre != nullptr; ++Pre) { StringRef Prefix(*Pre); if (Str.startswith(Prefix)) { StringRef Rest = Str.substr(Prefix.size()); bool Matched = IgnoreCase - ? startsWithIgnoreCase(Rest, I->Name) + ? Rest.startswith_lower(I->Name) : Rest.startswith(I->Name); if (Matched) return Prefix.size() + StringRef(I->Name).size(); @@ -247,7 +240,7 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, // Otherwise, see if this argument was missing values. if (Prev != Index) - return 0; + return nullptr; } // If we failed to find an option and this arg started with /, then it's @@ -307,7 +300,18 @@ static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) { llvm_unreachable("Invalid option with help text."); case Option::MultiArgClass: - llvm_unreachable("Cannot print metavar for this kind of option."); + if (const char *MetaVarName = Opts.getOptionMetaVar(Id)) { + // For MultiArgs, metavar is full list of all argument names. + Name += ' '; + Name += MetaVarName; + } + else { + // For MultiArgs, if metavar not supplied, print N times. + for (unsigned i=0, e=O.getNumArgs(); i< e; ++i) { + Name += " "; + } + } + break; case Option::FlagClass: break;