scale.clef.type
Class FixedArrayType

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.FixedArrayType
All Implemented Interfaces:
AnnotationInterface, DisplayNode

public class FixedArrayType
extends ArrayType

This class represents array types with fixed bounds.

$Id: FixedArrayType.java,v 1.53 2007-03-21 13:31:56 burrill Exp $

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

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.

It is not necessary for the upper-bound of the outer-most bounds to be known at compile time for this value is not needed to calculate offsets into the array.


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 FixedArrayType create(long minIndex, long maxIndex, Type elementType)
          Re-use an existing instance of a one-dimensional fixed array type.
static FixedArrayType create(Vector<Bound> indicies, 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 new vector of the array indexes.
 int getRank()
          Return the rank of the type.
static java.util.Enumeration<FixedArrayType> getTypes()
          Return an enumeration of all the different types.
 boolean isBounded()
          Return true if the array has definite bounds.
 boolean isFixedArrayType()
          Return true if type represents an array whose dimensions are known at compile time.
 boolean isSizeKnown()
          Return true if the size of the array is known.
 long numberOfElements()
          Calculate how many elements are in the array.
 int numChildren()
          Return the number of AST children of this node.
 FixedArrayType returnFixedArrayType()
          Return if this is a FixedArrayType, 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, isAllocArrayType, isAtomicType, isAttributeSet, isBooleanType, isCharacterType, isClassType, isComplexType, isConst, isEnumerationType, isFloatType, isFortranCharType, isIncompleteType, isIntegerType, isNamedType, isNumericType, isPointerType, isProcedureType, isRealType, isRefType, isRestricted, isSigned, isUnionType, isVoidType, isVolatile, mapTypeToCString, mapTypeToF77String, memorySizeAsInt, nextVisit, registerType, returnAggregateType, returnAllocArrayType, returnAtomicType, returnBooleanType, returnCharacterType, returnComplexType, returnEnumerationType, 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 FixedArrayType create(Vector<Bound> indicies,
                                    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:
indicies - a vector of Bound entries - one for each dimension.
elementType - the type of elements in the array.

create

public static FixedArrayType create(long minIndex,
                                    long maxIndex,
                                    Type elementType)
Re-use an existing instance of a one-dimensional fixed array type. If no equivalent fixed array type exists, create a new one. If minIndex > maxIndex, the range is considered to be unbounded.

Parameters:
minIndex - is the lower bound on the array
maxIndex - is the upper bound on the array
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 new 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

isSizeKnown

public final boolean isSizeKnown()
Return true if the size of the array is known.

Specified by:
isSizeKnown in class ArrayType

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<FixedArrayType> 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.


isFixedArrayType

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

Overrides:
isFixedArrayType in class Type

returnFixedArrayType

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

Overrides:
returnFixedArrayType in class Type