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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 TypeMask get dynamicType => compiler.typesTask.dynamicType; | 224 TypeMask get dynamicType => compiler.typesTask.dynamicType; |
225 TypeMask get nullType => compiler.typesTask.nullType; | 225 TypeMask get nullType => compiler.typesTask.nullType; |
226 TypeMask get emptyType => const TypeMask.nonNullEmpty(); | 226 TypeMask get emptyType => const TypeMask.nonNullEmpty(); |
227 TypeMask indexablePrimitiveType; | 227 TypeMask indexablePrimitiveType; |
228 TypeMask readableArrayType; | 228 TypeMask readableArrayType; |
229 TypeMask mutableArrayType; | 229 TypeMask mutableArrayType; |
230 TypeMask fixedArrayType; | 230 TypeMask fixedArrayType; |
231 TypeMask extendableArrayType; | 231 TypeMask extendableArrayType; |
232 TypeMask nonNullType; | 232 TypeMask nonNullType; |
233 | 233 |
| 234 /// Maps special classes to their implementation (JSXxx) class. |
| 235 Map<ClassElement, ClassElement> implementationClasses; |
234 | 236 |
235 Element getNativeInterceptorMethod; | 237 Element getNativeInterceptorMethod; |
236 bool needToInitializeDispatchProperty = false; | 238 bool needToInitializeDispatchProperty = false; |
237 | 239 |
238 final Namer namer; | 240 final Namer namer; |
239 | 241 |
240 /** | 242 /** |
241 * Interface used to determine if an object has the JavaScript | 243 * Interface used to determine if an object has the JavaScript |
242 * indexing behavior. The interface is only visible to specific | 244 * indexing behavior. The interface is only visible to specific |
243 * libraries. | 245 * libraries. |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 jsBoolClass = compiler.findInterceptor('JSBool'), | 573 jsBoolClass = compiler.findInterceptor('JSBool'), |
572 jsMutableArrayClass = compiler.findInterceptor('JSMutableArray'), | 574 jsMutableArrayClass = compiler.findInterceptor('JSMutableArray'), |
573 jsFixedArrayClass = compiler.findInterceptor('JSFixedArray'), | 575 jsFixedArrayClass = compiler.findInterceptor('JSFixedArray'), |
574 jsExtendableArrayClass = compiler.findInterceptor('JSExtendableArray'), | 576 jsExtendableArrayClass = compiler.findInterceptor('JSExtendableArray'), |
575 jsPlainJavaScriptObjectClass = | 577 jsPlainJavaScriptObjectClass = |
576 compiler.findInterceptor('PlainJavaScriptObject'), | 578 compiler.findInterceptor('PlainJavaScriptObject'), |
577 jsUnknownJavaScriptObjectClass = | 579 jsUnknownJavaScriptObjectClass = |
578 compiler.findInterceptor('UnknownJavaScriptObject'), | 580 compiler.findInterceptor('UnknownJavaScriptObject'), |
579 ]; | 581 ]; |
580 | 582 |
| 583 implementationClasses = <ClassElement, ClassElement>{}; |
| 584 implementationClasses[compiler.intClass] = jsIntClass; |
| 585 implementationClasses[compiler.boolClass] = jsBoolClass; |
| 586 implementationClasses[compiler.numClass] = jsNumberClass; |
| 587 implementationClasses[compiler.doubleClass] = jsDoubleClass; |
| 588 implementationClasses[compiler.stringClass] = jsStringClass; |
| 589 implementationClasses[compiler.listClass] = jsArrayClass; |
| 590 |
581 jsIndexableClass = compiler.findInterceptor('JSIndexable'); | 591 jsIndexableClass = compiler.findInterceptor('JSIndexable'); |
582 jsMutableIndexableClass = compiler.findInterceptor('JSMutableIndexable'); | 592 jsMutableIndexableClass = compiler.findInterceptor('JSMutableIndexable'); |
583 | 593 |
584 // TODO(kasperl): Some tests do not define the special JSArray | 594 // TODO(kasperl): Some tests do not define the special JSArray |
585 // subclasses, so we check to see if they are defined before | 595 // subclasses, so we check to see if they are defined before |
586 // trying to resolve them. | 596 // trying to resolve them. |
587 if (jsFixedArrayClass != null) { | 597 if (jsFixedArrayClass != null) { |
588 jsFixedArrayClass.ensureResolved(compiler); | 598 jsFixedArrayClass.ensureResolved(compiler); |
589 } | 599 } |
590 if (jsExtendableArrayClass != null) { | 600 if (jsExtendableArrayClass != null) { |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 LibraryElement importedLibrary = library.getLibraryFromTag(tag); | 1283 LibraryElement importedLibrary = library.getLibraryFromTag(tag); |
1274 if (importedLibrary != compiler.mirrorsLibrary) continue; | 1284 if (importedLibrary != compiler.mirrorsLibrary) continue; |
1275 compiler.withCurrentElement(library, () { | 1285 compiler.withCurrentElement(library, () { |
1276 compiler.reportInfo(importTag, MessageKind.MIRROR_IMPORT); | 1286 compiler.reportInfo(importTag, MessageKind.MIRROR_IMPORT); |
1277 }); | 1287 }); |
1278 } | 1288 } |
1279 } | 1289 } |
1280 } | 1290 } |
1281 } | 1291 } |
1282 | 1292 |
| 1293 Element getDartClass(Element element) { |
| 1294 for (ClassElement dartClass in implementationClasses.keys) { |
| 1295 if (element == implementationClasses[dartClass]) { |
| 1296 return dartClass; |
| 1297 } |
| 1298 } |
| 1299 return element; |
| 1300 } |
| 1301 |
1283 Element getImplementationClass(Element element) { | 1302 Element getImplementationClass(Element element) { |
1284 if (element == compiler.intClass) { | 1303 for (ClassElement dartClass in implementationClasses.keys) { |
1285 return jsIntClass; | 1304 if (element == dartClass) { |
1286 } else if (element == compiler.boolClass) { | 1305 return implementationClasses[dartClass]; |
1287 return jsBoolClass; | 1306 } |
1288 } else if (element == compiler.numClass) { | |
1289 return jsNumberClass; | |
1290 } else if (element == compiler.doubleClass) { | |
1291 return jsDoubleClass; | |
1292 } else if (element == compiler.stringClass) { | |
1293 return jsStringClass; | |
1294 } else if (element == compiler.listClass) { | |
1295 return jsArrayClass; | |
1296 } else { | |
1297 return element; | |
1298 } | 1307 } |
| 1308 return element; |
1299 } | 1309 } |
1300 | 1310 |
1301 /** | 1311 /** |
1302 * Returns the checked mode helper that will be needed to do a type check/type | 1312 * Returns the checked mode helper that will be needed to do a type check/type |
1303 * cast on [type] at runtime. Note that this method is being called both by | 1313 * cast on [type] at runtime. Note that this method is being called both by |
1304 * the resolver with interface types (int, String, ...), and by the SSA | 1314 * the resolver with interface types (int, String, ...), and by the SSA |
1305 * backend with implementation types (JSInt, JSString, ...). | 1315 * backend with implementation types (JSInt, JSString, ...). |
1306 */ | 1316 */ |
1307 CheckedModeHelper getCheckedModeHelper(DartType type, {bool typeCast}) { | 1317 CheckedModeHelper getCheckedModeHelper(DartType type, {bool typeCast}) { |
1308 return getCheckedModeHelperInternal( | 1318 return getCheckedModeHelperInternal( |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1708 if (hasInsufficientMirrorsUsed) return true; | 1718 if (hasInsufficientMirrorsUsed) return true; |
1709 return isNeededForReflection(element); | 1719 return isNeededForReflection(element); |
1710 } | 1720 } |
1711 | 1721 |
1712 /** | 1722 /** |
1713 * Returns `true` if the emitter must emit the element even though there | 1723 * Returns `true` if the emitter must emit the element even though there |
1714 * is no direct use in the program, but because the reflective system may | 1724 * is no direct use in the program, but because the reflective system may |
1715 * need to access it. | 1725 * need to access it. |
1716 */ | 1726 */ |
1717 bool isNeededForReflection(Element element) { | 1727 bool isNeededForReflection(Element element) { |
| 1728 element = getDartClass(element); |
1718 if (hasInsufficientMirrorsUsed) return isTreeShakingDisabled; | 1729 if (hasInsufficientMirrorsUsed) return isTreeShakingDisabled; |
1719 /// Record the name of [element] in [symbolsUsed]. Return true for | 1730 /// Record the name of [element] in [symbolsUsed]. Return true for |
1720 /// convenience. | 1731 /// convenience. |
1721 bool registerNameOf(Element element) { | 1732 bool registerNameOf(Element element) { |
1722 symbolsUsed.add(element.name); | 1733 symbolsUsed.add(element.name); |
1723 if (element.isConstructor()) { | 1734 if (element.isConstructor()) { |
1724 symbolsUsed.add(element.getEnclosingClass().name); | 1735 symbolsUsed.add(element.getEnclosingClass().name); |
1725 } | 1736 } |
1726 return true; | 1737 return true; |
1727 } | 1738 } |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1880 copy(constant.values); | 1891 copy(constant.values); |
1881 copy(constant.protoValue); | 1892 copy(constant.protoValue); |
1882 copy(constant); | 1893 copy(constant); |
1883 } | 1894 } |
1884 | 1895 |
1885 void visitConstructed(ConstructedConstant constant) { | 1896 void visitConstructed(ConstructedConstant constant) { |
1886 copy(constant.fields); | 1897 copy(constant.fields); |
1887 copy(constant); | 1898 copy(constant); |
1888 } | 1899 } |
1889 } | 1900 } |
OLD | NEW |