private void analyze() { Graph<T> DT = dom.dominatorTree(); Iterator<T> XS = DFS.iterateFinishTime(DT, new NonNullSingletonIterator<T>(root)); while (XS.hasNext()) { T X = XS.next(); Set<T> DF_X = HashSetFactory.make(); DF.put(X, DF_X); // DF_local for (Iterator<? extends T> YS = G.getSuccNodes(X); YS.hasNext(); ) { T Y = YS.next(); if (dom.getIdom(Y) != X) { DF_X.add(Y); } } // DF_up for (Iterator<? extends T> ZS = DT.getSuccNodes(X); ZS.hasNext(); ) { T Z = ZS.next(); for (Iterator<T> YS2 = getDominanceFrontier(Z); YS2.hasNext(); ) { T Y2 = YS2.next(); if (dom.getIdom(Y2) != X) DF_X.add(Y2); } } } }
private static void removeNode(Graph<AbstractPDGNode> cfg, AbstractPDGNode node) { Iterator<? extends AbstractPDGNode> itPred = cfg.getPredNodes(node); while (itPred.hasNext()) { AbstractPDGNode pred = itPred.next(); Iterator<? extends AbstractPDGNode> itSucc = cfg.getSuccNodes(node); while (itSucc.hasNext()) { AbstractPDGNode succ = itSucc.next(); cfg.addEdge(pred, succ); } } cfg.removeNodeAndEdges(node); }
/** * Return a view of an {@link IClassHierarchy} as a {@link Graph}, with edges from classes to * immediate subtypes */ public static Graph<IClass> typeHierarchy2Graph(IClassHierarchy cha) throws WalaException { Graph<IClass> result = SlowSparseNumberedGraph.make(); for (IClass c : cha) { result.addNode(c); } for (IClass c : cha) { for (IClass x : cha.getImmediateSubclasses(c)) { result.addEdge(c, x); } if (c.isInterface()) { for (IClass x : cha.getImplementors(c.getReference())) { result.addEdge(c, x); } } } return result; }
public static Map<InstanceKey, String> runAnalysisHelper(CallGraph cg, PointerAnalysis pa) throws CancelRuntimeException { logger.debug("*******************************************************"); logger.debug("* Prefix Analysis: Constructing Prefix Transfer Graph *"); final Graph<InstanceKeySite> g = new UriPrefixTransferGraph(pa); logger.debug("* The Graph: *"); logger.debug("*******************************************************"); Iterator<InstanceKeySite> iksI = g.iterator(); while (iksI.hasNext()) { InstanceKeySite iks = iksI.next(); logger.debug("# " + iks); Iterator<InstanceKeySite> edgesI = g.getSuccNodes(iks); while (edgesI.hasNext()) { logger.debug("? \t -->" + edgesI.next()); } } final PrefixTransferFunctionProvider tfp = new PrefixTransferFunctionProvider(); IKilldallFramework<InstanceKeySite, PrefixVariable> framework = new IKilldallFramework<InstanceKeySite, PrefixVariable>() { public Graph<InstanceKeySite> getFlowGraph() { return g; } public ITransferFunctionProvider<InstanceKeySite, PrefixVariable> getTransferFunctionProvider() { return tfp; } }; DataflowSolver<InstanceKeySite, PrefixVariable> dfs = new DataflowSolver<InstanceKeySite, PrefixVariable>(framework) { @Override protected PrefixVariable makeEdgeVariable(InstanceKeySite src, InstanceKeySite dst) { return new PrefixVariable() {}; } @Override protected PrefixVariable makeNodeVariable(InstanceKeySite n, boolean IN) { // TODO Auto-generated method stub PrefixVariable var = new PrefixVariable() {}; // if (n instanceof StringBuilderToStringInstanceKeySite) // var.setOrderNumber(0); // else var.setOrderNumber(10); // var.add(3); return var; } @Override protected PrefixVariable[] makeStmtRHS(int size) { return new PrefixVariable[size]; } }; logger.debug("\n**************************************************"); logger.debug("* Running Analysis"); try { dfs.solve(new EmptyProgressMonitor()); } catch (CancelException e) { throw new CancelRuntimeException(e); } Map<InstanceKey, String> prefixes = new HashMap<InstanceKey, String>(); iksI = g.iterator(); while (iksI.hasNext()) { InstanceKeySite iks = iksI.next(); prefixes.put( pa.getInstanceKeyMapping().getMappedObject(iks.instanceID()), dfs.getOut(iks).knownPrefixes.get(iks.instanceID())); // logger.debug(iks + " ~> " + dfs.getOut(iks)); } // logger.debug("\nLocalPointerKeys that point to String constants: \n" + stringConstants); for (Entry<InstanceKey, String> e : prefixes.entrySet()) { logger.debug(pa.getInstanceKeyMapping().getMappedIndex(e.getKey()) + "\t~> " + e.getValue()); } // TODO: populate prefixes return prefixes; }
/** * Constructor DFSFinishTimeIterator. * * @param G * @throws NullPointerException if G is null */ public BFSIterator(Graph<T> G) throws NullPointerException { this(G, G == null ? null : G.iterator()); }
/** * get the out edges of a given node * * @param n the node of which to get the out edges * @return the out edges */ protected Iterator<? extends T> getConnected(T n) { return G.getSuccNodes(n); }