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 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 Loading... |
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 = _fieldPropertyName(node.element); | 1725 String name = backend.namer.getName(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 = _fieldPropertyName(node.element); | 1737 String name = backend.namer.getName(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 | |
1760 visitLocalGet(HLocalGet node) { | 1756 visitLocalGet(HLocalGet node) { |
1761 use(node.receiver); | 1757 use(node.receiver); |
1762 } | 1758 } |
1763 | 1759 |
1764 visitLocalSet(HLocalSet node) { | 1760 visitLocalSet(HLocalSet node) { |
1765 use(node.value); | 1761 use(node.value); |
1766 assignVariable(variableNames.getName(node.receiver), pop()); | 1762 assignVariable(variableNames.getName(node.receiver), pop()); |
1767 } | 1763 } |
1768 | 1764 |
1769 visitForeign(HForeign node) { | 1765 visitForeign(HForeign node) { |
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3024 if (leftType.canBeNull() && rightType.canBeNull()) { | 3020 if (leftType.canBeNull() && rightType.canBeNull()) { |
3025 if (left.isConstantNull() || right.isConstantNull() || | 3021 if (left.isConstantNull() || right.isConstantNull() || |
3026 (leftType.isPrimitive() && leftType == rightType)) { | 3022 (leftType.isPrimitive() && leftType == rightType)) { |
3027 return '=='; | 3023 return '=='; |
3028 } | 3024 } |
3029 return null; | 3025 return null; |
3030 } else { | 3026 } else { |
3031 return '==='; | 3027 return '==='; |
3032 } | 3028 } |
3033 } | 3029 } |
OLD | NEW |