Package sootup.core.graph
Class StmtGraph<V extends BasicBlock<V>>
java.lang.Object
sootup.core.graph.StmtGraph<V>
- Direct Known Subclasses:
ForwardingStmtGraph
,ImmutableBlockStmtGraph
,MutableStmtGraph
Interface for control flow graphs on Jimple Stmts. A StmtGraph is directed and connected (except
for traphandlers - those are not connected to the unexceptional flow via StmtGraph). Its directed
edges represent flows between Stmts. If the edge starts in a branching Stmt there is an edge for
each flow to the target Stmt. This can include duplicate flows to the same target e.g. for
JSwitchStmt, so that every label has its own flow to a target.
THe StmtGraph structure keeps the edge insertion order of each node to store information about
successor stmts in its edges for Branching. Ordered edges are necessary because we want to
associate the i-th item with the i-th branch case of a BranchingStmt
. In a valid
StmtGraph it is not allowed to have unconnected Nodes.
Stmt stmt1, stmt2; ... MutableStmtGraph graph = new MutableBlockStmtGraph(); graph.setEntryPoint(stmt1); graph.addNode(stmt1); graph.addNode(stmt2); graph.putEdge(stmt1, stmt2);
- Author:
- Markus Schmidt
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Iterates over the blocksclass
Iterates over the Blocks and collects/aggregates Trap information -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionreturns a (reconstructed) list of traps like the traptable in the bytecodeabstract boolean
containsNode
(Stmt node) int
returns the amount of flows with node as source or target.boolean
exceptionalPredecessors
(Stmt node) it is possible to reach traphandlers through inline code i.e.exceptionalSuccessors
(Stmt node) getAllSuccessors
(Stmt stmt) Collects all successors i.e.Iterator<BasicBlock<?>>
abstract BasicBlock<?>
getBlockOf
(Stmt stmt) abstract Collection<? extends BasicBlock<?>>
abstract List<? extends BasicBlock<?>>
getBranchTargetsOf
(BranchingStmt fromStmt) returns a Collection of all stmt in the graph that are either the starting stmt or only have an exceptional ingoing flowgetExtendedBasicBlockPathBetween
(Stmt from, Stmt to) Look for a path in graph, from def to use.Returns the result of iterating through all Stmts in this body.abstract Collection<Stmt>
getNodes()
returns the nodes in this graph in a non-deterministic order (->Set) to get the nodes in linearized, ordered manner use iterator() or getStmts.abstract Stmt
abstract BasicBlock<?>
getStmts()
getTails()
returns a Collection of Stmts that leave the body (i.e.abstract boolean
hasEdgeConnecting
(Stmt source, Stmt target) returns true if there is a flow between source and target throws an Exception if at least one of the parameters is not contained in the graph.abstract int
returns the amount of ingoing flows into nodeboolean
isStmtBranchTarget
(Stmt targetStmt) iterator()
abstract int
returns the amount of flows that start from nodepredecessors
(Stmt node) returns the ingoing flows to node as an List with no reliable/specific order and possibly duplicate entries i.e.abstract void
removeExceptionalFlowFromAllBlocks
(ClassType exceptionType, Stmt exceptionHandlerStmt) Removes the specified exceptional flow from all blocks.successors
(Stmt node) returns the outgoing flows of node as ordered List.toString()
void
validates whether the each Stmt has the correct amount of outgoing flows.Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
StmtGraph
public StmtGraph()
-
-
Method Details
-
getStartingStmt
-
getStartingStmtBlock
-
getNodes
returns the nodes in this graph in a non-deterministic order (->Set) to get the nodes in linearized, ordered manner use iterator() or getStmts. -
getStmts
-
getBlocks
-
getBlocksSorted
-
getBlockIterator
-
getBlockOf
-
containsNode
-
predecessors
returns the ingoing flows to node as an List with no reliable/specific order and possibly duplicate entries i.e. if a JSwitchStmt has multiple cases that brnach to `node` -
exceptionalPredecessors
it is possible to reach traphandlers through inline code i.e. without any exceptional flow -
successors
returns the outgoing flows of node as ordered List. The List can have duplicate entries! -
exceptionalSuccessors
-
getAllSuccessors
Collects all successors i.e. unexceptional and exceptional successors of a given stmt into a list.- Parameters:
stmt
- in the given graph- Returns:
- a list containing the unexceptional+exceptional successors of the given stmt
-
inDegree
returns the amount of ingoing flows into node -
outDegree
returns the amount of flows that start from node -
degree
returns the amount of flows with node as source or target. -
hasEdgeConnecting
returns true if there is a flow between source and target throws an Exception if at least one of the parameters is not contained in the graph. -
buildTraps
returns a (reconstructed) list of traps like the traptable in the bytecodeNote: if you need exceptionional flow information in more augmented with the affected blocks/stmts and not just a (reconstructed, possibly more verbose) traptable - have a look at BasicBlock.getExceptionalSuccessor()
-
removeExceptionalFlowFromAllBlocks
public abstract void removeExceptionalFlowFromAllBlocks(ClassType exceptionType, Stmt exceptionHandlerStmt) Removes the specified exceptional flow from all blocks.- Parameters:
exceptionType
- The class type of the exceptional flow.exceptionHandlerStmt
- The handler statement of the exceptional flow.
-
getTails
returns a Collection of Stmts that leave the body (i.e. JReturnVoidStmt, JReturnStmt and JThrowStmt) -
getEntrypoints
returns a Collection of all stmt in the graph that are either the starting stmt or only have an exceptional ingoing flow -
validateStmtConnectionsInGraph
public void validateStmtConnectionsInGraph()validates whether the each Stmt has the correct amount of outgoing flows. -
getExtendedBasicBlockPathBetween
Look for a path in graph, from def to use. This path has to lie inside an extended basic block (and this property implies uniqueness.). The path returned includes from and to. FIXME: ms: explain better- Parameters:
from
- start point for the path.to
- end point for the path.- Returns:
- null if there is no such path.
-
equals
-
iterator
- Specified by:
iterator
in interfaceIterable<V extends BasicBlock<V>>
-
getBranchTargetsOf
-
isStmtBranchTarget
-
getLabeledStmts
Returns the result of iterating through all Stmts in this body. All Stmts thus found are returned. Branching Stmts and statements which use PhiExpr will have Stmts; a Stmt contains a Stmt that is either a target of a branch or is being used as a pointer to the end of a CFG block.This method was typically used for pointer patching, e.g. when the unit chain is cloned.
- Returns:
- A collection of all the Stmts that are targets of a BranchingStmt
-
toString
-