Class TypeSet


  • public class TypeSet
    extends Object
    A union of the types a value may hold, flagged complete when the members are exact and incomplete when subtypes may also occur.
    • Constructor Detail

      • TypeSet

        public TypeSet()
        Creates an empty, complete type set.
      • TypeSet

        public TypeSet​(IRType singleType)
        Creates a set holding one type, or an empty set if it is null.
        Parameters:
        singleType - the sole member, may be null
      • TypeSet

        public TypeSet​(Collection<? extends IRType> types)
        Creates a set holding the given types.
        Parameters:
        types - the initial members
    • Method Detail

      • allSubtypesOf

        public static TypeSet allSubtypesOf​(IRType type)
        Creates an incomplete set rooted at the given type, standing for it and all its subtypes.
        Parameters:
        type - the root type
        Returns:
        the incomplete set
      • addType

        public void addType​(IRType type)
        Adds a type, ignoring null.
        Parameters:
        type - the type to add, may be null
      • removeType

        public void removeType​(IRType type)
        Removes a type.
        Parameters:
        type - the type to remove
      • getTypes

        public Set<IRType> getTypes()
        Returns:
        an unmodifiable view of the members
      • size

        public int size()
        Returns:
        the number of members
      • isEmpty

        public boolean isEmpty()
        Returns:
        true when there are no members
      • isSingleton

        public boolean isSingleton()
        Returns:
        true when there is exactly one member
      • getSingleType

        public IRType getSingleType()
        Returns the sole member of a singleton set.
        Returns:
        the only member
        Throws:
        IllegalStateException - if the set does not hold exactly one type
      • getAnyType

        public IRType getAnyType()
        Returns an arbitrary member to stand in for the set.
        Returns:
        a member, or null when the set is empty
      • contains

        public boolean contains​(IRType type)
        Tests membership.
        Parameters:
        type - the type to look for
        Returns:
        true when the type is a member
      • isComplete

        public boolean isComplete()
        Returns:
        true when the members are exact, false when subtypes may also occur
      • setIncomplete

        public void setIncomplete()
        Marks the set as possibly including subtypes of its members.
      • join

        public TypeSet join​(TypeSet other)
        Unions two sets; the result is complete only when both operands are.
        Parameters:
        other - the set to union with
        Returns:
        a new set holding the union
      • meet

        public TypeSet meet​(TypeSet other)
        Intersects two sets; the result is complete when either operand is.
        Parameters:
        other - the set to intersect with
        Returns:
        a new set holding the intersection
      • getLeastUpperBound

        public IRType getLeastUpperBound()
        Computes the least upper bound, collapsing any mix of reference types to Object.
        Returns:
        the sole member when singleton, Object when all members are references, null when the set is empty or mixes primitives
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object