Package ptolemy.data.type
Class StructuredType
- java.lang.Object
-
- ptolemy.data.type.StructuredType
-
- All Implemented Interfaces:
Type
- Direct Known Subclasses:
ArrayType
,AssociativeType
,ConceptType
,FixType
,FunctionType
,MatrixType
,ObjectType
,TupleType
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$
- Author:
- Yuhong Xiong, Steve Neuendorffer
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (yuhong)
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
MAXDEPTHBOUND
Set up a bound for the max depth of structured types.-
Fields inherited from interface ptolemy.data.type.Type
HASH_INVALID
-
-
Constructor Summary
Constructors Constructor Description StructuredType()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.Type
add(Type rightArgumentType)
Return a new type which represents the type that results from adding a token of this type and a token of the given argument type.abstract java.lang.Object
clone()
Return a deep copy of this StructuredType.int
depth()
Return the depth of a structured type.Type
divide(Type rightArgumentType)
Return a new type which represents the type that results from dividing a token of this type and a token of the given argument type.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.boolean
isAbstract()
Return true if this type does not correspond to a single token class.Type
modulo(Type rightArgumentType)
Return a new type which represents the type that results from moduloing a token of this type and a token of the given argument type.Type
multiply(Type rightArgumentType)
Return a new type which represents the type that results from multiplying a token of this type and a token of the given argument type.Type
one()
Return the type of the multiplicative identity for elements of this type.Type
subtract(Type rightArgumentType)
Return a new type which represents the type that results from subtracting a token of this type and a token of the given argument type.void
updateType(StructuredType newType)
Update this StructuredType to the specified Structured Type.Type
zero()
Return the type of the additive identity for elements of this 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
-
-
-
-
Field Detail
-
MAXDEPTHBOUND
protected static final int MAXDEPTHBOUND
Set up a bound for the max depth of structured types. This bound is used to detect infinite iterations.- See Also:
- Constant Field Values
-
-
Method Detail
-
add
public Type add(Type rightArgumentType)
Return a new type which represents the type that results from adding a token of this type and a token of the given argument type.
-
clone
public abstract java.lang.Object clone() throws java.lang.CloneNotSupportedException
Return a deep copy of this StructuredType.
-
divide
public Type divide(Type rightArgumentType)
Return a new type which represents the type that results from dividing a token of this type and a token of the given argument type.
-
depth
public int depth()
Return the depth of a structured type. The depth of a structured type is the number of times a structured type contains other structured types. For example, an array of arrays has depth 2, and an array of arrays of records has depth 3.- Returns:
- the depth of a structured type.
-
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 interfaceType
- Returns:
- A number greater than or equal to 0, or HASH_INVALID.
-
isAbstract
public boolean isAbstract()
Return true if this type does not correspond to a single token class. This occurs if the type is not instantiable, or it represents either an abstract base class or an interface. This method should be overridden in derived classes to return true only for types which are not abstract.- Specified by:
isAbstract
in interfaceType
- Returns:
- true.
-
initialize
public abstract void initialize(Type type)
Set the elements that have declared type BaseType.UNKNOWN to the specified type.- Parameters:
type
- A Type.
-
modulo
public Type modulo(Type rightArgumentType)
Return a new type which represents the type that results from moduloing a token of this type and a token of the given argument type.
-
multiply
public Type multiply(Type rightArgumentType)
Return a new type which represents the type that results from multiplying a token of this type and a token of the given argument type.
-
one
public Type one()
Return the type of the multiplicative identity for elements of this type.
-
subtract
public Type subtract(Type rightArgumentType)
Return a new type which represents the type that results from subtracting a token of this type and a token of the given argument type.
-
updateType
public void updateType(StructuredType newType) throws IllegalActionException
Update this StructuredType to the specified Structured Type. The specified type must have depth less than the MAXDEPTHBOUND, and 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.
-
zero
public Type zero()
Return the type of the additive identity for elements of this type.
-
_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.
-
-