mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
Make StringRef::getAsInteger work with all integer types. Before this change
it would fail with {,u}int64_t on x86-64 Linux. This also removes code duplication. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152517 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -285,8 +285,8 @@ static unsigned GetAutoSenseRadix(StringRef &Str) {
|
||||
|
||||
/// GetAsUnsignedInteger - Workhorse method that converts a integer character
|
||||
/// sequence of radix up to 36 to an unsigned long long value.
|
||||
static bool GetAsUnsignedInteger(StringRef Str, unsigned Radix,
|
||||
unsigned long long &Result) {
|
||||
bool llvm::getAsUnsignedInteger(StringRef Str, unsigned Radix,
|
||||
unsigned long long &Result) {
|
||||
// Autosense radix if not specified.
|
||||
if (Radix == 0)
|
||||
Radix = GetAutoSenseRadix(Str);
|
||||
@@ -326,17 +326,13 @@ static bool GetAsUnsignedInteger(StringRef Str, unsigned Radix,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StringRef::getAsInteger(unsigned Radix, unsigned long long &Result) const {
|
||||
return GetAsUnsignedInteger(*this, Radix, Result);
|
||||
}
|
||||
|
||||
|
||||
bool StringRef::getAsInteger(unsigned Radix, long long &Result) const {
|
||||
bool llvm::getAsSignedInteger(StringRef Str, unsigned Radix,
|
||||
long long &Result) {
|
||||
unsigned long long ULLVal;
|
||||
|
||||
// Handle positive strings first.
|
||||
if (empty() || front() != '-') {
|
||||
if (GetAsUnsignedInteger(*this, Radix, ULLVal) ||
|
||||
if (Str.empty() || Str.front() != '-') {
|
||||
if (getAsUnsignedInteger(Str, Radix, ULLVal) ||
|
||||
// Check for value so large it overflows a signed value.
|
||||
(long long)ULLVal < 0)
|
||||
return true;
|
||||
@@ -345,7 +341,7 @@ bool StringRef::getAsInteger(unsigned Radix, long long &Result) const {
|
||||
}
|
||||
|
||||
// Get the positive part of the value.
|
||||
if (GetAsUnsignedInteger(substr(1), Radix, ULLVal) ||
|
||||
if (getAsUnsignedInteger(Str.substr(1), Radix, ULLVal) ||
|
||||
// Reject values so large they'd overflow as negative signed, but allow
|
||||
// "-0". This negates the unsigned so that the negative isn't undefined
|
||||
// on signed overflow.
|
||||
@@ -356,24 +352,6 @@ bool StringRef::getAsInteger(unsigned Radix, long long &Result) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StringRef::getAsInteger(unsigned Radix, int &Result) const {
|
||||
long long Val;
|
||||
if (getAsInteger(Radix, Val) ||
|
||||
(int)Val != Val)
|
||||
return true;
|
||||
Result = Val;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StringRef::getAsInteger(unsigned Radix, unsigned &Result) const {
|
||||
unsigned long long Val;
|
||||
if (getAsInteger(Radix, Val) ||
|
||||
(unsigned)Val != Val)
|
||||
return true;
|
||||
Result = Val;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const {
|
||||
StringRef Str = *this;
|
||||
|
||||
|
Reference in New Issue
Block a user