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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 } | 771 } |
772 | 772 |
773 class ArrayInitializer extends Expression { | 773 class ArrayInitializer extends Expression { |
774 final int length; | 774 final int length; |
775 // We represent the array as sparse list of elements. Each element knows its | 775 // We represent the array as sparse list of elements. Each element knows its |
776 // position in the array. | 776 // position in the array. |
777 final List<ArrayElement> elements; | 777 final List<ArrayElement> elements; |
778 | 778 |
779 ArrayInitializer(this.length, this.elements); | 779 ArrayInitializer(this.length, this.elements); |
780 | 780 |
781 factory ArrayInitializer.from(List<Expression> expressions) => | 781 factory ArrayInitializer.from(Iterable<Expression> expressions) => |
782 new ArrayInitializer(expressions.length, _convert(expressions)); | 782 new ArrayInitializer(expressions.length, _convert(expressions)); |
783 | 783 |
784 accept(NodeVisitor visitor) => visitor.visitArrayInitializer(this); | 784 accept(NodeVisitor visitor) => visitor.visitArrayInitializer(this); |
785 | 785 |
786 void visitChildren(NodeVisitor visitor) { | 786 void visitChildren(NodeVisitor visitor) { |
787 for (ArrayElement element in elements) element.accept(visitor); | 787 for (ArrayElement element in elements) element.accept(visitor); |
788 } | 788 } |
789 | 789 |
790 int get precedenceLevel => PRIMARY; | 790 int get precedenceLevel => PRIMARY; |
791 | 791 |
792 static List<ArrayElement> _convert(List<Expression> expressions) { | 792 static List<ArrayElement> _convert(Iterable<Expression> expressions) { |
793 int index = 0; | 793 int index = 0; |
794 return expressions.map( | 794 return expressions.map( |
795 (expression) => new ArrayElement(index++, expression)) | 795 (expression) => new ArrayElement(index++, expression)) |
796 .toList(); | 796 .toList(); |
797 } | 797 } |
798 } | 798 } |
799 | 799 |
800 /** | 800 /** |
801 * An expression inside an [ArrayInitialization]. An [ArrayElement] knows | 801 * An expression inside an [ArrayInitialization]. An [ArrayElement] knows |
802 * its position in the containing [ArrayInitialization]. | 802 * its position in the containing [ArrayInitialization]. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 | 897 |
898 Fun fun(List<String> parameterNames, Block body) { | 898 Fun fun(List<String> parameterNames, Block body) { |
899 return new Fun(parameterNames.map((n) => new Parameter(n)).toList(), body); | 899 return new Fun(parameterNames.map((n) => new Parameter(n)).toList(), body); |
900 } | 900 } |
901 | 901 |
902 Assignment assign(Expression leftHandSide, Expression value) { | 902 Assignment assign(Expression leftHandSide, Expression value) { |
903 return new Assignment(leftHandSide, value); | 903 return new Assignment(leftHandSide, value); |
904 } | 904 } |
905 | 905 |
906 Expression undefined() => new Prefix('void', new LiteralNumber('0')); | 906 Expression undefined() => new Prefix('void', new LiteralNumber('0')); |
OLD | NEW |