| 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 library inferrer_visitor; | 5 library inferrer_visitor; |
| 6 | 6 |
| 7 import '../dart2jslib.dart' hide Selector, TypedSelector; | 7 import '../dart2jslib.dart' hide Selector, TypedSelector; |
| 8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../tree/tree.dart'; | 10 import '../tree/tree.dart'; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 * Returns a new type that unions [firstInput] and [secondInput]. | 72 * Returns a new type that unions [firstInput] and [secondInput]. |
| 73 */ | 73 */ |
| 74 T allocateDiamondPhi(T firstInput, T secondInput); | 74 T allocateDiamondPhi(T firstInput, T secondInput); |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * Returns a new type for holding the potential types of [element]. | 77 * Returns a new type for holding the potential types of [element]. |
| 78 * [inputType] is the first incoming type of the phi. | 78 * [inputType] is the first incoming type of the phi. |
| 79 */ | 79 */ |
| 80 T allocatePhi(Node node, Local variable, T inputType); | 80 T allocatePhi(Node node, Local variable, T inputType); |
| 81 | 81 |
| 82 |
| 83 /** |
| 84 * Returns a new type for holding the potential types of [element]. |
| 85 * [inputType] is the first incoming type of the phi. [allocateLoopPhi] |
| 86 * only differs from [allocatePhi] in that it allows the underlying |
| 87 * implementation of [TypeSystem] to differentiate Phi nodes due to loops |
| 88 * from other merging uses. |
| 89 */ |
| 90 T allocateLoopPhi(Node node, Local variable, T inputType); |
| 91 |
| 82 /** | 92 /** |
| 83 * Simplies the phi representing [element] and of the type | 93 * Simplies the phi representing [element] and of the type |
| 84 * [phiType]. For example, if this phi has one incoming input, an | 94 * [phiType]. For example, if this phi has one incoming input, an |
| 85 * implementation of this method could just return that incoming | 95 * implementation of this method could just return that incoming |
| 86 * input type. | 96 * input type. |
| 87 */ | 97 */ |
| 88 T simplifyPhi(Node node, Local variable, T phiType); | 98 T simplifyPhi(Node node, Local variable, T phiType); |
| 89 | 99 |
| 90 /** | 100 /** |
| 91 * Adds [newType] as an input of [phiType]. | 101 * Adds [newType] as an input of [phiType]. |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 bool changed = false; | 608 bool changed = false; |
| 599 assert(!seenReturnOrThrow); | 609 assert(!seenReturnOrThrow); |
| 600 handlers.forEach((other) { | 610 handlers.forEach((other) { |
| 601 changed = mergeHandler(other) || changed; | 611 changed = mergeHandler(other) || changed; |
| 602 }); | 612 }); |
| 603 return changed; | 613 return changed; |
| 604 } | 614 } |
| 605 | 615 |
| 606 void startLoop(Node loop) { | 616 void startLoop(Node loop) { |
| 607 locals.forEachLocal((Local variable, T type) { | 617 locals.forEachLocal((Local variable, T type) { |
| 608 T newType = types.allocatePhi(loop, variable, type); | 618 T newType = types.allocateLoopPhi(loop, variable, type); |
| 609 if (newType != type) { | 619 if (newType != type) { |
| 610 locals[variable] = newType; | 620 locals[variable] = newType; |
| 611 } | 621 } |
| 612 }); | 622 }); |
| 613 } | 623 } |
| 614 | 624 |
| 615 void endLoop(Node loop) { | 625 void endLoop(Node loop) { |
| 616 locals.forEachLocal((Local variable, T type) { | 626 locals.forEachLocal((Local variable, T type) { |
| 617 T newType = types.simplifyPhi(loop, variable, type); | 627 T newType = types.simplifyPhi(loop, variable, type); |
| 618 if (newType != type) { | 628 if (newType != type) { |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 return type; | 1268 return type; |
| 1259 } | 1269 } |
| 1260 | 1270 |
| 1261 T visitCascade(Cascade node) { | 1271 T visitCascade(Cascade node) { |
| 1262 // Ignore the result of the cascade send and return the type of the cascade | 1272 // Ignore the result of the cascade send and return the type of the cascade |
| 1263 // receiver. | 1273 // receiver. |
| 1264 visit(node.expression); | 1274 visit(node.expression); |
| 1265 return cascadeReceiverStack.removeLast(); | 1275 return cascadeReceiverStack.removeLast(); |
| 1266 } | 1276 } |
| 1267 } | 1277 } |
| OLD | NEW |