OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 import 'package:kernel/ast.dart' as ir; | 5 import 'package:kernel/ast.dart' as ir; |
6 import 'package:kernel/frontend/accessors.dart' | 6 import 'package:kernel/frontend/accessors.dart' |
7 show | 7 show |
8 Accessor, | 8 Accessor, |
9 IndexAccessor, | 9 IndexAccessor, |
10 NullAwarePropertyAccessor, | 10 NullAwarePropertyAccessor, |
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 ir.FunctionExpression function = | 1223 ir.FunctionExpression function = |
1224 new ir.FunctionExpression(buildFunctionNode(closure, body)); | 1224 new ir.FunctionExpression(buildFunctionNode(closure, body)); |
1225 kernel.localFunctions[closure] = function; | 1225 kernel.localFunctions[closure] = function; |
1226 return function; | 1226 return function; |
1227 }); | 1227 }); |
1228 } | 1228 } |
1229 | 1229 |
1230 @override | 1230 @override |
1231 ir.Expression visitCompoundIndexSet(SendSet node, Node receiver, Node index, | 1231 ir.Expression visitCompoundIndexSet(SendSet node, Node receiver, Node index, |
1232 AssignmentOperator operator, Node rhs, _) { | 1232 AssignmentOperator operator, Node rhs, _) { |
1233 // TODO(sra): Find binary operator. | 1233 return buildCompoundAssignment( |
1234 return buildIndexAccessor(receiver, index).buildCompoundAssignment( | 1234 node, |
| 1235 buildIndexAccessor(receiver, index), |
1235 kernel.irName(operator.selectorName, currentElement), | 1236 kernel.irName(operator.selectorName, currentElement), |
1236 visitForValue(rhs), | 1237 visitForValue(rhs)); |
1237 voidContext: isVoidContext); | |
1238 } | 1238 } |
1239 | 1239 |
1240 @override | 1240 @override |
1241 ir.InvocationExpression visitConstConstructorInvoke( | 1241 ir.InvocationExpression visitConstConstructorInvoke( |
1242 NewExpression node, ConstructedConstantExpression constant, _) { | 1242 NewExpression node, ConstructedConstantExpression constant, _) { |
1243 return buildConstructorInvoke(node, isConst: true); | 1243 return buildConstructorInvoke(node, isConst: true); |
1244 } | 1244 } |
1245 | 1245 |
1246 @override | 1246 @override |
1247 visitConstantGet(Send node, ConstantExpression constant, _) { | 1247 visitConstantGet(Send node, ConstantExpression constant, _) { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 return IndexAccessor.make( | 1576 return IndexAccessor.make( |
1577 visitForValue(receiver), visitForValue(index), null, null); | 1577 visitForValue(receiver), visitForValue(index), null, null); |
1578 } | 1578 } |
1579 | 1579 |
1580 @override | 1580 @override |
1581 ir.Expression visitIndex(Send node, Node receiver, Node index, _) { | 1581 ir.Expression visitIndex(Send node, Node receiver, Node index, _) { |
1582 return associateNode( | 1582 return associateNode( |
1583 buildIndexAccessor(receiver, index).buildSimpleRead(), node); | 1583 buildIndexAccessor(receiver, index).buildSimpleRead(), node); |
1584 } | 1584 } |
1585 | 1585 |
1586 ir.Expression buildIndexPostfix(Accessor accessor, IncDecOperator operator) { | 1586 ir.Expression buildIndexPostfix( |
| 1587 Send node, Accessor accessor, IncDecOperator operator) { |
1587 ir.Name name = kernel.irName(operator.selectorName, currentElement); | 1588 ir.Name name = kernel.irName(operator.selectorName, currentElement); |
1588 return accessor.buildPostfixIncrement(name, voidContext: isVoidContext); | 1589 return buildPostfixIncrement(node, accessor, name); |
1589 } | 1590 } |
1590 | 1591 |
1591 @override | 1592 @override |
1592 ir.Expression visitIndexPostfix( | 1593 ir.Expression visitIndexPostfix( |
1593 Send node, Node receiver, Node index, IncDecOperator operator, _) { | 1594 Send node, Node receiver, Node index, IncDecOperator operator, _) { |
1594 return buildIndexPostfix(buildIndexAccessor(receiver, index), operator); | 1595 return buildIndexPostfix( |
| 1596 node, buildIndexAccessor(receiver, index), operator); |
1595 } | 1597 } |
1596 | 1598 |
1597 ir.Expression buildIndexPrefix(Accessor accessor, IncDecOperator operator) { | 1599 ir.Expression buildIndexPrefix( |
| 1600 Send node, Accessor accessor, IncDecOperator operator) { |
1598 ir.Name name = kernel.irName(operator.selectorName, currentElement); | 1601 ir.Name name = kernel.irName(operator.selectorName, currentElement); |
1599 return accessor.buildPrefixIncrement(name, voidContext: isVoidContext); | 1602 return buildPrefixIncrement(node, accessor, name); |
1600 } | 1603 } |
1601 | 1604 |
1602 @override | 1605 @override |
1603 ir.Expression visitIndexPrefix( | 1606 ir.Expression visitIndexPrefix( |
1604 Send node, Node receiver, Node index, IncDecOperator operator, _) { | 1607 Send node, Node receiver, Node index, IncDecOperator operator, _) { |
1605 return buildIndexPrefix(buildIndexAccessor(receiver, index), operator); | 1608 return buildIndexPrefix( |
| 1609 node, buildIndexAccessor(receiver, index), operator); |
1606 } | 1610 } |
1607 | 1611 |
1608 @override | 1612 @override |
1609 ir.Expression visitIndexSet( | 1613 ir.Expression visitIndexSet( |
1610 SendSet node, Node receiver, Node index, Node rhs, _) { | 1614 SendSet node, Node receiver, Node index, Node rhs, _) { |
1611 return associateNode( | 1615 return associateNode( |
1612 buildIndexAccessor(receiver, index) | 1616 buildIndexAccessor(receiver, index) |
1613 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext), | 1617 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext), |
1614 node); | 1618 node); |
1615 } | 1619 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1718 } | 1722 } |
1719 | 1723 |
1720 @override | 1724 @override |
1721 ir.VariableGet handleLocalGet(Send node, LocalElement element, _) { | 1725 ir.VariableGet handleLocalGet(Send node, LocalElement element, _) { |
1722 return buildLocalGet(element); | 1726 return buildLocalGet(element); |
1723 } | 1727 } |
1724 | 1728 |
1725 ir.Expression buildCompound( | 1729 ir.Expression buildCompound( |
1726 Accessor accessor, CompoundRhs rhs, SendSet node) { | 1730 Accessor accessor, CompoundRhs rhs, SendSet node) { |
1727 ir.Name name = kernel.irName(rhs.operator.selectorName, currentElement); | 1731 ir.Name name = kernel.irName(rhs.operator.selectorName, currentElement); |
1728 ir.Expression result; | |
1729 switch (rhs.kind) { | 1732 switch (rhs.kind) { |
1730 case CompoundKind.POSTFIX: | 1733 case CompoundKind.POSTFIX: |
1731 result = | 1734 return buildPostfixIncrement(node, accessor, name); |
1732 accessor.buildPostfixIncrement(name, voidContext: isVoidContext); | |
1733 break; | |
1734 | 1735 |
1735 case CompoundKind.PREFIX: | 1736 case CompoundKind.PREFIX: |
1736 result = | 1737 return buildPrefixIncrement(node, accessor, name); |
1737 accessor.buildPrefixIncrement(name, voidContext: isVoidContext); | |
1738 break; | |
1739 | 1738 |
1740 case CompoundKind.ASSIGNMENT: | 1739 case CompoundKind.ASSIGNMENT: |
1741 result = accessor.buildCompoundAssignment(name, visitForValue(rhs.rhs), | 1740 return buildCompoundAssignment( |
1742 voidContext: isVoidContext); | 1741 node, accessor, name, visitForValue(rhs.rhs)); |
1743 break; | |
1744 } | 1742 } |
| 1743 } |
| 1744 |
| 1745 ir.Expression buildCompoundAssignment( |
| 1746 SendSet node, Accessor accessor, ir.Name name, ir.Expression rhs) { |
| 1747 ir.Expression result = |
| 1748 accessor.buildCompoundAssignment(name, rhs, voidContext: isVoidContext); |
| 1749 associateCompoundComponents(accessor, node); |
| 1750 return result; |
| 1751 } |
| 1752 |
| 1753 ir.Expression buildPrefixIncrement( |
| 1754 SendSet node, Accessor accessor, ir.Name name) { |
| 1755 ir.Expression result = |
| 1756 accessor.buildPrefixIncrement(name, voidContext: isVoidContext); |
| 1757 associateCompoundComponents(accessor, node); |
| 1758 return result; |
| 1759 } |
| 1760 |
| 1761 ir.Expression buildPostfixIncrement( |
| 1762 SendSet node, Accessor accessor, ir.Name name) { |
| 1763 ir.Expression result = |
| 1764 accessor.buildPostfixIncrement(name, voidContext: isVoidContext); |
| 1765 associateCompoundComponents(accessor, node); |
| 1766 return result; |
| 1767 } |
| 1768 |
| 1769 void associateCompoundComponents(Accessor accessor, Node node) { |
1745 assert(accessor.builtBinary != null); | 1770 assert(accessor.builtBinary != null); |
1746 kernel.nodeToAstOperator[accessor.builtBinary] = node; | 1771 kernel.nodeToAstOperator[accessor.builtBinary] = node; |
1747 if (accessor.builtGetter != null) { | 1772 if (accessor.builtGetter != null) { |
1748 kernel.nodeToAst[accessor.builtGetter] = node; | 1773 kernel.nodeToAst[accessor.builtGetter] = node; |
1749 } | 1774 } |
1750 return result; | |
1751 } | 1775 } |
1752 | 1776 |
1753 @override | 1777 @override |
1754 ir.Expression handleLocalCompounds( | 1778 ir.Expression handleLocalCompounds( |
1755 SendSet node, LocalElement local, CompoundRhs rhs, _, | 1779 SendSet node, LocalElement local, CompoundRhs rhs, _, |
1756 {bool isSetterValid}) { | 1780 {bool isSetterValid}) { |
1757 ir.Expression compound = | 1781 ir.Expression compound = |
1758 buildCompound(new VariableAccessor(getLocal(local)), rhs, node); | 1782 buildCompound(new VariableAccessor(getLocal(local)), rhs, node); |
1759 if (compound is ir.VariableSet) { | 1783 if (compound is ir.VariableSet) { |
1760 associateNode(compound.value, node); | 1784 associateNode(compound.value, node); |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2245 | 2269 |
2246 @override | 2270 @override |
2247 ir.Expression visitSuperCompoundIndexSet( | 2271 ir.Expression visitSuperCompoundIndexSet( |
2248 SendSet node, | 2272 SendSet node, |
2249 MethodElement getter, | 2273 MethodElement getter, |
2250 MethodElement setter, | 2274 MethodElement setter, |
2251 Node index, | 2275 Node index, |
2252 AssignmentOperator operator, | 2276 AssignmentOperator operator, |
2253 Node rhs, | 2277 Node rhs, |
2254 _) { | 2278 _) { |
2255 // TODO(sra): Find binary operator. | 2279 return buildCompoundAssignment( |
2256 return buildSuperIndexAccessor(index, getter, setter) | 2280 node, |
2257 .buildCompoundAssignment( | 2281 buildSuperIndexAccessor(index, getter, setter), |
2258 kernel.irName(operator.selectorName, currentElement), | 2282 kernel.irName(operator.selectorName, currentElement), |
2259 visitForValue(rhs), | 2283 visitForValue(rhs)); |
2260 voidContext: isVoidContext); | |
2261 } | 2284 } |
2262 | 2285 |
2263 @override | 2286 @override |
2264 ir.Initializer visitSuperConstructorInvoke( | 2287 ir.Initializer visitSuperConstructorInvoke( |
2265 Send node, | 2288 Send node, |
2266 ConstructorElement superConstructor, | 2289 ConstructorElement superConstructor, |
2267 InterfaceType type, | 2290 InterfaceType type, |
2268 NodeList arguments, | 2291 NodeList arguments, |
2269 CallStructure callStructure, | 2292 CallStructure callStructure, |
2270 _) { | 2293 _) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2429 ir.SuperMethodInvocation visitSuperIndex( | 2452 ir.SuperMethodInvocation visitSuperIndex( |
2430 Send node, FunctionElement function, Node index, _) { | 2453 Send node, FunctionElement function, Node index, _) { |
2431 return buildSuperIndexAccessor(index, function).buildSimpleRead(); | 2454 return buildSuperIndexAccessor(index, function).buildSimpleRead(); |
2432 } | 2455 } |
2433 | 2456 |
2434 @override | 2457 @override |
2435 ir.Expression visitSuperIndexPostfix(Send node, MethodElement indexFunction, | 2458 ir.Expression visitSuperIndexPostfix(Send node, MethodElement indexFunction, |
2436 MethodElement indexSetFunction, Node index, IncDecOperator operator, _) { | 2459 MethodElement indexSetFunction, Node index, IncDecOperator operator, _) { |
2437 Accessor accessor = | 2460 Accessor accessor = |
2438 buildSuperIndexAccessor(index, indexFunction, indexSetFunction); | 2461 buildSuperIndexAccessor(index, indexFunction, indexSetFunction); |
2439 return buildIndexPostfix(accessor, operator); | 2462 return buildIndexPostfix(node, accessor, operator); |
2440 } | 2463 } |
2441 | 2464 |
2442 @override | 2465 @override |
2443 ir.Expression visitSuperIndexPrefix(Send node, MethodElement indexFunction, | 2466 ir.Expression visitSuperIndexPrefix(Send node, MethodElement indexFunction, |
2444 MethodElement indexSetFunction, Node index, IncDecOperator operator, _) { | 2467 MethodElement indexSetFunction, Node index, IncDecOperator operator, _) { |
2445 Accessor accessor = | 2468 Accessor accessor = |
2446 buildSuperIndexAccessor(index, indexFunction, indexSetFunction); | 2469 buildSuperIndexAccessor(index, indexFunction, indexSetFunction); |
2447 return buildIndexPrefix(accessor, operator); | 2470 return buildIndexPrefix(node, accessor, operator); |
2448 } | 2471 } |
2449 | 2472 |
2450 @override | 2473 @override |
2451 ir.Expression visitSuperIndexSet( | 2474 ir.Expression visitSuperIndexSet( |
2452 SendSet node, FunctionElement function, Node index, Node rhs, _) { | 2475 SendSet node, FunctionElement function, Node index, Node rhs, _) { |
2453 return buildSuperIndexAccessor(index, null, function) | 2476 return buildSuperIndexAccessor(index, null, function) |
2454 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 2477 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
2455 } | 2478 } |
2456 | 2479 |
2457 @override | 2480 @override |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2817 : this(null, true, node, initializers); | 2840 : this(null, true, node, initializers); |
2818 | 2841 |
2819 accept(ir.Visitor v) => throw "unsupported"; | 2842 accept(ir.Visitor v) => throw "unsupported"; |
2820 | 2843 |
2821 visitChildren(ir.Visitor v) => throw "unsupported"; | 2844 visitChildren(ir.Visitor v) => throw "unsupported"; |
2822 | 2845 |
2823 String toString() { | 2846 String toString() { |
2824 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 2847 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
2825 } | 2848 } |
2826 } | 2849 } |
OLD | NEW |