/** * Return an Iterator over edges that connect given block to its logical * predecessors. For forward analyses, this is the incoming edges. For * backward analyses, this is the outgoing edges. */ private Iterator<Edge> logicalPredecessorEdgeIterator(BasicBlock block) { return isForwards ? cfg.incomingEdgeIterator(block) : cfg.outgoingEdgeIterator(block); }
/** * Enumerate the simple paths. * * @return this object */ public SimplePathEnumerator enumerate() { Iterator<Edge> entryOut = cfg.outgoingEdgeIterator(cfg.getEntry()); if (!entryOut.hasNext()) { throw new IllegalStateException(); } Edge entryEdge = entryOut.next(); LinkedList<Edge> init = new LinkedList<>(); init.add(entryEdge); work(init); if (DEBUG && work == maxWork) { System.out.println("**** Reached max work! ****"); } return this; }
/** * Get the first outgoing edge in basic block with given type. * * @param basicBlock * the basic block * @param edgeType * the edge type * @return the Edge, or null if there is no edge with that edge type */ public Edge getOutgoingEdgeWithType(BasicBlock basicBlock, @Type int edgeType) { return getEdgeWithType(outgoingEdgeIterator(basicBlock), edgeType); }
/** * Get number of non-exception control successors of given basic block. * * @param block * a BasicBlock * @return number of non-exception control successors of the basic block */ public int getNumNonExceptionSucessors(BasicBlock block) { int numNonExceptionSuccessors = block.getNumNonExceptionSuccessors(); if (numNonExceptionSuccessors < 0) { numNonExceptionSuccessors = 0; for (Iterator<Edge> i = outgoingEdgeIterator(block); i.hasNext();) { Edge edge = i.next(); if (!edge.isExceptionEdge()) { numNonExceptionSuccessors++; } } block.setNumNonExceptionSuccessors(numNonExceptionSuccessors); } return numNonExceptionSuccessors; }
WalkState walkState = walkStates.removeLast(); Set<Long> numbers = walkState.numbers; for(Iterator<Edge> iterator = cfg.outgoingEdgeIterator(walkState.target); iterator.hasNext(); ) { Edge edge = iterator.next(); Branch branch = edges.get(edge);
/** * Like bb.getFirstInstruction() except that if null is returned it will * follow the FALL_THROUGH_EDGE (if any) */ private static InstructionHandle getDeepFirstInstruction(CFG cfg, BasicBlock bb) { InstructionHandle ih = bb.getFirstInstruction(); if (ih != null) { return ih; } Iterator<Edge> iei = cfg.outgoingEdgeIterator(bb); while (iei.hasNext()) { Edge e = iei.next(); if (EdgeTypes.FALL_THROUGH_EDGE == e.getType()) { return getDeepFirstInstruction(cfg, e.getTarget()); } } return null; }
Iterator<Edge> i = cfg.outgoingEdgeIterator(last.getTarget()); while (i.hasNext()) { Edge outEdge = i.next();
public void print(PrintStream out) { Iterator<BasicBlock> i = cfg.blockIterator(); while (i.hasNext()) { BasicBlock bb = i.next(); out.println(); out.println("BASIC BLOCK: " + bb.getLabel() + (bb.isExceptionThrower() ? " [EXCEPTION THROWER]" : "") + blockStartAnnotate(bb)); if (bb.isExceptionThrower()) { out.println(" Exception thrower: " + bb.getExceptionThrower()); } CodeExceptionGen exceptionGen = bb.getExceptionGen(); if (exceptionGen != null) { out.println("\tCATCHES " + exceptionGen.getCatchType()); } Iterator<InstructionHandle> j = instructionIterator(bb); while (j.hasNext()) { InstructionHandle handle = j.next(); out.println(handle + instructionAnnotate(handle, bb)); } out.println("END" + blockAnnotate(bb)); Iterator<Edge> edgeIter = isForwards ? cfg.outgoingEdgeIterator(bb) : cfg.incomingEdgeIterator(bb); while (edgeIter.hasNext()) { Edge edge = edgeIter.next(); out.println(" " + edge.formatAsString(!isForwards) + " " + edgeAnnotate(edge)); } } }
private InstructionHandle findThenFinish(CFG cfg, BasicBlock thenBB, int elsePos) { InstructionHandle inst = thenBB.getFirstInstruction(); while (inst == null) { Iterator<Edge> ie = cfg.outgoingEdgeIterator(thenBB); while (ie.hasNext()) { Edge e = ie.next(); if (e.getType() == EdgeTypes.FALL_THROUGH_EDGE) { thenBB = e.getTarget(); break; } } inst = thenBB.getFirstInstruction(); } InstructionHandle lastIns = inst; while (inst.getPosition() < elsePos) { lastIns = inst; inst = inst.getNext(); } return lastIns; }
HashMap<Integer, InstructionHandle> prevHandle = new HashMap<>(); Iterator<Edge> iei = cfg.outgoingEdgeIterator(bb); int idx = 0;
Edge lastExceptionEdge = null; for (Iterator<Edge> i = cfg.outgoingEdgeIterator(basicBlock); i.hasNext();) { Edge e = i.next(); if (e.isExceptionEdge()) { thrownExceptionSet = thrownExceptionSet.duplicate(); for (Iterator<Edge> i = cfg.outgoingEdgeIterator(basicBlock); i.hasNext();) { Edge edge = i.next(); if (edge.isExceptionEdge()) {
Iterator<Edge> iei = cfg.outgoingEdgeIterator(bb); while (iei.hasNext()) { Edge e = iei.next();
Iterator<Edge> i = cfg.outgoingEdgeIterator(state.getBasicBlock()); BitSet visitedSuccessorSet = new BitSet(); while (i.hasNext()) {
private void findIfElseDuplicates(CFG cfg, Method method, BasicBlock bb) { BasicBlock thenBB = null, elseBB = null; Iterator<Edge> iei = cfg.outgoingEdgeIterator(bb); while (iei.hasNext()) { Edge e = iei.next();
Iterator<Edge> edgeIter = subCFG.outgoingEdgeIterator(subBlock); while (edgeIter.hasNext()) { Edge edge = edgeIter.next();
/** * Return an Iterator over edges that connect given block to its logical * predecessors. For forward analyses, this is the incoming edges. For * backward analyses, this is the outgoing edges. */ private Iterator<Edge> logicalPredecessorEdgeIterator(BasicBlock block) { return isForwards ? cfg.incomingEdgeIterator(block) : cfg.outgoingEdgeIterator(block); }
/** * Get the first outgoing edge in basic block with given type. * * @param basicBlock * the basic block * @param edgeType * the edge type * @return the Edge, or null if there is no edge with that edge type */ public Edge getOutgoingEdgeWithType(BasicBlock basicBlock, @Type int edgeType) { return getEdgeWithType(outgoingEdgeIterator(basicBlock), edgeType); }
/** * Enumerate the simple paths. * * @return this object */ public SimplePathEnumerator enumerate() { Iterator<Edge> entryOut = cfg.outgoingEdgeIterator(cfg.getEntry()); if (!entryOut.hasNext()) { throw new IllegalStateException(); } Edge entryEdge = entryOut.next(); LinkedList<Edge> init = new LinkedList<Edge>(); init.add(entryEdge); work(init); if (DEBUG && work == maxWork) { System.out.println("**** Reached max work! ****"); } return this; }
/** * Get number of non-exception control successors of given basic block. * * @param block * a BasicBlock * @return number of non-exception control successors of the basic block */ public int getNumNonExceptionSucessors(BasicBlock block) { int numNonExceptionSuccessors = block.getNumNonExceptionSuccessors(); if (numNonExceptionSuccessors < 0) { numNonExceptionSuccessors = 0; for (Iterator<Edge> i = outgoingEdgeIterator(block); i.hasNext();) { Edge edge = i.next(); if (!edge.isExceptionEdge()) { numNonExceptionSuccessors++; } } block.setNumNonExceptionSuccessors(numNonExceptionSuccessors); } return numNonExceptionSuccessors; }
/** * Like bb.getFirstInstruction() except that if null is returned it will * follow the FALL_THROUGH_EDGE (if any) */ private static InstructionHandle getDeepFirstInstruction(CFG cfg, BasicBlock bb) { InstructionHandle ih = bb.getFirstInstruction(); if (ih != null) { return ih; } Iterator<Edge> iei = cfg.outgoingEdgeIterator(bb); while (iei.hasNext()) { Edge e = iei.next(); String edgeString = e.toString(); if (EdgeTypes.FALL_THROUGH_EDGE == e.getType()) { return getDeepFirstInstruction(cfg, e.getTarget()); } } return null; }