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/unittests | |
| 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/unittests')
| -rw-r--r-- | llvm/unittests/Option/OptionParsingTest.cpp | 19 | ||||
| -rw-r--r-- | llvm/unittests/Option/Opts.td | 3 | 
2 files changed, 19 insertions, 3 deletions
diff --git a/llvm/unittests/Option/OptionParsingTest.cpp b/llvm/unittests/Option/OptionParsingTest.cpp index 2c4fdcfa2c7..101568a567e 100644 --- a/llvm/unittests/Option/OptionParsingTest.cpp +++ b/llvm/unittests/Option/OptionParsingTest.cpp @@ -17,9 +17,11 @@  using namespace llvm;  using namespace llvm::opt; +#define SUPPORT_ALIASARGS // FIXME: Remove when no longer necessary. +  enum ID {    OPT_INVALID = 0, // This is not an option ID. -#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \ +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \                HELPTEXT, METAVAR) OPT_##ID,  #include "Opts.inc"    LastOption @@ -37,10 +39,10 @@ enum OptionFlags {  };  static const OptTable::Info InfoTable[] = { -#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, FLAGS, PARAM, \ +#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \                 HELPTEXT, METAVAR)   \    { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, Option::KIND##Class, PARAM, \ -    FLAGS, OPT_##GROUP, OPT_##ALIAS }, +    FLAGS, OPT_##GROUP, OPT_##ALIAS, ALIASARGS },  #include "Opts.inc"  #undef OPTION  }; @@ -145,3 +147,14 @@ TEST(Option, ParseAliasInGroup) {    OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));    EXPECT_TRUE(AL->hasArg(OPT_H));  } + +TEST(Option, AliasArgs) { +  TestOptTable T; +  unsigned MAI, MAC; + +  const char *MyArgs[] = { "-J", "-Joo" }; +  OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC)); +  EXPECT_TRUE(AL->hasArg(OPT_B)); +  EXPECT_EQ(AL->getAllArgValues(OPT_B)[0], "foo"); +  EXPECT_EQ(AL->getAllArgValues(OPT_B)[1], "bar"); +} diff --git a/llvm/unittests/Option/Opts.td b/llvm/unittests/Option/Opts.td index 8e33ba8580b..986b3122af7 100644 --- a/llvm/unittests/Option/Opts.td +++ b/llvm/unittests/Option/Opts.td @@ -19,3 +19,6 @@ def H : Flag<["-"], "H">, Flags<[HelpHidden]>;  def my_group : OptionGroup<"my group">;  def I : Flag<["-"], "I">, Alias<H>, Group<my_group>; + +def J : Flag<["-"], "J">, Alias<B>, AliasArgs<["foo"]>; +def Joo : Flag<["-"], "Joo">, Alias<B>, AliasArgs<["bar"]>;  | 

