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

Unified Diff: pkg/compiler/lib/src/ssa/jump_handler.dart

Issue 2648443004: Implement complex switch statement (switch with continue). (Closed)
Patch Set: . Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder_kernel.dart ('k') | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/jump_handler.dart
diff --git a/pkg/compiler/lib/src/ssa/jump_handler.dart b/pkg/compiler/lib/src/ssa/jump_handler.dart
index d401ca8361bbe87a151b1169c284c21207fb6d61..c3d1528bebce9f6bf6c80d37fcffebfe8fc48d04 100644
--- a/pkg/compiler/lib/src/ssa/jump_handler.dart
+++ b/pkg/compiler/lib/src/ssa/jump_handler.dart
@@ -150,36 +150,13 @@ class TargetJumpHandler implements JumpHandler {
/// Special [JumpHandler] implementation used to handle continue statements
/// targeting switch cases.
-class SwitchCaseJumpHandler extends TargetJumpHandler {
+abstract class SwitchCaseJumpHandler extends TargetJumpHandler {
/// Map from switch case targets to indices used to encode the flow of the
/// switch case loop.
final Map<JumpTarget, int> targetIndexMap = new Map<JumpTarget, int>();
- SwitchCaseJumpHandler(
- GraphBuilder builder, JumpTarget target, ast.SwitchStatement node)
- : super(builder, target) {
- // The switch case indices must match those computed in
- // [SsaFromAstMixin.buildSwitchCaseConstants].
- // Switch indices are 1-based so we can bypass the synthetic loop when no
- // cases match simply by branching on the index (which defaults to null).
- int switchIndex = 1;
- for (ast.SwitchCase switchCase in node.cases) {
- for (ast.Node labelOrCase in switchCase.labelsAndCases) {
- ast.Node label = labelOrCase.asLabel();
- if (label != null) {
- LabelDefinition labelElement =
- builder.elements.getLabelDefinition(label);
- if (labelElement != null && labelElement.isContinueTarget) {
- JumpTarget continueTarget = labelElement.target;
- targetIndexMap[continueTarget] = switchIndex;
- assert(builder.jumpTargets[continueTarget] == null);
- builder.jumpTargets[continueTarget] = this;
- }
- }
- }
- switchIndex++;
- }
- }
+ SwitchCaseJumpHandler(GraphBuilder builder, JumpTarget target)
+ : super(builder, target);
void generateBreak([LabelDefinition label]) {
if (label == null) {
@@ -232,3 +209,33 @@ class SwitchCaseJumpHandler extends TargetJumpHandler {
super.close();
}
}
+
+/// Special [JumpHandler] implementation used to handle continue statements
+/// targeting switch cases.
+class AstSwitchCaseJumpHandler extends SwitchCaseJumpHandler {
+ AstSwitchCaseJumpHandler(
+ GraphBuilder builder, JumpTarget target, ast.SwitchStatement node)
+ : super(builder, target) {
+ // The switch case indices must match those computed in
+ // [SsaFromAstMixin.buildSwitchCaseConstants].
+ // Switch indices are 1-based so we can bypass the synthetic loop when no
+ // cases match simply by branching on the index (which defaults to null).
+ int switchIndex = 1;
+ for (ast.SwitchCase switchCase in node.cases) {
+ for (ast.Node labelOrCase in switchCase.labelsAndCases) {
+ ast.Node label = labelOrCase.asLabel();
+ if (label != null) {
+ LabelDefinition labelElement =
+ builder.elements.getLabelDefinition(label);
+ if (labelElement != null && labelElement.isContinueTarget) {
+ JumpTarget continueTarget = labelElement.target;
+ targetIndexMap[continueTarget] = switchIndex;
+ assert(builder.jumpTargets[continueTarget] == null);
+ builder.jumpTargets[continueTarget] = this;
+ }
+ }
+ }
+ switchIndex++;
+ }
+ }
+}
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder_kernel.dart ('k') | pkg/compiler/lib/src/ssa/kernel_ast_adapter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698