Java 类org.apache.bcel.generic.IndexedInstruction 实例源码

项目:findbugs-all-the-bugs    文件:FindDeadLocalStores.java   
/**
 * Count stores, loads, and increments of local variables in method whose
 * CFG is given.
 * 
 * @param localStoreCount
 *            counts of local stores (indexed by local)
 * @param localLoadCount
 *            counts of local loads (indexed by local)
 * @param localIncrementCount
 *            counts of local increments (indexed by local)
 * @param cfg
 *            control flow graph (CFG) of method
 */
private void countLocalStoresLoadsAndIncrements(int[] localStoreCount, int[] localLoadCount, int[] localIncrementCount,
        CFG cfg) {
    for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
        Location location = i.next();

        if (location.getBasicBlock().isExceptionHandler())
            continue;

        boolean isStore = isStore(location);
        boolean isLoad = isLoad(location);
        if (!isStore && !isLoad)
            continue;

        IndexedInstruction ins = (IndexedInstruction) location.getHandle().getInstruction();
        int local = ins.getIndex();
        if (ins instanceof IINC) {
            localStoreCount[local]++;
            localLoadCount[local]++;
            localIncrementCount[local]++;
        } else if (isStore)
            localStoreCount[local]++;
        else
            localLoadCount[local]++;
    }
}
项目:FindBug-for-Domino-Designer    文件:FindDeadLocalStores.java   
/**
 * Count stores, loads, and increments of local variables in method whose
 * CFG is given.
 *
 * @param localStoreCount
 *            counts of local stores (indexed by local)
 * @param localLoadCount
 *            counts of local loads (indexed by local)
 * @param localIncrementCount
 *            counts of local increments (indexed by local)
 * @param cfg
 *            control flow graph (CFG) of method
 */
private void countLocalStoresLoadsAndIncrements(int[] localStoreCount, int[] localLoadCount, int[] localIncrementCount,
        CFG cfg) {
    for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
        Location location = i.next();

        if (location.getBasicBlock().isExceptionHandler())
            continue;

        boolean isStore = isStore(location);
        boolean isLoad = isLoad(location);
        if (!isStore && !isLoad)
            continue;

        IndexedInstruction ins = (IndexedInstruction) location.getHandle().getInstruction();
        int local = ins.getIndex();
        if (ins instanceof IINC) {
            localStoreCount[local]++;
            localLoadCount[local]++;
            localIncrementCount[local]++;
        } else if (isStore)
            localStoreCount[local]++;
        else
            localLoadCount[local]++;
    }
}
项目:findbugs-all-the-bugs    文件:LocalVariableAnnotation.java   
public static LocalVariableAnnotation getLocalVariableAnnotation(Method method, Location location, IndexedInstruction ins) {
    int local = ins.getIndex();
    InstructionHandle handle = location.getHandle();
    int position1 = handle.getNext().getPosition();
    int position2 = handle.getPosition();
    return getLocalVariableAnnotation(method, local, position1, position2);
}
项目:FindBug-for-Domino-Designer    文件:LocalVariableAnnotation.java   
public static LocalVariableAnnotation getLocalVariableAnnotation(Method method, Location location, IndexedInstruction ins) {
    int local = ins.getIndex();
    InstructionHandle handle = location.getHandle();
    int position1 = handle.getNext().getPosition();
    int position2 = handle.getPosition();
    return getLocalVariableAnnotation(method, local, position1, position2);
}
项目:VestaClient    文件:Subroutines.java   
public int[] getAccessedLocalsIndices(){
    //TODO: Implement caching.
    Set acc = new HashSet();
    if (theRET == null && this != TOPLEVEL){
        throw new AssertionViolatedException("This subroutine object must be built up completely before calculating accessed locals.");
    }
    Iterator i = instructions.iterator();
    while (i.hasNext()){
        InstructionHandle ih = (InstructionHandle) i.next();
        // RET is not a LocalVariableInstruction in the current version of BCEL.
        if (ih.getInstruction() instanceof LocalVariableInstruction || ih.getInstruction() instanceof RET){
            int idx = ((IndexedInstruction) (ih.getInstruction())).getIndex();
            acc.add(new Integer(idx));
            // LONG? DOUBLE?.
            try{
                // LocalVariableInstruction instances are typed without the need to look into
                // the constant pool.
                if (ih.getInstruction() instanceof LocalVariableInstruction){
                    int s = ((LocalVariableInstruction) ih.getInstruction()).getType(null).getSize();
                    if (s==2) {
                              acc.add(new Integer(idx+1));
                          }
                }
            }
            catch(RuntimeException re){
                throw new AssertionViolatedException("Oops. BCEL did not like NULL as a ConstantPoolGen object.");
            }
        }
    }

    int[] ret = new int[acc.size()];
    i = acc.iterator();
    int j=-1;
    while (i.hasNext()){
        j++;
        ret[j] = ((Integer) i.next()).intValue();
    }
    return ret;
}
项目:eclectic    文件:Subroutines.java   
public int[] getAccessedLocalsIndices(){
    //TODO: Implement caching.
    final Set<Integer> acc = new HashSet<Integer>();
    if (theRET == null && this != TOPLEVEL){
        throw new AssertionViolatedException("This subroutine object must be built up completely before calculating accessed locals.");
    }
    for (final InstructionHandle ih : instructions) {
        // RET is not a LocalVariableInstruction in the current version of BCEL.
        if (ih.getInstruction() instanceof LocalVariableInstruction || ih.getInstruction() instanceof RET){
            int idx = IndexedInstruction.class.cast(ih.getInstruction()).getIndex();
            acc.add(idx);
            // LONG? DOUBLE?.
            try {
                // LocalVariableInstruction instances are typed without the need to look into
                // the constant pool.
                if (ih.getInstruction() instanceof LocalVariableInstruction) {
                    int s = LocalVariableInstruction.class.cast(ih.getInstruction()).getType(null).getSize();
                    if (s == 2) acc.add(idx + 1);
                }
            } catch(final RuntimeException re) {
                throw new AssertionViolatedException("Oops. BCEL did not like NULL as a ConstantPoolGen object.");
            }
        }
    }

    int[] ret = new int[acc.size()];
    int j = 0;
    for (final int v : acc) {
        ret[j++] = v;
    }
    return ret;
}
项目:eclectic    文件:Subroutines.java   
public int[] getAccessedLocalsIndices(){
    //TODO: Implement caching.
    final Set<Integer> acc = new HashSet<Integer>();
    if (theRET == null && this != TOPLEVEL){
        throw new AssertionViolatedException("This subroutine object must be built up completely before calculating accessed locals.");
    }
    for (final InstructionHandle ih : instructions) {
        // RET is not a LocalVariableInstruction in the current version of BCEL.
        if (ih.getInstruction() instanceof LocalVariableInstruction || ih.getInstruction() instanceof RET){
            int idx = IndexedInstruction.class.cast(ih.getInstruction()).getIndex();
            acc.add(idx);
            // LONG? DOUBLE?.
            try {
                // LocalVariableInstruction instances are typed without the need to look into
                // the constant pool.
                if (ih.getInstruction() instanceof LocalVariableInstruction) {
                    int s = LocalVariableInstruction.class.cast(ih.getInstruction()).getType(null).getSize();
                    if (s == 2) acc.add(idx + 1);
                }
            } catch(final RuntimeException re) {
                throw new AssertionViolatedException("Oops. BCEL did not like NULL as a ConstantPoolGen object.");
            }
        }
    }

    int[] ret = new int[acc.size()];
    int j = 0;
    for (final int v : acc) {
        ret[j++] = v;
    }
    return ret;
}