Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 11299220: Add @JSName annotation for native fields and methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 part of js_backend; 5 part of js_backend;
6 6
7 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 bool needsGetter, 724 bool needsGetter,
725 bool needsSetter, 725 bool needsSetter,
726 bool needsCheckedSetter)) { 726 bool needsCheckedSetter)) {
727 assert(invariant(classElement, classElement.isDeclaration)); 727 assert(invariant(classElement, classElement.isDeclaration));
728 // If the class is never instantiated we still need to set it up for 728 // If the class is never instantiated we still need to set it up for
729 // inheritance purposes, but we can simplify its JavaScript constructor. 729 // inheritance purposes, but we can simplify its JavaScript constructor.
730 bool isInstantiated = 730 bool isInstantiated =
731 compiler.codegenWorld.instantiatedClasses.contains(classElement); 731 compiler.codegenWorld.instantiatedClasses.contains(classElement);
732 732
733 void visitField(ClassElement enclosingClass, Element member) { 733 void visitField(ClassElement enclosingClass, Element member) {
734 assert(!member.isNative());
735 assert(invariant(classElement, member.isDeclaration)); 734 assert(invariant(classElement, member.isDeclaration));
736 735
737 LibraryElement library = member.getLibrary(); 736 LibraryElement library = member.getLibrary();
738 SourceString name = member.name; 737 SourceString name = member.name;
739 bool isPrivate = name.isPrivate(); 738 bool isPrivate = name.isPrivate();
740 // See if we can dynamically create getters and setters. 739 // See if we can dynamically create getters and setters.
741 // We can only generate getters and setters for [classElement] since 740 // We can only generate getters and setters for [classElement] since
742 // the fields of super classes could be overwritten with getters or 741 // the fields of super classes could be overwritten with getters or
743 // setters. 742 // setters.
744 bool needsGetter = false; 743 bool needsGetter = false;
745 bool needsSetter = false; 744 bool needsSetter = false;
746 // We need to name shadowed fields differently, so they don't clash with 745 // We need to name shadowed fields differently, so they don't clash with
747 // the non-shadowed field. 746 // the non-shadowed field.
748 bool isShadowed = false; 747 bool isShadowed = false;
749 if (identical(enclosingClass, classElement)) { 748 if (identical(enclosingClass, classElement)) {
750 needsGetter = instanceFieldNeedsGetter(member); 749 needsGetter = instanceFieldNeedsGetter(member);
751 needsSetter = instanceFieldNeedsSetter(member); 750 needsSetter = instanceFieldNeedsSetter(member);
752 } else { 751 } else {
753 isShadowed = classElement.isShadowedByField(member); 752 isShadowed = classElement.isShadowedByField(member);
754 } 753 }
755 754
756 if ((isInstantiated && !enclosingClass.isNative()) 755 if ((isInstantiated && !enclosingClass.isNative())
757 || needsGetter 756 || needsGetter
758 || needsSetter) { 757 || needsSetter) {
759 String fieldName = isShadowed 758 String accessorName = isShadowed
760 ? namer.shadowedFieldName(member) 759 ? namer.shadowedFieldName(member)
761 : namer.getName(member); 760 : namer.getName(member);
761 String fieldName = member.isNative()
762 ? member.nativeName()
763 : accessorName;
762 bool needsCheckedSetter = false; 764 bool needsCheckedSetter = false;
763 if (needsSetter && compiler.enableTypeAssertions 765 if (needsSetter && compiler.enableTypeAssertions
764 && canGenerateCheckedSetter(member)) { 766 && canGenerateCheckedSetter(member)) {
765 needsCheckedSetter = true; 767 needsCheckedSetter = true;
766 needsSetter = false; 768 needsSetter = false;
767 } 769 }
768 // Getters and setters with suffixes will be generated dynamically. 770 // Getters and setters with suffixes will be generated dynamically.
769 addField(member, 771 addField(member,
770 fieldName, 772 fieldName,
771 needsGetter, 773 needsGetter,
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 */ 1248 */
1247 void emitCallStubForGetter(Element member, 1249 void emitCallStubForGetter(Element member,
1248 Set<Selector> selectors, 1250 Set<Selector> selectors,
1249 DefineMemberFunction defineInstanceMember) { 1251 DefineMemberFunction defineInstanceMember) {
1250 assert(invariant(member, member.isDeclaration)); 1252 assert(invariant(member, member.isDeclaration));
1251 LibraryElement memberLibrary = member.getLibrary(); 1253 LibraryElement memberLibrary = member.getLibrary();
1252 String getter; 1254 String getter;
1253 if (member.isGetter()) { 1255 if (member.isGetter()) {
1254 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()"; 1256 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()";
1255 } else { 1257 } else {
1256 String name = namer.instanceFieldName(memberLibrary, member.name); 1258 String name = member.isNative()
1259 ? member.nativeName()
1260 : namer.instanceFieldName(memberLibrary, member.name);
1257 getter = "this.$name"; 1261 getter = "this.$name";
1258 } 1262 }
1259 for (Selector selector in selectors) { 1263 for (Selector selector in selectors) {
1260 if (selector.applies(member, compiler)) { 1264 if (selector.applies(member, compiler)) {
1261 String invocationName = 1265 String invocationName =
1262 namer.instanceMethodInvocationName(memberLibrary, member.name, 1266 namer.instanceMethodInvocationName(memberLibrary, member.name,
1263 selector); 1267 selector);
1264 SourceString callName = Namer.CLOSURE_INVOCATION_NAME; 1268 SourceString callName = Namer.CLOSURE_INVOCATION_NAME;
1265 String closureCallName = 1269 String closureCallName =
1266 namer.instanceMethodInvocationName(memberLibrary, callName, 1270 namer.instanceMethodInvocationName(memberLibrary, callName,
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 const String HOOKS_API_USAGE = """ 1779 const String HOOKS_API_USAGE = """
1776 // Generated by dart2js, the Dart to JavaScript compiler. 1780 // Generated by dart2js, the Dart to JavaScript compiler.
1777 // The code supports the following hooks: 1781 // The code supports the following hooks:
1778 // dartPrint(message) - if this function is defined it is called 1782 // dartPrint(message) - if this function is defined it is called
1779 // instead of the Dart [print] method. 1783 // instead of the Dart [print] method.
1780 // dartMainRunner(main) - if this function is defined, the Dart [main] 1784 // dartMainRunner(main) - if this function is defined, the Dart [main]
1781 // method will not be invoked directly. 1785 // method will not be invoked directly.
1782 // Instead, a closure that will invoke [main] is 1786 // Instead, a closure that will invoke [main] is
1783 // passed to [dartMainRunner]. 1787 // passed to [dartMainRunner].
1784 """; 1788 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698