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

Side by Side Diff: frog/leg/tree/nodes.dart

Issue 9632018: Switch-implementation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 visitCatchBlock(CatchBlock node); 8 R visitCatchBlock(CatchBlock node);
9 R visitClassNode(ClassNode node); 9 R visitClassNode(ClassNode node);
10 R visitConditional(Conditional node); 10 R visitConditional(Conditional node);
(...skipping 1387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 cases.accept(visitor); 1398 cases.accept(visitor);
1399 } 1399 }
1400 1400
1401 Token getBeginToken() => switchKeyword; 1401 Token getBeginToken() => switchKeyword;
1402 1402
1403 Token getEndToken() => cases.getEndToken(); 1403 Token getEndToken() => cases.getEndToken();
1404 } 1404 }
1405 1405
1406 class SwitchCase extends Node { 1406 class SwitchCase extends Node {
1407 final Identifier label; 1407 final Identifier label;
1408 final Expression expression; 1408 final NodeList expressions;
1409 final Token defaultKeyword;
1409 final NodeList statements; 1410 final NodeList statements;
1410 1411
1411 final Token caseKeyword; 1412 final Token startToken;
1412 1413
1413 SwitchCase(this.label, this.expression, this.statements, this.caseKeyword); 1414 SwitchCase(this.label, this.expressions, this.defaultKeyword,
1415 this.statements, this.startToken);
1414 1416
1415 SwitchCase asSwitchCase() => this; 1417 SwitchCase asSwitchCase() => this;
1416 1418
1419 bool get isDefaultCase() => defaultKeyword !== null;
1420
1417 accept(Visitor visitor) => visitor.visitSwitchCase(this); 1421 accept(Visitor visitor) => visitor.visitSwitchCase(this);
1418 1422
1419 visitChildren(Visitor visitor) { 1423 visitChildren(Visitor visitor) {
1420 if (label !== null) label.accept(visitor); 1424 if (label !== null) label.accept(visitor);
1421 expression.accept(visitor); 1425 expressions.accept(visitor);
1422 statements.accept(visitor); 1426 statements.accept(visitor);
1423 } 1427 }
1424 1428
1425 Token getBeginToken() { 1429 Token getBeginToken() {
1426 if (label !== null) return label.getBeginToken(); 1430 return startToken;
1427 return caseKeyword;
1428 } 1431 }
1429 1432
1430 Token getEndToken() { 1433 Token getEndToken() {
1431 if (statements.nodes.isEmpty()) { 1434 if (statements.nodes.isEmpty()) {
1432 // The colon after the expression. 1435 // The colon after the expression.
1433 return expression.getEndToken().next; 1436 return expressions.getEndToken().next;
1434 } else { 1437 } else {
1435 return statements.getEndToken(); 1438 return statements.getEndToken();
1436 } 1439 }
1437 }
1438 }
1439
1440 class DefaultCase extends Node {
1441 final Identifier label;
1442 final NodeList statements;
1443
1444 final Token defaultKeyword;
1445
1446 DefaultCase(this.label, this.statements, this.defaultKeyword);
1447
1448 DefaultCase asDefaultCase() => this;
1449
1450 accept(Visitor visitor) => visitor.visitDefaultCase(this);
1451
1452 visitChildren(Visitor visitor) {
1453 if (label !== null) label.accept(visitor);
1454 statements.accept(visitor);
1455 }
1456
1457 Token getBeginToken() {
1458 if (label !== null) return label.getBeginToken();
1459 return defaultKeyword;
1460 }
1461
1462 Token getEndToken() {
1463 if (statements.nodes.isEmpty()) {
1464 // The colon after default.
1465 return defaultKeyword.next;
1466 } else {
1467 return statements.getEndToken();
1468 }
1469 } 1440 }
1470 } 1441 }
1471 1442
1472 class GotoStatement extends Statement { 1443 class GotoStatement extends Statement {
1473 final Identifier target; 1444 final Identifier target;
1474 final Token keywordToken; 1445 final Token keywordToken;
1475 final Token semicolonToken; 1446 final Token semicolonToken;
1476 1447
1477 GotoStatement(this.target, this.keywordToken, this.semicolonToken); 1448 GotoStatement(this.target, this.keywordToken, this.semicolonToken);
1478 1449
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 static bool isConstructorRedirect(Send node) { 1671 static bool isConstructorRedirect(Send node) {
1701 return (node.receiver === null && 1672 return (node.receiver === null &&
1702 node.selector.asIdentifier() !== null && 1673 node.selector.asIdentifier() !== null &&
1703 node.selector.asIdentifier().isThis()) || 1674 node.selector.asIdentifier().isThis()) ||
1704 (node.receiver !== null && 1675 (node.receiver !== null &&
1705 node.receiver.asIdentifier() !== null && 1676 node.receiver.asIdentifier() !== null &&
1706 node.receiver.asIdentifier().isThis() && 1677 node.receiver.asIdentifier().isThis() &&
1707 node.selector.asIdentifier() !== null); 1678 node.selector.asIdentifier() !== null);
1708 } 1679 }
1709 } 1680 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698