| 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; | 8 final Set<HInstruction> boundsChecked; |
| 9 | 9 |
| 10 JavaScriptItemCompilationContext() | 10 JavaScriptItemCompilationContext() |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 Element jsArrayRemoveLast; | 193 Element jsArrayRemoveLast; |
| 194 Element jsArrayAdd; | 194 Element jsArrayAdd; |
| 195 Element jsStringSplit; | 195 Element jsStringSplit; |
| 196 Element jsStringToString; | 196 Element jsStringToString; |
| 197 Element jsStringOperatorAdd; | 197 Element jsStringOperatorAdd; |
| 198 Element objectEquals; | 198 Element objectEquals; |
| 199 | 199 |
| 200 ClassElement typeLiteralClass; | 200 ClassElement typeLiteralClass; |
| 201 ClassElement mapLiteralClass; | 201 ClassElement mapLiteralClass; |
| 202 ClassElement constMapLiteralClass; | 202 ClassElement constMapLiteralClass; |
| 203 ClassElement typeVariableClass; |
| 203 | 204 |
| 204 Element getInterceptorMethod; | 205 Element getInterceptorMethod; |
| 205 Element interceptedNames; | 206 Element interceptedNames; |
| 206 | 207 |
| 207 /** | 208 /** |
| 208 * This element is a top-level variable (in generated output) that the | 209 * This element is a top-level variable (in generated output) that the |
| 209 * compiler initializes to a datastructure used to map from a Type to the | 210 * compiler initializes to a datastructure used to map from a Type to the |
| 210 * interceptor. See declaration of `mapTypeToInterceptor` in | 211 * interceptor. See declaration of `mapTypeToInterceptor` in |
| 211 * `interceptors.dart`. | 212 * `interceptors.dart`. |
| 212 */ | 213 */ |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 const SourceString('propertyTypeCast')), | 400 const SourceString('propertyTypeCast')), |
| 400 const PropertyCheckedModeHelper( | 401 const PropertyCheckedModeHelper( |
| 401 const SourceString('propertyTypeCheck')) ]; | 402 const SourceString('propertyTypeCheck')) ]; |
| 402 | 403 |
| 403 // Checked mode helpers indexed by name. | 404 // Checked mode helpers indexed by name. |
| 404 Map<String, CheckedModeHelper> checkedModeHelperByName = | 405 Map<String, CheckedModeHelper> checkedModeHelperByName = |
| 405 new Map<String, CheckedModeHelper>.fromIterable( | 406 new Map<String, CheckedModeHelper>.fromIterable( |
| 406 checkedModeHelpers, | 407 checkedModeHelpers, |
| 407 key: (helper) => helper.name.slowToString()); | 408 key: (helper) => helper.name.slowToString()); |
| 408 | 409 |
| 410 TypeVariableHandler typeVariableHandler; |
| 411 |
| 409 /// Number of methods compiled before considering reflection. | 412 /// Number of methods compiled before considering reflection. |
| 410 int preMirrorsMethodCount = 0; | 413 int preMirrorsMethodCount = 0; |
| 411 | 414 |
| 412 /// Resolution and codegen support for generating table of interceptors and | 415 /// Resolution and codegen support for generating table of interceptors and |
| 413 /// constructors for custom elements. | 416 /// constructors for custom elements. |
| 414 CustomElementsAnalysis customElementsAnalysis; | 417 CustomElementsAnalysis customElementsAnalysis; |
| 415 | 418 |
| 416 JavaScriptBackend(Compiler compiler, bool generateSourceMap) | 419 JavaScriptBackend(Compiler compiler, bool generateSourceMap) |
| 417 : namer = determineNamer(compiler), | 420 : namer = determineNamer(compiler), |
| 418 oneShotInterceptors = new Map<String, Selector>(), | 421 oneShotInterceptors = new Map<String, Selector>(), |
| 419 interceptedElements = new Map<SourceString, Set<Element>>(), | 422 interceptedElements = new Map<SourceString, Set<Element>>(), |
| 420 rti = new RuntimeTypes(compiler), | 423 rti = new RuntimeTypes(compiler), |
| 421 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), | 424 specializedGetInterceptors = new Map<String, Set<ClassElement>>(), |
| 422 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { | 425 super(compiler, JAVA_SCRIPT_CONSTANT_SYSTEM) { |
| 423 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); | 426 emitter = new CodeEmitterTask(compiler, namer, generateSourceMap); |
| 424 builder = new SsaBuilderTask(this); | 427 builder = new SsaBuilderTask(this); |
| 425 optimizer = new SsaOptimizerTask(this); | 428 optimizer = new SsaOptimizerTask(this); |
| 426 generator = new SsaCodeGeneratorTask(this); | 429 generator = new SsaCodeGeneratorTask(this); |
| 430 typeVariableHandler = new TypeVariableHandler(this); |
| 427 customElementsAnalysis = new CustomElementsAnalysis(this); | 431 customElementsAnalysis = new CustomElementsAnalysis(this); |
| 428 } | 432 } |
| 429 | 433 |
| 430 static Namer determineNamer(Compiler compiler) { | 434 static Namer determineNamer(Compiler compiler) { |
| 431 return compiler.enableMinification ? | 435 return compiler.enableMinification ? |
| 432 new MinifyNamer(compiler) : | 436 new MinifyNamer(compiler) : |
| 433 new Namer(compiler); | 437 new Namer(compiler); |
| 434 } | 438 } |
| 435 | 439 |
| 436 bool usedByBackend(Element element) { | 440 bool usedByBackend(Element element) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 indexablePrimitiveType = new HBoundedType( | 667 indexablePrimitiveType = new HBoundedType( |
| 664 new TypeMask.nonNullSubtype(jsIndexableClass)); | 668 new TypeMask.nonNullSubtype(jsIndexableClass)); |
| 665 readableArrayType = new HBoundedType( | 669 readableArrayType = new HBoundedType( |
| 666 new TypeMask.nonNullSubclass(jsArrayClass)); | 670 new TypeMask.nonNullSubclass(jsArrayClass)); |
| 667 mutableArrayType = new HBoundedType( | 671 mutableArrayType = new HBoundedType( |
| 668 new TypeMask.nonNullSubclass(jsMutableArrayClass)); | 672 new TypeMask.nonNullSubclass(jsMutableArrayClass)); |
| 669 fixedArrayType = new HBoundedType( | 673 fixedArrayType = new HBoundedType( |
| 670 new TypeMask.nonNullExact(jsFixedArrayClass)); | 674 new TypeMask.nonNullExact(jsFixedArrayClass)); |
| 671 extendableArrayType = new HBoundedType( | 675 extendableArrayType = new HBoundedType( |
| 672 new TypeMask.nonNullExact(jsExtendableArrayClass)); | 676 new TypeMask.nonNullExact(jsExtendableArrayClass)); |
| 677 |
| 678 typeVariableClass = |
| 679 compiler.findHelper(const SourceString('TypeVariable')); |
| 673 } | 680 } |
| 674 | 681 |
| 675 void validateInterceptorImplementsAllObjectMethods( | 682 void validateInterceptorImplementsAllObjectMethods( |
| 676 ClassElement interceptorClass) { | 683 ClassElement interceptorClass) { |
| 677 if (interceptorClass == null) return; | 684 if (interceptorClass == null) return; |
| 678 interceptorClass.ensureResolved(compiler); | 685 interceptorClass.ensureResolved(compiler); |
| 679 compiler.objectClass.forEachMember((_, Element member) { | 686 compiler.objectClass.forEachMember((_, Element member) { |
| 680 if (member.isGenerativeConstructor()) return; | 687 if (member.isGenerativeConstructor()) return; |
| 681 Element interceptorMember = interceptorClass.lookupMember(member.name); | 688 Element interceptorMember = interceptorClass.lookupMember(member.name); |
| 682 // Interceptors must override all Object methods due to calling convention | 689 // Interceptors must override all Object methods due to calling convention |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 if (mustRetainMetadata) { | 797 if (mustRetainMetadata) { |
| 791 registerCompileTimeConstant(constant, elements); | 798 registerCompileTimeConstant(constant, elements); |
| 792 } else { | 799 } else { |
| 793 metadataConstants.add(new Dependency(constant, elements)); | 800 metadataConstants.add(new Dependency(constant, elements)); |
| 794 } | 801 } |
| 795 } | 802 } |
| 796 | 803 |
| 797 void registerInstantiatedClass(ClassElement cls, | 804 void registerInstantiatedClass(ClassElement cls, |
| 798 Enqueuer enqueuer, | 805 Enqueuer enqueuer, |
| 799 TreeElements elements) { | 806 TreeElements elements) { |
| 807 if (!cls.typeVariables.isEmpty) { |
| 808 typeVariableHandler.registerClassWithTypeVariables(cls); |
| 809 } |
| 810 |
| 800 if (!seenAnyClass) { | 811 if (!seenAnyClass) { |
| 801 seenAnyClass = true; | 812 seenAnyClass = true; |
| 802 if (enqueuer.isResolutionQueue) { | 813 if (enqueuer.isResolutionQueue) { |
| 803 // TODO(9577): Make it so that these are not needed when there are no | 814 // TODO(9577): Make it so that these are not needed when there are no |
| 804 // native classes. | 815 // native classes. |
| 805 enqueue(enqueuer, getNativeInterceptorMethod, elements); | 816 enqueue(enqueuer, getNativeInterceptorMethod, elements); |
| 806 enqueue(enqueuer, defineNativeMethodsFinishMethod, elements); | 817 enqueue(enqueuer, defineNativeMethodsFinishMethod, elements); |
| 807 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); | 818 enqueueClass(enqueuer, jsInterceptorClass, compiler.globalDependencies); |
| 808 } | 819 } |
| 809 } | 820 } |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1839 compiler.log('Retaining metadata.'); | 1850 compiler.log('Retaining metadata.'); |
| 1840 | 1851 |
| 1841 compiler.libraries.values.forEach(retainMetadataOf); | 1852 compiler.libraries.values.forEach(retainMetadataOf); |
| 1842 for (Dependency dependency in metadataConstants) { | 1853 for (Dependency dependency in metadataConstants) { |
| 1843 registerCompileTimeConstant( | 1854 registerCompileTimeConstant( |
| 1844 dependency.constant, dependency.user); | 1855 dependency.constant, dependency.user); |
| 1845 } | 1856 } |
| 1846 metadataConstants.clear(); | 1857 metadataConstants.clear(); |
| 1847 } | 1858 } |
| 1848 | 1859 |
| 1860 if (isTreeShakingDisabled) { |
| 1861 if (enqueuer.isResolutionQueue) { |
| 1862 typeVariableHandler.onResolutionQueueEmpty(enqueuer); |
| 1863 } else { |
| 1864 typeVariableHandler.onCodegenQueueEmpty(); |
| 1865 } |
| 1866 } |
| 1849 customElementsAnalysis.onQueueEmpty(enqueuer); | 1867 customElementsAnalysis.onQueueEmpty(enqueuer); |
| 1850 } | 1868 } |
| 1851 } | 1869 } |
| 1852 | 1870 |
| 1853 /// Records that [constant] is used by [user.element]. | 1871 /// Records that [constant] is used by [user.element]. |
| 1854 class Dependency { | 1872 class Dependency { |
| 1855 final Constant constant; | 1873 final Constant constant; |
| 1856 final TreeElements user; | 1874 final TreeElements user; |
| 1857 | 1875 |
| 1858 const Dependency(this.constant, this.user); | 1876 const Dependency(this.constant, this.user); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1899 copy(constant.values); | 1917 copy(constant.values); |
| 1900 copy(constant.protoValue); | 1918 copy(constant.protoValue); |
| 1901 copy(constant); | 1919 copy(constant); |
| 1902 } | 1920 } |
| 1903 | 1921 |
| 1904 void visitConstructed(ConstructedConstant constant) { | 1922 void visitConstructed(ConstructedConstant constant) { |
| 1905 copy(constant.fields); | 1923 copy(constant.fields); |
| 1906 copy(constant); | 1924 copy(constant); |
| 1907 } | 1925 } |
| 1908 } | 1926 } |
| OLD | NEW |