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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/codegen.dart

Issue 11419250: Add @JSName annotation for native fields and methods - second try. (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 ssa; 5 part of ssa;
6 6
7 class SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 10
(...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 1725
1726 visitFieldGet(HFieldGet node) { 1726 visitFieldGet(HFieldGet node) {
1727 use(node.receiver); 1727 use(node.receiver);
1728 if (node.element == backend.jsArrayLength 1728 if (node.element == backend.jsArrayLength
1729 || node.element == backend.jsStringLength) { 1729 || node.element == backend.jsStringLength) {
1730 // We're accessing a native JavaScript property called 'length' 1730 // We're accessing a native JavaScript property called 'length'
1731 // on a JS String or a JS array. Therefore, the name of that 1731 // on a JS String or a JS array. Therefore, the name of that
1732 // property should not be mangled. 1732 // property should not be mangled.
1733 push(new js.PropertyAccess.field(pop(), 'length'), node); 1733 push(new js.PropertyAccess.field(pop(), 'length'), node);
1734 } else { 1734 } else {
1735 String name = backend.namer.getName(node.element); 1735 String name = _fieldPropertyName(node.element);
1736 push(new js.PropertyAccess.field(pop(), name), node); 1736 push(new js.PropertyAccess.field(pop(), name), node);
1737 HType receiverHType = types[node.receiver]; 1737 HType receiverHType = types[node.receiver];
1738 DartType type = receiverHType.computeType(compiler); 1738 DartType type = receiverHType.computeType(compiler);
1739 if (type != null) { 1739 if (type != null) {
1740 world.registerFieldGetter( 1740 world.registerFieldGetter(
1741 node.element.name, node.element.getLibrary(), type); 1741 node.element.name, node.element.getLibrary(), type);
1742 } 1742 }
1743 } 1743 }
1744 } 1744 }
1745 1745
1746 visitFieldSet(HFieldSet node) { 1746 visitFieldSet(HFieldSet node) {
1747 String name = backend.namer.getName(node.element); 1747 String name = _fieldPropertyName(node.element);
1748 DartType type = types[node.receiver].computeType(compiler); 1748 DartType type = types[node.receiver].computeType(compiler);
1749 if (type != null) { 1749 if (type != null) {
1750 // Field setters in the generative constructor body are handled in a 1750 // Field setters in the generative constructor body are handled in a
1751 // step "SsaConstructionFieldTypes" in the ssa optimizer. 1751 // step "SsaConstructionFieldTypes" in the ssa optimizer.
1752 if (!work.element.isGenerativeConstructorBody()) { 1752 if (!work.element.isGenerativeConstructorBody()) {
1753 world.registerFieldSetter( 1753 world.registerFieldSetter(
1754 node.element.name, node.element.getLibrary(), type); 1754 node.element.name, node.element.getLibrary(), type);
1755 backend.registerFieldSetter( 1755 backend.registerFieldSetter(
1756 work.element, node.element, types[node.value]); 1756 work.element, node.element, types[node.value]);
1757 } 1757 }
1758 } 1758 }
1759 use(node.receiver); 1759 use(node.receiver);
1760 js.Expression receiver = pop(); 1760 js.Expression receiver = pop();
1761 use(node.value); 1761 use(node.value);
1762 push(new js.Assignment(new js.PropertyAccess.field(receiver, name), pop()), 1762 push(new js.Assignment(new js.PropertyAccess.field(receiver, name), pop()),
1763 node); 1763 node);
1764 } 1764 }
1765 1765
1766 String _fieldPropertyName(Element element) => element.isNative()
1767 ? element.nativeName()
1768 : backend.namer.getName(element);
1769
1766 visitLocalGet(HLocalGet node) { 1770 visitLocalGet(HLocalGet node) {
1767 use(node.receiver); 1771 use(node.receiver);
1768 } 1772 }
1769 1773
1770 visitLocalSet(HLocalSet node) { 1774 visitLocalSet(HLocalSet node) {
1771 use(node.value); 1775 use(node.value);
1772 assignVariable(variableNames.getName(node.receiver), pop()); 1776 assignVariable(variableNames.getName(node.receiver), pop());
1773 } 1777 }
1774 1778
1775 visitForeign(HForeign node) { 1779 visitForeign(HForeign node) {
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 if (leftType.canBeNull() && rightType.canBeNull()) { 3034 if (leftType.canBeNull() && rightType.canBeNull()) {
3031 if (left.isConstantNull() || right.isConstantNull() || 3035 if (left.isConstantNull() || right.isConstantNull() ||
3032 (leftType.isPrimitive() && leftType == rightType)) { 3036 (leftType.isPrimitive() && leftType == rightType)) {
3033 return '=='; 3037 return '==';
3034 } 3038 }
3035 return null; 3039 return null;
3036 } else { 3040 } else {
3037 return '==='; 3041 return '===';
3038 } 3042 }
3039 } 3043 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698