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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 void computeRequiredTypeChecks() { | 62 void computeRequiredTypeChecks() { |
63 assert(checkedClasses == null); | 63 assert(checkedClasses == null); |
64 checkedClasses = new Set<ClassElement>(); | 64 checkedClasses = new Set<ClassElement>(); |
65 compiler.codegenWorld.isChecks.forEach((DartType t) { | 65 compiler.codegenWorld.isChecks.forEach((DartType t) { |
66 if (t is InterfaceType) checkedClasses.add(t.element); | 66 if (t is InterfaceType) checkedClasses.add(t.element); |
67 }); | 67 }); |
68 } | 68 } |
69 | 69 |
70 void writeConstantToBuffer(Constant value, CodeBuffer buffer, | 70 void writeConstantToBuffer(Constant value, CodeBuffer buffer, |
71 [emitCanonicalVersion = true]) { | 71 {emitCanonicalVersion: true}) { |
72 if (emitCanonicalVersion) { | 72 if (emitCanonicalVersion) { |
73 constantEmitter.emitCanonicalVersionOfConstant(value, buffer); | 73 constantEmitter.emitCanonicalVersionOfConstant(value, buffer); |
74 } else { | 74 } else { |
75 constantEmitter.emitJavaScriptCodeForConstant(value, buffer); | 75 constantEmitter.emitJavaScriptCodeForConstant(value, buffer); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 String get name => 'CodeEmitter'; | 79 String get name => 'CodeEmitter'; |
80 | 80 |
81 String get defineClassName | 81 String get defineClassName |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 } | 708 } |
709 buffer.add('"'); | 709 buffer.add('"'); |
710 } | 710 } |
711 } | 711 } |
712 | 712 |
713 // If a class is not instantiated then we add the field just so we can | 713 // If a class is not instantiated then we add the field just so we can |
714 // generate the field getter/setter dynamically. Since this is only | 714 // generate the field getter/setter dynamically. Since this is only |
715 // allowed on fields that are in [classElement] we don't need to visit | 715 // allowed on fields that are in [classElement] we don't need to visit |
716 // superclasses for non-instantiated classes. | 716 // superclasses for non-instantiated classes. |
717 classElement.implementation.forEachInstanceField( | 717 classElement.implementation.forEachInstanceField( |
718 addField, | 718 f: addField, |
719 includeBackendMembers: true, | 719 includeBackendMembers: true, |
720 includeSuperMembers: isInstantiated && !classElement.isNative()); | 720 includeSuperMembers: isInstantiated && !classElement.isNative()); |
721 return checkedSetters; | 721 return checkedSetters; |
722 } | 722 } |
723 | 723 |
724 /** | 724 /** |
725 * Documentation wanted -- johnniwinther | 725 * Documentation wanted -- johnniwinther |
726 * | 726 * |
727 * Invariant: [classElement] must be a declaration element. | 727 * Invariant: [classElement] must be a declaration element. |
728 */ | 728 */ |
729 void emitInstanceMembers(ClassElement classElement, | 729 void emitInstanceMembers(ClassElement classElement, |
730 CodeBuffer buffer, | 730 CodeBuffer buffer, |
731 bool needsLeadingComma) { | 731 bool needsLeadingComma) { |
732 assert(invariant(classElement, classElement.isDeclaration)); | 732 assert(invariant(classElement, classElement.isDeclaration)); |
733 bool needsComma = needsLeadingComma; | 733 bool needsComma = needsLeadingComma; |
734 void defineInstanceMember(String name, CodeBuffer memberBuffer) { | 734 void defineInstanceMember(String name, CodeBuffer memberBuffer) { |
735 if (needsComma) buffer.add(','); | 735 if (needsComma) buffer.add(','); |
736 needsComma = true; | 736 needsComma = true; |
737 buffer.add('\n'); | 737 buffer.add('\n'); |
738 buffer.add(' $name: '); | 738 buffer.add(' $name: '); |
739 buffer.add(memberBuffer); | 739 buffer.add(memberBuffer); |
740 } | 740 } |
741 | 741 |
742 classElement.implementation.forEachMember(includeBackendMembers: true, | 742 classElement.implementation.forEachMember( |
743 f: (ClassElement enclosing, Element member) { | 743 (ClassElement enclosing, Element member) { |
744 assert(invariant(classElement, member.isDeclaration)); | 744 assert(invariant(classElement, member.isDeclaration)); |
745 if (member.isInstanceMember()) { | 745 if (member.isInstanceMember()) { |
746 addInstanceMember(member, defineInstanceMember); | 746 addInstanceMember(member, defineInstanceMember); |
747 } | 747 } |
748 }); | 748 }, |
| 749 includeBackendMembers: true); |
749 | 750 |
750 generateIsTestsOn(classElement, (ClassElement other) { | 751 generateIsTestsOn(classElement, (ClassElement other) { |
751 String code; | 752 String code; |
752 if (other.isObject(compiler)) return; | 753 if (other.isObject(compiler)) return; |
753 if (nativeEmitter.requiresNativeIsCheck(other)) { | 754 if (nativeEmitter.requiresNativeIsCheck(other)) { |
754 code = 'function() { return true; }'; | 755 code = 'function() { return true; }'; |
755 } else { | 756 } else { |
756 code = 'true'; | 757 code = 'true'; |
757 } | 758 } |
758 CodeBuffer typeTestBuffer = new CodeBuffer(); | 759 CodeBuffer typeTestBuffer = new CodeBuffer(); |
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 const String HOOKS_API_USAGE = """ | 1513 const String HOOKS_API_USAGE = """ |
1513 // Generated by dart2js, the Dart to JavaScript compiler. | 1514 // Generated by dart2js, the Dart to JavaScript compiler. |
1514 // The code supports the following hooks: | 1515 // The code supports the following hooks: |
1515 // dartPrint(message) - if this function is defined it is called | 1516 // dartPrint(message) - if this function is defined it is called |
1516 // instead of the Dart [print] method. | 1517 // instead of the Dart [print] method. |
1517 // dartMainRunner(main) - if this function is defined, the Dart [main] | 1518 // dartMainRunner(main) - if this function is defined, the Dart [main] |
1518 // method will not be invoked directly. | 1519 // method will not be invoked directly. |
1519 // Instead, a closure that will invoke [main] is | 1520 // Instead, a closure that will invoke [main] is |
1520 // passed to [dartMainRunner]. | 1521 // passed to [dartMainRunner]. |
1521 """; | 1522 """; |
OLD | NEW |