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

Unified Diff: lib/compiler/implementation/scanner/listener.dart

Issue 10387080: Accept more labels per switch case. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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/scanner/listener.dart
diff --git a/lib/compiler/implementation/scanner/listener.dart b/lib/compiler/implementation/scanner/listener.dart
index 74dd30f0dc1b51b65e5489840bdb8bc7bd995db5..3744f66de2bde5bf244db819f96823fe6270403b 100644
--- a/lib/compiler/implementation/scanner/listener.dart
+++ b/lib/compiler/implementation/scanner/listener.dart
@@ -251,6 +251,9 @@ class Listener {
void beginTryStatement(Token token) {
}
+ void handleCaseMatch(Token caseKeyword, Token colon) {
+ }
+
void handleCatchBlock(Token catchKeyword) {
}
@@ -404,7 +407,7 @@ class Listener {
void handleSuperExpression(Token token) {
}
- void handleSwitchCase(Token labelToken, int expressionCount,
+ void handleSwitchCase(int labelCount, int expressionCount,
Token defaultKeyword, int statementCount,
Token firstToken, Token endToken) {
}
@@ -1331,6 +1334,10 @@ class NodeListener extends ElementListener {
tryKeyword, finallyKeyword));
}
+ void handleCaseMatch(Token caseKeyword, Token colon) {
+ pushNode(new CaseMatch(caseKeyword, popNode(), colon));
+ }
+
void handleCatchBlock(Token catchKeyword) {
Block block = popNode();
NodeList formals = popNode();
@@ -1353,16 +1360,29 @@ class NodeListener extends ElementListener {
pushNode(new NodeList(beginToken, caseNodes, endToken, null));
}
- void handleSwitchCase(Token labelToken, int expressionCount,
+ void handleSwitchCase(int labelCount, int caseCount,
Token defaultKeyword, int statementCount,
Token firstToken, Token endToken) {
NodeList statements = makeNodeList(statementCount, null, null, null);
- NodeList expressions = makeNodeList(expressionCount, null, null, null);
- Label label = null;
- if (labelToken !== null) {
- label = popNode();
+ Link<Label> labels = const EmptyLink<Label>();
+ Link<CaseMatch> cases = const EmptyLink<CaseMatch>();
+ while (labelCount > 0 || caseCount > 0) {
+ Node node = popNode();
+ Label label = node.asLabel();
+ if (label !== null) {
+ labels = labels.prepend(label);
+ labelCount--;
+ } else {
+ CaseMatch match = node.asCaseMatch();
+ assert(match !== null);
+ cases = cases.prepend(match);
+ caseCount--;
+ }
}
- pushNode(new SwitchCase(label, expressions, defaultKeyword, statements,
+
+ NodeList caseList = new NodeList(null, cases, null, null);
+ NodeList labelList = new NodeList(null, labels, null, null);
+ pushNode(new SwitchCase(labelList, caseList, defaultKeyword, statements,
firstToken));
}

Powered by Google App Engine
This is Rietveld 408576698