Created
February 23, 2017 18:40
-
-
Save khatchad/fc6c2f0400c1368bcf17791e3f584082 to your computer and use it in GitHub Desktop.
Find out if a object creation instruction produces an instance with the given instance key in WALA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* True iff the given {@link InstanceKey} corresponds with the given | |
* {@link SSAInvokeInstruction} in the given {@link CallGraph}. In other | |
* words, the result is true iff the instruction is used to create the | |
* instance. | |
* | |
* @param instanceKey | |
* An instance in question. | |
* @param instruction | |
* An instruction in question. Should be corresponding to a ctor | |
* call. | |
* @param callGraph | |
* The corresponding call graph. | |
* @return True iff the given instruction was used to instantiate the given | |
* instance key according to the given call graph. | |
*/ | |
public static boolean instanceKeyCorrespondsWithInstantiationInstruction(InstanceKey instanceKey, | |
SSAInvokeInstruction instruction, CallGraph callGraph) { | |
// Creation sites for the instance with the given key in the given call | |
// graph. | |
Iterator<Pair<CGNode, NewSiteReference>> creationSites = instanceKey.getCreationSites(callGraph); | |
// for each creation site. | |
while (creationSites.hasNext()) { | |
Pair<CGNode, NewSiteReference> pair = creationSites.next(); | |
// get the call string of the node in the call graph. | |
ContextItem contextItem = pair.fst.getContext().get(CallStringContextSelector.CALL_STRING); | |
CallString callString = (CallString) contextItem; | |
// get the call site references corresponding to the call string. | |
CallSiteReference[] callSiteRefs = callString.getCallSiteRefs(); | |
// for each call site reference. | |
for (CallSiteReference callSiteReference : callSiteRefs) | |
// if the call site reference equals the call site corresponding | |
// to the creation instruction. | |
if (callSiteReference.equals(instruction.getCallSite())) | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment