Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/constants.dart

Issue 24282005: Move compile-time constant registrations to the backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 27 matching lines...) Expand all
38 bool isPrimitive() => false; 38 bool isPrimitive() => false;
39 /** Returns true if the constant is a list, a map or a constructed object. */ 39 /** Returns true if the constant is a list, a map or a constructed object. */
40 bool isObject() => false; 40 bool isObject() => false;
41 bool isType() => false; 41 bool isType() => false;
42 bool isSentinel() => false; 42 bool isSentinel() => false;
43 bool isInterceptor() => false; 43 bool isInterceptor() => false;
44 44
45 bool isNaN() => false; 45 bool isNaN() => false;
46 bool isMinusZero() => false; 46 bool isMinusZero() => false;
47 47
48 // TODO(johnniwinther): Replace with a 'type' getter.
48 DartType computeType(Compiler compiler); 49 DartType computeType(Compiler compiler);
49 50
50 List<Constant> getDependencies(); 51 List<Constant> getDependencies();
51 52
52 accept(ConstantVisitor visitor); 53 accept(ConstantVisitor visitor);
53 } 54 }
54 55
55 class FunctionConstant extends Constant { 56 class FunctionConstant extends Constant {
56 Element element; 57 Element element;
57 58
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 bool operator ==(var other) { 289 bool operator ==(var other) {
289 if (other is !StringConstant) return false; 290 if (other is !StringConstant) return false;
290 StringConstant otherString = other; 291 StringConstant otherString = other;
291 return (hashCode == otherString.hashCode) && (value == otherString.value); 292 return (hashCode == otherString.hashCode) && (value == otherString.value);
292 } 293 }
293 294
294 DartString toDartString() => value; 295 DartString toDartString() => value;
295 int get length => value.length; 296 int get length => value.length;
296 297
297 accept(ConstantVisitor visitor) => visitor.visitString(this); 298 accept(ConstantVisitor visitor) => visitor.visitString(this);
299
300 String toString() {
301 return 'StringConstant(${Error.safeToString(value.slowToString())})';
302 }
298 } 303 }
299 304
300 abstract class ObjectConstant extends Constant { 305 abstract class ObjectConstant extends Constant {
301 final DartType type; 306 final DartType type;
302 307
303 ObjectConstant(this.type); 308 ObjectConstant(this.type);
304 bool isObject() => true; 309 bool isObject() => true;
305 310
306 DartType computeType(Compiler compiler) => type; 311 DartType computeType(Compiler compiler) => type;
307 } 312 }
308 313
309 class TypeConstant extends ObjectConstant { 314 class TypeConstant extends ObjectConstant {
310 /// The user type that this constant represents. 315 /// The user type that this constant represents.
311 final DartType representedType; 316 final DartType representedType;
312 317
313 TypeConstant(this.representedType, type) : super(type); 318 TypeConstant(this.representedType, type) : super(type);
314 319
315 bool isType() => true; 320 bool isType() => true;
316 321
317 bool operator ==(other) { 322 bool operator ==(other) {
318 return other is TypeConstant && representedType == other.representedType; 323 return other is TypeConstant && representedType == other.representedType;
319 } 324 }
320 325
321 int get hashCode => representedType.hashCode * 13; 326 int get hashCode => representedType.hashCode * 13;
322 327
323 List<Constant> getDependencies() => const <Constant>[]; 328 List<Constant> getDependencies() => const <Constant>[];
324 329
325 accept(ConstantVisitor visitor) => visitor.visitType(this); 330 accept(ConstantVisitor visitor) => visitor.visitType(this);
331
332 String toString() => 'TypeConstant(${Error.safeToString(representedType)})';
326 } 333 }
327 334
328 class ListConstant extends ObjectConstant { 335 class ListConstant extends ObjectConstant {
329 final List<Constant> entries; 336 final List<Constant> entries;
330 final int hashCode; 337 final int hashCode;
331 338
332 ListConstant(DartType type, List<Constant> entries) 339 ListConstant(DartType type, List<Constant> entries)
333 : this.entries = entries, 340 : this.entries = entries,
334 hashCode = _computeHash(type, entries), 341 hashCode = _computeHash(type, entries),
335 super(type); 342 super(type);
(...skipping 19 matching lines...) Expand all
355 if (entries[i] != otherList.entries[i]) return false; 362 if (entries[i] != otherList.entries[i]) return false;
356 } 363 }
357 return true; 364 return true;
358 } 365 }
359 366
360 List<Constant> getDependencies() => entries; 367 List<Constant> getDependencies() => entries;
361 368
362 int get length => entries.length; 369 int get length => entries.length;
363 370
364 accept(ConstantVisitor visitor) => visitor.visitList(this); 371 accept(ConstantVisitor visitor) => visitor.visitList(this);
372
373 String toString() {
374 StringBuffer sb = new StringBuffer();
375 sb.write('ListConstant([');
376 for (int i = 0 ; i < entries.length ; i++) {
377 if (i > 0) sb.write(',');
378 sb.write(Error.safeToString(entries[i]));
379 }
380 sb.write('])');
381 return sb.toString();
382 }
365 } 383 }
366 384
367 class MapConstant extends ObjectConstant { 385 class MapConstant extends ObjectConstant {
368 /** 386 /**
369 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript 387 * The [PROTO_PROPERTY] must not be used as normal property in any JavaScript
370 * object. It would change the prototype chain. 388 * object. It would change the prototype chain.
371 */ 389 */
372 static const LiteralDartString PROTO_PROPERTY = 390 static const LiteralDartString PROTO_PROPERTY =
373 const LiteralDartString("__proto__"); 391 const LiteralDartString("__proto__");
374 392
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 // for the keys. 448 // for the keys.
431 result.addAll(keys.entries); 449 result.addAll(keys.entries);
432 } 450 }
433 result.addAll(values); 451 result.addAll(values);
434 return result; 452 return result;
435 } 453 }
436 454
437 int get length => keys.length; 455 int get length => keys.length;
438 456
439 accept(ConstantVisitor visitor) => visitor.visitMap(this); 457 accept(ConstantVisitor visitor) => visitor.visitMap(this);
458
459 String toString() {
460 StringBuffer sb = new StringBuffer();
461 sb.write('MapConstant({');
462 for (int i = 0 ; i < keys.entries.length ; i++) {
463 if (i > 0) sb.write(',');
464 sb.write(Error.safeToString(keys.entries[i]));
465 sb.write(':');
466 sb.write(Error.safeToString(values[i]));
467 }
468 sb.write('})');
469 return sb.toString();
470 }
440 } 471 }
441 472
442 class InterceptorConstant extends Constant { 473 class InterceptorConstant extends Constant {
443 /// The type for which this interceptor holds the methods. The constant 474 /// The type for which this interceptor holds the methods. The constant
444 /// is a dispatch table for this type. 475 /// is a dispatch table for this type.
445 final DartType dispatchedType; 476 final DartType dispatchedType;
446 477
447 InterceptorConstant(this.dispatchedType); 478 InterceptorConstant(this.dispatchedType);
448 479
449 bool isInterceptor() => true; 480 bool isInterceptor() => true;
450 481
451 bool operator ==(other) { 482 bool operator ==(other) {
452 return other is InterceptorConstant 483 return other is InterceptorConstant
453 && dispatchedType == other.dispatchedType; 484 && dispatchedType == other.dispatchedType;
454 } 485 }
455 486
456 int get hashCode => dispatchedType.hashCode * 43; 487 int get hashCode => dispatchedType.hashCode * 43;
457 488
458 List<Constant> getDependencies() => const <Constant>[]; 489 List<Constant> getDependencies() => const <Constant>[];
459 490
460 accept(ConstantVisitor visitor) => visitor.visitInterceptor(this); 491 accept(ConstantVisitor visitor) => visitor.visitInterceptor(this);
461 492
462 DartType computeType(Compiler compiler) => compiler.types.dynamicType; 493 DartType computeType(Compiler compiler) => compiler.types.dynamicType;
494
495 String toString() {
496 return 'InterceptorConstant(${Error.safeToString(dispatchedType)})';
497 }
463 } 498 }
464 499
465 class ConstructedConstant extends ObjectConstant { 500 class ConstructedConstant extends ObjectConstant {
466 final List<Constant> fields; 501 final List<Constant> fields;
467 final int hashCode; 502 final int hashCode;
468 503
469 ConstructedConstant(DartType type, List<Constant> fields) 504 ConstructedConstant(DartType type, List<Constant> fields)
470 : this.fields = fields, 505 : this.fields = fields,
471 hashCode = computeHash(type, fields), 506 hashCode = computeHash(type, fields),
472 super(type) { 507 super(type) {
(...skipping 30 matching lines...) Expand all
503 Map<Element, Constant> get fieldElements { 538 Map<Element, Constant> get fieldElements {
504 // TODO(ahe): Refactor constant system to store this information directly. 539 // TODO(ahe): Refactor constant system to store this information directly.
505 ClassElement classElement = type.element; 540 ClassElement classElement = type.element;
506 int count = 0; 541 int count = 0;
507 Map<Element, Constant> result = new Map<Element, Constant>(); 542 Map<Element, Constant> result = new Map<Element, Constant>();
508 classElement.implementation.forEachInstanceField((holder, field) { 543 classElement.implementation.forEachInstanceField((holder, field) {
509 result[field] = fields[count++]; 544 result[field] = fields[count++];
510 }, includeSuperAndInjectedMembers: true); 545 }, includeSuperAndInjectedMembers: true);
511 return result; 546 return result;
512 } 547 }
548
549 String toString() {
550 StringBuffer sb = new StringBuffer();
551 sb.write('ConstructedConstant(');
552 sb.write(type);
553 sb.write('(');
554 int i = 0;
555 fieldElements.forEach((Element field, Constant value) {
556 if (i > 0) sb.write(',');
557 sb.write(Error.safeToString(field.name.slowToString()));
558 sb.write('=');
559 sb.write(Error.safeToString(value));
560 i++;
561 });
562 sb.write('))');
563 return sb.toString();
564 }
513 } 565 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698