Package sootup.core.graph
Class MutableBlockStmtGraph
java.lang.Object
sootup.core.graph.StmtGraph<MutableBasicBlock>
sootup.core.graph.MutableStmtGraph
sootup.core.graph.MutableBlockStmtGraph
-
Nested Class Summary
Nested classes/interfaces inherited from class sootup.core.graph.StmtGraph
StmtGraph.BlockGraphIterator, StmtGraph.BlockGraphIteratorAndTrapAggregator
-
Constructor Summary
ConstructorDescriptionMutableBlockStmtGraph
(boolean isStatic, MethodSignature sig, LocalGenerator localgen) MutableBlockStmtGraph
(StmtGraph<? extends BasicBlock<?>> graph) copies a StmtGraph into this Mutable instance -
Method Summary
Modifier and TypeMethodDescriptionvoid
The list of Stmts must contain only fallsthrough Stmts; A flow manipulating Stmt (BranchingStmt, return, throw) is only allowed at the Tail.void
addExceptionalEdge
(Stmt stmt, ClassType exceptionType, Stmt traphandlerStmt) Adds an exceptional flow with the type "exception" to a "stmt" which will reach "traphandlerStmt"void
inserts a "stmt" with exceptional flows "traps" into the StmtGraphprotected org.apache.commons.lang3.tuple.Pair<Integer,
MutableBasicBlock> addNodeToBlock
(MutableBasicBlock block, Stmt stmt) Adds a Stmt to the end of a block i.e.hint: little expensive getter - its more of a build/create - currently no overlapsvoid
clearExceptionalEdges
(Stmt node) Modifications of exceptional flows removes all exceptional flows from "stmt"boolean
containsNode
(Stmt node) protected org.apache.commons.lang3.tuple.Pair<Integer,
MutableBasicBlock> createStmtsBlock
(Stmt stmt) creates a Block and inserts the given Stmt.static StmtGraph<?>
createUnmodifiableStmtGraph
(StmtGraph<?> stmtGraph) List<? extends BasicBlock<?>>
exceptionalPredecessorBlocks
(BasicBlock<?> block) exceptionalPredecessors
(Stmt node) it is possible to reach traphandlers through inline code i.e.exceptionalSuccessors
(Stmt node) BasicBlock<?>
getBlockOf
(Stmt stmt) Set<? extends BasicBlock<?>>
List<? extends BasicBlock<?>>
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.BasicBlock<?>
getTrapComparator
(Map<Stmt, Integer> stmtsBlockIdx) Comparator which sorts the trap output in getTraps()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.int
returns the amount of ingoing flows into nodevoid
initializeWith
(List<List<Stmt>> blocks, Map<BranchingStmt, List<Stmt>> successorMap, List<Trap> traps) Creates a Graph representation from the 'legacy' representation i.e.void
insertBefore
(Stmt beforeStmt, List<FallsThroughStmt> stmts, Map<ClassType, Stmt> exceptionMap) protected boolean
isMergeable
(MutableBasicBlock firstBlock, MutableBasicBlock followingBlock) 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.void
putEdge
(BranchingStmt stmtA, int succesorIdx, Stmt stmtB) void
putEdge
(FallsThroughStmt stmtA, Stmt stmtB) Modifications of unexceptional flowsprotected void
putEdge_internal
(Stmt stmtA, int succesorIdx, Stmt stmtB) void
removeBlock
(BasicBlock<?> block) removeEdge
(Stmt from, Stmt to) removes the current outgoing flows of "from" to "to"void
removeExceptionalEdge
(Stmt node, ClassType exceptionType) removes an exceptional flow of the type "exception" flow from "stmt"void
removeExceptionalFlowFromAllBlocks
(ClassType exceptionType, Stmt exceptionHandlerStmt) Removes the specified exceptional flow from all blocks.void
removeNode
(Stmt stmt) removes "stmt" from the StmtGraphvoid
removeNode
(Stmt stmt, boolean keepFlow) Removes a Stmt from the StmtGraph.void
replaceNode
(Stmt oldStmt, Stmt newStmt) Modification of stmts (without manipulating any flows; possible assigned exceptional flows stay the same as well)boolean
replaceSucessorEdge
(Stmt from, Stmt oldTo, Stmt newTo) Replaces all SuccessorEdge(s) of from to oldTo by mewTovoid
setEdges
(BranchingStmt fromStmt, List<Stmt> targets) replaces the current outgoing flows of "from" to "targets"void
setStartingStmt
(Stmt startingStmt) successors
(Stmt node) returns the outgoing flows of node as ordered List.protected boolean
tryMergeBlocks
(MutableBasicBlock firstBlock, MutableBasicBlock followingBlock) trys to merge the second block into the first one if possibleStmtGraph<?>
protected void
updateIndexRangeAfterMerge
(MutableBasicBlock firstBlock, MutableBasicBlock secondBlock) void
Methods inherited from class sootup.core.graph.MutableStmtGraph
addBlock, addNode, insertBefore, setEdges
Methods inherited from class sootup.core.graph.StmtGraph
degree, equals, getAllSuccessors, getBlockIterator, getBranchTargetsOf, getEntrypoints, getExtendedBasicBlockPathBetween, getLabeledStmts, getStmts, getTails, isStmtBranchTarget, iterator, toString, validateStmtConnectionsInGraph
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
-
MutableBlockStmtGraph
public MutableBlockStmtGraph() -
MutableBlockStmtGraph
-
MutableBlockStmtGraph
copies a StmtGraph into this Mutable instance
-
-
Method Details
-
createUnmodifiableStmtGraph
-
initializeWith
public void initializeWith(@Nonnull List<List<Stmt>> blocks, @Nonnull Map<BranchingStmt, List<Stmt>> successorMap, @Nonnull List<Trap> traps) Creates a Graph representation from the 'legacy' representation i.e. a List of Stmts and Traps. -
addExceptionalEdge
public void addExceptionalEdge(@Nonnull Stmt stmt, @Nonnull ClassType exceptionType, @Nonnull Stmt traphandlerStmt) Description copied from class:MutableStmtGraph
Adds an exceptional flow with the type "exception" to a "stmt" which will reach "traphandlerStmt"- Specified by:
addExceptionalEdge
in classMutableStmtGraph
-
removeExceptionalEdge
Description copied from class:MutableStmtGraph
removes an exceptional flow of the type "exception" flow from "stmt"- Specified by:
removeExceptionalEdge
in classMutableStmtGraph
-
clearExceptionalEdges
Description copied from class:MutableStmtGraph
Modifications of exceptional flows removes all exceptional flows from "stmt"- Specified by:
clearExceptionalEdges
in classMutableStmtGraph
-
getBlocks
- Specified by:
getBlocks
in classStmtGraph<MutableBasicBlock>
-
getBlocksSorted
- Specified by:
getBlocksSorted
in classStmtGraph<MutableBasicBlock>
-
addBlock
The list of Stmts must contain only fallsthrough Stmts; A flow manipulating Stmt (BranchingStmt, return, throw) is only allowed at the Tail. (like the conditions of a Block)- Specified by:
addBlock
in classMutableStmtGraph
-
removeBlock
- Specified by:
removeBlock
in classMutableStmtGraph
-
addNode
Description copied from class:MutableStmtGraph
inserts a "stmt" with exceptional flows "traps" into the StmtGraph- Specified by:
addNode
in classMutableStmtGraph
-
updateIndexRangeAfterMerge
protected void updateIndexRangeAfterMerge(@Nonnull MutableBasicBlock firstBlock, @Nonnull MutableBasicBlock secondBlock) -
isMergeable
protected boolean isMergeable(@Nonnull MutableBasicBlock firstBlock, @Nonnull MutableBasicBlock followingBlock) -
tryMergeBlocks
protected boolean tryMergeBlocks(@Nonnull MutableBasicBlock firstBlock, @Nonnull MutableBasicBlock followingBlock) trys to merge the second block into the first one if possible -
createStmtsBlock
@Nonnull protected org.apache.commons.lang3.tuple.Pair<Integer,MutableBasicBlock> createStmtsBlock(@Nonnull Stmt stmt) creates a Block and inserts the given Stmt.- Returns:
- -1 if Stmt is already in the graph!
-
addNodeToBlock
protected org.apache.commons.lang3.tuple.Pair<Integer,MutableBasicBlock> addNodeToBlock(@Nonnull MutableBasicBlock block, @Nonnull Stmt stmt) Adds a Stmt to the end of a block i.e. stmt will become the new tail. -
removeNode
Description copied from class:MutableStmtGraph
removes "stmt" from the StmtGraph- Specified by:
removeNode
in classMutableStmtGraph
-
removeNode
Removes a Stmt from the StmtGraph.It can optionally keep the flow (edges) of the statement by connecting the predecessors of the statement with successors of the statement. Keeping the flow does not work when the statement has multiple successors.
- Specified by:
removeNode
in classMutableStmtGraph
- Parameters:
stmt
- the Stmt to be removedkeepFlow
- flag indicating whether to keep the flow or not- Throws:
IllegalArgumentException
- if keepFlow is true but the stmt has multiple successors
-
replaceNode
Description copied from class:MutableStmtGraph
Modification of stmts (without manipulating any flows; possible assigned exceptional flows stay the same as well)- Specified by:
replaceNode
in classMutableStmtGraph
-
validateBlocks
public void validateBlocks() -
insertBefore
public void insertBefore(@Nonnull Stmt beforeStmt, @Nonnull List<FallsThroughStmt> stmts, @Nonnull Map<ClassType, Stmt> exceptionMap) - Specified by:
insertBefore
in classMutableStmtGraph
-
replaceSucessorEdge
Replaces all SuccessorEdge(s) of from to oldTo by mewTo- Specified by:
replaceSucessorEdge
in classMutableStmtGraph
-
putEdge
Description copied from class:MutableStmtGraph
Modifications of unexceptional flowsAdds a flow "from" to "to". if at least one of the parameter Stmts is not already in the StmtGraph it will be added. if "to" needs to be added to the StmtGraph i.e. "to" is not already in the StmtGraph the method assumes "to" has the same exceptional flows as "from".
- Specified by:
putEdge
in classMutableStmtGraph
-
putEdge
- Specified by:
putEdge
in classMutableStmtGraph
-
putEdge_internal
-
removeEdge
Description copied from class:MutableStmtGraph
removes the current outgoing flows of "from" to "to"- Specified by:
removeEdge
in classMutableStmtGraph
- Returns:
- returns List of the successor indices of "from" that were connected to "to" - items are 0 in case of FallsThroughStmts or idx > 0 in case of BranchingStmts with multiple successors
-
setEdges
Description copied from class:MutableStmtGraph
replaces the current outgoing flows of "from" to "targets"- Specified by:
setEdges
in classMutableStmtGraph
-
getStartingStmt
- Specified by:
getStartingStmt
in classStmtGraph<MutableBasicBlock>
-
getStartingStmtBlock
- Specified by:
getStartingStmtBlock
in classStmtGraph<MutableBasicBlock>
-
getBlockOf
- Specified by:
getBlockOf
in classStmtGraph<MutableBasicBlock>
-
unmodifiableStmtGraph
- Specified by:
unmodifiableStmtGraph
in classMutableStmtGraph
-
setStartingStmt
- Specified by:
setStartingStmt
in classMutableStmtGraph
-
getNodes
Description copied from class:StmtGraph
returns the nodes in this graph in a non-deterministic order (->Set) to get the nodes in linearized, ordered manner use iterator() or getStmts.- Specified by:
getNodes
in classStmtGraph<MutableBasicBlock>
-
containsNode
- Specified by:
containsNode
in classStmtGraph<MutableBasicBlock>
-
predecessors
Description copied from class:StmtGraph
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`- Specified by:
predecessors
in classStmtGraph<MutableBasicBlock>
-
exceptionalPredecessors
Description copied from class:StmtGraph
it is possible to reach traphandlers through inline code i.e. without any exceptional flow- Specified by:
exceptionalPredecessors
in classStmtGraph<MutableBasicBlock>
-
exceptionalPredecessors
-
exceptionalPredecessorBlocks
-
successors
Description copied from class:StmtGraph
returns the outgoing flows of node as ordered List. The List can have duplicate entries!- Specified by:
successors
in classStmtGraph<MutableBasicBlock>
-
exceptionalSuccessors
- Specified by:
exceptionalSuccessors
in classStmtGraph<MutableBasicBlock>
-
inDegree
Description copied from class:StmtGraph
returns the amount of ingoing flows into node- Specified by:
inDegree
in classStmtGraph<MutableBasicBlock>
-
outDegree
Description copied from class:StmtGraph
returns the amount of flows that start from node- Specified by:
outDegree
in classStmtGraph<MutableBasicBlock>
-
hasEdgeConnecting
Description copied from class:StmtGraph
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.- Specified by:
hasEdgeConnecting
in classStmtGraph<MutableBasicBlock>
-
getTrapComparator
Comparator which sorts the trap output in getTraps() -
buildTraps
hint: little expensive getter - its more of a build/create - currently no overlaps- Specified by:
buildTraps
in classStmtGraph<MutableBasicBlock>
-
removeExceptionalFlowFromAllBlocks
public void removeExceptionalFlowFromAllBlocks(@Nonnull ClassType exceptionType, @Nonnull Stmt exceptionHandlerStmt) Description copied from class:StmtGraph
Removes the specified exceptional flow from all blocks.- Specified by:
removeExceptionalFlowFromAllBlocks
in classStmtGraph<MutableBasicBlock>
- Parameters:
exceptionType
- The class type of the exceptional flow.exceptionHandlerStmt
- The handler statement of the exceptional flow.
-