Add support for 'unsigned' command line arguments
authorChris Lattner <sabre@nondot.org>
Sat, 28 Jun 2003 15:47:20 +0000 (15:47 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 28 Jun 2003 15:47:20 +0000 (15:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6928 91177308-0d34-0410-b5e6-96231b3b80d8

include/Support/CommandLine.h
include/llvm/Support/CommandLine.h
lib/Support/CommandLine.cpp
support/lib/Support/CommandLine.cpp

index ed2559bd2b9f1af962eddc1a4cf789896efc9585..97b223c738148b174f34fdfbda963d5414decc58 100644 (file)
@@ -515,6 +515,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>
 //
index ed2559bd2b9f1af962eddc1a4cf789896efc9585..97b223c738148b174f34fdfbda963d5414decc58 100644 (file)
@@ -515,6 +515,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>
 //
index a0eca7a8ed4099602d8364d6e9cbff4e13048b58..bbf996af7b1081d376463017fe60afa4824606c4 100644 (file)
@@ -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) {
index a0eca7a8ed4099602d8364d6e9cbff4e13048b58..bbf996af7b1081d376463017fe60afa4824606c4 100644 (file)
@@ -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) {