| 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 '../constants/values.dart' as values; | 8 import '../constants/values.dart' as values; |
| 9 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 9 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| (...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 final Reference<Continuation> trueContinuation; | 1189 final Reference<Continuation> trueContinuation; |
| 1190 final Reference<Continuation> falseContinuation; | 1190 final Reference<Continuation> falseContinuation; |
| 1191 | 1191 |
| 1192 /// If true, only the value `true` satisfies the condition. Otherwise, any | 1192 /// If true, only the value `true` satisfies the condition. Otherwise, any |
| 1193 /// truthy value satisfies the check. | 1193 /// truthy value satisfies the check. |
| 1194 /// | 1194 /// |
| 1195 /// Non-strict checks are preferable when the condition is known to be a | 1195 /// Non-strict checks are preferable when the condition is known to be a |
| 1196 /// boolean. | 1196 /// boolean. |
| 1197 bool isStrictCheck; | 1197 bool isStrictCheck; |
| 1198 | 1198 |
| 1199 Branch(Primitive condition, |
| 1200 Continuation trueCont, |
| 1201 Continuation falseCont, |
| 1202 {bool strict}) |
| 1203 : this.condition = new Reference<Primitive>(condition), |
| 1204 trueContinuation = new Reference<Continuation>(trueCont), |
| 1205 falseContinuation = new Reference<Continuation>(falseCont), |
| 1206 isStrictCheck = strict { |
| 1207 assert(strict != null); |
| 1208 } |
| 1209 |
| 1199 Branch.strict(Primitive condition, | 1210 Branch.strict(Primitive condition, |
| 1200 Continuation trueCont, | 1211 Continuation trueCont, |
| 1201 Continuation falseCont) | 1212 Continuation falseCont) |
| 1202 : this.condition = new Reference<Primitive>(condition), | 1213 : this(condition, trueCont, falseCont, strict: true); |
| 1203 trueContinuation = new Reference<Continuation>(trueCont), | |
| 1204 falseContinuation = new Reference<Continuation>(falseCont), | |
| 1205 isStrictCheck = true; | |
| 1206 | 1214 |
| 1207 Branch.loose(Primitive condition, | 1215 Branch.loose(Primitive condition, |
| 1208 Continuation trueCont, | 1216 Continuation trueCont, |
| 1209 Continuation falseCont) | 1217 Continuation falseCont) |
| 1210 : this.condition = new Reference<Primitive>(condition), | 1218 : this(condition, trueCont, falseCont, strict: false); |
| 1211 trueContinuation = new Reference<Continuation>(trueCont), | |
| 1212 falseContinuation = new Reference<Continuation>(falseCont), | |
| 1213 this.isStrictCheck = false; | |
| 1214 | 1219 |
| 1215 accept(BlockVisitor visitor) => visitor.visitBranch(this); | 1220 accept(BlockVisitor visitor) => visitor.visitBranch(this); |
| 1216 | 1221 |
| 1217 void setParentPointers() { | 1222 void setParentPointers() { |
| 1218 condition.parent = this; | 1223 condition.parent = this; |
| 1219 trueContinuation.parent = this; | 1224 trueContinuation.parent = this; |
| 1220 falseContinuation.parent = this; | 1225 falseContinuation.parent = this; |
| 1221 } | 1226 } |
| 1222 } | 1227 } |
| 1223 | 1228 |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 node = node.next; | 1907 node = node.next; |
| 1903 nodes.add(node); | 1908 nodes.add(node); |
| 1904 } | 1909 } |
| 1905 } | 1910 } |
| 1906 walkBlock(root); | 1911 walkBlock(root); |
| 1907 while (stack.isNotEmpty) { | 1912 while (stack.isNotEmpty) { |
| 1908 walkBlock(stack.removeLast()); | 1913 walkBlock(stack.removeLast()); |
| 1909 } | 1914 } |
| 1910 nodes.reversed.forEach(v.visit); | 1915 nodes.reversed.forEach(v.visit); |
| 1911 } | 1916 } |
| 1917 |
| 1918 /// Visits block-level nodes in lexical pre-order. |
| 1919 /// |
| 1920 /// The IR may be transformed during the traversal, but the currently |
| 1921 /// visited node should not be removed, as its 'body' pointer is needed |
| 1922 /// for the traversal. |
| 1923 static void traverseInPreOrder(FunctionDefinition root, BlockVisitor v) { |
| 1924 List<Continuation> stack = <Continuation>[]; |
| 1925 void walkBlock(InteriorNode block) { |
| 1926 v.visit(block); |
| 1927 Expression node = block.body; |
| 1928 v.visit(node); |
| 1929 while (node.next != null) { |
| 1930 if (node is LetCont) { |
| 1931 stack.addAll(node.continuations); |
| 1932 } else if (node is LetHandler) { |
| 1933 stack.add(node.handler); |
| 1934 } |
| 1935 node = node.next; |
| 1936 v.visit(node); |
| 1937 } |
| 1938 } |
| 1939 walkBlock(root); |
| 1940 while (stack.isNotEmpty) { |
| 1941 walkBlock(stack.removeLast()); |
| 1942 } |
| 1943 } |
| 1912 } | 1944 } |
| 1913 | 1945 |
| 1914 abstract class Visitor<T> implements BlockVisitor<T> { | 1946 abstract class Visitor<T> implements BlockVisitor<T> { |
| 1915 const Visitor(); | 1947 const Visitor(); |
| 1916 | 1948 |
| 1917 T visit(Node node); | 1949 T visit(Node node); |
| 1918 | 1950 |
| 1919 // Definitions. | 1951 // Definitions. |
| 1920 T visitInvokeStatic(InvokeStatic node); | 1952 T visitInvokeStatic(InvokeStatic node); |
| 1921 T visitInvokeMethod(InvokeMethod node); | 1953 T visitInvokeMethod(InvokeMethod node); |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2794 plug(new Branch.loose(_definitions.getCopy(node.condition), | 2826 plug(new Branch.loose(_definitions.getCopy(node.condition), |
| 2795 _copies[node.trueContinuation.definition], | 2827 _copies[node.trueContinuation.definition], |
| 2796 _copies[node.falseContinuation.definition]) | 2828 _copies[node.falseContinuation.definition]) |
| 2797 ..isStrictCheck = node.isStrictCheck); | 2829 ..isStrictCheck = node.isStrictCheck); |
| 2798 } | 2830 } |
| 2799 | 2831 |
| 2800 visitUnreachable(Unreachable node) { | 2832 visitUnreachable(Unreachable node) { |
| 2801 plug(new Unreachable()); | 2833 plug(new Unreachable()); |
| 2802 } | 2834 } |
| 2803 } | 2835 } |
| OLD | NEW |