Skip to content

Commit

Permalink
Merge pull request #7126 from tgehr/fix17814
Browse files Browse the repository at this point in the history
fix Issue 17814 - bad output of "static foreach" with -vcg-ast
  • Loading branch information
WalterBright committed Sep 16, 2017
2 parents 891b53a + 448ce8d commit 591c7bb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/ddmd/hdrgen.d
Expand Up @@ -247,7 +247,7 @@ public:
buf.writenl();
}

override void visit(ForeachStatement s)
private void visitWithoutBody(ForeachStatement s)
{
buf.writestring(Token.toString(s.op));
buf.writestring(" (");
Expand All @@ -266,6 +266,11 @@ public:
s.aggr.accept(this);
buf.writeByte(')');
buf.writenl();
}

override void visit(ForeachStatement s)
{
visitWithoutBody(s);
buf.writeByte('{');
buf.writenl();
buf.level++;
Expand All @@ -276,7 +281,7 @@ public:
buf.writenl();
}

override void visit(ForeachRangeStatement s)
private void visitWithoutBody(ForeachRangeStatement s)
{
buf.writestring(Token.toString(s.op));
buf.writestring(" (");
Expand All @@ -292,6 +297,11 @@ public:
buf.writenl();
buf.writeByte('{');
buf.writenl();
}

override void visit(ForeachRangeStatement s)
{
visitWithoutBody(s);
buf.level++;
if (s._body)
s._body.accept(this);
Expand Down Expand Up @@ -1346,6 +1356,28 @@ public:
buf.writenl();
}

override void visit(StaticForeachDeclaration s)
{
buf.writestring("static ");
if (s.sfe.aggrfe)
{
visitWithoutBody(s.sfe.aggrfe);
}
else
{
assert(s.sfe.rangefe);
visitWithoutBody(s.sfe.rangefe);
}
buf.writeByte('{');
buf.writenl();
buf.level++;
visit(cast(AttribDeclaration)s);
buf.level--;
buf.writeByte('}');
buf.writenl();

}

override void visit(CompileDeclaration d)
{
buf.writestring("mixin(");
Expand Down Expand Up @@ -1760,6 +1792,8 @@ public:

override void visit(AliasDeclaration d)
{
if (d.storage_class & STClocal)
return;
buf.writestring("alias ");
if (d.aliassym)
{
Expand Down Expand Up @@ -1791,6 +1825,8 @@ public:

override void visit(VarDeclaration d)
{
if (d.storage_class & STClocal)
return;
visitVarDecl(d, false);
buf.writeByte(';');
buf.writenl();
Expand Down
14 changes: 14 additions & 0 deletions test/compilable/vcg-ast.d
Expand Up @@ -16,3 +16,17 @@ template R(T)
}

typeof(R!int._R.elem) x;


static foreach(enum i; 0..3)
{
mixin("int a" ~ i.stringof ~ " = 1;");
}

void foo()
{
static foreach(enum i; 0..3)
{
mixin("int a" ~ i.stringof ~ " = 1;");
}
}

0 comments on commit 591c7bb

Please sign in to comment.