@@ -83,7 +83,7 @@ class Type extends @type {
83
83
private predicate implementsNotComparable ( InterfaceType i ) {
84
84
(
85
85
forall ( TypeSetLiteralType tslit | tslit = i .getAnEmbeddedTypeSetLiteral ( ) |
86
- tslit .hasInTypeSet ( this )
86
+ tslit .includesType ( this )
87
87
) and
88
88
(
89
89
not i .hasMethod ( _, _)
@@ -112,22 +112,21 @@ class Type extends @type {
112
112
or
113
113
u instanceof ArrayType and u .( ArrayType ) .getElementType ( ) .implementsComparable ( )
114
114
or
115
- u instanceof InterfaceType and
116
- (
117
- not u instanceof BasicInterfaceType and
118
- if exists ( u .( InterfaceType ) .getAnEmbeddedTypeSetLiteral ( ) )
115
+ exists ( InterfaceType uif | uif = u |
116
+ not uif instanceof BasicInterfaceType and
117
+ if exists ( uif .getAnEmbeddedTypeSetLiteral ( ) )
119
118
then
119
+ // All types in the intersection of all the embedded type set
120
+ // literals must implement comparable.
120
121
forall ( Type intersectionType |
121
- intersectionType = u .( InterfaceType ) .getAnEmbeddedTypeSetLiteral ( ) .getATerm ( ) .getType ( ) and
122
- forall ( TypeSetLiteralType tslit |
123
- tslit = u .( InterfaceType ) .getAnEmbeddedTypeSetLiteral ( )
124
- |
122
+ intersectionType = uif .getAnEmbeddedTypeSetLiteral ( ) .getATerm ( ) .getType ( ) and
123
+ forall ( TypeSetLiteralType tslit | tslit = uif .getAnEmbeddedTypeSetLiteral ( ) |
125
124
intersectionType = tslit .getATerm ( ) .getType ( )
126
125
)
127
126
|
128
127
intersectionType .implementsComparable ( )
129
128
)
130
- else u . ( InterfaceType ) .isOrEmbedsComparable ( )
129
+ else uif .isOrEmbedsComparable ( )
131
130
)
132
131
)
133
132
}
@@ -610,8 +609,8 @@ class PointerType extends @pointertype, CompositeType {
610
609
override string toString ( ) { result = "pointer type" }
611
610
}
612
611
613
- private newtype TTerm =
614
- MkTerm ( TypeSetLiteralType tslit , int index ) { component_types ( tslit , index , _, _) }
612
+ private newtype TTypeSetTerm =
613
+ MkTypeSetTerm ( TypeSetLiteralType tslit , int index ) { component_types ( tslit , index , _, _) }
615
614
616
615
/**
617
616
* A term in a type set literal.
@@ -622,13 +621,13 @@ private newtype TTerm =
622
621
* ~string
623
622
* ```
624
623
*/
625
- class Term extends TTerm {
624
+ class TypeSetTerm extends TTypeSetTerm {
626
625
boolean tilde ;
627
626
Type tp ;
628
627
629
- Term ( ) {
628
+ TypeSetTerm ( ) {
630
629
exists ( TypeSetLiteralType tslit , int index |
631
- this = MkTerm ( tslit , index ) and
630
+ this = MkTypeSetTerm ( tslit , index ) and
632
631
(
633
632
component_types ( tslit , index , "" , tp ) and
634
633
tilde = false
@@ -651,7 +650,7 @@ class Term extends TTerm {
651
650
Type getType ( ) { result = tp }
652
651
653
652
/** Holds if `t` is in the type set of this term. */
654
- predicate hasInTypeSet ( Type t ) { if tilde = false then t = tp else t .getUnderlyingType (<
6D40
/span>) = tp }
653
+ predicate includesType ( Type t ) { if tilde = false then t = tp else t .getUnderlyingType ( ) = tp }
655
654
656
655
/** Gets a pretty-printed representation of this term. */
657
656
string pp ( ) {
@@ -661,15 +660,15 @@ class Term extends TTerm {
661
660
}
662
661
663
662
/** Gets a textual representation of this element. */
664
- string toString ( ) { result = "term" }
663
+ string toString ( ) { result = "type set term" }
665
664
}
666
665
667
- private Term getIntersection ( Term term1 , Term term2 ) {
666
+ private TypeSetTerm getIntersection ( TypeSetTerm term1 , TypeSetTerm term2 ) {
668
667
term1 .getType ( ) = term2 .getType ( ) and
669
668
if term1 .hasTilde ( ) then result = term2 else result = term1
670
669
}
671
670
672
- Term getTermInIntersection ( TypeSetLiteralType a , TypeSetLiteralType b ) {
671
+ TypeSetTerm getTermInIntersection ( TypeSetLiteralType a , TypeSetLiteralType b ) {
673
672
result = getIntersection ( a .getATerm ( ) , b .getATerm ( ) )
674
673
}
675
674
@@ -689,13 +688,13 @@ Term getTermInIntersection(TypeSetLiteralType a, TypeSetLiteralType b) {
689
688
*/
690
689
class TypeSetLiteralType extends @typesetliteraltype, CompositeType {
691
690
/** Gets the `i`th term in this type set literal. */
692
- Term getTerm ( int i ) { result = MkTerm ( this , i ) }
691
+ TypeSetTerm getTerm ( int i ) { result = MkTypeSetTerm ( this , i ) }
693
692
694
693
/** Gets a term in this type set literal. */
695
- Term getATerm ( ) { result = getTerm ( _) }
694
+ TypeSetTerm getATerm ( ) { result = getTerm ( _) }
696
695
697
696
/** Holds if `t` is in the type set of this type set literal. */
698
- predicate hasInTypeSet ( Type t ) { exists ( int i | this .getTerm ( i ) . hasInTypeSet ( t ) ) }
697
+ predicate includesType ( Type t ) { this .getATerm ( ) . includesType ( t ) }
699
698
700
699
/**
701
700
* Gets the interface type specified by just this type set literal, if it
@@ -705,15 +704,15 @@ class TypeSetLiteralType extends @typesetliteraltype, CompositeType {
705
704
* the bound in a type parameter declaration.
706
705
*/
707
706
InterfaceType getInterfaceType ( ) {
708
- this = result .getExplicitlyEmbeddedTypeSetLiteral ( 0 ) and
709
- not exists ( result .getExplicitlyEmbeddedTypeSetLiteral ( 1 ) ) and
707
+ this = result .getDirectlyEmbeddedTypeSetLiteral ( 0 ) and
708
+ not exists ( result .getDirectlyEmbeddedTypeSetLiteral ( 1 ) ) and
710
709
not result .hasMethod ( _, _) and
711
- not exists ( result .getAnExplicitlyEmbeddedInterface ( ) )
710
+ not exists ( result .getADirectlyEmbeddedInterface ( ) )
712
711
}
713
712
714
713
language [ monotonicAggregates]
715
714
override string pp ( ) {
716
- result = concat ( Term t , int i | t = this .getTerm ( i ) | t .pp ( ) , " | " order by i )
715
+ result = concat ( TypeSetTerm t , int i | t = this .getTerm ( i ) | t .pp ( ) , " | " order by i )
717
716
}
718
717
719
718
override string toString ( ) { result = "type set literal type" }
@@ -723,30 +722,32 @@ class TypeSetLiteralType extends @typesetliteraltype, CompositeType {
723
722
class InterfaceType extends @interfacetype, CompositeType {
724
723
/** Gets the type of method `name` of this interface type. */
725
724
Type getMethodType ( string name ) {
725
+ // Note that negative indices correspond to embedded interfaces and type
726
+ // set literals.
726
727
exists ( int i | i >= 0 | component_types ( this , i , name , result ) )
727
728
}
728
729
729
730
override predicate hasMethod ( string m , SignatureType t ) { t = this .getMethodType ( m ) }
730
731
731
732
/**
732
- * Holds if `tp` is an explicitly embedded type with index `index`.
733
+ * Holds if `tp` is a directly embedded type with index `index`.
733
734
*
734
- * `tp` is either a type set literal type or its underlyign type is an
735
+ * `tp` (or its underlying type) is either a type set literal type or an
735
736
* interface type.
736
737
*/
737
- private predicate hasExplicitlyEmbeddedType ( int index , Type tp ) {
738
+ private predicate hasDirectlyEmbeddedType ( int index , Type tp ) {
738
739
index >= 0 and component_types ( this , - ( index + 1 ) , _, tp )
739
740
}
740
741
741
742
/**
742
- * Gets a type whose underlying type is an interface that is explicitly
743
+ * Gets a type whose underlying type is an interface that is directly
743
744
* embedded into this interface.
744
745
*
745
746
* Note that the methods of the embedded interface are already considered
746
747
* as part of the method set of this interface.
747
748
*/
748
- Type getAnExplicitlyEmbeddedInterface ( ) {
749
- hasExplicitlyEmbeddedType ( _, result ) and result .getUnderlyingType ( ) instanceof InterfaceType
749
+ Type getADirectlyEmbeddedInterface ( ) {
750
+ hasDirectlyEmbeddedType ( _, result ) and result .getUnderlyingType ( ) instanceof InterfaceType
750
751
}
751
752
752
753
/**
@@ -757,9 +758,9 @@ class InterfaceType extends @interfacetype, CompositeType {
757
758
* as part of the method set of this interface.
758
759
*/
759
760
Type getAnEmbeddedInterface ( ) {
760
- result = this .getAnExplicitlyEmbeddedInterface ( ) or
761
+ result = this .getADirectlyEmbeddedInterface ( ) or
761
762
result =
762
- this .getAnExplicitlyEmbeddedInterface ( )
763
+ this .getADirectlyEmbeddedInterface ( )
763
764
.getUnderlyingType ( )
764
765
.( InterfaceType )
765
766
.getAnEmbeddedInterface ( )
@@ -778,10 +779,10 @@ class InterfaceType extends @interfacetype, CompositeType {
778
779
* Gets the type set literal with index `index` from the definition of this
779
780
* interface type.
780
781
*
781
- * Note that the indexing includes embedded interfaces but not methods .
782
+ * Note that the indexes are not contiguous .
782
783
*/
783
- TypeSetLiteralType getExplicitlyEmbeddedTypeSetLiteral ( int index ) {
784
- hasExplicitlyEmbeddedType ( index , result )
784
+ TypeSetLiteralType getDirectlyEmbeddedTypeSetLiteral ( int index ) {
785
+ hasDirectlyEmbeddedType ( index , result )
785
786
}
786
787
787
788
/**
@@ -790,9 +791,9 @@ class InterfaceType extends @interfacetype, CompositeType {
790
791
* This includes type set literals of embedded interfaces.
791
792
*/
792
793
TypeSetLiteralType getAnEmbeddedTypeSetLiteral ( ) {
793
- result = this .getExplicitlyEmbeddedTypeSetLiteral ( _) or
794
+ result = this .getDirectlyEmbeddedTypeSetLiteral ( _) or
794
795
result =
795
- getAnExplicitlyEmbeddedInterface ( )
796
+ getADirectlyEmbeddedInterface ( )
796
797
.getUnderlyingType ( )
797
798
.( InterfaceType )
798
799
.getAnEmbeddedTypeSetLiteral ( )
0 commit comments