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 compiler.src.inferrer.type_graph_nodes; | 5 library compiler.src.inferrer.type_graph_nodes; |
6 | 6 |
7 import 'dart:collection' show IterableBase; | 7 import 'dart:collection' show IterableBase; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/names.dart' show Identifiers; | 10 import '../common/names.dart' show Identifiers; |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 throw new UnsupportedError('ParameterTypeInformation.getInferredSignature'); | 824 throw new UnsupportedError('ParameterTypeInformation.getInferredSignature'); |
825 } | 825 } |
826 } | 826 } |
827 | 827 |
828 enum CallType { | 828 enum CallType { |
829 access, | 829 access, |
830 complex, | 830 complex, |
831 forIn, | 831 forIn, |
832 } | 832 } |
833 | 833 |
834 bool validCallType(CallType callType, Spannable call) { | 834 bool validCallType(CallType callType, Object call) { |
835 switch (callType) { | 835 switch (callType) { |
836 case CallType.complex: | 836 case CallType.complex: |
837 return call is ast.SendSet; | 837 return call is ast.SendSet; |
838 case CallType.access: | 838 case CallType.access: |
839 return call is ast.Send; | 839 return call is ast.Send; |
840 case CallType.forIn: | 840 case CallType.forIn: |
841 return call is ast.ForIn; | 841 return call is ast.ForIn; |
842 } | 842 } |
843 throw new StateError('Unexpected call type $callType.'); | 843 throw new StateError('Unexpected call type $callType.'); |
844 } | 844 } |
845 | 845 |
846 /** | 846 /** |
847 * A [CallSiteTypeInformation] is a call found in the AST, or a | 847 * A [CallSiteTypeInformation] is a call found in the AST, or a |
848 * synthesized call for implicit calls in Dart (such as forwarding | 848 * synthesized call for implicit calls in Dart (such as forwarding |
849 * factories). The [_call] field is a [ast.Node] for the former, and an | 849 * factories). The [_call] field is a [ast.Node] for the former, and an |
850 * [Element] for the latter. | 850 * [Element] for the latter. |
851 * | 851 * |
852 * In the inferrer graph, [CallSiteTypeInformation] nodes do not have | 852 * In the inferrer graph, [CallSiteTypeInformation] nodes do not have |
853 * any assignment. They rely on the [caller] field for static calls, | 853 * any assignment. They rely on the [caller] field for static calls, |
854 * and [selector] and [receiver] fields for dynamic calls. | 854 * and [selector] and [receiver] fields for dynamic calls. |
855 */ | 855 */ |
856 abstract class CallSiteTypeInformation extends TypeInformation | 856 abstract class CallSiteTypeInformation extends TypeInformation |
857 with ApplyableTypeInformation { | 857 with ApplyableTypeInformation { |
858 final Spannable _call; | 858 final Object _call; |
859 final MemberEntity caller; | 859 final MemberEntity caller; |
860 final Selector selector; | 860 final Selector selector; |
861 final TypeMask mask; | 861 final TypeMask mask; |
862 final ArgumentsTypes arguments; | 862 final ArgumentsTypes arguments; |
863 final bool inLoop; | 863 final bool inLoop; |
864 | 864 |
865 CallSiteTypeInformation(MemberTypeInformation context, this._call, | 865 CallSiteTypeInformation(MemberTypeInformation context, this._call, |
866 this.caller, this.selector, this.mask, this.arguments, this.inLoop) | 866 this.caller, this.selector, this.mask, this.arguments, this.inLoop) |
867 : super.noAssignments(context) { | 867 : super.noAssignments(context) { |
868 assert(_checkCaller(caller)); | 868 assert(_checkCaller(caller)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 void removeAndClearReferences(InferrerEngine inferrer) { | 959 void removeAndClearReferences(InferrerEngine inferrer) { |
960 ElementTypeInformation callee = _getCalledTypeInfo(inferrer); | 960 ElementTypeInformation callee = _getCalledTypeInfo(inferrer); |
961 callee.removeUser(this); | 961 callee.removeUser(this); |
962 if (arguments != null) { | 962 if (arguments != null) { |
963 arguments.forEach((info) => info.removeUser(this)); | 963 arguments.forEach((info) => info.removeUser(this)); |
964 } | 964 } |
965 super.removeAndClearReferences(inferrer); | 965 super.removeAndClearReferences(inferrer); |
966 } | 966 } |
967 } | 967 } |
968 | 968 |
969 class DynamicCallSiteTypeInformation extends CallSiteTypeInformation { | 969 class DynamicCallSiteTypeInformation<T> extends CallSiteTypeInformation { |
970 final CallType _callType; | 970 final CallType _callType; |
971 final TypeInformation receiver; | 971 final TypeInformation receiver; |
972 final bool isConditional; | 972 final bool isConditional; |
973 | 973 |
974 /// Cached targets of this call. | 974 /// Cached targets of this call. |
975 Iterable<MemberEntity> targets; | 975 Iterable<MemberEntity> targets; |
976 | 976 |
977 DynamicCallSiteTypeInformation( | 977 DynamicCallSiteTypeInformation( |
978 MemberTypeInformation context, | 978 MemberTypeInformation context, |
979 this._callType, | 979 this._callType, |
980 ast.Node call, | 980 T call, |
981 MemberEntity enclosing, | 981 MemberEntity enclosing, |
982 Selector selector, | 982 Selector selector, |
983 TypeMask mask, | 983 TypeMask mask, |
984 this.receiver, | 984 this.receiver, |
985 ArgumentsTypes arguments, | 985 ArgumentsTypes arguments, |
986 bool inLoop, | 986 bool inLoop, |
987 this.isConditional) | 987 this.isConditional) |
988 : super(context, call, enclosing, selector, mask, arguments, inLoop) { | 988 : super(context, call, enclosing, selector, mask, arguments, inLoop) { |
989 assert(validCallType(_callType, _call)); | 989 assert(validCallType(_callType, _call)); |
990 } | 990 } |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 (arguments == null || arguments.every((info) => info.isStable)) && | 1289 (arguments == null || arguments.every((info) => info.isStable)) && |
1290 super.hasStableType(inferrer); | 1290 super.hasStableType(inferrer); |
1291 } | 1291 } |
1292 } | 1292 } |
1293 | 1293 |
1294 class ClosureCallSiteTypeInformation extends CallSiteTypeInformation { | 1294 class ClosureCallSiteTypeInformation extends CallSiteTypeInformation { |
1295 final TypeInformation closure; | 1295 final TypeInformation closure; |
1296 | 1296 |
1297 ClosureCallSiteTypeInformation( | 1297 ClosureCallSiteTypeInformation( |
1298 MemberTypeInformation context, | 1298 MemberTypeInformation context, |
1299 Spannable call, | 1299 Object call, |
1300 MemberEntity enclosing, | 1300 MemberEntity enclosing, |
1301 Selector selector, | 1301 Selector selector, |
1302 TypeMask mask, | 1302 TypeMask mask, |
1303 this.closure, | 1303 this.closure, |
1304 ArgumentsTypes arguments, | 1304 ArgumentsTypes arguments, |
1305 bool inLoop) | 1305 bool inLoop) |
1306 : super(context, call, enclosing, selector, mask, arguments, inLoop); | 1306 : super(context, call, enclosing, selector, mask, arguments, inLoop); |
1307 | 1307 |
1308 void addToGraph(InferrerEngine inferrer) { | 1308 void addToGraph(InferrerEngine inferrer) { |
1309 arguments.forEach((info) => info.addUser(this)); | 1309 arguments.forEach((info) => info.addUser(this)); |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 otherType = closedWorld.commonMasks.functionType; | 1941 otherType = closedWorld.commonMasks.functionType; |
1942 } else { | 1942 } else { |
1943 assert(annotation.isTypeVariable); | 1943 assert(annotation.isTypeVariable); |
1944 // TODO(ngeoffray): Narrow to bound. | 1944 // TODO(ngeoffray): Narrow to bound. |
1945 return type; | 1945 return type; |
1946 } | 1946 } |
1947 if (isNullable) otherType = otherType.nullable(); | 1947 if (isNullable) otherType = otherType.nullable(); |
1948 if (type == null) return otherType; | 1948 if (type == null) return otherType; |
1949 return type.intersection(otherType, closedWorld); | 1949 return type.intersection(otherType, closedWorld); |
1950 } | 1950 } |
OLD | NEW |