|
1 | 1 | package com.ibm.wala.cast.python.ml.client; |
2 | 2 |
|
3 | | -import static com.ibm.wala.ipa.callgraph.propagation.cfa.CallStringContextSelector.CALL_STRING; |
4 | 3 | import static java.util.function.Function.identity; |
5 | 4 |
|
6 | 5 | import com.ibm.wala.cast.python.ml.types.TensorFlowTypes.DType; |
|
9 | 8 | import com.ibm.wala.cast.python.ssa.PythonInvokeInstruction; |
10 | 9 | import com.ibm.wala.classLoader.CallSiteReference; |
11 | 10 | import com.ibm.wala.ipa.callgraph.CGNode; |
| 11 | +import com.ibm.wala.ipa.callgraph.CallGraph; |
12 | 12 | import com.ibm.wala.ipa.callgraph.propagation.ConstantKey; |
13 | 13 | import com.ibm.wala.ipa.callgraph.propagation.InstanceKey; |
14 | 14 | import com.ibm.wala.ipa.callgraph.propagation.PointerAnalysis; |
15 | 15 | import com.ibm.wala.ipa.callgraph.propagation.PointerKey; |
16 | 16 | import com.ibm.wala.ipa.callgraph.propagation.PointsToSetVariable; |
17 | 17 | import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder; |
18 | | -import com.ibm.wala.ipa.callgraph.propagation.cfa.CallString; |
19 | 18 | import com.ibm.wala.ssa.SSAAbstractInvokeInstruction; |
20 | 19 | import com.ibm.wala.util.collections.HashSetFactory; |
21 | 20 | import com.ibm.wala.util.intset.OrdinalSet; |
@@ -152,34 +151,33 @@ protected Set<List<Dimension<?>>> getShapes(PropagationCallGraphBuilder builder) |
152 | 151 | */ |
153 | 152 | private Set<Integer> getNumberOfPossiblePositionalArguments(PropagationCallGraphBuilder builder) { |
154 | 153 | Set<Integer> ret = HashSetFactory.make(); |
| 154 | + CallGraph callGraph = builder.getCallGraph(); |
155 | 155 |
|
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(); |
158 | 158 |
|
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() + "."); |
162 | 164 |
|
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 + "."); |
166 | 167 |
|
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 + "."); |
169 | 170 |
|
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 + "."); |
172 | 176 |
|
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); |
181 | 178 | } |
182 | 179 | } |
| 180 | + } |
183 | 181 |
|
184 | 182 | return ret; |
185 | 183 | } |
|
0 commit comments