| 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 typedef void Recompile(Element element); | 7 typedef void Recompile(Element element); |
| 8 | 8 |
| 9 class ReturnInfo { | 9 class ReturnInfo { |
| 10 HType returnType; | 10 HType returnType; |
| (...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 | 1227 |
| 1228 void registerTypeVariableExpression(TreeElements elements) { | 1228 void registerTypeVariableExpression(TreeElements elements) { |
| 1229 registerRuntimeType(elements); | 1229 registerRuntimeType(elements); |
| 1230 enqueueInResolution(getRuntimeTypeToString(), elements); | 1230 enqueueInResolution(getRuntimeTypeToString(), elements); |
| 1231 enqueueInResolution(getCreateRuntimeType(), elements); | 1231 enqueueInResolution(getCreateRuntimeType(), elements); |
| 1232 } | 1232 } |
| 1233 | 1233 |
| 1234 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { | 1234 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| 1235 world.registerInstantiatedClass(compiler.boolClass, elements); | 1235 world.registerInstantiatedClass(compiler.boolClass, elements); |
| 1236 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; | 1236 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; |
| 1237 bool inCheckedMode = compiler.enableTypeAssertions; |
| 1237 if (!type.isRaw || isTypeVariable) { | 1238 if (!type.isRaw || isTypeVariable) { |
| 1238 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 1239 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 1239 enqueueInResolution(getGetRuntimeTypeInfo(), elements); | 1240 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
| 1240 enqueueInResolution(getGetRuntimeTypeArgument(), elements); | 1241 enqueueInResolution(getGetRuntimeTypeArgument(), elements); |
| 1242 if (inCheckedMode) { |
| 1243 enqueueInResolution(getAssertSubtype(), elements); |
| 1244 } |
| 1241 enqueueInResolution(getCheckSubtype(), elements); | 1245 enqueueInResolution(getCheckSubtype(), elements); |
| 1242 if (isTypeVariable) { | 1246 if (isTypeVariable) { |
| 1243 enqueueInResolution(getGetObjectIsSubtype(), elements); | 1247 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements); |
| 1248 if (inCheckedMode) { |
| 1249 enqueueInResolution(getAssertSubtypeOfRuntimeType(), elements); |
| 1250 } |
| 1244 } | 1251 } |
| 1245 world.registerInstantiatedClass(compiler.listClass, elements); | 1252 world.registerInstantiatedClass(compiler.listClass, elements); |
| 1246 } | 1253 } |
| 1247 // [registerIsCheck] is also called for checked mode checks, so we | 1254 // [registerIsCheck] is also called for checked mode checks, so we |
| 1248 // need to register checked mode helpers. | 1255 // need to register checked mode helpers. |
| 1249 if (compiler.enableTypeAssertions) { | 1256 if (inCheckedMode) { |
| 1250 Element e = getCheckedModeHelper(type, typeCast: false); | 1257 Element e = getCheckedModeHelper(type, typeCast: false); |
| 1251 if (e != null) world.addToWorkList(e); | 1258 if (e != null) world.addToWorkList(e); |
| 1252 // We also need the native variant of the check (for DOM types). | 1259 // We also need the native variant of the check (for DOM types). |
| 1253 e = getNativeCheckedModeHelper(type, typeCast: false); | 1260 e = getNativeCheckedModeHelper(type, typeCast: false); |
| 1254 if (e != null) world.addToWorkList(e); | 1261 if (e != null) world.addToWorkList(e); |
| 1255 } | 1262 } |
| 1256 if (type.element.isNative()) { | 1263 if (type.element.isNative()) { |
| 1257 // We will neeed to add the "$is" and "$as" properties on the | 1264 // We will neeed to add the "$is" and "$as" properties on the |
| 1258 // JavaScript object prototype, so we make sure | 1265 // JavaScript object prototype, so we make sure |
| 1259 // [:defineProperty:] is compiled. | 1266 // [:defineProperty:] is compiled. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 }); | 1332 }); |
| 1326 } | 1333 } |
| 1327 // TODO(ngeoffray): Also handle T a (in checked mode). | 1334 // TODO(ngeoffray): Also handle T a (in checked mode). |
| 1328 } | 1335 } |
| 1329 | 1336 |
| 1330 void registerClassUsingVariableExpression(ClassElement cls) { | 1337 void registerClassUsingVariableExpression(ClassElement cls) { |
| 1331 rti.classesUsingTypeVariableExpression.add(cls); | 1338 rti.classesUsingTypeVariableExpression.add(cls); |
| 1332 } | 1339 } |
| 1333 | 1340 |
| 1334 bool needsRti(ClassElement cls) { | 1341 bool needsRti(ClassElement cls) { |
| 1335 return rti.classesNeedingRti.contains(cls.declaration) | 1342 return rti.classesNeedingRti.contains(cls.declaration) || |
| 1336 || compiler.enabledRuntimeType; | 1343 compiler.enabledRuntimeType; |
| 1337 } | 1344 } |
| 1338 | 1345 |
| 1339 bool isDefaultNoSuchMethodImplementation(Element element) { | 1346 bool isDefaultNoSuchMethodImplementation(Element element) { |
| 1340 assert(element.name == Compiler.NO_SUCH_METHOD); | 1347 assert(element.name == Compiler.NO_SUCH_METHOD); |
| 1341 ClassElement classElement = element.getEnclosingClass(); | 1348 ClassElement classElement = element.getEnclosingClass(); |
| 1342 return classElement == compiler.objectClass | 1349 return classElement == compiler.objectClass |
| 1343 || classElement == jsInterceptorClass; | 1350 || classElement == jsInterceptorClass; |
| 1344 } | 1351 } |
| 1345 | 1352 |
| 1346 bool isDefaultEqualityImplementation(Element element) { | 1353 bool isDefaultEqualityImplementation(Element element) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 } | 1598 } |
| 1592 } | 1599 } |
| 1593 | 1600 |
| 1594 /** | 1601 /** |
| 1595 * Returns the checked mode helper that will be needed to do a type check/type | 1602 * Returns the checked mode helper that will be needed to do a type check/type |
| 1596 * cast on [type] at runtime. Note that this method is being called both by | 1603 * cast on [type] at runtime. Note that this method is being called both by |
| 1597 * the resolver with interface types (int, String, ...), and by the SSA | 1604 * the resolver with interface types (int, String, ...), and by the SSA |
| 1598 * backend with implementation types (JSInt, JSString, ...). | 1605 * backend with implementation types (JSInt, JSString, ...). |
| 1599 */ | 1606 */ |
| 1600 Element getCheckedModeHelper(DartType type, {bool typeCast}) { | 1607 Element getCheckedModeHelper(DartType type, {bool typeCast}) { |
| 1601 return compiler.findHelper(getCheckedModeHelperName( | 1608 SourceString name = getCheckedModeHelperName( |
| 1602 type, typeCast: typeCast, nativeCheckOnly: false)); | 1609 type, typeCast: typeCast, nativeCheckOnly: false); |
| 1610 return compiler.findHelper(name); |
| 1603 } | 1611 } |
| 1604 | 1612 |
| 1605 /** | 1613 /** |
| 1606 * Returns the native checked mode helper that will be needed to do a type | 1614 * Returns the native checked mode helper that will be needed to do a type |
| 1607 * check/type cast on [type] at runtime. If no native helper exists for | 1615 * check/type cast on [type] at runtime. If no native helper exists for |
| 1608 * [type], [:null:] is returned. | 1616 * [type], [:null:] is returned. |
| 1609 */ | 1617 */ |
| 1610 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) { | 1618 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) { |
| 1611 SourceString sourceName = getCheckedModeHelperName( | 1619 SourceString sourceName = getCheckedModeHelperName( |
| 1612 type, typeCast: typeCast, nativeCheckOnly: true); | 1620 type, typeCast: typeCast, nativeCheckOnly: true); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1697 return typeCast | 1705 return typeCast |
| 1698 ? const SourceString("listSuperNativeTypeCast") | 1706 ? const SourceString("listSuperNativeTypeCast") |
| 1699 : const SourceString('listSuperNativeTypeCheck'); | 1707 : const SourceString('listSuperNativeTypeCheck'); |
| 1700 } else { | 1708 } else { |
| 1701 return typeCast | 1709 return typeCast |
| 1702 ? const SourceString("listSuperTypeCast") | 1710 ? const SourceString("listSuperTypeCast") |
| 1703 : const SourceString('listSuperTypeCheck'); | 1711 : const SourceString('listSuperTypeCheck'); |
| 1704 } | 1712 } |
| 1705 } else { | 1713 } else { |
| 1706 if (nativeCheck) { | 1714 if (nativeCheck) { |
| 1715 // TODO(karlklose): can we get rid of this branch when we use |
| 1716 // interceptors? |
| 1707 return typeCast | 1717 return typeCast |
| 1708 ? const SourceString("interceptedTypeCast") | 1718 ? const SourceString("interceptedTypeCast") |
| 1709 : const SourceString('interceptedTypeCheck'); | 1719 : const SourceString('interceptedTypeCheck'); |
| 1710 } else { | 1720 } else { |
| 1711 return typeCast | 1721 if (typeCast) { |
| 1712 ? const SourceString("propertyTypeCast") | 1722 return const SourceString("propertyTypeCast"); |
| 1713 : const SourceString('propertyTypeCheck'); | 1723 } |
| 1724 if (type.kind == TypeKind.INTERFACE && !type.isRaw) { |
| 1725 return const SourceString('assertSubtype'); |
| 1726 } else if (type.kind == TypeKind.TYPE_VARIABLE) { |
| 1727 return const SourceString('assertSubtypeOfRuntimeType'); |
| 1728 } else { |
| 1729 return const SourceString('propertyTypeCheck'); |
| 1730 } |
| 1714 } | 1731 } |
| 1715 } | 1732 } |
| 1716 } | 1733 } |
| 1717 } | 1734 } |
| 1718 | 1735 |
| 1719 void dumpInferredTypes() { | 1736 void dumpInferredTypes() { |
| 1720 print("Inferred argument types:"); | 1737 print("Inferred argument types:"); |
| 1721 print("------------------------"); | 1738 print("------------------------"); |
| 1722 argumentTypes.dump(); | 1739 argumentTypes.dump(); |
| 1723 print(""); | 1740 print(""); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1786 } | 1803 } |
| 1787 | 1804 |
| 1788 Element getRuntimeTypeToString() { | 1805 Element getRuntimeTypeToString() { |
| 1789 return compiler.findHelper(const SourceString('runtimeTypeToString')); | 1806 return compiler.findHelper(const SourceString('runtimeTypeToString')); |
| 1790 } | 1807 } |
| 1791 | 1808 |
| 1792 Element getCheckSubtype() { | 1809 Element getCheckSubtype() { |
| 1793 return compiler.findHelper(const SourceString('checkSubtype')); | 1810 return compiler.findHelper(const SourceString('checkSubtype')); |
| 1794 } | 1811 } |
| 1795 | 1812 |
| 1796 Element getGetObjectIsSubtype() { | 1813 Element getAssertSubtype() { |
| 1797 return compiler.findHelper(const SourceString('objectIsSubtype')); | 1814 return compiler.findHelper(const SourceString('assertSubtype')); |
| 1815 } |
| 1816 |
| 1817 Element getCheckSubtypeOfRuntimeType() { |
| 1818 return compiler.findHelper(const SourceString('checkSubtypeOfRuntimeType')); |
| 1819 } |
| 1820 |
| 1821 Element getAssertSubtypeOfRuntimeType() { |
| 1822 return compiler.findHelper( |
| 1823 const SourceString('assertSubtypeOfRuntimeType')); |
| 1798 } | 1824 } |
| 1799 | 1825 |
| 1800 Element getThrowNoSuchMethod() { | 1826 Element getThrowNoSuchMethod() { |
| 1801 return compiler.findHelper(const SourceString('throwNoSuchMethod')); | 1827 return compiler.findHelper(const SourceString('throwNoSuchMethod')); |
| 1802 } | 1828 } |
| 1803 | 1829 |
| 1804 Element getCreateRuntimeType() { | 1830 Element getCreateRuntimeType() { |
| 1805 return compiler.findHelper(const SourceString('createRuntimeType')); | 1831 return compiler.findHelper(const SourceString('createRuntimeType')); |
| 1806 } | 1832 } |
| 1807 | 1833 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 ClassElement get constListImplementation => jsArrayClass; | 1868 ClassElement get constListImplementation => jsArrayClass; |
| 1843 ClassElement get fixedListImplementation => jsFixedArrayClass; | 1869 ClassElement get fixedListImplementation => jsFixedArrayClass; |
| 1844 ClassElement get growableListImplementation => jsExtendableArrayClass; | 1870 ClassElement get growableListImplementation => jsExtendableArrayClass; |
| 1845 ClassElement get mapImplementation => mapLiteralClass; | 1871 ClassElement get mapImplementation => mapLiteralClass; |
| 1846 ClassElement get constMapImplementation => constMapLiteralClass; | 1872 ClassElement get constMapImplementation => constMapLiteralClass; |
| 1847 ClassElement get functionImplementation => jsFunctionClass; | 1873 ClassElement get functionImplementation => jsFunctionClass; |
| 1848 ClassElement get typeImplementation => typeLiteralClass; | 1874 ClassElement get typeImplementation => typeLiteralClass; |
| 1849 ClassElement get boolImplementation => jsBoolClass; | 1875 ClassElement get boolImplementation => jsBoolClass; |
| 1850 ClassElement get nullImplementation => jsNullClass; | 1876 ClassElement get nullImplementation => jsNullClass; |
| 1851 } | 1877 } |
| OLD | NEW |