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; |
11 import '../common/resolution.dart' show ResolutionImpact, Frontend, Target; | 11 import '../common/resolution.dart' show ResolutionImpact, Frontend, Target; |
12 import '../compile_time_constants.dart' | 12 import '../compile_time_constants.dart' |
13 show BackendConstantEnvironment, ConstantCompilerTask; | 13 show BackendConstantEnvironment, ConstantCompilerTask; |
14 import '../compiler.dart' show Compiler; | 14 import '../compiler.dart' show Compiler; |
15 import '../constants/constant_system.dart' show ConstantSystem; | 15 import '../constants/constant_system.dart' show ConstantSystem; |
16 import '../constants/expressions.dart' show ConstantExpression; | 16 import '../constants/expressions.dart' show ConstantExpression; |
17 import '../constants/values.dart' show ConstantValue; | 17 import '../constants/values.dart' show ConstantValue; |
18 import '../dart_types.dart' show DartType, InterfaceType; | 18 import '../dart_types.dart' show DartType, InterfaceType; |
19 import '../elements/elements.dart' | 19 import '../elements/elements.dart' |
20 show | 20 show ClassElement, Element, FunctionElement, LibraryElement; |
21 ClassElement, | 21 import '../enqueue.dart' show Enqueuer, EnqueueTask, ResolutionEnqueuer; |
22 Element, | |
23 FunctionElement, | |
24 LibraryElement, | |
25 MetadataAnnotation, | |
26 MethodElement; | |
27 import '../enqueue.dart' | |
28 show Enqueuer, EnqueueTask, CodegenEnqueuer, ResolutionEnqueuer; | |
29 import '../io/code_output.dart' show CodeBuffer; | 22 import '../io/code_output.dart' show CodeBuffer; |
30 import '../io/source_information.dart' show SourceInformationStrategy; | 23 import '../io/source_information.dart' show SourceInformationStrategy; |
31 import '../js_backend/backend_helpers.dart' as js_backend show BackendHelpers; | 24 import '../js_backend/backend_helpers.dart' as js_backend show BackendHelpers; |
32 import '../js_backend/js_backend.dart' as js_backend; | 25 import '../js_backend/js_backend.dart' as js_backend; |
33 import '../library_loader.dart' show LibraryLoader, LoadedLibraries; | 26 import '../library_loader.dart' show LibraryLoader, LoadedLibraries; |
34 import '../native/native.dart' as native show NativeEnqueuer, maybeEnableNative; | 27 import '../native/native.dart' as native show NativeEnqueuer, maybeEnableNative; |
35 import '../patch_parser.dart' | 28 import '../patch_parser.dart' |
36 show checkNativeAnnotation, checkJsInteropAnnotation; | 29 show checkNativeAnnotation, checkJsInteropAnnotation; |
37 import '../serialization/serialization.dart' | 30 import '../serialization/serialization.dart' |
38 show DeserializerPlugin, SerializerPlugin; | 31 show DeserializerPlugin, SerializerPlugin; |
39 import '../tree/tree.dart' show Node, Send; | 32 import '../tree/tree.dart' show Node; |
40 import '../universe/call_structure.dart' show CallStructure; | |
41 import '../universe/world_impact.dart' show ImpactStrategy, WorldImpact; | 33 import '../universe/world_impact.dart' show ImpactStrategy, WorldImpact; |
42 import 'codegen.dart' show CodegenWorkItem; | 34 import 'codegen.dart' show CodegenWorkItem; |
43 import 'registry.dart' show Registry; | 35 import 'registry.dart' show Registry; |
44 import 'tasks.dart' show CompilerTask; | 36 import 'tasks.dart' show CompilerTask; |
45 import 'work.dart' show ItemCompilationContext; | 37 import 'work.dart' show ItemCompilationContext; |
46 | 38 |
47 abstract class Backend extends Target { | 39 abstract class Backend extends Target { |
48 final Compiler compiler; | 40 final Compiler compiler; |
49 | 41 |
50 Backend(this.compiler); | 42 Backend(this.compiler); |
51 | 43 |
52 /// Returns true if the backend supports reflection. | 44 /// Returns true if the backend supports reflection. |
53 bool get supportsReflection; | 45 bool get supportsReflection; |
54 | 46 |
55 /// Returns true if the backend supports reflection. | |
56 bool get supportsAsyncAwait; | |
57 | |
58 /// The [ConstantSystem] used to interpret compile-time constants for this | 47 /// The [ConstantSystem] used to interpret compile-time constants for this |
59 /// backend. | 48 /// backend. |
60 ConstantSystem get constantSystem; | 49 ConstantSystem get constantSystem; |
61 | 50 |
62 /// The constant environment for the backend interpretation of compile-time | 51 /// The constant environment for the backend interpretation of compile-time |
63 /// constants. | 52 /// constants. |
64 BackendConstantEnvironment get constants; | 53 BackendConstantEnvironment get constants; |
65 | 54 |
66 /// The compiler task responsible for the compilation of constants for both | 55 /// The compiler task responsible for the compilation of constants for both |
67 /// the frontend and the backend. | 56 /// the frontend and the backend. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 compiler.coreClasses.futureClass; | 211 compiler.coreClasses.futureClass; |
223 ClassElement get asyncStarStreamImplementation => | 212 ClassElement get asyncStarStreamImplementation => |
224 compiler.coreClasses.streamClass; | 213 compiler.coreClasses.streamClass; |
225 | 214 |
226 ClassElement defaultSuperclass(ClassElement element) { | 215 ClassElement defaultSuperclass(ClassElement element) { |
227 return compiler.coreClasses.objectClass; | 216 return compiler.coreClasses.objectClass; |
228 } | 217 } |
229 | 218 |
230 bool isInterceptorClass(ClassElement element) => false; | 219 bool isInterceptorClass(ClassElement element) => false; |
231 | 220 |
232 /// Returns `true` if [element] is a foreign element, that is, that the | |
233 /// backend has specialized handling for the element. | |
234 bool isForeign(Element element) => false; | |
235 | |
236 /// Returns `true` if [element] is a native element, that is, that the | |
237 /// corresponding entity already exists in the target language. | |
238 bool isNative(Element element) => false; | |
239 | |
240 /// Returns `true` if [element] is implemented via typed JavaScript interop. | 221 /// Returns `true` if [element] is implemented via typed JavaScript interop. |
241 // TODO(johnniwinther): Move this to [JavaScriptBackend]. | 222 // TODO(johnniwinther): Move this to [JavaScriptBackend]. |
242 bool isJsInterop(Element element) => false; | 223 bool isJsInterop(Element element) => false; |
243 | 224 |
244 /// Returns `true` if the `native` pseudo keyword is supported for [library]. | 225 /// Returns `true` if the `native` pseudo keyword is supported for [library]. |
245 bool canLibraryUseNative(LibraryElement library) { | 226 bool canLibraryUseNative(LibraryElement library) { |
246 // TODO(johnniwinther): Move this to [JavaScriptBackend]. | 227 // TODO(johnniwinther): Move this to [JavaScriptBackend]. |
247 return native.maybeEnableNative(compiler, library); | 228 return native.maybeEnableNative(compiler, library); |
248 } | 229 } |
249 | 230 |
250 /// Processes [element] for resolution and returns the [MethodElement] that | |
251 /// defines the implementation of [element]. | |
252 MethodElement resolveExternalFunction(MethodElement element) => element; | |
253 | |
254 @override | 231 @override |
255 bool isTargetSpecificLibrary(LibraryElement library) { | 232 bool isTargetSpecificLibrary(LibraryElement library) { |
256 // TODO(johnniwinther): Remove this when patching is only done by the | 233 // TODO(johnniwinther): Remove this when patching is only done by the |
257 // JavaScript backend. | 234 // JavaScript backend. |
258 Uri canonicalUri = library.canonicalUri; | 235 Uri canonicalUri = library.canonicalUri; |
259 if (canonicalUri == js_backend.BackendHelpers.DART_JS_HELPER || | 236 if (canonicalUri == js_backend.BackendHelpers.DART_JS_HELPER || |
260 canonicalUri == js_backend.BackendHelpers.DART_INTERCEPTORS) { | 237 canonicalUri == js_backend.BackendHelpers.DART_INTERCEPTORS) { |
261 return true; | 238 return true; |
262 } | 239 } |
263 return false; | 240 return false; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 345 |
369 FunctionElement helperForMainArity() => null; | 346 FunctionElement helperForMainArity() => null; |
370 | 347 |
371 void forgetElement(Element element) {} | 348 void forgetElement(Element element) {} |
372 | 349 |
373 void registerMainHasArguments(Enqueuer enqueuer) {} | 350 void registerMainHasArguments(Enqueuer enqueuer) {} |
374 | 351 |
375 void registerAsyncMarker( | 352 void registerAsyncMarker( |
376 FunctionElement element, Enqueuer enqueuer, Registry registry) {} | 353 FunctionElement element, Enqueuer enqueuer, Registry registry) {} |
377 | 354 |
378 /// Called when resolving a call to a foreign function. If a non-null value | |
379 /// is returned, this is stored as native data for [node] in the resolved | |
380 /// AST. | |
381 dynamic resolveForeignCall(Send node, Element element, | |
382 CallStructure callStructure, ForeignResolver resolver) {} | |
383 | |
384 /// Returns the location of the patch-file associated with [libraryName] | 355 /// Returns the location of the patch-file associated with [libraryName] |
385 /// resolved from [plaformConfigUri]. | 356 /// resolved from [plaformConfigUri]. |
386 /// | 357 /// |
387 /// Returns null if there is none. | 358 /// Returns null if there is none. |
388 Uri resolvePatchUri(String libraryName, Uri plaformConfigUri); | 359 Uri resolvePatchUri(String libraryName, Uri plaformConfigUri); |
389 | 360 |
390 /// Creates an impact strategy to use for compilation. | 361 /// Creates an impact strategy to use for compilation. |
391 ImpactStrategy createImpactStrategy( | 362 ImpactStrategy createImpactStrategy( |
392 {bool supportDeferredLoad: true, | 363 {bool supportDeferredLoad: true, |
393 bool supportDumpInfo: true, | 364 bool supportDumpInfo: true, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 } | 406 } |
436 } | 407 } |
437 | 408 |
438 /// Interface for serialization of backend specific data. | 409 /// Interface for serialization of backend specific data. |
439 class BackendSerialization { | 410 class BackendSerialization { |
440 const BackendSerialization(); | 411 const BackendSerialization(); |
441 | 412 |
442 SerializerPlugin get serializer => const SerializerPlugin(); | 413 SerializerPlugin get serializer => const SerializerPlugin(); |
443 DeserializerPlugin get deserializer => const DeserializerPlugin(); | 414 DeserializerPlugin get deserializer => const DeserializerPlugin(); |
444 } | 415 } |
OLD | NEW |