aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Option
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2013-07-31 22:44:41 +0000
committerHans Wennborg <hans@hanshq.net>2013-07-31 22:44:41 +0000
commit9dd8c0cffe7de82900823c05159bba765120f1e3 (patch)
tree79572820d2cf0d73ef30d9a6b90c2c3302ac57bb /lib/Option
parent03fb46bed1a1489725e0da3dea4608d6ef6e6e4b (diff)
downloadexternal_llvm-9dd8c0cffe7de82900823c05159bba765120f1e3.zip
external_llvm-9dd8c0cffe7de82900823c05159bba765120f1e3.tar.gz
external_llvm-9dd8c0cffe7de82900823c05159bba765120f1e3.tar.bz2
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187537 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Option')
-rw-r--r--lib/Option/Option.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/Option/Option.cpp b/lib/Option/Option.cpp
index 5b418e8..1d6a3d3 100644
--- a/lib/Option/Option.cpp
+++ b/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);