scale.clef.type
Class AllocArrayType

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

public class AllocArrayType
extends ArrayType

This class represents array types with bounds that are determined at run time.

$Id: AllocArrayType.java,v 1.3 2007-06-15 18:21:56 burrill Exp $

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

Allocatable arrays are allocated at run time.

Regardless of whether the source language uses row major or column major array ordering, the dimensions represented by this type are always in row major (C style) ordering.


Method Summary
 ArrayType addIndex(Bound index)
          Return a new array type with the additional dimension.
static void cleanup()
          Remove static lists of types.
 ArrayType copy(Type elementType)
          Creates an array type with the same dimensions but a different element type.
static AllocArrayType create(int rank, Type struct, Type elementType)
          Re-use an existing instance of a particular fixed array type.
 boolean equivalent(Type t)
          Return true if the types are equivalent.
 Type getArraySubtype(int n)
          Return the type of a subscript expression with the specified number of subscripts or null if there are too many subscripts.
 Node getChild(int i)
          Return the specified AST child of this node.
 Bound getFirstIndex()
          Return the type of the first index of the array.
 Bound getIndex(int i)
          Return the specified array index.
protected  Vector<Bound> getIndexes()
          Return a vector of the array indexes.
 int getRank()
          Return the rank of the type.
 Type getStruct()
          Return the structure used to represent the array at run time.
static java.util.Enumeration<AllocArrayType> getTypes()
          Return an enumeration of all the different types.
 boolean isAllocArrayType()
          Return true.
 boolean isBounded()
          Return true if the array has definite bounds.
 boolean isSizeKnown()
          Return false - the size is not known at compile time.
 long numberOfElements()
          Calculate how many elements are in the array.
 int numChildren()
          Return the number of AST children of this node.
 AllocArrayType returnAllocArrayType()
          Return if this is a AllocArrayType, return this.
 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.ArrayType
alignment, elementSize, getArraySubtype, getElementType, isArrayType, memorySize, precedence, returnArrayType
 
Methods inherited from class scale.clef.type.CompositeType
isCompositeType, returnCompositeType
 
Methods inherited from class scale.clef.type.Type
canBeInRegister, getCompleteType, getCoreType, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getEquivalentType, getNonAttributeType, getNonConstType, getPointedTo, getPointedToCore, getSignedType, getTag, getType, isAggregateType, isAtomicType, isAttributeSet, isBooleanType, isCharacterType, isClassType, isComplexType, isConst, isEnumerationType, isFixedArrayType, isFloatType, isFortranCharType, isIncompleteType, isIntegerType, isNamedType, isNumericType, isPointerType, isProcedureType, isRealType, isRefType, isRestricted, isSigned, isUnionType, isVoidType, isVolatile, mapTypeToCString, mapTypeToF77String, memorySizeAsInt, nextVisit, registerType, returnAggregateType, returnAtomicType, returnBooleanType, returnCharacterType, returnComplexType, returnEnumerationType, returnFixedArrayType, returnFloatType, returnFortranCharType, returnIncompleteType, returnIntegerType, returnNumericType, returnPointerType, returnProcedureType, returnRealType, returnRecordType, returnRefType, returnSignedIntegerType, returnUnionType, returnUnsignedIntegerType, returnVoidType, setTag, setVisited, specifyCanBeInRegister, toString, toStringShort, visited
 
Methods inherited from class scale.clef.Node
getDecl, 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 AllocArrayType create(int rank,
                                    Type struct,
                                    Type elementType)
Re-use an existing instance of a particular fixed array type. If no equivalent fixed array type exists, create a new one.

Parameters:
rank - specifies the number of array dimensions
struct - specifies the structure used to represent array at run time.
elementType - the type of elements in the array.

copy

public ArrayType copy(Type elementType)
Creates an array type with the same dimensions but a different element type.

Specified by:
copy in class ArrayType
Parameters:
elementType - the new array element type
Returns:
the new type

getIndexes

protected final Vector<Bound> getIndexes()
Return a vector of the array indexes. Regardless of whether the source language uses row major or column major array ordering, the dimensions represented by this type are always in row major (C style) ordering.

Specified by:
getIndexes in class ArrayType

getIndex

public final Bound getIndex(int i)
Return the specified array index. Regardless of whether the source language uses row major or column major array ordering, the dimensions represented by this type are always in row major (C style) ordering.

Specified by:
getIndex in class ArrayType

getRank

public final 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.

Specified by:
getRank in class ArrayType

getStruct

public final Type getStruct()
Return the structure used to represent the array at run time.


isSizeKnown

public final boolean isSizeKnown()
Return false - the size is not known at compile time.

Specified by:
isSizeKnown in class ArrayType

returnAllocArrayType

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

Overrides:
returnAllocArrayType in class Type

isAllocArrayType

public final boolean isAllocArrayType()
Return true.

Overrides:
isAllocArrayType in class Type

numberOfElements

public final long numberOfElements()
Calculate how many elements are in the array.

Specified by:
numberOfElements in class ArrayType
Returns:
the number of elements

getFirstIndex

public final Bound getFirstIndex()
Return the type of the first index of the array.

Specified by:
getFirstIndex in class ArrayType

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 ArrayType
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 ArrayType
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

equivalent

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

Specified by:
equivalent in class Type

isBounded

public boolean isBounded()
Return true if the array has definite bounds.

Specified by:
isBounded in class ArrayType

getArraySubtype

public Type getArraySubtype(int n)
Return the type of a subscript expression with the specified number of subscripts or null if there are too many subscripts.

Specified by:
getArraySubtype in class ArrayType

getTypes

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


cleanup

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


addIndex

public final ArrayType addIndex(Bound index)
Return a new array type with the additional dimension.