| 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 [type] is an [InterfaceType], this holds the internal representation of | 592 /// If [dartType] is an [InterfaceType], this holds the internal |
| 593 /// the type arguments to [type]. Since these may reference type variables | 593 /// representation of the type arguments to [dartType]. Since these may |
| 594 /// from the enclosing class, they are not constant. | 594 /// reference type variables from the enclosing class, they are not constant. |
| 595 /// | 595 /// |
| 596 /// If [type] is a [TypeVariableType], this is a singleton list with | 596 /// If [dartType] is a [TypeVariableType], this is a singleton list with the |
| 597 /// the internal representation of the type held in that type variable. | 597 /// internal representation of the type held in that type variable. |
| 598 /// | 598 /// |
| 599 /// If [type] is a [FunctionType], this is a singleton list with the | 599 /// If [dartType] 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 |
| 605 TypeTest(Primitive value, | 611 TypeTest(Primitive value, |
| 606 this.dartType, | 612 this.dartType, |
| 607 List<Primitive> typeArguments) | 613 List<Primitive> typeArguments) |
| 608 : this.value = new Reference<Primitive>(value), | 614 : this.value = new Reference<Primitive>(value), |
| 609 this.typeArguments = _referenceList(typeArguments); | 615 this.typeArguments = _referenceList(typeArguments); |
| 610 | 616 |
| 611 accept(Visitor visitor) => visitor.visitTypeTest(this); | 617 accept(Visitor visitor) => visitor.visitTypeTest(this); |
| 612 | 618 |
| 613 bool get isSafeForElimination => true; | 619 bool get isSafeForElimination => true; |
| 614 bool get isSafeForReordering => true; | 620 bool get isSafeForReordering => true; |
| 615 } | 621 } |
| 616 | 622 |
| 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 |
| 617 /// An "as" type cast. | 639 /// An "as" type cast. |
| 618 /// | 640 /// |
| 619 /// If [value] is `null` or is an instance of [type], [continuation] is invoked | 641 /// If [value] is `null` or is an instance of [type], [continuation] is invoked |
| 620 /// with [value] as argument. Otherwise, a [CastError] is thrown. | 642 /// with [value] as argument. Otherwise, a [CastError] is thrown. |
| 621 /// | 643 /// |
| 622 /// Discussion: | 644 /// Discussion: |
| 623 /// The parameter to [continuation] is redundant since it will always equal | 645 /// The parameter to [continuation] is redundant since it will always equal |
| 624 /// [value], which is typically in scope in the continuation. However, it might | 646 /// [value], which is typically in scope in the continuation. However, it might |
| 625 /// simplify type propagation, since a better type can be computed for the | 647 /// simplify type propagation, since a better type can be computed for the |
| 626 /// continuation parameter without needing flow-sensitive analysis. | 648 /// continuation parameter without needing flow-sensitive analysis. |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1364 T visitGetStatic(GetStatic node); | 1386 T visitGetStatic(GetStatic node); |
| 1365 T visitInterceptor(Interceptor node); | 1387 T visitInterceptor(Interceptor node); |
| 1366 T visitCreateInstance(CreateInstance node); | 1388 T visitCreateInstance(CreateInstance node); |
| 1367 T visitGetField(GetField node); | 1389 T visitGetField(GetField node); |
| 1368 T visitCreateBox(CreateBox node); | 1390 T visitCreateBox(CreateBox node); |
| 1369 T visitReifyRuntimeType(ReifyRuntimeType node); | 1391 T visitReifyRuntimeType(ReifyRuntimeType node); |
| 1370 T visitReadTypeVariable(ReadTypeVariable node); | 1392 T visitReadTypeVariable(ReadTypeVariable node); |
| 1371 T visitTypeExpression(TypeExpression node); | 1393 T visitTypeExpression(TypeExpression node); |
| 1372 T visitCreateInvocationMirror(CreateInvocationMirror node); | 1394 T visitCreateInvocationMirror(CreateInvocationMirror node); |
| 1373 T visitTypeTest(TypeTest node); | 1395 T visitTypeTest(TypeTest node); |
| 1396 T visitTypeTestViaFlag(TypeTestViaFlag node); |
| 1374 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); | 1397 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); |
| 1375 T visitApplyBuiltinMethod(ApplyBuiltinMethod node); | 1398 T visitApplyBuiltinMethod(ApplyBuiltinMethod node); |
| 1376 T visitGetLength(GetLength node); | 1399 T visitGetLength(GetLength node); |
| 1377 T visitGetIndex(GetIndex node); | 1400 T visitGetIndex(GetIndex node); |
| 1378 T visitSetIndex(SetIndex node); | 1401 T visitSetIndex(SetIndex node); |
| 1379 T visitRefinement(Refinement node); | 1402 T visitRefinement(Refinement node); |
| 1380 | 1403 |
| 1381 // Support for literal foreign code. | 1404 // Support for literal foreign code. |
| 1382 T visitForeignCode(ForeignCode node); | 1405 T visitForeignCode(ForeignCode node); |
| 1383 } | 1406 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1489 processTypeCast(node); | 1512 processTypeCast(node); |
| 1490 processReference(node.continuation); | 1513 processReference(node.continuation); |
| 1491 processReference(node.value); | 1514 processReference(node.value); |
| 1492 node.typeArguments.forEach(processReference); | 1515 node.typeArguments.forEach(processReference); |
| 1493 } | 1516 } |
| 1494 | 1517 |
| 1495 processTypeTest(TypeTest node) {} | 1518 processTypeTest(TypeTest node) {} |
| 1496 visitTypeTest(TypeTest node) { | 1519 visitTypeTest(TypeTest node) { |
| 1497 processTypeTest(node); | 1520 processTypeTest(node); |
| 1498 processReference(node.value); | 1521 processReference(node.value); |
| 1522 if (node.interceptor != null) processReference(node.interceptor); |
| 1499 node.typeArguments.forEach(processReference); | 1523 node.typeArguments.forEach(processReference); |
| 1500 } | 1524 } |
| 1501 | 1525 |
| 1526 processTypeTestViaFlag(TypeTestViaFlag node) {} |
| 1527 visitTypeTestViaFlag(TypeTestViaFlag node) { |
| 1528 processTypeTestViaFlag(node); |
| 1529 processReference(node.interceptor); |
| 1530 } |
| 1531 |
| 1502 processSetMutable(SetMutable node) {} | 1532 processSetMutable(SetMutable node) {} |
| 1503 visitSetMutable(SetMutable node) { | 1533 visitSetMutable(SetMutable node) { |
| 1504 processSetMutable(node); | 1534 processSetMutable(node); |
| 1505 processReference(node.variable); | 1535 processReference(node.variable); |
| 1506 processReference(node.value); | 1536 processReference(node.value); |
| 1507 } | 1537 } |
| 1508 | 1538 |
| 1509 processGetLazyStatic(GetLazyStatic node) {} | 1539 processGetLazyStatic(GetLazyStatic node) {} |
| 1510 visitGetLazyStatic(GetLazyStatic node) { | 1540 visitGetLazyStatic(GetLazyStatic node) { |
| 1511 processGetLazyStatic(node); | 1541 processGetLazyStatic(node); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1817 /// Visit a just-deleted subterm and unlink all [Reference]s in it. | 1847 /// Visit a just-deleted subterm and unlink all [Reference]s in it. |
| 1818 class RemovalVisitor extends RecursiveVisitor { | 1848 class RemovalVisitor extends RecursiveVisitor { |
| 1819 processReference(Reference reference) { | 1849 processReference(Reference reference) { |
| 1820 reference.unlink(); | 1850 reference.unlink(); |
| 1821 } | 1851 } |
| 1822 | 1852 |
| 1823 static void remove(Node node) { | 1853 static void remove(Node node) { |
| 1824 (new RemovalVisitor()).visit(node); | 1854 (new RemovalVisitor()).visit(node); |
| 1825 } | 1855 } |
| 1826 } | 1856 } |
| OLD | NEW |