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

Side by Side Diff: lib/compiler/implementation/ssa/types.dart

Issue 10411094: Fix bug in combination of bounded and exact types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove typo. Created 8 years, 7 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
« no previous file with comments | « no previous file | tests/language/switch_this_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 abstract class HType { 5 abstract class HType {
6 const HType(); 6 const HType();
7 7
8 /** 8 /**
9 * Returns an [HType] that represents [type] and all types that have 9 * Returns an [HType] that represents [type] and all types that have
10 * [type] as supertype. 10 * [type] as supertype.
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 final Type type; 598 final Type type;
599 final bool _canBeNull; 599 final bool _canBeNull;
600 600
601 bool canBeNull() => _canBeNull; 601 bool canBeNull() => _canBeNull;
602 602
603 const HBoundedType(Type this.type, [bool this._canBeNull = false]); 603 const HBoundedType(Type this.type, [bool this._canBeNull = false]);
604 String toString() => type.toString(); 604 String toString() => type.toString();
605 605
606 Type computeType(Compiler compiler) => type; 606 Type computeType(Compiler compiler) => type;
607 607
608 HType combine(HType other) { 608 HType intersection(HType other) {
609 if (other.isNull()) return canBeNull() ? HType.NULL : HType.CONFLICTING;
609 if (other is HBoundedType) { 610 if (other is HBoundedType) {
610 HBoundedType temp = other; 611 HBoundedType temp = other;
611 // Return [other] in case it is an exact type. 612 // Return [other] in case it is an exact type.
612 if (this.type === temp.type) return other; 613 if (this.type === temp.type) return other;
613 } 614 }
614 if (other.isUnknown()) return this; 615 if (other.isUnknown()) return this;
615 return HType.CONFLICTING; 616 return HType.CONFLICTING;
616 } 617 }
617 618
618 // As long as we don't keep track of super/sub types for non-primitive types
619 // the intersection and union is the same, except when [other] is
620 // null.
621 HType intersection(HType other) {
622 if (other.isNull()) return canBeNull() ? HType.NULL : HType.CONFLICTING;
623 return combine(other);
624 }
625
626 HType union(HType other) { 619 HType union(HType other) {
627 if (other.isNull()) { 620 if (other.isNull()) {
628 if (canBeNull()) { 621 return canBeNull() ? this : new HBoundedType(type, true);
629 return this;
630 } else {
631 return new HBoundedType(type, true);
632 }
633 } 622 }
634 return combine(other); 623 if (other is HBoundedType) {
624 HBoundedType temp = other;
625 // Return [this] in case [other] is an exact type.
626 if (this.type === temp.type) return this;
627 }
628 if (other.isUnknown()) return this;
629 return HType.CONFLICTING;
635 } 630 }
636 } 631 }
637 632
638 class HExactType extends HBoundedType { 633 class HExactType extends HBoundedType {
639 const HExactType(Type type) : super(type); 634 const HExactType(Type type) : super(type);
640 bool isExact() => true; 635 bool isExact() => true;
641 636
642 Element lookupMember(SourceString name) { 637 Element lookupMember(SourceString name) {
643 ClassElement classElement = type.element; 638 ClassElement classElement = type.element;
644 return classElement.lookupMember(name); 639 return classElement.lookupMember(name);
645 } 640 }
646 641
647 HType combine(HType other) { 642 HType intersection(HType other) {
648 if (other.isExact()) { 643 if (other is HBoundedType) {
649 HExactType concrete = other; 644 HBoundedType bounded = other;
650 if (this.type === concrete.type) return this; 645 if (this.type === bounded.type) return this;
651 } 646 }
652 if (other.isUnknown()) return this; 647 return super.intersection(other);
653 return HType.CONFLICTING;
654 } 648 }
655 649
656 HType union(HType other) { 650 HType union(HType other) {
657 if (other.isNull()) return HType.CONFLICTING; 651 if (other is HBoundedType) {
658 return combine(other); 652 HBoundedType bounded = other;
653 if (this.type === bounded.type) return other;
654 }
655 return super.union(other);
659 } 656 }
660 } 657 }
661 658
662 class HBoundedPotentialPrimitiveType extends HBoundedType { 659 class HBoundedPotentialPrimitiveType extends HBoundedType {
663 const HBoundedPotentialPrimitiveType(Type type, bool canBeNull) 660 const HBoundedPotentialPrimitiveType(Type type, bool canBeNull)
664 : super(type, canBeNull); 661 : super(type, canBeNull);
665 bool canBePrimitive() => true; 662 bool canBePrimitive() => true;
666 } 663 }
667 664
668 class HBoundedPotentialPrimitiveArray extends HBoundedPotentialPrimitiveType { 665 class HBoundedPotentialPrimitiveArray extends HBoundedPotentialPrimitiveType {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 HType intersection(HType other) { 717 HType intersection(HType other) {
721 if (other.isString()) return HType.STRING; 718 if (other.isString()) return HType.STRING;
722 if (other.isStringOrNull()) { 719 if (other.isStringOrNull()) {
723 return canBeNull() ? HType.STRING_OR_NULL : HType.STRING; 720 return canBeNull() ? HType.STRING_OR_NULL : HType.STRING;
724 } 721 }
725 if (other.isReadableArray()) return HType.CONFLICTING; 722 if (other.isReadableArray()) return HType.CONFLICTING;
726 if (other.isIndexablePrimitive()) return HType.STRING; 723 if (other.isIndexablePrimitive()) return HType.STRING;
727 return super.intersection(other); 724 return super.intersection(other);
728 } 725 }
729 } 726 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/switch_this_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698