forked from OSchip/llvm-project
Add support for binary literals:
http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html#Binary-constants llvm-svn: 39621
This commit is contained in:
parent
8655428238
commit
de12ae2fd7
|
@ -215,6 +215,7 @@ NumericLiteralParser(const char *begin, const char *end,
|
||||||
DigitsBegin = s;
|
DigitsBegin = s;
|
||||||
s = SkipHexDigits(s);
|
s = SkipHexDigits(s);
|
||||||
if (s == ThisTokEnd) {
|
if (s == ThisTokEnd) {
|
||||||
|
// Done.
|
||||||
} else if (*s == '.') {
|
} else if (*s == '.') {
|
||||||
s++;
|
s++;
|
||||||
saw_period = true;
|
saw_period = true;
|
||||||
|
@ -237,6 +238,19 @@ NumericLiteralParser(const char *begin, const char *end,
|
||||||
Diag(TokLoc, diag::err_hexconstant_requires_exponent);
|
Diag(TokLoc, diag::err_hexconstant_requires_exponent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (*s == 'b' || *s == 'B') {
|
||||||
|
// 0b101010 is a GCC extension.
|
||||||
|
++s;
|
||||||
|
radix = 2;
|
||||||
|
DigitsBegin = s;
|
||||||
|
s = SkipBinaryDigits(s);
|
||||||
|
if (s == ThisTokEnd) {
|
||||||
|
// Done.
|
||||||
|
} else if (isxdigit(*s)) {
|
||||||
|
Diag(TokLoc, diag::err_invalid_binary_digit, std::string(s, s+1));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PP.Diag(TokLoc, diag::ext_binary_literal);
|
||||||
} else {
|
} else {
|
||||||
// For now, the radix is set to 8. If we discover that we have a
|
// For now, the radix is set to 8. If we discover that we have a
|
||||||
// floating point constant, the radix will change to 10. Octal floating
|
// floating point constant, the radix will change to 10. Octal floating
|
||||||
|
|
|
@ -530,6 +530,10 @@ DIAG(warn_integer_too_large_for_signed, WARNING,
|
||||||
"integer constant is so large that it is unsigned")
|
"integer constant is so large that it is unsigned")
|
||||||
DIAG(err_exponent_has_no_digits, ERROR,
|
DIAG(err_exponent_has_no_digits, ERROR,
|
||||||
"exponent has no digits")
|
"exponent has no digits")
|
||||||
|
DIAG(ext_binary_literal, EXTENSION,
|
||||||
|
"binary integer literals are an extension")
|
||||||
|
DIAG(err_invalid_binary_digit, ERROR,
|
||||||
|
"invalid digit '%0' in binary constant")
|
||||||
DIAG(err_invalid_octal_digit, ERROR,
|
DIAG(err_invalid_octal_digit, ERROR,
|
||||||
"invalid digit '%0' in octal constant")
|
"invalid digit '%0' in octal constant")
|
||||||
DIAG(err_invalid_decimal_digit, ERROR,
|
DIAG(err_invalid_decimal_digit, ERROR,
|
||||||
|
|
|
@ -97,6 +97,15 @@ private:
|
||||||
ptr++;
|
ptr++;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// SkipBinaryDigits - Read and skip over any binary digits, up to End.
|
||||||
|
/// Return a pointer to the first non-binary digit or End.
|
||||||
|
const char *SkipBinaryDigits(const char *ptr) {
|
||||||
|
while (ptr != ThisTokEnd && (*ptr == '0' || *ptr == '1'))
|
||||||
|
ptr++;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// CharLiteralParser - Perform interpretation and semantic analysis of a
|
/// CharLiteralParser - Perform interpretation and semantic analysis of a
|
||||||
|
|
Loading…
Reference in New Issue