| 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/expressions.dart'; | 7 import '../constants/expressions.dart'; |
| 8 import '../constants/values.dart' as values; | 8 import '../constants/values.dart' as values; |
| 9 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 9 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
| 10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 Element element; | 710 Element element; |
| 711 Expression value; | 711 Expression value; |
| 712 SourceInformation sourceInformation; | 712 SourceInformation sourceInformation; |
| 713 | 713 |
| 714 SetStatic(this.element, this.value, this.sourceInformation); | 714 SetStatic(this.element, this.value, this.sourceInformation); |
| 715 | 715 |
| 716 accept(ExpressionVisitor visitor) => visitor.visitSetStatic(this); | 716 accept(ExpressionVisitor visitor) => visitor.visitSetStatic(this); |
| 717 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitSetStatic(this, arg); | 717 accept1(ExpressionVisitor1 visitor, arg) => visitor.visitSetStatic(this, arg); |
| 718 } | 718 } |
| 719 | 719 |
| 720 class GetLength extends Expression { |
| 721 Expression object; |
| 722 |
| 723 GetLength(this.object); |
| 724 |
| 725 accept(ExpressionVisitor v) => v.visitGetLength(this); |
| 726 accept1(ExpressionVisitor1 v, arg) => v.visitGetLength(this, arg); |
| 727 } |
| 728 |
| 729 class GetIndex extends Expression { |
| 730 Expression object; |
| 731 Expression index; |
| 732 |
| 733 GetIndex(this.object, this.index); |
| 734 |
| 735 accept(ExpressionVisitor v) => v.visitGetIndex(this); |
| 736 accept1(ExpressionVisitor1 v, arg) => v.visitGetIndex(this, arg); |
| 737 } |
| 738 |
| 739 class SetIndex extends Expression { |
| 740 Expression object; |
| 741 Expression index; |
| 742 Expression value; |
| 743 |
| 744 SetIndex(this.object, this.index, this.value); |
| 745 |
| 746 accept(ExpressionVisitor v) => v.visitSetIndex(this); |
| 747 accept1(ExpressionVisitor1 v, arg) => v.visitSetIndex(this, arg); |
| 748 } |
| 749 |
| 720 class ReifyRuntimeType extends Expression { | 750 class ReifyRuntimeType extends Expression { |
| 721 Expression value; | 751 Expression value; |
| 722 | 752 |
| 723 ReifyRuntimeType(this.value); | 753 ReifyRuntimeType(this.value); |
| 724 | 754 |
| 725 accept(ExpressionVisitor visitor) { | 755 accept(ExpressionVisitor visitor) { |
| 726 return visitor.visitReifyRuntimeType(this); | 756 return visitor.visitReifyRuntimeType(this); |
| 727 } | 757 } |
| 728 | 758 |
| 729 accept1(ExpressionVisitor1 visitor, arg) { | 759 accept1(ExpressionVisitor1 visitor, arg) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 E visitSetStatic(SetStatic node); | 896 E visitSetStatic(SetStatic node); |
| 867 E visitCreateBox(CreateBox node); | 897 E visitCreateBox(CreateBox node); |
| 868 E visitCreateInstance(CreateInstance node); | 898 E visitCreateInstance(CreateInstance node); |
| 869 E visitReifyRuntimeType(ReifyRuntimeType node); | 899 E visitReifyRuntimeType(ReifyRuntimeType node); |
| 870 E visitReadTypeVariable(ReadTypeVariable node); | 900 E visitReadTypeVariable(ReadTypeVariable node); |
| 871 E visitTypeExpression(TypeExpression node); | 901 E visitTypeExpression(TypeExpression node); |
| 872 E visitCreateInvocationMirror(CreateInvocationMirror node); | 902 E visitCreateInvocationMirror(CreateInvocationMirror node); |
| 873 E visitInterceptor(Interceptor node); | 903 E visitInterceptor(Interceptor node); |
| 874 E visitApplyBuiltinOperator(ApplyBuiltinOperator node); | 904 E visitApplyBuiltinOperator(ApplyBuiltinOperator node); |
| 875 E visitForeignExpression(ForeignExpression node); | 905 E visitForeignExpression(ForeignExpression node); |
| 906 E visitGetLength(GetLength node); |
| 907 E visitGetIndex(GetIndex node); |
| 908 E visitSetIndex(SetIndex node); |
| 876 } | 909 } |
| 877 | 910 |
| 878 abstract class ExpressionVisitor1<E, A> { | 911 abstract class ExpressionVisitor1<E, A> { |
| 879 E visitExpression(Expression node, A arg) => node.accept1(this, arg); | 912 E visitExpression(Expression node, A arg) => node.accept1(this, arg); |
| 880 E visitVariableUse(VariableUse node, A arg); | 913 E visitVariableUse(VariableUse node, A arg); |
| 881 E visitAssign(Assign node, A arg); | 914 E visitAssign(Assign node, A arg); |
| 882 E visitInvokeStatic(InvokeStatic node, A arg); | 915 E visitInvokeStatic(InvokeStatic node, A arg); |
| 883 E visitInvokeMethod(InvokeMethod node, A arg); | 916 E visitInvokeMethod(InvokeMethod node, A arg); |
| 884 E visitInvokeMethodDirectly(InvokeMethodDirectly node, A arg); | 917 E visitInvokeMethodDirectly(InvokeMethodDirectly node, A arg); |
| 885 E visitInvokeConstructor(InvokeConstructor node, A arg); | 918 E visitInvokeConstructor(InvokeConstructor node, A arg); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 898 E visitSetStatic(SetStatic node, A arg); | 931 E visitSetStatic(SetStatic node, A arg); |
| 899 E visitCreateBox(CreateBox node, A arg); | 932 E visitCreateBox(CreateBox node, A arg); |
| 900 E visitCreateInstance(CreateInstance node, A arg); | 933 E visitCreateInstance(CreateInstance node, A arg); |
| 901 E visitReifyRuntimeType(ReifyRuntimeType node, A arg); | 934 E visitReifyRuntimeType(ReifyRuntimeType node, A arg); |
| 902 E visitReadTypeVariable(ReadTypeVariable node, A arg); | 935 E visitReadTypeVariable(ReadTypeVariable node, A arg); |
| 903 E visitTypeExpression(TypeExpression node, A arg); | 936 E visitTypeExpression(TypeExpression node, A arg); |
| 904 E visitCreateInvocationMirror(CreateInvocationMirror node, A arg); | 937 E visitCreateInvocationMirror(CreateInvocationMirror node, A arg); |
| 905 E visitInterceptor(Interceptor node, A arg); | 938 E visitInterceptor(Interceptor node, A arg); |
| 906 E visitApplyBuiltinOperator(ApplyBuiltinOperator node, A arg); | 939 E visitApplyBuiltinOperator(ApplyBuiltinOperator node, A arg); |
| 907 E visitForeignExpression(ForeignExpression node, A arg); | 940 E visitForeignExpression(ForeignExpression node, A arg); |
| 941 E visitGetLength(GetLength node, A arg); |
| 942 E visitGetIndex(GetIndex node, A arg); |
| 943 E visitSetIndex(SetIndex node, A arg); |
| 908 } | 944 } |
| 909 | 945 |
| 910 abstract class StatementVisitor<S> { | 946 abstract class StatementVisitor<S> { |
| 911 S visitStatement(Statement node) => node.accept(this); | 947 S visitStatement(Statement node) => node.accept(this); |
| 912 S visitLabeledStatement(LabeledStatement node); | 948 S visitLabeledStatement(LabeledStatement node); |
| 913 S visitReturn(Return node); | 949 S visitReturn(Return node); |
| 914 S visitThrow(Throw node); | 950 S visitThrow(Throw node); |
| 915 S visitRethrow(Rethrow node); | 951 S visitRethrow(Rethrow node); |
| 916 S visitBreak(Break node); | 952 S visitBreak(Break node); |
| 917 S visitContinue(Continue node); | 953 S visitContinue(Continue node); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 visitInterceptor(Interceptor node) { | 1146 visitInterceptor(Interceptor node) { |
| 1111 visitExpression(node.input); | 1147 visitExpression(node.input); |
| 1112 } | 1148 } |
| 1113 | 1149 |
| 1114 visitForeignCode(ForeignCode node) { | 1150 visitForeignCode(ForeignCode node) { |
| 1115 node.arguments.forEach(visitExpression); | 1151 node.arguments.forEach(visitExpression); |
| 1116 } | 1152 } |
| 1117 | 1153 |
| 1118 visitForeignExpression(ForeignExpression node) => visitForeignCode(node); | 1154 visitForeignExpression(ForeignExpression node) => visitForeignCode(node); |
| 1119 visitForeignStatement(ForeignStatement node) => visitForeignCode(node); | 1155 visitForeignStatement(ForeignStatement node) => visitForeignCode(node); |
| 1156 |
| 1157 visitGetLength(GetLength node) { |
| 1158 visitExpression(node.object); |
| 1159 } |
| 1160 |
| 1161 visitGetIndex(GetIndex node) { |
| 1162 visitExpression(node.object); |
| 1163 visitExpression(node.index); |
| 1164 } |
| 1165 |
| 1166 visitSetIndex(SetIndex node) { |
| 1167 visitExpression(node.object); |
| 1168 visitExpression(node.index); |
| 1169 visitExpression(node.value); |
| 1170 } |
| 1120 } | 1171 } |
| 1121 | 1172 |
| 1122 abstract class Transformer implements ExpressionVisitor<Expression>, | 1173 abstract class Transformer implements ExpressionVisitor<Expression>, |
| 1123 StatementVisitor<Statement> { | 1174 StatementVisitor<Statement> { |
| 1124 Expression visitExpression(Expression e) => e.accept(this); | 1175 Expression visitExpression(Expression e) => e.accept(this); |
| 1125 Statement visitStatement(Statement s) => s.accept(this); | 1176 Statement visitStatement(Statement s) => s.accept(this); |
| 1126 } | 1177 } |
| 1127 | 1178 |
| 1128 class RecursiveTransformer extends Transformer { | 1179 class RecursiveTransformer extends Transformer { |
| 1129 void visitInnerFunction(FunctionDefinition node) { | 1180 void visitInnerFunction(FunctionDefinition node) { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1325 | 1376 |
| 1326 visitApplyBuiltinOperator(ApplyBuiltinOperator node) { | 1377 visitApplyBuiltinOperator(ApplyBuiltinOperator node) { |
| 1327 _replaceExpressions(node.arguments); | 1378 _replaceExpressions(node.arguments); |
| 1328 return node; | 1379 return node; |
| 1329 } | 1380 } |
| 1330 | 1381 |
| 1331 visitInterceptor(Interceptor node) { | 1382 visitInterceptor(Interceptor node) { |
| 1332 node.input = visitExpression(node.input); | 1383 node.input = visitExpression(node.input); |
| 1333 return node; | 1384 return node; |
| 1334 } | 1385 } |
| 1386 |
| 1387 visitGetLength(GetLength node) { |
| 1388 node.object = visitExpression(node.object); |
| 1389 return node; |
| 1390 } |
| 1391 |
| 1392 visitGetIndex(GetIndex node) { |
| 1393 node.object = visitExpression(node.object); |
| 1394 node.index = visitExpression(node.index); |
| 1395 return node; |
| 1396 } |
| 1397 |
| 1398 visitSetIndex(SetIndex node) { |
| 1399 node.object = visitExpression(node.object); |
| 1400 node.index = visitExpression(node.index); |
| 1401 node.value = visitExpression(node.value); |
| 1402 return node; |
| 1403 } |
| 1335 } | 1404 } |
| 1336 | 1405 |
| 1337 class FallthroughTarget { | 1406 class FallthroughTarget { |
| 1338 final Statement target; | 1407 final Statement target; |
| 1339 int useCount = 0; | 1408 int useCount = 0; |
| 1340 | 1409 |
| 1341 FallthroughTarget(this.target); | 1410 FallthroughTarget(this.target); |
| 1342 } | 1411 } |
| 1343 | 1412 |
| 1344 /// A stack machine for tracking fallthrough while traversing the Tree IR. | 1413 /// A stack machine for tracking fallthrough while traversing the Tree IR. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1362 | 1431 |
| 1363 /// Number of uses of the current fallthrough target. | 1432 /// Number of uses of the current fallthrough target. |
| 1364 int get useCount => _stack.last.useCount; | 1433 int get useCount => _stack.last.useCount; |
| 1365 | 1434 |
| 1366 /// Indicate that a statement will fall through to the current fallthrough | 1435 /// Indicate that a statement will fall through to the current fallthrough |
| 1367 /// target. | 1436 /// target. |
| 1368 void use() { | 1437 void use() { |
| 1369 ++_stack.last.useCount; | 1438 ++_stack.last.useCount; |
| 1370 } | 1439 } |
| 1371 } | 1440 } |
| OLD | NEW |