From d6f175b3ec8d40e33ab8110020ca8feb98295834 Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Fri, 30 Jan 2009 08:19:46 +0000 Subject: [PATCH] Add opposite_of and inverse_opt to support -fno- style options. This is necessary for eventual gcc commmand line compatibility. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63384 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/CommandLine.h | 33 ++++++++++++++++++++++++++++++ lib/Support/CommandLine.cpp | 22 +++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h index e7f5a02b77d..9b218dab031 100644 --- a/include/llvm/Support/CommandLine.h +++ b/include/llvm/Support/CommandLine.h @@ -302,6 +302,12 @@ 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 @@ -576,6 +582,30 @@ 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 // @@ -917,6 +947,9 @@ EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); EXTERN_TEMPLATE_INSTANTIATION(class opt); +class boolInverse; +typedef opt > inverse_opt; + //===----------------------------------------------------------------------===// // list_storage class diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 2414734869d..e06f324c871 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -40,6 +40,7 @@ using namespace cl; // TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); +TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); TEMPLATE_INSTANTIATION(class basic_parser); @@ -55,6 +56,7 @@ void Option::anchor() {} void basic_parser_impl::anchor() {} void parser::anchor() {} void parser::anchor() {} +void parser::anchor() {} void parser::anchor() {} void parser::anchor() {} void parser::anchor() {} @@ -882,7 +884,8 @@ bool parser::parse(Option &O, const char *ArgName, if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" || Arg == "1") { Value = BOU_TRUE; - } else if (Arg == "false" || Arg == "FALSE" || Arg == "False" || Arg == "0") { + } else if (Arg == "false" || Arg == "FALSE" + || Arg == "False" || Arg == "0") { Value = BOU_FALSE; } else { return O.error(": '" + Arg + @@ -891,6 +894,23 @@ bool parser::parse(Option &O, const char *ArgName, return false; } +// parser implementation +// +bool parser::parse(Option &O, const char *ArgName, + const std::string &Arg, bool &Value) { + if (Arg == "" || Arg == "true" || Arg == "TRUE" || Arg == "True" || + Arg == "1") { + Value = false; + } else if (Arg == "false" || Arg == "FALSE" + || Arg == "False" || Arg == "0") { + Value = true; + } else { + return O.error(": '" + Arg + + "' is invalid value for boolean argument! Try 0 or 1"); + } + return false; +} + // parser implementation // bool parser::parse(Option &O, const char *ArgName, -- 2.34.1