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

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: Comments from floitch 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 buildReifyTypeVariable(irBuilder.buildThis(), 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, _) {
(...skipping 101 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 }
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 return irBuilder.buildConstant(getConstantForNode(node)); 1832 return irBuilder.buildConstant(getConstantForNode(node));
1861 } 1833 }
1862 1834
1863 ir.Primitive visitThrow(ast.Throw node) { 1835 ir.Primitive visitThrow(ast.Throw node) {
1864 assert(irBuilder.isOpen); 1836 assert(irBuilder.isOpen);
1865 // This function is not called for throw expressions occurring as 1837 // This function is not called for throw expressions occurring as
1866 // statements. 1838 // statements.
1867 return irBuilder.buildNonTailThrow(visit(node.expression)); 1839 return irBuilder.buildNonTailThrow(visit(node.expression));
1868 } 1840 }
1869 1841
1842 ir.Primitive buildStaticNoSuchMethod(
1843 Selector selector,
1844 List<ir.Primitive> arguments);
1845
1846 ir.Primitive buildInstanceNoSuchMethod(
1847 Selector selector,
1848 List<ir.Primitive> arguments);
1849
1850 ir.Primitive buildRuntimeError(String message);
1851
1852 ir.Primitive buildAbstractClassInstantiationError(ClassElement element);
1853
1854 @override
1855 ir.Primitive errorInvalidAssert(
1856 ast.Send node,
1857 ast.NodeList arguments, _) {
1858 if (compiler.enableUserAssertions) {
1859 return giveup(node, 'Assert');
1860 } else {
1861 return irBuilder.buildNullConstant();
1862 }
1863 }
1864
1865 @override
1866 ir.Primitive errorUnresolvedCompound(
1867 ast.Send node,
1868 Element element,
1869 op.AssignmentOperator operator,
1870 ast.Node rhs, _) {
1871 // TODO(asgerf): What is unresolved? The getter and/or the setter?
1872 // If it was the setter, we must evaluate the right-hand side.
1873 return buildStaticNoSuchMethod(elements.getSelector(node), []);
1874 }
1875
1876 @override
1877 ir.Primitive visitUnresolvedClassConstructorInvoke(
1878 ast.NewExpression node,
1879 Element element,
1880 DartType type,
1881 ast.NodeList arguments,
1882 Selector selector, _) {
1883 // If the class is missing it's a runtime error.
1884 return buildRuntimeError("Unresolved class: '${element.name}'");
1885 }
1886
1887 @override
1888 ir.Primitive visitUnresolvedConstructorInvoke(
1889 ast.NewExpression node,
1890 Element constructor,
1891 DartType type,
1892 ast.NodeList arguments,
1893 Selector selector, _) {
1894 // If the class is there but the constructor is missing, it's an NSM error.
1895 return buildStaticNoSuchMethod(selector,
1896 translateDynamicArguments(arguments, selector.callStructure));
1897 }
1898
1899 @override
1900 ir.Primitive errorNonConstantConstructorInvoke(
1901 ast.NewExpression node,
1902 Element element,
1903 InterfaceType type,
1904 ast.NodeList arguments,
1905 CallStructure callStructure, _) {
1906 assert(compiler.compilationFailed);
1907 return irBuilder.buildNullConstant();
1908 }
1909
1910 @override
1911 ir.Primitive visitUnresolvedGet(
1912 ast.Send node,
1913 Element element, _) {
1914 return buildStaticNoSuchMethod(elements.getSelector(node), []);
1915 }
1916
1917 @override
1918 ir.Primitive visitUnresolvedInvoke(
1919 ast.Send node,
1920 Element element,
1921 ast.NodeList arguments,
1922 Selector selector, _) {
1923 return buildStaticNoSuchMethod(elements.getSelector(node),
1924 arguments.nodes.mapToList(visit));
1925 }
1926
1927 @override
1928 ir.Primitive errorUnresolvedPostfix(
1929 ast.Send node,
1930 Element element,
1931 op.IncDecOperator operator, _) {
1932 // TODO(asgerf): Which ones are missing? The getter and/or the setter?
1933 return buildStaticNoSuchMethod(elements.getSelector(node), []);
1934 }
1935
1936 @override
1937 ir.Primitive errorUnresolvedPrefix(
1938 ast.Send node,
1939 Element element,
1940 op.IncDecOperator operator, _) {
1941 // TODO(asgerf): Which ones are missing? The getter and/or the setter?
1942 return buildStaticNoSuchMethod(elements.getSelector(node), []);
1943 }
1944
1945 @override
1946 ir.Primitive visitUnresolvedRedirectingFactoryConstructorInvoke(
1947 ast.NewExpression node,
1948 ConstructorElement constructor,
1949 InterfaceType type,
1950 ast.NodeList arguments,
1951 CallStructure callStructure, _) {
1952 String nameString = Elements.reconstructConstructorName(constructor);
1953 Name name = new Name(nameString, constructor.library);
1954 return buildStaticNoSuchMethod(
1955 new Selector(SelectorKind.CALL, name, callStructure),
1956 translateDynamicArguments(arguments, callStructure));
1957 }
1958
1959 @override
1960 ir.Primitive errorUnresolvedSet(
1961 ast.Send node,
1962 Element element,
1963 ast.Node rhs, _) {
1964 return buildStaticNoSuchMethod(elements.getSelector(node), [visit(rhs)]);
1965 }
1966
1967 @override
1968 ir.Primitive errorUnresolvedSuperCompoundIndexSet(
1969 ast.SendSet node,
1970 Element element,
1971 ast.Node index,
1972 op.AssignmentOperator operator,
1973 ast.Node rhs, _) {
1974 // Assume the index getter is missing.
1975 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
1976 return buildInstanceNoSuchMethod(selector, [visit(index)]);
1977 }
1978
1979 @override
1980 ir.Primitive visitUnresolvedSuperIndex(
1981 ast.Send node,
1982 Element function,
1983 ast.Node index, _) {
1984 // Assume the index getter is missing.
1985 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
1986 return buildInstanceNoSuchMethod(selector, [visit(index)]);
1987 }
1988
1989 @override
1990 ir.Primitive errorUnresolvedSuperIndexPostfix(
1991 ast.Send node,
1992 Element function,
1993 ast.Node index,
1994 op.IncDecOperator operator, _) {
1995 // Assume the index getter is missing.
1996 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
1997 return buildInstanceNoSuchMethod(selector, [visit(index)]);
1998 }
1999
2000 @override
2001 ir.Primitive errorUnresolvedSuperIndexPrefix(
2002 ast.Send node,
2003 Element function,
2004 ast.Node index,
2005 op.IncDecOperator operator, _) {
2006 // Assume the index getter is missing.
2007 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
2008 return buildInstanceNoSuchMethod(selector, [visit(index)]);
2009 }
2010
2011 @override
2012 ir.Primitive errorUnresolvedSuperIndexSet(
2013 ast.SendSet node,
2014 Element element,
2015 ast.Node index,
2016 ast.Node rhs, _) {
2017 Selector selector = useSelectorTypeOfNode(new Selector.index(), node);
2018 return buildInstanceNoSuchMethod(
2019 selector,
2020 [visit(index), visit(rhs)]);
2021 }
2022
2023 @override
2024 ir.Primitive visitUnresolvedSuperBinary(
2025 ast.Send node,
2026 Element element,
2027 op.BinaryOperator operator,
2028 ast.Node argument, _) {
2029 return buildInstanceNoSuchMethod(
2030 elements.getSelector(node),
2031 [visit(argument)]);
2032 }
2033
2034 @override
2035 ir.Primitive visitUnresolvedSuperUnary(
2036 ast.Send node,
2037 op.UnaryOperator operator,
2038 Element element, _) {
2039 return buildInstanceNoSuchMethod(elements.getSelector(node), []);
2040 }
2041
2042 @override
2043 ir.Primitive errorUndefinedBinaryExpression(
2044 ast.Send node,
2045 ast.Node left,
2046 ast.Operator operator,
2047 ast.Node right, _) {
2048 assert(compiler.compilationFailed);
2049 return irBuilder.buildNullConstant();
2050 }
2051
2052 @override
2053 ir.Primitive errorUndefinedUnaryExpression(
2054 ast.Send node,
2055 ast.Operator operator,
2056 ast.Node expression, _) {
2057 assert(compiler.compilationFailed);
2058 return irBuilder.buildNullConstant();
2059 }
2060
2061 @override
2062 ir.Primitive errorTopLevelFunctionSet(
2063 ast.Send node,
2064 MethodElement function,
2065 ast.Node rhs, _) {
2066 return buildStaticNoSuchMethod(
2067 new Selector.setter(function.name, function.library),
2068 [visit(rhs)]);
2069 }
2070
2071 @override
2072 ir.Primitive errorTopLevelSetterGet(
2073 ast.Send node,
2074 FunctionElement setter, _) {
2075 return buildStaticNoSuchMethod(
2076 new Selector.getter(setter.name, setter.library), []);
2077 }
2078
2079 @override
2080 ir.Primitive errorTopLevelGetterSet(
2081 ast.SendSet node,
2082 FunctionElement getter,
2083 ast.Node rhs, _) {
2084 return buildStaticNoSuchMethod(
2085 new Selector.setter(getter.name, getter.library),
2086 [visit(rhs)]);
2087 }
2088
2089 @override
2090 ir.Primitive errorTopLevelSetterInvoke(
2091 ast.Send node,
2092 FunctionElement setter,
2093 ast.NodeList arguments,
2094 CallStructure callStructure, _) {
2095 return buildStaticNoSuchMethod(
2096 new Selector.getter(setter.name, setter.library), []);
2097 }
2098
2099 @override
2100 ir.Primitive errorClassTypeLiteralSet(
2101 ast.SendSet node,
2102 TypeConstantExpression constant,
2103 ast.Node rhs, _) {
2104 InterfaceType type = constant.type;
2105 ClassElement element = type.element;
2106 return buildStaticNoSuchMethod(
2107 new Selector.setter(element.name, element.library), [visit(rhs)]);
2108 }
2109
2110 @override
2111 ir.Primitive errorTypedefTypeLiteralSet(
2112 ast.SendSet node,
2113 TypeConstantExpression constant,
2114 ast.Node rhs, _) {
2115 TypedefType type = constant.type;
2116 TypedefElement element = type.element;
2117 return buildStaticNoSuchMethod(
2118 new Selector.setter(element.name, element.library), [visit(rhs)]);
2119 }
2120
2121 @override
2122 ir.Primitive errorTypeVariableTypeLiteralSet(
2123 ast.SendSet node,
2124 TypeVariableElement element,
2125 ast.Node rhs, _) {
2126 return buildStaticNoSuchMethod(
2127 new Selector.setter(element.name, element.library), [visit(rhs)]);
2128 }
2129
2130 @override
2131 ir.Primitive errorDynamicTypeLiteralSet(
2132 ast.SendSet node,
2133 ConstantExpression constant,
2134 ast.Node rhs, _) {
2135 return buildStaticNoSuchMethod(
2136 new Selector.setter('dynamic', null), [visit(rhs)]);
2137 }
2138
2139 @override
2140 ir.Primitive visitAbstractClassConstructorInvoke(
2141 ast.NewExpression node,
2142 ConstructorElement element,
2143 InterfaceType type,
2144 ast.NodeList arguments,
2145 CallStructure callStructure, _) {
2146 return buildAbstractClassInstantiationError(element.enclosingClass);
2147 }
2148
2149 @override
2150 ir.Primitive errorClassTypeLiteralCompound(
2151 ast.Send node,
2152 ConstantExpression constant,
2153 op.AssignmentOperator operator,
2154 ast.Node rhs, _) {
2155 return translateCompound(
2156 getValue: () => irBuilder.buildConstant(constant),
2157 operator: operator,
2158 rhs: rhs,
2159 setValue: (value) {}); // The binary operator will throw before this.
2160 }
2161
2162 @override
2163 ir.Primitive errorClassTypeLiteralPostfix(
2164 ast.Send node,
2165 ConstantExpression constant,
2166 op.IncDecOperator operator, _) {
2167 return translatePrefixPostfix(
2168 getValue: () => irBuilder.buildConstant(constant),
2169 operator: operator,
2170 setValue: (value) {}, // The binary operator will throw before this.
2171 isPrefix: false);
2172 }
2173
2174 @override
2175 ir.Primitive errorClassTypeLiteralPrefix(
2176 ast.Send node,
2177 ConstantExpression constant,
2178 op.IncDecOperator operator, _) {
2179 return translatePrefixPostfix(
2180 getValue: () => irBuilder.buildConstant(constant),
2181 operator: operator,
2182 setValue: (value) {}, // The binary operator will throw before this.
2183 isPrefix: true);
2184 }
2185
2186 @override
2187 ir.Primitive errorDynamicTypeLiteralCompound(
2188 ast.Send node,
2189 ConstantExpression constant,
2190 op.AssignmentOperator operator,
2191 ast.Node rhs, _) {
2192 return translateCompound(
2193 getValue: () => irBuilder.buildConstant(constant),
2194 operator: operator,
2195 rhs: rhs,
2196 setValue: (value) {}); // The binary operator will throw before this.
2197 }
2198
2199 @override
2200 ir.Primitive errorDynamicTypeLiteralPostfix(
2201 ast.Send node,
2202 ConstantExpression constant,
2203 op.IncDecOperator operator, _) {
2204 return translatePrefixPostfix(
2205 getValue: () => irBuilder.buildConstant(constant),
2206 operator: operator,
2207 setValue: (value) {}, // The binary operator will throw before this.
2208 isPrefix: false);
2209 }
2210
2211 @override
2212 ir.Primitive errorDynamicTypeLiteralPrefix(
2213 ast.Send node,
2214 ConstantExpression constant,
2215 op.IncDecOperator operator, _) {
2216 return translatePrefixPostfix(
2217 getValue: () => irBuilder.buildConstant(constant),
2218 operator: operator,
2219 setValue: (value) {}, // The binary operator will throw before this.
2220 isPrefix: true);
2221 }
2222
2223 @override
2224 ir.Primitive errorFinalLocalVariableCompound(
2225 ast.Send node,
2226 LocalVariableElement variable,
2227 op.AssignmentOperator operator,
2228 ast.Node rhs, _) {
2229 Selector selector = new Selector.setter(variable.name, null);
2230 return translateCompound(
2231 getValue: () => irBuilder.buildLocalVariableGet(variable),
2232 operator: operator,
2233 rhs: rhs,
2234 setValue: (value) => buildStaticNoSuchMethod(selector, [value]));
2235 }
2236
2237 @override
2238 ir.Primitive errorFinalLocalVariableSet(
2239 ast.SendSet node,
2240 LocalVariableElement variable,
2241 ast.Node rhs, _) {
2242 Selector selector = new Selector.setter(variable.name, null);
2243 return buildStaticNoSuchMethod(selector, [visit(rhs)]);
2244 }
2245
2246 @override
2247 ir.Primitive errorFinalParameterCompound(
2248 ast.Send node,
2249 ParameterElement parameter,
2250 op.AssignmentOperator operator,
2251 ast.Node rhs, _) {
2252 Selector selector = new Selector.setter(parameter.name, null);
2253 return translateCompound(
2254 getValue: () => irBuilder.buildLocalVariableGet(parameter),
2255 operator: operator,
2256 rhs: rhs,
2257 setValue: (value) => buildStaticNoSuchMethod(selector, [value]));
2258 }
2259
2260 @override
2261 ir.Primitive errorFinalParameterSet(
2262 ast.SendSet node,
2263 ParameterElement parameter,
2264 ast.Node rhs, _) {
2265 Selector selector = new Selector.setter(parameter.name, null);
2266 return buildStaticNoSuchMethod(selector, [visit(rhs)]);
2267 }
2268
2269 @override
2270 ir.Primitive errorFinalStaticFieldCompound(
2271 ast.Send node,
2272 FieldElement field,
2273 op.AssignmentOperator operator,
2274 ast.Node rhs, _) {
2275 return translateCompound(
2276 getValue: () => irBuilder.buildStaticFieldGet(field),
2277 operator: operator,
2278 rhs: rhs,
2279 setValue: (value) => buildStaticNoSuchMethod(
2280 new Selector.setter(field.name, field.library), [value]));
2281 }
2282
2283 @override
2284 ir.Primitive errorFinalStaticFieldSet(
2285 ast.SendSet node,
2286 FieldElement field,
2287 ast.Node rhs, _) {
2288 // TODO(asgerf): Include class name somehow?
2289 return buildStaticNoSuchMethod(
2290 new Selector.setter(field.name, field.library),
2291 [visit(rhs)]);
2292 }
2293
2294 @override
2295 ir.Primitive errorFinalSuperFieldCompound(
2296 ast.Send node,
2297 FieldElement field,
2298 op.AssignmentOperator operator,
2299 ast.Node rhs, _) {
2300 Selector selector = useSelectorTypeOfNode(
2301 new Selector.setter(field.name, field.library),
2302 node);
2303 return translateCompound(
2304 getValue: () => irBuilder.buildSuperFieldGet(field),
2305 operator: operator,
2306 rhs: rhs,
2307 setValue: (value) => buildInstanceNoSuchMethod(selector, [value]));
2308 }
2309
2310 @override
2311 ir.Primitive errorFinalSuperFieldSet(
2312 ast.SendSet node,
2313 FieldElement field,
2314 ast.Node rhs, _) {
2315 Selector selector = useSelectorTypeOfNode(
2316 new Selector.setter(field.name, field.library),
2317 node);
2318 return buildInstanceNoSuchMethod(selector, [visit(rhs)]);
2319 }
2320
2321 @override
2322 ir.Primitive errorFinalTopLevelFieldCompound(
2323 ast.Send node,
2324 FieldElement field,
2325 op.AssignmentOperator operator,
2326 ast.Node rhs, _) {
2327 return translateCompound(
2328 getValue: () => irBuilder.buildStaticFieldGet(field),
2329 operator: operator,
2330 rhs: rhs,
2331 setValue: (value) => buildStaticNoSuchMethod(
2332 new Selector.setter(field.name, field.library), [value]));
2333 }
2334
2335 @override
2336 ir.Primitive errorFinalTopLevelFieldSet(
2337 ast.SendSet node,
2338 FieldElement field,
2339 ast.Node rhs, _) {
2340 return buildStaticNoSuchMethod(
2341 new Selector.setter(field.name, field.library),
2342 [visit(rhs)]);
2343 }
2344
2345 @override
2346 ir.Primitive errorLocalFunctionCompound(
2347 ast.Send node,
2348 LocalFunctionElement function,
2349 op.AssignmentOperator operator,
2350 ast.Node rhs, _) {
2351 return translateCompound(
2352 getValue: () => irBuilder.buildLocalFunctionGet(function),
2353 operator: operator,
2354 rhs: rhs,
2355 setValue: (value) {}); // Binary operator will throw before this.
2356 }
2357
2358 @override
2359 ir.Primitive errorLocalFunctionPostfix(
2360 ast.Send node,
2361 LocalFunctionElement function,
2362 op.IncDecOperator operator,
2363 _) {
2364 return translatePrefixPostfix(
2365 getValue: () => irBuilder.buildLocalFunctionGet(function),
2366 operator: operator,
2367 setValue: (value) {}, // Binary operator will throw before this.
2368 isPrefix: false);
2369 }
2370
2371 @override
2372 ir.Primitive errorLocalFunctionPrefix(
2373 ast.Send node,
2374 LocalFunctionElement function,
2375 op.IncDecOperator operator,
2376 _) {
2377 return translatePrefixPostfix(
2378 getValue: () => irBuilder.buildLocalFunctionGet(function),
2379 operator: operator,
2380 setValue: (value) {}, // Binary operator will throw before this.
2381 isPrefix: true);
2382 }
2383
2384 @override
2385 ir.Primitive errorLocalFunctionSet(
2386 ast.SendSet node,
2387 LocalFunctionElement function,
2388 ast.Node rhs, _) {
2389 return buildStaticNoSuchMethod(
2390 new Selector.setter(function.name, null),
2391 [visit(rhs)]);
2392 }
2393
2394 @override
2395 ir.Primitive errorStaticFunctionSet(
2396 ast.Send node,
2397 MethodElement function,
2398 ast.Node rhs,
2399 _) {
2400 return buildStaticNoSuchMethod(
2401 new Selector.setter(function.name, function.library),
2402 [visit(rhs)]);
2403 }
2404
2405 @override
2406 ir.Primitive errorStaticGetterSet(
2407 ast.SendSet node,
2408 FunctionElement getter,
2409 ast.Node rhs,
2410 _) {
2411 return buildStaticNoSuchMethod(
2412 new Selector.setter(getter.name, getter.library),
2413 [visit(rhs)]);
2414 }
2415
2416 @override
2417 ir.Primitive errorStaticSetterGet(
2418 ast.Send node,
2419 FunctionElement setter,
2420 _) {
2421 return buildStaticNoSuchMethod(
2422 new Selector.getter(setter.name, setter.library),
2423 []);
2424 }
2425
2426 @override
2427 ir.Primitive errorStaticSetterInvoke(
2428 ast.Send node,
2429 FunctionElement setter,
2430 ast.NodeList arguments,
2431 CallStructure callStructure, _) {
2432 // Translate as a method call.
2433 List<ir.Primitive> args = arguments.nodes.mapToList(visit);
2434 Name name = new Name(setter.name, setter.library);
2435 return buildStaticNoSuchMethod(
2436 new Selector(SelectorKind.CALL, name, callStructure),
2437 args);
2438 }
2439
2440 @override
2441 ir.Primitive errorSuperGetterSet(
2442 ast.SendSet node,
2443 FunctionElement getter,
2444 ast.Node rhs,
2445 _) {
2446 Selector selector = useSelectorTypeOfNode(
2447 new Selector.setter(getter.name, getter.library),
2448 node);
2449 return buildInstanceNoSuchMethod(selector, [visit(rhs)]);
2450 }
2451
2452 @override
2453 ir.Primitive errorSuperMethodSet(
2454 ast.Send node,
2455 MethodElement method,
2456 ast.Node rhs,
2457 _) {
2458 Selector selector = useSelectorTypeOfNode(
2459 new Selector.setter(method.name, method.library),
2460 node);
2461 return buildInstanceNoSuchMethod(selector, [visit(rhs)]);
2462 }
2463
2464 @override
2465 ir.Primitive errorSuperSetterGet(
2466 ast.Send node,
2467 FunctionElement setter, _) {
2468 Selector selector = useSelectorTypeOfNode(
2469 new Selector.setter(setter.name, setter.library),
2470 node);
2471 return buildInstanceNoSuchMethod(selector, []);
2472 }
2473
2474 @override
2475 ir.Primitive errorSuperSetterInvoke(
2476 ast.Send node,
2477 FunctionElement setter,
2478 ast.NodeList arguments,
2479 CallStructure callStructure, _) {
2480 List<ir.Primitive> args =
2481 translateDynamicArguments(arguments, callStructure);
2482 Name name = new Name(setter.name, setter.library);
2483 Selector selector = useSelectorTypeOfNode(
2484 new Selector(SelectorKind.CALL, name, callStructure),
2485 node);
2486 return buildInstanceNoSuchMethod(selector, args);
2487 }
2488
2489 @override
2490 ir.Primitive errorTypeVariableTypeLiteralCompound(
2491 ast.Send node,
2492 TypeVariableElement element,
2493 op.AssignmentOperator operator,
2494 ast.Node rhs, _) {
2495 ir.Primitive receiver = irBuilder.buildThis();
2496 return translateCompound(
2497 getValue: () => buildReifyTypeVariable(receiver, element.type),
2498 operator: operator,
2499 rhs: rhs,
2500 setValue: (value) {}); // The binary operator will throw before this.
2501 }
2502
2503 @override
2504 ir.Primitive errorTypeVariableTypeLiteralPostfix(
2505 ast.Send node,
2506 TypeVariableElement element,
2507 op.IncDecOperator operator, _) {
2508 ir.Primitive receiver = irBuilder.buildThis();
2509 return translatePrefixPostfix(
2510 getValue: () => buildReifyTypeVariable(receiver, element.type),
2511 operator: operator,
2512 setValue: (value) {}, // The binary operator will throw before this.
2513 isPrefix: false);
2514 }
2515
2516 @override
2517 ir.Primitive errorTypeVariableTypeLiteralPrefix(
2518 ast.Send node,
2519 TypeVariableElement element,
2520 op.IncDecOperator operator, _) {
2521 ir.Primitive receiver = irBuilder.buildThis();
2522 return translatePrefixPostfix(
2523 getValue: () => buildReifyTypeVariable(receiver, element.type),
2524 operator: operator,
2525 setValue: (value) {}, // The binary operator will throw before this.
2526 isPrefix: true);
2527 }
2528
2529 @override
2530 ir.Primitive errorTypedefTypeLiteralCompound(
2531 ast.Send node,
2532 ConstantExpression constant,
2533 op.AssignmentOperator operator,
2534 ast.Node rhs, _) {
2535 return translateCompound(
2536 getValue: () => irBuilder.buildConstant(constant),
2537 operator: operator,
2538 rhs: rhs,
2539 setValue: (value) {}); // The binary operator will throw before this.
2540 }
2541
2542 @override
2543 ir.Primitive errorTypedefTypeLiteralPostfix(
2544 ast.Send node,
2545 ConstantExpression constant,
2546 op.IncDecOperator operator, _) {
2547 return translatePrefixPostfix(
2548 getValue: () => irBuilder.buildConstant(constant),
2549 operator: operator,
2550 setValue: (value) {}, // The binary operator will throw before this.
2551 isPrefix: false);
2552 }
2553
2554 @override
2555 ir.Primitive errorTypedefTypeLiteralPrefix(
2556 ast.Send node,
2557 TypeConstantExpression constant,
2558 op.IncDecOperator operator, _) {
2559 return translatePrefixPostfix(
2560 getValue: () => irBuilder.buildConstant(constant),
2561 operator: operator,
2562 setValue: (value) {}, // The binary operator will throw before this.
2563 isPrefix: true);
2564 }
2565
1870 ir.RootNode nullIfGiveup(ir.RootNode action()) { 2566 ir.RootNode nullIfGiveup(ir.RootNode action()) {
1871 try { 2567 try {
1872 return action(); 2568 return action();
1873 } catch(e) { 2569 } catch(e) {
1874 if (e == ABORT_IRNODE_BUILDER) { 2570 if (e == ABORT_IRNODE_BUILDER) {
1875 return null; 2571 return null;
1876 } 2572 }
1877 rethrow; 2573 rethrow;
1878 } 2574 }
1879 } 2575 }
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2206 ast.NodeList arguments, 2902 ast.NodeList arguments,
2207 CallStructure callStructure, _) { 2903 CallStructure callStructure, _) {
2208 List<ir.Primitive> arguments = 2904 List<ir.Primitive> arguments =
2209 node.send.arguments.mapToList(visit, growable:false); 2905 node.send.arguments.mapToList(visit, growable:false);
2210 return irBuilder.buildConstructorInvocation( 2906 return irBuilder.buildConstructorInvocation(
2211 constructor, 2907 constructor,
2212 callStructure, 2908 callStructure,
2213 type, 2909 type,
2214 arguments); 2910 arguments);
2215 } 2911 }
2912
2913 @override
2914 ir.Primitive buildStaticNoSuchMethod(Selector selector,
2915 List<ir.Primitive> arguments) {
2916 return giveup(null, 'Static noSuchMethod');
2917 }
2918
2919 @override
2920 ir.Primitive buildInstanceNoSuchMethod(Selector selector,
2921 List<ir.Primitive> arguments) {
2922 return giveup(null, 'Instance noSuchMethod');
2923 }
2924
2925 @override
2926 ir.Primitive buildRuntimeError(String message) {
2927 return giveup(null, 'Build runtime error: $message');
2928 }
2929
2930 @override
2931 ir.Primitive buildAbstractClassInstantiationError(ClassElement element) {
2932 return giveup(null, 'Abstract class instantiation: ${element.name}');
2933 }
2216 } 2934 }
2217 2935
2218 /// The [IrBuilder]s view on the information about the program that has been 2936 /// The [IrBuilder]s view on the information about the program that has been
2219 /// computed in resolution and and type interence. 2937 /// computed in resolution and and type interence.
2220 class GlobalProgramInformation { 2938 class GlobalProgramInformation {
2221 final Compiler _compiler; 2939 final Compiler _compiler;
2222 JavaScriptBackend get _backend => _compiler.backend; 2940 JavaScriptBackend get _backend => _compiler.backend;
2223 2941
2224 GlobalProgramInformation(this._compiler); 2942 GlobalProgramInformation(this._compiler);
2225 2943
2226 /// Returns [true], if the analysis could not determine that the type 2944 /// Returns [true], if the analysis could not determine that the type
2227 /// arguments for the class [cls] are never used in the program. 2945 /// arguments for the class [cls] are never used in the program.
2228 bool requiresRuntimeTypesFor(ClassElement cls) { 2946 bool requiresRuntimeTypesFor(ClassElement cls) {
2229 return cls.typeVariables.isNotEmpty && _backend.classNeedsRti(cls); 2947 return cls.typeVariables.isNotEmpty && _backend.classNeedsRti(cls);
2230 } 2948 }
2231 } 2949 }
2232 2950
2233 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder]. 2951 /// IR builder specific to the JavaScript backend, coupled to the [JsIrBuilder].
2234 class JsIrBuilderVisitor extends IrBuilderVisitor { 2952 class JsIrBuilderVisitor extends IrBuilderVisitor {
2235 /// Promote the type of [irBuilder] to [JsIrBuilder]. 2953 /// Promote the type of [irBuilder] to [JsIrBuilder].
2236 JsIrBuilder get irBuilder => super.irBuilder; 2954 JsIrBuilder get irBuilder => super.irBuilder;
2237 2955
2956 JavaScriptBackend get backend => compiler.backend;
2957
2238 /// Result of closure conversion for the current body of code. 2958 /// Result of closure conversion for the current body of code.
2239 /// 2959 ///
2240 /// Will be initialized upon entering the body of a function. 2960 /// Will be initialized upon entering the body of a function.
2241 /// It is computed by the [ClosureTranslator]. 2961 /// It is computed by the [ClosureTranslator].
2242 ClosureClassMap closureMap; 2962 ClosureClassMap closureMap;
2243 2963
2244 /// During construction of a constructor factory, [fieldValues] maps fields 2964 /// During construction of a constructor factory, [fieldValues] maps fields
2245 /// to the primitive containing their initial value. 2965 /// to the primitive containing their initial value.
2246 Map<FieldElement, ir.Primitive> fieldValues = <FieldElement, ir.Primitive>{}; 2966 Map<FieldElement, ir.Primitive> fieldValues = <FieldElement, ir.Primitive>{};
2247 2967
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2838 List<ir.Primitive> arguments = 3558 List<ir.Primitive> arguments =
2839 node.send.arguments.mapToList(visit, growable:false); 3559 node.send.arguments.mapToList(visit, growable:false);
2840 arguments = normalizeStaticArguments( 3560 arguments = normalizeStaticArguments(
2841 callStructure, constructor, arguments); 3561 callStructure, constructor, arguments);
2842 return irBuilder.buildConstructorInvocation( 3562 return irBuilder.buildConstructorInvocation(
2843 constructor.effectiveTarget, 3563 constructor.effectiveTarget,
2844 callStructure, 3564 callStructure,
2845 constructor.computeEffectiveTargetType(type), 3565 constructor.computeEffectiveTargetType(type),
2846 arguments); 3566 arguments);
2847 } 3567 }
3568
3569 @override
3570 ir.Primitive buildStaticNoSuchMethod(Selector selector,
3571 List<ir.Primitive> arguments) {
3572 Element thrower = backend.getThrowNoSuchMethod();
3573 ir.Primitive receiver = irBuilder.buildStringConstant('');
3574 ir.Primitive name = irBuilder.buildStringConstant(selector.name);
3575 ir.Primitive argumentList = irBuilder.buildListLiteral(null, arguments);
3576 ir.Primitive expectedArgumentNames = irBuilder.buildNullConstant();
3577 return irBuilder.buildStaticFunctionInvocation(
3578 thrower,
3579 new CallStructure.unnamed(4),
3580 [receiver, name, argumentList, expectedArgumentNames]);
3581 }
3582
3583 @override
3584 ir.Primitive buildInstanceNoSuchMethod(Selector selector,
3585 List<ir.Primitive> arguments) {
3586 return irBuilder.buildDynamicInvocation(
3587 irBuilder.buildThis(),
3588 useSelectorType(compiler.noSuchMethodSelector, selector),
3589 [irBuilder.buildInvocationMirror(selector, arguments)]);
3590 }
3591
3592 @override
3593 ir.Primitive buildRuntimeError(String message) {
3594 return irBuilder.buildStaticFunctionInvocation(
3595 backend.getThrowRuntimeError(),
3596 new CallStructure.unnamed(1),
3597 [irBuilder.buildStringConstant(message)]);
3598 }
3599
3600 @override
3601 ir.Primitive buildAbstractClassInstantiationError(ClassElement element) {
3602 return irBuilder.buildStaticFunctionInvocation(
3603 backend.getThrowAbstractClassInstantiationError(),
3604 new CallStructure.unnamed(1),
3605 [irBuilder.buildStringConstant(element.name)]);
3606 }
2848 } 3607 }
2849 3608
2850 /// Perform simple post-processing on the initial CPS-translated root term. 3609 /// Perform simple post-processing on the initial CPS-translated root term.
2851 /// 3610 ///
2852 /// This pass performs backend-independent post-processing on the translated 3611 /// This pass performs backend-independent post-processing on the translated
2853 /// term. It is implemented separately from the optimization passes because 3612 /// term. It is implemented separately from the optimization passes because
2854 /// it is required for correctness of the implementation. 3613 /// it is required for correctness of the implementation.
2855 /// 3614 ///
2856 /// It performs the following translations: 3615 /// It performs the following translations:
2857 /// - Replace [ir.LetPrim] binding a [ir.NonTailThrow] with a [ir.Throw] 3616 /// - 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); 3665 node.body = replacementFor(node.body);
2907 } 3666 }
2908 } 3667 }
2909 3668
2910 /// Visit a just-deleted subterm and unlink all [Reference]s in it. 3669 /// Visit a just-deleted subterm and unlink all [Reference]s in it.
2911 class RemovalVisitor extends ir.RecursiveVisitor { 3670 class RemovalVisitor extends ir.RecursiveVisitor {
2912 processReference(ir.Reference reference) { 3671 processReference(ir.Reference reference) {
2913 reference.unlink(); 3672 reference.unlink();
2914 } 3673 }
2915 } 3674 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698