| 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 | 4 |
| 5 library dart2js.ir_builder_task; | 5 library dart2js.ir_builder_task; |
| 6 | 6 |
| 7 import '../closure.dart' as closurelib; | 7 import '../closure.dart' as closurelib; |
| 8 import '../closure.dart' hide ClosureScope; | 8 import '../closure.dart' hide ClosureScope; |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 FunctionElement target, | 213 FunctionElement target, |
| 214 List<ir.Primitive> arguments); | 214 List<ir.Primitive> arguments); |
| 215 | 215 |
| 216 /// Normalizes the argument list of a dynamic invocation (i.e. where the | 216 /// Normalizes the argument list of a dynamic invocation (i.e. where the |
| 217 /// target element is unknown). | 217 /// target element is unknown). |
| 218 /// | 218 /// |
| 219 /// For the JS backend, normalizes order of named arguments. | 219 /// For the JS backend, normalizes order of named arguments. |
| 220 /// | 220 /// |
| 221 /// For the Dart backend, returns [arguments]. | 221 /// For the Dart backend, returns [arguments]. |
| 222 List<ir.Primitive> normalizeDynamicArguments( | 222 List<ir.Primitive> normalizeDynamicArguments( |
| 223 Selector selector, | 223 CallStructure callStructure, |
| 224 List<ir.Primitive> arguments); | 224 List<ir.Primitive> arguments); |
| 225 | 225 |
| 226 ir.RootNode _makeFunctionBody(FunctionElement element, | 226 ir.RootNode _makeFunctionBody(FunctionElement element, |
| 227 ast.FunctionExpression node) { | 227 ast.FunctionExpression node) { |
| 228 FunctionSignature signature = element.functionSignature; | 228 FunctionSignature signature = element.functionSignature; |
| 229 List<ParameterElement> parameters = []; | 229 List<ParameterElement> parameters = []; |
| 230 signature.orderedForEachParameter(parameters.add); | 230 signature.orderedForEachParameter(parameters.add); |
| 231 | 231 |
| 232 irBuilder.buildFunctionHeader(parameters, | 232 irBuilder.buildFunctionHeader(parameters, |
| 233 closureScope: getClosureScopeForNode(node), | 233 closureScope: getClosureScopeForNode(node), |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 return visit(node.expression); | 657 return visit(node.expression); |
| 658 } | 658 } |
| 659 | 659 |
| 660 @override | 660 @override |
| 661 ir.Primitive visitExpressionInvoke(ast.Send node, | 661 ir.Primitive visitExpressionInvoke(ast.Send node, |
| 662 ast.Node expression, | 662 ast.Node expression, |
| 663 ast.NodeList arguments, | 663 ast.NodeList arguments, |
| 664 Selector selector, _) { | 664 Selector selector, _) { |
| 665 ir.Primitive receiver = visit(expression); | 665 ir.Primitive receiver = visit(expression); |
| 666 List<ir.Primitive> arguments = node.arguments.mapToList(visit); | 666 List<ir.Primitive> arguments = node.arguments.mapToList(visit); |
| 667 arguments = normalizeDynamicArguments(selector, arguments); | 667 arguments = normalizeDynamicArguments(selector.callStructure, arguments); |
| 668 return irBuilder.buildCallInvocation(receiver, selector, arguments); | 668 return irBuilder.buildCallInvocation( |
| 669 receiver, selector.callStructure, arguments); |
| 669 } | 670 } |
| 670 | 671 |
| 671 /// Returns `true` if [node] is a super call. | 672 /// Returns `true` if [node] is a super call. |
| 672 // TODO(johnniwinther): Remove the need for this. | 673 // TODO(johnniwinther): Remove the need for this. |
| 673 bool isSuperCall(ast.Send node) { | 674 bool isSuperCall(ast.Send node) { |
| 674 return node != null && node.receiver != null && node.receiver.isSuper(); | 675 return node != null && node.receiver != null && node.receiver.isSuper(); |
| 675 } | 676 } |
| 676 | 677 |
| 677 @override | 678 @override |
| 678 ir.Primitive handleConstantGet( | 679 ir.Primitive handleConstantGet( |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 853 isTypeTest: true, | 854 isTypeTest: true, |
| 854 isNotCheck: true); | 855 isNotCheck: true); |
| 855 } | 856 } |
| 856 | 857 |
| 857 ir.Primitive translateBinary(ast.Node left, | 858 ir.Primitive translateBinary(ast.Node left, |
| 858 op.BinaryOperator operator, | 859 op.BinaryOperator operator, |
| 859 ast.Node right) { | 860 ast.Node right) { |
| 860 Selector selector = new Selector.binaryOperator(operator.selectorName); | 861 Selector selector = new Selector.binaryOperator(operator.selectorName); |
| 861 ir.Primitive receiver = visit(left); | 862 ir.Primitive receiver = visit(left); |
| 862 List<ir.Primitive> arguments = <ir.Primitive>[visit(right)]; | 863 List<ir.Primitive> arguments = <ir.Primitive>[visit(right)]; |
| 863 arguments = normalizeDynamicArguments(selector, arguments); | 864 arguments = normalizeDynamicArguments(selector.callStructure, arguments); |
| 864 return irBuilder.buildDynamicInvocation(receiver, selector, arguments); | 865 return irBuilder.buildDynamicInvocation(receiver, selector, arguments); |
| 865 } | 866 } |
| 866 | 867 |
| 867 @override | 868 @override |
| 868 ir.Primitive visitBinary(ast.Send node, | 869 ir.Primitive visitBinary(ast.Send node, |
| 869 ast.Node left, | 870 ast.Node left, |
| 870 op.BinaryOperator operator, | 871 op.BinaryOperator operator, |
| 871 ast.Node right, _) { | 872 ast.Node right, _) { |
| 872 return translateBinary(left, operator, right); | 873 return translateBinary(left, operator, right); |
| 873 } | 874 } |
| 874 | 875 |
| 875 @override | 876 @override |
| 876 ir.Primitive visitIndex(ast.Send node, | 877 ir.Primitive visitIndex(ast.Send node, |
| 877 ast.Node receiver, | 878 ast.Node receiver, |
| 878 ast.Node index, _) { | 879 ast.Node index, _) { |
| 879 Selector selector = new Selector.index(); | 880 Selector selector = new Selector.index(); |
| 880 ir.Primitive target = visit(receiver); | 881 ir.Primitive target = visit(receiver); |
| 881 List<ir.Primitive> arguments = <ir.Primitive>[visit(index)]; | 882 List<ir.Primitive> arguments = <ir.Primitive>[visit(index)]; |
| 882 arguments = normalizeDynamicArguments(selector, arguments); | 883 arguments = normalizeDynamicArguments(selector.callStructure, arguments); |
| 883 return irBuilder.buildDynamicInvocation(target, selector, arguments); | 884 return irBuilder.buildDynamicInvocation(target, selector, arguments); |
| 884 } | 885 } |
| 885 | 886 |
| 886 ir.Primitive translateSuperBinary(FunctionElement function, | 887 ir.Primitive translateSuperBinary(FunctionElement function, |
| 887 op.BinaryOperator operator, | 888 op.BinaryOperator operator, |
| 888 ast.Node argument) { | 889 ast.Node argument) { |
| 889 Selector selector = new Selector.binaryOperator(operator.selectorName); | 890 CallStructure callStructure = CallStructure.ONE_ARG; |
| 890 List<ir.Primitive> arguments = <ir.Primitive>[visit(argument)]; | 891 List<ir.Primitive> arguments = <ir.Primitive>[visit(argument)]; |
| 891 arguments = normalizeDynamicArguments(selector, arguments); | 892 arguments = normalizeDynamicArguments(callStructure, arguments); |
| 892 return irBuilder.buildSuperMethodInvocation(function, selector, arguments); | 893 return irBuilder.buildSuperMethodInvocation( |
| 894 function, callStructure, arguments); |
| 893 } | 895 } |
| 894 | 896 |
| 895 @override | 897 @override |
| 896 ir.Primitive visitSuperBinary( | 898 ir.Primitive visitSuperBinary( |
| 897 ast.Send node, | 899 ast.Send node, |
| 898 FunctionElement function, | 900 FunctionElement function, |
| 899 op.BinaryOperator operator, | 901 op.BinaryOperator operator, |
| 900 ast.Node argument, | 902 ast.Node argument, |
| 901 _) { | 903 _) { |
| 902 return translateSuperBinary(function, operator, argument); | 904 return translateSuperBinary(function, operator, argument); |
| 903 } | 905 } |
| 904 | 906 |
| 905 @override | 907 @override |
| 906 ir.Primitive visitSuperIndex( | 908 ir.Primitive visitSuperIndex( |
| 907 ast.Send node, | 909 ast.Send node, |
| 908 FunctionElement function, | 910 FunctionElement function, |
| 909 ast.Node index, | 911 ast.Node index, |
| 910 _) { | 912 _) { |
| 911 Selector selector = new Selector.index(); | 913 return irBuilder.buildSuperIndex(function, visit(index)); |
| 912 List<ir.Primitive> arguments = <ir.Primitive>[visit(index)]; | |
| 913 arguments = normalizeDynamicArguments(selector, arguments); | |
| 914 return irBuilder.buildSuperMethodInvocation(function, selector, arguments); | |
| 915 } | 914 } |
| 916 | 915 |
| 917 @override | 916 @override |
| 918 ir.Primitive visitEquals( | 917 ir.Primitive visitEquals( |
| 919 ast.Send node, | 918 ast.Send node, |
| 920 ast.Node left, | 919 ast.Node left, |
| 921 ast.Node right, | 920 ast.Node right, |
| 922 _) { | 921 _) { |
| 923 return translateBinary(left, op.BinaryOperator.EQ, right); | 922 return translateBinary(left, op.BinaryOperator.EQ, right); |
| 924 } | 923 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 ir.Primitive receiver = translateReceiver(expression); | 970 ir.Primitive receiver = translateReceiver(expression); |
| 972 return irBuilder.buildDynamicInvocation(receiver, selector, const []); | 971 return irBuilder.buildDynamicInvocation(receiver, selector, const []); |
| 973 } | 972 } |
| 974 | 973 |
| 975 @override | 974 @override |
| 976 ir.Primitive visitSuperUnary( | 975 ir.Primitive visitSuperUnary( |
| 977 ast.Send node, | 976 ast.Send node, |
| 978 op.UnaryOperator operator, | 977 op.UnaryOperator operator, |
| 979 FunctionElement function, | 978 FunctionElement function, |
| 980 _) { | 979 _) { |
| 981 // TODO(johnniwinther): Clean up the creation of selectors. | 980 return irBuilder.buildSuperMethodInvocation( |
| 982 Selector selector = new Selector( | 981 function, CallStructure.NO_ARGS, const []); |
| 983 SelectorKind.OPERATOR, | |
| 984 new PublicName(operator.selectorName), | |
| 985 CallStructure.NO_ARGS); | |
| 986 return irBuilder.buildSuperMethodInvocation(function, selector, const []); | |
| 987 } | 982 } |
| 988 | 983 |
| 989 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct | 984 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct |
| 990 // semantic correlation between arguments and invocation. | 985 // semantic correlation between arguments and invocation. |
| 991 List<ir.Primitive> translateDynamicArguments(ast.NodeList nodeList, | 986 List<ir.Primitive> translateDynamicArguments(ast.NodeList nodeList, |
| 992 Selector selector) { | 987 CallStructure callStructure) { |
| 993 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); | 988 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); |
| 994 return normalizeDynamicArguments(selector, arguments); | 989 return normalizeDynamicArguments(callStructure, arguments); |
| 995 } | 990 } |
| 996 | 991 |
| 997 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct | 992 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct |
| 998 // semantic correlation between arguments and invocation. | 993 // semantic correlation between arguments and invocation. |
| 999 List<ir.Primitive> translateStaticArguments(ast.NodeList nodeList, | 994 List<ir.Primitive> translateStaticArguments(ast.NodeList nodeList, |
| 1000 Element element, | 995 Element element, |
| 1001 CallStructure callStructure) { | 996 CallStructure callStructure) { |
| 1002 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); | 997 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); |
| 1003 return normalizeStaticArguments(callStructure, element, arguments); | 998 return normalizeStaticArguments(callStructure, element, arguments); |
| 1004 } | 999 } |
| 1005 | 1000 |
| 1006 ir.Primitive translateCallInvoke(ir.Primitive target, | 1001 ir.Primitive translateCallInvoke(ir.Primitive target, |
| 1007 ast.NodeList arguments, | 1002 ast.NodeList arguments, |
| 1008 Selector selector) { | 1003 CallStructure callStructure) { |
| 1009 | 1004 |
| 1010 return irBuilder.buildCallInvocation(target, selector, | 1005 return irBuilder.buildCallInvocation(target, callStructure, |
| 1011 translateDynamicArguments(arguments, selector)); | 1006 translateDynamicArguments(arguments, callStructure)); |
| 1012 } | |
| 1013 | |
| 1014 ir.Primitive translateConstantInvoke(ConstantExpression constant, | |
| 1015 ast.NodeList arguments, | |
| 1016 Selector selector) { | |
| 1017 return translateCallInvoke( | |
| 1018 irBuilder.buildConstantLiteral(constant), | |
| 1019 arguments, | |
| 1020 selector); | |
| 1021 } | 1007 } |
| 1022 | 1008 |
| 1023 @override | 1009 @override |
| 1024 ir.Primitive handleConstantInvoke( | 1010 ir.Primitive handleConstantInvoke( |
| 1025 ast.Send node, | 1011 ast.Send node, |
| 1026 ConstantExpression constant, | 1012 ConstantExpression constant, |
| 1027 ast.NodeList arguments, | 1013 ast.NodeList arguments, |
| 1028 Selector selector, | 1014 CallStructure callStructure, |
| 1029 _) { | 1015 _) { |
| 1030 return translateConstantInvoke(constant, arguments, selector); | 1016 return translateCallInvoke( |
| 1017 irBuilder.buildConstantLiteral(constant), |
| 1018 arguments, |
| 1019 callStructure); |
| 1031 } | 1020 } |
| 1032 | 1021 |
| 1033 @override | 1022 @override |
| 1034 ir.Primitive handleDynamicInvoke( | 1023 ir.Primitive handleDynamicInvoke( |
| 1035 ast.Send node, | 1024 ast.Send node, |
| 1036 ast.Node receiver, | 1025 ast.Node receiver, |
| 1037 ast.NodeList arguments, | 1026 ast.NodeList arguments, |
| 1038 Selector selector, | 1027 Selector selector, |
| 1039 _) { | 1028 _) { |
| 1040 return irBuilder.buildDynamicInvocation( | 1029 return irBuilder.buildDynamicInvocation( |
| 1041 translateReceiver(receiver), selector, | 1030 translateReceiver(receiver), selector, |
| 1042 translateDynamicArguments(arguments, selector)); | 1031 translateDynamicArguments(arguments, selector.callStructure)); |
| 1043 } | 1032 } |
| 1044 | 1033 |
| 1045 ir.Primitive handleLocalInvoke( | 1034 ir.Primitive handleLocalInvoke( |
| 1046 ast.Send node, | 1035 ast.Send node, |
| 1047 LocalElement element, | 1036 LocalElement element, |
| 1048 ast.NodeList arguments, | 1037 ast.NodeList arguments, |
| 1049 Selector selector, | 1038 CallStructure callStructure, |
| 1050 _) { | 1039 _) { |
| 1051 return irBuilder.buildLocalVariableInvocation(element, selector, | 1040 return irBuilder.buildLocalVariableInvocation(element, callStructure, |
| 1052 translateDynamicArguments(arguments, selector)); | 1041 translateDynamicArguments(arguments, callStructure)); |
| 1053 } | 1042 } |
| 1054 | 1043 |
| 1055 @override | 1044 @override |
| 1056 ir.Primitive visitLocalFunctionInvoke( | 1045 ir.Primitive visitLocalFunctionInvoke( |
| 1057 ast.Send node, | 1046 ast.Send node, |
| 1058 LocalFunctionElement function, | 1047 LocalFunctionElement function, |
| 1059 ast.NodeList arguments, | 1048 ast.NodeList arguments, |
| 1060 Selector selector, | 1049 CallStructure callStructure, |
| 1061 _) { | 1050 _) { |
| 1062 return irBuilder.buildLocalFunctionInvocation(function, selector, | 1051 return irBuilder.buildLocalFunctionInvocation(function, callStructure, |
| 1063 translateDynamicArguments(arguments, selector)); | 1052 translateDynamicArguments(arguments, callStructure)); |
| 1064 } | 1053 } |
| 1065 | 1054 |
| 1066 @override | 1055 @override |
| 1067 ir.Primitive handleStaticFieldInvoke( | 1056 ir.Primitive handleStaticFieldInvoke( |
| 1068 ast.Send node, | 1057 ast.Send node, |
| 1069 FieldElement field, | 1058 FieldElement field, |
| 1070 ast.NodeList arguments, | 1059 ast.NodeList arguments, |
| 1071 Selector selector, | 1060 CallStructure callStructure, |
| 1072 _) { | 1061 _) { |
| 1073 return irBuilder.buildStaticFieldInvocation(field, selector, | 1062 return irBuilder.buildStaticFieldInvocation(field, callStructure, |
| 1074 translateDynamicArguments(arguments, selector)); | 1063 translateDynamicArguments(arguments, callStructure)); |
| 1075 } | 1064 } |
| 1076 | 1065 |
| 1077 @override | 1066 @override |
| 1078 ir.Primitive handleStaticFunctionInvoke( | 1067 ir.Primitive handleStaticFunctionInvoke( |
| 1079 ast.Send node, | 1068 ast.Send node, |
| 1080 MethodElement function, | 1069 MethodElement function, |
| 1081 ast.NodeList arguments, | 1070 ast.NodeList arguments, |
| 1082 Selector selector, | 1071 CallStructure callStructure, |
| 1083 _) { | 1072 _) { |
| 1084 // TODO(karlklose): support foreign functions. | 1073 // TODO(karlklose): support foreign functions. |
| 1085 if (function.isForeign(compiler.backend)) { | 1074 if (function.isForeign(compiler.backend)) { |
| 1086 return giveup(node, 'handleStaticFunctionInvoke: foreign: $function'); | 1075 return giveup(node, 'handleStaticFunctionInvoke: foreign: $function'); |
| 1087 } | 1076 } |
| 1088 return irBuilder.buildStaticFunctionInvocation(function, selector, | 1077 return irBuilder.buildStaticFunctionInvocation(function, callStructure, |
| 1089 translateStaticArguments(arguments, function, selector.callStructure), | 1078 translateStaticArguments(arguments, function, callStructure), |
| 1090 sourceInformation: sourceInformationBuilder.buildCall(node)); | 1079 sourceInformation: sourceInformationBuilder.buildCall(node)); |
| 1091 } | 1080 } |
| 1092 | 1081 |
| 1093 @override | 1082 @override |
| 1094 ir.Primitive handleStaticGetterInvoke( | 1083 ir.Primitive handleStaticGetterInvoke( |
| 1095 ast.Send node, | 1084 ast.Send node, |
| 1096 FunctionElement getter, | 1085 FunctionElement getter, |
| 1097 ast.NodeList arguments, | 1086 ast.NodeList arguments, |
| 1098 Selector selector, | 1087 CallStructure callStructure, |
| 1099 _) { | 1088 _) { |
| 1100 return irBuilder.buildStaticGetterInvocation(getter, selector, | 1089 return irBuilder.buildStaticGetterInvocation(getter, callStructure, |
| 1101 translateDynamicArguments(arguments, selector)); | 1090 translateDynamicArguments(arguments, callStructure)); |
| 1102 } | 1091 } |
| 1103 | 1092 |
| 1104 @override | 1093 @override |
| 1105 ir.Primitive visitSuperFieldInvoke( | 1094 ir.Primitive visitSuperFieldInvoke( |
| 1106 ast.Send node, | 1095 ast.Send node, |
| 1107 FieldElement field, | 1096 FieldElement field, |
| 1108 ast.NodeList arguments, | 1097 ast.NodeList arguments, |
| 1109 Selector selector, | 1098 CallStructure callStructure, |
| 1110 _) { | 1099 _) { |
| 1111 return irBuilder.buildSuperFieldInvocation(field, selector, | 1100 return irBuilder.buildSuperFieldInvocation(field, callStructure, |
| 1112 translateDynamicArguments(arguments, selector)); | 1101 translateDynamicArguments(arguments, callStructure)); |
| 1113 } | 1102 } |
| 1114 | 1103 |
| 1115 @override | 1104 @override |
| 1116 ir.Primitive visitSuperGetterInvoke( | 1105 ir.Primitive visitSuperGetterInvoke( |
| 1117 ast.Send node, | 1106 ast.Send node, |
| 1118 FunctionElement getter, | 1107 FunctionElement getter, |
| 1119 ast.NodeList arguments, | 1108 ast.NodeList arguments, |
| 1120 Selector selector, | 1109 CallStructure callStructure, |
| 1121 _) { | 1110 _) { |
| 1122 return irBuilder.buildSuperGetterInvocation(getter, selector, | 1111 return irBuilder.buildSuperGetterInvocation(getter, callStructure, |
| 1123 translateDynamicArguments(arguments, selector)); | 1112 translateDynamicArguments(arguments, callStructure)); |
| 1124 } | 1113 } |
| 1125 | 1114 |
| 1126 @override | 1115 @override |
| 1127 ir.Primitive visitSuperMethodInvoke( | 1116 ir.Primitive visitSuperMethodInvoke( |
| 1128 ast.Send node, | 1117 ast.Send node, |
| 1129 MethodElement method, | 1118 MethodElement method, |
| 1130 ast.NodeList arguments, | 1119 ast.NodeList arguments, |
| 1131 Selector selector, | 1120 CallStructure callStructure, |
| 1132 _) { | 1121 _) { |
| 1133 return irBuilder.buildSuperMethodInvocation(method, selector, | 1122 return irBuilder.buildSuperMethodInvocation(method, callStructure, |
| 1134 translateDynamicArguments(arguments, selector)); | 1123 translateDynamicArguments(arguments, callStructure)); |
| 1135 } | 1124 } |
| 1136 | 1125 |
| 1137 @override | 1126 @override |
| 1138 ir.Primitive visitThisInvoke( | 1127 ir.Primitive visitThisInvoke( |
| 1139 ast.Send node, | 1128 ast.Send node, |
| 1140 ast.NodeList arguments, | 1129 ast.NodeList arguments, |
| 1141 Selector selector, | 1130 CallStructure callStructure, |
| 1142 _) { | 1131 _) { |
| 1143 return translateCallInvoke(irBuilder.buildThis(), arguments, selector); | 1132 return translateCallInvoke(irBuilder.buildThis(), arguments, callStructure); |
| 1144 } | 1133 } |
| 1145 | 1134 |
| 1146 @override | 1135 @override |
| 1147 ir.Primitive visitTypeVariableTypeLiteralInvoke( | 1136 ir.Primitive visitTypeVariableTypeLiteralInvoke( |
| 1148 ast.Send node, | 1137 ast.Send node, |
| 1149 TypeVariableElement element, | 1138 TypeVariableElement element, |
| 1150 ast.NodeList arguments, | 1139 ast.NodeList arguments, |
| 1151 Selector selector, | 1140 CallStructure callStructure, |
| 1152 _) { | 1141 _) { |
| 1153 return translateCallInvoke( | 1142 return translateCallInvoke( |
| 1154 translateTypeVariableTypeLiteral(element), | 1143 translateTypeVariableTypeLiteral(element), |
| 1155 arguments, | 1144 arguments, |
| 1156 selector); | 1145 callStructure); |
| 1157 } | |
| 1158 | |
| 1159 @override | |
| 1160 ir.Primitive visitTypedefTypeLiteralInvoke( | |
| 1161 ast.Send node, | |
| 1162 TypeConstantExpression constant, | |
| 1163 ast.NodeList arguments, | |
| 1164 Selector selector, _) { | |
| 1165 return translateConstantInvoke(constant, arguments, selector); | |
| 1166 } | 1146 } |
| 1167 | 1147 |
| 1168 // TODO(johnniwinther): This should be a method on [IrBuilder]. | 1148 // TODO(johnniwinther): This should be a method on [IrBuilder]. |
| 1169 ir.Primitive buildReifyTypeVariable(ir.Primitive target, | 1149 ir.Primitive buildReifyTypeVariable(ir.Primitive target, |
| 1170 TypeVariableType variable); | 1150 TypeVariableType variable); |
| 1171 | 1151 |
| 1172 @override | 1152 @override |
| 1173 ir.Primitive visitIndexSet( | 1153 ir.Primitive visitIndexSet( |
| 1174 ast.SendSet node, | 1154 ast.SendSet node, |
| 1175 ast.Node receiver, | 1155 ast.Node receiver, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1197 ast.Node index, | 1177 ast.Node index, |
| 1198 op.AssignmentOperator operator, | 1178 op.AssignmentOperator operator, |
| 1199 ast.Node rhs, | 1179 ast.Node rhs, |
| 1200 _) { | 1180 _) { |
| 1201 ir.Primitive target = visit(receiver); | 1181 ir.Primitive target = visit(receiver); |
| 1202 ir.Primitive indexValue = visit(index); | 1182 ir.Primitive indexValue = visit(index); |
| 1203 return translateCompound( | 1183 return translateCompound( |
| 1204 getValue: () { | 1184 getValue: () { |
| 1205 Selector selector = new Selector.index(); | 1185 Selector selector = new Selector.index(); |
| 1206 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; | 1186 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; |
| 1207 arguments = normalizeDynamicArguments(selector, arguments); | 1187 arguments = |
| 1188 normalizeDynamicArguments(selector.callStructure, arguments); |
| 1208 return irBuilder.buildDynamicInvocation(target, selector, arguments); | 1189 return irBuilder.buildDynamicInvocation(target, selector, arguments); |
| 1209 }, | 1190 }, |
| 1210 operator: operator, | 1191 operator: operator, |
| 1211 rhs: rhs, | 1192 rhs: rhs, |
| 1212 setValue: (ir.Primitive result) { | 1193 setValue: (ir.Primitive result) { |
| 1213 irBuilder.buildDynamicIndexSet(target, indexValue, result); | 1194 irBuilder.buildDynamicIndexSet(target, indexValue, result); |
| 1214 }); | 1195 }); |
| 1215 } | 1196 } |
| 1216 | 1197 |
| 1217 @override | 1198 @override |
| 1218 ir.Primitive visitSuperCompoundIndexSet( | 1199 ir.Primitive visitSuperCompoundIndexSet( |
| 1219 ast.SendSet node, | 1200 ast.SendSet node, |
| 1220 FunctionElement getter, | 1201 FunctionElement getter, |
| 1221 FunctionElement setter, | 1202 FunctionElement setter, |
| 1222 ast.Node index, | 1203 ast.Node index, |
| 1223 op.AssignmentOperator operator, | 1204 op.AssignmentOperator operator, |
| 1224 ast.Node rhs, | 1205 ast.Node rhs, |
| 1225 _) { | 1206 _) { |
| 1226 ir.Primitive indexValue = visit(index); | 1207 ir.Primitive indexValue = visit(index); |
| 1227 return translateCompound( | 1208 return translateCompound( |
| 1228 getValue: () { | 1209 getValue: () { |
| 1229 Selector selector = new Selector.index(); | 1210 return irBuilder.buildSuperIndex(getter, indexValue); |
| 1230 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; | |
| 1231 arguments = normalizeDynamicArguments(selector, arguments); | |
| 1232 return irBuilder.buildSuperMethodInvocation( | |
| 1233 getter, selector, arguments); | |
| 1234 }, | 1211 }, |
| 1235 operator: operator, | 1212 operator: operator, |
| 1236 rhs: rhs, | 1213 rhs: rhs, |
| 1237 setValue: (ir.Primitive result) { | 1214 setValue: (ir.Primitive result) { |
| 1238 irBuilder.buildSuperIndexSet(setter, indexValue, result); | 1215 irBuilder.buildSuperIndexSet(setter, indexValue, result); |
| 1239 }); | 1216 }); |
| 1240 } | 1217 } |
| 1241 | 1218 |
| 1242 ir.Primitive translatePrefixPostfix( | 1219 ir.Primitive translatePrefixPostfix( |
| 1243 {ir.Primitive getValue(), | 1220 {ir.Primitive getValue(), |
| 1244 op.IncDecOperator operator, | 1221 op.IncDecOperator operator, |
| 1245 void setValue(ir.Primitive value), | 1222 void setValue(ir.Primitive value), |
| 1246 bool isPrefix}) { | 1223 bool isPrefix}) { |
| 1247 ir.Primitive value = getValue(); | 1224 ir.Primitive value = getValue(); |
| 1248 Selector operatorSelector = | 1225 Selector operatorSelector = |
| 1249 new Selector.binaryOperator(operator.selectorName); | 1226 new Selector.binaryOperator(operator.selectorName); |
| 1250 List<ir.Primitive> arguments = | 1227 List<ir.Primitive> arguments = |
| 1251 <ir.Primitive>[irBuilder.buildIntegerLiteral(1)]; | 1228 <ir.Primitive>[irBuilder.buildIntegerLiteral(1)]; |
| 1252 arguments = normalizeDynamicArguments(operatorSelector, arguments); | 1229 arguments = normalizeDynamicArguments( |
| 1230 operatorSelector.callStructure, arguments); |
| 1253 ir.Primitive result = | 1231 ir.Primitive result = |
| 1254 irBuilder.buildDynamicInvocation(value, operatorSelector, arguments); | 1232 irBuilder.buildDynamicInvocation(value, operatorSelector, arguments); |
| 1255 setValue(result); | 1233 setValue(result); |
| 1256 return isPrefix ? result : value; | 1234 return isPrefix ? result : value; |
| 1257 } | 1235 } |
| 1258 | 1236 |
| 1259 ir.Primitive translateCompound( | 1237 ir.Primitive translateCompound( |
| 1260 {ir.Primitive getValue(), | 1238 {ir.Primitive getValue(), |
| 1261 op.AssignmentOperator operator, | 1239 op.AssignmentOperator operator, |
| 1262 ast.Node rhs, | 1240 ast.Node rhs, |
| 1263 void setValue(ir.Primitive value)}) { | 1241 void setValue(ir.Primitive value)}) { |
| 1264 ir.Primitive value = getValue(); | 1242 ir.Primitive value = getValue(); |
| 1265 Selector operatorSelector = | 1243 Selector operatorSelector = |
| 1266 new Selector.binaryOperator(operator.selectorName); | 1244 new Selector.binaryOperator(operator.selectorName); |
| 1267 List<ir.Primitive> arguments = <ir.Primitive>[visit(rhs)]; | 1245 List<ir.Primitive> arguments = <ir.Primitive>[visit(rhs)]; |
| 1268 arguments = normalizeDynamicArguments(operatorSelector, arguments); | 1246 arguments = normalizeDynamicArguments( |
| 1247 operatorSelector.callStructure, arguments); |
| 1269 ir.Primitive result = | 1248 ir.Primitive result = |
| 1270 irBuilder.buildDynamicInvocation(value, operatorSelector, arguments); | 1249 irBuilder.buildDynamicInvocation(value, operatorSelector, arguments); |
| 1271 setValue(result); | 1250 setValue(result); |
| 1272 return result; | 1251 return result; |
| 1273 } | 1252 } |
| 1274 | 1253 |
| 1275 @override | 1254 @override |
| 1276 ir.Primitive handleDynamicCompound( | 1255 ir.Primitive handleDynamicCompound( |
| 1277 ast.Send node, | 1256 ast.Send node, |
| 1278 ast.Node receiver, | 1257 ast.Node receiver, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 ast.Node index, | 1562 ast.Node index, |
| 1584 op.IncDecOperator operator, | 1563 op.IncDecOperator operator, |
| 1585 arg, | 1564 arg, |
| 1586 {bool isPrefix}) { | 1565 {bool isPrefix}) { |
| 1587 ir.Primitive target = visit(receiver); | 1566 ir.Primitive target = visit(receiver); |
| 1588 ir.Primitive indexValue = visit(index); | 1567 ir.Primitive indexValue = visit(index); |
| 1589 return translatePrefixPostfix( | 1568 return translatePrefixPostfix( |
| 1590 getValue: () { | 1569 getValue: () { |
| 1591 Selector selector = new Selector.index(); | 1570 Selector selector = new Selector.index(); |
| 1592 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; | 1571 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; |
| 1593 arguments = normalizeDynamicArguments(selector, arguments); | 1572 arguments = |
| 1573 normalizeDynamicArguments(selector.callStructure, arguments); |
| 1594 return irBuilder.buildDynamicInvocation(target, selector, arguments); | 1574 return irBuilder.buildDynamicInvocation(target, selector, arguments); |
| 1595 }, | 1575 }, |
| 1596 operator: operator, | 1576 operator: operator, |
| 1597 setValue: (ir.Primitive result) { | 1577 setValue: (ir.Primitive result) { |
| 1598 Selector selector = new Selector.indexSet(); | 1578 Selector selector = new Selector.indexSet(); |
| 1599 List<ir.Primitive> arguments = <ir.Primitive>[indexValue, result]; | 1579 List<ir.Primitive> arguments = <ir.Primitive>[indexValue, result]; |
| 1600 arguments = normalizeDynamicArguments(selector, arguments); | 1580 arguments = |
| 1581 normalizeDynamicArguments(selector.callStructure, arguments); |
| 1601 irBuilder.buildDynamicInvocation(target, selector, arguments); | 1582 irBuilder.buildDynamicInvocation(target, selector, arguments); |
| 1602 }, | 1583 }, |
| 1603 isPrefix: isPrefix); | 1584 isPrefix: isPrefix); |
| 1604 } | 1585 } |
| 1605 | 1586 |
| 1606 @override | 1587 @override |
| 1607 ir.Primitive handleSuperIndexPostfixPrefix( | 1588 ir.Primitive handleSuperIndexPostfixPrefix( |
| 1608 ast.Send node, | 1589 ast.Send node, |
| 1609 FunctionElement indexFunction, | 1590 FunctionElement indexFunction, |
| 1610 FunctionElement indexSetFunction, | 1591 FunctionElement indexSetFunction, |
| 1611 ast.Node index, | 1592 ast.Node index, |
| 1612 op.IncDecOperator operator, | 1593 op.IncDecOperator operator, |
| 1613 arg, | 1594 arg, |
| 1614 {bool isPrefix}) { | 1595 {bool isPrefix}) { |
| 1615 ir.Primitive indexValue = visit(index); | 1596 ir.Primitive indexValue = visit(index); |
| 1616 return translatePrefixPostfix( | 1597 return translatePrefixPostfix( |
| 1617 getValue: () { | 1598 getValue: () { |
| 1618 Selector selector = new Selector.index(); | 1599 return irBuilder.buildSuperIndex(indexFunction, indexValue); |
| 1619 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; | |
| 1620 arguments = normalizeDynamicArguments(selector, arguments); | |
| 1621 return irBuilder.buildSuperMethodInvocation( | |
| 1622 indexFunction, selector, arguments); | |
| 1623 }, | 1600 }, |
| 1624 operator: operator, | 1601 operator: operator, |
| 1625 setValue: (ir.Primitive result) { | 1602 setValue: (ir.Primitive result) { |
| 1626 Selector selector = new Selector.indexSet(); | 1603 irBuilder.buildSuperIndexSet(indexSetFunction, indexValue, result); |
| 1627 List<ir.Primitive> arguments = <ir.Primitive>[indexValue, result]; | |
| 1628 arguments = normalizeDynamicArguments(selector, arguments); | |
| 1629 irBuilder.buildSuperMethodInvocation( | |
| 1630 indexSetFunction, selector, arguments); | |
| 1631 }, | 1604 }, |
| 1632 isPrefix: isPrefix); | 1605 isPrefix: isPrefix); |
| 1633 } | 1606 } |
| 1634 | 1607 |
| 1635 @override | 1608 @override |
| 1636 ir.Primitive handleStaticSetterSet( | 1609 ir.Primitive handleStaticSetterSet( |
| 1637 ast.SendSet node, | 1610 ast.SendSet node, |
| 1638 FunctionElement setter, | 1611 FunctionElement setter, |
| 1639 ast.Node rhs, | 1612 ast.Node rhs, |
| 1640 _) { | 1613 _) { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2089 } | 2062 } |
| 2090 | 2063 |
| 2091 List<ir.Primitive> normalizeStaticArguments( | 2064 List<ir.Primitive> normalizeStaticArguments( |
| 2092 CallStructure callStructure, | 2065 CallStructure callStructure, |
| 2093 FunctionElement target, | 2066 FunctionElement target, |
| 2094 List<ir.Primitive> arguments) { | 2067 List<ir.Primitive> arguments) { |
| 2095 return arguments; | 2068 return arguments; |
| 2096 } | 2069 } |
| 2097 | 2070 |
| 2098 List<ir.Primitive> normalizeDynamicArguments( | 2071 List<ir.Primitive> normalizeDynamicArguments( |
| 2099 Selector selector, | 2072 CallStructure callStructure, |
| 2100 List<ir.Primitive> arguments) { | 2073 List<ir.Primitive> arguments) { |
| 2101 return arguments; | 2074 return arguments; |
| 2102 } | 2075 } |
| 2103 | 2076 |
| 2104 @override | 2077 @override |
| 2105 ir.Primitive buildReifyTypeVariable(ir.Primitive target, | 2078 ir.Primitive buildReifyTypeVariable(ir.Primitive target, |
| 2106 TypeVariableType variable) { | 2079 TypeVariableType variable) { |
| 2107 assert(target == irBuilder.state.enclosingMethodThisParameter); | 2080 assert(target == irBuilder.state.enclosingMethodThisParameter); |
| 2108 ir.Primitive prim = new ir.ReifyTypeVar(variable.element); | 2081 ir.Primitive prim = new ir.ReifyTypeVar(variable.element); |
| 2109 irBuilder.add(new ir.LetPrim(prim)); | 2082 irBuilder.add(new ir.LetPrim(prim)); |
| 2110 return prim; | 2083 return prim; |
| 2111 } | 2084 } |
| 2112 | 2085 |
| 2113 @override | 2086 @override |
| 2114 ir.Primitive handleConstructorInvoke( | 2087 ir.Primitive handleConstructorInvoke( |
| 2115 ast.NewExpression node, | 2088 ast.NewExpression node, |
| 2116 ConstructorElement constructor, | 2089 ConstructorElement constructor, |
| 2117 DartType type, | 2090 DartType type, |
| 2118 ast.NodeList arguments, | 2091 ast.NodeList arguments, |
| 2119 Selector selector, _) { | 2092 CallStructure callStructure, _) { |
| 2120 List<ir.Primitive> arguments = | 2093 List<ir.Primitive> arguments = |
| 2121 node.send.arguments.mapToList(visit, growable:false); | 2094 node.send.arguments.mapToList(visit, growable:false); |
| 2122 return irBuilder.buildConstructorInvocation( | 2095 return irBuilder.buildConstructorInvocation( |
| 2123 constructor, | 2096 constructor, |
| 2124 selector, | 2097 callStructure, |
| 2125 type, | 2098 type, |
| 2126 arguments); | 2099 arguments); |
| 2127 } | 2100 } |
| 2128 } | 2101 } |
| 2129 | 2102 |
| 2130 /// The [IrBuilder]s view on the information about the program that has been | 2103 /// The [IrBuilder]s view on the information about the program that has been |
| 2131 /// computed in resolution and and type interence. | 2104 /// computed in resolution and and type interence. |
| 2132 class GlobalProgramInformation { | 2105 class GlobalProgramInformation { |
| 2133 final Compiler _compiler; | 2106 final Compiler _compiler; |
| 2134 JavaScriptBackend get _backend => _compiler.backend; | 2107 JavaScriptBackend get _backend => _compiler.backend; |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2676 } else { | 2649 } else { |
| 2677 result.add(translateDefaultValue(element)); | 2650 result.add(translateDefaultValue(element)); |
| 2678 } | 2651 } |
| 2679 }); | 2652 }); |
| 2680 } | 2653 } |
| 2681 return result; | 2654 return result; |
| 2682 } | 2655 } |
| 2683 | 2656 |
| 2684 /// Normalizes order of named arguments. | 2657 /// Normalizes order of named arguments. |
| 2685 List<ir.Primitive> normalizeDynamicArguments( | 2658 List<ir.Primitive> normalizeDynamicArguments( |
| 2686 Selector selector, | 2659 CallStructure callStructure, |
| 2687 List<ir.Primitive> arguments) { | 2660 List<ir.Primitive> arguments) { |
| 2688 CallStructure callStructure = selector.callStructure; | |
| 2689 assert(arguments.length == callStructure.argumentCount); | 2661 assert(arguments.length == callStructure.argumentCount); |
| 2690 // Optimization: don't copy the argument list for trivial cases. | 2662 // Optimization: don't copy the argument list for trivial cases. |
| 2691 if (callStructure.namedArguments.isEmpty) return arguments; | 2663 if (callStructure.namedArguments.isEmpty) return arguments; |
| 2692 List<ir.Primitive> result = <ir.Primitive>[]; | 2664 List<ir.Primitive> result = <ir.Primitive>[]; |
| 2693 for (int i=0; i < callStructure.positionalArgumentCount; i++) { | 2665 for (int i=0; i < callStructure.positionalArgumentCount; i++) { |
| 2694 result.add(arguments[i]); | 2666 result.add(arguments[i]); |
| 2695 } | 2667 } |
| 2696 for (String argName in callStructure.getOrderedNamedArguments()) { | 2668 for (String argName in callStructure.getOrderedNamedArguments()) { |
| 2697 int nameIndex = callStructure.namedArguments.indexOf(argName); | 2669 int nameIndex = callStructure.namedArguments.indexOf(argName); |
| 2698 int translatedIndex = callStructure.positionalArgumentCount + nameIndex; | 2670 int translatedIndex = callStructure.positionalArgumentCount + nameIndex; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2711 irBuilder.add(new ir.LetPrim(type)); | 2683 irBuilder.add(new ir.LetPrim(type)); |
| 2712 return type; | 2684 return type; |
| 2713 } | 2685 } |
| 2714 | 2686 |
| 2715 @override | 2687 @override |
| 2716 ir.Primitive handleConstructorInvoke( | 2688 ir.Primitive handleConstructorInvoke( |
| 2717 ast.NewExpression node, | 2689 ast.NewExpression node, |
| 2718 ConstructorElement constructor, | 2690 ConstructorElement constructor, |
| 2719 DartType type, | 2691 DartType type, |
| 2720 ast.NodeList arguments, | 2692 ast.NodeList arguments, |
| 2721 Selector selector, _) { | 2693 CallStructure callStructure, |
| 2694 _) { |
| 2722 List<ir.Primitive> arguments = | 2695 List<ir.Primitive> arguments = |
| 2723 node.send.arguments.mapToList(visit, growable:false); | 2696 node.send.arguments.mapToList(visit, growable:false); |
| 2724 arguments = normalizeStaticArguments( | 2697 arguments = normalizeStaticArguments( |
| 2725 selector.callStructure, constructor, arguments); | 2698 callStructure, constructor, arguments); |
| 2726 return irBuilder.buildConstructorInvocation( | 2699 return irBuilder.buildConstructorInvocation( |
| 2727 constructor.effectiveTarget, | 2700 constructor.effectiveTarget, |
| 2728 selector, | 2701 callStructure, |
| 2729 constructor.computeEffectiveTargetType(type), | 2702 constructor.computeEffectiveTargetType(type), |
| 2730 arguments); | 2703 arguments); |
| 2731 } | 2704 } |
| 2732 } | 2705 } |
| 2733 | 2706 |
| 2734 /// Interface for generating [SourceInformation] for the CPS. | 2707 /// Interface for generating [SourceInformation] for the CPS. |
| 2735 class SourceInformationBuilder { | 2708 class SourceInformationBuilder { |
| 2736 const SourceInformationBuilder(); | 2709 const SourceInformationBuilder(); |
| 2737 | 2710 |
| 2738 /// Create a [SourceInformationBuilder] for [element]. | 2711 /// Create a [SourceInformationBuilder] for [element]. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2764 SourceInformation buildCall(ast.Node node) { | 2737 SourceInformation buildCall(ast.Node node) { |
| 2765 return new PositionSourceInformation( | 2738 return new PositionSourceInformation( |
| 2766 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); | 2739 new TokenSourceLocation(sourceFile, node.getBeginToken(), name)); |
| 2767 } | 2740 } |
| 2768 | 2741 |
| 2769 @override | 2742 @override |
| 2770 SourceInformationBuilder forContext(AstElement element) { | 2743 SourceInformationBuilder forContext(AstElement element) { |
| 2771 return new PositionSourceInformationBuilder(element); | 2744 return new PositionSourceInformationBuilder(element); |
| 2772 } | 2745 } |
| 2773 } | 2746 } |
| OLD | NEW |