OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 | 4 |
5 library tree_ir_nodes; | 5 library tree_ir_nodes; |
6 | 6 |
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 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 | 931 |
932 accept(ExpressionVisitor visitor) { | 932 accept(ExpressionVisitor visitor) { |
933 return visitor.visitAwait(this); | 933 return visitor.visitAwait(this); |
934 } | 934 } |
935 | 935 |
936 accept1(ExpressionVisitor1 visitor, arg) { | 936 accept1(ExpressionVisitor1 visitor, arg) { |
937 return visitor.visitAwait(this, arg); | 937 return visitor.visitAwait(this, arg); |
938 } | 938 } |
939 } | 939 } |
940 | 940 |
| 941 class Yield extends Statement { |
| 942 Statement next; |
| 943 Expression input; |
| 944 final bool hasStar; |
| 945 |
| 946 Yield(this.input, this.hasStar, this.next); |
| 947 |
| 948 accept(StatementVisitor visitor) { |
| 949 return visitor.visitYield(this); |
| 950 } |
| 951 |
| 952 accept1(StatementVisitor1 visitor, arg) { |
| 953 return visitor.visitYield(this, arg); |
| 954 } |
| 955 } |
| 956 |
941 abstract class ExpressionVisitor<E> { | 957 abstract class ExpressionVisitor<E> { |
942 E visitExpression(Expression node) => node.accept(this); | 958 E visitExpression(Expression node) => node.accept(this); |
943 E visitVariableUse(VariableUse node); | 959 E visitVariableUse(VariableUse node); |
944 E visitAssign(Assign node); | 960 E visitAssign(Assign node); |
945 E visitInvokeStatic(InvokeStatic node); | 961 E visitInvokeStatic(InvokeStatic node); |
946 E visitInvokeMethod(InvokeMethod node); | 962 E visitInvokeMethod(InvokeMethod node); |
947 E visitInvokeMethodDirectly(InvokeMethodDirectly node); | 963 E visitInvokeMethodDirectly(InvokeMethodDirectly node); |
948 E visitInvokeConstructor(InvokeConstructor node); | 964 E visitInvokeConstructor(InvokeConstructor node); |
949 E visitConstant(Constant node); | 965 E visitConstant(Constant node); |
950 E visitThis(This node); | 966 E visitThis(This node); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 S visitRethrow(Rethrow node); | 1036 S visitRethrow(Rethrow node); |
1021 S visitBreak(Break node); | 1037 S visitBreak(Break node); |
1022 S visitContinue(Continue node); | 1038 S visitContinue(Continue node); |
1023 S visitIf(If node); | 1039 S visitIf(If node); |
1024 S visitWhileTrue(WhileTrue node); | 1040 S visitWhileTrue(WhileTrue node); |
1025 S visitFor(For node); | 1041 S visitFor(For node); |
1026 S visitExpressionStatement(ExpressionStatement node); | 1042 S visitExpressionStatement(ExpressionStatement node); |
1027 S visitTry(Try node); | 1043 S visitTry(Try node); |
1028 S visitUnreachable(Unreachable node); | 1044 S visitUnreachable(Unreachable node); |
1029 S visitForeignStatement(ForeignStatement node); | 1045 S visitForeignStatement(ForeignStatement node); |
| 1046 S visitYield(Yield node); |
1030 } | 1047 } |
1031 | 1048 |
1032 abstract class StatementVisitor1<S, A> { | 1049 abstract class StatementVisitor1<S, A> { |
1033 S visitStatement(Statement node, A arg) => node.accept1(this, arg); | 1050 S visitStatement(Statement node, A arg) => node.accept1(this, arg); |
1034 S visitLabeledStatement(LabeledStatement node, A arg); | 1051 S visitLabeledStatement(LabeledStatement node, A arg); |
1035 S visitReturn(Return node, A arg); | 1052 S visitReturn(Return node, A arg); |
1036 S visitThrow(Throw node, A arg); | 1053 S visitThrow(Throw node, A arg); |
1037 S visitRethrow(Rethrow node, A arg); | 1054 S visitRethrow(Rethrow node, A arg); |
1038 S visitBreak(Break node, A arg); | 1055 S visitBreak(Break node, A arg); |
1039 S visitContinue(Continue node, A arg); | 1056 S visitContinue(Continue node, A arg); |
1040 S visitIf(If node, A arg); | 1057 S visitIf(If node, A arg); |
1041 S visitWhileTrue(WhileTrue node, A arg); | 1058 S visitWhileTrue(WhileTrue node, A arg); |
1042 S visitFor(For node, A arg); | 1059 S visitFor(For node, A arg); |
1043 S visitExpressionStatement(ExpressionStatement node, A arg); | 1060 S visitExpressionStatement(ExpressionStatement node, A arg); |
1044 S visitTry(Try node, A arg); | 1061 S visitTry(Try node, A arg); |
1045 S visitUnreachable(Unreachable node, A arg); | 1062 S visitUnreachable(Unreachable node, A arg); |
1046 S visitForeignStatement(ForeignStatement node, A arg); | 1063 S visitForeignStatement(ForeignStatement node, A arg); |
| 1064 S visitYield(Yield node, A arg); |
1047 } | 1065 } |
1048 | 1066 |
1049 abstract class RecursiveVisitor implements StatementVisitor, ExpressionVisitor { | 1067 abstract class RecursiveVisitor implements StatementVisitor, ExpressionVisitor { |
1050 visitExpression(Expression e) => e.accept(this); | 1068 visitExpression(Expression e) => e.accept(this); |
1051 visitStatement(Statement s) => s.accept(this); | 1069 visitStatement(Statement s) => s.accept(this); |
1052 | 1070 |
1053 visitInnerFunction(FunctionDefinition node); | 1071 visitInnerFunction(FunctionDefinition node); |
1054 | 1072 |
1055 visitVariable(Variable variable) {} | 1073 visitVariable(Variable variable) {} |
1056 | 1074 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 | 1264 |
1247 visitSetIndex(SetIndex node) { | 1265 visitSetIndex(SetIndex node) { |
1248 visitExpression(node.object); | 1266 visitExpression(node.object); |
1249 visitExpression(node.index); | 1267 visitExpression(node.index); |
1250 visitExpression(node.value); | 1268 visitExpression(node.value); |
1251 } | 1269 } |
1252 | 1270 |
1253 visitAwait(Await node) { | 1271 visitAwait(Await node) { |
1254 visitExpression(node.input); | 1272 visitExpression(node.input); |
1255 } | 1273 } |
| 1274 |
| 1275 visitYield(Yield node) { |
| 1276 visitExpression(node.input); |
| 1277 visitStatement(node.next); |
| 1278 } |
1256 } | 1279 } |
1257 | 1280 |
1258 abstract class Transformer implements ExpressionVisitor<Expression>, | 1281 abstract class Transformer implements ExpressionVisitor<Expression>, |
1259 StatementVisitor<Statement> { | 1282 StatementVisitor<Statement> { |
1260 Expression visitExpression(Expression e) => e.accept(this); | 1283 Expression visitExpression(Expression e) => e.accept(this); |
1261 Statement visitStatement(Statement s) => s.accept(this); | 1284 Statement visitStatement(Statement s) => s.accept(this); |
1262 } | 1285 } |
1263 | 1286 |
1264 class RecursiveTransformer extends Transformer { | 1287 class RecursiveTransformer extends Transformer { |
1265 void visitInnerFunction(FunctionDefinition node) { | 1288 void visitInnerFunction(FunctionDefinition node) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 node.object = visitExpression(node.object); | 1523 node.object = visitExpression(node.object); |
1501 node.index = visitExpression(node.index); | 1524 node.index = visitExpression(node.index); |
1502 node.value = visitExpression(node.value); | 1525 node.value = visitExpression(node.value); |
1503 return node; | 1526 return node; |
1504 } | 1527 } |
1505 | 1528 |
1506 visitAwait(Await node) { | 1529 visitAwait(Await node) { |
1507 node.input = visitExpression(node.input); | 1530 node.input = visitExpression(node.input); |
1508 return node; | 1531 return node; |
1509 } | 1532 } |
| 1533 |
| 1534 visitYield(Yield node) { |
| 1535 node.input = visitExpression(node.input); |
| 1536 return node; |
| 1537 } |
1510 } | 1538 } |
1511 | 1539 |
1512 class FallthroughTarget { | 1540 class FallthroughTarget { |
1513 final Statement target; | 1541 final Statement target; |
1514 int useCount = 0; | 1542 int useCount = 0; |
1515 | 1543 |
1516 FallthroughTarget(this.target); | 1544 FallthroughTarget(this.target); |
1517 } | 1545 } |
1518 | 1546 |
1519 /// A stack machine for tracking fallthrough while traversing the Tree IR. | 1547 /// A stack machine for tracking fallthrough while traversing the Tree IR. |
(...skipping 17 matching lines...) Expand all Loading... |
1537 | 1565 |
1538 /// Number of uses of the current fallthrough target. | 1566 /// Number of uses of the current fallthrough target. |
1539 int get useCount => _stack.last.useCount; | 1567 int get useCount => _stack.last.useCount; |
1540 | 1568 |
1541 /// Indicate that a statement will fall through to the current fallthrough | 1569 /// Indicate that a statement will fall through to the current fallthrough |
1542 /// target. | 1570 /// target. |
1543 void use() { | 1571 void use() { |
1544 ++_stack.last.useCount; | 1572 ++_stack.last.useCount; |
1545 } | 1573 } |
1546 } | 1574 } |
OLD | NEW |