Class UnitGraph
- java.lang.Object
-
- soot.toolkits.graph.UnitGraph
-
- All Implemented Interfaces:
Iterable<Unit>,DirectedBodyGraph<Unit>,DirectedGraph<Unit>
- Direct Known Subclasses:
BriefUnitGraph,EnhancedUnitGraph,ExceptionalUnitGraph,TrapUnitGraph
public abstract class UnitGraph extends Object implements DirectedBodyGraph<Unit>
Represents a CFG where the nodes are
Unitinstances and edges represent unexceptional and (possibly) exceptional control flow between Units.This is an abstract class, providing the facilities used to build CFGs for specific purposes.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddEdge(Map<Unit,List<Unit>> unitToSuccs, Map<Unit,List<Unit>> unitToPreds, Unit head, Unit tail)Utility method for adding an edge to maps representing the CFG.protected voidbuildHeadsAndTails()Utility method used in the construction ofUnitGraphs, to be called only after the unitToPreds and unitToSuccs maps have been built.protected voidbuildUnexceptionalEdges(Map<Unit,List<Unit>> unitToSuccs, Map<Unit,List<Unit>> unitToPreds)Utility method for UnitGraph constructors.protected Map<Unit,List<Unit>>combineMapValues(Map<Unit,List<Unit>> mapA, Map<Unit,List<Unit>> mapB)BodygetBody()List<Unit>getExtendedBasicBlockPathBetween(Unit from, Unit to)Look for a path in graph, from def to use.List<Unit>getHeads()Returns a list of entry points for this graph.List<Unit>getPredsOf(Unit u)Returns a list of predecessors for the given node in the graph.List<Unit>getSuccsOf(Unit u)Returns a list of successors for the given node in the graph.List<Unit>getTails()Returns a list of exit points for this graph.Iterator<Unit>iterator()Returns an iterator for the nodes in this graph.intsize()Returns the node count for this graph.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
body
protected final Body body
-
method
protected final SootMethod method
-
-
Constructor Detail
-
UnitGraph
protected UnitGraph(Body body)
Performs the work that is required to construct any sort of UnitGraph.- Parameters:
body- The body of the method for which to construct a control flow graph.
-
-
Method Detail
-
buildUnexceptionalEdges
protected void buildUnexceptionalEdges(Map<Unit,List<Unit>> unitToSuccs, Map<Unit,List<Unit>> unitToPreds)
Utility method for UnitGraph constructors. It computes the edges corresponding to unexceptional control flow.- Parameters:
unitToSuccs- AMapfromUnits toLists ofUnits. This is an ``out parameter''; callers must pass an emptyMap. buildUnexceptionalEdges will add a mapping for every Unit in the body to a list of its unexceptional successors.unitToPreds- AMapfromUnits toLists ofUnits. This is an ``out parameter''; callers must pass an emptyMap. buildUnexceptionalEdges will add a mapping for every Unit in the body to a list of its unexceptional predecessors.
-
buildHeadsAndTails
protected void buildHeadsAndTails()
Utility method used in the construction of
UnitGraphs, to be called only after the unitToPreds and unitToSuccs maps have been built.UnitGraphprovides an implementation ofbuildHeadsAndTails()which defines the graph's set of heads to include the firstUnitin the graph's body, together with any other Unit which has no predecessors. It defines the graph's set of tails to include all Units with no successors. Subclasses ofUnitGraphmay override this method to change the criteria for classifying a node as a head or tail.
-
combineMapValues
protected Map<Unit,List<Unit>> combineMapValues(Map<Unit,List<Unit>> mapA, Map<Unit,List<Unit>> mapB)
Utility method that produces a new map from theUnits of this graph's body to the union of the values stored in the two argumentMaps, used to combine the maps of exceptional and unexceptional predecessors and successors into maps of all predecessors and successors. The values stored in both argument maps must beLists ofUnits, which are assumed not to contain any duplicate Units.- Parameters:
mapA- The first map to be combined.mapB- The second map to be combined.
-
addEdge
protected void addEdge(Map<Unit,List<Unit>> unitToSuccs, Map<Unit,List<Unit>> unitToPreds, Unit head, Unit tail)
Utility method for adding an edge to maps representing the CFG.
-
getBody
public Body getBody()
- Specified by:
getBodyin interfaceDirectedBodyGraph<Unit>- Returns:
- The body from which this UnitGraph was built.
- See Also:
Body
-
getExtendedBasicBlockPathBetween
public List<Unit> getExtendedBasicBlockPathBetween(Unit from, Unit to)
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.- Parameters:
from- start point for the path.to- end point for the path.- Returns:
- null if there is no such path.
-
getHeads
public List<Unit> getHeads()
Description copied from interface:DirectedGraphReturns a list of entry points for this graph.- Specified by:
getHeadsin interfaceDirectedGraph<Unit>
-
getTails
public List<Unit> getTails()
Description copied from interface:DirectedGraphReturns a list of exit points for this graph.- Specified by:
getTailsin interfaceDirectedGraph<Unit>
-
getPredsOf
public List<Unit> getPredsOf(Unit u)
Description copied from interface:DirectedGraphReturns a list of predecessors for the given node in the graph.- Specified by:
getPredsOfin interfaceDirectedGraph<Unit>
-
getSuccsOf
public List<Unit> getSuccsOf(Unit u)
Description copied from interface:DirectedGraphReturns a list of successors for the given node in the graph.- Specified by:
getSuccsOfin interfaceDirectedGraph<Unit>
-
size
public int size()
Description copied from interface:DirectedGraphReturns the node count for this graph.- Specified by:
sizein interfaceDirectedGraph<Unit>
-
iterator
public Iterator<Unit> iterator()
Description copied from interface:DirectedGraphReturns an iterator for the nodes in this graph. No specific ordering of the nodes is guaranteed.
-
-