cetus.hir
Class ArrayAccess

java.lang.Object
  extended by cetus.hir.Expression
      extended by cetus.hir.ArrayAccess
All Implemented Interfaces:
Printable, Traversable, java.lang.Cloneable, java.lang.Comparable<Expression>

public class ArrayAccess
extends Expression

Represents the access of an array or pointer variable: array[x][y]...


Field Summary
 
Fields inherited from class cetus.hir.Expression
children, needs_parens, object_print_method, parent
 
Constructor Summary
ArrayAccess(Expression array, Expression index)
          Creates an array access with a single index expression.
ArrayAccess(Expression array, java.util.List indices)
          Creates an array access with multiple index expressions.
 
Method Summary
 void addIndex(Expression expr)
           
 java.lang.Object clone()
          Creates and returns a deep copy of this expression.
static void defaultPrint(ArrayAccess expr, java.io.OutputStream stream)
          Prints an array access expression to a stream.
 Expression getArrayName()
          Returns the expression being indexed.
 Expression getIndex(int n)
          Gets the nth index expression of this array access.
 java.util.List<Expression> getIndices()
          Returns the list of indices in the array access.
 int getNumIndices()
          Returns the number of index expressions used in this array access.
static void setClassPrintMethod(java.lang.reflect.Method m)
          Overrides the class print method, so that all subsequently created objects will use the supplied method.
 void setIndex(int n, Expression expr)
          Sets the nth index expression of this array access.
 void setIndices(java.util.List indices)
          Set the list of index expressions.
 java.lang.String toString()
          Every expression class should override toString method.
 
Methods inherited from class cetus.hir.Expression
compareTo, equals, equals2, findExpression, getChildren, getParent, getStatement, needsParens, print, printSelf, removeChild, setChild, setParens, setParent, setPrintMethod, swapWith, verify
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArrayAccess

public ArrayAccess(Expression array,
                   Expression index)
Creates an array access with a single index expression.

Parameters:
array - An expression evaluating to an address.
index - The expression with which to index the array.

ArrayAccess

public ArrayAccess(Expression array,
                   java.util.List indices)
Creates an array access with multiple index expressions.

Parameters:
array - An expression evaluating to an address.
indices - A list of expressions with which to index the array.
Method Detail

addIndex

public void addIndex(Expression expr)

clone

public java.lang.Object clone()
Description copied from class: Expression
Creates and returns a deep copy of this expression.

Overrides:
clone in class Expression
Returns:
a deep copy of this expression.

defaultPrint

public static void defaultPrint(ArrayAccess expr,
                                java.io.OutputStream stream)
Prints an array access expression to a stream.

Parameters:
expr - The array access to print.
stream - The stream on which to print the array access.

toString

public java.lang.String toString()
Description copied from class: Expression
Every expression class should override toString method.

Overrides:
toString in class Expression

getArrayName

public Expression getArrayName()
Returns the expression being indexed. Most often, the expression will be an Identifier, but any expression that evaluates to an address is allowed.

Returns:
the expression being indexed.

getIndex

public Expression getIndex(int n)
Gets the nth index expression of this array access.

Parameters:
n - The position of the index expression.
Returns:
the nth index expression.
Throws:
java.lang.IndexOutOfBoundsException - if there is no expression at that position.

getIndices

public java.util.List<Expression> getIndices()
Returns the list of indices in the array access.

Returns:
the list of indices.

getNumIndices

public int getNumIndices()
Returns the number of index expressions used in this array access.

Returns:
the number of index expressions.

setIndex

public void setIndex(int n,
                     Expression expr)
Sets the nth index expression of this array access.

Parameters:
n - The position of the index expression.
expr - The expression to use for the index.
Throws:
java.lang.IndexOutOfBoundsException - if there is no expression at that position.

setIndices

public void setIndices(java.util.List indices)
Set the list of index expressions.

Parameters:
indices - A list of expressions.

setClassPrintMethod

public static void setClassPrintMethod(java.lang.reflect.Method m)
Overrides the class print method, so that all subsequently created objects will use the supplied method.

Parameters:
m - The new print method.