| 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 library dart2js.constants.values; | 5 library dart2js.constants.values; |
| 6 | 6 |
| 7 import '../common.dart'; | 7 import '../common.dart'; |
| 8 import '../core_types.dart'; | 8 import '../core_types.dart'; |
| 9 import '../elements/elements.dart' show Entity; | 9 import '../elements/elements.dart' show Entity; |
| 10 import '../elements/entities.dart'; | 10 import '../elements/entities.dart'; |
| 11 import '../elements/resolution_types.dart'; | 11 import '../elements/types.dart'; |
| 12 import '../tree/dartstring.dart'; | 12 import '../tree/dartstring.dart'; |
| 13 import '../util/util.dart' show Hashing; | 13 import '../util/util.dart' show Hashing; |
| 14 | 14 |
| 15 enum ConstantValueKind { | 15 enum ConstantValueKind { |
| 16 FUNCTION, | 16 FUNCTION, |
| 17 NULL, | 17 NULL, |
| 18 INT, | 18 INT, |
| 19 DOUBLE, | 19 DOUBLE, |
| 20 BOOL, | 20 BOOL, |
| 21 STRING, | 21 STRING, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 bool get isDummy => false; | 75 bool get isDummy => false; |
| 76 | 76 |
| 77 bool get isNaN => false; | 77 bool get isNaN => false; |
| 78 bool get isMinusZero => false; | 78 bool get isMinusZero => false; |
| 79 bool get isZero => false; | 79 bool get isZero => false; |
| 80 bool get isOne => false; | 80 bool get isOne => false; |
| 81 bool get isPositiveInfinity => false; | 81 bool get isPositiveInfinity => false; |
| 82 bool get isNegativeInfinity => false; | 82 bool get isNegativeInfinity => false; |
| 83 | 83 |
| 84 // TODO(johnniwinther): Replace with a 'type' getter. | 84 // TODO(johnniwinther): Replace with a 'type' getter. |
| 85 ResolutionDartType getType(CommonElements types); | 85 DartType getType(CommonElements types); |
| 86 | 86 |
| 87 List<ConstantValue> getDependencies(); | 87 List<ConstantValue> getDependencies(); |
| 88 | 88 |
| 89 accept(ConstantValueVisitor visitor, arg); | 89 accept(ConstantValueVisitor visitor, arg); |
| 90 | 90 |
| 91 /// The value of this constant in Dart syntax, if possible. | 91 /// The value of this constant in Dart syntax, if possible. |
| 92 /// | 92 /// |
| 93 /// For [ConstructedConstantValue]s there is no way to create a valid const | 93 /// For [ConstructedConstantValue]s there is no way to create a valid const |
| 94 /// expression from the value so the unparse of these is best effort. | 94 /// expression from the value so the unparse of these is best effort. |
| 95 /// | 95 /// |
| (...skipping 11 matching lines...) Expand all Loading... |
| 107 assertDebugMode("Use ConstantValue.toDartText() or " | 107 assertDebugMode("Use ConstantValue.toDartText() or " |
| 108 "ConstantValue.toStructuredText() " | 108 "ConstantValue.toStructuredText() " |
| 109 "instead of ConstantValue.toString()."); | 109 "instead of ConstantValue.toString()."); |
| 110 return toStructuredText(); | 110 return toStructuredText(); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 class FunctionConstantValue extends ConstantValue { | 114 class FunctionConstantValue extends ConstantValue { |
| 115 final FunctionEntity element; | 115 final FunctionEntity element; |
| 116 // TODO(johnniwinther): Should the type be derived from [element]. | 116 // TODO(johnniwinther): Should the type be derived from [element]. |
| 117 final ResolutionFunctionType type; | 117 final FunctionType type; |
| 118 | 118 |
| 119 FunctionConstantValue(this.element, this.type); | 119 FunctionConstantValue(this.element, this.type); |
| 120 | 120 |
| 121 bool get isFunction => true; | 121 bool get isFunction => true; |
| 122 | 122 |
| 123 bool operator ==(var other) { | 123 bool operator ==(var other) { |
| 124 if (other is! FunctionConstantValue) return false; | 124 if (other is! FunctionConstantValue) return false; |
| 125 return identical(other.element, element); | 125 return identical(other.element, element); |
| 126 } | 126 } |
| 127 | 127 |
| 128 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 128 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 129 | 129 |
| 130 DartString toDartString() { | 130 DartString toDartString() { |
| 131 return new DartString.literal(element.name); | 131 return new DartString.literal(element.name); |
| 132 } | 132 } |
| 133 | 133 |
| 134 ResolutionDartType getType(CommonElements types) => type; | 134 DartType getType(CommonElements types) => type; |
| 135 | 135 |
| 136 int get hashCode => (17 * element.hashCode) & 0x7fffffff; | 136 int get hashCode => (17 * element.hashCode) & 0x7fffffff; |
| 137 | 137 |
| 138 accept(ConstantValueVisitor visitor, arg) => visitor.visitFunction(this, arg); | 138 accept(ConstantValueVisitor visitor, arg) => visitor.visitFunction(this, arg); |
| 139 | 139 |
| 140 ConstantValueKind get kind => ConstantValueKind.FUNCTION; | 140 ConstantValueKind get kind => ConstantValueKind.FUNCTION; |
| 141 | 141 |
| 142 String toDartText() { | 142 String toDartText() { |
| 143 if (element.enclosingClass != null) { | 143 if (element.enclosingClass != null) { |
| 144 return '${element.enclosingClass.name}.${element.name}'; | 144 return '${element.enclosingClass.name}.${element.name}'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 static const String JsNull = "null"; | 182 static const String JsNull = "null"; |
| 183 | 183 |
| 184 const factory NullConstantValue() = NullConstantValue._internal; | 184 const factory NullConstantValue() = NullConstantValue._internal; |
| 185 | 185 |
| 186 const NullConstantValue._internal(); | 186 const NullConstantValue._internal(); |
| 187 | 187 |
| 188 bool get isNull => true; | 188 bool get isNull => true; |
| 189 | 189 |
| 190 get primitiveValue => null; | 190 get primitiveValue => null; |
| 191 | 191 |
| 192 ResolutionDartType getType(CommonElements types) => types.nullType; | 192 DartType getType(CommonElements types) => types.nullType; |
| 193 | 193 |
| 194 // The magic constant has no meaning. It is just a random value. | 194 // The magic constant has no meaning. It is just a random value. |
| 195 int get hashCode => 785965825; | 195 int get hashCode => 785965825; |
| 196 | 196 |
| 197 DartString toDartString() => const LiteralDartString("null"); | 197 DartString toDartString() => const LiteralDartString("null"); |
| 198 | 198 |
| 199 accept(ConstantValueVisitor visitor, arg) => visitor.visitNull(this, arg); | 199 accept(ConstantValueVisitor visitor, arg) => visitor.visitNull(this, arg); |
| 200 | 200 |
| 201 ConstantValueKind get kind => ConstantValueKind.NULL; | 201 ConstantValueKind get kind => ConstantValueKind.NULL; |
| 202 | 202 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 bool isUInt31() => primitiveValue >= 0 && primitiveValue < (1 << 31); | 254 bool isUInt31() => primitiveValue >= 0 && primitiveValue < (1 << 31); |
| 255 | 255 |
| 256 bool isUInt32() => primitiveValue >= 0 && primitiveValue < (1 << 32); | 256 bool isUInt32() => primitiveValue >= 0 && primitiveValue < (1 << 32); |
| 257 | 257 |
| 258 bool isPositive() => primitiveValue >= 0; | 258 bool isPositive() => primitiveValue >= 0; |
| 259 | 259 |
| 260 bool get isZero => primitiveValue == 0; | 260 bool get isZero => primitiveValue == 0; |
| 261 | 261 |
| 262 bool get isOne => primitiveValue == 1; | 262 bool get isOne => primitiveValue == 1; |
| 263 | 263 |
| 264 ResolutionDartType getType(CommonElements types) => types.intType; | 264 DartType getType(CommonElements types) => types.intType; |
| 265 | 265 |
| 266 // We have to override the equality operator so that ints and doubles are | 266 // We have to override the equality operator so that ints and doubles are |
| 267 // treated as separate constants. | 267 // treated as separate constants. |
| 268 // The is [:!IntConstant:] check at the beginning of the function makes sure | 268 // The is [:!IntConstant:] check at the beginning of the function makes sure |
| 269 // that we compare only equal to integer constants. | 269 // that we compare only equal to integer constants. |
| 270 bool operator ==(var other) { | 270 bool operator ==(var other) { |
| 271 if (other is! IntConstantValue) return false; | 271 if (other is! IntConstantValue) return false; |
| 272 IntConstantValue otherInt = other; | 272 IntConstantValue otherInt = other; |
| 273 return primitiveValue == otherInt.primitiveValue; | 273 return primitiveValue == otherInt.primitiveValue; |
| 274 } | 274 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 bool get isMinusZero => primitiveValue == 0.0 && primitiveValue.isNegative; | 315 bool get isMinusZero => primitiveValue == 0.0 && primitiveValue.isNegative; |
| 316 | 316 |
| 317 bool get isZero => primitiveValue == 0.0; | 317 bool get isZero => primitiveValue == 0.0; |
| 318 | 318 |
| 319 bool get isOne => primitiveValue == 1.0; | 319 bool get isOne => primitiveValue == 1.0; |
| 320 | 320 |
| 321 bool get isPositiveInfinity => primitiveValue == double.INFINITY; | 321 bool get isPositiveInfinity => primitiveValue == double.INFINITY; |
| 322 | 322 |
| 323 bool get isNegativeInfinity => primitiveValue == -double.INFINITY; | 323 bool get isNegativeInfinity => primitiveValue == -double.INFINITY; |
| 324 | 324 |
| 325 ResolutionDartType getType(CommonElements types) => types.doubleType; | 325 DartType getType(CommonElements types) => types.doubleType; |
| 326 | 326 |
| 327 bool operator ==(var other) { | 327 bool operator ==(var other) { |
| 328 if (other is! DoubleConstantValue) return false; | 328 if (other is! DoubleConstantValue) return false; |
| 329 DoubleConstantValue otherDouble = other; | 329 DoubleConstantValue otherDouble = other; |
| 330 double otherValue = otherDouble.primitiveValue; | 330 double otherValue = otherDouble.primitiveValue; |
| 331 if (primitiveValue == 0.0 && otherValue == 0.0) { | 331 if (primitiveValue == 0.0 && otherValue == 0.0) { |
| 332 return primitiveValue.isNegative == otherValue.isNegative; | 332 return primitiveValue.isNegative == otherValue.isNegative; |
| 333 } else if (primitiveValue.isNaN) { | 333 } else if (primitiveValue.isNaN) { |
| 334 return otherValue.isNaN; | 334 return otherValue.isNaN; |
| 335 } else { | 335 } else { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 352 | 352 |
| 353 abstract class BoolConstantValue extends PrimitiveConstantValue { | 353 abstract class BoolConstantValue extends PrimitiveConstantValue { |
| 354 factory BoolConstantValue(value) { | 354 factory BoolConstantValue(value) { |
| 355 return value ? new TrueConstantValue() : new FalseConstantValue(); | 355 return value ? new TrueConstantValue() : new FalseConstantValue(); |
| 356 } | 356 } |
| 357 | 357 |
| 358 const BoolConstantValue._internal(); | 358 const BoolConstantValue._internal(); |
| 359 | 359 |
| 360 bool get isBool => true; | 360 bool get isBool => true; |
| 361 | 361 |
| 362 ResolutionDartType getType(CommonElements types) => types.boolType; | 362 DartType getType(CommonElements types) => types.boolType; |
| 363 | 363 |
| 364 BoolConstantValue negate(); | 364 BoolConstantValue negate(); |
| 365 | 365 |
| 366 accept(ConstantValueVisitor visitor, arg) => visitor.visitBool(this, arg); | 366 accept(ConstantValueVisitor visitor, arg) => visitor.visitBool(this, arg); |
| 367 | 367 |
| 368 ConstantValueKind get kind => ConstantValueKind.BOOL; | 368 ConstantValueKind get kind => ConstantValueKind.BOOL; |
| 369 | 369 |
| 370 String toStructuredText() => 'BoolConstant(${toDartText()})'; | 370 String toStructuredText() => 'BoolConstant(${toDartText()})'; |
| 371 } | 371 } |
| 372 | 372 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 // DartString. | 420 // DartString. |
| 421 StringConstantValue(DartString value) | 421 StringConstantValue(DartString value) |
| 422 : this.primitiveValue = value, | 422 : this.primitiveValue = value, |
| 423 this.hashCode = value.slowToString().hashCode; | 423 this.hashCode = value.slowToString().hashCode; |
| 424 | 424 |
| 425 StringConstantValue.fromString(String value) | 425 StringConstantValue.fromString(String value) |
| 426 : this(new DartString.literal(value)); | 426 : this(new DartString.literal(value)); |
| 427 | 427 |
| 428 bool get isString => true; | 428 bool get isString => true; |
| 429 | 429 |
| 430 ResolutionDartType getType(CommonElements types) => types.stringType; | 430 DartType getType(CommonElements types) => types.stringType; |
| 431 | 431 |
| 432 bool operator ==(var other) { | 432 bool operator ==(var other) { |
| 433 if (identical(this, other)) return true; | 433 if (identical(this, other)) return true; |
| 434 if (other is! StringConstantValue) return false; | 434 if (other is! StringConstantValue) return false; |
| 435 StringConstantValue otherString = other; | 435 StringConstantValue otherString = other; |
| 436 return hashCode == otherString.hashCode && | 436 return hashCode == otherString.hashCode && |
| 437 primitiveValue == otherString.primitiveValue; | 437 primitiveValue == otherString.primitiveValue; |
| 438 } | 438 } |
| 439 | 439 |
| 440 DartString toDartString() => primitiveValue; | 440 DartString toDartString() => primitiveValue; |
| 441 | 441 |
| 442 int get length => primitiveValue.length; | 442 int get length => primitiveValue.length; |
| 443 | 443 |
| 444 accept(ConstantValueVisitor visitor, arg) => visitor.visitString(this, arg); | 444 accept(ConstantValueVisitor visitor, arg) => visitor.visitString(this, arg); |
| 445 | 445 |
| 446 ConstantValueKind get kind => ConstantValueKind.STRING; | 446 ConstantValueKind get kind => ConstantValueKind.STRING; |
| 447 | 447 |
| 448 // TODO(johnniwinther): Ensure correct escaping. | 448 // TODO(johnniwinther): Ensure correct escaping. |
| 449 String toDartText() => '"${primitiveValue.slowToString()}"'; | 449 String toDartText() => '"${primitiveValue.slowToString()}"'; |
| 450 | 450 |
| 451 String toStructuredText() => 'StringConstant(${toDartText()})'; | 451 String toStructuredText() => 'StringConstant(${toDartText()})'; |
| 452 } | 452 } |
| 453 | 453 |
| 454 abstract class ObjectConstantValue extends ConstantValue { | 454 abstract class ObjectConstantValue extends ConstantValue { |
| 455 final ResolutionInterfaceType type; | 455 final InterfaceType type; |
| 456 | 456 |
| 457 ObjectConstantValue(this.type); | 457 ObjectConstantValue(this.type); |
| 458 | 458 |
| 459 bool get isObject => true; | 459 bool get isObject => true; |
| 460 | 460 |
| 461 ResolutionDartType getType(CommonElements types) => type; | 461 DartType getType(CommonElements types) => type; |
| 462 | 462 |
| 463 void _unparseTypeArguments(StringBuffer sb) { | 463 void _unparseTypeArguments(StringBuffer sb) { |
| 464 if (!type.treatAsRaw) { | 464 if (!type.treatAsRaw) { |
| 465 sb.write('<'); | 465 sb.write('<'); |
| 466 sb.write(type.typeArguments.join(', ')); | 466 sb.write(type.typeArguments.join(', ')); |
| 467 sb.write('>'); | 467 sb.write('>'); |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 } | 470 } |
| 471 | 471 |
| 472 class TypeConstantValue extends ObjectConstantValue { | 472 class TypeConstantValue extends ObjectConstantValue { |
| 473 /// The user type that this constant represents. | 473 /// The user type that this constant represents. |
| 474 final ResolutionDartType representedType; | 474 final DartType representedType; |
| 475 | 475 |
| 476 TypeConstantValue(this.representedType, ResolutionInterfaceType type) | 476 TypeConstantValue(this.representedType, InterfaceType type) : super(type); |
| 477 : super(type); | |
| 478 | 477 |
| 479 bool get isType => true; | 478 bool get isType => true; |
| 480 | 479 |
| 481 bool operator ==(other) { | 480 bool operator ==(other) { |
| 482 return other is TypeConstantValue && | 481 return other is TypeConstantValue && |
| 483 representedType == other.representedType; | 482 representedType == other.representedType; |
| 484 } | 483 } |
| 485 | 484 |
| 486 int get hashCode => representedType.hashCode * 13; | 485 int get hashCode => representedType.hashCode * 13; |
| 487 | 486 |
| 488 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 487 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 489 | 488 |
| 490 accept(ConstantValueVisitor visitor, arg) => visitor.visitType(this, arg); | 489 accept(ConstantValueVisitor visitor, arg) => visitor.visitType(this, arg); |
| 491 | 490 |
| 492 ConstantValueKind get kind => ConstantValueKind.TYPE; | 491 ConstantValueKind get kind => ConstantValueKind.TYPE; |
| 493 | 492 |
| 494 String toDartText() => '$representedType'; | 493 String toDartText() => '$representedType'; |
| 495 | 494 |
| 496 String toStructuredText() => 'TypeConstant(${representedType})'; | 495 String toStructuredText() => 'TypeConstant(${representedType})'; |
| 497 } | 496 } |
| 498 | 497 |
| 499 class ListConstantValue extends ObjectConstantValue { | 498 class ListConstantValue extends ObjectConstantValue { |
| 500 final List<ConstantValue> entries; | 499 final List<ConstantValue> entries; |
| 501 final int hashCode; | 500 final int hashCode; |
| 502 | 501 |
| 503 ListConstantValue(ResolutionInterfaceType type, List<ConstantValue> entries) | 502 ListConstantValue(InterfaceType type, List<ConstantValue> entries) |
| 504 : this.entries = entries, | 503 : this.entries = entries, |
| 505 hashCode = Hashing.listHash(entries, Hashing.objectHash(type)), | 504 hashCode = Hashing.listHash(entries, Hashing.objectHash(type)), |
| 506 super(type); | 505 super(type); |
| 507 | 506 |
| 508 bool get isList => true; | 507 bool get isList => true; |
| 509 | 508 |
| 510 bool operator ==(var other) { | 509 bool operator ==(var other) { |
| 511 if (identical(this, other)) return true; | 510 if (identical(this, other)) return true; |
| 512 if (other is! ListConstantValue) return false; | 511 if (other is! ListConstantValue) return false; |
| 513 ListConstantValue otherList = other; | 512 ListConstantValue otherList = other; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 return sb.toString(); | 552 return sb.toString(); |
| 554 } | 553 } |
| 555 } | 554 } |
| 556 | 555 |
| 557 class MapConstantValue extends ObjectConstantValue { | 556 class MapConstantValue extends ObjectConstantValue { |
| 558 final List<ConstantValue> keys; | 557 final List<ConstantValue> keys; |
| 559 final List<ConstantValue> values; | 558 final List<ConstantValue> values; |
| 560 final int hashCode; | 559 final int hashCode; |
| 561 Map<ConstantValue, ConstantValue> _lookupMap; | 560 Map<ConstantValue, ConstantValue> _lookupMap; |
| 562 | 561 |
| 563 MapConstantValue(ResolutionInterfaceType type, List<ConstantValue> keys, | 562 MapConstantValue( |
| 564 List<ConstantValue> values) | 563 InterfaceType type, List<ConstantValue> keys, List<ConstantValue> values) |
| 565 : this.keys = keys, | 564 : this.keys = keys, |
| 566 this.values = values, | 565 this.values = values, |
| 567 this.hashCode = Hashing.listHash( | 566 this.hashCode = Hashing.listHash( |
| 568 values, Hashing.listHash(keys, Hashing.objectHash(type))), | 567 values, Hashing.listHash(keys, Hashing.objectHash(type))), |
| 569 super(type) { | 568 super(type) { |
| 570 assert(keys.length == values.length); | 569 assert(keys.length == values.length); |
| 571 } | 570 } |
| 572 | 571 |
| 573 bool get isMap => true; | 572 bool get isMap => true; |
| 574 | 573 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 sb.write(keys[i].toStructuredText()); | 628 sb.write(keys[i].toStructuredText()); |
| 630 sb.write(': '); | 629 sb.write(': '); |
| 631 sb.write(values[i].toStructuredText()); | 630 sb.write(values[i].toStructuredText()); |
| 632 } | 631 } |
| 633 sb.write('})'); | 632 sb.write('})'); |
| 634 return sb.toString(); | 633 return sb.toString(); |
| 635 } | 634 } |
| 636 } | 635 } |
| 637 | 636 |
| 638 class InterceptorConstantValue extends ConstantValue { | 637 class InterceptorConstantValue extends ConstantValue { |
| 639 /// The type for which this interceptor holds the methods. The constant | 638 /// The class for which this interceptor holds the methods. The constant |
| 640 /// is a dispatch table for this type. | 639 /// is a dispatch table for this class. |
| 641 final ResolutionDartType dispatchedType; | 640 final ClassEntity cls; |
| 642 | 641 |
| 643 InterceptorConstantValue(this.dispatchedType); | 642 InterceptorConstantValue(this.cls); |
| 644 | 643 |
| 645 bool get isInterceptor => true; | 644 bool get isInterceptor => true; |
| 646 | 645 |
| 647 bool operator ==(other) { | 646 bool operator ==(other) { |
| 648 return other is InterceptorConstantValue && | 647 return other is InterceptorConstantValue && cls == other.cls; |
| 649 dispatchedType == other.dispatchedType; | |
| 650 } | 648 } |
| 651 | 649 |
| 652 int get hashCode => dispatchedType.hashCode * 43; | 650 int get hashCode => cls.hashCode * 43; |
| 653 | 651 |
| 654 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 652 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 655 | 653 |
| 656 accept(ConstantValueVisitor visitor, arg) { | 654 accept(ConstantValueVisitor visitor, arg) { |
| 657 return visitor.visitInterceptor(this, arg); | 655 return visitor.visitInterceptor(this, arg); |
| 658 } | 656 } |
| 659 | 657 |
| 660 ResolutionDartType getType(CommonElements types) => | 658 DartType getType(CommonElements types) => types.dynamicType; |
| 661 const ResolutionDynamicType(); | |
| 662 | 659 |
| 663 ConstantValueKind get kind => ConstantValueKind.INTERCEPTOR; | 660 ConstantValueKind get kind => ConstantValueKind.INTERCEPTOR; |
| 664 | 661 |
| 665 String toDartText() { | 662 String toDartText() { |
| 666 return 'interceptor($dispatchedType)'; | 663 return 'interceptor($cls)'; |
| 667 } | 664 } |
| 668 | 665 |
| 669 String toStructuredText() { | 666 String toStructuredText() { |
| 670 return 'InterceptorConstant(${dispatchedType.getStringAsDeclared("o")})'; | 667 return 'InterceptorConstant(${cls.name})'; |
| 671 } | 668 } |
| 672 } | 669 } |
| 673 | 670 |
| 674 class SyntheticConstantValue extends ConstantValue { | 671 class SyntheticConstantValue extends ConstantValue { |
| 675 final payload; | 672 final payload; |
| 676 final valueKind; | 673 final valueKind; |
| 677 | 674 |
| 678 SyntheticConstantValue(this.valueKind, this.payload); | 675 SyntheticConstantValue(this.valueKind, this.payload); |
| 679 | 676 |
| 680 bool get isDummy => true; | 677 bool get isDummy => true; |
| 681 | 678 |
| 682 bool operator ==(other) { | 679 bool operator ==(other) { |
| 683 return other is SyntheticConstantValue && payload == other.payload; | 680 return other is SyntheticConstantValue && payload == other.payload; |
| 684 } | 681 } |
| 685 | 682 |
| 686 get hashCode => payload.hashCode * 17 + valueKind.hashCode; | 683 get hashCode => payload.hashCode * 17 + valueKind.hashCode; |
| 687 | 684 |
| 688 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 685 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 689 | 686 |
| 690 accept(ConstantValueVisitor visitor, arg) { | 687 accept(ConstantValueVisitor visitor, arg) { |
| 691 return visitor.visitSynthetic(this, arg); | 688 return visitor.visitSynthetic(this, arg); |
| 692 } | 689 } |
| 693 | 690 |
| 694 ResolutionDartType getType(CommonElements types) => | 691 DartType getType(CommonElements types) => types.dynamicType; |
| 695 const ResolutionDynamicType(); | |
| 696 | 692 |
| 697 ConstantValueKind get kind => ConstantValueKind.SYNTHETIC; | 693 ConstantValueKind get kind => ConstantValueKind.SYNTHETIC; |
| 698 | 694 |
| 699 String toDartText() => 'synthetic($valueKind, $payload)'; | 695 String toDartText() => 'synthetic($valueKind, $payload)'; |
| 700 | 696 |
| 701 String toStructuredText() => 'SyntheticConstant($valueKind, $payload)'; | 697 String toStructuredText() => 'SyntheticConstant($valueKind, $payload)'; |
| 702 } | 698 } |
| 703 | 699 |
| 704 class ConstructedConstantValue extends ObjectConstantValue { | 700 class ConstructedConstantValue extends ObjectConstantValue { |
| 705 // TODO(johnniwinther): Make [fields] private to avoid misuse of the map | 701 // TODO(johnniwinther): Make [fields] private to avoid misuse of the map |
| 706 // ordering and mutability. | 702 // ordering and mutability. |
| 707 final Map<FieldEntity, ConstantValue> fields; | 703 final Map<FieldEntity, ConstantValue> fields; |
| 708 final int hashCode; | 704 final int hashCode; |
| 709 | 705 |
| 710 ConstructedConstantValue( | 706 ConstructedConstantValue( |
| 711 ResolutionInterfaceType type, Map<FieldEntity, ConstantValue> fields) | 707 InterfaceType type, Map<FieldEntity, ConstantValue> fields) |
| 712 : this.fields = fields, | 708 : this.fields = fields, |
| 713 hashCode = Hashing.unorderedMapHash(fields, Hashing.objectHash(type)), | 709 hashCode = Hashing.unorderedMapHash(fields, Hashing.objectHash(type)), |
| 714 super(type) { | 710 super(type) { |
| 715 assert(type != null); | 711 assert(type != null); |
| 716 assert(!fields.containsValue(null)); | 712 assert(!fields.containsValue(null)); |
| 717 } | 713 } |
| 718 | 714 |
| 719 bool get isConstructedObject => true; | 715 bool get isConstructedObject => true; |
| 720 | 716 |
| 721 bool operator ==(var otherVar) { | 717 bool operator ==(var otherVar) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 734 List<ConstantValue> getDependencies() => fields.values.toList(); | 730 List<ConstantValue> getDependencies() => fields.values.toList(); |
| 735 | 731 |
| 736 accept(ConstantValueVisitor visitor, arg) { | 732 accept(ConstantValueVisitor visitor, arg) { |
| 737 return visitor.visitConstructed(this, arg); | 733 return visitor.visitConstructed(this, arg); |
| 738 } | 734 } |
| 739 | 735 |
| 740 ConstantValueKind get kind => ConstantValueKind.CONSTRUCTED; | 736 ConstantValueKind get kind => ConstantValueKind.CONSTRUCTED; |
| 741 | 737 |
| 742 String toDartText() { | 738 String toDartText() { |
| 743 StringBuffer sb = new StringBuffer(); | 739 StringBuffer sb = new StringBuffer(); |
| 744 sb.write(type.name); | 740 sb.write(type.element.name); |
| 745 _unparseTypeArguments(sb); | 741 _unparseTypeArguments(sb); |
| 746 sb.write('('); | 742 sb.write('('); |
| 747 int i = 0; | 743 int i = 0; |
| 748 fields.forEach((FieldEntity field, ConstantValue value) { | 744 fields.forEach((FieldEntity field, ConstantValue value) { |
| 749 if (i > 0) sb.write(','); | 745 if (i > 0) sb.write(','); |
| 750 sb.write(field.name); | 746 sb.write(field.name); |
| 751 sb.write('='); | 747 sb.write('='); |
| 752 sb.write(value.toDartText()); | 748 sb.write(value.toDartText()); |
| 753 i++; | 749 i++; |
| 754 }); | 750 }); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 referenced == other.referenced && | 785 referenced == other.referenced && |
| 790 prefix == other.prefix; | 786 prefix == other.prefix; |
| 791 } | 787 } |
| 792 | 788 |
| 793 get hashCode => (referenced.hashCode * 17 + prefix.hashCode) & 0x3fffffff; | 789 get hashCode => (referenced.hashCode * 17 + prefix.hashCode) & 0x3fffffff; |
| 794 | 790 |
| 795 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; | 791 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; |
| 796 | 792 |
| 797 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); | 793 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); |
| 798 | 794 |
| 799 ResolutionDartType getType(CommonElements types) => referenced.getType(types); | 795 DartType getType(CommonElements types) => referenced.getType(types); |
| 800 | 796 |
| 801 ConstantValueKind get kind => ConstantValueKind.DEFERRED; | 797 ConstantValueKind get kind => ConstantValueKind.DEFERRED; |
| 802 | 798 |
| 803 String toDartText() => 'deferred(${referenced.toDartText()})'; | 799 String toDartText() => 'deferred(${referenced.toDartText()})'; |
| 804 | 800 |
| 805 String toStructuredText() { | 801 String toStructuredText() { |
| 806 return 'DeferredConstant(${referenced.toStructuredText()})'; | 802 return 'DeferredConstant(${referenced.toStructuredText()})'; |
| 807 } | 803 } |
| 808 } | 804 } |
| 809 | 805 |
| 810 /// A constant value resulting from a non constant or erroneous constant | 806 /// A constant value resulting from a non constant or erroneous constant |
| 811 /// expression. | 807 /// expression. |
| 812 // TODO(johnniwinther): Expand this to contain the error kind. | 808 // TODO(johnniwinther): Expand this to contain the error kind. |
| 813 class NonConstantValue extends ConstantValue { | 809 class NonConstantValue extends ConstantValue { |
| 814 bool get isConstant => false; | 810 bool get isConstant => false; |
| 815 | 811 |
| 816 @override | 812 @override |
| 817 accept(ConstantValueVisitor visitor, arg) { | 813 accept(ConstantValueVisitor visitor, arg) { |
| 818 return visitor.visitNonConstant(this, arg); | 814 return visitor.visitNonConstant(this, arg); |
| 819 } | 815 } |
| 820 | 816 |
| 821 @override | 817 @override |
| 822 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 818 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 823 | 819 |
| 824 @override | 820 @override |
| 825 ResolutionDartType getType(CommonElements types) => | 821 DartType getType(CommonElements types) => types.dynamicType; |
| 826 const ResolutionDynamicType(); | |
| 827 | 822 |
| 828 ConstantValueKind get kind => ConstantValueKind.NON_CONSTANT; | 823 ConstantValueKind get kind => ConstantValueKind.NON_CONSTANT; |
| 829 | 824 |
| 830 @override | 825 @override |
| 831 String toStructuredText() => 'NonConstant'; | 826 String toStructuredText() => 'NonConstant'; |
| 832 | 827 |
| 833 @override | 828 @override |
| 834 String toDartText() => '>>non-constant<<'; | 829 String toDartText() => '>>non-constant<<'; |
| 835 } | 830 } |
| OLD | NEW |