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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 final Map<JumpTarget, ir.LabeledStatement> breakTargets = | 192 final Map<JumpTarget, ir.LabeledStatement> breakTargets = |
193 <JumpTarget, ir.LabeledStatement>{}; | 193 <JumpTarget, ir.LabeledStatement>{}; |
194 | 194 |
195 final Map<LocalElement, ir.VariableDeclaration> locals = | 195 final Map<LocalElement, ir.VariableDeclaration> locals = |
196 <LocalElement, ir.VariableDeclaration>{}; | 196 <LocalElement, ir.VariableDeclaration>{}; |
197 | 197 |
198 final Map<CascadeReceiver, ir.VariableGet> cascadeReceivers = | 198 final Map<CascadeReceiver, ir.VariableGet> cascadeReceivers = |
199 <CascadeReceiver, ir.VariableGet>{}; | 199 <CascadeReceiver, ir.VariableGet>{}; |
200 | 200 |
201 final Map<ir.Node, Element> nodeToElement = <ir.Node, Element>{}; | 201 final Map<ir.Node, Element> nodeToElement = <ir.Node, Element>{}; |
| 202 final Map<ir.Node, Node> nodeToAst = <ir.Node, Node>{}; |
202 | 203 |
203 ir.Node associate(ir.Node node, Element element) { | 204 ir.Node associateElement(ir.Node node, Element element) { |
204 nodeToElement[node] = element; | 205 nodeToElement[node] = element; |
205 return node; | 206 return node; |
206 } | 207 } |
207 | 208 |
208 final Map<ir.Node, Node> nodeToAst = <ir.Node, Node>{}; | 209 ir.Node associateNode(ir.Node node, Node ast) { |
| 210 nodeToAst[node] = ast; |
| 211 return node; |
| 212 } |
209 | 213 |
210 bool isVoidContext = false; | 214 bool isVoidContext = false; |
211 | 215 |
212 KernelVisitor(this.currentElement, this.elements, this.kernel); | 216 KernelVisitor(this.currentElement, this.elements, this.kernel); |
213 | 217 |
214 KernelVisitor get sendVisitor => this; | 218 KernelVisitor get sendVisitor => this; |
215 | 219 |
216 KernelVisitor get declVisitor => this; | 220 KernelVisitor get declVisitor => this; |
217 | 221 |
218 ir.TreeNode visitForValue(Expression node) { | 222 ir.TreeNode visitForValue(Expression node) { |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 | 1127 |
1124 @override | 1128 @override |
1125 ir.AsExpression visitAs(Send node, Node expression, DartType type, _) { | 1129 ir.AsExpression visitAs(Send node, Node expression, DartType type, _) { |
1126 return new ir.AsExpression( | 1130 return new ir.AsExpression( |
1127 visitForValue(expression), kernel.typeToIr(type)); | 1131 visitForValue(expression), kernel.typeToIr(type)); |
1128 } | 1132 } |
1129 | 1133 |
1130 @override | 1134 @override |
1131 ir.MethodInvocation visitBinary( | 1135 ir.MethodInvocation visitBinary( |
1132 Send node, Node left, BinaryOperator operator, Node right, _) { | 1136 Send node, Node left, BinaryOperator operator, Node right, _) { |
1133 return buildBinaryOperator(left, operator.selectorName, right); | 1137 return associateNode( |
| 1138 buildBinaryOperator(left, operator.selectorName, right), node); |
1134 } | 1139 } |
1135 | 1140 |
1136 ir.Expression buildConstructorInvoke(NewExpression node, {bool isConst}) { | 1141 ir.Expression buildConstructorInvoke(NewExpression node, {bool isConst}) { |
1137 ConstructorElement constructor = elements[node.send]; | 1142 ConstructorElement constructor = elements[node.send]; |
1138 ConstructorTarget target = | 1143 ConstructorTarget target = |
1139 kernel.computeEffectiveTarget(constructor, elements.getType(node)); | 1144 kernel.computeEffectiveTarget(constructor, elements.getType(node)); |
1140 NodeList arguments = node.send.argumentsNode; | 1145 NodeList arguments = node.send.argumentsNode; |
1141 if (kernel.isSyntheticError(target.element)) { | 1146 if (kernel.isSyntheticError(target.element)) { |
1142 return new ir.MethodInvocation(new ir.InvalidExpression(), | 1147 return new ir.MethodInvocation(new ir.InvalidExpression(), |
1143 kernel.irName("call", currentElement), buildArguments(arguments)); | 1148 kernel.irName("call", currentElement), buildArguments(arguments)); |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1915 if (setterKind == CompoundSetter.INVALID) { | 1920 if (setterKind == CompoundSetter.INVALID) { |
1916 setter = null; | 1921 setter = null; |
1917 } | 1922 } |
1918 return buildStaticAccessor(getter, setter).buildNullAwareAssignment( | 1923 return buildStaticAccessor(getter, setter).buildNullAwareAssignment( |
1919 visitForValue(rhs), | 1924 visitForValue(rhs), |
1920 voidContext: isVoidContext); | 1925 voidContext: isVoidContext); |
1921 } | 1926 } |
1922 | 1927 |
1923 ir.VariableDeclaration getLocal(LocalElement local) { | 1928 ir.VariableDeclaration getLocal(LocalElement local) { |
1924 return locals.putIfAbsent(local, () { | 1929 return locals.putIfAbsent(local, () { |
1925 return associate( | 1930 return associateElement( |
1926 new ir.VariableDeclaration(local.name, | 1931 new ir.VariableDeclaration(local.name, |
1927 initializer: null, | 1932 initializer: null, |
1928 type: typeToIrHack(local.type), | 1933 type: typeToIrHack(local.type), |
1929 isFinal: local.isFinal, | 1934 isFinal: local.isFinal, |
1930 isConst: local.isConst), | 1935 isConst: local.isConst), |
1931 local); | 1936 local); |
1932 }); | 1937 }); |
1933 } | 1938 } |
1934 | 1939 |
1935 ir.FunctionNode buildFunctionNode(FunctionElement function, Node bodyNode) { | 1940 ir.FunctionNode buildFunctionNode(FunctionElement function, Node bodyNode) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 break; | 1996 break; |
1992 | 1997 |
1993 default: | 1998 default: |
1994 internalError( | 1999 internalError( |
1995 function, "Unknown async maker: ${function.asyncMarker}"); | 2000 function, "Unknown async maker: ${function.asyncMarker}"); |
1996 break; | 2001 break; |
1997 } | 2002 } |
1998 } | 2003 } |
1999 ir.Statement body = | 2004 ir.Statement body = |
2000 (bodyNode == null) ? null : buildStatementInBlock(bodyNode); | 2005 (bodyNode == null) ? null : buildStatementInBlock(bodyNode); |
2001 return associate( | 2006 return associateElement( |
2002 new ir.FunctionNode(body, | 2007 new ir.FunctionNode(body, |
2003 asyncMarker: asyncMarker, | 2008 asyncMarker: asyncMarker, |
2004 returnType: returnType, | 2009 returnType: returnType, |
2005 typeParameters: typeParameters, | 2010 typeParameters: typeParameters, |
2006 positionalParameters: positionalParameters, | 2011 positionalParameters: positionalParameters, |
2007 namedParameters: namedParameters, | 2012 namedParameters: namedParameters, |
2008 requiredParameterCount: requiredParameterCount), | 2013 requiredParameterCount: requiredParameterCount), |
2009 function); | 2014 function); |
2010 } | 2015 } |
2011 | 2016 |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2709 : this(null, true, node, initializers); | 2714 : this(null, true, node, initializers); |
2710 | 2715 |
2711 accept(ir.Visitor v) => throw "unsupported"; | 2716 accept(ir.Visitor v) => throw "unsupported"; |
2712 | 2717 |
2713 visitChildren(ir.Visitor v) => throw "unsupported"; | 2718 visitChildren(ir.Visitor v) => throw "unsupported"; |
2714 | 2719 |
2715 String toString() { | 2720 String toString() { |
2716 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 2721 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
2717 } | 2722 } |
2718 } | 2723 } |
OLD | NEW |