| 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 simple_types_inferrer; | 5 library simple_types_inferrer; |
| 6 | 6 |
| 7 import '../closure.dart' show ClosureRepresentationInfo; | 7 import '../closure.dart' show ClosureRepresentationInfo; |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/names.dart' show Identifiers, Selectors; | 9 import '../common/names.dart' show Identifiers, Selectors; |
| 10 import '../compiler.dart' show Compiler; | 10 import '../compiler.dart' show Compiler; |
| (...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 inferrer.recordTypeOfField(field, thisType); | 1119 inferrer.recordTypeOfField(field, thisType); |
| 1120 } | 1120 } |
| 1121 // The type is null for type parameters. | 1121 // The type is null for type parameters. |
| 1122 if (locals.locals[variable] == null) return; | 1122 if (locals.locals[variable] == null) return; |
| 1123 inferrer.recordTypeOfField(field, locals.locals[variable]); | 1123 inferrer.recordTypeOfField(field, locals.locals[variable]); |
| 1124 } | 1124 } |
| 1125 capturedVariables.add(variable); | 1125 capturedVariables.add(variable); |
| 1126 }); | 1126 }); |
| 1127 | 1127 |
| 1128 return inferrer.concreteTypes.putIfAbsent(node, () { | 1128 return inferrer.concreteTypes.putIfAbsent(node, () { |
| 1129 return types.allocateClosure(node, element.callMethod); | 1129 return types.allocateClosure(element.callMethod); |
| 1130 }); | 1130 }); |
| 1131 } | 1131 } |
| 1132 | 1132 |
| 1133 TypeInformation visitFunctionDeclaration(ast.FunctionDeclaration node) { | 1133 TypeInformation visitFunctionDeclaration(ast.FunctionDeclaration node) { |
| 1134 LocalFunctionElement element = | 1134 LocalFunctionElement element = |
| 1135 elements.getFunctionDefinition(node.function); | 1135 elements.getFunctionDefinition(node.function); |
| 1136 TypeInformation type = | 1136 TypeInformation type = |
| 1137 inferrer.concreteTypes.putIfAbsent(node.function, () { | 1137 inferrer.concreteTypes.putIfAbsent(node.function, () { |
| 1138 return types.allocateClosure(node.function, element.callMethod); | 1138 return types.allocateClosure(element.callMethod); |
| 1139 }); | 1139 }); |
| 1140 locals.update(element, type, node); | 1140 locals.update(element, type, node); |
| 1141 visit(node.function); | 1141 visit(node.function); |
| 1142 return type; | 1142 return type; |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 TypeInformation visitStringInterpolation(ast.StringInterpolation node) { | 1145 TypeInformation visitStringInterpolation(ast.StringInterpolation node) { |
| 1146 // Interpolation could have any effects since it could call any toString() | 1146 // Interpolation could have any effects since it could call any toString() |
| 1147 // method. | 1147 // method. |
| 1148 // TODO(sra): This could be modelled by a call to toString() but with a | 1148 // TODO(sra): This could be modelled by a call to toString() but with a |
| (...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2747 mask = receiverType == types.dynamicType | 2747 mask = receiverType == types.dynamicType |
| 2748 ? null | 2748 ? null |
| 2749 : types.newTypedSelector(receiverType, mask); | 2749 : types.newTypedSelector(receiverType, mask); |
| 2750 inferrer.updateSelectorInMember(outermostElement, node, selector, mask); | 2750 inferrer.updateSelectorInMember(outermostElement, node, selector, mask); |
| 2751 } | 2751 } |
| 2752 | 2752 |
| 2753 // If the receiver of the call is a local, we may know more about | 2753 // If the receiver of the call is a local, we may know more about |
| 2754 // its type by refining it with the potential targets of the | 2754 // its type by refining it with the potential targets of the |
| 2755 // calls. | 2755 // calls. |
| 2756 ast.Send send = node.asSend(); | 2756 ast.Send send = node.asSend(); |
| 2757 bool isConditional = false; |
| 2757 if (send != null) { | 2758 if (send != null) { |
| 2759 isConditional = send.isConditional; |
| 2758 ast.Node receiver = send.receiver; | 2760 ast.Node receiver = send.receiver; |
| 2759 if (receiver != null) { | 2761 if (receiver != null) { |
| 2760 Element element = elements[receiver]; | 2762 Element element = elements[receiver]; |
| 2761 if (Elements.isLocal(element) && !capturedVariables.contains(element)) { | 2763 if (Elements.isLocal(element) && !capturedVariables.contains(element)) { |
| 2762 TypeInformation refinedType = types.refineReceiver( | 2764 TypeInformation refinedType = types.refineReceiver( |
| 2763 selector, mask, receiverType, send.isConditional); | 2765 selector, mask, receiverType, send.isConditional); |
| 2764 locals.update(element, refinedType, node); | 2766 locals.update(element, refinedType, node); |
| 2765 } | 2767 } |
| 2766 } | 2768 } |
| 2767 } | 2769 } |
| 2768 | 2770 |
| 2769 return inferrer.registerCalledSelector(node, selector, mask, receiverType, | 2771 return inferrer.registerCalledSelector(node, selector, mask, receiverType, |
| 2770 outermostElement, arguments, sideEffects, inLoop); | 2772 outermostElement, arguments, sideEffects, inLoop, isConditional); |
| 2771 } | 2773 } |
| 2772 | 2774 |
| 2773 TypeInformation handleDynamicInvoke(ast.Send node) { | 2775 TypeInformation handleDynamicInvoke(ast.Send node) { |
| 2774 return _handleDynamicSend(node); | 2776 return _handleDynamicSend(node); |
| 2775 } | 2777 } |
| 2776 | 2778 |
| 2777 TypeInformation handleDynamicGet(ast.Send node) { | 2779 TypeInformation handleDynamicGet(ast.Send node) { |
| 2778 return _handleDynamicSend(node); | 2780 return _handleDynamicSend(node); |
| 2779 } | 2781 } |
| 2780 | 2782 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2945 Selector moveNextSelector = Selectors.moveNext; | 2947 Selector moveNextSelector = Selectors.moveNext; |
| 2946 TypeMask moveNextMask = memberData.typeOfIteratorMoveNext(node); | 2948 TypeMask moveNextMask = memberData.typeOfIteratorMoveNext(node); |
| 2947 | 2949 |
| 2948 TypeInformation iteratorType = handleDynamicSend(node, iteratorSelector, | 2950 TypeInformation iteratorType = handleDynamicSend(node, iteratorSelector, |
| 2949 iteratorMask, expressionType, new ArgumentsTypes.empty()); | 2951 iteratorMask, expressionType, new ArgumentsTypes.empty()); |
| 2950 | 2952 |
| 2951 return handleForInLoop(node, iteratorType, currentSelector, currentMask, | 2953 return handleForInLoop(node, iteratorType, currentSelector, currentMask, |
| 2952 moveNextSelector, moveNextMask); | 2954 moveNextSelector, moveNextMask); |
| 2953 } | 2955 } |
| 2954 } | 2956 } |
| OLD | NEW |