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

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

Issue 1130813002: dart2js cps: Handle error cases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Whitelist unused API due to semantic visitor being WIP Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.ir_builder_task; 5 library dart2js.ir_builder_task;
6 6
7 import '../closure.dart' as closurelib; 7 import '../closure.dart' as closurelib;
8 import '../closure.dart' hide ClosureScope; 8 import '../closure.dart' hide ClosureScope;
9 import '../constants/expressions.dart'; 9 import '../constants/expressions.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 // TODO(johnniwinther): Implement [SemanticDeclVisitor]. 133 // TODO(johnniwinther): Implement [SemanticDeclVisitor].
134 abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive> 134 abstract class IrBuilderVisitor extends ast.Visitor<ir.Primitive>
135 with IrBuilderMixin<ast.Node>, 135 with IrBuilderMixin<ast.Node>,
136 SemanticSendResolvedMixin<ir.Primitive, dynamic>, 136 SemanticSendResolvedMixin<ir.Primitive, dynamic>,
137 SendResolverMixin, 137 SendResolverMixin,
138 BaseImplementationOfStaticsMixin<ir.Primitive, dynamic>, 138 BaseImplementationOfStaticsMixin<ir.Primitive, dynamic>,
139 BaseImplementationOfLocalsMixin<ir.Primitive, dynamic>, 139 BaseImplementationOfLocalsMixin<ir.Primitive, dynamic>,
140 BaseImplementationOfDynamicsMixin<ir.Primitive, dynamic>, 140 BaseImplementationOfDynamicsMixin<ir.Primitive, dynamic>,
141 BaseImplementationOfConstantsMixin<ir.Primitive, dynamic>, 141 BaseImplementationOfConstantsMixin<ir.Primitive, dynamic>,
142 BaseImplementationOfSuperIncDecsMixin<ir.Primitive, dynamic>, 142 BaseImplementationOfSuperIncDecsMixin<ir.Primitive, dynamic>,
143 BaseImplementationOfNewMixin<ir.Primitive, dynamic>, 143 BaseImplementationOfNewMixin<ir.Primitive, dynamic>
144 ErrorBulkMixin<ir.Primitive, dynamic>
145 implements SemanticSendVisitor<ir.Primitive, dynamic> { 144 implements SemanticSendVisitor<ir.Primitive, dynamic> {
146 final TreeElements elements; 145 final TreeElements elements;
147 final Compiler compiler; 146 final Compiler compiler;
148 final SourceInformationBuilder sourceInformationBuilder; 147 final SourceInformationBuilder sourceInformationBuilder;
149 148
150 /// A map from try statements in the source to analysis information about 149 /// A map from try statements in the source to analysis information about
151 /// them. 150 /// them.
152 /// 151 ///
153 /// The analysis information includes the set of variables that must be 152 /// The analysis information includes the set of variables that must be
154 /// copied into [ir.MutableVariable]s on entry to the try and copied out on 153 /// copied into [ir.MutableVariable]s on entry to the try and copied out on
(...skipping 16 matching lines...) Expand all
171 // assigned in the delimited subexpression to their reaching definition --- 170 // assigned in the delimited subexpression to their reaching definition ---
172 // that is, the definition in effect at the hole in 'current'. These are 171 // that is, the definition in effect at the hole in 'current'. These are
173 // used to determine if a join-point continuation needs to be passed 172 // used to determine if a join-point continuation needs to be passed
174 // arguments, and what the arguments are. 173 // arguments, and what the arguments are.
175 174
176 /// Construct a top-level visitor. 175 /// Construct a top-level visitor.
177 IrBuilderVisitor(this.elements, 176 IrBuilderVisitor(this.elements,
178 this.compiler, 177 this.compiler,
179 this.sourceInformationBuilder); 178 this.sourceInformationBuilder);
180 179
181 @override
182 bulkHandleNode(ast.Node node, String message, _) {
183 giveup(node, message.replaceFirst('#', '$node'));
184 }
185
186 String bailoutMessage = null; 180 String bailoutMessage = null;
187 181
188 @override 182 @override
189 ir.Primitive apply(ast.Node node, _) => node.accept(this); 183 ir.Primitive apply(ast.Node node, _) => node.accept(this);
190 184
191 @override 185 @override
192 SemanticSendVisitor get sendVisitor => this; 186 SemanticSendVisitor get sendVisitor => this;
193 187
194 /** 188 /**
195 * Builds the [ir.RootNode] for an executable element. In case the 189 * Builds the [ir.RootNode] for an executable element. In case the
(...skipping 20 matching lines...) Expand all
216 /// Normalizes the argument list of a dynamic invocation (i.e. where the 210 /// Normalizes the argument list of a dynamic invocation (i.e. where the
217 /// target element is unknown). 211 /// target element is unknown).
218 /// 212 ///
219 /// For the JS backend, normalizes order of named arguments. 213 /// For the JS backend, normalizes order of named arguments.
220 /// 214 ///
221 /// For the Dart backend, returns [arguments]. 215 /// For the Dart backend, returns [arguments].
222 List<ir.Primitive> normalizeDynamicArguments( 216 List<ir.Primitive> normalizeDynamicArguments(
223 CallStructure callStructure, 217 CallStructure callStructure,
224 List<ir.Primitive> arguments); 218 List<ir.Primitive> arguments);
225 219
220 /// Creates a [TypedSelector] variant of [newSelector] using the type of
221 /// [oldSelector], if available.
222 ///
223 /// This is needed to preserve inferred receiver types when creating new
224 /// selectors.
225 Selector useSelectorType(Selector newSelector, Selector oldSelector) {
226 // TODO(asgerf,johnniwinther): This works but it is brittle.
227 // We should decouple selectors from inferred receiver type masks.
228 // TODO(asgerf): Use this whenever we create a selector for a dynamic call.
229 if (oldSelector is TypedSelector) {
230 return new TypedSelector(oldSelector.mask, newSelector, compiler.world);
231 } else {
232 return newSelector;
233 }
234 }
235
236 /// Like [useSelectorType], except the original typed selector is obtained
237 /// from the [node].
238 Selector useSelectorTypeOfNode(Selector newSelector, ast.Send node) {
239 return useSelectorType(newSelector, elements.getSelector(node));
240 }
241
226 ir.RootNode _makeFunctionBody(FunctionElement element, 242 ir.RootNode _makeFunctionBody(FunctionElement element,
227 ast.FunctionExpression node) { 243 ast.FunctionExpression node) {
228 FunctionSignature signature = element.functionSignature; 244 FunctionSignature signature = element.functionSignature;
229 List<ParameterElement> parameters = []; 245 List<ParameterElement> parameters = [];
230 signature.orderedForEachParameter(parameters.add); 246 signature.orderedForEachParameter(parameters.add);
231 247
232 irBuilder.buildFunctionHeader(parameters, 248 irBuilder.buildFunctionHeader(parameters,
233 closureScope: getClosureScopeForNode(node), 249 closureScope: getClosureScopeForNode(node),
234 env: getClosureEnvironment()); 250 env: getClosureEnvironment());
235 251
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 node.entries.nodes.map((e) => e.key), 623 node.entries.nodes.map((e) => e.key),
608 node.entries.nodes.map((e) => e.value), 624 node.entries.nodes.map((e) => e.value),
609 build); 625 build);
610 } 626 }
611 627
612 ir.Primitive visitLiteralSymbol(ast.LiteralSymbol node) { 628 ir.Primitive visitLiteralSymbol(ast.LiteralSymbol node) {
613 assert(irBuilder.isOpen); 629 assert(irBuilder.isOpen);
614 return translateConstant(node); 630 return translateConstant(node);
615 } 631 }
616 632
617 ir.Primitive visitIdentifier(ast.Identifier node) {
618 // "this" is the only identifier that should be met by the visitor.
619 assert(node.isThis());
620 return irBuilder.buildThis();
621 }
622
623 ir.Primitive visitParenthesizedExpression( 633 ir.Primitive visitParenthesizedExpression(
624 ast.ParenthesizedExpression node) { 634 ast.ParenthesizedExpression node) {
625 assert(irBuilder.isOpen); 635 assert(irBuilder.isOpen);
626 return visit(node.expression); 636 return visit(node.expression);
627 } 637 }
628 638
629 // Stores the result of visiting a CascadeReceiver, so we can return it from 639 // Stores the result of visiting a CascadeReceiver, so we can return it from
630 // its enclosing Cascade. 640 // its enclosing Cascade.
631 ir.Primitive _currentCascadeReceiver; 641 ir.Primitive _currentCascadeReceiver;
632 642
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 798
789 @override 799 @override
790 ir.Primitive visitSuperMethodGet( 800 ir.Primitive visitSuperMethodGet(
791 ast.Send node, 801 ast.Send node,
792 MethodElement method, 802 MethodElement method,
793 _) { 803 _) {
794 return irBuilder.buildSuperMethodGet(method); 804 return irBuilder.buildSuperMethodGet(method);
795 } 805 }
796 806
797 @override 807 @override
798 ir.Primitive visitUnresolvedGet(
799 ast.Send node,
800 Element element,
801 _) {
802 return giveup(node, 'visitUnresolvedGet');
803 }
804
805 @override
806 ir.Primitive visitUnresolvedSuperGet( 808 ir.Primitive visitUnresolvedSuperGet(
807 ast.Send node, 809 ast.Send node,
808 Element element, 810 Element element, _) {
809 _) { 811 return buildInstanceNoSuchMethod(elements.getSelector(node), []);
810 return giveup(node, 'visitUnresolvedSuperGet');
811 } 812 }
812 813
813 @override 814 @override
814 ir.Primitive visitThisGet(ast.Identifier node, _) { 815 ir.Primitive visitThisGet(ast.Identifier node, _) {
816 if (irBuilder.state.thisParameter == null) {
817 // TODO(asgerf,johnniwinther): Should be in a visitInvalidThis method.
818 // 'this' in static context. Just translate to null.
819 assert(compiler.compilationFailed);
820 return irBuilder.buildNullConstant();
821 }
815 return irBuilder.buildThis(); 822 return irBuilder.buildThis();
816 } 823 }
817 824
818 ir.Primitive translateTypeVariableTypeLiteral(TypeVariableElement element) { 825 ir.Primitive translateTypeVariableTypeLiteral(TypeVariableElement element) {
819 return buildReifyTypeVariable(irBuilder.buildThis(), element.type); 826 return irBuilder.buildReifyTypeVariable(element.type);
820 } 827 }
821 828
822 @override 829 @override
823 ir.Primitive visitTypeVariableTypeLiteralGet(ast.Send node, 830 ir.Primitive visitTypeVariableTypeLiteralGet(ast.Send node,
824 TypeVariableElement element, _) { 831 TypeVariableElement element, _) {
825 return translateTypeVariableTypeLiteral(element); 832 return translateTypeVariableTypeLiteral(element);
826 } 833 }
827 834
828 ir.Primitive translateLogicalOperator(ast.Expression left, 835 ir.Primitive translateLogicalOperator(ast.Expression left,
829 ast.Expression right, 836 ast.Expression right,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 ir.Primitive visitSuperBinary( 933 ir.Primitive visitSuperBinary(
927 ast.Send node, 934 ast.Send node,
928 FunctionElement function, 935 FunctionElement function,
929 op.BinaryOperator operator, 936 op.BinaryOperator operator,
930 ast.Node argument, 937 ast.Node argument,
931 _) { 938 _) {
932 return translateSuperBinary(function, operator, argument); 939 return translateSuperBinary(function, operator, argument);
933 } 940 }
934 941
935 @override 942 @override
936 ir.Primitive visitUnresolvedSuperBinary(
937 ast.Send node,
938 Element element,
939 op.BinaryOperator operator,
940 ast.Node argument,
941 _) {
942 return giveup(node, 'visitUnresolvedSuperBinary');
943 }
944
945 @override
946 ir.Primitive visitSuperIndex( 943 ir.Primitive visitSuperIndex(
947 ast.Send node, 944 ast.Send node,
948 FunctionElement function, 945 FunctionElement function,
949 ast.Node index, 946 ast.Node index,
950 _) { 947 _) {
951 return irBuilder.buildSuperIndex(function, visit(index)); 948 return irBuilder.buildSuperIndex(function, visit(index));
952 } 949 }
953 950
954 @override 951 @override
955 ir.Primitive visitUnresolvedSuperIndex(
956 ast.Send node,
957 Element element,
958 ast.Node index,
959 _) {
960 return giveup(node, 'visitUnresolvedSuperIndex');
961 }
962
963 @override
964 ir.Primitive visitEquals( 952 ir.Primitive visitEquals(
965 ast.Send node, 953 ast.Send node,
966 ast.Node left, 954 ast.Node left,
967 ast.Node right, 955 ast.Node right,
968 _) { 956 _) {
969 return translateBinary(left, op.BinaryOperator.EQ, right); 957 return translateBinary(left, op.BinaryOperator.EQ, right);
970 } 958 }
971 959
972 @override 960 @override
973 ir.Primitive visitSuperEquals( 961 ir.Primitive visitSuperEquals(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 @override 1009 @override
1022 ir.Primitive visitSuperUnary( 1010 ir.Primitive visitSuperUnary(
1023 ast.Send node, 1011 ast.Send node,
1024 op.UnaryOperator operator, 1012 op.UnaryOperator operator,
1025 FunctionElement function, 1013 FunctionElement function,
1026 _) { 1014 _) {
1027 return irBuilder.buildSuperMethodInvocation( 1015 return irBuilder.buildSuperMethodInvocation(
1028 function, CallStructure.NO_ARGS, const []); 1016 function, CallStructure.NO_ARGS, const []);
1029 } 1017 }
1030 1018
1031 @override
1032 ir.Primitive visitUnresolvedSuperUnary(
1033 ast.Send node,
1034 op.UnaryOperator operator,
1035 Element element,
1036 _) {
1037 return giveup(node, 'visitUnresolvedSuperUnary');
1038 }
1039
1040 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct 1019 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct
1041 // semantic correlation between arguments and invocation. 1020 // semantic correlation between arguments and invocation.
1042 List<ir.Primitive> translateDynamicArguments(ast.NodeList nodeList, 1021 List<ir.Primitive> translateDynamicArguments(ast.NodeList nodeList,
1043 CallStructure callStructure) { 1022 CallStructure callStructure) {
1044 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit); 1023 List<ir.Primitive> arguments = nodeList.nodes.mapToList(visit);
1045 return normalizeDynamicArguments(callStructure, arguments); 1024 return normalizeDynamicArguments(callStructure, arguments);
1046 } 1025 }
1047 1026
1048 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct 1027 // TODO(johnniwinther): Handle this in the [IrBuilder] to ensure the correct
1049 // semantic correlation between arguments and invocation. 1028 // semantic correlation between arguments and invocation.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 return irBuilder.buildStaticFunctionInvocation(function, callStructure, 1112 return irBuilder.buildStaticFunctionInvocation(function, callStructure,
1134 translateStaticArguments(arguments, function, callStructure), 1113 translateStaticArguments(arguments, function, callStructure),
1135 sourceInformation: sourceInformationBuilder.buildCall(node)); 1114 sourceInformation: sourceInformationBuilder.buildCall(node));
1136 } 1115 }
1137 1116
1138 @override 1117 @override
1139 ir.Primitive handleStaticFunctionIncompatibleInvoke( 1118 ir.Primitive handleStaticFunctionIncompatibleInvoke(
1140 ast.Send node, 1119 ast.Send node,
1141 MethodElement function, 1120 MethodElement function,
1142 ast.NodeList arguments, 1121 ast.NodeList arguments,
1143 CallStructure callStructure, 1122 CallStructure callStructure, _) {
1144 _) { 1123 return buildStaticNoSuchMethod(
1145 return giveup(node, 'handleStaticFunctionIncompatibleInvoke'); 1124 elements.getSelector(node),
1125 arguments.nodes.mapToList(visit));
1146 } 1126 }
1147 1127
1148 @override 1128 @override
1149 ir.Primitive handleStaticGetterInvoke( 1129 ir.Primitive handleStaticGetterInvoke(
1150 ast.Send node, 1130 ast.Send node,
1151 FunctionElement getter, 1131 FunctionElement getter,
1152 ast.NodeList arguments, 1132 ast.NodeList arguments,
1153 CallStructure callStructure, 1133 CallStructure callStructure,
1154 _) { 1134 _) {
1155 if (getter.isForeign(compiler.backend)) { 1135 if (getter.isForeign(compiler.backend)) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 _) { 1176 _) {
1197 return irBuilder.buildSuperMethodInvocation(method, callStructure, 1177 return irBuilder.buildSuperMethodInvocation(method, callStructure,
1198 translateDynamicArguments(arguments, callStructure)); 1178 translateDynamicArguments(arguments, callStructure));
1199 } 1179 }
1200 1180
1201 @override 1181 @override
1202 ir.Primitive visitSuperMethodIncompatibleInvoke( 1182 ir.Primitive visitSuperMethodIncompatibleInvoke(
1203 ast.Send node, 1183 ast.Send node,
1204 MethodElement method, 1184 MethodElement method,
1205 ast.NodeList arguments, 1185 ast.NodeList arguments,
1206 CallStructure callStructure, 1186 CallStructure callStructure, _) {
1207 _) { 1187 return buildInstanceNoSuchMethod(
1208 return giveup(node, 'visitSuperMethodIncompatibleInvoke'); 1188 elements.getSelector(node),
1189 translateDynamicArguments(arguments, callStructure));
1209 } 1190 }
1210 1191
1211 @override 1192 @override
1212 ir.Primitive visitUnresolvedInvoke(
1213 ast.Send node,
1214 Element element,
1215 ast.NodeList arguments,
1216 Selector selector,
1217 _) {
1218 return giveup(node, 'visitUnresolvedInvoke');
1219 }
1220
1221 @override
1222 ir.Primitive visitUnresolvedSuperInvoke( 1193 ir.Primitive visitUnresolvedSuperInvoke(
1223 ast.Send node, 1194 ast.Send node,
1224 Element element, 1195 Element element,
1225 ast.NodeList arguments, 1196 ast.NodeList arguments,
1226 Selector selector, 1197 Selector selector, _) {
1227 _) { 1198 return buildInstanceNoSuchMethod(
1228 return giveup(node, 'visitUnresolvedSuperInvoke'); 1199 elements.getSelector(node),
1200 translateDynamicArguments(arguments, selector.callStructure));
1229 } 1201 }
1230 1202
1231 @override 1203 @override
1232 ir.Primitive visitThisInvoke( 1204 ir.Primitive visitThisInvoke(
1233 ast.Send node, 1205 ast.Send node,
1234 ast.NodeList arguments, 1206 ast.NodeList arguments,
1235 CallStructure callStructure, 1207 CallStructure callStructure,
1236 _) { 1208 _) {
1237 return translateCallInvoke(irBuilder.buildThis(), arguments, callStructure); 1209 return translateCallInvoke(irBuilder.buildThis(), arguments, callStructure);
1238 } 1210 }
1239 1211
1240 @override 1212 @override
1241 ir.Primitive visitTypeVariableTypeLiteralInvoke( 1213 ir.Primitive visitTypeVariableTypeLiteralInvoke(
1242 ast.Send node, 1214 ast.Send node,
1243 TypeVariableElement element, 1215 TypeVariableElement element,
1244 ast.NodeList arguments, 1216 ast.NodeList arguments,
1245 CallStructure callStructure, 1217 CallStructure callStructure,
1246 _) { 1218 _) {
1247 return translateCallInvoke( 1219 return translateCallInvoke(
1248 translateTypeVariableTypeLiteral(element), 1220 translateTypeVariableTypeLiteral(element),
1249 arguments, 1221 arguments,
1250 callStructure); 1222 callStructure);
1251 } 1223 }
1252 1224
1253 // TODO(johnniwinther): This should be a method on [IrBuilder].
1254 ir.Primitive buildReifyTypeVariable(ir.Primitive target,
1255 TypeVariableType variable);
1256
1257 @override 1225 @override
1258 ir.Primitive visitIndexSet( 1226 ir.Primitive visitIndexSet(
1259 ast.SendSet node, 1227 ast.SendSet node,
1260 ast.Node receiver, 1228 ast.Node receiver,
1261 ast.Node index, 1229 ast.Node index,
1262 ast.Node rhs, 1230 ast.Node rhs,
1263 _) { 1231 _) {
1264 return irBuilder.buildDynamicIndexSet( 1232 return irBuilder.buildDynamicIndexSet(
1265 visit(receiver), visit(index), visit(rhs)); 1233 visit(receiver), visit(index), visit(rhs));
1266 } 1234 }
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 return irBuilder.buildConstant(getConstantForNode(node)); 1828 return irBuilder.buildConstant(getConstantForNode(node));
1861 } 1829 }
1862 1830
1863 ir.Primitive visitThrow(ast.Throw node) { 1831 ir.Primitive visitThrow(ast.Throw node) {
1864 assert(irBuilder.isOpen); 1832 assert(irBuilder.isOpen);
1865 // This function is not called for throw expressions occurring as 1833 // This function is not called for throw expressions occurring as
1866 // statements. 1834 // statements.
1867 return irBuilder.buildNonTailThrow(visit(node.expression)); 1835 return irBuilder.buildNonTailThrow(visit(node.expression));
1868 } 1836 }
1869 1837
1838 ir.Primitive buildStaticNoSuchMethod(
1839 Selector selector,
1840 List<ir.Primitive> arguments);
1841
1842 ir.Primitive buildInstanceNoSuchMethod(
1843 Selector selector,
1844 List<ir.Primitive> arguments);
1845
1846 ir.Primitive buildRuntimeError(String message);
1847
1848 ir.Primitive buildAbstractClassInstantiationError(ClassElement element);
1849
1850 @override
1851 ir.Primitive errorInvalidAssert(
1852 ast.Send node,
1853 ast.NodeList arguments, _) {
1854 if (compiler.enableUserAssertions) {
1855 return giveup(node, 'Assert');
1856 } else {
1857 return irBuilder.buildNullConstant();
1858 }
1859 }
1860
1861 @override
1862 ir.Primitive errorUnresolvedCompound(
1863 ast.Send node,
1864 Element element,
1865 op.AssignmentOperator operator,
1866 ast.Node rhs, _) {
1867 // TODO(asgerf): What is unresolved? The getter and/or the setter?
1868 // If it was the setter, we must evaluate the right-hand side.
1869 return buildStaticNoSuchMethod(elements.getSelector(node), []);
1870 }
1871
1872 @override
1873 ir.Primitive visitUnresolvedClassConstructorInvoke(
1874 ast.NewExpression node,
1875 Element element,
1876 DartType type,
1877 ast.NodeList arguments,
1878 Selector selector, _) {
1879 // If the class is missing it's a runtime error.
1880 return buildRuntimeError("Unresolved class: '${element.name}'");
1881 }
1882
1883 @override
1884 ir.Primitive visitUnresolvedConstructorInvoke(
1885 ast.NewExpression node,
1886 Element constructor,
1887 DartType type,
1888 ast.NodeList arguments,
1889 Selector selector, _) {
1890 // If the class is there but the constructor is missing, it's an NSM error.
1891 return buildStaticNoSuchMethod(selector,
1892 translateDynamicArguments(arguments, selector.callStructure));
1893 }
1894
1895 @override
1896 ir.Primitive errorNonConstantConstructorInvoke(
1897 ast.NewExpression node,
1898 Element element,
1899 InterfaceType type,
1900 ast.NodeList arguments,
1901 CallStructure callStructure, _) {
1902 assert(compiler.compilationFailed);
1903 return irBuilder.buildNullConstant();
1904 }
1905
1906 @override
1907 ir.Primitive visitUnresolvedGet(
1908 ast.Send node,
1909 Element element, _) {
1910 return buildStaticNoSuchMethod(elements.getSelector(node), []);
1911 }
1912
1913 @override
1914 ir.Primitive visitUnresolvedInvoke(
1915 ast.Send node,
1916 Element element,
1917 ast.NodeList arguments,
1918 Selector selector, _) {
1919 return buildStaticNoSuchMethod(elements.getSelector(node),
1920 arguments.nodes.mapToList(visit));
1921 }
1922
1923 @override
1924 ir.Primitive errorUnresolvedPostfix(
1925 ast.Send node,
1926 Element element,
1927 op.IncDecOperator operator, _) {
1928 // TODO(asgerf): Which ones are missing? The getter and/or the setter?
1929 return buildStaticNoSuchMethod(elements.getSelector(node), []);
1930 }
1931
1932 @override
1933 ir.Primitive errorUnresolvedPrefix(
1934 ast.Send node,
1935 Element element,
1936 op.IncDecOperator operator, _) {
1937 // TODO(asgerf): Which ones are missing? The getter and/or the setter?
1938 return buildStaticNoSuchMethod(elements.getSelector(node), []);
1939 }
1940
1941 @override
1942 ir.Primitive visitUnresolvedRedirectingFactoryConstructorInvoke(
1943 ast.NewExpression node,
1944 ConstructorElement constructor,
1945 InterfaceType type,
1946 ast.NodeList arguments,
1947 CallStructure callStructure, _) {
1948 String nameString = Elements.reconstructConstructorName(constructor);
1949 Name name = new Name(nameString, constructor.library);
1950 return buildStaticNoSuchMethod(
1951 new Selector(SelectorKind.CALL, name, callStructure),
1952 translateDynamicArguments(arguments, callStructure));
1953 }
1954
1955 @override
1956 ir.Primitive errorUnresolvedSet(
1957 ast.Send node,
1958 Element element,
1959 ast.Node rhs, _) {
1960 return buildStaticNoSuchMethod(elements.getSelector(node), [visit(rhs)]);
1961 }
1962
1963 @override
1964 ir.Primitive errorUnresolvedSuperCompoundIndexSet(
1965 ast.SendSet node,
1966 Element element,
1967 ast.Node index,
1968 op.AssignmentOperator operator,
1969 ast.Node rhs, _) {
1970 // Assume the index getter is missing.
1971 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
1972 return buildInstanceNoSuchMethod(selector, [visit(index)]);
1973 }
1974
1975 @override
1976 ir.Primitive visitUnresolvedSuperIndex(
1977 ast.Send node,
1978 Element function,
1979 ast.Node index, _) {
1980 // Assume the index getter is missing.
1981 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
1982 return buildInstanceNoSuchMethod(selector, [visit(index)]);
1983 }
1984
1985 @override
1986 ir.Primitive errorUnresolvedSuperIndexPostfix(
1987 ast.Send node,
1988 Element function,
1989 ast.Node index,
1990 op.IncDecOperator operator, _) {
1991 // Assume the index getter is missing.
1992 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
1993 return buildInstanceNoSuchMethod(selector, [visit(index)]);
1994 }
1995
1996 @override
1997 ir.Primitive errorUnresolvedSuperIndexPrefix(
1998 ast.Send node,
1999 Element function,
2000 ast.Node index,
2001 op.IncDecOperator operator, _) {
2002 // Assume the index getter is missing.
2003 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
2004 return buildInstanceNoSuchMethod(selector, [visit(index)]);
2005 }
2006
2007 @override
2008 ir.Primitive errorUnresolvedSuperIndexSet(
2009 ast.SendSet node,
2010 Element element,
2011 ast.Node index,
2012 ast.Node rhs, _) {
2013 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
2014 return buildInstanceNoSuchMethod(
2015 selector,
2016 [visit(index), visit(rhs)]);
2017 }
2018
2019 @override
2020 ir.Primitive visitUnresolvedSuperBinary(
2021 ast.Send node,
2022 Element element,
2023 op.BinaryOperator operator,
2024 ast.Node argument, _) {
2025 return buildInstanceNoSuchMethod(
2026 elements.getSelector(node),
2027 [visit(argument)]);
2028 }
2029
2030 @override
2031 ir.Primitive visitUnresolvedSuperUnary(
2032 ast.Send node,
2033 op.UnaryOperator operator,
2034 Element element, _) {
2035 return buildInstanceNoSuchMethod(elements.getSelector(node), []);
2036 }
2037
2038 @override
2039 ir.Primitive errorUndefinedBinaryExpression(
2040 ast.Send node,
2041 ast.Node left,
2042 ast.Operator operator,
2043 ast.Node right, _) {
2044 assert(compiler.compilationFailed);
2045 return irBuilder.buildNullConstant();
2046 }
2047
2048 @override
2049 ir.Primitive errorUndefinedUnaryExpression(
2050 ast.Send node,
2051 ast.Operator operator,
2052 ast.Node expression, _) {
2053 assert(compiler.compilationFailed);
2054 return irBuilder.buildNullConstant();
2055 }
2056
2057 @override
2058 ir.Primitive errorTopLevelFunctionSet(
2059 ast.Send node,
2060 MethodElement function,
2061 ast.Node rhs, _) {
2062 return buildStaticNoSuchMethod(
2063 new Selector.setter(function.name, function.library),
2064 [visit(rhs)]);
2065 }
2066
2067 @override
2068 ir.Primitive errorTopLevelSetterGet(
2069 ast.Send node,
2070 FunctionElement setter, _) {
2071 return buildStaticNoSuchMethod(
2072 new Selector.getter(setter.name, setter.library), []);
2073 }
2074
2075 @override
2076 ir.Primitive errorTopLevelGetterSet(
2077 ast.SendSet node,
2078 FunctionElement getter,
2079 ast.Node rhs, _) {
2080 return buildStaticNoSuchMethod(
2081 new Selector.setter(getter.name, getter.library),
2082 [visit(rhs)]);
2083 }
2084
2085 @override
2086 ir.Primitive errorTopLevelSetterInvoke(
2087 ast.Send node,
2088 FunctionElement setter,
2089 ast.NodeList arguments,
2090 CallStructure callStructure, _) {
2091 return buildStaticNoSuchMethod(
2092 new Selector.getter(setter.name, setter.library), []);
2093 }
2094
2095 @override
2096 ir.Primitive errorClassTypeLiteralSet(
2097 ast.SendSet node,
2098 TypeConstantExpression constant,
2099 ast.Node rhs, _) {
2100 InterfaceType type = constant.type;
2101 ClassElement element = type.element;
2102 return buildStaticNoSuchMethod(
2103 new Selector.setter(element.name, element.library), [visit(rhs)]);
2104 }
2105
2106 @override
2107 ir.Primitive errorTypedefTypeLiteralSet(
2108 ast.SendSet node,
2109 TypeConstantExpression constant,
2110 ast.Node rhs, _) {
2111 TypedefType type = constant.type;
2112 TypedefElement element = type.element;
2113 return buildStaticNoSuchMethod(
2114 new Selector.setter(element.name, element.library), [visit(rhs)]);
2115 }
2116
2117 @override
2118 ir.Primitive errorTypeVariableTypeLiteralSet(
2119 ast.SendSet node,
2120 TypeVariableElement element,
2121 ast.Node rhs, _) {
2122 return buildStaticNoSuchMethod(
2123 new Selector.setter(element.name, element.library), [visit(rhs)]);
2124 }
2125
2126 @override
2127 ir.Primitive errorDynamicTypeLiteralSet(
2128 ast.SendSet node,
2129 ConstantExpression constant,
2130 ast.Node rhs, _) {
2131 return buildStaticNoSuchMethod(
2132 new Selector.setter('dynamic', null), [visit(rhs)]);
2133 }
2134
2135 @override
2136 ir.Primitive visitAbstractClassConstructorInvoke(
2137 ast.NewExpression node,
2138 ConstructorElement element,
2139 InterfaceType type,
2140 ast.NodeList arguments,
2141 CallStructure callStructure, _) {
2142 return buildAbstractClassInstantiationError(element.enclosingClass);
2143 }
2144
2145 @override
2146 ir.Primitive errorClassTypeLiteralCompound(
2147 ast.Send node,
2148 ConstantExpression constant,
2149 op.AssignmentOperator operator,
2150 ast.Node rhs, _) {
2151 return translateCompound(
2152 getValue: () => irBuilder.buildConstant(constant),
2153 operator: operator,
2154 rhs: rhs,
2155 setValue: (value) {}); // The binary operator will throw before this.
2156 }
2157
2158 @override
2159 ir.Primitive errorClassTypeLiteralPostfix(
2160 ast.Send node,
2161 ConstantExpression constant,
2162 op.IncDecOperator operator, _) {
2163 return translatePrefixPostfix(
2164 getValue: () => irBuilder.buildConstant(constant),
2165 operator: operator,
2166 setValue: (value) {}, // The binary operator will throw before this.
2167 isPrefix: false);
2168 }
2169
2170 @override
2171 ir.Primitive errorClassTypeLiteralPrefix(
2172 ast.Send node,
2173 ConstantExpression constant,
2174 op.IncDecOperator operator, _) {
2175 return translatePrefixPostfix(
2176 getValue: () => irBuilder.buildConstant(constant),
2177 operator: operator,
2178 setValue: (value) {}, // The binary operator will throw before this.
2179 isPrefix: true);
2180 }
2181
2182 @override
2183 ir.Primitive errorDynamicTypeLiteralCompound(
2184 ast.Send node,
2185 ConstantExpression constant,
2186 op.AssignmentOperator operator,
2187 ast.Node rhs, _) {
2188 return translateCompound(
2189 getValue: () => irBuilder.buildConstant(constant),
2190 operator: operator,
2191 rhs: rhs,
2192 setValue: (value) {}); // The binary operator will throw before this.
2193 }
2194
2195 @override
2196 ir.Primitive errorDynamicTypeLiteralPostfix(
2197 ast.Send node,
2198 ConstantExpression constant,
2199 op.IncDecOperator operator, _) {
2200 return translatePrefixPostfix(
2201 getValue: () => irBuilder.buildConstant(constant),
2202 operator: operator,
2203 setValue: (value) {}, // The binary operator will throw before this.
2204 isPrefix: false);
2205 }
2206
2207 @override
2208 ir.Primitive errorDynamicTypeLiteralPrefix(
2209 ast.Send node,
2210 ConstantExpression constant,
2211 op.IncDecOperator operator, _) {
2212 return translatePrefixPostfix(
2213 getValue: () => irBuilder.buildConstant(constant),
2214 operator: operator,
2215 setValue: (value) {}, // The binary operator will throw before this.
2216 isPrefix: true);
2217 }
2218
2219 @override
2220 ir.Primitive errorFinalLocalVariableCompound(
2221 ast.Send node,
2222 LocalVariableElement variable,
2223 op.AssignmentOperator operator,
2224 ast.Node rhs, _) {
2225 Selector selector = new Selector.setter(variable.name, null);
2226 return translateCompound(
2227 getValue: () => irBuilder.buildLocalVariableGet(variable),
2228 operator: operator,
2229 rhs: rhs,
2230 setValue: (value) => buildStaticNoSuchMethod(selector, [value]));
2231 }
2232
2233 @override
2234 ir.Primitive errorFinalLocalVariableSet(
2235 ast.SendSet node,
2236 LocalVariableElement variable,
2237 ast.Node rhs, _) {
2238 Selector selector = new Selector.setter(variable.name, null);
2239 return buildStaticNoSuchMethod(selector, [visit(rhs)]);
2240 }
2241
2242 @override
2243 ir.Primitive errorFinalParameterCompound(
2244 ast.Send node,
2245 ParameterElement parameter,
2246 op.AssignmentOperator operator,
2247 ast.Node rhs, _) {
2248 Selector selector = new Selector.setter(parameter.name, null);
2249 return translateCompound(
2250 getValue: () => irBuilder.buildLocalVariableGet(parameter),
2251 operator: operator,
2252 rhs: rhs,
2253 setValue: (value) => buildStaticNoSuchMethod(selector, [value]));
2254 }
2255
2256 @override
2257 ir.Primitive errorFinalParameterSet(
2258 ast.SendSet node,
2259 ParameterElement parameter,
2260 ast.Node rhs, _) {
2261 Selector selector = new Selector.setter(parameter.name, null);
2262 return buildStaticNoSuchMethod(selector, [visit(rhs)]);
2263 }
2264
2265 @override
2266 ir.Primitive errorFinalStaticFieldCompound(
2267 ast.Send node,
2268 FieldElement field,
2269 op.AssignmentOperator operator,
2270 ast.Node rhs, _) {
2271 return translateCompound(
2272 getValue: () => irBuilder.buildStaticFieldGet(field),
2273 operator: operator,
2274 rhs: rhs,
2275 setValue: (value) => buildStaticNoSuchMethod(
2276 new Selector.setter(field.name, field.library), [value]));
2277 }
2278
2279 @override
2280 ir.Primitive errorFinalStaticFieldSet(
2281 ast.SendSet node,
2282 FieldElement field,
2283 ast.Node rhs, _) {
2284 // TODO(asgerf): Include class name somehow?
2285 return buildStaticNoSuchMethod(
2286 new Selector.setter(field.name, field.library),
2287 [visit(rhs)]);
2288 }
2289
2290 @override
2291 ir.Primitive errorFinalSuperFieldCompound(
2292 ast.Send node,
2293 FieldElement field,
2294 op.AssignmentOperator operator,
2295 ast.Node rhs, _) {
2296 Selector selector = useSelectorTypeOfNode(
2297 new Selector.setter(field.name, field.library),
2298 node);
2299 return translateCompound(
2300 getValue: () => irBuilder.buildSuperFieldGet(field),
2301 operator: operator,
2302 rhs: rhs,
2303 setValue: (value) => buildInstanceNoSuchMethod(selector, [value]));
2304 }
2305
2306 @override
2307 ir.Primitive errorFinalSuperFieldSet(
2308 ast.SendSet node,
2309 FieldElement field,
2310 ast.Node rhs, _) {
2311 Selector selector = useSelectorTypeOfNode(
2312 new Selector.setter(field.name, field.library),
2313 node);
2314 return buildInstanceNoSuchMethod(selector, [visit(rhs)]);
2315 }
2316
2317 @override
2318 ir.Primitive errorFinalTopLevelFieldCompound(
2319 ast.Send node,
2320 FieldElement field,
2321 op.AssignmentOperator operator,
2322 ast.Node rhs, _) {
2323 return translateCompound(
2324 getValue: () => irBuilder.buildStaticFieldGet(field),
2325 operator: operator,
2326 rhs: rhs,
2327 setValue: (value) => buildStaticNoSuchMethod(
2328 new Selector.setter(field.name, field.library), [value]));
2329 }
2330
2331 @override
2332 ir.Primitive errorFinalTopLevelFieldSet(
2333 ast.SendSet node,
2334 FieldElement field,
2335 ast.Node rhs, _) {
2336 return buildStaticNoSuchMethod(
2337 new Selector.setter(field.name, field.library),
2338 [visit(rhs)]);
2339 }
2340
2341 @override
2342 ir.Primitive errorLocalFunctionCompound(
2343 ast.Send node,
2344 LocalFunctionElement function,
2345 op.AssignmentOperator operator,
2346 ast.Node rhs, _) {
2347 return translateCompound(
2348 getValue: () => irBuilder.buildLocalFunctionGet(function),
2349 operator: operator,
2350 rhs: rhs,
2351 setValue: (value) {}); // Binary operator will throw before this.
2352 }
2353
2354 @override
2355 ir.Primitive errorLocalFunctionPostfix(
2356 ast.Send node,
2357 LocalFunctionElement function,
2358 op.IncDecOperator operator,
2359 _) {
2360 return translatePrefixPostfix(
2361 getValue: () => irBuilder.buildLocalFunctionGet(function),
2362 operator: operator,
2363 setValue: (value) {}, // Binary operator will throw before this.
2364 isPrefix: false);
2365 }
2366
2367 @override
2368 ir.Primitive errorLocalFunctionPrefix(
2369 ast.Send node,
2370 LocalFunctionElement function,
2371 op.IncDecOperator operator,
2372 _) {
2373 return translatePrefixPostfix(
2374 getValue: () => irBuilder.buildLocalFunctionGet(function),
2375 operator: operator,
2376 setValue: (value) {}, // Binary operator will throw before this.
2377 isPrefix: true);
2378 }
2379
2380 @override
2381 ir.Primitive errorLocalFunctionSet(
2382 ast.SendSet node,
2383 LocalFunctionElement function,
2384 ast.Node rhs, _) {
2385 return buildStaticNoSuchMethod(
2386 new Selector.setter(function.name, null),
2387 [visit(rhs)]);
2388 }
2389
2390 @override
2391 ir.Primitive errorStaticFunctionSet(
2392 ast.Send node,
2393 MethodElement function,
2394 ast.Node rhs,
2395 _) {
2396 return buildStaticNoSuchMethod(
2397 new Selector.setter(function.name, function.library),
2398 [visit(rhs)]);
2399 }
2400
2401 @override
2402 ir.Primitive errorStaticGetterSet(
2403 ast.SendSet node,
2404 FunctionElement getter,
2405 ast.Node rhs,
2406 _) {
2407 return buildStaticNoSuchMethod(
2408 new Selector.setter(getter.name, getter.library),
2409 [visit(rhs)]);
2410 }
2411
2412 @override
2413 ir.Primitive errorStaticSetterGet(
2414 ast.Send node,
2415 FunctionElement setter,
2416 _) {
2417 return buildStaticNoSuchMethod(
2418 new Selector.getter(setter.name, setter.library),
2419 []);
2420 }
2421
2422 @override
2423 ir.Primitive errorStaticSetterInvoke(
2424 ast.Send node,
2425 FunctionElement setter,
2426 ast.NodeList arguments,
2427 CallStructure callStructure, _) {
2428 // Translate as a method call.
2429 List<ir.Primitive> args = arguments.nodes.mapToList(visit);
2430 Name name = new Name(setter.name, setter.library);
2431 return buildStaticNoSuchMethod(
2432 new Selector(SelectorKind.CALL, name, callStructure),
2433 args);
2434 }
2435
2436 @override
2437 ir.Primitive errorSuperGetterSet(
2438 ast.SendSet node,
2439 FunctionElement getter,
2440 ast.Node rhs,
2441 _) {
2442 Selector selector = useSelectorTypeOfNode(
2443 new Selector.setter(getter.name, getter.library),
2444 node);
2445 return buildInstanceNoSuchMethod(selector, [visit(rhs)]);
2446 }
2447
2448 @override
2449 ir.Primitive errorSuperMethodSet(
2450 ast.Send node,
2451 MethodElement method,
2452 ast.Node rhs,
2453 _) {
2454 Selector selector = useSelectorTypeOfNode(
2455 new Selector.setter(method.name, method.library),
2456 node);
2457 return buildInstanceNoSuchMethod(selector, [visit(rhs)]);
2458 }
2459
2460 @override
2461 ir.Primitive errorSuperSetterGet(
2462 ast.Send node,
2463 FunctionElement setter, _) {
2464 Selector selector = useSelectorTypeOfNode(
2465 new Selector.setter(setter.name, setter.library),
2466 node);
2467 return buildInstanceNoSuchMethod(selector, []);
2468 }
2469
2470 @override
2471 ir.Primitive errorSuperSetterInvoke(
2472 ast.Send node,
2473 FunctionElement setter,
2474 ast.NodeList arguments,
2475 CallStructure callStructure, _) {
2476 List<ir.Primitive> args =
2477 translateDynamicArguments(arguments, callStructure);
2478 Name name = new Name(setter.name, setter.library);
2479 Selector selector = useSelectorTypeOfNode(
2480 new Selector(SelectorKind.CALL, name, callStructure),
2481 node);
2482 return buildInstanceNoSuchMethod(selector, args);
2483 }
2484
2485 @override
2486 ir.Primitive errorTypeVariableTypeLiteralCompound(
2487 ast.Send node,
2488 TypeVariableElement element,
2489 op.AssignmentOperator operator,
2490 ast.Node rhs, _) {
2491 return translateCompound(
2492 getValue: () => irBuilder.buildReifyTypeVariable(element.type),
2493 operator: operator,
2494 rhs: rhs,
2495 setValue: (value) {}); // The binary operator will throw before this.
2496 }
2497
2498 @override
2499 ir.Primitive errorTypeVariableTypeLiteralPostfix(
2500 ast.Send node,
2501 TypeVariableElement element,
2502 op.IncDecOperator operator, _) {
2503 return translatePrefixPostfix(
2504 getValue: () => irBuilder.buildReifyTypeVariable(element.type),
2505 operator: operator,
2506 setValue: (value) {}, // The binary operator will throw before this.
2507 isPrefix: false);
2508 }
2509
2510 @override
2511 ir.Primitive errorTypeVariableTypeLiteralPrefix(
2512 ast.Send node,
2513 TypeVariableElement element,
2514 op.IncDecOperator operator, _) {
2515 return translatePrefixPostfix(
2516 getValue: () => irBuilder.buildReifyTypeVariable(element.type),
2517 operator: operator,
2518 setValue: (value) {}, // The binary operator will throw before this.
2519 isPrefix: true);
2520 }
2521
2522 @override
2523 ir.Primitive errorTypedefTypeLiteralCompound(
2524 ast.Send node,
2525 ConstantExpression constant,
2526 op.AssignmentOperator operator,
2527 ast.Node rhs, _) {
2528 return translateCompound(
2529 getValue: () => irBuilder.buildConstant(constant),
2530 operator: operator,
2531 rhs: rhs,
2532 setValue: (value) {}); // The binary operator will throw before this.
2533 }
2534
2535 @override
2536 ir.Primitive errorTypedefTypeLiteralPostfix(
2537 ast.Send node,
2538 ConstantExpression constant,
2539 op.IncDecOperator operator, _) {
2540 return translatePrefixPostfix(
2541 getValue: () => irBuilder.buildConstant(constant),
2542 operator: operator,
2543 setValue: (value) {}, // The binary operator will throw before this.
2544 isPrefix: false);
2545 }
2546
2547 @override
2548 ir.Primitive errorTypedefTypeLiteralPrefix(
2549 ast.Send node,
2550 TypeConstantExpression constant,
2551 op.IncDecOperator operator, _) {
2552 return translatePrefixPostfix(
2553 getValue: () => irBuilder.buildConstant(constant),
2554 operator: operator,
2555 setValue: (value) {}, // The binary operator will throw before this.
2556 isPrefix: true);
2557 }
2558
1870 ir.RootNode nullIfGiveup(ir.RootNode action()) { 2559 ir.RootNode nullIfGiveup(ir.RootNode action()) {
1871 try { 2560 try {
1872 return action(); 2561 return action();
1873 } catch(e) { 2562 } catch(e) {
1874 if (e == ABORT_IRNODE_BUILDER) { 2563 if (e == ABORT_IRNODE_BUILDER) {
1875 return null; 2564 return null;
1876 } 2565 }
1877 rethrow; 2566 rethrow;
1878 } 2567 }
1879 } 2568 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2183 return arguments; 2872 return arguments;
2184 } 2873 }
2185 2874
2186 List<ir.Primitive> normalizeDynamicArguments( 2875 List<ir.Primitive> normalizeDynamicArguments(
2187 CallStructure callStructure, 2876 CallStructure callStructure,
2188 List<ir.Primitive> arguments) { 2877 List<ir.Primitive> arguments) {
2189 return arguments; 2878 return arguments;
2190 } 2879 }
2191 2880
2192 @override 2881 @override
2193 ir.Primitive buildReifyTypeVariable(ir.Primitive target,
2194 TypeVariableType variable) {
2195 assert(target == irBuilder.state.enclosingMethodThisParameter);
2196 ir.Primitive prim = new ir.ReifyTypeVar(variable.element);
2197 irBuilder.add(new ir.LetPrim(prim));
2198 return prim;
2199 }
2200
2201 @override
2202 ir.Primitive handleConstructorInvoke( 2882 ir.Primitive handleConstructorInvoke(
2203 ast.NewExpression node, 2883 ast.NewExpression node,
2204 ConstructorElement constructor, 2884 ConstructorElement constructor,
2205 DartType type, 2885 DartType type,
2206 ast.NodeList arguments, 2886 ast.NodeList arguments,
2207 CallStructure callStructure, _) { 2887 CallStructure callStructure, _) {
2208 List<ir.Primitive> arguments = 2888 List<ir.Primitive> arguments =
2209 node.send.arguments.mapToList(visit, growable:false); 2889 node.send.arguments.mapToList(visit, growable:false);
2210 return irBuilder.buildConstructorInvocation( 2890 return irBuilder.buildConstructorInvocation(
2211 constructor, 2891 constructor,
2212 callStructure, 2892 callStructure,
2213 type, 2893 type,
2214 arguments); 2894 arguments);
2215 } 2895 }
2896
2897 @override
2898 ir.Primitive buildStaticNoSuchMethod(Selector selector,
2899 List<ir.Primitive> arguments) {
2900 return giveup(null, 'Static noSuchMethod');
2901 }
2902
2903 @override
2904 ir.Primitive buildInstanceNoSuchMethod(Selector selector,
2905 List<ir.Primitive> arguments) {
2906 return giveup(null, 'Instance noSuchMethod');
2907 }
2908
2909 @override
2910 ir.Primitive buildRuntimeError(String message) {
2911 return giveup(null, 'Build runtime error: $message');
2912 }
2913
2914 @override
2915 ir.Primitive buildAbstractClassInstantiationError(ClassElement element) {
2916 return giveup(null, 'Abstract class instantiation: ${element.name}');
2917 }
2216 } 2918 }
2217 2919
2218 /// The [IrBuilder]s view on the information about the program that has been 2920 /// The [IrBuilder]s view on the information about the program that has been
2219 /// computed in resolution and and type interence. 2921 /// computed in resolution and and type interence.
2220 class GlobalProgramInformation { 2922 class GlobalProgramInformation {
2221 final Compiler _compiler; 2923 final Compiler _compiler;
2222 JavaScriptBackend get _backend => _compiler.backend; 2924 JavaScriptBackend get _backend => _compiler.backend;
2223 2925
2224 GlobalProgramInformation(this._compiler); 2926 GlobalProgramInformation(this._compiler);
2225 2927
2226 /// Returns [true], if the analysis could not determine that the type 2928 /// Returns [true], if the analysis could not determine that the type
2227 /// arguments for the class [cls] are never used in the program. 2929 /// arguments for the class [cls] are never used in the program.
2228 bool requiresRuntimeTypesFor(ClassElement cls) { 2930 bool requiresRuntimeTypesFor(ClassElement cls) {
2229 return cls.typeVariables.isNotEmpty && _backend.classNeedsRti(cls); 2931 return cls.typeVariables.isNotEmpty && _backend.classNeedsRti(cls);
2230 } 2932 }
2231 } 2933 }
2232 2934
2233 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder]. 2935 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder].
2234 class JsIrBuilderVisitor extends IrBuilderVisitor { 2936 class JsIrBuilderVisitor extends IrBuilderVisitor {
2235 /// Promote the type of [irBuilder] to [JsIrBuilder]. 2937 /// Promote the type of [irBuilder] to [JsIrBuilder].
2236 JsIrBuilder get irBuilder => super.irBuilder; 2938 JsIrBuilder get irBuilder => super.irBuilder;
2237 2939
2940 JavaScriptBackend get backend => compiler.backend;
2941
2238 /// Result of closure conversion for the current body of code. 2942 /// Result of closure conversion for the current body of code.
2239 /// 2943 ///
2240 /// Will be initialized upon entering the body of a function. 2944 /// Will be initialized upon entering the body of a function.
2241 /// It is computed by the [ClosureTranslator]. 2945 /// It is computed by the [ClosureTranslator].
2242 ClosureClassMap closureMap; 2946 ClosureClassMap closureMap;
2243 2947
2244 /// During construction of a constructor factory, [fieldValues] maps fields 2948 /// During construction of a constructor factory, [fieldValues] maps fields
2245 /// to the primitive containing their initial value. 2949 /// to the primitive containing their initial value.
2246 Map<FieldElement, ir.Primitive> fieldValues = <FieldElement, ir.Primitive>{}; 2950 Map<FieldElement, ir.Primitive> fieldValues = <FieldElement, ir.Primitive>{};
2247 2951
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 for (int i=0; i < callStructure.positionalArgumentCount; i++) { 3512 for (int i=0; i < callStructure.positionalArgumentCount; i++) {
2809 result.add(arguments[i]); 3513 result.add(arguments[i]);
2810 } 3514 }
2811 for (String argName in callStructure.getOrderedNamedArguments()) { 3515 for (String argName in callStructure.getOrderedNamedArguments()) {
2812 int nameIndex = callStructure.namedArguments.indexOf(argName); 3516 int nameIndex = callStructure.namedArguments.indexOf(argName);
2813 int translatedIndex = callStructure.positionalArgumentCount + nameIndex; 3517 int translatedIndex = callStructure.positionalArgumentCount + nameIndex;
2814 result.add(arguments[translatedIndex]); 3518 result.add(arguments[translatedIndex]);
2815 } 3519 }
2816 return result; 3520 return result;
2817 } 3521 }
2818
2819 @override
2820 ir.Primitive buildReifyTypeVariable(ir.Primitive target,
2821 TypeVariableType variable) {
2822 ir.Primitive typeArgument =
2823 irBuilder.buildTypeVariableAccess(target, variable);
2824
2825 ir.Primitive type = new ir.ReifyRuntimeType(typeArgument);
2826 irBuilder.add(new ir.LetPrim(type));
2827 return type;
2828 }
2829
2830 @override 3522 @override
2831 ir.Primitive handleConstructorInvoke( 3523 ir.Primitive handleConstructorInvoke(
2832 ast.NewExpression node, 3524 ast.NewExpression node,
2833 ConstructorElement constructor, 3525 ConstructorElement constructor,
2834 DartType type, 3526 DartType type,
2835 ast.NodeList arguments, 3527 ast.NodeList arguments,
2836 CallStructure callStructure, 3528 CallStructure callStructure,
2837 _) { 3529 _) {
2838 List<ir.Primitive> arguments = 3530 List<ir.Primitive> arguments =
2839 node.send.arguments.mapToList(visit, growable:false); 3531 node.send.arguments.mapToList(visit, growable:false);
2840 arguments = normalizeStaticArguments( 3532 arguments = normalizeStaticArguments(
2841 callStructure, constructor, arguments); 3533 callStructure, constructor, arguments);
2842 return irBuilder.buildConstructorInvocation( 3534 return irBuilder.buildConstructorInvocation(
2843 constructor.effectiveTarget, 3535 constructor.effectiveTarget,
2844 callStructure, 3536 callStructure,
2845 constructor.computeEffectiveTargetType(type), 3537 constructor.computeEffectiveTargetType(type),
2846 arguments); 3538 arguments);
2847 } 3539 }
3540
3541 @override
3542 ir.Primitive buildStaticNoSuchMethod(Selector selector,
3543 List<ir.Primitive> arguments) {
3544 Element thrower = backend.getThrowNoSuchMethod();
3545 ir.Primitive receiver = irBuilder.buildStringConstant('');
3546 ir.Primitive name = irBuilder.buildStringConstant(selector.name);
3547 ir.Primitive argumentList = irBuilder.buildListLiteral(null, arguments);
3548 ir.Primitive expectedArgumentNames = irBuilder.buildNullConstant();
3549 return irBuilder.buildStaticFunctionInvocation(
3550 thrower,
3551 new CallStructure.unnamed(4),
3552 [receiver, name, argumentList, expectedArgumentNames]);
3553 }
3554
3555 @override
3556 ir.Primitive buildInstanceNoSuchMethod(Selector selector,
3557 List<ir.Primitive> arguments) {
3558 return irBuilder.buildDynamicInvocation(
3559 irBuilder.buildThis(),
3560 useSelectorType(compiler.noSuchMethodSelector, selector),
3561 [irBuilder.buildInvocationMirror(selector, arguments)]);
3562 }
3563
3564 @override
3565 ir.Primitive buildRuntimeError(String message) {
3566 return irBuilder.buildStaticFunctionInvocation(
3567 backend.getThrowRuntimeError(),
3568 new CallStructure.unnamed(1),
3569 [irBuilder.buildStringConstant(message)]);
3570 }
3571
3572 @override
3573 ir.Primitive buildAbstractClassInstantiationError(ClassElement element) {
3574 return irBuilder.buildStaticFunctionInvocation(
3575 backend.getThrowAbstractClassInstantiationError(),
3576 new CallStructure.unnamed(1),
3577 [irBuilder.buildStringConstant(element.name)]);
3578 }
2848 } 3579 }
2849 3580
2850 /// Perform simple post-processing on the initial CPS-translated root term. 3581 /// Perform simple post-processing on the initial CPS-translated root term.
2851 /// 3582 ///
2852 /// This pass performs backend-independent post-processing on the translated 3583 /// This pass performs backend-independent post-processing on the translated
2853 /// term. It is implemented separately from the optimization passes because 3584 /// term. It is implemented separately from the optimization passes because
2854 /// it is required for correctness of the implementation. 3585 /// it is required for correctness of the implementation.
2855 /// 3586 ///
2856 /// It performs the following translations: 3587 /// It performs the following translations:
2857 /// - Replace [ir.LetPrim] binding a [ir.NonTailThrow] with a [ir.Throw] 3588 /// - Replace [ir.LetPrim] binding a [ir.NonTailThrow] with a [ir.Throw]
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 node.body = replacementFor(node.body); 3637 node.body = replacementFor(node.body);
2907 } 3638 }
2908 } 3639 }
2909 3640
2910 /// Visit a just-deleted subterm and unlink all [Reference]s in it. 3641 /// Visit a just-deleted subterm and unlink all [Reference]s in it.
2911 class RemovalVisitor extends ir.RecursiveVisitor { 3642 class RemovalVisitor extends ir.RecursiveVisitor {
2912 processReference(ir.Reference reference) { 3643 processReference(ir.Reference reference) {
2913 reference.unlink(); 3644 reference.unlink();
2914 } 3645 }
2915 } 3646 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698