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