Skip to content

Commit b5c41d5

Browse files
committed
Improve the code?
1 parent fef8b47 commit b5c41d5

File tree

1 file changed

+20
-22
lines changed
  • com.ibm.wala.cast.python.ml/source/com/ibm/wala/cast/python/ml/client

1 file changed

+20
-22
lines changed

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.ibm.wala.cast.python.ml.client;
22

3-
import static com.ibm.wala.ipa.callgraph.propagation.cfa.CallStringContextSelector.CALL_STRING;
43
import static java.util.function.Function.identity;
54

65
import com.ibm.wala.cast.python.ml.types.TensorFlowTypes.DType;
@@ -9,13 +8,13 @@
98
import com.ibm.wala.cast.python.ssa.PythonInvokeInstruction;
109
import com.ibm.wala.classLoader.CallSiteReference;
1110
import com.ibm.wala.ipa.callgraph.CGNode;
11+
import com.ibm.wala.ipa.callgraph.CallGraph;
1212
import com.ibm.wala.ipa.callgraph.propagation.ConstantKey;
1313
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
1414
import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis;
1515
import com.ibm.wala.ipa.callgraph.propagation.PointerKey;
1616
import com.ibm.wala.ipa.callgraph.propagation.PointsToSetVariable;
1717
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
18-
import com.ibm.wala.ipa.callgraph.propagation.cfa.CallString;
1918
import com.ibm.wala.ssa.SSAAbstractInvokeInstruction;
2019
import com.ibm.wala.util.collections.HashSetFactory;
2120
import com.ibm.wala.util.intset.OrdinalSet;
@@ -152,34 +151,33 @@ protected Set<List<Dimension<?>>> getShapes(PropagationCallGraphBuilder builder)
152151
*/
153152
private Set<Integer> getNumberOfPossiblePositionalArguments(PropagationCallGraphBuilder builder) {
154153
Set<Integer> ret = HashSetFactory.make();
154+
CallGraph callGraph = builder.getCallGraph();
155155

156-
CallString cs = (CallString) this.getNode().getContext().get(CALL_STRING);
157-
CallSiteReference siteReference = cs.getCallSiteRefs()[0];
156+
for (Iterator<CGNode> pIt = callGraph.getPredNodes(this.getNode()); pIt.hasNext(); ) {
157+
CGNode caller = pIt.next();
158158

159-
for (CGNode caller : builder.getCallGraph())
160-
for (Iterator<CallSiteReference> it = caller.getIR().iterateCallSites(); it.hasNext(); ) {
161-
CallSiteReference callSite = it.next();
159+
for (Iterator<CallSiteReference> cIt = callGraph.getPossibleSites(caller, this.getNode());
160+
cIt.hasNext(); ) {
161+
CallSiteReference callSite = cIt.next();
162+
// caller is the node that made the call.
163+
LOGGER.finest(() -> "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(callSite);
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-
}
177+
ret.add(numberOfPositionalParameters);
181178
}
182179
}
180+
}
183181

184182
return ret;
185183
}

0 commit comments

Comments
 (0)