| 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 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 visitForValue(receiver), nameToIrName(name), value); | 1311 visitForValue(receiver), nameToIrName(name), value); |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 @override | 1314 @override |
| 1315 ir.Expression handleDynamicSetIfNulls( | 1315 ir.Expression handleDynamicSetIfNulls( |
| 1316 Send node, Node receiver, Name name, Node rhs, _) { | 1316 Send node, Node receiver, Name name, Node rhs, _) { |
| 1317 ir.Name irName = nameToIrName(name); | 1317 ir.Name irName = nameToIrName(name); |
| 1318 Accessor accessor = (receiver == null) | 1318 Accessor accessor = (receiver == null) |
| 1319 ? new ThisPropertyAccessor(irName, null, null) | 1319 ? new ThisPropertyAccessor(irName, null, null) |
| 1320 : PropertyAccessor.make(visitForValue(receiver), irName, null, null); | 1320 : PropertyAccessor.make(visitForValue(receiver), irName, null, null); |
| 1321 return accessor.buildNullAwareAssignment(visitForValue(rhs), null, | 1321 return _finishSetIfNull(node, accessor, rhs); |
| 1322 } |
| 1323 |
| 1324 ir.Expression _finishSetIfNull(Send node, Accessor accessor, Node rhs) { |
| 1325 ir.Expression result = accessor.buildNullAwareAssignment( |
| 1326 visitForValue(rhs), null, |
| 1322 voidContext: isVoidContext); | 1327 voidContext: isVoidContext); |
| 1328 if (accessor.builtGetter != null) { |
| 1329 kernel.nodeToAst[accessor.builtGetter] = node; |
| 1330 } |
| 1331 return result; |
| 1323 } | 1332 } |
| 1324 | 1333 |
| 1325 @override | 1334 @override |
| 1326 ir.TypeLiteral visitDynamicTypeLiteralGet( | 1335 ir.TypeLiteral visitDynamicTypeLiteralGet( |
| 1327 Send node, ConstantExpression constant, _) { | 1336 Send node, ConstantExpression constant, _) { |
| 1328 return buildTypeLiteral(constant); | 1337 return buildTypeLiteral(constant); |
| 1329 } | 1338 } |
| 1330 | 1339 |
| 1331 @override | 1340 @override |
| 1332 ir.MethodInvocation visitDynamicTypeLiteralInvoke( | 1341 ir.MethodInvocation visitDynamicTypeLiteralInvoke( |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 @override | 1553 @override |
| 1545 ir.Expression visitIfNotNullDynamicPropertySet( | 1554 ir.Expression visitIfNotNullDynamicPropertySet( |
| 1546 SendSet node, Node receiver, Name name, Node rhs, _) { | 1555 SendSet node, Node receiver, Name name, Node rhs, _) { |
| 1547 return buildNullAwarePropertyAccessor(receiver, name) | 1556 return buildNullAwarePropertyAccessor(receiver, name) |
| 1548 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 1557 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
| 1549 } | 1558 } |
| 1550 | 1559 |
| 1551 @override | 1560 @override |
| 1552 ir.Expression visitIfNotNullDynamicPropertySetIfNull( | 1561 ir.Expression visitIfNotNullDynamicPropertySetIfNull( |
| 1553 Send node, Node receiver, Name name, Node rhs, _) { | 1562 Send node, Node receiver, Name name, Node rhs, _) { |
| 1554 return buildNullAwarePropertyAccessor(receiver, name) | 1563 return _finishSetIfNull( |
| 1555 .buildNullAwareAssignment(visitForValue(rhs), null, | 1564 node, buildNullAwarePropertyAccessor(receiver, name), rhs); |
| 1556 voidContext: isVoidContext); | |
| 1557 } | 1565 } |
| 1558 | 1566 |
| 1559 ir.LogicalExpression buildLogicalExpression( | 1567 ir.LogicalExpression buildLogicalExpression( |
| 1560 Node left, Operator operator, Node right) { | 1568 Node left, Operator operator, Node right) { |
| 1561 return new ir.LogicalExpression( | 1569 return new ir.LogicalExpression( |
| 1562 visitForValue(left), operator.source, visitForValue(right)); | 1570 visitForValue(left), operator.source, visitForValue(right)); |
| 1563 } | 1571 } |
| 1564 | 1572 |
| 1565 @override | 1573 @override |
| 1566 ir.Expression visitIfNull(Send node, Node left, Node right, _) { | 1574 ir.Expression visitIfNull(Send node, Node left, Node right, _) { |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 ir.MethodInvocation handleLocalInvoke(Send node, LocalElement element, | 1893 ir.MethodInvocation handleLocalInvoke(Send node, LocalElement element, |
| 1886 NodeList arguments, CallStructure callStructure, _) { | 1894 NodeList arguments, CallStructure callStructure, _) { |
| 1887 return associateNode( | 1895 return associateNode( |
| 1888 buildCall(buildLocalGet(element), callStructure, arguments), node); | 1896 buildCall(buildLocalGet(element), callStructure, arguments), node); |
| 1889 } | 1897 } |
| 1890 | 1898 |
| 1891 @override | 1899 @override |
| 1892 ir.Expression handleLocalSetIfNulls( | 1900 ir.Expression handleLocalSetIfNulls( |
| 1893 SendSet node, LocalElement local, Node rhs, _, | 1901 SendSet node, LocalElement local, Node rhs, _, |
| 1894 {bool isSetterValid}) { | 1902 {bool isSetterValid}) { |
| 1895 return new VariableAccessor(getLocal(local)).buildNullAwareAssignment( | 1903 return _finishSetIfNull(node, new VariableAccessor(getLocal(local)), rhs); |
| 1896 visitForValue(rhs), null, | |
| 1897 voidContext: isVoidContext); | |
| 1898 } | 1904 } |
| 1899 | 1905 |
| 1900 @override | 1906 @override |
| 1901 IrFunction visitRedirectingFactoryConstructorDeclaration( | 1907 IrFunction visitRedirectingFactoryConstructorDeclaration( |
| 1902 FunctionExpression node, | 1908 FunctionExpression node, |
| 1903 ConstructorElement constructor, | 1909 ConstructorElement constructor, |
| 1904 NodeList parameters, | 1910 NodeList parameters, |
| 1905 ResolutionDartType redirectionType, // TODO(ahe): Should be InterfaceType. | 1911 ResolutionDartType redirectionType, // TODO(ahe): Should be InterfaceType. |
| 1906 ConstructorElement redirectionTarget, | 1912 ConstructorElement redirectionTarget, |
| 1907 _) { | 1913 _) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2002 SendSet node, | 2008 SendSet node, |
| 2003 Element getter, | 2009 Element getter, |
| 2004 CompoundGetter getterKind, | 2010 CompoundGetter getterKind, |
| 2005 Element setter, | 2011 Element setter, |
| 2006 CompoundSetter setterKind, | 2012 CompoundSetter setterKind, |
| 2007 Node rhs, | 2013 Node rhs, |
| 2008 _) { | 2014 _) { |
| 2009 if (setterKind == CompoundSetter.INVALID) { | 2015 if (setterKind == CompoundSetter.INVALID) { |
| 2010 setter = null; | 2016 setter = null; |
| 2011 } | 2017 } |
| 2012 return buildStaticAccessor(getter, setter).buildNullAwareAssignment( | 2018 return _finishSetIfNull(node, buildStaticAccessor(getter, setter), rhs); |
| 2013 visitForValue(rhs), null, | |
| 2014 voidContext: isVoidContext); | |
| 2015 } | 2019 } |
| 2016 | 2020 |
| 2017 ir.VariableDeclaration getLocal(LocalElement local) { | 2021 ir.VariableDeclaration getLocal(LocalElement local) { |
| 2018 return locals.putIfAbsent(local, () { | 2022 return locals.putIfAbsent(local, () { |
| 2019 // Currently, initializing formals are not final. | 2023 // Currently, initializing formals are not final. |
| 2020 bool isFinal = local.isFinal && !local.isInitializingFormal; | 2024 bool isFinal = local.isFinal && !local.isInitializingFormal; |
| 2021 return associateElement( | 2025 return associateElement( |
| 2022 new ir.VariableDeclaration(local.name, | 2026 new ir.VariableDeclaration(local.name, |
| 2023 initializer: null, | 2027 initializer: null, |
| 2024 type: typeToIrHack(local.type), | 2028 type: typeToIrHack(local.type), |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2449 SendSet node, | 2453 SendSet node, |
| 2450 Element getter, | 2454 Element getter, |
| 2451 CompoundGetter getterKind, | 2455 CompoundGetter getterKind, |
| 2452 Element setter, | 2456 Element setter, |
| 2453 CompoundSetter setterKind, | 2457 CompoundSetter setterKind, |
| 2454 Node rhs, | 2458 Node rhs, |
| 2455 _) { | 2459 _) { |
| 2456 if (setterKind == CompoundSetter.INVALID) { | 2460 if (setterKind == CompoundSetter.INVALID) { |
| 2457 setter = null; | 2461 setter = null; |
| 2458 } | 2462 } |
| 2459 return buildSuperPropertyAccessor(getter, setter).buildNullAwareAssignment( | 2463 return _finishSetIfNull( |
| 2460 visitForValue(rhs), null, | 2464 node, buildSuperPropertyAccessor(getter, setter), rhs); |
| 2461 voidContext: isVoidContext); | |
| 2462 } | 2465 } |
| 2463 | 2466 |
| 2464 @override | 2467 @override |
| 2465 ir.SuperMethodInvocation visitSuperIndex( | 2468 ir.SuperMethodInvocation visitSuperIndex( |
| 2466 Send node, FunctionElement function, Node index, _) { | 2469 Send node, FunctionElement function, Node index, _) { |
| 2467 return buildSuperIndexAccessor(index, function).buildSimpleRead(); | 2470 return buildSuperIndexAccessor(index, function).buildSimpleRead(); |
| 2468 } | 2471 } |
| 2469 | 2472 |
| 2470 @override | 2473 @override |
| 2471 ir.Expression visitSuperIndexPostfix(Send node, MethodElement indexFunction, | 2474 ir.Expression visitSuperIndexPostfix(Send node, MethodElement indexFunction, |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2678 @override | 2681 @override |
| 2679 ir.Expression visitTypeVariableTypeLiteralSet( | 2682 ir.Expression visitTypeVariableTypeLiteralSet( |
| 2680 SendSet node, TypeVariableElement element, Node rhs, _) { | 2683 SendSet node, TypeVariableElement element, Node rhs, _) { |
| 2681 return new ReadOnlyAccessor(buildTypeVariable(element)) | 2684 return new ReadOnlyAccessor(buildTypeVariable(element)) |
| 2682 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 2685 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
| 2683 } | 2686 } |
| 2684 | 2687 |
| 2685 @override | 2688 @override |
| 2686 ir.Expression visitTypeVariableTypeLiteralSetIfNull( | 2689 ir.Expression visitTypeVariableTypeLiteralSetIfNull( |
| 2687 Send node, TypeVariableElement element, Node rhs, _) { | 2690 Send node, TypeVariableElement element, Node rhs, _) { |
| 2688 return new ReadOnlyAccessor(buildTypeVariable(element)) | 2691 return _finishSetIfNull( |
| 2689 .buildNullAwareAssignment(visitForValue(rhs), null, | 2692 node, new ReadOnlyAccessor(buildTypeVariable(element)), rhs); |
| 2690 voidContext: isVoidContext); | |
| 2691 } | 2693 } |
| 2692 | 2694 |
| 2693 @override | 2695 @override |
| 2694 ir.TypeLiteral visitTypedefTypeLiteralGet( | 2696 ir.TypeLiteral visitTypedefTypeLiteralGet( |
| 2695 Send node, ConstantExpression constant, _) { | 2697 Send node, ConstantExpression constant, _) { |
| 2696 return buildTypeLiteral(constant); | 2698 return buildTypeLiteral(constant); |
| 2697 } | 2699 } |
| 2698 | 2700 |
| 2699 @override | 2701 @override |
| 2700 ir.MethodInvocation visitTypedefTypeLiteralInvoke( | 2702 ir.MethodInvocation visitTypedefTypeLiteralInvoke( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2744 | 2746 |
| 2745 @override | 2747 @override |
| 2746 visitForIn(ForIn node) { | 2748 visitForIn(ForIn node) { |
| 2747 // Shouldn't be called, handled by [visitAsyncForIn] or [visitSyncForIn]. | 2749 // Shouldn't be called, handled by [visitAsyncForIn] or [visitSyncForIn]. |
| 2748 return internalError(node, "ForIn"); | 2750 return internalError(node, "ForIn"); |
| 2749 } | 2751 } |
| 2750 | 2752 |
| 2751 @override | 2753 @override |
| 2752 ir.Expression visitIndexSetIfNull( | 2754 ir.Expression visitIndexSetIfNull( |
| 2753 SendSet node, Node receiver, Node index, Node rhs, _) { | 2755 SendSet node, Node receiver, Node index, Node rhs, _) { |
| 2754 return buildIndexAccessor(receiver, index).buildNullAwareAssignment( | 2756 return _finishSetIfNull(node, buildIndexAccessor(receiver, index), rhs); |
| 2755 visitForValue(rhs), null, | |
| 2756 voidContext: isVoidContext); | |
| 2757 } | 2757 } |
| 2758 | 2758 |
| 2759 @override | 2759 @override |
| 2760 ir.Expression visitSuperIndexSetIfNull(SendSet node, MethodElement getter, | 2760 ir.Expression visitSuperIndexSetIfNull(SendSet node, MethodElement getter, |
| 2761 MethodElement setter, Node index, Node rhs, _) { | 2761 MethodElement setter, Node index, Node rhs, _) { |
| 2762 return buildSuperIndexAccessor(index, getter, setter) | 2762 return _finishSetIfNull( |
| 2763 .buildNullAwareAssignment(visitForValue(rhs), null, | 2763 node, buildSuperIndexAccessor(index, getter, setter), rhs); |
| 2764 voidContext: isVoidContext); | |
| 2765 } | 2764 } |
| 2766 | 2765 |
| 2767 @override | 2766 @override |
| 2768 ir.Node visitVariableDefinitions(VariableDefinitions definitions) { | 2767 ir.Node visitVariableDefinitions(VariableDefinitions definitions) { |
| 2769 // TODO(ahe): This method is copied from [SemanticDeclarationResolvedMixin] | 2768 // TODO(ahe): This method is copied from [SemanticDeclarationResolvedMixin] |
| 2770 // and modified. Perhaps we can find a way to avoid code duplication. | 2769 // and modified. Perhaps we can find a way to avoid code duplication. |
| 2771 List<ir.VariableDeclaration> variables = <ir.VariableDeclaration>[]; | 2770 List<ir.VariableDeclaration> variables = <ir.VariableDeclaration>[]; |
| 2772 computeVariableStructures(definitions, | 2771 computeVariableStructures(definitions, |
| 2773 (Node node, VariableStructure structure) { | 2772 (Node node, VariableStructure structure) { |
| 2774 if (structure == null) { | 2773 if (structure == null) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2853 : this(null, true, node, initializers); | 2852 : this(null, true, node, initializers); |
| 2854 | 2853 |
| 2855 accept(ir.Visitor v) => throw "unsupported"; | 2854 accept(ir.Visitor v) => throw "unsupported"; |
| 2856 | 2855 |
| 2857 visitChildren(ir.Visitor v) => throw "unsupported"; | 2856 visitChildren(ir.Visitor v) => throw "unsupported"; |
| 2858 | 2857 |
| 2859 String toString() { | 2858 String toString() { |
| 2860 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 2859 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
| 2861 } | 2860 } |
| 2862 } | 2861 } |
| OLD | NEW |