Class TypeLattice


  • public class TypeLattice
    extends java.lang.Object
    Type hierarchy for token classes.

    There is exactly one instance of the type lattice. It is constructed once and then does not change during execution. A concurrent hash table is used to cache type comparison results to optimize for frequently occurring type comparisons.

    The Java Language Spec, 3rd ed. says:

    "The integral types are byte, short, int, and long, whose values are 8-bit, 16-bit, 32-bit and 64-bit signed two's-complement integers, respectively, and char, whose values are 16-bit unsigned integers representing UTF-16 code units (3.1). The floating-point types are float, whose values include the 32-bit IEEE 754 floating-point numbers, and double, whose values include the 64-bit IEEE 754 floating-point numbers"
    Thus,
  • 16-bit shorts are not losslessly convertable into 16-bit chars (unsigned integers).
  • 32-bit ints are not losslessly convertable into 32-bit floats.
  • 64-bit longs are not losslessly convertable into 64-bit doubles.
  • Since:
    Ptolemy II 0.4
    Version:
    $Id$
    Author:
    Yuhong Xiong, Steve Neuendorffer, Marten Lohstroh
    See Also:
    CPO
    Pt.AcceptedRating:
    Red
    Pt.ProposedRating:
    Red (yuhong)
    • Constructor Summary

      Constructors 
      Constructor Description
      TypeLattice()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static CPO basicLattice()
      Return the an instance of CPO representing the basic type lattice.
      static int compare​(Token token1, Token token2)
      Compare the types of the two specified tokens in the type lattice.
      static int compare​(Token token, Type type)
      Compare the types of the two specified tokens in the type lattice.
      static int compare​(Type type, Token token)
      Compare the types of the two specified tokens in the type lattice.
      static int compare​(Type type1, Type type2)
      Compare two types in the type lattice.
      static CPO lattice()
      Return the an instance of CPO representing the infinite type lattice.
      static Type leastUpperBound​(Type type1, Type type2)
      Return the least upper bound of the two given types.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TypeLattice

        public TypeLattice()
    • Method Detail

      • basicLattice

        public static CPO basicLattice()
        Return the an instance of CPO representing the basic type lattice.
        Returns:
        an instance of CPO.
      • compare

        public static int compare​(Token token1,
                                  Token token2)
        Compare the types of the two specified tokens in the type lattice. This method returns one of ptolemy.graph.CPO.LOWER, ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating the the type of the first argument is lower than, equal to, higher than, or incomparable with that of the second in the type hierarchy, respectively.
        Parameters:
        token1 - a Token.
        token2 - a Token.
        Returns:
        An integer.
      • compare

        public static int compare​(Token token,
                                  Type type)
        Compare the types of the two specified tokens in the type lattice. This method returns one of ptolemy.graph.CPO.LOWER, ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating the the type of the first argument is lower than, equal to, higher than, or incomparable with that of the second in the type hierarchy, respectively.
        Parameters:
        token - a Token.
        type - a Type.
        Returns:
        An integer.
      • compare

        public static int compare​(Type type,
                                  Token token)
        Compare the types of the two specified tokens in the type lattice. This method returns one of ptolemy.graph.CPO.LOWER, ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating the the type of the first argument is lower than, equal to, higher than, or incomparable with that of the second in the type hierarchy, respectively.
        Parameters:
        token - a Token.
        type - a Type.
        Returns:
        An integer.
      • compare

        public static int compare​(Type type1,
                                  Type type2)
        Compare two types in the type lattice. This method returns one of ptolemy.graph.CPO.LOWER, ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating the first argument is lower than, equal to, higher than, or incomparable with the second argument in the type hierarchy, respectively.
        Parameters:
        type1 - an instance of Type.
        type2 - an instance of Type.
        Returns:
        An integer.
      • lattice

        public static CPO lattice()
        Return the an instance of CPO representing the infinite type lattice.
        Returns:
        an instance of CPO.
      • leastUpperBound

        public static Type leastUpperBound​(Type type1,
                                           Type type2)
        Return the least upper bound of the two given types.
        Parameters:
        type1 - The first given type.
        type2 - The second given type.
        Returns:
        The least upper bound of type1 and type2.