mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 21:21:48 +03:00
fix Issue 22559 - ImportC: support gnu case ranges (#15068)
This commit is contained in:
parent
5a79fff38f
commit
3fd5c8d081
2 changed files with 29 additions and 1 deletions
|
@ -508,6 +508,14 @@ final class CParser(AST) : Parser!AST
|
|||
|
||||
nextToken();
|
||||
auto exp = cparseAssignExp();
|
||||
AST.Expression expHigh;
|
||||
if (token.value == TOK.dotDotDot)
|
||||
{
|
||||
/* Case Ranges https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html
|
||||
*/
|
||||
nextToken();
|
||||
expHigh = cparseAssignExp();
|
||||
}
|
||||
check(TOK.colon);
|
||||
|
||||
if (flags & ParseStatementFlags.curlyScope)
|
||||
|
@ -533,6 +541,9 @@ final class CParser(AST) : Parser!AST
|
|||
s = cparseStatement(0);
|
||||
}
|
||||
s = new AST.ScopeStatement(loc, s, token.loc);
|
||||
if (expHigh)
|
||||
s = new AST.CaseRangeStatement(loc, exp, expHigh, s);
|
||||
else
|
||||
s = new AST.CaseStatement(loc, exp, s);
|
||||
break;
|
||||
}
|
||||
|
|
17
compiler/test/compilable/test22559.i
Normal file
17
compiler/test/compilable/test22559.i
Normal file
|
@ -0,0 +1,17 @@
|
|||
// https://gcc.gnu.org/onlinedocs/gcc/Case-Ranges.html
|
||||
|
||||
int alpha(char c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'A' ... 'Z': return 1;
|
||||
case 'a' ... 'z': return 1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
_Static_assert(alpha('A') == 1, "1");
|
||||
_Static_assert(alpha('B') == 1, "2");
|
||||
_Static_assert(alpha('z') == 1, "3");
|
||||
_Static_assert(alpha('z' + 1) == 0, "3");
|
||||
_Static_assert(alpha('0') == 0, "4");
|
Loading…
Add table
Add a link
Reference in a new issue