edu.cmu.cs.crystal.internal
Class ControlFlowNode

java.lang.Object
  extended by edu.cmu.cs.crystal.internal.ControlFlowNode

public class ControlFlowNode
extends java.lang.Object

Represents one node in a Control Flow Graph.

Author:
David Dickey

Nested Class Summary
static class ControlFlowNode.Direction
           
 
Constructor Summary
ControlFlowNode(ControlFlowGraph cfg, org.eclipse.jdt.core.dom.ASTNode inASTNode)
          Contructor.
 
Method Summary
 void addEdge(ControlFlowNode.Direction direction, ControlFlowNode node)
          Adds an edge from this node to another.
 ControlFlowNode breaking(java.lang.String label, boolean keepRemovingNodes)
          A recursive method for correcting the structure of a CFG in the context of a break statement.
 ControlFlowNode continuing(java.lang.String label, boolean keepRemovingNodes)
          A recursive method for correcting the structure of a CFG in the context of a continue statement.
 void evaluate()
          Evaluates this ControlFlowNode for possible subnodes based on this node's ASTNode.
 ControlFlowNode findNode(ControlFlowNode.Direction direction, int astNodeType)
          Searches for the first ASTNode type in the CFG.
 org.eclipse.jdt.core.dom.ASTNode getASTNode()
          Retrieves the ASTNode associated with this ControlFlowNode
 ControlFlowGraph getControlFlowGraph()
          Retrieves the ControlFlowGraph
 java.util.Iterator<ControlFlowNode> getIterator(ControlFlowNode.Direction direction)
          Retrieves an iterator for either the forward or backward nodes in the CFG.
 ControlFlowNode getNode(ControlFlowNode.Direction direction)
          Retrieves the only forward or backward node from this node.
 int getNumberOfEdges(ControlFlowNode.Direction direction)
          Retrieves the number of edges in a direction.
 void insertNode(ControlFlowNode.Direction direction, ControlFlowNode insertNode)
          Inserts a node between this node and all its subsequent nodes depending on the direction.
 boolean isDummy()
          Used to identify dummy nodes
 void moveEdges(ControlFlowNode.Direction direction, ControlFlowNode node)
          Take all edges and move them to another node.
 ControlFlowNode newControlFlowNode(org.eclipse.jdt.core.dom.ASTNode node)
          Creates a new ControlFlowNode from another ControlFlowNode.
 void remove()
          Removes this Control Flow Node from the tree, connecting edges appropriately
 ControlFlowNode returning()
          A recursive method for correcting the structure of a CFG in the context of a return statement.
 void setFirstChild(ControlFlowNode child)
          Stores the CFN of the first CFN that is a child of this CFN
 void setLoopPaths(ControlFlowNode enter, ControlFlowNode exit)
          loop paths are CFN pointers that record the edge that enters the loop and the edge that exits the loop.
 java.lang.String toString()
          Converts this node into a string representation
 java.lang.String toStringGraph(ControlFlowNode.Direction direction)
          Populates a string with a multi-line textual representation of the control flow.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ControlFlowNode

public ControlFlowNode(ControlFlowGraph cfg,
                       org.eclipse.jdt.core.dom.ASTNode inASTNode)
Contructor. Initializes the node.

Parameters:
cfg - the graph this node belongs to
inASTNode - the ASTNode to associate to this CFN
Method Detail

newControlFlowNode

public ControlFlowNode newControlFlowNode(org.eclipse.jdt.core.dom.ASTNode node)
Creates a new ControlFlowNode from another ControlFlowNode. Use this method when creating new nodes in the same graph as another node.

Parameters:
node - the ASTNode to create a CFN for
Returns:
the ControlFlowNode associated with this graph and the node

evaluate

public void evaluate()
Evaluates this ControlFlowNode for possible subnodes based on this node's ASTNode. For example: a CFN containing a MethodDeclaration will generate new CFNs for each statement in the MethodDeclaration's body.


isDummy

public boolean isDummy()
Used to identify dummy nodes

Returns:
true if this node is a Dummy node, false otherwise

getASTNode

public org.eclipse.jdt.core.dom.ASTNode getASTNode()
Retrieves the ASTNode associated with this ControlFlowNode

Returns:
the ASTNode for this CFN

setLoopPaths

public void setLoopPaths(ControlFlowNode enter,
                         ControlFlowNode exit)
loop paths are CFN pointers that record the edge that enters the loop and the edge that exits the loop. This is used to assist in break/continue/return jumps.

Parameters:
enter - the node that enters the loop
exit - the node that exits the loop

setFirstChild

public void setFirstChild(ControlFlowNode child)
Stores the CFN of the first CFN that is a child of this CFN

Parameters:
child -

getControlFlowGraph

public ControlFlowGraph getControlFlowGraph()
Retrieves the ControlFlowGraph

Returns:
the ControlFlowGraph that contains this node

getIterator

public java.util.Iterator<ControlFlowNode> getIterator(ControlFlowNode.Direction direction)
Retrieves an iterator for either the forward or backward nodes in the CFG.

Parameters:
direction - the direction to retrieve the iterator for
Returns:
the edges iterator

getNode

public ControlFlowNode getNode(ControlFlowNode.Direction direction)
Retrieves the only forward or backward node from this node. If there is more than one node in the direction, then an exception is thrown.

Parameters:
direction - the direction to retrieve the node from
Returns:
the node

getNumberOfEdges

public int getNumberOfEdges(ControlFlowNode.Direction direction)
Retrieves the number of edges in a direction.

Parameters:
direction - the direction to count
Returns:
the number of edges

addEdge

public void addEdge(ControlFlowNode.Direction direction,
                    ControlFlowNode node)
Adds an edge from this node to another.

Parameters:
direction - the direction to add the edge to
node - the node to add

remove

public void remove()
Removes this Control Flow Node from the tree, connecting edges appropriately


moveEdges

public void moveEdges(ControlFlowNode.Direction direction,
                      ControlFlowNode node)
Take all edges and move them to another node. This operation removes all edges from this node, and creates edges to the provided node.

Parameters:
direction - the direction to move edges from
node - the node to move edges to

insertNode

public void insertNode(ControlFlowNode.Direction direction,
                       ControlFlowNode insertNode)
Inserts a node between this node and all its subsequent nodes depending on the direction.

Parameters:
direction - the direction to insert into
insertNode - the node to insert

toString

public java.lang.String toString()
Converts this node into a string representation

Overrides:
toString in class java.lang.Object

toStringGraph

public java.lang.String toStringGraph(ControlFlowNode.Direction direction)
Populates a string with a multi-line textual representation of the control flow. Useful for printing out the structure of the control flow.

Parameters:
direction - sets the traversal direction
Returns:
a textual control flow representation

findNode

public ControlFlowNode findNode(ControlFlowNode.Direction direction,
                                int astNodeType)
Searches for the first ASTNode type in the CFG.

Parameters:
direction - the direction to look
astNodeType - the node type to look for (see ASTNode.getNodeType())
Returns:
the first node of the type, or null if none found

returning

public ControlFlowNode returning()
A recursive method for correcting the structure of a CFG in the context of a return statement. After this method completes, the return statement will be properly connected to the methodDeclaration.

Returns:
the methodDeclaration to return to

breaking

public ControlFlowNode breaking(java.lang.String label,
                                boolean keepRemovingNodes)
A recursive method for correcting the structure of a CFG in the context of a break statement. After this method completes, the break statement will be properly connected to whatever the target of the break is.

Parameters:
label - the label of the break, or null if none
keepRemovingNodes - if true then remove forward nodes
Returns:
the target of the break

continuing

public ControlFlowNode continuing(java.lang.String label,
                                  boolean keepRemovingNodes)
A recursive method for correcting the structure of a CFG in the context of a continue statement. After this method completes, the continue statement will be properly connected to whatever the target of the continue is.

Parameters:
label - the label of the continue, or null if none
keepRemovingNodes - if true then remove forward nodes
Returns:
the target of the continue