org.jtool.jxplatform.graph.cfg
Class CFG

java.lang.Object
  extended byorg.jtool.jxplatform.graph.Graph
      extended byorg.jtool.jxplatform.graph.cfg.CFG

public class CFG
extends Graph

An object storing information about a control flow graph (CFG).

Author:
Katsuhsa Maruyama

Field Summary
protected  CFGExit end
          An end node of this CFG.
protected  CFGMethodEntry start
          A start node of this CFG.
 
Fields inherited from class org.jtool.jxplatform.graph.Graph
edges, nodes
 
Constructor Summary
protected CFG()
          Creates a new, empty object.
  CFG(org.w3c.dom.Element elem)
          Creates the CFG of a method.
  CFG(org.w3c.dom.Element elem, boolean bool)
          Creates the CFG of a method.
 
Method Summary
 GraphElementSet getBackwardReachableNodes(CFGNode fromNode, CFGNode toNode)
          Calculates and returns the nodes passed backward between two CFG nodes.
 GraphElementSet getBackwardReachableNodesWithoutLoopback(CFGNode fromNode, CFGNode toNode)
          Calculates and returns the nodes passed backward between two CFG nodes not traversing loopback edges.
 GraphElementSet getDstNodes(CFGNode src)
          Returns destination nodes of the edges the source of which is a given node.
 CFGExit getEndNode()
          Returns the end node of this CFG.
 ControlFlow getFalseFlowFrom(CFGNode src)
          Returns a false control flow outgoing from a given node.
 CFGNode getFalseSuccessor(CFGNode node)
          Returns a successor node of a given node with respect to the false control flow.
 ControlFlow getFlow(CFGNode src, CFGNode dst)
          Returns an edge specified by a given source node destination node.
 GraphElementSet getForwardReachableNodes(CFGNode fromNode, CFGNode toNode)
          Calculates and returns the nodes passed forward between two nodes CFG.
 GraphElementSet getForwardReachableNodesWithoutLoopback(CFGNode fromNode, CFGNode toNode)
          Calculates and returns the nodes passed forward between two CFG nodes not traversing loopback edges.
 CFGNode getNode(org.w3c.dom.Element elem)
          Returns a CFG node which corresponds to a DOM element.
 CFGNode getNode(int id)
          Returns a CFG node with a given identifier.
 GraphElementSet getSrcNodes(CFGNode dst)
          Returns source nodes of the edges the destination of which is a given node.
 CFGMethodEntry getStartNode()
          Returns the start node of this CFG.
 ControlFlow getTrueFlowFrom(CFGNode src)
          Returns a true control flow outgoing from a given node.
 CFGNode getTrueSuccessor(CFGNode node)
          Returns a successor node of a given node with respect to the true control flow.
 void print()
          Displays information about this CFG.
protected  void setEndNode(CFGExit node)
          Sets the end node of this CFG.
protected  void setStartNode(CFGMethodEntry node)
          Sets the start node of this CFG.
 java.lang.String write()
          Writes information about this CFG.
 void writeEdges(java.lang.StringBuffer buf)
          Collects information about edges of this CFG for writing an XML document.
 void writeNodes(java.lang.StringBuffer buf)
          Collects information about nodes of this CFG for writing an XML document.
 
Methods inherited from class org.jtool.jxplatform.graph.Graph
add, add, clear, contains, contains, equals, getEdges, getNodes, printEdges, printNodes, remove, remove, setEdges, setNodes, setSrcDstNodes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

start

protected CFGMethodEntry start
A start node of this CFG.


end

protected CFGExit end
An end node of this CFG.

Constructor Detail

CFG

protected CFG()
Creates a new, empty object.


CFG

public CFG(org.w3c.dom.Element elem)
    throws GraphException
Creates the CFG of a method.

Parameters:
elem - A DOM element corresponding to a target method.
Throws:
GraphException - if the creation of a CFG fails.

CFG

public CFG(org.w3c.dom.Element elem,
           boolean bool)
    throws GraphException
Creates the CFG of a method.

Parameters:
elem - A DOM element corresponding to a target method.
bool - true if the creation of actual-in and -out nodes is wanted.
Throws:
GraphException - if the creation of a CFG fails.
Method Detail

setStartNode

protected void setStartNode(CFGMethodEntry node)
Sets the start node of this CFG.

Parameters:
node - A start node of this CFG.

getStartNode

public CFGMethodEntry getStartNode()
Returns the start node of this CFG.

Returns:
The start node of this CFG.

setEndNode

protected void setEndNode(CFGExit node)
Sets the end node of this CFG.

Parameters:
node - An end node of this CFG.

getEndNode

public CFGExit getEndNode()
Returns the end node of this CFG.

Returns:
The end node of this CFG.

getForwardReachableNodes

public GraphElementSet getForwardReachableNodes(CFGNode fromNode,
                                                CFGNode toNode)
Calculates and returns the nodes passed forward between two nodes CFG.

Parameters:
fromNode - A start node of reachable path to be calculated.
toNode - An end node of reachable path to be calculated.
Returns:
The nodes on the forward reachable path.

getForwardReachableNodesWithoutLoopback

public GraphElementSet getForwardReachableNodesWithoutLoopback(CFGNode fromNode,
                                                               CFGNode toNode)
Calculates and returns the nodes passed forward between two CFG nodes not traversing loopback edges.

Parameters:
fromNode - A start node of reachable path to be calculated.
toNode - An end node of reachable path to be calculated.
Returns:
The nodes on the forward reachable path.

getBackwardReachableNodes

public GraphElementSet getBackwardReachableNodes(CFGNode fromNode,
                                                 CFGNode toNode)
Calculates and returns the nodes passed backward between two CFG nodes.

Parameters:
fromNode - A start node of reachable path to be calculated.
toNode - An end node of reachable path to be calculated.
Returns:
The nodes on the forward reachable path.

getBackwardReachableNodesWithoutLoopback

public GraphElementSet getBackwardReachableNodesWithoutLoopback(CFGNode fromNode,
                                                                CFGNode toNode)
Calculates and returns the nodes passed backward between two CFG nodes not traversing loopback edges.

Parameters:
fromNode - A start node of reachable path to be calculated.
toNode - An end node of reachable path to be calculated.
Returns:
The nodes on the forward reachable path.

getFlow

public ControlFlow getFlow(CFGNode src,
                           CFGNode dst)
Returns an edge specified by a given source node destination node.

Parameters:
src - A source CFG node for an edge to be retrieved.
dst - A destination CFG node for an edge to be retrieved.
Returns:
The specified edge of this CFG, or null if there is no edge found.

getSrcNodes

public GraphElementSet getSrcNodes(CFGNode dst)
Returns source nodes of the edges the destination of which is a given node.

Parameters:
dst - A CFG node.
Returns:
The source nodes.

getDstNodes

public GraphElementSet getDstNodes(CFGNode src)
Returns destination nodes of the edges the source of which is a given node.

Parameters:
src - A CFG.
Returns:
The destination nodes.

getNode

public CFGNode getNode(org.w3c.dom.Element elem)
Returns a CFG node which corresponds to a DOM element.

Parameters:
elem - A DOM element.
Returns:
The corresponding node, or null if there is no corresponding node found.

getNode

public CFGNode getNode(int id)
Returns a CFG node with a given identifier.

Parameters:
id - The identifier of a node.
Returns:
The corresponding node, or null if there is no corresponding node found.

getTrueFlowFrom

public ControlFlow getTrueFlowFrom(CFGNode src)
Returns a true control flow outgoing from a given node.

Parameters:
src - A CFG node.
Returns:
The true control flow, or null if there is no corresponding flow found.

getFalseFlowFrom

public ControlFlow getFalseFlowFrom(CFGNode src)
Returns a false control flow outgoing from a given node.

Parameters:
src - A CFG node.
Returns:
The flase control flow, or null if there is no corresponding flow found.

getTrueSuccessor

public CFGNode getTrueSuccessor(CFGNode node)
Returns a successor node of a given node with respect to the true control flow.

Parameters:
node - A CFG node.
Returns:
The successor node, or null if there is no corresponding node found.

getFalseSuccessor

public CFGNode getFalseSuccessor(CFGNode node)
Returns a successor node of a given node with respect to the false control flow.

Parameters:
node - A CFG node.
Returns:
The successor node, or null if there is no corresponding node found.

print

public void print()
Displays information about this CFG.

Overrides:
print in class Graph

write

public java.lang.String write()
                       throws GraphException
Writes information about this CFG.

Throws:
GraphException - the write of this CFG fails.

writeNodes

public void writeNodes(java.lang.StringBuffer buf)
Collects information about nodes of this CFG for writing an XML document.

Overrides:
writeNodes in class Graph
Parameters:
buf - The information about the node.

writeEdges

public void writeEdges(java.lang.StringBuffer buf)
Collects information about edges of this CFG for writing an XML document.

Overrides:
writeEdges in class Graph
Parameters:
buf - The information about the node.