| 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'; |
| 11 import '../io/source_information.dart' show SourceInformation; | 11 import '../io/source_information.dart' show SourceInformation; |
| 12 import '../universe/universe.dart' show Selector; | 12 import '../universe/universe.dart' show Selector; |
| 13 | 13 |
| 14 import '../cps_ir/builtin_operator.dart'; | 14 import '../cps_ir/builtin_operator.dart'; |
| 15 export '../cps_ir/builtin_operator.dart'; | 15 export '../cps_ir/builtin_operator.dart'; |
| 16 | 16 |
| 17 // These imports are only used for the JavaScript specific nodes. If we want to |
| 18 // support more than one native backend, we should probably create better |
| 19 // abstractions for native code and its type and effect system. |
| 20 import '../js/js.dart' as js show Template; |
| 21 import '../native/native.dart' as native show NativeBehavior; |
| 22 import '../types/types.dart' as types show TypeMask; |
| 23 |
| 17 // The Tree language is the target of translation out of the CPS-based IR. | 24 // The Tree language is the target of translation out of the CPS-based IR. |
| 18 // | 25 // |
| 19 // The translation from CPS to Dart consists of several stages. Among the | 26 // The translation from CPS to Dart consists of several stages. Among the |
| 20 // stages are translation to direct style, translation out of SSA, eliminating | 27 // stages are translation to direct style, translation out of SSA, eliminating |
| 21 // unnecessary names, recognizing high-level control constructs. Combining | 28 // unnecessary names, recognizing high-level control constructs. Combining |
| 22 // these separate concerns is complicated and the constraints of the CPS-based | 29 // these separate concerns is complicated and the constraints of the CPS-based |
| 23 // language do not permit a multi-stage translation. | 30 // language do not permit a multi-stage translation. |
| 24 // | 31 // |
| 25 // For that reason, CPS is translated to the direct-style language Tree. | 32 // For that reason, CPS is translated to the direct-style language Tree. |
| 26 // Translation out of SSA, unnaming, and control-flow, as well as 'instruction | 33 // Translation out of SSA, unnaming, and control-flow, as well as 'instruction |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 | 776 |
| 770 accept(ExpressionVisitor visitor) { | 777 accept(ExpressionVisitor visitor) { |
| 771 return visitor.visitCreateInvocationMirror(this); | 778 return visitor.visitCreateInvocationMirror(this); |
| 772 } | 779 } |
| 773 | 780 |
| 774 accept1(ExpressionVisitor1 visitor, arg) { | 781 accept1(ExpressionVisitor1 visitor, arg) { |
| 775 return visitor.visitCreateInvocationMirror(this, arg); | 782 return visitor.visitCreateInvocationMirror(this, arg); |
| 776 } | 783 } |
| 777 } | 784 } |
| 778 | 785 |
| 786 class ForeignCode extends Node { |
| 787 final js.Template codeTemplate; |
| 788 final types.TypeMask type; |
| 789 final List<Expression> arguments; |
| 790 final native.NativeBehavior nativeBehavior; |
| 791 final Element dependency; |
| 792 |
| 793 ForeignCode(this.codeTemplate, this.type, this.arguments, this.nativeBehavior, |
| 794 this.dependency); |
| 795 } |
| 796 |
| 797 class ForeignExpression extends ForeignCode implements Expression { |
| 798 ForeignExpression(js.Template codeTemplate, types.TypeMask type, |
| 799 List<Expression> arguments, native.NativeBehavior nativeBehavior, |
| 800 Element dependency) |
| 801 : super(codeTemplate, type, arguments, nativeBehavior, |
| 802 dependency); |
| 803 |
| 804 accept(ExpressionVisitor visitor) { |
| 805 return visitor.visitForeignExpression(this); |
| 806 } |
| 807 |
| 808 accept1(ExpressionVisitor1 visitor, arg) { |
| 809 return visitor.visitForeignExpression(this, arg); |
| 810 } |
| 811 } |
| 812 |
| 813 class ForeignStatement extends ForeignCode implements Statement { |
| 814 ForeignStatement(js.Template codeTemplate, types.TypeMask type, |
| 815 List<Expression> arguments, native.NativeBehavior nativeBehavior, |
| 816 Element dependency) |
| 817 : super(codeTemplate, type, arguments, nativeBehavior, |
| 818 dependency); |
| 819 |
| 820 accept(StatementVisitor visitor) { |
| 821 return visitor.visitForeignStatement(this); |
| 822 } |
| 823 |
| 824 accept1(StatementVisitor1 visitor, arg) { |
| 825 return visitor.visitForeignStatement(this, arg); |
| 826 } |
| 827 |
| 828 @override |
| 829 Statement get next => null; |
| 830 |
| 831 @override |
| 832 void set next(Statement s) => throw 'UNREACHABLE'; |
| 833 } |
| 834 |
| 779 /// Denotes the internal representation of [dartType], where all type variables | 835 /// Denotes the internal representation of [dartType], where all type variables |
| 780 /// are replaced by the values in [arguments]. | 836 /// are replaced by the values in [arguments]. |
| 781 /// (See documentation on the TypeExpression CPS node for more details.) | 837 /// (See documentation on the TypeExpression CPS node for more details.) |
| 782 class TypeExpression extends Expression { | 838 class TypeExpression extends Expression { |
| 783 final DartType dartType; | 839 final DartType dartType; |
| 784 final List<Expression> arguments; | 840 final List<Expression> arguments; |
| 785 | 841 |
| 786 TypeExpression(this.dartType, this.arguments); | 842 TypeExpression(this.dartType, this.arguments); |
| 787 | 843 |
| 788 accept(ExpressionVisitor visitor) { | 844 accept(ExpressionVisitor visitor) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 816 E visitSetField(SetField node); | 872 E visitSetField(SetField node); |
| 817 E visitGetStatic(GetStatic node); | 873 E visitGetStatic(GetStatic node); |
| 818 E visitSetStatic(SetStatic node); | 874 E visitSetStatic(SetStatic node); |
| 819 E visitCreateBox(CreateBox node); | 875 E visitCreateBox(CreateBox node); |
| 820 E visitCreateInstance(CreateInstance node); | 876 E visitCreateInstance(CreateInstance node); |
| 821 E visitReifyRuntimeType(ReifyRuntimeType node); | 877 E visitReifyRuntimeType(ReifyRuntimeType node); |
| 822 E visitReadTypeVariable(ReadTypeVariable node); | 878 E visitReadTypeVariable(ReadTypeVariable node); |
| 823 E visitTypeExpression(TypeExpression node); | 879 E visitTypeExpression(TypeExpression node); |
| 824 E visitCreateInvocationMirror(CreateInvocationMirror node); | 880 E visitCreateInvocationMirror(CreateInvocationMirror node); |
| 825 E visitApplyBuiltinOperator(ApplyBuiltinOperator node); | 881 E visitApplyBuiltinOperator(ApplyBuiltinOperator node); |
| 882 E visitForeignExpression(ForeignExpression node); |
| 826 } | 883 } |
| 827 | 884 |
| 828 abstract class ExpressionVisitor1<E, A> { | 885 abstract class ExpressionVisitor1<E, A> { |
| 829 E visitExpression(Expression node, A arg) => node.accept1(this, arg); | 886 E visitExpression(Expression node, A arg) => node.accept1(this, arg); |
| 830 E visitVariableUse(VariableUse node, A arg); | 887 E visitVariableUse(VariableUse node, A arg); |
| 831 E visitAssign(Assign node, A arg); | 888 E visitAssign(Assign node, A arg); |
| 832 E visitInvokeStatic(InvokeStatic node, A arg); | 889 E visitInvokeStatic(InvokeStatic node, A arg); |
| 833 E visitInvokeMethod(InvokeMethod node, A arg); | 890 E visitInvokeMethod(InvokeMethod node, A arg); |
| 834 E visitInvokeMethodDirectly(InvokeMethodDirectly node, A arg); | 891 E visitInvokeMethodDirectly(InvokeMethodDirectly node, A arg); |
| 835 E visitInvokeConstructor(InvokeConstructor node, A arg); | 892 E visitInvokeConstructor(InvokeConstructor node, A arg); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 847 E visitSetField(SetField node, A arg); | 904 E visitSetField(SetField node, A arg); |
| 848 E visitGetStatic(GetStatic node, A arg); | 905 E visitGetStatic(GetStatic node, A arg); |
| 849 E visitSetStatic(SetStatic node, A arg); | 906 E visitSetStatic(SetStatic node, A arg); |
| 850 E visitCreateBox(CreateBox node, A arg); | 907 E visitCreateBox(CreateBox node, A arg); |
| 851 E visitCreateInstance(CreateInstance node, A arg); | 908 E visitCreateInstance(CreateInstance node, A arg); |
| 852 E visitReifyRuntimeType(ReifyRuntimeType node, A arg); | 909 E visitReifyRuntimeType(ReifyRuntimeType node, A arg); |
| 853 E visitReadTypeVariable(ReadTypeVariable node, A arg); | 910 E visitReadTypeVariable(ReadTypeVariable node, A arg); |
| 854 E visitTypeExpression(TypeExpression node, A arg); | 911 E visitTypeExpression(TypeExpression node, A arg); |
| 855 E visitCreateInvocationMirror(CreateInvocationMirror node, A arg); | 912 E visitCreateInvocationMirror(CreateInvocationMirror node, A arg); |
| 856 E visitApplyBuiltinOperator(ApplyBuiltinOperator node, A arg); | 913 E visitApplyBuiltinOperator(ApplyBuiltinOperator node, A arg); |
| 914 E visitForeignExpression(ForeignExpression node, A arg); |
| 857 } | 915 } |
| 858 | 916 |
| 859 abstract class StatementVisitor<S> { | 917 abstract class StatementVisitor<S> { |
| 860 S visitStatement(Statement node) => node.accept(this); | 918 S visitStatement(Statement node) => node.accept(this); |
| 861 S visitLabeledStatement(LabeledStatement node); | 919 S visitLabeledStatement(LabeledStatement node); |
| 862 S visitReturn(Return node); | 920 S visitReturn(Return node); |
| 863 S visitThrow(Throw node); | 921 S visitThrow(Throw node); |
| 864 S visitRethrow(Rethrow node); | 922 S visitRethrow(Rethrow node); |
| 865 S visitBreak(Break node); | 923 S visitBreak(Break node); |
| 866 S visitContinue(Continue node); | 924 S visitContinue(Continue node); |
| 867 S visitIf(If node); | 925 S visitIf(If node); |
| 868 S visitWhileTrue(WhileTrue node); | 926 S visitWhileTrue(WhileTrue node); |
| 869 S visitWhileCondition(WhileCondition node); | 927 S visitWhileCondition(WhileCondition node); |
| 870 S visitExpressionStatement(ExpressionStatement node); | 928 S visitExpressionStatement(ExpressionStatement node); |
| 871 S visitTry(Try node); | 929 S visitTry(Try node); |
| 872 S visitUnreachable(Unreachable node); | 930 S visitUnreachable(Unreachable node); |
| 931 S visitForeignStatement(ForeignStatement node); |
| 873 } | 932 } |
| 874 | 933 |
| 875 abstract class StatementVisitor1<S, A> { | 934 abstract class StatementVisitor1<S, A> { |
| 876 S visitStatement(Statement node, A arg) => node.accept1(this, arg); | 935 S visitStatement(Statement node, A arg) => node.accept1(this, arg); |
| 877 S visitLabeledStatement(LabeledStatement node, A arg); | 936 S visitLabeledStatement(LabeledStatement node, A arg); |
| 878 S visitReturn(Return node, A arg); | 937 S visitReturn(Return node, A arg); |
| 879 S visitThrow(Throw node, A arg); | 938 S visitThrow(Throw node, A arg); |
| 880 S visitRethrow(Rethrow node, A arg); | 939 S visitRethrow(Rethrow node, A arg); |
| 881 S visitBreak(Break node, A arg); | 940 S visitBreak(Break node, A arg); |
| 882 S visitContinue(Continue node, A arg); | 941 S visitContinue(Continue node, A arg); |
| 883 S visitIf(If node, A arg); | 942 S visitIf(If node, A arg); |
| 884 S visitWhileTrue(WhileTrue node, A arg); | 943 S visitWhileTrue(WhileTrue node, A arg); |
| 885 S visitWhileCondition(WhileCondition node, A arg); | 944 S visitWhileCondition(WhileCondition node, A arg); |
| 886 S visitExpressionStatement(ExpressionStatement node, A arg); | 945 S visitExpressionStatement(ExpressionStatement node, A arg); |
| 887 S visitTry(Try node, A arg); | 946 S visitTry(Try node, A arg); |
| 888 S visitUnreachable(Unreachable node, A arg); | 947 S visitUnreachable(Unreachable node, A arg); |
| 948 S visitForeignStatement(ForeignStatement node, A arg); |
| 889 } | 949 } |
| 890 | 950 |
| 891 abstract class RecursiveVisitor implements StatementVisitor, ExpressionVisitor { | 951 abstract class RecursiveVisitor implements StatementVisitor, ExpressionVisitor { |
| 892 visitExpression(Expression e) => e.accept(this); | 952 visitExpression(Expression e) => e.accept(this); |
| 893 visitStatement(Statement s) => s.accept(this); | 953 visitStatement(Statement s) => s.accept(this); |
| 894 | 954 |
| 895 visitInnerFunction(FunctionDefinition node); | 955 visitInnerFunction(FunctionDefinition node); |
| 896 | 956 |
| 897 visitVariable(Variable variable) {} | 957 visitVariable(Variable variable) {} |
| 898 | 958 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 } | 1104 } |
| 1045 | 1105 |
| 1046 visitTypeExpression(TypeExpression node) { | 1106 visitTypeExpression(TypeExpression node) { |
| 1047 node.arguments.forEach(visitExpression); | 1107 node.arguments.forEach(visitExpression); |
| 1048 } | 1108 } |
| 1049 | 1109 |
| 1050 visitCreateInvocationMirror(CreateInvocationMirror node) { | 1110 visitCreateInvocationMirror(CreateInvocationMirror node) { |
| 1051 node.arguments.forEach(visitExpression); | 1111 node.arguments.forEach(visitExpression); |
| 1052 } | 1112 } |
| 1053 | 1113 |
| 1054 visitUnreachable(Unreachable node) {} | 1114 visitUnreachable(Unreachable node) { |
| 1115 } |
| 1055 | 1116 |
| 1056 visitApplyBuiltinOperator(ApplyBuiltinOperator node) { | 1117 visitApplyBuiltinOperator(ApplyBuiltinOperator node) { |
| 1057 node.arguments.forEach(visitExpression); | 1118 node.arguments.forEach(visitExpression); |
| 1058 } | 1119 } |
| 1120 |
| 1121 visitForeignCode(ForeignCode node) { |
| 1122 node.arguments.forEach(visitExpression); |
| 1123 } |
| 1124 |
| 1125 visitForeignExpression(ForeignExpression node) => visitForeignCode(node); |
| 1126 visitForeignStatement(ForeignStatement node) => visitForeignCode(node); |
| 1059 } | 1127 } |
| 1060 | 1128 |
| 1061 abstract class Transformer implements ExpressionVisitor<Expression>, | 1129 abstract class Transformer implements ExpressionVisitor<Expression>, |
| 1062 StatementVisitor<Statement> { | 1130 StatementVisitor<Statement> { |
| 1063 Expression visitExpression(Expression e) => e.accept(this); | 1131 Expression visitExpression(Expression e) => e.accept(this); |
| 1064 Statement visitStatement(Statement s) => s.accept(this); | 1132 Statement visitStatement(Statement s) => s.accept(this); |
| 1065 } | 1133 } |
| 1066 | 1134 |
| 1067 class RecursiveTransformer extends Transformer { | 1135 class RecursiveTransformer extends Transformer { |
| 1068 void visitInnerFunction(FunctionDefinition node) { | 1136 void visitInnerFunction(FunctionDefinition node) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 visitTypeExpression(TypeExpression node) { | 1314 visitTypeExpression(TypeExpression node) { |
| 1247 _replaceExpressions(node.arguments); | 1315 _replaceExpressions(node.arguments); |
| 1248 return node; | 1316 return node; |
| 1249 } | 1317 } |
| 1250 | 1318 |
| 1251 visitCreateInvocationMirror(CreateInvocationMirror node) { | 1319 visitCreateInvocationMirror(CreateInvocationMirror node) { |
| 1252 _replaceExpressions(node.arguments); | 1320 _replaceExpressions(node.arguments); |
| 1253 return node; | 1321 return node; |
| 1254 } | 1322 } |
| 1255 | 1323 |
| 1324 visitForeignExpression(ForeignExpression node) { |
| 1325 _replaceExpressions(node.arguments); |
| 1326 return node; |
| 1327 } |
| 1328 |
| 1329 visitForeignStatement(ForeignStatement node) { |
| 1330 _replaceExpressions(node.arguments); |
| 1331 return node; |
| 1332 } |
| 1333 |
| 1256 visitUnreachable(Unreachable node) { | 1334 visitUnreachable(Unreachable node) { |
| 1257 return node; | 1335 return node; |
| 1258 } | 1336 } |
| 1259 | 1337 |
| 1260 visitApplyBuiltinOperator(ApplyBuiltinOperator node) { | 1338 visitApplyBuiltinOperator(ApplyBuiltinOperator node) { |
| 1261 _replaceExpressions(node.arguments); | 1339 _replaceExpressions(node.arguments); |
| 1262 return node; | 1340 return node; |
| 1263 } | 1341 } |
| 1264 } | 1342 } |
| OLD | NEW |