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