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 BackendClasses, 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/js_backend.dart'; | |
19 import '../js_backend/backend_helpers.dart'; | |
20 import '../tree/tree.dart'; | 18 import '../tree/tree.dart'; |
21 import '../universe/side_effects.dart' show SideEffects; | 19 import '../universe/side_effects.dart' show SideEffects; |
22 import '../util/util.dart'; | 20 import '../util/util.dart'; |
23 import 'js.dart'; | 21 import 'js.dart'; |
24 | 22 |
25 typedef dynamic /*DartType|SpecialType*/ TypeLookup(String typeString, | 23 typedef dynamic /*DartType|SpecialType*/ TypeLookup(String typeString, |
26 {bool required}); | 24 {bool required}); |
27 | 25 |
28 /// This class is a temporary work-around until we get a more powerful DartType. | 26 /// This class is a temporary work-around until we get a more powerful DartType. |
29 class SpecialType { | 27 class SpecialType { |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 return type; | 840 return type; |
843 } | 841 } |
844 } | 842 } |
845 return const ResolutionDynamicType(); | 843 return const ResolutionDynamicType(); |
846 } | 844 } |
847 } | 845 } |
848 | 846 |
849 abstract class BehaviorBuilder { | 847 abstract class BehaviorBuilder { |
850 CommonElements get commonElements; | 848 CommonElements get commonElements; |
851 BackendClasses get backendClasses; | 849 BackendClasses get backendClasses; |
852 BackendHelpers get helpers; | |
853 DiagnosticReporter get reporter; | 850 DiagnosticReporter get reporter; |
854 ConstantEnvironment get constants; | 851 ConstantEnvironment get constants; |
855 bool get trustJSInteropTypeAnnotations; | 852 bool get trustJSInteropTypeAnnotations; |
856 | 853 |
857 Resolution get resolution => null; | 854 Resolution get resolution => null; |
858 | 855 |
859 NativeBehavior _behavior; | 856 NativeBehavior _behavior; |
860 | 857 |
861 void _overrideWithAnnotations( | 858 void _overrideWithAnnotations( |
862 Iterable<ConstantExpression> metadata, TypeLookup lookupType) { | 859 Iterable<ConstantExpression> metadata, TypeLookup lookupType) { |
863 if (metadata.isEmpty) return; | 860 if (metadata.isEmpty) return; |
864 | 861 |
865 List creates = | 862 List creates = |
866 _collect(metadata, helpers.annotationCreatesClass, lookupType); | 863 _collect(metadata, commonElements.annotationCreatesClass, lookupType); |
867 List returns = | 864 List returns = |
868 _collect(metadata, helpers.annotationReturnsClass, lookupType); | 865 _collect(metadata, commonElements.annotationReturnsClass, lookupType); |
869 | 866 |
870 if (creates != null) { | 867 if (creates != null) { |
871 _behavior.typesInstantiated | 868 _behavior.typesInstantiated |
872 ..clear() | 869 ..clear() |
873 ..addAll(creates); | 870 ..addAll(creates); |
874 } | 871 } |
875 if (returns != null) { | 872 if (returns != null) { |
876 _behavior.typesReturned | 873 _behavior.typesReturned |
877 ..clear() | 874 ..clear() |
878 ..addAll(returns); | 875 ..addAll(returns); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 | 955 |
959 if (!trustJSInteropTypeAnnotations || | 956 if (!trustJSInteropTypeAnnotations || |
960 type.isDynamic || | 957 type.isDynamic || |
961 type == commonElements.objectType) { | 958 type == commonElements.objectType) { |
962 // 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 |
963 // 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 |
964 // JS interop API returns dynamic or when we don't trust the type | 961 // JS interop API returns dynamic or when we don't trust the type |
965 // annotations. This means that to some degree we still use the return | 962 // annotations. This means that to some degree we still use the return |
966 // type to decide whether to include native types, even if we don't | 963 // type to decide whether to include native types, even if we don't |
967 // trust the type annotation. | 964 // trust the type annotation. |
968 ClassElement cls = helpers.jsJavaScriptObjectClass; | 965 ClassElement cls = commonElements.jsJavaScriptObjectClass; |
969 cls.ensureResolved(resolution); | 966 cls.ensureResolved(resolution); |
970 _behavior.typesInstantiated.add(cls.thisType); | 967 _behavior.typesInstantiated.add(cls.thisType); |
971 } else { | 968 } else { |
972 // Otherwise, when the declared type is a Dart type, we do not | 969 // Otherwise, when the declared type is a Dart type, we do not |
973 // register an allocation because we assume it cannot be instantiated | 970 // register an allocation because we assume it cannot be instantiated |
974 // from within the JS-interop code. It must have escaped from another | 971 // from within the JS-interop code. It must have escaped from another |
975 // API. | 972 // API. |
976 } | 973 } |
977 } | 974 } |
978 } | 975 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 bool get trustJSInteropTypeAnnotations => | 1045 bool get trustJSInteropTypeAnnotations => |
1049 compiler.options.trustJSInteropTypeAnnotations; | 1046 compiler.options.trustJSInteropTypeAnnotations; |
1050 | 1047 |
1051 @override | 1048 @override |
1052 ConstantEnvironment get constants => compiler.constants; | 1049 ConstantEnvironment get constants => compiler.constants; |
1053 | 1050 |
1054 @override | 1051 @override |
1055 DiagnosticReporter get reporter => compiler.reporter; | 1052 DiagnosticReporter get reporter => compiler.reporter; |
1056 | 1053 |
1057 @override | 1054 @override |
1058 BackendHelpers get helpers { | |
1059 JavaScriptBackend backend = compiler.backend; | |
1060 return backend.helpers; | |
1061 } | |
1062 | |
1063 @override | |
1064 BackendClasses get backendClasses => compiler.backend.backendClasses; | 1055 BackendClasses get backendClasses => compiler.backend.backendClasses; |
1065 | 1056 |
1066 @override | 1057 @override |
1067 Resolution get resolution => compiler.resolution; | 1058 Resolution get resolution => compiler.resolution; |
1068 } | 1059 } |
OLD | NEW |