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 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 = new Set<HInstruction>(); | 8 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
9 final Set<HInstruction> allocatedFixedLists = new Set<HInstruction>(); | 9 final Set<HInstruction> allocatedFixedLists = new Set<HInstruction>(); |
10 } | 10 } |
(...skipping 17 matching lines...) Expand all Loading... |
28 return new jsAst.Call(new jsAst.VariableUse(helperName), arguments); | 28 return new jsAst.Call(new jsAst.VariableUse(helperName), arguments); |
29 } | 29 } |
30 | 30 |
31 void generateAdditionalArguments(SsaCodeGenerator codegen, | 31 void generateAdditionalArguments(SsaCodeGenerator codegen, |
32 HTypeConversion node, | 32 HTypeConversion node, |
33 List<jsAst.Expression> arguments) { | 33 List<jsAst.Expression> arguments) { |
34 // No additional arguments needed. | 34 // No additional arguments needed. |
35 } | 35 } |
36 } | 36 } |
37 | 37 |
| 38 class MalformedCheckedModeHelper extends CheckedModeHelper { |
| 39 const MalformedCheckedModeHelper(String name) : super(name); |
| 40 |
| 41 void generateAdditionalArguments(SsaCodeGenerator codegen, |
| 42 HTypeConversion node, |
| 43 List<jsAst.Expression> arguments) { |
| 44 ErroneousElement element = node.typeExpression.element; |
| 45 arguments.add(js.string(element.message)); |
| 46 } |
| 47 } |
| 48 |
38 class PropertyCheckedModeHelper extends CheckedModeHelper { | 49 class PropertyCheckedModeHelper extends CheckedModeHelper { |
39 const PropertyCheckedModeHelper(String name) : super(name); | 50 const PropertyCheckedModeHelper(String name) : super(name); |
40 | 51 |
41 void generateAdditionalArguments(SsaCodeGenerator codegen, | 52 void generateAdditionalArguments(SsaCodeGenerator codegen, |
42 HTypeConversion node, | 53 HTypeConversion node, |
43 List<jsAst.Expression> arguments) { | 54 List<jsAst.Expression> arguments) { |
44 DartType type = node.typeExpression; | 55 DartType type = node.typeExpression; |
45 String additionalArgument = codegen.backend.namer.operatorIsType(type); | 56 String additionalArgument = codegen.backend.namer.operatorIsType(type); |
46 arguments.add(js.string(additionalArgument)); | 57 arguments.add(js.string(additionalArgument)); |
47 } | 58 } |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 342 |
332 /// List of elements that the backend may use. | 343 /// List of elements that the backend may use. |
333 final Set<Element> helpersUsed = new Set<Element>(); | 344 final Set<Element> helpersUsed = new Set<Element>(); |
334 | 345 |
335 | 346 |
336 /// Set of typedefs that are used as type literals. | 347 /// Set of typedefs that are used as type literals. |
337 final Set<TypedefElement> typedefTypeLiterals = new Set<TypedefElement>(); | 348 final Set<TypedefElement> typedefTypeLiterals = new Set<TypedefElement>(); |
338 | 349 |
339 /// All the checked mode helpers. | 350 /// All the checked mode helpers. |
340 static const checkedModeHelpers = const [ | 351 static const checkedModeHelpers = const [ |
| 352 const MalformedCheckedModeHelper('checkMalformedType'), |
341 const CheckedModeHelper('voidTypeCheck'), | 353 const CheckedModeHelper('voidTypeCheck'), |
342 const CheckedModeHelper('stringTypeCast'), | 354 const CheckedModeHelper('stringTypeCast'), |
343 const CheckedModeHelper('stringTypeCheck'), | 355 const CheckedModeHelper('stringTypeCheck'), |
344 const CheckedModeHelper('doubleTypeCast'), | 356 const CheckedModeHelper('doubleTypeCast'), |
345 const CheckedModeHelper('doubleTypeCheck'), | 357 const CheckedModeHelper('doubleTypeCheck'), |
346 const CheckedModeHelper('numTypeCast'), | 358 const CheckedModeHelper('numTypeCast'), |
347 const CheckedModeHelper('numTypeCheck'), | 359 const CheckedModeHelper('numTypeCheck'), |
348 const CheckedModeHelper('boolTypeCast'), | 360 const CheckedModeHelper('boolTypeCast'), |
349 const CheckedModeHelper('boolTypeCheck'), | 361 const CheckedModeHelper('boolTypeCheck'), |
350 const CheckedModeHelper('intTypeCast'), | 362 const CheckedModeHelper('intTypeCast'), |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 enqueue(world, helper.getElement(compiler), elements); | 993 enqueue(world, helper.getElement(compiler), elements); |
982 } | 994 } |
983 // We also need the native variant of the check (for DOM types). | 995 // We also need the native variant of the check (for DOM types). |
984 helper = getNativeCheckedModeHelper(type, typeCast: false); | 996 helper = getNativeCheckedModeHelper(type, typeCast: false); |
985 if (helper != null) { | 997 if (helper != null) { |
986 enqueue(world, helper.getElement(compiler), elements); | 998 enqueue(world, helper.getElement(compiler), elements); |
987 } | 999 } |
988 } | 1000 } |
989 } | 1001 } |
990 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; | 1002 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; |
| 1003 if (type.kind == TypeKind.MALFORMED_TYPE) { |
| 1004 enqueueInResolution(getThrowTypeError(), elements); |
| 1005 } |
991 if (!type.treatAsRaw || type.containsTypeVariables) { | 1006 if (!type.treatAsRaw || type.containsTypeVariables) { |
992 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 1007 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
993 enqueueInResolution(getGetRuntimeTypeInfo(), elements); | 1008 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
994 enqueueInResolution(getGetRuntimeTypeArgument(), elements); | 1009 enqueueInResolution(getGetRuntimeTypeArgument(), elements); |
995 if (inCheckedMode) { | 1010 if (inCheckedMode) { |
996 enqueueInResolution(getAssertSubtype(), elements); | 1011 enqueueInResolution(getAssertSubtype(), elements); |
997 } | 1012 } |
998 enqueueInResolution(getCheckSubtype(), elements); | 1013 enqueueInResolution(getCheckSubtype(), elements); |
999 if (isTypeVariable) { | 1014 if (isTypeVariable) { |
1000 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements); | 1015 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 if (name == null) return null; | 1332 if (name == null) return null; |
1318 CheckedModeHelper helper = checkedModeHelperByName[name]; | 1333 CheckedModeHelper helper = checkedModeHelperByName[name]; |
1319 assert(helper != null); | 1334 assert(helper != null); |
1320 return helper; | 1335 return helper; |
1321 } | 1336 } |
1322 | 1337 |
1323 String getCheckedModeHelperNameInternal(DartType type, | 1338 String getCheckedModeHelperNameInternal(DartType type, |
1324 {bool typeCast, | 1339 {bool typeCast, |
1325 bool nativeCheckOnly}) { | 1340 bool nativeCheckOnly}) { |
1326 assert(type.kind != TypeKind.TYPEDEF); | 1341 assert(type.kind != TypeKind.TYPEDEF); |
| 1342 if (type.kind == TypeKind.MALFORMED_TYPE) { |
| 1343 // The same error is thrown for type test and type cast of a malformed |
| 1344 // type so we only need one check method. |
| 1345 return 'checkMalformedType'; |
| 1346 } |
1327 Element element = type.element; | 1347 Element element = type.element; |
1328 bool nativeCheck = nativeCheckOnly || | 1348 bool nativeCheck = nativeCheckOnly || |
1329 emitter.nativeEmitter.requiresNativeIsCheck(element); | 1349 emitter.nativeEmitter.requiresNativeIsCheck(element); |
1330 | 1350 |
1331 // TODO(13955), TODO(9731). The test for non-primitive types should use an | 1351 // TODO(13955), TODO(9731). The test for non-primitive types should use an |
1332 // interceptor. The interceptor should be an argument to HTypeConversion so | 1352 // interceptor. The interceptor should be an argument to HTypeConversion so |
1333 // that it can be optimized by standard interceptor optimizations. | 1353 // that it can be optimized by standard interceptor optimizations. |
1334 nativeCheck = true; | 1354 nativeCheck = true; |
1335 | 1355 |
1336 if (type == compiler.types.voidType) { | 1356 if (type == compiler.types.voidType) { |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1861 copy(constant.values); | 1881 copy(constant.values); |
1862 copy(constant.protoValue); | 1882 copy(constant.protoValue); |
1863 copy(constant); | 1883 copy(constant); |
1864 } | 1884 } |
1865 | 1885 |
1866 void visitConstructed(ConstructedConstant constant) { | 1886 void visitConstructed(ConstructedConstant constant) { |
1867 copy(constant.fields); | 1887 copy(constant.fields); |
1868 copy(constant); | 1888 copy(constant); |
1869 } | 1889 } |
1870 } | 1890 } |
OLD | NEW |