scale.clef.type
Class Type

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.type.Type
All Implemented Interfaces:
AnnotationInterface, DisplayNode
Direct Known Subclasses:
AtomicType, CompositeType, IncompleteType, ProcedureType, RefType, VoidType

public abstract class Type
extends Node

This class is the root class for type nodes.

$Id: Type.java,v 1.104 2007-08-27 18:13:32 burrill Exp $

Copyright 2007 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

A type is represented by a graph (DAG) of type nodes.

The current list of special case nodes is as follows:

Note: types are unique! There is only one instance of any specific type. Types are created using a static create method. The new operator is not used. However, the IncompleteType is not unique and is created using new because it must be modified after it is created.

Types should not have annotations unless the annotation applies to every instance where the type may be used.


Constructor Summary
Type()
           
 
Method Summary
abstract  int alignment(Machine machine)
          Calculate the alignment needed for this data type.
 boolean canBeInRegister()
          True if values of this type can be placed in a register.
static void cleanup()
          Remove static lists of types.
 long elementSize(Machine machine)
          Return the number of addressable memory units are needed to represent an element of the type.
abstract  boolean equivalent(Type t)
          Return true if the types are equivalent.
 Type getCompleteType()
          Return the completed type or null if it is not complete.
 Type getCoreType()
          This method filters out some of the special case type nodes from a type DAG.
 DColor getDisplayColorHint()
          Return a String specifying the color to use for coloring this node in a graphical display.
 java.lang.String getDisplayLabel()
          Return a String suitable for labeling this node in a graphical display.
 DShape getDisplayShapeHint()
          Return a String specifying a shape to use when drawing this node in a graphical display.
protected  Type getEquivalentType()
          Return the type to be used by the equivalence method.
 Type getNonAttributeType()
          Return the type without any attributes such as "const".
 Type getNonConstType()
          Return the type without any "const" attributes.
 Type getPointedTo()
          Return the type of the thing pointed to.
 Type getPointedToCore()
          Return the type of the thing pointed to.
 int getRank()
          Return the rank of the type.
 Type getSignedType()
          Return the equivalent signed type of the core type.
 int getTag()
          Return the tag associated with this variable.
 Type getType()
          Return the Type associated with this Node.
 boolean isAggregateType()
          Return true if type represents an aggregate object.
 boolean isAllocArrayType()
          Return true if type represents an array whose dimensions are not known at compile time.
 boolean isArrayType()
          Return true if type represents an array.
 boolean isAtomicType()
          Return true if type represents an atomic type.
 boolean isAttributeSet(RefAttr attribute)
          Return true if the attribute is associated with this type.
 boolean isBooleanType()
          Return true if type represents a boolean type.
 boolean isCharacterType()
          Return true if type represents a character type.
 boolean isClassType()
          Return true if type represents a class type.
 boolean isComplexType()
          Return true if type represents a complex value.
 boolean isCompositeType()
          Return true if type represents a composite type.
 boolean isConst()
          Return true if the type specifies const.
 boolean isEnumerationType()
          Return true if type represents an enumeration value.
 boolean isFixedArrayType()
          Return true if type represents an array whose dimensions are known at compile time.
 boolean isFloatType()
          Return true if type represents a character type.
 boolean isFortranCharType()
          Return true if type represents a Fortran CHARACTER type.
 boolean isIncompleteType()
          Return true if type represents an incomplete type.
 boolean isIntegerType()
          Return true if type represents an integer value.
 boolean isNamedType()
          Return true if this type has an associated TypeDecl or TypeName.
 boolean isNumericType()
          Return true if type represents a numeric type.
 boolean isPointerType()
          Return true if type represents an address.
 boolean isProcedureType()
          Return true if this type represents a procedure.
 boolean isRealType()
          Return true if type represents a floating point value.
 boolean isRefType()
          Return true if type represents a reference type.
 boolean isRestricted()
          Return true if the type specifies restricted.
 boolean isSigned()
          Return true if the type is signed.
 boolean isUnionType()
          Return true if type represents a union.
 boolean isVoidType()
          Return true if type represents no type.
 boolean isVolatile()
          Return true if the type specifies volatile.
 java.lang.String mapTypeToCString()
          Map a type to a C string.
 java.lang.String mapTypeToF77String()
          Map a type to a Fortran string.
abstract  long memorySize(Machine machine)
          Return the number of addressable memory units that are needed to represent the type.
 int memorySizeAsInt(Machine machine)
          Calculate how many addressable memory units that are needed to represent the type.
static void nextVisit()
          Set up for a new traversal - that is, use the next color value.
 long numberOfElements()
          Return the number of elements represented by this type.
 int precedence()
          Return a precedence value for types.
 Type registerType()
          Return the type to use if a variable of this type is in a register.
 AggregateType returnAggregateType()
          Return if this is a AggregateType, return this.
 AllocArrayType returnAllocArrayType()
          Return if this is a AllocArrayType, return this.
 ArrayType returnArrayType()
          Return if this is a ArrayType return this.
 AtomicType returnAtomicType()
          Return if this is a AtomicType return this.
 BooleanType returnBooleanType()
          Return if this is a BooleanType return this.
 CharacterType returnCharacterType()
          Return if this is a CharacterType, return this.
 ComplexType returnComplexType()
          Return if this is a ComplexType return this.
 CompositeType returnCompositeType()
          Return if this is a CompositeType, return this.
 EnumerationType returnEnumerationType()
          Return if this is a EnumerationType, return this.
 FixedArrayType returnFixedArrayType()
          Return if this is a FixedArrayType, return this.
 FloatType returnFloatType()
          Return if this is a FloatType return this.
 FortranCharType returnFortranCharType()
          Return if this is a FortranCharType, return this.
 IncompleteType returnIncompleteType()
          Return if this is a IncompleteType, return this.
 IntegerType returnIntegerType()
          Return if this is a IntegerType return this.
 NumericType returnNumericType()
          Return if this is a NumericType return this.
 PointerType returnPointerType()
          Return if this is a PointerType return this.
 ProcedureType returnProcedureType()
          Return if this is a ProcedureType, return this.
 RealType returnRealType()
          Return if this is a RealType, return this.
 RecordType returnRecordType()
          Return if this is a RecordType return this.
 RefType returnRefType()
          Return if this is a RefType, return this.
 SignedIntegerType returnSignedIntegerType()
          Return if this is a SignedIntegerType, return this.
 UnionType returnUnionType()
          Return if this is a UnionType return this.
 UnsignedIntegerType returnUnsignedIntegerType()
          Return if this is a UnsignedIntegerType, return this.
 VoidType returnVoidType()
          Return if this is a VoidType, return this.
 void setTag(int tag)
          Set the tag for this variable.
 void setVisited()
          Associate the current color value with this Type.
 void specifyCanBeInRegister(boolean canBeInRegister)
          Specify that values of this type can be placed in a register.
 java.lang.String toString()
           
 java.lang.String toStringShort()
           
 void visit(Predicate p)
          Process a node by calling its associated routine.
 void visit(TypePredicate p)
          Process a node by calling its associated routine.
 boolean visited()
          Return true if this Type has been visited during the current visit (i.e., is the current color).
 
Methods inherited from class scale.clef.Node
getChild, getDecl, getSourceLineNumber, numChildren, setAnnotationLevel, setReportLevel, setSourceLineNumber, toString, toStringChildren, toStringSpecial
 
Methods inherited from class scale.common.Root
addAnnotation, allAnnotations, allMatchingAnnotations, getAnnotation, getDisplayName, getDisplayString, getNodeCount, getNodeID, hasAnnotation, hasEqualAnnotation, hashCode, removeAnnotation, removeAnnotations, toStringAnnotations, toStringClass, trace, trace, trace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Type

public Type()
Method Detail

nextVisit

public static void nextVisit()
Set up for a new traversal - that is, use the next color value. This color is used to mark types in spanning algorithms.

See Also:
setVisited(), visited(), nextVisit()

setVisited

public void setVisited()
Associate the current color value with this Type. The color is for the use of spanning algorithms.

See Also:
nextVisit(), visited()

visited

public final boolean visited()
Return true if this Type has been visited during the current visit (i.e., is the current color).

See Also:
nextVisit(), setVisited()

setTag

public final void setTag(int tag)
Set the tag for this variable. The tag can be used by various algorithms.


getTag

public final int getTag()
Return the tag associated with this variable. The tag can be used by various algorithms.


specifyCanBeInRegister

public final void specifyCanBeInRegister(boolean canBeInRegister)
Specify that values of this type can be placed in a register.


canBeInRegister

public final boolean canBeInRegister()
True if values of this type can be placed in a register. This will return false unless the specifyCanBeInRegister() method has been called for the type instance. (See the code in scale.backend.Generator#processCoreType().)


toString

public java.lang.String toString()
Overrides:
toString in class Node

toStringShort

public java.lang.String toStringShort()

getDisplayLabel

public java.lang.String getDisplayLabel()
Return a String suitable for labeling this node in a graphical display. This method should be over-ridden as it simplay returns the class name.

Specified by:
getDisplayLabel in interface DisplayNode
Overrides:
getDisplayLabel in class Root

getDisplayColorHint

public DColor getDisplayColorHint()
Return a String specifying the color to use for coloring this node in a graphical display. This method should be over-ridden as it simplay returns the color red.

Specified by:
getDisplayColorHint in interface DisplayNode
Overrides:
getDisplayColorHint in class Root
See Also:
DColor

getDisplayShapeHint

public DShape getDisplayShapeHint()
Return a String specifying a shape to use when drawing this node in a graphical display. This method should be over-ridden as it simplay returns the shape "ellipse".

Specified by:
getDisplayShapeHint in interface DisplayNode
Overrides:
getDisplayShapeHint in class Root
See Also:
DShape

returnAggregateType

public AggregateType returnAggregateType()
Return if this is a AggregateType, return this. Otherwise, return null.


returnAllocArrayType

public AllocArrayType returnAllocArrayType()
Return if this is a AllocArrayType, return this. Otherwise, return null.


returnArrayType

public ArrayType returnArrayType()
Return if this is a ArrayType return this. Otherwise, return null.


returnAtomicType

public AtomicType returnAtomicType()
Return if this is a AtomicType return this. Otherwise, return null.


returnBooleanType

public BooleanType returnBooleanType()
Return if this is a BooleanType return this. Otherwise, return null.


returnCharacterType

public CharacterType returnCharacterType()
Return if this is a CharacterType, return this. Otherwise, return null.


returnComplexType

public ComplexType returnComplexType()
Return if this is a ComplexType return this. Otherwise, return null.


returnCompositeType

public CompositeType returnCompositeType()
Return if this is a CompositeType, return this. Otherwise, return null.


returnEnumerationType

public EnumerationType returnEnumerationType()
Return if this is a EnumerationType, return this. Otherwise, return null.


returnFixedArrayType

public FixedArrayType returnFixedArrayType()
Return if this is a FixedArrayType, return this. Otherwise, return null.


returnFloatType

public FloatType returnFloatType()
Return if this is a FloatType return this. Otherwise, return null.


returnFortranCharType

public FortranCharType returnFortranCharType()
Return if this is a FortranCharType, return this. Otherwise, return null.


returnIncompleteType

public IncompleteType returnIncompleteType()
Return if this is a IncompleteType, return this. Otherwise, return null.


returnIntegerType

public IntegerType returnIntegerType()
Return if this is a IntegerType return this. Otherwise, return null.


returnNumericType

public NumericType returnNumericType()
Return if this is a NumericType return this. Otherwise, return null.


returnPointerType

public PointerType returnPointerType()
Return if this is a PointerType return this. Otherwise, return null.


returnProcedureType

public ProcedureType returnProcedureType()
Return if this is a ProcedureType, return this. Otherwise, return null.


returnRealType

public RealType returnRealType()
Return if this is a RealType, return this. Otherwise, return null.


returnRecordType

public RecordType returnRecordType()
Return if this is a RecordType return this. Otherwise, return null.


returnRefType

public RefType returnRefType()
Return if this is a RefType, return this. Otherwise, return null.


returnSignedIntegerType

public SignedIntegerType returnSignedIntegerType()
Return if this is a SignedIntegerType, return this. Otherwise, return null.


returnUnionType

public UnionType returnUnionType()
Return if this is a UnionType return this. Otherwise, return null.


returnUnsignedIntegerType

public UnsignedIntegerType returnUnsignedIntegerType()
Return if this is a UnsignedIntegerType, return this. Otherwise, return null.


returnVoidType

public VoidType returnVoidType()
Return if this is a VoidType, return this. Otherwise, return null.


isArrayType

public boolean isArrayType()
Return true if type represents an array.


isAllocArrayType

public boolean isAllocArrayType()
Return true if type represents an array whose dimensions are not known at compile time.


isFixedArrayType

public boolean isFixedArrayType()
Return true if type represents an array whose dimensions are known at compile time.


isClassType

public boolean isClassType()
Return true if type represents a class type.


isFloatType

public boolean isFloatType()
Return true if type represents a character type.


isRefType

public boolean isRefType()
Return true if type represents a reference type.


isCharacterType

public boolean isCharacterType()
Return true if type represents a character type.


isIncompleteType

public boolean isIncompleteType()
Return true if type represents an incomplete type.


isPointerType

public boolean isPointerType()
Return true if type represents an address.


isVoidType

public boolean isVoidType()
Return true if type represents no type.


isAggregateType

public boolean isAggregateType()
Return true if type represents an aggregate object.


isUnionType

public boolean isUnionType()
Return true if type represents a union.


isCompositeType

public boolean isCompositeType()
Return true if type represents a composite type.


isRealType

public boolean isRealType()
Return true if type represents a floating point value.


isIntegerType

public boolean isIntegerType()
Return true if type represents an integer value.


isEnumerationType

public boolean isEnumerationType()
Return true if type represents an enumeration value.


isComplexType

public boolean isComplexType()
Return true if type represents a complex value.


isAtomicType

public boolean isAtomicType()
Return true if type represents an atomic type.


isBooleanType

public boolean isBooleanType()
Return true if type represents a boolean type.


isFortranCharType

public boolean isFortranCharType()
Return true if type represents a Fortran CHARACTER type.


isNumericType

public boolean isNumericType()
Return true if type represents a numeric type.


isNamedType

public boolean isNamedType()
Return true if this type has an associated TypeDecl or TypeName.


isProcedureType

public boolean isProcedureType()
Return true if this type represents a procedure.


isSigned

public boolean isSigned()
Return true if the type is signed.


getSignedType

public Type getSignedType()
Return the equivalent signed type of the core type.


numberOfElements

public long numberOfElements()
Return the number of elements represented by this type.


isAttributeSet

public boolean isAttributeSet(RefAttr attribute)
Return true if the attribute is associated with this type.

See Also:
RefType

visit

public void visit(Predicate p)
Description copied from class: Node
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each class has a visit(Predicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Node n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements Predicate can call
   n.visit(this);
 
where n is a Node sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

Specified by:
visit in class Node
See Also:
Predicate

visit

public void visit(TypePredicate p)
Process a node by calling its associated routine. See the "visitor" design pattern in Design Patterns: Elements of Reusable Object-Oriented Software by E. Gamma, et al, Addison Wesley, ISBN 0-201-63361-2.

Each type class has a visit(TypePredicate p) method. For example, in class ABC:

   public void visit(Predicate p)
   {
     p.visitABC(this);
   }
 
and the class that implements Predicate has a method
   public void visitABC(Node n)
   {
     ABC a = (ABC) n;
     ...
   }
 
Thus, the class that implements TypePredicate can call
   n.visit(this);
 
where n is a Node sub-class without determining which specific sub-class n is. The visit pattern basically avoids implementing a large switch statement or defining different methods in each class for some purpose.

See Also:
TypePredicate

getCoreType

public Type getCoreType()
This method filters out some of the special case type nodes from a type DAG.

We define core type as being a primitive type, or a type built from type constructors. Starting at the root of a type DAG, this method skips over select speical case type nodes and returns the first core type node. Well, actually, it returns the first anything that is not one of the select special case nodes. The select special case nodes are (currently) as follows:

The remaining two special case type nodes are simply irrelevant for my current application, so I haven't bothered to determine what happens to them. This nondecision may be changed as appropriate in the future. Null implies the absense of a type, so no core type would exist.

This method instance defines the behavior for all core types, which is to simply return the current type. This method needs to be overridden in the select special case type classes.

Overrides:
getCoreType in class Node
See Also:
Node.getType(), RefType

getType

public Type getType()
Description copied from class: Node
Return the Type associated with this Node.

Overrides:
getType in class Node

registerType

public Type registerType()
Return the type to use if a variable of this type is in a register.


getCompleteType

public Type getCompleteType()
Return the completed type or null if it is not complete.

See Also:
IncompleteType

getNonAttributeType

public Type getNonAttributeType()
Return the type without any attributes such as "const".

See Also:
RefType

getNonConstType

public Type getNonConstType()
Return the type without any "const" attributes.

See Also:
RefType.getNonConstType()

equivalent

public abstract boolean equivalent(Type t)
Return true if the types are equivalent. Types are equivalent if they are the same except for names. For example,
    struct x { int a; int b;}
 
is equivalent to
    struct x { int c; int d;}
 


getEquivalentType

protected Type getEquivalentType()
Return the type to be used by the equivalence method.


getPointedTo

public Type getPointedTo()
Return the type of the thing pointed to.


getPointedToCore

public final Type getPointedToCore()
Return the type of the thing pointed to. Equivalent to
   getCoreType().getPointedTo().getCoreType()
 


getRank

public int getRank()
Return the rank of the type. For a scalar, the rank is 0. For an array, the rank is the number of dimensions.


isConst

public boolean isConst()
Return true if the type specifies const.


isVolatile

public boolean isVolatile()
Return true if the type specifies volatile.


isRestricted

public boolean isRestricted()
Return true if the type specifies restricted.


memorySize

public abstract long memorySize(Machine machine)
Return the number of addressable memory units that are needed to represent the type.

Parameters:
machine - is the machine-specific data machine

elementSize

public long elementSize(Machine machine)
Return the number of addressable memory units are needed to represent an element of the type. Except for arrays this is identical to the value return by memorySize().

Parameters:
machine - is the machine-specific data machine

memorySizeAsInt

public final int memorySizeAsInt(Machine machine)
Calculate how many addressable memory units that are needed to represent the type.

Parameters:
machine - is the machine-specific data machine
Returns:
the number of addressable memory units required to represent this type

alignment

public abstract int alignment(Machine machine)
Calculate the alignment needed for this data type.


precedence

public int precedence()
Return a precedence value for types. We assign precendence values to declarators that use operators (e.g., arrays, functions, pointers). The precendence values are relative to the other operators - larger values mean higher precedence.

Returns:
an integer representing the precendence value for the type relative to the other values.

mapTypeToCString

public java.lang.String mapTypeToCString()
Map a type to a C string. The string representation is based upon the size of the type.

Returns:
the string representation of the type

mapTypeToF77String

public java.lang.String mapTypeToF77String()
Map a type to a Fortran string. The string representation is based upon the size of the type.

Returns:
the string representation of the type

cleanup

public static void cleanup()
Remove static lists of types.