Class SymTypeRelations
- java.lang.Object
-
- de.monticore.types3.SymTypeRelations
-
- Direct Known Subclasses:
SymTypeRelationsDefaultDelegatee
public abstract class SymTypeRelations extends java.lang.ObjectRelations of SymTypeExpressionssome are dependent on the specific type system and as such not hardcoded in the SymTypeExpressions themselves
Default implementation in
SymTypeRelationsDefaultDelegatee
-
-
Field Summary
Fields Modifier and Type Field Description protected static SymTypeRelationsdelegate
-
Constructor Summary
Constructors Constructor Description SymTypeRelations()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected abstract SymTypeExpression_box(SymTypeExpression unboxed)protected abstract java.util.List<Bound>_constrainCompatible(SymTypeExpression target, SymTypeExpression source)protected abstract java.util.List<Bound>_constrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)protected abstract java.util.List<Bound>_constrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)protected abstract java.util.List<SymTypeExpression>_getNominalSuperTypes(SymTypeExpression thisType)protected abstract java.util.List<Bound>_internal_constrainSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType)protected abstract boolean_isBoolean(SymTypeExpression type)protected abstract boolean_isBottom(SymTypeExpression type)protected abstract boolean_isByte(SymTypeExpression type)protected abstract boolean_isChar(SymTypeExpression type)protected abstract boolean_isCompatible(SymTypeExpression target, SymTypeExpression source)protected abstract boolean_isDouble(SymTypeExpression type)protected abstract boolean_isFloat(SymTypeExpression type)protected abstract boolean_isInt(SymTypeExpression type)protected abstract boolean_isIntegralType(SymTypeExpression type)protected abstract boolean_isLong(SymTypeExpression type)protected abstract boolean_isNumericType(SymTypeExpression type)protected abstract boolean_isShort(SymTypeExpression type)protected abstract boolean_isString(SymTypeExpression type)protected abstract boolean_isStringOrSubType(SymTypeExpression type)protected abstract boolean_isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)protected abstract boolean_isTop(SymTypeExpression type)protected abstract java.util.Optional<SymTypeExpression>_leastUpperBound(java.util.Collection<SymTypeExpression> types)protected abstract SymTypeExpression_normalize(SymTypeExpression type)protected abstract SymTypeExpression_numericPromotion(java.util.List<SymTypeExpression> types)protected abstract SymTypeExpression_unbox(SymTypeExpression boxed)static SymTypeExpressionbox(SymTypeExpression unboxed)Boxes SymTypeExpressions, including, but not limited to, Java primitive boxing e.g.,int -> java.lang.Integere.g.,List -> java.util.Liststatic java.util.List<Bound>constrainCompatible(SymTypeExpression target, SymTypeExpression source)Same asisCompatible(SymTypeExpression, SymTypeExpression), but returns the bounds on inference variables.static java.util.List<Bound>constrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)returns the list of Bounds on the free type variables, if the inputs are to be the same type.static java.util.List<Bound>constrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)Same asisSubTypeOf(SymTypeExpression, SymTypeExpression), but returns the bounds on inference variables.protected static SymTypeRelationsgetDelegate()static java.util.List<SymTypeExpression>getNominalSuperTypes(SymTypeExpression thisType)returns nominal supertypes.static voidinit()static java.util.List<Bound>internal_constrainSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType)Same asconstrainSubTypeOf(SymTypeExpression, SymTypeExpression), but the arguments are expected to have been normalized (seenormalize(SymTypeExpression)).static booleaninternal_isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft)Deprecated, for removal: This API element is subject to removal in a future version.use constrain* methods above.static booleaninternal_isSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft)Deprecated, for removal: This API element is subject to removal in a future version.Use constrain* methods above.static booleanisBoolean(SymTypeExpression type)static booleanisBottom(SymTypeExpression type)static booleanisByte(SymTypeExpression type)static booleanisChar(SymTypeExpression type)static booleanisCompatible(SymTypeExpression target, SymTypeExpression source)whether the target can be assigned to by the source, e.g., assignment operator: x = 2, type of x and type of 2 need to be compatible, e.g., function call:(float -> void)(2), float and type of 2 need to be compatible.static booleanisDouble(SymTypeExpression type)static booleanisFloat(SymTypeExpression type)static booleanisInt(SymTypeExpression type)static booleanisIntegralType(SymTypeExpression type)tests if the expression is of integral type, e.g., in Java: (long, int, char, short, byte)static booleanisLong(SymTypeExpression type)static booleanisNumericType(SymTypeExpression type)tests if the expression is of numeric type, e.g., in Java: (double, float, long, int, char, short, byte)static booleanisShort(SymTypeExpression type)static booleanisString(SymTypeExpression type)This is most likely NOT the method you need; This returns whether the type is _exactly_ String.static booleanisStringOrSubType(SymTypeExpression type)static booleanisSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)Whether subType is the sub-type of superType, Examples: isSubType(Person, Person) isSubType(Student, Person) !isSubType(Person, Student) isSubType(int, float) !isSubType(float, int)static booleanisTop(SymTypeExpression type)static java.util.Optional<SymTypeExpression>leastUpperBound(SymTypeExpression... types)static java.util.Optional<SymTypeExpression>leastUpperBound(java.util.Collection<SymTypeExpression> types)least upper bound for a set of types DISREGARDING the union of the types; The least upper bound for a set of types is always the union of the same, this will create the least upper bound that is not the union.static SymTypeExpressionnormalize(SymTypeExpression type)normalizes the SymTypeExpression, e.g.,(A & B[])[] -> (A[] & B[][])static SymTypeExpressionnumericPromotion(SymTypeExpression... types)static SymTypeExpressionnumericPromotion(java.util.List<SymTypeExpression> types)calculates the one promoted numeric type, ignoring the specifics of the context s.static voidreset()protected static voidsetDelegate(SymTypeRelations newDelegate)static SymTypeExpressionunbox(SymTypeExpression boxed)Unboxes SymTypeExpressions, including, but not limited to, Java primitive unboxing e.g.,java.lang.Integer -> inte.g.,java.util.List -> List
-
-
-
Field Detail
-
delegate
protected static SymTypeRelations delegate
-
-
Method Detail
-
isCompatible
public static boolean isCompatible(SymTypeExpression target, SymTypeExpression source)
whether the target can be assigned to by the source, e.g., assignment operator: x = 2, type of x and type of 2 need to be compatible, e.g., function call:(float -> void)(2), float and type of 2 need to be compatible.
-
_isCompatible
protected abstract boolean _isCompatible(SymTypeExpression target, SymTypeExpression source)
-
isSubTypeOf
public static boolean isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
Whether subType is the sub-type of superType, Examples: isSubType(Person, Person) isSubType(Student, Person) !isSubType(Person, Student) isSubType(int, float) !isSubType(float, int)
-
_isSubTypeOf
protected abstract boolean _isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
-
getNominalSuperTypes
public static java.util.List<SymTypeExpression> getNominalSuperTypes(SymTypeExpression thisType)
returns nominal supertypes. Nominal supertypes are those that are explicitly listed as super types, e.g., in Java those specified using "extends" or "implements". The return value is neither the reflexive nor the transitive closure, i.e., only the direct supertypes are included (s. Java spec 20 4.10). Note that the "direct" supertype-relation is deliberately underspecified, such that it can be refined according to the specific type system's needs.
-
_getNominalSuperTypes
protected abstract java.util.List<SymTypeExpression> _getNominalSuperTypes(SymTypeExpression thisType)
-
leastUpperBound
public static java.util.Optional<SymTypeExpression> leastUpperBound(java.util.Collection<SymTypeExpression> types)
least upper bound for a set of types DISREGARDING the union of the types; The least upper bound for a set of types is always the union of the same, this will create the least upper bound that is not the union.For, e.g., union types unlike the Java counterpart, we specify it for non-reference types as well, making it more akin to Java conditional expressions, where "a?b:c" has type leastUpperBound(b,c)
todo should just return top? todo need to rename to e.g. simplifiedLeastUpperBound https://git.rwth-aachen.de/monticore/monticore/-/issues/4187 empty represents the universal type (aka the lack of a bound) Obscure is returned, if no lub could be calculated, e.g. lub(int, Person)
-
leastUpperBound
public static java.util.Optional<SymTypeExpression> leastUpperBound(SymTypeExpression... types)
-
_leastUpperBound
protected abstract java.util.Optional<SymTypeExpression> _leastUpperBound(java.util.Collection<SymTypeExpression> types)
-
box
public static SymTypeExpression box(SymTypeExpression unboxed)
Boxes SymTypeExpressions, including, but not limited to, Java primitive boxing e.g.,int -> java.lang.Integere.g.,List -> java.util.List
-
_box
protected abstract SymTypeExpression _box(SymTypeExpression unboxed)
-
unbox
public static SymTypeExpression unbox(SymTypeExpression boxed)
Unboxes SymTypeExpressions, including, but not limited to, Java primitive unboxing e.g.,java.lang.Integer -> inte.g.,java.util.List -> List
-
_unbox
protected abstract SymTypeExpression _unbox(SymTypeExpression boxed)
-
normalize
public static SymTypeExpression normalize(SymTypeExpression type)
normalizes the SymTypeExpression, e.g.,(A & B[])[] -> (A[] & B[][])Within our type systems, each type has ONE normalized representation. This can be used to, e.g., compare SymTypeExpressions
-
_normalize
protected abstract SymTypeExpression _normalize(SymTypeExpression type)
-
numericPromotion
public static SymTypeExpression numericPromotion(java.util.List<SymTypeExpression> types)
calculates the one promoted numeric type, ignoring the specifics of the context s. Java spec. 20 5.6 e.g.,short -> inte.g.,byte, float -> float
-
_numericPromotion
protected abstract SymTypeExpression _numericPromotion(java.util.List<SymTypeExpression> types)
-
numericPromotion
public static SymTypeExpression numericPromotion(SymTypeExpression... types)
-
isNumericType
public static boolean isNumericType(SymTypeExpression type)
tests if the expression is of numeric type, e.g., in Java: (double, float, long, int, char, short, byte)
-
_isNumericType
protected abstract boolean _isNumericType(SymTypeExpression type)
-
isIntegralType
public static boolean isIntegralType(SymTypeExpression type)
tests if the expression is of integral type, e.g., in Java: (long, int, char, short, byte)
-
_isIntegralType
protected abstract boolean _isIntegralType(SymTypeExpression type)
-
isBoolean
public static boolean isBoolean(SymTypeExpression type)
-
_isBoolean
protected abstract boolean _isBoolean(SymTypeExpression type)
-
isInt
public static boolean isInt(SymTypeExpression type)
-
_isInt
protected abstract boolean _isInt(SymTypeExpression type)
-
isDouble
public static boolean isDouble(SymTypeExpression type)
-
_isDouble
protected abstract boolean _isDouble(SymTypeExpression type)
-
isFloat
public static boolean isFloat(SymTypeExpression type)
-
_isFloat
protected abstract boolean _isFloat(SymTypeExpression type)
-
isLong
public static boolean isLong(SymTypeExpression type)
-
_isLong
protected abstract boolean _isLong(SymTypeExpression type)
-
isChar
public static boolean isChar(SymTypeExpression type)
-
_isChar
protected abstract boolean _isChar(SymTypeExpression type)
-
isShort
public static boolean isShort(SymTypeExpression type)
-
_isShort
protected abstract boolean _isShort(SymTypeExpression type)
-
isByte
public static boolean isByte(SymTypeExpression type)
-
_isByte
protected abstract boolean _isByte(SymTypeExpression type)
-
isString
public static boolean isString(SymTypeExpression type)
This is most likely NOT the method you need; This returns whether the type is _exactly_ String. In most cases, you want to check whether the type is either compatible to, or a subtype of String. You may want to useisStringOrSubType(SymTypeExpression)instead.
-
_isString
protected abstract boolean _isString(SymTypeExpression type)
-
isStringOrSubType
public static boolean isStringOrSubType(SymTypeExpression type)
- Parameters:
type- the SymTypeExpression to check- Returns:
- whether it is a String (boxed or unboxed) or a subtype (e.g., a RegEx)
-
_isStringOrSubType
protected abstract boolean _isStringOrSubType(SymTypeExpression type)
-
isTop
public static boolean isTop(SymTypeExpression type)
-
_isTop
protected abstract boolean _isTop(SymTypeExpression type)
-
isBottom
public static boolean isBottom(SymTypeExpression type)
-
_isBottom
protected abstract boolean _isBottom(SymTypeExpression type)
-
constrainCompatible
public static java.util.List<Bound> constrainCompatible(SymTypeExpression target, SymTypeExpression source)
Same asisCompatible(SymTypeExpression, SymTypeExpression), but returns the bounds on inference variables.
-
_constrainCompatible
protected abstract java.util.List<Bound> _constrainCompatible(SymTypeExpression target, SymTypeExpression source)
-
constrainSubTypeOf
public static java.util.List<Bound> constrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
Same asisSubTypeOf(SymTypeExpression, SymTypeExpression), but returns the bounds on inference variables.
-
_constrainSubTypeOf
protected abstract java.util.List<Bound> _constrainSubTypeOf(SymTypeExpression subType, SymTypeExpression superType)
-
internal_constrainSubTypeOfPreNormalized
public static java.util.List<Bound> internal_constrainSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType)
Same asconstrainSubTypeOf(SymTypeExpression, SymTypeExpression), but the arguments are expected to have been normalized (seenormalize(SymTypeExpression)). This is required to not create infinite loops during normalization.
-
_internal_constrainSubTypeOfPreNormalized
protected abstract java.util.List<Bound> _internal_constrainSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType)
-
constrainSameType
public static java.util.List<Bound> constrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)
returns the list of Bounds on the free type variables, if the inputs are to be the same type. Due to union/intersection types, this cannot (trivially/at all?) be replaced with constraining the subtyping relationship in both directions and collecting the bounds.
-
_constrainSameType
protected abstract java.util.List<Bound> _constrainSameType(SymTypeExpression typeA, SymTypeExpression typeB)
-
internal_isSubTypeOf
@Deprecated(forRemoval=true) public static boolean internal_isSubTypeOf(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft)
Deprecated, for removal: This API element is subject to removal in a future version.use constrain* methods above.
-
internal_isSubTypeOfPreNormalized
@Deprecated(forRemoval=true) public static boolean internal_isSubTypeOfPreNormalized(SymTypeExpression subType, SymTypeExpression superType, boolean subTypeIsSoft)
Deprecated, for removal: This API element is subject to removal in a future version.Use constrain* methods above.
-
init
public static void init()
-
reset
public static void reset()
-
setDelegate
protected static void setDelegate(SymTypeRelations newDelegate)
-
getDelegate
protected static SymTypeRelations getDelegate()
-
-