summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-06-28 15:47:20 +0000
committerChris Lattner <sabre@nondot.org>2003-06-28 15:47:20 +0000
commitd2a6fc397ee982936dee7dd5692b1481bcd9fe8f (patch)
tree18334c195e72532f5d044c5f3ce2c402ae85bba1
parent3a56364f00b96a238f5de76a2c54bb34be8fd66f (diff)
downloadllvm-d2a6fc397ee982936dee7dd5692b1481bcd9fe8f.tar.gz
llvm-d2a6fc397ee982936dee7dd5692b1481bcd9fe8f.tar.bz2
llvm-d2a6fc397ee982936dee7dd5692b1481bcd9fe8f.tar.xz
Add support for 'unsigned' command line arguments
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6928 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/Support/CommandLine.h15
-rw-r--r--include/llvm/Support/CommandLine.h15
-rw-r--r--lib/Support/CommandLine.cpp15
-rw-r--r--support/lib/Support/CommandLine.cpp15
4 files changed, 56 insertions, 4 deletions
diff --git a/include/Support/CommandLine.h b/include/Support/CommandLine.h
index ed2559bd2b..97b223c738 100644
--- a/include/Support/CommandLine.h
+++ b/include/Support/CommandLine.h
@@ -516,6 +516,21 @@ struct parser<int> : public basic_parser<int> {
//--------------------------------------------------
+// parser<unsigned>
+//
+template<>
+struct parser<unsigned> : public basic_parser<unsigned> {
+
+ // parse - Return true on error.
+ bool parse(Option &O, const char *ArgName, const std::string &Arg,
+ unsigned &Val);
+
+ // getValueName - Overload in subclass to provide a better default value.
+ virtual const char *getValueName() const { return "uint"; }
+};
+
+
+//--------------------------------------------------
// parser<double>
//
template<>
diff --git a/include/llvm/Support/CommandLine.h b/include/llvm/Support/CommandLine.h
index ed2559bd2b..97b223c738 100644
--- a/include/llvm/Support/CommandLine.h
+++ b/include/llvm/Support/CommandLine.h
@@ -516,6 +516,21 @@ struct parser<int> : public basic_parser<int> {
//--------------------------------------------------
+// parser<unsigned>
+//
+template<>
+struct parser<unsigned> : public basic_parser<unsigned> {
+
+ // parse - Return true on error.
+ bool parse(Option &O, const char *ArgName, const std::string &Arg,
+ unsigned &Val);
+
+ // getValueName - Overload in subclass to provide a better default value.
+ virtual const char *getValueName() const { return "uint"; }
+};
+
+
+//--------------------------------------------------
// parser<double>
//
template<>
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index a0eca7a8ed..bbf996af7b 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -575,14 +575,25 @@ bool parser<bool>::parse(Option &O, const char *ArgName,
//
bool parser<int>::parse(Option &O, const char *ArgName,
const std::string &Arg, int &Value) {
- const char *ArgStart = Arg.c_str();
char *End;
- Value = (int)strtol(ArgStart, &End, 0);
+ Value = (int)strtol(Arg.c_str(), &End, 0);
if (*End != 0)
return O.error(": '" + Arg + "' value invalid for integer argument!");
return false;
}
+// parser<unsigned> implementation
+//
+bool parser<unsigned>::parse(Option &O, const char *ArgName,
+ const std::string &Arg, unsigned &Value) {
+ char *End;
+ long long int V = strtoll(Arg.c_str(), &End, 0);
+ Value = (unsigned)V;
+ if (*End != 0 || V < 0 || Value != V)
+ return O.error(": '" + Arg + "' value invalid for uint argument!");
+ return false;
+}
+
// parser<double>/parser<float> implementation
//
static bool parseDouble(Option &O, const std::string &Arg, double &Value) {
diff --git a/support/lib/Support/CommandLine.cpp b/support/lib/Support/CommandLine.cpp
index a0eca7a8ed..bbf996af7b 100644
--- a/support/lib/Support/CommandLine.cpp
+++ b/support/lib/Support/CommandLine.cpp
@@ -575,14 +575,25 @@ bool parser<bool>::parse(Option &O, const char *ArgName,
//
bool parser<int>::parse(Option &O, const char *ArgName,
const std::string &Arg, int &Value) {
- const char *ArgStart = Arg.c_str();
char *End;
- Value = (int)strtol(ArgStart, &End, 0);
+ Value = (int)strtol(Arg.c_str(), &End, 0);
if (*End != 0)
return O.error(": '" + Arg + "' value invalid for integer argument!");
return false;
}
+// parser<unsigned> implementation
+//
+bool parser<unsigned>::parse(Option &O, const char *ArgName,
+ const std::string &Arg, unsigned &Value) {
+ char *End;
+ long long int V = strtoll(Arg.c_str(), &End, 0);
+ Value = (unsigned)V;
+ if (*End != 0 || V < 0 || Value != V)
+ return O.error(": '" + Arg + "' value invalid for uint argument!");
+ return false;
+}
+
// parser<double>/parser<float> implementation
//
static bool parseDouble(Option &O, const std::string &Arg, double &Value) {