@Override public Iterator<Pair<CGNode, NewSiteReference>> getCreationSites(CallGraph CG) { return new ComposedIterator<CGNode, Pair<CGNode, NewSiteReference>>(CG.iterator()) { @Override public Iterator<? extends Pair<CGNode, NewSiteReference>> makeInner(final CGNode outer) { return new MapIterator<>( new FilterIterator<>( outer.iterateNewSites(), o -> o.getDeclaredType().equals(type.getReference()) ), object -> Pair.make(outer, object)); } }; } }
@Override public Iterator<Pair<CGNode, NewSiteReference>> getCreationSites(CallGraph CG) { return new ComposedIterator<CGNode, Pair<CGNode, NewSiteReference>>(CG.iterator()) { @Override public Iterator<? extends Pair<CGNode, NewSiteReference>> makeInner(final CGNode outer) { return new MapIterator<>( new FilterIterator<>( outer.iterateNewSites(), o -> o.getDeclaredType().equals(type.getReference()) ), object -> Pair.make(outer, object)); } }; } }
@Override public Iterator<CGNode> iterator() { Iterator<CGNode> tmp = cg.iterator(); Collection<CGNode> col = new LinkedList<>(); while (tmp.hasNext()) { CGNode n = tmp.next(); if (keep.contains(n)) { col.add(n); } } return col.iterator(); }
@Override public Iterator<CGNode> iterator() { Iterator<CGNode> tmp = cg.iterator(); Collection<CGNode> col = new LinkedList<>(); while (tmp.hasNext()) { CGNode n = tmp.next(); if (keep.contains(n)) { col.add(n); } } return col.iterator(); }
Iterator<CGNode> nodes = this.callgraph.iterator(); CGNode srcnode = null, tgtnode = null; com.sap.psr.vulas.shared.json.model.ConstructId src_cid = null, tgt_cid = null;
@Test public void testInnerClassSuper() throws IllegalArgumentException, CancelException, IOException { Pair<CallGraph, PointerAnalysis<? extends InstanceKey>> x = runTest(singleTestSrc(), rtJar, simpleTestEntryPoint(), new ArrayList<IRAssertion>(), true, null); // can't do an IRAssertion() -- we need the pointer analysis CallGraph cg = x.fst; PointerAnalysis<? extends InstanceKey> pa = x.snd; Iterator<CGNode> iter = cg.iterator(); while ( iter.hasNext() ) { CGNode n = iter.next(); if ( n.getMethod().getSignature().equals("LInnerClassSuper$SuperOuter.test()V") ) { // find enclosing instruction for ( SSAInstruction instr: n.getIR().getInstructions() ) { if ( instr instanceof EnclosingObjectReference ) { StringBuilder allIksBuilder = new StringBuilder(); for (InstanceKey ik: pa.getPointsToSet(new LocalPointerKey(n,instr.getDef()))) allIksBuilder.append(ik.getConcreteType().getName()).append(','); final String allIks = allIksBuilder.toString(); Assert.assertTrue("assertion failed: expecting ik \"LSub,\" in method, got \"" + allIks + "\"\n", allIks.equals("LSub,")); break; } } } } }
PointerAnalysis<? extends InstanceKey> pa = x.snd; Iterator<CGNode> iter = cg.iterator(); while ( iter.hasNext() ) { CGNode n = iter.next();
@Test public void testNList() throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException { AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope(TestConstants.WALA_TESTDATA, CallGraphTestUtil.REGRESSION_EXCLUSIONS); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "Lrecurse/NList"); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); CallGraph cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCacheImpl(), cha, scope, false); IBinaryNaturalRelation backEdges = Acyclic.computeBackEdges(cg, cg.getFakeRootNode()); Assert.assertTrue("NList should have cycles", backEdges.iterator().hasNext()); Map<CGNode, Set<CGNode>> cgBackEdges = HashMapFactory.make(); for (IntPair p : backEdges) { CGNode src = cg.getNode(p.getX()); if (!cgBackEdges.containsKey(src)) { cgBackEdges.put(src, HashSetFactory.<CGNode>make()); } cgBackEdges.get(src).add(cg.getNode(p.getY())); } PrunedCallGraph pcg = new PrunedCallGraph(cg, Iterator2Collection.toSet(cg.iterator()), cgBackEdges); Assert.assertTrue("cycles should be gone", !Acyclic.computeBackEdges(pcg, pcg.getFakeRootNode()).iterator().hasNext()); }