Package org.jtool.cfg
Class CFG
An object storing information on a control flow graph (CFG).
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(BasicBlock block) Adds a basic block to this CFG.backwardReachableNodes
(CFGNode startnode, boolean loopbackOk, boolean fallthroughOk) Walks backward from a given node on this CFG and collects the traversed nodes.backwardReachableNodes
(CFGNode startnode, boolean loopbackOk, boolean fallthroughOk, StopConditionOnReachablePath condition) Walks backward from a given node on this CFG and collects the traversed nodes.backwardReachableNodes
(CFGNode from, CFGNode to, boolean loopbackOk, boolean fallthroughOk) Walks backward between two nodes on this CFG and collects the traversed nodes.void
Clears basic blocks existing in this CFG.constrainedReachableNodes
(CFGNode from, CFGNode to) Calculates a constrained reachable nodes between two nodes.boolean
boolean
Tests if a given CFG is equal to this CFG.org.jtool.cfg.internal.DominantStatement
findDominantStatement
(CFGNode node) Finds a statement that dominates a given node.forwardReachableNodes
(CFGNode startnode, boolean loopbackOk, boolean fallthroughOk) Walks forward from a given node on this CFG and collects the traversed nodes.forwardReachableNodes
(CFGNode startnode, boolean loopbackOk, boolean fallthroughOk, StopConditionOnReachablePath condition) Walks forward from a given node on this CFG and collects the traversed nodes.forwardReachableNodes
(CFGNode from, CFGNode to, boolean loopbackOk, boolean fallthroughOk) Walks forward between two nodes on this CFG and collects the traversed nodes.Returns all basic blocks existing in this CFG.org.jtool.cfg.internal.DominantStatement
Obtains the dominant statement having a given flow.Returns the entry node of this CFG.Finds an exception catch flow edge outgoing from a given node.Returns a successor node of a given CFG node with respect to the exception catch flow.Returns the exit node of this CFG.Finds a fall-through control flow edge outgoing from a given node.Returns a successor node of a given CFG node with respect to the fall-through control flow.getFalseFlowFrom
(CFGNode node) Finds a false control flow edge outgoing from a given node.getFalseSuccessor
(CFGNode node) Returns a successor node of a given CFG node with respect to the false control flow.Obtains CFG nodes for field accesses.Finds an control flow edge specified by given source and destination CFG nodes.long
getId()
Returns the identification number of this CFG, which is equals to that of the entry node.Obtains CFG nodes for method calls.getNode
(long id) Returns a CFG node with a given identification number.Returns the fully-qualified name of this CFG, which is equals to the fully-qualified of a class, a method, or a field corresponding to this CFG.Obtains CFG nodes for return statements.Obtains CFG nodes for statements having defined and used variables.getTrueFlowFrom
(CFGNode node) Finds a true control flow edge outgoing from a given node.getTrueSuccessor
(CFGNode node) Returns a successor node of a given CFG node with respect to the true control flow.int
hashCode()
boolean
Tests if the method of this CFG contains a try statement.boolean
Tests if a given CFG node represents a branch in this CFG.boolean
isField()
Tests if this CFG is created from a field.boolean
isJoinNode
(CFGNode node) Tests if a given CFG node represents a join in this CFG.boolean
Tests if a given CFG node represents a loop in this CFG.boolean
isMethod()
Tests if this CFG is created from a method.postDominator
(CFGNode anchor) Calculates post-dominant nodes for a given CFG.void
print()
Displays information on this graph.reachableNodes
(CFGNode from, CFGNode to, boolean loopbackOk, boolean fallthroughOk) Calculates nodes traversed between two nodes on this CFG, which are reachable from the both nodes.void
registerDominantStatement
(ControlFlow flow, org.jtool.cfg.internal.DominantStatement statement) Registers a control flow and a dominant statement having the flow.void
setEntryNode
(CFGEntry node) Sets the entry node of this CFG.void
setExitNode
(CFGNode node) Sets the exit node of this CFG.void
setTimeoutOccurred
(boolean bool) Sets whether the timeout occurred.boolean
Tests if the timeout occurred.toString()
Obtains information on this CFG.protected String
Obtains information on all edges enclosed in this graph.protected String
Obtains information on all nodes enclosed in this graph.
-
Constructor Details
-
CFG
public CFG()Creates a new, empty object for storing a CFG information. This method is not intended to be invoked by clients.
-
-
Method Details
-
setEntryNode
Sets the entry node of this CFG. This method is not intended to be invoked by clients.- Parameters:
node
- the entry node of this CFG
-
getEntryNode
Returns the entry node of this CFG.- Returns:
- the entry node of this CFG
-
setExitNode
Sets the exit node of this CFG. This method is not intended to be invoked by clients.- Parameters:
node
- exit end node of this CFG
-
getExitNode
Returns the exit node of this CFG.- Returns:
- the exit node of this CFG
-
setTimeoutOccurred
public void setTimeoutOccurred(boolean bool) Sets whether the timeout occurred.- Parameters:
bool
-true
if the timeout occurred, otherwisefalse
-
timeoutOccurred
public boolean timeoutOccurred()Tests if the timeout occurred.- Returns:
true
if the timeout occurred, otherwisefalse
-
getId
public long getId()Returns the identification number of this CFG, which is equals to that of the entry node.- Returns:
- the identification number of this CFG
-
getQualifiedName
Returns the fully-qualified name of this CFG, which is equals to the fully-qualified of a class, a method, or a field corresponding to this CFG.- Returns:
- the CFG name.
-
add
Adds a basic block to this CFG. This method is not intended to be invoked by clients.- Parameters:
block
- the basic block to be added
-
getBasicBlocks
Returns all basic blocks existing in this CFG.- Returns:
- the collection of the basic blocks
-
clearBasicBlocks
public void clearBasicBlocks()Clears basic blocks existing in this CFG. -
isMethod
public boolean isMethod()Tests if this CFG is created from a method.- Returns:
true
if this CFG is created from a method, otherwisefalse
-
isField
public boolean isField()Tests if this CFG is created from a field.- Returns:
true
if this CFG is created from a field, otherwisefalse
-
isBranch
Tests if a given CFG node represents a branch in this CFG.- Parameters:
node
- the node to be checked- Returns:
true
if the node represents a branch, otherwisefalse
-
isLoop
Tests if a given CFG node represents a loop in this CFG.- Parameters:
node
- the node to be checked- Returns:
true
if the node represents a loop, otherwisefalse
-
isJoinNode
Tests if a given CFG node represents a join in this CFG.- Parameters:
node
- the node to be checked- Returns:
true
if the node represents a join, otherwisefalse
-
getNode
Returns a CFG node with a given identification number.- Parameters:
id
- the identification number of the node to be retrieved- Returns:
- the found node, or
null
if no node is found
-
getFlow
Finds an control flow edge specified by given source and destination CFG nodes.- Parameters:
src
- the source CFG node for the edge to be retrieveddst
- the destination CFG node for the edge to be retrieved- Returns:
- the found edge, or
null
if no edge is found
-
getTrueFlowFrom
Finds a true control flow edge outgoing from a given node.- Parameters:
node
- the CFG node having the outgoing edge- Returns:
- the found true control flow edge, or
null
if no edge is found
-
getFalseFlowFrom
Finds a false control flow edge outgoing from a given node.- Parameters:
node
- the CFG node having the outgoing edge- Returns:
- the found false control flow edge, or
null
if no edge is found
-
getFallThroughFlowFrom
Finds a fall-through control flow edge outgoing from a given node.- Parameters:
node
- the CFG node having the outgoing edge- Returns:
- the found fall-through control flow edge, or
null
if no edge is found
-
getExceptionCatchFlowFrom
Finds an exception catch flow edge outgoing from a given node.- Parameters:
node
- the CFG node having the outgoing edge- Returns:
- the found exception catch flow edge, or
null
if no edge is found
-
getTrueSuccessor
Returns a successor node of a given CFG node with respect to the true control flow.- Parameters:
node
- the source node- Returns:
- the found successor, or
null
if no successor is found
-
getFalseSuccessor
Returns a successor node of a given CFG node with respect to the false control flow.- Parameters:
node
- the source node- Returns:
- the found successor, or
null
if no successor is found
-
getFallThroughSuccessor
Returns a successor node of a given CFG node with respect to the fall-through control flow.- Parameters:
node
- the source node- Returns:
- the found successor, or
null
if no successor is found
-
getExceptionCatchSuccessor
Returns a successor node of a given CFG node with respect to the exception catch flow.- Parameters:
node
- the source node- Returns:
- the found successor, or
null
if no successor is found
-
hasTryStatement
public boolean hasTryStatement()Tests if the method of this CFG contains a try statement.- Returns:
true
if the method contains a try statement, otherwisefalse
-
getMethodCallNodes
Obtains CFG nodes for method calls.- Returns:
- the collection of the method call nodes
-
getStatementNodes
Obtains CFG nodes for statements having defined and used variables.- Returns:
- the collection of the statement nodes
-
getFieldAccessNodes
Obtains CFG nodes for field accesses.- Returns:
- the collection of the field access nodes
-
getReturnNodes
Obtains CFG nodes for return statements.- Returns:
- the collection of the return statement nodes
-
forwardReachableNodes
public List<CFGNode> forwardReachableNodes(CFGNode startnode, boolean loopbackOk, boolean fallthroughOk, StopConditionOnReachablePath condition) Walks forward from a given node on this CFG and collects the traversed nodes.- Parameters:
startnode
- the starting node to be traversedloopbackOk
-true
if loop-back edges can be traversed, otherwisefalse
fallthroughOk
-true
if fall-through edges can be traversed, otherwisefalse
condition
- the condition that stops traversing- Returns:
- the collection of the forward-traversed nodes
-
forwardReachableNodes
public List<CFGNode> forwardReachableNodes(CFGNode startnode, boolean loopbackOk, boolean fallthroughOk) Walks forward from a given node on this CFG and collects the traversed nodes.- Parameters:
startnode
- the starting node to be traversedloopbackOk
-true
if loop-back edges can be traversed, otherwisefalse
fallthroughOk
-true
if fall-through edges can be traversed, otherwisefalse
- Returns:
- the collection of the forward-traversed nodes
-
forwardReachableNodes
public List<CFGNode> forwardReachableNodes(CFGNode from, CFGNode to, boolean loopbackOk, boolean fallthroughOk) Walks forward between two nodes on this CFG and collects the traversed nodes.- Parameters:
from
- the source nodeto
- the destination nodeloopbackOk
-true
if loop-back edges can be traversed, otherwisefalse
fallthroughOk
-true
if fall-through edges can be traversed, otherwisefalse
- Returns:
- the collection of the forward-traversed nodes
-
backwardReachableNodes
public List<CFGNode> backwardReachableNodes(CFGNode startnode, boolean loopbackOk, boolean fallthroughOk, StopConditionOnReachablePath condition) Walks backward from a given node on this CFG and collects the traversed nodes.- Parameters:
startnode
- the starting node to be traversedloopbackOk
-true
if loop-back edges can be traversed, otherwisefalse
fallthroughOk
-true
if fall-through edges can be traversed, otherwisefalse
condition
- the condition that stops traversing- Returns:
- the collection of the backward-traversed nodes
-
backwardReachableNodes
public List<CFGNode> backwardReachableNodes(CFGNode startnode, boolean loopbackOk, boolean fallthroughOk) Walks backward from a given node on this CFG and collects the traversed nodes.- Parameters:
startnode
- the starting node to be traversedloopbackOk
-true
if loop-back edges can be traversed, otherwisefalse
fallthroughOk
-true
if fall-through edges can be traversed, otherwisefalse
- Returns:
- the collection of the backward-traversed nodes
-
backwardReachableNodes
public List<CFGNode> backwardReachableNodes(CFGNode from, CFGNode to, boolean loopbackOk, boolean fallthroughOk) Walks backward between two nodes on this CFG and collects the traversed nodes.- Parameters:
from
- the source nodeto
- the destination nodeloopbackOk
-true
if loop-back edges can be traversed, otherwisefalse
fallthroughOk
-true
if fall-through edges can be traversed, otherwisefalse
- Returns:
- the collection of the backward-traversed nodes
-
reachableNodes
public Set<CFGNode> reachableNodes(CFGNode from, CFGNode to, boolean loopbackOk, boolean fallthroughOk) Calculates nodes traversed between two nodes on this CFG, which are reachable from the both nodes.- Parameters:
from
- the source nodeto
- the destination nodeloopbackOk
-true
if loop-back edges can be traversed, otherwisefalse
fallthroughOk
-true
if fall-through edges can be traversed, otherwisefalse
- Returns:
- the collection of the traversed nodes
-
constrainedReachableNodes
Calculates a constrained reachable nodes between two nodes.- Parameters:
from
- the source nodeto
- the destination node- Returns:
- the collection of the reachable nodes
-
postDominator
Calculates post-dominant nodes for a given CFG. This is a naive implementation. Use Lengauer-Tarjan Dominator Tree Algorithm to make the calculation efficient.- Parameters:
anchor
- the anchor node that might dominate other nodes- Returns:
- the collection of the dominated nodes
-
registerDominantStatement
public void registerDominantStatement(ControlFlow flow, org.jtool.cfg.internal.DominantStatement statement) Registers a control flow and a dominant statement having the flow. This method is not intended to be invoked by clients.- Parameters:
flow
- a flow that dominates nodesstatement
- a dominant statement having the flow
-
getDominantStatement
Obtains the dominant statement having a given flow. This method is not intended to be invoked by clients.- Parameters:
flow
- the control flow- Returns:
- the found dominant statement,
null
if it was found
-
findDominantStatement
Finds a statement that dominates a given node.- Parameters:
node
- the node to be retrieved- Returns:
- the found dominant statement
-
equals
-
equals
Tests if a given CFG is equal to this CFG.- Parameters:
cfg
- the CFG to be checked- Returns:
- the
true
if the given CFG is equal to this CFG
-
hashCode
public int hashCode() -
print
public void print()Displays information on this graph. -
toString
Obtains information on this CFG.- Overrides:
toString
in classGraph<CFGNode,
ControlFlow> - Returns:
- the string representing the information
-
toStringForNodes
Obtains information on all nodes enclosed in this graph.- Overrides:
toStringForNodes
in classGraph<CFGNode,
ControlFlow> - Returns:
- the string representing the information
-
toStringForEdges
Obtains information on all edges enclosed in this graph.- Overrides:
toStringForEdges
in classGraph<CFGNode,
ControlFlow> - Returns:
- the string representing the information
-