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 | 4 |
5 // IrNodes are kept in a separate library to have precise control over their | 5 // IrNodes are kept in a separate library to have precise control over their |
6 // dependencies on other parts of the system. | 6 // dependencies on other parts of the system. |
7 library dart2js.ir_nodes; | 7 library dart2js.ir_nodes; |
8 | 8 |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../constants/values.dart' as values show ConstantValue; | 10 import '../constants/values.dart' as values show ConstantValue; |
(...skipping 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 | 31 |
32 /// The base class of things that variables can refer to: primitives, | 32 /// The base class of things that variables can refer to: primitives, |
33 /// continuations, function and continuation parameters, etc. | 33 /// continuations, function and continuation parameters, etc. |
34 abstract class Definition<T extends Definition<T>> extends Node { | 34 abstract class Definition<T extends Definition<T>> extends Node { |
35 // The head of a linked-list of occurrences, in no particular order. | 35 // The head of a linked-list of occurrences, in no particular order. |
36 Reference<T> firstRef; | 36 Reference<T> firstRef; |
37 | 37 |
38 bool get hasAtMostOneUse => firstRef == null || firstRef.next == null; | 38 bool get hasAtMostOneUse => firstRef == null || firstRef.next == null; |
39 bool get hasExactlyOneUse => firstRef != null && firstRef.next == null; | 39 bool get hasExactlyOneUse => firstRef != null && firstRef.next == null; |
| 40 bool get hasNoUses => firstRef == null; |
40 bool get hasAtLeastOneUse => firstRef != null; | 41 bool get hasAtLeastOneUse => firstRef != null; |
41 bool get hasMultipleUses => !hasAtMostOneUse; | 42 bool get hasMultipleUses => !hasAtMostOneUse; |
42 | 43 |
43 void substituteFor(Definition<T> other) { | 44 void substituteFor(Definition<T> other) { |
44 if (other.firstRef == null) return; | 45 if (other.hasNoUses) return; |
45 Reference<T> previous, current = other.firstRef; | 46 Reference<T> previous, current = other.firstRef; |
46 do { | 47 do { |
47 current.definition = this; | 48 current.definition = this; |
48 previous = current; | 49 previous = current; |
49 current = current.next; | 50 current = current.next; |
50 } while (current != null); | 51 } while (current != null); |
51 previous.next = firstRef; | 52 previous.next = firstRef; |
52 if (firstRef != null) firstRef.previous = previous; | 53 if (firstRef != null) firstRef.previous = previous; |
53 firstRef = other.firstRef; | 54 firstRef = other.firstRef; |
| 55 other.firstRef = null; |
54 } | 56 } |
55 } | 57 } |
56 | 58 |
57 /// An expression that cannot throw or diverge and has no side-effects. | 59 /// An expression that cannot throw or diverge and has no side-effects. |
58 /// All primitives are named using the identity of the [Primitive] object. | 60 /// All primitives are named using the identity of the [Primitive] object. |
59 /// | 61 /// |
60 /// Primitives may allocate objects, this is not considered side-effect here. | 62 /// Primitives may allocate objects, this is not considered side-effect here. |
61 /// | 63 /// |
62 /// Although primitives may not mutate state, they may depend on state. | 64 /// Although primitives may not mutate state, they may depend on state. |
63 abstract class Primitive extends Definition<Primitive> { | 65 abstract class Primitive extends Definition<Primitive> { |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 processReadTypeVariable(node); | 1260 processReadTypeVariable(node); |
1259 processReference(node.target); | 1261 processReference(node.target); |
1260 } | 1262 } |
1261 | 1263 |
1262 processTypeExpression(TypeExpression node) {} | 1264 processTypeExpression(TypeExpression node) {} |
1263 visitTypeExpression(TypeExpression node) { | 1265 visitTypeExpression(TypeExpression node) { |
1264 processTypeExpression(node); | 1266 processTypeExpression(node); |
1265 node.arguments.forEach(processReference); | 1267 node.arguments.forEach(processReference); |
1266 } | 1268 } |
1267 } | 1269 } |
OLD | NEW |