| 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 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 | 1222 |
| 1223 void registerTypeVariableExpression(TreeElements elements) { | 1223 void registerTypeVariableExpression(TreeElements elements) { |
| 1224 registerRuntimeType(elements); | 1224 registerRuntimeType(elements); |
| 1225 enqueueInResolution(getRuntimeTypeToString(), elements); | 1225 enqueueInResolution(getRuntimeTypeToString(), elements); |
| 1226 enqueueInResolution(getCreateRuntimeType(), elements); | 1226 enqueueInResolution(getCreateRuntimeType(), elements); |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { | 1229 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| 1230 world.registerInstantiatedClass(compiler.boolClass, elements); | 1230 world.registerInstantiatedClass(compiler.boolClass, elements); |
| 1231 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; | 1231 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; |
| 1232 bool inCheckedMode = compiler.enableTypeAssertions; | |
| 1233 if (!type.isRaw || isTypeVariable) { | 1232 if (!type.isRaw || isTypeVariable) { |
| 1234 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 1233 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 1235 enqueueInResolution(getGetRuntimeTypeInfo(), elements); | 1234 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
| 1236 enqueueInResolution(getGetRuntimeTypeArgument(), elements); | 1235 enqueueInResolution(getGetRuntimeTypeArgument(), elements); |
| 1237 if (inCheckedMode) { | |
| 1238 enqueueInResolution(getAssertSubtype(), elements); | |
| 1239 } | |
| 1240 enqueueInResolution(getCheckSubtype(), elements); | 1236 enqueueInResolution(getCheckSubtype(), elements); |
| 1241 if (isTypeVariable) { | 1237 if (isTypeVariable) { |
| 1242 enqueueInResolution(getCheckSubtypeOfRuntimeType(), elements); | 1238 enqueueInResolution(getGetObjectIsSubtype(), elements); |
| 1243 if (inCheckedMode) { | |
| 1244 enqueueInResolution(getAssertSubtypeOfRuntimeType(), elements); | |
| 1245 } | |
| 1246 } | 1239 } |
| 1247 world.registerInstantiatedClass(compiler.listClass, elements); | 1240 world.registerInstantiatedClass(compiler.listClass, elements); |
| 1248 } | 1241 } |
| 1249 // [registerIsCheck] is also called for checked mode checks, so we | 1242 // [registerIsCheck] is also called for checked mode checks, so we |
| 1250 // need to register checked mode helpers. | 1243 // need to register checked mode helpers. |
| 1251 if (inCheckedMode) { | 1244 if (compiler.enableTypeAssertions) { |
| 1252 Element e = getCheckedModeHelper(type, typeCast: false); | 1245 Element e = getCheckedModeHelper(type, typeCast: false); |
| 1253 if (e != null) world.addToWorkList(e); | 1246 if (e != null) world.addToWorkList(e); |
| 1254 // We also need the native variant of the check (for DOM types). | 1247 // We also need the native variant of the check (for DOM types). |
| 1255 e = getNativeCheckedModeHelper(type, typeCast: false); | 1248 e = getNativeCheckedModeHelper(type, typeCast: false); |
| 1256 if (e != null) world.addToWorkList(e); | 1249 if (e != null) world.addToWorkList(e); |
| 1257 } | 1250 } |
| 1258 if (type.element.isNative()) { | 1251 if (type.element.isNative()) { |
| 1259 // We will neeed to add the "$is" and "$as" properties on the | 1252 // We will neeed to add the "$is" and "$as" properties on the |
| 1260 // JavaScript object prototype, so we make sure | 1253 // JavaScript object prototype, so we make sure |
| 1261 // [:defineProperty:] is compiled. | 1254 // [:defineProperty:] is compiled. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 }); | 1320 }); |
| 1328 } | 1321 } |
| 1329 // TODO(ngeoffray): Also handle T a (in checked mode). | 1322 // TODO(ngeoffray): Also handle T a (in checked mode). |
| 1330 } | 1323 } |
| 1331 | 1324 |
| 1332 void registerClassUsingVariableExpression(ClassElement cls) { | 1325 void registerClassUsingVariableExpression(ClassElement cls) { |
| 1333 rti.classesUsingTypeVariableExpression.add(cls); | 1326 rti.classesUsingTypeVariableExpression.add(cls); |
| 1334 } | 1327 } |
| 1335 | 1328 |
| 1336 bool needsRti(ClassElement cls) { | 1329 bool needsRti(ClassElement cls) { |
| 1337 return rti.classesNeedingRti.contains(cls.declaration) || | 1330 return rti.classesNeedingRti.contains(cls.declaration) |
| 1338 compiler.enabledRuntimeType; | 1331 || compiler.enabledRuntimeType; |
| 1339 } | 1332 } |
| 1340 | 1333 |
| 1341 bool isDefaultNoSuchMethodImplementation(Element element) { | 1334 bool isDefaultNoSuchMethodImplementation(Element element) { |
| 1342 assert(element.name == Compiler.NO_SUCH_METHOD); | 1335 assert(element.name == Compiler.NO_SUCH_METHOD); |
| 1343 ClassElement classElement = element.getEnclosingClass(); | 1336 ClassElement classElement = element.getEnclosingClass(); |
| 1344 return classElement == compiler.objectClass | 1337 return classElement == compiler.objectClass |
| 1345 || classElement == jsInterceptorClass; | 1338 || classElement == jsInterceptorClass; |
| 1346 } | 1339 } |
| 1347 | 1340 |
| 1348 bool isDefaultEqualityImplementation(Element element) { | 1341 bool isDefaultEqualityImplementation(Element element) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1593 } | 1586 } |
| 1594 } | 1587 } |
| 1595 | 1588 |
| 1596 /** | 1589 /** |
| 1597 * Returns the checked mode helper that will be needed to do a type check/type | 1590 * Returns the checked mode helper that will be needed to do a type check/type |
| 1598 * cast on [type] at runtime. Note that this method is being called both by | 1591 * cast on [type] at runtime. Note that this method is being called both by |
| 1599 * the resolver with interface types (int, String, ...), and by the SSA | 1592 * the resolver with interface types (int, String, ...), and by the SSA |
| 1600 * backend with implementation types (JSInt, JSString, ...). | 1593 * backend with implementation types (JSInt, JSString, ...). |
| 1601 */ | 1594 */ |
| 1602 Element getCheckedModeHelper(DartType type, {bool typeCast}) { | 1595 Element getCheckedModeHelper(DartType type, {bool typeCast}) { |
| 1603 SourceString name = getCheckedModeHelperName( | 1596 return compiler.findHelper(getCheckedModeHelperName( |
| 1604 type, typeCast: typeCast, nativeCheckOnly: false); | 1597 type, typeCast: typeCast, nativeCheckOnly: false)); |
| 1605 return compiler.findHelper(name); | |
| 1606 } | 1598 } |
| 1607 | 1599 |
| 1608 /** | 1600 /** |
| 1609 * Returns the native checked mode helper that will be needed to do a type | 1601 * Returns the native checked mode helper that will be needed to do a type |
| 1610 * check/type cast on [type] at runtime. If no native helper exists for | 1602 * check/type cast on [type] at runtime. If no native helper exists for |
| 1611 * [type], [:null:] is returned. | 1603 * [type], [:null:] is returned. |
| 1612 */ | 1604 */ |
| 1613 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) { | 1605 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) { |
| 1614 SourceString sourceName = getCheckedModeHelperName( | 1606 SourceString sourceName = getCheckedModeHelperName( |
| 1615 type, typeCast: typeCast, nativeCheckOnly: true); | 1607 type, typeCast: typeCast, nativeCheckOnly: true); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1694 return typeCast | 1686 return typeCast |
| 1695 ? const SourceString("listSuperNativeTypeCast") | 1687 ? const SourceString("listSuperNativeTypeCast") |
| 1696 : const SourceString('listSuperNativeTypeCheck'); | 1688 : const SourceString('listSuperNativeTypeCheck'); |
| 1697 } else { | 1689 } else { |
| 1698 return typeCast | 1690 return typeCast |
| 1699 ? const SourceString("listSuperTypeCast") | 1691 ? const SourceString("listSuperTypeCast") |
| 1700 : const SourceString('listSuperTypeCheck'); | 1692 : const SourceString('listSuperTypeCheck'); |
| 1701 } | 1693 } |
| 1702 } else { | 1694 } else { |
| 1703 if (nativeCheck) { | 1695 if (nativeCheck) { |
| 1704 // TODO(karlklose): can we get rid of this branch when we use | |
| 1705 // interceptors? | |
| 1706 return typeCast | 1696 return typeCast |
| 1707 ? const SourceString("interceptedTypeCast") | 1697 ? const SourceString("interceptedTypeCast") |
| 1708 : const SourceString('interceptedTypeCheck'); | 1698 : const SourceString('interceptedTypeCheck'); |
| 1709 } else { | 1699 } else { |
| 1710 if (typeCast) { | 1700 return typeCast |
| 1711 return const SourceString("propertyTypeCast"); | 1701 ? const SourceString("propertyTypeCast") |
| 1712 } | 1702 : const SourceString('propertyTypeCheck'); |
| 1713 if (type.kind == TypeKind.INTERFACE && !type.isRaw) { | |
| 1714 return const SourceString('assertSubtype'); | |
| 1715 } else if (type.kind == TypeKind.TYPE_VARIABLE) { | |
| 1716 return const SourceString('assertSubtypeOfRuntimeType'); | |
| 1717 } else { | |
| 1718 return const SourceString('propertyTypeCheck'); | |
| 1719 } | |
| 1720 } | 1703 } |
| 1721 } | 1704 } |
| 1722 } | 1705 } |
| 1723 } | 1706 } |
| 1724 | 1707 |
| 1725 void dumpInferredTypes() { | 1708 void dumpInferredTypes() { |
| 1726 print("Inferred argument types:"); | 1709 print("Inferred argument types:"); |
| 1727 print("------------------------"); | 1710 print("------------------------"); |
| 1728 argumentTypes.dump(); | 1711 argumentTypes.dump(); |
| 1729 print(""); | 1712 print(""); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 } | 1775 } |
| 1793 | 1776 |
| 1794 Element getRuntimeTypeToString() { | 1777 Element getRuntimeTypeToString() { |
| 1795 return compiler.findHelper(const SourceString('runtimeTypeToString')); | 1778 return compiler.findHelper(const SourceString('runtimeTypeToString')); |
| 1796 } | 1779 } |
| 1797 | 1780 |
| 1798 Element getCheckSubtype() { | 1781 Element getCheckSubtype() { |
| 1799 return compiler.findHelper(const SourceString('checkSubtype')); | 1782 return compiler.findHelper(const SourceString('checkSubtype')); |
| 1800 } | 1783 } |
| 1801 | 1784 |
| 1802 Element getAssertSubtype() { | 1785 Element getGetObjectIsSubtype() { |
| 1803 return compiler.findHelper(const SourceString('assertSubtype')); | 1786 return compiler.findHelper(const SourceString('objectIsSubtype')); |
| 1804 } | |
| 1805 | |
| 1806 Element getCheckSubtypeOfRuntimeType() { | |
| 1807 return compiler.findHelper(const SourceString('checkSubtypeOfRuntimeType')); | |
| 1808 } | |
| 1809 | |
| 1810 Element getAssertSubtypeOfRuntimeType() { | |
| 1811 return compiler.findHelper( | |
| 1812 const SourceString('assertSubtypeOfRuntimeType')); | |
| 1813 } | 1787 } |
| 1814 | 1788 |
| 1815 Element getThrowNoSuchMethod() { | 1789 Element getThrowNoSuchMethod() { |
| 1816 return compiler.findHelper(const SourceString('throwNoSuchMethod')); | 1790 return compiler.findHelper(const SourceString('throwNoSuchMethod')); |
| 1817 } | 1791 } |
| 1818 | 1792 |
| 1819 Element getCreateRuntimeType() { | 1793 Element getCreateRuntimeType() { |
| 1820 return compiler.findHelper(const SourceString('createRuntimeType')); | 1794 return compiler.findHelper(const SourceString('createRuntimeType')); |
| 1821 } | 1795 } |
| 1822 | 1796 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1856 ClassElement get listImplementation => jsArrayClass; | 1830 ClassElement get listImplementation => jsArrayClass; |
| 1857 ClassElement get constListImplementation => jsArrayClass; | 1831 ClassElement get constListImplementation => jsArrayClass; |
| 1858 ClassElement get fixedListImplementation => jsFixedArrayClass; | 1832 ClassElement get fixedListImplementation => jsFixedArrayClass; |
| 1859 ClassElement get growableListImplementation => jsExtendableArrayClass; | 1833 ClassElement get growableListImplementation => jsExtendableArrayClass; |
| 1860 ClassElement get mapImplementation => mapLiteralClass; | 1834 ClassElement get mapImplementation => mapLiteralClass; |
| 1861 ClassElement get constMapImplementation => constMapLiteralClass; | 1835 ClassElement get constMapImplementation => constMapLiteralClass; |
| 1862 ClassElement get typeImplementation => typeLiteralClass; | 1836 ClassElement get typeImplementation => typeLiteralClass; |
| 1863 ClassElement get boolImplementation => jsBoolClass; | 1837 ClassElement get boolImplementation => jsBoolClass; |
| 1864 ClassElement get nullImplementation => jsNullClass; | 1838 ClassElement get nullImplementation => jsNullClass; |
| 1865 } | 1839 } |
| OLD | NEW |