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

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

Issue 102833009: Redo "Dummy receiver optimization" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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);
11 R visitDouble(DoubleConstant constant); 11 R visitDouble(DoubleConstant constant);
12 R visitTrue(TrueConstant constant); 12 R visitTrue(TrueConstant constant);
13 R visitFalse(FalseConstant constant); 13 R visitFalse(FalseConstant constant);
14 R visitString(StringConstant constant); 14 R visitString(StringConstant constant);
15 R visitList(ListConstant constant); 15 R visitList(ListConstant constant);
16 R visitMap(MapConstant constant); 16 R visitMap(MapConstant constant);
17 R visitConstructed(ConstructedConstant constant); 17 R visitConstructed(ConstructedConstant constant);
18 R visitType(TypeConstant constant); 18 R visitType(TypeConstant constant);
19 R visitInterceptor(InterceptorConstant constant); 19 R visitInterceptor(InterceptorConstant constant);
20 R visitDummyReceiver(DummyReceiverConstant constant);
20 } 21 }
21 22
22 abstract class Constant { 23 abstract class Constant {
23 const Constant(); 24 const Constant();
24 25
25 bool isNull() => false; 26 bool isNull() => false;
26 bool isBool() => false; 27 bool isBool() => false;
27 bool isTrue() => false; 28 bool isTrue() => false;
28 bool isFalse() => false; 29 bool isFalse() => false;
29 bool isInt() => false; 30 bool isInt() => false;
30 bool isDouble() => false; 31 bool isDouble() => false;
31 bool isNum() => false; 32 bool isNum() => false;
32 bool isString() => false; 33 bool isString() => false;
33 bool isList() => false; 34 bool isList() => false;
34 bool isMap() => false; 35 bool isMap() => false;
35 bool isConstructedObject() => false; 36 bool isConstructedObject() => false;
36 bool isFunction() => false; 37 bool isFunction() => false;
37 /** Returns true if the constant is null, a bool, a number or a string. */ 38 /** Returns true if the constant is null, a bool, a number or a string. */
38 bool isPrimitive() => false; 39 bool isPrimitive() => false;
39 /** Returns true if the constant is a list, a map or a constructed object. */ 40 /** Returns true if the constant is a list, a map or a constructed object. */
40 bool isObject() => false; 41 bool isObject() => false;
41 bool isType() => false; 42 bool isType() => false;
42 bool isSentinel() => false; 43 bool isSentinel() => false;
43 bool isInterceptor() => false; 44 bool isInterceptor() => false;
45 bool isDummyReceiver() => false;
44 46
45 bool isNaN() => false; 47 bool isNaN() => false;
46 bool isMinusZero() => false; 48 bool isMinusZero() => false;
47 49
48 // TODO(johnniwinther): Replace with a 'type' getter. 50 // TODO(johnniwinther): Replace with a 'type' getter.
49 DartType computeType(Compiler compiler); 51 DartType computeType(Compiler compiler);
50 52
51 ti.TypeMask computeMask(Compiler compiler); 53 ti.TypeMask computeMask(Compiler compiler);
52 54
53 List<Constant> getDependencies(); 55 List<Constant> getDependencies();
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 533
532 ti.TypeMask computeMask(Compiler compiler) { 534 ti.TypeMask computeMask(Compiler compiler) {
533 return compiler.typesTask.nonNullType; 535 return compiler.typesTask.nonNullType;
534 } 536 }
535 537
536 String toString() { 538 String toString() {
537 return 'InterceptorConstant(${Error.safeToString(dispatchedType)})'; 539 return 'InterceptorConstant(${Error.safeToString(dispatchedType)})';
538 } 540 }
539 } 541 }
540 542
543 class DummyReceiverConstant extends Constant {
544 final ti.TypeMask typeMask;
545
546 DummyReceiverConstant(this.typeMask);
547
548 bool isDummyReceiver() => true;
549
550 bool operator ==(other) {
551 return other is DummyReceiverConstant
552 && typeMask == other.typeMask;
553 }
554
555 get hashCode => typeMask.hashCode;
556
557 List<Constant> getDependencies() => const <Constant>[];
558
559 accept(ConstantVisitor visitor) => visitor.visitDummyReceiver(this);
560
561 DartType computeType(Compiler compiler) => compiler.types.dynamicType;
562
563 ti.TypeMask computeMask(Compiler compiler) => typeMask;
564
565 String toString() {
566 return 'DummyReceiverConstant($typeMask)';
567 }
568 }
569
541 class ConstructedConstant extends ObjectConstant { 570 class ConstructedConstant extends ObjectConstant {
542 final List<Constant> fields; 571 final List<Constant> fields;
543 final int hashCode; 572 final int hashCode;
544 573
545 ConstructedConstant(DartType type, List<Constant> fields) 574 ConstructedConstant(DartType type, List<Constant> fields)
546 : this.fields = fields, 575 : this.fields = fields,
547 hashCode = computeHash(type, fields), 576 hashCode = computeHash(type, fields),
548 super(type) { 577 super(type) {
549 assert(type != null); 578 assert(type != null);
550 } 579 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 if (i > 0) sb.write(','); 633 if (i > 0) sb.write(',');
605 sb.write(Error.safeToString(field.name)); 634 sb.write(Error.safeToString(field.name));
606 sb.write('='); 635 sb.write('=');
607 sb.write(Error.safeToString(value)); 636 sb.write(Error.safeToString(value));
608 i++; 637 i++;
609 }); 638 });
610 sb.write('))'); 639 sb.write('))');
611 return sb.toString(); 640 return sb.toString();
612 } 641 }
613 } 642 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698