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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ir/ir_builder.dart

Issue 349923004: Add support for superSend to the new IR and dart backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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; 5 library dart2js.ir_builder;
6 6
7 import 'ir_nodes.dart' as ir; 7 import 'ir_nodes.dart' as ir;
8 import '../elements/elements.dart'; 8 import '../elements/elements.dart';
9 import '../dart2jslib.dart'; 9 import '../dart2jslib.dart';
10 import '../dart_types.dart'; 10 import '../dart_types.dart';
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 805
806 ir.Primitive visitLiteralSymbol(ast.LiteralSymbol node) { 806 ir.Primitive visitLiteralSymbol(ast.LiteralSymbol node) {
807 assert(isOpen); 807 assert(isOpen);
808 ir.Constant constant = new ir.Constant(getConstantForNode(node)); 808 ir.Constant constant = new ir.Constant(getConstantForNode(node));
809 add(new ir.LetPrim(constant)); 809 add(new ir.LetPrim(constant));
810 return constant; 810 return constant;
811 } 811 }
812 812
813 ir.Primitive visitIdentifier(ast.Identifier node) { 813 ir.Primitive visitIdentifier(ast.Identifier node) {
814 assert(isOpen); 814 assert(isOpen);
815 assert(node.isThis()); 815 if (node.isThis()) {
816 return lookupThis(); 816 return lookupThis();
817 } else if (node.isSuper()) {
818 return lookupSuper();
819 } else {
820 // super and this are the only identifiers that should be met by the
821 // visitor.
822 assert(false);
823 return null;
824 }
817 } 825 }
818 826
819 ir.Primitive visitParenthesizedExpression( 827 ir.Primitive visitParenthesizedExpression(
820 ast.ParenthesizedExpression node) { 828 ast.ParenthesizedExpression node) {
821 assert(isOpen); 829 assert(isOpen);
822 return visit(node.expression); 830 return visit(node.expression);
823 } 831 }
824 832
825 // Stores the result of visiting a CascadeReceiver, so we can return it from 833 // Stores the result of visiting a CascadeReceiver, so we can return it from
826 // its enclosing Cascade. 834 // its enclosing Cascade.
(...skipping 14 matching lines...) Expand all
841 _currentCascadeReceiver = oldCascadeReceiver; 849 _currentCascadeReceiver = oldCascadeReceiver;
842 return receiver; 850 return receiver;
843 } 851 }
844 852
845 ir.Primitive lookupThis() { 853 ir.Primitive lookupThis() {
846 ir.Primitive result = new ir.This(); 854 ir.Primitive result = new ir.This();
847 add(new ir.LetPrim(result)); 855 add(new ir.LetPrim(result));
848 return result; 856 return result;
849 } 857 }
850 858
859 ir.Primitive lookupSuper() {
860 ir.Primitive result = new ir.Super();
861 add(new ir.LetPrim(result));
862 return result;
863 }
864
851 ir.Primitive lookupLocal(Element element) { 865 ir.Primitive lookupLocal(Element element) {
852 int index = variableIndex[element]; 866 int index = variableIndex[element];
853 ir.Primitive value = assignedVars[index]; 867 ir.Primitive value = assignedVars[index];
854 return value == null ? freeVars[index] : value; 868 return value == null ? freeVars[index] : value;
855 } 869 }
856 870
857 // ==== Sends ==== 871 // ==== Sends ====
858 ir.Primitive visitAssert(ast.Send node) { 872 ir.Primitive visitAssert(ast.Send node) {
859 assert(isOpen); 873 assert(isOpen);
860 return giveup(node, 'Assert'); 874 return giveup(node, 'Assert');
(...skipping 28 matching lines...) Expand all
889 ir.Parameter v = new ir.Parameter(null); 903 ir.Parameter v = new ir.Parameter(null);
890 ir.Continuation k = new ir.Continuation([v]); 904 ir.Continuation k = new ir.Continuation([v]);
891 ir.Expression invoke = 905 ir.Expression invoke =
892 new ir.InvokeMethod(closureTarget, namedCallSelector, k, arguments); 906 new ir.InvokeMethod(closureTarget, namedCallSelector, k, arguments);
893 add(new ir.LetCont(k, invoke)); 907 add(new ir.LetCont(k, invoke));
894 return v; 908 return v;
895 } 909 }
896 910
897 ir.Primitive visitDynamicSend(ast.Send node) { 911 ir.Primitive visitDynamicSend(ast.Send node) {
898 assert(isOpen); 912 assert(isOpen);
899 if (node.receiver == null || node.receiver.isSuper()) { 913 if (node.receiver == null) {
900 return giveup(node, 'DynamicSend without receiver, or super receiver'); 914 return giveup(node, 'DynamicSend without receiver');
901 } 915 }
902 Selector selector = elements.getSelector(node); 916 Selector selector = elements.getSelector(node);
903 ir.Primitive receiver = visit(node.receiver); 917 ir.Primitive receiver = visit(node.receiver);
904 List<ir.Primitive> arguments = new List<ir.Primitive>(); 918 List<ir.Primitive> arguments = new List<ir.Primitive>();
905 for (ast.Node n in node.arguments) { 919 for (ast.Node n in node.arguments) {
906 arguments.add(visit(n)); 920 arguments.add(visit(n));
907 } 921 }
908 ir.Parameter v = new ir.Parameter(null); 922 ir.Parameter v = new ir.Parameter(null);
909 ir.Continuation k = new ir.Continuation([v]); 923 ir.Continuation k = new ir.Continuation([v]);
910 ir.Expression invoke = 924 ir.Expression invoke =
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 ir.Parameter v = new ir.Parameter(null); 1129 ir.Parameter v = new ir.Parameter(null);
1116 ir.Continuation k = new ir.Continuation([v]); 1130 ir.Continuation k = new ir.Continuation([v]);
1117 ir.Expression invoke = 1131 ir.Expression invoke =
1118 new ir.InvokeStatic(element, selector, k, arguments); 1132 new ir.InvokeStatic(element, selector, k, arguments);
1119 add(new ir.LetCont(k, invoke)); 1133 add(new ir.LetCont(k, invoke));
1120 return v; 1134 return v;
1121 } 1135 }
1122 1136
1123 ir.Primitive visitSuperSend(ast.Send node) { 1137 ir.Primitive visitSuperSend(ast.Send node) {
1124 assert(isOpen); 1138 assert(isOpen);
1125 return giveup(node, 'SuperSend'); 1139 if (node.isPropertyAccess) {
1140 return visitGetterSend(node);
1141 } else {
1142 return visitDynamicSend(node);
1143 }
1126 } 1144 }
1127 1145
1128 ir.Primitive visitTypeReferenceSend(ast.Send node) { 1146 ir.Primitive visitTypeReferenceSend(ast.Send node) {
1129 assert(isOpen); 1147 assert(isOpen);
1130 if (node.argumentsNode != null) { 1148 if (node.argumentsNode != null) {
1131 // May happen in strange, invalid code. 1149 // May happen in strange, invalid code.
1132 // TODO(asgerf): Generate code that throws a runtime error. 1150 // TODO(asgerf): Generate code that throws a runtime error.
1133 return giveup(node, 'TypeReferenceSend: has argument'); 1151 return giveup(node, 'TypeReferenceSend: has argument');
1134 } 1152 }
1135 Element element = elements[node]; 1153 Element element = elements[node];
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 new ir.InvokeStatic(element, selector, k, [arg]); 1192 new ir.InvokeStatic(element, selector, k, [arg]);
1175 add(new ir.LetCont(k, invoke)); 1193 add(new ir.LetCont(k, invoke));
1176 return arg; 1194 return arg;
1177 } else if (node.receiver == null) { 1195 } else if (node.receiver == null) {
1178 // Nodes that fall in this case: 1196 // Nodes that fall in this case:
1179 // - Unresolved top-level 1197 // - Unresolved top-level
1180 // - Assignment to final variable (will not be resolved) 1198 // - Assignment to final variable (will not be resolved)
1181 return giveup(node, 'SendSet: non-local, non-static, but no receiver'); 1199 return giveup(node, 'SendSet: non-local, non-static, but no receiver');
1182 } else { 1200 } else {
1183 if (element != null && Elements.isUnresolved(element)) { 1201 if (element != null && Elements.isUnresolved(element)) {
1184 return giveup(node); 1202 return giveup(node, 'SendSet: non-local, non-static, unresolved');
1185 } 1203 }
1186 1204
1187 // Setter or index-setter invocation 1205 // Setter or index-setter invocation
1188 assert(node.receiver != null); 1206 assert(node.receiver != null);
1189 1207
1190 if (node.receiver.isSuper()) return giveup(node, 'Super SendSet'); 1208 if (node.receiver.isSuper()) return giveup(node, 'Super SendSet');
1191 1209
1192 ir.Primitive receiver = node.receiver == null 1210 ir.Primitive receiver = node.receiver == null
1193 ? lookupThis() 1211 ? lookupThis()
1194 : visit(node.receiver); 1212 : visit(node.receiver);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 1319
1302 static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted"; 1320 static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted";
1303 1321
1304 ir.Primitive giveup(ast.Node node, [String reason]) { 1322 ir.Primitive giveup(ast.Node node, [String reason]) {
1305 throw ABORT_IRNODE_BUILDER; 1323 throw ABORT_IRNODE_BUILDER;
1306 } 1324 }
1307 1325
1308 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { 1326 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) {
1309 try { 1327 try {
1310 return action(); 1328 return action();
1311 } catch(e) { 1329 } catch(e, tr) {
1312 if (e == ABORT_IRNODE_BUILDER) return null; 1330 if (e == ABORT_IRNODE_BUILDER) {
1331 return null;
1332 }
1313 rethrow; 1333 rethrow;
1314 } 1334 }
1315 } 1335 }
1316 1336
1317 void internalError(String reason, {ast.Node node}) { 1337 void internalError(String reason, {ast.Node node}) {
1318 giveup(node); 1338 giveup(node);
1319 } 1339 }
1320 } 1340 }
1321 1341
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698