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 '../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 Loading... |
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 Loading... |
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 = |
320 arguments); | 320 normalizeStaticArguments(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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 assert(irBuilder.isOpen); | 712 assert(irBuilder.isOpen); |
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 = argumentsNode.nodes.mapToList(visit); |
723 arguments = normalizeDynamicArguments(callStructure, arguments); | 723 callStructure = normalizeDynamicArguments(callStructure, arguments); |
724 return irBuilder.buildCallInvocation( | 724 return irBuilder.buildCallInvocation(receiver, callStructure, arguments, |
725 receiver, callStructure, arguments, | |
726 sourceInformation: | 725 sourceInformation: |
727 sourceInformationBuilder.buildCall(node, argumentsNode)); | 726 sourceInformationBuilder.buildCall(node, argumentsNode)); |
728 } | 727 } |
729 | 728 |
730 /// Returns `true` if [node] is a super call. | 729 /// Returns `true` if [node] is a super call. |
731 // TODO(johnniwinther): Remove the need for this. | 730 // TODO(johnniwinther): Remove the need for this. |
732 bool isSuperCall(ast.Send node) { | 731 bool isSuperCall(ast.Send node) { |
733 return node != null && node.receiver != null && node.receiver.isSuper(); | 732 return node != null && node.receiver != null && node.receiver.isSuper(); |
734 } | 733 } |
735 | 734 |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 ir.Primitive value = visit(expression); | 942 ir.Primitive value = visit(expression); |
944 ir.Primitive check = irBuilder.buildTypeOperator( | 943 ir.Primitive check = irBuilder.buildTypeOperator( |
945 value, type, isTypeTest: true); | 944 value, type, isTypeTest: true); |
946 return irBuilder.buildNegation(check); | 945 return irBuilder.buildNegation(check); |
947 } | 946 } |
948 | 947 |
949 ir.Primitive translateBinary(ast.Send node, | 948 ir.Primitive translateBinary(ast.Send node, |
950 ast.Node left, | 949 ast.Node left, |
951 op.BinaryOperator operator, | 950 op.BinaryOperator operator, |
952 ast.Node right) { | 951 ast.Node right) { |
| 952 ir.Primitive receiver = visit(left); |
953 Selector selector = new Selector.binaryOperator(operator.selectorName); | 953 Selector selector = new Selector.binaryOperator(operator.selectorName); |
954 ir.Primitive receiver = visit(left); | |
955 List<ir.Primitive> arguments = <ir.Primitive>[visit(right)]; | 954 List<ir.Primitive> arguments = <ir.Primitive>[visit(right)]; |
956 arguments = normalizeDynamicArguments(selector.callStructure, arguments); | 955 CallStructure callStructure = |
| 956 normalizeDynamicArguments(selector.callStructure, arguments); |
957 return irBuilder.buildDynamicInvocation( | 957 return irBuilder.buildDynamicInvocation( |
958 receiver, selector, elements.getTypeMask(node), arguments, | 958 receiver, |
| 959 new Selector(selector.kind, selector.memberName, callStructure), |
| 960 elements.getTypeMask(node), |
| 961 arguments, |
959 sourceInformation: | 962 sourceInformation: |
960 sourceInformationBuilder.buildCall(node, node.selector)); | 963 sourceInformationBuilder.buildCall(node, node.selector)); |
961 } | 964 } |
962 | 965 |
963 @override | 966 @override |
964 ir.Primitive visitBinary(ast.Send node, | 967 ir.Primitive visitBinary(ast.Send node, |
965 ast.Node left, | 968 ast.Node left, |
966 op.BinaryOperator operator, | 969 op.BinaryOperator operator, |
967 ast.Node right, _) { | 970 ast.Node right, _) { |
968 return translateBinary(node, left, operator, right); | 971 return translateBinary(node, left, operator, right); |
969 } | 972 } |
970 | 973 |
971 @override | 974 @override |
972 ir.Primitive visitIndex(ast.Send node, | 975 ir.Primitive visitIndex(ast.Send node, |
973 ast.Node receiver, | 976 ast.Node receiver, |
974 ast.Node index, _) { | 977 ast.Node index, _) { |
| 978 ir.Primitive target = visit(receiver); |
975 Selector selector = new Selector.index(); | 979 Selector selector = new Selector.index(); |
976 ir.Primitive target = visit(receiver); | |
977 List<ir.Primitive> arguments = <ir.Primitive>[visit(index)]; | 980 List<ir.Primitive> arguments = <ir.Primitive>[visit(index)]; |
978 arguments = normalizeDynamicArguments(selector.callStructure, arguments); | 981 CallStructure callStructure = |
| 982 normalizeDynamicArguments(selector.callStructure, arguments); |
979 return irBuilder.buildDynamicInvocation( | 983 return irBuilder.buildDynamicInvocation( |
980 target, selector, elements.getTypeMask(node), arguments, | 984 target, |
| 985 new Selector(selector.kind, selector.memberName, callStructure), |
| 986 elements.getTypeMask(node), |
| 987 arguments, |
981 sourceInformation: | 988 sourceInformation: |
982 sourceInformationBuilder.buildCall(receiver, node.selector)); | 989 sourceInformationBuilder.buildCall(receiver, node.selector)); |
983 } | 990 } |
984 | 991 |
985 ir.Primitive translateSuperBinary(FunctionElement function, | 992 ir.Primitive translateSuperBinary(FunctionElement function, |
986 op.BinaryOperator operator, | 993 op.BinaryOperator operator, |
987 ast.Node argument) { | 994 ast.Node argument) { |
988 CallStructure callStructure = CallStructure.ONE_ARG; | |
989 List<ir.Primitive> arguments = <ir.Primitive>[visit(argument)]; | 995 List<ir.Primitive> arguments = <ir.Primitive>[visit(argument)]; |
990 arguments = normalizeDynamicArguments(callStructure, arguments); | 996 CallStructure callStructure = |
| 997 normalizeDynamicArguments(CallStructure.ONE_ARG, arguments); |
991 return irBuilder.buildSuperMethodInvocation( | 998 return irBuilder.buildSuperMethodInvocation( |
992 function, callStructure, arguments); | 999 function, callStructure, arguments); |
993 } | 1000 } |
994 | 1001 |
995 @override | 1002 @override |
996 ir.Primitive visitSuperBinary( | 1003 ir.Primitive visitSuperBinary( |
997 ast.Send node, | 1004 ast.Send node, |
998 FunctionElement function, | 1005 FunctionElement function, |
999 op.BinaryOperator operator, | 1006 op.BinaryOperator operator, |
1000 ast.Node argument, | 1007 ast.Node argument, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 ast.Send node, | 1081 ast.Send node, |
1075 op.UnaryOperator operator, | 1082 op.UnaryOperator operator, |
1076 FunctionElement function, | 1083 FunctionElement function, |
1077 _) { | 1084 _) { |
1078 return irBuilder.buildSuperMethodInvocation( | 1085 return irBuilder.buildSuperMethodInvocation( |
1079 function, CallStructure.NO_ARGS, const []); | 1086 function, CallStructure.NO_ARGS, const []); |
1080 } | 1087 } |
1081 | 1088 |
1082 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct | 1089 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct |
1083 // semantic correlation between arguments and invocation. | 1090 // semantic correlation between arguments and invocation. |
1084 List<ir.Primitive> translateDynamicArguments(ast.NodeList nodeList, | 1091 CallStructure translateDynamicArguments(ast.NodeList nodeList, |
1085 CallStructure callStructure) { | 1092 CallStructure callStructure, |
1086 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); | 1093 List<ir.Primitive> arguments) { |
| 1094 assert(arguments.isEmpty); |
| 1095 for (ast.Node node in nodeList) arguments.add(visit(node)); |
1087 return normalizeDynamicArguments(callStructure, arguments); | 1096 return normalizeDynamicArguments(callStructure, arguments); |
1088 } | 1097 } |
1089 | 1098 |
1090 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct | 1099 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct |
1091 // semantic correlation between arguments and invocation. | 1100 // semantic correlation between arguments and invocation. |
1092 List<ir.Primitive> translateStaticArguments(ast.NodeList nodeList, | 1101 CallStructure translateStaticArguments(ast.NodeList nodeList, |
1093 Element element, | 1102 Element element, |
1094 CallStructure callStructure) { | 1103 CallStructure callStructure, |
1095 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); | 1104 List<ir.Primitive> arguments) { |
| 1105 assert(arguments.isEmpty); |
| 1106 for (ast.Node node in nodeList) arguments.add(visit(node)); |
1096 return normalizeStaticArguments(callStructure, element, arguments); | 1107 return normalizeStaticArguments(callStructure, element, arguments); |
1097 } | 1108 } |
1098 | 1109 |
1099 ir.Primitive translateCallInvoke(ir.Primitive target, | 1110 ir.Primitive translateCallInvoke(ir.Primitive target, |
1100 ast.NodeList arguments, | 1111 ast.NodeList argumentsNode, |
1101 CallStructure callStructure, | 1112 CallStructure callStructure, |
1102 SourceInformation sourceInformation) { | 1113 SourceInformation sourceInformation) { |
1103 | 1114 List<ir.Primitive> arguments = <ir.Primitive>[]; |
1104 return irBuilder.buildCallInvocation(target, callStructure, | 1115 callStructure = |
1105 translateDynamicArguments(arguments, callStructure), | 1116 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 1117 return irBuilder.buildCallInvocation(target, callStructure, arguments, |
1106 sourceInformation: sourceInformation); | 1118 sourceInformation: sourceInformation); |
1107 } | 1119 } |
1108 | 1120 |
1109 @override | 1121 @override |
1110 ir.Primitive handleConstantInvoke( | 1122 ir.Primitive handleConstantInvoke( |
1111 ast.Send node, | 1123 ast.Send node, |
1112 ConstantExpression constant, | 1124 ConstantExpression constant, |
1113 ast.NodeList arguments, | 1125 ast.NodeList arguments, |
1114 CallStructure callStructure, | 1126 CallStructure callStructure, |
1115 _) { | 1127 _) { |
1116 ir.Primitive target = buildConstantExpression(constant, | 1128 ir.Primitive target = buildConstantExpression(constant, |
1117 sourceInformationBuilder.buildGet(node)); | 1129 sourceInformationBuilder.buildGet(node)); |
1118 return translateCallInvoke(target, arguments, callStructure, | 1130 return translateCallInvoke(target, arguments, callStructure, |
1119 sourceInformationBuilder.buildCall(node, arguments)); | 1131 sourceInformationBuilder.buildCall(node, arguments)); |
1120 } | 1132 } |
1121 | 1133 |
1122 @override | 1134 @override |
1123 ir.Primitive handleDynamicInvoke( | 1135 ir.Primitive handleDynamicInvoke( |
1124 ast.Send node, | 1136 ast.Send node, |
1125 ast.Node receiver, | 1137 ast.Node receiver, |
1126 ast.NodeList arguments, | 1138 ast.NodeList argumentsNode, |
1127 Selector selector, | 1139 Selector selector, |
1128 _) { | 1140 _) { |
| 1141 ir.Primitive target = translateReceiver(receiver); |
| 1142 List<ir.Primitive> arguments = <ir.Primitive>[]; |
| 1143 CallStructure callStructure = translateDynamicArguments( |
| 1144 argumentsNode, selector.callStructure, arguments); |
1129 return irBuilder.buildDynamicInvocation( | 1145 return irBuilder.buildDynamicInvocation( |
1130 translateReceiver(receiver), selector, elements.getTypeMask(node), | 1146 target, |
1131 translateDynamicArguments(arguments, selector.callStructure), | 1147 new Selector(selector.kind, selector.memberName, callStructure), |
| 1148 elements.getTypeMask(node), |
| 1149 arguments, |
1132 sourceInformation: | 1150 sourceInformation: |
1133 sourceInformationBuilder.buildCall(node, node.selector)); | 1151 sourceInformationBuilder.buildCall(node, node.selector)); |
1134 } | 1152 } |
1135 | 1153 |
1136 @override | 1154 @override |
1137 ir.Primitive visitIfNotNullDynamicPropertyInvoke( | 1155 ir.Primitive visitIfNotNullDynamicPropertyInvoke( |
1138 ast.Send node, | 1156 ast.Send node, |
1139 ast.Node receiver, | 1157 ast.Node receiver, |
1140 ast.NodeList arguments, | 1158 ast.NodeList argumentsNode, |
1141 Selector selector, | 1159 Selector selector, |
1142 _) { | 1160 _) { |
1143 ir.Primitive target = visit(receiver); | 1161 ir.Primitive target = visit(receiver); |
1144 return irBuilder.buildIfNotNullSend( | 1162 return irBuilder.buildIfNotNullSend( |
1145 target, | 1163 target, |
1146 nested(() => irBuilder.buildDynamicInvocation( | 1164 nested(() { |
1147 target, selector, elements.getTypeMask(node), | 1165 List<ir.Primitive> arguments = <ir.Primitive>[]; |
1148 translateDynamicArguments(arguments, selector.callStructure)))); | 1166 CallStructure callStructure = translateDynamicArguments( |
| 1167 argumentsNode, selector.callStructure, arguments); |
| 1168 return irBuilder.buildDynamicInvocation( |
| 1169 target, |
| 1170 new Selector(selector.kind, selector.memberName, callStructure), |
| 1171 elements.getTypeMask(node), |
| 1172 arguments); |
| 1173 })); |
1149 } | 1174 } |
1150 | 1175 |
1151 ir.Primitive handleLocalInvoke( | 1176 ir.Primitive handleLocalInvoke( |
1152 ast.Send node, | 1177 ast.Send node, |
1153 LocalElement element, | 1178 LocalElement element, |
1154 ast.NodeList arguments, | 1179 ast.NodeList argumentsNode, |
1155 CallStructure callStructure, | 1180 CallStructure callStructure, |
1156 _) { | 1181 _) { |
1157 return irBuilder.buildLocalVariableInvocation(element, callStructure, | 1182 List<ir.Primitive> arguments = <ir.Primitive>[]; |
1158 translateDynamicArguments(arguments, callStructure), | 1183 callStructure = |
| 1184 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 1185 return irBuilder.buildLocalVariableInvocation( |
| 1186 element, |
| 1187 callStructure, |
| 1188 arguments, |
1159 callSourceInformation: | 1189 callSourceInformation: |
1160 sourceInformationBuilder.buildCall(node, arguments)); | 1190 sourceInformationBuilder.buildCall(node, argumentsNode)); |
1161 } | 1191 } |
1162 | 1192 |
1163 @override | 1193 @override |
1164 ir.Primitive visitLocalFunctionInvoke( | 1194 ir.Primitive visitLocalFunctionInvoke( |
1165 ast.Send node, | 1195 ast.Send node, |
1166 LocalFunctionElement function, | 1196 LocalFunctionElement function, |
1167 ast.NodeList arguments, | 1197 ast.NodeList argumentsNode, |
1168 CallStructure callStructure, | 1198 CallStructure callStructure, |
1169 _) { | 1199 _) { |
1170 return irBuilder.buildLocalFunctionInvocation(function, callStructure, | 1200 List<ir.Primitive> arguments = <ir.Primitive>[]; |
1171 translateDynamicArguments(arguments, callStructure), | 1201 callStructure = |
1172 sourceInformationBuilder.buildCall(node, arguments)); | 1202 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 1203 return irBuilder.buildLocalFunctionInvocation( |
| 1204 function, |
| 1205 callStructure, |
| 1206 arguments, |
| 1207 sourceInformationBuilder.buildCall(node, argumentsNode)); |
1173 } | 1208 } |
1174 | 1209 |
1175 @override | 1210 @override |
1176 ir.Primitive handleStaticFieldGet(ast.Send node, FieldElement field, _) { | 1211 ir.Primitive handleStaticFieldGet(ast.Send node, FieldElement field, _) { |
1177 return buildStaticFieldGet(field, sourceInformationBuilder.buildGet(node)); | 1212 return buildStaticFieldGet(field, sourceInformationBuilder.buildGet(node)); |
1178 } | 1213 } |
1179 | 1214 |
1180 @override | 1215 @override |
1181 ir.Primitive handleStaticFieldInvoke( | 1216 ir.Primitive handleStaticFieldInvoke( |
1182 ast.Send node, | 1217 ast.Send node, |
1183 FieldElement field, | 1218 FieldElement field, |
1184 ast.NodeList arguments, | 1219 ast.NodeList argumentsNode, |
1185 CallStructure callStructure, | 1220 CallStructure callStructure, |
1186 _) { | 1221 _) { |
1187 SourceInformation src = sourceInformationBuilder.buildGet(node); | 1222 SourceInformation src = sourceInformationBuilder.buildGet(node); |
1188 ir.Primitive target = buildStaticFieldGet(field, src); | 1223 ir.Primitive target = buildStaticFieldGet(field, src); |
1189 return irBuilder.buildCallInvocation(target, | 1224 List<ir.Primitive> arguments = <ir.Primitive>[]; |
| 1225 callStructure = |
| 1226 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 1227 return irBuilder.buildCallInvocation( |
| 1228 target, |
1190 callStructure, | 1229 callStructure, |
1191 translateDynamicArguments(arguments, callStructure), | 1230 arguments, |
1192 sourceInformation: | 1231 sourceInformation: |
1193 sourceInformationBuilder.buildCall(node, arguments)); | 1232 sourceInformationBuilder.buildCall(node, argumentsNode)); |
1194 } | 1233 } |
1195 | 1234 |
1196 @override | 1235 @override |
1197 ir.Primitive handleStaticFunctionInvoke( | 1236 ir.Primitive handleStaticFunctionInvoke( |
1198 ast.Send node, | 1237 ast.Send node, |
1199 MethodElement function, | 1238 MethodElement function, |
1200 ast.NodeList arguments, | 1239 ast.NodeList arguments, |
1201 CallStructure callStructure, | 1240 CallStructure callStructure, |
1202 _); | 1241 _); |
1203 | 1242 |
1204 @override | 1243 @override |
1205 ir.Primitive handleStaticFunctionIncompatibleInvoke( | 1244 ir.Primitive handleStaticFunctionIncompatibleInvoke( |
1206 ast.Send node, | 1245 ast.Send node, |
1207 MethodElement function, | 1246 MethodElement function, |
1208 ast.NodeList arguments, | 1247 ast.NodeList arguments, |
1209 CallStructure callStructure, _) { | 1248 CallStructure callStructure, _) { |
1210 return buildStaticNoSuchMethod( | 1249 return buildStaticNoSuchMethod( |
1211 elements.getSelector(node), | 1250 elements.getSelector(node), |
1212 arguments.nodes.mapToList(visit)); | 1251 arguments.nodes.mapToList(visit)); |
1213 } | 1252 } |
1214 | 1253 |
1215 @override | 1254 @override |
1216 ir.Primitive handleStaticGetterInvoke( | 1255 ir.Primitive handleStaticGetterInvoke( |
1217 ast.Send node, | 1256 ast.Send node, |
1218 FunctionElement getter, | 1257 FunctionElement getter, |
1219 ast.NodeList arguments, | 1258 ast.NodeList argumentsNode, |
1220 CallStructure callStructure, | 1259 CallStructure callStructure, |
1221 _) { | 1260 _) { |
1222 ir.Primitive target = irBuilder.buildStaticGetterGet( | 1261 ir.Primitive target = irBuilder.buildStaticGetterGet(getter, |
1223 getter, sourceInformationBuilder.buildGet(node)); | 1262 sourceInformationBuilder.buildGet(node)); |
1224 return irBuilder.buildCallInvocation(target, | 1263 List<ir.Primitive> arguments = <ir.Primitive>[]; |
| 1264 callStructure = |
| 1265 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 1266 return irBuilder.buildCallInvocation( |
| 1267 target, |
1225 callStructure, | 1268 callStructure, |
1226 translateDynamicArguments(arguments, callStructure), | 1269 arguments, |
1227 sourceInformation: | 1270 sourceInformation: |
1228 sourceInformationBuilder.buildCall(node, arguments)); | 1271 sourceInformationBuilder.buildCall(node, argumentsNode)); |
1229 } | 1272 } |
1230 | 1273 |
1231 @override | 1274 @override |
1232 ir.Primitive visitSuperFieldInvoke( | 1275 ir.Primitive visitSuperFieldInvoke( |
1233 ast.Send node, | 1276 ast.Send node, |
1234 FieldElement field, | 1277 FieldElement field, |
1235 ast.NodeList arguments, | 1278 ast.NodeList argumentsNode, |
1236 CallStructure callStructure, | 1279 CallStructure callStructure, |
1237 _) { | 1280 _) { |
1238 ir.Primitive target = irBuilder.buildSuperFieldGet(field); | 1281 ir.Primitive target = irBuilder.buildSuperFieldGet(field); |
1239 return irBuilder.buildCallInvocation(target, | 1282 List<ir.Primitive> arguments = <ir.Primitive>[]; |
| 1283 callStructure = |
| 1284 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 1285 return irBuilder.buildCallInvocation( |
| 1286 target, |
1240 callStructure, | 1287 callStructure, |
1241 translateDynamicArguments(arguments, callStructure), | 1288 arguments, |
1242 sourceInformation: | 1289 sourceInformation: |
1243 sourceInformationBuilder.buildCall(node, arguments)); | 1290 sourceInformationBuilder.buildCall(node, argumentsNode)); |
1244 } | 1291 } |
1245 | 1292 |
1246 @override | 1293 @override |
1247 ir.Primitive visitSuperGetterInvoke( | 1294 ir.Primitive visitSuperGetterInvoke( |
1248 ast.Send node, | 1295 ast.Send node, |
1249 FunctionElement getter, | 1296 FunctionElement getter, |
1250 ast.NodeList arguments, | 1297 ast.NodeList argumentsNode, |
1251 CallStructure callStructure, | 1298 CallStructure callStructure, |
1252 _) { | 1299 _) { |
1253 ir.Primitive target = irBuilder.buildSuperGetterGet( | 1300 ir.Primitive target = irBuilder.buildSuperGetterGet(getter, |
1254 getter, sourceInformationBuilder.buildGet(node)); | 1301 sourceInformationBuilder.buildGet(node)); |
1255 return irBuilder.buildCallInvocation(target, | 1302 List<ir.Primitive> arguments = <ir.Primitive>[]; |
| 1303 callStructure = |
| 1304 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 1305 return irBuilder.buildCallInvocation( |
| 1306 target, |
1256 callStructure, | 1307 callStructure, |
1257 translateDynamicArguments(arguments, callStructure), | 1308 arguments, |
1258 sourceInformation: | 1309 sourceInformation: |
1259 sourceInformationBuilder.buildCall(node, arguments)); | 1310 sourceInformationBuilder.buildCall(node, argumentsNode)); |
1260 } | 1311 } |
1261 | 1312 |
1262 @override | 1313 @override |
1263 ir.Primitive visitSuperMethodInvoke( | 1314 ir.Primitive visitSuperMethodInvoke( |
1264 ast.Send node, | 1315 ast.Send node, |
1265 MethodElement method, | 1316 MethodElement method, |
1266 ast.NodeList arguments, | 1317 ast.NodeList argumentsNode, |
1267 CallStructure callStructure, | 1318 CallStructure callStructure, |
1268 _) { | 1319 _) { |
1269 return irBuilder.buildSuperMethodInvocation(method, callStructure, | 1320 List<ir.Primitive> arguments = <ir.Primitive>[]; |
1270 translateDynamicArguments(arguments, callStructure), | 1321 callStructure = |
| 1322 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 1323 return irBuilder.buildSuperMethodInvocation( |
| 1324 method, |
| 1325 callStructure, |
| 1326 arguments, |
1271 sourceInformation: | 1327 sourceInformation: |
1272 sourceInformationBuilder.buildCall(node, node.selector)); | 1328 sourceInformationBuilder.buildCall(node, node.selector)); |
1273 } | 1329 } |
1274 | 1330 |
1275 @override | 1331 @override |
1276 ir.Primitive visitSuperMethodIncompatibleInvoke( | 1332 ir.Primitive visitSuperMethodIncompatibleInvoke( |
1277 ast.Send node, | 1333 ast.Send node, |
1278 MethodElement method, | 1334 MethodElement method, |
1279 ast.NodeList arguments, | 1335 ast.NodeList arguments, |
1280 CallStructure callStructure, _) { | 1336 CallStructure callStructure, _) { |
| 1337 List<ir.Primitive> normalizedArguments = <ir.Primitive>[]; |
| 1338 CallStructure normalizedCallStructure = |
| 1339 translateDynamicArguments(arguments, callStructure, normalizedArguments); |
1281 return buildInstanceNoSuchMethod( | 1340 return buildInstanceNoSuchMethod( |
1282 elements.getSelector(node), | 1341 new Selector.call(method.memberName, normalizedCallStructure), |
1283 elements.getTypeMask(node), | 1342 elements.getTypeMask(node), |
1284 translateDynamicArguments(arguments, callStructure)); | 1343 normalizedArguments); |
1285 } | 1344 } |
1286 | 1345 |
1287 @override | 1346 @override |
1288 ir.Primitive visitUnresolvedSuperInvoke( | 1347 ir.Primitive visitUnresolvedSuperInvoke( |
1289 ast.Send node, | 1348 ast.Send node, |
1290 Element element, | 1349 Element element, |
1291 ast.NodeList arguments, | 1350 ast.NodeList argumentsNode, |
1292 Selector selector, _) { | 1351 Selector selector, _) { |
| 1352 List<ir.Primitive> arguments = <ir.Primitive>[]; |
| 1353 CallStructure callStructure = translateDynamicArguments( |
| 1354 argumentsNode, selector.callStructure, arguments); |
| 1355 // TODO(johnniwinther): Supply a member name to the visit function instead |
| 1356 // of looking it up in elements. |
1293 return buildInstanceNoSuchMethod( | 1357 return buildInstanceNoSuchMethod( |
1294 elements.getSelector(node), | 1358 new Selector.call(elements.getSelector(node).memberName, callStructure), |
1295 elements.getTypeMask(node), | 1359 elements.getTypeMask(node), |
1296 translateDynamicArguments(arguments, selector.callStructure)); | 1360 arguments); |
1297 } | 1361 } |
1298 | 1362 |
1299 @override | 1363 @override |
1300 ir.Primitive visitThisInvoke( | 1364 ir.Primitive visitThisInvoke( |
1301 ast.Send node, | 1365 ast.Send node, |
1302 ast.NodeList arguments, | 1366 ast.NodeList arguments, |
1303 CallStructure callStructure, | 1367 CallStructure callStructure, |
1304 _) { | 1368 _) { |
1305 return translateCallInvoke( | 1369 return translateCallInvoke( |
1306 irBuilder.buildThis(), | 1370 irBuilder.buildThis(), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 | 1428 |
1365 Selector operatorSelector = | 1429 Selector operatorSelector = |
1366 new Selector.binaryOperator(operator.selectorName); | 1430 new Selector.binaryOperator(operator.selectorName); |
1367 ir.Primitive rhsValue; | 1431 ir.Primitive rhsValue; |
1368 if (rhs.kind == CompoundKind.ASSIGNMENT) { | 1432 if (rhs.kind == CompoundKind.ASSIGNMENT) { |
1369 rhsValue = visit(rhs.rhs); | 1433 rhsValue = visit(rhs.rhs); |
1370 } else { | 1434 } else { |
1371 rhsValue = irBuilder.buildIntegerConstant(1); | 1435 rhsValue = irBuilder.buildIntegerConstant(1); |
1372 } | 1436 } |
1373 List<ir.Primitive> arguments = <ir.Primitive>[rhsValue]; | 1437 List<ir.Primitive> arguments = <ir.Primitive>[rhsValue]; |
1374 arguments = normalizeDynamicArguments( | 1438 CallStructure callStructure = |
1375 operatorSelector.callStructure, arguments); | 1439 normalizeDynamicArguments(operatorSelector.callStructure, arguments); |
1376 TypeMask operatorTypeMask = | 1440 TypeMask operatorTypeMask = |
1377 elements.getOperatorTypeMaskInComplexSendSet(node); | 1441 elements.getOperatorTypeMaskInComplexSendSet(node); |
1378 SourceInformation operatorSourceInformation = | 1442 SourceInformation operatorSourceInformation = |
1379 sourceInformationBuilder.buildCall(node, node.assignmentOperator); | 1443 sourceInformationBuilder.buildCall(node, node.assignmentOperator); |
1380 ir.Primitive result = irBuilder.buildDynamicInvocation( | 1444 ir.Primitive result = irBuilder.buildDynamicInvocation( |
1381 value, operatorSelector, operatorTypeMask, arguments, | 1445 value, |
1382 sourceInformation: operatorSourceInformation); | 1446 new Selector(operatorSelector.kind, operatorSelector.memberName, |
| 1447 callStructure), |
| 1448 operatorTypeMask, |
| 1449 arguments, |
| 1450 sourceInformation: operatorSourceInformation); |
1383 setValue(result); | 1451 setValue(result); |
1384 return rhs.kind == CompoundKind.POSTFIX ? value : result; | 1452 return rhs.kind == CompoundKind.POSTFIX ? value : result; |
1385 } | 1453 } |
1386 | 1454 |
1387 ir.Primitive translateSetIfNull( | 1455 ir.Primitive translateSetIfNull( |
1388 ast.SendSet node, | 1456 ast.SendSet node, |
1389 {ir.Primitive getValue(), | 1457 {ir.Primitive getValue(), |
1390 ast.Node rhs, | 1458 ast.Node rhs, |
1391 void setValue(ir.Primitive value)}) { | 1459 void setValue(ir.Primitive value)}) { |
1392 ir.Primitive value = getValue(); | 1460 ir.Primitive value = getValue(); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 ast.Node index, | 1919 ast.Node index, |
1852 CompoundRhs rhs, | 1920 CompoundRhs rhs, |
1853 arg) { | 1921 arg) { |
1854 ir.Primitive target = visit(receiver); | 1922 ir.Primitive target = visit(receiver); |
1855 ir.Primitive indexValue = visit(index); | 1923 ir.Primitive indexValue = visit(index); |
1856 return translateCompounds( | 1924 return translateCompounds( |
1857 node, | 1925 node, |
1858 getValue: () { | 1926 getValue: () { |
1859 Selector selector = new Selector.index(); | 1927 Selector selector = new Selector.index(); |
1860 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; | 1928 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; |
1861 arguments = | 1929 CallStructure callStructure = |
1862 normalizeDynamicArguments(selector.callStructure, arguments); | 1930 normalizeDynamicArguments(selector.callStructure, arguments); |
1863 return irBuilder.buildDynamicInvocation( | 1931 return irBuilder.buildDynamicInvocation( |
1864 target, | 1932 target, |
1865 selector, | 1933 new Selector(selector.kind, selector.memberName, callStructure), |
1866 elements.getGetterTypeMaskInComplexSendSet(node), | 1934 elements.getGetterTypeMaskInComplexSendSet(node), |
1867 arguments, | 1935 arguments, |
1868 sourceInformation: | 1936 sourceInformation: |
1869 sourceInformationBuilder.buildCall(receiver, node)); | 1937 sourceInformationBuilder.buildCall(receiver, node)); |
1870 }, | 1938 }, |
1871 rhs: rhs, | 1939 rhs: rhs, |
1872 setValue: (ir.Primitive result) { | 1940 setValue: (ir.Primitive result) { |
1873 irBuilder.buildDynamicIndexSet( | 1941 irBuilder.buildDynamicIndexSet( |
1874 target, | 1942 target, |
1875 elements.getTypeMask(node), | 1943 elements.getTypeMask(node), |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2001 Selector selector, _) { | 2069 Selector selector, _) { |
2002 // If the class is missing it's a runtime error. | 2070 // If the class is missing it's a runtime error. |
2003 return buildRuntimeError("Unresolved class: '${element.name}'"); | 2071 return buildRuntimeError("Unresolved class: '${element.name}'"); |
2004 } | 2072 } |
2005 | 2073 |
2006 @override | 2074 @override |
2007 ir.Primitive visitUnresolvedConstructorInvoke( | 2075 ir.Primitive visitUnresolvedConstructorInvoke( |
2008 ast.NewExpression node, | 2076 ast.NewExpression node, |
2009 Element constructor, | 2077 Element constructor, |
2010 DartType type, | 2078 DartType type, |
2011 ast.NodeList arguments, | 2079 ast.NodeList argumentsNode, |
2012 Selector selector, _) { | 2080 Selector selector, _) { |
2013 // If the class is there but the constructor is missing, it's an NSM error. | 2081 // If the class is there but the constructor is missing, it's an NSM error. |
2014 return buildStaticNoSuchMethod(selector, | 2082 List<ir.Primitive> arguments = <ir.Primitive>[]; |
2015 translateDynamicArguments(arguments, selector.callStructure)); | 2083 CallStructure callStructure = translateDynamicArguments( |
| 2084 argumentsNode, selector.callStructure, arguments); |
| 2085 return buildStaticNoSuchMethod( |
| 2086 new Selector(selector.kind, selector.memberName, callStructure), |
| 2087 arguments); |
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 ConstructorElement constructor, |
2022 DartType type, | 2094 DartType type, |
2023 ast.NodeList arguments, | 2095 ast.NodeList argumentsNode, |
2024 CallStructure callStructure, _) { | 2096 CallStructure callStructure, _) { |
2025 return buildStaticNoSuchMethod(elements.getSelector(node.send), | 2097 List<ir.Primitive> arguments = <ir.Primitive>[]; |
2026 translateDynamicArguments(arguments, callStructure)); | 2098 callStructure = |
| 2099 translateDynamicArguments(argumentsNode, callStructure, arguments); |
| 2100 return buildStaticNoSuchMethod( |
| 2101 new Selector.call(constructor.memberName, callStructure), arguments); |
2027 } | 2102 } |
2028 | 2103 |
2029 @override | 2104 @override |
2030 ir.Primitive visitUnresolvedGet( | 2105 ir.Primitive visitUnresolvedGet( |
2031 ast.Send node, | 2106 ast.Send node, |
2032 Element element, _) { | 2107 Element element, _) { |
2033 return buildStaticNoSuchMethod(elements.getSelector(node), []); | 2108 return buildStaticNoSuchMethod(elements.getSelector(node), []); |
2034 } | 2109 } |
2035 | 2110 |
2036 @override | 2111 @override |
2037 ir.Primitive visitUnresolvedInvoke( | 2112 ir.Primitive visitUnresolvedInvoke( |
2038 ast.Send node, | 2113 ast.Send node, |
2039 Element element, | 2114 Element element, |
2040 ast.NodeList arguments, | 2115 ast.NodeList arguments, |
2041 Selector selector, _) { | 2116 Selector selector, _) { |
2042 return buildStaticNoSuchMethod(elements.getSelector(node), | 2117 return buildStaticNoSuchMethod(elements.getSelector(node), |
2043 arguments.nodes.mapToList(visit)); | 2118 arguments.nodes.mapToList(visit)); |
2044 } | 2119 } |
2045 | 2120 |
2046 @override | 2121 @override |
2047 ir.Primitive visitUnresolvedRedirectingFactoryConstructorInvoke( | 2122 ir.Primitive visitUnresolvedRedirectingFactoryConstructorInvoke( |
2048 ast.NewExpression node, | 2123 ast.NewExpression node, |
2049 ConstructorElement constructor, | 2124 ConstructorElement constructor, |
2050 InterfaceType type, | 2125 InterfaceType type, |
2051 ast.NodeList arguments, | 2126 ast.NodeList argumentsNode, |
2052 CallStructure callStructure, _) { | 2127 CallStructure callStructure, _) { |
2053 String nameString = Elements.reconstructConstructorName(constructor); | 2128 String nameString = Elements.reconstructConstructorName(constructor); |
2054 Name name = new Name(nameString, constructor.library); | 2129 Name name = new Name(nameString, constructor.library); |
| 2130 List<ir.Primitive> arguments = <ir.Primitive>[]; |
| 2131 callStructure = |
| 2132 translateDynamicArguments(argumentsNode, callStructure, arguments); |
2055 return buildStaticNoSuchMethod( | 2133 return buildStaticNoSuchMethod( |
2056 new Selector.call(name, callStructure), | 2134 new Selector.call(name, callStructure), |
2057 translateDynamicArguments(arguments, callStructure)); | 2135 arguments); |
2058 } | 2136 } |
2059 | 2137 |
2060 @override | 2138 @override |
2061 ir.Primitive visitUnresolvedSet( | 2139 ir.Primitive visitUnresolvedSet( |
2062 ast.Send node, | 2140 ast.Send node, |
2063 Element element, | 2141 Element element, |
2064 ast.Node rhs, _) { | 2142 ast.Node rhs, _) { |
2065 return buildStaticNoSuchMethod(elements.getSelector(node), [visit(rhs)]); | 2143 return buildStaticNoSuchMethod(elements.getSelector(node), [visit(rhs)]); |
2066 } | 2144 } |
2067 | 2145 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2220 _) { | 2298 _) { |
2221 return buildStaticNoSuchMethod( | 2299 return buildStaticNoSuchMethod( |
2222 new Selector.getter(setter.memberName), | 2300 new Selector.getter(setter.memberName), |
2223 []); | 2301 []); |
2224 } | 2302 } |
2225 | 2303 |
2226 @override | 2304 @override |
2227 ir.Primitive handleStaticSetterInvoke( | 2305 ir.Primitive handleStaticSetterInvoke( |
2228 ast.Send node, | 2306 ast.Send node, |
2229 SetterElement setter, | 2307 SetterElement setter, |
2230 ast.NodeList arguments, | 2308 ast.NodeList argumentsNode, |
2231 CallStructure callStructure, _) { | 2309 CallStructure callStructure, _) { |
2232 // Translate as a method call. | 2310 // Translate as a method call. |
2233 List<ir.Primitive> args = arguments.nodes.mapToList(visit); | 2311 List<ir.Primitive> arguments = argumentsNode.nodes.mapToList(visit); |
2234 return buildStaticNoSuchMethod( | 2312 return buildStaticNoSuchMethod( |
2235 new Selector.call(setter.memberName, callStructure), | 2313 new Selector.call(setter.memberName, callStructure), |
2236 args); | 2314 arguments); |
2237 } | 2315 } |
2238 | 2316 |
2239 @override | 2317 @override |
2240 ir.Primitive visitSuperGetterSet( | 2318 ir.Primitive visitSuperGetterSet( |
2241 ast.SendSet node, | 2319 ast.SendSet node, |
2242 GetterElement getter, | 2320 GetterElement getter, |
2243 ast.Node rhs, | 2321 ast.Node rhs, |
2244 _) { | 2322 _) { |
2245 return buildInstanceNoSuchMethod( | 2323 return buildInstanceNoSuchMethod( |
2246 new Selector.setter(getter.memberName), | 2324 new Selector.setter(getter.memberName), |
(...skipping 20 matching lines...) Expand all Loading... |
2267 return buildInstanceNoSuchMethod( | 2345 return buildInstanceNoSuchMethod( |
2268 new Selector.setter(setter.memberName), | 2346 new Selector.setter(setter.memberName), |
2269 elements.getTypeMask(node), | 2347 elements.getTypeMask(node), |
2270 []); | 2348 []); |
2271 } | 2349 } |
2272 | 2350 |
2273 @override | 2351 @override |
2274 ir.Primitive visitSuperSetterInvoke( | 2352 ir.Primitive visitSuperSetterInvoke( |
2275 ast.Send node, | 2353 ast.Send node, |
2276 SetterElement setter, | 2354 SetterElement setter, |
2277 ast.NodeList arguments, | 2355 ast.NodeList argumentsNode, |
2278 CallStructure callStructure, _) { | 2356 CallStructure callStructure, _) { |
2279 List<ir.Primitive> args = | 2357 List<ir.Primitive> arguments = <ir.Primitive>[]; |
2280 translateDynamicArguments(arguments, callStructure); | 2358 callStructure = |
| 2359 translateDynamicArguments(argumentsNode, callStructure, arguments); |
2281 return buildInstanceNoSuchMethod( | 2360 return buildInstanceNoSuchMethod( |
2282 new Selector.call(setter.memberName, callStructure), | 2361 new Selector.call(setter.memberName, callStructure), |
2283 elements.getTypeMask(node), | 2362 elements.getTypeMask(node), |
2284 args); | 2363 arguments); |
2285 } | 2364 } |
2286 | 2365 |
2287 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { | 2366 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { |
2288 try { | 2367 try { |
2289 return action(); | 2368 return action(); |
2290 } catch(e) { | 2369 } catch(e) { |
2291 if (e == ABORT_IRNODE_BUILDER) { | 2370 if (e == ABORT_IRNODE_BUILDER) { |
2292 return null; | 2371 return null; |
2293 } | 2372 } |
2294 rethrow; | 2373 rethrow; |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3201 | 3280 |
3202 /// Creates a primitive for the default value of [parameter]. | 3281 /// Creates a primitive for the default value of [parameter]. |
3203 ir.Primitive translateDefaultValue(ParameterElement parameter) { | 3282 ir.Primitive translateDefaultValue(ParameterElement parameter) { |
3204 if (parameter.initializer == null) { | 3283 if (parameter.initializer == null) { |
3205 return irBuilder.buildNullConstant(); | 3284 return irBuilder.buildNullConstant(); |
3206 } else { | 3285 } else { |
3207 return inlineConstant(parameter.executableContext, parameter.initializer); | 3286 return inlineConstant(parameter.executableContext, parameter.initializer); |
3208 } | 3287 } |
3209 } | 3288 } |
3210 | 3289 |
3211 /// Inserts default arguments and normalizes order of named arguments. | 3290 CallStructure normalizeStaticArguments(CallStructure callStructure, |
3212 List<ir.Primitive> normalizeStaticArguments( | 3291 FunctionElement target, |
3213 CallStructure callStructure, | 3292 List<ir.Primitive> arguments) { |
3214 FunctionElement target, | |
3215 List<ir.Primitive> arguments) { | |
3216 target = target.implementation; | 3293 target = target.implementation; |
3217 FunctionSignature signature = target.functionSignature; | 3294 FunctionSignature signature = target.functionSignature; |
3218 if (!signature.optionalParametersAreNamed && | 3295 if (!signature.optionalParametersAreNamed && |
3219 signature.parameterCount == arguments.length) { | 3296 signature.parameterCount == arguments.length) { |
3220 // Optimization: don't copy the argument list for trivial cases. | 3297 return callStructure; |
3221 return arguments; | |
3222 } | 3298 } |
3223 | 3299 |
3224 List<ir.Primitive> result = <ir.Primitive>[]; | |
3225 int i = 0; | |
3226 signature.forEachRequiredParameter((ParameterElement element) { | |
3227 result.add(arguments[i]); | |
3228 ++i; | |
3229 }); | |
3230 | |
3231 if (!signature.optionalParametersAreNamed) { | 3300 if (!signature.optionalParametersAreNamed) { |
| 3301 int i = signature.requiredParameterCount; |
3232 signature.forEachOptionalParameter((ParameterElement element) { | 3302 signature.forEachOptionalParameter((ParameterElement element) { |
3233 if (i < arguments.length) { | 3303 if (i < callStructure.positionalArgumentCount) { |
3234 result.add(arguments[i]); | |
3235 ++i; | 3304 ++i; |
3236 } else { | 3305 } else { |
3237 result.add(translateDefaultValue(element)); | 3306 arguments.add(translateDefaultValue(element)); |
3238 } | 3307 } |
3239 }); | 3308 }); |
3240 } else { | 3309 return new CallStructure(signature.parameterCount); |
3241 int offset = i; | |
3242 // Iterate over the optional parameters of the signature, and try to | |
3243 // find them in [compiledNamedArguments]. If found, we use the | |
3244 // value in the temporary list, otherwise the default value. | |
3245 signature.orderedOptionalParameters.forEach((ParameterElement element) { | |
3246 int nameIndex = callStructure.namedArguments.indexOf(element.name); | |
3247 if (nameIndex != -1) { | |
3248 int translatedIndex = offset + nameIndex; | |
3249 result.add(arguments[translatedIndex]); | |
3250 } else { | |
3251 result.add(translateDefaultValue(element)); | |
3252 } | |
3253 }); | |
3254 } | 3310 } |
3255 return result; | 3311 |
| 3312 int offset = signature.requiredParameterCount; |
| 3313 List<ir.Primitive> namedArguments = arguments.sublist(offset); |
| 3314 arguments.length = offset; |
| 3315 List<String> normalizedNames = <String>[]; |
| 3316 // Iterate over the optional parameters of the signature, and try to |
| 3317 // find them in the callStructure's named arguments. If found, we use the |
| 3318 // value in the temporary list, otherwise the default value. |
| 3319 signature.orderedOptionalParameters.forEach((ParameterElement element) { |
| 3320 int nameIndex = callStructure.namedArguments.indexOf(element.name); |
| 3321 arguments.add(nameIndex == -1 ? translateDefaultValue(element) |
| 3322 : namedArguments[nameIndex]); |
| 3323 normalizedNames.add(element.name); |
| 3324 }); |
| 3325 return new CallStructure(signature.parameterCount, normalizedNames); |
3256 } | 3326 } |
3257 | 3327 |
3258 /// Normalizes order of named arguments. | 3328 CallStructure normalizeDynamicArguments(CallStructure callStructure, |
3259 List<ir.Primitive> normalizeDynamicArguments( | 3329 List<ir.Primitive> arguments) { |
3260 CallStructure callStructure, | |
3261 List<ir.Primitive> arguments) { | |
3262 assert(arguments.length == callStructure.argumentCount); | 3330 assert(arguments.length == callStructure.argumentCount); |
3263 // Optimization: don't copy the argument list for trivial cases. | 3331 if (callStructure.namedArguments.isEmpty) return callStructure; |
3264 if (callStructure.namedArguments.isEmpty) return arguments; | 3332 int destinationIndex = callStructure.positionalArgumentCount; |
3265 List<ir.Primitive> result = <ir.Primitive>[]; | 3333 List<ir.Primitive> namedArguments = arguments.sublist(destinationIndex); |
3266 for (int i=0; i < callStructure.positionalArgumentCount; i++) { | 3334 for (String argName in callStructure.getOrderedNamedArguments()) { |
3267 result.add(arguments[i]); | 3335 int sourceIndex = callStructure.namedArguments.indexOf(argName); |
| 3336 arguments[destinationIndex++] = namedArguments[sourceIndex]; |
3268 } | 3337 } |
3269 for (String argName in callStructure.getOrderedNamedArguments()) { | 3338 return new CallStructure(callStructure.argumentCount, |
3270 int nameIndex = callStructure.namedArguments.indexOf(argName); | 3339 callStructure.getOrderedNamedArguments()); |
3271 int translatedIndex = callStructure.positionalArgumentCount + nameIndex; | |
3272 result.add(arguments[translatedIndex]); | |
3273 } | |
3274 return result; | |
3275 } | 3340 } |
3276 | 3341 |
3277 @override | 3342 @override |
3278 ir.Primitive handleConstructorInvoke( | 3343 ir.Primitive handleConstructorInvoke( |
3279 ast.NewExpression node, | 3344 ast.NewExpression node, |
3280 ConstructorElement constructor, | 3345 ConstructorElement constructor, |
3281 DartType type, | 3346 DartType type, |
3282 ast.NodeList arguments, | 3347 ast.NodeList argumentsNode, |
3283 CallStructure callStructure, | 3348 CallStructure callStructure, |
3284 _) { | 3349 _) { |
3285 List<ir.Primitive> arguments = | 3350 List<ir.Primitive> arguments = argumentsNode.nodes.mapToList(visit); |
3286 node.send.arguments.mapToList(visit, growable:false); | |
3287 // Use default values from the effective target, not the immediate target. | 3351 // Use default values from the effective target, not the immediate target. |
3288 ConstructorElement target = constructor.effectiveTarget; | 3352 ConstructorElement target = constructor.effectiveTarget; |
3289 arguments = normalizeStaticArguments(callStructure, target, arguments); | 3353 callStructure = |
| 3354 normalizeStaticArguments(callStructure, target, arguments); |
3290 TypeMask allocationSiteType; | 3355 TypeMask allocationSiteType; |
3291 ast.Node send = node.send; | 3356 ast.Node send = node.send; |
3292 if (Elements.isFixedListConstructorCall(constructor, send, compiler) || | 3357 if (Elements.isFixedListConstructorCall(constructor, send, compiler) || |
3293 Elements.isGrowableListConstructorCall(constructor, send, compiler) || | 3358 Elements.isGrowableListConstructorCall(constructor, send, compiler) || |
3294 Elements.isFilledListConstructorCall(constructor, send, compiler) || | 3359 Elements.isFilledListConstructorCall(constructor, send, compiler) || |
3295 Elements.isConstructorOfTypedArraySubclass(constructor, compiler)) { | 3360 Elements.isConstructorOfTypedArraySubclass(constructor, compiler)) { |
3296 allocationSiteType = getAllocationSiteType(send); | 3361 allocationSiteType = getAllocationSiteType(send); |
3297 } | 3362 } |
3298 return irBuilder.buildConstructorInvocation( | 3363 return irBuilder.buildConstructorInvocation( |
3299 target, | 3364 target, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3390 } | 3455 } |
3391 | 3456 |
3392 /// Call a helper method from the isolate library. The isolate library uses | 3457 /// Call a helper method from the isolate library. The isolate library uses |
3393 /// its own isolate structure, that encapsulates dart2js's isolate. | 3458 /// its own isolate structure, that encapsulates dart2js's isolate. |
3394 ir.Primitive buildIsolateHelperInvocation(Element element, | 3459 ir.Primitive buildIsolateHelperInvocation(Element element, |
3395 CallStructure callStructure) { | 3460 CallStructure callStructure) { |
3396 if (element == null) { | 3461 if (element == null) { |
3397 reporter.internalError(node, | 3462 reporter.internalError(node, |
3398 'Isolate library and compiler mismatch.'); | 3463 'Isolate library and compiler mismatch.'); |
3399 } | 3464 } |
3400 List<ir.Primitive> arguments = translateStaticArguments(argumentList, | 3465 List<ir.Primitive> arguments = <ir.Primitive>[]; |
3401 element, callStructure); | 3466 callStructure = translateStaticArguments(argumentList, element, |
3402 return irBuilder.buildStaticFunctionInvocation(element, | 3467 callStructure, arguments); |
3403 callStructure, arguments, | 3468 return irBuilder.buildStaticFunctionInvocation( |
| 3469 element, |
| 3470 callStructure, |
| 3471 arguments, |
3404 sourceInformation: | 3472 sourceInformation: |
3405 sourceInformationBuilder.buildCall(node, node.selector)); | 3473 sourceInformationBuilder.buildCall(node, node.selector)); |
3406 } | 3474 } |
3407 | 3475 |
3408 /// Lookup the value of the enum described by [node]. | 3476 /// Lookup the value of the enum described by [node]. |
3409 getEnumValue(ast.Node node, EnumClassElement enumClass, List values) { | 3477 getEnumValue(ast.Node node, EnumClassElement enumClass, List values) { |
3410 Element element = elements[node]; | 3478 Element element = elements[node]; |
3411 if (element is! FieldElement || element.enclosingClass != enumClass) { | 3479 if (element is! FieldElement || element.enclosingClass != enumClass) { |
3412 internalError(node, 'expected a JsBuiltin enum value'); | 3480 internalError(node, 'expected a JsBuiltin enum value'); |
3413 } | 3481 } |
3414 | 3482 |
3415 int index = enumClass.enumValues.indexOf(element); | 3483 int index = enumClass.enumValues.indexOf(element); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3585 | 3653 |
3586 default: | 3654 default: |
3587 giveup(node, 'unplemented native construct: ${function.name}'); | 3655 giveup(node, 'unplemented native construct: ${function.name}'); |
3588 break; | 3656 break; |
3589 } | 3657 } |
3590 } | 3658 } |
3591 | 3659 |
3592 @override | 3660 @override |
3593 ir.Primitive handleStaticFunctionInvoke(ast.Send node, | 3661 ir.Primitive handleStaticFunctionInvoke(ast.Send node, |
3594 MethodElement function, | 3662 MethodElement function, |
3595 ast.NodeList argumentList, | 3663 ast.NodeList argumentsNode, |
3596 CallStructure callStructure, | 3664 CallStructure callStructure, |
3597 _) { | 3665 _) { |
3598 if (compiler.backend.isForeign(function)) { | 3666 if (compiler.backend.isForeign(function)) { |
3599 return handleForeignCode(node, function, argumentList, callStructure); | 3667 return handleForeignCode(node, function, argumentsNode, callStructure); |
3600 } else { | 3668 } else { |
3601 return irBuilder.buildStaticFunctionInvocation(function, callStructure, | 3669 List<ir.Primitive> arguments = <ir.Primitive>[]; |
3602 translateStaticArguments(argumentList, function, callStructure), | 3670 callStructure = translateStaticArguments(argumentsNode, function, |
| 3671 callStructure, arguments); |
| 3672 return irBuilder.buildStaticFunctionInvocation(function, |
| 3673 callStructure, |
| 3674 arguments, |
3603 sourceInformation: | 3675 sourceInformation: |
3604 sourceInformationBuilder.buildCall(node, node.selector)); | 3676 sourceInformationBuilder.buildCall(node, node.selector)); |
3605 } | 3677 } |
3606 } | 3678 } |
3607 } | 3679 } |
OLD | NEW |