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/registry.dart' show Registry; | 9 import '../common/registry.dart' show Registry; |
10 import '../common/resolution.dart' show Resolution; | 10 import '../common/resolution.dart' show Resolution; |
(...skipping 16 matching lines...) Expand all Loading... | |
27 * This could be an abstract class but we use it as a stub for the dart_backend. | 27 * This could be an abstract class but we use it as a stub for the dart_backend. |
28 */ | 28 */ |
29 class NativeEnqueuer { | 29 class NativeEnqueuer { |
30 /// Initial entry point to native enqueuer. | 30 /// Initial entry point to native enqueuer. |
31 void processNativeClasses(Iterable<LibraryElement> libraries) {} | 31 void processNativeClasses(Iterable<LibraryElement> libraries) {} |
32 | 32 |
33 /// Registers the [nativeBehavior]. Adds the liveness of its instantiated | 33 /// Registers the [nativeBehavior]. Adds the liveness of its instantiated |
34 /// types to the world. | 34 /// types to the world. |
35 void registerNativeBehavior(NativeBehavior nativeBehavior, cause) {} | 35 void registerNativeBehavior(NativeBehavior nativeBehavior, cause) {} |
36 | 36 |
37 /// Notification of a main Enqueuer worklist element. For methods, adds | 37 // TODO(johnniwinther): Move [handleFieldAnnotations] and |
38 /// information from metadata attributes, and computes types instantiated due | 38 // [handleMethodAnnotations] to [JavaScriptBackend] or [NativeData]. |
Harry Terkelsen
2016/06/08 16:34:42
do these do anything if the element is not native?
Johnni Winther
2016/06/10 07:58:51
Adding a TODO to make them return a bool; they act
| |
39 /// to calling the method. | 39 /// Process the potentially native [field]. Adds information from metadata |
40 void registerElement(Element element) {} | 40 /// attributes. |
41 | |
42 /// Notification of native field. Adds information from metadata attributes. | |
43 void handleFieldAnnotations(Element field) {} | 41 void handleFieldAnnotations(Element field) {} |
44 | 42 |
45 /// Computes types instantiated due to getting a native field. | 43 /// Process the potentially native [method]. Adds information from metadata |
46 void registerFieldLoad(Element field) {} | 44 /// attributes. |
47 | 45 void handleMethodAnnotations(Element method) {} |
48 /// Computes types instantiated due to setting a native field. | |
49 void registerFieldStore(Element field) {} | |
50 | 46 |
51 /// Returns whether native classes are being used. | 47 /// Returns whether native classes are being used. |
52 bool hasInstantiatedNativeClasses() => false; | 48 bool hasInstantiatedNativeClasses() => false; |
53 | 49 |
54 /// Emits a summary information using the [log] function. | 50 /// Emits a summary information using the [log] function. |
55 void logSummary(log(message)) {} | 51 void logSummary(log(message)) {} |
56 | 52 |
57 // Do not use annotations in dart2dart. | 53 // Do not use annotations in dart2dart. |
58 ClassElement get annotationCreatesClass => null; | 54 ClassElement get annotationCreatesClass => null; |
59 ClassElement get annotationReturnsClass => null; | 55 ClassElement get annotationReturnsClass => null; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 // TODO(ahe): Is this really a global dependency? | 360 // TODO(ahe): Is this really a global dependency? |
365 classElement.ensureResolved(resolution); | 361 classElement.ensureResolved(resolution); |
366 compiler.backend.registerInstantiatedType( | 362 compiler.backend.registerInstantiatedType( |
367 classElement.rawType, world, compiler.globalDependencies); | 363 classElement.rawType, world, compiler.globalDependencies); |
368 | 364 |
369 if (firstTime) { | 365 if (firstTime) { |
370 queue.add(onFirstNativeClass); | 366 queue.add(onFirstNativeClass); |
371 } | 367 } |
372 } | 368 } |
373 | 369 |
374 registerElement(Element element) { | |
375 reporter.withCurrentElement(element, () { | |
376 if (element.isFunction || | |
377 element.isFactoryConstructor || | |
378 element.isGetter || | |
379 element.isSetter) { | |
380 handleMethodAnnotations(element); | |
381 if (backend.isNative(element)) { | |
382 registerMethodUsed(element); | |
383 } | |
384 } else if (element.isField) { | |
385 handleFieldAnnotations(element); | |
386 if (backend.isNative(element)) { | |
387 registerFieldLoad(element); | |
388 registerFieldStore(element); | |
389 } | |
390 } | |
391 }); | |
392 } | |
393 | |
394 void handleFieldAnnotations(Element element) { | 370 void handleFieldAnnotations(Element element) { |
395 if (compiler.serialization.isDeserialized(element)) { | 371 if (compiler.serialization.isDeserialized(element)) { |
396 return; | 372 return; |
397 } | 373 } |
398 if (backend.isNative(element.enclosingElement)) { | 374 if (backend.isNative(element.enclosingElement)) { |
399 // Exclude non-instance (static) fields - they not really native and are | 375 // Exclude non-instance (static) fields - they not really native and are |
400 // compiled as isolate globals. Access of a property of a constructor | 376 // compiled as isolate globals. Access of a property of a constructor |
401 // function or a non-method property in the prototype chain, must be coded | 377 // function or a non-method property in the prototype chain, must be coded |
402 // using a JS-call. | 378 // using a JS-call. |
403 if (element.isInstanceMember) { | 379 if (element.isInstanceMember) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 if (identical(token.stringValue, 'native')) return true; | 444 if (identical(token.stringValue, 'native')) return true; |
469 return false; | 445 return false; |
470 }); | 446 }); |
471 } | 447 } |
472 | 448 |
473 void registerNativeBehavior(NativeBehavior nativeBehavior, cause) { | 449 void registerNativeBehavior(NativeBehavior nativeBehavior, cause) { |
474 processNativeBehavior(nativeBehavior, cause); | 450 processNativeBehavior(nativeBehavior, cause); |
475 flushQueue(); | 451 flushQueue(); |
476 } | 452 } |
477 | 453 |
478 void registerMethodUsed(Element method) { | |
479 registerNativeBehavior(NativeBehavior.ofMethod(method, compiler), method); | |
480 } | |
481 | |
482 void registerFieldLoad(Element field) { | |
483 registerNativeBehavior(NativeBehavior.ofFieldLoad(field, compiler), field); | |
484 } | |
485 | |
486 void registerFieldStore(Element field) { | |
487 registerNativeBehavior(NativeBehavior.ofFieldStore(field, compiler), field); | |
488 } | |
489 | |
490 processNativeBehavior(NativeBehavior behavior, cause) { | 454 processNativeBehavior(NativeBehavior behavior, cause) { |
491 // TODO(ahe): Is this really a global dependency? | 455 // TODO(ahe): Is this really a global dependency? |
492 Registry registry = compiler.globalDependencies; | 456 Registry registry = compiler.globalDependencies; |
493 bool allUsedBefore = unusedClasses.isEmpty; | 457 bool allUsedBefore = unusedClasses.isEmpty; |
494 for (var type in behavior.typesInstantiated) { | 458 for (var type in behavior.typesInstantiated) { |
495 if (matchedTypeConstraints.contains(type)) continue; | 459 if (matchedTypeConstraints.contains(type)) continue; |
496 matchedTypeConstraints.add(type); | 460 matchedTypeConstraints.add(type); |
497 if (type is SpecialType) { | 461 if (type is SpecialType) { |
498 if (type == SpecialType.JsObject) { | 462 if (type == SpecialType.JsObject) { |
499 backend.registerInstantiatedType( | 463 backend.registerInstantiatedType( |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 List<Element> directSubtypes = | 670 List<Element> directSubtypes = |
707 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassElement>[]); | 671 emitter.directSubtypes.putIfAbsent(superclass, () => <ClassElement>[]); |
708 directSubtypes.add(cls); | 672 directSubtypes.add(cls); |
709 } | 673 } |
710 | 674 |
711 void logSummary(log(message)) { | 675 void logSummary(log(message)) { |
712 log('Compiled ${registeredClasses.length} native classes, ' | 676 log('Compiled ${registeredClasses.length} native classes, ' |
713 '${unusedClasses.length} native classes omitted.'); | 677 '${unusedClasses.length} native classes omitted.'); |
714 } | 678 } |
715 } | 679 } |
OLD | NEW |