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

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

Issue 10443010: Revert "Fix bug in combination of bounded and exact types." and "Make field final in const class." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 intersection(HType other) { 608 HType combine(HType other) {
609 if (other.isNull()) return canBeNull() ? HType.NULL : HType.CONFLICTING;
610 if (other is HBoundedType) { 609 if (other is HBoundedType) {
611 HBoundedType temp = other; 610 HBoundedType temp = other;
612 // Return [other] in case it is an exact type. 611 // Return [other] in case it is an exact type.
613 if (this.type === temp.type) return other; 612 if (this.type === temp.type) return other;
614 } 613 }
615 if (other.isUnknown()) return this; 614 if (other.isUnknown()) return this;
616 return HType.CONFLICTING; 615 return HType.CONFLICTING;
617 } 616 }
618 617
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
619 HType union(HType other) { 626 HType union(HType other) {
620 if (other.isNull()) { 627 if (other.isNull()) {
621 return canBeNull() ? this : new HBoundedType(type, true); 628 if (canBeNull()) {
629 return this;
630 } else {
631 return new HBoundedType(type, true);
632 }
622 } 633 }
623 if (other is HBoundedType) { 634 return combine(other);
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;
630 } 635 }
631 } 636 }
632 637
633 class HExactType extends HBoundedType { 638 class HExactType extends HBoundedType {
634 const HExactType(Type type) : super(type); 639 const HExactType(Type type) : super(type);
635 bool isExact() => true; 640 bool isExact() => true;
636 641
637 Element lookupMember(SourceString name) { 642 Element lookupMember(SourceString name) {
638 ClassElement classElement = type.element; 643 ClassElement classElement = type.element;
639 return classElement.lookupMember(name); 644 return classElement.lookupMember(name);
640 } 645 }
641 646
642 HType intersection(HType other) { 647 HType combine(HType other) {
643 if (other is HBoundedType) { 648 if (other.isExact()) {
644 HBoundedType bounded = other; 649 HExactType concrete = other;
645 if (this.type === bounded.type) return this; 650 if (this.type === concrete.type) return this;
646 } 651 }
647 return super.intersection(other); 652 if (other.isUnknown()) return this;
653 return HType.CONFLICTING;
648 } 654 }
649 655
650 HType union(HType other) { 656 HType union(HType other) {
651 if (other is HBoundedType) { 657 if (other.isNull()) return HType.CONFLICTING;
652 HBoundedType bounded = other; 658 return combine(other);
653 if (this.type === bounded.type) return other;
654 }
655 return super.union(other);
656 } 659 }
657 } 660 }
658 661
659 class HBoundedPotentialPrimitiveType extends HBoundedType { 662 class HBoundedPotentialPrimitiveType extends HBoundedType {
660 const HBoundedPotentialPrimitiveType(Type type, bool canBeNull) 663 const HBoundedPotentialPrimitiveType(Type type, bool canBeNull)
661 : super(type, canBeNull); 664 : super(type, canBeNull);
662 bool canBePrimitive() => true; 665 bool canBePrimitive() => true;
663 } 666 }
664 667
665 class HBoundedPotentialPrimitiveArray extends HBoundedPotentialPrimitiveType { 668 class HBoundedPotentialPrimitiveArray extends HBoundedPotentialPrimitiveType {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 HType intersection(HType other) { 720 HType intersection(HType other) {
718 if (other.isString()) return HType.STRING; 721 if (other.isString()) return HType.STRING;
719 if (other.isStringOrNull()) { 722 if (other.isStringOrNull()) {
720 return canBeNull() ? HType.STRING_OR_NULL : HType.STRING; 723 return canBeNull() ? HType.STRING_OR_NULL : HType.STRING;
721 } 724 }
722 if (other.isReadableArray()) return HType.CONFLICTING; 725 if (other.isReadableArray()) return HType.CONFLICTING;
723 if (other.isIndexablePrimitive()) return HType.STRING; 726 if (other.isIndexablePrimitive()) return HType.STRING;
724 return super.intersection(other); 727 return super.intersection(other);
725 } 728 }
726 } 729 }
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