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 part of js_ast; | 5 part of js_ast; |
6 | 6 |
7 abstract class NodeVisitor<T> { | 7 abstract class NodeVisitor<T> { |
8 T visitProgram(Program node); | 8 T visitProgram(Program node); |
9 | 9 |
10 T visitBlock(Block node); | 10 T visitBlock(Block node); |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 | 438 |
439 Statement toReturn() => this; | 439 Statement toReturn() => this; |
440 | 440 |
441 accept(NodeVisitor visitor) => visitor.visitReturn(this); | 441 accept(NodeVisitor visitor) => visitor.visitReturn(this); |
442 | 442 |
443 void visitChildren(NodeVisitor visitor) { | 443 void visitChildren(NodeVisitor visitor) { |
444 if (value != null) value.accept(visitor); | 444 if (value != null) value.accept(visitor); |
445 } | 445 } |
446 | 446 |
447 Return _clone() => new Return(value); | 447 Return _clone() => new Return(value); |
| 448 |
| 449 static bool foundIn(Node node) { |
| 450 _returnFinder.found = false; |
| 451 node.accept(_returnFinder); |
| 452 return _returnFinder.found; |
| 453 } |
448 } | 454 } |
449 | 455 |
| 456 final _returnFinder = new _ReturnFinder(); |
| 457 class _ReturnFinder extends BaseVisitor { |
| 458 bool found = false; |
| 459 visitReturn(Return node) { |
| 460 found = true; |
| 461 } |
| 462 visitNode(Node node) { |
| 463 if (!found) super.visitNode(node); |
| 464 } |
| 465 } |
| 466 |
| 467 |
450 class Throw extends Statement { | 468 class Throw extends Statement { |
451 final Expression expression; | 469 final Expression expression; |
452 | 470 |
453 Throw(this.expression); | 471 Throw(this.expression); |
454 | 472 |
455 accept(NodeVisitor visitor) => visitor.visitThrow(this); | 473 accept(NodeVisitor visitor) => visitor.visitThrow(this); |
456 | 474 |
457 void visitChildren(NodeVisitor visitor) { | 475 void visitChildren(NodeVisitor visitor) { |
458 expression.accept(visitor); | 476 expression.accept(visitor); |
459 } | 477 } |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 final Expression expression; | 1552 final Expression expression; |
1535 | 1553 |
1536 CommentExpression(this.comment, this.expression); | 1554 CommentExpression(this.comment, this.expression); |
1537 | 1555 |
1538 int get precedenceLevel => PRIMARY; | 1556 int get precedenceLevel => PRIMARY; |
1539 accept(NodeVisitor visitor) => visitor.visitCommentExpression(this); | 1557 accept(NodeVisitor visitor) => visitor.visitCommentExpression(this); |
1540 CommentExpression _clone() => new CommentExpression(comment, expression); | 1558 CommentExpression _clone() => new CommentExpression(comment, expression); |
1541 | 1559 |
1542 void visitChildren(NodeVisitor visitor) => expression.accept(visitor); | 1560 void visitChildren(NodeVisitor visitor) => expression.accept(visitor); |
1543 } | 1561 } |
OLD | NEW |