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 dart2js.backend_api; | 5 library dart2js.backend_api; |
6 | 6 |
7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common/codegen.dart' show CodegenImpact; | 10 import '../common/codegen.dart' show CodegenImpact; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 /// Set of classes that need to be considered for reflection although not | 76 /// Set of classes that need to be considered for reflection although not |
77 /// otherwise visible during resolution. | 77 /// otherwise visible during resolution. |
78 Iterable<ClassElement> classesRequiredForReflection = const []; | 78 Iterable<ClassElement> classesRequiredForReflection = const []; |
79 | 79 |
80 // Given a [FunctionElement], return a buffer with the code generated for it | 80 // Given a [FunctionElement], return a buffer with the code generated for it |
81 // or null if no code was generated. | 81 // or null if no code was generated. |
82 CodeBuffer codeOf(Element element) => null; | 82 CodeBuffer codeOf(Element element) => null; |
83 | 83 |
84 void initializeHelperClasses() {} | 84 void initializeHelperClasses() {} |
85 | 85 |
86 void enqueueHelpers(ResolutionEnqueuer world, Registry registry); | 86 void enqueueHelpers(ResolutionEnqueuer world); |
87 | 87 |
88 /// Creates an [Enqueuer] for code generation specific to this backend. | 88 /// Creates an [Enqueuer] for code generation specific to this backend. |
89 Enqueuer createCodegenEnqueuer(Compiler compiler); | 89 Enqueuer createCodegenEnqueuer(Compiler compiler); |
90 | 90 |
91 WorldImpact codegen(CodegenWorkItem work); | 91 WorldImpact codegen(CodegenWorkItem work); |
92 | 92 |
93 // The backend determines the native resolution enqueuer, with a no-op | 93 // The backend determines the native resolution enqueuer, with a no-op |
94 // default, so tools like dart2dart can ignore the native classes. | 94 // default, so tools like dart2dart can ignore the native classes. |
95 native.NativeEnqueuer nativeResolutionEnqueuer(world) { | 95 native.NativeEnqueuer nativeResolutionEnqueuer(world) { |
96 return new native.NativeEnqueuer(); | 96 return new native.NativeEnqueuer(); |
(...skipping 13 matching lines...) Expand all Loading... |
110 | 110 |
111 bool classNeedsRti(ClassElement cls); | 111 bool classNeedsRti(ClassElement cls); |
112 bool methodNeedsRti(FunctionElement function); | 112 bool methodNeedsRti(FunctionElement function); |
113 | 113 |
114 /// Enable compilation of code with compile time errors. Returns `true` if | 114 /// Enable compilation of code with compile time errors. Returns `true` if |
115 /// supported by the backend. | 115 /// supported by the backend. |
116 bool enableCodegenWithErrorsIfSupported(Spannable node); | 116 bool enableCodegenWithErrorsIfSupported(Spannable node); |
117 | 117 |
118 /// Enable deferred loading. Returns `true` if the backend supports deferred | 118 /// Enable deferred loading. Returns `true` if the backend supports deferred |
119 /// loading. | 119 /// loading. |
120 bool enableDeferredLoadingIfSupported(Spannable node, Registry registry); | 120 bool enableDeferredLoadingIfSupported( |
| 121 ResolutionEnqueuer enqueuer, Spannable node); |
121 | 122 |
122 /// Called during codegen when [constant] has been used. | 123 /// Called during codegen when [constant] has been used. |
123 void computeImpactForCompileTimeConstant(ConstantValue constant, | 124 void computeImpactForCompileTimeConstant(ConstantValue constant, |
124 WorldImpactBuilder impactBuilder, bool isForResolution) {} | 125 WorldImpactBuilder impactBuilder, bool isForResolution) {} |
125 | 126 |
126 /// Called to notify to the backend that a class is being instantiated. | 127 /// Called to notify to the backend that a class is being instantiated. |
127 // TODO(johnniwinther): Remove this. It's only called once for each [cls] and | 128 // TODO(johnniwinther): Remove this. It's only called once for each [cls] and |
128 // only with [Compiler.globalDependencies] as [registry]. | 129 // only with [Compiler.globalDependencies] as [registry]. |
129 void registerInstantiatedClass( | 130 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} |
130 ClassElement cls, Enqueuer enqueuer, Registry registry) {} | |
131 | 131 |
132 /// Called to notify to the backend that a class is implemented by an | 132 /// Called to notify to the backend that a class is implemented by an |
133 /// instantiated class. | 133 /// instantiated class. |
134 void registerImplementedClass( | 134 void registerImplementedClass(ClassElement cls, Enqueuer enqueuer) {} |
135 ClassElement cls, Enqueuer enqueuer, Registry registry) {} | |
136 | 135 |
137 /// Called to instruct to the backend register [type] as instantiated on | 136 /// Called to instruct to the backend register [type] as instantiated on |
138 /// [enqueuer]. | 137 /// [enqueuer]. |
139 void registerInstantiatedType( | 138 void registerInstantiatedType(InterfaceType type) {} |
140 InterfaceType type, Enqueuer enqueuer, Registry registry, | |
141 {bool mirrorUsage: false}) { | |
142 registry.registerDependency(type.element); | |
143 enqueuer.registerInstantiatedType(type, mirrorUsage: mirrorUsage); | |
144 } | |
145 | 139 |
146 /// Register a runtime type variable bound tests between [typeArgument] and | 140 /// Register a runtime type variable bound tests between [typeArgument] and |
147 /// [bound]. | 141 /// [bound]. |
148 void registerTypeVariableBoundsSubtypeCheck( | 142 void registerTypeVariableBoundsSubtypeCheck( |
149 DartType typeArgument, DartType bound) {} | 143 DartType typeArgument, DartType bound) {} |
150 | 144 |
151 /** | 145 /** |
152 * Call this to register that an instantiated generic class has a call | 146 * Call this to register that an instantiated generic class has a call |
153 * method. | 147 * method. |
154 */ | 148 */ |
155 void registerCallMethodWithFreeTypeVariables( | 149 void registerCallMethodWithFreeTypeVariables( |
156 Element callMethod, Enqueuer enqueuer, Registry registry) {} | 150 Element callMethod, Enqueuer enqueuer) {} |
157 | 151 |
158 /// Called to instruct the backend to register that a closure exists for a | 152 /// Called to instruct the backend to register that a closure exists for a |
159 /// function on an instantiated generic class. | 153 /// function on an instantiated generic class. |
160 void registerClosureWithFreeTypeVariables( | 154 void registerClosureWithFreeTypeVariables( |
161 Element closure, Enqueuer enqueuer, Registry registry) {} | 155 Element closure, Enqueuer enqueuer) {} |
162 | 156 |
163 /// Call this to register that a member has been closurized. | 157 /// Call this to register that a member has been closurized. |
164 void registerBoundClosure(Enqueuer enqueuer) {} | 158 void registerBoundClosure(Enqueuer enqueuer) {} |
165 | 159 |
166 /// Call this to register that a static function has been closurized. | 160 /// Call this to register that a static function has been closurized. |
167 void registerGetOfStaticFunction(Enqueuer enqueuer) {} | 161 void registerGetOfStaticFunction(Enqueuer enqueuer) {} |
168 | 162 |
169 /** | 163 /** |
170 * Call this to register that the [:runtimeType:] property has been accessed. | 164 * Call this to register that the [:runtimeType:] property has been accessed. |
171 */ | 165 */ |
172 void registerRuntimeType(Enqueuer enqueuer, Registry registry) {} | 166 void registerRuntimeType(Enqueuer enqueuer) {} |
173 | 167 |
174 /// Call this to register a `noSuchMethod` implementation. | 168 /// Call this to register a `noSuchMethod` implementation. |
175 void registerNoSuchMethod(FunctionElement noSuchMethodElement) {} | 169 void registerNoSuchMethod(FunctionElement noSuchMethodElement) {} |
176 | 170 |
177 /// Call this method to enable support for `noSuchMethod`. | 171 /// Call this method to enable support for `noSuchMethod`. |
178 void enableNoSuchMethod(Enqueuer enqueuer) {} | 172 void enableNoSuchMethod(Enqueuer enqueuer) {} |
179 | 173 |
180 /// Returns whether or not `noSuchMethod` support has been enabled. | 174 /// Returns whether or not `noSuchMethod` support has been enabled. |
181 bool get enabledNoSuchMethod => false; | 175 bool get enabledNoSuchMethod => false; |
182 | 176 |
(...skipping 23 matching lines...) Expand all Loading... |
206 // TODO(johnniwinther): Remove this when patching is only done by the | 200 // TODO(johnniwinther): Remove this when patching is only done by the |
207 // JavaScript backend. | 201 // JavaScript backend. |
208 Uri canonicalUri = library.canonicalUri; | 202 Uri canonicalUri = library.canonicalUri; |
209 if (canonicalUri == js_backend.BackendHelpers.DART_JS_HELPER || | 203 if (canonicalUri == js_backend.BackendHelpers.DART_JS_HELPER || |
210 canonicalUri == js_backend.BackendHelpers.DART_INTERCEPTORS) { | 204 canonicalUri == js_backend.BackendHelpers.DART_INTERCEPTORS) { |
211 return true; | 205 return true; |
212 } | 206 } |
213 return false; | 207 return false; |
214 } | 208 } |
215 | 209 |
216 void registerStaticUse(Element element, {bool forResolution}) {} | 210 void registerStaticUse(Enqueuer enqueuer, Element element) {} |
217 | 211 |
218 /// This method is called immediately after the [LibraryElement] [library] has | 212 /// This method is called immediately after the [LibraryElement] [library] has |
219 /// been created. | 213 /// been created. |
220 void onLibraryCreated(LibraryElement library) {} | 214 void onLibraryCreated(LibraryElement library) {} |
221 | 215 |
222 /// This method is called immediately after the [library] and its parts have | 216 /// This method is called immediately after the [library] and its parts have |
223 /// been scanned. | 217 /// been scanned. |
224 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { | 218 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { |
225 // TODO(johnniwinther): Move this to [JavaScriptBackend]. | 219 // TODO(johnniwinther): Move this to [JavaScriptBackend]. |
226 if (!compiler.serialization.isDeserialized(library)) { | 220 if (!compiler.serialization.isDeserialized(library)) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 void registerInstantiatedType(InterfaceType type); | 355 void registerInstantiatedType(InterfaceType type); |
362 | 356 |
363 /// Resolves [typeName] to a type in the context of [node]. | 357 /// Resolves [typeName] to a type in the context of [node]. |
364 DartType resolveTypeFromString(Node node, String typeName); | 358 DartType resolveTypeFromString(Node node, String typeName); |
365 } | 359 } |
366 | 360 |
367 /// Backend transformation methods for the world impacts. | 361 /// Backend transformation methods for the world impacts. |
368 class ImpactTransformer { | 362 class ImpactTransformer { |
369 /// Transform the [ResolutionImpact] into a [WorldImpact] adding the | 363 /// Transform the [ResolutionImpact] into a [WorldImpact] adding the |
370 /// backend dependencies for features used in [worldImpact]. | 364 /// backend dependencies for features used in [worldImpact]. |
371 WorldImpact transformResolutionImpact(ResolutionImpact worldImpact) { | 365 WorldImpact transformResolutionImpact( |
| 366 ResolutionEnqueuer enqueuer, ResolutionImpact worldImpact) { |
372 return worldImpact; | 367 return worldImpact; |
373 } | 368 } |
374 | 369 |
375 /// Transform the [CodegenImpact] into a [WorldImpact] adding the | 370 /// Transform the [CodegenImpact] into a [WorldImpact] adding the |
376 /// backend dependencies for features used in [worldImpact]. | 371 /// backend dependencies for features used in [worldImpact]. |
377 WorldImpact transformCodegenImpact(CodegenImpact worldImpact) { | 372 WorldImpact transformCodegenImpact(CodegenImpact worldImpact) { |
378 return worldImpact; | 373 return worldImpact; |
379 } | 374 } |
380 } | 375 } |
381 | 376 |
(...skipping 21 matching lines...) Expand all Loading... |
403 ClassElement get typeImplementation; | 398 ClassElement get typeImplementation; |
404 ClassElement get boolImplementation; | 399 ClassElement get boolImplementation; |
405 ClassElement get nullImplementation; | 400 ClassElement get nullImplementation; |
406 ClassElement get uint32Implementation; | 401 ClassElement get uint32Implementation; |
407 ClassElement get uint31Implementation; | 402 ClassElement get uint31Implementation; |
408 ClassElement get positiveIntImplementation; | 403 ClassElement get positiveIntImplementation; |
409 ClassElement get syncStarIterableImplementation; | 404 ClassElement get syncStarIterableImplementation; |
410 ClassElement get asyncFutureImplementation; | 405 ClassElement get asyncFutureImplementation; |
411 ClassElement get asyncStarStreamImplementation; | 406 ClassElement get asyncStarStreamImplementation; |
412 } | 407 } |
OLD | NEW |