| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of native; | 5 part of native; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * This could be an abstract class but we use it as a stub for the dart_backend. | 8 * This could be an abstract class but we use it as a stub for the dart_backend. |
| 9 */ | 9 */ |
| 10 class NativeEnqueuer { | 10 class NativeEnqueuer { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 ClassElement _annotationCreatesClass; | 88 ClassElement _annotationCreatesClass; |
| 89 ClassElement _annotationReturnsClass; | 89 ClassElement _annotationReturnsClass; |
| 90 ClassElement _annotationJsNameClass; | 90 ClassElement _annotationJsNameClass; |
| 91 | 91 |
| 92 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. | 92 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. |
| 93 NativeEnqueuerBase(this.world, Compiler compiler, this.enableLiveTypeAnalysis) | 93 NativeEnqueuerBase(this.world, Compiler compiler, this.enableLiveTypeAnalysis) |
| 94 : this.compiler = compiler, | 94 : this.compiler = compiler, |
| 95 processedLibraries = compiler.cacheStrategy.newSet(); | 95 processedLibraries = compiler.cacheStrategy.newSet(); |
| 96 | 96 |
| 97 JavaScriptBackend get backend => compiler.backend; | 97 JavaScriptBackend get backend => compiler.backend; |
| 98 BackendHelpers get helpers => backend.helpers; |
| 98 Resolution get resolution => compiler.resolution; | 99 Resolution get resolution => compiler.resolution; |
| 99 | 100 |
| 100 DiagnosticReporter get reporter => compiler.reporter; | 101 DiagnosticReporter get reporter => compiler.reporter; |
| 101 CoreTypes get coreTypes => compiler.coreTypes; | 102 CoreTypes get coreTypes => compiler.coreTypes; |
| 102 | 103 |
| 103 void processNativeClasses(Iterable<LibraryElement> libraries) { | 104 void processNativeClasses(Iterable<LibraryElement> libraries) { |
| 104 if (compiler.hasIncrementalSupport) { | 105 if (compiler.hasIncrementalSupport) { |
| 105 // Since [Set.add] returns bool if an element was added, this restricts | 106 // Since [Set.add] returns bool if an element was added, this restricts |
| 106 // [libraries] to ones that haven't already been processed. This saves | 107 // [libraries] to ones that haven't already been processed. This saves |
| 107 // time during incremental compiles. | 108 // time during incremental compiles. |
| 108 libraries = libraries.where(processedLibraries.add); | 109 libraries = libraries.where(processedLibraries.add); |
| 109 } | 110 } |
| 110 libraries.forEach(processNativeClassesInLibrary); | 111 libraries.forEach(processNativeClassesInLibrary); |
| 111 if (backend.isolateHelperLibrary != null) { | 112 if (helpers.isolateHelperLibrary != null) { |
| 112 processNativeClassesInLibrary(backend.isolateHelperLibrary); | 113 processNativeClassesInLibrary(helpers.isolateHelperLibrary); |
| 113 } | 114 } |
| 114 processSubclassesOfNativeClasses(libraries); | 115 processSubclassesOfNativeClasses(libraries); |
| 115 if (!enableLiveTypeAnalysis) { | 116 if (!enableLiveTypeAnalysis) { |
| 116 nativeClasses.forEach((c) => enqueueClass(c, 'forced')); | 117 nativeClasses.forEach((c) => enqueueClass(c, 'forced')); |
| 117 flushQueue(); | 118 flushQueue(); |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 | 121 |
| 121 void processNativeClassesInLibrary(LibraryElement library) { | 122 void processNativeClassesInLibrary(LibraryElement library) { |
| 122 // Use implementation to ensure the inclusion of injected members. | 123 // Use implementation to ensure the inclusion of injected members. |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 263 } |
| 263 | 264 |
| 264 ClassElement get annotationJsNameClass { | 265 ClassElement get annotationJsNameClass { |
| 265 findAnnotationClasses(); | 266 findAnnotationClasses(); |
| 266 return _annotationJsNameClass; | 267 return _annotationJsNameClass; |
| 267 } | 268 } |
| 268 | 269 |
| 269 void findAnnotationClasses() { | 270 void findAnnotationClasses() { |
| 270 if (_annotationCreatesClass != null) return; | 271 if (_annotationCreatesClass != null) return; |
| 271 ClassElement find(name) { | 272 ClassElement find(name) { |
| 272 Element e = backend.findHelper(name); | 273 Element e = helpers.findHelper(name); |
| 273 if (e == null || e is! ClassElement) { | 274 if (e == null || e is! ClassElement) { |
| 274 reporter.internalError(NO_LOCATION_SPANNABLE, | 275 reporter.internalError(NO_LOCATION_SPANNABLE, |
| 275 "Could not find implementation class '${name}'."); | 276 "Could not find implementation class '${name}'."); |
| 276 } | 277 } |
| 277 return e; | 278 return e; |
| 278 } | 279 } |
| 279 _annotationCreatesClass = find('Creates'); | 280 _annotationCreatesClass = find('Creates'); |
| 280 _annotationReturnsClass = find('Returns'); | 281 _annotationReturnsClass = find('Returns'); |
| 281 _annotationJsNameClass = find('JSName'); | 282 _annotationJsNameClass = find('JSName'); |
| 282 } | 283 } |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 enqueueUnusedClassesMatching(bool predicate(classElement), | 510 enqueueUnusedClassesMatching(bool predicate(classElement), |
| 510 cause, | 511 cause, |
| 511 [String reason]) { | 512 [String reason]) { |
| 512 Iterable matches = unusedClasses.where(predicate); | 513 Iterable matches = unusedClasses.where(predicate); |
| 513 matches.toList().forEach((c) => enqueueClass(c, cause)); | 514 matches.toList().forEach((c) => enqueueClass(c, cause)); |
| 514 } | 515 } |
| 515 | 516 |
| 516 onFirstNativeClass() { | 517 onFirstNativeClass() { |
| 517 staticUse(name) { | 518 staticUse(name) { |
| 518 backend.enqueue( | 519 backend.enqueue( |
| 519 world, backend.findHelper(name), compiler.globalDependencies); | 520 world, helpers.findHelper(name), compiler.globalDependencies); |
| 520 } | 521 } |
| 521 | 522 |
| 522 staticUse('defineProperty'); | 523 staticUse('defineProperty'); |
| 523 staticUse('toStringForNativeObject'); | 524 staticUse('toStringForNativeObject'); |
| 524 staticUse('hashCodeForNativeObject'); | 525 staticUse('hashCodeForNativeObject'); |
| 525 staticUse('convertDartClosureToJS'); | 526 staticUse('convertDartClosureToJS'); |
| 526 addNativeExceptions(); | 527 addNativeExceptions(); |
| 527 } | 528 } |
| 528 | 529 |
| 529 addNativeExceptions() { | 530 addNativeExceptions() { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 superclass, | 682 superclass, |
| 682 () => <ClassElement>[]); | 683 () => <ClassElement>[]); |
| 683 directSubtypes.add(cls); | 684 directSubtypes.add(cls); |
| 684 } | 685 } |
| 685 | 686 |
| 686 void logSummary(log(message)) { | 687 void logSummary(log(message)) { |
| 687 log('Compiled ${registeredClasses.length} native classes, ' | 688 log('Compiled ${registeredClasses.length} native classes, ' |
| 688 '${unusedClasses.length} native classes omitted.'); | 689 '${unusedClasses.length} native classes omitted.'); |
| 689 } | 690 } |
| 690 } | 691 } |
| OLD | NEW |