From 3567d38441bcedf4050b94f8d8331ba84559da81 Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Mon, 2 Feb 2009 22:48:49 +0000 Subject: Improve -fno-opt style option processing to not require an extra option to make the -fno- form on the option. We also document the new form in the CommandLine documentation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63559 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/CommandLine.h | 59 ++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 34 deletions(-) (limited to 'include/llvm/Support/CommandLine.h') diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index 9b218da..def5ce7 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -126,7 +126,8 @@ enum MiscFlags { // Miscellaneous flags to adjust argument CommaSeparated = 0x200, // Should this cl::list split between commas? PositionalEatsArgs = 0x400, // Should this positional cl::list eat -args? Sink = 0x800, // Should this cl::list eat all unknown options? - MiscMask = 0xE00 // Union of the above flags. + AllowInverse = 0x1000, // Can this option take a -Xno- form? + MiscMask = 0x1E00 // Union of the above flags. }; @@ -302,12 +303,6 @@ struct LocationClass { template LocationClass location(Ty &L) { return LocationClass(L); } -// opposite_of - Allow the user to specify which other option this -// option is the opposite of. -// -template -LocationClass opposite_of(Ty &O) { return location(O.getValue()); } - //===----------------------------------------------------------------------===// // Enum valued command line option @@ -542,10 +537,33 @@ struct basic_parser : public basic_parser_impl { // template<> class parser : public basic_parser { + bool IsInvertable; // Should we synthezise a -xno- style option? + const char *ArgStr; public: + void getExtraOptionNames(std::vector &OptionNames) { + if (IsInvertable) { + char *s = new char [strlen(ArgStr) + 3 + 1]; + s[0] = ArgStr[0]; + s[1] = 'n'; + s[2] = 'o'; + s[3] = '-'; + strcpy(&s[4], ArgStr+1); + OptionNames.push_back(s); + } + } + // parse - Return true on error. bool parse(Option &O, const char *ArgName, const std::string &Arg, bool &Val); + template + void initialize(Opt &O) { + if (O.getMiscFlags() & llvm::cl::AllowInverse) + IsInvertable = true; + else + IsInvertable = false; + ArgStr = O.ArgStr; + } + enum ValueExpected getValueExpectedFlagDefault() const { return ValueOptional; } @@ -583,30 +601,6 @@ public: EXTERN_TEMPLATE_INSTANTIATION(class basic_parser); //-------------------------------------------------- -// parser -class boolInverse { }; -template<> -class parser : public basic_parser { -public: - typedef bool parser_data_type; - // parse - Return true on error. - bool parse(Option &O, const char *ArgName, const std::string &Arg, - bool &Val); - - enum ValueExpected getValueExpectedFlagDefault() const { - return ValueOptional; - } - - // getValueName - Do not print = at all. - virtual const char *getValueName() const { return 0; } - - // An out-of-line virtual method to provide a 'home' for this class. - virtual void anchor(); -}; - -EXTERN_TEMPLATE_INSTANTIATION(class basic_parser); - -//-------------------------------------------------- // parser // template<> @@ -947,9 +941,6 @@ EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); -class boolInverse; -typedef opt > inverse_opt; - //===----------------------------------------------------------------------===// // list_storage class -- cgit v1.1