| 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 25 matching lines...) Expand all Loading... |
| 36 root.body = visitStatement(root.body); | 36 root.body = visitStatement(root.body); |
| 37 } | 37 } |
| 38 | 38 |
| 39 Statement visitLabeledStatement(LabeledStatement node) { | 39 Statement visitLabeledStatement(LabeledStatement node) { |
| 40 node.body = visitStatement(node.body); | 40 node.body = visitStatement(node.body); |
| 41 node.next = visitStatement(node.next); | 41 node.next = visitStatement(node.next); |
| 42 return node; | 42 return node; |
| 43 } | 43 } |
| 44 | 44 |
| 45 Statement visitAssign(Assign node) { | 45 Statement visitAssign(Assign node) { |
| 46 // Clean up redundant assignments left behind in the previous phase. | |
| 47 Expression value = node.value; | |
| 48 if (value is VariableUse && node.variable == value.variable) { | |
| 49 --node.variable.readCount; | |
| 50 --node.variable.writeCount; | |
| 51 return visitStatement(node.next); | |
| 52 } | |
| 53 visitExpression(node.value); | 46 visitExpression(node.value); |
| 54 node.next = visitStatement(node.next); | 47 node.next = visitStatement(node.next); |
| 55 return node; | 48 return node; |
| 56 } | 49 } |
| 57 | 50 |
| 58 Statement visitReturn(Return node) { | 51 Statement visitReturn(Return node) { |
| 59 visitExpression(node.value); | 52 visitExpression(node.value); |
| 60 return node; | 53 return node; |
| 61 } | 54 } |
| 62 | 55 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 } | 130 } |
| 138 | 131 |
| 139 Statement visitSetField(SetField node) { | 132 Statement visitSetField(SetField node) { |
| 140 visitExpression(node.object); | 133 visitExpression(node.object); |
| 141 visitExpression(node.value); | 134 visitExpression(node.value); |
| 142 node.next = visitStatement(node.next); | 135 node.next = visitStatement(node.next); |
| 143 return node; | 136 return node; |
| 144 } | 137 } |
| 145 | 138 |
| 146 } | 139 } |
| OLD | NEW |