Merge remote-tracking branch 'upstream/master' into ncb/complete-h3-inspection-funcs

This commit is contained in:
bharatnc 2021-09-23 14:51:13 -07:00
commit 52289fa41e
3 changed files with 13 additions and 73 deletions

View File

@ -1525,26 +1525,6 @@ bool ParserNull::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
}
static bool parseNumber(char * buffer, size_t size, bool negative, int base, Field & res)
{
errno = 0; /// Functions strto* don't clear errno.
char * pos_integer = buffer;
UInt64 uint_value = std::strtoull(buffer, &pos_integer, base);
if (pos_integer == buffer + size && errno != ERANGE && (!negative || uint_value <= (1ULL << 63)))
{
if (negative)
res = static_cast<Int64>(-uint_value);
else
res = uint_value;
return true;
}
return false;
}
bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
Pos literal_begin = pos;
@ -1584,22 +1564,6 @@ bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
Float64 float_value = std::strtod(buf, &pos_double);
if (pos_double != buf + pos->size() || errno == ERANGE)
{
/// Try to parse number as binary literal representation. Example: 0b0001.
if (pos->size() > 2 && buf[0] == '0' && buf[1] == 'b')
{
char * buf_skip_prefix = buf + 2;
if (parseNumber(buf_skip_prefix, pos->size() - 2, negative, 2, res))
{
auto literal = std::make_shared<ASTLiteral>(res);
literal->begin = literal_begin;
literal->end = ++pos;
node = literal;
return true;
}
}
expected.add(pos, "number");
return false;
}
@ -1614,16 +1578,22 @@ bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
/// try to use more exact type: UInt64
if (parseNumber(buf, pos->size(), negative, 0, res))
{
auto literal = std::make_shared<ASTLiteral>(res);
literal->begin = literal_begin;
literal->end = ++pos;
node = literal;
char * pos_integer = buf;
return true;
errno = 0;
UInt64 uint_value = std::strtoull(buf, &pos_integer, 0);
if (pos_integer == pos_double && errno != ERANGE && (!negative || uint_value <= (1ULL << 63)))
{
if (negative)
res = static_cast<Int64>(-uint_value);
else
res = uint_value;
}
auto literal = std::make_shared<ASTLiteral>(res);
literal->begin = literal_begin;
literal->end = ++pos;
node = literal;
return true;
}

View File

@ -1,14 +0,0 @@
1 UInt8
2 UInt8
4 UInt8
8 UInt8
Unsigned numbers
128 UInt8
32768 UInt16
2147483648 UInt32
9223372036854775808 UInt64
Signed numbers
-128 Int8
-32768 Int16
-2147483648 Int32
-9223372036854775808 Int64

View File

@ -1,16 +0,0 @@
SELECT 0b0001 as number, toTypeName(number);
SELECT 0b0010 as number, toTypeName(number);
SELECT 0b0100 as number, toTypeName(number);
SELECT 0b1000 as number, toTypeName(number);
SELECT 'Unsigned numbers';
SELECT 0b10000000 as number, toTypeName(number);
SELECT 0b1000000000000000 as number, toTypeName(number);
SELECT 0b10000000000000000000000000000000 as number, toTypeName(number);
SELECT 0b1000000000000000000000000000000000000000000000000000000000000000 as number, toTypeName(number);
SELECT 'Signed numbers';
SELECT -0b10000000 as number, toTypeName(number);
SELECT -0b1000000000000000 as number, toTypeName(number);
SELECT -0b10000000000000000000000000000000 as number, toTypeName(number);
SELECT -0b1000000000000000000000000000000000000000000000000000000000000000 as number, toTypeName(number);