Class BaseCallGraph
- java.lang.Object
-
- it.unive.lisa.util.datastructures.graph.BaseGraph<BaseCallGraph,CallGraphNode,CallGraphEdge>
-
- it.unive.lisa.interprocedural.callgraph.BaseCallGraph
-
- All Implemented Interfaces:
CallGraph
,Graph<BaseCallGraph,CallGraphNode,CallGraphEdge>
public abstract class BaseCallGraph extends BaseGraph<BaseCallGraph,CallGraphNode,CallGraphEdge> implements CallGraph
An instance ofCallGraph
that provides the basic mechanism to resolveUnresolvedCall
s.
The graph underlying this call graph is built lazily through each call to resolve: querying for information about the graph before the completion of the analysis might lead to wrong results.
-
-
Field Summary
-
Fields inherited from class it.unive.lisa.util.datastructures.graph.BaseGraph
adjacencyMatrix, entrypoints
-
-
Constructor Summary
Constructors Constructor Description BaseCallGraph()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
checkMember(UnresolvedCall call, java.util.Set<Type>[] types, java.util.Collection<CFG> targets, java.util.Collection<NativeCFG> natives, SymbolAliasing aliasing, CodeMember cm, boolean instance)
Checks if the given code membercm
is a candidate target for the given call, and proceeds to add it to the set of targets if it is.java.util.Collection<CodeMember>
getCallees(CodeMember cm)
Yields all theCodeMember
s that are called by the given one.java.util.Collection<CodeMember>
getCallers(CodeMember cm)
Yields all theCodeMember
s that call the given one.java.util.Collection<Call>
getCallSites(CodeMember cm)
Yields all theCall
s that targets the givenCodeMember
.abstract java.util.Collection<Type>
getPossibleTypesOfReceiver(Expression receiver, java.util.Set<Type> types)
Returns all the possible types of the given expression that should be considered as possible receivers of the call.void
init(Application app)
Initializes the call graph of the given program.boolean
matchCodeMemberName(UnresolvedCall call, java.lang.String qualifier, java.lang.String name)
Matches the name (qualifier + target name) of the given call against the given code member.void
registerCall(CFGCall call)
Call
resolve(UnresolvedCall call, java.util.Set<Type>[] types, SymbolAliasing aliasing)
Yields aCall
implementation that corresponds to the resolution of the givenUnresolvedCall
.void
resolveInstance(UnresolvedCall call, java.util.Set<Type>[] types, java.util.Collection<CFG> targets, java.util.Collection<NativeCFG> natives, SymbolAliasing aliasing)
Resolves the given call as an instance call.void
resolveNonInstance(UnresolvedCall call, java.util.Set<Type>[] types, java.util.Collection<CFG> targets, java.util.Collection<NativeCFG> natives, SymbolAliasing aliasing)
Resolves the given call as regular (non-instance) call.-
Methods inherited from class it.unive.lisa.util.datastructures.graph.BaseGraph
addEdge, addNode, addNode, containsEdge, containsNode, followersOf, getAdjacencyMatrix, getEdgeConnecting, getEdges, getEdgesConnecting, getEdgesCount, getEntrypoints, getIngoingEdges, getNodes, getNodesCount, getOutgoingEdges, isEqualTo, predecessorsOf, toSerializableGraph, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface it.unive.lisa.util.datastructures.graph.Graph
accept, toSerializableGraph
-
-
-
-
Method Detail
-
init
public void init(Application app) throws CallGraphConstructionException
Description copied from interface:CallGraph
Initializes the call graph of the given program.- Specified by:
init
in interfaceCallGraph
- Parameters:
app
- the application to analyze- Throws:
CallGraphConstructionException
- if an exception happens while building the call graph
-
registerCall
public void registerCall(CFGCall call)
Description copied from interface:CallGraph
- Specified by:
registerCall
in interfaceCallGraph
- Parameters:
call
- the call to register
-
resolve
public Call resolve(UnresolvedCall call, java.util.Set<Type>[] types, SymbolAliasing aliasing) throws CallResolutionException
Description copied from interface:CallGraph
Yields aCall
implementation that corresponds to the resolution of the givenUnresolvedCall
.- Specified by:
resolve
in interfaceCallGraph
- Parameters:
call
- the call to resolvetypes
- the runtime types of the parameters of the callaliasing
- the symbol aliasing information- Returns:
- a collection of all the possible runtime targets
- Throws:
CallResolutionException
- if this call graph is unable to resolve the given call
-
resolveNonInstance
public void resolveNonInstance(UnresolvedCall call, java.util.Set<Type>[] types, java.util.Collection<CFG> targets, java.util.Collection<NativeCFG> natives, SymbolAliasing aliasing) throws CallResolutionException
Resolves the given call as regular (non-instance) call.- Parameters:
call
- the call to resolvetypes
- the runtime types of the parameters of the calltargets
- the list of targets that, after the execution of this method, will contain theCFG
s targeted by the callnatives
- the list of targets that, after the execution of this method, will contain theNativeCFG
s targeted by the callaliasing
- the symbol aliasing information- Throws:
CallResolutionException
- if something goes wrong while resolving the call
-
resolveInstance
public void resolveInstance(UnresolvedCall call, java.util.Set<Type>[] types, java.util.Collection<CFG> targets, java.util.Collection<NativeCFG> natives, SymbolAliasing aliasing) throws CallResolutionException
Resolves the given call as an instance call.- Parameters:
call
- the call to resolvetypes
- the runtime types of the parameters of the calltargets
- the list of targets that, after the execution of this method, will contain theCFG
s targeted by the callnatives
- the list of targets that, after the execution of this method, will contain theNativeCFG
s targeted by the callaliasing
- the symbol aliasing information- Throws:
CallResolutionException
- if something goes wrong while resolving the call
-
checkMember
public void checkMember(UnresolvedCall call, java.util.Set<Type>[] types, java.util.Collection<CFG> targets, java.util.Collection<NativeCFG> natives, SymbolAliasing aliasing, CodeMember cm, boolean instance)
Checks if the given code membercm
is a candidate target for the given call, and proceeds to add it to the set of targets if it is. Aliasing information is used here to match code members that have been aliased and that can be targeted by calls that refer to other names. Note thatAbstractCodeMember
s are always discarded.- Parameters:
call
- the call to matchtypes
- the runtime types of the parameters of the calltargets
- the list of targets that, after the execution of this method, will contain theCFG
s targeted by the callnatives
- the list of targets that, after the execution of this method, will contain theNativeCFG
s targeted by the callaliasing
- the symbol aliasing informationcm
- the code member to matchinstance
- whether or not the only instance or non-instance members should be matched
-
matchCodeMemberName
public boolean matchCodeMemberName(UnresolvedCall call, java.lang.String qualifier, java.lang.String name)
Matches the name (qualifier + target name) of the given call against the given code member.- Parameters:
call
- the call to matchqualifier
- the qualifier (name of the defining unit) of the code membername
- the name of the code member- Returns:
true
if the qualifier and name are compatible with the ones of the call's target
-
getPossibleTypesOfReceiver
public abstract java.util.Collection<Type> getPossibleTypesOfReceiver(Expression receiver, java.util.Set<Type> types) throws CallResolutionException
Returns all the possible types of the given expression that should be considered as possible receivers of the call. How we choose this set varies from the call graph algorithm we decide to adopt (e.g., CHA, RTA, 0-CFA, ...)- Parameters:
receiver
- an expressiontypes
- the runtime types of the receiver- Returns:
- the possible types to use as receivers
- Throws:
CallResolutionException
- if the types cannot be computed
-
getCallees
public java.util.Collection<CodeMember> getCallees(CodeMember cm)
Description copied from interface:CallGraph
Yields all theCodeMember
s that are called by the given one. The returned collection might contain partial results if this call graph is not fully built.- Specified by:
getCallees
in interfaceCallGraph
- Parameters:
cm
- the target code member- Returns:
- the collection of called code members
-
getCallers
public java.util.Collection<CodeMember> getCallers(CodeMember cm)
Description copied from interface:CallGraph
Yields all theCodeMember
s that call the given one. The returned collection might contain partial results if this call graph is not fully built.- Specified by:
getCallers
in interfaceCallGraph
- Parameters:
cm
- the target code member- Returns:
- the collection of callers code members
-
getCallSites
public java.util.Collection<Call> getCallSites(CodeMember cm)
Description copied from interface:CallGraph
Yields all theCall
s that targets the givenCodeMember
. The returned collection might contain partial results if this call graph is not fully built.- Specified by:
getCallSites
in interfaceCallGraph
- Parameters:
cm
- the target code member- Returns:
- the collection of calls that target the code member
-
-