ptolemy.data.type
Class StructuredType

java.lang.Object
  extended byptolemy.data.type.StructuredType
All Implemented Interfaces:
Type
Direct Known Subclasses:
ArrayType, FixType, FunctionType, RecordType, SizedMatrixType, TopMatrixType, UnsizedMatrixType

public abstract class StructuredType
extends java.lang.Object
implements Type

Base class for structured type. Making this an abstract class (not an interface) allows the methods to be protected. All the types of the same structured type (e.g. all the array types) must form a lattice. Each instance of a structured type must know how to compare itself with another instance of the same structured type, and compute the least upper bound and greatest lower bound. This class defines methods for these operations.

Subclasses should override clone() to do a deep cloning.

Since:
Ptolemy II 0.4
Version:
$Id: StructuredType.java,v 1.38 2004/04/13 03:22:32 cxh Exp $
Author:
Yuhong Xiong, Steve Neuendorffer
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (yuhong)

Field Summary
 
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID, HASH_MAX
 
Constructor Summary
StructuredType()
           
 
Method Summary
protected abstract  int _compare(StructuredType type)
          Compare this type with the specified type.
protected abstract  StructuredType _getRepresentative()
          Return a static instance of this structured type.
protected abstract  StructuredType _greatestLowerBound(StructuredType type)
          Return the greatest lower bound of this type with the specified type.
protected abstract  StructuredType _leastUpperBound(StructuredType type)
          Return the least upper bound of this type with the specified type.
abstract  java.lang.Object clone()
          Return a deep copy of this StructuredType.
 int getTypeHash()
          Return a perfect hash for this type.
abstract  void initialize(Type type)
          Set the elements that have declared type BaseType.UNKNOWN to the specified type.
abstract  void updateType(StructuredType newType)
          Update this StructuredType to the specified Structured Type.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ptolemy.data.type.Type
convert, equals, getTokenClass, isCompatible, isConstant, isInstantiable, isSubstitutionInstance, toString
 

Constructor Detail

StructuredType

public StructuredType()
Method Detail

clone

public abstract java.lang.Object clone()
                                throws java.lang.CloneNotSupportedException
Return a deep copy of this StructuredType.

Specified by:
clone in interface Type
Returns:
A StructuredType.
Throws:
java.lang.CloneNotSupportedException - Not thrown in this base class.

getTypeHash

public int getTypeHash()
Return a perfect hash for this type. This number corresponds uniquely to a particular type, and is used to improve performance of certain operations in the TypeLattice class. All instances of a particular type (e.g. integer array) must return the same number. Types that return HASH_INVALID will not have results in TypeLattice cached. Note that it is safer to return HASH_INVALID, than to return a number that is not unique, or different number for the same type from different instances. This base class returns HASH_INVALID.

Specified by:
getTypeHash in interface Type
Returns:
A number between 0 and HASH_MAX, or HASH_INVALID.

initialize

public abstract void initialize(Type type)
Set the elements that have declared type BaseType.UNKNOWN to the specified type.

Parameters:
type - A Type.

updateType

public abstract void updateType(StructuredType newType)
                         throws IllegalActionException
Update this StructuredType to the specified Structured Type. The specified type must have the same structure as this type. This method will only update the component type that is BaseType.UNKNOWN, and leave the constant part of this type intact.

Parameters:
newType - A StructuredType.
Throws:
IllegalActionException - If the specified type has a different structure.

_compare

protected abstract int _compare(StructuredType type)
Compare this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown. This method returns one of ptolemy.graph.CPO.LOWER, ptolemy.graph.CPO.SAME, ptolemy.graph.CPO.HIGHER, ptolemy.graph.CPO.INCOMPARABLE, indicating this type is lower than, equal to, higher than, or incomparable with the specified type in the type hierarchy, respectively.

Parameters:
type - a StructuredType.
Returns:
An integer.
Throws:
java.lang.IllegalArgumentException - If the specified type is not the same structured type as this one.

_getRepresentative

protected abstract StructuredType _getRepresentative()
Return a static instance of this structured type. The return value is used by TypeLattice to represent this type.

Returns:
a StructuredType.

_greatestLowerBound

protected abstract StructuredType _greatestLowerBound(StructuredType type)
Return the greatest lower bound of this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown.

Parameters:
type - a StructuredType.
Returns:
a StructuredType.
Throws:
java.lang.IllegalArgumentException - If the specified type is not the same structured type as this one.

_leastUpperBound

protected abstract StructuredType _leastUpperBound(StructuredType type)
Return the least upper bound of this type with the specified type. The specified type must be of the same structured type, otherwise an exception will be thrown.

Parameters:
type - a StructuredType.
Returns:
a StructuredType.
Throws:
java.lang.IllegalArgumentException - If the specified type is not the same structured type as this one.