Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1491973002: dart2js: Use correct call structures throughout the backend. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '../common.dart'; 9 import '../common.dart';
10 import '../common/names.dart' show 10 import '../common/names.dart' show
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 * Builds the [ir.FunctionDefinition] for an executable element. In case the 178 * Builds the [ir.FunctionDefinition] for an executable element. In case the
179 * function uses features that cannot be expressed in the IR, this element 179 * function uses features that cannot be expressed in the IR, this element
180 * returns `null`. 180 * returns `null`.
181 */ 181 */
182 ir.FunctionDefinition buildExecutable(ExecutableElement element); 182 ir.FunctionDefinition buildExecutable(ExecutableElement element);
183 183
184 ClosureClassMap get closureClassMap; 184 ClosureClassMap get closureClassMap;
185 ClosureScope getClosureScopeForNode(ast.Node node); 185 ClosureScope getClosureScopeForNode(ast.Node node);
186 ClosureEnvironment getClosureEnvironment(); 186 ClosureEnvironment getClosureEnvironment();
187 187
188 /// Normalizes the argument list to a static invocation (i.e. where the target 188 /// Normalizes the argument list of a static invocation.
189 /// element is known).
190 /// 189 ///
191 /// For the JS backend, inserts default arguments and normalizes order of 190 /// A static invocation is one where the target is known. The argument list
192 /// named arguments. 191 /// [arguments] is normalized by adding default values for optional arguments
193 /// 192 /// that are not passed, and by sorting it in place so that named arguments
194 /// For the Dart backend, returns [arguments]. 193 /// appear in a canonical order. A [CallStructure] reflecting this order
195 List<ir.Primitive> normalizeStaticArguments( 194 /// is returned.
195 CallStructure normalizeStaticArguments(
196 CallStructure callStructure, 196 CallStructure callStructure,
197 FunctionElement target, 197 FunctionElement target,
198 List<ir.Primitive> arguments); 198 List<ir.Primitive> arguments);
199 199
200 /// Normalizes the argument list of a dynamic invocation (i.e. where the 200 /// Normalizes the argument list of a dynamic invocation.
201 /// target element is unknown).
202 /// 201 ///
203 /// For the JS backend, normalizes order of named arguments. 202 /// A dynamic invocation is one where the target is not known. The argument
204 /// 203 /// list [arguments] is normalized by sorting it in place so that the named
205 /// For the Dart backend, returns [arguments]. 204 /// arguments appear in a canonical order. A [CallStructure] reflecting this
206 List<ir.Primitive> normalizeDynamicArguments( 205 /// order is returned.
206 CallStructure normalizeDynamicArguments(
207 CallStructure callStructure, 207 CallStructure callStructure,
208 List<ir.Primitive> arguments); 208 List<ir.Primitive> arguments);
209 209
210 /// Read the value of [field]. 210 /// Read the value of [field].
211 ir.Primitive buildStaticFieldGet(FieldElement field, SourceInformation src); 211 ir.Primitive buildStaticFieldGet(FieldElement field, SourceInformation src);
212 212
213 ir.FunctionDefinition _makeFunctionBody(FunctionElement element, 213 ir.FunctionDefinition _makeFunctionBody(FunctionElement element,
214 ast.FunctionExpression node) { 214 ast.FunctionExpression node) {
215 FunctionSignature signature = element.functionSignature; 215 FunctionSignature signature = element.functionSignature;
216 List<Local> parameters = <Local>[]; 216 List<Local> parameters = <Local>[];
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 if (parameter.isNamed) { 309 if (parameter.isNamed) {
310 namedParameters.add(parameter.name); 310 namedParameters.add(parameter.name);
311 } 311 }
312 }); 312 });
313 ClassElement cls = redirectingConstructor.enclosingClass; 313 ClassElement cls = redirectingConstructor.enclosingClass;
314 InterfaceType targetType = 314 InterfaceType targetType =
315 redirectingConstructor.computeEffectiveTargetType(cls.thisType); 315 redirectingConstructor.computeEffectiveTargetType(cls.thisType);
316 CallStructure callStructure = new CallStructure( 316 CallStructure callStructure = new CallStructure(
317 redirectingSignature.parameterCount, 317 redirectingSignature.parameterCount,
318 namedParameters); 318 namedParameters);
319 arguments = normalizeStaticArguments(callStructure, targetConstructor, 319 callStructure = normalizeStaticArguments(
320 arguments); 320 callStructure, targetConstructor, arguments);
321 ir.Primitive instance = irBuilder.buildConstructorInvocation( 321 ir.Primitive instance = irBuilder.buildConstructorInvocation(
322 targetConstructor, 322 targetConstructor,
323 callStructure, 323 callStructure,
324 targetType, 324 targetType,
325 arguments, 325 arguments,
326 sourceInformationBuilder.buildNew(node)); 326 sourceInformationBuilder.buildNew(node));
327 irBuilder.buildReturn( 327 irBuilder.buildReturn(
328 value: instance, 328 value: instance,
329 sourceInformation: sourceInformationBuilder.buildReturn(node)); 329 sourceInformation: sourceInformationBuilder.buildReturn(node));
330 } 330 }
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 return visit(node.expression); 713 return visit(node.expression);
714 } 714 }
715 715
716 @override 716 @override
717 ir.Primitive visitExpressionInvoke(ast.Send node, 717 ir.Primitive visitExpressionInvoke(ast.Send node,
718 ast.Node expression, 718 ast.Node expression,
719 ast.NodeList argumentsNode, 719 ast.NodeList argumentsNode,
720 CallStructure callStructure, _) { 720 CallStructure callStructure, _) {
721 ir.Primitive receiver = visit(expression); 721 ir.Primitive receiver = visit(expression);
722 List<ir.Primitive> arguments = node.arguments.mapToList(visit); 722 List<ir.Primitive> arguments = node.arguments.mapToList(visit);
723 arguments = normalizeDynamicArguments(callStructure, arguments); 723 CallStructure normalizedCallStructure =
724 normalizeDynamicArguments(callStructure, arguments);
724 return irBuilder.buildCallInvocation( 725 return irBuilder.buildCallInvocation(
725 receiver, callStructure, arguments, 726 receiver, normalizedCallStructure, arguments,
726 sourceInformation: 727 sourceInformation:
727 sourceInformationBuilder.buildCall(node, argumentsNode)); 728 sourceInformationBuilder.buildCall(node, argumentsNode));
728 } 729 }
729 730
730 /// Returns `true` if [node] is a super call. 731 /// Returns `true` if [node] is a super call.
731 // TODO(johnniwinther): Remove the need for this. 732 // TODO(johnniwinther): Remove the need for this.
732 bool isSuperCall(ast.Send node) { 733 bool isSuperCall(ast.Send node) {
733 return node != null && node.receiver != null && node.receiver.isSuper(); 734 return node != null && node.receiver != null && node.receiver.isSuper();
734 } 735 }
735 736
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 return irBuilder.buildNegation(check); 947 return irBuilder.buildNegation(check);
947 } 948 }
948 949
949 ir.Primitive translateBinary(ast.Send node, 950 ir.Primitive translateBinary(ast.Send node,
950 ast.Node left, 951 ast.Node left,
951 op.BinaryOperator operator, 952 op.BinaryOperator operator,
952 ast.Node right) { 953 ast.Node right) {
953 Selector selector = new Selector.binaryOperator(operator.selectorName); 954 Selector selector = new Selector.binaryOperator(operator.selectorName);
954 ir.Primitive receiver = visit(left); 955 ir.Primitive receiver = visit(left);
955 List<ir.Primitive> arguments = <ir.Primitive>[visit(right)]; 956 List<ir.Primitive> arguments = <ir.Primitive>[visit(right)];
956 arguments = normalizeDynamicArguments(selector.callStructure, arguments); 957 CallStructure callStructure =
958 normalizeDynamicArguments(selector.callStructure, arguments);
957 return irBuilder.buildDynamicInvocation( 959 return irBuilder.buildDynamicInvocation(
958 receiver, selector, elements.getTypeMask(node), arguments, 960 receiver,
961 new Selector(selector.kind, selector.memberName, callStructure),
962 elements.getTypeMask(node),
963 arguments,
959 sourceInformation: 964 sourceInformation:
960 sourceInformationBuilder.buildCall(node, node.selector)); 965 sourceInformationBuilder.buildCall(node, node.selector));
961 } 966 }
962 967
963 @override 968 @override
964 ir.Primitive visitBinary(ast.Send node, 969 ir.Primitive visitBinary(ast.Send node,
965 ast.Node left, 970 ast.Node left,
966 op.BinaryOperator operator, 971 op.BinaryOperator operator,
967 ast.Node right, _) { 972 ast.Node right, _) {
968 return translateBinary(node, left, operator, right); 973 return translateBinary(node, left, operator, right);
969 } 974 }
970 975
971 @override 976 @override
972 ir.Primitive visitIndex(ast.Send node, 977 ir.Primitive visitIndex(ast.Send node,
973 ast.Node receiver, 978 ast.Node receiver,
974 ast.Node index, _) { 979 ast.Node index, _) {
975 Selector selector = new Selector.index(); 980 Selector selector = new Selector.index();
976 ir.Primitive target = visit(receiver); 981 ir.Primitive target = visit(receiver);
977 List<ir.Primitive> arguments = <ir.Primitive>[visit(index)]; 982 List<ir.Primitive> arguments = <ir.Primitive>[visit(index)];
978 arguments = normalizeDynamicArguments(selector.callStructure, arguments); 983 CallStructure callStructure =
984 normalizeDynamicArguments(selector.callStructure, arguments);
979 return irBuilder.buildDynamicInvocation( 985 return irBuilder.buildDynamicInvocation(
980 target, selector, elements.getTypeMask(node), arguments, 986 target,
987 new Selector(selector.kind, selector.memberName, callStructure),
988 elements.getTypeMask(node),
989 arguments,
981 sourceInformation: 990 sourceInformation:
982 sourceInformationBuilder.buildCall(receiver, node.selector)); 991 sourceInformationBuilder.buildCall(receiver, node.selector));
983 } 992 }
984 993
985 ir.Primitive translateSuperBinary(FunctionElement function, 994 ir.Primitive translateSuperBinary(FunctionElement function,
986 op.BinaryOperator operator, 995 op.BinaryOperator operator,
987 ast.Node argument) { 996 ast.Node argument) {
988 CallStructure callStructure = CallStructure.ONE_ARG;
989 List<ir.Primitive> arguments = <ir.Primitive>[visit(argument)]; 997 List<ir.Primitive> arguments = <ir.Primitive>[visit(argument)];
990 arguments = normalizeDynamicArguments(callStructure, arguments); 998 CallStructure callStructure =
999 normalizeDynamicArguments(CallStructure.ONE_ARG, arguments);
991 return irBuilder.buildSuperMethodInvocation( 1000 return irBuilder.buildSuperMethodInvocation(
992 function, callStructure, arguments); 1001 function, callStructure, arguments);
993 } 1002 }
994 1003
995 @override 1004 @override
996 ir.Primitive visitSuperBinary( 1005 ir.Primitive visitSuperBinary(
997 ast.Send node, 1006 ast.Send node,
998 FunctionElement function, 1007 FunctionElement function,
999 op.BinaryOperator operator, 1008 op.BinaryOperator operator,
1000 ast.Node argument, 1009 ast.Node argument,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 ast.Send node, 1083 ast.Send node,
1075 op.UnaryOperator operator, 1084 op.UnaryOperator operator,
1076 FunctionElement function, 1085 FunctionElement function,
1077 _) { 1086 _) {
1078 return irBuilder.buildSuperMethodInvocation( 1087 return irBuilder.buildSuperMethodInvocation(
1079 function, CallStructure.NO_ARGS, const []); 1088 function, CallStructure.NO_ARGS, const []);
1080 } 1089 }
1081 1090
1082 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct 1091 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct
1083 // semantic correlation between arguments and invocation. 1092 // semantic correlation between arguments and invocation.
1084 List<ir.Primitive> translateDynamicArguments(ast.NodeList nodeList, 1093 CallStructure translateDynamicArguments(ast.NodeList nodeList,
1085 CallStructure callStructure) { 1094 CallStructure callStructure,
1086 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); 1095 List<ir.Primitive> arguments) {
1096 assert(arguments.isEmpty);
1097 for (ast.Node node in nodeList) arguments.add(visit(node));
1087 return normalizeDynamicArguments(callStructure, arguments); 1098 return normalizeDynamicArguments(callStructure, arguments);
1088 } 1099 }
1089 1100
1090 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct 1101 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct
1091 // semantic correlation between arguments and invocation. 1102 // semantic correlation between arguments and invocation.
1092 List<ir.Primitive> translateStaticArguments(ast.NodeList nodeList, 1103 CallStructure translateStaticArguments(ast.NodeList nodeList,
1093 Element element, 1104 Element element,
1094 CallStructure callStructure) { 1105 CallStructure callStructure,
1095 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); 1106 List<ir.Primitive> arguments) {
1107 assert(arguments.isEmpty);
1108 for (ast.Node node in nodeList) arguments.add(visit(node));
1096 return normalizeStaticArguments(callStructure, element, arguments); 1109 return normalizeStaticArguments(callStructure, element, arguments);
1097 } 1110 }
1098 1111
1099 ir.Primitive translateCallInvoke(ir.Primitive target, 1112 ir.Primitive translateCallInvoke(ir.Primitive target,
1100 ast.NodeList arguments, 1113 ast.NodeList arguments,
1101 CallStructure callStructure, 1114 CallStructure callStructure,
1102 SourceInformation sourceInformation) { 1115 SourceInformation sourceInformation) {
1103 1116 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1104 return irBuilder.buildCallInvocation(target, callStructure, 1117 CallStructure normalizedCallStructure = translateDynamicArguments(
1105 translateDynamicArguments(arguments, callStructure), 1118 arguments, callStructure, normalizedArguments);
1119 return irBuilder.buildCallInvocation(target, normalizedCallStructure,
1120 normalizedArguments,
1106 sourceInformation: sourceInformation); 1121 sourceInformation: sourceInformation);
1107 } 1122 }
1108 1123
1109 @override 1124 @override
1110 ir.Primitive handleConstantInvoke( 1125 ir.Primitive handleConstantInvoke(
1111 ast.Send node, 1126 ast.Send node,
1112 ConstantExpression constant, 1127 ConstantExpression constant,
1113 ast.NodeList arguments, 1128 ast.NodeList arguments,
1114 CallStructure callStructure, 1129 CallStructure callStructure,
1115 _) { 1130 _) {
1116 ir.Primitive target = buildConstantExpression(constant, 1131 ir.Primitive target = buildConstantExpression(constant,
1117 sourceInformationBuilder.buildGet(node)); 1132 sourceInformationBuilder.buildGet(node));
1118 return translateCallInvoke(target, arguments, callStructure, 1133 return translateCallInvoke(target, arguments, callStructure,
1119 sourceInformationBuilder.buildCall(node, arguments)); 1134 sourceInformationBuilder.buildCall(node, arguments));
1120 } 1135 }
1121 1136
1122 @override 1137 @override
1123 ir.Primitive handleDynamicInvoke( 1138 ir.Primitive handleDynamicInvoke(
1124 ast.Send node, 1139 ast.Send node,
1125 ast.Node receiver, 1140 ast.Node receiver,
1126 ast.NodeList arguments, 1141 ast.NodeList arguments,
1127 Selector selector, 1142 Selector selector,
1128 _) { 1143 _) {
1144 ir.Primitive target = translateReceiver(receiver);
1145 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1146 CallStructure normalizedCallStructure = translateDynamicArguments(
1147 arguments, selector.callStructure, normalizedArguments);
1129 return irBuilder.buildDynamicInvocation( 1148 return irBuilder.buildDynamicInvocation(
1130 translateReceiver(receiver), selector, elements.getTypeMask(node), 1149 target,
1131 translateDynamicArguments(arguments, selector.callStructure), 1150 new Selector(selector.kind, selector.memberName,
1151 normalizedCallStructure),
1152 elements.getTypeMask(node),
1153 normalizedArguments,
1132 sourceInformation: 1154 sourceInformation:
1133 sourceInformationBuilder.buildCall(node, node.selector)); 1155 sourceInformationBuilder.buildCall(node, node.selector));
1134 } 1156 }
1135 1157
1136 @override 1158 @override
1137 ir.Primitive visitIfNotNullDynamicPropertyInvoke( 1159 ir.Primitive visitIfNotNullDynamicPropertyInvoke(
1138 ast.Send node, 1160 ast.Send node,
1139 ast.Node receiver, 1161 ast.Node receiver,
1140 ast.NodeList arguments, 1162 ast.NodeList arguments,
1141 Selector selector, 1163 Selector selector,
1142 _) { 1164 _) {
1143 ir.Primitive target = visit(receiver); 1165 ir.Primitive target = visit(receiver);
1144 return irBuilder.buildIfNotNullSend( 1166 return irBuilder.buildIfNotNullSend(
1145 target, 1167 target,
1146 nested(() => irBuilder.buildDynamicInvocation( 1168 nested(() {
1147 target, selector, elements.getTypeMask(node), 1169 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1148 translateDynamicArguments(arguments, selector.callStructure)))); 1170 CallStructure normalizedCallStructure = translateDynamicArguments(
1171 arguments, selector.callStructure, normalizedArguments);
1172 return irBuilder.buildDynamicInvocation(
1173 target,
1174 new Selector(selector.kind, selector.memberName,
1175 normalizedCallStructure),
1176 elements.getTypeMask(node),
1177 normalizedArguments);
1178 }));
1149 } 1179 }
1150 1180
1151 ir.Primitive handleLocalInvoke( 1181 ir.Primitive handleLocalInvoke(
1152 ast.Send node, 1182 ast.Send node,
1153 LocalElement element, 1183 LocalElement element,
1154 ast.NodeList arguments, 1184 ast.NodeList arguments,
1155 CallStructure callStructure, 1185 CallStructure callStructure,
1156 _) { 1186 _) {
1157 return irBuilder.buildLocalVariableInvocation(element, callStructure, 1187 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1158 translateDynamicArguments(arguments, callStructure), 1188 CallStructure normalizedCallStructure = translateDynamicArguments(
1189 arguments, callStructure, normalizedArguments);
1190 return irBuilder.buildLocalVariableInvocation(
1191 element,
1192 normalizedCallStructure,
1193 normalizedArguments,
1159 callSourceInformation: 1194 callSourceInformation:
1160 sourceInformationBuilder.buildCall(node, arguments)); 1195 sourceInformationBuilder.buildCall(node, arguments));
1161 } 1196 }
1162 1197
1163 @override 1198 @override
1164 ir.Primitive visitLocalFunctionInvoke( 1199 ir.Primitive visitLocalFunctionInvoke(
1165 ast.Send node, 1200 ast.Send node,
1166 LocalFunctionElement function, 1201 LocalFunctionElement function,
1167 ast.NodeList arguments, 1202 ast.NodeList arguments,
1168 CallStructure callStructure, 1203 CallStructure callStructure,
1169 _) { 1204 _) {
1170 return irBuilder.buildLocalFunctionInvocation(function, callStructure, 1205 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1171 translateDynamicArguments(arguments, callStructure), 1206 CallStructure normalizedCallStructure = translateDynamicArguments(
1207 arguments, callStructure, normalizedArguments);
1208 return irBuilder.buildLocalFunctionInvocation(
1209 function,
1210 normalizedCallStructure,
1211 normalizedArguments,
1172 sourceInformationBuilder.buildCall(node, arguments)); 1212 sourceInformationBuilder.buildCall(node, arguments));
1173 } 1213 }
1174 1214
1175 @override 1215 @override
1176 ir.Primitive handleStaticFieldGet(ast.Send node, FieldElement field, _) { 1216 ir.Primitive handleStaticFieldGet(ast.Send node, FieldElement field, _) {
1177 return buildStaticFieldGet(field, sourceInformationBuilder.buildGet(node)); 1217 return buildStaticFieldGet(field, sourceInformationBuilder.buildGet(node));
1178 } 1218 }
1179 1219
1180 @override 1220 @override
1181 ir.Primitive handleStaticFieldInvoke( 1221 ir.Primitive handleStaticFieldInvoke(
1182 ast.Send node, 1222 ast.Send node,
1183 FieldElement field, 1223 FieldElement field,
1184 ast.NodeList arguments, 1224 ast.NodeList arguments,
1185 CallStructure callStructure, 1225 CallStructure callStructure,
1186 _) { 1226 _) {
1187 SourceInformation src = sourceInformationBuilder.buildGet(node); 1227 SourceInformation src = sourceInformationBuilder.buildGet(node);
1188 ir.Primitive target = buildStaticFieldGet(field, src); 1228 ir.Primitive target = buildStaticFieldGet(field, src);
1189 return irBuilder.buildCallInvocation(target, 1229 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1190 callStructure, 1230 CallStructure normalizedCallStructure = translateDynamicArguments(
1191 translateDynamicArguments(arguments, callStructure), 1231 arguments, callStructure, normalizedArguments);
1232 return irBuilder.buildCallInvocation(
1233 target,
1234 normalizedCallStructure,
1235 normalizedArguments,
1192 sourceInformation: 1236 sourceInformation:
1193 sourceInformationBuilder.buildCall(node, arguments)); 1237 sourceInformationBuilder.buildCall(node, arguments));
1194 } 1238 }
1195 1239
1196 @override 1240 @override
1197 ir.Primitive handleStaticFunctionInvoke( 1241 ir.Primitive handleStaticFunctionInvoke(
1198 ast.Send node, 1242 ast.Send node,
1199 MethodElement function, 1243 MethodElement function,
1200 ast.NodeList arguments, 1244 ast.NodeList arguments,
1201 CallStructure callStructure, 1245 CallStructure callStructure,
(...skipping 12 matching lines...) Expand all
1214 1258
1215 @override 1259 @override
1216 ir.Primitive handleStaticGetterInvoke( 1260 ir.Primitive handleStaticGetterInvoke(
1217 ast.Send node, 1261 ast.Send node,
1218 FunctionElement getter, 1262 FunctionElement getter,
1219 ast.NodeList arguments, 1263 ast.NodeList arguments,
1220 CallStructure callStructure, 1264 CallStructure callStructure,
1221 _) { 1265 _) {
1222 ir.Primitive target = irBuilder.buildStaticGetterGet( 1266 ir.Primitive target = irBuilder.buildStaticGetterGet(
1223 getter, sourceInformationBuilder.buildGet(node)); 1267 getter, sourceInformationBuilder.buildGet(node));
1224 return irBuilder.buildCallInvocation(target, 1268 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1225 callStructure, 1269 CallStructure normalizedCallStructure = translateDynamicArguments(
1226 translateDynamicArguments(arguments, callStructure), 1270 arguments, callStructure, normalizedArguments);
1271 return irBuilder.buildCallInvocation(
1272 target,
1273 normalizedCallStructure,
1274 normalizedArguments,
1227 sourceInformation: 1275 sourceInformation:
1228 sourceInformationBuilder.buildCall(node, arguments)); 1276 sourceInformationBuilder.buildCall(node, arguments));
1229 } 1277 }
1230 1278
1231 @override 1279 @override
1232 ir.Primitive visitSuperFieldInvoke( 1280 ir.Primitive visitSuperFieldInvoke(
1233 ast.Send node, 1281 ast.Send node,
1234 FieldElement field, 1282 FieldElement field,
1235 ast.NodeList arguments, 1283 ast.NodeList arguments,
1236 CallStructure callStructure, 1284 CallStructure callStructure,
1237 _) { 1285 _) {
1238 ir.Primitive target = irBuilder.buildSuperFieldGet(field); 1286 ir.Primitive target = irBuilder.buildSuperFieldGet(field);
1239 return irBuilder.buildCallInvocation(target, 1287 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1240 callStructure, 1288 CallStructure normalizedCallStructure = translateDynamicArguments(
1241 translateDynamicArguments(arguments, callStructure), 1289 arguments, callStructure, normalizedArguments);
1290 return irBuilder.buildCallInvocation(
1291 target,
1292 normalizedCallStructure,
1293 normalizedArguments,
1242 sourceInformation: 1294 sourceInformation:
1243 sourceInformationBuilder.buildCall(node, arguments)); 1295 sourceInformationBuilder.buildCall(node, arguments));
1244 } 1296 }
1245 1297
1246 @override 1298 @override
1247 ir.Primitive visitSuperGetterInvoke( 1299 ir.Primitive visitSuperGetterInvoke(
1248 ast.Send node, 1300 ast.Send node,
1249 FunctionElement getter, 1301 FunctionElement getter,
1250 ast.NodeList arguments, 1302 ast.NodeList arguments,
1251 CallStructure callStructure, 1303 CallStructure callStructure,
1252 _) { 1304 _) {
1253 ir.Primitive target = irBuilder.buildSuperGetterGet( 1305 ir.Primitive target = irBuilder.buildSuperGetterGet(
1254 getter, sourceInformationBuilder.buildGet(node)); 1306 getter, sourceInformationBuilder.buildGet(node));
1255 return irBuilder.buildCallInvocation(target, 1307 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1256 callStructure, 1308 CallStructure normalizedCallStructure = translateDynamicArguments(
1257 translateDynamicArguments(arguments, callStructure), 1309 arguments, callStructure, normalizedArguments);
1310 return irBuilder.buildCallInvocation(
1311 target,
1312 normalizedCallStructure,
1313 normalizedArguments,
1258 sourceInformation: 1314 sourceInformation:
1259 sourceInformationBuilder.buildCall(node, arguments)); 1315 sourceInformationBuilder.buildCall(node, arguments));
1260 } 1316 }
1261 1317
1262 @override 1318 @override
1263 ir.Primitive visitSuperMethodInvoke( 1319 ir.Primitive visitSuperMethodInvoke(
1264 ast.Send node, 1320 ast.Send node,
1265 MethodElement method, 1321 MethodElement method,
1266 ast.NodeList arguments, 1322 ast.NodeList arguments,
1267 CallStructure callStructure, 1323 CallStructure callStructure,
1268 _) { 1324 _) {
1269 return irBuilder.buildSuperMethodInvocation(method, callStructure, 1325 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1270 translateDynamicArguments(arguments, callStructure), 1326 CallStructure normalizedCallStructure = translateDynamicArguments(
1327 arguments, callStructure, normalizedArguments);
1328 return irBuilder.buildSuperMethodInvocation(
1329 method,
1330 normalizedCallStructure,
1331 normalizedArguments,
1271 sourceInformation: 1332 sourceInformation:
1272 sourceInformationBuilder.buildCall(node, node.selector)); 1333 sourceInformationBuilder.buildCall(node, node.selector));
1273 } 1334 }
1274 1335
1275 @override 1336 @override
1276 ir.Primitive visitSuperMethodIncompatibleInvoke( 1337 ir.Primitive visitSuperMethodIncompatibleInvoke(
1277 ast.Send node, 1338 ast.Send node,
1278 MethodElement method, 1339 MethodElement method,
1279 ast.NodeList arguments, 1340 ast.NodeList arguments,
1280 CallStructure callStructure, _) { 1341 CallStructure callStructure, _) {
1342 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1343 translateDynamicArguments(arguments, callStructure, normalizedArguments);
1281 return buildInstanceNoSuchMethod( 1344 return buildInstanceNoSuchMethod(
1282 elements.getSelector(node), 1345 elements.getSelector(node),
Kevin Millikin (Google) 2015/12/02 15:45:31 It's not obvious whether this selector should matc
Johnni Winther 2015/12/03 12:15:42 We should. Create the new selector by: CallStruct
Kevin Millikin (Google) 2015/12/09 12:49:13 Done.
1283 elements.getTypeMask(node), 1346 elements.getTypeMask(node),
1284 translateDynamicArguments(arguments, callStructure)); 1347 normalizedArguments);
1285 } 1348 }
1286 1349
1287 @override 1350 @override
1288 ir.Primitive visitUnresolvedSuperInvoke( 1351 ir.Primitive visitUnresolvedSuperInvoke(
1289 ast.Send node, 1352 ast.Send node,
1290 Element element, 1353 Element element,
1291 ast.NodeList arguments, 1354 ast.NodeList arguments,
1292 Selector selector, _) { 1355 Selector selector, _) {
1356 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
1357 translateDynamicArguments(arguments, selector.callStructure,
1358 normalizedArguments);
1293 return buildInstanceNoSuchMethod( 1359 return buildInstanceNoSuchMethod(
1294 elements.getSelector(node), 1360 elements.getSelector(node),
Kevin Millikin (Google) 2015/12/02 15:45:31 It's not obvious whether this selector should matc
Johnni Winther 2015/12/03 12:15:42 Also here. Obtain the member name from `elements.g
Kevin Millikin (Google) 2015/12/09 12:49:13 Done.
1295 elements.getTypeMask(node), 1361 elements.getTypeMask(node),
1296 translateDynamicArguments(arguments, selector.callStructure)); 1362 normalizedArguments);
1297 } 1363 }
1298 1364
1299 @override 1365 @override
1300 ir.Primitive visitThisInvoke( 1366 ir.Primitive visitThisInvoke(
1301 ast.Send node, 1367 ast.Send node,
1302 ast.NodeList arguments, 1368 ast.NodeList arguments,
1303 CallStructure callStructure, 1369 CallStructure callStructure,
1304 _) { 1370 _) {
1305 return translateCallInvoke( 1371 return translateCallInvoke(
1306 irBuilder.buildThis(), 1372 irBuilder.buildThis(),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 1430
1365 Selector operatorSelector = 1431 Selector operatorSelector =
1366 new Selector.binaryOperator(operator.selectorName); 1432 new Selector.binaryOperator(operator.selectorName);
1367 ir.Primitive rhsValue; 1433 ir.Primitive rhsValue;
1368 if (rhs.kind == CompoundKind.ASSIGNMENT) { 1434 if (rhs.kind == CompoundKind.ASSIGNMENT) {
1369 rhsValue = visit(rhs.rhs); 1435 rhsValue = visit(rhs.rhs);
1370 } else { 1436 } else {
1371 rhsValue = irBuilder.buildIntegerConstant(1); 1437 rhsValue = irBuilder.buildIntegerConstant(1);
1372 } 1438 }
1373 List<ir.Primitive> arguments = <ir.Primitive>[rhsValue]; 1439 List<ir.Primitive> arguments = <ir.Primitive>[rhsValue];
1374 arguments = normalizeDynamicArguments( 1440 CallStructure callStructure =
1375 operatorSelector.callStructure, arguments); 1441 normalizeDynamicArguments(operatorSelector.callStructure, arguments);
1376 TypeMask operatorTypeMask = 1442 TypeMask operatorTypeMask =
1377 elements.getOperatorTypeMaskInComplexSendSet(node); 1443 elements.getOperatorTypeMaskInComplexSendSet(node);
1378 SourceInformation operatorSourceInformation = 1444 SourceInformation operatorSourceInformation =
1379 sourceInformationBuilder.buildCall(node, node.assignmentOperator); 1445 sourceInformationBuilder.buildCall(node, node.assignmentOperator);
1380 ir.Primitive result = irBuilder.buildDynamicInvocation( 1446 ir.Primitive result = irBuilder.buildDynamicInvocation(
1381 value, operatorSelector, operatorTypeMask, arguments, 1447 value,
1382 sourceInformation: operatorSourceInformation); 1448 new Selector(operatorSelector.kind, operatorSelector.memberName,
1449 callStructure),
1450 operatorTypeMask,
1451 arguments,
1452 sourceInformation: operatorSourceInformation);
1383 setValue(result); 1453 setValue(result);
1384 return rhs.kind == CompoundKind.POSTFIX ? value : result; 1454 return rhs.kind == CompoundKind.POSTFIX ? value : result;
1385 } 1455 }
1386 1456
1387 ir.Primitive translateSetIfNull( 1457 ir.Primitive translateSetIfNull(
1388 ast.SendSet node, 1458 ast.SendSet node,
1389 {ir.Primitive getValue(), 1459 {ir.Primitive getValue(),
1390 ast.Node rhs, 1460 ast.Node rhs,
1391 void setValue(ir.Primitive value)}) { 1461 void setValue(ir.Primitive value)}) {
1392 ir.Primitive value = getValue(); 1462 ir.Primitive value = getValue();
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 ast.Node index, 1921 ast.Node index,
1852 CompoundRhs rhs, 1922 CompoundRhs rhs,
1853 arg) { 1923 arg) {
1854 ir.Primitive target = visit(receiver); 1924 ir.Primitive target = visit(receiver);
1855 ir.Primitive indexValue = visit(index); 1925 ir.Primitive indexValue = visit(index);
1856 return translateCompounds( 1926 return translateCompounds(
1857 node, 1927 node,
1858 getValue: () { 1928 getValue: () {
1859 Selector selector = new Selector.index(); 1929 Selector selector = new Selector.index();
1860 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; 1930 List<ir.Primitive> arguments = <ir.Primitive>[indexValue];
1861 arguments = 1931 CallStructure callStructure =
1862 normalizeDynamicArguments(selector.callStructure, arguments); 1932 normalizeDynamicArguments(selector.callStructure, arguments);
1863 return irBuilder.buildDynamicInvocation( 1933 return irBuilder.buildDynamicInvocation(
1864 target, 1934 target,
1865 selector, 1935 new Selector(selector.kind, selector.memberName, callStructure),
1866 elements.getGetterTypeMaskInComplexSendSet(node), 1936 elements.getGetterTypeMaskInComplexSendSet(node),
1867 arguments, 1937 arguments,
1868 sourceInformation: 1938 sourceInformation:
1869 sourceInformationBuilder.buildCall(receiver, node)); 1939 sourceInformationBuilder.buildCall(receiver, node));
1870 }, 1940 },
1871 rhs: rhs, 1941 rhs: rhs,
1872 setValue: (ir.Primitive result) { 1942 setValue: (ir.Primitive result) {
1873 irBuilder.buildDynamicIndexSet( 1943 irBuilder.buildDynamicIndexSet(
1874 target, 1944 target,
1875 elements.getTypeMask(node), 1945 elements.getTypeMask(node),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 } 2074 }
2005 2075
2006 @override 2076 @override
2007 ir.Primitive visitUnresolvedConstructorInvoke( 2077 ir.Primitive visitUnresolvedConstructorInvoke(
2008 ast.NewExpression node, 2078 ast.NewExpression node,
2009 Element constructor, 2079 Element constructor,
2010 DartType type, 2080 DartType type,
2011 ast.NodeList arguments, 2081 ast.NodeList arguments,
2012 Selector selector, _) { 2082 Selector selector, _) {
2013 // If the class is there but the constructor is missing, it's an NSM error. 2083 // If the class is there but the constructor is missing, it's an NSM error.
2014 return buildStaticNoSuchMethod(selector, 2084 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
2015 translateDynamicArguments(arguments, selector.callStructure)); 2085 translateDynamicArguments(arguments, selector.callStructure,
2086 normalizedArguments);
2087 return buildStaticNoSuchMethod(selector, normalizedArguments);
Kevin Millikin (Google) 2015/12/02 15:45:31 This selector doesn't seem to matter because it lo
Johnni Winther 2015/12/03 12:15:42 Similar to the super-cases above. We should normal
Kevin Millikin (Google) 2015/12/09 12:49:13 Done.
2016 } 2088 }
2017 2089
2018 @override 2090 @override
2019 ir.Primitive visitConstructorIncompatibleInvoke( 2091 ir.Primitive visitConstructorIncompatibleInvoke(
2020 ast.NewExpression node, 2092 ast.NewExpression node,
2021 Element constructor, 2093 Element constructor,
2022 DartType type, 2094 DartType type,
2023 ast.NodeList arguments, 2095 ast.NodeList arguments,
2024 CallStructure callStructure, _) { 2096 CallStructure callStructure, _) {
2097 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
2098 translateDynamicArguments(arguments, callStructure, normalizedArguments);
2025 return buildStaticNoSuchMethod(elements.getSelector(node.send), 2099 return buildStaticNoSuchMethod(elements.getSelector(node.send),
Kevin Millikin (Google) 2015/12/02 15:45:31 It's not clear if this selector should match the n
2026 translateDynamicArguments(arguments, callStructure)); 2100 normalizedArguments);
2027 } 2101 }
2028 2102
2029 @override 2103 @override
2030 ir.Primitive visitUnresolvedGet( 2104 ir.Primitive visitUnresolvedGet(
2031 ast.Send node, 2105 ast.Send node,
2032 Element element, _) { 2106 Element element, _) {
2033 return buildStaticNoSuchMethod(elements.getSelector(node), []); 2107 return buildStaticNoSuchMethod(elements.getSelector(node), []);
Kevin Millikin (Google) 2015/12/02 15:45:31 It's not clear if this selector should match the n
2034 } 2108 }
2035 2109
2036 @override 2110 @override
2037 ir.Primitive visitUnresolvedInvoke( 2111 ir.Primitive visitUnresolvedInvoke(
2038 ast.Send node, 2112 ast.Send node,
2039 Element element, 2113 Element element,
2040 ast.NodeList arguments, 2114 ast.NodeList arguments,
2041 Selector selector, _) { 2115 Selector selector, _) {
2042 return buildStaticNoSuchMethod(elements.getSelector(node), 2116 return buildStaticNoSuchMethod(elements.getSelector(node),
Kevin Millikin (Google) 2015/12/02 15:45:31 It's not clear if this selector should match the n
2043 arguments.nodes.mapToList(visit)); 2117 arguments.nodes.mapToList(visit));
2044 } 2118 }
2045 2119
2046 @override 2120 @override
2047 ir.Primitive visitUnresolvedRedirectingFactoryConstructorInvoke( 2121 ir.Primitive visitUnresolvedRedirectingFactoryConstructorInvoke(
2048 ast.NewExpression node, 2122 ast.NewExpression node,
2049 ConstructorElement constructor, 2123 ConstructorElement constructor,
2050 InterfaceType type, 2124 InterfaceType type,
2051 ast.NodeList arguments, 2125 ast.NodeList arguments,
2052 CallStructure callStructure, _) { 2126 CallStructure callStructure, _) {
2053 String nameString = Elements.reconstructConstructorName(constructor); 2127 String nameString = Elements.reconstructConstructorName(constructor);
2054 Name name = new Name(nameString, constructor.library); 2128 Name name = new Name(nameString, constructor.library);
2129 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
2130 CallStructure normalizedCallStructure = translateDynamicArguments(
2131 arguments, callStructure, normalizedArguments);
2055 return buildStaticNoSuchMethod( 2132 return buildStaticNoSuchMethod(
Kevin Millikin (Google) 2015/12/02 15:45:31 It's not clear if this selector should match the n
2056 new Selector.call(name, callStructure), 2133 new Selector.call(name, normalizedCallStructure),
2057 translateDynamicArguments(arguments, callStructure)); 2134 normalizedArguments);
2058 } 2135 }
2059 2136
2060 @override 2137 @override
2061 ir.Primitive visitUnresolvedSet( 2138 ir.Primitive visitUnresolvedSet(
2062 ast.Send node, 2139 ast.Send node,
2063 Element element, 2140 Element element,
2064 ast.Node rhs, _) { 2141 ast.Node rhs, _) {
2065 return buildStaticNoSuchMethod(elements.getSelector(node), [visit(rhs)]); 2142 return buildStaticNoSuchMethod(elements.getSelector(node), [visit(rhs)]);
Kevin Millikin (Google) 2015/12/02 15:45:31 It's not clear if this selector should match the n
2066 } 2143 }
2067 2144
2068 @override 2145 @override
2069 ir.Primitive visitUnresolvedSuperIndex( 2146 ir.Primitive visitUnresolvedSuperIndex(
2070 ast.Send node, 2147 ast.Send node,
2071 Element function, 2148 Element function,
2072 ast.Node index, _) { 2149 ast.Node index, _) {
2073 // Assume the index getter is missing. 2150 // Assume the index getter is missing.
2074 return buildInstanceNoSuchMethod( 2151 return buildInstanceNoSuchMethod(
2075 new Selector.index(), elements.getTypeMask(node), [visit(index)]); 2152 new Selector.index(), elements.getTypeMask(node), [visit(index)]);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2268 elements.getTypeMask(node), 2345 elements.getTypeMask(node),
2269 []); 2346 []);
2270 } 2347 }
2271 2348
2272 @override 2349 @override
2273 ir.Primitive visitSuperSetterInvoke( 2350 ir.Primitive visitSuperSetterInvoke(
2274 ast.Send node, 2351 ast.Send node,
2275 SetterElement setter, 2352 SetterElement setter,
2276 ast.NodeList arguments, 2353 ast.NodeList arguments,
2277 CallStructure callStructure, _) { 2354 CallStructure callStructure, _) {
2278 List<ir.Primitive> args = 2355 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
2279 translateDynamicArguments(arguments, callStructure); 2356 CallStructure normalizedCallStructure = translateDynamicArguments(
2357 arguments, callStructure, normalizedArguments);
2280 return buildInstanceNoSuchMethod( 2358 return buildInstanceNoSuchMethod(
2281 new Selector.call(setter.memberName, callStructure), 2359 new Selector.call(setter.memberName, normalizedCallStructure),
Kevin Millikin (Google) 2015/12/02 15:45:31 It's not obvious if this selector should match the
2282 elements.getTypeMask(node), 2360 elements.getTypeMask(node),
2283 args); 2361 normalizedArguments);
2284 } 2362 }
2285 2363
2286 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { 2364 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) {
2287 try { 2365 try {
2288 return action(); 2366 return action();
2289 } catch(e) { 2367 } catch(e) {
2290 if (e == ABORT_IRNODE_BUILDER) { 2368 if (e == ABORT_IRNODE_BUILDER) {
2291 return null; 2369 return null;
2292 } 2370 }
2293 rethrow; 2371 rethrow;
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 3278
3201 /// Creates a primitive for the default value of [parameter]. 3279 /// Creates a primitive for the default value of [parameter].
3202 ir.Primitive translateDefaultValue(ParameterElement parameter) { 3280 ir.Primitive translateDefaultValue(ParameterElement parameter) {
3203 if (parameter.initializer == null) { 3281 if (parameter.initializer == null) {
3204 return irBuilder.buildNullConstant(); 3282 return irBuilder.buildNullConstant();
3205 } else { 3283 } else {
3206 return inlineConstant(parameter.executableContext, parameter.initializer); 3284 return inlineConstant(parameter.executableContext, parameter.initializer);
3207 } 3285 }
3208 } 3286 }
3209 3287
3210 /// Inserts default arguments and normalizes order of named arguments. 3288 CallStructure normalizeStaticArguments(CallStructure callStructure,
3211 List<ir.Primitive> normalizeStaticArguments( 3289 FunctionElement target,
3212 CallStructure callStructure, 3290 List<ir.Primitive> arguments) {
3213 FunctionElement target,
3214 List<ir.Primitive> arguments) {
3215 target = target.implementation; 3291 target = target.implementation;
3216 FunctionSignature signature = target.functionSignature; 3292 FunctionSignature signature = target.functionSignature;
3217 if (!signature.optionalParametersAreNamed && 3293 if (!signature.optionalParametersAreNamed &&
3218 signature.parameterCount == arguments.length) { 3294 signature.parameterCount == arguments.length) {
3219 // Optimization: don't copy the argument list for trivial cases. 3295 return callStructure;
3220 return arguments;
3221 } 3296 }
3222 3297
3223 List<ir.Primitive> result = <ir.Primitive>[];
3224 int i = 0;
3225 signature.forEachRequiredParameter((ParameterElement element) {
3226 result.add(arguments[i]);
3227 ++i;
3228 });
3229
3230 if (!signature.optionalParametersAreNamed) { 3298 if (!signature.optionalParametersAreNamed) {
3299 int i = signature.requiredParameterCount;
3231 signature.forEachOptionalParameter((ParameterElement element) { 3300 signature.forEachOptionalParameter((ParameterElement element) {
3232 if (i < arguments.length) { 3301 if (i < callStructure.positionalArgumentCount) {
3233 result.add(arguments[i]);
3234 ++i; 3302 ++i;
3235 } else { 3303 } else {
3236 result.add(translateDefaultValue(element)); 3304 arguments.add(translateDefaultValue(element));
3237 } 3305 }
3238 }); 3306 });
3239 } else { 3307 return new CallStructure(signature.parameterCount);
3240 int offset = i;
3241 // Iterate over the optional parameters of the signature, and try to
3242 // find them in [compiledNamedArguments]. If found, we use the
3243 // value in the temporary list, otherwise the default value.
3244 signature.orderedOptionalParameters.forEach((ParameterElement element) {
3245 int nameIndex = callStructure.namedArguments.indexOf(element.name);
3246 if (nameIndex != -1) {
3247 int translatedIndex = offset + nameIndex;
3248 result.add(arguments[translatedIndex]);
3249 } else {
3250 result.add(translateDefaultValue(element));
3251 }
3252 });
3253 } 3308 }
3254 return result; 3309
3310 int offset = signature.requiredParameterCount;
3311 List<ir.Primitive> namedArguments = arguments.sublist(offset);
3312 arguments.length = offset;
3313 List<String> normalizedNames = <String>[];
3314 // Iterate over the optional parameters of the signature, and try to
3315 // find them in the callStructure's named arguments. If found, we use the
3316 // value in the temporary list, otherwise the default value.
3317 signature.orderedOptionalParameters.forEach((ParameterElement element) {
3318 int nameIndex = callStructure.namedArguments.indexOf(element.name);
3319 arguments.add(nameIndex == -1 ? translateDefaultValue(element)
3320 : namedArguments[nameIndex]);
3321 normalizedNames.add(element.name);
3322 });
3323 return new CallStructure(signature.parameterCount, normalizedNames);
3255 } 3324 }
3256 3325
3257 /// Normalizes order of named arguments. 3326 CallStructure normalizeDynamicArguments(CallStructure callStructure,
3258 List<ir.Primitive> normalizeDynamicArguments( 3327 List<ir.Primitive> arguments) {
3259 CallStructure callStructure,
3260 List<ir.Primitive> arguments) {
3261 assert(arguments.length == callStructure.argumentCount); 3328 assert(arguments.length == callStructure.argumentCount);
3262 // Optimization: don't copy the argument list for trivial cases. 3329 if (callStructure.namedArguments.isEmpty) return callStructure;
3263 if (callStructure.namedArguments.isEmpty) return arguments; 3330 int destinationIndex = callStructure.positionalArgumentCount;
3264 List<ir.Primitive> result = <ir.Primitive>[]; 3331 List<ir.Primitive> namedArguments = arguments.sublist(destinationIndex);
3265 for (int i=0; i < callStructure.positionalArgumentCount; i++) { 3332 for (String argName in callStructure.getOrderedNamedArguments()) {
3266 result.add(arguments[i]); 3333 int sourceIndex = callStructure.namedArguments.indexOf(argName);
3334 arguments[destinationIndex++] = namedArguments[sourceIndex];
3267 } 3335 }
3268 for (String argName in callStructure.getOrderedNamedArguments()) { 3336 return new CallStructure(callStructure.argumentCount,
3269 int nameIndex = callStructure.namedArguments.indexOf(argName); 3337 callStructure.getOrderedNamedArguments());
3270 int translatedIndex = callStructure.positionalArgumentCount + nameIndex;
3271 result.add(arguments[translatedIndex]);
3272 }
3273 return result;
3274 } 3338 }
3275 3339
3276 @override 3340 @override
3277 ir.Primitive handleConstructorInvoke( 3341 ir.Primitive handleConstructorInvoke(
3278 ast.NewExpression node, 3342 ast.NewExpression node,
3279 ConstructorElement constructor, 3343 ConstructorElement constructor,
3280 DartType type, 3344 DartType type,
3281 ast.NodeList arguments, 3345 ast.NodeList arguments,
3282 CallStructure callStructure, 3346 CallStructure callStructure,
3283 _) { 3347 _) {
3284 List<ir.Primitive> arguments = 3348 List<ir.Primitive> arguments = node.send.arguments.mapToList(visit);
3285 node.send.arguments.mapToList(visit, growable:false);
3286 // Use default values from the effective target, not the immediate target. 3349 // Use default values from the effective target, not the immediate target.
3287 ConstructorElement target = constructor.effectiveTarget; 3350 ConstructorElement target = constructor.effectiveTarget;
3288 arguments = normalizeStaticArguments(callStructure, target, arguments); 3351 CallStructure normalizedCallStructure =
3352 normalizeStaticArguments(callStructure, target, arguments);
3289 TypeMask allocationSiteType; 3353 TypeMask allocationSiteType;
3290 ast.Node send = node.send; 3354 ast.Node send = node.send;
3291 if (Elements.isFixedListConstructorCall(constructor, send, compiler) || 3355 if (Elements.isFixedListConstructorCall(constructor, send, compiler) ||
3292 Elements.isGrowableListConstructorCall(constructor, send, compiler) || 3356 Elements.isGrowableListConstructorCall(constructor, send, compiler) ||
3293 Elements.isFilledListConstructorCall(constructor, send, compiler) || 3357 Elements.isFilledListConstructorCall(constructor, send, compiler) ||
3294 Elements.isConstructorOfTypedArraySubclass(constructor, compiler)) { 3358 Elements.isConstructorOfTypedArraySubclass(constructor, compiler)) {
3295 allocationSiteType = getAllocationSiteType(send); 3359 allocationSiteType = getAllocationSiteType(send);
3296 } 3360 }
3297 return irBuilder.buildConstructorInvocation( 3361 return irBuilder.buildConstructorInvocation(
3298 target, 3362 target,
3299 callStructure, 3363 normalizedCallStructure,
3300 constructor.computeEffectiveTargetType(type), 3364 constructor.computeEffectiveTargetType(type),
3301 arguments, 3365 arguments,
3302 sourceInformationBuilder.buildNew(node), 3366 sourceInformationBuilder.buildNew(node),
3303 allocationSiteType: allocationSiteType); 3367 allocationSiteType: allocationSiteType);
3304 } 3368 }
3305 3369
3306 @override 3370 @override
3307 ir.Primitive buildStaticNoSuchMethod(Selector selector, 3371 ir.Primitive buildStaticNoSuchMethod(Selector selector,
3308 List<ir.Primitive> arguments) { 3372 List<ir.Primitive> arguments) {
3309 Element thrower = backend.helpers.throwNoSuchMethod; 3373 Element thrower = backend.helpers.throwNoSuchMethod;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3389 } 3453 }
3390 3454
3391 /// Call a helper method from the isolate library. The isolate library uses 3455 /// Call a helper method from the isolate library. The isolate library uses
3392 /// its own isolate structure, that encapsulates dart2js's isolate. 3456 /// its own isolate structure, that encapsulates dart2js's isolate.
3393 ir.Primitive buildIsolateHelperInvocation(Element element, 3457 ir.Primitive buildIsolateHelperInvocation(Element element,
3394 CallStructure callStructure) { 3458 CallStructure callStructure) {
3395 if (element == null) { 3459 if (element == null) {
3396 reporter.internalError(node, 3460 reporter.internalError(node,
3397 'Isolate library and compiler mismatch.'); 3461 'Isolate library and compiler mismatch.');
3398 } 3462 }
3399 List<ir.Primitive> arguments = translateStaticArguments(argumentList, 3463 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
3400 element, callStructure); 3464 CallStructure normalizedCallStructure = translateStaticArguments(
3401 return irBuilder.buildStaticFunctionInvocation(element, 3465 argumentList, element, callStructure, normalizedArguments);
3402 callStructure, arguments, 3466 return irBuilder.buildStaticFunctionInvocation(
3467 element,
3468 normalizedCallStructure,
3469 normalizedArguments,
3403 sourceInformation: 3470 sourceInformation:
3404 sourceInformationBuilder.buildCall(node, node.selector)); 3471 sourceInformationBuilder.buildCall(node, node.selector));
3405 } 3472 }
3406 3473
3407 /// Lookup the value of the enum described by [node]. 3474 /// Lookup the value of the enum described by [node].
3408 getEnumValue(ast.Node node, EnumClassElement enumClass, List values) { 3475 getEnumValue(ast.Node node, EnumClassElement enumClass, List values) {
3409 Element element = elements[node]; 3476 Element element = elements[node];
3410 if (element is! FieldElement || element.enclosingClass != enumClass) { 3477 if (element is! FieldElement || element.enclosingClass != enumClass) {
3411 internalError(node, 'expected a JsBuiltin enum value'); 3478 internalError(node, 'expected a JsBuiltin enum value');
3412 } 3479 }
3413 3480
3414 int index = enumClass.enumValues.indexOf(element); 3481 int index = enumClass.enumValues.indexOf(element);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
3590 3657
3591 @override 3658 @override
3592 ir.Primitive handleStaticFunctionInvoke(ast.Send node, 3659 ir.Primitive handleStaticFunctionInvoke(ast.Send node,
3593 MethodElement function, 3660 MethodElement function,
3594 ast.NodeList argumentList, 3661 ast.NodeList argumentList,
3595 CallStructure callStructure, 3662 CallStructure callStructure,
3596 _) { 3663 _) {
3597 if (compiler.backend.isForeign(function)) { 3664 if (compiler.backend.isForeign(function)) {
3598 return handleForeignCode(node, function, argumentList, callStructure); 3665 return handleForeignCode(node, function, argumentList, callStructure);
3599 } else { 3666 } else {
3600 return irBuilder.buildStaticFunctionInvocation(function, callStructure, 3667 List<ir.Primitive> normalizedArguments = <ir.Primitive>[];
3601 translateStaticArguments(argumentList, function, callStructure), 3668 CallStructure normalizedCallStructure = translateStaticArguments(
3669 argumentList, function, callStructure, normalizedArguments);
3670 return irBuilder.buildStaticFunctionInvocation(function,
3671 normalizedCallStructure,
3672 normalizedArguments,
3602 sourceInformation: 3673 sourceInformation:
3603 sourceInformationBuilder.buildCall(node, node.selector)); 3674 sourceInformationBuilder.buildCall(node, node.selector));
3604 } 3675 }
3605 } 3676 }
3606 } 3677 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/cps_ir/cps_ir_nodes_sexpr.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698