Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: pkg/compiler/lib/src/native/behavior.dart

Issue 2863073003: Access NativeData only through ClosedWorld (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/compiler/lib/src/kernel/element_map.dart ('k') | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 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 '../constants/values.dart'; 9 import '../constants/values.dart';
10 import '../common_elements.dart' show CommonElements; 10 import '../common_elements.dart' show CommonElements;
11 import '../elements/elements.dart'; 11 import '../elements/elements.dart';
12 import '../elements/entities.dart'; 12 import '../elements/entities.dart';
13 import '../elements/resolution_types.dart'; 13 import '../elements/resolution_types.dart';
14 import '../elements/types.dart'; 14 import '../elements/types.dart';
15 import '../js/js.dart' as js; 15 import '../js/js.dart' as js;
16 import '../js_backend/native_data.dart' show NativeData; 16 import '../js_backend/native_data.dart' show NativeBasicData;
17 import '../tree/tree.dart'; 17 import '../tree/tree.dart';
18 import '../universe/side_effects.dart' show SideEffects; 18 import '../universe/side_effects.dart' show SideEffects;
19 import '../util/util.dart'; 19 import '../util/util.dart';
20 import 'js.dart'; 20 import 'js.dart';
21 21
22 typedef dynamic /*DartType|SpecialType*/ TypeLookup(String typeString, 22 typedef dynamic /*DartType|SpecialType*/ TypeLookup(String typeString,
23 {bool required}); 23 {bool required});
24 24
25 /// This class is a temporary work-around until we get a more powerful DartType. 25 /// This class is a temporary work-around until we get a more powerful DartType.
26 class SpecialType { 26 class SpecialType {
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 MethodElement element, Compiler compiler, 768 MethodElement element, Compiler compiler,
769 {bool isJsInterop}) { 769 {bool isJsInterop}) {
770 ResolutionFunctionType type = element.computeType(compiler.resolution); 770 ResolutionFunctionType type = element.computeType(compiler.resolution);
771 List<ConstantValue> metadata = <ConstantValue>[]; 771 List<ConstantValue> metadata = <ConstantValue>[];
772 for (MetadataAnnotation annotation in element.implementation.metadata) { 772 for (MetadataAnnotation annotation in element.implementation.metadata) {
773 annotation.ensureResolved(compiler.resolution); 773 annotation.ensureResolved(compiler.resolution);
774 metadata.add(compiler.constants.getConstantValue(annotation.constant)); 774 metadata.add(compiler.constants.getConstantValue(annotation.constant));
775 } 775 }
776 776
777 BehaviorBuilder builder = 777 BehaviorBuilder builder =
778 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeData); 778 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeBasicData);
779 return builder.buildMethodBehavior( 779 return builder.buildMethodBehavior(
780 type, metadata, lookupFromElement(compiler.resolution, element), 780 type, metadata, lookupFromElement(compiler.resolution, element),
781 isJsInterop: isJsInterop); 781 isJsInterop: isJsInterop);
782 } 782 }
783 783
784 static NativeBehavior ofFieldElementLoad( 784 static NativeBehavior ofFieldElementLoad(
785 MemberElement element, Compiler compiler, 785 MemberElement element, Compiler compiler,
786 {bool isJsInterop}) { 786 {bool isJsInterop}) {
787 Resolution resolution = compiler.resolution; 787 Resolution resolution = compiler.resolution;
788 ResolutionDartType type = element.computeType(resolution); 788 ResolutionDartType type = element.computeType(resolution);
789 List<ConstantValue> metadata = <ConstantValue>[]; 789 List<ConstantValue> metadata = <ConstantValue>[];
790 for (MetadataAnnotation annotation in element.implementation.metadata) { 790 for (MetadataAnnotation annotation in element.implementation.metadata) {
791 annotation.ensureResolved(compiler.resolution); 791 annotation.ensureResolved(compiler.resolution);
792 metadata.add(compiler.constants.getConstantValue(annotation.constant)); 792 metadata.add(compiler.constants.getConstantValue(annotation.constant));
793 } 793 }
794 794
795 BehaviorBuilder builder = 795 BehaviorBuilder builder =
796 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeData); 796 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeBasicData);
797 return builder.buildFieldLoadBehavior( 797 return builder.buildFieldLoadBehavior(
798 type, metadata, lookupFromElement(resolution, element), 798 type, metadata, lookupFromElement(resolution, element),
799 isJsInterop: isJsInterop); 799 isJsInterop: isJsInterop);
800 } 800 }
801 801
802 static NativeBehavior ofFieldElementStore( 802 static NativeBehavior ofFieldElementStore(
803 MemberElement field, Compiler compiler) { 803 MemberElement field, Compiler compiler) {
804 BehaviorBuilder builder = 804 BehaviorBuilder builder =
805 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeData); 805 new ResolverBehaviorBuilder(compiler, compiler.backend.nativeBasicData);
806 ResolutionDartType type = field.computeType(compiler.resolution); 806 ResolutionDartType type = field.computeType(compiler.resolution);
807 return builder.buildFieldStoreBehavior(type); 807 return builder.buildFieldStoreBehavior(type);
808 } 808 }
809 809
810 static TypeLookup lookupFromElement(Resolution resolution, Element element) { 810 static TypeLookup lookupFromElement(Resolution resolution, Element element) {
811 ResolutionDartType lookup(String name, {bool required}) { 811 ResolutionDartType lookup(String name, {bool required}) {
812 Element e = element.buildScope().lookup(name); 812 Element e = element.buildScope().lookup(name);
813 if (e == null || e is! ClassElement) { 813 if (e == null || e is! ClassElement) {
814 if (required) { 814 if (required) {
815 resolution.reporter.reportErrorMessage(element, MessageKind.GENERIC, 815 resolution.reporter.reportErrorMessage(element, MessageKind.GENERIC,
(...skipping 26 matching lines...) Expand all
842 return type; 842 return type;
843 } 843 }
844 } 844 }
845 return const ResolutionDynamicType(); 845 return const ResolutionDynamicType();
846 } 846 }
847 } 847 }
848 848
849 abstract class BehaviorBuilder { 849 abstract class BehaviorBuilder {
850 CommonElements get commonElements; 850 CommonElements get commonElements;
851 DiagnosticReporter get reporter; 851 DiagnosticReporter get reporter;
852 NativeData get nativeData; 852 NativeBasicData get nativeBasicData;
853 bool get trustJSInteropTypeAnnotations; 853 bool get trustJSInteropTypeAnnotations;
854 854
855 Resolution get resolution => null; 855 Resolution get resolution => null;
856 856
857 NativeBehavior _behavior; 857 NativeBehavior _behavior;
858 858
859 void _overrideWithAnnotations( 859 void _overrideWithAnnotations(
860 Iterable<ConstantValue> metadata, TypeLookup lookupType) { 860 Iterable<ConstantValue> metadata, TypeLookup lookupType) {
861 if (metadata.isEmpty) return; 861 if (metadata.isEmpty) return;
862 862
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 if (type is FunctionType) { 939 if (type is FunctionType) {
940 FunctionType functionType = type; 940 FunctionType functionType = type;
941 _capture(functionType.returnType, isInterop: isInterop); 941 _capture(functionType.returnType, isInterop: isInterop);
942 for (DartType parameter in functionType.parameterTypes) { 942 for (DartType parameter in functionType.parameterTypes) {
943 _escape(parameter); 943 _escape(parameter);
944 } 944 }
945 } else { 945 } else {
946 if (!isInterop) { 946 if (!isInterop) {
947 _behavior.typesInstantiated.add(type); 947 _behavior.typesInstantiated.add(type);
948 } else { 948 } else {
949 if (type is InterfaceType && nativeData.isNativeClass(type.element)) { 949 if (type is InterfaceType &&
950 nativeBasicData.isNativeClass(type.element)) {
950 // Any declared native or interop type (isNative implies isJsInterop) 951 // Any declared native or interop type (isNative implies isJsInterop)
951 // is assumed to be allocated. 952 // is assumed to be allocated.
952 _behavior.typesInstantiated.add(type); 953 _behavior.typesInstantiated.add(type);
953 } 954 }
954 955
955 if (!trustJSInteropTypeAnnotations || 956 if (!trustJSInteropTypeAnnotations ||
956 type.isDynamic || 957 type.isDynamic ||
957 type == commonElements.objectType) { 958 type == commonElements.objectType) {
958 // By saying that only JS-interop types can be created, we prevent 959 // By saying that only JS-interop types can be created, we prevent
959 // pulling in every other native type (e.g. all of dart:html) when a 960 // 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
1027 _escape(type); 1028 _escape(type);
1028 } 1029 }
1029 1030
1030 _overrideWithAnnotations(metadata, lookupType); 1031 _overrideWithAnnotations(metadata, lookupType);
1031 return _behavior; 1032 return _behavior;
1032 } 1033 }
1033 } 1034 }
1034 1035
1035 class ResolverBehaviorBuilder extends BehaviorBuilder { 1036 class ResolverBehaviorBuilder extends BehaviorBuilder {
1036 final Compiler compiler; 1037 final Compiler compiler;
1037 final NativeData nativeData; 1038 final NativeBasicData nativeBasicData;
1038 1039
1039 ResolverBehaviorBuilder(this.compiler, this.nativeData); 1040 ResolverBehaviorBuilder(this.compiler, this.nativeBasicData);
1040 1041
1041 @override 1042 @override
1042 CommonElements get commonElements => compiler.commonElements; 1043 CommonElements get commonElements => compiler.commonElements;
1043 1044
1044 @override 1045 @override
1045 bool get trustJSInteropTypeAnnotations => 1046 bool get trustJSInteropTypeAnnotations =>
1046 compiler.options.trustJSInteropTypeAnnotations; 1047 compiler.options.trustJSInteropTypeAnnotations;
1047 1048
1048 @override 1049 @override
1049 DiagnosticReporter get reporter => compiler.reporter; 1050 DiagnosticReporter get reporter => compiler.reporter;
1050 1051
1051 @override 1052 @override
1052 Resolution get resolution => compiler.resolution; 1053 Resolution get resolution => compiler.resolution;
1053 } 1054 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/kernel/element_map.dart ('k') | pkg/compiler/lib/src/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698