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 abstract class ConstantVisitor<R> { | 5 abstract class ConstantVisitor<R> { |
6 R visitSentinel(SentinelConstant constant); | 6 R visitSentinel(SentinelConstant constant); |
7 R visitFunction(FunctionConstant constant); | 7 R visitFunction(FunctionConstant constant); |
8 R visitNull(NullConstant constant); | 8 R visitNull(NullConstant constant); |
9 R visitInt(IntConstant constant); | 9 R visitInt(IntConstant constant); |
10 R visitDouble(DoubleConstant constant); | 10 R visitDouble(DoubleConstant constant); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 177 |
178 int get hashCode => value.hashCode; | 178 int get hashCode => value.hashCode; |
179 DartString toDartString() => new DartString.literal(value.toString()); | 179 DartString toDartString() => new DartString.literal(value.toString()); |
180 | 180 |
181 accept(ConstantVisitor visitor) => visitor.visitInt(this); | 181 accept(ConstantVisitor visitor) => visitor.visitInt(this); |
182 } | 182 } |
183 | 183 |
184 class DoubleConstant extends NumConstant { | 184 class DoubleConstant extends NumConstant { |
185 final double value; | 185 final double value; |
186 factory DoubleConstant(double value) { | 186 factory DoubleConstant(double value) { |
187 if (value.isNaN()) { | 187 if (value.isNaN) { |
188 return const DoubleConstant._internal(double.NAN); | 188 return const DoubleConstant._internal(double.NAN); |
189 } else if (value == double.INFINITY) { | 189 } else if (value == double.INFINITY) { |
190 return const DoubleConstant._internal(double.INFINITY); | 190 return const DoubleConstant._internal(double.INFINITY); |
191 } else if (value == -double.INFINITY) { | 191 } else if (value == -double.INFINITY) { |
192 return const DoubleConstant._internal(-double.INFINITY); | 192 return const DoubleConstant._internal(-double.INFINITY); |
193 } else if (value == 0.0 && !value.isNegative()) { | 193 } else if (value == 0.0 && !value.isNegative) { |
194 return const DoubleConstant._internal(0.0); | 194 return const DoubleConstant._internal(0.0); |
195 } else if (value == 1.0) { | 195 } else if (value == 1.0) { |
196 return const DoubleConstant._internal(1.0); | 196 return const DoubleConstant._internal(1.0); |
197 } else { | 197 } else { |
198 return new DoubleConstant._internal(value); | 198 return new DoubleConstant._internal(value); |
199 } | 199 } |
200 } | 200 } |
201 const DoubleConstant._internal(this.value); | 201 const DoubleConstant._internal(this.value); |
202 bool isDouble() => true; | 202 bool isDouble() => true; |
203 bool isNaN() => value.isNaN(); | 203 bool isNaN() => value.isNaN; |
204 // We need to check for the negative sign since -0.0 == 0.0. | 204 // We need to check for the negative sign since -0.0 == 0.0. |
205 bool isMinusZero() => value == 0.0 && value.isNegative(); | 205 bool isMinusZero() => value == 0.0 && value.isNegative; |
206 | 206 |
207 DartType computeType(Compiler compiler) { | 207 DartType computeType(Compiler compiler) { |
208 return compiler.doubleClass.computeType(compiler); | 208 return compiler.doubleClass.computeType(compiler); |
209 } | 209 } |
210 | 210 |
211 bool operator ==(var other) { | 211 bool operator ==(var other) { |
212 if (other is !DoubleConstant) return false; | 212 if (other is !DoubleConstant) return false; |
213 DoubleConstant otherDouble = other; | 213 DoubleConstant otherDouble = other; |
214 double otherValue = otherDouble.value; | 214 double otherValue = otherDouble.value; |
215 if (value == 0.0 && otherValue == 0.0) { | 215 if (value == 0.0 && otherValue == 0.0) { |
216 return value.isNegative() == otherValue.isNegative(); | 216 return value.isNegative == otherValue.isNegative; |
217 } else if (value.isNaN()) { | 217 } else if (value.isNaN) { |
218 return otherValue.isNaN(); | 218 return otherValue.isNaN; |
219 } else { | 219 } else { |
220 return value == otherValue; | 220 return value == otherValue; |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 int get hashCode => value.hashCode; | 224 int get hashCode => value.hashCode; |
225 DartString toDartString() => new DartString.literal(value.toString()); | 225 DartString toDartString() => new DartString.literal(value.toString()); |
226 | 226 |
227 accept(ConstantVisitor visitor) => visitor.visitDouble(this); | 227 accept(ConstantVisitor visitor) => visitor.visitDouble(this); |
228 } | 228 } |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 for (int i = 0; i < fields.length; i++) { | 445 for (int i = 0; i < fields.length; i++) { |
446 if (fields[i] != other.fields[i]) return false; | 446 if (fields[i] != other.fields[i]) return false; |
447 } | 447 } |
448 return true; | 448 return true; |
449 } | 449 } |
450 | 450 |
451 List<Constant> getDependencies() => fields; | 451 List<Constant> getDependencies() => fields; |
452 | 452 |
453 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); | 453 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); |
454 } | 454 } |
OLD | NEW |