| 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 |
| 11 import '../common.dart'; | 11 import '../common.dart'; |
| 12 import '../common/backend_api.dart' | 12 import '../common/backend_api.dart' |
| 13 show BackendClasses, ForeignResolver, NativeRegistry; | 13 show BackendClasses, ForeignResolver, NativeRegistry; |
| 14 import '../common/codegen.dart' show CodegenImpact, CodegenWorkItem; | 14 import '../common/codegen.dart' show CodegenImpact, CodegenWorkItem; |
| 15 import '../common/names.dart' show Identifiers, Uris; | 15 import '../common/names.dart' show Uris; |
| 16 import '../common/resolution.dart' | 16 import '../common/resolution.dart' |
| 17 show Frontend, Resolution, ResolutionImpact, Target; | 17 show Frontend, Resolution, ResolutionImpact, Target; |
| 18 import '../common/tasks.dart' show CompilerTask; | 18 import '../common/tasks.dart' show CompilerTask; |
| 19 import '../compiler.dart' show Compiler; | 19 import '../compiler.dart' show Compiler; |
| 20 import '../constants/constant_system.dart'; | 20 import '../constants/constant_system.dart'; |
| 21 import '../constants/expressions.dart'; | 21 import '../constants/expressions.dart'; |
| 22 import '../constants/values.dart'; | 22 import '../constants/values.dart'; |
| 23 import '../common_elements.dart' show CommonElements, ElementEnvironment; | 23 import '../common_elements.dart' show CommonElements, ElementEnvironment; |
| 24 import '../deferred_load.dart' show DeferredLoadTask; | 24 import '../deferred_load.dart' show DeferredLoadTask; |
| 25 import '../dump_info.dart' show DumpInfoTask; | 25 import '../dump_info.dart' show DumpInfoTask; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 40 import '../io/start_end_information.dart' | 40 import '../io/start_end_information.dart' |
| 41 show StartEndSourceInformationStrategy; | 41 show StartEndSourceInformationStrategy; |
| 42 import '../js/js.dart' as jsAst; | 42 import '../js/js.dart' as jsAst; |
| 43 import '../js/js.dart' show js; | 43 import '../js/js.dart' show js; |
| 44 import '../js/js_source_mapping.dart' show JavaScriptSourceInformationStrategy; | 44 import '../js/js_source_mapping.dart' show JavaScriptSourceInformationStrategy; |
| 45 import '../js/rewrite_async.dart'; | 45 import '../js/rewrite_async.dart'; |
| 46 import '../js_emitter/js_emitter.dart' show CodeEmitterTask; | 46 import '../js_emitter/js_emitter.dart' show CodeEmitterTask; |
| 47 import '../kernel/task.dart'; | 47 import '../kernel/task.dart'; |
| 48 import '../library_loader.dart' show LibraryLoader, LoadedLibraries; | 48 import '../library_loader.dart' show LibraryLoader, LoadedLibraries; |
| 49 import '../native/native.dart' as native; | 49 import '../native/native.dart' as native; |
| 50 import '../options.dart' show CompilerOptions; | |
| 51 import '../patch_parser.dart' | 50 import '../patch_parser.dart' |
| 52 show checkNativeAnnotation, checkJsInteropAnnotation; | 51 show checkNativeAnnotation, checkJsInteropAnnotation; |
| 53 import '../ssa/ssa.dart' show SsaFunctionCompiler; | 52 import '../ssa/ssa.dart' show SsaFunctionCompiler; |
| 54 import '../tracer.dart'; | 53 import '../tracer.dart'; |
| 55 import '../tree/tree.dart'; | 54 import '../tree/tree.dart'; |
| 56 import '../universe/call_structure.dart' show CallStructure; | 55 import '../universe/call_structure.dart' show CallStructure; |
| 57 import '../universe/selector.dart' show Selector; | 56 import '../universe/selector.dart' show Selector; |
| 58 import '../universe/world_builder.dart'; | 57 import '../universe/world_builder.dart'; |
| 59 import '../universe/use.dart' show StaticUse, TypeUse; | 58 import '../universe/use.dart' show StaticUse, TypeUse; |
| 60 import '../universe/world_impact.dart' | 59 import '../universe/world_impact.dart' |
| (...skipping 16 matching lines...) Expand all Loading... |
| 77 import 'custom_elements_analysis.dart'; | 76 import 'custom_elements_analysis.dart'; |
| 78 import 'enqueuer.dart'; | 77 import 'enqueuer.dart'; |
| 79 import 'impact_transformer.dart'; | 78 import 'impact_transformer.dart'; |
| 80 import 'interceptor_data.dart'; | 79 import 'interceptor_data.dart'; |
| 81 import 'js_interop_analysis.dart' show JsInteropAnalysis; | 80 import 'js_interop_analysis.dart' show JsInteropAnalysis; |
| 82 import 'lookup_map_analysis.dart' | 81 import 'lookup_map_analysis.dart' |
| 83 show LookupMapLibraryAccess, LookupMapAnalysis; | 82 show LookupMapLibraryAccess, LookupMapAnalysis; |
| 84 import 'mirrors_analysis.dart'; | 83 import 'mirrors_analysis.dart'; |
| 85 import 'mirrors_data.dart'; | 84 import 'mirrors_data.dart'; |
| 86 import 'namer.dart'; | 85 import 'namer.dart'; |
| 87 import 'native_data.dart' show NativeData; | 86 import 'native_data.dart'; |
| 88 import 'no_such_method_registry.dart'; | 87 import 'no_such_method_registry.dart'; |
| 89 import 'patch_resolver.dart'; | 88 import 'patch_resolver.dart'; |
| 90 import 'resolution_listener.dart'; | 89 import 'resolution_listener.dart'; |
| 91 import 'type_variable_handler.dart'; | 90 import 'type_variable_handler.dart'; |
| 92 | 91 |
| 93 part 'runtime_types.dart'; | 92 part 'runtime_types.dart'; |
| 94 | 93 |
| 95 const VERBOSE_OPTIMIZER_HINTS = false; | 94 const VERBOSE_OPTIMIZER_HINTS = false; |
| 96 | 95 |
| 97 abstract class FunctionCompiler { | 96 abstract class FunctionCompiler { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 302 } |
| 304 } | 303 } |
| 305 | 304 |
| 306 enum SyntheticConstantKind { | 305 enum SyntheticConstantKind { |
| 307 DUMMY_INTERCEPTOR, | 306 DUMMY_INTERCEPTOR, |
| 308 EMPTY_VALUE, | 307 EMPTY_VALUE, |
| 309 TYPEVARIABLE_REFERENCE, // Reference to a type in reflection data. | 308 TYPEVARIABLE_REFERENCE, // Reference to a type in reflection data. |
| 310 NAME | 309 NAME |
| 311 } | 310 } |
| 312 | 311 |
| 313 class JavaScriptBackend extends Target { | 312 class JavaScriptBackend { |
| 314 final Compiler compiler; | 313 final Compiler compiler; |
| 315 | 314 |
| 316 String get patchVersion => emitter.patchVersion; | 315 String get patchVersion => emitter.patchVersion; |
| 317 | 316 |
| 318 /// Returns true if the backend supports reflection. | 317 /// Returns true if the backend supports reflection. |
| 319 bool get supportsReflection => emitter.supportsReflection; | 318 bool get supportsReflection => emitter.supportsReflection; |
| 320 | 319 |
| 321 final Annotations annotations; | 320 final Annotations annotations; |
| 322 | 321 |
| 323 /// Set of classes that need to be considered for reflection although not | 322 /// Set of classes that need to be considered for reflection although not |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 JavaScriptImpactTransformer impactTransformer; | 423 JavaScriptImpactTransformer impactTransformer; |
| 425 | 424 |
| 426 PatchResolverTask patchResolverTask; | 425 PatchResolverTask patchResolverTask; |
| 427 | 426 |
| 428 /// The strategy used for collecting and emitting source information. | 427 /// The strategy used for collecting and emitting source information. |
| 429 SourceInformationStrategy sourceInformationStrategy; | 428 SourceInformationStrategy sourceInformationStrategy; |
| 430 | 429 |
| 431 /// Interface for serialization of backend specific data. | 430 /// Interface for serialization of backend specific data. |
| 432 JavaScriptBackendSerialization serialization; | 431 JavaScriptBackendSerialization serialization; |
| 433 | 432 |
| 434 final NativeData nativeData = new NativeData(); | 433 final NativeDataImpl _nativeData = new NativeDataImpl(); |
| 434 NativeData get nativeData => _nativeData; |
| 435 NativeDataBuilder get nativeDataBuilder => _nativeData; |
| 435 InterceptorDataBuilder _interceptorDataBuilder; | 436 InterceptorDataBuilder _interceptorDataBuilder; |
| 436 InterceptorData _interceptorData; | 437 InterceptorData _interceptorData; |
| 437 OneShotInterceptorData _oneShotInterceptorData; | 438 OneShotInterceptorData _oneShotInterceptorData; |
| 438 BackendUsage _backendUsage; | 439 BackendUsage _backendUsage; |
| 439 BackendUsageBuilder _backendUsageBuilder; | 440 BackendUsageBuilder _backendUsageBuilder; |
| 440 MirrorsData mirrorsData; | 441 MirrorsData mirrorsData; |
| 441 CheckedModeHelpers _checkedModeHelpers; | 442 CheckedModeHelpers _checkedModeHelpers; |
| 442 | 443 |
| 443 ResolutionEnqueuerListener _resolutionEnqueuerListener; | 444 ResolutionEnqueuerListener _resolutionEnqueuerListener; |
| 444 CodegenEnqueuerListener _codegenEnqueuerListener; | 445 CodegenEnqueuerListener _codegenEnqueuerListener; |
| 445 | 446 |
| 446 BackendHelpers helpers; | 447 BackendHelpers helpers; |
| 447 BackendImpacts impacts; | 448 BackendImpacts impacts; |
| 448 | 449 |
| 449 /// Common classes used by the backend. | 450 /// Common classes used by the backend. |
| 450 BackendClasses backendClasses; | 451 BackendClasses backendClasses; |
| 451 | 452 |
| 452 /// Backend access to the front-end. | 453 /// Backend access to the front-end. |
| 453 final JSFrontendAccess frontend; | 454 final JSFrontendAccess frontend; |
| 454 | 455 |
| 456 Target _target; |
| 457 |
| 455 Tracer tracer; | 458 Tracer tracer; |
| 456 | 459 |
| 457 static SourceInformationStrategy createSourceInformationStrategy( | 460 static SourceInformationStrategy createSourceInformationStrategy( |
| 458 {bool generateSourceMap: false, | 461 {bool generateSourceMap: false, |
| 459 bool useMultiSourceInfo: false, | 462 bool useMultiSourceInfo: false, |
| 460 bool useNewSourceInfo: false}) { | 463 bool useNewSourceInfo: false}) { |
| 461 if (!generateSourceMap) return const JavaScriptSourceInformationStrategy(); | 464 if (!generateSourceMap) return const JavaScriptSourceInformationStrategy(); |
| 462 if (useMultiSourceInfo) { | 465 if (useMultiSourceInfo) { |
| 463 if (useNewSourceInfo) { | 466 if (useNewSourceInfo) { |
| 464 return const MultiSourceInformationStrategy(const [ | 467 return const MultiSourceInformationStrategy(const [ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 486 bool useKernel: false}) | 489 bool useKernel: false}) |
| 487 : _rti = new _RuntimeTypes(compiler), | 490 : _rti = new _RuntimeTypes(compiler), |
| 488 annotations = new Annotations(compiler), | 491 annotations = new Annotations(compiler), |
| 489 this.sourceInformationStrategy = createSourceInformationStrategy( | 492 this.sourceInformationStrategy = createSourceInformationStrategy( |
| 490 generateSourceMap: generateSourceMap, | 493 generateSourceMap: generateSourceMap, |
| 491 useMultiSourceInfo: useMultiSourceInfo, | 494 useMultiSourceInfo: useMultiSourceInfo, |
| 492 useNewSourceInfo: useNewSourceInfo), | 495 useNewSourceInfo: useNewSourceInfo), |
| 493 frontend = new JSFrontendAccess(compiler), | 496 frontend = new JSFrontendAccess(compiler), |
| 494 constantCompilerTask = new JavaScriptConstantTask(compiler), | 497 constantCompilerTask = new JavaScriptConstantTask(compiler), |
| 495 this.compiler = compiler { | 498 this.compiler = compiler { |
| 499 _target = new JavaScriptBackendTarget(this); |
| 496 helpers = new BackendHelpers(compiler.elementEnvironment, commonElements); | 500 helpers = new BackendHelpers(compiler.elementEnvironment, commonElements); |
| 497 impacts = new BackendImpacts(compiler.options, commonElements, helpers); | 501 impacts = new BackendImpacts(compiler.options, commonElements, helpers); |
| 498 backendClasses = new JavaScriptBackendClasses( | 502 backendClasses = new JavaScriptBackendClasses( |
| 499 compiler.elementEnvironment, helpers, nativeData); | 503 compiler.elementEnvironment, helpers, nativeData); |
| 500 mirrorsData = new MirrorsData( | 504 mirrorsData = new MirrorsData( |
| 501 compiler, compiler.options, commonElements, helpers, constants); | 505 compiler, compiler.options, commonElements, helpers, constants); |
| 502 _backendUsageBuilder = new BackendUsageBuilderImpl( | 506 _backendUsageBuilder = new BackendUsageBuilderImpl( |
| 503 compiler.elementEnvironment, commonElements, helpers); | 507 compiler.elementEnvironment, commonElements, helpers); |
| 504 _checkedModeHelpers = new CheckedModeHelpers(commonElements, helpers); | 508 _checkedModeHelpers = new CheckedModeHelpers(commonElements, helpers); |
| 505 emitter = | 509 emitter = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 /// The [ConstantSystem] used to interpret compile-time constants for this | 574 /// The [ConstantSystem] used to interpret compile-time constants for this |
| 571 /// backend. | 575 /// backend. |
| 572 ConstantSystem get constantSystem => constants.constantSystem; | 576 ConstantSystem get constantSystem => constants.constantSystem; |
| 573 | 577 |
| 574 DiagnosticReporter get reporter => compiler.reporter; | 578 DiagnosticReporter get reporter => compiler.reporter; |
| 575 | 579 |
| 576 CommonElements get commonElements => compiler.commonElements; | 580 CommonElements get commonElements => compiler.commonElements; |
| 577 | 581 |
| 578 Resolution get resolution => compiler.resolution; | 582 Resolution get resolution => compiler.resolution; |
| 579 | 583 |
| 584 Target get target => _target; |
| 585 |
| 580 InterceptorData get interceptorData { | 586 InterceptorData get interceptorData { |
| 581 assert(invariant(NO_LOCATION_SPANNABLE, _interceptorData != null, | 587 assert(invariant(NO_LOCATION_SPANNABLE, _interceptorData != null, |
| 582 message: "InterceptorData has not been computed yet.")); | 588 message: "InterceptorData has not been computed yet.")); |
| 583 return _interceptorData; | 589 return _interceptorData; |
| 584 } | 590 } |
| 585 | 591 |
| 586 OneShotInterceptorData get oneShotInterceptorData { | 592 OneShotInterceptorData get oneShotInterceptorData { |
| 587 assert(invariant(NO_LOCATION_SPANNABLE, _oneShotInterceptorData != null, | 593 assert(invariant(NO_LOCATION_SPANNABLE, _oneShotInterceptorData != null, |
| 588 message: "OneShotInterceptorData has not been prepared yet.")); | 594 message: "OneShotInterceptorData has not been prepared yet.")); |
| 589 return _oneShotInterceptorData; | 595 return _oneShotInterceptorData; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 _resolutionEnqueuerListener; | 645 _resolutionEnqueuerListener; |
| 640 | 646 |
| 641 EnqueuerListener get codegenEnqueuerListener => _codegenEnqueuerListener; | 647 EnqueuerListener get codegenEnqueuerListener => _codegenEnqueuerListener; |
| 642 | 648 |
| 643 /// Returns constant environment for the JavaScript interpretation of the | 649 /// Returns constant environment for the JavaScript interpretation of the |
| 644 /// constants. | 650 /// constants. |
| 645 JavaScriptConstantCompiler get constants { | 651 JavaScriptConstantCompiler get constants { |
| 646 return constantCompilerTask.jsConstantCompiler; | 652 return constantCompilerTask.jsConstantCompiler; |
| 647 } | 653 } |
| 648 | 654 |
| 649 @override | |
| 650 bool isDefaultNoSuchMethod(MethodElement element) { | 655 bool isDefaultNoSuchMethod(MethodElement element) { |
| 651 return noSuchMethodRegistry.isDefaultNoSuchMethodImplementation(element); | 656 return noSuchMethodRegistry.isDefaultNoSuchMethodImplementation(element); |
| 652 } | 657 } |
| 653 | 658 |
| 654 MethodElement resolveExternalFunction(MethodElement element) { | 659 MethodElement resolveExternalFunction(MethodElement element) { |
| 655 if (isForeign(element)) { | 660 if (isForeign(element)) { |
| 656 return element; | 661 return element; |
| 657 } | 662 } |
| 658 if (isJsInterop(element)) { | 663 if (nativeData.isJsInterop(element)) { |
| 659 if (element.memberName == const PublicName('[]') || | 664 if (element.memberName == const PublicName('[]') || |
| 660 element.memberName == const PublicName('[]=')) { | 665 element.memberName == const PublicName('[]=')) { |
| 661 reporter.reportErrorMessage( | 666 reporter.reportErrorMessage( |
| 662 element, MessageKind.JS_INTEROP_INDEX_NOT_SUPPORTED); | 667 element, MessageKind.JS_INTEROP_INDEX_NOT_SUPPORTED); |
| 663 } | 668 } |
| 664 return element; | 669 return element; |
| 665 } | 670 } |
| 666 return patchResolverTask.measure(() { | 671 return patchResolverTask.measure(() { |
| 667 return patchResolverTask.resolveExternalFunction(element); | 672 return patchResolverTask.resolveExternalFunction(element); |
| 668 }); | 673 }); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 return !selector.isGetter; | 727 return !selector.isGetter; |
| 723 } | 728 } |
| 724 | 729 |
| 725 /** | 730 /** |
| 726 * Returns `true` if [member] is called from a subclass via `super`. | 731 * Returns `true` if [member] is called from a subclass via `super`. |
| 727 */ | 732 */ |
| 728 bool isAliasedSuperMember(FunctionElement member) { | 733 bool isAliasedSuperMember(FunctionElement member) { |
| 729 return aliasedSuperMembers.contains(member); | 734 return aliasedSuperMembers.contains(member); |
| 730 } | 735 } |
| 731 | 736 |
| 732 /// Returns `true` if [element] is implemented via typed JavaScript interop. | 737 void resolveNativeElement(MemberElement element, NativeRegistry registry) { |
| 733 @override | |
| 734 bool isJsInterop(Element element) => nativeData.isJsInterop(element); | |
| 735 | |
| 736 /// Returns `true` if [element] is a JsInterop class. | |
| 737 bool isJsInteropClass(ClassElement element) => isJsInterop(element); | |
| 738 | |
| 739 /// Returns `true` if [element] is a JsInterop method. | |
| 740 bool isJsInteropMethod(MethodElement element) => isJsInterop(element); | |
| 741 | |
| 742 /// Whether [element] corresponds to a native JavaScript construct either | |
| 743 /// through the native mechanism (`@Native(...)` or the `native` pseudo | |
| 744 /// keyword) which is only allowed for internal libraries or via the typed | |
| 745 /// JavaScriptInterop mechanism which is allowed for user libraries. | |
| 746 @override | |
| 747 bool isNative(Entity element) => nativeData.isNative(element); | |
| 748 | |
| 749 /// Returns the [NativeBehavior] for calling the native [method]. | |
| 750 native.NativeBehavior getNativeMethodBehavior(MethodElement method) { | |
| 751 return nativeData.getNativeMethodBehavior(method); | |
| 752 } | |
| 753 | |
| 754 /// Returns the [NativeBehavior] for reading from the native [field]. | |
| 755 native.NativeBehavior getNativeFieldLoadBehavior(FieldElement field) { | |
| 756 return nativeData.getNativeFieldLoadBehavior(field); | |
| 757 } | |
| 758 | |
| 759 /// Returns the [NativeBehavior] for writing to the native [field]. | |
| 760 native.NativeBehavior getNativeFieldStoreBehavior(FieldElement field) { | |
| 761 return nativeData.getNativeFieldStoreBehavior(field); | |
| 762 } | |
| 763 | |
| 764 @override | |
| 765 void resolveNativeElement(Element element, NativeRegistry registry) { | |
| 766 if (element.isFunction || | 738 if (element.isFunction || |
| 767 element.isConstructor || | 739 element.isConstructor || |
| 768 element.isGetter || | 740 element.isGetter || |
| 769 element.isSetter) { | 741 element.isSetter) { |
| 770 compiler.enqueuer.resolution.nativeEnqueuer | 742 compiler.enqueuer.resolution.nativeEnqueuer |
| 771 .handleMethodAnnotations(element); | 743 .handleMethodAnnotations(element); |
| 772 if (isNative(element)) { | 744 if (nativeData.isNativeMember(element)) { |
| 773 native.NativeBehavior behavior = | 745 native.NativeBehavior behavior = |
| 774 native.NativeBehavior.ofMethodElement(element, compiler); | 746 native.NativeBehavior.ofMethodElement(element, compiler); |
| 775 nativeData.setNativeMethodBehavior(element, behavior); | 747 nativeDataBuilder.setNativeMethodBehavior(element, behavior); |
| 776 registry.registerNativeData(behavior); | 748 registry.registerNativeData(behavior); |
| 777 } | 749 } |
| 778 } else if (element.isField) { | 750 } else if (element.isField) { |
| 779 compiler.enqueuer.resolution.nativeEnqueuer | 751 compiler.enqueuer.resolution.nativeEnqueuer |
| 780 .handleFieldAnnotations(element); | 752 .handleFieldAnnotations(element); |
| 781 if (isNative(element)) { | 753 if (nativeData.isNativeMember(element)) { |
| 782 native.NativeBehavior fieldLoadBehavior = | 754 native.NativeBehavior fieldLoadBehavior = |
| 783 native.NativeBehavior.ofFieldElementLoad(element, compiler); | 755 native.NativeBehavior.ofFieldElementLoad(element, compiler); |
| 784 native.NativeBehavior fieldStoreBehavior = | 756 native.NativeBehavior fieldStoreBehavior = |
| 785 native.NativeBehavior.ofFieldElementStore(element, compiler); | 757 native.NativeBehavior.ofFieldElementStore(element, compiler); |
| 786 nativeData.setNativeFieldLoadBehavior(element, fieldLoadBehavior); | 758 nativeDataBuilder.setNativeFieldLoadBehavior( |
| 787 nativeData.setNativeFieldStoreBehavior(element, fieldStoreBehavior); | 759 element, fieldLoadBehavior); |
| 760 nativeDataBuilder.setNativeFieldStoreBehavior( |
| 761 element, fieldStoreBehavior); |
| 788 | 762 |
| 789 // TODO(sra): Process fields for storing separately. | 763 // TODO(sra): Process fields for storing separately. |
| 790 // We have to handle both loading and storing to the field because we | 764 // We have to handle both loading and storing to the field because we |
| 791 // only get one look at each member and there might be a load or store | 765 // only get one look at each member and there might be a load or store |
| 792 // we have not seen yet. | 766 // we have not seen yet. |
| 793 registry.registerNativeData(fieldLoadBehavior); | 767 registry.registerNativeData(fieldLoadBehavior); |
| 794 registry.registerNativeData(fieldStoreBehavior); | 768 registry.registerNativeData(fieldStoreBehavior); |
| 795 } | 769 } |
| 796 } | 770 } |
| 797 } | 771 } |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1043 |
| 1070 native.NativeEnqueuer nativeResolutionEnqueuer() { | 1044 native.NativeEnqueuer nativeResolutionEnqueuer() { |
| 1071 return new native.NativeResolutionEnqueuer(compiler); | 1045 return new native.NativeResolutionEnqueuer(compiler); |
| 1072 } | 1046 } |
| 1073 | 1047 |
| 1074 native.NativeEnqueuer nativeCodegenEnqueuer() { | 1048 native.NativeEnqueuer nativeCodegenEnqueuer() { |
| 1075 return new native.NativeCodegenEnqueuer(compiler, emitter); | 1049 return new native.NativeCodegenEnqueuer(compiler, emitter); |
| 1076 } | 1050 } |
| 1077 | 1051 |
| 1078 ClassElement defaultSuperclass(ClassElement element) { | 1052 ClassElement defaultSuperclass(ClassElement element) { |
| 1079 if (isJsInterop(element)) { | 1053 if (nativeData.isJsInterop(element)) { |
| 1080 return helpers.jsJavaScriptObjectClass; | 1054 return helpers.jsJavaScriptObjectClass; |
| 1081 } | 1055 } |
| 1082 // Native classes inherit from Interceptor. | 1056 // Native classes inherit from Interceptor. |
| 1083 return isNative(element) | 1057 return nativeData.isNativeClass(element) |
| 1084 ? helpers.jsInterceptorClass | 1058 ? helpers.jsInterceptorClass |
| 1085 : commonElements.objectClass; | 1059 : commonElements.objectClass; |
| 1086 } | 1060 } |
| 1087 | 1061 |
| 1088 /** | 1062 /** |
| 1089 * Unit test hook that returns code of an element as a String. | 1063 * Unit test hook that returns code of an element as a String. |
| 1090 * | 1064 * |
| 1091 * Invariant: [element] must be a declaration element. | 1065 * Invariant: [element] must be a declaration element. |
| 1092 */ | 1066 */ |
| 1093 String getGeneratedCode(Element element) { | 1067 String getGeneratedCode(Element element) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1172 if (canLibraryUseNative(library)) { | 1146 if (canLibraryUseNative(library)) { |
| 1173 library.forEachLocalMember((Element element) { | 1147 library.forEachLocalMember((Element element) { |
| 1174 if (element.isClass) { | 1148 if (element.isClass) { |
| 1175 checkNativeAnnotation(compiler, element); | 1149 checkNativeAnnotation(compiler, element); |
| 1176 } | 1150 } |
| 1177 }); | 1151 }); |
| 1178 } | 1152 } |
| 1179 checkJsInteropAnnotation(compiler, library); | 1153 checkJsInteropAnnotation(compiler, library); |
| 1180 library.forEachLocalMember((Element element) { | 1154 library.forEachLocalMember((Element element) { |
| 1181 checkJsInteropAnnotation(compiler, element); | 1155 checkJsInteropAnnotation(compiler, element); |
| 1182 if (element.isClass && isJsInterop(element)) { | 1156 if (element.isClass && nativeData.isJsInterop(element)) { |
| 1183 ClassElement classElement = element; | 1157 ClassElement classElement = element; |
| 1184 classElement.forEachMember((_, memberElement) { | 1158 classElement.forEachMember((_, memberElement) { |
| 1185 checkJsInteropAnnotation(compiler, memberElement); | 1159 checkJsInteropAnnotation(compiler, memberElement); |
| 1186 }); | 1160 }); |
| 1187 } | 1161 } |
| 1188 }); | 1162 }); |
| 1189 } | 1163 } |
| 1190 if (library.isPlatformLibrary && | 1164 if (library.isPlatformLibrary && |
| 1191 // Don't patch library currently disallowed. | 1165 // Don't patch library currently disallowed. |
| 1192 !library.isSynthesized && | 1166 !library.isSynthesized && |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 } | 1268 } |
| 1295 | 1269 |
| 1296 // Does this element belong in the output | 1270 // Does this element belong in the output |
| 1297 bool shouldOutput(Element element) => true; | 1271 bool shouldOutput(Element element) => true; |
| 1298 | 1272 |
| 1299 /// Returns `true` if the `native` pseudo keyword is supported for [library]. | 1273 /// Returns `true` if the `native` pseudo keyword is supported for [library]. |
| 1300 bool canLibraryUseNative(LibraryElement library) { | 1274 bool canLibraryUseNative(LibraryElement library) { |
| 1301 return native.maybeEnableNative(compiler, library); | 1275 return native.maybeEnableNative(compiler, library); |
| 1302 } | 1276 } |
| 1303 | 1277 |
| 1304 @override | |
| 1305 bool isTargetSpecificLibrary(LibraryElement library) { | 1278 bool isTargetSpecificLibrary(LibraryElement library) { |
| 1306 Uri canonicalUri = library.canonicalUri; | 1279 Uri canonicalUri = library.canonicalUri; |
| 1307 if (canonicalUri == BackendHelpers.DART_JS_HELPER || | 1280 if (canonicalUri == BackendHelpers.DART_JS_HELPER || |
| 1308 canonicalUri == BackendHelpers.DART_INTERCEPTORS) { | 1281 canonicalUri == BackendHelpers.DART_INTERCEPTORS) { |
| 1309 return true; | 1282 return true; |
| 1310 } | 1283 } |
| 1311 return false; | 1284 return false; |
| 1312 } | 1285 } |
| 1313 | 1286 |
| 1314 /// Process backend specific annotations. | 1287 /// Process backend specific annotations. |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1603 | 1576 |
| 1604 bool isDefaultEqualityImplementation(MemberElement element) { | 1577 bool isDefaultEqualityImplementation(MemberElement element) { |
| 1605 assert(element.name == '=='); | 1578 assert(element.name == '=='); |
| 1606 ClassElement classElement = element.enclosingClass; | 1579 ClassElement classElement = element.enclosingClass; |
| 1607 return classElement == helpers.commonElements.objectClass || | 1580 return classElement == helpers.commonElements.objectClass || |
| 1608 classElement == helpers.jsInterceptorClass || | 1581 classElement == helpers.jsInterceptorClass || |
| 1609 classElement == helpers.jsNullClass; | 1582 classElement == helpers.jsNullClass; |
| 1610 } | 1583 } |
| 1611 | 1584 |
| 1612 @override | 1585 @override |
| 1613 bool isNativeClass(ClassElement element) { | 1586 bool isNativeClass(ClassEntity element) { |
| 1614 return _nativeData.isNative(element); | 1587 return _nativeData.isNativeClass(element); |
| 1615 } | 1588 } |
| 1616 | 1589 |
| 1617 @override | 1590 @override |
| 1618 bool isNativeMember(MemberElement element) { | 1591 bool isNativeMember(MemberEntity element) { |
| 1619 return _nativeData.isNative(element); | 1592 return _nativeData.isNativeMember(element); |
| 1620 } | 1593 } |
| 1621 | 1594 |
| 1622 InterfaceType getConstantMapTypeFor(InterfaceType sourceType, | 1595 InterfaceType getConstantMapTypeFor(InterfaceType sourceType, |
| 1623 {bool hasProtoKey: false, bool onlyStringKeys: false}) { | 1596 {bool hasProtoKey: false, bool onlyStringKeys: false}) { |
| 1624 ClassElement classElement = onlyStringKeys | 1597 ClassElement classElement = onlyStringKeys |
| 1625 ? (hasProtoKey | 1598 ? (hasProtoKey |
| 1626 ? helpers.constantProtoMapClass | 1599 ? helpers.constantProtoMapClass |
| 1627 : helpers.constantStringMapClass) | 1600 : helpers.constantStringMapClass) |
| 1628 : helpers.generalConstantMapClass; | 1601 : helpers.generalConstantMapClass; |
| 1629 List<DartType> typeArgument = sourceType.typeArguments; | 1602 List<DartType> typeArgument = sourceType.typeArguments; |
| 1630 if (sourceType.treatAsRaw) { | 1603 if (sourceType.treatAsRaw) { |
| 1631 return _env.getRawType(classElement); | 1604 return _env.getRawType(classElement); |
| 1632 } else { | 1605 } else { |
| 1633 return _env.createInterfaceType(classElement, typeArgument); | 1606 return _env.createInterfaceType(classElement, typeArgument); |
| 1634 } | 1607 } |
| 1635 } | 1608 } |
| 1636 | 1609 |
| 1637 @override | 1610 @override |
| 1638 FieldEntity get symbolField => helpers.symbolImplementationField; | 1611 FieldEntity get symbolField => helpers.symbolImplementationField; |
| 1639 | 1612 |
| 1640 @override | 1613 @override |
| 1641 InterfaceType get symbolType { | 1614 InterfaceType get symbolType { |
| 1642 return _env.getRawType(helpers.symbolImplementationClass); | 1615 return _env.getRawType(helpers.symbolImplementationClass); |
| 1643 } | 1616 } |
| 1644 } | 1617 } |
| 1618 |
| 1619 class JavaScriptBackendTarget extends Target { |
| 1620 final JavaScriptBackend _backend; |
| 1621 |
| 1622 JavaScriptBackendTarget(this._backend); |
| 1623 |
| 1624 @override |
| 1625 bool isTargetSpecificLibrary(LibraryElement element) { |
| 1626 return _backend.isTargetSpecificLibrary(element); |
| 1627 } |
| 1628 |
| 1629 @override |
| 1630 void resolveNativeElement(MemberElement element, NativeRegistry registry) { |
| 1631 return _backend.resolveNativeElement(element, registry); |
| 1632 } |
| 1633 |
| 1634 @override |
| 1635 MethodElement resolveExternalFunction(MethodElement element) { |
| 1636 return _backend.resolveExternalFunction(element); |
| 1637 } |
| 1638 |
| 1639 @override |
| 1640 dynamic resolveForeignCall(Send node, Element element, |
| 1641 CallStructure callStructure, ForeignResolver resolver) { |
| 1642 return _backend.resolveForeignCall(node, element, callStructure, resolver); |
| 1643 } |
| 1644 |
| 1645 @override |
| 1646 bool isDefaultNoSuchMethod(MethodElement element) { |
| 1647 return _backend.isDefaultNoSuchMethod(element); |
| 1648 } |
| 1649 |
| 1650 @override |
| 1651 ClassElement defaultSuperclass(ClassElement element) { |
| 1652 return _backend.defaultSuperclass(element); |
| 1653 } |
| 1654 |
| 1655 @override |
| 1656 bool isNativeClass(ClassEntity element) => |
| 1657 _backend.nativeData.isNativeClass(element); |
| 1658 |
| 1659 @override |
| 1660 bool isForeign(Element element) => _backend.isForeign(element); |
| 1661 } |
| OLD | NEW |