Package sootup.core.graph
Class ControlFlowGraph<V extends BasicBlock<V>>
java.lang.Object
sootup.core.graph.ControlFlowGraph<V>
- Direct Known Subclasses:
ForwardingControlFlowGraph,ImmutableBlockControlFlowGraph,MutableControlFlowGraph
public abstract class ControlFlowGraph<V extends BasicBlock<V>>
extends Object
implements Iterable<Stmt>
Interface for control flow graphs on Jimple Stmts. A ControlFlowGraph is directed and connected
(except for traphandlers - those are not connected to the unexceptional flow via
ControlFlowGraph). 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 ControlFlowGraph 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 ControlFlowGraph it is not allowed to have unconnected Nodes.
Stmt stmt1, stmt2; ... MutableControlFlowGraph graph = new MutableBlockControlFlowGraph(); graph.setEntryPoint(stmt1); graph.addNode(stmt1); graph.addNode(stmt2); graph.putEdge(stmt1, stmt2);
- Author:
- Markus Schmidt
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleancontainsNode(@NonNull Stmt node) intreturns the amount of flows with node as source or target.booleanexceptionalPredecessors(@NonNull Stmt node) it is possible to reach traphandlers through inline code i.e. without any exceptional flowexceptionalSuccessors(@NonNull Stmt node) getAllSuccessors(@NonNull Stmt stmt) Collects all successors i.e. unexceptional and exceptional successors of a given stmt into a list.Iterator<BasicBlock<?>>abstract BasicBlock<?>getBlockOf(@NonNull Stmt stmt) abstract @NonNull Collection<? extends BasicBlock<?>>abstract @NonNull List<? extends BasicBlock<?>>getBranchTargetsOf(BranchingStmt fromStmt) @NonNull Collection<Stmt>returns a Collection of all stmt in the graph that are either the starting stmt or only have an exceptional ingoing flowgetExtendedBasicBlockPathBetween(@NonNull Stmt from, @NonNull Stmt to) Look for a path in graph, from def to use.abstract @NonNull 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 Stmtabstract BasicBlock<?>getStmts()getTails()returns a Collection of Stmts that leave the body (i.e.abstract List<BasicBlock<?>>abstract booleanhasEdgeConnecting(@NonNull Stmt source, @NonNull 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 intreturns the amount of ingoing flows into nodebooleanisStmtBranchTarget(@NonNull Stmt targetStmt) iterator()abstract intreturns the amount of flows that start from nodepredecessors(@NonNull Stmt node) 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`abstract voidremoveExceptionalFlowFromAllBlocks(ClassType exceptionType, Stmt exceptionHandlerStmt) Removes the specified exceptional flow from all blocks.successors(@NonNull Stmt node) returns the outgoing flows of node as ordered List.toString()voidvalidates 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, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ControlFlowGraph
public ControlFlowGraph()
-
-
Method Details
-
getStartingStmt
-
getStartingStmtBlock
-
getTailStmtBlocks
-
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. -
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:
iteratorin interfaceIterable<V extends BasicBlock<V>>
-
getBranchTargetsOf
-
isStmtBranchTarget
-
toString
-