| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library dart2js.ir_nodes; | 4 library dart2js.ir_nodes; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'cps_fragment.dart' show CpsFragment; | 7 import 'cps_fragment.dart' show CpsFragment; |
| 8 import 'cps_ir_nodes_sexpr.dart'; | 8 import 'cps_ir_nodes_sexpr.dart'; |
| 9 import '../constants/values.dart' as values; | 9 import '../constants/values.dart' as values; |
| 10 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 10 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
| (...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2004 } | 2004 } |
| 2005 walkBlock(root); | 2005 walkBlock(root); |
| 2006 while (stack.isNotEmpty) { | 2006 while (stack.isNotEmpty) { |
| 2007 walkBlock(stack.removeLast()); | 2007 walkBlock(stack.removeLast()); |
| 2008 } | 2008 } |
| 2009 nodes.reversed.forEach(v.visit); | 2009 nodes.reversed.forEach(v.visit); |
| 2010 } | 2010 } |
| 2011 | 2011 |
| 2012 /// Visits block-level nodes in lexical pre-order. | 2012 /// Visits block-level nodes in lexical pre-order. |
| 2013 /// | 2013 /// |
| 2014 /// The IR may be transformed during the traversal, but the currently | 2014 /// Traversal continues at the original success for the current node, so: |
| 2015 /// visited node should not be removed, as its 'body' pointer is needed | 2015 /// - The current node can safely be removed. |
| 2016 /// for the traversal. | 2016 /// - Nodes inserted immediately below the current node will not be seen. |
| 2017 /// - The body of the current node should not be moved/removed, as traversal |
| 2018 /// would otherwise continue into an orphaned or relocated node. |
| 2017 static void traverseInPreOrder(FunctionDefinition root, BlockVisitor v) { | 2019 static void traverseInPreOrder(FunctionDefinition root, BlockVisitor v) { |
| 2018 List<Continuation> stack = <Continuation>[]; | 2020 List<Continuation> stack = <Continuation>[]; |
| 2019 void walkBlock(InteriorNode block) { | 2021 void walkBlock(InteriorNode block) { |
| 2020 v.visit(block); | 2022 v.visit(block); |
| 2021 Expression node = block.body; | 2023 Expression node = block.body; |
| 2022 v.visit(node); | 2024 while (node != null) { |
| 2023 while (node.next != null) { | |
| 2024 if (node is LetCont) { | 2025 if (node is LetCont) { |
| 2025 stack.addAll(node.continuations); | 2026 stack.addAll(node.continuations); |
| 2026 } else if (node is LetHandler) { | 2027 } else if (node is LetHandler) { |
| 2027 stack.add(node.handler); | 2028 stack.add(node.handler); |
| 2028 } | 2029 } |
| 2029 node = node.next; | 2030 Expression next = node.next; |
| 2030 v.visit(node); | 2031 v.visit(node); |
| 2032 node = next; |
| 2031 } | 2033 } |
| 2032 } | 2034 } |
| 2033 walkBlock(root); | 2035 walkBlock(root); |
| 2034 while (stack.isNotEmpty) { | 2036 while (stack.isNotEmpty) { |
| 2035 walkBlock(stack.removeLast()); | 2037 walkBlock(stack.removeLast()); |
| 2036 } | 2038 } |
| 2037 } | 2039 } |
| 2038 } | 2040 } |
| 2039 | 2041 |
| 2040 abstract class Visitor<T> implements BlockVisitor<T> { | 2042 abstract class Visitor<T> implements BlockVisitor<T> { |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2909 plug(new Branch.loose(_definitions.getCopy(node.condition), | 2911 plug(new Branch.loose(_definitions.getCopy(node.condition), |
| 2910 _copies[node.trueContinuation.definition], | 2912 _copies[node.trueContinuation.definition], |
| 2911 _copies[node.falseContinuation.definition]) | 2913 _copies[node.falseContinuation.definition]) |
| 2912 ..isStrictCheck = node.isStrictCheck); | 2914 ..isStrictCheck = node.isStrictCheck); |
| 2913 } | 2915 } |
| 2914 | 2916 |
| 2915 visitUnreachable(Unreachable node) { | 2917 visitUnreachable(Unreachable node) { |
| 2916 plug(new Unreachable()); | 2918 plug(new Unreachable()); |
| 2917 } | 2919 } |
| 2918 } | 2920 } |
| OLD | NEW |