llvm.org GIT mirror llvm / d2a6fc3
Add support for 'unsigned' command line arguments git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6928 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
4 changed file(s) with 56 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
515515
516516
517517 //--------------------------------------------------
518 // parser
519 //
520 template<>
521 struct parser : public basic_parser {
522
523 // parse - Return true on error.
524 bool parse(Option &O, const char *ArgName, const std::string &Arg,
525 unsigned &Val);
526
527 // getValueName - Overload in subclass to provide a better default value.
528 virtual const char *getValueName() const { return "uint"; }
529 };
530
531
532 //--------------------------------------------------
518533 // parser
519534 //
520535 template<>
515515
516516
517517 //--------------------------------------------------
518 // parser
519 //
520 template<>
521 struct parser : public basic_parser {
522
523 // parse - Return true on error.
524 bool parse(Option &O, const char *ArgName, const std::string &Arg,
525 unsigned &Val);
526
527 // getValueName - Overload in subclass to provide a better default value.
528 virtual const char *getValueName() const { return "uint"; }
529 };
530
531
532 //--------------------------------------------------
518533 // parser
519534 //
520535 template<>
574574 //
575575 bool parser::parse(Option &O, const char *ArgName,
576576 const std::string &Arg, int &Value) {
577 const char *ArgStart = Arg.c_str();
578577 char *End;
579 Value = (int)strtol(ArgStart, &End, 0);
578 Value = (int)strtol(Arg.c_str(), &End, 0);
580579 if (*End != 0)
581580 return O.error(": '" + Arg + "' value invalid for integer argument!");
581 return false;
582 }
583
584 // parser implementation
585 //
586 bool parser::parse(Option &O, const char *ArgName,
587 const std::string &Arg, unsigned &Value) {
588 char *End;
589 long long int V = strtoll(Arg.c_str(), &End, 0);
590 Value = (unsigned)V;
591 if (*End != 0 || V < 0 || Value != V)
592 return O.error(": '" + Arg + "' value invalid for uint argument!");
582593 return false;
583594 }
584595
574574 //
575575 bool parser::parse(Option &O, const char *ArgName,
576576 const std::string &Arg, int &Value) {
577 const char *ArgStart = Arg.c_str();
578577 char *End;
579 Value = (int)strtol(ArgStart, &End, 0);
578 Value = (int)strtol(Arg.c_str(), &End, 0);
580579 if (*End != 0)
581580 return O.error(": '" + Arg + "' value invalid for integer argument!");
581 return false;
582 }
583
584 // parser implementation
585 //
586 bool parser::parse(Option &O, const char *ArgName,
587 const std::string &Arg, unsigned &Value) {
588 char *End;
589 long long int V = strtoll(Arg.c_str(), &End, 0);
590 Value = (unsigned)V;
591 if (*End != 0 || V < 0 || Value != V)
592 return O.error(": '" + Arg + "' value invalid for uint argument!");
582593 return false;
583594 }
584595