diff options
| author | Michael J. Spencer <bigcheesegs@gmail.com> | 2012-10-22 22:13:48 +0000 |
|---|---|---|
| committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2012-10-22 22:13:48 +0000 |
| commit | 929fccd4761b3de9d6c651cc85799d4bbfd165b0 (patch) | |
| tree | ba81d70746265516fbbef1bb9f00057257bcdb38 /clang/lib/Driver/Arg.cpp | |
| parent | dbeb0f0e0cdb0201d35635e72baed288e3021906 (diff) | |
| download | bcm5719-llvm-929fccd4761b3de9d6c651cc85799d4bbfd165b0.tar.gz bcm5719-llvm-929fccd4761b3de9d6c651cc85799d4bbfd165b0.zip | |
[Options] Add prefixes to options.
Each option has a set of prefixes. When matching an argument such as
-funroll-loops. First the leading - is removed as it is a prefix. Then
a lower_bound search for "funroll-loops" is done against the option table by
option name. From there each option prefix + option name combination is tested
against the argument.
This allows us to support Microsoft style options where both / and - are valid
prefixes. It also simplifies the cases we already have where options come in
both - and -- forms. Almost every option for gnu-ld happens to have this form.
llvm-svn: 166444
Diffstat (limited to 'clang/lib/Driver/Arg.cpp')
| -rw-r--r-- | clang/lib/Driver/Arg.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/clang/lib/Driver/Arg.cpp b/clang/lib/Driver/Arg.cpp index b156d7cf714..2431051e9d1 100644 --- a/clang/lib/Driver/Arg.cpp +++ b/clang/lib/Driver/Arg.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "clang/Driver/Arg.h" +#include "clang/Basic/LLVM.h" #include "clang/Driver/ArgList.h" #include "clang/Driver/Option.h" #include "llvm/ADT/SmallString.h" @@ -15,22 +16,23 @@ #include "llvm/Support/raw_ostream.h" using namespace clang::driver; +using clang::StringRef; -Arg::Arg(const Option _Opt, unsigned _Index, const Arg *_BaseArg) - : Opt(_Opt), BaseArg(_BaseArg), Index(_Index), +Arg::Arg(const Option _Opt, StringRef S, unsigned _Index, const Arg *_BaseArg) + : Opt(_Opt), BaseArg(_BaseArg), Spelling(S), Index(_Index), Claimed(false), OwnsValues(false) { } -Arg::Arg(const Option _Opt, unsigned _Index, +Arg::Arg(const Option _Opt, StringRef S, unsigned _Index, const char *Value0, const Arg *_BaseArg) - : Opt(_Opt), BaseArg(_BaseArg), Index(_Index), + : Opt(_Opt), BaseArg(_BaseArg), Spelling(S), Index(_Index), Claimed(false), OwnsValues(false) { Values.push_back(Value0); } -Arg::Arg(const Option _Opt, unsigned _Index, +Arg::Arg(const Option _Opt, StringRef S, unsigned _Index, const char *Value0, const char *Value1, const Arg *_BaseArg) - : Opt(_Opt), BaseArg(_BaseArg), Index(_Index), + : Opt(_Opt), BaseArg(_BaseArg), Spelling(S), Index(_Index), Claimed(false), OwnsValues(false) { Values.push_back(Value0); Values.push_back(Value1); @@ -96,7 +98,7 @@ void Arg::render(const ArgList &Args, ArgStringList &Output) const { case Option::RenderCommaJoinedStyle: { SmallString<256> Res; llvm::raw_svector_ostream OS(Res); - OS << getOption().getName(); + OS << getSpelling(); for (unsigned i = 0, e = getNumValues(); i != e; ++i) { if (i) OS << ','; OS << getValue(Args, i); @@ -107,13 +109,13 @@ void Arg::render(const ArgList &Args, ArgStringList &Output) const { case Option::RenderJoinedStyle: Output.push_back(Args.GetOrMakeJoinedArgString( - getIndex(), getOption().getName(), getValue(Args, 0))); + getIndex(), getSpelling(), getValue(Args, 0))); for (unsigned i = 1, e = getNumValues(); i != e; ++i) Output.push_back(getValue(Args, i)); break; case Option::RenderSeparateStyle: - Output.push_back(getOption().getName().data()); + Output.push_back(Args.MakeArgString(getSpelling())); for (unsigned i = 0, e = getNumValues(); i != e; ++i) Output.push_back(getValue(Args, i)); break; |

