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