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