scale.clef.type
Class Type

java.lang.Object
  |
  +--scale.common.Root
        |
        +--scale.clef.Node
              |
              +--scale.clef.type.Type
All Implemented Interfaces:
AnnotationInterface, DisplayNode, java.io.Serializable
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.68 2002/01/03 21:44:15 burrill Exp $

Copyright 2002 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.

See Also:
Serialized Form

Fields inherited from interface scale.common.DisplayNode
ANNO, CLEF, DD, DEFUSE, DOM, EXPR, MAYUSE, TYPE
 
Constructor Summary
Type()
           
 
Method Summary
abstract  int alignment(Machine machine)
          Calculate the alignment needed for this data type.
abstract  boolean equivalent(Type t)
          Return true if the types are strictly equivalent.
protected  void finalize()
          Keep the count of instances up-to-date.
 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.
 java.lang.String getDisplayColorHint()
          Return a String specifying the color to use for coloring this node in a graphical display.
 java.lang.String getDisplayShapeHint()
          Return a String specifying a shape to use when drawing this node in a graphical display.
 java.lang.String getDisplayText()
          Return a String suitable for labeling this node in a graphical display.
 Type getPointedTo()
          Return the type of the thing pointed to.
 int getTag()
          Return the tag associated with this variable.
 Type getType()
          Return the Type associated with this Node.
 boolean isAddressType()
          Return true if type represents the address of something.
 boolean isAggregateType()
          Return true if type represents an aggregate object.
 boolean isArrayType()
          Return true if type represents an array.
 boolean isAtomicType()
          Return true if type represents a scaler value.
 boolean isAttributeSet(int attribute)
          Return true if the attribute is associated with this 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 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 value.
 boolean isPointerType()
          Return true if type represents an address.
 boolean isRealType()
          Return true if type represents a floating point value.
 boolean isSigned()
          Return true is the type is signed.
 boolean isVoidType()
          Return true if type represents no type.
 boolean isVolatile()
          Return true if the type specifies volatile.
abstract  int memorySize(Machine machine)
          Calculate how many addressable memory units are needed to represent the type.
static void nextVisit()
          Set up for a new traversal - that is, use the next color value.
static int number()
          Return the current number of instances of this class.
 void setTag(int tag)
          Set the tag for this variable.
 void setVisited()
          Associate the current color value with this Type.
 java.lang.String toString()
           
 java.lang.String toStringShort()
           
 void visit(Predicate p)
          The visit() method is used to implement a visit 'pattern'.
 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
createChildren, getChildren, getDecl, getParent, setAnnotationLevel, setParent, setReportLevel, 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
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Type

public Type()
Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Keep the count of instances up-to-date.
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - [needs description]

number

public static int number()
Return the current number of instances of this class.

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.

toString

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

toStringShort

public java.lang.String toStringShort()

getDisplayText

public java.lang.String getDisplayText()
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.
Overrides:
getDisplayText in class Root

getDisplayColorHint

public java.lang.String 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.
Overrides:
getDisplayColorHint in class Root

getDisplayShapeHint

public java.lang.String 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".
Overrides:
getDisplayShapeHint in class Root

isAddressType

public boolean isAddressType()
Return true if type represents the address of something.

isArrayType

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

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.

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.

isComplexType

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

isAtomicType

public boolean isAtomicType()
Return true if type represents a scaler value.

isNumericType

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

isNamedType

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

isSigned

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

isAttributeSet

public boolean isAttributeSet(int 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
The visit() method is used to implement a visit 'pattern'.
Overrides:
visit in class Node

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
Following copied from class: scale.clef.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

getCompleteType

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

equivalent

public abstract boolean equivalent(Type t)
Return true if the types are strictly equivalent.

getPointedTo

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

isConst

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

isVolatile

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

memorySize

public abstract int memorySize(Machine machine)
Calculate how many addressable memory units 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.