Skip to content

Commit

Permalink
fix Issue 17814 - bad output of "static foreach" with -vcg-ast
Browse files Browse the repository at this point in the history
  • Loading branch information
tgehr committed Sep 10, 2017
1 parent 365e392 commit 4317772
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/ddmd/hdrgen.d
Original file line number Diff line number Diff line change
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
14 changes: 14 additions & 0 deletions test/compilable/vcg-ast.d
Original file line number Diff line number Diff line change
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 4317772

Please sign in to comment.