Chromium Code Reviews| Index: lib/compiler/implementation/dart_backend/backend.dart |
| diff --git a/lib/compiler/implementation/dart_backend/backend.dart b/lib/compiler/implementation/dart_backend/backend.dart |
| index 0f9ec2b54a12308d9798526044d4b42cdb481b2d..e9af56a075b73bd0ec0d47a1505afc6f1a297342 100644 |
| --- a/lib/compiler/implementation/dart_backend/backend.dart |
| +++ b/lib/compiler/implementation/dart_backend/backend.dart |
| @@ -82,13 +82,28 @@ class FunctionBodyRewriter extends CloningVisitor { |
| return false; |
| } |
| + rewritTo(Statement statement) { |
|
Roman
2012/09/21 12:10:27
tryRewriteSingleStatementBlock?
Anton Muhin
2012/09/21 12:13:08
There should be no references to single statement
Roman
2012/09/21 12:16:00
then just rewriteStatement?
side note: does 'try'
|
| + if (statement is Block) { |
| + Link statements = statement.statements.nodes; |
| + if (!statements.isEmpty() && statements.tail.isEmpty()) { |
| + Statement single = statements.head; |
| + bool isDeclaration = |
| + single is VariableDefinitions || single is FunctionDeclaration; |
| + if (!isDeclaration) return single; |
| + } |
| + } |
| + return statement; |
| + } |
| + |
| rewriteBody(Statement body) { |
| if (body is !Block) return visit(body); |
| Block block = body; |
| NodeList statements = block.statements; |
| LinkBuilder<Statement> builder = new LinkBuilder<Statement>(); |
| for (Statement statement in statements.nodes) { |
| - if (!shouldOmit(statement)) builder.addLast(visit(statement)); |
| + if (!shouldOmit(statement)) { |
| + builder.addLast(visit(rewritTo(statement))); |
| + } |
| } |
| return new Block(rewriteNodeList(statements, builder.toLink())); |
| } |