| 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 16 matching lines...) Expand all Loading... |
| 27 void registerFieldLoad(Element field) {} | 27 void registerFieldLoad(Element field) {} |
| 28 | 28 |
| 29 /// Computes types instantiated due to setting a native field. | 29 /// Computes types instantiated due to setting a native field. |
| 30 void registerFieldStore(Element field) {} | 30 void registerFieldStore(Element field) {} |
| 31 | 31 |
| 32 NativeBehavior getNativeBehaviorOf(Send node) => new NativeBehavior(); | 32 NativeBehavior getNativeBehaviorOf(Send node) => new NativeBehavior(); |
| 33 | 33 |
| 34 /// Returns whether native classes are being used. | 34 /// Returns whether native classes are being used. |
| 35 bool hasInstantiatedNativeClasses() => false; | 35 bool hasInstantiatedNativeClasses() => false; |
| 36 | 36 |
| 37 /** | |
| 38 * Handles JS-calls, which can be an instantiation point for types. | |
| 39 * | |
| 40 * For example, the following code instantiates and returns native classes | |
| 41 * that are `_DOMWindowImpl` or a subtype. | |
| 42 * | |
| 43 * JS('_DOMWindowImpl', 'window') | |
| 44 * | |
| 45 */ | |
| 46 // TODO(sra): The entry from codegen will not have a resolver. | |
| 47 void registerJsCall(Send node, ResolverVisitor resolver) {} | |
| 48 | |
| 49 /** | |
| 50 * Handles JS-embedded global calls, which can be an instantiation point for | |
| 51 * types. | |
| 52 * | |
| 53 * For example, the following code instantiates and returns a String class | |
| 54 * | |
| 55 * JS_EMBEDDED_GLOBAL('String', 'foo') | |
| 56 * | |
| 57 */ | |
| 58 // TODO(sra): The entry from codegen will not have a resolver. | |
| 59 void registerJsEmbeddedGlobalCall(Send node, ResolverVisitor resolver) {} | |
| 60 | |
| 61 /** | |
| 62 * Handles JS-compiler builtin calls, which can be an instantiation point for | |
| 63 * types. | |
| 64 * | |
| 65 * For example, the following code instantiates and returns a String class | |
| 66 * | |
| 67 * JS_BUILTIN('String', 'int2string', 0) | |
| 68 * | |
| 69 */ | |
| 70 // TODO(sra): The entry from codegen will not have a resolver. | |
| 71 void registerJsBuiltinCall(Send node, ResolverVisitor resolver) {} | |
| 72 | |
| 73 /// Emits a summary information using the [log] function. | 37 /// Emits a summary information using the [log] function. |
| 74 void logSummary(log(message)) {} | 38 void logSummary(log(message)) {} |
| 75 | 39 |
| 76 // Do not use annotations in dart2dart. | 40 // Do not use annotations in dart2dart. |
| 77 ClassElement get annotationCreatesClass => null; | 41 ClassElement get annotationCreatesClass => null; |
| 78 ClassElement get annotationReturnsClass => null; | 42 ClassElement get annotationReturnsClass => null; |
| 79 ClassElement get annotationJsNameClass => null; | 43 ClassElement get annotationJsNameClass => null; |
| 80 } | 44 } |
| 81 | 45 |
| 82 | 46 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 } | 446 } |
| 483 | 447 |
| 484 void registerFieldLoad(Element field) { | 448 void registerFieldLoad(Element field) { |
| 485 registerNativeBehavior(NativeBehavior.ofFieldLoad(field, compiler), field); | 449 registerNativeBehavior(NativeBehavior.ofFieldLoad(field, compiler), field); |
| 486 } | 450 } |
| 487 | 451 |
| 488 void registerFieldStore(Element field) { | 452 void registerFieldStore(Element field) { |
| 489 registerNativeBehavior(NativeBehavior.ofFieldStore(field, compiler), field); | 453 registerNativeBehavior(NativeBehavior.ofFieldStore(field, compiler), field); |
| 490 } | 454 } |
| 491 | 455 |
| 492 void registerJsCall(Send node, ResolverVisitor resolver) { | |
| 493 NativeBehavior behavior = NativeBehavior.ofJsCall(node, compiler, resolver); | |
| 494 registerNativeBehavior(behavior, node); | |
| 495 nativeBehaviors[node] = behavior; | |
| 496 } | |
| 497 | |
| 498 void registerJsEmbeddedGlobalCall(Send node, ResolverVisitor resolver) { | |
| 499 NativeBehavior behavior = | |
| 500 NativeBehavior.ofJsEmbeddedGlobalCall(node, compiler, resolver); | |
| 501 registerNativeBehavior(behavior, node); | |
| 502 nativeBehaviors[node] = behavior; | |
| 503 } | |
| 504 | |
| 505 void registerJsBuiltinCall(Send node, ResolverVisitor resolver) { | |
| 506 NativeBehavior behavior = | |
| 507 NativeBehavior.ofJsBuiltinCall(node, compiler, resolver); | |
| 508 registerNativeBehavior(behavior, node); | |
| 509 nativeBehaviors[node] = behavior; | |
| 510 } | |
| 511 | |
| 512 NativeBehavior getNativeBehaviorOf(Send node) => nativeBehaviors[node]; | 456 NativeBehavior getNativeBehaviorOf(Send node) => nativeBehaviors[node]; |
| 513 | 457 |
| 514 processNativeBehavior(NativeBehavior behavior, cause) { | 458 processNativeBehavior(NativeBehavior behavior, cause) { |
| 515 // TODO(ahe): Is this really a global dependency? | 459 // TODO(ahe): Is this really a global dependency? |
| 516 Registry registry = compiler.globalDependencies; | 460 Registry registry = compiler.globalDependencies; |
| 517 bool allUsedBefore = unusedClasses.isEmpty; | 461 bool allUsedBefore = unusedClasses.isEmpty; |
| 518 for (var type in behavior.typesInstantiated) { | 462 for (var type in behavior.typesInstantiated) { |
| 519 if (matchedTypeConstraints.contains(type)) continue; | 463 if (matchedTypeConstraints.contains(type)) continue; |
| 520 matchedTypeConstraints.add(type); | 464 matchedTypeConstraints.add(type); |
| 521 if (type is SpecialType) { | 465 if (type is SpecialType) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 } else { | 559 } else { |
| 616 tagOwner[tag] = classElement; | 560 tagOwner[tag] = classElement; |
| 617 } | 561 } |
| 618 } | 562 } |
| 619 } | 563 } |
| 620 | 564 |
| 621 void logSummary(log(message)) { | 565 void logSummary(log(message)) { |
| 622 log('Resolved ${registeredClasses.length} native elements used, ' | 566 log('Resolved ${registeredClasses.length} native elements used, ' |
| 623 '${unusedClasses.length} native elements dead.'); | 567 '${unusedClasses.length} native elements dead.'); |
| 624 } | 568 } |
| 569 |
| 570 /** |
| 571 * Handles JS-calls, which can be an instantiation point for types. |
| 572 * |
| 573 * For example, the following code instantiates and returns native classes |
| 574 * that are `_DOMWindowImpl` or a subtype. |
| 575 * |
| 576 * JS('_DOMWindowImpl', 'window') |
| 577 * |
| 578 */ |
| 579 void registerJsCall(Send node, ForeignResolver resolver) { |
| 580 NativeBehavior behavior = NativeBehavior.ofJsCall(node, compiler, resolver); |
| 581 registerNativeBehavior(behavior, node); |
| 582 nativeBehaviors[node] = behavior; |
| 583 } |
| 584 |
| 585 |
| 586 /** |
| 587 * Handles JS-embedded global calls, which can be an instantiation point for |
| 588 * types. |
| 589 * |
| 590 * For example, the following code instantiates and returns a String class |
| 591 * |
| 592 * JS_EMBEDDED_GLOBAL('String', 'foo') |
| 593 * |
| 594 */ |
| 595 void registerJsEmbeddedGlobalCall(Send node, ForeignResolver resolver) { |
| 596 NativeBehavior behavior = |
| 597 NativeBehavior.ofJsEmbeddedGlobalCall(node, compiler, resolver); |
| 598 registerNativeBehavior(behavior, node); |
| 599 nativeBehaviors[node] = behavior; |
| 600 } |
| 601 |
| 602 |
| 603 /** |
| 604 * Handles JS-compiler builtin calls, which can be an instantiation point for |
| 605 * types. |
| 606 * |
| 607 * For example, the following code instantiates and returns a String class |
| 608 * |
| 609 * JS_BUILTIN('String', 'int2string', 0) |
| 610 * |
| 611 */ |
| 612 void registerJsBuiltinCall(Send node, ForeignResolver resolver) { |
| 613 NativeBehavior behavior = |
| 614 NativeBehavior.ofJsBuiltinCall(node, compiler, resolver); |
| 615 registerNativeBehavior(behavior, node); |
| 616 nativeBehaviors[node] = behavior; |
| 617 } |
| 625 } | 618 } |
| 626 | 619 |
| 627 | 620 |
| 628 class NativeCodegenEnqueuer extends NativeEnqueuerBase { | 621 class NativeCodegenEnqueuer extends NativeEnqueuerBase { |
| 629 | 622 |
| 630 final CodeEmitterTask emitter; | 623 final CodeEmitterTask emitter; |
| 631 | 624 |
| 632 final Set<ClassElement> doneAddSubtypes = new Set<ClassElement>(); | 625 final Set<ClassElement> doneAddSubtypes = new Set<ClassElement>(); |
| 633 | 626 |
| 634 NativeCodegenEnqueuer(Enqueuer world, Compiler compiler, this.emitter) | 627 NativeCodegenEnqueuer(Enqueuer world, Compiler compiler, this.emitter) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 superclass, | 676 superclass, |
| 684 () => <ClassElement>[]); | 677 () => <ClassElement>[]); |
| 685 directSubtypes.add(cls); | 678 directSubtypes.add(cls); |
| 686 } | 679 } |
| 687 | 680 |
| 688 void logSummary(log(message)) { | 681 void logSummary(log(message)) { |
| 689 log('Compiled ${registeredClasses.length} native classes, ' | 682 log('Compiled ${registeredClasses.length} native classes, ' |
| 690 '${unusedClasses.length} native classes omitted.'); | 683 '${unusedClasses.length} native classes omitted.'); |
| 691 } | 684 } |
| 692 } | 685 } |
| OLD | NEW |