Skip to content

Commit daf0646

Browse files
committed
Improve code for analyzing call sites.
We should consider the context.
1 parent 98c0fea commit daf0646

File tree

1 file changed

+16
-19
lines changed
  • com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/client

1 file changed

+16
-19
lines changed

com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/client/Range.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -155,31 +155,28 @@ private Set<Integer> getNumberOfPossiblePositionalArguments(PropagationCallGraph
155155

156156
CallString cs = (CallString) this.getNode().getContext().get(CALL_STRING);
157157
CallSiteReference siteReference = cs.getCallSiteRefs()[0];
158+
LOGGER.fine(() -> "Analyzing call site: " + siteReference + ".");
158159

159-
for (CGNode caller : builder.getCallGraph())
160-
for (Iterator<CallSiteReference> it = caller.getIR().iterateCallSites(); it.hasNext(); ) {
161-
CallSiteReference callSite = it.next();
160+
for (Iterator<CGNode> it = builder.getCallGraph().getPredNodes(this.getNode());
161+
it.hasNext(); ) {
162+
CGNode caller = it.next();
163+
LOGGER.fine(() -> "Analyzing caller node: " + caller.getMethod().getSignature() + ".");
162164

163-
if (callSite.equals(siteReference)) {
164-
// caller is the node that made the call.
165-
LOGGER.finest(() -> "Caller node: " + caller.getMethod().getSignature() + ".");
165+
SSAAbstractInvokeInstruction[] calls = caller.getIR().getCalls(siteReference);
166+
LOGGER.finest(() -> "Number of calls at this site: " + calls.length + ".");
166167

167-
SSAAbstractInvokeInstruction[] calls = caller.getIR().getCalls(callSite);
168-
LOGGER.finest(() -> "Number of calls at this site: " + calls.length + ".");
168+
for (SSAAbstractInvokeInstruction callInstr : calls) {
169+
LOGGER.finest(() -> "Call instruction: " + callInstr + ".");
169170

170-
for (SSAAbstractInvokeInstruction callInstr : calls) {
171-
LOGGER.finest(() -> "Call instruction: " + callInstr + ".");
171+
PythonInvokeInstruction pyCallInstr = (PythonInvokeInstruction) callInstr;
172+
int numberOfPositionalParameters =
173+
pyCallInstr.getNumberOfPositionalParameters() - 1; // Exclude the function name.
174+
LOGGER.finer(
175+
() -> "Number of positional parameters: " + numberOfPositionalParameters + ".");
172176

173-
PythonInvokeInstruction pyCallInstr = (PythonInvokeInstruction) callInstr;
174-
int numberOfPositionalParameters =
175-
pyCallInstr.getNumberOfPositionalParameters() - 1; // Exclude the function name.
176-
LOGGER.finer(
177-
() -> "Number of positional parameters: " + numberOfPositionalParameters + ".");
178-
179-
ret.add(numberOfPositionalParameters);
180-
}
181-
}
177+
ret.add(numberOfPositionalParameters);
182178
}
179+
}
183180

184181
return ret;
185182
}

0 commit comments

Comments
 (0)