OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import '../closure.dart'; | 5 import '../closure.dart'; |
6 import '../common.dart'; | 6 import '../common.dart'; |
7 import '../common/backend_api.dart' show BackendClasses; | 7 import '../common_elements.dart' show CommonElements; |
8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
11 import '../elements/elements.dart' show JumpTarget, LabelDefinition; | 11 import '../elements/elements.dart' show JumpTarget, LabelDefinition; |
12 import '../elements/entities.dart'; | 12 import '../elements/entities.dart'; |
13 import '../elements/types.dart'; | 13 import '../elements/types.dart'; |
14 import '../io/source_information.dart'; | 14 import '../io/source_information.dart'; |
15 import '../js/js.dart' as js; | 15 import '../js/js.dart' as js; |
16 import '../js_backend/js_backend.dart'; | 16 import '../js_backend/js_backend.dart'; |
17 import '../native/native.dart' as native; | 17 import '../native/native.dart' as native; |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 | 1005 |
1006 bool canBePrimitive(ClosedWorld closedWorld) { | 1006 bool canBePrimitive(ClosedWorld closedWorld) { |
1007 return canBePrimitiveNumber(closedWorld) || | 1007 return canBePrimitiveNumber(closedWorld) || |
1008 canBePrimitiveArray(closedWorld) || | 1008 canBePrimitiveArray(closedWorld) || |
1009 canBePrimitiveBoolean(closedWorld) || | 1009 canBePrimitiveBoolean(closedWorld) || |
1010 canBePrimitiveString(closedWorld) || | 1010 canBePrimitiveString(closedWorld) || |
1011 isNull(); | 1011 isNull(); |
1012 } | 1012 } |
1013 | 1013 |
1014 bool canBePrimitiveNumber(ClosedWorld closedWorld) { | 1014 bool canBePrimitiveNumber(ClosedWorld closedWorld) { |
1015 BackendClasses backendClasses = closedWorld.backendClasses; | 1015 CommonElements commonElements = closedWorld.commonElements; |
1016 // TODO(sra): It should be possible to test only jsDoubleClass and | 1016 // TODO(sra): It should be possible to test only jsDoubleClass and |
1017 // jsUInt31Class, since all others are superclasses of these two. | 1017 // jsUInt31Class, since all others are superclasses of these two. |
1018 return containsType( | 1018 return containsType( |
1019 instructionType, backendClasses.numClass, closedWorld) || | 1019 instructionType, commonElements.jsNumberClass, closedWorld) || |
1020 containsType(instructionType, backendClasses.intClass, closedWorld) || | 1020 containsType(instructionType, commonElements.jsIntClass, closedWorld) || |
1021 containsType( | 1021 containsType( |
1022 instructionType, backendClasses.positiveIntClass, closedWorld) || | 1022 instructionType, commonElements.jsPositiveIntClass, closedWorld) || |
1023 containsType( | 1023 containsType( |
1024 instructionType, backendClasses.uint32Class, closedWorld) || | 1024 instructionType, commonElements.jsUInt32Class, closedWorld) || |
1025 containsType( | 1025 containsType( |
1026 instructionType, backendClasses.uint31Class, closedWorld) || | 1026 instructionType, commonElements.jsUInt31Class, closedWorld) || |
1027 containsType(instructionType, backendClasses.doubleClass, closedWorld); | 1027 containsType( |
| 1028 instructionType, commonElements.jsDoubleClass, closedWorld); |
1028 } | 1029 } |
1029 | 1030 |
1030 bool canBePrimitiveBoolean(ClosedWorld closedWorld) { | 1031 bool canBePrimitiveBoolean(ClosedWorld closedWorld) { |
1031 return containsType( | 1032 return containsType( |
1032 instructionType, closedWorld.backendClasses.boolClass, closedWorld); | 1033 instructionType, closedWorld.commonElements.jsBoolClass, closedWorld); |
1033 } | 1034 } |
1034 | 1035 |
1035 bool canBePrimitiveArray(ClosedWorld closedWorld) { | 1036 bool canBePrimitiveArray(ClosedWorld closedWorld) { |
1036 BackendClasses backendClasses = closedWorld.backendClasses; | 1037 CommonElements commonElements = closedWorld.commonElements; |
1037 return containsType( | 1038 return containsType( |
1038 instructionType, backendClasses.listClass, closedWorld) || | 1039 instructionType, commonElements.jsArrayClass, closedWorld) || |
1039 containsType( | 1040 containsType( |
1040 instructionType, backendClasses.fixedListClass, closedWorld) || | 1041 instructionType, commonElements.jsFixedArrayClass, closedWorld) || |
1041 containsType( | 1042 containsType(instructionType, commonElements.jsExtendableArrayClass, |
1042 instructionType, backendClasses.growableListClass, closedWorld) || | 1043 closedWorld) || |
1043 containsType( | 1044 containsType(instructionType, commonElements.jsUnmodifiableArrayClass, |
1044 instructionType, backendClasses.constListClass, closedWorld); | 1045 closedWorld); |
1045 } | 1046 } |
1046 | 1047 |
1047 bool isIndexablePrimitive(ClosedWorld closedWorld) { | 1048 bool isIndexablePrimitive(ClosedWorld closedWorld) { |
1048 return instructionType.containsOnlyString(closedWorld) || | 1049 return instructionType.containsOnlyString(closedWorld) || |
1049 isInstanceOf(instructionType, closedWorld.backendClasses.indexableClass, | 1050 isInstanceOf(instructionType, |
1050 closedWorld); | 1051 closedWorld.commonElements.jsIndexableClass, closedWorld); |
1051 } | 1052 } |
1052 | 1053 |
1053 bool isFixedArray(ClosedWorld closedWorld) { | 1054 bool isFixedArray(ClosedWorld closedWorld) { |
1054 BackendClasses backendClasses = closedWorld.backendClasses; | 1055 CommonElements commonElements = closedWorld.commonElements; |
1055 // TODO(sra): Recognize the union of these types as well. | 1056 // TODO(sra): Recognize the union of these types as well. |
1056 return containsOnlyType( | 1057 return containsOnlyType( |
1057 instructionType, backendClasses.fixedListClass, closedWorld) || | 1058 instructionType, commonElements.jsFixedArrayClass, closedWorld) || |
1058 containsOnlyType( | 1059 containsOnlyType(instructionType, |
1059 instructionType, backendClasses.constListClass, closedWorld); | 1060 commonElements.jsUnmodifiableArrayClass, closedWorld); |
1060 } | 1061 } |
1061 | 1062 |
1062 bool isExtendableArray(ClosedWorld closedWorld) { | 1063 bool isExtendableArray(ClosedWorld closedWorld) { |
1063 return containsOnlyType(instructionType, | 1064 return containsOnlyType(instructionType, |
1064 closedWorld.backendClasses.growableListClass, closedWorld); | 1065 closedWorld.commonElements.jsExtendableArrayClass, closedWorld); |
1065 } | 1066 } |
1066 | 1067 |
1067 bool isMutableArray(ClosedWorld closedWorld) { | 1068 bool isMutableArray(ClosedWorld closedWorld) { |
1068 return isInstanceOf(instructionType, | 1069 return isInstanceOf(instructionType, |
1069 closedWorld.backendClasses.mutableListClass, closedWorld); | 1070 closedWorld.commonElements.jsMutableArrayClass, closedWorld); |
1070 } | 1071 } |
1071 | 1072 |
1072 bool isReadableArray(ClosedWorld closedWorld) { | 1073 bool isReadableArray(ClosedWorld closedWorld) { |
1073 return isInstanceOf( | 1074 return isInstanceOf( |
1074 instructionType, closedWorld.backendClasses.listClass, closedWorld); | 1075 instructionType, closedWorld.commonElements.jsArrayClass, closedWorld); |
1075 } | 1076 } |
1076 | 1077 |
1077 bool isMutableIndexable(ClosedWorld closedWorld) { | 1078 bool isMutableIndexable(ClosedWorld closedWorld) { |
1078 return isInstanceOf(instructionType, | 1079 return isInstanceOf(instructionType, |
1079 closedWorld.backendClasses.mutableIndexableClass, closedWorld); | 1080 closedWorld.commonElements.jsMutableIndexableClass, closedWorld); |
1080 } | 1081 } |
1081 | 1082 |
1082 bool isArray(ClosedWorld closedWorld) => isReadableArray(closedWorld); | 1083 bool isArray(ClosedWorld closedWorld) => isReadableArray(closedWorld); |
1083 | 1084 |
1084 bool canBePrimitiveString(ClosedWorld closedWorld) { | 1085 bool canBePrimitiveString(ClosedWorld closedWorld) { |
1085 return containsType( | 1086 return containsType( |
1086 instructionType, closedWorld.backendClasses.stringClass, closedWorld); | 1087 instructionType, closedWorld.commonElements.jsStringClass, closedWorld); |
1087 } | 1088 } |
1088 | 1089 |
1089 bool isInteger(ClosedWorld closedWorld) { | 1090 bool isInteger(ClosedWorld closedWorld) { |
1090 return instructionType.containsOnlyInt(closedWorld) && | 1091 return instructionType.containsOnlyInt(closedWorld) && |
1091 !instructionType.isNullable; | 1092 !instructionType.isNullable; |
1092 } | 1093 } |
1093 | 1094 |
1094 bool isUInt32(ClosedWorld closedWorld) { | 1095 bool isUInt32(ClosedWorld closedWorld) { |
1095 return !instructionType.isNullable && | 1096 return !instructionType.isNullable && |
1096 isInstanceOf(instructionType, closedWorld.backendClasses.uint32Class, | 1097 isInstanceOf(instructionType, closedWorld.commonElements.jsUInt32Class, |
1097 closedWorld); | 1098 closedWorld); |
1098 } | 1099 } |
1099 | 1100 |
1100 bool isUInt31(ClosedWorld closedWorld) { | 1101 bool isUInt31(ClosedWorld closedWorld) { |
1101 return !instructionType.isNullable && | 1102 return !instructionType.isNullable && |
1102 isInstanceOf(instructionType, closedWorld.backendClasses.uint31Class, | 1103 isInstanceOf(instructionType, closedWorld.commonElements.jsUInt31Class, |
1103 closedWorld); | 1104 closedWorld); |
1104 } | 1105 } |
1105 | 1106 |
1106 bool isPositiveInteger(ClosedWorld closedWorld) { | 1107 bool isPositiveInteger(ClosedWorld closedWorld) { |
1107 return !instructionType.isNullable && | 1108 return !instructionType.isNullable && |
1108 isInstanceOf(instructionType, | 1109 isInstanceOf(instructionType, |
1109 closedWorld.backendClasses.positiveIntClass, closedWorld); | 1110 closedWorld.commonElements.jsPositiveIntClass, closedWorld); |
1110 } | 1111 } |
1111 | 1112 |
1112 bool isPositiveIntegerOrNull(ClosedWorld closedWorld) { | 1113 bool isPositiveIntegerOrNull(ClosedWorld closedWorld) { |
1113 return isInstanceOf(instructionType, | 1114 return isInstanceOf(instructionType, |
1114 closedWorld.backendClasses.positiveIntClass, closedWorld); | 1115 closedWorld.commonElements.jsPositiveIntClass, closedWorld); |
1115 } | 1116 } |
1116 | 1117 |
1117 bool isIntegerOrNull(ClosedWorld closedWorld) { | 1118 bool isIntegerOrNull(ClosedWorld closedWorld) { |
1118 return instructionType.containsOnlyInt(closedWorld); | 1119 return instructionType.containsOnlyInt(closedWorld); |
1119 } | 1120 } |
1120 | 1121 |
1121 bool isNumber(ClosedWorld closedWorld) { | 1122 bool isNumber(ClosedWorld closedWorld) { |
1122 return instructionType.containsOnlyNum(closedWorld) && | 1123 return instructionType.containsOnlyNum(closedWorld) && |
1123 !instructionType.isNullable; | 1124 !instructionType.isNullable; |
1124 } | 1125 } |
(...skipping 2396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3521 // ignore: MISSING_RETURN | 3522 // ignore: MISSING_RETURN |
3522 String get kindAsString { | 3523 String get kindAsString { |
3523 switch (kind) { | 3524 switch (kind) { |
3524 case TypeInfoExpressionKind.COMPLETE: | 3525 case TypeInfoExpressionKind.COMPLETE: |
3525 return 'COMPLETE'; | 3526 return 'COMPLETE'; |
3526 case TypeInfoExpressionKind.INSTANCE: | 3527 case TypeInfoExpressionKind.INSTANCE: |
3527 return 'INSTANCE'; | 3528 return 'INSTANCE'; |
3528 } | 3529 } |
3529 } | 3530 } |
3530 } | 3531 } |
OLD | NEW |