scale.clef.type
Class RefType

java.lang.Object
  extended by scale.common.Root
      extended by scale.clef.Node
          extended by scale.clef.type.Type
              extended by scale.clef.type.RefType
All Implemented Interfaces:
AnnotationInterface, DisplayNode

public class RefType
extends Type

A RefType node is used to represent an exisiting type when attributes must be set on a new equivalent type.

$Id: RefType.java,v 1.76 2007-10-04 19:58:08 burrill Exp $

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

For example:

   char *s;
   typedef const char *Identifier;
   Identifier id;
 
would be represented in clef as:
      VariableDecl(s)  VariableDecl(id)  TypeDecl(Identifier)
             \                 |          |
              \                |          |
               \               v          v
                \             RefType{const}
                 \            /
                  \          /
                   |         |
                   v         v
                   PointerType
                        |
                        v
                   CharacterType
 


Method Summary
 int alignment(Machine machine)
          Calculate the alignment needed for this data type.
static void cleanup()
          Remove static lists of types.
static RefType create(Type refTo, Declaration myDecl)
          Re-use an existing instance of a particular reference type.
static RefType create(Type refTo, RefAttr attribute)
          Re-use an existing instance of a particular reference type.
static RefType createAligned(Type refTo, int alignment)
          Re-use an existing instance of a particular reference type.
 long elementSize(Machine machine)
          Return the number of addressable memory units are needed to represent an element of the type.
 boolean equivalent(Type t)
          Return true if the types are equivalent.
 RefAttr getAttribute()
          Return the attribute of this type reference.
 Node getChild(int i)
          Return the specified AST child of this node.
 Type getCoreType()
          This method filters out some the special case type nodes from a type DAG.
 Declaration getDecl()
          Return the TypeDecl or TypeName of this type reference.
 java.lang.String getDisplayLabel()
          Return a String suitable for labeling this node in a graphical display.
protected  Type getEquivalentType()
          Return the type to be used by the equivalence method.
 Type getNonConstType()
          Return the type without any "const" attributes.
 int getRank()
          Return the rank of the type.
 Type getRefTo()
          Return the type referenced.
 Type getSignedType()
          Return the equivalent signed type.
static java.util.Enumeration<RefType> getTypes()
          Return an enumeration of all the different types.
 boolean hasDecl()
          Return true if this instance references a Declaration.
 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(RefAttr 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 TypeName or TypeDecl.
 boolean isNumericType()
          Return true if type represents a numeric value.
 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 is the type is signed.
 boolean isUnionType()
          Return true if type represents a union object.
 boolean isVoidType()
          Return true if type represents no type.
 boolean isVolatile()
          Return true if the type specifies volatile.
 long memorySize(Machine machine)
          Return the number of addressable memory units are needed to represent the type.
 int numChildren()
          Return the number of AST children of this node.
 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.
 RefType returnRefType()
          Return if this is a RefType, return this.
 void setRefTo(Type refTo)
          Set the type referenced.
 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.
 
Methods inherited from class scale.clef.type.Type
canBeInRegister, getCompleteType, getDisplayColorHint, getDisplayShapeHint, getNonAttributeType, getPointedTo, getPointedToCore, getTag, getType, isAllocArrayType, isBooleanType, isCharacterType, isClassType, isEnumerationType, isFixedArrayType, isFloatType, isFortranCharType, isIncompleteType, mapTypeToCString, mapTypeToF77String, memorySizeAsInt, nextVisit, numberOfElements, returnAggregateType, returnAllocArrayType, returnArrayType, returnAtomicType, returnBooleanType, returnCharacterType, returnComplexType, returnCompositeType, returnEnumerationType, returnFixedArrayType, returnFloatType, returnFortranCharType, returnIncompleteType, returnIntegerType, returnNumericType, returnPointerType, returnProcedureType, returnRealType, returnRecordType, returnSignedIntegerType, returnUnionType, returnUnsignedIntegerType, returnVoidType, setTag, setVisited, specifyCanBeInRegister, visited
 
Methods inherited from class scale.clef.Node
getSourceLineNumber, 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
 

Method Detail

create

public static RefType create(Type refTo,
                             Declaration myDecl)
Re-use an existing instance of a particular reference type. If no equivalent reference type exists, create a new one.

Parameters:
refTo - the actual type
myDecl - null or a TypeName or TypeDecl declaration

create

public static RefType create(Type refTo,
                             RefAttr attribute)
Re-use an existing instance of a particular reference type. If no equivalent reference type exists, create a new one.

Parameters:
refTo - the actual type
attribute - an attribute of the type

createAligned

public static RefType createAligned(Type refTo,
                                    int alignment)
Re-use an existing instance of a particular reference type. If no equivalent reference type exists, create a new one. Do not specify an alignment of zero.

Parameters:
refTo - the actual type
alignment - is the user-specified alignment

getNonConstType

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

Overrides:
getNonConstType in class Type
See Also:
RefType

registerType

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

Overrides:
registerType in class Type

getRefTo

public final Type getRefTo()
Return the type referenced.


setRefTo

public final void setRefTo(Type refTo)
Set the type referenced.


isAttributeSet

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

Overrides:
isAttributeSet in class Type
See Also:
RefType

returnRefType

public final RefType returnRefType()
Description copied from class: Type
Return if this is a RefType, return this. Otherwise, return null.

Overrides:
returnRefType in class Type

getAttribute

public RefAttr getAttribute()
Return the attribute of this type reference.


isConst

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

Overrides:
isConst in class Type

isVolatile

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

Overrides:
isVolatile in class Type

isRestricted

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

Overrides:
isRestricted in class Type

getDecl

public Declaration getDecl()
Return the TypeDecl or TypeName of this type reference.

Overrides:
getDecl in class Node

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.

Overrides:
visit in class Type
See Also:
Predicate

visit

public void visit(TypePredicate p)
Description copied from class: Type
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.

Overrides:
visit in class Type
See Also:
TypePredicate

getChild

public Node getChild(int i)
Return the specified AST child of this node.

Overrides:
getChild in class Node

numChildren

public int numChildren()
Return the number of AST children of this node.

Overrides:
numChildren in class Node

getCoreType

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

Overrides:
getCoreType in class Type
See Also:
Type.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.

Overrides:
getRank in class Type

isArrayType

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

Overrides:
isArrayType in class Type

isPointerType

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

Overrides:
isPointerType in class Type

isVoidType

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

Overrides:
isVoidType in class Type

isAggregateType

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

Overrides:
isAggregateType in class Type

isUnionType

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

Overrides:
isUnionType in class Type

isCompositeType

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

Overrides:
isCompositeType in class Type

isRealType

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

Overrides:
isRealType in class Type

isIntegerType

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

Overrides:
isIntegerType in class Type

isComplexType

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

Overrides:
isComplexType in class Type

isAtomicType

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

Overrides:
isAtomicType in class Type

isNumericType

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

Overrides:
isNumericType in class Type

isRefType

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

Overrides:
isRefType in class Type

isNamedType

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

Overrides:
isNamedType in class Type

isProcedureType

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

Overrides:
isProcedureType in class Type

isSigned

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

Overrides:
isSigned in class Type

getSignedType

public Type getSignedType()
Return the equivalent signed type.

Overrides:
getSignedType in class Type

memorySize

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

Specified by:
memorySize in class 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().

Overrides:
elementSize in class Type
Parameters:
machine - is the machine-specific data machine

alignment

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

Specified by:
alignment in class Type

hasDecl

public final boolean hasDecl()
Return true if this instance references a Declaration. Note that hasDecl() may return false even when getDecl() returns a non-null result.


equivalent

public boolean equivalent(Type t)
Return true if the types are equivalent. Types are equivalent if they are the same except for names. For example, if
    typedef int X;
 
then types X and int are equivalent.

Specified by:
equivalent in class Type

getEquivalentType

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

Overrides:
getEquivalentType in class Type

getTypes

public static java.util.Enumeration<RefType> getTypes()
Return an enumeration of all the different types.


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 Type

toString

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

toStringShort

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

Overrides:
precedence in class Type
Returns:
an integer representing the precendence value for the type relative to the other values.

cleanup

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