Properly recurse in ForLoopInitRewriter

This commit is contained in:
Daniel Kirchner
2018-12-04 13:36:25 +01:00
parent e49f37be7f
commit 1b8a013d4a
3 changed files with 62 additions and 7 deletions
+9 -2
View File
@@ -27,17 +27,24 @@ void ForLoopInitRewriter::operator()(Block& _block)
{
iterateReplacing(
_block.statements,
[](Statement& _stmt) -> boost::optional<vector<Statement>>
[&](Statement& _stmt) -> boost::optional<vector<Statement>>
{
if (_stmt.type() == typeid(ForLoop))
{
auto& forLoop = boost::get<ForLoop>(_stmt);
(*this)(forLoop.pre);
(*this)(forLoop.body);
(*this)(forLoop.post);
vector<Statement> rewrite;
swap(rewrite, forLoop.pre.statements);
rewrite.emplace_back(move(forLoop));
return rewrite;
}
return {};
else
{
visit(_stmt);
return {};
}
}
);
}