| 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); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 339 |
| 340 accept(ConstantVisitor visitor) => visitor.visitType(this); | 340 accept(ConstantVisitor visitor) => visitor.visitType(this); |
| 341 } | 341 } |
| 342 | 342 |
| 343 class ListConstant extends ObjectConstant { | 343 class ListConstant extends ObjectConstant { |
| 344 final List<Constant> entries; | 344 final List<Constant> entries; |
| 345 final int hashCode; | 345 final int hashCode; |
| 346 | 346 |
| 347 ListConstant(DartType type, List<Constant> entries) | 347 ListConstant(DartType type, List<Constant> entries) |
| 348 : this.entries = entries, | 348 : this.entries = entries, |
| 349 hashCode = _computeHash(entries), | 349 hashCode = _computeHash(type, entries), |
| 350 super(type); | 350 super(type); |
| 351 bool isList() => true; | 351 bool isList() => true; |
| 352 | 352 |
| 353 static int _computeHash(List<Constant> entries) { | 353 static int _computeHash(DartType type, List<Constant> entries) { |
| 354 // TODO(floitsch): create a better hash. | 354 // TODO(floitsch): create a better hash. |
| 355 int hash = 0; | 355 int hash = 7; |
| 356 for (Constant input in entries) hash ^= input.hashCode; | 356 for (Constant input in entries) { |
| 357 hash ^= input.hashCode; |
| 358 } |
| 359 hash ^= type.hashCode; |
| 357 return hash; | 360 return hash; |
| 358 } | 361 } |
| 359 | 362 |
| 360 bool operator ==(var other) { | 363 bool operator ==(var other) { |
| 361 if (other is !ListConstant) return false; | 364 if (other is !ListConstant) return false; |
| 362 ListConstant otherList = other; | 365 ListConstant otherList = other; |
| 363 if (hashCode != otherList.hashCode) return false; | 366 if (hashCode != otherList.hashCode) return false; |
| 364 // TODO(floitsch): verify that the generic types are the same. | 367 if (type != otherList.type) return false; |
| 365 if (entries.length != otherList.entries.length) return false; | 368 if (entries.length != otherList.entries.length) return false; |
| 366 for (int i = 0; i < entries.length; i++) { | 369 for (int i = 0; i < entries.length; i++) { |
| 367 if (entries[i] != otherList.entries[i]) return false; | 370 if (entries[i] != otherList.entries[i]) return false; |
| 368 } | 371 } |
| 369 return true; | 372 return true; |
| 370 } | 373 } |
| 371 | 374 |
| 372 List<Constant> getDependencies() => entries; | 375 List<Constant> getDependencies() => entries; |
| 373 | 376 |
| 374 int get length => entries.length; | 377 int get length => entries.length; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 393 static const SourceString KEYS_NAME = const SourceString("_keys"); | 396 static const SourceString KEYS_NAME = const SourceString("_keys"); |
| 394 static const SourceString PROTO_VALUE = const SourceString("_protoValue"); | 397 static const SourceString PROTO_VALUE = const SourceString("_protoValue"); |
| 395 | 398 |
| 396 final ListConstant keys; | 399 final ListConstant keys; |
| 397 final List<Constant> values; | 400 final List<Constant> values; |
| 398 final Constant protoValue; | 401 final Constant protoValue; |
| 399 final int hashCode; | 402 final int hashCode; |
| 400 | 403 |
| 401 MapConstant(DartType type, this.keys, List<Constant> values, this.protoValue) | 404 MapConstant(DartType type, this.keys, List<Constant> values, this.protoValue) |
| 402 : this.values = values, | 405 : this.values = values, |
| 403 this.hashCode = computeHash(values), | 406 this.hashCode = computeHash(type, values), |
| 404 super(type); | 407 super(type); |
| 405 bool isMap() => true; | 408 bool isMap() => true; |
| 406 | 409 |
| 407 static int computeHash(List<Constant> values) { | 410 static int computeHash(DartType type, List<Constant> values) { |
| 408 // TODO(floitsch): create a better hash. | 411 // TODO(floitsch): create a better hash. |
| 409 int hash = 0; | 412 int hash = 0; |
| 410 for (Constant value in values) hash ^= value.hashCode; | 413 for (Constant value in values) { |
| 414 hash ^= value.hashCode; |
| 415 } |
| 416 hash ^= type.hashCode; |
| 411 return hash; | 417 return hash; |
| 412 } | 418 } |
| 413 | 419 |
| 414 bool operator ==(var other) { | 420 bool operator ==(var other) { |
| 415 if (other is !MapConstant) return false; | 421 if (other is !MapConstant) return false; |
| 416 MapConstant otherMap = other; | 422 MapConstant otherMap = other; |
| 417 if (hashCode != otherMap.hashCode) return false; | 423 if (hashCode != otherMap.hashCode) return false; |
| 418 // TODO(floitsch): verify that the generic types are the same. | 424 if (type != other.type) return false; |
| 419 if (keys != otherMap.keys) return false; | 425 if (keys != otherMap.keys) return false; |
| 420 for (int i = 0; i < values.length; i++) { | 426 for (int i = 0; i < values.length; i++) { |
| 421 if (values[i] != otherMap.values[i]) return false; | 427 if (values[i] != otherMap.values[i]) return false; |
| 422 } | 428 } |
| 423 return true; | 429 return true; |
| 424 } | 430 } |
| 425 | 431 |
| 426 List<Constant> getDependencies() { | 432 List<Constant> getDependencies() { |
| 427 List<Constant> result = <Constant>[keys]; | 433 List<Constant> result = <Constant>[keys]; |
| 428 result.addAll(values); | 434 result.addAll(values); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 assert(type != null); | 474 assert(type != null); |
| 469 } | 475 } |
| 470 bool isConstructedObject() => true; | 476 bool isConstructedObject() => true; |
| 471 | 477 |
| 472 static int computeHash(DartType type, List<Constant> fields) { | 478 static int computeHash(DartType type, List<Constant> fields) { |
| 473 // TODO(floitsch): create a better hash. | 479 // TODO(floitsch): create a better hash. |
| 474 int hash = 0; | 480 int hash = 0; |
| 475 for (Constant field in fields) { | 481 for (Constant field in fields) { |
| 476 hash ^= field.hashCode; | 482 hash ^= field.hashCode; |
| 477 } | 483 } |
| 478 hash ^= type.element.hashCode; | 484 hash ^= type.hashCode; |
| 479 return hash; | 485 return hash; |
| 480 } | 486 } |
| 481 | 487 |
| 482 bool operator ==(var otherVar) { | 488 bool operator ==(var otherVar) { |
| 483 if (otherVar is !ConstructedConstant) return false; | 489 if (otherVar is !ConstructedConstant) return false; |
| 484 ConstructedConstant other = otherVar; | 490 ConstructedConstant other = otherVar; |
| 485 if (hashCode != other.hashCode) return false; | 491 if (hashCode != other.hashCode) return false; |
| 486 // TODO(floitsch): verify that the (generic) types are the same. | 492 if (type != other.type) return false; |
| 487 if (type.element != other.type.element) return false; | |
| 488 if (fields.length != other.fields.length) return false; | 493 if (fields.length != other.fields.length) return false; |
| 489 for (int i = 0; i < fields.length; i++) { | 494 for (int i = 0; i < fields.length; i++) { |
| 490 if (fields[i] != other.fields[i]) return false; | 495 if (fields[i] != other.fields[i]) return false; |
| 491 } | 496 } |
| 492 return true; | 497 return true; |
| 493 } | 498 } |
| 494 | 499 |
| 495 List<Constant> getDependencies() => fields; | 500 List<Constant> getDependencies() => fields; |
| 496 | 501 |
| 497 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); | 502 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); |
| 498 } | 503 } |
| OLD | NEW |