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

Side by Side Diff: frog/leg/ssa/builder.dart

Issue 9370020: Fully support try/catch. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 10 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
« no previous file with comments | « no previous file | frog/leg/ssa/codegen.dart » ('j') | frog/leg/ssa/codegen.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 compiler.unimplemented("Ssa.visitIdentifier.", node: node); 868 compiler.unimplemented("Ssa.visitIdentifier.", node: node);
869 } 869 }
870 stack.add(localsHandler.thisDefinition); 870 stack.add(localsHandler.thisDefinition);
871 } else { 871 } else {
872 compiler.internalError("SsaBuilder.visitIdentifier on non-this", 872 compiler.internalError("SsaBuilder.visitIdentifier on non-this",
873 node: node); 873 node: node);
874 } 874 }
875 } 875 }
876 876
877 visitIf(If node) { 877 visitIf(If node) {
878 // Add the condition to the current block.
879 bool hasElse = node.hasElsePart;
880 visit(node.condition); 878 visit(node.condition);
879 Function visitElse;
880 if (node.elsePart != null) {
881 visitElse = () {
882 visit(node.elsePart);
883 };
884 }
885 handleIf(() => visit(node.thenPart), visitElse);
886 }
887
888 void handleIf(void visitThen(), void visitElse()) {
889 bool hasElse = visitElse != null;
881 HBasicBlock conditionBlock = close(new HIf(popBoolified(), hasElse)); 890 HBasicBlock conditionBlock = close(new HIf(popBoolified(), hasElse));
882 891
883 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler); 892 LocalsHandler savedLocals = new LocalsHandler.from(localsHandler);
884 893
885 // The then part. 894 // The then part.
886 HBasicBlock thenBlock = addNewBlock(); 895 HBasicBlock thenBlock = addNewBlock();
887 conditionBlock.addSuccessor(thenBlock); 896 conditionBlock.addSuccessor(thenBlock);
888 open(thenBlock); 897 open(thenBlock);
889 visit(node.thenPart); 898 visitThen();
890 thenBlock = current; 899 thenBlock = current;
891 900
892 // Reset the locals state to the state after the condition and keep the 901 // Reset the locals state to the state after the condition and keep the
893 // current state in [thenLocals]. 902 // current state in [thenLocals].
894 LocalsHandler thenLocals = localsHandler; 903 LocalsHandler thenLocals = localsHandler;
895 localsHandler = savedLocals; 904 localsHandler = savedLocals;
896 905
897 // Now the else part. 906 // Now the else part.
898 HBasicBlock elseBlock = null; 907 HBasicBlock elseBlock = null;
899 if (hasElse) { 908 if (hasElse) {
900 elseBlock = addNewBlock(); 909 elseBlock = addNewBlock();
901 conditionBlock.addSuccessor(elseBlock); 910 conditionBlock.addSuccessor(elseBlock);
902 open(elseBlock); 911 open(elseBlock);
903 visit(node.elsePart); 912 visitElse();
904 elseBlock = current; 913 elseBlock = current;
905 } 914 }
906 915
907 if (thenBlock === null && elseBlock === null && hasElse) { 916 if (thenBlock === null && elseBlock === null && hasElse) {
908 current = null; 917 current = null;
909 } else { 918 } else {
910 HBasicBlock joinBlock = addNewBlock(); 919 HBasicBlock joinBlock = addNewBlock();
911 if (thenBlock !== null) goto(thenBlock, joinBlock); 920 if (thenBlock !== null) goto(thenBlock, joinBlock);
912 if (elseBlock !== null) goto(elseBlock, joinBlock); 921 if (elseBlock !== null) goto(elseBlock, joinBlock);
913 else if (!hasElse) conditionBlock.addSuccessor(joinBlock); 922 else if (!hasElse) conditionBlock.addSuccessor(joinBlock);
(...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 HTry tryInstruction = new HTry(); 1826 HTry tryInstruction = new HTry();
1818 close(tryInstruction); 1827 close(tryInstruction);
1819 1828
1820 HBasicBlock tryBody = graph.addNewBlock(); 1829 HBasicBlock tryBody = graph.addNewBlock();
1821 enterBlock.addSuccessor(tryBody); 1830 enterBlock.addSuccessor(tryBody);
1822 open(tryBody); 1831 open(tryBody);
1823 visit(node.tryBlock); 1832 visit(node.tryBlock);
1824 List<HBasicBlock> blocks = <HBasicBlock>[]; 1833 List<HBasicBlock> blocks = <HBasicBlock>[];
1825 if (!isAborted()) blocks.add(close(new HGoto())); 1834 if (!isAborted()) blocks.add(close(new HGoto()));
1826 1835
1827 int catchBlocksCount = 0; 1836 if (!node.catchBlocks.isEmpty()) {
1828 for (CatchBlock catchBlock in node.catchBlocks.nodes) {
1829 if (++catchBlocksCount != 1) {
1830 compiler.unimplemented('SsaBuilder multiple catch blocks', node: node);
1831 }
1832 HBasicBlock block = graph.addNewBlock(); 1837 HBasicBlock block = graph.addNewBlock();
1833 enterBlock.addSuccessor(block); 1838 enterBlock.addSuccessor(block);
1834 open(block); 1839 open(block);
1835 visit(catchBlock); 1840 Element element = new Element(
1841 const SourceString(''), ElementKind.PARAMETER, work.element);
floitsch 2012/02/09 15:06:57 I would still give it a name.
ngeoffray 2012/02/09 15:13:48 Done.
1842 HParameterValue exception = new HParameterValue(element);
1843 add(exception);
1844 tryInstruction.exception = exception;
1845 Link<Node> link = node.catchBlocks.nodes;
1846
1847 void pushCondition(CatchBlock catchBlock) {
1848 VariableDefinitions declaration = catchBlock.formals.nodes.head;
1849 HInstruction condition = null;
1850 if (declaration.type == null) {
1851 condition = new HLiteral(true, HType.BOOLEAN);
1852 } else {
1853 Element element = elements[declaration.type];
1854 if (element == null) {
1855 compiler.cancel('Catch with unresolved type', node: catchBlock);
1856 }
1857 condition = new HIs(elements[declaration.type], exception);
floitsch 2012/02/09 15:06:57 element
ngeoffray 2012/02/09 15:13:48 Done.
1858 }
1859 push(condition);
1860 }
1861
1862 void visitThen() {
1863 CatchBlock catchBlock = link.head;
1864 link = link.tail;
1865 VariableDefinitions declaration = catchBlock.formals.nodes.head;
1866 localsHandler.updateLocal(elements[declaration.definitions.nodes.head],
1867 exception);
1868 visit(catchBlock);
1869 }
1870
1871 Function visitElse;
1872 visitElse = () {
floitsch 2012/02/09 15:06:57 void visitElse() { ...
ngeoffray 2012/02/09 15:13:48 Done.
1873 if (link.isEmpty()) {
1874 close(new HThrow(exception));
1875 } else {
1876 CatchBlock newBlock = link.head;
1877 pushCondition(newBlock);
1878 handleIf(visitThen, visitElse);
1879 }
1880 };
1881 CatchBlock firstBlock = link.head;
1882 pushCondition(firstBlock);
1883
1884 handleIf(visitThen, visitElse);
1885
1836 if (!isAborted()) blocks.add(close(new HGoto())); 1886 if (!isAborted()) blocks.add(close(new HGoto()));
1837 } 1887 }
1838 1888
1839 if (node.finallyBlock != null) { 1889 if (node.finallyBlock != null) {
1840 HBasicBlock finallyBlock = graph.addNewBlock(); 1890 HBasicBlock finallyBlock = graph.addNewBlock();
1841 enterBlock.addSuccessor(finallyBlock); 1891 enterBlock.addSuccessor(finallyBlock);
1842 open(finallyBlock); 1892 open(finallyBlock);
1843 visit(node.finallyBlock); 1893 visit(node.finallyBlock);
1844 if (!isAborted()) blocks.add(close(new HGoto())); 1894 if (!isAborted()) blocks.add(close(new HGoto()));
1845 tryInstruction.finallyBlock = finallyBlock; 1895 tryInstruction.finallyBlock = finallyBlock;
(...skipping 10 matching lines...) Expand all
1856 1906
1857 open(exitBlock); 1907 open(exitBlock);
1858 } 1908 }
1859 } 1909 }
1860 1910
1861 visitScriptTag(ScriptTag node) { 1911 visitScriptTag(ScriptTag node) {
1862 compiler.unimplemented('SsaBuilder.visitScriptTag', node: node); 1912 compiler.unimplemented('SsaBuilder.visitScriptTag', node: node);
1863 } 1913 }
1864 1914
1865 visitCatchBlock(CatchBlock node) { 1915 visitCatchBlock(CatchBlock node) {
1866 NodeList formals = node.formals;
1867 VariableDefinitions exception = formals.nodes.head;
1868 if (exception.type != null) {
1869 compiler.unimplemented('SsaBuilder catch with type', node: node);
1870 }
1871 visit(node.block); 1916 visit(node.block);
1872 } 1917 }
1873 1918
1874 visitTypedef(Typedef node) { 1919 visitTypedef(Typedef node) {
1875 compiler.unimplemented('SsaBuilder.visitTypedef', node: node); 1920 compiler.unimplemented('SsaBuilder.visitTypedef', node: node);
1876 } 1921 }
1877 } 1922 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/ssa/codegen.dart » ('j') | frog/leg/ssa/codegen.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698