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 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 7 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/backend_api.dart' | 10 import '../common/backend_api.dart' |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 import '../types/types.dart'; | 53 import '../types/types.dart'; |
54 import '../universe/call_structure.dart' show CallStructure; | 54 import '../universe/call_structure.dart' show CallStructure; |
55 import '../universe/selector.dart' show Selector; | 55 import '../universe/selector.dart' show Selector; |
56 import '../universe/world_builder.dart'; | 56 import '../universe/world_builder.dart'; |
57 import '../universe/use.dart' show ConstantUse, StaticUse; | 57 import '../universe/use.dart' show ConstantUse, StaticUse; |
58 import '../universe/world_impact.dart' | 58 import '../universe/world_impact.dart' |
59 show ImpactStrategy, ImpactUseCase, WorldImpact, WorldImpactVisitor; | 59 show ImpactStrategy, ImpactUseCase, WorldImpact, WorldImpactVisitor; |
60 import '../util/util.dart'; | 60 import '../util/util.dart'; |
61 import '../world.dart' show ClosedWorld, ClosedWorldRefiner; | 61 import '../world.dart' show ClosedWorld, ClosedWorldRefiner; |
62 import 'annotations.dart'; | 62 import 'annotations.dart'; |
63 import 'backend_helpers.dart'; | |
64 import 'backend_impact.dart'; | 63 import 'backend_impact.dart'; |
65 import 'backend_serialization.dart' show JavaScriptBackendSerialization; | 64 import 'backend_serialization.dart' show JavaScriptBackendSerialization; |
66 import 'backend_usage.dart'; | 65 import 'backend_usage.dart'; |
67 import 'checked_mode_helpers.dart'; | 66 import 'checked_mode_helpers.dart'; |
68 import 'codegen_listener.dart'; | 67 import 'codegen_listener.dart'; |
69 import 'constant_handler_javascript.dart'; | 68 import 'constant_handler_javascript.dart'; |
70 import 'custom_elements_analysis.dart'; | 69 import 'custom_elements_analysis.dart'; |
71 import 'enqueuer.dart'; | 70 import 'enqueuer.dart'; |
72 import 'impact_transformer.dart'; | 71 import 'impact_transformer.dart'; |
73 import 'interceptor_data.dart'; | 72 import 'interceptor_data.dart'; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 296 } |
298 | 297 |
299 enum SyntheticConstantKind { | 298 enum SyntheticConstantKind { |
300 DUMMY_INTERCEPTOR, | 299 DUMMY_INTERCEPTOR, |
301 EMPTY_VALUE, | 300 EMPTY_VALUE, |
302 TYPEVARIABLE_REFERENCE, // Reference to a type in reflection data. | 301 TYPEVARIABLE_REFERENCE, // Reference to a type in reflection data. |
303 NAME | 302 NAME |
304 } | 303 } |
305 | 304 |
306 class JavaScriptBackend { | 305 class JavaScriptBackend { |
| 306 static const String JS = 'JS'; |
| 307 static const String JS_BUILTIN = 'JS_BUILTIN'; |
| 308 static const String JS_EMBEDDED_GLOBAL = 'JS_EMBEDDED_GLOBAL'; |
| 309 static const String JS_INTERCEPTOR_CONSTANT = 'JS_INTERCEPTOR_CONSTANT'; |
| 310 |
307 final Compiler compiler; | 311 final Compiler compiler; |
308 | 312 |
309 String get patchVersion => emitter.patchVersion; | 313 String get patchVersion => emitter.patchVersion; |
310 | 314 |
311 /// Returns true if the backend supports reflection. | 315 /// Returns true if the backend supports reflection. |
312 bool get supportsReflection => emitter.supportsReflection; | 316 bool get supportsReflection => emitter.supportsReflection; |
313 | 317 |
314 final Annotations annotations; | 318 final Annotations annotations; |
315 | 319 |
316 /// Set of classes that need to be considered for reflection although not | 320 /// Set of classes that need to be considered for reflection although not |
317 /// otherwise visible during resolution. | 321 /// otherwise visible during resolution. |
318 Iterable<ClassEntity> get classesRequiredForReflection { | 322 Iterable<ClassEntity> get classesRequiredForReflection { |
319 // TODO(herhut): Clean this up when classes needed for rti are tracked. | 323 // TODO(herhut): Clean this up when classes needed for rti are tracked. |
320 return [helpers.closureClass, helpers.jsIndexableClass]; | 324 return [commonElements.closureClass, commonElements.jsIndexableClass]; |
321 } | 325 } |
322 | 326 |
323 FunctionCompiler functionCompiler; | 327 FunctionCompiler functionCompiler; |
324 | 328 |
325 CodeEmitterTask emitter; | 329 CodeEmitterTask emitter; |
326 | 330 |
327 /** | 331 /** |
328 * The generated code as a js AST for compiled methods. | 332 * The generated code as a js AST for compiled methods. |
329 */ | 333 */ |
330 final Map<MemberElement, jsAst.Expression> generatedCode = | 334 final Map<MemberElement, jsAst.Expression> generatedCode = |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 BackendUsage _backendUsage; | 441 BackendUsage _backendUsage; |
438 BackendUsageBuilder _backendUsageBuilder; | 442 BackendUsageBuilder _backendUsageBuilder; |
439 MirrorsDataImpl _mirrorsData; | 443 MirrorsDataImpl _mirrorsData; |
440 CheckedModeHelpers _checkedModeHelpers; | 444 CheckedModeHelpers _checkedModeHelpers; |
441 | 445 |
442 final SuperMemberData superMemberData = new SuperMemberData(); | 446 final SuperMemberData superMemberData = new SuperMemberData(); |
443 | 447 |
444 native.NativeResolutionEnqueuer _nativeResolutionEnqueuer; | 448 native.NativeResolutionEnqueuer _nativeResolutionEnqueuer; |
445 native.NativeCodegenEnqueuer _nativeCodegenEnqueuer; | 449 native.NativeCodegenEnqueuer _nativeCodegenEnqueuer; |
446 | 450 |
447 BackendHelpers helpers; | |
448 BackendImpacts impacts; | 451 BackendImpacts impacts; |
449 | 452 |
450 /// Common classes used by the backend. | 453 /// Common classes used by the backend. |
451 BackendClasses _backendClasses; | 454 BackendClasses _backendClasses; |
452 | 455 |
453 /// Backend access to the front-end. | 456 /// Backend access to the front-end. |
454 final JSFrontendAccess frontend; | 457 final JSFrontendAccess frontend; |
455 | 458 |
456 Target _target; | 459 Target _target; |
457 | 460 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 : _rti = new _RuntimeTypes(compiler), | 493 : _rti = new _RuntimeTypes(compiler), |
491 annotations = new Annotations(compiler), | 494 annotations = new Annotations(compiler), |
492 this.sourceInformationStrategy = createSourceInformationStrategy( | 495 this.sourceInformationStrategy = createSourceInformationStrategy( |
493 generateSourceMap: generateSourceMap, | 496 generateSourceMap: generateSourceMap, |
494 useMultiSourceInfo: useMultiSourceInfo, | 497 useMultiSourceInfo: useMultiSourceInfo, |
495 useNewSourceInfo: useNewSourceInfo), | 498 useNewSourceInfo: useNewSourceInfo), |
496 frontend = new JSFrontendAccess(compiler), | 499 frontend = new JSFrontendAccess(compiler), |
497 constantCompilerTask = new JavaScriptConstantTask(compiler), | 500 constantCompilerTask = new JavaScriptConstantTask(compiler), |
498 _nativeDataResolver = new NativeDataResolverImpl(compiler) { | 501 _nativeDataResolver = new NativeDataResolverImpl(compiler) { |
499 _target = new JavaScriptBackendTarget(this); | 502 _target = new JavaScriptBackendTarget(this); |
500 helpers = new BackendHelpers(compiler.elementEnvironment, commonElements); | 503 impacts = new BackendImpacts(compiler.options, commonElements); |
501 impacts = new BackendImpacts(compiler.options, commonElements, helpers); | |
502 _mirrorsData = new MirrorsDataImpl( | 504 _mirrorsData = new MirrorsDataImpl( |
503 compiler, compiler.options, commonElements, helpers, constants); | 505 compiler, compiler.options, commonElements, constants); |
504 _backendUsageBuilder = new BackendUsageBuilderImpl(commonElements, helpers); | 506 _backendUsageBuilder = new BackendUsageBuilderImpl(commonElements); |
505 _checkedModeHelpers = new CheckedModeHelpers(commonElements, helpers); | 507 _checkedModeHelpers = new CheckedModeHelpers(commonElements); |
506 emitter = | 508 emitter = |
507 new CodeEmitterTask(compiler, generateSourceMap, useStartupEmitter); | 509 new CodeEmitterTask(compiler, generateSourceMap, useStartupEmitter); |
508 | 510 |
509 _typeVariableResolutionAnalysis = new TypeVariableResolutionAnalysis( | 511 _typeVariableResolutionAnalysis = new TypeVariableResolutionAnalysis( |
510 compiler.elementEnvironment, impacts, backendUsageBuilder); | 512 compiler.elementEnvironment, impacts, backendUsageBuilder); |
511 jsInteropAnalysis = new JsInteropAnalysis(this); | 513 jsInteropAnalysis = new JsInteropAnalysis(this); |
512 _mirrorsResolutionAnalysis = | 514 _mirrorsResolutionAnalysis = |
513 new MirrorsResolutionAnalysisImpl(this, compiler.resolution); | 515 new MirrorsResolutionAnalysisImpl(this, compiler.resolution); |
514 lookupMapResolutionAnalysis = | 516 lookupMapResolutionAnalysis = |
515 new LookupMapResolutionAnalysis(reporter, compiler.elementEnvironment); | 517 new LookupMapResolutionAnalysis(reporter, compiler.elementEnvironment); |
516 | 518 |
517 noSuchMethodRegistry = | 519 noSuchMethodRegistry = new NoSuchMethodRegistry( |
518 new NoSuchMethodRegistry(helpers, new NoSuchMethodResolverImpl()); | 520 commonElements, new NoSuchMethodResolverImpl()); |
519 kernelTask = new KernelTask(compiler); | 521 kernelTask = new KernelTask(compiler); |
520 patchResolverTask = new PatchResolverTask(compiler); | 522 patchResolverTask = new PatchResolverTask(compiler); |
521 functionCompiler = | 523 functionCompiler = |
522 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); | 524 new SsaFunctionCompiler(this, sourceInformationStrategy, useKernel); |
523 serialization = new JavaScriptBackendSerialization(this); | 525 serialization = new JavaScriptBackendSerialization(this); |
524 } | 526 } |
525 | 527 |
526 /// The [ConstantSystem] used to interpret compile-time constants for this | 528 /// The [ConstantSystem] used to interpret compile-time constants for this |
527 /// backend. | 529 /// backend. |
528 ConstantSystem get constantSystem => constants.constantSystem; | 530 ConstantSystem get constantSystem => constants.constantSystem; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 reporter.reportErrorMessage( | 688 reporter.reportErrorMessage( |
687 element, MessageKind.JS_INTEROP_INDEX_NOT_SUPPORTED); | 689 element, MessageKind.JS_INTEROP_INDEX_NOT_SUPPORTED); |
688 } | 690 } |
689 return element; | 691 return element; |
690 } | 692 } |
691 return patchResolverTask.measure(() { | 693 return patchResolverTask.measure(() { |
692 return patchResolverTask.resolveExternalFunction(element); | 694 return patchResolverTask.resolveExternalFunction(element); |
693 }); | 695 }); |
694 } | 696 } |
695 | 697 |
696 bool isForeign(Element element) => element.library == helpers.foreignLibrary; | 698 bool isForeign(Element element) => |
| 699 element.library == commonElements.foreignLibrary; |
697 | 700 |
698 bool isBackendLibrary(LibraryElement library) { | 701 bool isBackendLibrary(LibraryElement library) { |
699 return library == helpers.interceptorsLibrary || | 702 return library == commonElements.interceptorsLibrary || |
700 library == helpers.jsHelperLibrary; | 703 library == compiler.commonElements.jsHelperLibrary; |
701 } | 704 } |
702 | 705 |
703 Namer determineNamer( | 706 Namer determineNamer( |
704 ClosedWorld closedWorld, CodegenWorldBuilder codegenWorldBuilder) { | 707 ClosedWorld closedWorld, CodegenWorldBuilder codegenWorldBuilder) { |
705 return compiler.options.enableMinification | 708 return compiler.options.enableMinification |
706 ? compiler.options.useFrequencyNamer | 709 ? compiler.options.useFrequencyNamer |
707 ? new FrequencyBasedNamer( | 710 ? new FrequencyBasedNamer( |
708 helpers, nativeData, closedWorld, codegenWorldBuilder) | 711 nativeData, closedWorld, codegenWorldBuilder) |
709 : new MinifyNamer( | 712 : new MinifyNamer(nativeData, closedWorld, codegenWorldBuilder) |
710 helpers, nativeData, closedWorld, codegenWorldBuilder) | 713 : new Namer(nativeData, closedWorld, codegenWorldBuilder); |
711 : new Namer(helpers, nativeData, closedWorld, codegenWorldBuilder); | |
712 } | 714 } |
713 | 715 |
714 /// Returns true if global optimizations such as type inferencing can apply to | 716 /// Returns true if global optimizations such as type inferencing can apply to |
715 /// the field [element]. | 717 /// the field [element]. |
716 /// | 718 /// |
717 /// One category of elements that do not apply is runtime helpers that the | 719 /// One category of elements that do not apply is runtime helpers that the |
718 /// backend calls, but the optimizations don't see those calls. | 720 /// backend calls, but the optimizations don't see those calls. |
719 bool canFieldBeUsedForGlobalOptimizations(FieldElement element) { | 721 bool canFieldBeUsedForGlobalOptimizations(FieldElement element) { |
720 return !backendUsage.isFieldUsedByBackend(element) && | 722 return !backendUsage.isFieldUsedByBackend(element) && |
721 !mirrorsData.invokedReflectively(element); | 723 !mirrorsData.invokedReflectively(element); |
722 } | 724 } |
723 | 725 |
724 /// Returns true if global optimizations such as type inferencing can apply to | 726 /// Returns true if global optimizations such as type inferencing can apply to |
725 /// the parameter [element]. | 727 /// the parameter [element]. |
726 /// | 728 /// |
727 /// One category of elements that do not apply is runtime helpers that the | 729 /// One category of elements that do not apply is runtime helpers that the |
728 /// backend calls, but the optimizations don't see those calls. | 730 /// backend calls, but the optimizations don't see those calls. |
729 bool canFunctionParametersBeUsedForGlobalOptimizations( | 731 bool canFunctionParametersBeUsedForGlobalOptimizations( |
730 FunctionElement element) { | 732 FunctionElement element) { |
731 if (element.isLocal) return true; | 733 if (element.isLocal) return true; |
732 MethodElement method = element; | 734 MethodElement method = element; |
733 return !backendUsage.isFunctionUsedByBackend(method) && | 735 return !backendUsage.isFunctionUsedByBackend(method) && |
734 !mirrorsData.invokedReflectively(method); | 736 !mirrorsData.invokedReflectively(method); |
735 } | 737 } |
736 | 738 |
737 /// Maps compile-time classes to their runtime class. The runtime class is | 739 /// Maps compile-time classes to their runtime class. The runtime class is |
738 /// always a superclass or the class itself. | 740 /// always a superclass or the class itself. |
739 ClassElement getRuntimeClass(ClassElement class_) { | 741 ClassElement getRuntimeClass(ClassElement class_) { |
740 if (class_.isSubclassOf(helpers.jsIntClass)) return helpers.jsIntClass; | 742 if (class_.isSubclassOf(commonElements.jsIntClass)) |
741 if (class_.isSubclassOf(helpers.jsArrayClass)) return helpers.jsArrayClass; | 743 return commonElements.jsIntClass; |
| 744 if (class_.isSubclassOf(commonElements.jsArrayClass)) |
| 745 return commonElements.jsArrayClass; |
742 return class_; | 746 return class_; |
743 } | 747 } |
744 | 748 |
745 bool operatorEqHandlesNullArgument(FunctionElement operatorEqfunction) { | 749 bool operatorEqHandlesNullArgument(FunctionElement operatorEqfunction) { |
746 return specialOperatorEqClasses.contains(operatorEqfunction.enclosingClass); | 750 return specialOperatorEqClasses.contains(operatorEqfunction.enclosingClass); |
747 } | 751 } |
748 | 752 |
749 void validateInterceptorImplementsAllObjectMethods( | 753 void validateInterceptorImplementsAllObjectMethods( |
750 ClassElement interceptorClass) { | 754 ClassElement interceptorClass) { |
751 if (interceptorClass == null) return; | 755 if (interceptorClass == null) return; |
752 interceptorClass.ensureResolved(resolution); | 756 interceptorClass.ensureResolved(resolution); |
753 ClassElement objectClass = commonElements.objectClass; | 757 ClassElement objectClass = commonElements.objectClass; |
754 objectClass.forEachMember((_, Element member) { | 758 objectClass.forEachMember((_, Element member) { |
755 if (member.isGenerativeConstructor) return; | 759 if (member.isGenerativeConstructor) return; |
756 Element interceptorMember = interceptorClass.lookupMember(member.name); | 760 Element interceptorMember = interceptorClass.lookupMember(member.name); |
757 // Interceptors must override all Object methods due to calling convention | 761 // Interceptors must override all Object methods due to calling convention |
758 // differences. | 762 // differences. |
759 assert(invariant(interceptorMember, | 763 assert(invariant(interceptorMember, |
760 interceptorMember.enclosingClass == interceptorClass, | 764 interceptorMember.enclosingClass == interceptorClass, |
761 message: | 765 message: |
762 "Member ${member.name} not overridden in ${interceptorClass}. " | 766 "Member ${member.name} not overridden in ${interceptorClass}. " |
763 "Found $interceptorMember from " | 767 "Found $interceptorMember from " |
764 "${interceptorMember.enclosingClass}.")); | 768 "${interceptorMember.enclosingClass}.")); |
765 }); | 769 }); |
766 } | 770 } |
767 | 771 |
768 void onResolutionStart(ResolutionEnqueuer enqueuer) { | 772 void onResolutionStart(ResolutionEnqueuer enqueuer) { |
769 helpers.onResolutionStart(); | 773 // TODO(johnniwinther): Avoid the compiler.elementEnvironment.getThisType |
| 774 // calls. Currently needed to ensure resolution of the classes for various |
| 775 // queries in native behavior computation, inference and codegen. |
| 776 compiler.elementEnvironment.getThisType(commonElements.jsArrayClass); |
| 777 compiler.elementEnvironment |
| 778 .getThisType(commonElements.jsExtendableArrayClass); |
770 | 779 |
771 validateInterceptorImplementsAllObjectMethods(helpers.jsInterceptorClass); | 780 validateInterceptorImplementsAllObjectMethods( |
| 781 commonElements.jsInterceptorClass); |
772 // The null-interceptor must also implement *all* methods. | 782 // The null-interceptor must also implement *all* methods. |
773 validateInterceptorImplementsAllObjectMethods(helpers.jsNullClass); | 783 validateInterceptorImplementsAllObjectMethods(commonElements.jsNullClass); |
774 } | 784 } |
775 | 785 |
776 void onResolutionComplete( | 786 void onResolutionComplete( |
777 ClosedWorld closedWorld, ClosedWorldRefiner closedWorldRefiner) { | 787 ClosedWorld closedWorld, ClosedWorldRefiner closedWorldRefiner) { |
778 for (Entity entity in compiler.enqueuer.resolution.processedEntities) { | 788 for (Entity entity in compiler.enqueuer.resolution.processedEntities) { |
779 processAnnotations(entity, closedWorldRefiner); | 789 processAnnotations(entity, closedWorldRefiner); |
780 } | 790 } |
781 mirrorsDataBuilder.computeMembersNeededForReflection( | 791 mirrorsDataBuilder.computeMembersNeededForReflection( |
782 compiler.enqueuer.resolution.worldBuilder, closedWorld); | 792 compiler.enqueuer.resolution.worldBuilder, closedWorld); |
783 _backendUsage = backendUsageBuilder.close(); | 793 _backendUsage = backendUsageBuilder.close(); |
784 _rtiNeed = rtiNeedBuilder.computeRuntimeTypesNeed( | 794 _rtiNeed = rtiNeedBuilder.computeRuntimeTypesNeed( |
785 compiler.enqueuer.resolution.worldBuilder, | 795 compiler.enqueuer.resolution.worldBuilder, |
786 closedWorld, | 796 closedWorld, |
787 compiler.types, | 797 compiler.types, |
788 commonElements, | 798 commonElements, |
789 helpers, | |
790 _backendUsage, | 799 _backendUsage, |
791 enableTypeAssertions: compiler.options.enableTypeAssertions); | 800 enableTypeAssertions: compiler.options.enableTypeAssertions); |
792 _interceptorData = interceptorDataBuilder.onResolutionComplete(closedWorld); | 801 _interceptorData = interceptorDataBuilder.onResolutionComplete(closedWorld); |
793 _oneShotInterceptorData = | 802 _oneShotInterceptorData = |
794 new OneShotInterceptorData(interceptorData, helpers); | 803 new OneShotInterceptorData(interceptorData, commonElements); |
795 mirrorsResolutionAnalysis.onResolutionComplete(); | 804 mirrorsResolutionAnalysis.onResolutionComplete(); |
796 } | 805 } |
797 | 806 |
798 void onTypeInferenceComplete(GlobalTypeInferenceResults results) { | 807 void onTypeInferenceComplete(GlobalTypeInferenceResults results) { |
799 noSuchMethodRegistry.onTypeInferenceComplete(results); | 808 noSuchMethodRegistry.onTypeInferenceComplete(results); |
800 } | 809 } |
801 | 810 |
802 /// Called when resolving a call to a foreign function. | 811 /// Called when resolving a call to a foreign function. |
803 native.NativeBehavior resolveForeignCall(Send node, Element element, | 812 native.NativeBehavior resolveForeignCall(Send node, Element element, |
804 CallStructure callStructure, ForeignResolver resolver) { | 813 CallStructure callStructure, ForeignResolver resolver) { |
805 if (element.name == BackendHelpers.JS) { | 814 if (element.name == JS) { |
806 return _nativeDataResolver.resolveJsCall(node, resolver); | 815 return _nativeDataResolver.resolveJsCall(node, resolver); |
807 } else if (element.name == BackendHelpers.JS_EMBEDDED_GLOBAL) { | 816 } else if (element.name == JS_EMBEDDED_GLOBAL) { |
808 return _nativeDataResolver.resolveJsEmbeddedGlobalCall(node, resolver); | 817 return _nativeDataResolver.resolveJsEmbeddedGlobalCall(node, resolver); |
809 } else if (element.name == BackendHelpers.JS_BUILTIN) { | 818 } else if (element.name == JS_BUILTIN) { |
810 return _nativeDataResolver.resolveJsBuiltinCall(node, resolver); | 819 return _nativeDataResolver.resolveJsBuiltinCall(node, resolver); |
811 } else if (element.name == BackendHelpers.JS_INTERCEPTOR_CONSTANT) { | 820 } else if (element.name == JS_INTERCEPTOR_CONSTANT) { |
812 // The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names | 821 // The type constant that is an argument to JS_INTERCEPTOR_CONSTANT names |
813 // a class that will be instantiated outside the program by attaching a | 822 // a class that will be instantiated outside the program by attaching a |
814 // native class dispatch record referencing the interceptor. | 823 // native class dispatch record referencing the interceptor. |
815 if (!node.argumentsNode.isEmpty) { | 824 if (!node.argumentsNode.isEmpty) { |
816 Node argument = node.argumentsNode.nodes.head; | 825 Node argument = node.argumentsNode.nodes.head; |
817 ConstantExpression constant = resolver.getConstant(argument); | 826 ConstantExpression constant = resolver.getConstant(argument); |
818 if (constant != null && constant.kind == ConstantExpressionKind.TYPE) { | 827 if (constant != null && constant.kind == ConstantExpressionKind.TYPE) { |
819 TypeConstantExpression typeConstant = constant; | 828 TypeConstantExpression typeConstant = constant; |
820 if (typeConstant.type is ResolutionInterfaceType) { | 829 if (typeConstant.type is ResolutionInterfaceType) { |
821 resolver.registerInstantiatedType(typeConstant.type); | 830 resolver.registerInstantiatedType(typeConstant.type); |
822 // No native behavior for this call. | 831 // No native behavior for this call. |
823 return null; | 832 return null; |
824 } | 833 } |
825 } | 834 } |
826 } | 835 } |
827 reporter.reportErrorMessage( | 836 reporter.reportErrorMessage( |
828 node, MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); | 837 node, MessageKind.WRONG_ARGUMENT_FOR_JS_INTERCEPTOR_CONSTANT); |
829 } | 838 } |
830 // No native behavior for this call. | 839 // No native behavior for this call. |
831 return null; | 840 return null; |
832 } | 841 } |
833 | 842 |
834 ResolutionEnqueuer createResolutionEnqueuer( | 843 ResolutionEnqueuer createResolutionEnqueuer( |
835 CompilerTask task, Compiler compiler) { | 844 CompilerTask task, Compiler compiler) { |
836 _nativeBasicData = | 845 _nativeBasicData = |
837 nativeBasicDataBuilder.close(compiler.elementEnvironment); | 846 nativeBasicDataBuilder.close(compiler.elementEnvironment); |
838 _backendClasses = new JavaScriptBackendClasses( | 847 _backendClasses = new JavaScriptBackendClasses( |
839 compiler.elementEnvironment, helpers, nativeBasicData); | 848 compiler.elementEnvironment, commonElements, nativeBasicData); |
840 _nativeResolutionEnqueuer = new native.NativeResolutionEnqueuer( | 849 _nativeResolutionEnqueuer = new native.NativeResolutionEnqueuer( |
841 compiler.options, | 850 compiler.options, |
842 compiler.elementEnvironment, | 851 compiler.elementEnvironment, |
843 commonElements, | 852 commonElements, |
844 helpers, | |
845 backendClasses, | 853 backendClasses, |
846 backendUsageBuilder, | 854 backendUsageBuilder, |
847 new NativeClassResolverImpl( | 855 new NativeClassResolverImpl( |
848 compiler.resolution, reporter, helpers, nativeBasicData)); | 856 compiler.resolution, reporter, commonElements, nativeBasicData)); |
849 _nativeData = new NativeDataImpl(nativeBasicData); | 857 _nativeData = new NativeDataImpl(nativeBasicData); |
850 _customElementsResolutionAnalysis = new CustomElementsResolutionAnalysis( | 858 _customElementsResolutionAnalysis = new CustomElementsResolutionAnalysis( |
851 compiler.resolution, | 859 compiler.resolution, |
852 constantSystem, | 860 constantSystem, |
853 commonElements, | 861 commonElements, |
854 backendClasses, | 862 backendClasses, |
855 helpers, | |
856 nativeBasicData, | 863 nativeBasicData, |
857 backendUsageBuilder); | 864 backendUsageBuilder); |
858 impactTransformer = new JavaScriptImpactTransformer( | 865 impactTransformer = new JavaScriptImpactTransformer( |
859 compiler.options, | 866 compiler.options, |
860 compiler.resolution, | 867 compiler.resolution, |
861 compiler.elementEnvironment, | 868 compiler.elementEnvironment, |
862 commonElements, | 869 commonElements, |
863 impacts, | 870 impacts, |
864 nativeBasicData, | 871 nativeBasicData, |
865 _nativeResolutionEnqueuer, | 872 _nativeResolutionEnqueuer, |
866 backendUsageBuilder, | 873 backendUsageBuilder, |
867 mirrorsDataBuilder, | 874 mirrorsDataBuilder, |
868 customElementsResolutionAnalysis, | 875 customElementsResolutionAnalysis, |
869 rtiNeedBuilder); | 876 rtiNeedBuilder); |
870 _interceptorDataBuilder = new InterceptorDataBuilderImpl( | 877 _interceptorDataBuilder = new InterceptorDataBuilderImpl( |
871 nativeBasicData, helpers, compiler.elementEnvironment, commonElements); | 878 nativeBasicData, compiler.elementEnvironment, commonElements); |
872 return new ResolutionEnqueuer( | 879 return new ResolutionEnqueuer( |
873 task, | 880 task, |
874 compiler.options, | 881 compiler.options, |
875 compiler.reporter, | 882 compiler.reporter, |
876 compiler.options.analyzeOnly && compiler.options.analyzeMain | 883 compiler.options.analyzeOnly && compiler.options.analyzeMain |
877 ? const DirectEnqueuerStrategy() | 884 ? const DirectEnqueuerStrategy() |
878 : const TreeShakingEnqueuerStrategy(), | 885 : const TreeShakingEnqueuerStrategy(), |
879 new ResolutionEnqueuerListener( | 886 new ResolutionEnqueuerListener( |
880 compiler.options, | 887 compiler.options, |
881 compiler.elementEnvironment, | 888 compiler.elementEnvironment, |
882 commonElements, | 889 commonElements, |
883 helpers, | |
884 impacts, | 890 impacts, |
885 backendClasses, | 891 backendClasses, |
886 nativeBasicData, | 892 nativeBasicData, |
887 interceptorDataBuilder, | 893 interceptorDataBuilder, |
888 backendUsageBuilder, | 894 backendUsageBuilder, |
889 rtiNeedBuilder, | 895 rtiNeedBuilder, |
890 mirrorsDataBuilder, | 896 mirrorsDataBuilder, |
891 noSuchMethodRegistry, | 897 noSuchMethodRegistry, |
892 customElementsResolutionAnalysis, | 898 customElementsResolutionAnalysis, |
893 lookupMapResolutionAnalysis, | 899 lookupMapResolutionAnalysis, |
894 mirrorsResolutionAnalysis, | 900 mirrorsResolutionAnalysis, |
895 typeVariableResolutionAnalysis, | 901 typeVariableResolutionAnalysis, |
896 _nativeResolutionEnqueuer, | 902 _nativeResolutionEnqueuer, |
897 compiler.deferredLoadTask, | 903 compiler.deferredLoadTask, |
898 kernelTask), | 904 kernelTask), |
899 new ElementResolutionWorldBuilder( | 905 new ElementResolutionWorldBuilder( |
900 this, compiler.resolution, const OpenWorldStrategy()), | 906 this, compiler.resolution, const OpenWorldStrategy()), |
901 new ResolutionWorkItemBuilder(compiler.resolution)); | 907 new ResolutionWorkItemBuilder(compiler.resolution)); |
902 } | 908 } |
903 | 909 |
904 /// Creates an [Enqueuer] for code generation specific to this backend. | 910 /// Creates an [Enqueuer] for code generation specific to this backend. |
905 CodegenEnqueuer createCodegenEnqueuer( | 911 CodegenEnqueuer createCodegenEnqueuer( |
906 CompilerTask task, Compiler compiler, ClosedWorld closedWorld) { | 912 CompilerTask task, Compiler compiler, ClosedWorld closedWorld) { |
907 _typeVariableCodegenAnalysis = | 913 _typeVariableCodegenAnalysis = |
908 new TypeVariableCodegenAnalysis(this, helpers, mirrorsData); | 914 new TypeVariableCodegenAnalysis(this, commonElements, mirrorsData); |
909 _lookupMapAnalysis = new LookupMapAnalysis( | 915 _lookupMapAnalysis = new LookupMapAnalysis( |
910 reporter, | 916 reporter, |
911 constantSystem, | 917 constantSystem, |
912 constants, | 918 constants, |
913 compiler.elementEnvironment, | 919 compiler.elementEnvironment, |
914 commonElements, | 920 commonElements, |
915 helpers, | |
916 backendClasses, | 921 backendClasses, |
917 lookupMapResolutionAnalysis); | 922 lookupMapResolutionAnalysis); |
918 _mirrorsCodegenAnalysis = mirrorsResolutionAnalysis.close(); | 923 _mirrorsCodegenAnalysis = mirrorsResolutionAnalysis.close(); |
919 _customElementsCodegenAnalysis = new CustomElementsCodegenAnalysis( | 924 _customElementsCodegenAnalysis = new CustomElementsCodegenAnalysis( |
920 compiler.resolution, | 925 compiler.resolution, |
921 constantSystem, | 926 constantSystem, |
922 commonElements, | 927 commonElements, |
923 backendClasses, | 928 backendClasses, |
924 helpers, | |
925 nativeBasicData); | 929 nativeBasicData); |
926 _nativeCodegenEnqueuer = new native.NativeCodegenEnqueuer( | 930 _nativeCodegenEnqueuer = new native.NativeCodegenEnqueuer( |
927 compiler.options, | 931 compiler.options, |
928 compiler.elementEnvironment, | 932 compiler.elementEnvironment, |
929 commonElements, | 933 commonElements, |
930 helpers, | |
931 backendClasses, | 934 backendClasses, |
932 emitter, | 935 emitter, |
933 _nativeResolutionEnqueuer, | 936 _nativeResolutionEnqueuer, |
934 nativeData); | 937 nativeData); |
935 return new CodegenEnqueuer( | 938 return new CodegenEnqueuer( |
936 task, | 939 task, |
937 compiler.options, | 940 compiler.options, |
938 const TreeShakingEnqueuerStrategy(), | 941 const TreeShakingEnqueuerStrategy(), |
939 new CodegenWorldBuilderImpl( | 942 new CodegenWorldBuilderImpl( |
940 nativeBasicData, closedWorld, constants, const TypeMaskStrategy()), | 943 nativeBasicData, closedWorld, constants, const TypeMaskStrategy()), |
941 new CodegenWorkItemBuilder(this, compiler.options), | 944 new CodegenWorkItemBuilder(this, compiler.options), |
942 new CodegenEnqueuerListener( | 945 new CodegenEnqueuerListener( |
943 compiler.elementEnvironment, | 946 compiler.elementEnvironment, |
944 commonElements, | 947 commonElements, |
945 helpers, | |
946 impacts, | 948 impacts, |
947 backendClasses, | 949 backendClasses, |
948 backendUsage, | 950 backendUsage, |
949 rtiNeed, | 951 rtiNeed, |
950 customElementsCodegenAnalysis, | 952 customElementsCodegenAnalysis, |
951 typeVariableCodegenAnalysis, | 953 typeVariableCodegenAnalysis, |
952 lookupMapAnalysis, | 954 lookupMapAnalysis, |
953 mirrorsCodegenAnalysis, | 955 mirrorsCodegenAnalysis, |
954 nativeCodegenEnqueuer)); | 956 nativeCodegenEnqueuer)); |
955 } | 957 } |
(...skipping 11 matching lines...) Expand all Loading... |
967 js.escapedString("Compile time error in $element: $messageText"); | 969 js.escapedString("Compile time error in $element: $messageText"); |
968 generatedCode[element] = | 970 generatedCode[element] = |
969 js("function () { throw new Error(#); }", [messageLiteral]); | 971 js("function () { throw new Error(#); }", [messageLiteral]); |
970 return const CodegenImpact(); | 972 return const CodegenImpact(); |
971 } | 973 } |
972 var kind = element.kind; | 974 var kind = element.kind; |
973 if (kind == ElementKind.TYPEDEF) { | 975 if (kind == ElementKind.TYPEDEF) { |
974 return const WorldImpact(); | 976 return const WorldImpact(); |
975 } | 977 } |
976 if (element.isConstructor && | 978 if (element.isConstructor && |
977 element.enclosingClass == helpers.jsNullClass) { | 979 element.enclosingClass == commonElements.jsNullClass) { |
978 // Work around a problem compiling JSNull's constructor. | 980 // Work around a problem compiling JSNull's constructor. |
979 return const CodegenImpact(); | 981 return const CodegenImpact(); |
980 } | 982 } |
981 if (kind.category == ElementCategory.VARIABLE) { | 983 if (kind.category == ElementCategory.VARIABLE) { |
982 FieldElement variableElement = element; | 984 FieldElement variableElement = element; |
983 ConstantExpression constant = variableElement.constant; | 985 ConstantExpression constant = variableElement.constant; |
984 if (constant != null) { | 986 if (constant != null) { |
985 ConstantValue initialValue = constants.getConstantValue(constant); | 987 ConstantValue initialValue = constants.getConstantValue(constant); |
986 if (initialValue != null) { | 988 if (initialValue != null) { |
987 work.registry.worldImpact | 989 work.registry.worldImpact |
(...skipping 13 matching lines...) Expand all Loading... |
1001 constant.isPotential, | 1003 constant.isPotential, |
1002 message: "Constant expression without value: " | 1004 message: "Constant expression without value: " |
1003 "${constant.toStructuredText()}.")); | 1005 "${constant.toStructuredText()}.")); |
1004 } | 1006 } |
1005 } else { | 1007 } else { |
1006 // If the constant-handler was not able to produce a result we have to | 1008 // If the constant-handler was not able to produce a result we have to |
1007 // go through the builder (below) to generate the lazy initializer for | 1009 // go through the builder (below) to generate the lazy initializer for |
1008 // the static variable. | 1010 // the static variable. |
1009 // We also need to register the use of the cyclic-error helper. | 1011 // We also need to register the use of the cyclic-error helper. |
1010 work.registry.worldImpact.registerStaticUse(new StaticUse.staticInvoke( | 1012 work.registry.worldImpact.registerStaticUse(new StaticUse.staticInvoke( |
1011 helpers.cyclicThrowHelper, CallStructure.ONE_ARG)); | 1013 commonElements.cyclicThrowHelper, CallStructure.ONE_ARG)); |
1012 } | 1014 } |
1013 } | 1015 } |
1014 | 1016 |
1015 jsAst.Fun function = functionCompiler.compile(work, _closedWorld); | 1017 jsAst.Fun function = functionCompiler.compile(work, _closedWorld); |
1016 if (function.sourceInformation == null) { | 1018 if (function.sourceInformation == null) { |
1017 function = function.withSourceInformation( | 1019 function = function.withSourceInformation( |
1018 sourceInformationStrategy.buildSourceMappedMarker()); | 1020 sourceInformationStrategy.buildSourceMappedMarker()); |
1019 } | 1021 } |
1020 generatedCode[element] = function; | 1022 generatedCode[element] = function; |
1021 WorldImpact worldImpact = _codegenImpactTransformer | 1023 WorldImpact worldImpact = _codegenImpactTransformer |
1022 .transformCodegenImpact(work.registry.worldImpact); | 1024 .transformCodegenImpact(work.registry.worldImpact); |
1023 compiler.dumpInfoTask.registerImpact(element, worldImpact); | 1025 compiler.dumpInfoTask.registerImpact(element, worldImpact); |
1024 return worldImpact; | 1026 return worldImpact; |
1025 } | 1027 } |
1026 | 1028 |
1027 // TODO(johnniwinther): Remove this. It is now only used for testing. | 1029 // TODO(johnniwinther): Remove this. It is now only used for testing. |
1028 @deprecated | 1030 @deprecated |
1029 native.NativeEnqueuer get nativeResolutionEnqueuer => | 1031 native.NativeEnqueuer get nativeResolutionEnqueuer => |
1030 _nativeResolutionEnqueuer; | 1032 _nativeResolutionEnqueuer; |
1031 | 1033 |
1032 native.NativeEnqueuer get nativeCodegenEnqueuer => _nativeCodegenEnqueuer; | 1034 native.NativeEnqueuer get nativeCodegenEnqueuer => _nativeCodegenEnqueuer; |
1033 | 1035 |
1034 ClassElement defaultSuperclass(ClassElement element) { | 1036 ClassElement defaultSuperclass(ClassElement element) { |
1035 if (nativeBasicData.isJsInteropClass(element)) { | 1037 if (nativeBasicData.isJsInteropClass(element)) { |
1036 return helpers.jsJavaScriptObjectClass; | 1038 return commonElements.jsJavaScriptObjectClass; |
1037 } | 1039 } |
1038 // Native classes inherit from Interceptor. | 1040 // Native classes inherit from Interceptor. |
1039 return nativeBasicData.isNativeClass(element) | 1041 return nativeBasicData.isNativeClass(element) |
1040 ? helpers.jsInterceptorClass | 1042 ? commonElements.jsInterceptorClass |
1041 : commonElements.objectClass; | 1043 : commonElements.objectClass; |
1042 } | 1044 } |
1043 | 1045 |
1044 /** | 1046 /** |
1045 * Unit test hook that returns code of an element as a String. | 1047 * Unit test hook that returns code of an element as a String. |
1046 * | 1048 * |
1047 * Invariant: [element] must be a declaration element. | 1049 * Invariant: [element] must be a declaration element. |
1048 */ | 1050 */ |
1049 String getGeneratedCode(Element element) { | 1051 String getGeneratedCode(Element element) { |
1050 assert(invariant(element, element.isDeclaration)); | 1052 assert(invariant(element, element.isDeclaration)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 * Returns [:true:] if the checking of [type] is performed directly on the | 1099 * Returns [:true:] if the checking of [type] is performed directly on the |
1098 * object and not on an interceptor. | 1100 * object and not on an interceptor. |
1099 */ | 1101 */ |
1100 bool hasDirectCheckFor(ResolutionDartType type) { | 1102 bool hasDirectCheckFor(ResolutionDartType type) { |
1101 Element element = type.element; | 1103 Element element = type.element; |
1102 return element == commonElements.stringClass || | 1104 return element == commonElements.stringClass || |
1103 element == commonElements.boolClass || | 1105 element == commonElements.boolClass || |
1104 element == commonElements.numClass || | 1106 element == commonElements.numClass || |
1105 element == commonElements.intClass || | 1107 element == commonElements.intClass || |
1106 element == commonElements.doubleClass || | 1108 element == commonElements.doubleClass || |
1107 element == helpers.jsArrayClass || | 1109 element == commonElements.jsArrayClass || |
1108 element == helpers.jsMutableArrayClass || | 1110 element == commonElements.jsMutableArrayClass || |
1109 element == helpers.jsExtendableArrayClass || | 1111 element == commonElements.jsExtendableArrayClass || |
1110 element == helpers.jsFixedArrayClass || | 1112 element == commonElements.jsFixedArrayClass || |
1111 element == helpers.jsUnmodifiableArrayClass; | 1113 element == commonElements.jsUnmodifiableArrayClass; |
1112 } | 1114 } |
1113 | 1115 |
1114 /// This method is called immediately after the [library] and its parts have | 1116 /// This method is called immediately after the [library] and its parts have |
1115 /// been loaded. | 1117 /// been loaded. |
1116 void setAnnotations(LibraryElement library) { | 1118 void setAnnotations(LibraryElement library) { |
1117 if (!compiler.serialization.isDeserialized(library)) { | 1119 if (!compiler.serialization.isDeserialized(library)) { |
1118 if (canLibraryUseNative(library)) { | 1120 if (canLibraryUseNative(library)) { |
1119 library.forEachLocalMember((Element element) { | 1121 library.forEachLocalMember((Element element) { |
1120 if (element.isClass) { | 1122 if (element.isClass) { |
1121 checkNativeAnnotation(compiler, element, nativeBasicDataBuilder); | 1123 checkNativeAnnotation(compiler, element, nativeBasicDataBuilder); |
1122 } | 1124 } |
1123 }); | 1125 }); |
1124 } | 1126 } |
1125 checkJsInteropClassAnnotations(compiler, library, nativeBasicDataBuilder); | 1127 checkJsInteropClassAnnotations(compiler, library, nativeBasicDataBuilder); |
1126 } | 1128 } |
1127 Uri uri = library.canonicalUri; | 1129 Uri uri = library.canonicalUri; |
1128 if (uri == Uris.dart_html) { | 1130 if (uri == Uris.dart_html) { |
1129 htmlLibraryIsLoaded = true; | 1131 htmlLibraryIsLoaded = true; |
1130 } else if (uri == LookupMapResolutionAnalysis.PACKAGE_LOOKUP_MAP) { | 1132 } else if (uri == LookupMapResolutionAnalysis.PACKAGE_LOOKUP_MAP) { |
1131 lookupMapResolutionAnalysis.init(library); | 1133 lookupMapResolutionAnalysis.init(library); |
1132 } | 1134 } |
1133 annotations.onLibraryLoaded(library); | 1135 annotations.onLibraryLoaded(library); |
1134 } | 1136 } |
1135 | 1137 |
1136 /// This method is called when all new libraries loaded through | 1138 /// This method is called when all new libraries loaded through |
1137 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 1139 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
1138 /// have been computed. | 1140 /// have been computed. |
1139 void onLibrariesLoaded(LoadedLibraries loadedLibraries) { | 1141 void onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
1140 if (loadedLibraries.containsLibrary(Uris.dart_core)) { | 1142 if (loadedLibraries.containsLibrary(Uris.dart_core)) { |
1141 helpers.onLibrariesLoaded(loadedLibraries); | 1143 assert(loadedLibraries.containsLibrary(Uris.dart_core)); |
| 1144 assert(loadedLibraries.containsLibrary(Uris.dart__interceptors)); |
| 1145 assert(loadedLibraries.containsLibrary(Uris.dart__js_helper)); |
1142 | 1146 |
1143 // These methods are overwritten with generated versions. | 1147 // These methods are overwritten with generated versions. |
1144 inlineCache.markAsNonInlinable(helpers.getInterceptorMethod, | 1148 inlineCache.markAsNonInlinable(commonElements.getInterceptorMethod, |
1145 insideLoop: true); | 1149 insideLoop: true); |
1146 | 1150 |
1147 specialOperatorEqClasses | 1151 specialOperatorEqClasses |
1148 ..add(commonElements.objectClass) | 1152 ..add(commonElements.objectClass) |
1149 ..add(helpers.jsInterceptorClass) | 1153 ..add(commonElements.jsInterceptorClass) |
1150 ..add(helpers.jsNullClass); | 1154 ..add(commonElements.jsNullClass); |
1151 } | 1155 } |
1152 } | 1156 } |
1153 | 1157 |
1154 jsAst.Call generateIsJsIndexableCall( | 1158 jsAst.Call generateIsJsIndexableCall( |
1155 jsAst.Expression use1, jsAst.Expression use2) { | 1159 jsAst.Expression use1, jsAst.Expression use2) { |
1156 String dispatchPropertyName = embeddedNames.DISPATCH_PROPERTY_NAME; | 1160 String dispatchPropertyName = embeddedNames.DISPATCH_PROPERTY_NAME; |
1157 jsAst.Expression dispatchProperty = | 1161 jsAst.Expression dispatchProperty = |
1158 emitter.generateEmbeddedGlobalAccess(dispatchPropertyName); | 1162 emitter.generateEmbeddedGlobalAccess(dispatchPropertyName); |
1159 | 1163 |
1160 // We pass the dispatch property record to the isJsIndexable | 1164 // We pass the dispatch property record to the isJsIndexable |
1161 // helper rather than reading it inside the helper to increase the | 1165 // helper rather than reading it inside the helper to increase the |
1162 // chance of making the dispatch record access monomorphic. | 1166 // chance of making the dispatch record access monomorphic. |
1163 jsAst.PropertyAccess record = | 1167 jsAst.PropertyAccess record = |
1164 new jsAst.PropertyAccess(use2, dispatchProperty); | 1168 new jsAst.PropertyAccess(use2, dispatchProperty); |
1165 | 1169 |
1166 List<jsAst.Expression> arguments = <jsAst.Expression>[use1, record]; | 1170 List<jsAst.Expression> arguments = <jsAst.Expression>[use1, record]; |
1167 MethodElement helper = helpers.isJsIndexable; | 1171 MethodElement helper = commonElements.isJsIndexable; |
1168 jsAst.Expression helperExpression = emitter.staticFunctionAccess(helper); | 1172 jsAst.Expression helperExpression = emitter.staticFunctionAccess(helper); |
1169 return new jsAst.Call(helperExpression, arguments); | 1173 return new jsAst.Call(helperExpression, arguments); |
1170 } | 1174 } |
1171 | 1175 |
1172 /// Called after the queue is closed. [onQueueEmpty] may be called multiple | 1176 /// Called after the queue is closed. [onQueueEmpty] may be called multiple |
1173 /// times, but [onQueueClosed] is only called once. | 1177 /// times, but [onQueueClosed] is only called once. |
1174 void onQueueClosed() { | 1178 void onQueueClosed() { |
1175 jsInteropAnalysis.onQueueClosed(); | 1179 jsInteropAnalysis.onQueueClosed(); |
1176 } | 1180 } |
1177 | 1181 |
(...skipping 11 matching lines...) Expand all Loading... |
1189 } | 1193 } |
1190 | 1194 |
1191 /// Called when the compiler starts running the codegen enqueuer. The | 1195 /// Called when the compiler starts running the codegen enqueuer. The |
1192 /// [WorldImpact] of enabled backend features is returned. | 1196 /// [WorldImpact] of enabled backend features is returned. |
1193 WorldImpact onCodegenStart( | 1197 WorldImpact onCodegenStart( |
1194 ClosedWorld closedWorld, CodegenWorldBuilder codegenWorldBuilder) { | 1198 ClosedWorld closedWorld, CodegenWorldBuilder codegenWorldBuilder) { |
1195 _closedWorld = closedWorld; | 1199 _closedWorld = closedWorld; |
1196 _namer = determineNamer(closedWorld, codegenWorldBuilder); | 1200 _namer = determineNamer(closedWorld, codegenWorldBuilder); |
1197 tracer = new Tracer(closedWorld, namer, compiler); | 1201 tracer = new Tracer(closedWorld, namer, compiler); |
1198 emitter.createEmitter(namer, closedWorld); | 1202 emitter.createEmitter(namer, closedWorld); |
1199 _rtiEncoder = | 1203 _rtiEncoder = _namer.rtiEncoder = |
1200 _namer.rtiEncoder = new _RuntimeTypesEncoder(namer, emitter, helpers); | 1204 new _RuntimeTypesEncoder(namer, emitter, commonElements); |
1201 _codegenImpactTransformer = new CodegenImpactTransformer( | 1205 _codegenImpactTransformer = new CodegenImpactTransformer( |
1202 compiler.options, | 1206 compiler.options, |
1203 compiler.elementEnvironment, | 1207 compiler.elementEnvironment, |
1204 helpers, | 1208 commonElements, |
1205 impacts, | 1209 impacts, |
1206 checkedModeHelpers, | 1210 checkedModeHelpers, |
1207 nativeData, | 1211 nativeData, |
1208 backendUsage, | 1212 backendUsage, |
1209 rtiNeed, | 1213 rtiNeed, |
1210 nativeCodegenEnqueuer, | 1214 nativeCodegenEnqueuer, |
1211 namer, | 1215 namer, |
1212 oneShotInterceptorData, | 1216 oneShotInterceptorData, |
1213 lookupMapAnalysis, | 1217 lookupMapAnalysis, |
1214 rtiChecksBuilder); | 1218 rtiChecksBuilder); |
1215 return const WorldImpact(); | 1219 return const WorldImpact(); |
1216 } | 1220 } |
1217 | 1221 |
1218 /// Called when code generation has been completed. | 1222 /// Called when code generation has been completed. |
1219 void onCodegenEnd() { | 1223 void onCodegenEnd() { |
1220 sourceInformationStrategy.onComplete(); | 1224 sourceInformationStrategy.onComplete(); |
1221 tracer.close(); | 1225 tracer.close(); |
1222 } | 1226 } |
1223 | 1227 |
1224 // Does this element belong in the output | 1228 // Does this element belong in the output |
1225 bool shouldOutput(Element element) => true; | 1229 bool shouldOutput(Element element) => true; |
1226 | 1230 |
1227 /// Returns `true` if the `native` pseudo keyword is supported for [library]. | 1231 /// Returns `true` if the `native` pseudo keyword is supported for [library]. |
1228 bool canLibraryUseNative(LibraryElement library) { | 1232 bool canLibraryUseNative(LibraryElement library) { |
1229 return native.maybeEnableNative(compiler, library); | 1233 return native.maybeEnableNative(compiler, library); |
1230 } | 1234 } |
1231 | 1235 |
1232 bool isTargetSpecificLibrary(LibraryElement library) { | 1236 bool isTargetSpecificLibrary(LibraryElement library) { |
1233 Uri canonicalUri = library.canonicalUri; | 1237 Uri canonicalUri = library.canonicalUri; |
1234 if (canonicalUri == BackendHelpers.DART_JS_HELPER || | 1238 if (canonicalUri == Uris.dart__js_helper || |
1235 canonicalUri == BackendHelpers.DART_INTERCEPTORS) { | 1239 canonicalUri == Uris.dart__interceptors) { |
1236 return true; | 1240 return true; |
1237 } | 1241 } |
1238 return false; | 1242 return false; |
1239 } | 1243 } |
1240 | 1244 |
1241 /// Process backend specific annotations. | 1245 /// Process backend specific annotations. |
1242 void processAnnotations( | 1246 void processAnnotations( |
1243 Element element, ClosedWorldRefiner closedWorldRefiner) { | 1247 Element element, ClosedWorldRefiner closedWorldRefiner) { |
1244 if (element.isMalformed) { | 1248 if (element.isMalformed) { |
1245 // Elements that are marked as malformed during parsing or resolution | 1249 // Elements that are marked as malformed during parsing or resolution |
(...skipping 14 matching lines...) Expand all Loading... |
1260 bool hasForceInline = false; | 1264 bool hasForceInline = false; |
1261 bool hasNoThrows = false; | 1265 bool hasNoThrows = false; |
1262 bool hasNoSideEffects = false; | 1266 bool hasNoSideEffects = false; |
1263 for (MetadataAnnotation metadata in element.implementation.metadata) { | 1267 for (MetadataAnnotation metadata in element.implementation.metadata) { |
1264 metadata.ensureResolved(resolution); | 1268 metadata.ensureResolved(resolution); |
1265 ConstantValue constantValue = | 1269 ConstantValue constantValue = |
1266 compiler.constants.getConstantValue(metadata.constant); | 1270 compiler.constants.getConstantValue(metadata.constant); |
1267 if (!constantValue.isConstructedObject) continue; | 1271 if (!constantValue.isConstructedObject) continue; |
1268 ObjectConstantValue value = constantValue; | 1272 ObjectConstantValue value = constantValue; |
1269 ClassElement cls = value.type.element; | 1273 ClassElement cls = value.type.element; |
1270 if (cls == helpers.forceInlineClass) { | 1274 if (cls == commonElements.forceInlineClass) { |
1271 hasForceInline = true; | 1275 hasForceInline = true; |
1272 if (VERBOSE_OPTIMIZER_HINTS) { | 1276 if (VERBOSE_OPTIMIZER_HINTS) { |
1273 reporter.reportHintMessage( | 1277 reporter.reportHintMessage( |
1274 element, MessageKind.GENERIC, {'text': "Must inline"}); | 1278 element, MessageKind.GENERIC, {'text': "Must inline"}); |
1275 } | 1279 } |
1276 inlineCache.markAsMustInline(element); | 1280 inlineCache.markAsMustInline(element); |
1277 } else if (cls == helpers.noInlineClass) { | 1281 } else if (cls == commonElements.noInlineClass) { |
1278 hasNoInline = true; | 1282 hasNoInline = true; |
1279 if (VERBOSE_OPTIMIZER_HINTS) { | 1283 if (VERBOSE_OPTIMIZER_HINTS) { |
1280 reporter.reportHintMessage( | 1284 reporter.reportHintMessage( |
1281 element, MessageKind.GENERIC, {'text': "Cannot inline"}); | 1285 element, MessageKind.GENERIC, {'text': "Cannot inline"}); |
1282 } | 1286 } |
1283 inlineCache.markAsNonInlinable(element); | 1287 inlineCache.markAsNonInlinable(element); |
1284 } else if (cls == helpers.noThrowsClass) { | 1288 } else if (cls == commonElements.noThrowsClass) { |
1285 hasNoThrows = true; | 1289 hasNoThrows = true; |
1286 if (!Elements.isStaticOrTopLevelFunction(element) && | 1290 if (!Elements.isStaticOrTopLevelFunction(element) && |
1287 !element.isFactoryConstructor) { | 1291 !element.isFactoryConstructor) { |
1288 reporter.internalError( | 1292 reporter.internalError( |
1289 element, | 1293 element, |
1290 "@NoThrows() is currently limited to top-level" | 1294 "@NoThrows() is currently limited to top-level" |
1291 " or static functions and factory constructors."); | 1295 " or static functions and factory constructors."); |
1292 } | 1296 } |
1293 if (VERBOSE_OPTIMIZER_HINTS) { | 1297 if (VERBOSE_OPTIMIZER_HINTS) { |
1294 reporter.reportHintMessage( | 1298 reporter.reportHintMessage( |
1295 element, MessageKind.GENERIC, {'text': "Cannot throw"}); | 1299 element, MessageKind.GENERIC, {'text': "Cannot throw"}); |
1296 } | 1300 } |
1297 closedWorldRefiner.registerCannotThrow(element); | 1301 closedWorldRefiner.registerCannotThrow(element); |
1298 } else if (cls == helpers.noSideEffectsClass) { | 1302 } else if (cls == commonElements.noSideEffectsClass) { |
1299 hasNoSideEffects = true; | 1303 hasNoSideEffects = true; |
1300 if (VERBOSE_OPTIMIZER_HINTS) { | 1304 if (VERBOSE_OPTIMIZER_HINTS) { |
1301 reporter.reportHintMessage( | 1305 reporter.reportHintMessage( |
1302 element, MessageKind.GENERIC, {'text': "Has no side effects"}); | 1306 element, MessageKind.GENERIC, {'text': "Has no side effects"}); |
1303 } | 1307 } |
1304 closedWorldRefiner.registerSideEffectsFree(element); | 1308 closedWorldRefiner.registerSideEffectsFree(element); |
1305 } | 1309 } |
1306 } | 1310 } |
1307 if (hasForceInline && hasNoInline) { | 1311 if (hasForceInline && hasNoInline) { |
1308 reporter.internalError( | 1312 reporter.internalError( |
1309 element, "@ForceInline() must not be used with @NoInline."); | 1313 element, "@ForceInline() must not be used with @NoInline."); |
1310 } | 1314 } |
1311 if (hasNoThrows && !hasNoInline) { | 1315 if (hasNoThrows && !hasNoInline) { |
1312 reporter.internalError( | 1316 reporter.internalError( |
1313 element, "@NoThrows() should always be combined with @NoInline."); | 1317 element, "@NoThrows() should always be combined with @NoInline."); |
1314 } | 1318 } |
1315 if (hasNoSideEffects && !hasNoInline) { | 1319 if (hasNoSideEffects && !hasNoInline) { |
1316 reporter.internalError(element, | 1320 reporter.internalError(element, |
1317 "@NoSideEffects() should always be combined with @NoInline."); | 1321 "@NoSideEffects() should always be combined with @NoInline."); |
1318 } | 1322 } |
1319 } | 1323 } |
1320 | 1324 |
1321 MethodElement helperForBadMain() => helpers.badMain; | 1325 MethodElement helperForBadMain() => commonElements.badMain; |
1322 | 1326 |
1323 MethodElement helperForMissingMain() => helpers.missingMain; | 1327 MethodElement helperForMissingMain() => commonElements.missingMain; |
1324 | 1328 |
1325 MethodElement helperForMainArity() => helpers.mainHasTooManyParameters; | 1329 MethodElement helperForMainArity() => commonElements.mainHasTooManyParameters; |
1326 | 1330 |
1327 /// Returns the filename for the output-unit named [name]. | 1331 /// Returns the filename for the output-unit named [name]. |
1328 /// | 1332 /// |
1329 /// The filename is of the form "<main output file>_<name>.part.js". | 1333 /// The filename is of the form "<main output file>_<name>.part.js". |
1330 /// If [addExtension] is false, the ".part.js" suffix is left out. | 1334 /// If [addExtension] is false, the ".part.js" suffix is left out. |
1331 String deferredPartFileName(String name, {bool addExtension: true}) { | 1335 String deferredPartFileName(String name, {bool addExtension: true}) { |
1332 assert(name != ""); | 1336 assert(name != ""); |
1333 String outPath = compiler.options.outputUri != null | 1337 String outPath = compiler.options.outputUri != null |
1334 ? compiler.options.outputUri.path | 1338 ? compiler.options.outputUri.path |
1335 : "out"; | 1339 : "out"; |
(...skipping 10 matching lines...) Expand all Loading... |
1346 /// supported by the backend. | 1350 /// supported by the backend. |
1347 bool enableCodegenWithErrorsIfSupported(Spannable node) => true; | 1351 bool enableCodegenWithErrorsIfSupported(Spannable node) => true; |
1348 | 1352 |
1349 jsAst.Expression rewriteAsync( | 1353 jsAst.Expression rewriteAsync( |
1350 FunctionElement element, jsAst.Expression code) { | 1354 FunctionElement element, jsAst.Expression code) { |
1351 AsyncRewriterBase rewriter = null; | 1355 AsyncRewriterBase rewriter = null; |
1352 jsAst.Name name = namer.methodPropertyName(element); | 1356 jsAst.Name name = namer.methodPropertyName(element); |
1353 switch (element.asyncMarker) { | 1357 switch (element.asyncMarker) { |
1354 case AsyncMarker.ASYNC: | 1358 case AsyncMarker.ASYNC: |
1355 rewriter = new AsyncRewriter(reporter, element, | 1359 rewriter = new AsyncRewriter(reporter, element, |
1356 asyncHelper: emitter.staticFunctionAccess(helpers.asyncHelper), | 1360 asyncHelper: |
1357 wrapBody: emitter.staticFunctionAccess(helpers.wrapBody), | 1361 emitter.staticFunctionAccess(commonElements.asyncHelper), |
1358 newCompleter: | 1362 wrapBody: emitter.staticFunctionAccess(commonElements.wrapBody), |
1359 emitter.staticFunctionAccess(helpers.syncCompleterConstructor), | 1363 newCompleter: emitter |
| 1364 .staticFunctionAccess(commonElements.syncCompleterConstructor), |
1360 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, | 1365 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, |
1361 bodyName: namer.deriveAsyncBodyName(name)); | 1366 bodyName: namer.deriveAsyncBodyName(name)); |
1362 break; | 1367 break; |
1363 case AsyncMarker.SYNC_STAR: | 1368 case AsyncMarker.SYNC_STAR: |
1364 rewriter = new SyncStarRewriter(reporter, element, | 1369 rewriter = new SyncStarRewriter(reporter, element, |
1365 endOfIteration: | 1370 endOfIteration: |
1366 emitter.staticFunctionAccess(helpers.endOfIteration), | 1371 emitter.staticFunctionAccess(commonElements.endOfIteration), |
1367 newIterable: emitter | 1372 newIterable: emitter.staticFunctionAccess( |
1368 .staticFunctionAccess(helpers.syncStarIterableConstructor), | 1373 commonElements.syncStarIterableConstructor), |
1369 yieldStarExpression: | 1374 yieldStarExpression: |
1370 emitter.staticFunctionAccess(helpers.yieldStar), | 1375 emitter.staticFunctionAccess(commonElements.yieldStar), |
1371 uncaughtErrorExpression: | 1376 uncaughtErrorExpression: emitter |
1372 emitter.staticFunctionAccess(helpers.syncStarUncaughtError), | 1377 .staticFunctionAccess(commonElements.syncStarUncaughtError), |
1373 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, | 1378 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, |
1374 bodyName: namer.deriveAsyncBodyName(name)); | 1379 bodyName: namer.deriveAsyncBodyName(name)); |
1375 break; | 1380 break; |
1376 case AsyncMarker.ASYNC_STAR: | 1381 case AsyncMarker.ASYNC_STAR: |
1377 rewriter = new AsyncStarRewriter(reporter, element, | 1382 rewriter = new AsyncStarRewriter(reporter, element, |
1378 asyncStarHelper: | 1383 asyncStarHelper: |
1379 emitter.staticFunctionAccess(helpers.asyncStarHelper), | 1384 emitter.staticFunctionAccess(commonElements.asyncStarHelper), |
1380 streamOfController: | 1385 streamOfController: |
1381 emitter.staticFunctionAccess(helpers.streamOfController), | 1386 emitter.staticFunctionAccess(commonElements.streamOfController), |
1382 wrapBody: emitter.staticFunctionAccess(helpers.wrapBody), | 1387 wrapBody: emitter.staticFunctionAccess(commonElements.wrapBody), |
1383 newController: emitter | 1388 newController: emitter.staticFunctionAccess( |
1384 .staticFunctionAccess(helpers.asyncStarControllerConstructor), | 1389 commonElements.asyncStarControllerConstructor), |
1385 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, | 1390 safeVariableName: namer.safeVariablePrefixForAsyncRewrite, |
1386 yieldExpression: emitter.staticFunctionAccess(helpers.yieldSingle), | 1391 yieldExpression: |
| 1392 emitter.staticFunctionAccess(commonElements.yieldSingle), |
1387 yieldStarExpression: | 1393 yieldStarExpression: |
1388 emitter.staticFunctionAccess(helpers.yieldStar), | 1394 emitter.staticFunctionAccess(commonElements.yieldStar), |
1389 bodyName: namer.deriveAsyncBodyName(name)); | 1395 bodyName: namer.deriveAsyncBodyName(name)); |
1390 break; | 1396 break; |
1391 default: | 1397 default: |
1392 assert(element.asyncMarker == AsyncMarker.SYNC); | 1398 assert(element.asyncMarker == AsyncMarker.SYNC); |
1393 return code; | 1399 return code; |
1394 } | 1400 } |
1395 return rewriter.rewrite(code); | 1401 return rewriter.rewrite(code); |
1396 } | 1402 } |
1397 | 1403 |
1398 /// Creates an impact strategy to use for compilation. | 1404 /// Creates an impact strategy to use for compilation. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 @override | 1467 @override |
1462 void onImpactUsed(ImpactUseCase impactUse) { | 1468 void onImpactUsed(ImpactUseCase impactUse) { |
1463 if (impactUse == DeferredLoadTask.IMPACT_USE && !supportSerialization) { | 1469 if (impactUse == DeferredLoadTask.IMPACT_USE && !supportSerialization) { |
1464 // TODO(johnniwinther): Allow emptying when serialization has been | 1470 // TODO(johnniwinther): Allow emptying when serialization has been |
1465 // performed. | 1471 // performed. |
1466 resolution.emptyCache(); | 1472 resolution.emptyCache(); |
1467 } | 1473 } |
1468 } | 1474 } |
1469 } | 1475 } |
1470 | 1476 |
| 1477 // TODO(efortuna): Merge with commonElements. |
1471 class JavaScriptBackendClasses implements BackendClasses { | 1478 class JavaScriptBackendClasses implements BackendClasses { |
1472 final ElementEnvironment _env; | 1479 final ElementEnvironment _env; |
1473 final BackendHelpers helpers; | 1480 final CommonElements _commonElements; |
1474 final NativeBasicData _nativeData; | 1481 final NativeBasicData _nativeData; |
1475 | 1482 |
1476 JavaScriptBackendClasses(this._env, this.helpers, this._nativeData); | 1483 JavaScriptBackendClasses(this._env, this._commonElements, this._nativeData); |
1477 | 1484 |
1478 ClassElement get intClass => helpers.jsIntClass; | 1485 ClassElement get intClass => _commonElements.jsIntClass; |
1479 ClassElement get uint32Class => helpers.jsUInt32Class; | 1486 ClassElement get uint32Class => _commonElements.jsUInt32Class; |
1480 ClassElement get uint31Class => helpers.jsUInt31Class; | 1487 ClassElement get uint31Class => _commonElements.jsUInt31Class; |
1481 ClassElement get positiveIntClass => helpers.jsPositiveIntClass; | 1488 ClassElement get positiveIntClass => _commonElements.jsPositiveIntClass; |
1482 ClassElement get doubleClass => helpers.jsDoubleClass; | 1489 ClassElement get doubleClass => _commonElements.jsDoubleClass; |
1483 ClassElement get numClass => helpers.jsNumberClass; | 1490 ClassElement get numClass => _commonElements.jsNumberClass; |
1484 ClassElement get stringClass => helpers.jsStringClass; | 1491 ClassElement get stringClass => _commonElements.jsStringClass; |
1485 ClassElement get listClass => helpers.jsArrayClass; | 1492 ClassElement get listClass => _commonElements.jsArrayClass; |
1486 ClassElement get mutableListClass => helpers.jsMutableArrayClass; | 1493 ClassElement get mutableListClass => _commonElements.jsMutableArrayClass; |
1487 ClassElement get constListClass => helpers.jsUnmodifiableArrayClass; | 1494 ClassElement get constListClass => _commonElements.jsUnmodifiableArrayClass; |
1488 ClassElement get fixedListClass => helpers.jsFixedArrayClass; | 1495 ClassElement get fixedListClass => _commonElements.jsFixedArrayClass; |
1489 ClassElement get growableListClass => helpers.jsExtendableArrayClass; | 1496 ClassElement get growableListClass => _commonElements.jsExtendableArrayClass; |
1490 ClassElement get mapClass => helpers.mapLiteralClass; | 1497 ClassElement get mapClass => _commonElements.mapLiteralClass; |
1491 ClassElement get constMapClass => helpers.constMapLiteralClass; | 1498 ClassElement get constMapClass => _commonElements.constMapLiteralClass; |
1492 ClassElement get typeClass => helpers.typeLiteralClass; | 1499 ClassElement get typeClass => _commonElements.typeLiteralClass; |
1493 InterfaceType get typeType => _env.getRawType(typeClass); | 1500 InterfaceType get typeType => _env.getRawType(typeClass); |
1494 | 1501 |
1495 ClassElement get boolClass => helpers.jsBoolClass; | 1502 ClassElement get boolClass => _commonElements.jsBoolClass; |
1496 ClassElement get nullClass => helpers.jsNullClass; | 1503 ClassElement get nullClass => _commonElements.jsNullClass; |
1497 ClassElement get syncStarIterableClass => helpers.syncStarIterable; | 1504 ClassElement get syncStarIterableClass => _commonElements.syncStarIterable; |
1498 ClassElement get asyncFutureClass => helpers.futureImplementation; | 1505 ClassElement get asyncFutureClass => _commonElements.futureImplementation; |
1499 ClassElement get asyncStarStreamClass => helpers.controllerStream; | 1506 ClassElement get asyncStarStreamClass => _commonElements.controllerStream; |
1500 ClassElement get functionClass => helpers.commonElements.functionClass; | 1507 ClassElement get functionClass => _commonElements.functionClass; |
1501 ClassElement get indexableClass => helpers.jsIndexableClass; | 1508 ClassElement get indexableClass => _commonElements.jsIndexableClass; |
1502 ClassElement get mutableIndexableClass => helpers.jsMutableIndexableClass; | 1509 ClassElement get mutableIndexableClass => |
1503 ClassElement get indexingBehaviorClass => helpers.jsIndexingBehaviorInterface; | 1510 _commonElements.jsMutableIndexableClass; |
1504 ClassElement get interceptorClass => helpers.jsInterceptorClass; | 1511 ClassElement get indexingBehaviorClass => |
| 1512 _commonElements.jsIndexingBehaviorInterface; |
| 1513 ClassElement get interceptorClass => _commonElements.jsInterceptorClass; |
1505 | 1514 |
1506 bool isDefaultEqualityImplementation(MemberElement element) { | 1515 bool isDefaultEqualityImplementation(MemberElement element) { |
1507 assert(element.name == '=='); | 1516 assert(element.name == '=='); |
1508 ClassElement classElement = element.enclosingClass; | 1517 ClassElement classElement = element.enclosingClass; |
1509 return classElement == helpers.commonElements.objectClass || | 1518 return classElement == _commonElements.objectClass || |
1510 classElement == helpers.jsInterceptorClass || | 1519 classElement == _commonElements.jsInterceptorClass || |
1511 classElement == helpers.jsNullClass; | 1520 classElement == _commonElements.jsNullClass; |
1512 } | 1521 } |
1513 | 1522 |
1514 @override | 1523 @override |
1515 bool isNativeClass(ClassEntity element) { | 1524 bool isNativeClass(ClassEntity element) { |
1516 return _nativeData.isNativeClass(element); | 1525 return _nativeData.isNativeClass(element); |
1517 } | 1526 } |
1518 | 1527 |
1519 InterfaceType getConstantMapTypeFor(InterfaceType sourceType, | 1528 InterfaceType getConstantMapTypeFor(InterfaceType sourceType, |
1520 {bool hasProtoKey: false, bool onlyStringKeys: false}) { | 1529 {bool hasProtoKey: false, bool onlyStringKeys: false}) { |
1521 ClassElement classElement = onlyStringKeys | 1530 ClassElement classElement = onlyStringKeys |
1522 ? (hasProtoKey | 1531 ? (hasProtoKey |
1523 ? helpers.constantProtoMapClass | 1532 ? _commonElements.constantProtoMapClass |
1524 : helpers.constantStringMapClass) | 1533 : _commonElements.constantStringMapClass) |
1525 : helpers.generalConstantMapClass; | 1534 : _commonElements.generalConstantMapClass; |
1526 List<DartType> typeArgument = sourceType.typeArguments; | 1535 List<DartType> typeArgument = sourceType.typeArguments; |
1527 if (sourceType.treatAsRaw) { | 1536 if (sourceType.treatAsRaw) { |
1528 return _env.getRawType(classElement); | 1537 return _env.getRawType(classElement); |
1529 } else { | 1538 } else { |
1530 return _env.createInterfaceType(classElement, typeArgument); | 1539 return _env.createInterfaceType(classElement, typeArgument); |
1531 } | 1540 } |
1532 } | 1541 } |
1533 | 1542 |
1534 @override | 1543 @override |
1535 FieldEntity get symbolField => helpers.symbolImplementationField; | 1544 FieldEntity get symbolField => _commonElements.symbolImplementationField; |
1536 | 1545 |
1537 @override | 1546 @override |
1538 InterfaceType get symbolType { | 1547 InterfaceType get symbolType { |
1539 return _env.getRawType(helpers.symbolImplementationClass); | 1548 return _env.getRawType(_commonElements.symbolImplementationClass); |
1540 } | 1549 } |
1541 } | 1550 } |
1542 | 1551 |
1543 class JavaScriptBackendTarget extends Target { | 1552 class JavaScriptBackendTarget extends Target { |
1544 final JavaScriptBackend _backend; | 1553 final JavaScriptBackend _backend; |
1545 | 1554 |
1546 JavaScriptBackendTarget(this._backend); | 1555 JavaScriptBackendTarget(this._backend); |
1547 | 1556 |
1548 @override | 1557 @override |
1549 bool isTargetSpecificLibrary(LibraryElement element) { | 1558 bool isTargetSpecificLibrary(LibraryElement element) { |
(...skipping 11 matching lines...) Expand all Loading... |
1561 } | 1570 } |
1562 | 1571 |
1563 @override | 1572 @override |
1564 dynamic resolveForeignCall(Send node, Element element, | 1573 dynamic resolveForeignCall(Send node, Element element, |
1565 CallStructure callStructure, ForeignResolver resolver) { | 1574 CallStructure callStructure, ForeignResolver resolver) { |
1566 return _backend.resolveForeignCall(node, element, callStructure, resolver); | 1575 return _backend.resolveForeignCall(node, element, callStructure, resolver); |
1567 } | 1576 } |
1568 | 1577 |
1569 @override | 1578 @override |
1570 bool isDefaultNoSuchMethod(MethodElement element) { | 1579 bool isDefaultNoSuchMethod(MethodElement element) { |
1571 return _backend.helpers.isDefaultNoSuchMethodImplementation(element); | 1580 return _backend.commonElements.isDefaultNoSuchMethodImplementation(element); |
1572 } | 1581 } |
1573 | 1582 |
1574 @override | 1583 @override |
1575 ClassElement defaultSuperclass(ClassElement element) { | 1584 ClassElement defaultSuperclass(ClassElement element) { |
1576 return _backend.defaultSuperclass(element); | 1585 return _backend.defaultSuperclass(element); |
1577 } | 1586 } |
1578 | 1587 |
1579 @override | 1588 @override |
1580 bool isNativeClass(ClassEntity element) => | 1589 bool isNativeClass(ClassEntity element) => |
1581 _backend.nativeBasicData.isNativeClass(element); | 1590 _backend.nativeBasicData.isNativeClass(element); |
(...skipping 19 matching lines...) Expand all Loading... |
1601 | 1610 |
1602 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { | 1611 bool canUseAliasedSuperMember(MemberEntity member, Selector selector) { |
1603 return !selector.isGetter; | 1612 return !selector.isGetter; |
1604 } | 1613 } |
1605 | 1614 |
1606 /// Returns `true` if [member] is called from a subclass via `super`. | 1615 /// Returns `true` if [member] is called from a subclass via `super`. |
1607 bool isAliasedSuperMember(MemberEntity member) { | 1616 bool isAliasedSuperMember(MemberEntity member) { |
1608 return _aliasedSuperMembers.contains(member); | 1617 return _aliasedSuperMembers.contains(member); |
1609 } | 1618 } |
1610 } | 1619 } |
OLD | NEW |