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

Side by Side Diff: pkg/compiler/lib/src/kernel/kernel_visitor.dart

Issue 2338093002: Build entire program with kernel for conversion to ssa. (Closed)
Patch Set: Created 4 years, 3 months 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
OLDNEW
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 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 InterfaceType type, 1238 InterfaceType type,
1239 NodeList arguments, 1239 NodeList arguments,
1240 CallStructure callStructure, 1240 CallStructure callStructure,
1241 _) { 1241 _) {
1242 return new ir.InvalidExpression(); 1242 return new ir.InvalidExpression();
1243 } 1243 }
1244 1244
1245 @override 1245 @override
1246 ir.PropertyGet visitDynamicPropertyGet( 1246 ir.PropertyGet visitDynamicPropertyGet(
1247 Send node, Node receiver, Name name, _) { 1247 Send node, Node receiver, Name name, _) {
1248 return new ir.PropertyGet(visitForValue(receiver), nameToIrName(name)); 1248 return associateNode(
1249 new ir.PropertyGet(visitForValue(receiver), nameToIrName(name)), node);
1249 } 1250 }
1250 1251
1251 @override 1252 @override
1252 ir.MethodInvocation visitDynamicPropertyInvoke( 1253 ir.MethodInvocation visitDynamicPropertyInvoke(
1253 Send node, Node receiver, NodeList arguments, Selector selector, _) { 1254 Send node, Node receiver, NodeList arguments, Selector selector, _) {
1254 return buildInvokeSelector( 1255 return associateNode(
1255 visitForValue(receiver), selector, buildArguments(arguments)); 1256 buildInvokeSelector(
1257 visitForValue(receiver), selector, buildArguments(arguments)),
1258 node);
1256 } 1259 }
1257 1260
1258 @override 1261 @override
1259 ir.Expression handleDynamicCompounds( 1262 ir.Expression handleDynamicCompounds(
1260 Send node, Node receiver, Name name, CompoundRhs rhs, _) { 1263 Send node, Node receiver, Name name, CompoundRhs rhs, _) {
1261 ir.Expression receiverNode = 1264 ir.Expression receiverNode =
1262 receiver == null ? new ir.ThisExpression() : visitForValue(receiver); 1265 receiver == null ? new ir.ThisExpression() : visitForValue(receiver);
1263 return buildCompound( 1266 ir.Expression compound = associateNode(
1264 PropertyAccessor.make(receiverNode, nameToIrName(name), null, null), 1267 buildCompound(
1265 rhs); 1268 PropertyAccessor.make(receiverNode, nameToIrName(name), null, null),
1269 rhs),
1270 node);
1271 if (compound is ir.VariableSet) {
1272 associateNode(compound.value, node);
Siggi Cherem (dart-lang) 2016/09/13 23:48:19 in this case, should both compound and compound.va
Harry Terkelsen 2016/09/14 00:07:24 I think you're right, if it is a compound assignme
1273 }
1274 return compound;
1266 } 1275 }
1267 1276
1268 @override 1277 @override
1269 ir.PropertySet visitDynamicPropertySet( 1278 ir.PropertySet visitDynamicPropertySet(
1270 SendSet node, Node receiver, Name name, Node rhs, _) { 1279 SendSet node, Node receiver, Name name, Node rhs, _) {
1271 ir.Expression value = visitForValue(rhs); 1280 ir.Expression value = visitForValue(rhs);
1272 return new ir.PropertySet( 1281 return new ir.PropertySet(
1273 visitForValue(receiver), nameToIrName(name), value); 1282 visitForValue(receiver), nameToIrName(name), value);
1274 } 1283 }
1275 1284
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 } 1316 }
1308 1317
1309 ir.MethodInvocation buildBinaryOperator( 1318 ir.MethodInvocation buildBinaryOperator(
1310 Node left, String operator, Node right) { 1319 Node left, String operator, Node right) {
1311 ir.Name name = kernel.irName(operator, currentElement); 1320 ir.Name name = kernel.irName(operator, currentElement);
1312 return makeBinary(visitForValue(left), name, null, visitForValue(right)); 1321 return makeBinary(visitForValue(left), name, null, visitForValue(right));
1313 } 1322 }
1314 1323
1315 @override 1324 @override
1316 ir.MethodInvocation visitEquals(Send node, Node left, Node right, _) { 1325 ir.MethodInvocation visitEquals(Send node, Node left, Node right, _) {
1317 return buildBinaryOperator(left, '==', right); 1326 return associateNode(buildBinaryOperator(left, '==', right), node);
1318 } 1327 }
1319 1328
1320 @override 1329 @override
1321 ir.MethodInvocation visitExpressionInvoke(Send node, Node expression, 1330 ir.MethodInvocation visitExpressionInvoke(Send node, Node expression,
1322 NodeList arguments, CallStructure callStructure, _) { 1331 NodeList arguments, CallStructure callStructure, _) {
1323 return buildCall(visitForValue(expression), callStructure, arguments); 1332 return associateNode(
1333 buildCall(visitForValue(expression), callStructure, arguments), node);
1324 } 1334 }
1325 1335
1326 @override 1336 @override
1327 IrFunction visitFactoryConstructorDeclaration(FunctionExpression node, 1337 IrFunction visitFactoryConstructorDeclaration(FunctionExpression node,
1328 ConstructorElement constructor, NodeList parameters, Node body, _) { 1338 ConstructorElement constructor, NodeList parameters, Node body, _) {
1329 return buildIrFunction(ir.ProcedureKind.Factory, constructor, body); 1339 return buildIrFunction(ir.ProcedureKind.Factory, constructor, body);
1330 } 1340 }
1331 1341
1332 @override 1342 @override
1333 ir.InvocationExpression visitFactoryConstructorInvoke( 1343 ir.InvocationExpression visitFactoryConstructorInvoke(
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 kernel.functionToIr(superConstructor), new ir.Arguments.empty()); 1559 kernel.functionToIr(superConstructor), new ir.Arguments.empty());
1550 } 1560 }
1551 1561
1552 Accessor buildIndexAccessor(Node receiver, Node index) { 1562 Accessor buildIndexAccessor(Node receiver, Node index) {
1553 return IndexAccessor.make( 1563 return IndexAccessor.make(
1554 visitForValue(receiver), visitForValue(index), null, null); 1564 visitForValue(receiver), visitForValue(index), null, null);
1555 } 1565 }
1556 1566
1557 @override 1567 @override
1558 ir.Expression visitIndex(Send node, Node receiver, Node index, _) { 1568 ir.Expression visitIndex(Send node, Node receiver, Node index, _) {
1559 return buildIndexAccessor(receiver, index).buildSimpleRead(); 1569 return associateNode(
1570 buildIndexAccessor(receiver, index).buildSimpleRead(), node);
1560 } 1571 }
1561 1572
1562 ir.Expression buildIndexPostfix(Accessor accessor, IncDecOperator operator) { 1573 ir.Expression buildIndexPostfix(Accessor accessor, IncDecOperator operator) {
1563 ir.Name name = kernel.irName(operator.selectorName, currentElement); 1574 ir.Name name = kernel.irName(operator.selectorName, currentElement);
1564 return accessor.buildPostfixIncrement(name, voidContext: isVoidContext); 1575 return accessor.buildPostfixIncrement(name, voidContext: isVoidContext);
1565 } 1576 }
1566 1577
1567 @override 1578 @override
1568 ir.Expression visitIndexPostfix( 1579 ir.Expression visitIndexPostfix(
1569 Send node, Node receiver, Node index, IncDecOperator operator, _) { 1580 Send node, Node receiver, Node index, IncDecOperator operator, _) {
1570 return buildIndexPostfix(buildIndexAccessor(receiver, index), operator); 1581 return buildIndexPostfix(buildIndexAccessor(receiver, index), operator);
1571 } 1582 }
1572 1583
1573 ir.Expression buildIndexPrefix(Accessor accessor, IncDecOperator operator) { 1584 ir.Expression buildIndexPrefix(Accessor accessor, IncDecOperator operator) {
1574 ir.Name name = kernel.irName(operator.selectorName, currentElement); 1585 ir.Name name = kernel.irName(operator.selectorName, currentElement);
1575 return accessor.buildPrefixIncrement(name, voidContext: isVoidContext); 1586 return accessor.buildPrefixIncrement(name, voidContext: isVoidContext);
1576 } 1587 }
1577 1588
1578 @override 1589 @override
1579 ir.Expression visitIndexPrefix( 1590 ir.Expression visitIndexPrefix(
1580 Send node, Node receiver, Node index, IncDecOperator operator, _) { 1591 Send node, Node receiver, Node index, IncDecOperator operator, _) {
1581 return buildIndexPrefix(buildIndexAccessor(receiver, index), operator); 1592 return buildIndexPrefix(buildIndexAccessor(receiver, index), operator);
1582 } 1593 }
1583 1594
1584 @override 1595 @override
1585 ir.Expression visitIndexSet( 1596 ir.Expression visitIndexSet(
1586 SendSet node, Node receiver, Node index, Node rhs, _) { 1597 SendSet node, Node receiver, Node index, Node rhs, _) {
1587 return buildIndexAccessor(receiver, index) 1598 return associateNode(
1588 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); 1599 buildIndexAccessor(receiver, index)
1600 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext),
1601 node);
1589 } 1602 }
1590 1603
1591 ir.Initializer buildInitializingFormal(InitializingFormalElement parameter) { 1604 ir.Initializer buildInitializingFormal(InitializingFormalElement parameter) {
1592 FieldElement field = parameter.fieldElement; 1605 FieldElement field = parameter.fieldElement;
1593 if (kernel.isSyntheticError(field)) { 1606 if (kernel.isSyntheticError(field)) {
1594 return new ir.InvalidInitializer(); 1607 return new ir.InvalidInitializer();
1595 } else { 1608 } else {
1596 return new ir.FieldInitializer( 1609 return new ir.FieldInitializer(
1597 kernel.fieldToIr(field), buildLocalGet(parameter)); 1610 kernel.fieldToIr(field), buildLocalGet(parameter));
1598 } 1611 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 case CompoundKind.ASSIGNMENT: 1717 case CompoundKind.ASSIGNMENT:
1705 return accessor.buildCompoundAssignment(name, visitForValue(rhs.rhs), 1718 return accessor.buildCompoundAssignment(name, visitForValue(rhs.rhs),
1706 voidContext: isVoidContext); 1719 voidContext: isVoidContext);
1707 } 1720 }
1708 } 1721 }
1709 1722
1710 @override 1723 @override
1711 ir.Expression handleLocalCompounds( 1724 ir.Expression handleLocalCompounds(
1712 SendSet node, LocalElement local, CompoundRhs rhs, _, 1725 SendSet node, LocalElement local, CompoundRhs rhs, _,
1713 {bool isSetterValid}) { 1726 {bool isSetterValid}) {
1714 return buildCompound(new VariableAccessor(getLocal(local)), rhs); 1727 ir.Expression compound = associateNode(
1728 buildCompound(new VariableAccessor(getLocal(local)), rhs), node);
1729 if (compound is ir.VariableSet) {
1730 associateNode(compound.value, node);
1731 }
1732 return compound;
1715 } 1733 }
1716 1734
1717 @override 1735 @override
1718 ir.VariableSet handleLocalSet( 1736 ir.VariableSet handleLocalSet(
1719 SendSet node, LocalElement element, Node rhs, _) { 1737 SendSet node, LocalElement element, Node rhs, _) {
1720 return new ir.VariableSet(getLocal(element), visitForValue(rhs)); 1738 return new ir.VariableSet(getLocal(element), visitForValue(rhs));
1721 } 1739 }
1722 1740
1723 @override 1741 @override
1724 ir.VariableSet handleImmutableLocalSet( 1742 ir.VariableSet handleImmutableLocalSet(
(...skipping 29 matching lines...) Expand all
1754 return internalError(node, "NamedParameterDeclaration"); 1772 return internalError(node, "NamedParameterDeclaration");
1755 } 1773 }
1756 1774
1757 @override 1775 @override
1758 ir.Not visitNot(Send node, Node expression, _) { 1776 ir.Not visitNot(Send node, Node expression, _) {
1759 return new ir.Not(visitForValue(expression)); 1777 return new ir.Not(visitForValue(expression));
1760 } 1778 }
1761 1779
1762 @override 1780 @override
1763 ir.Not visitNotEquals(Send node, Node left, Node right, _) { 1781 ir.Not visitNotEquals(Send node, Node left, Node right, _) {
1764 return new ir.Not(buildBinaryOperator(left, '==', right)); 1782 return associateNode(
1783 new ir.Not(associateNode(buildBinaryOperator(left, '==', right), node)),
1784 node);
1765 } 1785 }
1766 1786
1767 @override 1787 @override
1768 ir.Initializer visitOptionalInitializingFormalDeclaration( 1788 ir.Initializer visitOptionalInitializingFormalDeclaration(
1769 VariableDefinitions node, 1789 VariableDefinitions node,
1770 Node definition, 1790 Node definition,
1771 InitializingFormalElement parameter, 1791 InitializingFormalElement parameter,
1772 ConstantExpression defaultValue, 1792 ConstantExpression defaultValue,
1773 int index, 1793 int index,
1774 _) { 1794 _) {
(...skipping 15 matching lines...) Expand all
1790 @override 1810 @override
1791 visitParameterDeclaration(VariableDefinitions node, Node definition, 1811 visitParameterDeclaration(VariableDefinitions node, Node definition,
1792 ParameterElement parameter, int index, _) { 1812 ParameterElement parameter, int index, _) {
1793 // Shouldn't be called, we handle parameters via [FunctionSignture]. 1813 // Shouldn't be called, we handle parameters via [FunctionSignture].
1794 return internalError(node, "ParameterDeclaration"); 1814 return internalError(node, "ParameterDeclaration");
1795 } 1815 }
1796 1816
1797 @override 1817 @override
1798 ir.MethodInvocation handleLocalInvoke(Send node, LocalElement element, 1818 ir.MethodInvocation handleLocalInvoke(Send node, LocalElement element,
1799 NodeList arguments, CallStructure callStructure, _) { 1819 NodeList arguments, CallStructure callStructure, _) {
1800 return buildCall(buildLocalGet(element), callStructure, arguments); 1820 return associateNode(
1821 buildCall(buildLocalGet(element), callStructure, arguments), node);
1801 } 1822 }
1802 1823
1803 @override 1824 @override
1804 ir.Expression handleLocalSetIfNulls( 1825 ir.Expression handleLocalSetIfNulls(
1805 SendSet node, LocalElement local, Node rhs, _, 1826 SendSet node, LocalElement local, Node rhs, _,
1806 {bool isSetterValid}) { 1827 {bool isSetterValid}) {
1807 return new VariableAccessor(getLocal(local)).buildNullAwareAssignment( 1828 return new VariableAccessor(getLocal(local)).buildNullAwareAssignment(
1808 visitForValue(rhs), 1829 visitForValue(rhs),
1809 voidContext: isVoidContext); 1830 voidContext: isVoidContext);
1810 } 1831 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 } 1913 }
1893 1914
1894 @override 1915 @override
1895 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) { 1916 ir.Expression handleStaticFieldGet(Send node, FieldElement field, _) {
1896 return buildStaticGet(field); 1917 return buildStaticGet(field);
1897 } 1918 }
1898 1919
1899 @override 1920 @override
1900 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field, 1921 ir.MethodInvocation handleStaticFieldInvoke(Send node, FieldElement field,
1901 NodeList arguments, CallStructure callStructure, _) { 1922 NodeList arguments, CallStructure callStructure, _) {
1902 return buildCall(buildStaticGet(field), callStructure, arguments); 1923 return associateNode(
1924 buildCall(buildStaticGet(field), callStructure, arguments), node);
1903 } 1925 }
1904 1926
1905 @override 1927 @override
1906 ir.Expression handleStaticFieldSet( 1928 ir.Expression handleStaticFieldSet(
1907 SendSet node, FieldElement field, Node rhs, _) { 1929 SendSet node, FieldElement field, Node rhs, _) {
1908 return buildStaticFieldSet(field, rhs); 1930 return buildStaticFieldSet(field, rhs);
1909 } 1931 }
1910 1932
1911 @override 1933 @override
1912 ir.Expression handleStaticSetIfNulls( 1934 ir.Expression handleStaticSetIfNulls(
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
2384 return buildSuperMethodInvoke(method, arguments); 2406 return buildSuperMethodInvoke(method, arguments);
2385 } 2407 }
2386 2408
2387 @override 2409 @override
2388 ir.SuperMethodInvocation visitSuperMethodInvoke( 2410 ir.SuperMethodInvocation visitSuperMethodInvoke(
2389 Send node, 2411 Send node,
2390 MethodElement method, 2412 MethodElement method,
2391 NodeList arguments, 2413 NodeList arguments,
2392 CallStructure callStructure, 2414 CallStructure callStructure,
2393 _) { 2415 _) {
2394 return buildSuperMethodInvoke(method, arguments); 2416 return associateNode(buildSuperMethodInvoke(method, arguments), node);
2395 } 2417 }
2396 2418
2397 @override 2419 @override
2398 ir.Expression visitSuperMethodSet( 2420 ir.Expression visitSuperMethodSet(
2399 Send node, MethodElement method, Node rhs, _) { 2421 Send node, MethodElement method, Node rhs, _) {
2400 return buildSuperPropertyAccessor(method) 2422 return buildSuperPropertyAccessor(method)
2401 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); 2423 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext);
2402 } 2424 }
2403 2425
2404 @override 2426 @override
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 Send node, NodeList arguments, CallStructure callStructure, _) { 2480 Send node, NodeList arguments, CallStructure callStructure, _) {
2459 return buildCall(new ir.ThisExpression(), callStructure, arguments); 2481 return buildCall(new ir.ThisExpression(), callStructure, arguments);
2460 } 2482 }
2461 2483
2462 Accessor buildThisPropertyAccessor(Name name) { 2484 Accessor buildThisPropertyAccessor(Name name) {
2463 return new ThisPropertyAccessor(nameToIrName(name), null, null); 2485 return new ThisPropertyAccessor(nameToIrName(name), null, null);
2464 } 2486 }
2465 2487
2466 @override 2488 @override
2467 ir.Expression visitThisPropertyGet(Send node, Name name, _) { 2489 ir.Expression visitThisPropertyGet(Send node, Name name, _) {
2468 return buildThisPropertyAccessor(name).buildSimpleRead(); 2490 return associateNode(
2491 buildThisPropertyAccessor(name).buildSimpleRead(), node);
2469 } 2492 }
2470 2493
2471 @override 2494 @override
2472 ir.MethodInvocation visitThisPropertyInvoke( 2495 ir.MethodInvocation visitThisPropertyInvoke(
2473 Send node, NodeList arguments, Selector selector, _) { 2496 Send node, NodeList arguments, Selector selector, _) {
2474 return buildInvokeSelector( 2497 return associateNode(
2475 new ir.ThisExpression(), selector, buildArguments(arguments)); 2498 buildInvokeSelector(
2499 new ir.ThisExpression(), selector, buildArguments(arguments)),
2500 node);
2476 } 2501 }
2477 2502
2478 @override 2503 @override
2479 ir.Expression visitThisPropertySet(SendSet node, Name name, Node rhs, _) { 2504 ir.Expression visitThisPropertySet(SendSet node, Name name, Node rhs, _) {
2480 return buildThisPropertyAccessor(name) 2505 return buildThisPropertyAccessor(name)
2481 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); 2506 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext);
2482 } 2507 }
2483 2508
2484 @override 2509 @override
2485 ir.Expression visitTopLevelConstantDeclaration(VariableDefinitions node, 2510 ir.Expression visitTopLevelConstantDeclaration(VariableDefinitions node,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 @override 2608 @override
2584 ir.Expression handleTypeLiteralConstantSetIfNulls( 2609 ir.Expression handleTypeLiteralConstantSetIfNulls(
2585 SendSet node, ConstantExpression constant, Node rhs, _) { 2610 SendSet node, ConstantExpression constant, Node rhs, _) {
2586 // Degenerate case: ignores [rhs] as a type literal is never null. 2611 // Degenerate case: ignores [rhs] as a type literal is never null.
2587 return buildTypeLiteral(constant); 2612 return buildTypeLiteral(constant);
2588 } 2613 }
2589 2614
2590 @override 2615 @override
2591 ir.MethodInvocation visitUnary( 2616 ir.MethodInvocation visitUnary(
2592 Send node, UnaryOperator operator, Node expression, _) { 2617 Send node, UnaryOperator operator, Node expression, _) {
2593 return new ir.MethodInvocation( 2618 return associateNode(
2594 visitForValue(expression), 2619 new ir.MethodInvocation(
2595 kernel.irName(operator.selectorName, currentElement), 2620 visitForValue(expression),
2596 new ir.Arguments.empty()); 2621 kernel.irName(operator.selectorName, currentElement),
2622 new ir.Arguments.empty()),
2623 node);
2597 } 2624 }
2598 2625
2599 @override 2626 @override
2600 visitConditionalUri(ConditionalUri node) { 2627 visitConditionalUri(ConditionalUri node) {
2601 // Shouldn't be called, handled by library loader. 2628 // Shouldn't be called, handled by library loader.
2602 return internalError(node, "ConditionalUri"); 2629 return internalError(node, "ConditionalUri");
2603 } 2630 }
2604 2631
2605 @override 2632 @override
2606 visitDottedName(DottedName node) { 2633 visitDottedName(DottedName node) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 : this(null, true, node, initializers); 2746 : this(null, true, node, initializers);
2720 2747
2721 accept(ir.Visitor v) => throw "unsupported"; 2748 accept(ir.Visitor v) => throw "unsupported";
2722 2749
2723 visitChildren(ir.Visitor v) => throw "unsupported"; 2750 visitChildren(ir.Visitor v) => throw "unsupported";
2724 2751
2725 String toString() { 2752 String toString() {
2726 return "IrFunction($kind, $isConstructor, $node, $initializers)"; 2753 return "IrFunction($kind, $isConstructor, $node, $initializers)";
2727 } 2754 }
2728 } 2755 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698