| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart2js.ir_builder; | 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 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 return result; | 803 return result; |
| 804 } | 804 } |
| 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) { |
| 814 assert(isOpen); |
| 815 assert(node.isThis()); |
| 816 return lookupThis(); |
| 817 } |
| 818 |
| 813 ir.Primitive visitParenthesizedExpression( | 819 ir.Primitive visitParenthesizedExpression( |
| 814 ast.ParenthesizedExpression node) { | 820 ast.ParenthesizedExpression node) { |
| 815 assert(isOpen); | 821 assert(isOpen); |
| 816 return visit(node.expression); | 822 return visit(node.expression); |
| 817 } | 823 } |
| 818 | 824 |
| 819 // Stores the result of visiting a CascadeReceiver, so we can return it from | 825 // Stores the result of visiting a CascadeReceiver, so we can return it from |
| 820 // its enclosing Cascade. | 826 // its enclosing Cascade. |
| 821 ir.Primitive _currentCascadeReceiver; | 827 ir.Primitive _currentCascadeReceiver; |
| 822 | 828 |
| 823 ir.Primitive visitCascadeReceiver(ast.CascadeReceiver node) { | 829 ir.Primitive visitCascadeReceiver(ast.CascadeReceiver node) { |
| 824 assert(isOpen); | 830 assert(isOpen); |
| 825 return _currentCascadeReceiver = visit(node.expression); | 831 return _currentCascadeReceiver = visit(node.expression); |
| 826 } | 832 } |
| 827 | 833 |
| 828 ir.Primitive visitCascade(ast.Cascade node) { | 834 ir.Primitive visitCascade(ast.Cascade node) { |
| 829 assert(isOpen); | 835 assert(isOpen); |
| 830 var oldCascadeReceiver = _currentCascadeReceiver; | 836 var oldCascadeReceiver = _currentCascadeReceiver; |
| 831 // Throw away the result of visiting the expression. | 837 // Throw away the result of visiting the expression. |
| 832 // Instead we return the result of visiting the CascadeReceiver. | 838 // Instead we return the result of visiting the CascadeReceiver. |
| 833 this.visit(node.expression); | 839 this.visit(node.expression); |
| 834 ir.Primitive receiver = _currentCascadeReceiver; | 840 ir.Primitive receiver = _currentCascadeReceiver; |
| 835 _currentCascadeReceiver = oldCascadeReceiver; | 841 _currentCascadeReceiver = oldCascadeReceiver; |
| 836 return receiver; | 842 return receiver; |
| 837 } | 843 } |
| 838 | 844 |
| 845 ir.Primitive lookupThis() { |
| 846 ir.Primitive result = new ir.This(); |
| 847 add(new ir.LetPrim(result)); |
| 848 return result; |
| 849 } |
| 850 |
| 839 ir.Primitive lookupLocal(Element element) { | 851 ir.Primitive lookupLocal(Element element) { |
| 840 int index = variableIndex[element]; | 852 int index = variableIndex[element]; |
| 841 ir.Primitive value = assignedVars[index]; | 853 ir.Primitive value = assignedVars[index]; |
| 842 return value == null ? freeVars[index] : value; | 854 return value == null ? freeVars[index] : value; |
| 843 } | 855 } |
| 844 | 856 |
| 845 // ==== Sends ==== | 857 // ==== Sends ==== |
| 846 ir.Primitive visitAssert(ast.Send node) { | 858 ir.Primitive visitAssert(ast.Send node) { |
| 847 assert(isOpen); | 859 assert(isOpen); |
| 848 return giveup(node, 'Assert'); | 860 return giveup(node, 'Assert'); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 add(new ir.LetCont(k, invoke)); | 912 add(new ir.LetCont(k, invoke)); |
| 901 return v; | 913 return v; |
| 902 } | 914 } |
| 903 | 915 |
| 904 ir.Primitive visitGetterSend(ast.Send node) { | 916 ir.Primitive visitGetterSend(ast.Send node) { |
| 905 assert(isOpen); | 917 assert(isOpen); |
| 906 Element element = elements[node]; | 918 Element element = elements[node]; |
| 907 if (Elements.isLocal(element)) { | 919 if (Elements.isLocal(element)) { |
| 908 return lookupLocal(element); | 920 return lookupLocal(element); |
| 909 } else if (element == null || Elements.isInstanceField(element)) { | 921 } else if (element == null || Elements.isInstanceField(element)) { |
| 910 // TODO: Support implicit this. | 922 ir.Primitive receiver = node.receiver == null |
| 911 if (node.receiver == null) return giveup(node); | 923 ? lookupThis() |
| 912 | 924 : visit(node.receiver); |
| 913 ir.Primitive receiver = visit(node.receiver); | |
| 914 ir.Parameter v = new ir.Parameter(null); | 925 ir.Parameter v = new ir.Parameter(null); |
| 915 ir.Continuation k = new ir.Continuation([v]); | 926 ir.Continuation k = new ir.Continuation([v]); |
| 916 Selector selector = elements.getSelector(node); | 927 Selector selector = elements.getSelector(node); |
| 917 assert(selector.kind == SelectorKind.GETTER); | 928 assert(selector.kind == SelectorKind.GETTER); |
| 918 ir.InvokeMethod invoke = new ir.InvokeMethod(receiver, selector, k, []); | 929 ir.InvokeMethod invoke = new ir.InvokeMethod(receiver, selector, k, []); |
| 919 add(new ir.LetCont(k, invoke)); | 930 add(new ir.LetCont(k, invoke)); |
| 920 return v; | 931 return v; |
| 921 } else if (element.isField) { | 932 } else if (element.isField) { |
| 922 ir.Parameter v = new ir.Parameter(null); | 933 ir.Parameter v = new ir.Parameter(null); |
| 923 ir.Continuation k = new ir.Continuation([v]); | 934 ir.Continuation k = new ir.Continuation([v]); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 ir.InvokeStatic invoke = | 1173 ir.InvokeStatic invoke = |
| 1163 new ir.InvokeStatic(element, selector, k, [arg]); | 1174 new ir.InvokeStatic(element, selector, k, [arg]); |
| 1164 add(new ir.LetCont(k, invoke)); | 1175 add(new ir.LetCont(k, invoke)); |
| 1165 return arg; | 1176 return arg; |
| 1166 } else if (node.receiver == null) { | 1177 } else if (node.receiver == null) { |
| 1167 // Nodes that fall in this case: | 1178 // Nodes that fall in this case: |
| 1168 // - Unresolved top-level | 1179 // - Unresolved top-level |
| 1169 // - Assignment to final variable (will not be resolved) | 1180 // - Assignment to final variable (will not be resolved) |
| 1170 return giveup(node, 'SendSet: non-local, non-static, but no receiver'); | 1181 return giveup(node, 'SendSet: non-local, non-static, but no receiver'); |
| 1171 } else { | 1182 } else { |
| 1183 if (element != null && Elements.isUnresolved(element)) return giveup(); |
| 1184 |
| 1172 // Setter or index-setter invocation | 1185 // Setter or index-setter invocation |
| 1173 assert(node.receiver != null); | 1186 assert(node.receiver != null); |
| 1187 |
| 1174 if (node.receiver.isSuper()) return giveup(node, 'Super SendSet'); | 1188 if (node.receiver.isSuper()) return giveup(node, 'Super SendSet'); |
| 1175 | 1189 |
| 1176 ir.Primitive receiver = visit(node.receiver); | 1190 ir.Primitive receiver = node.receiver == null |
| 1191 ? lookupThis() |
| 1192 : visit(node.receiver); |
| 1177 ir.Parameter v = new ir.Parameter(null); | 1193 ir.Parameter v = new ir.Parameter(null); |
| 1178 ir.Continuation k = new ir.Continuation([v]); | 1194 ir.Continuation k = new ir.Continuation([v]); |
| 1179 Selector selector = elements.getSelector(node); | 1195 Selector selector = elements.getSelector(node); |
| 1180 assert(selector.kind == SelectorKind.SETTER || | 1196 assert(selector.kind == SelectorKind.SETTER || |
| 1181 selector.kind == SelectorKind.INDEX); | 1197 selector.kind == SelectorKind.INDEX); |
| 1182 List<ir.Definition> args = node.arguments.mapToList(visit, | 1198 List<ir.Definition> args = node.arguments.mapToList(visit, |
| 1183 growable:false); | 1199 growable:false); |
| 1184 ir.InvokeMethod invoke = | 1200 ir.InvokeMethod invoke = |
| 1185 new ir.InvokeMethod(receiver, selector, k, args); | 1201 new ir.InvokeMethod(receiver, selector, k, args); |
| 1186 add(new ir.LetCont(k, invoke)); | 1202 add(new ir.LetCont(k, invoke)); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1294 if (e == ABORT_IRNODE_BUILDER) return null; | 1310 if (e == ABORT_IRNODE_BUILDER) return null; |
| 1295 rethrow; | 1311 rethrow; |
| 1296 } | 1312 } |
| 1297 } | 1313 } |
| 1298 | 1314 |
| 1299 void internalError(String reason, {ast.Node node}) { | 1315 void internalError(String reason, {ast.Node node}) { |
| 1300 giveup(node); | 1316 giveup(node); |
| 1301 } | 1317 } |
| 1302 } | 1318 } |
| 1303 | 1319 |
| OLD | NEW |