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, |
11 PropertyAccessor, | 11 PropertyAccessor, |
12 ReadOnlyAccessor, | 12 ReadOnlyAccessor, |
13 StaticAccessor, | 13 StaticAccessor, |
14 SuperIndexAccessor, | 14 SuperIndexAccessor, |
15 SuperPropertyAccessor, | 15 SuperPropertyAccessor, |
16 ThisPropertyAccessor, | 16 ThisPropertyAccessor, |
17 VariableAccessor, | 17 VariableAccessor, |
18 buildIsNull, | 18 buildIsNull, |
19 makeBinary, | 19 makeBinary, |
20 makeLet, | 20 makeLet, |
21 makeOrReuseVariable; | 21 makeOrReuseVariable; |
| 22 import 'package:kernel/transformations/flags.dart'; |
22 | 23 |
23 import '../common.dart'; | 24 import '../common.dart'; |
24 import '../constants/expressions.dart' | 25 import '../constants/expressions.dart' |
25 show | 26 show |
26 BoolFromEnvironmentConstantExpression, | 27 BoolFromEnvironmentConstantExpression, |
27 ConstantExpression, | 28 ConstantExpression, |
28 ConstructedConstantExpression, | 29 ConstructedConstantExpression, |
29 IntFromEnvironmentConstantExpression, | 30 IntFromEnvironmentConstantExpression, |
30 StringFromEnvironmentConstantExpression, | 31 StringFromEnvironmentConstantExpression, |
31 TypeConstantExpression; | 32 TypeConstantExpression; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 UnavailableVisitor, | 177 UnavailableVisitor, |
177 UnresolvedVisitor, | 178 UnresolvedVisitor, |
178 KernelError | 179 KernelError |
179 implements | 180 implements |
180 SemanticVisitor, | 181 SemanticVisitor, |
181 SemanticSendVisitor, | 182 SemanticSendVisitor, |
182 SemanticDeclarationVisitor { | 183 SemanticDeclarationVisitor { |
183 TreeElements elements; | 184 TreeElements elements; |
184 AstElement currentElement; | 185 AstElement currentElement; |
185 final Kernel kernel; | 186 final Kernel kernel; |
| 187 int transformerFlags = 0; |
186 | 188 |
187 final Map<JumpTarget, ir.LabeledStatement> continueTargets = | 189 final Map<JumpTarget, ir.LabeledStatement> continueTargets = |
188 <JumpTarget, ir.LabeledStatement>{}; | 190 <JumpTarget, ir.LabeledStatement>{}; |
189 | 191 |
190 final Map<JumpTarget, ir.SwitchCase> continueSwitchTargets = | 192 final Map<JumpTarget, ir.SwitchCase> continueSwitchTargets = |
191 <JumpTarget, ir.SwitchCase>{}; | 193 <JumpTarget, ir.SwitchCase>{}; |
192 | 194 |
193 final Map<JumpTarget, ir.LabeledStatement> breakTargets = | 195 final Map<JumpTarget, ir.LabeledStatement> breakTargets = |
194 <JumpTarget, ir.LabeledStatement>{}; | 196 <JumpTarget, ir.LabeledStatement>{}; |
195 | 197 |
(...skipping 1991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 | 2189 |
2188 @override | 2190 @override |
2189 ir.InvocationExpression visitStringFromEnvironmentConstructorInvoke( | 2191 ir.InvocationExpression visitStringFromEnvironmentConstructorInvoke( |
2190 NewExpression node, StringFromEnvironmentConstantExpression constant, _) { | 2192 NewExpression node, StringFromEnvironmentConstantExpression constant, _) { |
2191 return buildConstructorInvoke(node, isConst: true); | 2193 return buildConstructorInvoke(node, isConst: true); |
2192 } | 2194 } |
2193 | 2195 |
2194 @override | 2196 @override |
2195 ir.SuperMethodInvocation visitSuperBinary(Send node, FunctionElement function, | 2197 ir.SuperMethodInvocation visitSuperBinary(Send node, FunctionElement function, |
2196 BinaryOperator operator, Node argument, _) { | 2198 BinaryOperator operator, Node argument, _) { |
| 2199 transformerFlags |= TransformerFlag.superCalls; |
2197 return new ir.SuperMethodInvocation( | 2200 return new ir.SuperMethodInvocation( |
2198 kernel.irName(operator.selectorName, currentElement), | 2201 kernel.irName(operator.selectorName, currentElement), |
2199 new ir.Arguments(<ir.Expression>[visitForValue(argument)]), | 2202 new ir.Arguments(<ir.Expression>[visitForValue(argument)]), |
2200 kernel.functionToIr(function)); | 2203 kernel.functionToIr(function)); |
2201 } | 2204 } |
2202 | 2205 |
2203 @override | 2206 @override |
2204 ir.Expression visitSuperCompoundIndexSet( | 2207 ir.Expression visitSuperCompoundIndexSet( |
2205 SendSet node, | 2208 SendSet node, |
2206 MethodElement getter, | 2209 MethodElement getter, |
(...skipping 20 matching lines...) Expand all Loading... |
2227 if (kernel.isSyntheticError(superConstructor)) { | 2230 if (kernel.isSyntheticError(superConstructor)) { |
2228 // TODO(ahe): Semantic visitor shouldn't call in this case. | 2231 // TODO(ahe): Semantic visitor shouldn't call in this case. |
2229 return new ir.InvalidInitializer(); | 2232 return new ir.InvalidInitializer(); |
2230 } | 2233 } |
2231 return new ir.SuperInitializer( | 2234 return new ir.SuperInitializer( |
2232 kernel.functionToIr(superConstructor), buildArguments(arguments)); | 2235 kernel.functionToIr(superConstructor), buildArguments(arguments)); |
2233 } | 2236 } |
2234 | 2237 |
2235 ir.SuperMethodInvocation buildSuperEquals( | 2238 ir.SuperMethodInvocation buildSuperEquals( |
2236 FunctionElement function, Node argument) { | 2239 FunctionElement function, Node argument) { |
| 2240 transformerFlags |= TransformerFlag.superCalls; |
2237 return new ir.SuperMethodInvocation( | 2241 return new ir.SuperMethodInvocation( |
2238 kernel.irName(function.name, function), | 2242 kernel.irName(function.name, function), |
2239 new ir.Arguments(<ir.Expression>[visitForValue(argument)], | 2243 new ir.Arguments(<ir.Expression>[visitForValue(argument)], |
2240 types: null, named: null), | 2244 types: null, named: null), |
2241 kernel.functionToIr(function)); | 2245 kernel.functionToIr(function)); |
2242 } | 2246 } |
2243 | 2247 |
2244 @override | 2248 @override |
2245 ir.SuperMethodInvocation visitSuperEquals( | 2249 ir.SuperMethodInvocation visitSuperEquals( |
2246 Send node, FunctionElement function, Node argument, _) { | 2250 Send node, FunctionElement function, Node argument, _) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 } | 2310 } |
2307 | 2311 |
2308 @override | 2312 @override |
2309 ir.Expression visitSuperFieldSet( | 2313 ir.Expression visitSuperFieldSet( |
2310 SendSet node, FieldElement field, Node rhs, _) { | 2314 SendSet node, FieldElement field, Node rhs, _) { |
2311 return buildSuperPropertyAccessor(field) | 2315 return buildSuperPropertyAccessor(field) |
2312 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 2316 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
2313 } | 2317 } |
2314 | 2318 |
2315 Accessor buildSuperPropertyAccessor(Element getter, [Element setter]) { | 2319 Accessor buildSuperPropertyAccessor(Element getter, [Element setter]) { |
| 2320 transformerFlags |= TransformerFlag.superCalls; |
2316 if (setter == null && | 2321 if (setter == null && |
2317 getter.isField && | 2322 getter.isField && |
2318 !getter.isFinal && | 2323 !getter.isFinal && |
2319 !getter.isConst) { | 2324 !getter.isConst) { |
2320 setter = getter; | 2325 setter = getter; |
2321 } | 2326 } |
2322 Element element = getter ?? setter; | 2327 Element element = getter ?? setter; |
2323 return new SuperPropertyAccessor( | 2328 return new SuperPropertyAccessor( |
2324 kernel.irName(element.name, element), | 2329 kernel.irName(element.name, element), |
2325 (getter == null) ? null : kernel.elementToIr(getter), | 2330 (getter == null) ? null : kernel.elementToIr(getter), |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2406 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 2411 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
2407 } | 2412 } |
2408 | 2413 |
2409 @override | 2414 @override |
2410 ir.Expression visitSuperMethodGet(Send node, MethodElement method, _) { | 2415 ir.Expression visitSuperMethodGet(Send node, MethodElement method, _) { |
2411 return buildSuperPropertyAccessor(method).buildSimpleRead(); | 2416 return buildSuperPropertyAccessor(method).buildSimpleRead(); |
2412 } | 2417 } |
2413 | 2418 |
2414 ir.SuperMethodInvocation buildSuperMethodInvoke( | 2419 ir.SuperMethodInvocation buildSuperMethodInvoke( |
2415 MethodElement method, NodeList arguments) { | 2420 MethodElement method, NodeList arguments) { |
| 2421 transformerFlags |= TransformerFlag.superCalls; |
2416 return new ir.SuperMethodInvocation(kernel.irName(method.name, method), | 2422 return new ir.SuperMethodInvocation(kernel.irName(method.name, method), |
2417 buildArguments(arguments), kernel.functionToIr(method)); | 2423 buildArguments(arguments), kernel.functionToIr(method)); |
2418 } | 2424 } |
2419 | 2425 |
2420 @override | 2426 @override |
2421 ir.SuperMethodInvocation visitSuperMethodIncompatibleInvoke( | 2427 ir.SuperMethodInvocation visitSuperMethodIncompatibleInvoke( |
2422 Send node, | 2428 Send node, |
2423 MethodElement method, | 2429 MethodElement method, |
2424 NodeList arguments, | 2430 NodeList arguments, |
2425 CallStructure callStructure, | 2431 CallStructure callStructure, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2465 @override | 2471 @override |
2466 ir.Expression visitSuperSetterSet( | 2472 ir.Expression visitSuperSetterSet( |
2467 SendSet node, FunctionElement setter, Node rhs, _) { | 2473 SendSet node, FunctionElement setter, Node rhs, _) { |
2468 return buildSuperPropertyAccessor(null, setter) | 2474 return buildSuperPropertyAccessor(null, setter) |
2469 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); | 2475 .buildAssignment(visitForValue(rhs), voidContext: isVoidContext); |
2470 } | 2476 } |
2471 | 2477 |
2472 @override | 2478 @override |
2473 ir.SuperMethodInvocation visitSuperUnary( | 2479 ir.SuperMethodInvocation visitSuperUnary( |
2474 Send node, UnaryOperator operator, FunctionElement function, _) { | 2480 Send node, UnaryOperator operator, FunctionElement function, _) { |
| 2481 transformerFlags |= TransformerFlag.superCalls; |
2475 return new ir.SuperMethodInvocation(kernel.irName(function.name, function), | 2482 return new ir.SuperMethodInvocation(kernel.irName(function.name, function), |
2476 new ir.Arguments.empty(), kernel.functionToIr(function)); | 2483 new ir.Arguments.empty(), kernel.functionToIr(function)); |
2477 } | 2484 } |
2478 | 2485 |
2479 @override | 2486 @override |
2480 ir.Initializer visitThisConstructorInvoke( | 2487 ir.Initializer visitThisConstructorInvoke( |
2481 Send node, | 2488 Send node, |
2482 ConstructorElement thisConstructor, | 2489 ConstructorElement thisConstructor, |
2483 NodeList arguments, | 2490 NodeList arguments, |
2484 CallStructure callStructure, | 2491 CallStructure callStructure, |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2767 : this(null, true, node, initializers); | 2774 : this(null, true, node, initializers); |
2768 | 2775 |
2769 accept(ir.Visitor v) => throw "unsupported"; | 2776 accept(ir.Visitor v) => throw "unsupported"; |
2770 | 2777 |
2771 visitChildren(ir.Visitor v) => throw "unsupported"; | 2778 visitChildren(ir.Visitor v) => throw "unsupported"; |
2772 | 2779 |
2773 String toString() { | 2780 String toString() { |
2774 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 2781 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
2775 } | 2782 } |
2776 } | 2783 } |
OLD | NEW |