| 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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 LibraryElement importedLibrary = library.getLibraryFromTag(tag); | 1297 LibraryElement importedLibrary = library.getLibraryFromTag(tag); |
| 1288 if (importedLibrary != compiler.mirrorsLibrary) continue; | 1298 if (importedLibrary != compiler.mirrorsLibrary) continue; |
| 1289 compiler.withCurrentElement(library, () { | 1299 compiler.withCurrentElement(library, () { |
| 1290 compiler.reportInfo(importTag, MessageKind.MIRROR_IMPORT); | 1300 compiler.reportInfo(importTag, MessageKind.MIRROR_IMPORT); |
| 1291 }); | 1301 }); |
| 1292 } | 1302 } |
| 1293 } | 1303 } |
| 1294 } | 1304 } |
| 1295 } | 1305 } |
| 1296 | 1306 |
| 1307 Element getDartClass(Element element) { |
| 1308 for (ClassElement dartClass in implementationClasses.keys) { |
| 1309 if (element == implementationClasses[dartClass]) { |
| 1310 return dartClass; |
| 1311 } |
| 1312 } |
| 1313 return element; |
| 1314 } |
| 1315 |
| 1297 Element getImplementationClass(Element element) { | 1316 Element getImplementationClass(Element element) { |
| 1298 if (element == compiler.intClass) { | 1317 for (ClassElement dartClass in implementationClasses.keys) { |
| 1299 return jsIntClass; | 1318 if (element == dartClass) { |
| 1300 } else if (element == compiler.boolClass) { | 1319 return implementationClasses[dartClass]; |
| 1301 return jsBoolClass; | 1320 } |
| 1302 } else if (element == compiler.numClass) { | |
| 1303 return jsNumberClass; | |
| 1304 } else if (element == compiler.doubleClass) { | |
| 1305 return jsDoubleClass; | |
| 1306 } else if (element == compiler.stringClass) { | |
| 1307 return jsStringClass; | |
| 1308 } else if (element == compiler.listClass) { | |
| 1309 return jsArrayClass; | |
| 1310 } else { | |
| 1311 return element; | |
| 1312 } | 1321 } |
| 1322 return element; |
| 1313 } | 1323 } |
| 1314 | 1324 |
| 1315 /** | 1325 /** |
| 1316 * Returns the checked mode helper that will be needed to do a type check/type | 1326 * Returns the checked mode helper that will be needed to do a type check/type |
| 1317 * cast on [type] at runtime. Note that this method is being called both by | 1327 * cast on [type] at runtime. Note that this method is being called both by |
| 1318 * the resolver with interface types (int, String, ...), and by the SSA | 1328 * the resolver with interface types (int, String, ...), and by the SSA |
| 1319 * backend with implementation types (JSInt, JSString, ...). | 1329 * backend with implementation types (JSInt, JSString, ...). |
| 1320 */ | 1330 */ |
| 1321 CheckedModeHelper getCheckedModeHelper(DartType type, {bool typeCast}) { | 1331 CheckedModeHelper getCheckedModeHelper(DartType type, {bool typeCast}) { |
| 1322 return getCheckedModeHelperInternal( | 1332 return getCheckedModeHelperInternal( |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1730 if (hasInsufficientMirrorsUsed) return true; | 1740 if (hasInsufficientMirrorsUsed) return true; |
| 1731 return isNeededForReflection(element); | 1741 return isNeededForReflection(element); |
| 1732 } | 1742 } |
| 1733 | 1743 |
| 1734 /** | 1744 /** |
| 1735 * Returns `true` if the emitter must emit the element even though there | 1745 * Returns `true` if the emitter must emit the element even though there |
| 1736 * is no direct use in the program, but because the reflective system may | 1746 * is no direct use in the program, but because the reflective system may |
| 1737 * need to access it. | 1747 * need to access it. |
| 1738 */ | 1748 */ |
| 1739 bool isNeededForReflection(Element element) { | 1749 bool isNeededForReflection(Element element) { |
| 1750 element = getDartClass(element); |
| 1740 if (hasInsufficientMirrorsUsed) return isTreeShakingDisabled; | 1751 if (hasInsufficientMirrorsUsed) return isTreeShakingDisabled; |
| 1741 /// Record the name of [element] in [symbolsUsed]. Return true for | 1752 /// Record the name of [element] in [symbolsUsed]. Return true for |
| 1742 /// convenience. | 1753 /// convenience. |
| 1743 bool registerNameOf(Element element) { | 1754 bool registerNameOf(Element element) { |
| 1744 symbolsUsed.add(element.name); | 1755 symbolsUsed.add(element.name); |
| 1745 if (element.isConstructor()) { | 1756 if (element.isConstructor()) { |
| 1746 symbolsUsed.add(element.getEnclosingClass().name); | 1757 symbolsUsed.add(element.getEnclosingClass().name); |
| 1747 } | 1758 } |
| 1748 return true; | 1759 return true; |
| 1749 } | 1760 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 copy(constant.values); | 1913 copy(constant.values); |
| 1903 copy(constant.protoValue); | 1914 copy(constant.protoValue); |
| 1904 copy(constant); | 1915 copy(constant); |
| 1905 } | 1916 } |
| 1906 | 1917 |
| 1907 void visitConstructed(ConstructedConstant constant) { | 1918 void visitConstructed(ConstructedConstant constant) { |
| 1908 copy(constant.fields); | 1919 copy(constant.fields); |
| 1909 copy(constant); | 1920 copy(constant); |
| 1910 } | 1921 } |
| 1911 } | 1922 } |
| OLD | NEW |