| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * A function element that represents a closure call. The signature is copied | 6 * A function element that represents a closure call. The signature is copied |
| 7 * from the given element. | 7 * from the given element. |
| 8 */ | 8 */ |
| 9 class ClosureInvocationElement extends FunctionElement { | 9 class ClosureInvocationElement extends FunctionElement { |
| 10 ClosureInvocationElement(SourceString name, | 10 ClosureInvocationElement(SourceString name, |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 buffer.add(memberBuffer); | 630 buffer.add(memberBuffer); |
| 631 } | 631 } |
| 632 | 632 |
| 633 classElement.forEachMember(includeBackendMembers: true, | 633 classElement.forEachMember(includeBackendMembers: true, |
| 634 f: (ClassElement enclosing, Element member) { | 634 f: (ClassElement enclosing, Element member) { |
| 635 if (member.isInstanceMember()) { | 635 if (member.isInstanceMember()) { |
| 636 addInstanceMember(member, defineInstanceMember); | 636 addInstanceMember(member, defineInstanceMember); |
| 637 } | 637 } |
| 638 }); | 638 }); |
| 639 | 639 |
| 640 generateTypeTests(classElement, (Element other) { | 640 generateIsTestsOn(classElement, (Element other) { |
| 641 String code; | 641 String code; |
| 642 if (nativeEmitter.requiresNativeIsCheck(other)) { | 642 if (nativeEmitter.requiresNativeIsCheck(other)) { |
| 643 code = 'function() { return true; }'; | 643 code = 'function() { return true; }'; |
| 644 } else { | 644 } else { |
| 645 code = 'true'; | 645 code = 'true'; |
| 646 } | 646 } |
| 647 CodeBuffer typeTestBuffer = new CodeBuffer(); | 647 CodeBuffer typeTestBuffer = new CodeBuffer(); |
| 648 typeTestBuffer.add(code); | 648 typeTestBuffer.add(code); |
| 649 defineInstanceMember(namer.operatorIs(other), typeTestBuffer); | 649 defineInstanceMember(namer.operatorIs(other), typeTestBuffer); |
| 650 }); | 650 }); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 // syntax. | 689 // syntax. |
| 690 buffer.add(' "super": "$superName"'); | 690 buffer.add(' "super": "$superName"'); |
| 691 if (!checkedSetters.isEmpty()) { | 691 if (!checkedSetters.isEmpty()) { |
| 692 buffer.add(',\n'); | 692 buffer.add(',\n'); |
| 693 buffer.add('${Strings.join(checkedSetters, ",\n")}'); | 693 buffer.add('${Strings.join(checkedSetters, ",\n")}'); |
| 694 } | 694 } |
| 695 emitInstanceMembers(classElement, buffer, true); | 695 emitInstanceMembers(classElement, buffer, true); |
| 696 buffer.add('\n};\n\n'); | 696 buffer.add('\n};\n\n'); |
| 697 } | 697 } |
| 698 | 698 |
| 699 void generateTypeTests(ClassElement cls, | 699 /** |
| 700 void generateTypeTest(ClassElement element)) { | 700 * Generate "is tests" for [cls]: itself, and the "is tests" for the |
| 701 * classes it implements. We don't need to add the "is tests" of the |
| 702 * super class because they will be inherited at runtime. |
| 703 */ |
| 704 void generateIsTestsOn(ClassElement cls, |
| 705 void emitIsTest(ClassElement element)) { |
| 701 if (checkedClasses.contains(cls)) { | 706 if (checkedClasses.contains(cls)) { |
| 702 generateTypeTest(cls); | 707 emitIsTest(cls); |
| 703 } | 708 } |
| 704 generateInterfacesIsTests(cls, generateTypeTest, new Set<Element>()); | 709 Set<Element> generated = new Set<Element>(); |
| 705 } | |
| 706 | |
| 707 void generateInterfacesIsTests(ClassElement cls, | |
| 708 void generateTypeTest(ClassElement element), | |
| 709 Set<Element> alreadyGenerated) { | |
| 710 for (DartType interfaceType in cls.interfaces) { | 710 for (DartType interfaceType in cls.interfaces) { |
| 711 Element element = interfaceType.element; | 711 generateInterfacesIsTests(interfaceType.element, emitIsTest, generated); |
| 712 if (!alreadyGenerated.contains(element) && | |
| 713 checkedClasses.contains(element)) { | |
| 714 alreadyGenerated.add(element); | |
| 715 generateTypeTest(element); | |
| 716 } | |
| 717 generateInterfacesIsTests(element, generateTypeTest, alreadyGenerated); | |
| 718 | |
| 719 // Since [element] is implemented by [cls], we need to also emit | |
| 720 // is checks for the superclass and its supertypes. | |
| 721 ClassElement superclass = element.superclass; | |
| 722 if (!alreadyGenerated.contains(superclass) && | |
| 723 checkedClasses.contains(superclass)) { | |
| 724 alreadyGenerated.add(superclass); | |
| 725 generateTypeTest(superclass); | |
| 726 } | |
| 727 generateInterfacesIsTests(superclass, generateTypeTest, alreadyGenerated); | |
| 728 } | 712 } |
| 729 } | 713 } |
| 730 | 714 |
| 715 /** |
| 716 * Generate "is tests" where [cls] is being implemented. |
| 717 */ |
| 718 void generateInterfacesIsTests(ClassElement cls, |
| 719 void emitIsTest(ClassElement element), |
| 720 Set<Element> alreadyGenerated) { |
| 721 void tryEmitTest(ClassElement cls) { |
| 722 if (!alreadyGenerated.contains(cls) && checkedClasses.contains(cls)) { |
| 723 alreadyGenerated.add(cls); |
| 724 emitIsTest(cls); |
| 725 } |
| 726 }; |
| 727 |
| 728 tryEmitTest(cls); |
| 729 |
| 730 for (DartType interfaceType in cls.interfaces) { |
| 731 Element element = interfaceType.element; |
| 732 tryEmitTest(element); |
| 733 generateInterfacesIsTests(element, emitIsTest, alreadyGenerated); |
| 734 } |
| 735 |
| 736 // We need to also emit "is checks" for the superclass and its supertypes. |
| 737 ClassElement superclass = cls.superclass; |
| 738 if (superclass != null) { |
| 739 tryEmitTest(superclass); |
| 740 generateInterfacesIsTests(superclass, emitIsTest, alreadyGenerated); |
| 741 } |
| 742 } |
| 743 |
| 731 void emitClasses(CodeBuffer buffer) { | 744 void emitClasses(CodeBuffer buffer) { |
| 732 // Compute the required type checks to know which classes need a | 745 // Compute the required type checks to know which classes need a |
| 733 // 'is$' method. | 746 // 'is$' method. |
| 734 computeRequiredTypeChecks(); | 747 computeRequiredTypeChecks(); |
| 735 Set<ClassElement> instantiatedClasses = | 748 Set<ClassElement> instantiatedClasses = |
| 736 compiler.codegenWorld.instantiatedClasses; | 749 compiler.codegenWorld.instantiatedClasses; |
| 737 Set<ClassElement> neededClasses = | 750 Set<ClassElement> neededClasses = |
| 738 new Set<ClassElement>.from(instantiatedClasses); | 751 new Set<ClassElement>.from(instantiatedClasses); |
| 739 for (ClassElement element in instantiatedClasses) { | 752 for (ClassElement element in instantiatedClasses) { |
| 740 for (ClassElement superclass = element.superclass; | 753 for (ClassElement superclass = element.superclass; |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 const String HOOKS_API_USAGE = """ | 1374 const String HOOKS_API_USAGE = """ |
| 1362 // Generated by dart2js, the Dart to JavaScript compiler. | 1375 // Generated by dart2js, the Dart to JavaScript compiler. |
| 1363 // The code supports the following hooks: | 1376 // The code supports the following hooks: |
| 1364 // dartPrint(message) - if this function is defined it is called | 1377 // dartPrint(message) - if this function is defined it is called |
| 1365 // instead of the Dart [print] method. | 1378 // instead of the Dart [print] method. |
| 1366 // dartMainRunner(main) - if this function is defined, the Dart [main] | 1379 // dartMainRunner(main) - if this function is defined, the Dart [main] |
| 1367 // method will not be invoked directly. | 1380 // method will not be invoked directly. |
| 1368 // Instead, a closure that will invoke [main] is | 1381 // Instead, a closure that will invoke [main] is |
| 1369 // passed to [dartMainRunner]. | 1382 // passed to [dartMainRunner]. |
| 1370 """; | 1383 """; |
| OLD | NEW |