| 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 '../dart_types.dart'; | 9 import '../dart_types.dart'; |
| 10 import '../elements/elements.dart' | 10 import '../elements/elements.dart' |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 accept(ConstantValueVisitor visitor, arg); | 71 accept(ConstantValueVisitor visitor, arg); |
| 72 | 72 |
| 73 /// The value of this constant in Dart syntax, if possible. | 73 /// The value of this constant in Dart syntax, if possible. |
| 74 /// | 74 /// |
| 75 /// For [ConstructedConstantValue]s there is no way to create a valid const | 75 /// For [ConstructedConstantValue]s there is no way to create a valid const |
| 76 /// expression from the value so the unparse of these is best effort. | 76 /// expression from the value so the unparse of these is best effort. |
| 77 /// | 77 /// |
| 78 /// For the synthetic constants, [DeferredConstantValue], | 78 /// For the synthetic constants, [DeferredConstantValue], |
| 79 /// [SyntheticConstantValue], [InterceptorConstantValue] the unparse is | 79 /// [SyntheticConstantValue], [InterceptorConstantValue] the unparse is |
| 80 /// descriptive only. | 80 /// descriptive only. |
| 81 String unparse(); | 81 String toDartText(); |
| 82 | 82 |
| 83 /// Returns a structured representation of this constant suited for debugging. | 83 /// Returns a structured representation of this constant suited for debugging. |
| 84 String toStructuredString(); | 84 String toStructuredText(); |
| 85 | 85 |
| 86 String toString() { | 86 String toString() { |
| 87 assertDebugMode("Use Constant.unparse() or Constant.toStructuredString() " | 87 assertDebugMode("Use ConstantValue.toDartText() or " |
| 88 "instead of Constant.toString()."); | 88 "ConstantValue.toStructuredText() " |
| 89 return toStructuredString(); | 89 "instead of ConstantValue.toString()."); |
| 90 return toStructuredText(); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 class FunctionConstantValue extends ConstantValue { | 94 class FunctionConstantValue extends ConstantValue { |
| 94 FunctionElement element; | 95 FunctionElement element; |
| 95 | 96 |
| 96 FunctionConstantValue(this.element) { | 97 FunctionConstantValue(this.element) { |
| 97 assert(element.type != null); | 98 assert(element.type != null); |
| 98 } | 99 } |
| 99 | 100 |
| 100 bool get isFunction => true; | 101 bool get isFunction => true; |
| 101 | 102 |
| 102 bool operator ==(var other) { | 103 bool operator ==(var other) { |
| 103 if (other is! FunctionConstantValue) return false; | 104 if (other is! FunctionConstantValue) return false; |
| 104 return identical(other.element, element); | 105 return identical(other.element, element); |
| 105 } | 106 } |
| 106 | 107 |
| 107 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 108 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 108 | 109 |
| 109 DartString toDartString() { | 110 DartString toDartString() { |
| 110 return new DartString.literal(element.name); | 111 return new DartString.literal(element.name); |
| 111 } | 112 } |
| 112 | 113 |
| 113 DartType getType(CoreTypes types) => element.type; | 114 DartType getType(CoreTypes types) => element.type; |
| 114 | 115 |
| 115 int get hashCode => (17 * element.hashCode) & 0x7fffffff; | 116 int get hashCode => (17 * element.hashCode) & 0x7fffffff; |
| 116 | 117 |
| 117 accept(ConstantValueVisitor visitor, arg) => visitor.visitFunction(this, arg); | 118 accept(ConstantValueVisitor visitor, arg) => visitor.visitFunction(this, arg); |
| 118 | 119 |
| 119 String unparse() { | 120 String toDartText() { |
| 120 if (element.isStatic) { | 121 if (element.isStatic) { |
| 121 return '${element.enclosingClass.name}.${element.name}'; | 122 return '${element.enclosingClass.name}.${element.name}'; |
| 122 } else { | 123 } else { |
| 123 return '${element.name}'; | 124 return '${element.name}'; |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 | 127 |
| 127 String toStructuredString() { | 128 String toStructuredText() { |
| 128 return 'FunctionConstant(${unparse()})'; | 129 return 'FunctionConstant(${toDartText()})'; |
| 129 } | 130 } |
| 130 } | 131 } |
| 131 | 132 |
| 132 abstract class PrimitiveConstantValue extends ConstantValue { | 133 abstract class PrimitiveConstantValue extends ConstantValue { |
| 133 get primitiveValue; | 134 get primitiveValue; |
| 134 | 135 |
| 135 const PrimitiveConstantValue(); | 136 const PrimitiveConstantValue(); |
| 136 | 137 |
| 137 bool get isPrimitive => true; | 138 bool get isPrimitive => true; |
| 138 | 139 |
| 139 bool operator ==(var other) { | 140 bool operator ==(var other) { |
| 140 if (other is! PrimitiveConstantValue) return false; | 141 if (other is! PrimitiveConstantValue) return false; |
| 141 PrimitiveConstantValue otherPrimitive = other; | 142 PrimitiveConstantValue otherPrimitive = other; |
| 142 // We use == instead of 'identical' so that DartStrings compare correctly. | 143 // We use == instead of 'identical' so that DartStrings compare correctly. |
| 143 return primitiveValue == otherPrimitive.primitiveValue; | 144 return primitiveValue == otherPrimitive.primitiveValue; |
| 144 } | 145 } |
| 145 | 146 |
| 146 int get hashCode => throw new UnsupportedError('PrimitiveConstant.hashCode'); | 147 int get hashCode => throw new UnsupportedError('PrimitiveConstant.hashCode'); |
| 147 | 148 |
| 148 // Primitive constants don't have dependencies. | 149 // Primitive constants don't have dependencies. |
| 149 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 150 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 150 | 151 |
| 151 DartString toDartString(); | 152 DartString toDartString(); |
| 152 | 153 |
| 153 /// This value in Dart syntax. | 154 /// This value in Dart syntax. |
| 154 String unparse() => primitiveValue.toString(); | 155 String toDartText() => primitiveValue.toString(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 class NullConstantValue extends PrimitiveConstantValue { | 158 class NullConstantValue extends PrimitiveConstantValue { |
| 158 /** The value a Dart null is compiled to in JavaScript. */ | 159 /** The value a Dart null is compiled to in JavaScript. */ |
| 159 static const String JsNull = "null"; | 160 static const String JsNull = "null"; |
| 160 | 161 |
| 161 factory NullConstantValue() => const NullConstantValue._internal(); | 162 factory NullConstantValue() => const NullConstantValue._internal(); |
| 162 | 163 |
| 163 const NullConstantValue._internal(); | 164 const NullConstantValue._internal(); |
| 164 | 165 |
| 165 bool get isNull => true; | 166 bool get isNull => true; |
| 166 | 167 |
| 167 get primitiveValue => null; | 168 get primitiveValue => null; |
| 168 | 169 |
| 169 DartType getType(CoreTypes types) => types.nullType; | 170 DartType getType(CoreTypes types) => types.nullType; |
| 170 | 171 |
| 171 // The magic constant has no meaning. It is just a random value. | 172 // The magic constant has no meaning. It is just a random value. |
| 172 int get hashCode => 785965825; | 173 int get hashCode => 785965825; |
| 173 | 174 |
| 174 DartString toDartString() => const LiteralDartString("null"); | 175 DartString toDartString() => const LiteralDartString("null"); |
| 175 | 176 |
| 176 accept(ConstantValueVisitor visitor, arg) => visitor.visitNull(this, arg); | 177 accept(ConstantValueVisitor visitor, arg) => visitor.visitNull(this, arg); |
| 177 | 178 |
| 178 String toStructuredString() => 'NullConstant'; | 179 String toStructuredText() => 'NullConstant'; |
| 179 } | 180 } |
| 180 | 181 |
| 181 abstract class NumConstantValue extends PrimitiveConstantValue { | 182 abstract class NumConstantValue extends PrimitiveConstantValue { |
| 182 const NumConstantValue(); | 183 const NumConstantValue(); |
| 183 | 184 |
| 184 num get primitiveValue; | 185 num get primitiveValue; |
| 185 | 186 |
| 186 bool get isNum => true; | 187 bool get isNum => true; |
| 187 } | 188 } |
| 188 | 189 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 } | 250 } |
| 250 | 251 |
| 251 int get hashCode => primitiveValue & Hashing.SMI_MASK; | 252 int get hashCode => primitiveValue & Hashing.SMI_MASK; |
| 252 | 253 |
| 253 DartString toDartString() { | 254 DartString toDartString() { |
| 254 return new DartString.literal(primitiveValue.toString()); | 255 return new DartString.literal(primitiveValue.toString()); |
| 255 } | 256 } |
| 256 | 257 |
| 257 accept(ConstantValueVisitor visitor, arg) => visitor.visitInt(this, arg); | 258 accept(ConstantValueVisitor visitor, arg) => visitor.visitInt(this, arg); |
| 258 | 259 |
| 259 String toStructuredString() => 'IntConstant(${unparse()})'; | 260 String toStructuredText() => 'IntConstant(${toDartText()})'; |
| 260 } | 261 } |
| 261 | 262 |
| 262 class DoubleConstantValue extends NumConstantValue { | 263 class DoubleConstantValue extends NumConstantValue { |
| 263 final double primitiveValue; | 264 final double primitiveValue; |
| 264 | 265 |
| 265 factory DoubleConstantValue(double value) { | 266 factory DoubleConstantValue(double value) { |
| 266 if (value.isNaN) { | 267 if (value.isNaN) { |
| 267 return const DoubleConstantValue._internal(double.NAN); | 268 return const DoubleConstantValue._internal(double.NAN); |
| 268 } else if (value == double.INFINITY) { | 269 } else if (value == double.INFINITY) { |
| 269 return const DoubleConstantValue._internal(double.INFINITY); | 270 return const DoubleConstantValue._internal(double.INFINITY); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 312 } |
| 312 | 313 |
| 313 int get hashCode => primitiveValue.hashCode; | 314 int get hashCode => primitiveValue.hashCode; |
| 314 | 315 |
| 315 DartString toDartString() { | 316 DartString toDartString() { |
| 316 return new DartString.literal(primitiveValue.toString()); | 317 return new DartString.literal(primitiveValue.toString()); |
| 317 } | 318 } |
| 318 | 319 |
| 319 accept(ConstantValueVisitor visitor, arg) => visitor.visitDouble(this, arg); | 320 accept(ConstantValueVisitor visitor, arg) => visitor.visitDouble(this, arg); |
| 320 | 321 |
| 321 String toStructuredString() => 'DoubleConstant(${unparse()})'; | 322 String toStructuredText() => 'DoubleConstant(${toDartText()})'; |
| 322 } | 323 } |
| 323 | 324 |
| 324 abstract class BoolConstantValue extends PrimitiveConstantValue { | 325 abstract class BoolConstantValue extends PrimitiveConstantValue { |
| 325 factory BoolConstantValue(value) { | 326 factory BoolConstantValue(value) { |
| 326 return value ? new TrueConstantValue() : new FalseConstantValue(); | 327 return value ? new TrueConstantValue() : new FalseConstantValue(); |
| 327 } | 328 } |
| 328 | 329 |
| 329 const BoolConstantValue._internal(); | 330 const BoolConstantValue._internal(); |
| 330 | 331 |
| 331 bool get isBool => true; | 332 bool get isBool => true; |
| 332 | 333 |
| 333 DartType getType(CoreTypes types) => types.boolType; | 334 DartType getType(CoreTypes types) => types.boolType; |
| 334 | 335 |
| 335 BoolConstantValue negate(); | 336 BoolConstantValue negate(); |
| 336 | 337 |
| 337 accept(ConstantValueVisitor visitor, arg) => visitor.visitBool(this, arg); | 338 accept(ConstantValueVisitor visitor, arg) => visitor.visitBool(this, arg); |
| 338 | 339 |
| 339 String toStructuredString() => 'BoolConstant(${unparse()})'; | 340 String toStructuredText() => 'BoolConstant(${toDartText()})'; |
| 340 } | 341 } |
| 341 | 342 |
| 342 class TrueConstantValue extends BoolConstantValue { | 343 class TrueConstantValue extends BoolConstantValue { |
| 343 factory TrueConstantValue() => const TrueConstantValue._internal(); | 344 factory TrueConstantValue() => const TrueConstantValue._internal(); |
| 344 | 345 |
| 345 const TrueConstantValue._internal() : super._internal(); | 346 const TrueConstantValue._internal() : super._internal(); |
| 346 | 347 |
| 347 bool get isTrue => true; | 348 bool get isTrue => true; |
| 348 | 349 |
| 349 bool get primitiveValue => true; | 350 bool get primitiveValue => true; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 primitiveValue == otherString.primitiveValue; | 407 primitiveValue == otherString.primitiveValue; |
| 407 } | 408 } |
| 408 | 409 |
| 409 DartString toDartString() => primitiveValue; | 410 DartString toDartString() => primitiveValue; |
| 410 | 411 |
| 411 int get length => primitiveValue.length; | 412 int get length => primitiveValue.length; |
| 412 | 413 |
| 413 accept(ConstantValueVisitor visitor, arg) => visitor.visitString(this, arg); | 414 accept(ConstantValueVisitor visitor, arg) => visitor.visitString(this, arg); |
| 414 | 415 |
| 415 // TODO(johnniwinther): Ensure correct escaping. | 416 // TODO(johnniwinther): Ensure correct escaping. |
| 416 String unparse() => '"${primitiveValue.slowToString()}"'; | 417 String toDartText() => '"${primitiveValue.slowToString()}"'; |
| 417 | 418 |
| 418 String toStructuredString() => 'StringConstant(${unparse()})'; | 419 String toStructuredText() => 'StringConstant(${toDartText()})'; |
| 419 } | 420 } |
| 420 | 421 |
| 421 abstract class ObjectConstantValue extends ConstantValue { | 422 abstract class ObjectConstantValue extends ConstantValue { |
| 422 final InterfaceType type; | 423 final InterfaceType type; |
| 423 | 424 |
| 424 ObjectConstantValue(this.type); | 425 ObjectConstantValue(this.type); |
| 425 | 426 |
| 426 bool get isObject => true; | 427 bool get isObject => true; |
| 427 | 428 |
| 428 DartType getType(CoreTypes types) => type; | 429 DartType getType(CoreTypes types) => type; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 448 return other is TypeConstantValue && | 449 return other is TypeConstantValue && |
| 449 representedType == other.representedType; | 450 representedType == other.representedType; |
| 450 } | 451 } |
| 451 | 452 |
| 452 int get hashCode => representedType.hashCode * 13; | 453 int get hashCode => representedType.hashCode * 13; |
| 453 | 454 |
| 454 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 455 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 455 | 456 |
| 456 accept(ConstantValueVisitor visitor, arg) => visitor.visitType(this, arg); | 457 accept(ConstantValueVisitor visitor, arg) => visitor.visitType(this, arg); |
| 457 | 458 |
| 458 String unparse() => '$representedType'; | 459 String toDartText() => '$representedType'; |
| 459 | 460 |
| 460 String toStructuredString() => 'TypeConstant(${representedType})'; | 461 String toStructuredText() => 'TypeConstant(${representedType})'; |
| 461 } | 462 } |
| 462 | 463 |
| 463 class ListConstantValue extends ObjectConstantValue { | 464 class ListConstantValue extends ObjectConstantValue { |
| 464 final List<ConstantValue> entries; | 465 final List<ConstantValue> entries; |
| 465 final int hashCode; | 466 final int hashCode; |
| 466 | 467 |
| 467 ListConstantValue(InterfaceType type, List<ConstantValue> entries) | 468 ListConstantValue(InterfaceType type, List<ConstantValue> entries) |
| 468 : this.entries = entries, | 469 : this.entries = entries, |
| 469 hashCode = Hashing.listHash(entries, Hashing.objectHash(type)), | 470 hashCode = Hashing.listHash(entries, Hashing.objectHash(type)), |
| 470 super(type); | 471 super(type); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 483 } | 484 } |
| 484 return true; | 485 return true; |
| 485 } | 486 } |
| 486 | 487 |
| 487 List<ConstantValue> getDependencies() => entries; | 488 List<ConstantValue> getDependencies() => entries; |
| 488 | 489 |
| 489 int get length => entries.length; | 490 int get length => entries.length; |
| 490 | 491 |
| 491 accept(ConstantValueVisitor visitor, arg) => visitor.visitList(this, arg); | 492 accept(ConstantValueVisitor visitor, arg) => visitor.visitList(this, arg); |
| 492 | 493 |
| 493 String unparse() { | 494 String toDartText() { |
| 494 StringBuffer sb = new StringBuffer(); | 495 StringBuffer sb = new StringBuffer(); |
| 495 _unparseTypeArguments(sb); | 496 _unparseTypeArguments(sb); |
| 496 sb.write('['); | 497 sb.write('['); |
| 497 for (int i = 0; i < length; i++) { | 498 for (int i = 0; i < length; i++) { |
| 498 if (i > 0) sb.write(','); | 499 if (i > 0) sb.write(','); |
| 499 sb.write(entries[i].unparse()); | 500 sb.write(entries[i].toDartText()); |
| 500 } | 501 } |
| 501 sb.write(']'); | 502 sb.write(']'); |
| 502 return sb.toString(); | 503 return sb.toString(); |
| 503 } | 504 } |
| 504 | 505 |
| 505 String toStructuredString() { | 506 String toStructuredText() { |
| 506 StringBuffer sb = new StringBuffer(); | 507 StringBuffer sb = new StringBuffer(); |
| 507 sb.write('ListConstant('); | 508 sb.write('ListConstant('); |
| 508 _unparseTypeArguments(sb); | 509 _unparseTypeArguments(sb); |
| 509 sb.write('['); | 510 sb.write('['); |
| 510 for (int i = 0; i < length; i++) { | 511 for (int i = 0; i < length; i++) { |
| 511 if (i > 0) sb.write(', '); | 512 if (i > 0) sb.write(', '); |
| 512 sb.write(entries[i].toStructuredString()); | 513 sb.write(entries[i].toStructuredText()); |
| 513 } | 514 } |
| 514 sb.write('])'); | 515 sb.write('])'); |
| 515 return sb.toString(); | 516 return sb.toString(); |
| 516 } | 517 } |
| 517 } | 518 } |
| 518 | 519 |
| 519 class MapConstantValue extends ObjectConstantValue { | 520 class MapConstantValue extends ObjectConstantValue { |
| 520 final List<ConstantValue> keys; | 521 final List<ConstantValue> keys; |
| 521 final List<ConstantValue> values; | 522 final List<ConstantValue> values; |
| 522 final int hashCode; | 523 final int hashCode; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 int get length => keys.length; | 559 int get length => keys.length; |
| 559 | 560 |
| 560 ConstantValue lookup(ConstantValue key) { | 561 ConstantValue lookup(ConstantValue key) { |
| 561 var lookupMap = _lookupMap ??= | 562 var lookupMap = _lookupMap ??= |
| 562 new Map<ConstantValue, ConstantValue>.fromIterables(keys, values); | 563 new Map<ConstantValue, ConstantValue>.fromIterables(keys, values); |
| 563 return lookupMap[key]; | 564 return lookupMap[key]; |
| 564 } | 565 } |
| 565 | 566 |
| 566 accept(ConstantValueVisitor visitor, arg) => visitor.visitMap(this, arg); | 567 accept(ConstantValueVisitor visitor, arg) => visitor.visitMap(this, arg); |
| 567 | 568 |
| 568 String unparse() { | 569 String toDartText() { |
| 569 StringBuffer sb = new StringBuffer(); | 570 StringBuffer sb = new StringBuffer(); |
| 570 _unparseTypeArguments(sb); | 571 _unparseTypeArguments(sb); |
| 571 sb.write('{'); | 572 sb.write('{'); |
| 572 for (int i = 0; i < length; i++) { | 573 for (int i = 0; i < length; i++) { |
| 573 if (i > 0) sb.write(','); | 574 if (i > 0) sb.write(','); |
| 574 sb.write(keys[i].unparse()); | 575 sb.write(keys[i].toDartText()); |
| 575 sb.write(':'); | 576 sb.write(':'); |
| 576 sb.write(values[i].unparse()); | 577 sb.write(values[i].toDartText()); |
| 577 } | 578 } |
| 578 sb.write('}'); | 579 sb.write('}'); |
| 579 return sb.toString(); | 580 return sb.toString(); |
| 580 } | 581 } |
| 581 | 582 |
| 582 String toStructuredString() { | 583 String toStructuredText() { |
| 583 StringBuffer sb = new StringBuffer(); | 584 StringBuffer sb = new StringBuffer(); |
| 584 sb.write('MapConstant('); | 585 sb.write('MapConstant('); |
| 585 _unparseTypeArguments(sb); | 586 _unparseTypeArguments(sb); |
| 586 sb.write('{'); | 587 sb.write('{'); |
| 587 for (int i = 0; i < length; i++) { | 588 for (int i = 0; i < length; i++) { |
| 588 if (i > 0) sb.write(', '); | 589 if (i > 0) sb.write(', '); |
| 589 sb.write(keys[i].toStructuredString()); | 590 sb.write(keys[i].toStructuredText()); |
| 590 sb.write(': '); | 591 sb.write(': '); |
| 591 sb.write(values[i].toStructuredString()); | 592 sb.write(values[i].toStructuredText()); |
| 592 } | 593 } |
| 593 sb.write('})'); | 594 sb.write('})'); |
| 594 return sb.toString(); | 595 return sb.toString(); |
| 595 } | 596 } |
| 596 } | 597 } |
| 597 | 598 |
| 598 class InterceptorConstantValue extends ConstantValue { | 599 class InterceptorConstantValue extends ConstantValue { |
| 599 /// The type for which this interceptor holds the methods. The constant | 600 /// The type for which this interceptor holds the methods. The constant |
| 600 /// is a dispatch table for this type. | 601 /// is a dispatch table for this type. |
| 601 final DartType dispatchedType; | 602 final DartType dispatchedType; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 612 int get hashCode => dispatchedType.hashCode * 43; | 613 int get hashCode => dispatchedType.hashCode * 43; |
| 613 | 614 |
| 614 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 615 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 615 | 616 |
| 616 accept(ConstantValueVisitor visitor, arg) { | 617 accept(ConstantValueVisitor visitor, arg) { |
| 617 return visitor.visitInterceptor(this, arg); | 618 return visitor.visitInterceptor(this, arg); |
| 618 } | 619 } |
| 619 | 620 |
| 620 DartType getType(CoreTypes types) => const DynamicType(); | 621 DartType getType(CoreTypes types) => const DynamicType(); |
| 621 | 622 |
| 622 String unparse() { | 623 String toDartText() { |
| 623 return 'interceptor($dispatchedType)'; | 624 return 'interceptor($dispatchedType)'; |
| 624 } | 625 } |
| 625 | 626 |
| 626 String toStructuredString() { | 627 String toStructuredText() { |
| 627 return 'InterceptorConstant(${dispatchedType.getStringAsDeclared("o")})'; | 628 return 'InterceptorConstant(${dispatchedType.getStringAsDeclared("o")})'; |
| 628 } | 629 } |
| 629 } | 630 } |
| 630 | 631 |
| 631 class SyntheticConstantValue extends ConstantValue { | 632 class SyntheticConstantValue extends ConstantValue { |
| 632 final payload; | 633 final payload; |
| 633 final kind; | 634 final kind; |
| 634 | 635 |
| 635 SyntheticConstantValue(this.kind, this.payload); | 636 SyntheticConstantValue(this.kind, this.payload); |
| 636 | 637 |
| 637 bool get isDummy => true; | 638 bool get isDummy => true; |
| 638 | 639 |
| 639 bool operator ==(other) { | 640 bool operator ==(other) { |
| 640 return other is SyntheticConstantValue && payload == other.payload; | 641 return other is SyntheticConstantValue && payload == other.payload; |
| 641 } | 642 } |
| 642 | 643 |
| 643 get hashCode => payload.hashCode * 17 + kind.hashCode; | 644 get hashCode => payload.hashCode * 17 + kind.hashCode; |
| 644 | 645 |
| 645 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 646 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 646 | 647 |
| 647 accept(ConstantValueVisitor visitor, arg) { | 648 accept(ConstantValueVisitor visitor, arg) { |
| 648 return visitor.visitSynthetic(this, arg); | 649 return visitor.visitSynthetic(this, arg); |
| 649 } | 650 } |
| 650 | 651 |
| 651 DartType getType(CoreTypes types) => const DynamicType(); | 652 DartType getType(CoreTypes types) => const DynamicType(); |
| 652 | 653 |
| 653 String unparse() => 'synthetic($kind, $payload)'; | 654 String toDartText() => 'synthetic($kind, $payload)'; |
| 654 | 655 |
| 655 String toStructuredString() => 'SyntheticConstant($kind, $payload)'; | 656 String toStructuredText() => 'SyntheticConstant($kind, $payload)'; |
| 656 } | 657 } |
| 657 | 658 |
| 658 class ConstructedConstantValue extends ObjectConstantValue { | 659 class ConstructedConstantValue extends ObjectConstantValue { |
| 659 final Map<FieldElement, ConstantValue> fields; | 660 final Map<FieldElement, ConstantValue> fields; |
| 660 final int hashCode; | 661 final int hashCode; |
| 661 | 662 |
| 662 ConstructedConstantValue( | 663 ConstructedConstantValue( |
| 663 InterfaceType type, Map<FieldElement, ConstantValue> fields) | 664 InterfaceType type, Map<FieldElement, ConstantValue> fields) |
| 664 : this.fields = fields, | 665 : this.fields = fields, |
| 665 hashCode = Hashing.mapHash(fields, Hashing.objectHash(type)), | 666 hashCode = Hashing.mapHash(fields, Hashing.objectHash(type)), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 682 } | 683 } |
| 683 return true; | 684 return true; |
| 684 } | 685 } |
| 685 | 686 |
| 686 List<ConstantValue> getDependencies() => fields.values.toList(); | 687 List<ConstantValue> getDependencies() => fields.values.toList(); |
| 687 | 688 |
| 688 accept(ConstantValueVisitor visitor, arg) { | 689 accept(ConstantValueVisitor visitor, arg) { |
| 689 return visitor.visitConstructed(this, arg); | 690 return visitor.visitConstructed(this, arg); |
| 690 } | 691 } |
| 691 | 692 |
| 692 String unparse() { | 693 String toDartText() { |
| 693 StringBuffer sb = new StringBuffer(); | 694 StringBuffer sb = new StringBuffer(); |
| 694 sb.write(type.name); | 695 sb.write(type.name); |
| 695 _unparseTypeArguments(sb); | 696 _unparseTypeArguments(sb); |
| 696 sb.write('('); | 697 sb.write('('); |
| 697 int i = 0; | 698 int i = 0; |
| 698 fields.forEach((FieldElement field, ConstantValue value) { | 699 fields.forEach((FieldElement field, ConstantValue value) { |
| 699 if (i > 0) sb.write(','); | 700 if (i > 0) sb.write(','); |
| 700 sb.write(field.name); | 701 sb.write(field.name); |
| 701 sb.write('='); | 702 sb.write('='); |
| 702 sb.write(value.unparse()); | 703 sb.write(value.toDartText()); |
| 703 i++; | 704 i++; |
| 704 }); | 705 }); |
| 705 sb.write(')'); | 706 sb.write(')'); |
| 706 return sb.toString(); | 707 return sb.toString(); |
| 707 } | 708 } |
| 708 | 709 |
| 709 String toStructuredString() { | 710 String toStructuredText() { |
| 710 StringBuffer sb = new StringBuffer(); | 711 StringBuffer sb = new StringBuffer(); |
| 711 sb.write('ConstructedConstant('); | 712 sb.write('ConstructedConstant('); |
| 712 sb.write(type); | 713 sb.write(type); |
| 713 sb.write('('); | 714 sb.write('('); |
| 714 int i = 0; | 715 int i = 0; |
| 715 fields.forEach((FieldElement field, ConstantValue value) { | 716 fields.forEach((FieldElement field, ConstantValue value) { |
| 716 if (i > 0) sb.write(','); | 717 if (i > 0) sb.write(','); |
| 717 sb.write(field.name); | 718 sb.write(field.name); |
| 718 sb.write('='); | 719 sb.write('='); |
| 719 sb.write(value.toStructuredString()); | 720 sb.write(value.toStructuredText()); |
| 720 i++; | 721 i++; |
| 721 }); | 722 }); |
| 722 sb.write('))'); | 723 sb.write('))'); |
| 723 return sb.toString(); | 724 return sb.toString(); |
| 724 } | 725 } |
| 725 } | 726 } |
| 726 | 727 |
| 727 /// A reference to a constant in another output unit. | 728 /// A reference to a constant in another output unit. |
| 728 /// Used for referring to deferred constants. | 729 /// Used for referring to deferred constants. |
| 729 class DeferredConstantValue extends ConstantValue { | 730 class DeferredConstantValue extends ConstantValue { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 741 } | 742 } |
| 742 | 743 |
| 743 get hashCode => (referenced.hashCode * 17 + prefix.hashCode) & 0x3fffffff; | 744 get hashCode => (referenced.hashCode * 17 + prefix.hashCode) & 0x3fffffff; |
| 744 | 745 |
| 745 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; | 746 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; |
| 746 | 747 |
| 747 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); | 748 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); |
| 748 | 749 |
| 749 DartType getType(CoreTypes types) => referenced.getType(types); | 750 DartType getType(CoreTypes types) => referenced.getType(types); |
| 750 | 751 |
| 751 String unparse() => 'deferred(${referenced.unparse()})'; | 752 String toDartText() => 'deferred(${referenced.toDartText()})'; |
| 752 | 753 |
| 753 String toStructuredString() => 'DeferredConstant($referenced)'; | 754 String toStructuredText() => 'DeferredConstant($referenced)'; |
| 754 } | 755 } |
| 755 | 756 |
| 756 /// A constant value resulting from a non constant or erroneous constant | 757 /// A constant value resulting from a non constant or erroneous constant |
| 757 /// expression. | 758 /// expression. |
| 758 // TODO(johnniwinther): Expand this to contain the error kind. | 759 // TODO(johnniwinther): Expand this to contain the error kind. |
| 759 class NonConstantValue extends ConstantValue { | 760 class NonConstantValue extends ConstantValue { |
| 760 bool get isConstant => false; | 761 bool get isConstant => false; |
| 761 | 762 |
| 762 @override | 763 @override |
| 763 accept(ConstantValueVisitor visitor, arg) { | 764 accept(ConstantValueVisitor visitor, arg) { |
| 764 // TODO(johnniwinther): Should this be part of the visiting? | 765 // TODO(johnniwinther): Should this be part of the visiting? |
| 765 } | 766 } |
| 766 | 767 |
| 767 @override | 768 @override |
| 768 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 769 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
| 769 | 770 |
| 770 @override | 771 @override |
| 771 DartType getType(CoreTypes types) => const DynamicType(); | 772 DartType getType(CoreTypes types) => const DynamicType(); |
| 772 | 773 |
| 773 @override | 774 @override |
| 774 String toStructuredString() => 'NonConstant'; | 775 String toStructuredText() => 'NonConstant'; |
| 775 | 776 |
| 776 @override | 777 @override |
| 777 String unparse() => '>>non-constant<<'; | 778 String toDartText() => '>>non-constant<<'; |
| 778 } | 779 } |
| OLD | NEW |