mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 05:30:13 +03:00
fix Issue 24173 - ImportC: add Microsoft iNN integer literal suffixes (#15654)
This commit is contained in:
parent
e775284c9c
commit
e096102f16
2 changed files with 109 additions and 2 deletions
|
@ -2206,9 +2206,14 @@ class Lexer
|
|||
if (base == 2)
|
||||
goto Ldone; // if ".identifier" or ".unicode"
|
||||
goto Lreal; // otherwise as part of a floating point literal
|
||||
|
||||
case 'i':
|
||||
if (Ccompile)
|
||||
goto Ldone;
|
||||
goto Lreal;
|
||||
|
||||
case 'p':
|
||||
case 'P':
|
||||
case 'i':
|
||||
Lreal:
|
||||
p = start;
|
||||
return inreal(t);
|
||||
|
@ -2401,7 +2406,13 @@ class Lexer
|
|||
decimal = 2, // decimal
|
||||
unsigned = 4, // u or U suffix
|
||||
long_ = 8, // l or L suffix
|
||||
llong = 0x10 // ll or LL
|
||||
llong = 0x10, // ll or LL
|
||||
|
||||
// Microsoft extensions
|
||||
i8 = 0x20,
|
||||
i16 = 0x40,
|
||||
i32 = 0x80,
|
||||
i64 = 0x100,
|
||||
}
|
||||
FLAGS flags = (base == 10) ? FLAGS.decimal : FLAGS.octalhex;
|
||||
bool err;
|
||||
|
@ -2427,6 +2438,37 @@ class Lexer
|
|||
}
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
case 'I':
|
||||
if (p[1] == '8')
|
||||
{
|
||||
f = FLAGS.i8;
|
||||
++p;
|
||||
}
|
||||
else if (p[1] == '1' && p[2] == '6')
|
||||
{
|
||||
f = FLAGS.i16;
|
||||
p += 2;
|
||||
}
|
||||
else if (p[1] == '3' && p[2] == '2')
|
||||
{
|
||||
f = FLAGS.i32;
|
||||
p += 2;
|
||||
}
|
||||
else if (p[1] == '6' && p[2] == '4')
|
||||
{
|
||||
f = FLAGS.i64;
|
||||
p += 2;
|
||||
}
|
||||
else
|
||||
break Lsuffixes;
|
||||
if (p[1] >= '0' && p[1] <= '9' && !err)
|
||||
{
|
||||
error("invalid integer suffix");
|
||||
err = true;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break Lsuffixes;
|
||||
}
|
||||
|
@ -2559,6 +2601,34 @@ class Lexer
|
|||
result = TOK.uns64Literal;
|
||||
break;
|
||||
|
||||
case FLAGS.octalhex | FLAGS.i8:
|
||||
case FLAGS.octalhex | FLAGS.i16:
|
||||
case FLAGS.octalhex | FLAGS.i32:
|
||||
case FLAGS.octalhex | FLAGS.unsigned | FLAGS.i8:
|
||||
case FLAGS.octalhex | FLAGS.unsigned | FLAGS.i16:
|
||||
case FLAGS.octalhex | FLAGS.unsigned | FLAGS.i32:
|
||||
case FLAGS.decimal | FLAGS.unsigned | FLAGS.i8:
|
||||
case FLAGS.decimal | FLAGS.unsigned | FLAGS.i16:
|
||||
case FLAGS.decimal | FLAGS.unsigned | FLAGS.i32:
|
||||
result = TOK.uns32Literal;
|
||||
break;
|
||||
|
||||
case FLAGS.decimal | FLAGS.i8:
|
||||
case FLAGS.decimal | FLAGS.i16:
|
||||
case FLAGS.decimal | FLAGS.i32:
|
||||
result = TOK.int32Literal;
|
||||
break;
|
||||
|
||||
case FLAGS.octalhex | FLAGS.i64:
|
||||
case FLAGS.octalhex | FLAGS.unsigned | FLAGS.i64:
|
||||
case FLAGS.decimal | FLAGS.unsigned | FLAGS.i64:
|
||||
result = TOK.uns64Literal;
|
||||
break;
|
||||
|
||||
case FLAGS.decimal | FLAGS.i64:
|
||||
result = TOK.int64Literal;
|
||||
break;
|
||||
|
||||
default:
|
||||
debug printf("%x\n",flags);
|
||||
assert(0);
|
||||
|
|
37
compiler/test/fail_compilation/test24173.c
Normal file
37
compiler/test/fail_compilation/test24173.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/test24173.c(101): Error: missing comma or semicolon after declaration of `a`, found `i` instead
|
||||
fail_compilation/test24173.c(102): Error: missing comma or semicolon after declaration of `b`, found `i7` instead
|
||||
fail_compilation/test24173.c(103): Error: missing comma or semicolon after declaration of `c`, found `i43` instead
|
||||
fail_compilation/test24173.c(104): Error: invalid integer suffix
|
||||
fail_compilation/test24173.c(104): Error: `=`, `;` or `,` expected to end declaration instead of `0`
|
||||
---
|
||||
*/
|
||||
|
||||
_Static_assert(-127i8 - 1 == 0xFFFFFF80, "1");
|
||||
_Static_assert(-32767i16 - 1 == 0xFFFF8000, "2");
|
||||
_Static_assert(-2147483647i32 - 1 == 0x80000000, "3");
|
||||
_Static_assert(-9223372036854775807i64 - 1 == 0x8000000000000000, "4");
|
||||
|
||||
_Static_assert(127i8 == 0x7F, "5");
|
||||
_Static_assert(32767i16 == 0x7FFF, "6");
|
||||
_Static_assert(2147483647i32 == 0x7FFFFFFF, "7");
|
||||
_Static_assert(9223372036854775807i64 == 0x7FFFFFFFFFFFFFFF, "8");
|
||||
|
||||
_Static_assert(127ui8 == 0x7F, "9");
|
||||
_Static_assert(32767ui16 == 0x7FFF, "10");
|
||||
_Static_assert(2147483647ui32 == 0x7FFFFFFF, "11");
|
||||
_Static_assert(9223372036854775807ui64 == 0x7FFFFFFFFFFFFFFF, "12");
|
||||
|
||||
_Static_assert(0xffui8 == 0xFF, "13");
|
||||
_Static_assert(0xffffui16 == 0xFFFF, "14");
|
||||
_Static_assert(0xffffffffui32 == 0xFFFFFFFF, "15");
|
||||
_Static_assert(0xFFFFFFFFFFFFFFFFui64 == 0xFFFFFFFFFFFFFFFF, "16");
|
||||
|
||||
#line 100
|
||||
|
||||
int a = 2i;
|
||||
int b = 2i7;
|
||||
int c = 2ui43;
|
||||
int d = 2i160;
|
Loading…
Add table
Add a link
Reference in a new issue