| 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 library tree_ir.optimization.logical_rewriter; | 5 library tree_ir.optimization.logical_rewriter; |
| 6 | 6 |
| 7 import '../tree_ir_nodes.dart'; | 7 import '../tree_ir_nodes.dart'; |
| 8 import 'optimization.dart' show Pass; | 8 import 'optimization.dart' show Pass; |
| 9 import '../../constants/values.dart' as values; | 9 import '../../constants/values.dart' as values; |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 return node.target.binding == target || | 88 return node.target.binding == target || |
| 89 target is Continue && target.target == node.target; | 89 target is Continue && target.target == node.target; |
| 90 } | 90 } |
| 91 | 91 |
| 92 bool isFallthroughReturn(Return node) { | 92 bool isFallthroughReturn(Return node) { |
| 93 return isNull(node.value) && fallthrough.target == null; | 93 return isNull(node.value) && fallthrough.target == null; |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool isTerminator(Statement node) { | 96 bool isTerminator(Statement node) { |
| 97 return (node is Jump || node is Return) && !isFallthrough(node) || | 97 return (node is Jump || node is Return) && !isFallthrough(node) || |
| 98 (node is ExpressionStatement && node.next is Unreachable); | 98 (node is ExpressionStatement && node.next is Unreachable) || |
| 99 node is Throw; |
| 99 } | 100 } |
| 100 | 101 |
| 101 Statement visitIf(If node) { | 102 Statement visitIf(If node) { |
| 102 // If one of the branches is empty (i.e. just a fallthrough), then that | 103 // If one of the branches is empty (i.e. just a fallthrough), then that |
| 103 // branch should preferably be the 'else' so we won't have to print it. | 104 // branch should preferably be the 'else' so we won't have to print it. |
| 104 // In other words, we wish to perform this rewrite: | 105 // In other words, we wish to perform this rewrite: |
| 105 // if (E) {} else {S} | 106 // if (E) {} else {S} |
| 106 // ==> | 107 // ==> |
| 107 // if (!E) {S} | 108 // if (!E) {S} |
| 108 // In the tree language, empty statements do not exist yet, so we must check | 109 // In the tree language, empty statements do not exist yet, so we must check |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 return e2 is VariableUse && e1.variable == e2.variable; | 546 return e2 is VariableUse && e1.variable == e2.variable; |
| 546 } | 547 } |
| 547 return false; | 548 return false; |
| 548 } | 549 } |
| 549 | 550 |
| 550 void destroyVariableUse(VariableUse node) { | 551 void destroyVariableUse(VariableUse node) { |
| 551 --node.variable.readCount; | 552 --node.variable.readCount; |
| 552 } | 553 } |
| 553 } | 554 } |
| 554 | 555 |
| OLD | NEW |