/** * Return a new bit string as the AND of two others. */ public static BitVector and(BitVector b1, BitVector b2) { if (b1 == null) { throw new IllegalArgumentException("null b1"); } if (b2 == null) { throw new IllegalArgumentException("null b2"); } BitVector b = new BitVector(b1); b.and(b2); return b; }
@Override public BitVector getCatchBlocks() { BitVector result = new BitVector(); BitVector blocks = cfg.getCatchBlocks(); int i = 0; while ((i = blocks.nextSetBit(i)) != -1) { if (nodes.containsNode(getNode(i))) { result.set(i); } } return result; }
/** * record that basic block i is a catch block */ protected void setCatchBlock(int i) { catchBlocks.set(i); }
protected AbstractCFG(IMethod method) { this.method = method; this.catchBlocks = new BitVector(10); }
/** * @return true iff block i is a catch block */ public boolean isCatchBlock(int i) { return catchBlocks.get(i); }
@Override public void foreach(IntSetAction action) { if (action == null) { throw new IllegalArgumentException("null action"); } int nextBit = bitVector.nextSetBit(0); populationCount = (populationCount == UNDEFINED) ? bitVector.populationCount() : populationCount; for (int i = 0; i < populationCount; i++) { action.act(nextBit); nextBit = bitVector.nextSetBit(nextBit + 1); } }
/** * Perform the difference of two bit sets * * @param other the other bitset in the operation * @throws IllegalArgumentException if other is null */ public void difference(BitSet<T> other) { if (other == null) { throw new IllegalArgumentException("other is null"); } vector.and(BitVector.not(other.vector)); }
/** */ private boolean sameValueInternal(SparseIntSet that) { populationCount = (populationCount == UNDEFINED) ? bitVector.populationCount() : populationCount; if (populationCount != that.size()) { return false; } for (int i = 0; i < that.size(); i++) { int val = that.elementAt(i); if (!bitVector.contains(val)) { return false; } } return true; }
/** * Perform intersection of two bitsets * * @param other the other bitset in the operation * @throws IllegalArgumentException if other is null */ public void intersect(BitSet<?> other) { if (other == null) { throw new IllegalArgumentException("other is null"); } vector.and(other.vector); }
/** * @return min j >= n s.t get(j) */ public int nextSetBit(int n) { return bitVector.nextSetBit(n); }
@Override public int max() { return bitVector.max(); }
public int length() { return vector.length(); }
@Override public String toString() { StringBuilder s = new StringBuilder(); BitVector catches = this.getCatchBlocks(); for (BasicBlock bb : this) { s.append("BB").append(getNumber(bb)); if (catches.contains(bb.getNumber())) { s.append("<Handler>"); } s.append('\n'); for (int j = bb.getFirstInstructionIndex(); j <= bb.getLastInstructionIndex(); j++) { s.append(" ").append(j).append(" ").append(getInstructions()[j]).append('\n'); } Iterator<BasicBlock> succNodes = getSuccNodes(bb); while (succNodes.hasNext()) { s.append(" -> BB").append(getNumber(succNodes.next())).append('\n'); } } return s.toString(); }