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' |
11 show ClassElement, | 11 show ClassElement, Element, FieldElement, FunctionElement, PrefixElement; |
12 Element, | |
13 FieldElement, | |
14 FunctionElement, | |
15 PrefixElement; | |
16 import '../tree/tree.dart' hide unparse; | 12 import '../tree/tree.dart' hide unparse; |
17 import '../util/util.dart' show Hashing; | 13 import '../util/util.dart' show Hashing; |
18 | 14 |
19 abstract class ConstantValueVisitor<R, A> { | 15 abstract class ConstantValueVisitor<R, A> { |
20 const ConstantValueVisitor(); | 16 const ConstantValueVisitor(); |
21 | 17 |
22 R visitFunction(FunctionConstantValue constant, A arg); | 18 R visitFunction(FunctionConstantValue constant, A arg); |
23 R visitNull(NullConstantValue constant, A arg); | 19 R visitNull(NullConstantValue constant, A arg); |
24 R visitInt(IntConstantValue constant, A arg); | 20 R visitInt(IntConstantValue constant, A arg); |
25 R visitDouble(DoubleConstantValue constant, A arg); | 21 R visitDouble(DoubleConstantValue constant, A arg); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 /// For the synthetic constants, [DeferredConstantValue], | 78 /// For the synthetic constants, [DeferredConstantValue], |
83 /// [SyntheticConstantValue], [InterceptorConstantValue] the unparse is | 79 /// [SyntheticConstantValue], [InterceptorConstantValue] the unparse is |
84 /// descriptive only. | 80 /// descriptive only. |
85 String unparse(); | 81 String unparse(); |
86 | 82 |
87 /// Returns a structured representation of this constant suited for debugging. | 83 /// Returns a structured representation of this constant suited for debugging. |
88 String toStructuredString(); | 84 String toStructuredString(); |
89 | 85 |
90 String toString() { | 86 String toString() { |
91 assertDebugMode("Use Constant.unparse() or Constant.toStructuredString() " | 87 assertDebugMode("Use Constant.unparse() or Constant.toStructuredString() " |
92 "instead of Constant.toString()."); | 88 "instead of Constant.toString()."); |
93 return toStructuredString(); | 89 return toStructuredString(); |
94 } | 90 } |
95 } | 91 } |
96 | 92 |
97 class FunctionConstantValue extends ConstantValue { | 93 class FunctionConstantValue extends ConstantValue { |
98 FunctionElement element; | 94 FunctionElement element; |
99 | 95 |
100 FunctionConstantValue(this.element) { | 96 FunctionConstantValue(this.element) { |
101 assert(element.type != null); | 97 assert(element.type != null); |
102 } | 98 } |
103 | 99 |
104 bool get isFunction => true; | 100 bool get isFunction => true; |
105 | 101 |
106 bool operator ==(var other) { | 102 bool operator ==(var other) { |
107 if (other is !FunctionConstantValue) return false; | 103 if (other is! FunctionConstantValue) return false; |
108 return identical(other.element, element); | 104 return identical(other.element, element); |
109 } | 105 } |
110 | 106 |
111 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 107 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
112 | 108 |
113 DartString toDartString() { | 109 DartString toDartString() { |
114 return new DartString.literal(element.name); | 110 return new DartString.literal(element.name); |
115 } | 111 } |
116 | 112 |
117 DartType getType(CoreTypes types) => element.type; | 113 DartType getType(CoreTypes types) => element.type; |
(...skipping 16 matching lines...) Expand all Loading... |
134 } | 130 } |
135 | 131 |
136 abstract class PrimitiveConstantValue extends ConstantValue { | 132 abstract class PrimitiveConstantValue extends ConstantValue { |
137 get primitiveValue; | 133 get primitiveValue; |
138 | 134 |
139 const PrimitiveConstantValue(); | 135 const PrimitiveConstantValue(); |
140 | 136 |
141 bool get isPrimitive => true; | 137 bool get isPrimitive => true; |
142 | 138 |
143 bool operator ==(var other) { | 139 bool operator ==(var other) { |
144 if (other is !PrimitiveConstantValue) return false; | 140 if (other is! PrimitiveConstantValue) return false; |
145 PrimitiveConstantValue otherPrimitive = other; | 141 PrimitiveConstantValue otherPrimitive = other; |
146 // We use == instead of 'identical' so that DartStrings compare correctly. | 142 // We use == instead of 'identical' so that DartStrings compare correctly. |
147 return primitiveValue == otherPrimitive.primitiveValue; | 143 return primitiveValue == otherPrimitive.primitiveValue; |
148 } | 144 } |
149 | 145 |
150 int get hashCode => throw new UnsupportedError('PrimitiveConstant.hashCode'); | 146 int get hashCode => throw new UnsupportedError('PrimitiveConstant.hashCode'); |
151 | 147 |
152 // Primitive constants don't have dependencies. | 148 // Primitive constants don't have dependencies. |
153 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 149 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
154 | 150 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 num get primitiveValue; | 184 num get primitiveValue; |
189 | 185 |
190 bool get isNum => true; | 186 bool get isNum => true; |
191 } | 187 } |
192 | 188 |
193 class IntConstantValue extends NumConstantValue { | 189 class IntConstantValue extends NumConstantValue { |
194 final int primitiveValue; | 190 final int primitiveValue; |
195 | 191 |
196 factory IntConstantValue(int value) { | 192 factory IntConstantValue(int value) { |
197 switch (value) { | 193 switch (value) { |
198 case 0: return const IntConstantValue._internal(0); | 194 case 0: |
199 case 1: return const IntConstantValue._internal(1); | 195 return const IntConstantValue._internal(0); |
200 case 2: return const IntConstantValue._internal(2); | 196 case 1: |
201 case 3: return const IntConstantValue._internal(3); | 197 return const IntConstantValue._internal(1); |
202 case 4: return const IntConstantValue._internal(4); | 198 case 2: |
203 case 5: return const IntConstantValue._internal(5); | 199 return const IntConstantValue._internal(2); |
204 case 6: return const IntConstantValue._internal(6); | 200 case 3: |
205 case 7: return const IntConstantValue._internal(7); | 201 return const IntConstantValue._internal(3); |
206 case 8: return const IntConstantValue._internal(8); | 202 case 4: |
207 case 9: return const IntConstantValue._internal(9); | 203 return const IntConstantValue._internal(4); |
208 case 10: return const IntConstantValue._internal(10); | 204 case 5: |
209 case -1: return const IntConstantValue._internal(-1); | 205 return const IntConstantValue._internal(5); |
210 case -2: return const IntConstantValue._internal(-2); | 206 case 6: |
211 default: return new IntConstantValue._internal(value); | 207 return const IntConstantValue._internal(6); |
| 208 case 7: |
| 209 return const IntConstantValue._internal(7); |
| 210 case 8: |
| 211 return const IntConstantValue._internal(8); |
| 212 case 9: |
| 213 return const IntConstantValue._internal(9); |
| 214 case 10: |
| 215 return const IntConstantValue._internal(10); |
| 216 case -1: |
| 217 return const IntConstantValue._internal(-1); |
| 218 case -2: |
| 219 return const IntConstantValue._internal(-2); |
| 220 default: |
| 221 return new IntConstantValue._internal(value); |
212 } | 222 } |
213 } | 223 } |
214 | 224 |
215 const IntConstantValue._internal(this.primitiveValue); | 225 const IntConstantValue._internal(this.primitiveValue); |
216 | 226 |
217 bool get isInt => true; | 227 bool get isInt => true; |
218 | 228 |
219 bool isUInt31() => primitiveValue >= 0 && primitiveValue < (1 << 31); | 229 bool isUInt31() => primitiveValue >= 0 && primitiveValue < (1 << 31); |
220 | 230 |
221 bool isUInt32() => primitiveValue >= 0 && primitiveValue < (1 << 32); | 231 bool isUInt32() => primitiveValue >= 0 && primitiveValue < (1 << 32); |
222 | 232 |
223 bool isPositive() => primitiveValue >= 0; | 233 bool isPositive() => primitiveValue >= 0; |
224 | 234 |
225 bool get isZero => primitiveValue == 0; | 235 bool get isZero => primitiveValue == 0; |
226 | 236 |
227 bool get isOne => primitiveValue == 1; | 237 bool get isOne => primitiveValue == 1; |
228 | 238 |
229 DartType getType(CoreTypes types) => types.intType; | 239 DartType getType(CoreTypes types) => types.intType; |
230 | 240 |
231 // We have to override the equality operator so that ints and doubles are | 241 // We have to override the equality operator so that ints and doubles are |
232 // treated as separate constants. | 242 // treated as separate constants. |
233 // The is [:!IntConstant:] check at the beginning of the function makes sure | 243 // The is [:!IntConstant:] check at the beginning of the function makes sure |
234 // that we compare only equal to integer constants. | 244 // that we compare only equal to integer constants. |
235 bool operator ==(var other) { | 245 bool operator ==(var other) { |
236 if (other is !IntConstantValue) return false; | 246 if (other is! IntConstantValue) return false; |
237 IntConstantValue otherInt = other; | 247 IntConstantValue otherInt = other; |
238 return primitiveValue == otherInt.primitiveValue; | 248 return primitiveValue == otherInt.primitiveValue; |
239 } | 249 } |
240 | 250 |
241 int get hashCode => primitiveValue & Hashing.SMI_MASK; | 251 int get hashCode => primitiveValue & Hashing.SMI_MASK; |
242 | 252 |
243 DartString toDartString() { | 253 DartString toDartString() { |
244 return new DartString.literal(primitiveValue.toString()); | 254 return new DartString.literal(primitiveValue.toString()); |
245 } | 255 } |
246 | 256 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 291 |
282 bool get isOne => primitiveValue == 1.0; | 292 bool get isOne => primitiveValue == 1.0; |
283 | 293 |
284 bool get isPositiveInfinity => primitiveValue == double.INFINITY; | 294 bool get isPositiveInfinity => primitiveValue == double.INFINITY; |
285 | 295 |
286 bool get isNegativeInfinity => primitiveValue == -double.INFINITY; | 296 bool get isNegativeInfinity => primitiveValue == -double.INFINITY; |
287 | 297 |
288 DartType getType(CoreTypes types) => types.doubleType; | 298 DartType getType(CoreTypes types) => types.doubleType; |
289 | 299 |
290 bool operator ==(var other) { | 300 bool operator ==(var other) { |
291 if (other is !DoubleConstantValue) return false; | 301 if (other is! DoubleConstantValue) return false; |
292 DoubleConstantValue otherDouble = other; | 302 DoubleConstantValue otherDouble = other; |
293 double otherValue = otherDouble.primitiveValue; | 303 double otherValue = otherDouble.primitiveValue; |
294 if (primitiveValue == 0.0 && otherValue == 0.0) { | 304 if (primitiveValue == 0.0 && otherValue == 0.0) { |
295 return primitiveValue.isNegative == otherValue.isNegative; | 305 return primitiveValue.isNegative == otherValue.isNegative; |
296 } else if (primitiveValue.isNaN) { | 306 } else if (primitiveValue.isNaN) { |
297 return otherValue.isNaN; | 307 return otherValue.isNaN; |
298 } else { | 308 } else { |
299 return primitiveValue == otherValue; | 309 return primitiveValue == otherValue; |
300 } | 310 } |
301 } | 311 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 393 |
384 StringConstantValue.fromString(String value) | 394 StringConstantValue.fromString(String value) |
385 : this(new DartString.literal(value)); | 395 : this(new DartString.literal(value)); |
386 | 396 |
387 bool get isString => true; | 397 bool get isString => true; |
388 | 398 |
389 DartType getType(CoreTypes types) => types.stringType; | 399 DartType getType(CoreTypes types) => types.stringType; |
390 | 400 |
391 bool operator ==(var other) { | 401 bool operator ==(var other) { |
392 if (identical(this, other)) return true; | 402 if (identical(this, other)) return true; |
393 if (other is !StringConstantValue) return false; | 403 if (other is! StringConstantValue) return false; |
394 StringConstantValue otherString = other; | 404 StringConstantValue otherString = other; |
395 return hashCode == otherString.hashCode && | 405 return hashCode == otherString.hashCode && |
396 primitiveValue == otherString.primitiveValue; | 406 primitiveValue == otherString.primitiveValue; |
397 } | 407 } |
398 | 408 |
399 DartString toDartString() => primitiveValue; | 409 DartString toDartString() => primitiveValue; |
400 | 410 |
401 int get length => primitiveValue.length; | 411 int get length => primitiveValue.length; |
402 | 412 |
403 accept(ConstantValueVisitor visitor, arg) => visitor.visitString(this, arg); | 413 accept(ConstantValueVisitor visitor, arg) => visitor.visitString(this, arg); |
404 | 414 |
405 // TODO(johnniwinther): Ensure correct escaping. | 415 // TODO(johnniwinther): Ensure correct escaping. |
406 String unparse() => '"${primitiveValue.slowToString()}"'; | 416 String unparse() => '"${primitiveValue.slowToString()}"'; |
(...skipping 22 matching lines...) Expand all Loading... |
429 class TypeConstantValue extends ObjectConstantValue { | 439 class TypeConstantValue extends ObjectConstantValue { |
430 /// The user type that this constant represents. | 440 /// The user type that this constant represents. |
431 final DartType representedType; | 441 final DartType representedType; |
432 | 442 |
433 TypeConstantValue(this.representedType, InterfaceType type) : super(type); | 443 TypeConstantValue(this.representedType, InterfaceType type) : super(type); |
434 | 444 |
435 bool get isType => true; | 445 bool get isType => true; |
436 | 446 |
437 bool operator ==(other) { | 447 bool operator ==(other) { |
438 return other is TypeConstantValue && | 448 return other is TypeConstantValue && |
439 representedType == other.representedType; | 449 representedType == other.representedType; |
440 } | 450 } |
441 | 451 |
442 int get hashCode => representedType.hashCode * 13; | 452 int get hashCode => representedType.hashCode * 13; |
443 | 453 |
444 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 454 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
445 | 455 |
446 accept(ConstantValueVisitor visitor, arg) => visitor.visitType(this, arg); | 456 accept(ConstantValueVisitor visitor, arg) => visitor.visitType(this, arg); |
447 | 457 |
448 String unparse() => '$representedType'; | 458 String unparse() => '$representedType'; |
449 | 459 |
450 String toStructuredString() => 'TypeConstant(${representedType})'; | 460 String toStructuredString() => 'TypeConstant(${representedType})'; |
451 } | 461 } |
452 | 462 |
453 class ListConstantValue extends ObjectConstantValue { | 463 class ListConstantValue extends ObjectConstantValue { |
454 final List<ConstantValue> entries; | 464 final List<ConstantValue> entries; |
455 final int hashCode; | 465 final int hashCode; |
456 | 466 |
457 ListConstantValue(InterfaceType type, List<ConstantValue> entries) | 467 ListConstantValue(InterfaceType type, List<ConstantValue> entries) |
458 : this.entries = entries, | 468 : this.entries = entries, |
459 hashCode = Hashing.listHash(entries, Hashing.objectHash(type)), | 469 hashCode = Hashing.listHash(entries, Hashing.objectHash(type)), |
460 super(type); | 470 super(type); |
461 | 471 |
462 bool get isList => true; | 472 bool get isList => true; |
463 | 473 |
464 bool operator ==(var other) { | 474 bool operator ==(var other) { |
465 if (identical(this, other)) return true; | 475 if (identical(this, other)) return true; |
466 if (other is !ListConstantValue) return false; | 476 if (other is! ListConstantValue) return false; |
467 ListConstantValue otherList = other; | 477 ListConstantValue otherList = other; |
468 if (hashCode != otherList.hashCode) return false; | 478 if (hashCode != otherList.hashCode) return false; |
469 if (type != otherList.type) return false; | 479 if (type != otherList.type) return false; |
470 if (entries.length != otherList.entries.length) return false; | 480 if (entries.length != otherList.entries.length) return false; |
471 for (int i = 0; i < entries.length; i++) { | 481 for (int i = 0; i < entries.length; i++) { |
472 if (entries[i] != otherList.entries[i]) return false; | 482 if (entries[i] != otherList.entries[i]) return false; |
473 } | 483 } |
474 return true; | 484 return true; |
475 } | 485 } |
476 | 486 |
477 List<ConstantValue> getDependencies() => entries; | 487 List<ConstantValue> getDependencies() => entries; |
478 | 488 |
479 int get length => entries.length; | 489 int get length => entries.length; |
480 | 490 |
481 accept(ConstantValueVisitor visitor, arg) => visitor.visitList(this, arg); | 491 accept(ConstantValueVisitor visitor, arg) => visitor.visitList(this, arg); |
482 | 492 |
483 String unparse() { | 493 String unparse() { |
484 StringBuffer sb = new StringBuffer(); | 494 StringBuffer sb = new StringBuffer(); |
485 _unparseTypeArguments(sb); | 495 _unparseTypeArguments(sb); |
486 sb.write('['); | 496 sb.write('['); |
487 for (int i = 0 ; i < length ; i++) { | 497 for (int i = 0; i < length; i++) { |
488 if (i > 0) sb.write(','); | 498 if (i > 0) sb.write(','); |
489 sb.write(entries[i].unparse()); | 499 sb.write(entries[i].unparse()); |
490 } | 500 } |
491 sb.write(']'); | 501 sb.write(']'); |
492 return sb.toString(); | 502 return sb.toString(); |
493 } | 503 } |
494 | 504 |
495 String toStructuredString() { | 505 String toStructuredString() { |
496 StringBuffer sb = new StringBuffer(); | 506 StringBuffer sb = new StringBuffer(); |
497 sb.write('ListConstant('); | 507 sb.write('ListConstant('); |
498 _unparseTypeArguments(sb); | 508 _unparseTypeArguments(sb); |
499 sb.write('['); | 509 sb.write('['); |
500 for (int i = 0 ; i < length ; i++) { | 510 for (int i = 0; i < length; i++) { |
501 if (i > 0) sb.write(', '); | 511 if (i > 0) sb.write(', '); |
502 sb.write(entries[i].toStructuredString()); | 512 sb.write(entries[i].toStructuredString()); |
503 } | 513 } |
504 sb.write('])'); | 514 sb.write('])'); |
505 return sb.toString(); | 515 return sb.toString(); |
506 } | 516 } |
507 } | 517 } |
508 | 518 |
509 class MapConstantValue extends ObjectConstantValue { | 519 class MapConstantValue extends ObjectConstantValue { |
510 final List<ConstantValue> keys; | 520 final List<ConstantValue> keys; |
511 final List<ConstantValue> values; | 521 final List<ConstantValue> values; |
512 final int hashCode; | 522 final int hashCode; |
513 Map<ConstantValue, ConstantValue> _lookupMap; | 523 Map<ConstantValue, ConstantValue> _lookupMap; |
514 | 524 |
515 MapConstantValue(InterfaceType type, | 525 MapConstantValue( |
516 List<ConstantValue> keys, | 526 InterfaceType type, List<ConstantValue> keys, List<ConstantValue> values) |
517 List<ConstantValue> values) | |
518 : this.keys = keys, | 527 : this.keys = keys, |
519 this.values = values, | 528 this.values = values, |
520 this.hashCode = Hashing.listHash(values, | 529 this.hashCode = Hashing.listHash( |
521 Hashing.listHash(keys, | 530 values, Hashing.listHash(keys, Hashing.objectHash(type))), |
522 Hashing.objectHash(type))), | |
523 super(type) { | 531 super(type) { |
524 assert(keys.length == values.length); | 532 assert(keys.length == values.length); |
525 } | 533 } |
526 | 534 |
527 bool get isMap => true; | 535 bool get isMap => true; |
528 | 536 |
529 bool operator ==(var other) { | 537 bool operator ==(var other) { |
530 if (identical(this, other)) return true; | 538 if (identical(this, other)) return true; |
531 if (other is !MapConstantValue) return false; | 539 if (other is! MapConstantValue) return false; |
532 MapConstantValue otherMap = other; | 540 MapConstantValue otherMap = other; |
533 if (hashCode != otherMap.hashCode) return false; | 541 if (hashCode != otherMap.hashCode) return false; |
534 if (type != other.type) return false; | 542 if (type != other.type) return false; |
535 if (length != other.length) return false; | 543 if (length != other.length) return false; |
536 for (int i = 0; i < length; i++) { | 544 for (int i = 0; i < length; i++) { |
537 if (keys[i] != otherMap.keys[i]) return false; | 545 if (keys[i] != otherMap.keys[i]) return false; |
538 if (values[i] != otherMap.values[i]) return false; | 546 if (values[i] != otherMap.values[i]) return false; |
539 } | 547 } |
540 return true; | 548 return true; |
541 } | 549 } |
(...skipping 12 matching lines...) Expand all Loading... |
554 new Map<ConstantValue, ConstantValue>.fromIterables(keys, values); | 562 new Map<ConstantValue, ConstantValue>.fromIterables(keys, values); |
555 return lookupMap[key]; | 563 return lookupMap[key]; |
556 } | 564 } |
557 | 565 |
558 accept(ConstantValueVisitor visitor, arg) => visitor.visitMap(this, arg); | 566 accept(ConstantValueVisitor visitor, arg) => visitor.visitMap(this, arg); |
559 | 567 |
560 String unparse() { | 568 String unparse() { |
561 StringBuffer sb = new StringBuffer(); | 569 StringBuffer sb = new StringBuffer(); |
562 _unparseTypeArguments(sb); | 570 _unparseTypeArguments(sb); |
563 sb.write('{'); | 571 sb.write('{'); |
564 for (int i = 0 ; i < length ; i++) { | 572 for (int i = 0; i < length; i++) { |
565 if (i > 0) sb.write(','); | 573 if (i > 0) sb.write(','); |
566 sb.write(keys[i].unparse()); | 574 sb.write(keys[i].unparse()); |
567 sb.write(':'); | 575 sb.write(':'); |
568 sb.write(values[i].unparse()); | 576 sb.write(values[i].unparse()); |
569 } | 577 } |
570 sb.write('}'); | 578 sb.write('}'); |
571 return sb.toString(); | 579 return sb.toString(); |
572 } | 580 } |
573 | 581 |
574 String toStructuredString() { | 582 String toStructuredString() { |
(...skipping 15 matching lines...) Expand all Loading... |
590 class InterceptorConstantValue extends ConstantValue { | 598 class InterceptorConstantValue extends ConstantValue { |
591 /// The type for which this interceptor holds the methods. The constant | 599 /// The type for which this interceptor holds the methods. The constant |
592 /// is a dispatch table for this type. | 600 /// is a dispatch table for this type. |
593 final DartType dispatchedType; | 601 final DartType dispatchedType; |
594 | 602 |
595 InterceptorConstantValue(this.dispatchedType); | 603 InterceptorConstantValue(this.dispatchedType); |
596 | 604 |
597 bool get isInterceptor => true; | 605 bool get isInterceptor => true; |
598 | 606 |
599 bool operator ==(other) { | 607 bool operator ==(other) { |
600 return other is InterceptorConstantValue | 608 return other is InterceptorConstantValue && |
601 && dispatchedType == other.dispatchedType; | 609 dispatchedType == other.dispatchedType; |
602 } | 610 } |
603 | 611 |
604 int get hashCode => dispatchedType.hashCode * 43; | 612 int get hashCode => dispatchedType.hashCode * 43; |
605 | 613 |
606 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 614 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
607 | 615 |
608 accept(ConstantValueVisitor visitor, arg) { | 616 accept(ConstantValueVisitor visitor, arg) { |
609 return visitor.visitInterceptor(this, arg); | 617 return visitor.visitInterceptor(this, arg); |
610 } | 618 } |
611 | 619 |
(...skipping 10 matching lines...) Expand all Loading... |
622 | 630 |
623 class SyntheticConstantValue extends ConstantValue { | 631 class SyntheticConstantValue extends ConstantValue { |
624 final payload; | 632 final payload; |
625 final kind; | 633 final kind; |
626 | 634 |
627 SyntheticConstantValue(this.kind, this.payload); | 635 SyntheticConstantValue(this.kind, this.payload); |
628 | 636 |
629 bool get isDummy => true; | 637 bool get isDummy => true; |
630 | 638 |
631 bool operator ==(other) { | 639 bool operator ==(other) { |
632 return other is SyntheticConstantValue | 640 return other is SyntheticConstantValue && payload == other.payload; |
633 && payload == other.payload; | |
634 } | 641 } |
635 | 642 |
636 get hashCode => payload.hashCode * 17 + kind.hashCode; | 643 get hashCode => payload.hashCode * 17 + kind.hashCode; |
637 | 644 |
638 List<ConstantValue> getDependencies() => const <ConstantValue>[]; | 645 List<ConstantValue> getDependencies() => const <ConstantValue>[]; |
639 | 646 |
640 accept(ConstantValueVisitor visitor, arg) { | 647 accept(ConstantValueVisitor visitor, arg) { |
641 return visitor.visitSynthetic(this, arg); | 648 return visitor.visitSynthetic(this, arg); |
642 } | 649 } |
643 | 650 |
644 DartType getType(CoreTypes types) => const DynamicType(); | 651 DartType getType(CoreTypes types) => const DynamicType(); |
645 | 652 |
646 String unparse() => 'synthetic($kind, $payload)'; | 653 String unparse() => 'synthetic($kind, $payload)'; |
647 | 654 |
648 String toStructuredString() => 'SyntheticConstant($kind, $payload)'; | 655 String toStructuredString() => 'SyntheticConstant($kind, $payload)'; |
649 } | 656 } |
650 | 657 |
651 class ConstructedConstantValue extends ObjectConstantValue { | 658 class ConstructedConstantValue extends ObjectConstantValue { |
652 final Map<FieldElement, ConstantValue> fields; | 659 final Map<FieldElement, ConstantValue> fields; |
653 final int hashCode; | 660 final int hashCode; |
654 | 661 |
655 ConstructedConstantValue(InterfaceType type, | 662 ConstructedConstantValue( |
656 Map<FieldElement, ConstantValue> fields) | 663 InterfaceType type, Map<FieldElement, ConstantValue> fields) |
657 : this.fields = fields, | 664 : this.fields = fields, |
658 hashCode = Hashing.mapHash(fields, Hashing.objectHash(type)), | 665 hashCode = Hashing.mapHash(fields, Hashing.objectHash(type)), |
659 super(type) { | 666 super(type) { |
660 assert(type != null); | 667 assert(type != null); |
661 assert(!fields.containsValue(null)); | 668 assert(!fields.containsValue(null)); |
662 } | 669 } |
663 | 670 |
664 bool get isConstructedObject => true; | 671 bool get isConstructedObject => true; |
665 | 672 |
666 bool operator ==(var otherVar) { | 673 bool operator ==(var otherVar) { |
667 if (identical(this, otherVar)) return true; | 674 if (identical(this, otherVar)) return true; |
668 if (otherVar is !ConstructedConstantValue) return false; | 675 if (otherVar is! ConstructedConstantValue) return false; |
669 ConstructedConstantValue other = otherVar; | 676 ConstructedConstantValue other = otherVar; |
670 if (hashCode != other.hashCode) return false; | 677 if (hashCode != other.hashCode) return false; |
671 if (type != other.type) return false; | 678 if (type != other.type) return false; |
672 if (fields.length != other.fields.length) return false; | 679 if (fields.length != other.fields.length) return false; |
673 for (FieldElement field in fields.keys) { | 680 for (FieldElement field in fields.keys) { |
674 if (fields[field] != other.fields[field]) return false; | 681 if (fields[field] != other.fields[field]) return false; |
675 } | 682 } |
676 return true; | 683 return true; |
677 } | 684 } |
678 | 685 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 /// Used for referring to deferred constants. | 728 /// Used for referring to deferred constants. |
722 class DeferredConstantValue extends ConstantValue { | 729 class DeferredConstantValue extends ConstantValue { |
723 DeferredConstantValue(this.referenced, this.prefix); | 730 DeferredConstantValue(this.referenced, this.prefix); |
724 | 731 |
725 final ConstantValue referenced; | 732 final ConstantValue referenced; |
726 final PrefixElement prefix; | 733 final PrefixElement prefix; |
727 | 734 |
728 bool get isReference => true; | 735 bool get isReference => true; |
729 | 736 |
730 bool operator ==(other) { | 737 bool operator ==(other) { |
731 return other is DeferredConstantValue | 738 return other is DeferredConstantValue && |
732 && referenced == other.referenced | 739 referenced == other.referenced && |
733 && prefix == other.prefix; | 740 prefix == other.prefix; |
734 } | 741 } |
735 | 742 |
736 get hashCode => (referenced.hashCode * 17 + prefix.hashCode) & 0x3fffffff; | 743 get hashCode => (referenced.hashCode * 17 + prefix.hashCode) & 0x3fffffff; |
737 | 744 |
738 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; | 745 List<ConstantValue> getDependencies() => <ConstantValue>[referenced]; |
739 | 746 |
740 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); | 747 accept(ConstantValueVisitor visitor, arg) => visitor.visitDeferred(this, arg); |
741 | 748 |
742 DartType getType(CoreTypes types) => referenced.getType(types); | 749 DartType getType(CoreTypes types) => referenced.getType(types); |
743 | 750 |
(...skipping 18 matching lines...) Expand all Loading... |
762 | 769 |
763 @override | 770 @override |
764 DartType getType(CoreTypes types) => const DynamicType(); | 771 DartType getType(CoreTypes types) => const DynamicType(); |
765 | 772 |
766 @override | 773 @override |
767 String toStructuredString() => 'NonConstant'; | 774 String toStructuredString() => 'NonConstant'; |
768 | 775 |
769 @override | 776 @override |
770 String unparse() => '>>non-constant<<'; | 777 String unparse() => '>>non-constant<<'; |
771 } | 778 } |
OLD | NEW |