| 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 statement_rewriter; | 5 part of tree_ir.optimization; |
| 6 | |
| 7 import '../tree_ir/tree_ir_nodes.dart'; | |
| 8 | 6 |
| 9 /** | 7 /** |
| 10 * Performs the following transformations on the tree: | 8 * Performs the following transformations on the tree: |
| 11 * - Assignment propagation | 9 * - Assignment propagation |
| 12 * - If-to-conditional conversion | 10 * - If-to-conditional conversion |
| 13 * - Flatten nested ifs | 11 * - Flatten nested ifs |
| 14 * - Break inlining | 12 * - Break inlining |
| 15 * - Redirect breaks | 13 * - Redirect breaks |
| 16 * | 14 * |
| 17 * The above transformations all eliminate statements from the tree, and may | 15 * The above transformations all eliminate statements from the tree, and may |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 * to their label are redirected. | 84 * to their label are redirected. |
| 87 * For example, where 'jump' is either break or continue: | 85 * For example, where 'jump' is either break or continue: |
| 88 * | 86 * |
| 89 * L0: {... break L0 ...}; jump L1 | 87 * L0: {... break L0 ...}; jump L1 |
| 90 * ==> | 88 * ==> |
| 91 * {... jump L1 ...} | 89 * {... jump L1 ...} |
| 92 * | 90 * |
| 93 * This may trigger a flattening of nested ifs in case the eliminated label | 91 * This may trigger a flattening of nested ifs in case the eliminated label |
| 94 * separated two ifs. | 92 * separated two ifs. |
| 95 */ | 93 */ |
| 96 class StatementRewriter extends Visitor<Statement, Expression> { | 94 class StatementRewriter extends Visitor<Statement, Expression> implements Pass { |
| 97 // The binding environment. The rightmost element of the list is the nearest | 95 // The binding environment. The rightmost element of the list is the nearest |
| 98 // available enclosing binding. | 96 // available enclosing binding. |
| 99 List<Assign> environment; | 97 List<Assign> environment; |
| 100 | 98 |
| 101 /// Substitution map for labels. Any break to a label L should be substituted | 99 /// Substitution map for labels. Any break to a label L should be substituted |
| 102 /// for a break to L' if L maps to L'. | 100 /// for a break to L' if L maps to L'. |
| 103 Map<Label, Jump> labelRedirects = <Label, Jump>{}; | 101 Map<Label, Jump> labelRedirects = <Label, Jump>{}; |
| 104 | 102 |
| 105 /// Returns the redirect target of [label] or [label] itself if it should not | 103 /// Returns the redirect target of [label] or [label] itself if it should not |
| 106 /// be redirected. | 104 /// be redirected. |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 542 } |
| 545 | 543 |
| 546 Expression makeCondition(Expression e, bool polarity) { | 544 Expression makeCondition(Expression e, bool polarity) { |
| 547 return polarity ? e : new Not(e); | 545 return polarity ? e : new Not(e); |
| 548 } | 546 } |
| 549 | 547 |
| 550 Statement getBranch(If node, bool polarity) { | 548 Statement getBranch(If node, bool polarity) { |
| 551 return polarity ? node.thenStatement : node.elseStatement; | 549 return polarity ? node.thenStatement : node.elseStatement; |
| 552 } | 550 } |
| 553 } | 551 } |
| OLD | NEW |