Class SymTypeRelations

  • Direct Known Subclasses:
    SymTypeRelationsDefaultDelegatee

    public abstract class SymTypeRelations
    extends java.lang.Object
    Relations of SymTypeExpressions

    some are dependent on the specific type system and as such not hardcoded in the SymTypeExpressions themselves

    Default implementation in SymTypeRelationsDefaultDelegatee

    • Constructor Detail

      • SymTypeRelations

        public SymTypeRelations()
    • 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.
      • 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)
      • 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.
      • 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)

      • box

        public static SymTypeExpression box​(SymTypeExpression unboxed)
        Boxes SymTypeExpressions, including, but not limited to, Java primitive boxing e.g., int -> java.lang.Integer e.g., List -> java.util.List
      • unbox

        public static SymTypeExpression unbox​(SymTypeExpression boxed)
        Unboxes SymTypeExpressions, including, but not limited to, Java primitive unboxing e.g., java.lang.Integer -> int e.g., java.util.List -> List
      • 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

      • 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 -> int e.g., byte, float -> float
      • 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)
      • 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 use isStringOrSubType(SymTypeExpression) instead.
      • 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)
      • 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.
      • 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)