| 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 13 matching lines...) Expand all Loading... |
| 24 import '../common.dart'; | 24 import '../common.dart'; |
| 25 import '../common/names.dart'; | 25 import '../common/names.dart'; |
| 26 import '../constants/expressions.dart' | 26 import '../constants/expressions.dart' |
| 27 show | 27 show |
| 28 BoolFromEnvironmentConstantExpression, | 28 BoolFromEnvironmentConstantExpression, |
| 29 ConstantExpression, | 29 ConstantExpression, |
| 30 ConstructedConstantExpression, | 30 ConstructedConstantExpression, |
| 31 IntFromEnvironmentConstantExpression, | 31 IntFromEnvironmentConstantExpression, |
| 32 StringFromEnvironmentConstantExpression, | 32 StringFromEnvironmentConstantExpression, |
| 33 TypeConstantExpression; | 33 TypeConstantExpression; |
| 34 import '../elements/resolution_types.dart' show DartType, InterfaceType; | 34 import '../elements/resolution_types.dart' |
| 35 show ResolutionDartType, ResolutionInterfaceType; |
| 35 import '../diagnostics/spannable.dart' show Spannable; | 36 import '../diagnostics/spannable.dart' show Spannable; |
| 36 import '../elements/elements.dart' | 37 import '../elements/elements.dart' |
| 37 show | 38 show |
| 38 AstElement, | 39 AstElement, |
| 39 AsyncMarker, | 40 AsyncMarker, |
| 40 ClassElement, | 41 ClassElement, |
| 41 ConstructorElement, | 42 ConstructorElement, |
| 42 Element, | 43 Element, |
| 43 FieldElement, | 44 FieldElement, |
| 44 FunctionElement, | 45 FunctionElement, |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 253 } |
| 253 } | 254 } |
| 254 | 255 |
| 255 ir.DartType computeType(TypeAnnotation node) { | 256 ir.DartType computeType(TypeAnnotation node) { |
| 256 if (node == null) return const ir.DynamicType(); | 257 if (node == null) return const ir.DynamicType(); |
| 257 return kernel.typeToIr(elements.getType(node)); | 258 return kernel.typeToIr(elements.getType(node)); |
| 258 } | 259 } |
| 259 | 260 |
| 260 // This works around a bug in dart2js. | 261 // This works around a bug in dart2js. |
| 261 // TODO(ahe): Fix the bug in dart2js and remove this function. | 262 // TODO(ahe): Fix the bug in dart2js and remove this function. |
| 262 ir.DartType typeToIrHack(DartType type) { | 263 ir.DartType typeToIrHack(ResolutionDartType type) { |
| 263 if (currentElement.isSynthesized && | 264 if (currentElement.isSynthesized && |
| 264 currentElement.enclosingClass.isMixinApplication && | 265 currentElement.enclosingClass.isMixinApplication && |
| 265 !kernel.hasHierarchyProblem(currentElement.enclosingClass)) { | 266 !kernel.hasHierarchyProblem(currentElement.enclosingClass)) { |
| 266 // Dart2js doesn't compute the correct functionSignature for synthetic | 267 // Dart2js doesn't compute the correct functionSignature for synthetic |
| 267 // constructors in mixin applications. So we compute the correct type: | 268 // constructors in mixin applications. So we compute the correct type: |
| 268 // First, find the first superclass that isn't a mixin. | 269 // First, find the first superclass that isn't a mixin. |
| 269 ClassElement superclass = currentElement.enclosingClass.superclass; | 270 ClassElement superclass = currentElement.enclosingClass.superclass; |
| 270 while (superclass.isMixinApplication) { | 271 while (superclass.isMixinApplication) { |
| 271 superclass = superclass.superclass; | 272 superclass = superclass.superclass; |
| 272 } | 273 } |
| 273 // Then translate the "this type" of the mixin application to its | 274 // Then translate the "this type" of the mixin application to its |
| 274 // supertype with the correct type arguments. | 275 // supertype with the correct type arguments. |
| 275 // | 276 // |
| 276 // Consider this example: | 277 // Consider this example: |
| 277 // | 278 // |
| 278 // class Super<S> {} | 279 // class Super<S> {} |
| 279 // class Sub<T> extends Object with Super<T> {} | 280 // class Sub<T> extends Object with Super<T> {} |
| 280 // | 281 // |
| 281 // Here the problem is that dart2js has created a constructor that refers | 282 // Here the problem is that dart2js has created a constructor that refers |
| 282 // to S (not T) in Sub (for example, the return type of the constructor | 283 // to S (not T) in Sub (for example, the return type of the constructor |
| 283 // is Super<S> and it should be Sub<T>, but we settle for Super<T> for | 284 // is Super<S> and it should be Sub<T>, but we settle for Super<T> for |
| 284 // now). So we need to translate Sub<T> to an instance of Super, which is | 285 // now). So we need to translate Sub<T> to an instance of Super, which is |
| 285 // Super<T> (not Super<S>). | 286 // Super<T> (not Super<S>). |
| 286 InterfaceType supertype = | 287 ResolutionInterfaceType supertype = |
| 287 currentElement.enclosingClass.asInstanceOf(superclass); | 288 currentElement.enclosingClass.asInstanceOf(superclass); |
| 288 // Once we have [supertype], we know how to substitute S with T: the type | 289 // Once we have [supertype], we know how to substitute S with T: the type |
| 289 // arguments of [supertype] corresponds to T, and the type variables of | 290 // arguments of [supertype] corresponds to T, and the type variables of |
| 290 // its element correspond to S. | 291 // its element correspond to S. |
| 291 type = | 292 type = |
| 292 type.subst(supertype.typeArguments, supertype.element.typeVariables); | 293 type.subst(supertype.typeArguments, supertype.element.typeVariables); |
| 293 } | 294 } |
| 294 return kernel.typeToIr(type); | 295 return kernel.typeToIr(type); |
| 295 } | 296 } |
| 296 | 297 |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 @override | 1115 @override |
| 1115 ir.YieldStatement visitYield(Yield node) { | 1116 ir.YieldStatement visitYield(Yield node) { |
| 1116 return new ir.YieldStatement(visitForValue(node.expression), | 1117 return new ir.YieldStatement(visitForValue(node.expression), |
| 1117 isYieldStar: node.hasStar); | 1118 isYieldStar: node.hasStar); |
| 1118 } | 1119 } |
| 1119 | 1120 |
| 1120 @override | 1121 @override |
| 1121 ir.InvalidExpression visitAbstractClassConstructorInvoke( | 1122 ir.InvalidExpression visitAbstractClassConstructorInvoke( |
| 1122 NewExpression node, | 1123 NewExpression node, |
| 1123 ConstructorElement element, | 1124 ConstructorElement element, |
| 1124 InterfaceType type, | 1125 ResolutionInterfaceType type, |
| 1125 NodeList arguments, | 1126 NodeList arguments, |
| 1126 CallStructure callStructure, | 1127 CallStructure callStructure, |
| 1127 _) { | 1128 _) { |
| 1128 return new ir.InvalidExpression(); | 1129 return new ir.InvalidExpression(); |
| 1129 } | 1130 } |
| 1130 | 1131 |
| 1131 IrFunction buildIrFunction( | 1132 IrFunction buildIrFunction( |
| 1132 ir.ProcedureKind kind, FunctionElement function, Node body) { | 1133 ir.ProcedureKind kind, FunctionElement function, Node body) { |
| 1133 return new IrFunction.procedure(kind, buildFunctionNode(function, body)); | 1134 return new IrFunction.procedure(kind, buildFunctionNode(function, body)); |
| 1134 } | 1135 } |
| 1135 | 1136 |
| 1136 @override | 1137 @override |
| 1137 IrFunction visitAbstractGetterDeclaration( | 1138 IrFunction visitAbstractGetterDeclaration( |
| 1138 FunctionExpression node, MethodElement getter, _) { | 1139 FunctionExpression node, MethodElement getter, _) { |
| 1139 return buildIrFunction(ir.ProcedureKind.Getter, getter, null); | 1140 return buildIrFunction(ir.ProcedureKind.Getter, getter, null); |
| 1140 } | 1141 } |
| 1141 | 1142 |
| 1142 @override | 1143 @override |
| 1143 IrFunction visitAbstractSetterDeclaration( | 1144 IrFunction visitAbstractSetterDeclaration( |
| 1144 FunctionExpression node, MethodElement setter, NodeList parameters, _) { | 1145 FunctionExpression node, MethodElement setter, NodeList parameters, _) { |
| 1145 return buildIrFunction(ir.ProcedureKind.Setter, setter, null); | 1146 return buildIrFunction(ir.ProcedureKind.Setter, setter, null); |
| 1146 } | 1147 } |
| 1147 | 1148 |
| 1148 @override | 1149 @override |
| 1149 ir.AsExpression visitAs(Send node, Node expression, DartType type, _) { | 1150 ir.AsExpression visitAs( |
| 1151 Send node, Node expression, ResolutionDartType type, _) { |
| 1150 return new ir.AsExpression( | 1152 return new ir.AsExpression( |
| 1151 visitForValue(expression), kernel.typeToIr(type)); | 1153 visitForValue(expression), kernel.typeToIr(type)); |
| 1152 } | 1154 } |
| 1153 | 1155 |
| 1154 @override | 1156 @override |
| 1155 ir.MethodInvocation visitBinary( | 1157 ir.MethodInvocation visitBinary( |
| 1156 Send node, Node left, BinaryOperator operator, Node right, _) { | 1158 Send node, Node left, BinaryOperator operator, Node right, _) { |
| 1157 return associateNode( | 1159 return associateNode( |
| 1158 buildBinaryOperator(left, operator.selectorName, right), node); | 1160 buildBinaryOperator(left, operator.selectorName, right), node); |
| 1159 } | 1161 } |
| 1160 | 1162 |
| 1161 ir.Expression buildConstructorInvoke(NewExpression node, {bool isConst}) { | 1163 ir.Expression buildConstructorInvoke(NewExpression node, {bool isConst}) { |
| 1162 ConstructorElement constructor = elements[node.send]; | 1164 ConstructorElement constructor = elements[node.send]; |
| 1163 ConstructorTarget target = | 1165 ConstructorTarget target = |
| 1164 kernel.computeEffectiveTarget(constructor, elements.getType(node)); | 1166 kernel.computeEffectiveTarget(constructor, elements.getType(node)); |
| 1165 NodeList arguments = node.send.argumentsNode; | 1167 NodeList arguments = node.send.argumentsNode; |
| 1166 if (kernel.isSyntheticError(target.element)) { | 1168 if (kernel.isSyntheticError(target.element)) { |
| 1167 return new ir.MethodInvocation(new ir.InvalidExpression(), | 1169 return new ir.MethodInvocation(new ir.InvalidExpression(), |
| 1168 kernel.irName("call", currentElement), buildArguments(arguments)); | 1170 kernel.irName("call", currentElement), buildArguments(arguments)); |
| 1169 } | 1171 } |
| 1170 ir.InvocationExpression invoke = target.element.isGenerativeConstructor | 1172 ir.InvocationExpression invoke = target.element.isGenerativeConstructor |
| 1171 ? buildGenerativeConstructorInvoke(target.element, arguments, | 1173 ? buildGenerativeConstructorInvoke(target.element, arguments, |
| 1172 isConst: isConst) | 1174 isConst: isConst) |
| 1173 : buildStaticInvoke(target.element, arguments, isConst: isConst); | 1175 : buildStaticInvoke(target.element, arguments, isConst: isConst); |
| 1174 if (target.type.isInterfaceType) { | 1176 if (target.type.isInterfaceType) { |
| 1175 InterfaceType type = target.type; | 1177 ResolutionInterfaceType type = target.type; |
| 1176 if (type.isGeneric) { | 1178 if (type.isGeneric) { |
| 1177 invoke.arguments.types.addAll(kernel.typesToIr(type.typeArguments)); | 1179 invoke.arguments.types.addAll(kernel.typesToIr(type.typeArguments)); |
| 1178 } | 1180 } |
| 1179 } | 1181 } |
| 1180 return invoke; | 1182 return invoke; |
| 1181 } | 1183 } |
| 1182 | 1184 |
| 1183 @override | 1185 @override |
| 1184 ir.InvocationExpression visitBoolFromEnvironmentConstructorInvoke( | 1186 ir.InvocationExpression visitBoolFromEnvironmentConstructorInvoke( |
| 1185 NewExpression node, BoolFromEnvironmentConstantExpression constant, _) { | 1187 NewExpression node, BoolFromEnvironmentConstantExpression constant, _) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 visitConstantInvoke(Send node, ConstantExpression constant, | 1256 visitConstantInvoke(Send node, ConstantExpression constant, |
| 1255 NodeList arguments, CallStructure callStructure, _) { | 1257 NodeList arguments, CallStructure callStructure, _) { |
| 1256 // TODO(ahe): This method is never called. Is it a bug in semantic visitor? | 1258 // TODO(ahe): This method is never called. Is it a bug in semantic visitor? |
| 1257 return internalError(node, "ConstantInvoke"); | 1259 return internalError(node, "ConstantInvoke"); |
| 1258 } | 1260 } |
| 1259 | 1261 |
| 1260 @override | 1262 @override |
| 1261 ir.InvalidExpression visitConstructorIncompatibleInvoke( | 1263 ir.InvalidExpression visitConstructorIncompatibleInvoke( |
| 1262 NewExpression node, | 1264 NewExpression node, |
| 1263 ConstructorElement constructor, | 1265 ConstructorElement constructor, |
| 1264 InterfaceType type, | 1266 ResolutionInterfaceType type, |
| 1265 NodeList arguments, | 1267 NodeList arguments, |
| 1266 CallStructure callStructure, | 1268 CallStructure callStructure, |
| 1267 _) { | 1269 _) { |
| 1268 return new ir.InvalidExpression(); | 1270 return new ir.InvalidExpression(); |
| 1269 } | 1271 } |
| 1270 | 1272 |
| 1271 @override | 1273 @override |
| 1272 ir.PropertyGet visitDynamicPropertyGet( | 1274 ir.PropertyGet visitDynamicPropertyGet( |
| 1273 Send node, Node receiver, Name name, _) { | 1275 Send node, Node receiver, Name name, _) { |
| 1274 return associateNode( | 1276 return associateNode( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 @override | 1365 @override |
| 1364 IrFunction visitFactoryConstructorDeclaration(FunctionExpression node, | 1366 IrFunction visitFactoryConstructorDeclaration(FunctionExpression node, |
| 1365 ConstructorElement constructor, NodeList parameters, Node body, _) { | 1367 ConstructorElement constructor, NodeList parameters, Node body, _) { |
| 1366 return buildIrFunction(ir.ProcedureKind.Factory, constructor, body); | 1368 return buildIrFunction(ir.ProcedureKind.Factory, constructor, body); |
| 1367 } | 1369 } |
| 1368 | 1370 |
| 1369 @override | 1371 @override |
| 1370 ir.InvocationExpression visitFactoryConstructorInvoke( | 1372 ir.InvocationExpression visitFactoryConstructorInvoke( |
| 1371 NewExpression node, | 1373 NewExpression node, |
| 1372 ConstructorElement constructor, | 1374 ConstructorElement constructor, |
| 1373 InterfaceType type, | 1375 ResolutionInterfaceType type, |
| 1374 NodeList arguments, | 1376 NodeList arguments, |
| 1375 CallStructure callStructure, | 1377 CallStructure callStructure, |
| 1376 _) { | 1378 _) { |
| 1377 return buildConstructorInvoke(node, isConst: false); | 1379 return buildConstructorInvoke(node, isConst: false); |
| 1378 } | 1380 } |
| 1379 | 1381 |
| 1380 @override | 1382 @override |
| 1381 ir.Initializer visitFieldInitializer( | 1383 ir.Initializer visitFieldInitializer( |
| 1382 SendSet node, FieldElement field, Node expression, _) { | 1384 SendSet node, FieldElement field, Node expression, _) { |
| 1383 if (kernel.isSyntheticError(field)) { | 1385 if (kernel.isSyntheticError(field)) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1492 ir.Arguments argumentsNode = buildArguments(arguments); | 1494 ir.Arguments argumentsNode = buildArguments(arguments); |
| 1493 ir.Constructor target = kernel.functionToIr(constructor); | 1495 ir.Constructor target = kernel.functionToIr(constructor); |
| 1494 return new ir.ConstructorInvocation(target, argumentsNode, | 1496 return new ir.ConstructorInvocation(target, argumentsNode, |
| 1495 isConst: isConst); | 1497 isConst: isConst); |
| 1496 } | 1498 } |
| 1497 | 1499 |
| 1498 @override | 1500 @override |
| 1499 ir.InvocationExpression visitGenerativeConstructorInvoke( | 1501 ir.InvocationExpression visitGenerativeConstructorInvoke( |
| 1500 NewExpression node, | 1502 NewExpression node, |
| 1501 ConstructorElement constructor, | 1503 ConstructorElement constructor, |
| 1502 InterfaceType type, | 1504 ResolutionInterfaceType type, |
| 1503 NodeList arguments, | 1505 NodeList arguments, |
| 1504 CallStructure callStructure, | 1506 CallStructure callStructure, |
| 1505 _) { | 1507 _) { |
| 1506 return buildConstructorInvoke(node, isConst: false); | 1508 return buildConstructorInvoke(node, isConst: false); |
| 1507 } | 1509 } |
| 1508 | 1510 |
| 1509 Accessor buildNullAwarePropertyAccessor(Node receiver, Name name) { | 1511 Accessor buildNullAwarePropertyAccessor(Node receiver, Name name) { |
| 1510 return new NullAwarePropertyAccessor( | 1512 return new NullAwarePropertyAccessor( |
| 1511 visitForValue(receiver), nameToIrName(name), null, null, null); | 1513 visitForValue(receiver), nameToIrName(name), null, null, null); |
| 1512 } | 1514 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1564 ir.Expression visitIfNull(Send node, Node left, Node right, _) { | 1566 ir.Expression visitIfNull(Send node, Node left, Node right, _) { |
| 1565 var leftValue = new ir.VariableDeclaration.forValue(visitForValue(left)); | 1567 var leftValue = new ir.VariableDeclaration.forValue(visitForValue(left)); |
| 1566 return new ir.Let( | 1568 return new ir.Let( |
| 1567 leftValue, | 1569 leftValue, |
| 1568 new ir.ConditionalExpression(buildIsNull(new ir.VariableGet(leftValue)), | 1570 new ir.ConditionalExpression(buildIsNull(new ir.VariableGet(leftValue)), |
| 1569 visitForValue(right), new ir.VariableGet(leftValue), null)); | 1571 visitForValue(right), new ir.VariableGet(leftValue), null)); |
| 1570 } | 1572 } |
| 1571 | 1573 |
| 1572 @override | 1574 @override |
| 1573 ir.Initializer visitImplicitSuperConstructorInvoke(FunctionExpression node, | 1575 ir.Initializer visitImplicitSuperConstructorInvoke(FunctionExpression node, |
| 1574 ConstructorElement superConstructor, InterfaceType type, _) { | 1576 ConstructorElement superConstructor, ResolutionInterfaceType type, _) { |
| 1575 if (superConstructor == null) { | 1577 if (superConstructor == null) { |
| 1576 // TODO(ahe): Semantic visitor shouldn't call this. | 1578 // TODO(ahe): Semantic visitor shouldn't call this. |
| 1577 return new ir.InvalidInitializer(); | 1579 return new ir.InvalidInitializer(); |
| 1578 } | 1580 } |
| 1579 return new ir.SuperInitializer( | 1581 return new ir.SuperInitializer( |
| 1580 kernel.functionToIr(superConstructor), new ir.Arguments.empty()); | 1582 kernel.functionToIr(superConstructor), new ir.Arguments.empty()); |
| 1581 } | 1583 } |
| 1582 | 1584 |
| 1583 Accessor buildIndexAccessor(Node receiver, Node index) { | 1585 Accessor buildIndexAccessor(Node receiver, Node index) { |
| 1584 return IndexAccessor.make( | 1586 return IndexAccessor.make( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 MethodElement setter, NodeList parameters, Node body, _) { | 1662 MethodElement setter, NodeList parameters, Node body, _) { |
| 1661 return buildIrFunction(ir.ProcedureKind.Setter, setter, body); | 1663 return buildIrFunction(ir.ProcedureKind.Setter, setter, body); |
| 1662 } | 1664 } |
| 1663 | 1665 |
| 1664 @override | 1666 @override |
| 1665 ir.InvocationExpression visitIntFromEnvironmentConstructorInvoke( | 1667 ir.InvocationExpression visitIntFromEnvironmentConstructorInvoke( |
| 1666 NewExpression node, IntFromEnvironmentConstantExpression constant, _) { | 1668 NewExpression node, IntFromEnvironmentConstantExpression constant, _) { |
| 1667 return buildConstructorInvoke(node, isConst: true); | 1669 return buildConstructorInvoke(node, isConst: true); |
| 1668 } | 1670 } |
| 1669 | 1671 |
| 1670 ir.IsExpression buildIs(Node expression, DartType type) { | 1672 ir.IsExpression buildIs(Node expression, ResolutionDartType type) { |
| 1671 return new ir.IsExpression( | 1673 return new ir.IsExpression( |
| 1672 visitForValue(expression), kernel.typeToIr(type)); | 1674 visitForValue(expression), kernel.typeToIr(type)); |
| 1673 } | 1675 } |
| 1674 | 1676 |
| 1675 @override | 1677 @override |
| 1676 ir.IsExpression visitIs(Send node, Node expression, DartType type, _) { | 1678 ir.IsExpression visitIs( |
| 1679 Send node, Node expression, ResolutionDartType type, _) { |
| 1677 return buildIs(expression, type); | 1680 return buildIs(expression, type); |
| 1678 } | 1681 } |
| 1679 | 1682 |
| 1680 @override | 1683 @override |
| 1681 ir.Not visitIsNot(Send node, Node expression, DartType type, _) { | 1684 ir.Not visitIsNot(Send node, Node expression, ResolutionDartType type, _) { |
| 1682 return new ir.Not(buildIs(expression, type)); | 1685 return new ir.Not(buildIs(expression, type)); |
| 1683 } | 1686 } |
| 1684 | 1687 |
| 1685 ir.VariableDeclaration buildLocalVariableDeclaration( | 1688 ir.VariableDeclaration buildLocalVariableDeclaration( |
| 1686 LocalVariableElement variable, Node initializer) { | 1689 LocalVariableElement variable, Node initializer) { |
| 1687 ir.Expression initializerNode = visitForValue(initializer); | 1690 ir.Expression initializerNode = visitForValue(initializer); |
| 1688 ir.VariableDeclaration local = getLocal(variable); | 1691 ir.VariableDeclaration local = getLocal(variable); |
| 1689 if (initializer != null) { | 1692 if (initializer != null) { |
| 1690 local.initializer = initializerNode; | 1693 local.initializer = initializerNode; |
| 1691 initializerNode.parent = local; | 1694 initializerNode.parent = local; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 return new VariableAccessor(getLocal(local)).buildNullAwareAssignment( | 1895 return new VariableAccessor(getLocal(local)).buildNullAwareAssignment( |
| 1893 visitForValue(rhs), null, | 1896 visitForValue(rhs), null, |
| 1894 voidContext: isVoidContext); | 1897 voidContext: isVoidContext); |
| 1895 } | 1898 } |
| 1896 | 1899 |
| 1897 @override | 1900 @override |
| 1898 IrFunction visitRedirectingFactoryConstructorDeclaration( | 1901 IrFunction visitRedirectingFactoryConstructorDeclaration( |
| 1899 FunctionExpression node, | 1902 FunctionExpression node, |
| 1900 ConstructorElement constructor, | 1903 ConstructorElement constructor, |
| 1901 NodeList parameters, | 1904 NodeList parameters, |
| 1902 DartType redirectionType, // TODO(ahe): Should be InterfaceType. | 1905 ResolutionDartType redirectionType, // TODO(ahe): Should be InterfaceType. |
| 1903 ConstructorElement redirectionTarget, | 1906 ConstructorElement redirectionTarget, |
| 1904 _) { | 1907 _) { |
| 1905 if (!constructor.isFactoryConstructor) { | 1908 if (!constructor.isFactoryConstructor) { |
| 1906 // TODO(ahe): This seems like a bug in semantic visitor and how it | 1909 // TODO(ahe): This seems like a bug in semantic visitor and how it |
| 1907 // recovers from a bad constructor. | 1910 // recovers from a bad constructor. |
| 1908 return new IrFunction.constructor(buildFunctionNode(constructor, null), | 1911 return new IrFunction.constructor(buildFunctionNode(constructor, null), |
| 1909 <ir.Initializer>[new ir.InvalidInitializer()]); | 1912 <ir.Initializer>[new ir.InvalidInitializer()]); |
| 1910 } | 1913 } |
| 1911 ir.Statement body = null; | 1914 ir.Statement body = null; |
| 1912 if (kernel.isSyntheticError(redirectionTarget)) { | 1915 if (kernel.isSyntheticError(redirectionTarget)) { |
| 1913 body = new ir.InvalidStatement(); | 1916 body = new ir.InvalidStatement(); |
| 1914 } else { | 1917 } else { |
| 1915 // TODO(ahe): This should be implemented, but doesn't matter much unless | 1918 // TODO(ahe): This should be implemented, but doesn't matter much unless |
| 1916 // we support reflection. At the call-site, we bypass this factory and | 1919 // we support reflection. At the call-site, we bypass this factory and |
| 1917 // call its effective target directly. So this factory is only necessary | 1920 // call its effective target directly. So this factory is only necessary |
| 1918 // for reflection. | 1921 // for reflection. |
| 1919 body = new ir.InvalidStatement(); | 1922 body = new ir.InvalidStatement(); |
| 1920 } | 1923 } |
| 1921 IrFunction function = | 1924 IrFunction function = |
| 1922 buildIrFunction(ir.ProcedureKind.Factory, constructor, null); | 1925 buildIrFunction(ir.ProcedureKind.Factory, constructor, null); |
| 1923 function.node.body = body..parent = function.node; | 1926 function.node.body = body..parent = function.node; |
| 1924 return function; | 1927 return function; |
| 1925 } | 1928 } |
| 1926 | 1929 |
| 1927 @override | 1930 @override |
| 1928 ir.InvocationExpression visitRedirectingFactoryConstructorInvoke( | 1931 ir.InvocationExpression visitRedirectingFactoryConstructorInvoke( |
| 1929 NewExpression node, | 1932 NewExpression node, |
| 1930 ConstructorElement constructor, | 1933 ConstructorElement constructor, |
| 1931 InterfaceType type, | 1934 ResolutionInterfaceType type, |
| 1932 ConstructorElement effectiveTarget, | 1935 ConstructorElement effectiveTarget, |
| 1933 InterfaceType effectiveTargetType, | 1936 ResolutionInterfaceType effectiveTargetType, |
| 1934 NodeList arguments, | 1937 NodeList arguments, |
| 1935 CallStructure callStructure, | 1938 CallStructure callStructure, |
| 1936 _) { | 1939 _) { |
| 1937 return buildConstructorInvoke(node, isConst: false); | 1940 return buildConstructorInvoke(node, isConst: false); |
| 1938 } | 1941 } |
| 1939 | 1942 |
| 1940 @override | 1943 @override |
| 1941 IrFunction visitRedirectingGenerativeConstructorDeclaration( | 1944 IrFunction visitRedirectingGenerativeConstructorDeclaration( |
| 1942 FunctionExpression node, | 1945 FunctionExpression node, |
| 1943 ConstructorElement constructor, | 1946 ConstructorElement constructor, |
| 1944 NodeList parameters, | 1947 NodeList parameters, |
| 1945 NodeList initializers, | 1948 NodeList initializers, |
| 1946 _) { | 1949 _) { |
| 1947 return buildGenerativeConstructor(constructor, parameters, null); | 1950 return buildGenerativeConstructor(constructor, parameters, null); |
| 1948 } | 1951 } |
| 1949 | 1952 |
| 1950 @override | 1953 @override |
| 1951 ir.InvocationExpression visitRedirectingGenerativeConstructorInvoke( | 1954 ir.InvocationExpression visitRedirectingGenerativeConstructorInvoke( |
| 1952 NewExpression node, | 1955 NewExpression node, |
| 1953 ConstructorElement constructor, | 1956 ConstructorElement constructor, |
| 1954 InterfaceType type, | 1957 ResolutionInterfaceType type, |
| 1955 NodeList arguments, | 1958 NodeList arguments, |
| 1956 CallStructure callStructure, | 1959 CallStructure callStructure, |
| 1957 _) { | 1960 _) { |
| 1958 return buildConstructorInvoke(node, isConst: false); | 1961 return buildConstructorInvoke(node, isConst: false); |
| 1959 } | 1962 } |
| 1960 | 1963 |
| 1961 @override | 1964 @override |
| 1962 visitStaticConstantDeclaration(VariableDefinitions node, Node definition, | 1965 visitStaticConstantDeclaration(VariableDefinitions node, Node definition, |
| 1963 FieldElement field, ConstantExpression constant, _) { | 1966 FieldElement field, ConstantExpression constant, _) { |
| 1964 // Shouldn't be called, handled by fieldToIr. | 1967 // Shouldn't be called, handled by fieldToIr. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 kernel.parameterInitializerNodeToConstant[initializer] = | 2056 kernel.parameterInitializerNodeToConstant[initializer] = |
| 2054 parameter.constant; | 2057 parameter.constant; |
| 2055 } | 2058 } |
| 2056 }); | 2059 }); |
| 2057 if (function.isGenerativeConstructor) { | 2060 if (function.isGenerativeConstructor) { |
| 2058 returnType = const ir.VoidType(); | 2061 returnType = const ir.VoidType(); |
| 2059 } else { | 2062 } else { |
| 2060 returnType = typeToIrHack(signature.type.returnType); | 2063 returnType = typeToIrHack(signature.type.returnType); |
| 2061 } | 2064 } |
| 2062 if (function.isFactoryConstructor) { | 2065 if (function.isFactoryConstructor) { |
| 2063 InterfaceType type = function.enclosingClass.thisType; | 2066 ResolutionInterfaceType type = function.enclosingClass.thisType; |
| 2064 if (type.isGeneric) { | 2067 if (type.isGeneric) { |
| 2065 typeParameters = new List<ir.TypeParameter>(); | 2068 typeParameters = new List<ir.TypeParameter>(); |
| 2066 for (DartType parameter in type.typeArguments) { | 2069 for (ResolutionDartType parameter in type.typeArguments) { |
| 2067 typeParameters.add(kernel.typeVariableToIr(parameter.element)); | 2070 typeParameters.add(kernel.typeVariableToIr(parameter.element)); |
| 2068 } | 2071 } |
| 2069 } | 2072 } |
| 2070 } | 2073 } |
| 2071 } | 2074 } |
| 2072 ir.AsyncMarker asyncMarker = ir.AsyncMarker.Sync; | 2075 ir.AsyncMarker asyncMarker = ir.AsyncMarker.Sync; |
| 2073 if (!kernel.isSyntheticError(function)) { | 2076 if (!kernel.isSyntheticError(function)) { |
| 2074 switch (function.asyncMarker) { | 2077 switch (function.asyncMarker) { |
| 2075 case AsyncMarker.SYNC: | 2078 case AsyncMarker.SYNC: |
| 2076 asyncMarker = ir.AsyncMarker.Sync; | 2079 asyncMarker = ir.AsyncMarker.Sync; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2290 node, | 2293 node, |
| 2291 buildSuperIndexAccessor(index, getter, setter), | 2294 buildSuperIndexAccessor(index, getter, setter), |
| 2292 kernel.irName(operator.selectorName, currentElement), | 2295 kernel.irName(operator.selectorName, currentElement), |
| 2293 visitForValue(rhs)); | 2296 visitForValue(rhs)); |
| 2294 } | 2297 } |
| 2295 | 2298 |
| 2296 @override | 2299 @override |
| 2297 ir.Initializer visitSuperConstructorInvoke( | 2300 ir.Initializer visitSuperConstructorInvoke( |
| 2298 Send node, | 2301 Send node, |
| 2299 ConstructorElement superConstructor, | 2302 ConstructorElement superConstructor, |
| 2300 InterfaceType type, | 2303 ResolutionInterfaceType type, |
| 2301 NodeList arguments, | 2304 NodeList arguments, |
| 2302 CallStructure callStructure, | 2305 CallStructure callStructure, |
| 2303 _) { | 2306 _) { |
| 2304 if (kernel.isSyntheticError(superConstructor)) { | 2307 if (kernel.isSyntheticError(superConstructor)) { |
| 2305 // TODO(ahe): Semantic visitor shouldn't call in this case. | 2308 // TODO(ahe): Semantic visitor shouldn't call in this case. |
| 2306 return new ir.InvalidInitializer(); | 2309 return new ir.InvalidInitializer(); |
| 2307 } | 2310 } |
| 2308 return new ir.SuperInitializer( | 2311 return new ir.SuperInitializer( |
| 2309 kernel.functionToIr(superConstructor), buildArguments(arguments)); | 2312 kernel.functionToIr(superConstructor), buildArguments(arguments)); |
| 2310 } | 2313 } |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2850 : this(null, true, node, initializers); | 2853 : this(null, true, node, initializers); |
| 2851 | 2854 |
| 2852 accept(ir.Visitor v) => throw "unsupported"; | 2855 accept(ir.Visitor v) => throw "unsupported"; |
| 2853 | 2856 |
| 2854 visitChildren(ir.Visitor v) => throw "unsupported"; | 2857 visitChildren(ir.Visitor v) => throw "unsupported"; |
| 2855 | 2858 |
| 2856 String toString() { | 2859 String toString() { |
| 2857 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 2860 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
| 2858 } | 2861 } |
| 2859 } | 2862 } |
| OLD | NEW |