| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 class Interceptors { | 5 class Interceptors { |
| 6 Compiler compiler; | 6 Compiler compiler; |
| 7 Interceptors(Compiler this.compiler); | 7 Interceptors(Compiler this.compiler); |
| 8 | 8 |
| 9 SourceString mapOperatorToMethodName(Operator op) { | 9 SourceString mapOperatorToMethodName(Operator op) { |
| 10 String name = op.source.stringValue; | 10 String name = op.source.stringValue; |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 visitIdentifier(Identifier node) { | 863 visitIdentifier(Identifier node) { |
| 864 if (node.isThis()) { | 864 if (node.isThis()) { |
| 865 stack.add(localsHandler.readThis()); | 865 stack.add(localsHandler.readThis()); |
| 866 } else { | 866 } else { |
| 867 compiler.internalError("SsaBuilder.visitIdentifier on non-this", | 867 compiler.internalError("SsaBuilder.visitIdentifier on non-this", |
| 868 node: node); | 868 node: node); |
| 869 } | 869 } |
| 870 } | 870 } |
| 871 | 871 |
| 872 visitIf(If node) { | 872 visitIf(If node) { |
| 873 // Add the condition to the current block. | |
| 874 bool hasElse = node.hasElsePart; | |
| 875 visit(node.condition); | 873 visit(node.condition); |
| 874 Function visitElse; |
| 875 if (node.elsePart != null) { |
| 876 visitElse = () { |
| 877 visit(node.elsePart); |
| 878 }; |
| 879 } |
| 880 handleIf(() => visit(node.thenPart), visitElse); |
| 881 } |
| 882 |
| 883 void handleIf(void visitThen(), void visitElse()) { |
| 884 bool hasElse = visitElse != null; |
| 876 HBasicBlock conditionBlock = close(new HIf(popBoolified(), hasElse)); | 885 HBasicBlock conditionBlock = close(new HIf(popBoolified(), hasElse)); |
| 877 | 886 |
| 878 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); | 887 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); |
| 879 | 888 |
| 880 // The then part. | 889 // The then part. |
| 881 HBasicBlock thenBlock = addNewBlock(); | 890 HBasicBlock thenBlock = addNewBlock(); |
| 882 conditionBlock.addSuccessor(thenBlock); | 891 conditionBlock.addSuccessor(thenBlock); |
| 883 open(thenBlock); | 892 open(thenBlock); |
| 884 visit(node.thenPart); | 893 visitThen(); |
| 885 thenBlock = current; | 894 thenBlock = current; |
| 886 | 895 |
| 887 // Reset the locals state to the state after the condition and keep the | 896 // Reset the locals state to the state after the condition and keep the |
| 888 // current state in [thenLocals]. | 897 // current state in [thenLocals]. |
| 889 LocalsHandler thenLocals = localsHandler; | 898 LocalsHandler thenLocals = localsHandler; |
| 890 localsHandler = savedLocals; | 899 localsHandler = savedLocals; |
| 891 | 900 |
| 892 // Now the else part. | 901 // Now the else part. |
| 893 HBasicBlock elseBlock = null; | 902 HBasicBlock elseBlock = null; |
| 894 if (hasElse) { | 903 if (hasElse) { |
| 895 elseBlock = addNewBlock(); | 904 elseBlock = addNewBlock(); |
| 896 conditionBlock.addSuccessor(elseBlock); | 905 conditionBlock.addSuccessor(elseBlock); |
| 897 open(elseBlock); | 906 open(elseBlock); |
| 898 visit(node.elsePart); | 907 visitElse(); |
| 899 elseBlock = current; | 908 elseBlock = current; |
| 900 } | 909 } |
| 901 | 910 |
| 902 if (thenBlock === null && elseBlock === null && hasElse) { | 911 if (thenBlock === null && elseBlock === null && hasElse) { |
| 903 current = null; | 912 current = null; |
| 904 } else { | 913 } else { |
| 905 HBasicBlock joinBlock = addNewBlock(); | 914 HBasicBlock joinBlock = addNewBlock(); |
| 906 if (thenBlock !== null) goto(thenBlock, joinBlock); | 915 if (thenBlock !== null) goto(thenBlock, joinBlock); |
| 907 if (elseBlock !== null) goto(elseBlock, joinBlock); | 916 if (elseBlock !== null) goto(elseBlock, joinBlock); |
| 908 else if (!hasElse) conditionBlock.addSuccessor(joinBlock); | 917 else if (!hasElse) conditionBlock.addSuccessor(joinBlock); |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1798 HTry tryInstruction = new HTry(); | 1807 HTry tryInstruction = new HTry(); |
| 1799 close(tryInstruction); | 1808 close(tryInstruction); |
| 1800 | 1809 |
| 1801 HBasicBlock tryBody = graph.addNewBlock(); | 1810 HBasicBlock tryBody = graph.addNewBlock(); |
| 1802 enterBlock.addSuccessor(tryBody); | 1811 enterBlock.addSuccessor(tryBody); |
| 1803 open(tryBody); | 1812 open(tryBody); |
| 1804 visit(node.tryBlock); | 1813 visit(node.tryBlock); |
| 1805 List<HBasicBlock> blocks = <HBasicBlock>[]; | 1814 List<HBasicBlock> blocks = <HBasicBlock>[]; |
| 1806 if (!isAborted()) blocks.add(close(new HGoto())); | 1815 if (!isAborted()) blocks.add(close(new HGoto())); |
| 1807 | 1816 |
| 1808 int catchBlocksCount = 0; | 1817 if (!node.catchBlocks.isEmpty()) { |
| 1809 for (CatchBlock catchBlock in node.catchBlocks.nodes) { | |
| 1810 if (++catchBlocksCount != 1) { | |
| 1811 compiler.unimplemented('SsaBuilder multiple catch blocks', node: node); | |
| 1812 } | |
| 1813 HBasicBlock block = graph.addNewBlock(); | 1818 HBasicBlock block = graph.addNewBlock(); |
| 1814 enterBlock.addSuccessor(block); | 1819 enterBlock.addSuccessor(block); |
| 1815 open(block); | 1820 open(block); |
| 1816 visit(catchBlock); | 1821 // Note that the name of this element is irrelevant. |
| 1822 Element element = new Element( |
| 1823 const SourceString('exception'), ElementKind.PARAMETER, work.element); |
| 1824 HParameterValue exception = new HParameterValue(element); |
| 1825 add(exception); |
| 1826 tryInstruction.exception = exception; |
| 1827 Link<Node> link = node.catchBlocks.nodes; |
| 1828 |
| 1829 void pushCondition(CatchBlock catchBlock) { |
| 1830 VariableDefinitions declaration = catchBlock.formals.nodes.head; |
| 1831 HInstruction condition = null; |
| 1832 if (declaration.type == null) { |
| 1833 condition = new HLiteral(true, HType.BOOLEAN); |
| 1834 } else { |
| 1835 Element element = elements[declaration.type]; |
| 1836 if (element == null) { |
| 1837 compiler.cancel('Catch with unresolved type', node: catchBlock); |
| 1838 } |
| 1839 condition = new HIs(element, exception); |
| 1840 } |
| 1841 push(condition); |
| 1842 } |
| 1843 |
| 1844 void visitThen() { |
| 1845 CatchBlock catchBlock = link.head; |
| 1846 link = link.tail; |
| 1847 VariableDefinitions declaration = catchBlock.formals.nodes.head; |
| 1848 localsHandler.updateLocal(elements[declaration.definitions.nodes.head], |
| 1849 exception); |
| 1850 visit(catchBlock); |
| 1851 } |
| 1852 |
| 1853 void visitElse() { |
| 1854 if (link.isEmpty()) { |
| 1855 close(new HThrow(exception)); |
| 1856 } else { |
| 1857 CatchBlock newBlock = link.head; |
| 1858 pushCondition(newBlock); |
| 1859 handleIf(visitThen, visitElse); |
| 1860 } |
| 1861 } |
| 1862 |
| 1863 CatchBlock firstBlock = link.head; |
| 1864 pushCondition(firstBlock); |
| 1865 handleIf(visitThen, visitElse); |
| 1817 if (!isAborted()) blocks.add(close(new HGoto())); | 1866 if (!isAborted()) blocks.add(close(new HGoto())); |
| 1818 } | 1867 } |
| 1819 | 1868 |
| 1820 if (node.finallyBlock != null) { | 1869 if (node.finallyBlock != null) { |
| 1821 HBasicBlock finallyBlock = graph.addNewBlock(); | 1870 HBasicBlock finallyBlock = graph.addNewBlock(); |
| 1822 enterBlock.addSuccessor(finallyBlock); | 1871 enterBlock.addSuccessor(finallyBlock); |
| 1823 open(finallyBlock); | 1872 open(finallyBlock); |
| 1824 visit(node.finallyBlock); | 1873 visit(node.finallyBlock); |
| 1825 if (!isAborted()) blocks.add(close(new HGoto())); | 1874 if (!isAborted()) blocks.add(close(new HGoto())); |
| 1826 tryInstruction.finallyBlock = finallyBlock; | 1875 tryInstruction.finallyBlock = finallyBlock; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1837 | 1886 |
| 1838 open(exitBlock); | 1887 open(exitBlock); |
| 1839 } | 1888 } |
| 1840 } | 1889 } |
| 1841 | 1890 |
| 1842 visitScriptTag(ScriptTag node) { | 1891 visitScriptTag(ScriptTag node) { |
| 1843 compiler.unimplemented('SsaBuilder.visitScriptTag', node: node); | 1892 compiler.unimplemented('SsaBuilder.visitScriptTag', node: node); |
| 1844 } | 1893 } |
| 1845 | 1894 |
| 1846 visitCatchBlock(CatchBlock node) { | 1895 visitCatchBlock(CatchBlock node) { |
| 1847 NodeList formals = node.formals; | |
| 1848 VariableDefinitions exception = formals.nodes.head; | |
| 1849 if (exception.type != null) { | |
| 1850 compiler.unimplemented('SsaBuilder catch with type', node: node); | |
| 1851 } | |
| 1852 visit(node.block); | 1896 visit(node.block); |
| 1853 } | 1897 } |
| 1854 | 1898 |
| 1855 visitTypedef(Typedef node) { | 1899 visitTypedef(Typedef node) { |
| 1856 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); | 1900 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); |
| 1857 } | 1901 } |
| 1858 } | 1902 } |
| OLD | NEW |