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

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

Issue 9599026: Generate code for some switch statements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add a few comments 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 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 if (label !== null) label.accept(visitor); 1418 if (label !== null) label.accept(visitor);
1419 expression.accept(visitor); 1419 expression.accept(visitor);
1420 statements.accept(visitor); 1420 statements.accept(visitor);
1421 } 1421 }
1422 1422
1423 Token getBeginToken() { 1423 Token getBeginToken() {
1424 if (label !== null) return label.getBeginToken(); 1424 if (label !== null) return label.getBeginToken();
1425 return caseKeyword; 1425 return caseKeyword;
1426 } 1426 }
1427 1427
1428 Token getEndToken() => statements.getEndToken(); 1428 Token getEndToken() {
1429 if (statements.nodes.isEmpty()) {
1430 // The colon after the expression.
1431 return expression.getEndToken().next;
1432 } else {
1433 return statements.getEndToken();
1434 }
1435 }
1429 } 1436 }
1430 1437
1431 class DefaultCase extends Node { 1438 class DefaultCase extends Node {
1432 final Identifier label; 1439 final Identifier label;
1433 final NodeList statements; 1440 final NodeList statements;
1434 1441
1435 final Token defaultKeyword; 1442 final Token defaultKeyword;
1436 1443
1437 DefaultCase(this.label, this.statements, this.defaultKeyword); 1444 DefaultCase(this.label, this.statements, this.defaultKeyword);
1438 1445
1439 DefaultCase asDefaultCase() => this; 1446 DefaultCase asDefaultCase() => this;
1440 1447
1441 accept(Visitor visitor) => visitor.visitDefaultCase(this); 1448 accept(Visitor visitor) => visitor.visitDefaultCase(this);
1442 1449
1443 visitChildren(Visitor visitor) { 1450 visitChildren(Visitor visitor) {
1444 if (label !== null) label.accept(visitor); 1451 if (label !== null) label.accept(visitor);
1445 statements.accept(visitor); 1452 statements.accept(visitor);
1446 } 1453 }
1447 1454
1448 Token getBeginToken() { 1455 Token getBeginToken() {
1449 if (label === null) return label.getBeginToken(); 1456 if (label !== null) return label.getBeginToken();
1450 return defaultKeyword; 1457 return defaultKeyword;
1451 } 1458 }
1452 1459
1453 Token getEndToken() => statements.getEndToken(); 1460 Token getEndToken() {
1461 if (statements.nodes.isEmpty()) {
1462 // The colon after default.
1463 return defaultKeyword.next;
1464 } else {
1465 return statements.getEndToken();
1466 }
1467 }
1454 } 1468 }
1455 1469
1456 class GotoStatement extends Statement { 1470 class GotoStatement extends Statement {
1457 final Identifier target; 1471 final Identifier target;
1458 final Token keywordToken; 1472 final Token keywordToken;
1459 final Token semicolonToken; 1473 final Token semicolonToken;
1460 1474
1461 GotoStatement(this.target, this.keywordToken, this.semicolonToken); 1475 GotoStatement(this.target, this.keywordToken, this.semicolonToken);
1462 1476
1463 visitChildren(Visitor visitor) { 1477 visitChildren(Visitor visitor) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 static bool isConstructorRedirect(Send node) { 1684 static bool isConstructorRedirect(Send node) {
1671 return (node.receiver === null && 1685 return (node.receiver === null &&
1672 node.selector.asIdentifier() !== null && 1686 node.selector.asIdentifier() !== null &&
1673 node.selector.asIdentifier().isThis()) || 1687 node.selector.asIdentifier().isThis()) ||
1674 (node.receiver !== null && 1688 (node.receiver !== null &&
1675 node.receiver.asIdentifier() !== null && 1689 node.receiver.asIdentifier() !== null &&
1676 node.receiver.asIdentifier().isThis() && 1690 node.receiver.asIdentifier().isThis() &&
1677 node.selector.asIdentifier() !== null); 1691 node.selector.asIdentifier() !== null);
1678 } 1692 }
1679 } 1693 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698