| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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() => pattern.getEndToken().next(); |
| 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 // Represents the grammar: |
| 1326 // label? ('case' expression ':')* ('default' ':')? statement* | 1341 // (label | 'case' expression ':')* ('default' ':')? statement* |
| 1327 // Each expression is collected in [expressions]. | 1342 // The labels are collected in [labels]. |
| 1328 // The 'case' keywords can be obtained using [caseKeywords()]. | 1343 // Each case patterns are collected in [cases]. |
| 1344 // The default keyword, if present, is collected in [defaultKeyword]. |
| 1329 // Any actual switch case must have at least one 'case' or 'default' | 1345 // Any actual switch case must have at least one 'case' or 'default' |
| 1330 // clause. | 1346 // clause. |
| 1331 final Label label; | 1347 // Notice: The labels and cases can occur interleaved in the source. |
| 1332 final NodeList expressions; | 1348 // They are separated here, since the order is irrelevant to the meaning |
| 1349 // of the switch. |
| 1350 |
| 1351 /** List of [Identifier] of labels. */ |
| 1352 final NodeList labels; |
| 1353 /** List of [CaseMatch] structures. */ |
| 1354 final NodeList cases; |
| 1355 /** A "default" keyword token, if applicable. */ |
| 1333 final Token defaultKeyword; | 1356 final Token defaultKeyword; |
| 1357 /** List of statements, the body of the case. */ |
| 1334 final NodeList statements; | 1358 final NodeList statements; |
| 1335 | 1359 |
| 1336 final Token startToken; | 1360 final Token startToken; |
| 1337 | 1361 |
| 1338 SwitchCase(this.label, this.expressions, this.defaultKeyword, | 1362 SwitchCase(this.labels, this.cases, this.defaultKeyword, |
| 1339 this.statements, this.startToken); | 1363 this.statements, this.startToken); |
| 1340 | 1364 |
| 1341 SwitchCase asSwitchCase() => this; | 1365 SwitchCase asSwitchCase() => this; |
| 1342 | 1366 |
| 1343 bool get isDefaultCase() => defaultKeyword !== null; | 1367 bool get isDefaultCase() => defaultKeyword !== null; |
| 1344 | 1368 |
| 1369 bool isValidContinueTarget() => true; |
| 1370 |
| 1345 accept(Visitor visitor) => visitor.visitSwitchCase(this); | 1371 accept(Visitor visitor) => visitor.visitSwitchCase(this); |
| 1346 | 1372 |
| 1347 visitChildren(Visitor visitor) { | 1373 visitChildren(Visitor visitor) { |
| 1348 if (label !== null) label.accept(visitor); | 1374 labels.accept(visitor); |
| 1349 expressions.accept(visitor); | 1375 cases.accept(visitor); |
| 1350 statements.accept(visitor); | 1376 statements.accept(visitor); |
| 1351 } | 1377 } |
| 1352 | 1378 |
| 1353 Token getBeginToken() { | 1379 Token getBeginToken() { |
| 1354 return startToken; | 1380 return startToken; |
| 1355 } | 1381 } |
| 1356 | 1382 |
| 1357 Token getEndToken() { | 1383 Token getEndToken() { |
| 1358 if (statements.nodes.isEmpty()) { | 1384 if (statements.nodes.isEmpty()) { |
| 1359 // All cases must have at least one expression or be the default. | 1385 // All cases must have at least one expression or be the default. |
| 1360 if (defaultKeyword !== null) { | 1386 if (defaultKeyword !== null) { |
| 1361 // The colon after 'default'. | 1387 // The colon after 'default'. |
| 1362 return defaultKeyword.next; | 1388 return defaultKeyword.next; |
| 1363 } | 1389 } |
| 1364 // The colon after the expression. | 1390 // The colon after the last expression. |
| 1365 return expressions.getEndToken().next; | 1391 return cases.getEndToken(); |
| 1366 } else { | 1392 } else { |
| 1367 return statements.getEndToken(); | 1393 return statements.getEndToken(); |
| 1368 } | 1394 } |
| 1369 } | 1395 } |
| 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 } | 1396 } |
| 1389 | 1397 |
| 1390 class GotoStatement extends Statement { | 1398 class GotoStatement extends Statement { |
| 1391 final Identifier target; | 1399 final Label target; |
| 1392 final Token keywordToken; | 1400 final Token keywordToken; |
| 1393 final Token semicolonToken; | 1401 final Token semicolonToken; |
| 1394 | 1402 |
| 1395 GotoStatement(this.target, this.keywordToken, this.semicolonToken); | 1403 GotoStatement(this.target, this.keywordToken, this.semicolonToken); |
| 1396 | 1404 |
| 1397 visitChildren(Visitor visitor) { | 1405 visitChildren(Visitor visitor) { |
| 1398 if (target !== null) target.accept(visitor); | 1406 if (target !== null) target.accept(visitor); |
| 1399 } | 1407 } |
| 1400 | 1408 |
| 1401 Token getBeginToken() => keywordToken; | 1409 Token getBeginToken() => keywordToken; |
| 1402 | 1410 |
| 1403 Token getEndToken() => semicolonToken; | 1411 Token getEndToken() => semicolonToken; |
| 1404 | 1412 |
| 1405 // TODO(ahe): make class abstract instead of adding an abstract method. | 1413 // TODO(ahe): make class abstract instead of adding an abstract method. |
| 1406 abstract accept(Visitor visitor); | 1414 abstract accept(Visitor visitor); |
| 1407 } | 1415 } |
| 1408 | 1416 |
| 1409 class BreakStatement extends GotoStatement { | 1417 class BreakStatement extends GotoStatement { |
| 1410 BreakStatement(Identifier target, Token keywordToken, Token semicolonToken) | 1418 BreakStatement(Label target, Token keywordToken, Token semicolonToken) |
| 1411 : super(target, keywordToken, semicolonToken); | 1419 : super(target, keywordToken, semicolonToken); |
| 1412 | 1420 |
| 1413 BreakStatement asBreakStatement() => this; | 1421 BreakStatement asBreakStatement() => this; |
| 1414 | 1422 |
| 1415 accept(Visitor visitor) => visitor.visitBreakStatement(this); | 1423 accept(Visitor visitor) => visitor.visitBreakStatement(this); |
| 1416 } | 1424 } |
| 1417 | 1425 |
| 1418 class ContinueStatement extends GotoStatement { | 1426 class ContinueStatement extends GotoStatement { |
| 1419 ContinueStatement(Identifier target, Token keywordToken, Token semicolonToken) | 1427 ContinueStatement(Label target, Token keywordToken, Token semicolonToken) |
| 1420 : super(target, keywordToken, semicolonToken); | 1428 : super(target, keywordToken, semicolonToken); |
| 1421 | 1429 |
| 1422 ContinueStatement asContinueStatement() => this; | 1430 ContinueStatement asContinueStatement() => this; |
| 1423 | 1431 |
| 1424 accept(Visitor visitor) => visitor.visitContinueStatement(this); | 1432 accept(Visitor visitor) => visitor.visitContinueStatement(this); |
| 1425 } | 1433 } |
| 1426 | 1434 |
| 1427 class ForIn extends Loop { | 1435 class ForIn extends Loop { |
| 1428 final Node declaredIdentifier; | 1436 final Node declaredIdentifier; |
| 1429 final Expression expression; | 1437 final Expression expression; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 * argument). | 1710 * argument). |
| 1703 * | 1711 * |
| 1704 * TODO(ahe): This method is controversial, the team needs to discuss | 1712 * TODO(ahe): This method is controversial, the team needs to discuss |
| 1705 * if top-level methods are acceptable and what naming conventions to | 1713 * if top-level methods are acceptable and what naming conventions to |
| 1706 * use. | 1714 * use. |
| 1707 */ | 1715 */ |
| 1708 initializerDo(Node node, f(Node node)) { | 1716 initializerDo(Node node, f(Node node)) { |
| 1709 SendSet send = node.asSendSet(); | 1717 SendSet send = node.asSendSet(); |
| 1710 if (send !== null) return f(send.arguments.head); | 1718 if (send !== null) return f(send.arguments.head); |
| 1711 } | 1719 } |
| OLD | NEW |