| 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 part of dart2js.ir_builder; | 5 part of dart2js.ir_builder; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * This task iterates through all resolved elements and builds [ir.Node]s. The | 8 * This task iterates through all resolved elements and builds [ir.Node]s. The |
| 9 * nodes are stored in the [nodes] map and accessible through [hasIr] and | 9 * nodes are stored in the [nodes] map and accessible through [hasIr] and |
| 10 * [getIr]. | 10 * [getIr]. |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 ir.Primitive visitAssert(ast.Send node) { | 424 ir.Primitive visitAssert(ast.Send node) { |
| 425 assert(irBuilder.isOpen); | 425 assert(irBuilder.isOpen); |
| 426 return giveup(node, 'Assert'); | 426 return giveup(node, 'Assert'); |
| 427 } | 427 } |
| 428 | 428 |
| 429 ir.Primitive visitNamedArgument(ast.NamedArgument node) { | 429 ir.Primitive visitNamedArgument(ast.NamedArgument node) { |
| 430 assert(irBuilder.isOpen); | 430 assert(irBuilder.isOpen); |
| 431 return visit(node.expression); | 431 return visit(node.expression); |
| 432 } | 432 } |
| 433 | 433 |
| 434 ir.Primitive translateClosureCall(ir.Primitive receiver, | |
| 435 Selector closureSelector, | |
| 436 ast.NodeList arguments) { | |
| 437 Selector namedCallSelector = new Selector(closureSelector.kind, | |
| 438 "call", | |
| 439 closureSelector.library, | |
| 440 closureSelector.argumentCount, | |
| 441 closureSelector.namedArguments); | |
| 442 List<ir.Primitive> args = arguments.nodes.mapToList(visit, growable:false); | |
| 443 return irBuilder.buildDynamicInvocation(receiver, namedCallSelector, args); | |
| 444 } | |
| 445 | |
| 446 ir.Primitive visitClosureSend(ast.Send node) { | 434 ir.Primitive visitClosureSend(ast.Send node) { |
| 447 assert(irBuilder.isOpen); | 435 assert(irBuilder.isOpen); |
| 448 Element element = elements[node]; | 436 Element element = elements[node]; |
| 449 ir.Primitive closureTarget; | 437 Selector closureSelector = elements.getSelector(node); |
| 450 if (element == null) { | 438 if (element == null) { |
| 451 closureTarget = visit(node.selector); | 439 ir.Primitive closureTarget = visit(node.selector); |
| 452 } else if (irBuilder.isClosureVariable(element)) { | 440 List<ir.Primitive> args = |
| 453 LocalElement local = element; | 441 node.arguments.mapToList(visit, growable:false); |
| 454 closureTarget = new ir.GetClosureVariable(local); | 442 return irBuilder.buildFunctionExpressionInvocation( |
| 455 irBuilder.add(new ir.LetPrim(closureTarget)); | 443 closureTarget, elements.getSelector(node), args); |
| 456 } else { | 444 } else { |
| 457 assert(Elements.isLocal(element)); | 445 List<ir.Primitive> args = |
| 458 closureTarget = irBuilder.environment.lookup(element); | 446 node.arguments.mapToList(visit, growable:false); |
| 447 return irBuilder.buildLocalInvocation( |
| 448 element, elements.getSelector(node), args); |
| 459 } | 449 } |
| 460 Selector closureSelector = elements.getSelector(node); | |
| 461 return translateClosureCall(closureTarget, closureSelector, | |
| 462 node.argumentsNode); | |
| 463 } | 450 } |
| 464 | 451 |
| 465 /// If [node] is null, returns this. | 452 /// If [node] is null, returns this. |
| 466 /// If [node] is super, returns null (for special handling) | 453 /// If [node] is super, returns null (for special handling) |
| 467 /// Otherwise visits [node] and returns the result. | 454 /// Otherwise visits [node] and returns the result. |
| 468 ir.Primitive visitReceiver(ast.Expression node) { | 455 ir.Primitive visitReceiver(ast.Expression node) { |
| 469 if (node == null) return irBuilder.buildThis(); | 456 if (node == null) return irBuilder.buildThis(); |
| 470 if (node.isSuper()) return null; | 457 if (node.isSuper()) return null; |
| 471 return visit(node); | 458 return visit(node); |
| 472 } | 459 } |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 | 773 |
| 787 ir.Primitive translateConstant(ast.Node node, [ConstantExpression constant]) { | 774 ir.Primitive translateConstant(ast.Node node, [ConstantExpression constant]) { |
| 788 assert(irBuilder.isOpen); | 775 assert(irBuilder.isOpen); |
| 789 if (constant == null) { | 776 if (constant == null) { |
| 790 constant = getConstantForNode(node); | 777 constant = getConstantForNode(node); |
| 791 } | 778 } |
| 792 return irBuilder.buildConstantLiteral(constant); | 779 return irBuilder.buildConstantLiteral(constant); |
| 793 } | 780 } |
| 794 | 781 |
| 795 ir.FunctionDefinition makeSubFunction(ast.FunctionExpression node) { | 782 ir.FunctionDefinition makeSubFunction(ast.FunctionExpression node) { |
| 796 // TODO(johnniwinther): Share the visitor. | 783 return buildFunctionInternal(elements[node]); |
| 797 return new IrBuilderVisitor(elements, compiler, sourceFile) | |
| 798 .buildFunctionInternal(elements[node]); | |
| 799 } | 784 } |
| 800 | 785 |
| 801 ir.Primitive visitFunctionExpression(ast.FunctionExpression node) { | 786 ir.Primitive visitFunctionExpression(ast.FunctionExpression node) { |
| 802 FunctionElement element = elements[node]; | 787 return irBuilder.buildFunctionExpression(makeSubFunction(node)); |
| 803 ir.FunctionDefinition inner = makeSubFunction(node); | |
| 804 ir.CreateFunction prim = new ir.CreateFunction(inner); | |
| 805 irBuilder.add(new ir.LetPrim(prim)); | |
| 806 return prim; | |
| 807 } | 788 } |
| 808 | 789 |
| 809 ir.Primitive visitFunctionDeclaration(ast.FunctionDeclaration node) { | 790 visitFunctionDeclaration(ast.FunctionDeclaration node) { |
| 810 LocalFunctionElement element = elements[node.function]; | 791 LocalFunctionElement element = elements[node.function]; |
| 811 ir.FunctionDefinition inner = makeSubFunction(node.function); | 792 ir.FunctionDefinition inner = makeSubFunction(node.function); |
| 812 if (irBuilder.isClosureVariable(element)) { | 793 irBuilder.declareLocalFunction(element, inner); |
| 813 irBuilder.add(new ir.DeclareFunction(element, inner)); | |
| 814 } else { | |
| 815 ir.CreateFunction prim = new ir.CreateFunction(inner); | |
| 816 irBuilder.add(new ir.LetPrim(prim)); | |
| 817 irBuilder.environment.extend(element, prim); | |
| 818 prim.useElementAsHint(element); | |
| 819 } | |
| 820 return null; | |
| 821 } | 794 } |
| 822 | 795 |
| 823 static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted"; | 796 static final String ABORT_IRNODE_BUILDER = "IrNode builder aborted"; |
| 824 | 797 |
| 825 dynamic giveup(ast.Node node, [String reason]) { | 798 dynamic giveup(ast.Node node, [String reason]) { |
| 826 throw ABORT_IRNODE_BUILDER; | 799 throw ABORT_IRNODE_BUILDER; |
| 827 } | 800 } |
| 828 | 801 |
| 829 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { | 802 ir.FunctionDefinition nullIfGiveup(ir.FunctionDefinition action()) { |
| 830 try { | 803 try { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 node.visitChildren(this); | 849 node.visitChildren(this); |
| 877 } | 850 } |
| 878 | 851 |
| 879 visitFunctionExpression(ast.FunctionExpression node) { | 852 visitFunctionExpression(ast.FunctionExpression node) { |
| 880 FunctionElement oldFunction = currentFunction; | 853 FunctionElement oldFunction = currentFunction; |
| 881 currentFunction = elements[node]; | 854 currentFunction = elements[node]; |
| 882 visit(node.body); | 855 visit(node.body); |
| 883 currentFunction = oldFunction; | 856 currentFunction = oldFunction; |
| 884 } | 857 } |
| 885 } | 858 } |
| OLD | NEW |