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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/codegen.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 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 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 1715
1716 visitFieldGet(HFieldGet node) { 1716 visitFieldGet(HFieldGet node) {
1717 use(node.receiver); 1717 use(node.receiver);
1718 if (node.element == backend.jsArrayLength 1718 if (node.element == backend.jsArrayLength
1719 || node.element == backend.jsStringLength) { 1719 || node.element == backend.jsStringLength) {
1720 // We're accessing a native JavaScript property called 'length' 1720 // We're accessing a native JavaScript property called 'length'
1721 // on a JS String or a JS array. Therefore, the name of that 1721 // on a JS String or a JS array. Therefore, the name of that
1722 // property should not be mangled. 1722 // property should not be mangled.
1723 push(new js.PropertyAccess.field(pop(), 'length'), node); 1723 push(new js.PropertyAccess.field(pop(), 'length'), node);
1724 } else { 1724 } else {
1725 String name = backend.namer.getName(node.element); 1725 String name = _fieldPropertyName(node.element);
1726 push(new js.PropertyAccess.field(pop(), name), node); 1726 push(new js.PropertyAccess.field(pop(), name), node);
1727 HType receiverHType = types[node.receiver]; 1727 HType receiverHType = types[node.receiver];
1728 DartType type = receiverHType.computeType(compiler); 1728 DartType type = receiverHType.computeType(compiler);
1729 if (type != null) { 1729 if (type != null) {
1730 world.registerFieldGetter( 1730 world.registerFieldGetter(
1731 node.element.name, node.element.getLibrary(), type); 1731 node.element.name, node.element.getLibrary(), type);
1732 } 1732 }
1733 } 1733 }
1734 } 1734 }
1735 1735
1736 visitFieldSet(HFieldSet node) { 1736 visitFieldSet(HFieldSet node) {
1737 String name = backend.namer.getName(node.element); 1737 String name = _fieldPropertyName(node.element);
1738 DartType type = types[node.receiver].computeType(compiler); 1738 DartType type = types[node.receiver].computeType(compiler);
1739 if (type != null) { 1739 if (type != null) {
1740 // Field setters in the generative constructor body are handled in a 1740 // Field setters in the generative constructor body are handled in a
1741 // step "SsaConstructionFieldTypes" in the ssa optimizer. 1741 // step "SsaConstructionFieldTypes" in the ssa optimizer.
1742 if (!work.element.isGenerativeConstructorBody()) { 1742 if (!work.element.isGenerativeConstructorBody()) {
1743 world.registerFieldSetter( 1743 world.registerFieldSetter(
1744 node.element.name, node.element.getLibrary(), type); 1744 node.element.name, node.element.getLibrary(), type);
1745 backend.registerFieldSetter( 1745 backend.registerFieldSetter(
1746 work.element, node.element, types[node.value]); 1746 work.element, node.element, types[node.value]);
1747 } 1747 }
1748 } 1748 }
1749 use(node.receiver); 1749 use(node.receiver);
1750 js.Expression receiver = pop(); 1750 js.Expression receiver = pop();
1751 use(node.value); 1751 use(node.value);
1752 push(new js.Assignment(new js.PropertyAccess.field(receiver, name), pop()), 1752 push(new js.Assignment(new js.PropertyAccess.field(receiver, name), pop()),
1753 node); 1753 node);
1754 } 1754 }
1755 1755
1756 String _fieldPropertyName(Element element) => element.isNative()
1757 ? element.nativeName()
1758 : backend.namer.getName(element);
1759
1756 visitLocalGet(HLocalGet node) { 1760 visitLocalGet(HLocalGet node) {
1757 use(node.receiver); 1761 use(node.receiver);
1758 } 1762 }
1759 1763
1760 visitLocalSet(HLocalSet node) { 1764 visitLocalSet(HLocalSet node) {
1761 use(node.value); 1765 use(node.value);
1762 assignVariable(variableNames.getName(node.receiver), pop()); 1766 assignVariable(variableNames.getName(node.receiver), pop());
1763 } 1767 }
1764 1768
1765 visitForeign(HForeign node) { 1769 visitForeign(HForeign node) {
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 if (leftType.canBeNull() && rightType.canBeNull()) { 3024 if (leftType.canBeNull() && rightType.canBeNull()) {
3021 if (left.isConstantNull() || right.isConstantNull() || 3025 if (left.isConstantNull() || right.isConstantNull() ||
3022 (leftType.isPrimitive() && leftType == rightType)) { 3026 (leftType.isPrimitive() && leftType == rightType)) {
3023 return '=='; 3027 return '==';
3024 } 3028 }
3025 return null; 3029 return null;
3026 } else { 3030 } else {
3027 return '==='; 3031 return '===';
3028 } 3032 }
3029 } 3033 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698