| 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 '../constants/values.dart' as values; | 7 import '../constants/values.dart' as values; |
| 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../io/source_information.dart' show SourceInformation; | 10 import '../io/source_information.dart' show SourceInformation; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void set body(Expression body); | 69 void set body(Expression body); |
| 70 } | 70 } |
| 71 | 71 |
| 72 /// An expression that creates new bindings and continues evaluation in | 72 /// An expression that creates new bindings and continues evaluation in |
| 73 /// a subexpression. | 73 /// a subexpression. |
| 74 /// | 74 /// |
| 75 /// The interior expressions are [LetPrim], [LetCont], [LetHandler], and | 75 /// The interior expressions are [LetPrim], [LetCont], [LetHandler], and |
| 76 /// [LetMutable]. | 76 /// [LetMutable]. |
| 77 abstract class InteriorExpression extends Expression implements InteriorNode { | 77 abstract class InteriorExpression extends Expression implements InteriorNode { |
| 78 Expression get next => body; | 78 Expression get next => body; |
| 79 |
| 80 /// Removes this expression from its current position in the IR. |
| 81 /// |
| 82 /// The node can be re-inserted elsewhere or remain orphaned. |
| 83 /// |
| 84 /// If orphaned, the caller is responsible for unlinking all references in |
| 85 /// the orphaned node. Use [Reference.unlink] or [Primitive.destroy] for this. |
| 86 void remove() { |
| 87 assert(parent != null); |
| 88 assert(parent.body == this); |
| 89 assert(body.parent == this); |
| 90 parent.body = body; |
| 91 body.parent = parent; |
| 92 parent = null; |
| 93 body = null; |
| 94 } |
| 95 |
| 96 /// Inserts this above [node]. |
| 97 /// |
| 98 /// This node must be orphaned first. |
| 99 void insertAbove(Expression node) { |
| 100 insertBelow(node.parent); |
| 101 } |
| 102 |
| 103 /// Inserts this below [node]. |
| 104 /// |
| 105 /// This node must be orphaned first. |
| 106 void insertBelow(InteriorNode newParent) { |
| 107 assert(parent == null); |
| 108 assert(body == null); |
| 109 Expression child = newParent.body; |
| 110 newParent.body = this; |
| 111 this.body = child; |
| 112 child.parent = this; |
| 113 this.parent = newParent; |
| 114 } |
| 79 } | 115 } |
| 80 | 116 |
| 81 /// An expression that passes a continuation to a call. | 117 /// An expression that passes a continuation to a call. |
| 82 abstract class CallExpression extends Expression { | 118 abstract class CallExpression extends Expression { |
| 83 Reference<Continuation> get continuation; | 119 Reference<Continuation> get continuation; |
| 84 Expression get next => continuation.definition.body; | 120 Expression get next => continuation.definition.body; |
| 85 } | 121 } |
| 86 | 122 |
| 87 /// An expression without a continuation or a subexpression body. | 123 /// An expression without a continuation or a subexpression body. |
| 88 /// | 124 /// |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 EffectiveUseIterable get effectiveUses => new EffectiveUseIterable(this); | 246 EffectiveUseIterable get effectiveUses => new EffectiveUseIterable(this); |
| 211 | 247 |
| 212 bool get hasMultipleEffectiveUses { | 248 bool get hasMultipleEffectiveUses { |
| 213 Iterator it = effectiveUses.iterator; | 249 Iterator it = effectiveUses.iterator; |
| 214 return it.moveNext() && it.moveNext(); | 250 return it.moveNext() && it.moveNext(); |
| 215 } | 251 } |
| 216 | 252 |
| 217 bool get hasNoEffectiveUses { | 253 bool get hasNoEffectiveUses { |
| 218 return effectiveUses.isEmpty; | 254 return effectiveUses.isEmpty; |
| 219 } | 255 } |
| 256 |
| 257 /// Unlinks all references contained in this node. |
| 258 void destroy() { |
| 259 assert(hasNoUses); |
| 260 RemovalVisitor.remove(this); |
| 261 } |
| 220 } | 262 } |
| 221 | 263 |
| 222 /// Operands to invocations and primitives are always variables. They point to | 264 /// Operands to invocations and primitives are always variables. They point to |
| 223 /// their definition and are doubly-linked into a list of occurrences. | 265 /// their definition and are doubly-linked into a list of occurrences. |
| 224 class Reference<T extends Definition<T>> { | 266 class Reference<T extends Definition<T>> { |
| 225 T definition; | 267 T definition; |
| 226 Reference<T> previous; | 268 Reference<T> previous; |
| 227 Reference<T> next; | 269 Reference<T> next; |
| 228 | 270 |
| 229 /// A pointer to the parent node. Is null until set by optimization passes. | 271 /// A pointer to the parent node. Is null until set by optimization passes. |
| (...skipping 1545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 /// Visit a just-deleted subterm and unlink all [Reference]s in it. | 1817 /// Visit a just-deleted subterm and unlink all [Reference]s in it. |
| 1776 class RemovalVisitor extends RecursiveVisitor { | 1818 class RemovalVisitor extends RecursiveVisitor { |
| 1777 processReference(Reference reference) { | 1819 processReference(Reference reference) { |
| 1778 reference.unlink(); | 1820 reference.unlink(); |
| 1779 } | 1821 } |
| 1780 | 1822 |
| 1781 static void remove(Node node) { | 1823 static void remove(Node node) { |
| 1782 (new RemovalVisitor()).visit(node); | 1824 (new RemovalVisitor()).visit(node); |
| 1783 } | 1825 } |
| 1784 } | 1826 } |
| OLD | NEW |