Skip to content

Commit

Permalink
Merge pull request #6855 from WalterBright/DIP1003
Browse files Browse the repository at this point in the history
DIP1003: Remove body as a Keyword
  • Loading branch information
WalterBright committed Jun 10, 2017
2 parents f1ecc9d + d0fabaa commit 175638f
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 113 deletions.
1 change: 1 addition & 0 deletions src/ddmd/idgen.d
Expand Up @@ -88,6 +88,7 @@ Msgtable[] msgtable =
{ "cpp_type_info_ptr", "__cpp_type_info_ptr" },
{ "_assert", "assert" },
{ "_unittest", "unittest" },
{ "_body", "body" },

{ "TypeInfo" },
{ "TypeInfo_Class" },
Expand Down
25 changes: 21 additions & 4 deletions src/ddmd/parse.d
Expand Up @@ -780,7 +780,10 @@ final class Parser(AST) : Lexer

/* Look for return type inference for template functions.
*/
if (token.value == TOKidentifier && skipParens(peek(&token), &tk) && skipAttributes(tk, &tk) && (tk.value == TOKlparen || tk.value == TOKlcurly || tk.value == TOKin || tk.value == TOKout || tk.value == TOKbody))
if (token.value == TOKidentifier && skipParens(peek(&token), &tk) && skipAttributes(tk, &tk) &&
(tk.value == TOKlparen || tk.value == TOKlcurly || tk.value == TOKin ||
tk.value == TOKout || tk.value == TOKdo ||
tk.value == TOKidentifier && tk.ident == Id._body))
{
a = parseDeclarations(true, pAttrs, pAttrs.comment);
if (a && a.dim)
Expand Down Expand Up @@ -4303,7 +4306,10 @@ final class Parser(AST) : Lexer

/* Look for return type inference for template functions.
*/
if ((storage_class || udas) && token.value == TOKidentifier && skipParens(peek(&token), &tk) && skipAttributes(tk, &tk) && (tk.value == TOKlparen || tk.value == TOKlcurly || tk.value == TOKin || tk.value == TOKout || tk.value == TOKbody))
if ((storage_class || udas) && token.value == TOKidentifier && skipParens(peek(&token), &tk) &&
skipAttributes(tk, &tk) &&
(tk.value == TOKlparen || tk.value == TOKlcurly || tk.value == TOKin || tk.value == TOKout ||
tk.value == TOKdo || tk.value == TOKidentifier && tk.ident == Id._body))
{
ts = null;
}
Expand Down Expand Up @@ -4662,7 +4668,12 @@ final class Parser(AST) : Lexer
f.endloc = endloc;
break;

case TOKbody:
case TOKidentifier:
if (token.ident == Id._body)
goto case TOKdo;
goto default;

case TOKdo:
nextToken();
f.fbody = parseStatement(PScurly);
f.endloc = endloc;
Expand Down Expand Up @@ -6609,7 +6620,7 @@ final class Parser(AST) : Lexer
case TOKlcurly:
case TOKin:
case TOKout:
case TOKbody:
case TOKdo:
// The !parens is to disallow unnecessary parentheses
if (!parens && (endtok == TOKreserved || endtok == t.value))
{
Expand All @@ -6618,13 +6629,19 @@ final class Parser(AST) : Lexer
}
return false;

case TOKidentifier:
if (t.ident == Id._body)
goto case TOKdo;
goto default;

case TOKif:
return haveTpl ? true : false;

default:
return false;
}
}
assert(0);
}

bool isParameters(Token** pt)
Expand Down
4 changes: 0 additions & 4 deletions src/ddmd/tokens.d
Expand Up @@ -267,7 +267,6 @@ enum TOK : int

// 213
// Contracts
TOKbody,
TOKinvariant,

// Testing
Expand Down Expand Up @@ -520,7 +519,6 @@ alias TOKscope = TOK.TOKscope;
alias TOKon_scope_exit = TOK.TOKon_scope_exit;
alias TOKon_scope_failure = TOK.TOKon_scope_failure;
alias TOKon_scope_success = TOK.TOKon_scope_success;
alias TOKbody = TOK.TOKbody;
alias TOKinvariant = TOK.TOKinvariant;
alias TOKunittest = TOK.TOKunittest;
alias TOKargTypes = TOK.TOKargTypes;
Expand Down Expand Up @@ -674,7 +672,6 @@ extern (C++) struct Token
TOKprotected: "protected",
TOKpublic: "public",
TOKexport: "export",
TOKbody: "body",
TOKinvariant: "invariant",
TOKunittest: "unittest",
TOKversion: "version",
Expand Down Expand Up @@ -1167,7 +1164,6 @@ private immutable TOK[] keywords =
TOKprotected,
TOKpublic,
TOKexport,
TOKbody,
TOKinvariant,
TOKunittest,
TOKversion,
Expand Down
24 changes: 24 additions & 0 deletions test/fail_compilation/failcontracts.d
@@ -0,0 +1,24 @@
/* TEST_OUTPUT:
---
fail_compilation/failcontracts.d(18): Error: missing { ... } for function literal
fail_compilation/failcontracts.d(18): Error: semicolon expected following auto declaration, not 'bode'
fail_compilation/failcontracts.d(19): Error: function declaration without return type. (Note that constructors are always named 'this')
fail_compilation/failcontracts.d(19): Error: no identifier for declarator test1()
fail_compilation/failcontracts.d(19): Error: semicolon expected following function declaration
fail_compilation/failcontracts.d(20): Error: semicolon expected following function declaration
fail_compilation/failcontracts.d(22): Error: unexpected ( in declarator
fail_compilation/failcontracts.d(22): Error: found 'T' when expecting ')'
fail_compilation/failcontracts.d(22): Error: enum declaration is invalid
fail_compilation/failcontracts.d(22): Error: found ')' instead of statement
---
*/

void test()
{
auto f1 = function() bode;
auto test1() bode;
auto test2()() bode;

enum : int (int function() bode T);
}

0 comments on commit 175638f

Please sign in to comment.