Package de.monticore.types3.util
Class SymTypeCompatibilityCalculator
java.lang.Object
de.monticore.types3.util.SymTypeCompatibilityCalculator
checks for compatibility between SymTypes
delegate of SymTypeRelations
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarrayConstrainSameType(SymTypeArray arrayA, SymTypeArray arrayB) arrayConstrainSubTypeOf(SymTypeArray subArray, SymTypeArray superArray) whether one array is the subType of anotherboxedPrimitiveConstrainSubTypeOf(SymTypeOfObject subType, SymTypeOfObject superType) whether a boxed primitive is the subType of another This version is NOT conform to the java spec (20); Java does not allow, e.g., Integer i = 2; Float f = i; Note, that this is (nearly) never an issue about losing object identity: E.g., Integer x = 2; Integer y = 2; // x == y holds but, Integer x = 222; Integer y = 222; // x != y holds (tested in JDK 17) s.a.protected <T extends SymTypeExpression>
TboxGenericButNotArguments(T type) E.g.:List<List<int>> to java.util.List<List<int>>constrainCompatible(SymTypeExpression target, SymTypeExpression source) constrainCompatiblePreNormalized(SymTypeExpression target, SymTypeExpression source) constrainContainsPreNormalized(SymTypeExpression subSetType, SymTypeExpression superSetType) Is the set of types denoted by subSetType a subSet of the set of types denoted by superSetType? s.constrainSameType(SymTypeExpression typeA, SymTypeExpression typeB) Reduces a constraint<a = b>to the constraints<a <: b>, <b <: a>.constrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) constrainSubTypeOfSubIntersection(SymTypeOfIntersection subType, SymTypeExpression superType) constrainSubTypeOfSubUnion(SymTypeOfUnion subType, SymTypeExpression superType) constrainSubTypeOfSuperIntersection(SymTypeExpression subType, SymTypeOfIntersection superType) constrainSubTypeOfSuperUnion(SymTypeExpression subType, SymTypeOfUnion superType) functionConstrainSameType(SymTypeOfFunction funcA, SymTypeOfFunction funcB) functionConstrainSubTypeOf(SymTypeOfFunction subFunc, SymTypeOfFunction superFunc) protected List<SymTypeExpression> getSuperTypes(SymTypeExpression thisType) Deprecated, for removal: This API element is subject to removal in a future version.protected UnsatisfiableBoundgetUnsatisfiableBoundForCompatibilty(SymTypeExpression targetType, SymTypeExpression sourceType) protected UnsatisfiableBoundgetUnsatisfiableBoundForContainment(SymTypeExpression subSetType, SymTypeExpression superSetType) protected UnsatisfiableBoundprotected UnsatisfiableBoundgetUnsatisfiableBoundForSubTyping(SymTypeExpression subType, SymTypeExpression superType) handleMultipleListOfBounds(List<List<Bound>> bounds, SymTypeExpression subType, SymTypeExpression superType) infVarConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB) internal_constrainSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType) booleaninternal_isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft) Deprecated, for removal: This API element is subject to removal in a future version.booleaninternal_isSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft) Deprecated, for removal: This API element is subject to removal in a future version.intersectionConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB) booleanisCompatible(SymTypeExpression target, SymTypeExpression source) booleanisSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) nullConstrainCompatible(SymTypeExpression target, SymTypeOfNull source) numericWithSIUnitConstrainSameType(SymTypeOfNumericWithSIUnit numericWithSIUnitA, SymTypeOfNumericWithSIUnit numericWithSIUnitB) numericWithSIUnitConstrainSubTypeOf(SymTypeOfNumericWithSIUnit subType, SymTypeOfNumericWithSIUnit superType) objectConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB) objectConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) whether one object is a subType of another this includes SymTypeOfObject, as well as SymTypeOfGenericsprimitiveConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) protected StringprintBounds(List<Bound> bounds) regExConstrainCompatible(SymTypeExpression target, SymTypeExpression source) isCompatible if one of the arguments is a SymTypeOfRegexregExConstrainSameType(SymTypeExpression regexA, SymTypeExpression regexB) regExConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) whether one type is the subType of another is if at least one of them is a SymTypeOfRegExsingleConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) this tests all symtypes that are not union or intersection types (and don't contain them)siUnitConstrainSameType(SymTypeOfSIUnit siUnitA, SymTypeOfSIUnit siUnitB) siUnitConstrainSubTypeOf(SymTypeOfSIUnit subType, SymTypeOfSIUnit superType) tupleConstrainSameType(SymTypeOfTuple tupleA, SymTypeOfTuple tupleB) tupleConstrainSubTypeOf(SymTypeOfTuple subTuple, SymTypeOfTuple superTuple) typeSetConstrainCompatible(SymTypeExpression target, SymTypeExpression source) s.a.typeSetConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) whether one expression is the subType of another, with at least one of the types being a variable or wildcard, thus representing a set of types, rather than a single type.unboxedPrimitiveConstrainSubTypeOf(SymTypePrimitive subType, SymTypePrimitive superType) whether unboxed primitives are in a subType relation s.unionConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)
-
Field Details
-
LOG_NAME
- See Also:
-
-
Constructor Details
-
SymTypeCompatibilityCalculator
public SymTypeCompatibilityCalculator()
-
-
Method Details
-
isCompatible
-
isSubTypeOf
-
internal_isSubTypeOf
@Deprecated(forRemoval=true) public boolean internal_isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft) Deprecated, for removal: This API element is subject to removal in a future version.isSubTypeOf and canBeSubTypeOf, as they are very similar subTypeIsSoft if it is only a possibility, that it is a subtype -
internal_isSubTypeOfPreNormalized
@Deprecated(forRemoval=true) public boolean internal_isSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft) Deprecated, for removal: This API element is subject to removal in a future version. -
constrainCompatible
-
constrainCompatiblePreNormalized
protected List<Bound> constrainCompatiblePreNormalized(SymTypeExpression target, SymTypeExpression source) -
typeSetConstrainCompatible
protected List<Bound> typeSetConstrainCompatible(SymTypeExpression target, SymTypeExpression source) -
nullConstrainCompatible
-
regExConstrainCompatible
isCompatible if one of the arguments is a SymTypeOfRegex- Returns:
- if false, it can still be compatible due to other typing rules
-
constrainSubTypeOf
-
internal_constrainSubTypeOfPreNormalized
public List<Bound> internal_constrainSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType) -
constrainSubTypeOfSubUnion
protected List<Bound> constrainSubTypeOfSubUnion(SymTypeOfUnion subType, SymTypeExpression superType) -
constrainSubTypeOfSuperUnion
protected List<Bound> constrainSubTypeOfSuperUnion(SymTypeExpression subType, SymTypeOfUnion superType) - Parameters:
subType- is not a union
-
constrainSubTypeOfSuperIntersection
protected List<Bound> constrainSubTypeOfSuperIntersection(SymTypeExpression subType, SymTypeOfIntersection superType) - Parameters:
subType- is not a union
-
constrainSubTypeOfSubIntersection
protected List<Bound> constrainSubTypeOfSubIntersection(SymTypeOfIntersection subType, SymTypeExpression superType) - Parameters:
superType- is neither union nor intersection
-
handleMultipleListOfBounds
protected List<Bound> handleMultipleListOfBounds(List<List<Bound>> bounds, SymTypeExpression subType, SymTypeExpression superType) Helper forconstrainSubTypeOfSuperUnion(SymTypeExpression, SymTypeOfUnion),constrainSubTypeOfSubIntersection(SymTypeOfIntersection, SymTypeExpression). In these cases, one does not calculate bounds that are connected by 'and', instead, List of 'and'-ed bounds are calculated, which in turn are connected by 'or'. Solving these sets of bounds may be heavily exponential, as such, we use a heuristic to reduce them to a single list of 'and'-ed bounds.- Parameters:
subType- used for loggingsuperType- used for logging- Returns:
- the result may not contain the most optimal set of bounds, but it will never(!) omit required bounds.
-
constrainSameType
-
internal_constrainSameTypePreNormalized
protected List<Bound> internal_constrainSameTypePreNormalized(SymTypeExpression typeA, SymTypeExpression typeB) -
singleConstrainSubTypeOf
protected List<Bound> singleConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) this tests all symtypes that are not union or intersection types (and don't contain them) -
typeSetConstrainSubTypeOf
protected List<Bound> typeSetConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) whether one expression is the subType of another, with at least one of the types being a variable or wildcard, thus representing a set of types, rather than a single type. -
arrayConstrainSubTypeOf
whether one array is the subType of another -
unboxedPrimitiveConstrainSubTypeOf
protected List<Bound> unboxedPrimitiveConstrainSubTypeOf(SymTypePrimitive subType, SymTypePrimitive superType) whether unboxed primitives are in a subType relation s. Java spec 20 4.10.1 -
boxedPrimitiveConstrainSubTypeOf
protected List<Bound> boxedPrimitiveConstrainSubTypeOf(SymTypeOfObject subType, SymTypeOfObject superType) whether a boxed primitive is the subType of another This version is NOT conform to the java spec (20); Java does not allow, e.g., Integer i = 2; Float f = i; Note, that this is (nearly) never an issue about losing object identity: E.g., Integer x = 2; Integer y = 2; // x == y holds but, Integer x = 222; Integer y = 222; // x != y holds (tested in JDK 17) s.a. Java spec 20 5.1.7 Thus, unlike Java we allow Integer i = 2; Float f = i;, is a subTypeRelation analoge to unboxed primitives This method needs to be overridden if a more Java-conform check is required -
primitiveConstrainSubTypeOf
protected List<Bound> primitiveConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) -
tupleConstrainSubTypeOf
-
functionConstrainSubTypeOf
protected List<Bound> functionConstrainSubTypeOf(SymTypeOfFunction subFunc, SymTypeOfFunction superFunc) -
objectConstrainSubTypeOf
protected List<Bound> objectConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) whether one object is a subType of another this includes SymTypeOfObject, as well as SymTypeOfGenerics -
regExConstrainSubTypeOf
protected List<Bound> regExConstrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType) whether one type is the subType of another is if at least one of them is a SymTypeOfRegEx -
numericWithSIUnitConstrainSubTypeOf
protected List<Bound> numericWithSIUnitConstrainSubTypeOf(SymTypeOfNumericWithSIUnit subType, SymTypeOfNumericWithSIUnit superType) -
siUnitConstrainSubTypeOf
-
infVarConstrainSameType
-
intersectionConstrainSameType
protected List<Bound> intersectionConstrainSameType(SymTypeExpression typeA, SymTypeExpression typeB) -
unionConstrainSameType
-
arrayConstrainSameType
-
tupleConstrainSameType
-
functionConstrainSameType
-
numericWithSIUnitConstrainSameType
protected List<Bound> numericWithSIUnitConstrainSameType(SymTypeOfNumericWithSIUnit numericWithSIUnitA, SymTypeOfNumericWithSIUnit numericWithSIUnitB) -
siUnitConstrainSameType
-
regExConstrainSameType
-
objectConstrainSameType
-
wildcardConstrainSameType
-
constrainContainsPreNormalized
protected List<Bound> constrainContainsPreNormalized(SymTypeExpression subSetType, SymTypeExpression superSetType) Is the set of types denoted by subSetType a subSet of the set of types denoted by superSetType? s. Java spec 20 4.5.1, 4.10.2 A type variable represents multiple Types, in other cases, this is an identity check. s. a.typeSetConstrainSubTypeOf(de.monticore.types.check.SymTypeExpression, de.monticore.types.check.SymTypeExpression)The arguments are expected to be normalized. Additionally, type variables within other symTypes are currently not supported, this helper function (currently) is only to check subtyping of generics. Tuples could be extended in this regard (currently not needed).Fundamentally, T1 "contains" T2 (
"T2 <= T1") if the set of types denoted by T1 is (provably) a superSet of the types denoted by T2. This translates to the reflexive and transitive closure of (from spec):-
? extends T <= ? extends S if T <: S -
? extends T <= ? -
? super T <= ? super S if S <: T -
? super T <= ? -
? super T <= ? extends Object -
T <= T -
T <= ? extends T -
T <= ? super T
-
-
constrainSameTypeUsingSubTypeOf
protected List<Bound> constrainSameTypeUsingSubTypeOf(SymTypeExpression typeA, SymTypeExpression typeB) Reduces a constraint<a = b>to the constraints<a <: b>, <b <: a>. This is not necessarily ideal wrt. resulting messages, and should be replaced in the future if required. It will most likely result in incorrect values, iff any inference variables are present. -
getUnsatisfiableBoundForCompatibilty
protected UnsatisfiableBound getUnsatisfiableBoundForCompatibilty(SymTypeExpression targetType, SymTypeExpression sourceType) -
getUnsatisfiableBoundForSubTyping
protected UnsatisfiableBound getUnsatisfiableBoundForSubTyping(SymTypeExpression subType, SymTypeExpression superType) -
getUnsatisfiableBoundForSameType
protected UnsatisfiableBound getUnsatisfiableBoundForSameType(SymTypeExpression typeA, SymTypeExpression typeB) -
getUnsatisfiableBoundForContainment
protected UnsatisfiableBound getUnsatisfiableBoundForContainment(SymTypeExpression subSetType, SymTypeExpression superSetType) -
getSuperTypes
@Deprecated(forRemoval=true) protected List<SymTypeExpression> getSuperTypes(SymTypeExpression thisType) Deprecated, for removal: This API element is subject to removal in a future version. -
boxGenericButNotArguments
E.g.:List<List<int>> to java.util.List<List<int>> -
printBounds
-
constrainSubTypeOf(SymTypeExpression, SymTypeExpression)