| 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 '../compiler.dart' show | 10 import '../compiler.dart' show |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 import '../io/code_output.dart' show | 36 import '../io/code_output.dart' show |
| 37 CodeBuffer; | 37 CodeBuffer; |
| 38 import '../io/source_information.dart' show | 38 import '../io/source_information.dart' show |
| 39 SourceInformationStrategy; | 39 SourceInformationStrategy; |
| 40 import '../js_backend/js_backend.dart' as js_backend show | 40 import '../js_backend/js_backend.dart' as js_backend show |
| 41 JavaScriptBackend; | 41 JavaScriptBackend; |
| 42 import '../library_loader.dart' show | 42 import '../library_loader.dart' show |
| 43 LibraryLoader, | 43 LibraryLoader, |
| 44 LoadedLibraries; | 44 LoadedLibraries; |
| 45 import '../native/native.dart' as native show | 45 import '../native/native.dart' as native show |
| 46 NativeEnqueuer; | 46 NativeEnqueuer, |
| 47 maybeEnableNative; |
| 47 import '../patch_parser.dart' show | 48 import '../patch_parser.dart' show |
| 48 checkNativeAnnotation, checkJsInteropAnnotation; | 49 checkNativeAnnotation, checkJsInteropAnnotation; |
| 49 import '../resolution/tree_elements.dart' show | 50 import '../resolution/tree_elements.dart' show |
| 50 TreeElements; | 51 TreeElements; |
| 51 import '../tree/tree.dart' show | 52 import '../tree/tree.dart' show |
| 52 Node, | 53 Node, |
| 53 Send; | 54 Send; |
| 54 import '../universe/call_structure.dart' show | 55 import '../universe/call_structure.dart' show |
| 55 CallStructure; | 56 CallStructure; |
| 56 | 57 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 ClassElement get positiveIntImplementation => compiler.intClass; | 253 ClassElement get positiveIntImplementation => compiler.intClass; |
| 253 | 254 |
| 254 ClassElement defaultSuperclass(ClassElement element) => compiler.objectClass; | 255 ClassElement defaultSuperclass(ClassElement element) => compiler.objectClass; |
| 255 | 256 |
| 256 bool isInterceptorClass(ClassElement element) => false; | 257 bool isInterceptorClass(ClassElement element) => false; |
| 257 | 258 |
| 258 /// Returns `true` if [element] is a foreign element, that is, that the | 259 /// Returns `true` if [element] is a foreign element, that is, that the |
| 259 /// backend has specialized handling for the element. | 260 /// backend has specialized handling for the element. |
| 260 bool isForeign(Element element) => false; | 261 bool isForeign(Element element) => false; |
| 261 | 262 |
| 263 /// Returns `true` if [element] is a native element, that is, that the |
| 264 /// corresponding entity already exists in the target language. |
| 265 bool isNative(Element element) => false; |
| 266 |
| 267 /// Returns `true` if [element] is implemented via typed JavaScript interop. |
| 268 // TODO(johnniwinther): Move this to [JavaScriptBackend]. |
| 269 bool isJsInterop(Element element) => false; |
| 270 |
| 271 /// Returns `true` if the `native` pseudo keyword is supported for [library]. |
| 272 bool canLibraryUseNative(LibraryElement library) { |
| 273 // TODO(johnniwinther): Move this to [JavaScriptBackend]. |
| 274 return native.maybeEnableNative(compiler, library); |
| 275 } |
| 276 |
| 262 /// Processes [element] for resolution and returns the [FunctionElement] that | 277 /// Processes [element] for resolution and returns the [FunctionElement] that |
| 263 /// defines the implementation of [element]. | 278 /// defines the implementation of [element]. |
| 264 FunctionElement resolveExternalFunction(FunctionElement element) => element; | 279 FunctionElement resolveExternalFunction(FunctionElement element) => element; |
| 265 | 280 |
| 266 /// Returns `true` if [library] is a backend specific library whose members | 281 /// Returns `true` if [library] is a backend specific library whose members |
| 267 /// have special treatment, such as being allowed to extends blacklisted | 282 /// have special treatment, such as being allowed to extends blacklisted |
| 268 /// classes or member being eagerly resolved. | 283 /// classes or member being eagerly resolved. |
| 269 bool isBackendLibrary(LibraryElement library) { | 284 bool isBackendLibrary(LibraryElement library) { |
| 270 // TODO(johnniwinther): Remove this when patching is only done by the | 285 // TODO(johnniwinther): Remove this when patching is only done by the |
| 271 // JavaScript backend. | 286 // JavaScript backend. |
| 272 Uri canonicalUri = library.canonicalUri; | 287 Uri canonicalUri = library.canonicalUri; |
| 273 if (canonicalUri == js_backend.JavaScriptBackend.DART_JS_HELPER || | 288 if (canonicalUri == js_backend.JavaScriptBackend.DART_JS_HELPER || |
| 274 canonicalUri == js_backend.JavaScriptBackend.DART_INTERCEPTORS) { | 289 canonicalUri == js_backend.JavaScriptBackend.DART_INTERCEPTORS) { |
| 275 return true; | 290 return true; |
| 276 } | 291 } |
| 277 return false; | 292 return false; |
| 278 } | 293 } |
| 279 | 294 |
| 280 void registerStaticUse(Element element, Enqueuer enqueuer) {} | 295 void registerStaticUse(Element element, Enqueuer enqueuer) {} |
| 281 | 296 |
| 282 /// This method is called immediately after the [LibraryElement] [library] has | 297 /// This method is called immediately after the [LibraryElement] [library] has |
| 283 /// been created. | 298 /// been created. |
| 284 void onLibraryCreated(LibraryElement library) {} | 299 void onLibraryCreated(LibraryElement library) {} |
| 285 | 300 |
| 286 /// This method is called immediately after the [library] and its parts have | 301 /// This method is called immediately after the [library] and its parts have |
| 287 /// been scanned. | 302 /// been scanned. |
| 288 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { | 303 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { |
| 289 if (library.canUseNative) { | 304 // TODO(johnniwinther): Move this to [JavaScriptBackend]. |
| 305 if (canLibraryUseNative(library)) { |
| 290 library.forEachLocalMember((Element element) { | 306 library.forEachLocalMember((Element element) { |
| 291 if (element.isClass) { | 307 if (element.isClass) { |
| 292 checkNativeAnnotation(compiler, element); | 308 checkNativeAnnotation(compiler, element); |
| 293 } | 309 } |
| 294 }); | 310 }); |
| 295 } | 311 } |
| 296 checkJsInteropAnnotation(compiler, library); | 312 checkJsInteropAnnotation(compiler, library); |
| 297 library.forEachLocalMember((Element element) { | 313 library.forEachLocalMember((Element element) { |
| 298 checkJsInteropAnnotation(compiler, element); | 314 checkJsInteropAnnotation(compiler, element); |
| 299 if (element.isClass && element.isJsInterop) { | 315 if (element.isClass && isJsInterop(element)) { |
| 300 ClassElement classElement = element; | 316 ClassElement classElement = element; |
| 301 classElement.forEachMember((_, memberElement) { | 317 classElement.forEachMember((_, memberElement) { |
| 302 checkJsInteropAnnotation(compiler, memberElement); | 318 checkJsInteropAnnotation(compiler, memberElement); |
| 303 }); | 319 }); |
| 304 } | 320 } |
| 305 }); | 321 }); |
| 306 return new Future.value(); | 322 return new Future.value(); |
| 307 } | 323 } |
| 308 | 324 |
| 309 /// This method is called when all new libraries loaded through | 325 /// This method is called when all new libraries loaded through |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 /// Returns the constant expression of [node], or `null` if [node] is not | 418 /// Returns the constant expression of [node], or `null` if [node] is not |
| 403 /// a constant expression. | 419 /// a constant expression. |
| 404 ConstantExpression getConstant(Node node); | 420 ConstantExpression getConstant(Node node); |
| 405 | 421 |
| 406 /// Registers [type] as instantiated. | 422 /// Registers [type] as instantiated. |
| 407 void registerInstantiatedType(InterfaceType type); | 423 void registerInstantiatedType(InterfaceType type); |
| 408 | 424 |
| 409 /// Resolves [typeName] to a type in the context of [node]. | 425 /// Resolves [typeName] to a type in the context of [node]. |
| 410 DartType resolveTypeFromString(Node node, String typeName); | 426 DartType resolveTypeFromString(Node node, String typeName); |
| 411 } | 427 } |
| OLD | NEW |