| 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 '../constants/values.dart' as values show ConstantValue; | 6 import '../constants/values.dart' as values show ConstantValue; |
| 7 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 7 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
| 8 import '../elements/elements.dart'; | 8 import '../elements/elements.dart'; |
| 9 import '../io/source_information.dart' show SourceInformation; | 9 import '../io/source_information.dart' show SourceInformation; |
| 10 import '../types/types.dart' show TypeMask; | 10 import '../types/types.dart' show TypeMask; |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 | 654 |
| 655 GetField(Primitive object, this.field) | 655 GetField(Primitive object, this.field) |
| 656 : this.object = new Reference<Primitive>(object); | 656 : this.object = new Reference<Primitive>(object); |
| 657 | 657 |
| 658 accept(Visitor visitor) => visitor.visitGetField(this); | 658 accept(Visitor visitor) => visitor.visitGetField(this); |
| 659 | 659 |
| 660 bool get isSafeForElimination => objectIsNotNull; | 660 bool get isSafeForElimination => objectIsNotNull; |
| 661 bool get isSafeForReordering => objectIsNotNull && field.isFinal; | 661 bool get isSafeForReordering => objectIsNotNull && field.isFinal; |
| 662 } | 662 } |
| 663 | 663 |
| 664 /// Get the length of a native list. |
| 665 class GetLength extends Primitive { |
| 666 final Reference<Primitive> object; |
| 667 |
| 668 /// True if the object is known not to be null. |
| 669 bool objectIsNotNull = false; |
| 670 |
| 671 GetLength(Primitive object) : this.object = new Reference<Primitive>(object); |
| 672 |
| 673 bool get isSafeForElimination => objectIsNotNull; |
| 674 bool get isSafeForReordering => false; |
| 675 |
| 676 accept(Visitor v) => v.visitGetLength(this); |
| 677 } |
| 678 |
| 679 /// Read an entry from a native list. |
| 680 /// |
| 681 /// [object] must be null or a native list, and [index] must be an integer. |
| 682 class GetIndex extends Primitive { |
| 683 final Reference<Primitive> object; |
| 684 final Reference<Primitive> index; |
| 685 |
| 686 /// True if the object is known not to be null. |
| 687 bool objectIsNotNull = false; |
| 688 |
| 689 GetIndex(Primitive object, Primitive index) |
| 690 : this.object = new Reference<Primitive>(object), |
| 691 this.index = new Reference<Primitive>(index); |
| 692 |
| 693 bool get isSafeForElimination => objectIsNotNull; |
| 694 bool get isSafeForReordering => false; |
| 695 |
| 696 accept(Visitor v) => v.visitGetIndex(this); |
| 697 } |
| 698 |
| 699 /// Set an entry on a native list. |
| 700 /// |
| 701 /// [object] must be null or a native list, and [index] must be an integer. |
| 702 /// |
| 703 /// The primitive itself has no value and may not be referenced. |
| 704 class SetIndex extends Primitive { |
| 705 final Reference<Primitive> object; |
| 706 final Reference<Primitive> index; |
| 707 final Reference<Primitive> value; |
| 708 |
| 709 SetIndex(Primitive object, Primitive index, Primitive value) |
| 710 : this.object = new Reference<Primitive>(object), |
| 711 this.index = new Reference<Primitive>(index), |
| 712 this.value = new Reference<Primitive>(value); |
| 713 |
| 714 bool get isSafeForElimination => false; |
| 715 bool get isSafeForReordering => false; |
| 716 |
| 717 accept(Visitor v) => v.visitSetIndex(this); |
| 718 } |
| 719 |
| 664 /// Reads the value of a static field or tears off a static method. | 720 /// Reads the value of a static field or tears off a static method. |
| 665 /// | 721 /// |
| 666 /// Note that lazily initialized fields should be read using GetLazyStatic. | 722 /// Note that lazily initialized fields should be read using GetLazyStatic. |
| 667 class GetStatic extends Primitive { | 723 class GetStatic extends Primitive { |
| 668 /// Can be [FieldElement] or [FunctionElement]. | 724 /// Can be [FieldElement] or [FunctionElement]. |
| 669 final Element element; | 725 final Element element; |
| 670 final SourceInformation sourceInformation; | 726 final SourceInformation sourceInformation; |
| 671 | 727 |
| 672 GetStatic(this.element, [this.sourceInformation]); | 728 GetStatic(this.element, [this.sourceInformation]); |
| 673 | 729 |
| 674 accept(Visitor visitor) => visitor.visitGetStatic(this); | 730 accept(Visitor visitor) => visitor.visitGetStatic(this); |
| 675 | 731 |
| 676 bool get isSafeForElimination { | 732 bool get isSafeForElimination { |
| 677 return true; | 733 return true; |
| 678 } | 734 } |
| 679 bool get isSafeForReordering { | 735 bool get isSafeForReordering { |
| 680 return element is FunctionElement || element.isFinal; | 736 return element is FunctionElement || element.isFinal; |
| 681 } | 737 } |
| 682 } | 738 } |
| 683 | 739 |
| 684 /// Sets the value of a static field. | 740 /// Sets the value of a static field. |
| 685 class SetStatic extends Expression implements InteriorNode { | 741 class SetStatic extends Expression implements InteriorNode { |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 T visitInterceptor(Interceptor node); | 1101 T visitInterceptor(Interceptor node); |
| 1046 T visitCreateInstance(CreateInstance node); | 1102 T visitCreateInstance(CreateInstance node); |
| 1047 T visitGetField(GetField node); | 1103 T visitGetField(GetField node); |
| 1048 T visitCreateBox(CreateBox node); | 1104 T visitCreateBox(CreateBox node); |
| 1049 T visitReifyRuntimeType(ReifyRuntimeType node); | 1105 T visitReifyRuntimeType(ReifyRuntimeType node); |
| 1050 T visitReadTypeVariable(ReadTypeVariable node); | 1106 T visitReadTypeVariable(ReadTypeVariable node); |
| 1051 T visitTypeExpression(TypeExpression node); | 1107 T visitTypeExpression(TypeExpression node); |
| 1052 T visitCreateInvocationMirror(CreateInvocationMirror node); | 1108 T visitCreateInvocationMirror(CreateInvocationMirror node); |
| 1053 T visitTypeTest(TypeTest node); | 1109 T visitTypeTest(TypeTest node); |
| 1054 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); | 1110 T visitApplyBuiltinOperator(ApplyBuiltinOperator node); |
| 1111 T visitGetLength(GetLength node); |
| 1112 T visitGetIndex(GetIndex node); |
| 1113 T visitSetIndex(SetIndex node); |
| 1055 | 1114 |
| 1056 // Conditions. | 1115 // Conditions. |
| 1057 T visitIsTrue(IsTrue node); | 1116 T visitIsTrue(IsTrue node); |
| 1058 | 1117 |
| 1059 // Support for literal foreign code. | 1118 // Support for literal foreign code. |
| 1060 T visitForeignCode(ForeignCode node); | 1119 T visitForeignCode(ForeignCode node); |
| 1061 } | 1120 } |
| 1062 | 1121 |
| 1063 /// Recursively visits the entire CPS term, and calls abstract `process*` | 1122 /// Recursively visits the entire CPS term, and calls abstract `process*` |
| 1064 /// (i.e. `processLetPrim`) functions in pre-order. | 1123 /// (i.e. `processLetPrim`) functions in pre-order. |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 if (node.continuation != null) { | 1394 if (node.continuation != null) { |
| 1336 processReference(node.continuation); | 1395 processReference(node.continuation); |
| 1337 } | 1396 } |
| 1338 node.arguments.forEach(processReference); | 1397 node.arguments.forEach(processReference); |
| 1339 } | 1398 } |
| 1340 | 1399 |
| 1341 processUnreachable(Unreachable node) {} | 1400 processUnreachable(Unreachable node) {} |
| 1342 visitUnreachable(Unreachable node) { | 1401 visitUnreachable(Unreachable node) { |
| 1343 processUnreachable(node); | 1402 processUnreachable(node); |
| 1344 } | 1403 } |
| 1404 |
| 1405 processGetLength(GetLength node) {} |
| 1406 visitGetLength(GetLength node) { |
| 1407 processGetLength(node); |
| 1408 processReference(node.object); |
| 1409 } |
| 1410 |
| 1411 processGetIndex(GetIndex node) {} |
| 1412 visitGetIndex(GetIndex node) { |
| 1413 processGetIndex(node); |
| 1414 processReference(node.object); |
| 1415 processReference(node.index); |
| 1416 } |
| 1417 |
| 1418 processSetIndex(SetIndex node) {} |
| 1419 visitSetIndex(SetIndex node) { |
| 1420 processSetIndex(node); |
| 1421 processReference(node.object); |
| 1422 processReference(node.index); |
| 1423 processReference(node.value); |
| 1424 } |
| 1345 } | 1425 } |
| 1346 | 1426 |
| 1347 /// Visit a just-deleted subterm and unlink all [Reference]s in it. | 1427 /// Visit a just-deleted subterm and unlink all [Reference]s in it. |
| 1348 class RemovalVisitor extends RecursiveVisitor { | 1428 class RemovalVisitor extends RecursiveVisitor { |
| 1349 const RemovalVisitor(); | 1429 const RemovalVisitor(); |
| 1350 | 1430 |
| 1351 processReference(Reference reference) { | 1431 processReference(Reference reference) { |
| 1352 reference.unlink(); | 1432 reference.unlink(); |
| 1353 } | 1433 } |
| 1354 | 1434 |
| 1355 static void remove(Node node) { | 1435 static void remove(Node node) { |
| 1356 (const RemovalVisitor()).visit(node); | 1436 (const RemovalVisitor()).visit(node); |
| 1357 } | 1437 } |
| 1358 } | 1438 } |
| OLD | NEW |