| 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 native; | 5 library native; |
| 6 | 6 |
| 7 import 'dart:uri'; | 7 import 'dart:uri'; |
| 8 import 'dart2jslib.dart' hide SourceString; | 8 import 'dart2jslib.dart' hide SourceString; |
| 9 import 'elements/elements.dart'; | 9 import 'elements/elements.dart'; |
| 10 import 'js_backend/js_backend.dart'; | 10 import 'js_backend/js_backend.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 /// The specific implementation of List that is JavaScript Array: | 26 /// The specific implementation of List that is JavaScript Array: |
| 27 static const JsArray = const SpecialType._('=List'); | 27 static const JsArray = const SpecialType._('=List'); |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * This could be an abstract class but we use it as a stub for the dart_backend. | 32 * This could be an abstract class but we use it as a stub for the dart_backend. |
| 33 */ | 33 */ |
| 34 class NativeEnqueuer { | 34 class NativeEnqueuer { |
| 35 /// Initial entry point to native enqueuer. | 35 /// Initial entry point to native enqueuer. |
| 36 void processNativeClasses(Collection<LibraryElement> libraries) {} | 36 void processNativeClasses(Iterable<LibraryElement> libraries) {} |
| 37 void processNativeClassesInLibrary(LibraryElement library) {} | 37 void processNativeClassesInLibrary(LibraryElement library) {} |
| 38 | 38 |
| 39 /// Notification of a main Enqueuer worklist element. For methods, adds | 39 /// Notification of a main Enqueuer worklist element. For methods, adds |
| 40 /// information from metadata attributes, and computes types instantiated due | 40 /// information from metadata attributes, and computes types instantiated due |
| 41 /// to calling the method. | 41 /// to calling the method. |
| 42 void registerElement(Element element) {} | 42 void registerElement(Element element) {} |
| 43 | 43 |
| 44 /// Notification of native field. Adds information from metadata attributes. | 44 /// Notification of native field. Adds information from metadata attributes. |
| 45 void handleFieldAnnotations(Element field) {} | 45 void handleFieldAnnotations(Element field) {} |
| 46 | 46 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 final Compiler compiler; | 95 final Compiler compiler; |
| 96 final bool enableLiveTypeAnalysis; | 96 final bool enableLiveTypeAnalysis; |
| 97 | 97 |
| 98 ClassElement _annotationCreatesClass; | 98 ClassElement _annotationCreatesClass; |
| 99 ClassElement _annotationReturnsClass; | 99 ClassElement _annotationReturnsClass; |
| 100 ClassElement _annotationJsNameClass; | 100 ClassElement _annotationJsNameClass; |
| 101 | 101 |
| 102 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. | 102 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. |
| 103 NativeEnqueuerBase(this.world, this.compiler, this.enableLiveTypeAnalysis); | 103 NativeEnqueuerBase(this.world, this.compiler, this.enableLiveTypeAnalysis); |
| 104 | 104 |
| 105 void processNativeClasses(Collection<LibraryElement> libraries) { | 105 void processNativeClasses(Iterable<LibraryElement> libraries) { |
| 106 libraries.forEach(processNativeClassesInLibrary); | 106 libraries.forEach(processNativeClassesInLibrary); |
| 107 if (!enableLiveTypeAnalysis) { | 107 if (!enableLiveTypeAnalysis) { |
| 108 nativeClasses.forEach((c) => enqueueClass(c, 'forced')); | 108 nativeClasses.forEach((c) => enqueueClass(c, 'forced')); |
| 109 flushQueue(); | 109 flushQueue(); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 void processNativeClassesInLibrary(LibraryElement library) { | 113 void processNativeClassesInLibrary(LibraryElement library) { |
| 114 // Use implementation to ensure the inclusion of injected members. | 114 // Use implementation to ensure the inclusion of injected members. |
| 115 library.implementation.forEachLocalMember((Element element) { | 115 library.implementation.forEachLocalMember((Element element) { |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 393 |
| 394 class NativeCodegenEnqueuer extends NativeEnqueuerBase { | 394 class NativeCodegenEnqueuer extends NativeEnqueuerBase { |
| 395 | 395 |
| 396 final CodeEmitterTask emitter; | 396 final CodeEmitterTask emitter; |
| 397 | 397 |
| 398 final Set<ClassElement> doneAddSubtypes = new Set<ClassElement>(); | 398 final Set<ClassElement> doneAddSubtypes = new Set<ClassElement>(); |
| 399 | 399 |
| 400 NativeCodegenEnqueuer(Enqueuer world, Compiler compiler, this.emitter) | 400 NativeCodegenEnqueuer(Enqueuer world, Compiler compiler, this.emitter) |
| 401 : super(world, compiler, compiler.enableNativeLiveTypeAnalysis); | 401 : super(world, compiler, compiler.enableNativeLiveTypeAnalysis); |
| 402 | 402 |
| 403 void processNativeClasses(Collection<LibraryElement> libraries) { | 403 void processNativeClasses(Iterable<LibraryElement> libraries) { |
| 404 super.processNativeClasses(libraries); | 404 super.processNativeClasses(libraries); |
| 405 | 405 |
| 406 // HACK HACK - add all the resolved classes. | 406 // HACK HACK - add all the resolved classes. |
| 407 NativeEnqueuerBase enqueuer = compiler.enqueuer.resolution.nativeEnqueuer; | 407 NativeEnqueuerBase enqueuer = compiler.enqueuer.resolution.nativeEnqueuer; |
| 408 for (final classElement in enqueuer.registeredClasses) { | 408 for (final classElement in enqueuer.registeredClasses) { |
| 409 if (unusedClasses.contains(classElement)) { | 409 if (unusedClasses.contains(classElement)) { |
| 410 enqueueClass(classElement, 'was resolved'); | 410 enqueueClass(classElement, 'was resolved'); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 flushQueue(); | 413 flushQueue(); |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 builder.add(new HForeign( | 891 builder.add(new HForeign( |
| 892 new DartString.literal('${parameter.name.slowToString()} = #'), | 892 new DartString.literal('${parameter.name.slowToString()} = #'), |
| 893 const LiteralDartString('void'), | 893 const LiteralDartString('void'), |
| 894 <HInstruction>[jsClosure])); | 894 <HInstruction>[jsClosure])); |
| 895 } | 895 } |
| 896 }); | 896 }); |
| 897 LiteralString jsCode = nativeBody.asLiteralString(); | 897 LiteralString jsCode = nativeBody.asLiteralString(); |
| 898 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); | 898 builder.push(new HForeign.statement(jsCode.dartString, <HInstruction>[])); |
| 899 } | 899 } |
| 900 } | 900 } |
| OLD | NEW |