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

Side by Side Diff: lib/compiler/implementation/tree/nodes.dart

Issue 10387080: Accept more labels per switch case. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 interface Visitor<R> { 5 interface Visitor<R> {
6 R visitBlock(Block node); 6 R visitBlock(Block node);
7 R visitBreakStatement(BreakStatement node); 7 R visitBreakStatement(BreakStatement node);
8 R visitCascade(Cascade node); 8 R visitCascade(Cascade node);
9 R visitCascadeReceiver(CascadeReceiver node); 9 R visitCascadeReceiver(CascadeReceiver node);
10 R visitCaseMatch(CaseMatch node);
10 R visitCatchBlock(CatchBlock node); 11 R visitCatchBlock(CatchBlock node);
11 R visitClassNode(ClassNode node); 12 R visitClassNode(ClassNode node);
12 R visitConditional(Conditional node); 13 R visitConditional(Conditional node);
13 R visitContinueStatement(ContinueStatement node); 14 R visitContinueStatement(ContinueStatement node);
14 R visitDoWhile(DoWhile node); 15 R visitDoWhile(DoWhile node);
15 R visitEmptyStatement(EmptyStatement node); 16 R visitEmptyStatement(EmptyStatement node);
16 R visitExpressionStatement(ExpressionStatement node); 17 R visitExpressionStatement(ExpressionStatement node);
17 R visitFor(For node); 18 R visitFor(For node);
18 R visitForIn(ForIn node); 19 R visitForIn(ForIn node);
19 R visitFunctionDeclaration(FunctionDeclaration node); 20 R visitFunctionDeclaration(FunctionDeclaration node);
20 R visitFunctionExpression(FunctionExpression node); 21 R visitFunctionExpression(FunctionExpression node);
21 R visitIdentifier(Identifier node); 22 R visitIdentifier(Identifier node);
22 R visitIf(If node); 23 R visitIf(If node);
23 R visitLabel(Label node); 24 R visitLabel(Label node);
24 R visitLabeledStatement(LabeledStatement node); 25 R visitLabeledStatement(LabeledStatement node);
25 R visitLiteralBool(LiteralBool node); 26 R visitLiteralBool(LiteralBool node);
26 R visitLiteralDouble(LiteralDouble node); 27 R visitLiteralDouble(LiteralDouble node);
27 R visitLiteralInt(LiteralInt node); 28 R visitLiteralInt(LiteralInt node);
28 R visitLiteralList(LiteralList node); 29 R visitLiteralList(LiteralList node);
29 R visitLiteralMap(LiteralMap node); 30 R visitLiteralMap(LiteralMap node);
30 R visitLiteralMapEntry(LiteralMapEntry node); 31 R visitLiteralMapEntry(LiteralMapEntry node);
31 R visitLiteralNull(LiteralNull node); 32 R visitLiteralNull(LiteralNull node);
32 R visitLiteralString(LiteralString node); 33 R visitLiteralString(LiteralString node);
33 R visitStringJuxtaposition(StringJuxtaposition node);
34 R visitModifiers(Modifiers node); 34 R visitModifiers(Modifiers node);
35 R visitNamedArgument(NamedArgument node); 35 R visitNamedArgument(NamedArgument node);
36 R visitNewExpression(NewExpression node); 36 R visitNewExpression(NewExpression node);
37 R visitNodeList(NodeList node); 37 R visitNodeList(NodeList node);
38 R visitOperator(Operator node); 38 R visitOperator(Operator node);
39 R visitParenthesizedExpression(ParenthesizedExpression node); 39 R visitParenthesizedExpression(ParenthesizedExpression node);
40 R visitReturn(Return node); 40 R visitReturn(Return node);
41 R visitScriptTag(ScriptTag node); 41 R visitScriptTag(ScriptTag node);
42 R visitSend(Send node); 42 R visitSend(Send node);
43 R visitSendSet(SendSet node); 43 R visitSendSet(SendSet node);
44 R visitStringInterpolation(StringInterpolation node); 44 R visitStringInterpolation(StringInterpolation node);
45 R visitStringInterpolationPart(StringInterpolationPart node); 45 R visitStringInterpolationPart(StringInterpolationPart node);
46 R visitStringJuxtaposition(StringJuxtaposition node);
46 R visitSwitchCase(SwitchCase node); 47 R visitSwitchCase(SwitchCase node);
47 R visitSwitchStatement(SwitchStatement node); 48 R visitSwitchStatement(SwitchStatement node);
48 R visitThrow(Throw node); 49 R visitThrow(Throw node);
49 R visitTryStatement(TryStatement node); 50 R visitTryStatement(TryStatement node);
50 R visitTypeAnnotation(TypeAnnotation node); 51 R visitTypeAnnotation(TypeAnnotation node);
51 R visitTypedef(Typedef node); 52 R visitTypedef(Typedef node);
52 R visitTypeVariable(TypeVariable node); 53 R visitTypeVariable(TypeVariable node);
53 R visitVariableDefinitions(VariableDefinitions node); 54 R visitVariableDefinitions(VariableDefinitions node);
54 R visitWhile(While node); 55 R visitWhile(While node);
55 } 56 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 107 }
107 108
108 abstract Token getBeginToken(); 109 abstract Token getBeginToken();
109 110
110 abstract Token getEndToken(); 111 abstract Token getEndToken();
111 112
112 Block asBlock() => null; 113 Block asBlock() => null;
113 BreakStatement asBreakStatement() => null; 114 BreakStatement asBreakStatement() => null;
114 Cascade asCascade() => null; 115 Cascade asCascade() => null;
115 CascadeReceiver asCascadeReceiver() => null; 116 CascadeReceiver asCascadeReceiver() => null;
117 CaseMatch asCaseMatch() => null;
116 CatchBlock asCatchBlock() => null; 118 CatchBlock asCatchBlock() => null;
117 ClassNode asClassNode() => null; 119 ClassNode asClassNode() => null;
118 Conditional asConditional() => null; 120 Conditional asConditional() => null;
119 ContinueStatement asContinueStatement() => null; 121 ContinueStatement asContinueStatement() => null;
120 DoWhile asDoWhile() => null; 122 DoWhile asDoWhile() => null;
121 EmptyStatement asEmptyStatement() => null; 123 EmptyStatement asEmptyStatement() => null;
122 Expression asExpression() => null; 124 Expression asExpression() => null;
123 ExpressionStatement asExpressionStatement() => null; 125 ExpressionStatement asExpressionStatement() => null;
124 For asFor() => null; 126 For asFor() => null;
125 ForIn asForIn() => null; 127 ForIn asForIn() => null;
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1314 visitChildren(Visitor visitor) { 1316 visitChildren(Visitor visitor) {
1315 parenthesizedExpression.accept(visitor); 1317 parenthesizedExpression.accept(visitor);
1316 cases.accept(visitor); 1318 cases.accept(visitor);
1317 } 1319 }
1318 1320
1319 Token getBeginToken() => switchKeyword; 1321 Token getBeginToken() => switchKeyword;
1320 1322
1321 Token getEndToken() => cases.getEndToken(); 1323 Token getEndToken() => cases.getEndToken();
1322 } 1324 }
1323 1325
1326 class CaseMatch extends Node {
1327 final Token caseKeyword;
1328 final Expression expression;
1329 final Token colonToken;
1330 CaseMatch(this.caseKeyword, this.expression, this.colonToken);
1331
1332 CaseMatch asCaseMatch() => this;
1333 Token getBeginToken() => caseKeyword;
1334 Token getEndToken() => colonToken;
1335 accept(Visitor visitor) => visitor.visitCaseMatch(this);
1336 visitChildren(Visitor visitor) => expression.accept(visitor);
1337 }
1338
1324 class SwitchCase extends Node { 1339 class SwitchCase extends Node {
1325 // Represents the grammar: 1340 // The labels and case patterns are collected in [labelsAndCases].
1326 // label? ('case' expression ':')* ('default' ':')? statement* 1341 // The default keyword, if present, is collected in [defaultKeyword].
1327 // Each expression is collected in [expressions].
1328 // The 'case' keywords can be obtained using [caseKeywords()].
1329 // Any actual switch case must have at least one 'case' or 'default' 1342 // Any actual switch case must have at least one 'case' or 'default'
1330 // clause. 1343 // clause.
1331 final Label label; 1344 // Notice: The labels and cases can occur interleaved in the source.
1332 final NodeList expressions; 1345 // They are separated here, since the order is irrelevant to the meaning
1346 // of the switch.
1347
1348 /** List of [Label] and [CaseMatch] nodes. */
1349 final NodeList labelsAndCases;
1350 /** A "default" keyword token, if applicable. */
1333 final Token defaultKeyword; 1351 final Token defaultKeyword;
1352 /** List of statements, the body of the case. */
1334 final NodeList statements; 1353 final NodeList statements;
1335 1354
1336 final Token startToken; 1355 final Token startToken;
1337 1356
1338 SwitchCase(this.label, this.expressions, this.defaultKeyword, 1357 SwitchCase(this.labelsAndCases, this.defaultKeyword,
1339 this.statements, this.startToken); 1358 this.statements, this.startToken);
1340 1359
1341 SwitchCase asSwitchCase() => this; 1360 SwitchCase asSwitchCase() => this;
1342 1361
1343 bool get isDefaultCase() => defaultKeyword !== null; 1362 bool get isDefaultCase() => defaultKeyword !== null;
1344 1363
1364 bool isValidContinueTarget() => true;
1365
1345 accept(Visitor visitor) => visitor.visitSwitchCase(this); 1366 accept(Visitor visitor) => visitor.visitSwitchCase(this);
1346 1367
1347 visitChildren(Visitor visitor) { 1368 visitChildren(Visitor visitor) {
1348 if (label !== null) label.accept(visitor); 1369 labelsAndCases.accept(visitor);
1349 expressions.accept(visitor);
1350 statements.accept(visitor); 1370 statements.accept(visitor);
1351 } 1371 }
1352 1372
1353 Token getBeginToken() { 1373 Token getBeginToken() {
1354 return startToken; 1374 return startToken;
1355 } 1375 }
1356 1376
1357 Token getEndToken() { 1377 Token getEndToken() {
1358 if (statements.nodes.isEmpty()) { 1378 if (statements.nodes.isEmpty()) {
1359 // All cases must have at least one expression or be the default. 1379 // All cases must have at least one expression or be the default.
1360 if (defaultKeyword !== null) { 1380 if (defaultKeyword !== null) {
1361 // The colon after 'default'. 1381 // The colon after 'default'.
1362 return defaultKeyword.next; 1382 return defaultKeyword.next;
1363 } 1383 }
1364 // The colon after the expression. 1384 // The colon after the last expression.
1365 return expressions.getEndToken().next; 1385 return labelsAndCases.getEndToken();
1366 } else { 1386 } else {
1367 return statements.getEndToken(); 1387 return statements.getEndToken();
1368 } 1388 }
1369 } 1389 }
1370
1371 Link<Token> caseKeywords() {
1372 Token token = startToken;
1373 if (label !== null) {
1374 // Skip past the label: <Identifier> ':'.
1375 token = token.next.next;
1376 }
1377 LinkBuilder<Token> builder = new LinkBuilder<Token>();
1378 Link<Expression> link = expressions.nodes;
1379 while (token.stringValue === 'case') {
1380 assert(token.next === link.head.getBeginToken());
1381 builder.addLast(token);
1382 Token colon = link.head.getEndToken().next;
1383 token = colon.next;
1384 link = link.tail;
1385 }
1386 return builder.toLink();
1387 }
1388 } 1390 }
1389 1391
1390 class GotoStatement extends Statement { 1392 class GotoStatement extends Statement {
1391 final Identifier target; 1393 final Identifier target;
1392 final Token keywordToken; 1394 final Token keywordToken;
1393 final Token semicolonToken; 1395 final Token semicolonToken;
1394 1396
1395 GotoStatement(this.target, this.keywordToken, this.semicolonToken); 1397 GotoStatement(this.target, this.keywordToken, this.semicolonToken);
1396 1398
1397 visitChildren(Visitor visitor) { 1399 visitChildren(Visitor visitor) {
(...skipping 27 matching lines...) Expand all
1425 } 1427 }
1426 1428
1427 class ForIn extends Loop { 1429 class ForIn extends Loop {
1428 final Node declaredIdentifier; 1430 final Node declaredIdentifier;
1429 final Expression expression; 1431 final Expression expression;
1430 1432
1431 final Token forToken; 1433 final Token forToken;
1432 final Token inToken; 1434 final Token inToken;
1433 1435
1434 ForIn(this.declaredIdentifier, this.expression, 1436 ForIn(this.declaredIdentifier, this.expression,
1435 Statement body, this.forToken, this.inToken) : super(body); 1437 Statement body, this.forToken, this.inToken) : super(body);
1436 1438
1437 Expression get condition() => null; 1439 Expression get condition() => null;
1438 1440
1439 ForIn asForIn() => this; 1441 ForIn asForIn() => this;
1440 1442
1441 accept(Visitor visitor) => visitor.visitForIn(this); 1443 accept(Visitor visitor) => visitor.visitForIn(this);
1442 1444
1443 visitChildren(Visitor visitor) { 1445 visitChildren(Visitor visitor) {
1444 declaredIdentifier.accept(visitor); 1446 declaredIdentifier.accept(visitor);
1445 expression.accept(visitor); 1447 expression.accept(visitor);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 * argument). 1704 * argument).
1703 * 1705 *
1704 * TODO(ahe): This method is controversial, the team needs to discuss 1706 * TODO(ahe): This method is controversial, the team needs to discuss
1705 * if top-level methods are acceptable and what naming conventions to 1707 * if top-level methods are acceptable and what naming conventions to
1706 * use. 1708 * use.
1707 */ 1709 */
1708 initializerDo(Node node, f(Node node)) { 1710 initializerDo(Node node, f(Node node)) {
1709 SendSet send = node.asSendSet(); 1711 SendSet send = node.asSendSet();
1710 if (send !== null) return f(send.arguments.head); 1712 if (send !== null) return f(send.arguments.head);
1711 } 1713 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/ssa/tracer.dart ('k') | lib/compiler/implementation/tree/unparser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698