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. |
Harry Terkelsen
2016/11/28 19:03:06
is this method called even if the call method does
Johnni Winther
2016/11/29 08:01:37
Yes. Added a note to the comment.
| |
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 WorldImpact registerCallMethodWithFreeTypeVariables(Element callMethod, |
147 */ | 154 {bool forResolution}) => |
148 void registerCallMethodWithFreeTypeVariables( | 155 const WorldImpact(); |
149 Element callMethod, Enqueuer enqueuer) {} | |
150 | 156 |
151 /// Called to instruct the backend to register that a closure exists for a | 157 /// Called to instruct the backend to register that a closure exists for a |
152 /// function on an instantiated generic class. | 158 /// function on an instantiated generic class. Any backend specific |
153 void registerClosureWithFreeTypeVariables( | 159 /// [WorldImpact] of this is returned. |
154 Element closure, Enqueuer enqueuer) {} | 160 WorldImpact registerClosureWithFreeTypeVariables(Element closure, |
161 {bool forResolution}) => | |
162 const WorldImpact(); | |
155 | 163 |
156 /// Call this to register that a member has been closurized. | 164 /// Called to register that a member has been closurized. Any backend specific |
157 void registerBoundClosure(Enqueuer enqueuer) {} | 165 /// [WorldImpact] of this is returned. |
166 WorldImpact registerBoundClosure() => const WorldImpact(); | |
158 | 167 |
159 /// Call this to register that a static function has been closurized. | 168 /// Called to register that a static function has been closurized. Any backend |
160 void registerGetOfStaticFunction(Enqueuer enqueuer) {} | 169 /// specific [WorldImpact] of this is returned. |
170 WorldImpact registerGetOfStaticFunction() => const WorldImpact(); | |
161 | 171 |
162 /** | 172 /// Called to register that the `runtimeType` property has been accessed. Any |
163 * Call this to register that the [:runtimeType:] property has been accessed. | 173 /// backend specific [WorldImpact] of this is returned. |
164 */ | 174 WorldImpact registerRuntimeType() => const WorldImpact(); |
165 void registerRuntimeType(Enqueuer enqueuer) {} | |
166 | 175 |
167 /// Call this to register a `noSuchMethod` implementation. | 176 /// Called to register a `noSuchMethod` implementation. |
168 void registerNoSuchMethod(FunctionElement noSuchMethodElement) {} | 177 void registerNoSuchMethod(FunctionElement noSuchMethodElement) {} |
169 | 178 |
170 /// Call this method to enable support for `noSuchMethod`. | 179 /// Called to enable support for `noSuchMethod`. Any backend specific |
171 void enableNoSuchMethod(Enqueuer enqueuer) {} | 180 /// [WorldImpact] of this is returned. |
181 WorldImpact enableNoSuchMethod() => const WorldImpact(); | |
172 | 182 |
173 /// Returns whether or not `noSuchMethod` support has been enabled. | 183 /// Returns whether or not `noSuchMethod` support has been enabled. |
174 bool get enabledNoSuchMethod => false; | 184 bool get enabledNoSuchMethod => false; |
175 | 185 |
176 /// Call this method to enable support for isolates. | 186 /// Called to enable support for isolates. Any backend specific [WorldImpact] |
177 void enableIsolateSupport(Enqueuer enqueuer) {} | 187 /// of this is returned. |
188 WorldImpact enableIsolateSupport({bool forResolution}); | |
178 | 189 |
179 void registerConstSymbol(String name) {} | 190 void registerConstSymbol(String name) {} |
180 | 191 |
181 ClassElement defaultSuperclass(ClassElement element) { | 192 ClassElement defaultSuperclass(ClassElement element) { |
182 return compiler.coreClasses.objectClass; | 193 return compiler.coreClasses.objectClass; |
183 } | 194 } |
184 | 195 |
185 bool isInterceptorClass(ClassElement element) => false; | 196 bool isInterceptorClass(ClassElement element) => false; |
186 | 197 |
187 /// Returns `true` if [element] is implemented via typed JavaScript interop. | 198 /// 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 | 210 // TODO(johnniwinther): Remove this when patching is only done by the |
200 // JavaScript backend. | 211 // JavaScript backend. |
201 Uri canonicalUri = library.canonicalUri; | 212 Uri canonicalUri = library.canonicalUri; |
202 if (canonicalUri == js_backend.BackendHelpers.DART_JS_HELPER || | 213 if (canonicalUri == js_backend.BackendHelpers.DART_JS_HELPER || |
203 canonicalUri == js_backend.BackendHelpers.DART_INTERCEPTORS) { | 214 canonicalUri == js_backend.BackendHelpers.DART_INTERCEPTORS) { |
204 return true; | 215 return true; |
205 } | 216 } |
206 return false; | 217 return false; |
207 } | 218 } |
208 | 219 |
209 void registerStaticUse(Enqueuer enqueuer, Element element) {} | 220 /// Called to register that [element] is statically known to be used. Any |
221 /// backend specific [WorldImpact] of this is returned. | |
222 WorldImpact registerStaticUse(Element element, {bool forResolution}) => | |
223 const WorldImpact(); | |
210 | 224 |
211 /// This method is called immediately after the [LibraryElement] [library] has | 225 /// This method is called immediately after the [LibraryElement] [library] has |
212 /// been created. | 226 /// been created. |
213 void onLibraryCreated(LibraryElement library) {} | 227 void onLibraryCreated(LibraryElement library) {} |
214 | 228 |
215 /// This method is called immediately after the [library] and its parts have | 229 /// This method is called immediately after the [library] and its parts have |
216 /// been scanned. | 230 /// been scanned. |
217 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { | 231 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { |
218 // TODO(johnniwinther): Move this to [JavaScriptBackend]. | 232 // TODO(johnniwinther): Move this to [JavaScriptBackend]. |
219 if (!compiler.serialization.isDeserialized(library)) { | 233 if (!compiler.serialization.isDeserialized(library)) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 | 321 |
308 FunctionElement helperForBadMain() => null; | 322 FunctionElement helperForBadMain() => null; |
309 | 323 |
310 FunctionElement helperForMissingMain() => null; | 324 FunctionElement helperForMissingMain() => null; |
311 | 325 |
312 FunctionElement helperForMainArity() => null; | 326 FunctionElement helperForMainArity() => null; |
313 | 327 |
314 void forgetElement(Element element) {} | 328 void forgetElement(Element element) {} |
315 | 329 |
316 /// Computes the [WorldImpact] of calling [mainMethod] as the entry point. | 330 /// Computes the [WorldImpact] of calling [mainMethod] as the entry point. |
317 WorldImpact computeMainImpact(Enqueuer enqueuer, MethodElement mainMethod) {} | 331 WorldImpact computeMainImpact(MethodElement mainMethod, |
332 {bool forResolution}) => | |
333 const WorldImpact(); | |
318 | 334 |
319 /// Returns the location of the patch-file associated with [libraryName] | 335 /// Returns the location of the patch-file associated with [libraryName] |
320 /// resolved from [plaformConfigUri]. | 336 /// resolved from [plaformConfigUri]. |
321 /// | 337 /// |
322 /// Returns null if there is none. | 338 /// Returns null if there is none. |
323 Uri resolvePatchUri(String libraryName, Uri plaformConfigUri); | 339 Uri resolvePatchUri(String libraryName, Uri plaformConfigUri); |
324 | 340 |
325 /// Creates an impact strategy to use for compilation. | 341 /// Creates an impact strategy to use for compilation. |
326 ImpactStrategy createImpactStrategy( | 342 ImpactStrategy createImpactStrategy( |
327 {bool supportDeferredLoad: true, | 343 {bool supportDeferredLoad: true, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 ClassElement get typeImplementation; | 411 ClassElement get typeImplementation; |
396 ClassElement get boolImplementation; | 412 ClassElement get boolImplementation; |
397 ClassElement get nullImplementation; | 413 ClassElement get nullImplementation; |
398 ClassElement get uint32Implementation; | 414 ClassElement get uint32Implementation; |
399 ClassElement get uint31Implementation; | 415 ClassElement get uint31Implementation; |
400 ClassElement get positiveIntImplementation; | 416 ClassElement get positiveIntImplementation; |
401 ClassElement get syncStarIterableImplementation; | 417 ClassElement get syncStarIterableImplementation; |
402 ClassElement get asyncFutureImplementation; | 418 ClassElement get asyncFutureImplementation; |
403 ClassElement get asyncStarStreamImplementation; | 419 ClassElement get asyncStarStreamImplementation; |
404 } | 420 } |
OLD | NEW |