| 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 library js_backend.backend; | 5 library js_backend.backend; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 9 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
| 10 | 10 |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 compiler, emitter, _nativeResolutionEnqueuer); | 513 compiler, emitter, _nativeResolutionEnqueuer); |
| 514 | 514 |
| 515 _typeVariableResolutionAnalysis = new TypeVariableResolutionAnalysis( | 515 _typeVariableResolutionAnalysis = new TypeVariableResolutionAnalysis( |
| 516 compiler.elementEnvironment, impacts, backendUsageBuilder); | 516 compiler.elementEnvironment, impacts, backendUsageBuilder); |
| 517 jsInteropAnalysis = new JsInteropAnalysis(this); | 517 jsInteropAnalysis = new JsInteropAnalysis(this); |
| 518 _mirrorsResolutionAnalysis = | 518 _mirrorsResolutionAnalysis = |
| 519 new MirrorsResolutionAnalysisImpl(this, compiler.resolution); | 519 new MirrorsResolutionAnalysisImpl(this, compiler.resolution); |
| 520 lookupMapResolutionAnalysis = | 520 lookupMapResolutionAnalysis = |
| 521 new LookupMapResolutionAnalysis(reporter, compiler.elementEnvironment); | 521 new LookupMapResolutionAnalysis(reporter, compiler.elementEnvironment); |
| 522 | 522 |
| 523 noSuchMethodRegistry = new NoSuchMethodRegistry(this); | 523 noSuchMethodRegistry = |
| 524 new NoSuchMethodRegistry(helpers, new NoSuchMethodResolverImpl()); |
| 524 kernelTask = new KernelTask(compiler); | 525 kernelTask = new KernelTask(compiler); |
| 525 patchResolverTask = new PatchResolverTask(compiler); | 526 patchResolverTask = new PatchResolverTask(compiler); |
| 526 functionCompiler = | 527 functionCompiler = |
| 527 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); | 528 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); |
| 528 serialization = new JavaScriptBackendSerialization(this); | 529 serialization = new JavaScriptBackendSerialization(this); |
| 529 } | 530 } |
| 530 | 531 |
| 531 /// The [ConstantSystem] used to interpret compile-time constants for this | 532 /// The [ConstantSystem] used to interpret compile-time constants for this |
| 532 /// backend. | 533 /// backend. |
| 533 ConstantSystem get constantSystem => constants.constantSystem; | 534 ConstantSystem get constantSystem => constants.constantSystem; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 } | 675 } |
| 675 | 676 |
| 676 CheckedModeHelpers get checkedModeHelpers => _checkedModeHelpers; | 677 CheckedModeHelpers get checkedModeHelpers => _checkedModeHelpers; |
| 677 | 678 |
| 678 /// Returns constant environment for the JavaScript interpretation of the | 679 /// Returns constant environment for the JavaScript interpretation of the |
| 679 /// constants. | 680 /// constants. |
| 680 JavaScriptConstantCompiler get constants { | 681 JavaScriptConstantCompiler get constants { |
| 681 return constantCompilerTask.jsConstantCompiler; | 682 return constantCompilerTask.jsConstantCompiler; |
| 682 } | 683 } |
| 683 | 684 |
| 684 bool isDefaultNoSuchMethod(MethodElement element) { | |
| 685 return noSuchMethodRegistry.isDefaultNoSuchMethodImplementation(element); | |
| 686 } | |
| 687 | |
| 688 MethodElement resolveExternalFunction(MethodElement element) { | 685 MethodElement resolveExternalFunction(MethodElement element) { |
| 689 if (isForeign(element)) { | 686 if (isForeign(element)) { |
| 690 return element; | 687 return element; |
| 691 } | 688 } |
| 692 if (_nativeDataResolver.isJsInteropMember(element)) { | 689 if (_nativeDataResolver.isJsInteropMember(element)) { |
| 693 if (element.memberName == const PublicName('[]') || | 690 if (element.memberName == const PublicName('[]') || |
| 694 element.memberName == const PublicName('[]=')) { | 691 element.memberName == const PublicName('[]=')) { |
| 695 reporter.reportErrorMessage( | 692 reporter.reportErrorMessage( |
| 696 element, MessageKind.JS_INTEROP_INDEX_NOT_SUPPORTED); | 693 element, MessageKind.JS_INTEROP_INDEX_NOT_SUPPORTED); |
| 697 } | 694 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 helpers, | 795 helpers, |
| 799 _backendUsage, | 796 _backendUsage, |
| 800 enableTypeAssertions: compiler.options.enableTypeAssertions); | 797 enableTypeAssertions: compiler.options.enableTypeAssertions); |
| 801 _interceptorData = | 798 _interceptorData = |
| 802 _interceptorDataBuilder.onResolutionComplete(closedWorld); | 799 _interceptorDataBuilder.onResolutionComplete(closedWorld); |
| 803 _oneShotInterceptorData = | 800 _oneShotInterceptorData = |
| 804 new OneShotInterceptorData(interceptorData, helpers); | 801 new OneShotInterceptorData(interceptorData, helpers); |
| 805 mirrorsResolutionAnalysis.onResolutionComplete(); | 802 mirrorsResolutionAnalysis.onResolutionComplete(); |
| 806 } | 803 } |
| 807 | 804 |
| 808 void onTypeInferenceComplete() { | 805 void onTypeInferenceComplete(GlobalTypeInferenceResults results) { |
| 809 noSuchMethodRegistry.onTypeInferenceComplete(); | 806 noSuchMethodRegistry.onTypeInferenceComplete(results); |
| 810 } | |
| 811 | |
| 812 /// Register a runtime type variable bound tests between [typeArgument] and | |
| 813 /// [bound]. | |
| 814 void registerTypeVariableBoundsSubtypeCheck( | |
| 815 ResolutionDartType typeArgument, ResolutionDartType bound) { | |
| 816 rtiChecksBuilder.registerTypeVariableBoundsSubtypeCheck( | |
| 817 typeArgument, bound); | |
| 818 } | 807 } |
| 819 | 808 |
| 820 /// Returns the [WorldImpact] of enabling deferred loading. | 809 /// Returns the [WorldImpact] of enabling deferred loading. |
| 821 WorldImpact computeDeferredLoadingImpact() { | 810 WorldImpact computeDeferredLoadingImpact() { |
| 822 backendUsageBuilder.processBackendImpact(impacts.deferredLoading); | 811 backendUsageBuilder.processBackendImpact(impacts.deferredLoading); |
| 823 return impacts.deferredLoading.createImpact(compiler.elementEnvironment); | 812 return impacts.deferredLoading.createImpact(compiler.elementEnvironment); |
| 824 } | 813 } |
| 825 | 814 |
| 826 /// Called when resolving a call to a foreign function. | 815 /// Called when resolving a call to a foreign function. |
| 827 native.NativeBehavior resolveForeignCall(Send node, Element element, | 816 native.NativeBehavior resolveForeignCall(Send node, Element element, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 848 } | 837 } |
| 849 } | 838 } |
| 850 } | 839 } |
| 851 reporter.reportErrorMessage( | 840 reporter.reportErrorMessage( |
| 852 node, MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); | 841 node, MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); |
| 853 } | 842 } |
| 854 // No native behavior for this call. | 843 // No native behavior for this call. |
| 855 return null; | 844 return null; |
| 856 } | 845 } |
| 857 | 846 |
| 858 bool isComplexNoSuchMethod(FunctionElement element) => | |
| 859 noSuchMethodRegistry.isComplex(element); | |
| 860 | |
| 861 ResolutionEnqueuer createResolutionEnqueuer( | 847 ResolutionEnqueuer createResolutionEnqueuer( |
| 862 CompilerTask task, Compiler compiler) { | 848 CompilerTask task, Compiler compiler) { |
| 863 _nativeBasicData = | 849 _nativeBasicData = |
| 864 nativeBasicDataBuilder.close(compiler.elementEnvironment); | 850 nativeBasicDataBuilder.close(compiler.elementEnvironment); |
| 865 _nativeData = new NativeDataImpl(nativeBasicData); | 851 _nativeData = new NativeDataImpl(nativeBasicData); |
| 866 _backendClasses = new JavaScriptBackendClasses( | 852 _backendClasses = new JavaScriptBackendClasses( |
| 867 compiler.elementEnvironment, helpers, nativeBasicData); | 853 compiler.elementEnvironment, helpers, nativeBasicData); |
| 868 _customElementsResolutionAnalysis = new CustomElementsResolutionAnalysis( | 854 _customElementsResolutionAnalysis = new CustomElementsResolutionAnalysis( |
| 869 compiler.resolution, | 855 compiler.resolution, |
| 870 constantSystem, | 856 constantSystem, |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1062 } | 1048 } |
| 1063 | 1049 |
| 1064 /// Called to finalize the [RuntimeTypesChecks] information. | 1050 /// Called to finalize the [RuntimeTypesChecks] information. |
| 1065 void finalizeRti() { | 1051 void finalizeRti() { |
| 1066 _rtiChecks = rtiChecksBuilder.computeRequiredChecks(); | 1052 _rtiChecks = rtiChecksBuilder.computeRequiredChecks(); |
| 1067 } | 1053 } |
| 1068 | 1054 |
| 1069 /// Generates the output and returns the total size of the generated code. | 1055 /// Generates the output and returns the total size of the generated code. |
| 1070 int assembleProgram(ClosedWorld closedWorld) { | 1056 int assembleProgram(ClosedWorld closedWorld) { |
| 1071 int programSize = emitter.assembleProgram(namer, closedWorld); | 1057 int programSize = emitter.assembleProgram(namer, closedWorld); |
| 1072 noSuchMethodRegistry.emitDiagnostic(); | 1058 noSuchMethodRegistry.emitDiagnostic(reporter); |
| 1073 int totalMethodCount = generatedCode.length; | 1059 int totalMethodCount = generatedCode.length; |
| 1074 if (totalMethodCount != mirrorsCodegenAnalysis.preMirrorsMethodCount) { | 1060 if (totalMethodCount != mirrorsCodegenAnalysis.preMirrorsMethodCount) { |
| 1075 int mirrorCount = | 1061 int mirrorCount = |
| 1076 totalMethodCount - mirrorsCodegenAnalysis.preMirrorsMethodCount; | 1062 totalMethodCount - mirrorsCodegenAnalysis.preMirrorsMethodCount; |
| 1077 double percentage = (mirrorCount / totalMethodCount) * 100; | 1063 double percentage = (mirrorCount / totalMethodCount) * 100; |
| 1078 DiagnosticMessage hint = | 1064 DiagnosticMessage hint = |
| 1079 reporter.createMessage(compiler.mainApp, MessageKind.MIRROR_BLOAT, { | 1065 reporter.createMessage(compiler.mainApp, MessageKind.MIRROR_BLOAT, { |
| 1080 'count': mirrorCount, | 1066 'count': mirrorCount, |
| 1081 'total': totalMethodCount, | 1067 'total': totalMethodCount, |
| 1082 'percentage': percentage.round() | 1068 'percentage': percentage.round() |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 } | 1557 } |
| 1572 | 1558 |
| 1573 @override | 1559 @override |
| 1574 dynamic resolveForeignCall(Send node, Element element, | 1560 dynamic resolveForeignCall(Send node, Element element, |
| 1575 CallStructure callStructure, ForeignResolver resolver) { | 1561 CallStructure callStructure, ForeignResolver resolver) { |
| 1576 return _backend.resolveForeignCall(node, element, callStructure, resolver); | 1562 return _backend.resolveForeignCall(node, element, callStructure, resolver); |
| 1577 } | 1563 } |
| 1578 | 1564 |
| 1579 @override | 1565 @override |
| 1580 bool isDefaultNoSuchMethod(MethodElement element) { | 1566 bool isDefaultNoSuchMethod(MethodElement element) { |
| 1581 return _backend.isDefaultNoSuchMethod(element); | 1567 return _backend.helpers.isDefaultNoSuchMethodImplementation(element); |
| 1582 } | 1568 } |
| 1583 | 1569 |
| 1584 @override | 1570 @override |
| 1585 ClassElement defaultSuperclass(ClassElement element) { | 1571 ClassElement defaultSuperclass(ClassElement element) { |
| 1586 return _backend.defaultSuperclass(element); | 1572 return _backend.defaultSuperclass(element); |
| 1587 } | 1573 } |
| 1588 | 1574 |
| 1589 @override | 1575 @override |
| 1590 bool isNativeClass(ClassEntity element) => | 1576 bool isNativeClass(ClassEntity element) => |
| 1591 _backend.nativeBasicData.isNativeClass(element); | 1577 _backend.nativeBasicData.isNativeClass(element); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1611 | 1597 |
| 1612 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { | 1598 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { |
| 1613 return !selector.isGetter; | 1599 return !selector.isGetter; |
| 1614 } | 1600 } |
| 1615 | 1601 |
| 1616 /// Returns `true` if [member] is called from a subclass via `super`. | 1602 /// Returns `true` if [member] is called from a subclass via `super`. |
| 1617 bool isAliasedSuperMember(MemberEntity member) { | 1603 bool isAliasedSuperMember(MemberEntity member) { |
| 1618 return _aliasedSuperMembers.contains(member); | 1604 return _aliasedSuperMembers.contains(member); |
| 1619 } | 1605 } |
| 1620 } | 1606 } |
| OLD | NEW |