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

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

Issue 9599013: Complete AST nodes for switch statement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
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);
11 R visitContinueStatement(ContinueStatement node); 11 R visitContinueStatement(ContinueStatement node);
12 R visitDefaultCase(DefaultCase node);
12 R visitDoWhile(DoWhile node); 13 R visitDoWhile(DoWhile node);
13 R visitEmptyStatement(EmptyStatement node); 14 R visitEmptyStatement(EmptyStatement node);
14 R visitExpressionStatement(ExpressionStatement node); 15 R visitExpressionStatement(ExpressionStatement node);
15 R visitFor(For node); 16 R visitFor(For node);
16 R visitForInStatement(ForInStatement node); 17 R visitForInStatement(ForInStatement node);
17 R visitFunctionDeclaration(FunctionDeclaration node); 18 R visitFunctionDeclaration(FunctionDeclaration node);
18 R visitFunctionExpression(FunctionExpression node); 19 R visitFunctionExpression(FunctionExpression node);
19 R visitIdentifier(Identifier node); 20 R visitIdentifier(Identifier node);
20 R visitIf(If node); 21 R visitIf(If node);
21 R visitLabelledStatement(LabelledStatement node); 22 R visitLabelledStatement(LabelledStatement node);
(...skipping 11 matching lines...) Expand all
33 R visitNewExpression(NewExpression node); 34 R visitNewExpression(NewExpression node);
34 R visitNodeList(NodeList node); 35 R visitNodeList(NodeList node);
35 R visitOperator(Operator node); 36 R visitOperator(Operator node);
36 R visitParenthesizedExpression(ParenthesizedExpression node); 37 R visitParenthesizedExpression(ParenthesizedExpression node);
37 R visitReturn(Return node); 38 R visitReturn(Return node);
38 R visitScriptTag(ScriptTag node); 39 R visitScriptTag(ScriptTag node);
39 R visitSend(Send node); 40 R visitSend(Send node);
40 R visitSendSet(SendSet node); 41 R visitSendSet(SendSet node);
41 R visitStringInterpolation(StringInterpolation node); 42 R visitStringInterpolation(StringInterpolation node);
42 R visitStringInterpolationPart(StringInterpolationPart node); 43 R visitStringInterpolationPart(StringInterpolationPart node);
44 R visitSwitchCase(SwitchCase node);
43 R visitSwitchStatement(SwitchStatement node); 45 R visitSwitchStatement(SwitchStatement node);
44 R visitThrow(Throw node); 46 R visitThrow(Throw node);
45 R visitTryStatement(TryStatement node); 47 R visitTryStatement(TryStatement node);
46 R visitTypeAnnotation(TypeAnnotation node); 48 R visitTypeAnnotation(TypeAnnotation node);
47 R visitTypedef(Typedef node); 49 R visitTypedef(Typedef node);
48 R visitVariableDefinitions(VariableDefinitions node); 50 R visitVariableDefinitions(VariableDefinitions node);
49 R visitWhile(While node); 51 R visitWhile(While node);
50 } 52 }
51 53
52 Token firstBeginToken(Node first, Node second) { 54 Token firstBeginToken(Node first, Node second) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 abstract Token getBeginToken(); 97 abstract Token getBeginToken();
96 98
97 abstract Token getEndToken(); 99 abstract Token getEndToken();
98 100
99 Block asBlock() => null; 101 Block asBlock() => null;
100 BreakStatement asBreakStatement() => null; 102 BreakStatement asBreakStatement() => null;
101 CatchBlock asCatchBlock() => null; 103 CatchBlock asCatchBlock() => null;
102 ClassNode asClassNode() => null; 104 ClassNode asClassNode() => null;
103 Conditional asConditional() => null; 105 Conditional asConditional() => null;
104 ContinueStatement asContinueStatement() => null; 106 ContinueStatement asContinueStatement() => null;
107 DefaultCase asDefaultCase() => null;
105 DoWhile asDoWhile() => null; 108 DoWhile asDoWhile() => null;
106 EmptyStatement asEmptyStatement() => null; 109 EmptyStatement asEmptyStatement() => null;
107 Expression asExpression() => null; 110 Expression asExpression() => null;
108 ExpressionStatement asExpressionStatement() => null; 111 ExpressionStatement asExpressionStatement() => null;
109 For asFor() => null; 112 For asFor() => null;
110 ForInStatement asForInStatement() => null; 113 ForInStatement asForInStatement() => null;
111 FunctionDeclaration asFunctionDeclaration() => null; 114 FunctionDeclaration asFunctionDeclaration() => null;
112 FunctionExpression asFunctionExpression() => null; 115 FunctionExpression asFunctionExpression() => null;
113 Identifier asIdentifier() => null; 116 Identifier asIdentifier() => null;
114 If asIf() => null; 117 If asIf() => null;
(...skipping 11 matching lines...) Expand all
126 NodeList asNodeList() => null; 129 NodeList asNodeList() => null;
127 Operator asOperator() => null; 130 Operator asOperator() => null;
128 ParenthesizedExpression asParenthesizedExpression() => null; 131 ParenthesizedExpression asParenthesizedExpression() => null;
129 Return asReturn() => null; 132 Return asReturn() => null;
130 ScriptTag asScriptTag() => null; 133 ScriptTag asScriptTag() => null;
131 Send asSend() => null; 134 Send asSend() => null;
132 SendSet asSendSet() => null; 135 SendSet asSendSet() => null;
133 Statement asStatement() => null; 136 Statement asStatement() => null;
134 StringInterpolation asStringInterpolation() => null; 137 StringInterpolation asStringInterpolation() => null;
135 StringInterpolationPart asStringInterpolationPart() => null; 138 StringInterpolationPart asStringInterpolationPart() => null;
139 SwitchCase asSwitchCase() => null;
136 SwitchStatement asSwitchStatement() => null; 140 SwitchStatement asSwitchStatement() => null;
137 Throw asThrow() => null; 141 Throw asThrow() => null;
138 TryStatement asTryStatement() => null; 142 TryStatement asTryStatement() => null;
139 TypeAnnotation asTypeAnnotation() => null; 143 TypeAnnotation asTypeAnnotation() => null;
140 Typedef asTypedef() => null; 144 Typedef asTypedef() => null;
141 VariableDefinitions asVariableDefinitions() => null; 145 VariableDefinitions asVariableDefinitions() => null;
142 While asWhile() => null; 146 While asWhile() => null;
143 } 147 }
144 148
145 class ClassNode extends Node { 149 class ClassNode extends Node {
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 expression.accept(visitor); 1371 expression.accept(visitor);
1368 } 1372 }
1369 1373
1370 Token getBeginToken() => name.getBeginToken(); 1374 Token getBeginToken() => name.getBeginToken();
1371 1375
1372 Token getEndToken() => expression.getEndToken(); 1376 Token getEndToken() => expression.getEndToken();
1373 } 1377 }
1374 1378
1375 class SwitchStatement extends Statement { 1379 class SwitchStatement extends Statement {
1376 final ParenthesizedExpression parenthesizedExpression; 1380 final ParenthesizedExpression parenthesizedExpression;
1381 final NodeList cases;
1377 1382
1378 final Token switchKeyword; 1383 final Token switchKeyword;
1379 final Token endToken;
1380 // TODO(ahe): More to come...
1381 1384
1382 SwitchStatement(this.parenthesizedExpression, 1385 SwitchStatement(this.parenthesizedExpression, this.cases,
1383 this.switchKeyword, this.endToken); 1386 this.switchKeyword);
1384 1387
1385 SwitchStatement asSwitchStatement() => this; 1388 SwitchStatement asSwitchStatement() => this;
1386 1389
1387 Expression get expression() => parenthesizedExpression.expression; 1390 Expression get expression() => parenthesizedExpression.expression;
1388 1391
1389 accept(Visitor visitor) => visitor.visitSwitchStatement(this); 1392 accept(Visitor visitor) => visitor.visitSwitchStatement(this);
1390 1393
1391 visitChildren(Visitor visitor) { 1394 visitChildren(Visitor visitor) {
1392 parenthesizedExpression.accept(visitor); 1395 parenthesizedExpression.accept(visitor);
1393 // TODO(ahe): Add more stuff here. 1396 cases.accept(visitor);
1394 } 1397 }
1395 1398
1396 Token getBeginToken() => switchKeyword; 1399 Token getBeginToken() => switchKeyword;
1397 1400
1398 Token getEndToken() => endToken; 1401 Token getEndToken() => cases.getEndToken();
1402 }
1403
1404 class SwitchCase extends Node {
1405 final Identifier label;
1406 final Expression expression;
Lasse Reichstein Nielsen 2012/03/05 19:54:04 Only one expression per case? How is foo: case 1
ahe 2012/03/05 20:07:23 new SwitchCase('foo', 1, []); new SwitchCase(null,
1407 final NodeList statements;
1408
1409 final Token caseKeyword;
1410
1411 SwitchCase(this.label, this.expression, this.statements, this.caseKeyword);
1412
1413 SwitchCase asSwitchCase() => this;
1414
1415 accept(Visitor visitor) => visitor.visitSwitchCase(this);
1416
1417 visitChildren(Visitor visitor) {
1418 if (label !== null) label.accept(visitor);
1419 expression.accept(visitor);
1420 statements.accept(visitor);
1421 }
1422
1423 Token getBeginToken() {
1424 if (label !== null) return label.getBeginToken();
1425 return caseKeyword;
1426 }
1427
1428 Token getEndToken() => statements.getEndToken();
1429 }
1430
1431 class DefaultCase extends Node {
1432 final Identifier label;
1433 final NodeList statements;
1434
1435 final Token defaultKeyword;
1436
1437 DefaultCase(this.label, this.statements, this.defaultKeyword);
1438
1439 DefaultCase asDefaultCase() => this;
1440
1441 accept(Visitor visitor) => visitor.visitDefaultCase(this);
1442
1443 visitChildren(Visitor visitor) {
1444 if (label !== null) label.accept(visitor);
1445 statements.accept(visitor);
1446 }
1447
1448 Token getBeginToken() {
1449 if (label === null) return label.getBeginToken();
1450 return defaultKeyword;
1451 }
1452
1453 Token getEndToken() => statements.getEndToken();
1399 } 1454 }
1400 1455
1401 class GotoStatement extends Statement { 1456 class GotoStatement extends Statement {
1402 final Identifier target; 1457 final Identifier target;
1403 final Token keywordToken; 1458 final Token keywordToken;
1404 final Token semicolonToken; 1459 final Token semicolonToken;
1405 1460
1406 GotoStatement(this.target, this.keywordToken, this.semicolonToken); 1461 GotoStatement(this.target, this.keywordToken, this.semicolonToken);
1407 1462
1408 visitChildren(Visitor visitor) { 1463 visitChildren(Visitor visitor) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 static bool isConstructorRedirect(Send node) { 1670 static bool isConstructorRedirect(Send node) {
1616 return (node.receiver === null && 1671 return (node.receiver === null &&
1617 node.selector.asIdentifier() !== null && 1672 node.selector.asIdentifier() !== null &&
1618 node.selector.asIdentifier().isThis()) || 1673 node.selector.asIdentifier().isThis()) ||
1619 (node.receiver !== null && 1674 (node.receiver !== null &&
1620 node.receiver.asIdentifier() !== null && 1675 node.receiver.asIdentifier() !== null &&
1621 node.receiver.asIdentifier().isThis() && 1676 node.receiver.asIdentifier().isThis() &&
1622 node.selector.asIdentifier() !== null); 1677 node.selector.asIdentifier() !== null);
1623 } 1678 }
1624 } 1679 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698