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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 /// Set of classes that need to be considered for reflection although not | 75 /// Set of classes that need to be considered for reflection although not |
76 /// otherwise visible during resolution. | 76 /// otherwise visible during resolution. |
77 Iterable<ClassElement> classesRequiredForReflection = const []; | 77 Iterable<ClassElement> classesRequiredForReflection = const []; |
78 | 78 |
79 // Given a [FunctionElement], return a buffer with the code generated for it | 79 // Given a [FunctionElement], return a buffer with the code generated for it |
80 // or null if no code was generated. | 80 // or null if no code was generated. |
81 CodeBuffer codeOf(Element element) => null; | 81 CodeBuffer codeOf(Element element) => null; |
82 | 82 |
83 void initializeHelperClasses() {} | 83 void initializeHelperClasses() {} |
84 | 84 |
85 void enqueueHelpers(ResolutionEnqueuer world); | 85 /// Compute the [WorldImpact] for backend helper methods. |
| 86 WorldImpact computeHelpersImpact(); |
86 | 87 |
87 /// Creates an [Enqueuer] for code generation specific to this backend. | 88 /// Creates an [Enqueuer] for code generation specific to this backend. |
88 Enqueuer createCodegenEnqueuer(CompilerTask task, Compiler compiler); | 89 Enqueuer createCodegenEnqueuer(CompilerTask task, Compiler compiler); |
89 | 90 |
90 WorldImpact codegen(CodegenWorkItem work); | 91 WorldImpact codegen(CodegenWorkItem work); |
91 | 92 |
92 // The backend determines the native resolution enqueuer, with a no-op | 93 // The backend determines the native resolution enqueuer, with a no-op |
93 // default, so tools like dart2dart can ignore the native classes. | 94 // default, so tools like dart2dart can ignore the native classes. |
94 native.NativeEnqueuer nativeResolutionEnqueuer() { | 95 native.NativeEnqueuer nativeResolutionEnqueuer() { |
95 return new native.NativeEnqueuer(); | 96 return new native.NativeEnqueuer(); |
(...skipping 13 matching lines...) Expand all Loading... |
109 | 110 |
110 bool classNeedsRti(ClassElement cls); | 111 bool classNeedsRti(ClassElement cls); |
111 bool methodNeedsRti(FunctionElement function); | 112 bool methodNeedsRti(FunctionElement function); |
112 | 113 |
113 /// Enable compilation of code with compile time errors. Returns `true` if | 114 /// Enable compilation of code with compile time errors. Returns `true` if |
114 /// supported by the backend. | 115 /// supported by the backend. |
115 bool enableCodegenWithErrorsIfSupported(Spannable node); | 116 bool enableCodegenWithErrorsIfSupported(Spannable node); |
116 | 117 |
117 /// Enable deferred loading. Returns `true` if the backend supports deferred | 118 /// Enable deferred loading. Returns `true` if the backend supports deferred |
118 /// loading. | 119 /// loading. |
119 bool enableDeferredLoadingIfSupported( | 120 bool enableDeferredLoadingIfSupported(Spannable node); |
120 ResolutionEnqueuer enqueuer, Spannable node); | 121 |
| 122 /// Returns the [WorldImpact] of enabling deferred loading. |
| 123 WorldImpact computeDeferredLoadingImpact() => const WorldImpact(); |
121 | 124 |
122 /// Called during codegen when [constant] has been used. | 125 /// Called during codegen when [constant] has been used. |
123 void computeImpactForCompileTimeConstant(ConstantValue constant, | 126 void computeImpactForCompileTimeConstant(ConstantValue constant, |
124 WorldImpactBuilder impactBuilder, bool isForResolution) {} | 127 WorldImpactBuilder impactBuilder, bool isForResolution) {} |
125 | 128 |
126 /// Called to notify to the backend that a class is being instantiated. | 129 /// Called to notify to the backend that a class is being instantiated. Any |
127 // TODO(johnniwinther): Remove this. It's only called once for each [cls] and | 130 /// backend specific [WorldImpact] of this is returned. |
128 // only with [Compiler.globalDependencies] as [registry]. | 131 WorldImpact registerInstantiatedClass(ClassElement cls, |
129 void registerInstantiatedClass(ClassElement cls, Enqueuer enqueuer) {} | 132 {bool forResolution}) => |
| 133 const WorldImpact(); |
130 | 134 |
131 /// Called to notify to the backend that a class is implemented by an | 135 /// Called to notify to the backend that a class is implemented by an |
132 /// instantiated class. | 136 /// instantiated class. Any backend specific [WorldImpact] of this is |
133 void registerImplementedClass(ClassElement cls, Enqueuer enqueuer) {} | 137 /// returned. |
| 138 WorldImpact registerImplementedClass(ClassElement cls, |
| 139 {bool forResolution}) => |
| 140 const WorldImpact(); |
134 | 141 |
135 /// Called to instruct to the backend register [type] as instantiated on | 142 /// Called to instruct to the backend register [type] as instantiated on |
136 /// [enqueuer]. | 143 /// [enqueuer]. |
137 void registerInstantiatedType(InterfaceType type) {} | 144 void registerInstantiatedType(InterfaceType type) {} |
138 | 145 |
139 /// Register a runtime type variable bound tests between [typeArgument] and | 146 /// Register a runtime type variable bound tests between [typeArgument] and |
140 /// [bound]. | 147 /// [bound]. |
141 void registerTypeVariableBoundsSubtypeCheck( | 148 void registerTypeVariableBoundsSubtypeCheck( |
142 DartType typeArgument, DartType bound) {} | 149 DartType typeArgument, DartType bound) {} |
143 | 150 |
144 /** | 151 /// Called to register that an instantiated generic class has a call method. |
145 * Call this to register that an instantiated generic class has a call | 152 /// Any backend specific [WorldImpact] of this is returned. |
146 * method. | 153 /// |
147 */ | 154 /// Note: The [callMethod] is registered even thought it doesn't reference |
148 void registerCallMethodWithFreeTypeVariables( | 155 /// the type variables. |
149 Element callMethod, Enqueuer enqueuer) {} | 156 WorldImpact registerCallMethodWithFreeTypeVariables(Element callMethod, |
| 157 {bool forResolution}) => |
| 158 const WorldImpact(); |
150 | 159 |
151 /// Called to instruct the backend to register that a closure exists for a | 160 /// Called to instruct the backend to register that a closure exists for a |
152 /// function on an instantiated generic class. | 161 /// function on an instantiated generic class. Any backend specific |
153 void registerClosureWithFreeTypeVariables( | 162 /// [WorldImpact] of this is returned. |
154 Element closure, Enqueuer enqueuer) {} | 163 WorldImpact registerClosureWithFreeTypeVariables(Element closure, |
| 164 {bool forResolution}) => |
| 165 const WorldImpact(); |
155 | 166 |
156 /// Call this to register that a member has been closurized. | 167 /// Called to register that a member has been closurized. Any backend specific |
157 void registerBoundClosure(Enqueuer enqueuer) {} | 168 /// [WorldImpact] of this is returned. |
| 169 WorldImpact registerBoundClosure() => const WorldImpact(); |
158 | 170 |
159 /// Call this to register that a static function has been closurized. | 171 /// Called to register that a static function has been closurized. Any backend |
160 void registerGetOfStaticFunction(Enqueuer enqueuer) {} | 172 /// specific [WorldImpact] of this is returned. |
| 173 WorldImpact registerGetOfStaticFunction() => const WorldImpact(); |
161 | 174 |
162 /** | 175 /// Called to register that the `runtimeType` property has been accessed. Any |
163 * Call this to register that the [:runtimeType:] property has been accessed. | 176 /// backend specific [WorldImpact] of this is returned. |
164 */ | 177 WorldImpact registerRuntimeType() => const WorldImpact(); |
165 void registerRuntimeType(Enqueuer enqueuer) {} | |
166 | 178 |
167 /// Call this to register a `noSuchMethod` implementation. | 179 /// Called to register a `noSuchMethod` implementation. |
168 void registerNoSuchMethod(FunctionElement noSuchMethodElement) {} | 180 void registerNoSuchMethod(FunctionElement noSuchMethodElement) {} |
169 | 181 |
170 /// Call this method to enable support for `noSuchMethod`. | 182 /// Called to enable support for `noSuchMethod`. Any backend specific |
171 void enableNoSuchMethod(Enqueuer enqueuer) {} | 183 /// [WorldImpact] of this is returned. |
| 184 WorldImpact enableNoSuchMethod() => const WorldImpact(); |
172 | 185 |
173 /// Returns whether or not `noSuchMethod` support has been enabled. | 186 /// Returns whether or not `noSuchMethod` support has been enabled. |
174 bool get enabledNoSuchMethod => false; | 187 bool get enabledNoSuchMethod => false; |
175 | 188 |
176 /// Call this method to enable support for isolates. | 189 /// Called to enable support for isolates. Any backend specific [WorldImpact] |
177 void enableIsolateSupport(Enqueuer enqueuer) {} | 190 /// of this is returned. |
| 191 WorldImpact enableIsolateSupport({bool forResolution}); |
178 | 192 |
179 void registerConstSymbol(String name) {} | 193 void registerConstSymbol(String name) {} |
180 | 194 |
181 ClassElement defaultSuperclass(ClassElement element) { | 195 ClassElement defaultSuperclass(ClassElement element) { |
182 return compiler.coreClasses.objectClass; | 196 return compiler.coreClasses.objectClass; |
183 } | 197 } |
184 | 198 |
185 bool isInterceptorClass(ClassElement element) => false; | 199 bool isInterceptorClass(ClassElement element) => false; |
186 | 200 |
187 /// Returns `true` if [element] is implemented via typed JavaScript interop. | 201 /// Returns `true` if [element] is implemented via typed JavaScript interop. |
(...skipping 11 matching lines...) Expand all Loading... |
199 // TODO(johnniwinther): Remove this when patching is only done by the | 213 // TODO(johnniwinther): Remove this when patching is only done by the |
200 // JavaScript backend. | 214 // JavaScript backend. |
201 Uri canonicalUri = library.canonicalUri; | 215 Uri canonicalUri = library.canonicalUri; |
202 if (canonicalUri == js_backend.BackendHelpers.DART_JS_HELPER || | 216 if (canonicalUri == js_backend.BackendHelpers.DART_JS_HELPER || |
203 canonicalUri == js_backend.BackendHelpers.DART_INTERCEPTORS) { | 217 canonicalUri == js_backend.BackendHelpers.DART_INTERCEPTORS) { |
204 return true; | 218 return true; |
205 } | 219 } |
206 return false; | 220 return false; |
207 } | 221 } |
208 | 222 |
209 void registerStaticUse(Enqueuer enqueuer, Element element) {} | 223 /// Called to register that [element] is statically known to be used. Any |
| 224 /// backend specific [WorldImpact] of this is returned. |
| 225 WorldImpact registerStaticUse(Element element, {bool forResolution}) => |
| 226 const WorldImpact(); |
210 | 227 |
211 /// This method is called immediately after the [LibraryElement] [library] has | 228 /// This method is called immediately after the [LibraryElement] [library] has |
212 /// been created. | 229 /// been created. |
213 void onLibraryCreated(LibraryElement library) {} | 230 void onLibraryCreated(LibraryElement library) {} |
214 | 231 |
215 /// This method is called immediately after the [library] and its parts have | 232 /// This method is called immediately after the [library] and its parts have |
216 /// been scanned. | 233 /// been scanned. |
217 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { | 234 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { |
218 // TODO(johnniwinther): Move this to [JavaScriptBackend]. | 235 // TODO(johnniwinther): Move this to [JavaScriptBackend]. |
219 if (!compiler.serialization.isDeserialized(library)) { | 236 if (!compiler.serialization.isDeserialized(library)) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 324 |
308 FunctionElement helperForBadMain() => null; | 325 FunctionElement helperForBadMain() => null; |
309 | 326 |
310 FunctionElement helperForMissingMain() => null; | 327 FunctionElement helperForMissingMain() => null; |
311 | 328 |
312 FunctionElement helperForMainArity() => null; | 329 FunctionElement helperForMainArity() => null; |
313 | 330 |
314 void forgetElement(Element element) {} | 331 void forgetElement(Element element) {} |
315 | 332 |
316 /// Computes the [WorldImpact] of calling [mainMethod] as the entry point. | 333 /// Computes the [WorldImpact] of calling [mainMethod] as the entry point. |
317 WorldImpact computeMainImpact(Enqueuer enqueuer, MethodElement mainMethod) {} | 334 WorldImpact computeMainImpact(MethodElement mainMethod, |
| 335 {bool forResolution}) => |
| 336 const WorldImpact(); |
318 | 337 |
319 /// Returns the location of the patch-file associated with [libraryName] | 338 /// Returns the location of the patch-file associated with [libraryName] |
320 /// resolved from [plaformConfigUri]. | 339 /// resolved from [plaformConfigUri]. |
321 /// | 340 /// |
322 /// Returns null if there is none. | 341 /// Returns null if there is none. |
323 Uri resolvePatchUri(String libraryName, Uri plaformConfigUri); | 342 Uri resolvePatchUri(String libraryName, Uri plaformConfigUri); |
324 | 343 |
325 /// Creates an impact strategy to use for compilation. | 344 /// Creates an impact strategy to use for compilation. |
326 ImpactStrategy createImpactStrategy( | 345 ImpactStrategy createImpactStrategy( |
327 {bool supportDeferredLoad: true, | 346 {bool supportDeferredLoad: true, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 ClassElement get typeImplementation; | 414 ClassElement get typeImplementation; |
396 ClassElement get boolImplementation; | 415 ClassElement get boolImplementation; |
397 ClassElement get nullImplementation; | 416 ClassElement get nullImplementation; |
398 ClassElement get uint32Implementation; | 417 ClassElement get uint32Implementation; |
399 ClassElement get uint31Implementation; | 418 ClassElement get uint31Implementation; |
400 ClassElement get positiveIntImplementation; | 419 ClassElement get positiveIntImplementation; |
401 ClassElement get syncStarIterableImplementation; | 420 ClassElement get syncStarIterableImplementation; |
402 ClassElement get asyncFutureImplementation; | 421 ClassElement get asyncFutureImplementation; |
403 ClassElement get asyncStarStreamImplementation; | 422 ClassElement get asyncStarStreamImplementation; |
404 } | 423 } |
OLD | NEW |