New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix Issue 20053 - add mixin types #10215
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6413,6 +6413,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol | |
if (ta) | ||
{ | ||
//printf("type %s\n", ta.toChars()); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated |
||
// It might really be an Expression or an Alias | ||
ta.resolve(loc, sc, &ea, &ta, &sa, (flags & 1) != 0); | ||
if (ea) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1929,19 +1929,7 @@ final class Parser(AST) : Lexer | |||||
// Get TemplateArgumentList | ||||||
while (token.value != endtok) | ||||||
{ | ||||||
// See if it is an Expression or a Type | ||||||
if (isDeclaration(&token, NeedDeclaratorId.no, TOK.reserved, null)) | ||||||
{ | ||||||
// Template argument is a type | ||||||
AST.Type ta = parseType(); | ||||||
tiargs.push(ta); | ||||||
} | ||||||
else | ||||||
{ | ||||||
// Template argument is an expression | ||||||
AST.Expression ea = parseAssignExp(); | ||||||
tiargs.push(ea); | ||||||
} | ||||||
tiargs.push(parseTypeOrAssignExp()); | ||||||
if (token.value != TOK.comma) | ||||||
break; | ||||||
nextToken(); | ||||||
|
@@ -1950,6 +1938,18 @@ final class Parser(AST) : Lexer | |||||
return tiargs; | ||||||
} | ||||||
|
||||||
/*************************************** | ||||||
* Parse a Type or an Expression | ||||||
* Returns: | ||||||
* RootObject representing the AST | ||||||
*/ | ||||||
RootObject parseTypeOrAssignExp() | ||||||
{ | ||||||
return isDeclaration(&token, NeedDeclaratorId.no, TOK.reserved, null) | ||||||
? parseType() // argument is a type | ||||||
: parseAssignExp(); // argument is an expression | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would have been better if this refactoring was in another PR |
||||||
} | ||||||
|
||||||
/***************************** | ||||||
* Parse single template argument, to support the syntax: | ||||||
* foo!arg | ||||||
|
@@ -3510,7 +3510,7 @@ final class Parser(AST) : Lexer | |||||
return decldefs; | ||||||
} | ||||||
|
||||||
private AST.Type parseType(Identifier* pident = null, AST.TemplateParameters** ptpl = null) | ||||||
AST.Type parseType(Identifier* pident = null, AST.TemplateParameters** ptpl = null) | ||||||
{ | ||||||
/* Take care of the storage class prefixes that | ||||||
* serve as type attributes: | ||||||
|
@@ -3712,6 +3712,15 @@ final class Parser(AST) : Lexer | |||||
} | ||||||
break; | ||||||
|
||||||
case TOK.mixin_: | ||||||
// https://dlang.org/spec/expression.html#mixin_types | ||||||
nextToken(); | ||||||
if (token.value != TOK.leftParentheses) | ||||||
error("found `%s` when expecting `%s` following %s", token.toChars(), Token.toChars(TOK.leftParentheses), "`mixin`".ptr); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
auto exps = parseArguments(); | ||||||
t = new AST.TypeMixin(exps); | ||||||
break; | ||||||
|
||||||
case TOK.dot: | ||||||
// Leading . as in .foo | ||||||
t = parseBasicTypeStartingAt(new AST.TypeIdentifier(token.loc, Id.empty), dontLookDotIdents); | ||||||
|
@@ -5630,6 +5639,8 @@ final class Parser(AST) : Lexer | |||||
} | ||||||
case TOK.mixin_: | ||||||
{ | ||||||
if (isDeclaration(&token, NeedDeclaratorId.mustIfDstyle, TOK.reserved, null)) | ||||||
goto Ldeclaration; | ||||||
Token* t = peek(&token); | ||||||
if (t.value == TOK.leftParentheses) | ||||||
{ | ||||||
|
@@ -6921,6 +6932,7 @@ final class Parser(AST) : Lexer | |||||
|
||||||
case TOK.typeof_: | ||||||
case TOK.vector: | ||||||
case TOK.mixin_: | ||||||
/* typeof(exp).identifier... | ||||||
*/ | ||||||
t = peek(t); | ||||||
|
@@ -7923,17 +7935,7 @@ final class Parser(AST) : Lexer | |||||
{ | ||||||
nextToken(); | ||||||
check(TOK.leftParentheses, "`typeid`"); | ||||||
RootObject o; | ||||||
if (isDeclaration(&token, NeedDeclaratorId.no, TOK.reserved, null)) | ||||||
{ | ||||||
// argument is a type | ||||||
o = parseType(); | ||||||
} | ||||||
else | ||||||
{ | ||||||
// argument is an expression | ||||||
o = parseAssignExp(); | ||||||
} | ||||||
RootObject o = parseTypeOrAssignExp(); | ||||||
check(TOK.rightParentheses); | ||||||
e = new AST.TypeidExp(loc, o); | ||||||
break; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused as to why this idiom was used here. It's just a more complicated way of saying... this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
arraySyntaxCopy
is used all over dmd, but is not available in astbase.d