| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of tree_ir.optimization; | 5 part of tree_ir.optimization; |
| 6 | 6 |
| 7 /// Rewrites [WhileTrue] statements with an [If] body into a [WhileCondition], | 7 /// Rewrites [WhileTrue] statements with an [If] body into a [WhileCondition], |
| 8 /// in situations where only one of the branches contains a [Continue] to the | 8 /// in situations where only one of the branches contains a [Continue] to the |
| 9 /// loop. Schematically: | 9 /// loop. Schematically: |
| 10 /// | 10 /// |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 /// while (E) { | 21 /// while (E) { |
| 22 /// S1 | 22 /// S1 |
| 23 /// }; | 23 /// }; |
| 24 /// S2 | 24 /// S2 |
| 25 /// | 25 /// |
| 26 /// A similar transformation is used when S2 occurs in the 'then' position. | 26 /// A similar transformation is used when S2 occurs in the 'then' position. |
| 27 /// | 27 /// |
| 28 /// Note that the above pattern needs no iteration since nested ifs | 28 /// Note that the above pattern needs no iteration since nested ifs |
| 29 /// have been collapsed previously in the [StatementRewriter] phase. | 29 /// have been collapsed previously in the [StatementRewriter] phase. |
| 30 class LoopRewriter extends RecursiveVisitor with PassMixin { | 30 class LoopRewriter extends RecursiveVisitor with PassMixin { |
| 31 String get passName => 'Loop rewriter'; |
| 31 | 32 |
| 32 Set<Label> usedContinueLabels = new Set<Label>(); | 33 Set<Label> usedContinueLabels = new Set<Label>(); |
| 33 | 34 |
| 34 void rewriteExecutableDefinition(ExecutableDefinition root) { | 35 void rewriteExecutableDefinition(ExecutableDefinition root) { |
| 35 root.body = visitStatement(root.body); | 36 root.body = visitStatement(root.body); |
| 36 } | 37 } |
| 37 | 38 |
| 38 Statement visitLabeledStatement(LabeledStatement node) { | 39 Statement visitLabeledStatement(LabeledStatement node) { |
| 39 node.body = visitStatement(node.body); | 40 node.body = visitStatement(node.body); |
| 40 node.next = visitStatement(node.next); | 41 node.next = visitStatement(node.next); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 137 } |
| 137 | 138 |
| 138 Statement visitSetField(SetField node) { | 139 Statement visitSetField(SetField node) { |
| 139 visitExpression(node.object); | 140 visitExpression(node.object); |
| 140 visitExpression(node.value); | 141 visitExpression(node.value); |
| 141 node.next = visitStatement(node.next); | 142 node.next = visitStatement(node.next); |
| 142 return node; | 143 return node; |
| 143 } | 144 } |
| 144 | 145 |
| 145 } | 146 } |
| OLD | NEW |