Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/dparse/ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,9 @@ final class AlignAttribute : BaseNode
}
mixin OpEquals;
/** */ ExpressionNode assignExpression;
/** */ bool isExplicitDefault() inout @property @safe nothrow @nogc pure {
return tokens.length > 2 && tokens[2] == tok!"default";
}
}

///
Expand Down Expand Up @@ -4203,7 +4206,7 @@ unittest // Differentiate between no and empty DDOC comments, e.g. for DDOC unit
assert(visitor.found.length == 6);
}

unittest // Support GCC-sytle asm statements
unittest // Support GCC-style asm statements
{
static void verify(T)(const string code, void function(scope const T) handler)
{
Expand Down
5 changes: 4 additions & 1 deletion src/dparse/formatter.d
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class Formatter(Sink)
**/

put("align");
if (alignAttribute.assignExpression !is null)
if (alignAttribute.isExplicitDefault)
put("(default)");
else if (alignAttribute.assignExpression !is null)
{
put("(");
format(alignAttribute.assignExpression);
Expand Down Expand Up @@ -4407,4 +4409,5 @@ z /// Documentation for z
testFormatNode!(VariableDeclaration)("auto x = i` $(b) is $(b)!`;");
testFormatNode!(VariableDeclaration)("auto x = iq{ $(b) is $(b)!};");
testFormatNode!(VariableDeclaration)("auto x = iq{{$('$')}};");
testFormatNode!(AlignAttribute)(`align(default) struct S {}`, `align(default)`);
}
2 changes: 1 addition & 1 deletion src/dparse/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private immutable operators = [
"^=", "^^", "^^=", "{", "|", "|=", "||", "}", "~", "~="
];

/// Kewords
/// Keywords
private immutable keywords = [
"abstract", "alias", "align", "asm", "assert", "auto", "bool",
"break", "byte", "case", "cast", "catch", "cdouble", "cent", "cfloat",
Expand Down
9 changes: 7 additions & 2 deletions src/dparse/parser.d
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ class Parser
* Parses an AlignAttribute.
*
* $(GRAMMAR $(RULEDEF alignAttribute):
* $(LITERAL 'align') ($(LITERAL '$(LPAREN)') $(RULE assignExpression) $(LITERAL '$(RPAREN)'))?
* $(LITERAL 'align')
* $(LITERAL 'align') $(LITERAL '$(LPAREN)') $(RULE assignExpression) $(LITERAL '$(RPAREN)')
* $(LITERAL 'align') $(LITERAL '$(LPAREN)') $(LITERAL 'default') $(LITERAL '$(RPAREN)')
* ;)
*/
AlignAttribute parseAlignAttribute()
Expand All @@ -312,7 +314,10 @@ class Parser
if (currentIs(tok!"("))
{
mixin(tokenCheck!"(");
mixin(parseNodeQ!("node.assignExpression", "AssignExpression"));
if (currentIs(tok!"default"))
advance();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is implicitly stored in the AST now (due to it having the tokens slice), but it's missing a boolean getter (e.g. bool isExplicitDefault()) inside AlignAttribute

The formatter.d code also needs to be adjusted to re-emit it in case it was explicit default.

else
mixin(parseNodeQ!("node.assignExpression", "AssignExpression"));
mixin(tokenCheck!")");
}
node.tokens = tokens[startIndex .. index];
Expand Down
16 changes: 16 additions & 0 deletions test/pass_files/issue0523.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct S
{
align(1)
{
short x1;
int y1;
long z1;

align(default)
{
short x;
int y;
long z;
}
}
}
Loading