| 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 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 : this.arguments = _referenceList(arguments), | 878 : this.arguments = _referenceList(arguments), |
| 879 this.continuation = new Reference<Continuation>(continuation); | 879 this.continuation = new Reference<Continuation>(continuation); |
| 880 | 880 |
| 881 accept(Visitor visitor) => visitor.visitForeignCode(this); | 881 accept(Visitor visitor) => visitor.visitForeignCode(this); |
| 882 } | 882 } |
| 883 | 883 |
| 884 class Constant extends Primitive { | 884 class Constant extends Primitive { |
| 885 final values.ConstantValue value; | 885 final values.ConstantValue value; |
| 886 final SourceInformation sourceInformation; | 886 final SourceInformation sourceInformation; |
| 887 | 887 |
| 888 Constant(this.value, {this.sourceInformation}); | 888 Constant(this.value, {this.sourceInformation}) { |
| 889 assert(value != null); |
| 890 } |
| 889 | 891 |
| 890 accept(Visitor visitor) => visitor.visitConstant(this); | 892 accept(Visitor visitor) => visitor.visitConstant(this); |
| 891 | 893 |
| 892 bool get isSafeForElimination => true; | 894 bool get isSafeForElimination => true; |
| 893 bool get isSafeForReordering => true; | 895 bool get isSafeForReordering => true; |
| 894 } | 896 } |
| 895 | 897 |
| 896 class LiteralList extends Primitive { | 898 class LiteralList extends Primitive { |
| 897 /// The List type being created; this is not the type argument. | 899 /// The List type being created; this is not the type argument. |
| 898 final InterfaceType type; | 900 final InterfaceType type; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1160 | 1162 |
| 1161 // Conditions. | 1163 // Conditions. |
| 1162 T visitIsTrue(IsTrue node); | 1164 T visitIsTrue(IsTrue node); |
| 1163 | 1165 |
| 1164 // Support for literal foreign code. | 1166 // Support for literal foreign code. |
| 1165 T visitForeignCode(ForeignCode node); | 1167 T visitForeignCode(ForeignCode node); |
| 1166 } | 1168 } |
| 1167 | 1169 |
| 1168 /// Visits all non-recursive children of a CPS term, i.e. anything | 1170 /// Visits all non-recursive children of a CPS term, i.e. anything |
| 1169 /// not of type [Expression] or [Continuation]. | 1171 /// not of type [Expression] or [Continuation]. |
| 1170 /// | 1172 /// |
| 1171 /// Note that the non-recursive nodes can contain other nodes inside of them, | 1173 /// Note that the non-recursive nodes can contain other nodes inside of them, |
| 1172 /// e.g. [Branch] contains an [IsTrue] which contains a [Reference]. | 1174 /// e.g. [Branch] contains an [IsTrue] which contains a [Reference]. |
| 1173 /// | 1175 /// |
| 1174 /// The `process*` methods are called in pre-order for every node visited. | 1176 /// The `process*` methods are called in pre-order for every node visited. |
| 1175 /// These can be overridden without disrupting the visitor traversal. | 1177 /// These can be overridden without disrupting the visitor traversal. |
| 1176 class LeafVisitor implements Visitor { | 1178 class LeafVisitor implements Visitor { |
| 1177 const LeafVisitor(); | 1179 const LeafVisitor(); |
| 1178 | 1180 |
| 1179 visit(Node node) => node.accept(this); | 1181 visit(Node node) => node.accept(this); |
| 1180 | 1182 |
| 1181 processReference(Reference ref) {} | 1183 processReference(Reference ref) {} |
| 1182 | 1184 |
| 1183 processFunctionDefinition(FunctionDefinition node) {} | 1185 processFunctionDefinition(FunctionDefinition node) {} |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 processReference(node.object); | 1466 processReference(node.object); |
| 1465 processReference(node.index); | 1467 processReference(node.index); |
| 1466 processReference(node.value); | 1468 processReference(node.value); |
| 1467 } | 1469 } |
| 1468 } | 1470 } |
| 1469 | 1471 |
| 1470 typedef void StackAction(); | 1472 typedef void StackAction(); |
| 1471 | 1473 |
| 1472 /// Calls `process*` for all nodes in a tree. | 1474 /// Calls `process*` for all nodes in a tree. |
| 1473 /// For simple usage, only override the `process*` methods. | 1475 /// For simple usage, only override the `process*` methods. |
| 1474 /// | 1476 /// |
| 1475 /// To avoid deep recursion, this class uses an "action stack" containing | 1477 /// To avoid deep recursion, this class uses an "action stack" containing |
| 1476 /// callbacks to be invoked after the processing of some term has finished. | 1478 /// callbacks to be invoked after the processing of some term has finished. |
| 1477 /// | 1479 /// |
| 1478 /// To avoid excessive overhead from the action stack, basic blocks of | 1480 /// To avoid excessive overhead from the action stack, basic blocks of |
| 1479 /// interior nodes are iterated in a loop without using the action stack. | 1481 /// interior nodes are iterated in a loop without using the action stack. |
| 1480 /// | 1482 /// |
| 1481 /// The iteration order can be controlled by overriding the `traverse*` | 1483 /// The iteration order can be controlled by overriding the `traverse*` |
| 1482 /// methods for [LetCont], [LetPrim], [LetMutable], [LetHandler] and | 1484 /// methods for [LetCont], [LetPrim], [LetMutable], [LetHandler] and |
| 1483 /// [Continuation]. | 1485 /// [Continuation]. |
| 1484 /// | 1486 /// |
| 1485 /// The `traverse*` methods return the expression to visit next, and may | 1487 /// The `traverse*` methods return the expression to visit next, and may |
| 1486 /// push other subterms onto the stack using [push] or [pushAction] to visit | 1488 /// push other subterms onto the stack using [push] or [pushAction] to visit |
| 1487 /// them later. Actions pushed onto the stack will be executed after the body | 1489 /// them later. Actions pushed onto the stack will be executed after the body |
| 1488 /// has been processed (and the stack actions it pushed have been executed). | 1490 /// has been processed (and the stack actions it pushed have been executed). |
| 1489 /// | 1491 /// |
| 1490 /// By default, the `traverse` methods visit all non-recursive subterms, | 1492 /// By default, the `traverse` methods visit all non-recursive subterms, |
| 1491 /// push all bound continuations on the stack, and return the body of the term. | 1493 /// push all bound continuations on the stack, and return the body of the term. |
| 1492 /// | 1494 /// |
| 1493 /// Subclasses should not override the `visit` methods for the nodes that have | 1495 /// Subclasses should not override the `visit` methods for the nodes that have |
| 1494 /// a `traverse` method. | 1496 /// a `traverse` method. |
| 1495 class RecursiveVisitor extends LeafVisitor { | 1497 class RecursiveVisitor extends LeafVisitor { |
| 1496 List<StackAction> _stack = <StackAction>[]; | 1498 List<StackAction> _stack = <StackAction>[]; |
| 1497 | 1499 |
| 1498 void pushAction(StackAction callback) { | 1500 void pushAction(StackAction callback) { |
| 1499 _stack.add(callback); | 1501 _stack.add(callback); |
| 1500 } | 1502 } |
| 1501 | 1503 |
| 1502 void push(Continuation cont) { | 1504 void push(Continuation cont) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1589 /// Visit a just-deleted subterm and unlink all [Reference]s in it. | 1591 /// Visit a just-deleted subterm and unlink all [Reference]s in it. |
| 1590 class RemovalVisitor extends RecursiveVisitor { | 1592 class RemovalVisitor extends RecursiveVisitor { |
| 1591 processReference(Reference reference) { | 1593 processReference(Reference reference) { |
| 1592 reference.unlink(); | 1594 reference.unlink(); |
| 1593 } | 1595 } |
| 1594 | 1596 |
| 1595 static void remove(Node node) { | 1597 static void remove(Node node) { |
| 1596 (new RemovalVisitor()).visit(node); | 1598 (new RemovalVisitor()).visit(node); |
| 1597 } | 1599 } |
| 1598 } | 1600 } |
| OLD | NEW |