| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 library dart2js.ir_nodes; | 4 library dart2js.ir_nodes; |
| 5 | 5 |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import '../constants/values.dart' as values; | 7 import '../constants/values.dart' as values; |
| 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../io/source_information.dart' show SourceInformation; | 10 import '../io/source_information.dart' show SourceInformation; |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 /// | 582 /// |
| 583 /// Returns `true` if [value] is an instance of [type]. | 583 /// Returns `true` if [value] is an instance of [type]. |
| 584 /// | 584 /// |
| 585 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might | 585 /// [type] must not be the [Object], `dynamic` or [Null] types (though it might |
| 586 /// be a type variable containing one of these types). This design is chosen | 586 /// be a type variable containing one of these types). This design is chosen |
| 587 /// to simplify code generation for type tests. | 587 /// to simplify code generation for type tests. |
| 588 class TypeTest extends Primitive { | 588 class TypeTest extends Primitive { |
| 589 Reference<Primitive> value; | 589 Reference<Primitive> value; |
| 590 final DartType dartType; | 590 final DartType dartType; |
| 591 | 591 |
| 592 /// If [dartType] is an [InterfaceType], this holds the internal | 592 /// If [type] is an [InterfaceType], this holds the internal representation of |
| 593 /// representation of the type arguments to [dartType]. Since these may | 593 /// the type arguments to [type]. Since these may reference type variables |
| 594 /// reference type variables from the enclosing class, they are not constant. | 594 /// from the enclosing class, they are not constant. |
| 595 /// | 595 /// |
| 596 /// If [dartType] is a [TypeVariableType], this is a singleton list with the | 596 /// If [type] is a [TypeVariableType], this is a singleton list with |
| 597 /// internal representation of the type held in that type variable. | 597 /// the internal representation of the type held in that type variable. |
| 598 /// | 598 /// |
| 599 /// If [dartType] is a [FunctionType], this is a singleton list with the | 599 /// If [type] is a [FunctionType], this is a singleton list with the |
| 600 /// internal representation of that type, | 600 /// internal representation of that type, |
| 601 /// | 601 /// |
| 602 /// Otherwise the list is empty. | 602 /// Otherwise the list is empty. |
| 603 final List<Reference<Primitive>> typeArguments; | 603 final List<Reference<Primitive>> typeArguments; |
| 604 | 604 |
| 605 /// The Interceptor for [value]. May be `null` if the test can be done | |
| 606 /// without an interceptor. May be the same as [value] after self-interceptor | |
| 607 /// optimization. | |
| 608 // TODO(24523): Remove this field. | |
| 609 Reference<Primitive> interceptor; | |
| 610 | |
| 611 TypeTest(Primitive value, | 605 TypeTest(Primitive value, |
| 612 this.dartType, | 606 this.dartType, |
| 613 List<Primitive> typeArguments) | 607 List<Primitive> typeArguments) |
| 614 : this.value = new Reference<Primitive>(value), | 608 : this.value = new Reference<Primitive>(value), |
| 615 this.typeArguments = _referenceList(typeArguments); | 609 this.typeArguments = _referenceList(typeArguments); |
| 616 | 610 |
| 617 accept(Visitor visitor) => visitor.visitTypeTest(this); | 611 accept(Visitor visitor) => visitor.visitTypeTest(this); |
| 618 | 612 |
| 619 bool get isSafeForElimination => true; | 613 bool get isSafeForElimination => true; |
| 620 bool get isSafeForReordering => true; | 614 bool get isSafeForReordering => true; |
| 621 } | 615 } |
| 622 | 616 |
| 623 /// An "is" type test for a raw type, performed by testing a flag property. | |
| 624 /// | |
| 625 /// Returns `true` if [interceptor] is for [dartType]. | |
| 626 class TypeTestViaFlag extends Primitive { | |
| 627 Reference<Primitive> interceptor; | |
| 628 final DartType dartType; | |
| 629 | |
| 630 TypeTestViaFlag(Primitive interceptor, this.dartType) | |
| 631 : this.interceptor = new Reference<Primitive>(interceptor); | |
| 632 | |
| 633 accept(Visitor visitor) => visitor.visitTypeTestViaFlag(this); | |
| 634 | |
| 635 bool get isSafeForElimination => true; | |
| 636 bool get isSafeForReordering => true; | |
| 637 } | |
| 638 | |
| 639 /// An "as" type cast. | 617 /// An "as" type cast. |
| 640 /// | 618 /// |
| 641 /// If [value] is `null` or is an instance of [type], [continuation] is invoked | 619 /// If [value] is `null` or is an instance of [type], [continuation] is invoked |
| 642 /// with [value] as argument. Otherwise, a [CastError] is thrown. | 620 /// with [value] as argument. Otherwise, a [CastError] is thrown. |
| 643 /// | 621 /// |
| 644 /// Discussion: | 622 /// Discussion: |
| 645 /// The parameter to [continuation] is redundant since it will always equal | 623 /// The parameter to [continuation] is redundant since it will always equal |
| 646 /// [value], which is typically in scope in the continuation. However, it might | 624 /// [value], which is typically in scope in the continuation. However, it might |
| 647 /// simplify type propagation, since a better type can be computed for the | 625 /// simplify type propagation, since a better type can be computed for the |
| 648 /// continuation parameter without needing flow-sensitive analysis. | 626 /// continuation parameter without needing flow-sensitive analysis. |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 T visitGetStatic(GetStatic node); | 1364 T visitGetStatic(GetStatic node); |
| 1387 T visitInterceptor(Interceptor node); | 1365 T visitInterceptor(Interceptor node); |
| 1388 T visitCreateInstance(CreateInstance node); | 1366 T visitCreateInstance(CreateInstance node); |
| 1389 T visitGetField(GetField node); | 1367 T visitGetField(GetField node); |
| 1390 T visitCreateBox(CreateBox node); | 1368 T visitCreateBox(CreateBox node); |
| 1391 T visitReifyRuntimeType(ReifyRuntimeType node); | 1369 T visitReifyRuntimeType(ReifyRuntimeType node); |
| 1392 T visitReadTypeVariable(ReadTypeVariable node); | 1370 T visitReadTypeVariable(ReadTypeVariable node); |
| 1393 T visitTypeExpression(TypeExpression node); | 1371 T visitTypeExpression(TypeExpression node); |
| 1394 T visitCreateInvocationMirror(CreateInvocationMirror node); | 1372 T visitCreateInvocationMirror(CreateInvocationMirror node); |
| 1395 T visitTypeTest(TypeTest node); | 1373 T visitTypeTest(TypeTest node); |
| 1396 T visitTypeTestViaFlag(TypeTestViaFlag node); | |
| 1397 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); | 1374 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); |
| 1398 T visitApplyBuiltinMethod(ApplyBuiltinMethod node); | 1375 T visitApplyBuiltinMethod(ApplyBuiltinMethod node); |
| 1399 T visitGetLength(GetLength node); | 1376 T visitGetLength(GetLength node); |
| 1400 T visitGetIndex(GetIndex node); | 1377 T visitGetIndex(GetIndex node); |
| 1401 T visitSetIndex(SetIndex node); | 1378 T visitSetIndex(SetIndex node); |
| 1402 T visitRefinement(Refinement node); | 1379 T visitRefinement(Refinement node); |
| 1403 | 1380 |
| 1404 // Support for literal foreign code. | 1381 // Support for literal foreign code. |
| 1405 T visitForeignCode(ForeignCode node); | 1382 T visitForeignCode(ForeignCode node); |
| 1406 } | 1383 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 processTypeCast(node); | 1489 processTypeCast(node); |
| 1513 processReference(node.continuation); | 1490 processReference(node.continuation); |
| 1514 processReference(node.value); | 1491 processReference(node.value); |
| 1515 node.typeArguments.forEach(processReference); | 1492 node.typeArguments.forEach(processReference); |
| 1516 } | 1493 } |
| 1517 | 1494 |
| 1518 processTypeTest(TypeTest node) {} | 1495 processTypeTest(TypeTest node) {} |
| 1519 visitTypeTest(TypeTest node) { | 1496 visitTypeTest(TypeTest node) { |
| 1520 processTypeTest(node); | 1497 processTypeTest(node); |
| 1521 processReference(node.value); | 1498 processReference(node.value); |
| 1522 if (node.interceptor != null) processReference(node.interceptor); | |
| 1523 node.typeArguments.forEach(processReference); | 1499 node.typeArguments.forEach(processReference); |
| 1524 } | 1500 } |
| 1525 | 1501 |
| 1526 processTypeTestViaFlag(TypeTestViaFlag node) {} | |
| 1527 visitTypeTestViaFlag(TypeTestViaFlag node) { | |
| 1528 processTypeTestViaFlag(node); | |
| 1529 processReference(node.interceptor); | |
| 1530 } | |
| 1531 | |
| 1532 processSetMutable(SetMutable node) {} | 1502 processSetMutable(SetMutable node) {} |
| 1533 visitSetMutable(SetMutable node) { | 1503 visitSetMutable(SetMutable node) { |
| 1534 processSetMutable(node); | 1504 processSetMutable(node); |
| 1535 processReference(node.variable); | 1505 processReference(node.variable); |
| 1536 processReference(node.value); | 1506 processReference(node.value); |
| 1537 } | 1507 } |
| 1538 | 1508 |
| 1539 processGetLazyStatic(GetLazyStatic node) {} | 1509 processGetLazyStatic(GetLazyStatic node) {} |
| 1540 visitGetLazyStatic(GetLazyStatic node) { | 1510 visitGetLazyStatic(GetLazyStatic node) { |
| 1541 processGetLazyStatic(node); | 1511 processGetLazyStatic(node); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 /// Visit a just-deleted subterm and unlink all [Reference]s in it. | 1817 /// Visit a just-deleted subterm and unlink all [Reference]s in it. |
| 1848 class RemovalVisitor extends RecursiveVisitor { | 1818 class RemovalVisitor extends RecursiveVisitor { |
| 1849 processReference(Reference reference) { | 1819 processReference(Reference reference) { |
| 1850 reference.unlink(); | 1820 reference.unlink(); |
| 1851 } | 1821 } |
| 1852 | 1822 |
| 1853 static void remove(Node node) { | 1823 static void remove(Node node) { |
| 1854 (new RemovalVisitor()).visit(node); | 1824 (new RemovalVisitor()).visit(node); |
| 1855 } | 1825 } |
| 1856 } | 1826 } |
| OLD | NEW |