diff options
| author | Hans Wennborg <hans@hanshq.net> | 2013-07-31 22:44:41 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2013-07-31 22:44:41 +0000 |
| commit | 5fdcf86861170e948ae577b4e931bdf98e7dfc35 (patch) | |
| tree | 378c98a7a85d6315bd64e1b8913698b12d4bafcd /llvm/lib/Option/Option.cpp | |
| parent | 97dd3d207a957e81885ddacae19a0abb3fc4faa8 (diff) | |
| download | bcm5719-llvm-5fdcf86861170e948ae577b4e931bdf98e7dfc35.tar.gz bcm5719-llvm-5fdcf86861170e948ae577b4e931bdf98e7dfc35.zip | |
Option parsing: add support for alias arguments.
This makes option aliases more powerful by enabling them to
pass along arguments to the option they're aliasing.
For example, if we have a joined option "-foo=", we can now
specify a flag option "-bar" to be an alias of that, with the
argument "baz".
This is especially useful for the cl.exe compatible clang driver,
where many options are aliases. For example, this patch enables
us to alias "/Ox" to "-O3" (-O is a joined option), and "/WX" to
"-Werror" (again, -W is a joined option).
Differential Revision: http://llvm-reviews.chandlerc.com/D1245
llvm-svn: 187537
Diffstat (limited to 'llvm/lib/Option/Option.cpp')
| -rw-r--r-- | llvm/lib/Option/Option.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/Option/Option.cpp b/llvm/lib/Option/Option.cpp index 5b418e845e0..1d6a3d38040 100644 --- a/llvm/lib/Option/Option.cpp +++ b/llvm/lib/Option/Option.cpp @@ -26,6 +26,13 @@ Option::Option(const OptTable::Info *info, const OptTable *owner) // tracking, it is not an inherent limitation. assert((!Info || !getAlias().isValid() || !getAlias().getAlias().isValid()) && "Multi-level aliases are not supported."); + + if (Info && getAliasArgs()) { + assert(getAlias().isValid() && "Only alias options can have alias args."); + assert(getKind() == FlagClass && "Only Flag aliases can have alias args."); + assert(getAlias().getKind() != FlagClass && + "Cannot provide alias args to a flag option."); + } } Option::~Option() { @@ -106,11 +113,22 @@ Arg *Option::accept(const ArgList &Args, } switch (getKind()) { - case FlagClass: + case FlagClass: { if (ArgSize != strlen(Args.getArgString(Index))) return 0; - return new Arg(UnaliasedOption, Spelling, Index++); + Arg *A = new Arg(UnaliasedOption, Spelling, Index++); + if (getAliasArgs()) { + const char *Val = getAliasArgs(); + while (*Val != '\0') { + A->getValues().push_back(Val); + + // Move past the '\0' to the next argument. + Val += strlen(Val) + 1; + } + } + return A; + } case JoinedClass: { const char *Value = Args.getArgString(Index) + ArgSize; return new Arg(UnaliasedOption, Spelling, Index++, Value); |

