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 'package:kernel/ast.dart' | 7 import 'package:kernel/ast.dart' |
8 hide InvalidExpression, InvalidInitializer, InvalidStatement; | 8 hide InvalidExpression, InvalidInitializer, InvalidStatement; |
9 | 9 |
10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; | 10 import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; |
(...skipping 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2851 } | 2851 } |
2852 push(new SwitchCase(expressions, expressionOffsets, block, | 2852 push(new SwitchCase(expressions, expressionOffsets, block, |
2853 isDefault: defaultKeyword != null) | 2853 isDefault: defaultKeyword != null) |
2854 ..fileOffset = firstToken.charOffset); | 2854 ..fileOffset = firstToken.charOffset); |
2855 push(labels); | 2855 push(labels); |
2856 } | 2856 } |
2857 | 2857 |
2858 @override | 2858 @override |
2859 void endSwitchStatement(Token switchKeyword, Token endToken) { | 2859 void endSwitchStatement(Token switchKeyword, Token endToken) { |
2860 debugEvent("SwitchStatement"); | 2860 debugEvent("SwitchStatement"); |
2861 // Do nothing. Handled by [endSwitchBlock]. | 2861 |
| 2862 List<SwitchCase> cases = pop(); |
| 2863 JumpTarget target = exitBreakTarget(); |
| 2864 exitSwitchScope(); |
| 2865 exitLocalScope(); |
| 2866 Expression expression = popForValue(); |
| 2867 Statement result = new KernelSwitchStatement(expression, cases) |
| 2868 ..fileOffset = switchKeyword.charOffset; |
| 2869 if (target.hasUsers) { |
| 2870 result = new KernelLabeledStatement(result); |
| 2871 target.resolveBreaks(result); |
| 2872 } |
| 2873 exitLoopOrSwitch(result); |
2862 } | 2874 } |
2863 | 2875 |
2864 @override | 2876 @override |
2865 void endSwitchBlock(int caseCount, Token beginToken, Token endToken) { | 2877 void endSwitchBlock(int caseCount, Token beginToken, Token endToken) { |
2866 debugEvent("SwitchBlock"); | 2878 debugEvent("SwitchBlock"); |
2867 List<SwitchCase> cases = | 2879 List<SwitchCase> cases = |
2868 new List<SwitchCase>.filled(caseCount, null, growable: true); | 2880 new List<SwitchCase>.filled(caseCount, null, growable: true); |
2869 for (int i = caseCount - 1; i >= 0; i--) { | 2881 for (int i = caseCount - 1; i >= 0; i--) { |
2870 List<Label> labels = pop(); | 2882 List<Label> labels = pop(); |
2871 SwitchCase current = cases[i] = pop(); | 2883 SwitchCase current = cases[i] = pop(); |
(...skipping 30 matching lines...) Expand all Loading... |
2902 } | 2914 } |
2903 if (lastNode is! BreakStatement && | 2915 if (lastNode is! BreakStatement && |
2904 lastNode is! ContinueSwitchStatement && | 2916 lastNode is! ContinueSwitchStatement && |
2905 lastNode is! Rethrow && | 2917 lastNode is! Rethrow && |
2906 lastNode is! ReturnStatement && | 2918 lastNode is! ReturnStatement && |
2907 lastNode is! Throw) { | 2919 lastNode is! Throw) { |
2908 block.addStatement( | 2920 block.addStatement( |
2909 new ExpressionStatement(buildFallThroughError(current.fileOffset))); | 2921 new ExpressionStatement(buildFallThroughError(current.fileOffset))); |
2910 } | 2922 } |
2911 } | 2923 } |
2912 JumpTarget target = exitBreakTarget(); | 2924 |
2913 exitSwitchScope(); | 2925 push(cases); |
2914 exitLocalScope(); | |
2915 Expression expression = popForValue(); | |
2916 Statement result = new KernelSwitchStatement(expression, cases); | |
2917 if (target.hasUsers) { | |
2918 result = new KernelLabeledStatement(result); | |
2919 target.resolveBreaks(result); | |
2920 } | |
2921 exitLoopOrSwitch(result); | |
2922 } | 2926 } |
2923 | 2927 |
2924 @override | 2928 @override |
2925 void handleCaseMatch(Token caseKeyword, Token colon) { | 2929 void handleCaseMatch(Token caseKeyword, Token colon) { |
2926 debugEvent("CaseMatch"); | 2930 debugEvent("CaseMatch"); |
2927 // Do nothing. Handled by [handleSwitchCase]. | 2931 // Do nothing. Handled by [handleSwitchCase]. |
2928 } | 2932 } |
2929 | 2933 |
2930 @override | 2934 @override |
2931 void handleBreakStatement( | 2935 void handleBreakStatement( |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3818 return AsyncMarker.Async; | 3822 return AsyncMarker.Async; |
3819 } else { | 3823 } else { |
3820 assert(identical(starToken.stringValue, "*")); | 3824 assert(identical(starToken.stringValue, "*")); |
3821 return AsyncMarker.AsyncStar; | 3825 return AsyncMarker.AsyncStar; |
3822 } | 3826 } |
3823 } else { | 3827 } else { |
3824 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", | 3828 return unhandled(asyncToken.lexeme, "asyncMarkerFromTokens", |
3825 asyncToken.charOffset, null); | 3829 asyncToken.charOffset, null); |
3826 } | 3830 } |
3827 } | 3831 } |
OLD | NEW |