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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/tree/nodes.dart

Issue 11783009: Big merge from experimental to bleeding edge. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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) 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 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 Send asSend() => this; 281 Send asSend() => this;
282 282
283 accept(Visitor visitor) => visitor.visitSend(this); 283 accept(Visitor visitor) => visitor.visitSend(this);
284 284
285 visitChildren(Visitor visitor) { 285 visitChildren(Visitor visitor) {
286 if (receiver != null) receiver.accept(visitor); 286 if (receiver != null) receiver.accept(visitor);
287 if (selector != null) selector.accept(visitor); 287 if (selector != null) selector.accept(visitor);
288 if (argumentsNode != null) argumentsNode.accept(visitor); 288 if (argumentsNode != null) argumentsNode.accept(visitor);
289 } 289 }
290 290
291 int argumentCount() => (argumentsNode == null) ? -1 : argumentsNode.length(); 291 int argumentCount() => (argumentsNode == null) ? -1 : argumentsNode.length;
292 292
293 bool get isSuperCall { 293 bool get isSuperCall {
294 return receiver != null && 294 return receiver != null &&
295 receiver.asIdentifier() != null && 295 receiver.asIdentifier() != null &&
296 receiver.asIdentifier().isSuper(); 296 receiver.asIdentifier().isSuper();
297 } 297 }
298 bool get isOperator => selector is Operator; 298 bool get isOperator => selector is Operator;
299 bool get isPropertyAccess => argumentsNode == null; 299 bool get isPropertyAccess => argumentsNode == null;
300 bool get isFunctionObjectInvocation => selector == null; 300 bool get isFunctionObjectInvocation => selector == null;
301 bool get isPrefix => argumentsNode is Prefix; 301 bool get isPrefix => argumentsNode is Prefix;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 412
413 class NodeList extends Node implements Iterable<Node> { 413 class NodeList extends Node implements Iterable<Node> {
414 final Link<Node> nodes; 414 final Link<Node> nodes;
415 final Token beginToken; 415 final Token beginToken;
416 final Token endToken; 416 final Token endToken;
417 final SourceString delimiter; 417 final SourceString delimiter;
418 bool get isEmpty => nodes.isEmpty; 418 bool get isEmpty => nodes.isEmpty;
419 419
420 NodeList([this.beginToken, this.nodes, this.endToken, this.delimiter]); 420 NodeList([this.beginToken, this.nodes, this.endToken, this.delimiter]);
421 421
422 Iterator<Node> iterator() => nodes.iterator(); 422 Iterator<Node> get iterator => nodes.iterator;
423 423
424 NodeList.singleton(Node node) : this(null, const Link<Node>().prepend(node)); 424 NodeList.singleton(Node node) : this(null, const Link<Node>().prepend(node));
425 NodeList.empty() : this(null, const Link<Node>()); 425 NodeList.empty() : this(null, const Link<Node>());
426 426
427 NodeList asNodeList() => this; 427 NodeList asNodeList() => this;
428 428
429 int length() { 429 int get length {
430 int result = 0; 430 int result = 0;
431 for (Link<Node> cursor = nodes; !cursor.isEmpty; cursor = cursor.tail) { 431 for (Link<Node> cursor = nodes; !cursor.isEmpty; cursor = cursor.tail) {
432 result++; 432 result++;
433 } 433 }
434 return result; 434 return result;
435 } 435 }
436 436
437 accept(Visitor visitor) => visitor.visitNodeList(this); 437 accept(Visitor visitor) => visitor.visitNodeList(this);
438 438
439 visitChildren(Visitor visitor) { 439 visitChildren(Visitor visitor) {
(...skipping 22 matching lines...) Expand all
462 if (endToken != null) return endToken; 462 if (endToken != null) return endToken;
463 if (nodes != null) { 463 if (nodes != null) {
464 Link<Node> link = nodes; 464 Link<Node> link = nodes;
465 if (link.isEmpty) return beginToken; 465 if (link.isEmpty) return beginToken;
466 while (!link.tail.isEmpty) link = link.tail; 466 while (!link.tail.isEmpty) link = link.tail;
467 if (link.head.getEndToken() != null) return link.head.getEndToken(); 467 if (link.head.getEndToken() != null) return link.head.getEndToken();
468 if (link.head.getBeginToken() != null) return link.head.getBeginToken(); 468 if (link.head.getBeginToken() != null) return link.head.getBeginToken();
469 } 469 }
470 return beginToken; 470 return beginToken;
471 } 471 }
472
473 // ------------------- Iterable methods -------------------------------------
474 //
475 // TODO(floitsch): these functions should be pulled in through a mixin
476 // mechanism.
477 Iterable mappedBy(f(Node element)) => new MappedIterable(this, f);
478
479 Iterable<Node> where(bool f(Node element))
480 => new WhereIterable<Node>(this, f);
481
482 bool contains(Node element) {
483 for (Node e in this) {
484 if (e == element) return true;
485 }
486 return false;
487 }
488
489 void forEach(void f(Node element)) {
490 for (Node element in this) f(element);
491 }
492
493 String join([String separator]) => Collections.join(this, separator);
494
495 dynamic reduce(var initialValue,
496 dynamic combine(var previousValue, Node element)) {
497 var value = initialValue;
498 for (Node element in this) value = combine(value, element);
499 return value;
500 }
501
502 bool every(bool f(Node element)) {
503 for (Node element in this) {
504 if (!f(element)) return false;
505 }
506 return true;
507 }
508
509 bool any(bool f(Node element)) {
510 for (Node element in this) {
511 if (f(element)) return true;
512 }
513 return false;
514 }
515
516 List<Node> toList() => new List<Node>.from(this);
517
518 Set<Node> toSet() => new Set<Node>.from(this);
519
520 Iterable<Node> take(int n) => new TakeIterable<Node>(this, n);
521
522 Iterable<Node> takeWhile(bool test(Node value)) {
523 return new TakeWhileIterable<Node>(this, test);
524 }
525
526 Iterable<Node> skip(int n) => new SkipIterable<Node>(this, n);
527
528 Iterable<Node> skipWhile(bool test(Node value)) {
529 return new SkipWhileIterable<Node>(this, test);
530 }
531
532 Node get first {
533 return Collections.first(this);
534 }
535
536 Node get last {
537 return Collections.last(this);
538 }
539
540 Node get single {
541 return Collections.single(this);
542 }
543
544 Node min([int compare(Node a, Node b)]) => Collections.min(this, compare);
545
546 Node max([int compare(Node a, Node b)]) => Collections.max(this, compare);
547
548 Node firstMatching(bool test(Node value), {Node orElse()}) {
549 return Collections.firstMatching(this, test, orElse);
550 }
551
552 Node lastMatching(bool test(Node value), {Node orElse()}) {
553 return Collections.lastMatching(this, test, orElse);
554 }
555
556 Node singleMatching(bool test(Node value)) {
557 return Collections.singleMatching(this, test);
558 }
559
560 Node elementAt(int index) {
561 return Collections.elementAt(this, index);
562 }
472 } 563 }
473 564
474 class Block extends Statement { 565 class Block extends Statement {
475 final NodeList statements; 566 final NodeList statements;
476 567
477 Block(this.statements); 568 Block(this.statements);
478 569
479 Block asBlock() => this; 570 Block asBlock() => this;
480 571
481 accept(Visitor visitor) => visitor.visitBlock(this); 572 accept(Visitor visitor) => visitor.visitBlock(this);
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 770
680 class LiteralInt extends Literal<int> { 771 class LiteralInt extends Literal<int> {
681 LiteralInt(Token token, DecodeErrorHandler handler) : super(token, handler); 772 LiteralInt(Token token, DecodeErrorHandler handler) : super(token, handler);
682 773
683 LiteralInt asLiteralInt() => this; 774 LiteralInt asLiteralInt() => this;
684 775
685 int get value { 776 int get value {
686 try { 777 try {
687 Token valueToken = token; 778 Token valueToken = token;
688 if (identical(valueToken.kind, PLUS_TOKEN)) valueToken = valueToken.next; 779 if (identical(valueToken.kind, PLUS_TOKEN)) valueToken = valueToken.next;
689 return parseInt(valueToken.value.slowToString()); 780 return int.parse(valueToken.value.slowToString());
690 } on FormatException catch (ex) { 781 } on FormatException catch (ex) {
691 (this.handler)(token, ex); 782 (this.handler)(token, ex);
692 } 783 }
693 } 784 }
694 785
695 accept(Visitor visitor) => visitor.visitLiteralInt(this); 786 accept(Visitor visitor) => visitor.visitLiteralInt(this);
696 } 787 }
697 788
698 class LiteralDouble extends Literal<double> { 789 class LiteralDouble extends Literal<double> {
699 LiteralDouble(Token token, DecodeErrorHandler handler) 790 LiteralDouble(Token token, DecodeErrorHandler handler)
700 : super(token, handler); 791 : super(token, handler);
701 792
702 LiteralDouble asLiteralDouble() => this; 793 LiteralDouble asLiteralDouble() => this;
703 794
704 double get value { 795 double get value {
705 try { 796 try {
706 Token valueToken = token; 797 Token valueToken = token;
707 if (identical(valueToken.kind, PLUS_TOKEN)) valueToken = valueToken.next; 798 if (identical(valueToken.kind, PLUS_TOKEN)) valueToken = valueToken.next;
708 return parseDouble(valueToken.value.slowToString()); 799 return double.parse(valueToken.value.slowToString());
709 } on FormatException catch (ex) { 800 } on FormatException catch (ex) {
710 (this.handler)(token, ex); 801 (this.handler)(token, ex);
711 } 802 }
712 } 803 }
713 804
714 accept(Visitor visitor) => visitor.visitLiteralDouble(this); 805 accept(Visitor visitor) => visitor.visitLiteralDouble(this);
715 } 806 }
716 807
717 class LiteralBool extends Literal<bool> { 808 class LiteralBool extends Literal<bool> {
718 LiteralBool(Token token, DecodeErrorHandler handler) : super(token, handler); 809 LiteralBool(Token token, DecodeErrorHandler handler) : super(token, handler);
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 * argument). 2089 * argument).
1999 * 2090 *
2000 * TODO(ahe): This method is controversial, the team needs to discuss 2091 * TODO(ahe): This method is controversial, the team needs to discuss
2001 * if top-level methods are acceptable and what naming conventions to 2092 * if top-level methods are acceptable and what naming conventions to
2002 * use. 2093 * use.
2003 */ 2094 */
2004 initializerDo(Node node, f(Node node)) { 2095 initializerDo(Node node, f(Node node)) {
2005 SendSet send = node.asSendSet(); 2096 SendSet send = node.asSendSet();
2006 if (send != null) return f(send.arguments.head); 2097 if (send != null) return f(send.arguments.head);
2007 } 2098 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698