tip.node
Class Node

java.lang.Object
  extended by tip.node.Node
All Implemented Interfaces:
Cloneable, NodeInterface
Direct Known Subclasses:
PBinop, PBlock, PBody, PDecl, PExp, PProgram, PStm, Start, Token

public abstract class Node
extends Object
implements Cloneable, NodeInterface

Node is the superclass of all nodes in the AST.


Constructor Summary
Node()
           
 
Method Summary
abstract  void apply(Analysis caller)
          Applies the Analysis visitor to this node.
abstract
<A> A
apply(Answer<A> caller)
          Returns the answer for caller by applying this node to the Answer visitor.
abstract
<Q> void
apply(Question<Q> caller, Q question)
          Applies this node to the Question visitor caller.
abstract
<Q,A> A
apply(QuestionAnswer<Q,A> caller, Q question)
          Returns the answer for answer by applying this node with the question to the QuestionAnswer visitor.
abstract  void checkOptionalInvariant()
           
abstract  Node clone()
           
abstract  Node clone(Map<Node,Node> oldToNewMap)
           
<T extends NodeInterface>
T
getAncestor(Class<T> classType)
          Returns the nearest ancestor of this node (including itself) which is a subclass of classType.
<T extends NodeInterface>
T
getAncestor(Class<T> classType, Class<? extends NodeInterface> guardClass)
          Returns the nearest ancestor of this node (including itself) which is a subclass of classType.
<T extends NodeInterface>
T
getAncestor(NodeFilter<T> filter)
          Returns the nearest ancestor of this node (including itself) which is accepted by the NodeFilter filter.
<T extends NodeInterface>
List<T>
getChildren(Class<T> classType)
          Returns the collection of children to this node which are subtypes of classType.
abstract
<T extends NodeInterface>
void
getChildren(Collection<T> collection, NodeFilter<T> filter)
          Adds all children of this Node node that are accepted by the NodeFilter filter to collection.
<T extends NodeInterface>
List<T>
getChildren(NodeFilter<T> filter)
          Returns the collection of children to this node which are accepted by the NodeFilter filter.
<T extends NodeInterface>
Collection<T>
getDescendants(Class<T> classType)
          Returns the collection of descendants to this node (including itself) which are subtypes of classType.
<T extends NodeInterface>
Collection<T>
getDescendants(Class<T> classType, Class<? extends NodeInterface> guardClass)
          Returns the collection of descendants to this node (including itself) which are subtypes of classType.
abstract
<T extends NodeInterface>
void
getDescendants(Collection<T> collection, NodeFilter<T> filter)
          Adds all descendants of this Node node (including the node itself) that are accepted by the NodeFilter filter to collection.
<T extends NodeInterface>
Collection<T>
getDescendants(NodeFilter<T> filter)
          Returns the collection of descendants to this node (including the node itself) which are accepted by the NodeFilter filter.
 boolean isOptionalInvariant()
           
abstract  NodeEnum kindNode()
          Returns the NodeEnum corresponding to the type of this Node node.
 Node parent()
          Returns the parent node of this node.
 void replaceBy(Node node)
          Replaces this node by node in the AST.
 void setOptionalInvariant(boolean value)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Node

public Node()
Method Detail

clone

public abstract Node clone()
Specified by:
clone in interface NodeInterface
Overrides:
clone in class Object

clone

public abstract Node clone(Map<Node,Node> oldToNewMap)
Specified by:
clone in interface NodeInterface

kindNode

public abstract NodeEnum kindNode()
Returns the NodeEnum corresponding to the type of this Node node.

Returns:
the NodeEnum for this node

parent

public Node parent()
Returns the parent node of this node.

Specified by:
parent in interface NodeInterface
Returns:
the parent node of this node

replaceBy

public void replaceBy(Node node)
Replaces this node by node in the AST. If this node has no parent node, this results in a NullPointerException. The replacing node is removed from its previous parent.

Specified by:
replaceBy in interface NodeInterface
Parameters:
node - the node replacing this node in the AST

getAncestor

public <T extends NodeInterface> T getAncestor(NodeFilter<T> filter)
Returns the nearest ancestor of this node (including itself) which is accepted by the NodeFilter filter. Traversal is stopped if the node is guarded by the NodeFilter filter.

Specified by:
getAncestor in interface NodeInterface
Parameters:
filter - the NodeFilter used
Returns:
the nearest ancestor of this node

getAncestor

public <T extends NodeInterface> T getAncestor(Class<T> classType)
Returns the nearest ancestor of this node (including itself) which is a subclass of classType.

Specified by:
getAncestor in interface NodeInterface
Parameters:
classType - the superclass used
Returns:
the nearest ancestor of this node

getAncestor

public <T extends NodeInterface> T getAncestor(Class<T> classType,
                                               Class<? extends NodeInterface> guardClass)
Returns the nearest ancestor of this node (including itself) which is a subclass of classType. Traversal is stopped if a subclass of guardClass is found.

Specified by:
getAncestor in interface NodeInterface
Parameters:
classType - the superclass used for filtering
guardClass - the superclass used for guarding
Returns:
the nearest ancestor of this node

getDescendants

public abstract <T extends NodeInterface> void getDescendants(Collection<T> collection,
                                                              NodeFilter<T> filter)
Adds all descendants of this Node node (including the node itself) that are accepted by the NodeFilter filter to collection.

Specified by:
getDescendants in interface NodeInterface
Parameters:
collection - the collection to which the descendants are added
filter - the NodeFilter used

getDescendants

public <T extends NodeInterface> Collection<T> getDescendants(NodeFilter<T> filter)
Returns the collection of descendants to this node (including the node itself) which are accepted by the NodeFilter filter. Descandants of nodes which are guarded by the NodeFilter filter are not included.

Specified by:
getDescendants in interface NodeInterface
Parameters:
filter - the NodeFilter used
Returns:
a collection of the accepted descendants

getDescendants

public <T extends NodeInterface> Collection<T> getDescendants(Class<T> classType)
Returns the collection of descendants to this node (including itself) which are subtypes of classType.

Specified by:
getDescendants in interface NodeInterface
Parameters:
classType - the supertype for all collected descendants
Returns:
a collection of the accepted nodes

getDescendants

public <T extends NodeInterface> Collection<T> getDescendants(Class<T> classType,
                                                              Class<? extends NodeInterface> guardClass)
Returns the collection of descendants to this node (including itself) which are subtypes of classType. Descendants of subtypes of guardClass are not included.

Specified by:
getDescendants in interface NodeInterface
Parameters:
classType - the supertype for all collected descendants
Returns:
a collection of the accepted nodes

getChildren

public abstract <T extends NodeInterface> void getChildren(Collection<T> collection,
                                                           NodeFilter<T> filter)
Adds all children of this Node node that are accepted by the NodeFilter filter to collection.

Specified by:
getChildren in interface NodeInterface
Parameters:
collection - the collection to which the children are added
filter - the NodeFilter used

getChildren

public <T extends NodeInterface> List<T> getChildren(NodeFilter<T> filter)
Returns the collection of children to this node which are accepted by the NodeFilter filter.

Specified by:
getChildren in interface NodeInterface
Parameters:
filter - the NodeFilter used
Returns:
a collection of the accepted children

getChildren

public <T extends NodeInterface> List<T> getChildren(Class<T> classType)
Returns the collection of children to this node which are subtypes of classType.

Specified by:
getChildren in interface NodeInterface
Parameters:
classType - the supertype for all collected children
Returns:
a collection of the accepted nodes

apply

public abstract void apply(Analysis caller)
Applies the Analysis visitor to this node.

Specified by:
apply in interface NodeInterface
Parameters:
caller - the Analysis to which this node is applied

apply

public abstract <A> A apply(Answer<A> caller)
Returns the answer for caller by applying this node to the Answer visitor.

Specified by:
apply in interface NodeInterface
Parameters:
caller - the Answer to which this node is applied
Returns:
the answer as returned from caller

apply

public abstract <Q> void apply(Question<Q> caller,
                               Q question)
Applies this node to the Question visitor caller.

Specified by:
apply in interface NodeInterface
Parameters:
caller - the Question to which this node is applied
question - the question provided to caller

apply

public abstract <Q,A> A apply(QuestionAnswer<Q,A> caller,
                              Q question)
Returns the answer for answer by applying this node with the question to the QuestionAnswer visitor.

Specified by:
apply in interface NodeInterface
Parameters:
caller - the QuestionAnswer to which this node is applied
question - the question provided to answer
Returns:
the answer as returned from answer

isOptionalInvariant

public boolean isOptionalInvariant()
Specified by:
isOptionalInvariant in interface NodeInterface

setOptionalInvariant

public void setOptionalInvariant(boolean value)
Specified by:
setOptionalInvariant in interface NodeInterface

checkOptionalInvariant

public abstract void checkOptionalInvariant()
Specified by:
checkOptionalInvariant in interface NodeInterface