ptolemy.data.type
Class TypeLattice

java.lang.Object
  extended by ptolemy.data.type.TypeLattice

public class TypeLattice
extends java.lang.Object

Type hierarchy for token classes. Note that all public methods are static and synchronized. There is exactly one instance of the type lattice. Although the type lattice is constructed once and then typically does not change during execution, the methods need to be synchronized because there are various data structures used to cache results that are expensive to compute. These data structures do change during execution. Multiple threads may be accessing the type lattice simultaneously and modifying these data structures. To ensure thread safety, the methods need to be synchronized.

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 lossly convertable into 16-bit chars (unsigned integers).
  • 32-bit ints are not lossly convertable into 32-bit floats.
  • 64-bit longs are not lossly convertable into 64-bit doubles.
  • Since:
    Ptolemy II 0.4
    Version:
    $Id: TypeLattice.java 59167 2010-09-21 17:08:02Z cxh $
    Author:
    Yuhong Xiong, Steve Neuendorffer
    See Also:
    CPO
    Accepted Rating:
    Red
    Proposed Rating:
    Red (yuhong)

    Nested Class Summary
    private static class TypeLattice.TheTypeLattice
               
     
    Field Summary
    private static int[][] _compareCache
              The result cache for parts of the type lattice.
    private static TypeLattice.TheTypeLattice _lattice
              The infinite type lattice.
     
    Constructor Summary
    TypeLattice()
               
     
    Method Summary
    private static int _getCachedTypeComparisonResult(int index1, int index2)
              Return the result for the types that have the given two indexes as hashes.
    private static void _setCachedTypeComparisonResult(int index1, int index2, int value)
              Set the result for the types that have the given two indexes as hashes.
    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
     

    Field Detail

    _lattice

    private static TypeLattice.TheTypeLattice _lattice
    The infinite type lattice.


    _compareCache

    private static int[][] _compareCache
    The result cache for parts of the type lattice.

    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.

    _getCachedTypeComparisonResult

    private static final int _getCachedTypeComparisonResult(int index1,
                                                            int index2)
    Return the result for the types that have the given two indexes as hashes.


    _setCachedTypeComparisonResult

    private static final void _setCachedTypeComparisonResult(int index1,
                                                             int index2,
                                                             int value)
    Set the result for the types that have the given two indexes as hashes.