Skip to content

Commit

Permalink
Merge pull request #3709 from ntrel/d-typecons
Browse files Browse the repository at this point in the history
D: parse const(T), immutable, inout and shared type qualifiers
  • Loading branch information
masatake committed May 1, 2023
2 parents 4622e54 + b7a7e08 commit 08b7295
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Units/parser-d.r/simple.d.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ quxx input.d /^ bool quxx;$/;" m union:Struct.Union file:
test.simple input.d /^module test.simple;$/;" M
tfun input.d /^ auto tfun(T)(T v)$/;" f class:Class
this input.d /^ public this(AliasInt x)$/;" f class:Class
type_con input.d /^const(int)* type_con;$/;" v
type_imm input.d /^immutable(int)* type_imm;$/;" v
type_shar input.d /^shared(int)[] type_shar;$/;" v
5 changes: 5 additions & 0 deletions Units/parser-d.r/simple.d.d/input.d
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ template Template(alias a, T...)

Object obj;

const(int)* type_con;
immutable(int)* type_imm;
inout(int)* f_inout(inout Object); // FIXME
shared(int)[] type_shar;

private:
int i;

Expand Down
24 changes: 21 additions & 3 deletions parsers/c-based.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ enum eKeywordId {
KEYWORD_FINAL, KEYWORD_FLOAT, KEYWORD_FOR, KEYWORD_FOREACH,
KEYWORD_FRIEND, KEYWORD_FUNCTION,
KEYWORD_GOTO,
KEYWORD_IF, KEYWORD_IMPLEMENTS, KEYWORD_IMPORT, KEYWORD_INLINE, KEYWORD_INT,
KEYWORD_IF, KEYWORD_IMMUTABLE, KEYWORD_IMPLEMENTS, KEYWORD_IMPORT,
KEYWORD_INLINE, KEYWORD_INT,
KEYWORD_INOUT, KEYWORD_INTERFACE,
KEYWORD_INTERNAL,
KEYWORD_LONG,
Expand All @@ -78,7 +79,7 @@ enum eKeywordId {
KEYWORD_OPERATOR, KEYWORD_OVERLOAD, KEYWORD_OVERRIDE,
KEYWORD_PACKAGE, KEYWORD_PRIVATE,
KEYWORD_PROTECTED, KEYWORD_PUBLIC,
KEYWORD_REGISTER, KEYWORD_RETURN,
KEYWORD_REGISTER, KEYWORD_RETURN, KEYWORD_SHARED,
KEYWORD_SHORT, KEYWORD_SIGNED, KEYWORD_STATIC, KEYWORD_STRING,
KEYWORD_STRUCT, KEYWORD_SWITCH, KEYWORD_SYNCHRONIZED,
KEYWORD_TEMPLATE, KEYWORD_THIS, KEYWORD_THROW,
Expand Down Expand Up @@ -419,6 +420,7 @@ static const keywordDesc KeywordTable [] = {
{ "idouble", KEYWORD_IDOUBLE, { 0, 1, 0 } },
{ "if", KEYWORD_IF, { 1, 1, 1 } },
{ "ifloat", KEYWORD_IFLOAT, { 0, 1, 0 } },
{ "immutable", KEYWORD_IMMUTABLE, { 0, 1, 0 } },
{ "implements", KEYWORD_IMPLEMENTS, { 0, 0, 1 } },
{ "import", KEYWORD_IMPORT, { 0, 1, 1 } },
{ "in", KEYWORD_IN, { 0, 1, 0 } },
Expand Down Expand Up @@ -452,6 +454,7 @@ static const keywordDesc KeywordTable [] = {
{ "register", KEYWORD_REGISTER, { 0, 1, 0 } },
{ "return", KEYWORD_RETURN, { 1, 1, 1 } },
{ "scope", KEYWORD_SCOPE, { 0, 1, 0 } },
{ "shared", KEYWORD_SHARED, { 0, 1, 0 } },
{ "short", KEYWORD_SHORT, { 1, 1, 1 } },
{ "signed", KEYWORD_SIGNED, { 0, 1, 0 } },
{ "static", KEYWORD_STATIC, { 1, 1, 1 } },
Expand Down Expand Up @@ -1877,7 +1880,16 @@ static void processToken (tokenInfo *const token, statementInfo *const st)
case KEYWORD_CATCH: skipParens (); skipBraces (); break;
case KEYWORD_CHAR: st->declaration = DECL_BASE; break;
case KEYWORD_CLASS: checkIsClassEnum (st, DECL_CLASS); break;
case KEYWORD_CONST: st->declaration = DECL_BASE; break;
case KEYWORD_IMMUTABLE:
case KEYWORD_INOUT:
case KEYWORD_SHARED:
if (!isInputLanguage (Lang_d))
break;
case KEYWORD_CONST:
st->declaration = DECL_BASE;
if (isInputLanguage (Lang_d))
skipParens ();
break;
case KEYWORD_DOUBLE: st->declaration = DECL_BASE; break;
case KEYWORD_ENUM: st->declaration = DECL_ENUM; break;
case KEYWORD_EXTENDS: readParents (st, '.');
Expand Down Expand Up @@ -2076,6 +2088,9 @@ static bool skipPostArgumentStuff (
case KEYWORD_TRY: break;

case KEYWORD_CONST:
case KEYWORD_IMMUTABLE:
case KEYWORD_INOUT:
case KEYWORD_SHARED:
case KEYWORD_VOLATILE:
if (vStringLength (Signature) > 0)
{
Expand Down Expand Up @@ -2381,6 +2396,9 @@ static int parseParens (statementInfo *const st, parenInfo *const info)
else if (isType (token, TOKEN_KEYWORD))
{
if (token->keyword != KEYWORD_CONST &&
token->keyword != KEYWORD_IMMUTABLE &&
token->keyword != KEYWORD_INOUT &&
token->keyword != KEYWORD_SHARED &&
token->keyword != KEYWORD_VOLATILE)
{
info->isNameCandidate = false;
Expand Down

0 comments on commit 08b7295

Please sign in to comment.