mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 19:52:54 +01:00
Add support for 'unsigned' command line arguments
llvm-svn: 6928
This commit is contained in:
parent
6fc4a480f3
commit
4d3ee0f3b1
@ -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>
|
||||
//
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user