Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1639)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/backend.dart

Issue 23959003: Fix casts and type assertions on mixins used in native classes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 part of js_backend; 5 part of js_backend;
6 6
7 class JavaScriptItemCompilationContext extends ItemCompilationContext { 7 class JavaScriptItemCompilationContext extends ItemCompilationContext {
8 final Set<HInstruction> boundsChecked; 8 final Set<HInstruction> boundsChecked;
9 9
10 JavaScriptItemCompilationContext() 10 JavaScriptItemCompilationContext()
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 /// List of elements that the user has requested for reflection. 334 /// List of elements that the user has requested for reflection.
335 final Set<Element> targetsUsed = new Set<Element>(); 335 final Set<Element> targetsUsed = new Set<Element>();
336 336
337 /// List of annotations provided by user that indicate that the annotated 337 /// List of annotations provided by user that indicate that the annotated
338 /// element must be retained. 338 /// element must be retained.
339 final Set<Element> metaTargetsUsed = new Set<Element>(); 339 final Set<Element> metaTargetsUsed = new Set<Element>();
340 340
341 /// List of elements that the backend may use. 341 /// List of elements that the backend may use.
342 final Set<Element> helpersUsed = new Set<Element>(); 342 final Set<Element> helpersUsed = new Set<Element>();
343 343
344 /// All the checked mode helpers.
345 static const checkedModeHelpers = const [
346 const CheckedModeHelper(const SourceString('voidTypeCheck')),
347 const CheckedModeHelper(const SourceString('stringTypeCast')),
348 const CheckedModeHelper(const SourceString('stringTypeCheck')),
349 const CheckedModeHelper(const SourceString('doubleTypeCast')),
350 const CheckedModeHelper(const SourceString('doubleTypeCheck')),
351 const CheckedModeHelper(const SourceString('numTypeCast')),
352 const CheckedModeHelper(const SourceString('numTypeCheck')),
353 const CheckedModeHelper(const SourceString('boolTypeCast')),
354 const CheckedModeHelper(const SourceString('boolTypeCheck')),
355 const CheckedModeHelper(const SourceString('intTypeCast')),
356 const CheckedModeHelper(const SourceString('intTypeCheck')),
357 const PropertyCheckedModeHelper(
358 const SourceString('numberOrStringSuperNativeTypeCast')),
359 const PropertyCheckedModeHelper(
360 const SourceString('numberOrStringSuperNativeTypeCheck')),
361 const PropertyCheckedModeHelper(
362 const SourceString('numberOrStringSuperTypeCast')),
363 const PropertyCheckedModeHelper(
364 const SourceString('numberOrStringSuperTypeCheck')),
365 const PropertyCheckedModeHelper(
366 const SourceString('stringSuperNativeTypeCast')),
367 const PropertyCheckedModeHelper(
368 const SourceString('stringSuperNativeTypeCheck')),
369 const PropertyCheckedModeHelper(
370 const SourceString('stringSuperTypeCast')),
371 const PropertyCheckedModeHelper(
372 const SourceString('stringSuperTypeCheck')),
373 const CheckedModeHelper(const SourceString('listTypeCast')),
374 const CheckedModeHelper(const SourceString('listTypeCheck')),
375 const PropertyCheckedModeHelper(
376 const SourceString('listSuperNativeTypeCast')),
377 const PropertyCheckedModeHelper(
378 const SourceString('listSuperNativeTypeCheck')),
379 const PropertyCheckedModeHelper(
380 const SourceString('listSuperTypeCast')),
381 const PropertyCheckedModeHelper(
382 const SourceString('listSuperTypeCheck')),
383 const PropertyCheckedModeHelper(
384 const SourceString('interceptedTypeCast')),
385 const PropertyCheckedModeHelper(
386 const SourceString('interceptedTypeCheck')),
387 const SubtypeCheckedModeHelper(
388 const SourceString('subtypeCast')),
389 const SubtypeCheckedModeHelper(
390 const SourceString('assertSubtype')),
391 const TypeVariableCheckedModeHelper(
392 const SourceString('subtypeOfRuntimeTypeCast')),
393 const TypeVariableCheckedModeHelper(
394 const SourceString('assertSubtypeOfRuntimeType')),
395 const FunctionTypeCheckedModeHelper(
396 const SourceString('functionSubtypeCast')),
397 const FunctionTypeCheckedModeHelper(
398 const SourceString('assertFunctionSubtype')),
399 const PropertyCheckedModeHelper(
400 const SourceString('propertyTypeCast')),
401 const PropertyCheckedModeHelper(
402 const SourceString('propertyTypeCheck')) ];
403
404 // Checked mode helpers indexed by name.
405 Map<String, Checkedmodehelpers> checkedModeHelperByName =
406 new Map<String, CheckedModeHelper>.fromIterable(
407 checkedModeHelpers,
408 key: (helper) => helper.name.slowToString());
409
344 JavaScriptBackend(Compiler compiler, bool generateSourceMap, bool disableEval) 410 JavaScriptBackend(Compiler compiler, bool generateSourceMap, bool disableEval)
345 : namer = determineNamer(compiler), 411 : namer = determineNamer(compiler),
346 oneShotInterceptors = new Map<String, Selector>(), 412 oneShotInterceptors = new Map<String, Selector>(),
347 interceptedElements = new Map<SourceString, Set<Element>>(), 413 interceptedElements = new Map<SourceString, Set<Element>>(),
348 rti = new RuntimeTypes(compiler), 414 rti = new RuntimeTypes(compiler),
349 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), 415 specializedGetInterceptors = new Map<String, Set<ClassElement>>(),
350 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { 416 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) {
351 emitter = disableEval 417 emitter = disableEval
352 ? new CodeEmitterNoEvalTask(compiler, namer, generateSourceMap) 418 ? new CodeEmitterNoEvalTask(compiler, namer, generateSourceMap)
353 : new CodeEmitterTask(compiler, namer, generateSourceMap); 419 : new CodeEmitterTask(compiler, namer, generateSourceMap);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 ClassElement cls, Enqueuer enqueuer) { 665 ClassElement cls, Enqueuer enqueuer) {
600 if (enqueuer.isResolutionQueue) { 666 if (enqueuer.isResolutionQueue) {
601 cls.ensureResolved(compiler); 667 cls.ensureResolved(compiler);
602 cls.forEachMember((ClassElement classElement, Element member) { 668 cls.forEachMember((ClassElement classElement, Element member) {
603 if (member.isSynthesized) return; 669 if (member.isSynthesized) return;
604 // All methods on [Object] are shadowed by [Interceptor]. 670 // All methods on [Object] are shadowed by [Interceptor].
605 if (classElement == compiler.objectClass) return; 671 if (classElement == compiler.objectClass) return;
606 Set<Element> set = interceptedElements.putIfAbsent( 672 Set<Element> set = interceptedElements.putIfAbsent(
607 member.name, () => new Set<Element>()); 673 member.name, () => new Set<Element>());
608 set.add(member); 674 set.add(member);
609 if (classElement == jsInterceptorClass) return; 675 },
610 if (classElement.isMixinApplication) { 676 includeSuperAndInjectedMembers: true);
611 MixinApplicationElement mixinApplication = classElement; 677
612 assert(member.getEnclosingClass() == mixinApplication.mixin); 678 // Walk superclass chain to find mixins.
679 for (; cls != null; cls = cls.superclass) {
680 if (cls.isMixinApplication) {
681 MixinApplicationElement mixinApplication = cls;
613 classesMixedIntoNativeClasses.add(mixinApplication.mixin); 682 classesMixedIntoNativeClasses.add(mixinApplication.mixin);
614 } 683 }
615 }, 684 }
616 includeSuperAndInjectedMembers: true);
617 } 685 }
618 } 686 }
619 687
620 void addInterceptors(ClassElement cls, 688 void addInterceptors(ClassElement cls,
621 Enqueuer enqueuer, 689 Enqueuer enqueuer,
622 TreeElements elements) { 690 TreeElements elements) {
623 if (enqueuer.isResolutionQueue) { 691 if (enqueuer.isResolutionQueue) {
624 _interceptedClasses.add(jsInterceptorClass); 692 _interceptedClasses.add(jsInterceptorClass);
625 _interceptedClasses.add(cls); 693 _interceptedClasses.add(cls);
626 cls.ensureResolved(compiler); 694 cls.ensureResolved(compiler);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 addInterceptors(jsBoolClass, world, elements); 835 addInterceptors(jsBoolClass, world, elements);
768 addInterceptors(jsNullClass, world, elements); 836 addInterceptors(jsNullClass, world, elements);
769 if (compiler.enableTypeAssertions) { 837 if (compiler.enableTypeAssertions) {
770 // Unconditionally register the helper that checks if the 838 // Unconditionally register the helper that checks if the
771 // expression in an if/while/for is a boolean. 839 // expression in an if/while/for is a boolean.
772 // TODO(ngeoffray): Should we have the resolver register those instead? 840 // TODO(ngeoffray): Should we have the resolver register those instead?
773 Element e = 841 Element e =
774 compiler.findHelper(const SourceString('boolConversionCheck')); 842 compiler.findHelper(const SourceString('boolConversionCheck'));
775 if (e != null) enqueue(world, e, elements); 843 if (e != null) enqueue(world, e, elements);
776 } 844 }
845 registerCheckedModeHelpers(elements);
777 } 846 }
778 847
779 onResolutionComplete() => rti.computeClassesNeedingRti(); 848 onResolutionComplete() => rti.computeClassesNeedingRti();
780 849
781 void registerStringInterpolation(TreeElements elements) { 850 void registerStringInterpolation(TreeElements elements) {
782 enqueueInResolution(getStringInterpolationHelper(), elements); 851 enqueueInResolution(getStringInterpolationHelper(), elements);
783 } 852 }
784 853
785 void registerCatchStatement(Enqueuer enqueuer, TreeElements elements) { 854 void registerCatchStatement(Enqueuer enqueuer, TreeElements elements) {
786 void ensure(ClassElement classElement) { 855 void ensure(ClassElement classElement) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 enqueueInResolution(getCreateRuntimeType(), elements); 935 enqueueInResolution(getCreateRuntimeType(), elements);
867 } 936 }
868 937
869 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { 938 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) {
870 type = type.unalias(compiler); 939 type = type.unalias(compiler);
871 enqueueClass(world, compiler.boolClass, elements); 940 enqueueClass(world, compiler.boolClass, elements);
872 bool inCheckedMode = compiler.enableTypeAssertions; 941 bool inCheckedMode = compiler.enableTypeAssertions;
873 // [registerIsCheck] is also called for checked mode checks, so we 942 // [registerIsCheck] is also called for checked mode checks, so we
874 // need to register checked mode helpers. 943 // need to register checked mode helpers.
875 if (inCheckedMode) { 944 if (inCheckedMode) {
876 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false); 945 if (!world.isResolutionQueue) {
877 if (helper != null) enqueue(world, helper.getElement(compiler), elements); 946 // All helpers are added to resolution queue in enqueueHelpers.
878 // We also need the native variant of the check (for DOM types). 947 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: false);
879 helper = getNativeCheckedModeHelper(type, typeCast: false); 948 if (helper != null) {
880 if (helper != null) enqueue(world, helper.getElement(compiler), elements); 949 enqueue(world, helper.getElement(compiler), elements);
950 }
951 // We also need the native variant of the check (for DOM types).
952 helper = getNativeCheckedModeHelper(type, typeCast: false);
953 if (helper != null) {
954 enqueue(world, helper.getElement(compiler), elements);
955 }
956 }
881 } 957 }
882 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; 958 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE;
883 if (!type.isRaw || type.containsTypeVariables) { 959 if (!type.isRaw || type.containsTypeVariables) {
884 enqueueInResolution(getSetRuntimeTypeInfo(), elements); 960 enqueueInResolution(getSetRuntimeTypeInfo(), elements);
885 enqueueInResolution(getGetRuntimeTypeInfo(), elements); 961 enqueueInResolution(getGetRuntimeTypeInfo(), elements);
886 enqueueInResolution(getGetRuntimeTypeArgument(), elements); 962 enqueueInResolution(getGetRuntimeTypeArgument(), elements);
887 if (inCheckedMode) { 963 if (inCheckedMode) {
888 enqueueInResolution(getAssertSubtype(), elements); 964 enqueueInResolution(getAssertSubtype(), elements);
889 } 965 }
890 enqueueInResolution(getCheckSubtype(), elements); 966 enqueueInResolution(getCheckSubtype(), elements);
891 if (isTypeVariable) { 967 if (isTypeVariable) {
892 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements); 968 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements);
893 if (inCheckedMode) { 969 if (inCheckedMode) {
894 enqueueInResolution(getAssertSubtypeOfRuntimeType(), elements); 970 enqueueInResolution(getAssertSubtypeOfRuntimeType(), elements);
895 } 971 }
896 } 972 }
897 enqueueClass(world, compiler.listClass, elements); 973 enqueueClass(world, compiler.listClass, elements);
898 } 974 }
899 if (type is FunctionType) { 975 if (type is FunctionType) {
900 enqueueInResolution(getCheckFunctionSubtype(), elements); 976 enqueueInResolution(getCheckFunctionSubtype(), elements);
901 } 977 }
902 if (type.element.isNative()) { 978 if (type.element.isNative()) {
903 // We will neeed to add the "$is" and "$as" properties on the 979 // We will neeed to add the "$is" and "$as" properties on the
904 // JavaScript object prototype, so we make sure 980 // JavaScript object prototype, so we make sure
905 // [:defineProperty:] is compiled. 981 // [:defineProperty:] is compiled.
906 enqueue(world, 982 enqueue(world,
907 compiler.findHelper(const SourceString('defineProperty')), 983 compiler.findHelper(const SourceString('defineProperty')),
908 elements); 984 elements);
909 } 985 }
910 } 986 }
911 987
912 void registerAsCheck(DartType type, TreeElements elements) { 988 void registerAsCheck(DartType type, Enqueuer world, TreeElements elements) {
913 type = type.unalias(compiler); 989 type = type.unalias(compiler);
914 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: true); 990 if (!world.isResolutionQueue) {
915 enqueueInResolution(helper.getElement(compiler), elements); 991 // All helpers are added to resolution queue in enqueueHelpers.
916 // We also need the native variant of the check (for DOM types). 992 CheckedModeHelper helper = getCheckedModeHelper(type, typeCast: true);
917 helper = getNativeCheckedModeHelper(type, typeCast: true);
918 if (helper != null) {
919 enqueueInResolution(helper.getElement(compiler), elements); 993 enqueueInResolution(helper.getElement(compiler), elements);
994 // We also need the native variant of the check (for DOM types).
995 helper = getNativeCheckedModeHelper(type, typeCast: true);
996 if (helper != null) {
997 enqueueInResolution(helper.getElement(compiler), elements);
karlklose 2013/09/06 07:11:30 Doesn't this work only because we already resolved
998 }
920 } 999 }
921 } 1000 }
922 1001
923 void registerThrowNoSuchMethod(TreeElements elements) { 1002 void registerThrowNoSuchMethod(TreeElements elements) {
924 enqueueInResolution(getThrowNoSuchMethod(), elements); 1003 enqueueInResolution(getThrowNoSuchMethod(), elements);
925 // Also register the types of the arguments passed to this method. 1004 // Also register the types of the arguments passed to this method.
926 enqueueClass(compiler.enqueuer.resolution, compiler.listClass, elements); 1005 enqueueClass(compiler.enqueuer.resolution, compiler.listClass, elements);
927 enqueueClass(compiler.enqueuer.resolution, compiler.stringClass, elements); 1006 enqueueClass(compiler.enqueuer.resolution, compiler.stringClass, elements);
928 } 1007 }
929 1008
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 type, typeCast: typeCast, nativeCheckOnly: true); 1238 type, typeCast: typeCast, nativeCheckOnly: true);
1160 } 1239 }
1161 1240
1162 /** 1241 /**
1163 * Returns the checked mode helper for the type check/type cast for [type]. If 1242 * Returns the checked mode helper for the type check/type cast for [type]. If
1164 * [nativeCheckOnly] is [:true:], only names for native helpers are returned. 1243 * [nativeCheckOnly] is [:true:], only names for native helpers are returned.
1165 */ 1244 */
1166 CheckedModeHelper getCheckedModeHelperInternal(DartType type, 1245 CheckedModeHelper getCheckedModeHelperInternal(DartType type,
1167 {bool typeCast, 1246 {bool typeCast,
1168 bool nativeCheckOnly}) { 1247 bool nativeCheckOnly}) {
1248 String name = getCheckedModeHelperNameInternal(type,
1249 typeCast: typeCast, nativeCheckOnly: nativeCheckOnly);
1250 if (name == null) return null;
1251 CheckedModeHelper helper = checkedModeHelperByName[name];
1252 assert(helper != null);
1253 return helper;
1254 }
1255
1256 String getCheckedModeHelperNameInternal(DartType type,
1257 {bool typeCast,
1258 bool nativeCheckOnly}) {
1169 assert(type.kind != TypeKind.TYPEDEF); 1259 assert(type.kind != TypeKind.TYPEDEF);
1170 Element element = type.element; 1260 Element element = type.element;
1171 bool nativeCheck = nativeCheckOnly || 1261 bool nativeCheck = nativeCheckOnly ||
1172 emitter.nativeEmitter.requiresNativeIsCheck(element); 1262 emitter.nativeEmitter.requiresNativeIsCheck(element);
1173 if (type == compiler.types.voidType) { 1263 if (type == compiler.types.voidType) {
1174 assert(!typeCast); // Cannot cast to void. 1264 assert(!typeCast); // Cannot cast to void.
1175 if (nativeCheckOnly) return null; 1265 if (nativeCheckOnly) return null;
1176 return const CheckedModeHelper(const SourceString('voidTypeCheck')); 1266 return 'voidTypeCheck';
1177 } else if (element == jsStringClass || element == compiler.stringClass) { 1267 } else if (element == jsStringClass || element == compiler.stringClass) {
1178 if (nativeCheckOnly) return null; 1268 if (nativeCheckOnly) return null;
1179 return typeCast 1269 return typeCast
1180 ? const CheckedModeHelper(const SourceString("stringTypeCast")) 1270 ? 'stringTypeCast'
1181 : const CheckedModeHelper(const SourceString('stringTypeCheck')); 1271 : 'stringTypeCheck';
1182 } else if (element == jsDoubleClass || element == compiler.doubleClass) { 1272 } else if (element == jsDoubleClass || element == compiler.doubleClass) {
1183 if (nativeCheckOnly) return null; 1273 if (nativeCheckOnly) return null;
1184 return typeCast 1274 return typeCast
1185 ? const CheckedModeHelper(const SourceString("doubleTypeCast")) 1275 ? 'doubleTypeCast'
1186 : const CheckedModeHelper(const SourceString('doubleTypeCheck')); 1276 : 'doubleTypeCheck';
1187 } else if (element == jsNumberClass || element == compiler.numClass) { 1277 } else if (element == jsNumberClass || element == compiler.numClass) {
1188 if (nativeCheckOnly) return null; 1278 if (nativeCheckOnly) return null;
1189 return typeCast 1279 return typeCast
1190 ? const CheckedModeHelper(const SourceString("numTypeCast")) 1280 ? 'numTypeCast'
1191 : const CheckedModeHelper(const SourceString('numTypeCheck')); 1281 : 'numTypeCheck';
1192 } else if (element == jsBoolClass || element == compiler.boolClass) { 1282 } else if (element == jsBoolClass || element == compiler.boolClass) {
1193 if (nativeCheckOnly) return null; 1283 if (nativeCheckOnly) return null;
1194 return typeCast 1284 return typeCast
1195 ? const CheckedModeHelper(const SourceString("boolTypeCast")) 1285 ? 'boolTypeCast'
1196 : const CheckedModeHelper(const SourceString('boolTypeCheck')); 1286 : 'boolTypeCheck';
1197 } else if (element == jsIntClass || element == compiler.intClass) { 1287 } else if (element == jsIntClass || element == compiler.intClass) {
1198 if (nativeCheckOnly) return null; 1288 if (nativeCheckOnly) return null;
1199 return typeCast 1289 return typeCast
1200 ? const CheckedModeHelper(const SourceString("intTypeCast")) 1290 ? 'intTypeCast'
1201 : const CheckedModeHelper(const SourceString('intTypeCheck')); 1291 : 'intTypeCheck';
1202 } else if (Elements.isNumberOrStringSupertype(element, compiler)) { 1292 } else if (Elements.isNumberOrStringSupertype(element, compiler)) {
1203 if (nativeCheck) { 1293 if (nativeCheck) {
1204 return typeCast 1294 return typeCast
1205 ? const PropertyCheckedModeHelper( 1295 ? 'numberOrStringSuperNativeTypeCast'
1206 const SourceString("numberOrStringSuperNativeTypeCast")) 1296 : 'numberOrStringSuperNativeTypeCheck';
1207 : const PropertyCheckedModeHelper(
1208 const SourceString('numberOrStringSuperNativeTypeCheck'));
1209 } else { 1297 } else {
1210 return typeCast 1298 return typeCast
1211 ? const PropertyCheckedModeHelper( 1299 ? 'numberOrStringSuperTypeCast'
1212 const SourceString("numberOrStringSuperTypeCast")) 1300 : 'numberOrStringSuperTypeCheck';
1213 : const PropertyCheckedModeHelper(
1214 const SourceString('numberOrStringSuperTypeCheck'));
1215 } 1301 }
1216 } else if (Elements.isStringOnlySupertype(element, compiler)) { 1302 } else if (Elements.isStringOnlySupertype(element, compiler)) {
1217 if (nativeCheck) { 1303 if (nativeCheck) {
1218 return typeCast 1304 return typeCast
1219 ? const PropertyCheckedModeHelper( 1305 ? 'stringSuperNativeTypeCast'
1220 const SourceString("stringSuperNativeTypeCast")) 1306 : 'stringSuperNativeTypeCheck';
1221 : const PropertyCheckedModeHelper(
1222 const SourceString('stringSuperNativeTypeCheck'));
1223 } else { 1307 } else {
1224 return typeCast 1308 return typeCast
1225 ? const PropertyCheckedModeHelper( 1309 ? 'stringSuperTypeCast'
1226 const SourceString("stringSuperTypeCast")) 1310 : 'stringSuperTypeCheck';
1227 : const PropertyCheckedModeHelper(
1228 const SourceString('stringSuperTypeCheck'));
1229 } 1311 }
1230 } else if ((element == compiler.listClass || element == jsArrayClass) && 1312 } else if ((element == compiler.listClass || element == jsArrayClass) &&
1231 type.isRaw) { 1313 type.isRaw) {
1232 if (nativeCheckOnly) return null; 1314 if (nativeCheckOnly) return null;
1233 return typeCast 1315 return typeCast
1234 ? const CheckedModeHelper(const SourceString("listTypeCast")) 1316 ? 'listTypeCast'
1235 : const CheckedModeHelper(const SourceString('listTypeCheck')); 1317 : 'listTypeCheck';
1236 } else { 1318 } else {
1237 if (Elements.isListSupertype(element, compiler)) { 1319 if (Elements.isListSupertype(element, compiler)) {
1238 if (nativeCheck) { 1320 if (nativeCheck) {
1239 return typeCast 1321 return typeCast
1240 ? const PropertyCheckedModeHelper( 1322 ? 'listSuperNativeTypeCast'
1241 const SourceString("listSuperNativeTypeCast")) 1323 : 'listSuperNativeTypeCheck';
1242 : const PropertyCheckedModeHelper(
1243 const SourceString('listSuperNativeTypeCheck'));
1244 } else { 1324 } else {
1245 return typeCast 1325 return typeCast
1246 ? const PropertyCheckedModeHelper( 1326 ? 'listSuperTypeCast'
1247 const SourceString("listSuperTypeCast")) 1327 : 'listSuperTypeCheck';
1248 : const PropertyCheckedModeHelper(
1249 const SourceString('listSuperTypeCheck'));
1250 } 1328 }
1251 } else { 1329 } else {
1252 if (nativeCheck) { 1330 if (nativeCheck) {
1253 // TODO(karlklose): can we get rid of this branch when we use 1331 // TODO(karlklose): can we get rid of this branch when we use
1254 // interceptors? 1332 // interceptors?
1255 return typeCast 1333 return typeCast
1256 ? const PropertyCheckedModeHelper( 1334 ? 'interceptedTypeCast'
1257 const SourceString("interceptedTypeCast")) 1335 : 'interceptedTypeCheck';
1258 : const PropertyCheckedModeHelper(
1259 const SourceString('interceptedTypeCheck'));
1260 } else { 1336 } else {
1261 if (type.kind == TypeKind.INTERFACE && !type.isRaw) { 1337 if (type.kind == TypeKind.INTERFACE && !type.isRaw) {
1262 return typeCast 1338 return typeCast
1263 ? const SubtypeCheckedModeHelper( 1339 ? 'subtypeCast'
1264 const SourceString('subtypeCast')) 1340 : 'assertSubtype';
1265 : const SubtypeCheckedModeHelper(
1266 const SourceString('assertSubtype'));
1267 } else if (type.kind == TypeKind.TYPE_VARIABLE) { 1341 } else if (type.kind == TypeKind.TYPE_VARIABLE) {
1268 return typeCast 1342 return typeCast
1269 ? const TypeVariableCheckedModeHelper( 1343 ? 'subtypeOfRuntimeTypeCast'
1270 const SourceString('subtypeOfRuntimeTypeCast')) 1344 : 'assertSubtypeOfRuntimeType';
1271 : const TypeVariableCheckedModeHelper(
1272 const SourceString('assertSubtypeOfRuntimeType'));
1273 } else if (type.kind == TypeKind.FUNCTION) { 1345 } else if (type.kind == TypeKind.FUNCTION) {
1274 return typeCast 1346 return typeCast
1275 ? const FunctionTypeCheckedModeHelper( 1347 ? 'functionSubtypeCast'
1276 const SourceString('functionSubtypeCast')) 1348 : 'assertFunctionSubtype';
1277 : const FunctionTypeCheckedModeHelper(
1278 const SourceString('assertFunctionSubtype'));
1279 } else { 1349 } else {
1280 return typeCast 1350 return typeCast
1281 ? const PropertyCheckedModeHelper( 1351 ? 'propertyTypeCast'
1282 const SourceString('propertyTypeCast')) 1352 : 'propertyTypeCheck';
1283 : const PropertyCheckedModeHelper(
1284 const SourceString('propertyTypeCheck'));
1285 } 1353 }
1286 } 1354 }
1287 } 1355 }
1288 } 1356 }
1289 } 1357 }
1290 1358
1359 void registerCheckedModeHelpers(TreeElements elements) {
1360 for (CheckedModeHelper helper in checkedModeHelpers) {
1361 enqueueInResolution(helper.getElement(compiler), elements);
1362 }
1363 }
1364
1291 /** 1365 /**
1292 * Returns [:true:] if the checking of [type] is performed directly on the 1366 * Returns [:true:] if the checking of [type] is performed directly on the
1293 * object and not on an interceptor. 1367 * object and not on an interceptor.
1294 */ 1368 */
1295 bool hasDirectCheckFor(DartType type) { 1369 bool hasDirectCheckFor(DartType type) {
1296 Element element = type.element; 1370 Element element = type.element;
1297 return element == compiler.stringClass || 1371 return element == compiler.stringClass ||
1298 element == compiler.boolClass || 1372 element == compiler.boolClass ||
1299 element == compiler.numClass || 1373 element == compiler.numClass ||
1300 element == compiler.intClass || 1374 element == compiler.intClass ||
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 copy(constant.values); 1764 copy(constant.values);
1691 copy(constant.protoValue); 1765 copy(constant.protoValue);
1692 copy(constant); 1766 copy(constant);
1693 } 1767 }
1694 1768
1695 void visitConstructed(ConstructedConstant constant) { 1769 void visitConstructed(ConstructedConstant constant) {
1696 copy(constant.fields); 1770 copy(constant.fields);
1697 copy(constant); 1771 copy(constant);
1698 } 1772 }
1699 } 1773 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698