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

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: Fix _NodeList 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 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 bool needsGetter, 743 bool needsGetter,
744 bool needsSetter, 744 bool needsSetter,
745 bool needsCheckedSetter)) { 745 bool needsCheckedSetter)) {
746 assert(invariant(classElement, classElement.isDeclaration)); 746 assert(invariant(classElement, classElement.isDeclaration));
747 // If the class is never instantiated we still need to set it up for 747 // If the class is never instantiated we still need to set it up for
748 // inheritance purposes, but we can simplify its JavaScript constructor. 748 // inheritance purposes, but we can simplify its JavaScript constructor.
749 bool isInstantiated = 749 bool isInstantiated =
750 compiler.codegenWorld.instantiatedClasses.contains(classElement); 750 compiler.codegenWorld.instantiatedClasses.contains(classElement);
751 751
752 void visitField(ClassElement enclosingClass, Element member) { 752 void visitField(ClassElement enclosingClass, Element member) {
753 assert(!member.isNative());
754 assert(invariant(classElement, member.isDeclaration)); 753 assert(invariant(classElement, member.isDeclaration));
755 754
756 LibraryElement library = member.getLibrary(); 755 LibraryElement library = member.getLibrary();
757 SourceString name = member.name; 756 SourceString name = member.name;
758 bool isPrivate = name.isPrivate(); 757 bool isPrivate = name.isPrivate();
759 // See if we can dynamically create getters and setters. 758 // See if we can dynamically create getters and setters.
760 // We can only generate getters and setters for [classElement] since 759 // We can only generate getters and setters for [classElement] since
761 // the fields of super classes could be overwritten with getters or 760 // the fields of super classes could be overwritten with getters or
762 // setters. 761 // setters.
763 bool needsGetter = false; 762 bool needsGetter = false;
764 bool needsSetter = false; 763 bool needsSetter = false;
765 // We need to name shadowed fields differently, so they don't clash with 764 // We need to name shadowed fields differently, so they don't clash with
766 // the non-shadowed field. 765 // the non-shadowed field.
767 bool isShadowed = false; 766 bool isShadowed = false;
768 if (identical(enclosingClass, classElement)) { 767 if (identical(enclosingClass, classElement)) {
769 needsGetter = instanceFieldNeedsGetter(member); 768 needsGetter = instanceFieldNeedsGetter(member);
770 needsSetter = instanceFieldNeedsSetter(member); 769 needsSetter = instanceFieldNeedsSetter(member);
771 } else { 770 } else {
772 isShadowed = classElement.isShadowedByField(member); 771 isShadowed = classElement.isShadowedByField(member);
773 } 772 }
774 773
775 if ((isInstantiated && !enclosingClass.isNative()) 774 if ((isInstantiated && !enclosingClass.isNative())
776 || needsGetter 775 || needsGetter
777 || needsSetter) { 776 || needsSetter) {
778 String accessorName = isShadowed 777 String accessorName = isShadowed
779 ? namer.shadowedFieldName(member) 778 ? namer.shadowedFieldName(member)
780 : namer.getName(member); 779 : namer.getName(member);
781 String fieldName = enclosingClass.isNative() ? 780 String fieldName = member.isNative()
782 member.name.slowToString() : accessorName; 781 ? member.nativeName()
782 : accessorName;
ngeoffray 2012/11/28 20:31:23 fits in one line now?
sra1 2012/12/04 01:31:31 Not quite.
783 bool needsCheckedSetter = false; 783 bool needsCheckedSetter = false;
784 if (needsSetter && compiler.enableTypeAssertions 784 if (needsSetter && compiler.enableTypeAssertions
785 && canGenerateCheckedSetter(member)) { 785 && canGenerateCheckedSetter(member)) {
786 needsCheckedSetter = true; 786 needsCheckedSetter = true;
787 needsSetter = false; 787 needsSetter = false;
788 } 788 }
789 // Getters and setters with suffixes will be generated dynamically. 789 // Getters and setters with suffixes will be generated dynamically.
790 addField(member, 790 addField(member,
791 fieldName, 791 fieldName,
792 accessorName, 792 accessorName,
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 */ 1282 */
1283 void emitCallStubForGetter(Element member, 1283 void emitCallStubForGetter(Element member,
1284 Set<Selector> selectors, 1284 Set<Selector> selectors,
1285 DefineMemberFunction defineInstanceMember) { 1285 DefineMemberFunction defineInstanceMember) {
1286 assert(invariant(member, member.isDeclaration)); 1286 assert(invariant(member, member.isDeclaration));
1287 LibraryElement memberLibrary = member.getLibrary(); 1287 LibraryElement memberLibrary = member.getLibrary();
1288 String getter; 1288 String getter;
1289 if (member.isGetter()) { 1289 if (member.isGetter()) {
1290 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()"; 1290 getter = "this.${namer.getterName(member.getLibrary(), member.name)}()";
1291 } else { 1291 } else {
1292 String name = namer.instanceFieldName(memberLibrary, member.name); 1292 String name = member.isNative()
1293 ? member.nativeName()
1294 : namer.instanceFieldName(memberLibrary, member.name);
1293 getter = "this.$name"; 1295 getter = "this.$name";
1294 } 1296 }
1295 for (Selector selector in selectors) { 1297 for (Selector selector in selectors) {
1296 if (selector.applies(member, compiler)) { 1298 if (selector.applies(member, compiler)) {
1297 String invocationName = 1299 String invocationName =
1298 namer.instanceMethodInvocationName(memberLibrary, member.name, 1300 namer.instanceMethodInvocationName(memberLibrary, member.name,
1299 selector); 1301 selector);
1300 SourceString callName = namer.CLOSURE_INVOCATION_NAME; 1302 SourceString callName = namer.CLOSURE_INVOCATION_NAME;
1301 String closureCallName = 1303 String closureCallName =
1302 namer.instanceMethodInvocationName(memberLibrary, callName, 1304 namer.instanceMethodInvocationName(memberLibrary, callName,
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 const String HOOKS_API_USAGE = """ 1806 const String HOOKS_API_USAGE = """
1805 // Generated by dart2js, the Dart to JavaScript compiler. 1807 // Generated by dart2js, the Dart to JavaScript compiler.
1806 // The code supports the following hooks: 1808 // The code supports the following hooks:
1807 // dartPrint(message) - if this function is defined it is called 1809 // dartPrint(message) - if this function is defined it is called
1808 // instead of the Dart [print] method. 1810 // instead of the Dart [print] method.
1809 // dartMainRunner(main) - if this function is defined, the Dart [main] 1811 // dartMainRunner(main) - if this function is defined, the Dart [main]
1810 // method will not be invoked directly. 1812 // method will not be invoked directly.
1811 // Instead, a closure that will invoke [main] is 1813 // Instead, a closure that will invoke [main] is
1812 // passed to [dartMainRunner]. 1814 // passed to [dartMainRunner].
1813 """; 1815 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698