Chromium Code Reviews| 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; | 5 part of js; |
| 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 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 } | 762 } |
| 763 | 763 |
| 764 class ArrayInitializer extends Expression { | 764 class ArrayInitializer extends Expression { |
| 765 final int length; | 765 final int length; |
| 766 // We represent the array as sparse list of elements. Each element knows its | 766 // We represent the array as sparse list of elements. Each element knows its |
| 767 // position in the array. | 767 // position in the array. |
| 768 final List<ArrayElement> elements; | 768 final List<ArrayElement> elements; |
| 769 | 769 |
| 770 ArrayInitializer(this.length, this.elements); | 770 ArrayInitializer(this.length, this.elements); |
| 771 | 771 |
| 772 factory ArrayInitializer.from(List<Expression> expressions) => | |
| 773 new ArrayInitializer(expressions.length, _convert(expressions)); | |
| 774 | |
| 772 accept(NodeVisitor visitor) => visitor.visitArrayInitializer(this); | 775 accept(NodeVisitor visitor) => visitor.visitArrayInitializer(this); |
| 773 | 776 |
| 774 void visitChildren(NodeVisitor visitor) { | 777 void visitChildren(NodeVisitor visitor) { |
| 775 for (ArrayElement element in elements) element.accept(visitor); | 778 for (ArrayElement element in elements) element.accept(visitor); |
| 776 } | 779 } |
| 777 | 780 |
| 778 int get precedenceLevel => PRIMARY; | 781 int get precedenceLevel => PRIMARY; |
| 782 | |
| 783 static List<ArrayElement> _convert(List<Expression> expressions) { | |
|
ngeoffray
2012/11/22 08:49:47
List<ArrayElement> is kind of not true.
| |
| 784 int index = 0; | |
| 785 return expressions.map( | |
| 786 (expression) => new ArrayElement(index++, expression)); | |
| 787 } | |
| 779 } | 788 } |
| 780 | 789 |
| 781 /** | 790 /** |
| 782 * An expression inside an [ArrayInitialization]. An [ArrayElement] knows | 791 * An expression inside an [ArrayInitialization]. An [ArrayElement] knows |
| 783 * its position in the containing [ArrayInitialization]. | 792 * its position in the containing [ArrayInitialization]. |
| 784 */ | 793 */ |
| 785 class ArrayElement extends Node { | 794 class ArrayElement extends Node { |
| 786 int index; | 795 int index; |
| 787 Expression value; | 796 Expression value; |
| 788 | 797 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 832 /** Contains the pattern and the flags.*/ | 841 /** Contains the pattern and the flags.*/ |
| 833 String pattern; | 842 String pattern; |
| 834 | 843 |
| 835 RegExpLiteral(this.pattern); | 844 RegExpLiteral(this.pattern); |
| 836 | 845 |
| 837 accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this); | 846 accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this); |
| 838 void visitChildren(NodeVisitor visitor) {} | 847 void visitChildren(NodeVisitor visitor) {} |
| 839 | 848 |
| 840 int get precedenceLevel => PRIMARY; | 849 int get precedenceLevel => PRIMARY; |
| 841 } | 850 } |
| OLD | NEW |