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

Unified Diff: lib/compiler/implementation/resolver.dart

Issue 10387080: Accept more labels per switch case. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix bug when there are more than one label on a statement. Created 8 years, 7 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
Index: lib/compiler/implementation/resolver.dart
diff --git a/lib/compiler/implementation/resolver.dart b/lib/compiler/implementation/resolver.dart
index 338148d6de278863f03f569c4f2868a603ce58f1..aef47a65e0e9f5c73db9d207aee435cd37460fdf 100644
--- a/lib/compiler/implementation/resolver.dart
+++ b/lib/compiler/implementation/resolver.dart
@@ -1213,6 +1213,10 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
if (!target.statement.isValidContinueTarget()) {
error(node.target, MessageKind.INVALID_CONTINUE, [labelName]);
}
+ // TODO(lrn): Handle continues to switch cases.
+ if (target.statement is SwitchCase) {
+ unimplemented(node, "continue to switch case");
+ }
label.setContinueTarget();
mapping[node.target] = label;
}
@@ -1237,6 +1241,9 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
}
}
+ visitLabel(Label node) {
+ }
+
visitLabeledStatement(LabeledStatement node) {
String labelName = node.label.slowToString();
LabelElement existingElement = statementScope.lookupLabel(labelName);
@@ -1283,8 +1290,9 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
Link<Node> cases = node.cases.nodes;
while (!cases.isEmpty()) {
SwitchCase switchCase = cases.head;
- if (switchCase.label !== null) {
- Label label = switchCase.label;
+ for (Node labelOrCase in switchCase.labelsAndCases) {
+ if (labelOrCase is! Label) continue;
+ Label label = labelOrCase;
String labelName = label.slowToString();
LabelElement existingElement = continueLabels[labelName];
@@ -1315,19 +1323,21 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
continueLabels[labelName] = labelElement;
}
cases = cases.tail;
+ // Test that only the last case, if any, is a default case.
if (switchCase.defaultKeyword !== null && !cases.isEmpty()) {
error(switchCase, MessageKind.INVALID_CASE_DEFAULT);
}
}
+
statementScope.enterSwitch(breakElement, continueLabels);
node.cases.accept(this);
statementScope.exitSwitch();
- // Clean-up unused labels
+ // Clean-up unused labels.
continueLabels.forEach((String key, LabelElement label) {
- TargetElement targetElement = label.target;
- SwitchCase switchCase = targetElement.statement;
if (!label.isContinueTarget) {
+ TargetElement targetElement = label.target;
+ SwitchCase switchCase = targetElement.statement;
mapping.remove(switchCase);
mapping.remove(label.label);
}
@@ -1335,11 +1345,14 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
}
visitSwitchCase(SwitchCase node) {
- // The label was handled in [visitSwitchStatement(SwitchStatement)].
- node.expressions.accept(this);
+ node.labelsAndCases.accept(this);
visitIn(node.statements, new BlockScope(context));
}
+ visitCaseMatch(CaseMatch node) {
+ visit(node.expression);
+ }
+
visitTryStatement(TryStatement node) {
visit(node.tryBlock);
if (node.catchBlocks.isEmpty() && node.finallyBlock == null) {

Powered by Google App Engine
This is Rietveld 408576698