harpoon.IR.Tree
Class Tree

java.lang.Object
  extended by harpoon.IR.Tree.Tree
All Implemented Interfaces:
HCodeElement
Direct Known Subclasses:
Exp, Stm

public abstract class Tree
extends Object
implements HCodeElement

Tree is the base class for the tree representation.

Version:
$Id: Tree.java,v 1.7 2004/02/08 01:55:51 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>

Nested Class Summary
static interface Tree.CloneCallback
          Callback interface to tree cloning code to allow you to update type and other annotations as the tree is cloned.
 
Field Summary
static ArrayFactory<Tree> arrayFactory
          Array factory: returns Tree[].
protected  Tree[] child
           
 
Constructor Summary
protected Tree(TreeFactory tf, HCodeElement source, int arity)
           
 
Method Summary
abstract  void accept(TreeVisitor v)
          Accept a visitor.
 Tree clone()
          Clone a subtree.
static Tree clone(TreeFactory ntf, Tree root, Tree.CloneCallback cb)
          Returns a clone of root.
protected  Tree getChild(int which)
          Fetch from the child array -- for subclass use only.
 TreeFactory getFactory()
          Returns the TreeFactory that generated this Tree.
 Tree getFirstChild()
          Returns the leftmost child of this tree, or null if this node has no children.
 int getID()
          Returns a unique numeric identifier for this Tree.
 int getLineNumber()
          Returns the line in the original source file that this Tree is derived from.
 Tree getParent()
          Returns the parent of this tree.
 Tree getSibling()
          Returns the right sibling of this tree, null if there are no siblings to the right of this node.
 String getSourceFile()
          Returns the original source file name that this Tree is derived from.
 int hashCode()
           
 ExpList kids()
          Return a list of subexpressions of this Tree.
abstract  int kind()
          Return an integer enumeration of the kind of this Tree.
 Tree rename(TempMap tm)
          Rename while cloning a subtree.
abstract  Tree rename(TreeFactory tf, TempMap tm, Tree.CloneCallback cb)
          Rename while cloning a subtree.
 void replace(Tree newTree)
          Replace the tree rooted at this with a new tree.
protected  void setChild(int which, Tree newChild)
          Modify the child array -- for subclass use only.
 void unlink()
          Make this a root-level tree, unlinking it from its parent.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

child

protected final Tree[] child

arrayFactory

public static final ArrayFactory<Tree> arrayFactory
Array factory: returns Tree[].

Constructor Detail

Tree

protected Tree(TreeFactory tf,
               HCodeElement source,
               int arity)
Method Detail

hashCode

public final int hashCode()
Overrides:
hashCode in class Object

getFactory

public final TreeFactory getFactory()
Returns the TreeFactory that generated this Tree.


getFirstChild

public final Tree getFirstChild()
Returns the leftmost child of this tree, or null if this node has no children.


getSibling

public final Tree getSibling()
Returns the right sibling of this tree, null if there are no siblings to the right of this node.


getParent

public final Tree getParent()
Returns the parent of this tree. If this tree is the root node, then returns null.


getChild

protected final Tree getChild(int which)
Fetch from the child array -- for subclass use only. The subclass will provide named accessors to the public (ie, getDst(), getLeft()).


setChild

protected final void setChild(int which,
                              Tree newChild)
Modify the child array -- for subclass use only. The subclass will provide named accessors to the public (ie, setDst(), setLeft() ).


replace

public final void replace(Tree newTree)
Replace the tree rooted at this with a new tree.


unlink

public final void unlink()
Make this a root-level tree, unlinking it from its parent.


getSourceFile

public final String getSourceFile()
Returns the original source file name that this Tree is derived from.

Specified by:
getSourceFile in interface HCodeElement

getLineNumber

public final int getLineNumber()
Returns the line in the original source file that this Tree is derived from.

Specified by:
getLineNumber in interface HCodeElement

getID

public final int getID()
Returns a unique numeric identifier for this Tree.

Specified by:
getID in interface HCodeElement

kind

public abstract int kind()
Return an integer enumeration of the kind of this Tree. The enumerated values are defined in TreeKind.


accept

public abstract void accept(TreeVisitor v)
Accept a visitor.


clone

public static Tree clone(TreeFactory ntf,
                         Tree root,
                         Tree.CloneCallback cb)
Returns a clone of root. The callback() method of the supplied CloneCallback will be invoked with every cloned subtree, from the bottom up to the root. The cloned subtree will be generated using the supplied TreeFactory, ntf.

Returns:
the root of the cloned tree.

NOTE: tree objects may actually contain temps from two different temp factories. The first temp factory with which a tree's temps may be associated is the TempFactory stored in their TreeFactory. The second is the TempFactory used by the tree's Frame to generate registers. Since these registers are assumed to be immutable, no temps from that temp factory will be cloned by this method. All other temps will be cloned using a new CloningTempMap.


clone

public final Tree clone()
Clone a subtree. This is a *deep* copy -- ie, this node and nodes rooted here are copied, all the way down to the leaves. The cloned subtree will have the same tree factory as this.

Overrides:
clone in class Object

rename

public final Tree rename(TempMap tm)
Rename while cloning a subtree. This node and all child nodes are cloned; the 'temp' information of all TEMP nodes are renamed according to the supplied TempMap. Note that Temps not belonging to this.getFactory().tempFactory() are not affected.


rename

public abstract Tree rename(TreeFactory tf,
                            TempMap tm,
                            Tree.CloneCallback cb)
Rename while cloning a subtree. This node and all child nodes are cloned; the 'temp' information of all TEMP nodes are renamed according to the supplied TempMap. Note that Temps not belonging to this.getFactory().tempFactory() are not affected. The callback() method of the supplied CloneCallback is invoked once on each subtree cloned, starting from the leaves and working back to the root in a post-order depth-first manner.


kids

public ExpList kids()
Return a list of subexpressions of this Tree.