Chromium Code Reviews| 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 visitFunction(FunctionConstant constant); | 8 R visitFunction(FunctionConstant constant); |
| 9 R visitNull(NullConstant constant); | 9 R visitNull(NullConstant constant); |
| 10 R visitInt(IntConstant constant); | 10 R visitInt(IntConstant constant); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 bool operator ==(var other) { | 288 bool operator ==(var other) { |
| 289 if (other is !StringConstant) return false; | 289 if (other is !StringConstant) return false; |
| 290 StringConstant otherString = other; | 290 StringConstant otherString = other; |
| 291 return (hashCode == otherString.hashCode) && (value == otherString.value); | 291 return (hashCode == otherString.hashCode) && (value == otherString.value); |
| 292 } | 292 } |
| 293 | 293 |
| 294 DartString toDartString() => value; | 294 DartString toDartString() => value; |
| 295 int get length => value.length; | 295 int get length => value.length; |
| 296 | 296 |
| 297 accept(ConstantVisitor visitor) => visitor.visitString(this); | 297 accept(ConstantVisitor visitor) => visitor.visitString(this); |
| 298 | |
| 299 String toString() { | |
|
ahe
2013/09/30 11:05:26
Nice with toString implementation, but I suggest t
Johnni Winther
2013/10/01 11:21:48
Done.
| |
| 300 return "'" + value.slowToString() + "'"; | |
|
ahe
2013/09/30 11:05:26
Use string interpolation, please.
Johnni Winther
2013/10/01 11:21:48
Done.
| |
| 301 } | |
| 298 } | 302 } |
| 299 | 303 |
| 300 abstract class ObjectConstant extends Constant { | 304 abstract class ObjectConstant extends Constant { |
| 301 final DartType type; | 305 final DartType type; |
| 302 | 306 |
| 303 ObjectConstant(this.type); | 307 ObjectConstant(this.type); |
| 304 bool isObject() => true; | 308 bool isObject() => true; |
| 305 | 309 |
| 306 DartType computeType(Compiler compiler) => type; | 310 DartType computeType(Compiler compiler) => type; |
| 307 } | 311 } |
| 308 | 312 |
| 309 class TypeConstant extends ObjectConstant { | 313 class TypeConstant extends ObjectConstant { |
| 310 /// The user type that this constant represents. | 314 /// The user type that this constant represents. |
| 311 final DartType representedType; | 315 final DartType representedType; |
| 312 | 316 |
| 313 TypeConstant(this.representedType, type) : super(type); | 317 TypeConstant(this.representedType, type) : super(type); |
| 314 | 318 |
| 315 bool isType() => true; | 319 bool isType() => true; |
| 316 | 320 |
| 317 bool operator ==(other) { | 321 bool operator ==(other) { |
| 318 return other is TypeConstant && representedType == other.representedType; | 322 return other is TypeConstant && representedType == other.representedType; |
| 319 } | 323 } |
| 320 | 324 |
| 321 int get hashCode => representedType.hashCode * 13; | 325 int get hashCode => representedType.hashCode * 13; |
| 322 | 326 |
| 323 List<Constant> getDependencies() => const <Constant>[]; | 327 List<Constant> getDependencies() => const <Constant>[]; |
| 324 | 328 |
| 325 accept(ConstantVisitor visitor) => visitor.visitType(this); | 329 accept(ConstantVisitor visitor) => visitor.visitType(this); |
| 330 | |
| 331 String toString() => '$representedType'; | |
| 326 } | 332 } |
| 327 | 333 |
| 328 class ListConstant extends ObjectConstant { | 334 class ListConstant extends ObjectConstant { |
| 329 final List<Constant> entries; | 335 final List<Constant> entries; |
| 330 final int hashCode; | 336 final int hashCode; |
| 331 | 337 |
| 332 ListConstant(DartType type, List<Constant> entries) | 338 ListConstant(DartType type, List<Constant> entries) |
| 333 : this.entries = entries, | 339 : this.entries = entries, |
| 334 hashCode = _computeHash(type, entries), | 340 hashCode = _computeHash(type, entries), |
| 335 super(type); | 341 super(type); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 355 if (entries[i] != otherList.entries[i]) return false; | 361 if (entries[i] != otherList.entries[i]) return false; |
| 356 } | 362 } |
| 357 return true; | 363 return true; |
| 358 } | 364 } |
| 359 | 365 |
| 360 List<Constant> getDependencies() => entries; | 366 List<Constant> getDependencies() => entries; |
| 361 | 367 |
| 362 int get length => entries.length; | 368 int get length => entries.length; |
| 363 | 369 |
| 364 accept(ConstantVisitor visitor) => visitor.visitList(this); | 370 accept(ConstantVisitor visitor) => visitor.visitList(this); |
| 371 | |
| 372 String toString() { | |
| 373 StringBuffer sb = new StringBuffer(); | |
| 374 sb.write('['); | |
| 375 for (int i = 0 ; i < entries.length ; i++) { | |
| 376 if (i > 0) sb.write(','); | |
| 377 sb.write(entries[i]); | |
| 378 } | |
| 379 sb.write(']'); | |
| 380 return sb.toString(); | |
| 381 } | |
| 365 } | 382 } |
| 366 | 383 |
| 367 class MapConstant extends ObjectConstant { | 384 class MapConstant extends ObjectConstant { |
| 368 /** | 385 /** |
| 369 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript | 386 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript |
| 370 * object. It would change the prototype chain. | 387 * object. It would change the prototype chain. |
| 371 */ | 388 */ |
| 372 static const LiteralDartString PROTO_PROPERTY = | 389 static const LiteralDartString PROTO_PROPERTY = |
| 373 const LiteralDartString("__proto__"); | 390 const LiteralDartString("__proto__"); |
| 374 | 391 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 // for the keys. | 447 // for the keys. |
| 431 result.addAll(keys.entries); | 448 result.addAll(keys.entries); |
| 432 } | 449 } |
| 433 result.addAll(values); | 450 result.addAll(values); |
| 434 return result; | 451 return result; |
| 435 } | 452 } |
| 436 | 453 |
| 437 int get length => keys.length; | 454 int get length => keys.length; |
| 438 | 455 |
| 439 accept(ConstantVisitor visitor) => visitor.visitMap(this); | 456 accept(ConstantVisitor visitor) => visitor.visitMap(this); |
| 457 | |
| 458 String toString() { | |
| 459 StringBuffer sb = new StringBuffer(); | |
| 460 sb.write('{'); | |
| 461 for (int i = 0 ; i < keys.entries.length ; i++) { | |
| 462 if (i > 0) sb.write(','); | |
| 463 sb.write(keys.entries[i]); | |
| 464 sb.write(':'); | |
| 465 sb.write(values[i]); | |
| 466 } | |
| 467 sb.write('}'); | |
| 468 return sb.toString(); | |
| 469 } | |
| 440 } | 470 } |
| 441 | 471 |
| 442 class InterceptorConstant extends Constant { | 472 class InterceptorConstant extends Constant { |
| 443 /// The type for which this interceptor holds the methods. The constant | 473 /// The type for which this interceptor holds the methods. The constant |
| 444 /// is a dispatch table for this type. | 474 /// is a dispatch table for this type. |
| 445 final DartType dispatchedType; | 475 final DartType dispatchedType; |
| 446 | 476 |
| 447 InterceptorConstant(this.dispatchedType); | 477 InterceptorConstant(this.dispatchedType); |
| 448 | 478 |
| 449 bool isInterceptor() => true; | 479 bool isInterceptor() => true; |
| 450 | 480 |
| 451 bool operator ==(other) { | 481 bool operator ==(other) { |
| 452 return other is InterceptorConstant | 482 return other is InterceptorConstant |
| 453 && dispatchedType == other.dispatchedType; | 483 && dispatchedType == other.dispatchedType; |
| 454 } | 484 } |
| 455 | 485 |
| 456 int get hashCode => dispatchedType.hashCode * 43; | 486 int get hashCode => dispatchedType.hashCode * 43; |
| 457 | 487 |
| 458 List<Constant> getDependencies() => const <Constant>[]; | 488 List<Constant> getDependencies() => const <Constant>[]; |
| 459 | 489 |
| 460 accept(ConstantVisitor visitor) => visitor.visitInterceptor(this); | 490 accept(ConstantVisitor visitor) => visitor.visitInterceptor(this); |
| 461 | 491 |
| 462 DartType computeType(Compiler compiler) => compiler.types.dynamicType; | 492 DartType computeType(Compiler compiler) => compiler.types.dynamicType; |
| 493 | |
| 494 String toString() { | |
| 495 return 'InterceptorConstant($dispatchedType)'; | |
| 496 } | |
| 463 } | 497 } |
| 464 | 498 |
| 465 class ConstructedConstant extends ObjectConstant { | 499 class ConstructedConstant extends ObjectConstant { |
| 466 final List<Constant> fields; | 500 final List<Constant> fields; |
| 467 final int hashCode; | 501 final int hashCode; |
| 468 | 502 |
| 469 ConstructedConstant(DartType type, List<Constant> fields) | 503 ConstructedConstant(DartType type, List<Constant> fields) |
| 470 : this.fields = fields, | 504 : this.fields = fields, |
| 471 hashCode = computeHash(type, fields), | 505 hashCode = computeHash(type, fields), |
| 472 super(type) { | 506 super(type) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 503 Map<Element, Constant> get fieldElements { | 537 Map<Element, Constant> get fieldElements { |
| 504 // TODO(ahe): Refactor constant system to store this information directly. | 538 // TODO(ahe): Refactor constant system to store this information directly. |
| 505 ClassElement classElement = type.element; | 539 ClassElement classElement = type.element; |
| 506 int count = 0; | 540 int count = 0; |
| 507 Map<Element, Constant> result = new Map<Element, Constant>(); | 541 Map<Element, Constant> result = new Map<Element, Constant>(); |
| 508 classElement.implementation.forEachInstanceField((holder, field) { | 542 classElement.implementation.forEachInstanceField((holder, field) { |
| 509 result[field] = fields[count++]; | 543 result[field] = fields[count++]; |
| 510 }, includeSuperAndInjectedMembers: true); | 544 }, includeSuperAndInjectedMembers: true); |
| 511 return result; | 545 return result; |
| 512 } | 546 } |
| 547 | |
| 548 String toString() { | |
| 549 StringBuffer sb = new StringBuffer(); | |
| 550 sb.write(type); | |
| 551 sb.write('('); | |
| 552 int i = 0; | |
| 553 fieldElements.forEach((Element field, Constant value) { | |
| 554 if (i > 0) sb.write(','); | |
| 555 sb.write(field.name.slowToString()); | |
| 556 sb.write('='); | |
| 557 sb.write(value); | |
| 558 i++; | |
| 559 }); | |
| 560 sb.write(')'); | |
| 561 return sb.toString(); | |
| 562 } | |
| 513 } | 563 } |
| OLD | NEW |