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

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

Issue 23724005: Eliminating some dart2js warnings from polymer_expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 class MapLiteral extends Expression { 77 class MapLiteral extends Expression {
78 final List<MapLiteralEntry> entries; 78 final List<MapLiteralEntry> entries;
79 79
80 MapLiteral(this.entries); 80 MapLiteral(this.entries);
81 81
82 accept(Visitor v) => v.visitMapLiteral(this); 82 accept(Visitor v) => v.visitMapLiteral(this);
83 83
84 String toString() => "{$entries}"; 84 String toString() => "{$entries}";
85 85
86 bool operator ==(o) => o is MapLiteral && _listEquals(o.entries, entries); 86 bool operator ==(o) => o is MapLiteral && _listEquals(o.entries, entries);
87
88 int get hashCode => _hashList(entries);
87 } 89 }
88 90
89 class MapLiteralEntry extends Expression { 91 class MapLiteralEntry extends Expression {
90 final Literal key; 92 final Literal key;
91 final Expression entryValue; 93 final Expression entryValue;
92 94
93 MapLiteralEntry(this.key, this.entryValue); 95 MapLiteralEntry(this.key, this.entryValue);
94 96
95 accept(Visitor v) => v.visitMapLiteralEntry(this); 97 accept(Visitor v) => v.visitMapLiteralEntry(this);
96 98
97 String toString() => "$key: $entryValue"; 99 String toString() => "$key: $entryValue";
98 100
99 bool operator ==(o) => o is MapLiteralEntry && o.key == key 101 bool operator ==(o) => o is MapLiteralEntry && o.key == key
100 && o.entryValue == entryValue; 102 && o.entryValue == entryValue;
103
104 int get hashCode => _JenkinsSmiHash.hash2(key.hashCode, entryValue.hashCode);
101 } 105 }
102 106
103 class ParenthesizedExpression extends Expression { 107 class ParenthesizedExpression extends Expression {
104 final Expression child; 108 final Expression child;
105 109
106 ParenthesizedExpression(this.child); 110 ParenthesizedExpression(this.child);
107 111
108 accept(Visitor v) => v.visitParenthesizedExpression(this); 112 accept(Visitor v) => v.visitParenthesizedExpression(this);
109 113
110 String toString() => '($child)'; 114 String toString() => '($child)';
(...skipping 22 matching lines...) Expand all
133 final Expression child; 137 final Expression child;
134 138
135 UnaryOperator(this.operator, this.child); 139 UnaryOperator(this.operator, this.child);
136 140
137 accept(Visitor v) => v.visitUnaryOperator(this); 141 accept(Visitor v) => v.visitUnaryOperator(this);
138 142
139 String toString() => '$operator $child'; 143 String toString() => '$operator $child';
140 144
141 bool operator ==(o) => o is UnaryOperator && o.operator == operator 145 bool operator ==(o) => o is UnaryOperator && o.operator == operator
142 && o.child == child; 146 && o.child == child;
147
148 int get hashCode => _JenkinsSmiHash.hash2(operator.hashCode, child.hashCode);
143 } 149 }
144 150
145 class BinaryOperator extends Expression { 151 class BinaryOperator extends Expression {
146 final String operator; 152 final String operator;
147 final Expression left; 153 final Expression left;
148 final Expression right; 154 final Expression right;
149 155
150 BinaryOperator(this.left, this.operator, this.right); 156 BinaryOperator(this.left, this.operator, this.right);
151 157
152 accept(Visitor v) => v.visitBinaryOperator(this); 158 accept(Visitor v) => v.visitBinaryOperator(this);
153 159
154 String toString() => '($left $operator $right)'; 160 String toString() => '($left $operator $right)';
155 161
156 bool operator ==(o) => o is BinaryOperator && o.operator == operator 162 bool operator ==(o) => o is BinaryOperator && o.operator == operator
157 && o.left == left && o.right == right; 163 && o.left == left && o.right == right;
164
165 int get hashCode => _JenkinsSmiHash.hash3(operator.hashCode, left.hashCode,
166 right.hashCode);
158 } 167 }
159 168
160 class InExpression extends Expression { 169 class InExpression extends Expression {
161 final Expression left; 170 final Expression left;
162 final Expression right; 171 final Expression right;
163 172
164 InExpression(this.left, this.right); 173 InExpression(this.left, this.right);
165 174
166 accept(Visitor v) => v.visitInExpression(this); 175 accept(Visitor v) => v.visitInExpression(this);
167 176
168 String toString() => '($left in $right)'; 177 String toString() => '($left in $right)';
169 178
170 bool operator ==(o) => o is InExpression && o.left == left 179 bool operator ==(o) => o is InExpression && o.left == left
171 && o.right == right; 180 && o.right == right;
181
182 int get hashCode => _JenkinsSmiHash.hash2(left.hashCode, right.hashCode);
172 } 183 }
173 184
174 /** 185 /**
175 * Represents a function or method invocation. If [method] is null, then 186 * Represents a function or method invocation. If [method] is null, then
176 * [receiver] is an expression that should evaluate to a function. If [method] 187 * [receiver] is an expression that should evaluate to a function. If [method]
177 * is not null, then [receiver] is an expression that should evaluate to an 188 * is not null, then [receiver] is an expression that should evaluate to an
178 * object that has an appropriate method. 189 * object that has an appropriate method.
179 */ 190 */
180 class Invoke extends Expression { 191 class Invoke extends Expression {
181 final Expression receiver; 192 final Expression receiver;
182 final String method; 193 final String method;
183 final List<Expression> arguments; 194 final List<Expression> arguments;
184 195
185 Invoke(this.receiver, this.method, [this.arguments]); 196 Invoke(this.receiver, this.method, [this.arguments]);
186 197
187 accept(Visitor v) => v.visitInvoke(this); 198 accept(Visitor v) => v.visitInvoke(this);
188 199
189 bool get isGetter => arguments == null; 200 bool get isGetter => arguments == null;
190 201
191 String toString() => '$receiver.$method($arguments)'; 202 String toString() => '$receiver.$method($arguments)';
192 203
193 bool operator ==(o) => 204 bool operator ==(o) =>
194 o is Invoke 205 o is Invoke
195 && o.receiver == receiver 206 && o.receiver == receiver
196 && o.method == method 207 && o.method == method
197 && _listEquals(o.arguments, arguments); 208 && _listEquals(o.arguments, arguments);
209
210 int get hashCode => _JenkinsSmiHash.hash3(receiver.hashCode, method.hashCode,
211 _hashList(arguments));
198 } 212 }
199 213
200 bool _listEquals(List a, List b) { 214 bool _listEquals(List a, List b) {
201 if (a == b) return true; 215 if (a == b) return true;
202 if (a == null || b == null) return false; 216 if (a == null || b == null) return false;
203 if (a.length != b.length) return false; 217 if (a.length != b.length) return false;
204 for (int i = 0; i < a.length; i++) { 218 for (int i = 0; i < a.length; i++) {
205 if (a[i] != b[i]) return false; 219 if (a[i] != b[i]) return false;
206 } 220 }
207 return true; 221 return true;
208 } 222 }
223
224 int _hashList(List l) {
225 var hash = l.fold(0,
226 (hash, item) => _JenkinsSmiHash.combine(hash, item.hashCode));
227 return _JenkinsSmiHash.finish(hash);
228 }
229
230 class _JenkinsSmiHash {
231 // TODO: Bug 11617- This class should be optimized and standardized elsewhere.
justinfagnani 2013/08/29 18:31:49 I was going to add a has function to quiver this w
blois 2013/08/29 19:43:22 Yeah, I did a version of it in dart:html but have
232
233 static int combine(int hash, int value) {
234 hash = 0x1fffffff & (hash + value);
235 hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
236 return hash ^ (hash >> 6);
237 }
238
239 static int finish(int hash) {
240 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
241 hash = hash ^ (hash >> 11);
242 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
243 }
244
245 static int hash2(a, b) => finish(combine(combine(0, a), b));
246
247 static int hash3(a, b, c) => finish(combine(combine(combine(0, a), b), c));
248
249 static int hash4(a, b, c, d) =>
250 finish(combine(combine(combine(combine(0, a), b), c), d));
251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698