[llvm-commits] [llvm] r63384 - in /llvm/trunk: include/llvm/Support/CommandLine.h lib/Support/CommandLine.cpp
Mike Stump
mrs at apple.com
Fri Jan 30 00:19:46 PST 2009
Author: mrs
Date: Fri Jan 30 02:19:46 2009
New Revision: 63384
URL: http://llvm.org/viewvc/llvm-project?rev=63384&view=rev
Log:
Add opposite_of and inverse_opt to support -fno- style options. This
is necessary for eventual gcc commmand line compatibility.
Modified:
llvm/trunk/include/llvm/Support/CommandLine.h
llvm/trunk/lib/Support/CommandLine.cpp
Modified: llvm/trunk/include/llvm/Support/CommandLine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CommandLine.h?rev=63384&r1=63383&r2=63384&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/CommandLine.h (original)
+++ llvm/trunk/include/llvm/Support/CommandLine.h Fri Jan 30 02:19:46 2009
@@ -302,6 +302,12 @@
template<class Ty>
LocationClass<Ty> location(Ty &L) { return LocationClass<Ty>(L); }
+// opposite_of - Allow the user to specify which other option this
+// option is the opposite of.
+//
+template<class Ty>
+LocationClass<bool> opposite_of(Ty &O) { return location(O.getValue()); }
+
//===----------------------------------------------------------------------===//
// Enum valued command line option
@@ -577,6 +583,30 @@
EXTERN_TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>);
//--------------------------------------------------
+// parser<boolInverse>
+class boolInverse { };
+template<>
+class parser<boolInverse> : public basic_parser<bool> {
+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 =<value> 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<bool>);
+
+//--------------------------------------------------
// parser<int>
//
template<>
@@ -917,6 +947,9 @@
EXTERN_TEMPLATE_INSTANTIATION(class opt<std::string>);
EXTERN_TEMPLATE_INSTANTIATION(class opt<bool>);
+class boolInverse;
+typedef opt<bool, true, parser<boolInverse> > inverse_opt;
+
//===----------------------------------------------------------------------===//
// list_storage class
Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=63384&r1=63383&r2=63384&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Fri Jan 30 02:19:46 2009
@@ -40,6 +40,7 @@
//
TEMPLATE_INSTANTIATION(class basic_parser<bool>);
TEMPLATE_INSTANTIATION(class basic_parser<boolOrDefault>);
+TEMPLATE_INSTANTIATION(class basic_parser<boolInverse>);
TEMPLATE_INSTANTIATION(class basic_parser<int>);
TEMPLATE_INSTANTIATION(class basic_parser<unsigned>);
TEMPLATE_INSTANTIATION(class basic_parser<double>);
@@ -55,6 +56,7 @@
void basic_parser_impl::anchor() {}
void parser<bool>::anchor() {}
void parser<boolOrDefault>::anchor() {}
+void parser<boolInverse>::anchor() {}
void parser<int>::anchor() {}
void parser<unsigned>::anchor() {}
void parser<double>::anchor() {}
@@ -882,7 +884,8 @@
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 @@
return false;
}
+// parser<boolInverse> implementation
+//
+bool parser<boolInverse>::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<int> implementation
//
bool parser<int>::parse(Option &O, const char *ArgName,
More information about the llvm-commits
mailing list