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

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

Issue 24983003: Use const instead of runtime type for equality of EmptyExpression. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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() => new EmptyExpression(); 11 EmptyExpression empty() => const EmptyExpression();
12 Literal literal(v) => new Literal(v); 12 Literal literal(v) => new Literal(v);
13 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => new MapLiteral(entries); 13 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => new MapLiteral(entries);
14 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) => 14 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) =>
15 new MapLiteralEntry(key, value); 15 new MapLiteralEntry(key, value);
16 Identifier ident(String v) => new Identifier(v); 16 Identifier ident(String v) => new Identifier(v);
17 ParenthesizedExpression paren(Expression e) => new ParenthesizedExpression(e); 17 ParenthesizedExpression paren(Expression e) => new ParenthesizedExpression(e);
18 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e); 18 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e);
19 BinaryOperator binary(Expression l, String op, Expression r) => 19 BinaryOperator binary(Expression l, String op, Expression r) =>
20 new BinaryOperator(l, op, r); 20 new BinaryOperator(l, op, r);
21 Invoke invoke(Expression e, String m, [List<Expression> a]) => 21 Invoke invoke(Expression e, String m, [List<Expression> a]) =>
22 new Invoke(e, m, a); 22 new Invoke(e, m, a);
23 InExpression inExpr(Expression l, Expression r) => new InExpression(l, r); 23 InExpression inExpr(Expression l, Expression r) => new InExpression(l, r);
24 24
25 25
26 class AstFactory { 26 class AstFactory {
27 EmptyExpression empty() => new EmptyExpression(); 27 EmptyExpression empty() => const EmptyExpression();
28 28
29 Literal literal(v) => new Literal(v); 29 Literal literal(v) => new Literal(v);
30 30
31 MapLiteral mapLiteral(List<MapLiteralEntry> entries) => 31 MapLiteral mapLiteral(List<MapLiteralEntry> entries) =>
32 new MapLiteral(entries); 32 new MapLiteral(entries);
33 33
34 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) => 34 MapLiteralEntry mapLiteralEntry(Literal key, Expression value) =>
35 new MapLiteralEntry(key, value); 35 new MapLiteralEntry(key, value);
36 36
37 Identifier identifier(String v) => new Identifier(v); 37 Identifier identifier(String v) => new Identifier(v);
38 38
39 ParenthesizedExpression parenthesized(Expression e) => 39 ParenthesizedExpression parenthesized(Expression e) =>
40 new ParenthesizedExpression(e); 40 new ParenthesizedExpression(e);
41 41
42 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e); 42 UnaryOperator unary(String op, Expression e) => new UnaryOperator(op, e);
43 43
44 BinaryOperator binary(Expression l, String op, Expression r) => 44 BinaryOperator binary(Expression l, String op, Expression r) =>
45 new BinaryOperator(l, op, r); 45 new BinaryOperator(l, op, r);
46 46
47 Invoke invoke(Expression e, String m, [List<Expression> a]) => 47 Invoke invoke(Expression e, String m, [List<Expression> a]) =>
48 new Invoke(e, m, a); 48 new Invoke(e, m, a);
49 49
50 InExpression inExpr(Expression l, Expression r) => new InExpression(l, r); 50 InExpression inExpr(Expression l, Expression r) => new InExpression(l, r);
51 } 51 }
52 52
53 /// Base class for all expressions 53 /// Base class for all expressions
54 abstract class Expression { 54 abstract class Expression {
55 const Expression();
55 accept(Visitor v); 56 accept(Visitor v);
56 } 57 }
57 58
58 class EmptyExpression extends Expression { 59 class EmptyExpression extends Expression {
60 const EmptyExpression();
59 accept(Visitor v) => v.visitEmptyExpression(this); 61 accept(Visitor v) => v.visitEmptyExpression(this);
60 bool operator ==(o) => o is EmptyExpression;
61 } 62 }
62 63
63 class Literal<T> extends Expression { 64 class Literal<T> extends Expression {
64 final T value; 65 final T value;
65 66
66 Literal(this.value); 67 Literal(this.value);
67 68
68 accept(Visitor v) => v.visitLiteral(this); 69 accept(Visitor v) => v.visitLiteral(this);
69 70
70 String toString() => (value is String) ? '"$value"' : '$value'; 71 String toString() => (value is String) ? '"$value"' : '$value';
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); 243 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
243 } 244 }
244 245
245 static int hash2(a, b) => finish(combine(combine(0, a), b)); 246 static int hash2(a, b) => finish(combine(combine(0, a), b));
246 247
247 static int hash3(a, b, c) => finish(combine(combine(combine(0, a), b), c)); 248 static int hash3(a, b, c) => finish(combine(combine(combine(0, a), b), c));
248 249
249 static int hash4(a, b, c, d) => 250 static int hash4(a, b, c, d) =>
250 finish(combine(combine(combine(combine(0, a), b), c), d)); 251 finish(combine(combine(combine(combine(0, a), b), c), d));
251 } 252 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698