| 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 dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 abstract class ConstantVisitor<R> { | 7 abstract class ConstantVisitor<R> { |
| 8 R visitSentinel(SentinelConstant constant); | 8 R visitSentinel(SentinelConstant constant); |
| 9 R visitFunction(FunctionConstant constant); | 9 R visitFunction(FunctionConstant constant); |
| 10 R visitNull(NullConstant constant); | 10 R visitNull(NullConstant constant); |
| 11 R visitInt(IntConstant constant); | 11 R visitInt(IntConstant constant); |
| 12 R visitDouble(DoubleConstant constant); | 12 R visitDouble(DoubleConstant constant); |
| 13 R visitTrue(TrueConstant constant); | 13 R visitTrue(TrueConstant constant); |
| 14 R visitFalse(FalseConstant constant); | 14 R visitFalse(FalseConstant constant); |
| 15 R visitString(StringConstant constant); | 15 R visitString(StringConstant constant); |
| 16 R visitList(ListConstant constant); | 16 R visitList(ListConstant constant); |
| 17 R visitMap(MapConstant constant); | 17 R visitMap(MapConstant constant); |
| 18 R visitConstructed(ConstructedConstant constant); | 18 R visitConstructed(ConstructedConstant constant); |
| 19 R visitType(TypeConstant constant); |
| 19 } | 20 } |
| 20 | 21 |
| 21 abstract class Constant { | 22 abstract class Constant { |
| 22 const Constant(); | 23 const Constant(); |
| 23 | 24 |
| 24 bool isNull() => false; | 25 bool isNull() => false; |
| 25 bool isBool() => false; | 26 bool isBool() => false; |
| 26 bool isTrue() => false; | 27 bool isTrue() => false; |
| 27 bool isFalse() => false; | 28 bool isFalse() => false; |
| 28 bool isInt() => false; | 29 bool isInt() => false; |
| 29 bool isDouble() => false; | 30 bool isDouble() => false; |
| 30 bool isNum() => false; | 31 bool isNum() => false; |
| 31 bool isString() => false; | 32 bool isString() => false; |
| 32 bool isList() => false; | 33 bool isList() => false; |
| 33 bool isMap() => false; | 34 bool isMap() => false; |
| 34 bool isConstructedObject() => false; | 35 bool isConstructedObject() => false; |
| 35 bool isFunction() => false; | 36 bool isFunction() => false; |
| 36 /** Returns true if the constant is null, a bool, a number or a string. */ | 37 /** Returns true if the constant is null, a bool, a number or a string. */ |
| 37 bool isPrimitive() => false; | 38 bool isPrimitive() => false; |
| 38 /** Returns true if the constant is a list, a map or a constructed object. */ | 39 /** Returns true if the constant is a list, a map or a constructed object. */ |
| 39 bool isObject() => false; | 40 bool isObject() => false; |
| 41 bool isType() => false; |
| 40 bool isSentinel() => false; | 42 bool isSentinel() => false; |
| 41 | 43 |
| 42 bool isNaN() => false; | 44 bool isNaN() => false; |
| 43 bool isMinusZero() => false; | 45 bool isMinusZero() => false; |
| 44 | 46 |
| 45 DartType computeType(Compiler compiler); | 47 DartType computeType(Compiler compiler); |
| 46 | 48 |
| 47 List<Constant> getDependencies(); | 49 List<Constant> getDependencies(); |
| 48 | 50 |
| 49 accept(ConstantVisitor); | 51 accept(ConstantVisitor visitor); |
| 50 } | 52 } |
| 51 | 53 |
| 52 class SentinelConstant extends Constant { | 54 class SentinelConstant extends Constant { |
| 53 const SentinelConstant(); | 55 const SentinelConstant(); |
| 54 static final SENTINEL = const SentinelConstant(); | 56 static final SENTINEL = const SentinelConstant(); |
| 55 | 57 |
| 56 List<Constant> getDependencies() => const <Constant>[]; | 58 List<Constant> getDependencies() => const <Constant>[]; |
| 57 | 59 |
| 58 // Just use a random value. | 60 // Just use a random value. |
| 59 int get hashCode => 24297418; | 61 int get hashCode => 24297418; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 accept(ConstantVisitor visitor) => visitor.visitString(this); | 310 accept(ConstantVisitor visitor) => visitor.visitString(this); |
| 309 } | 311 } |
| 310 | 312 |
| 311 abstract class ObjectConstant extends Constant { | 313 abstract class ObjectConstant extends Constant { |
| 312 final DartType type; | 314 final DartType type; |
| 313 | 315 |
| 314 ObjectConstant(this.type); | 316 ObjectConstant(this.type); |
| 315 bool isObject() => true; | 317 bool isObject() => true; |
| 316 | 318 |
| 317 DartType computeType(Compiler compiler) => type; | 319 DartType computeType(Compiler compiler) => type; |
| 320 } |
| 318 | 321 |
| 319 // TODO(1603): The class should be marked as abstract, but the VM doesn't | 322 class TypeConstant extends ObjectConstant { |
| 320 // currently allow this. | 323 /// The user type that this constant represents. |
| 321 int get hashCode; | 324 final DartType representedType; |
| 325 |
| 326 TypeConstant(this.representedType, type) : super(type); |
| 327 |
| 328 bool isType() => true; |
| 329 |
| 330 bool operator ==(other) { |
| 331 return other is TypeConstant && representedType == other.representedType; |
| 332 } |
| 333 |
| 334 int get hashCode => representedType.hashCode * 13; |
| 335 |
| 336 List<Constant> getDependencies() => const <Constant>[]; |
| 337 |
| 338 accept(ConstantVisitor visitor) => visitor.visitType(this); |
| 322 } | 339 } |
| 323 | 340 |
| 324 class ListConstant extends ObjectConstant { | 341 class ListConstant extends ObjectConstant { |
| 325 final List<Constant> entries; | 342 final List<Constant> entries; |
| 326 final int hashCode; | 343 final int hashCode; |
| 327 | 344 |
| 328 ListConstant(DartType type, List<Constant> entries) | 345 ListConstant(DartType type, List<Constant> entries) |
| 329 : this.entries = entries, | 346 : this.entries = entries, |
| 330 hashCode = _computeHash(entries), | 347 hashCode = _computeHash(entries), |
| 331 super(type); | 348 super(type); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 for (int i = 0; i < fields.length; i++) { | 464 for (int i = 0; i < fields.length; i++) { |
| 448 if (fields[i] != other.fields[i]) return false; | 465 if (fields[i] != other.fields[i]) return false; |
| 449 } | 466 } |
| 450 return true; | 467 return true; |
| 451 } | 468 } |
| 452 | 469 |
| 453 List<Constant> getDependencies() => fields; | 470 List<Constant> getDependencies() => fields; |
| 454 | 471 |
| 455 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); | 472 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); |
| 456 } | 473 } |
| OLD | NEW |