| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.body_builder; | 5 library fasta.body_builder; |
| 6 | 6 |
| 7 import '../fasta_codes.dart' | 7 import '../fasta_codes.dart' |
| 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; | 8 show FastaMessage, codeExpectedButGot, codeExpectedFunctionBody; |
| 9 | 9 |
| 10 import '../parser/parser.dart' show FormalParameterType, optional; | 10 import '../parser/parser.dart' show FormalParameterType, optional; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 78 |
| 79 @override | 79 @override |
| 80 final Uri uri; | 80 final Uri uri; |
| 81 | 81 |
| 82 Scope formalParameterScope; | 82 Scope formalParameterScope; |
| 83 | 83 |
| 84 bool inInitializer = false; | 84 bool inInitializer = false; |
| 85 | 85 |
| 86 bool inCatchClause = false; | 86 bool inCatchClause = false; |
| 87 | 87 |
| 88 bool inCatchBlock = false; |
| 89 |
| 88 int functionNestingLevel = 0; | 90 int functionNestingLevel = 0; |
| 89 | 91 |
| 90 Statement compileTimeErrorInTry; | 92 Statement compileTimeErrorInTry; |
| 91 | 93 |
| 92 Statement compileTimeErrorInLoopOrSwitch; | 94 Statement compileTimeErrorInLoopOrSwitch; |
| 93 | 95 |
| 94 Scope switchScope; | 96 Scope switchScope; |
| 95 | 97 |
| 96 CloneVisitor cloner; | 98 CloneVisitor cloner; |
| 97 | 99 |
| (...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 @override | 1513 @override |
| 1512 void beginCatchClause(Token token) { | 1514 void beginCatchClause(Token token) { |
| 1513 debugEvent("beginCatchClause"); | 1515 debugEvent("beginCatchClause"); |
| 1514 inCatchClause = true; | 1516 inCatchClause = true; |
| 1515 } | 1517 } |
| 1516 | 1518 |
| 1517 @override | 1519 @override |
| 1518 void endCatchClause(Token token) { | 1520 void endCatchClause(Token token) { |
| 1519 debugEvent("CatchClause"); | 1521 debugEvent("CatchClause"); |
| 1520 inCatchClause = false; | 1522 inCatchClause = false; |
| 1523 push(inCatchBlock); |
| 1524 inCatchBlock = true; |
| 1521 } | 1525 } |
| 1522 | 1526 |
| 1523 @override | 1527 @override |
| 1524 void handleCatchBlock(Token onKeyword, Token catchKeyword) { | 1528 void handleCatchBlock(Token onKeyword, Token catchKeyword) { |
| 1525 debugEvent("CatchBlock"); | 1529 debugEvent("CatchBlock"); |
| 1526 Block body = pop(); | 1530 Block body = pop(); |
| 1531 inCatchBlock = pop(); |
| 1527 if (catchKeyword != null) { | 1532 if (catchKeyword != null) { |
| 1528 exitLocalScope(); | 1533 exitLocalScope(); |
| 1529 } | 1534 } |
| 1530 FormalParameters catchParameters = popIfNotNull(catchKeyword); | 1535 FormalParameters catchParameters = popIfNotNull(catchKeyword); |
| 1531 DartType type = popIfNotNull(onKeyword) ?? const DynamicType(); | 1536 DartType type = popIfNotNull(onKeyword) ?? const DynamicType(); |
| 1532 VariableDeclaration exception; | 1537 VariableDeclaration exception; |
| 1533 VariableDeclaration stackTrace; | 1538 VariableDeclaration stackTrace; |
| 1534 if (catchParameters != null) { | 1539 if (catchParameters != null) { |
| 1535 if (catchParameters.required.length > 0) { | 1540 if (catchParameters.required.length > 0) { |
| 1536 exception = catchParameters.required[0]; | 1541 exception = catchParameters.required[0]; |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1903 scope[variable.name] = new KernelVariableBuilder( | 1908 scope[variable.name] = new KernelVariableBuilder( |
| 1904 variable, member ?? classBuilder ?? library, uri); | 1909 variable, member ?? classBuilder ?? library, uri); |
| 1905 enterLocalScope(); | 1910 enterLocalScope(); |
| 1906 } | 1911 } |
| 1907 | 1912 |
| 1908 void enterFunction() { | 1913 void enterFunction() { |
| 1909 debugEvent("enterFunction"); | 1914 debugEvent("enterFunction"); |
| 1910 functionNestingLevel++; | 1915 functionNestingLevel++; |
| 1911 push(switchScope ?? NullValue.SwitchScope); | 1916 push(switchScope ?? NullValue.SwitchScope); |
| 1912 switchScope = null; | 1917 switchScope = null; |
| 1918 push(inCatchBlock); |
| 1919 inCatchBlock = false; |
| 1913 } | 1920 } |
| 1914 | 1921 |
| 1915 void exitFunction() { | 1922 void exitFunction() { |
| 1916 debugEvent("exitFunction"); | 1923 debugEvent("exitFunction"); |
| 1917 functionNestingLevel--; | 1924 functionNestingLevel--; |
| 1925 inCatchBlock = pop(); |
| 1918 switchScope = pop(); | 1926 switchScope = pop(); |
| 1919 } | 1927 } |
| 1920 | 1928 |
| 1921 @override | 1929 @override |
| 1922 void beginFunction(Token token) { | 1930 void beginFunction(Token token) { |
| 1923 debugEvent("beginFunction"); | 1931 debugEvent("beginFunction"); |
| 1924 enterFunction(); | 1932 enterFunction(); |
| 1925 } | 1933 } |
| 1926 | 1934 |
| 1927 @override | 1935 @override |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 statement = new LabeledStatement(statement); | 2101 statement = new LabeledStatement(statement); |
| 2094 } | 2102 } |
| 2095 target.continueTarget.resolveContinues(statement); | 2103 target.continueTarget.resolveContinues(statement); |
| 2096 } | 2104 } |
| 2097 push(statement); | 2105 push(statement); |
| 2098 } | 2106 } |
| 2099 | 2107 |
| 2100 @override | 2108 @override |
| 2101 void endRethrowStatement(Token throwToken, Token endToken) { | 2109 void endRethrowStatement(Token throwToken, Token endToken) { |
| 2102 debugEvent("RethrowStatement"); | 2110 debugEvent("RethrowStatement"); |
| 2103 push(new ExpressionStatement( | 2111 if (inCatchBlock) { |
| 2104 new Rethrow()..fileOffset = throwToken.charOffset)); | 2112 push(new ExpressionStatement( |
| 2113 new Rethrow()..fileOffset = throwToken.charOffset)); |
| 2114 } else { |
| 2115 push(buildCompileTimeErrorStatement( |
| 2116 "'rethrow' can only be used in catch clauses.", |
| 2117 throwToken.charOffset)); |
| 2118 } |
| 2105 } | 2119 } |
| 2106 | 2120 |
| 2107 @override | 2121 @override |
| 2108 void handleFinallyBlock(Token finallyKeyword) { | 2122 void handleFinallyBlock(Token finallyKeyword) { |
| 2109 debugEvent("FinallyBlock"); | 2123 debugEvent("FinallyBlock"); |
| 2110 // Do nothing, handled by [endTryStatement]. | 2124 // Do nothing, handled by [endTryStatement]. |
| 2111 } | 2125 } |
| 2112 | 2126 |
| 2113 @override | 2127 @override |
| 2114 void endWhileStatement(Token whileKeyword, Token endToken) { | 2128 void endWhileStatement(Token whileKeyword, Token endToken) { |
| (...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2940 } else if (node is PrefixBuilder) { | 2954 } else if (node is PrefixBuilder) { |
| 2941 return node.name; | 2955 return node.name; |
| 2942 } else if (node is ThisAccessor) { | 2956 } else if (node is ThisAccessor) { |
| 2943 return node.isSuper ? "super" : "this"; | 2957 return node.isSuper ? "super" : "this"; |
| 2944 } else if (node is FastaAccessor) { | 2958 } else if (node is FastaAccessor) { |
| 2945 return node.plainNameForRead; | 2959 return node.plainNameForRead; |
| 2946 } else { | 2960 } else { |
| 2947 return internalError("Unhandled: ${node.runtimeType}"); | 2961 return internalError("Unhandled: ${node.runtimeType}"); |
| 2948 } | 2962 } |
| 2949 } | 2963 } |
| OLD | NEW |