Skip to content

Commit 08b7295

Browse files
authored
Merge pull request #3709 from ntrel/d-typecons
D: parse const(T), immutable, inout and shared type qualifiers
2 parents 4622e54 + b7a7e08 commit 08b7295

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

Units/parser-d.r/simple.d.d/expected.tags

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ quxx input.d /^ bool quxx;$/;" m union:Struct.Union file:
2828
test.simple input.d /^module test.simple;$/;" M
2929
tfun input.d /^ auto tfun(T)(T v)$/;" f class:Class
3030
this input.d /^ public this(AliasInt x)$/;" f class:Class
31+
type_con input.d /^const(int)* type_con;$/;" v
32+
type_imm input.d /^immutable(int)* type_imm;$/;" v
33+
type_shar input.d /^shared(int)[] type_shar;$/;" v

Units/parser-d.r/simple.d.d/input.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ template Template(alias a, T...)
7171

7272
Object obj;
7373

74+
const(int)* type_con;
75+
immutable(int)* type_imm;
76+
inout(int)* f_inout(inout Object); // FIXME
77+
shared(int)[] type_shar;
78+
7479
private:
7580
int i;
7681

parsers/c-based.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ enum eKeywordId {
6969
KEYWORD_FINAL, KEYWORD_FLOAT, KEYWORD_FOR, KEYWORD_FOREACH,
7070
KEYWORD_FRIEND, KEYWORD_FUNCTION,
7171
KEYWORD_GOTO,
72-
KEYWORD_IF, KEYWORD_IMPLEMENTS, KEYWORD_IMPORT, KEYWORD_INLINE, KEYWORD_INT,
72+
KEYWORD_IF, KEYWORD_IMMUTABLE, KEYWORD_IMPLEMENTS, KEYWORD_IMPORT,
73+
KEYWORD_INLINE, KEYWORD_INT,
7374
KEYWORD_INOUT, KEYWORD_INTERFACE,
7475
KEYWORD_INTERNAL,
7576
KEYWORD_LONG,
@@ -78,7 +79,7 @@ enum eKeywordId {
7879
KEYWORD_OPERATOR, KEYWORD_OVERLOAD, KEYWORD_OVERRIDE,
7980
KEYWORD_PACKAGE, KEYWORD_PRIVATE,
8081
KEYWORD_PROTECTED, KEYWORD_PUBLIC,
81-
KEYWORD_REGISTER, KEYWORD_RETURN,
82+
KEYWORD_REGISTER, KEYWORD_RETURN, KEYWORD_SHARED,
8283
KEYWORD_SHORT, KEYWORD_SIGNED, KEYWORD_STATIC, KEYWORD_STRING,
8384
KEYWORD_STRUCT, KEYWORD_SWITCH, KEYWORD_SYNCHRONIZED,
8485
KEYWORD_TEMPLATE, KEYWORD_THIS, KEYWORD_THROW,
@@ -419,6 +420,7 @@ static const keywordDesc KeywordTable [] = {
419420
{ "idouble", KEYWORD_IDOUBLE, { 0, 1, 0 } },
420421
{ "if", KEYWORD_IF, { 1, 1, 1 } },
421422
{ "ifloat", KEYWORD_IFLOAT, { 0, 1, 0 } },
423+
{ "immutable", KEYWORD_IMMUTABLE, { 0, 1, 0 } },
422424
{ "implements", KEYWORD_IMPLEMENTS, { 0, 0, 1 } },
423425
{ "import", KEYWORD_IMPORT, { 0, 1, 1 } },
424426
{ "in", KEYWORD_IN, { 0, 1, 0 } },
@@ -452,6 +454,7 @@ static const keywordDesc KeywordTable [] = {
452454
{ "register", KEYWORD_REGISTER, { 0, 1, 0 } },
453455
{ "return", KEYWORD_RETURN, { 1, 1, 1 } },
454456
{ "scope", KEYWORD_SCOPE, { 0, 1, 0 } },
457+
{ "shared", KEYWORD_SHARED, { 0, 1, 0 } },
455458
{ "short", KEYWORD_SHORT, { 1, 1, 1 } },
456459
{ "signed", KEYWORD_SIGNED, { 0, 1, 0 } },
457460
{ "static", KEYWORD_STATIC, { 1, 1, 1 } },
@@ -1877,7 +1880,16 @@ static void processToken (tokenInfo *const token, statementInfo *const st)
18771880
case KEYWORD_CATCH: skipParens (); skipBraces (); break;
18781881
case KEYWORD_CHAR: st->declaration = DECL_BASE; break;
18791882
case KEYWORD_CLASS: checkIsClassEnum (st, DECL_CLASS); break;
1880-
case KEYWORD_CONST: st->declaration = DECL_BASE; break;
1883+
case KEYWORD_IMMUTABLE:
1884+
case KEYWORD_INOUT:
1885+
case KEYWORD_SHARED:
1886+
if (!isInputLanguage (Lang_d))
1887+
break;
1888+
case KEYWORD_CONST:
1889+
st->declaration = DECL_BASE;
1890+
if (isInputLanguage (Lang_d))
1891+
skipParens ();
1892+
break;
18811893
case KEYWORD_DOUBLE: st->declaration = DECL_BASE; break;
18821894
case KEYWORD_ENUM: st->declaration = DECL_ENUM; break;
18831895
case KEYWORD_EXTENDS: readParents (st, '.');
@@ -2076,6 +2088,9 @@ static bool skipPostArgumentStuff (
20762088
case KEYWORD_TRY: break;
20772089

20782090
case KEYWORD_CONST:
2091+
case KEYWORD_IMMUTABLE:
2092+
case KEYWORD_INOUT:
2093+
case KEYWORD_SHARED:
20792094
case KEYWORD_VOLATILE:
20802095
if (vStringLength (Signature) > 0)
20812096
{
@@ -2381,6 +2396,9 @@ static int parseParens (statementInfo *const st, parenInfo *const info)
23812396
else if (isType (token, TOKEN_KEYWORD))
23822397
{
23832398
if (token->keyword != KEYWORD_CONST &&
2399+
token->keyword != KEYWORD_IMMUTABLE &&
2400+
token->keyword != KEYWORD_INOUT &&
2401+
token->keyword != KEYWORD_SHARED &&
23842402
token->keyword != KEYWORD_VOLATILE)
23852403
{
23862404
info->isNameCandidate = false;

0 commit comments

Comments
 (0)