diff options
author | Stephen Hines <srhines@google.com> | 2014-02-11 20:01:10 -0800 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-02-11 20:01:10 -0800 |
commit | ce9904c6ea8fd669978a8eefb854b330eb9828ff (patch) | |
tree | 2418ee2e96ea220977c8fb74959192036ab5b133 /lib/Option | |
parent | c27b10b198c1d9e9b51f2303994313ec2778edd7 (diff) | |
parent | dbb832b83351cec97b025b61c26536ef50c3181c (diff) | |
download | external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.zip external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.tar.gz external_llvm-ce9904c6ea8fd669978a8eefb854b330eb9828ff.tar.bz2 |
Merge remote-tracking branch 'upstream/release_34' into merge-20140211
Conflicts:
lib/Linker/LinkModules.cpp
lib/Support/Unix/Signals.inc
Change-Id: Ia54f291fa5dc828052d2412736e8495c1282aa64
Diffstat (limited to 'lib/Option')
-rw-r--r-- | lib/Option/OptTable.cpp | 73 | ||||
-rw-r--r-- | lib/Option/Option.cpp | 11 |
2 files changed, 47 insertions, 37 deletions
diff --git a/lib/Option/OptTable.cpp b/lib/Option/OptTable.cpp index 98e63bc..6fa459a 100644 --- a/lib/Option/OptTable.cpp +++ b/lib/Option/OptTable.cpp @@ -14,26 +14,27 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> +#include <cctype> #include <map> using namespace llvm; using namespace llvm::opt; -// Ordering on Info. The ordering is *almost* lexicographic, with two -// exceptions. First, '\0' comes at the end of the alphabet instead of -// the beginning (thus options precede any other options which prefix -// them). Second, for options with the same name, the less permissive -// version should come first; a Flag option should precede a Joined -// option, for example. +namespace llvm { +namespace opt { -static int StrCmpOptionName(const char *A, const char *B) { - char a = *A, b = *B; +// Ordering on Info. The ordering is *almost* case-insensitive lexicographic, +// with an exceptions. '\0' comes at the end of the alphabet instead of the +// beginning (thus options precede any other options which prefix them). +static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) { + const char *X = A, *Y = B; + char a = tolower(*A), b = tolower(*B); while (a == b) { if (a == '\0') return 0; - a = *++A; - b = *++B; + a = tolower(*++X); + b = tolower(*++Y); } if (a == '\0') // A is a prefix of B. @@ -45,21 +46,25 @@ static int StrCmpOptionName(const char *A, const char *B) { return (a < b) ? -1 : 1; } -namespace llvm { -namespace opt { +#ifndef NDEBUG +static int StrCmpOptionName(const char *A, const char *B) { + if (int N = StrCmpOptionNameIgnoreCase(A, B)) + return N; + return strcmp(A, B); +} static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) { if (&A == &B) return false; if (int N = StrCmpOptionName(A.Name, B.Name)) - return N == -1; + return N < 0; for (const char * const *APre = A.Prefixes, * const *BPre = B.Prefixes; *APre != 0 && *BPre != 0; ++APre, ++BPre) { if (int N = StrCmpOptionName(*APre, *BPre)) - return N == -1; + return N < 0; } // Names are the same, check that classes are in order; exactly one @@ -68,22 +73,22 @@ static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) { "Unexpected classes for options with same name."); return B.Kind == Option::JoinedClass; } +#endif // Support lower_bound between info and an option name. static inline bool operator<(const OptTable::Info &I, const char *Name) { - return StrCmpOptionName(I.Name, Name) == -1; -} -static inline bool operator<(const char *Name, const OptTable::Info &I) { - return StrCmpOptionName(Name, I.Name) == -1; + return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0; } } } OptSpecifier::OptSpecifier(const Option *Opt) : ID(Opt->getID()) {} -OptTable::OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos) +OptTable::OptTable(const Info *_OptionInfos, unsigned _NumOptionInfos, + bool _IgnoreCase) : OptionInfos(_OptionInfos), NumOptionInfos(_NumOptionInfos), + IgnoreCase(_IgnoreCase), TheInputOptionID(0), TheUnknownOptionID(0), FirstSearchableIndex(0) @@ -171,11 +176,18 @@ static bool isInput(const llvm::StringSet<> &Prefixes, StringRef Arg) { } /// \returns Matched size. 0 means no match. -static unsigned matchOption(const OptTable::Info *I, StringRef Str) { +static unsigned matchOption(const OptTable::Info *I, StringRef Str, + bool IgnoreCase) { for (const char * const *Pre = I->Prefixes; *Pre != 0; ++Pre) { StringRef Prefix(*Pre); - if (Str.startswith(Prefix) && Str.substr(Prefix.size()).startswith(I->Name)) - return Prefix.size() + StringRef(I->Name).size(); + if (Str.startswith(Prefix)) { + StringRef Rest = Str.substr(Prefix.size()); + bool Matched = IgnoreCase + ? Rest.startswith_lower(I->Name) + : Rest.startswith(I->Name); + if (Matched) + return Prefix.size() + StringRef(I->Name).size(); + } } return 0; } @@ -210,7 +222,7 @@ Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index, unsigned ArgSize = 0; // Scan for first option which is a proper prefix. for (; Start != End; ++Start) - if ((ArgSize = matchOption(Start, Str))) + if ((ArgSize = matchOption(Start, Str, IgnoreCase))) break; if (Start == End) break; @@ -259,20 +271,6 @@ InputArgList *OptTable::ParseArgs(const char *const *ArgBegin, continue; } - if (Str == "--") { - // Everything after -- is a filename. - ++Index; - - assert(TheInputOptionID != 0 && "Invalid input option ID."); - while (Index < End) { - Args->append(new Arg(getOption(TheInputOptionID), - Args->getArgString(Index), Index, - Args->getArgString(Index))); - ++Index; - } - break; - } - unsigned Prev = Index; Arg *A = ParseOneArg(*Args, Index, FlagsToInclude, FlagsToExclude); assert(Index > Prev && "Parser failed to consume argument."); @@ -308,6 +306,7 @@ static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) { break; case Option::SeparateClass: case Option::JoinedOrSeparateClass: + case Option::RemainingArgsClass: Name += ' '; // FALLTHROUGH case Option::JoinedClass: case Option::CommaJoinedClass: diff --git a/lib/Option/Option.cpp b/lib/Option/Option.cpp index 1d6a3d3..7b5ff2b 100644 --- a/lib/Option/Option.cpp +++ b/lib/Option/Option.cpp @@ -52,6 +52,7 @@ void Option::dump() const { P(MultiArgClass); P(JoinedOrSeparateClass); P(JoinedAndSeparateClass); + P(RemainingArgsClass); #undef P } @@ -214,6 +215,16 @@ Arg *Option::accept(const ArgList &Args, return new Arg(UnaliasedOption, Spelling, Index - 2, Args.getArgString(Index - 2) + ArgSize, Args.getArgString(Index - 1)); + case RemainingArgsClass: { + // Matches iff this is an exact match. + // FIXME: Avoid strlen. + if (ArgSize != strlen(Args.getArgString(Index))) + return 0; + Arg *A = new Arg(UnaliasedOption, Spelling, Index++); + while (Index < Args.getNumInputArgStrings()) + A->getValues().push_back(Args.getArgString(Index++)); + return A; + } default: llvm_unreachable("Invalid option kind!"); } |