| 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 import 'dart:collection' show Queue; | 5 import 'dart:collection' show Queue; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../common/backend_api.dart' show ForeignResolver; | 8 import '../common/backend_api.dart' show ForeignResolver; |
| 9 import '../common/resolution.dart' show Resolution; | 9 import '../common/resolution.dart' show Resolution; |
| 10 import '../compiler.dart' show Compiler; | 10 import '../compiler.dart' show Compiler; |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 return _annotationReturnsClass; | 276 return _annotationReturnsClass; |
| 277 } | 277 } |
| 278 | 278 |
| 279 ClassElement get annotationJsNameClass { | 279 ClassElement get annotationJsNameClass { |
| 280 findAnnotationClasses(); | 280 findAnnotationClasses(); |
| 281 return _annotationJsNameClass; | 281 return _annotationJsNameClass; |
| 282 } | 282 } |
| 283 | 283 |
| 284 void findAnnotationClasses() { | 284 void findAnnotationClasses() { |
| 285 if (_annotationCreatesClass != null) return; | 285 if (_annotationCreatesClass != null) return; |
| 286 ClassElement find(name) { | |
| 287 Element e = helpers.findHelper(name); | |
| 288 if (e == null || e is! ClassElement) { | |
| 289 reporter.internalError(NO_LOCATION_SPANNABLE, | |
| 290 "Could not find implementation class '${name}'."); | |
| 291 } | |
| 292 return e; | |
| 293 } | |
| 294 | 286 |
| 295 _annotationCreatesClass = find('Creates'); | 287 _annotationCreatesClass = helpers.annotationCreatesClass; |
| 296 _annotationReturnsClass = find('Returns'); | 288 _annotationReturnsClass = helpers.annotationReturnsClass; |
| 297 _annotationJsNameClass = find('JSName'); | 289 _annotationJsNameClass = helpers.annotationJSNameClass; |
| 298 } | 290 } |
| 299 | 291 |
| 300 /// Returns the JSName annotation string or `null` if no JSName annotation is | 292 /// Returns the JSName annotation string or `null` if no JSName annotation is |
| 301 /// present. | 293 /// present. |
| 302 String findJsNameFromAnnotation(Element element) { | 294 String findJsNameFromAnnotation(Element element) { |
| 303 String name = null; | 295 String name = null; |
| 304 ClassElement annotationClass = annotationJsNameClass; | 296 ClassElement annotationClass = annotationJsNameClass; |
| 305 for (MetadataAnnotation annotation in element.implementation.metadata) { | 297 for (MetadataAnnotation annotation in element.implementation.metadata) { |
| 306 annotation.ensureResolved(resolution); | 298 annotation.ensureResolved(resolution); |
| 307 ConstantValue value = | 299 ConstantValue value = |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 reporter.log('All native types marked as used due to $cause.'); | 483 reporter.log('All native types marked as used due to $cause.'); |
| 492 } | 484 } |
| 493 } | 485 } |
| 494 | 486 |
| 495 Iterable<ClassElement> _findUnusedClassesMatching( | 487 Iterable<ClassElement> _findUnusedClassesMatching( |
| 496 bool predicate(classElement)) { | 488 bool predicate(classElement)) { |
| 497 return _unusedClasses.where(predicate); | 489 return _unusedClasses.where(predicate); |
| 498 } | 490 } |
| 499 | 491 |
| 500 Iterable<ClassElement> _onFirstNativeClass(WorldImpactBuilder impactBuilder) { | 492 Iterable<ClassElement> _onFirstNativeClass(WorldImpactBuilder impactBuilder) { |
| 501 void staticUse(name) { | 493 void staticUse(element) { |
| 502 Element element = helpers.findHelper(name); | |
| 503 impactBuilder.registerStaticUse(new StaticUse.foreignUse(element)); | 494 impactBuilder.registerStaticUse(new StaticUse.foreignUse(element)); |
| 504 backend.registerBackendUse(element); | 495 backend.registerBackendUse(element); |
| 505 compiler.globalDependencies.registerDependency(element); | 496 compiler.globalDependencies.registerDependency(element); |
| 506 } | 497 } |
| 507 | 498 |
| 508 staticUse('defineProperty'); | 499 staticUse(helpers.defineProperty); |
| 509 staticUse('toStringForNativeObject'); | 500 staticUse(helpers.toStringForNativeObject); |
| 510 staticUse('hashCodeForNativeObject'); | 501 staticUse(helpers.hashCodeForNativeObject); |
| 511 staticUse('convertDartClosureToJS'); | 502 staticUse(helpers.closureConverter); |
| 512 return _findNativeExceptions(); | 503 return _findNativeExceptions(); |
| 513 } | 504 } |
| 514 | 505 |
| 515 Iterable<ClassElement> _findNativeExceptions() { | 506 Iterable<ClassElement> _findNativeExceptions() { |
| 516 return _findUnusedClassesMatching((classElement) { | 507 return _findUnusedClassesMatching((classElement) { |
| 517 // TODO(sra): Annotate exception classes in dart:html. | 508 // TODO(sra): Annotate exception classes in dart:html. |
| 518 String name = classElement.name; | 509 String name = classElement.name; |
| 519 if (name.contains('Exception')) return true; | 510 if (name.contains('Exception')) return true; |
| 520 if (name.contains('Error')) return true; | 511 if (name.contains('Error')) return true; |
| 521 return false; | 512 return false; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 List<Element> directSubtypes = | 653 List<Element> directSubtypes = |
| 663 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassElement>[]); | 654 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassElement>[]); |
| 664 directSubtypes.add(cls); | 655 directSubtypes.add(cls); |
| 665 } | 656 } |
| 666 | 657 |
| 667 void logSummary(log(message)) { | 658 void logSummary(log(message)) { |
| 668 log('Compiled ${_registeredClasses.length} native classes, ' | 659 log('Compiled ${_registeredClasses.length} native classes, ' |
| 669 '${_unusedClasses.length} native classes omitted.'); | 660 '${_unusedClasses.length} native classes omitted.'); |
| 670 } | 661 } |
| 671 } | 662 } |
| OLD | NEW |