| OLD | NEW |
| 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); |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 new RawSourceDartString(source, length); | 704 new RawSourceDartString(source, length); |
| 705 factory DartString.escapedString(SourceString source, int length) => | 705 factory DartString.escapedString(SourceString source, int length) => |
| 706 new EscapedSourceDartString(source, length); | 706 new EscapedSourceDartString(source, length); |
| 707 DartString(); | 707 DartString(); |
| 708 abstract int get length(); | 708 abstract int get length(); |
| 709 bool isEmpty() => length == 0; | 709 bool isEmpty() => length == 0; |
| 710 // TODO(lrn): Is this test too expensive? | 710 // TODO(lrn): Is this test too expensive? |
| 711 bool definitelyEquals(DartString other) => toString() == other.toString(); | 711 bool definitelyEquals(DartString other) => toString() == other.toString(); |
| 712 abstract Iterator<int> iterator(); | 712 abstract Iterator<int> iterator(); |
| 713 abstract String toString(); | 713 abstract String toString(); |
| 714 |
| 715 bool operator ==(var other) { |
| 716 if (other is !DartString) return false; |
| 717 DartString otherString = other; |
| 718 if (length != otherString.length) return false; |
| 719 Iterator it1 = iterator(); |
| 720 Iterator it2 = otherString.iterator(); |
| 721 while (it1.hasNext()) { |
| 722 if (it1.next() != it2.next()) return false; |
| 723 } |
| 724 return true; |
| 725 } |
| 714 } | 726 } |
| 715 | 727 |
| 716 class LiteralDartString extends DartString { | 728 class LiteralDartString extends DartString { |
| 717 final String string; | 729 final String string; |
| 718 LiteralDartString(this.string); | 730 LiteralDartString(this.string); |
| 719 int get length() => string.length; | 731 int get length() => string.length; |
| 720 Iterator<int> iterator() => new StringCodeIterator(string); | 732 Iterator<int> iterator() => new StringCodeIterator(string); |
| 721 String toString() => string; | 733 String toString() => string; |
| 722 } | 734 } |
| 723 | 735 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 740 | 752 |
| 741 class EscapedSourceDartString extends SourceBasedDartString { | 753 class EscapedSourceDartString extends SourceBasedDartString { |
| 742 EscapedSourceDartString(source, length) : super(source, length); | 754 EscapedSourceDartString(source, length) : super(source, length); |
| 743 Iterator<int> iterator() { | 755 Iterator<int> iterator() { |
| 744 if (toStringCache !== null) return new StringCodeIterator(toStringCache); | 756 if (toStringCache !== null) return new StringCodeIterator(toStringCache); |
| 745 return new StringEscapeIterator(source); | 757 return new StringEscapeIterator(source); |
| 746 } | 758 } |
| 747 String toString() { | 759 String toString() { |
| 748 if (toStringCache !== null) return toStringCache; | 760 if (toStringCache !== null) return toStringCache; |
| 749 StringBuffer buffer = new StringBuffer(); | 761 StringBuffer buffer = new StringBuffer(); |
| 750 StringEscapeIterator iterator = new StringEscapeIterator(source); | 762 StringEscapeIterator it = new StringEscapeIterator(source); |
| 751 while (iterator.hasNext()) { | 763 while (it.hasNext()) { |
| 752 buffer.add(new String.fromCharCodes(<int>[iterator.next()])); | 764 buffer.add(new String.fromCharCodes(<int>[it.next()])); |
| 753 } | 765 } |
| 754 toStringCache = buffer.toString(); | 766 toStringCache = buffer.toString(); |
| 755 return toStringCache; | 767 return toStringCache; |
| 756 } | 768 } |
| 757 } | 769 } |
| 758 | 770 |
| 771 class ConsDartString extends DartString { |
| 772 final DartString left; |
| 773 final DartString right; |
| 774 final int length; |
| 775 int hashCache = null; |
| 776 String toStringCache; |
| 777 ConsDartString(DartString left, DartString right) |
| 778 : this.left = left, |
| 779 this.right = right, |
| 780 length = left.length + right.length; |
| 781 |
| 782 Iterator<int> iterator() => new ConsDartStringIterator(this); |
| 783 |
| 784 String toString() { |
| 785 if (toStringCache !== null) return toStringCache; |
| 786 toStringCache = left.toString().concat(right.toString()); |
| 787 return toStringCache; |
| 788 } |
| 789 } |
| 790 |
| 791 class ConsDartStringIterator implements Iterator<int> { |
| 792 Iterator<int> current; |
| 793 DartString right; |
| 794 bool hasNextLookAhead; |
| 795 ConsDartStringIterator(ConsDartString cons) |
| 796 : current = cons.left.iterator(), |
| 797 right = cons.right { |
| 798 hasNextLookAhead = current.hasNext(); |
| 799 if (!hasNextLookAhead) { |
| 800 nextPart(); |
| 801 } |
| 802 } |
| 803 bool hasNext() { |
| 804 return hasNextLookAhead; |
| 805 } |
| 806 int next() { |
| 807 assert(hasNextLookAhead); |
| 808 int result = current.next(); |
| 809 hasNextLookAhead = current.hasNext(); |
| 810 if (!hasNextLookAhead) { |
| 811 nextPart(); |
| 812 } |
| 813 return result; |
| 814 } |
| 815 void nextPart() { |
| 816 if (right !== null) { |
| 817 current = right.iterator(); |
| 818 right = null; |
| 819 hasNextLookAhead = current.hasNext(); |
| 820 } |
| 821 } |
| 822 } |
| 759 | 823 |
| 760 /** | 824 /** |
| 761 *Iterator that returns the actual string contents of a string with escapes. | 825 *Iterator that returns the actual string contents of a string with escapes. |
| 762 */ | 826 */ |
| 763 class StringEscapeIterator implements Iterator<int>{ | 827 class StringEscapeIterator implements Iterator<int>{ |
| 764 final Iterator<int> source; | 828 final Iterator<int> source; |
| 765 StringEscapeIterator(SourceString source) : this.source = source.iterator(); | 829 StringEscapeIterator(SourceString source) : this.source = source.iterator(); |
| 766 bool hasNext() => source.hasNext(); | 830 bool hasNext() => source.hasNext(); |
| 767 int next() { | 831 int next() { |
| 768 int code = source.next(); | 832 int code = source.next(); |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 static bool isConstructorRedirect(Send node) { | 1547 static bool isConstructorRedirect(Send node) { |
| 1484 return (node.receiver === null && | 1548 return (node.receiver === null && |
| 1485 node.selector.asIdentifier() !== null && | 1549 node.selector.asIdentifier() !== null && |
| 1486 node.selector.asIdentifier().isThis()) || | 1550 node.selector.asIdentifier().isThis()) || |
| 1487 (node.receiver !== null && | 1551 (node.receiver !== null && |
| 1488 node.receiver.asIdentifier() !== null && | 1552 node.receiver.asIdentifier() !== null && |
| 1489 node.receiver.asIdentifier().isThis() && | 1553 node.receiver.asIdentifier().isThis() && |
| 1490 node.selector.asIdentifier() !== null); | 1554 node.selector.asIdentifier() !== null); |
| 1491 } | 1555 } |
| 1492 } | 1556 } |
| OLD | NEW |