| 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 '../common.dart'; | 5 import '../common.dart'; |
| 6 import '../common/backend_api.dart' show ForeignResolver; | 6 import '../common/backend_api.dart' show ForeignResolver; |
| 7 import '../common/resolution.dart' show Resolution; | 7 import '../common/resolution.dart' show Resolution; |
| 8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
| 9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
| 10 import '../core_types.dart' show CommonElements; | 10 import '../core_types.dart' show CommonElements; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 /// Process the potentially native [method]. Adds information from metadata | 50 /// Process the potentially native [method]. Adds information from metadata |
| 51 /// attributes. | 51 /// attributes. |
| 52 void handleMethodAnnotations(Element method) {} | 52 void handleMethodAnnotations(Element method) {} |
| 53 | 53 |
| 54 /// Returns whether native classes are being used. | 54 /// Returns whether native classes are being used. |
| 55 bool get hasInstantiatedNativeClasses => false; | 55 bool get hasInstantiatedNativeClasses => false; |
| 56 | 56 |
| 57 /// Emits a summary information using the [log] function. | 57 /// Emits a summary information using the [log] function. |
| 58 void logSummary(log(message)) {} | 58 void logSummary(log(message)) {} |
| 59 | |
| 60 // Do not use annotations in dart2dart. | |
| 61 ClassElement get annotationCreatesClass => null; | |
| 62 ClassElement get annotationReturnsClass => null; | |
| 63 ClassElement get annotationJsNameClass => null; | |
| 64 } | 59 } |
| 65 | 60 |
| 66 abstract class NativeEnqueuerBase implements NativeEnqueuer { | 61 abstract class NativeEnqueuerBase implements NativeEnqueuer { |
| 67 static final RegExp _identifier = new RegExp(r'^[a-zA-Z_$][a-zA-Z0-9_$]*$'); | 62 static final RegExp _identifier = new RegExp(r'^[a-zA-Z_$][a-zA-Z0-9_$]*$'); |
| 68 | 63 |
| 69 /// The set of all native classes. Each native class is in [nativeClasses] | 64 /// The set of all native classes. Each native class is in [nativeClasses] |
| 70 /// and exactly one of [unusedClasses] and [registeredClasses]. | 65 /// and exactly one of [unusedClasses] and [registeredClasses]. |
| 71 final Set<ClassElement> _nativeClasses = new Set<ClassElement>(); | 66 final Set<ClassElement> _nativeClasses = new Set<ClassElement>(); |
| 72 | 67 |
| 73 final Set<ClassElement> _registeredClasses = new Set<ClassElement>(); | 68 final Set<ClassElement> _registeredClasses = new Set<ClassElement>(); |
| 74 final Set<ClassElement> _unusedClasses = new Set<ClassElement>(); | 69 final Set<ClassElement> _unusedClasses = new Set<ClassElement>(); |
| 75 | 70 |
| 76 bool get hasInstantiatedNativeClasses => !_registeredClasses.isEmpty; | 71 bool get hasInstantiatedNativeClasses => !_registeredClasses.isEmpty; |
| 77 | 72 |
| 78 final Set<ClassElement> nativeClassesAndSubclasses = new Set<ClassElement>(); | 73 final Set<ClassElement> nativeClassesAndSubclasses = new Set<ClassElement>(); |
| 79 | 74 |
| 80 final Compiler compiler; | 75 final Compiler compiler; |
| 81 final bool enableLiveTypeAnalysis; | 76 final bool enableLiveTypeAnalysis; |
| 82 | 77 |
| 83 ClassElement _annotationCreatesClass; | |
| 84 ClassElement _annotationReturnsClass; | |
| 85 ClassElement _annotationJsNameClass; | |
| 86 | |
| 87 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. | 78 /// Subclasses of [NativeEnqueuerBase] are constructed by the backend. |
| 88 NativeEnqueuerBase(Compiler compiler, this.enableLiveTypeAnalysis) | 79 NativeEnqueuerBase(Compiler compiler, this.enableLiveTypeAnalysis) |
| 89 : this.compiler = compiler; | 80 : this.compiler = compiler; |
| 90 | 81 |
| 91 JavaScriptBackend get backend => compiler.backend; | 82 JavaScriptBackend get backend => compiler.backend; |
| 92 BackendHelpers get helpers => backend.helpers; | 83 BackendHelpers get helpers => backend.helpers; |
| 93 Resolution get resolution => compiler.resolution; | 84 Resolution get resolution => compiler.resolution; |
| 94 | 85 |
| 95 DiagnosticReporter get reporter => compiler.reporter; | 86 DiagnosticReporter get reporter => compiler.reporter; |
| 96 CommonElements get commonElements => compiler.commonElements; | 87 CommonElements get commonElements => compiler.commonElements; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 240 } |
| 250 // Should be at '{', 'with', 'implements', '<' or 'native'. | 241 // Should be at '{', 'with', 'implements', '<' or 'native'. |
| 251 return id.value; | 242 return id.value; |
| 252 } | 243 } |
| 253 | 244 |
| 254 return reporter.withCurrentElement(classElement, () { | 245 return reporter.withCurrentElement(classElement, () { |
| 255 return scanForExtendsName(classElement.position); | 246 return scanForExtendsName(classElement.position); |
| 256 }); | 247 }); |
| 257 } | 248 } |
| 258 | 249 |
| 259 ClassElement get annotationCreatesClass { | |
| 260 findAnnotationClasses(); | |
| 261 return _annotationCreatesClass; | |
| 262 } | |
| 263 | |
| 264 ClassElement get annotationReturnsClass { | |
| 265 findAnnotationClasses(); | |
| 266 return _annotationReturnsClass; | |
| 267 } | |
| 268 | |
| 269 ClassElement get annotationJsNameClass { | |
| 270 findAnnotationClasses(); | |
| 271 return _annotationJsNameClass; | |
| 272 } | |
| 273 | |
| 274 void findAnnotationClasses() { | |
| 275 if (_annotationCreatesClass != null) return; | |
| 276 | |
| 277 _annotationCreatesClass = helpers.annotationCreatesClass; | |
| 278 _annotationReturnsClass = helpers.annotationReturnsClass; | |
| 279 _annotationJsNameClass = helpers.annotationJSNameClass; | |
| 280 } | |
| 281 | |
| 282 /// Returns the JSName annotation string or `null` if no JSName annotation is | 250 /// Returns the JSName annotation string or `null` if no JSName annotation is |
| 283 /// present. | 251 /// present. |
| 284 String findJsNameFromAnnotation(Element element) { | 252 String findJsNameFromAnnotation(Element element) { |
| 285 String name = null; | 253 String name = null; |
| 286 ClassElement annotationClass = annotationJsNameClass; | 254 ClassElement annotationClass = backend.helpers.annotationJSNameClass; |
| 287 for (MetadataAnnotation annotation in element.implementation.metadata) { | 255 for (MetadataAnnotation annotation in element.implementation.metadata) { |
| 288 annotation.ensureResolved(resolution); | 256 annotation.ensureResolved(resolution); |
| 289 ConstantValue value = | 257 ConstantValue value = |
| 290 compiler.constants.getConstantValue(annotation.constant); | 258 compiler.constants.getConstantValue(annotation.constant); |
| 291 if (!value.isConstructedObject) continue; | 259 if (!value.isConstructedObject) continue; |
| 292 ConstructedConstantValue constructedObject = value; | 260 ConstructedConstantValue constructedObject = value; |
| 293 if (constructedObject.type.element != annotationClass) continue; | 261 if (constructedObject.type.element != annotationClass) continue; |
| 294 | 262 |
| 295 Iterable<ConstantValue> fields = constructedObject.fields.values; | 263 Iterable<ConstantValue> fields = constructedObject.fields.values; |
| 296 // TODO(sra): Better validation of the constant. | 264 // TODO(sra): Better validation of the constant. |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 List<ClassEntity> directSubtypes = | 605 List<ClassEntity> directSubtypes = |
| 638 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassEntity>[]); | 606 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassEntity>[]); |
| 639 directSubtypes.add(cls); | 607 directSubtypes.add(cls); |
| 640 } | 608 } |
| 641 | 609 |
| 642 void logSummary(log(message)) { | 610 void logSummary(log(message)) { |
| 643 log('Compiled ${_registeredClasses.length} native classes, ' | 611 log('Compiled ${_registeredClasses.length} native classes, ' |
| 644 '${_unusedClasses.length} native classes omitted.'); | 612 '${_unusedClasses.length} native classes omitted.'); |
| 645 } | 613 } |
| 646 } | 614 } |
| OLD | NEW |