| 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 library rasta.kernel_visitor; | 5 library rasta.kernel_visitor; |
| 6 | 6 |
| 7 import 'package:kernel/ast.dart' as ir; | 7 import 'package:kernel/ast.dart' as ir; |
| 8 | 8 |
| 9 import 'package:kernel/frontend/accessors.dart' show | 9 import 'package:kernel/frontend/accessors.dart' show |
| 10 Accessor, | 10 Accessor, |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 currentElement.enclosingClass.asInstanceOf(superclass); | 300 currentElement.enclosingClass.asInstanceOf(superclass); |
| 301 // Once we have [supertype], we know how to substitute S with T: the type | 301 // Once we have [supertype], we know how to substitute S with T: the type |
| 302 // arguments of [supertype] corresponds to T, and the type variables of | 302 // arguments of [supertype] corresponds to T, and the type variables of |
| 303 // its element correspond to S. | 303 // its element correspond to S. |
| 304 type = type.subst( | 304 type = type.subst( |
| 305 supertype.typeArguments, supertype.element.typeVariables); | 305 supertype.typeArguments, supertype.element.typeVariables); |
| 306 } | 306 } |
| 307 return kernel.typeToIr(type); | 307 return kernel.typeToIr(type); |
| 308 } | 308 } |
| 309 | 309 |
| 310 // TODO(ahe): Hack. Fix dart2js instead. |
| 311 ir.Name nameToIrName(Name name) { |
| 312 assert( |
| 313 !name.isPrivate || |
| 314 name.library.implementation == currentElement.library.implementation); |
| 315 return kernel.irName(name.text, currentElement); |
| 316 } |
| 317 |
| 310 List<ir.DartType> computeTypesFromTypes(NodeList nodes, {int expected}) { | 318 List<ir.DartType> computeTypesFromTypes(NodeList nodes, {int expected}) { |
| 311 if (expected == null) { | 319 if (expected == null) { |
| 312 throw "[expected] is null"; | 320 throw "[expected] is null"; |
| 313 } | 321 } |
| 314 List<ir.DartType> types = new List<ir.DartType>(expected); | 322 List<ir.DartType> types = new List<ir.DartType>(expected); |
| 315 Iterator<Node> iterator = nodes?.iterator; | 323 Iterator<Node> iterator = nodes?.iterator; |
| 316 for (int i = 0; i < expected; i++) { | 324 for (int i = 0; i < expected; i++) { |
| 317 TypeAnnotation type = null; | 325 TypeAnnotation type = null; |
| 318 if (iterator != null && iterator.moveNext()) { | 326 if (iterator != null && iterator.moveNext()) { |
| 319 type = iterator.current; | 327 type = iterator.current; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 330 | 338 |
| 331 ir.DartType computeTypeFromTypes(NodeList node) { | 339 ir.DartType computeTypeFromTypes(NodeList node) { |
| 332 return computeTypesFromTypes(node, expected: 1).single; | 340 return computeTypesFromTypes(node, expected: 1).single; |
| 333 } | 341 } |
| 334 | 342 |
| 335 ir.MethodInvocation buildInvokeSelector( | 343 ir.MethodInvocation buildInvokeSelector( |
| 336 ir.Expression receiver, | 344 ir.Expression receiver, |
| 337 Selector selector, | 345 Selector selector, |
| 338 ir.Arguments arguments) { | 346 ir.Arguments arguments) { |
| 339 return new ir.MethodInvocation( | 347 return new ir.MethodInvocation( |
| 340 receiver, kernel.nameToIrName(selector.memberName), arguments); | 348 receiver, nameToIrName(selector.memberName), arguments); |
| 341 } | 349 } |
| 342 | 350 |
| 343 ir.MethodInvocation buildCall( | 351 ir.MethodInvocation buildCall( |
| 344 ir.Expression receiver, | 352 ir.Expression receiver, |
| 345 CallStructure callStructure, | 353 CallStructure callStructure, |
| 346 NodeList arguments) { | 354 NodeList arguments) { |
| 347 return buildInvokeSelector( | 355 return buildInvokeSelector( |
| 348 receiver, callStructure.callSelector, buildArguments(arguments)); | 356 receiver, callStructure.callSelector, buildArguments(arguments)); |
| 349 } | 357 } |
| 350 | 358 |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 return new ir.InvalidExpression(); | 1292 return new ir.InvalidExpression(); |
| 1285 } | 1293 } |
| 1286 | 1294 |
| 1287 @override | 1295 @override |
| 1288 ir.PropertyGet visitDynamicPropertyGet( | 1296 ir.PropertyGet visitDynamicPropertyGet( |
| 1289 Send node, | 1297 Send node, |
| 1290 Node receiver, | 1298 Node receiver, |
| 1291 Name name, | 1299 Name name, |
| 1292 _) { | 1300 _) { |
| 1293 return new ir.PropertyGet( | 1301 return new ir.PropertyGet( |
| 1294 visitForValue(receiver), kernel.nameToIrName(name)); | 1302 visitForValue(receiver), nameToIrName(name)); |
| 1295 } | 1303 } |
| 1296 | 1304 |
| 1297 @override | 1305 @override |
| 1298 ir.MethodInvocation visitDynamicPropertyInvoke( | 1306 ir.MethodInvocation visitDynamicPropertyInvoke( |
| 1299 Send node, | 1307 Send node, |
| 1300 Node receiver, | 1308 Node receiver, |
| 1301 NodeList arguments, | 1309 NodeList arguments, |
| 1302 Selector selector, | 1310 Selector selector, |
| 1303 _) { | 1311 _) { |
| 1304 return buildInvokeSelector( | 1312 return buildInvokeSelector( |
| 1305 visitForValue(receiver), selector, buildArguments(arguments)); | 1313 visitForValue(receiver), selector, buildArguments(arguments)); |
| 1306 } | 1314 } |
| 1307 | 1315 |
| 1308 @override | 1316 @override |
| 1309 ir.Expression handleDynamicCompounds( | 1317 ir.Expression handleDynamicCompounds( |
| 1310 Send node, | 1318 Send node, |
| 1311 Node receiver, | 1319 Node receiver, |
| 1312 Name name, | 1320 Name name, |
| 1313 CompoundRhs rhs, | 1321 CompoundRhs rhs, |
| 1314 _) { | 1322 _) { |
| 1315 ir.Expression receiverNode = receiver == null | 1323 ir.Expression receiverNode = receiver == null |
| 1316 ? new ir.ThisExpression() : visitForValue(receiver); | 1324 ? new ir.ThisExpression() : visitForValue(receiver); |
| 1317 return buildCompound( | 1325 return buildCompound( |
| 1318 PropertyAccessor.make(receiverNode, kernel.nameToIrName(name)), rhs); | 1326 PropertyAccessor.make(receiverNode, nameToIrName(name)), rhs); |
| 1319 } | 1327 } |
| 1320 | 1328 |
| 1321 @override | 1329 @override |
| 1322 ir.PropertySet visitDynamicPropertySet( | 1330 ir.PropertySet visitDynamicPropertySet( |
| 1323 SendSet node, | 1331 SendSet node, |
| 1324 Node receiver, | 1332 Node receiver, |
| 1325 Name name, | 1333 Name name, |
| 1326 Node rhs, | 1334 Node rhs, |
| 1327 _) { | 1335 _) { |
| 1328 ir.Expression value = visitForValue(rhs); | 1336 ir.Expression value = visitForValue(rhs); |
| 1329 return new ir.PropertySet( | 1337 return new ir.PropertySet( |
| 1330 visitForValue(receiver), kernel.nameToIrName(name), value); | 1338 visitForValue(receiver), nameToIrName(name), value); |
| 1331 } | 1339 } |
| 1332 | 1340 |
| 1333 @override | 1341 @override |
| 1334 ir.Expression handleDynamicSetIfNulls( | 1342 ir.Expression handleDynamicSetIfNulls( |
| 1335 Send node, | 1343 Send node, |
| 1336 Node receiver, | 1344 Node receiver, |
| 1337 Name name, | 1345 Name name, |
| 1338 Node rhs, | 1346 Node rhs, |
| 1339 _) { | 1347 _) { |
| 1340 ir.Name irName = kernel.nameToIrName(name); | 1348 ir.Name irName = nameToIrName(name); |
| 1341 Accessor accessor = (receiver == null) | 1349 Accessor accessor = (receiver == null) |
| 1342 ? new ThisPropertyAccessor(irName) | 1350 ? new ThisPropertyAccessor(irName) |
| 1343 : PropertyAccessor.make(visitForValue(receiver), irName); | 1351 : PropertyAccessor.make(visitForValue(receiver), irName); |
| 1344 return accessor.buildNullAwareAssignment( | 1352 return accessor.buildNullAwareAssignment( |
| 1345 visitForValue(rhs), voidContext: isVoidContext); | 1353 visitForValue(rhs), voidContext: isVoidContext); |
| 1346 } | 1354 } |
| 1347 | 1355 |
| 1348 @override | 1356 @override |
| 1349 ir.TypeLiteral visitDynamicTypeLiteralGet( | 1357 ir.TypeLiteral visitDynamicTypeLiteralGet( |
| 1350 Send node, | 1358 Send node, |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1570 ConstructorElement constructor, | 1578 ConstructorElement constructor, |
| 1571 InterfaceType type, | 1579 InterfaceType type, |
| 1572 NodeList arguments, | 1580 NodeList arguments, |
| 1573 CallStructure callStructure, | 1581 CallStructure callStructure, |
| 1574 _) { | 1582 _) { |
| 1575 return buildConstructorInvoke(node, isConst: false); | 1583 return buildConstructorInvoke(node, isConst: false); |
| 1576 } | 1584 } |
| 1577 | 1585 |
| 1578 Accessor buildNullAwarePropertyAccessor(Node receiver, Name name) { | 1586 Accessor buildNullAwarePropertyAccessor(Node receiver, Name name) { |
| 1579 return new NullAwarePropertyAccessor( | 1587 return new NullAwarePropertyAccessor( |
| 1580 visitForValue(receiver), kernel.nameToIrName(name)); | 1588 visitForValue(receiver), nameToIrName(name)); |
| 1581 } | 1589 } |
| 1582 | 1590 |
| 1583 @override | 1591 @override |
| 1584 ir.Expression visitIfNotNullDynamicPropertyGet( | 1592 ir.Expression visitIfNotNullDynamicPropertyGet( |
| 1585 Send node, | 1593 Send node, |
| 1586 Node receiver, | 1594 Node receiver, |
| 1587 Name name, | 1595 Name name, |
| 1588 _) { | 1596 _) { |
| 1589 return buildNullAwarePropertyAccessor(receiver, name).buildSimpleRead(); | 1597 return buildNullAwarePropertyAccessor(receiver, name).buildSimpleRead(); |
| 1590 } | 1598 } |
| (...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2717 @override | 2725 @override |
| 2718 ir.MethodInvocation visitThisInvoke( | 2726 ir.MethodInvocation visitThisInvoke( |
| 2719 Send node, | 2727 Send node, |
| 2720 NodeList arguments, | 2728 NodeList arguments, |
| 2721 CallStructure callStructure, | 2729 CallStructure callStructure, |
| 2722 _) { | 2730 _) { |
| 2723 return buildCall(new ir.ThisExpression(), callStructure, arguments); | 2731 return buildCall(new ir.ThisExpression(), callStructure, arguments); |
| 2724 } | 2732 } |
| 2725 | 2733 |
| 2726 Accessor buildThisPropertyAccessor(Name name) { | 2734 Accessor buildThisPropertyAccessor(Name name) { |
| 2727 return new ThisPropertyAccessor(kernel.nameToIrName(name)); | 2735 return new ThisPropertyAccessor(nameToIrName(name)); |
| 2728 } | 2736 } |
| 2729 | 2737 |
| 2730 @override | 2738 @override |
| 2731 ir.Expression visitThisPropertyGet(Send node, Name name, _) { | 2739 ir.Expression visitThisPropertyGet(Send node, Name name, _) { |
| 2732 return buildThisPropertyAccessor(name).buildSimpleRead(); | 2740 return buildThisPropertyAccessor(name).buildSimpleRead(); |
| 2733 } | 2741 } |
| 2734 | 2742 |
| 2735 @override | 2743 @override |
| 2736 ir.MethodInvocation visitThisPropertyInvoke( | 2744 ir.MethodInvocation visitThisPropertyInvoke( |
| 2737 Send node, | 2745 Send node, |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3030 : this(null, true, node, initializers); | 3038 : this(null, true, node, initializers); |
| 3031 | 3039 |
| 3032 accept(ir.Visitor v) => throw "unsupported"; | 3040 accept(ir.Visitor v) => throw "unsupported"; |
| 3033 | 3041 |
| 3034 visitChildren(ir.Visitor v) => throw "unsupported"; | 3042 visitChildren(ir.Visitor v) => throw "unsupported"; |
| 3035 | 3043 |
| 3036 String toString() { | 3044 String toString() { |
| 3037 return "IrFunction($kind, $isConstructor, $node, $initializers)"; | 3045 return "IrFunction($kind, $isConstructor, $node, $initializers)"; |
| 3038 } | 3046 } |
| 3039 } | 3047 } |
| OLD | NEW |