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

Side by Side Diff: pkg/polymer_expressions/lib/expression.dart

Issue 139903008: List literals in polymer_expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library polymer_expressions.expression; 5 library polymer_expressions.expression;
6 6
7 import 'visitor.dart'; 7 import 'visitor.dart';
8 8
9 // Helper functions for building expression trees programmatically 9 // Helper functions for building expression trees programmatically
10 10
11 EmptyExpression empty() => const EmptyExpression(); 11 EmptyExpression empty() => const EmptyExpression();
12 Literal literal(v) => new Literal(v); 12 Literal literal(v) => new Literal(v);
13 ListLiteral listLiteral(List<Expression> items) => new ListLiteral(items);
13 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => new MapLiteral(entries); 14 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => new MapLiteral(entries);
14 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) => 15 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) =>
15 new MapLiteralEntry(key, value); 16 new MapLiteralEntry(key, value);
16 Identifier ident(String v) => new Identifier(v); 17 Identifier ident(String v) => new Identifier(v);
17 ParenthesizedExpression paren(Expression e) => new ParenthesizedExpression(e); 18 ParenthesizedExpression paren(Expression e) => new ParenthesizedExpression(e);
18 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e); 19 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e);
19 BinaryOperator binary(Expression l, String op, Expression r) => 20 BinaryOperator binary(Expression l, String op, Expression r) =>
20 new BinaryOperator(l, op, r); 21 new BinaryOperator(l, op, r);
21 Getter getter(Expression e, String m) => new Getter(e, m); 22 Getter getter(Expression e, String m) => new Getter(e, m);
22 Index index(Expression e, Expression a) => new Index(e, a); 23 Index index(Expression e, Expression a) => new Index(e, a);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 79
79 accept(Visitor v) => v.visitLiteral(this); 80 accept(Visitor v) => v.visitLiteral(this);
80 81
81 String toString() => (value is String) ? '"$value"' : '$value'; 82 String toString() => (value is String) ? '"$value"' : '$value';
82 83
83 bool operator ==(o) => o is Literal<T> && o.value == value; 84 bool operator ==(o) => o is Literal<T> && o.value == value;
84 85
85 int get hashCode => value.hashCode; 86 int get hashCode => value.hashCode;
86 } 87 }
87 88
89 class ListLiteral extends Expression {
90 final List<Expression> items;
91
92 ListLiteral(this.items);
93
94 accept(Visitor v) => v.visitListLiteral(this);
95
96 String toString() => "$items";
97
98 bool operator ==(o) => o is ListLiteral && _listEquals(o.items, items);
99
100 int get hashCode => _hashList(items);
101 }
102
88 class MapLiteral extends Expression { 103 class MapLiteral extends Expression {
89 final List<MapLiteralEntry> entries; 104 final List<MapLiteralEntry> entries;
90 105
91 MapLiteral(this.entries); 106 MapLiteral(this.entries);
92 107
93 accept(Visitor v) => v.visitMapLiteral(this); 108 accept(Visitor v) => v.visitMapLiteral(this);
94 109
95 String toString() => "{$entries}"; 110 String toString() => "{$entries}";
96 111
97 bool operator ==(o) => o is MapLiteral && _listEquals(o.entries, entries); 112 bool operator ==(o) => o is MapLiteral && _listEquals(o.entries, entries);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 327 }
313 328
314 static int hash2(int a, int b) => finish(combine(combine(0, a), b)); 329 static int hash2(int a, int b) => finish(combine(combine(0, a), b));
315 330
316 static int hash3(int a, int b, int c) => 331 static int hash3(int a, int b, int c) =>
317 finish(combine(combine(combine(0, a), b), c)); 332 finish(combine(combine(combine(0, a), b), c));
318 333
319 static int hash4(int a, int b, int c, int d) => 334 static int hash4(int a, int b, int c, int d) =>
320 finish(combine(combine(combine(combine(0, a), b), c), d)); 335 finish(combine(combine(combine(combine(0, a), b), c), d));
321 } 336 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698