|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object scale.common.Root scale.clef.Node scale.clef.expr.Expression scale.clef.expr.SubscriptOp
public abstract class SubscriptOp
This is the base class for subscripting operations.
$Id: SubscriptOp.java,v 1.64 2007-10-04 19:58:06 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 subscripts represented by an instance of this class are always in row major (C style) ordering.
There is a difference between how subscripting is represented between C and Fortran.
Array Def | Reference | C | Fortran |
---|---|---|---|
int x1[10] |
x1 |
pointer to int |
pointer to 1-D array of int |
int (*p1)[10] |
p1 |
pointer to 1-D array of int |
NA |
int x2[10][10] |
x2 |
pointer to 1-D array of int |
pointer to 2-D array of int |
int (*p2)[10][10] |
p2 |
pointer to 2-D array of int |
NA |
The C representation is necessary in order for pointer-arithmetic and subscripting to be interchangeable. It also requires that all C arrays be 0-origin indexed.
For Fortran, arrays can be defined using any integer origin.
Therefore, in order for the proper array offset to be calculated,
it is necessary for the complete array information to be available
from the type of the array operand of a SubscriptOp
instance.
An identical representation, as is used after parsing (SubscriptExpr
, ArrayIndexExpr
), cannot be used by
the C parser because the C language allows both subscripting
notation and pointer arithmetic to be combined in the same array
access expression.
setFortranArray()
,
isFortranArray()
Constructor Summary | |
---|---|
SubscriptOp(Type type,
Expression array,
Vector<Expression> subscripts)
|
Method Summary | |
---|---|
void |
addIndex(Expression index)
Add another index to the subscript expression. |
void |
addToIndex(int i,
Expression add)
Add another index to the subscript expression. |
boolean |
containsDeclaration(Declaration decl)
Return true if this expression contains a reference to the variable. |
boolean |
equivalent(java.lang.Object exp)
Return true if the two expressions are equivalent. |
Expression |
getArray()
Return the array address expression. |
Node |
getChild(int i)
Return the specified AST child of this node. |
long |
getConstantIndex()
Return the constant linear index or a negative value if not constant. |
void |
getDeclList(java.util.AbstractCollection<Declaration> varList)
Add all declarations referenced in this expression to the collection. |
Expression |
getSubscript(int i)
Return the specified subscript. |
protected Vector<Expression> |
getSubscripts()
Return the vector of index expressions. |
boolean |
isFortranArray()
Return true if this instance is a Fortran array subscript. |
int |
numChildren()
Return the number of AST children of this node. |
int |
numSubscripts()
Return the number of subscripts. |
protected void |
setArray(Expression array)
Specify the array address expression. |
void |
setFortranArray()
Specify that this instance is a Fortran array subscript. |
void |
visit(Predicate p)
Process a node by calling its associated routine. |
Methods inherited from class scale.clef.expr.Expression |
---|
canonical, getConstantValue, getCoreType, getDisplayColorHint, getDisplayLabel, getDisplayShapeHint, getPointedToCore, getType, hasTrueFalseResult, isSimpleOp, setType, toStringSpecial |
Methods inherited from class scale.clef.Node |
---|
getDecl, getSourceLineNumber, setAnnotationLevel, setReportLevel, setSourceLineNumber, toString, toString, toStringChildren |
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 |
---|
public SubscriptOp(Type type, Expression array, Vector<Expression> subscripts)
Method Detail |
---|
public final boolean isFortranArray()
public final void setFortranArray()
public boolean equivalent(java.lang.Object exp)
equivalent
in class Expression
public void visit(Predicate p)
Node
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.
visit
in class Expression
Predicate
public final Expression getArray()
protected Vector<Expression> getSubscripts()
protected final void setArray(Expression array)
public Node getChild(int i)
getChild
in class Node
public int numChildren()
numChildren
in class Node
public final int numSubscripts()
public Expression getSubscript(int i)
public final void addIndex(Expression index)
public final void addToIndex(int i, Expression add)
public long getConstantIndex()
public boolean containsDeclaration(Declaration decl)
containsDeclaration
in class Expression
public void getDeclList(java.util.AbstractCollection<Declaration> varList)
Expression
getDeclList
in class Expression
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |