Package com.tonic.analysis.pdg.sdg
Class SDG
- java.lang.Object
-
- com.tonic.analysis.pdg.sdg.SDG
-
public class SDG extends Object
System dependence graph - the per-method PDGs joined by parameter and summary edges at resolved call sites.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddEdge(PDGEdge edge)Adds an edge if it is not already present, links it to its endpoints and files interprocedural edges under the summary or parameter list.voidaddMethodEntry(MethodReference methodRef, SDGEntryNode entry)Registers a procedure entry node and adds it to the node set.voidaddMethodPDG(MethodReference methodRef, PDG pdg)Registers a method's PDG and folds its nodes and edges into the graph-wide sets, skipping ones already present.voidaddNode(PDGNode node)Adds a node if it is not already present.intallocateNodeId()Hands out the next unused node id.List<SDGActualInNode>getActualIns(SDGCallNode callNode)List<SDGActualOutNode>getActualOuts(SDGCallNode callNode)Collects the actual-out node of a call site, if it has one.List<PDGEdge>getAllEdges()List<PDGNode>getAllNodes()CallGraphgetCallGraph()List<SDGCallNode>getCallNodes(SDGEntryNode entry)Collects the call sites of a procedure from its PDG, plus any registered call node not already in that PDG.intgetCallNodesCount()Counts the call nodes across every registered node.Set<SDGCallNode>getCallSitesIn(MethodReference method)Finds the call sites appearing in a method's PDG.Set<SDGCallNode>getCallSitesTo(MethodReference method)Finds the call sites resolved to a method.Set<SDGEntryNode>getCallTargets(SDGCallNode callNode)Map<SDGCallNode,Set<SDGEntryNode>>getCallToTargets()SDGEntryNodegetEntry(MethodReference method)Collection<SDGEntryNode>getEntryNodes()List<SDGFormalInNode>getFormalIns(SDGEntryNode entry)List<SDGFormalOutNode>getFormalOuts(SDGEntryNode entry)Collects the formal-out node of a procedure, if it has one.intgetInterproceduralEdgeCount()List<PDGEdge>getInterproceduralEdges()intgetMethodCount()Map<MethodReference,SDGEntryNode>getMethodEntries()Map<MethodReference,PDG>getMethodPDGs()Set<MethodReference>getMethods()intgetNextNodeId()List<PDGEdge>getParameterEdges()PDGgetPDG(MethodReference method)intgetSummaryEdgeCount()List<PDGEdge>getSummaryEdges()List<PDGEdge>getSummaryEdges(SDGCallNode callNode)Selects the summary edges whose source is an actual-in of a call site.intgetTotalEdgeCount()intgetTotalNodeCount()voidregisterCallTarget(SDGCallNode callNode, SDGEntryNode targetEntry)Records a resolved callee for a call site and points the call node at it.StringtoString()
-
-
-
Constructor Detail
-
SDG
public SDG(CallGraph callGraph)
Creates an empty graph over a call graph; PDGs and entries are added afterwards.- Parameters:
callGraph- the call graph the procedures come from
-
-
Method Detail
-
getCallGraph
public CallGraph getCallGraph()
- Returns:
- the call graph
-
getMethodPDGs
public Map<MethodReference,PDG> getMethodPDGs()
- Returns:
- the method PD gs
-
getMethodEntries
public Map<MethodReference,SDGEntryNode> getMethodEntries()
- Returns:
- the method entries
-
getCallToTargets
public Map<SDGCallNode,Set<SDGEntryNode>> getCallToTargets()
- Returns:
- the call to targets
-
getNextNodeId
public int getNextNodeId()
- Returns:
- the next node id
-
allocateNodeId
public int allocateNodeId()
Hands out the next unused node id.- Returns:
- the allocated id
-
addMethodPDG
public void addMethodPDG(MethodReference methodRef, PDG pdg)
Registers a method's PDG and folds its nodes and edges into the graph-wide sets, skipping ones already present.- Parameters:
methodRef- the methodpdg- its dependence graph
-
addMethodEntry
public void addMethodEntry(MethodReference methodRef, SDGEntryNode entry)
Registers a procedure entry node and adds it to the node set.- Parameters:
methodRef- the methodentry- its entry node
-
addNode
public void addNode(PDGNode node)
Adds a node if it is not already present.- Parameters:
node- the node to add
-
addEdge
public void addEdge(PDGEdge edge)
Adds an edge if it is not already present, links it to its endpoints and files interprocedural edges under the summary or parameter list.- Parameters:
edge- the edge to add
-
registerCallTarget
public void registerCallTarget(SDGCallNode callNode, SDGEntryNode targetEntry)
Records a resolved callee for a call site and points the call node at it.- Parameters:
callNode- the call sitetargetEntry- the callee entry node
-
getPDG
public PDG getPDG(MethodReference method)
- Parameters:
method- the method to look up- Returns:
- its PDG, or null if none is registered
-
getEntry
public SDGEntryNode getEntry(MethodReference method)
- Parameters:
method- the method to look up- Returns:
- its entry node, or null if none is registered
-
getCallTargets
public Set<SDGEntryNode> getCallTargets(SDGCallNode callNode)
- Parameters:
callNode- the call site- Returns:
- the entry nodes registered as targets, empty if none
-
getCallSitesIn
public Set<SDGCallNode> getCallSitesIn(MethodReference method)
Finds the call sites appearing in a method's PDG.- Parameters:
method- the caller- Returns:
- the call sites, empty if the method has no registered PDG
-
getCallSitesTo
public Set<SDGCallNode> getCallSitesTo(MethodReference method)
Finds the call sites resolved to a method.- Parameters:
method- the callee- Returns:
- the call sites targeting it, empty if the method has no entry node
-
getInterproceduralEdges
public List<PDGEdge> getInterproceduralEdges()
- Returns:
- a fresh list of the parameter edges followed by the summary edges
-
getSummaryEdges
public List<PDGEdge> getSummaryEdges(SDGCallNode callNode)
Selects the summary edges whose source is an actual-in of a call site.- Parameters:
callNode- the call site- Returns:
- the matching summary edges
-
getMethods
public Set<MethodReference> getMethods()
- Returns:
- an unmodifiable view of the methods with a registered PDG
-
getMethodCount
public int getMethodCount()
- Returns:
- the number of methods with a registered PDG
-
getTotalNodeCount
public int getTotalNodeCount()
- Returns:
- the number of nodes
-
getTotalEdgeCount
public int getTotalEdgeCount()
- Returns:
- the number of edges
-
getInterproceduralEdgeCount
public int getInterproceduralEdgeCount()
- Returns:
- the number of parameter and summary edges combined
-
getSummaryEdgeCount
public int getSummaryEdgeCount()
- Returns:
- the number of summary edges
-
getEntryNodes
public Collection<SDGEntryNode> getEntryNodes()
- Returns:
- an unmodifiable view of every procedure entry node
-
getFormalIns
public List<SDGFormalInNode> getFormalIns(SDGEntryNode entry)
- Parameters:
entry- the procedure entry node- Returns:
- the formal-in nodes of the procedure
-
getFormalOuts
public List<SDGFormalOutNode> getFormalOuts(SDGEntryNode entry)
Collects the formal-out node of a procedure, if it has one.- Parameters:
entry- the procedure entry node- Returns:
- a list holding the formal-out node, or empty
-
getCallNodes
public List<SDGCallNode> getCallNodes(SDGEntryNode entry)
Collects the call sites of a procedure from its PDG, plus any registered call node not already in that PDG.- Parameters:
entry- the procedure entry node- Returns:
- the call sites
-
getActualIns
public List<SDGActualInNode> getActualIns(SDGCallNode callNode)
- Parameters:
callNode- the call site- Returns:
- the actual-in nodes of the call site
-
getActualOuts
public List<SDGActualOutNode> getActualOuts(SDGCallNode callNode)
Collects the actual-out node of a call site, if it has one.- Parameters:
callNode- the call site- Returns:
- a list holding the actual-out node, or empty
-
getCallNodesCount
public int getCallNodesCount()
Counts the call nodes across every registered node.- Returns:
- the number of call nodes
-
-