OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 import '../common.dart'; | 5 import '../common.dart'; |
6 import '../common/backend_api.dart' show BackendClasses, ForeignResolver; | 6 import '../common/backend_api.dart' show ForeignResolver; |
7 import '../common/resolution.dart' show ParsingContext, Resolution; | 7 import '../common/resolution.dart' show ParsingContext, Resolution; |
8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
9 import '../compile_time_constants.dart' show ConstantEnvironment; | 9 import '../compile_time_constants.dart' show ConstantEnvironment; |
10 import '../constants/expressions.dart'; | 10 import '../constants/expressions.dart'; |
11 import '../constants/values.dart'; | 11 import '../constants/values.dart'; |
12 import '../common_elements.dart' show CommonElements; | 12 import '../common_elements.dart' show CommonElements; |
13 import '../elements/elements.dart'; | 13 import '../elements/elements.dart'; |
14 import '../elements/entities.dart'; | 14 import '../elements/entities.dart'; |
15 import '../elements/resolution_types.dart'; | 15 import '../elements/resolution_types.dart'; |
16 import '../elements/types.dart'; | 16 import '../elements/types.dart'; |
17 import '../js/js.dart' as js; | 17 import '../js/js.dart' as js; |
| 18 import '../js_backend/native_data.dart' show NativeData; |
18 import '../tree/tree.dart'; | 19 import '../tree/tree.dart'; |
19 import '../universe/side_effects.dart' show SideEffects; | 20 import '../universe/side_effects.dart' show SideEffects; |
20 import '../util/util.dart'; | 21 import '../util/util.dart'; |
21 import 'js.dart'; | 22 import 'js.dart'; |
22 | 23 |
23 typedef dynamic /*DartType|SpecialType*/ TypeLookup(String typeString, | 24 typedef dynamic /*DartType|SpecialType*/ TypeLookup(String typeString, |
24 {bool required}); | 25 {bool required}); |
25 | 26 |
26 /// This class is a temporary work-around until we get a more powerful DartType. | 27 /// This class is a temporary work-around until we get a more powerful DartType. |
27 class SpecialType { | 28 class SpecialType { |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 static NativeBehavior ofMethodElement( | 769 static NativeBehavior ofMethodElement( |
769 MethodElement element, Compiler compiler, | 770 MethodElement element, Compiler compiler, |
770 {bool isJsInterop}) { | 771 {bool isJsInterop}) { |
771 ResolutionFunctionType type = element.computeType(compiler.resolution); | 772 ResolutionFunctionType type = element.computeType(compiler.resolution); |
772 List<ConstantExpression> metadata = <ConstantExpression>[]; | 773 List<ConstantExpression> metadata = <ConstantExpression>[]; |
773 for (MetadataAnnotation annotation in element.implementation.metadata) { | 774 for (MetadataAnnotation annotation in element.implementation.metadata) { |
774 annotation.ensureResolved(compiler.resolution); | 775 annotation.ensureResolved(compiler.resolution); |
775 metadata.add(annotation.constant); | 776 metadata.add(annotation.constant); |
776 } | 777 } |
777 | 778 |
778 BehaviorBuilder builder = new ResolverBehaviorBuilder(compiler); | 779 BehaviorBuilder builder = |
| 780 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeData); |
779 return builder.buildMethodBehavior( | 781 return builder.buildMethodBehavior( |
780 type, metadata, lookupFromElement(compiler.resolution, element), | 782 type, metadata, lookupFromElement(compiler.resolution, element), |
781 isJsInterop: isJsInterop); | 783 isJsInterop: isJsInterop); |
782 } | 784 } |
783 | 785 |
784 static NativeBehavior ofFieldElementLoad( | 786 static NativeBehavior ofFieldElementLoad( |
785 MemberElement element, Compiler compiler, | 787 MemberElement element, Compiler compiler, |
786 {bool isJsInterop}) { | 788 {bool isJsInterop}) { |
787 Resolution resolution = compiler.resolution; | 789 Resolution resolution = compiler.resolution; |
788 ResolutionDartType type = element.computeType(resolution); | 790 ResolutionDartType type = element.computeType(resolution); |
789 List<ConstantExpression> metadata = <ConstantExpression>[]; | 791 List<ConstantExpression> metadata = <ConstantExpression>[]; |
790 for (MetadataAnnotation annotation in element.implementation.metadata) { | 792 for (MetadataAnnotation annotation in element.implementation.metadata) { |
791 annotation.ensureResolved(compiler.resolution); | 793 annotation.ensureResolved(compiler.resolution); |
792 metadata.add(annotation.constant); | 794 metadata.add(annotation.constant); |
793 } | 795 } |
794 | 796 |
795 BehaviorBuilder builder = new ResolverBehaviorBuilder(compiler); | 797 BehaviorBuilder builder = |
| 798 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeData); |
796 return builder.buildFieldLoadBehavior( | 799 return builder.buildFieldLoadBehavior( |
797 type, metadata, lookupFromElement(resolution, element), | 800 type, metadata, lookupFromElement(resolution, element), |
798 isJsInterop: isJsInterop); | 801 isJsInterop: isJsInterop); |
799 } | 802 } |
800 | 803 |
801 static NativeBehavior ofFieldElementStore( | 804 static NativeBehavior ofFieldElementStore( |
802 MemberElement field, Compiler compiler) { | 805 MemberElement field, Compiler compiler) { |
803 BehaviorBuilder builder = new ResolverBehaviorBuilder(compiler); | 806 BehaviorBuilder builder = |
| 807 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeData); |
804 ResolutionDartType type = field.computeType(compiler.resolution); | 808 ResolutionDartType type = field.computeType(compiler.resolution); |
805 return builder.buildFieldStoreBehavior(type); | 809 return builder.buildFieldStoreBehavior(type); |
806 } | 810 } |
807 | 811 |
808 static TypeLookup lookupFromElement(Resolution resolution, Element element) { | 812 static TypeLookup lookupFromElement(Resolution resolution, Element element) { |
809 ResolutionDartType lookup(String name, {bool required}) { | 813 ResolutionDartType lookup(String name, {bool required}) { |
810 Element e = element.buildScope().lookup(name); | 814 Element e = element.buildScope().lookup(name); |
811 if (e == null || e is! ClassElement) { | 815 if (e == null || e is! ClassElement) { |
812 if (required) { | 816 if (required) { |
813 resolution.reporter.reportErrorMessage(element, MessageKind.GENERIC, | 817 resolution.reporter.reportErrorMessage(element, MessageKind.GENERIC, |
(...skipping 25 matching lines...) Expand all Loading... |
839 // TODO(sra): Parse type parameters. | 843 // TODO(sra): Parse type parameters. |
840 return type; | 844 return type; |
841 } | 845 } |
842 } | 846 } |
843 return const ResolutionDynamicType(); | 847 return const ResolutionDynamicType(); |
844 } | 848 } |
845 } | 849 } |
846 | 850 |
847 abstract class BehaviorBuilder { | 851 abstract class BehaviorBuilder { |
848 CommonElements get commonElements; | 852 CommonElements get commonElements; |
849 BackendClasses get backendClasses; | |
850 DiagnosticReporter get reporter; | 853 DiagnosticReporter get reporter; |
851 ConstantEnvironment get constants; | 854 ConstantEnvironment get constants; |
| 855 NativeData get nativeData; |
852 bool get trustJSInteropTypeAnnotations; | 856 bool get trustJSInteropTypeAnnotations; |
853 | 857 |
854 Resolution get resolution => null; | 858 Resolution get resolution => null; |
855 | 859 |
856 NativeBehavior _behavior; | 860 NativeBehavior _behavior; |
857 | 861 |
858 void _overrideWithAnnotations( | 862 void _overrideWithAnnotations( |
859 Iterable<ConstantExpression> metadata, TypeLookup lookupType) { | 863 Iterable<ConstantExpression> metadata, TypeLookup lookupType) { |
860 if (metadata.isEmpty) return; | 864 if (metadata.isEmpty) return; |
861 | 865 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 if (type is FunctionType) { | 943 if (type is FunctionType) { |
940 FunctionType functionType = type; | 944 FunctionType functionType = type; |
941 _capture(functionType.returnType, isInterop: isInterop); | 945 _capture(functionType.returnType, isInterop: isInterop); |
942 for (DartType parameter in functionType.parameterTypes) { | 946 for (DartType parameter in functionType.parameterTypes) { |
943 _escape(parameter); | 947 _escape(parameter); |
944 } | 948 } |
945 } else { | 949 } else { |
946 if (!isInterop) { | 950 if (!isInterop) { |
947 _behavior.typesInstantiated.add(type); | 951 _behavior.typesInstantiated.add(type); |
948 } else { | 952 } else { |
949 if (type is InterfaceType && | 953 if (type is InterfaceType && nativeData.isNativeClass(type.element)) { |
950 backendClasses.isNativeClass(type.element)) { | |
951 // Any declared native or interop type (isNative implies isJsInterop) | 954 // Any declared native or interop type (isNative implies isJsInterop) |
952 // is assumed to be allocated. | 955 // is assumed to be allocated. |
953 _behavior.typesInstantiated.add(type); | 956 _behavior.typesInstantiated.add(type); |
954 } | 957 } |
955 | 958 |
956 if (!trustJSInteropTypeAnnotations || | 959 if (!trustJSInteropTypeAnnotations || |
957 type.isDynamic || | 960 type.isDynamic || |
958 type == commonElements.objectType) { | 961 type == commonElements.objectType) { |
959 // By saying that only JS-interop types can be created, we prevent | 962 // By saying that only JS-interop types can be created, we prevent |
960 // pulling in every other native type (e.g. all of dart:html) when a | 963 // pulling in every other native type (e.g. all of dart:html) when a |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 _escape(type); | 1031 _escape(type); |
1029 } | 1032 } |
1030 | 1033 |
1031 _overrideWithAnnotations(metadata, lookupType); | 1034 _overrideWithAnnotations(metadata, lookupType); |
1032 return _behavior; | 1035 return _behavior; |
1033 } | 1036 } |
1034 } | 1037 } |
1035 | 1038 |
1036 class ResolverBehaviorBuilder extends BehaviorBuilder { | 1039 class ResolverBehaviorBuilder extends BehaviorBuilder { |
1037 final Compiler compiler; | 1040 final Compiler compiler; |
| 1041 final NativeData nativeData; |
1038 | 1042 |
1039 ResolverBehaviorBuilder(this.compiler); | 1043 ResolverBehaviorBuilder(this.compiler, this.nativeData); |
1040 | 1044 |
1041 @override | 1045 @override |
1042 CommonElements get commonElements => compiler.commonElements; | 1046 CommonElements get commonElements => compiler.commonElements; |
1043 | 1047 |
1044 @override | 1048 @override |
1045 bool get trustJSInteropTypeAnnotations => | 1049 bool get trustJSInteropTypeAnnotations => |
1046 compiler.options.trustJSInteropTypeAnnotations; | 1050 compiler.options.trustJSInteropTypeAnnotations; |
1047 | 1051 |
1048 @override | 1052 @override |
1049 ConstantEnvironment get constants => compiler.constants; | 1053 ConstantEnvironment get constants => compiler.constants; |
1050 | 1054 |
1051 @override | 1055 @override |
1052 DiagnosticReporter get reporter => compiler.reporter; | 1056 DiagnosticReporter get reporter => compiler.reporter; |
1053 | 1057 |
1054 @override | 1058 @override |
1055 BackendClasses get backendClasses => compiler.backend.backendClasses; | |
1056 | |
1057 @override | |
1058 Resolution get resolution => compiler.resolution; | 1059 Resolution get resolution => compiler.resolution; |
1059 } | 1060 } |
OLD | NEW |