scale.clef.type
Class ArrayType

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
All Implemented Interfaces:
AnnotationInterface, DisplayNode
Direct Known Subclasses:
AllocArrayType, FixedArrayType

public abstract class ArrayType
extends CompositeType

The abstract class for all array types.

$Id: ArrayType.java,v 1.77 2007-03-21 13:31:55 burrill Exp $

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

All arrays have this type. Note, this is not an address type.

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.


Constructor Summary
ArrayType(Type elementType)
           
 
Method Summary
 int alignment(Machine machine)
          Calculate the alignment needed for this data type.
abstract  ArrayType copy(Type elementType)
          Creates an array type with the same dimensions but a different element type.
 long elementSize(Machine machine)
          Return the number of addressable memory units that are needed to represent a single element of the array.
 Type getArraySubtype()
          Return the type of a subscript expression with one subscript.
abstract  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.
 Type getElementType()
          Return the type of the array elements.
abstract  Bound getFirstIndex()
          Return the type of the first index of the array.
abstract  Bound getIndex(int i)
          Return the specified array index.
protected abstract  Vector<Bound> getIndexes()
          Return a vector of the array indexes.
abstract  int getRank()
          Return the rank of the type.
 boolean isArrayType()
          Return true if type represents an array.
abstract  boolean isBounded()
          Return true if the array has definite bounds known at compile time.
abstract  boolean isSizeKnown()
          Return true if the size of the array is known.
 long memorySize(Machine machine)
          Calculate how many addressable memory units are needed to represent the type.
abstract  long numberOfElements()
          Calculate how many elements are in the array.
 int precedence()
          Return a precedence value for types.
 ArrayType returnArrayType()
          Return if this is a ArrayType 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.CompositeType
isCompositeType, returnCompositeType
 
Methods inherited from class scale.clef.type.Type
canBeInRegister, cleanup, equivalent, getCompleteType, getCoreType, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getEquivalentType, getNonAttributeType, getNonConstType, getPointedTo, getPointedToCore, getSignedType, getTag, getType, isAggregateType, isAllocArrayType, 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, returnAllocArrayType, 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
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

ArrayType

public ArrayType(Type elementType)
Method Detail

copy

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

Parameters:
elementType - the new array element type
Returns:
the new type

getIndexes

protected abstract 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.


getIndex

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


getRank

public abstract 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

elementSize

public long elementSize(Machine machine)
Return the number of addressable memory units that are needed to represent a single element of the array.

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

memorySize

public long memorySize(Machine machine)
Calculate how many addressable memory units are needed to represent the type.

Specified by:
memorySize in class Type
Parameters:
machine - is the machine-specific data machine
Returns:
the number of addressable memory units required to represent this type

isSizeKnown

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


numberOfElements

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

Overrides:
numberOfElements in class Type
Returns:
the number of elements

getFirstIndex

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


getElementType

public final Type getElementType()
Return the type of the array elements.


returnArrayType

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

Overrides:
returnArrayType in class Type

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 CompositeType
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 CompositeType
See Also:
TypePredicate

isBounded

public abstract boolean isBounded()
Return true if the array has definite bounds known at compile time.


isArrayType

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

Overrides:
isArrayType in class Type

getArraySubtype

public Type getArraySubtype()
Return the type of a subscript expression with one subscript. For a rank 1 array, this is the element type. For a rank 2 array, this is a rank 1 array of the element type, etc.


getArraySubtype

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


alignment

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

Specified by:
alignment in class Type

precedence

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