Chromium Code Reviews| 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 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1215 | 1215 |
| 1216 void registerTypeVariableExpression(TreeElements elements) { | 1216 void registerTypeVariableExpression(TreeElements elements) { |
| 1217 registerRuntimeType(elements); | 1217 registerRuntimeType(elements); |
| 1218 enqueueInResolution(getRuntimeTypeToString(), elements); | 1218 enqueueInResolution(getRuntimeTypeToString(), elements); |
| 1219 enqueueInResolution(getCreateRuntimeType(), elements); | 1219 enqueueInResolution(getCreateRuntimeType(), elements); |
| 1220 } | 1220 } |
| 1221 | 1221 |
| 1222 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { | 1222 void registerIsCheck(DartType type, Enqueuer world, TreeElements elements) { |
| 1223 world.registerInstantiatedClass(compiler.boolClass, elements); | 1223 world.registerInstantiatedClass(compiler.boolClass, elements); |
| 1224 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; | 1224 bool isTypeVariable = type.kind == TypeKind.TYPE_VARIABLE; |
| 1225 bool isCheckedMode = compiler.enableTypeAssertions; | |
|
ngeoffray
2013/05/13 09:10:59
isCheckedMode -> inCheckedMode ?
karlklose
2013/05/14 13:49:41
Done.
| |
| 1225 if (!type.isRaw || isTypeVariable) { | 1226 if (!type.isRaw || isTypeVariable) { |
| 1226 enqueueInResolution(getSetRuntimeTypeInfo(), elements); | 1227 enqueueInResolution(getSetRuntimeTypeInfo(), elements); |
| 1227 enqueueInResolution(getGetRuntimeTypeInfo(), elements); | 1228 enqueueInResolution(getGetRuntimeTypeInfo(), elements); |
| 1228 enqueueInResolution(getGetRuntimeTypeArgument(), elements); | 1229 enqueueInResolution(getGetRuntimeTypeArgument(), elements); |
| 1230 if (isCheckedMode) { | |
| 1231 enqueueInResolution(getAssertSubtype(), elements); | |
| 1232 } | |
| 1229 enqueueInResolution(getCheckSubtype(), elements); | 1233 enqueueInResolution(getCheckSubtype(), elements); |
| 1230 if (isTypeVariable) { | 1234 if (isTypeVariable) { |
| 1231 enqueueInResolution(getGetObjectIsSubtype(), elements); | 1235 enqueueInResolution(getObjectIsSubtype(), elements); |
| 1236 if (isCheckedMode) { | |
| 1237 enqueueInResolution(getAssertObjectIsSubtype(), elements); | |
| 1238 } | |
| 1232 } | 1239 } |
| 1233 world.registerInstantiatedClass(compiler.listClass, elements); | 1240 world.registerInstantiatedClass(compiler.listClass, elements); |
| 1234 } | 1241 } |
| 1235 // [registerIsCheck] is also called for checked mode checks, so we | 1242 // [registerIsCheck] is also called for checked mode checks, so we |
| 1236 // need to register checked mode helpers. | 1243 // need to register checked mode helpers. |
| 1237 if (compiler.enableTypeAssertions) { | 1244 if (isCheckedMode) { |
| 1238 Element e = getCheckedModeHelper(type, typeCast: false); | 1245 Element e = getCheckedModeHelper(type, typeCast: false); |
| 1239 if (e != null) world.addToWorkList(e); | 1246 if (e != null) world.addToWorkList(e); |
| 1240 // 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). |
| 1241 e = getNativeCheckedModeHelper(type, typeCast: false); | 1248 e = getNativeCheckedModeHelper(type, typeCast: false); |
| 1242 if (e != null) world.addToWorkList(e); | 1249 if (e != null) world.addToWorkList(e); |
| 1243 } | 1250 } |
| 1244 if (type.element.isNative()) { | 1251 if (type.element.isNative()) { |
| 1245 // 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 |
| 1246 // JavaScript object prototype, so we make sure | 1253 // JavaScript object prototype, so we make sure |
| 1247 // [:defineProperty:] is compiled. | 1254 // [:defineProperty:] is compiled. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1313 }); | 1320 }); |
| 1314 } | 1321 } |
| 1315 // TODO(ngeoffray): Also handle T a (in checked mode). | 1322 // TODO(ngeoffray): Also handle T a (in checked mode). |
| 1316 } | 1323 } |
| 1317 | 1324 |
| 1318 void registerClassUsingVariableExpression(ClassElement cls) { | 1325 void registerClassUsingVariableExpression(ClassElement cls) { |
| 1319 rti.classesUsingTypeVariableExpression.add(cls); | 1326 rti.classesUsingTypeVariableExpression.add(cls); |
| 1320 } | 1327 } |
| 1321 | 1328 |
| 1322 bool needsRti(ClassElement cls) { | 1329 bool needsRti(ClassElement cls) { |
| 1323 return rti.classesNeedingRti.contains(cls.declaration) | 1330 return rti.classesNeedingRti.contains(cls.declaration) || |
| 1324 || compiler.enabledRuntimeType; | 1331 compiler.enabledRuntimeType || |
| 1332 (compiler.enableTypeAssertions && !cls.typeVariables.isEmpty); | |
|
ngeoffray
2013/05/13 09:10:59
Why would a class with type variable need rti? Wha
karlklose
2013/05/14 13:49:41
Removed, it was not necessary.
| |
| 1325 } | 1333 } |
| 1326 | 1334 |
| 1327 bool isDefaultNoSuchMethodImplementation(Element element) { | 1335 bool isDefaultNoSuchMethodImplementation(Element element) { |
| 1328 assert(element.name == Compiler.NO_SUCH_METHOD); | 1336 assert(element.name == Compiler.NO_SUCH_METHOD); |
| 1329 ClassElement classElement = element.getEnclosingClass(); | 1337 ClassElement classElement = element.getEnclosingClass(); |
| 1330 return classElement == compiler.objectClass | 1338 return classElement == compiler.objectClass |
| 1331 || classElement == jsInterceptorClass; | 1339 || classElement == jsInterceptorClass; |
| 1332 } | 1340 } |
| 1333 | 1341 |
| 1334 bool isDefaultEqualityImplementation(Element element) { | 1342 bool isDefaultEqualityImplementation(Element element) { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1579 } | 1587 } |
| 1580 } | 1588 } |
| 1581 | 1589 |
| 1582 /** | 1590 /** |
| 1583 * Returns the checked mode helper that will be needed to do a type check/type | 1591 * Returns the checked mode helper that will be needed to do a type check/type |
| 1584 * cast on [type] at runtime. Note that this method is being called both by | 1592 * cast on [type] at runtime. Note that this method is being called both by |
| 1585 * the resolver with interface types (int, String, ...), and by the SSA | 1593 * the resolver with interface types (int, String, ...), and by the SSA |
| 1586 * backend with implementation types (JSInt, JSString, ...). | 1594 * backend with implementation types (JSInt, JSString, ...). |
| 1587 */ | 1595 */ |
| 1588 Element getCheckedModeHelper(DartType type, {bool typeCast}) { | 1596 Element getCheckedModeHelper(DartType type, {bool typeCast}) { |
| 1589 return compiler.findHelper(getCheckedModeHelperName( | 1597 SourceString name = getCheckedModeHelperName( |
| 1590 type, typeCast: typeCast, nativeCheckOnly: false)); | 1598 type, typeCast: typeCast, nativeCheckOnly: false); |
| 1599 return compiler.findHelper(name); | |
| 1591 } | 1600 } |
| 1592 | 1601 |
| 1593 /** | 1602 /** |
| 1594 * Returns the native checked mode helper that will be needed to do a type | 1603 * Returns the native checked mode helper that will be needed to do a type |
| 1595 * check/type cast on [type] at runtime. If no native helper exists for | 1604 * check/type cast on [type] at runtime. If no native helper exists for |
| 1596 * [type], [:null:] is returned. | 1605 * [type], [:null:] is returned. |
| 1597 */ | 1606 */ |
| 1598 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) { | 1607 Element getNativeCheckedModeHelper(DartType type, {bool typeCast}) { |
| 1599 SourceString sourceName = getCheckedModeHelperName( | 1608 SourceString sourceName = getCheckedModeHelperName( |
| 1600 type, typeCast: typeCast, nativeCheckOnly: true); | 1609 type, typeCast: typeCast, nativeCheckOnly: true); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1685 return typeCast | 1694 return typeCast |
| 1686 ? const SourceString("listSuperNativeTypeCast") | 1695 ? const SourceString("listSuperNativeTypeCast") |
| 1687 : const SourceString('listSuperNativeTypeCheck'); | 1696 : const SourceString('listSuperNativeTypeCheck'); |
| 1688 } else { | 1697 } else { |
| 1689 return typeCast | 1698 return typeCast |
| 1690 ? const SourceString("listSuperTypeCast") | 1699 ? const SourceString("listSuperTypeCast") |
| 1691 : const SourceString('listSuperTypeCheck'); | 1700 : const SourceString('listSuperTypeCheck'); |
| 1692 } | 1701 } |
| 1693 } else { | 1702 } else { |
| 1694 if (nativeCheck) { | 1703 if (nativeCheck) { |
| 1704 // TODO(karlklose): can we get rid of this branch when we use | |
| 1705 // interceptors? | |
| 1695 return typeCast | 1706 return typeCast |
| 1696 ? const SourceString("interceptedTypeCast") | 1707 ? const SourceString("interceptedTypeCast") |
| 1697 : const SourceString('interceptedTypeCheck'); | 1708 : const SourceString('interceptedTypeCheck'); |
| 1698 } else { | 1709 } else { |
| 1699 return typeCast | 1710 if (typeCast) { |
| 1700 ? const SourceString("propertyTypeCast") | 1711 return const SourceString("propertyTypeCast"); |
| 1701 : const SourceString('propertyTypeCheck'); | 1712 } |
| 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('assertObjectIsSubtype'); | |
|
ngeoffray
2013/05/13 09:10:59
Why is that called assertObjectIsSubtype? For me i
karlklose
2013/05/14 13:49:41
I renamed the functions.
| |
| 1717 } else { | |
| 1718 return const SourceString('propertyTypeCheck'); | |
| 1719 } | |
| 1702 } | 1720 } |
| 1703 } | 1721 } |
| 1704 } | 1722 } |
| 1705 } | 1723 } |
| 1706 | 1724 |
| 1707 void dumpInferredTypes() { | 1725 void dumpInferredTypes() { |
| 1708 print("Inferred argument types:"); | 1726 print("Inferred argument types:"); |
| 1709 print("------------------------"); | 1727 print("------------------------"); |
| 1710 argumentTypes.dump(); | 1728 argumentTypes.dump(); |
| 1711 print(""); | 1729 print(""); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1774 } | 1792 } |
| 1775 | 1793 |
| 1776 Element getRuntimeTypeToString() { | 1794 Element getRuntimeTypeToString() { |
| 1777 return compiler.findHelper(const SourceString('runtimeTypeToString')); | 1795 return compiler.findHelper(const SourceString('runtimeTypeToString')); |
| 1778 } | 1796 } |
| 1779 | 1797 |
| 1780 Element getCheckSubtype() { | 1798 Element getCheckSubtype() { |
| 1781 return compiler.findHelper(const SourceString('checkSubtype')); | 1799 return compiler.findHelper(const SourceString('checkSubtype')); |
| 1782 } | 1800 } |
| 1783 | 1801 |
| 1784 Element getGetObjectIsSubtype() { | 1802 Element getAssertSubtype() { |
| 1803 return compiler.findHelper(const SourceString('assertSubtype')); | |
| 1804 } | |
| 1805 | |
| 1806 Element getObjectIsSubtype() { | |
| 1785 return compiler.findHelper(const SourceString('objectIsSubtype')); | 1807 return compiler.findHelper(const SourceString('objectIsSubtype')); |
| 1786 } | 1808 } |
| 1787 | 1809 |
| 1810 Element getAssertObjectIsSubtype() { | |
| 1811 return compiler.findHelper(const SourceString('assertObjectIsSubtype')); | |
| 1812 } | |
| 1813 | |
| 1788 Element getThrowNoSuchMethod() { | 1814 Element getThrowNoSuchMethod() { |
| 1789 return compiler.findHelper(const SourceString('throwNoSuchMethod')); | 1815 return compiler.findHelper(const SourceString('throwNoSuchMethod')); |
| 1790 } | 1816 } |
| 1791 | 1817 |
| 1792 Element getCreateRuntimeType() { | 1818 Element getCreateRuntimeType() { |
| 1793 return compiler.findHelper(const SourceString('createRuntimeType')); | 1819 return compiler.findHelper(const SourceString('createRuntimeType')); |
| 1794 } | 1820 } |
| 1795 | 1821 |
| 1796 Element getFallThroughError() { | 1822 Element getFallThroughError() { |
| 1797 return compiler.findHelper(const SourceString("getFallThroughError")); | 1823 return compiler.findHelper(const SourceString("getFallThroughError")); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1830 ClassElement get constListImplementation => jsArrayClass; | 1856 ClassElement get constListImplementation => jsArrayClass; |
| 1831 ClassElement get fixedListImplementation => jsFixedArrayClass; | 1857 ClassElement get fixedListImplementation => jsFixedArrayClass; |
| 1832 ClassElement get growableListImplementation => jsExtendableArrayClass; | 1858 ClassElement get growableListImplementation => jsExtendableArrayClass; |
| 1833 ClassElement get mapImplementation => mapLiteralClass; | 1859 ClassElement get mapImplementation => mapLiteralClass; |
| 1834 ClassElement get constMapImplementation => constMapLiteralClass; | 1860 ClassElement get constMapImplementation => constMapLiteralClass; |
| 1835 ClassElement get functionImplementation => jsFunctionClass; | 1861 ClassElement get functionImplementation => jsFunctionClass; |
| 1836 ClassElement get typeImplementation => typeLiteralClass; | 1862 ClassElement get typeImplementation => typeLiteralClass; |
| 1837 ClassElement get boolImplementation => jsBoolClass; | 1863 ClassElement get boolImplementation => jsBoolClass; |
| 1838 ClassElement get nullImplementation => jsNullClass; | 1864 ClassElement get nullImplementation => jsNullClass; |
| 1839 } | 1865 } |
| OLD | NEW |