| 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 tree; | 5 part of tree; |
| 6 | 6 |
| 7 abstract class Visitor<R> { | 7 abstract class Visitor<R> { |
| 8 const Visitor(); | 8 const Visitor(); |
| 9 | 9 |
| 10 R visitNode(Node node); | 10 R visitNode(Node node); |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 if (endToken != null) return endToken; | 459 if (endToken != null) return endToken; |
| 460 if (nodes != null) { | 460 if (nodes != null) { |
| 461 Link<Node> link = nodes; | 461 Link<Node> link = nodes; |
| 462 if (link.isEmpty) return beginToken; | 462 if (link.isEmpty) return beginToken; |
| 463 while (!link.tail.isEmpty) link = link.tail; | 463 while (!link.tail.isEmpty) link = link.tail; |
| 464 if (link.head.getEndToken() != null) return link.head.getEndToken(); | 464 if (link.head.getEndToken() != null) return link.head.getEndToken(); |
| 465 if (link.head.getBeginToken() != null) return link.head.getBeginToken(); | 465 if (link.head.getBeginToken() != null) return link.head.getBeginToken(); |
| 466 } | 466 } |
| 467 return beginToken; | 467 return beginToken; |
| 468 } | 468 } |
| 469 |
| 470 // ------------------- Iterable methods ------------------------------------- |
| 471 // |
| 472 // TODO(floitsch): these functions should be pulled in through a mixin |
| 473 // mechanism. |
| 474 Collection mappedBy(f(Node element)) { |
| 475 List result = []; |
| 476 for (Node element in this) result.add(f(element)); |
| 477 return result; |
| 478 } |
| 479 |
| 480 Collection<Node> where(bool f(Node element)) { |
| 481 List result = <Node>[]; |
| 482 for (Node element in this) if (f(element)) result.add(element); |
| 483 return result; |
| 484 } |
| 485 |
| 486 bool contains(Node element) { |
| 487 for (Node e in this) { |
| 488 if (e == element) return true; |
| 489 } |
| 490 return false; |
| 491 } |
| 492 |
| 493 void forEach(void f(Node element)) { |
| 494 for (Node element in this) f(element); |
| 495 } |
| 496 |
| 497 dynamic reduce(var initialValue, |
| 498 dynamic combine(var previousValue, Node element)) { |
| 499 var value = initialValue; |
| 500 for (Node element in this) value = combine(value, element); |
| 501 return value; |
| 502 } |
| 503 |
| 504 bool every(bool f(Node element)) { |
| 505 for (Node element in this) { |
| 506 if (!f(element)) return false; |
| 507 } |
| 508 return true; |
| 509 } |
| 510 |
| 511 bool some(bool f(Node element)) { |
| 512 for (Node element in this) { |
| 513 if (f(element)) return true; |
| 514 } |
| 515 return false; |
| 516 } |
| 469 } | 517 } |
| 470 | 518 |
| 471 class Block extends Statement { | 519 class Block extends Statement { |
| 472 final NodeList statements; | 520 final NodeList statements; |
| 473 | 521 |
| 474 Block(this.statements); | 522 Block(this.statements); |
| 475 | 523 |
| 476 Block asBlock() => this; | 524 Block asBlock() => this; |
| 477 | 525 |
| 478 accept(Visitor visitor) => visitor.visitBlock(this); | 526 accept(Visitor visitor) => visitor.visitBlock(this); |
| (...skipping 1516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1995 * argument). | 2043 * argument). |
| 1996 * | 2044 * |
| 1997 * TODO(ahe): This method is controversial, the team needs to discuss | 2045 * TODO(ahe): This method is controversial, the team needs to discuss |
| 1998 * if top-level methods are acceptable and what naming conventions to | 2046 * if top-level methods are acceptable and what naming conventions to |
| 1999 * use. | 2047 * use. |
| 2000 */ | 2048 */ |
| 2001 initializerDo(Node node, f(Node node)) { | 2049 initializerDo(Node node, f(Node node)) { |
| 2002 SendSet send = node.asSendSet(); | 2050 SendSet send = node.asSendSet(); |
| 2003 if (send != null) return f(send.arguments.head); | 2051 if (send != null) return f(send.arguments.head); |
| 2004 } | 2052 } |
| OLD | NEW |