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

项目:findbugs-all-the-bugs    文件:TargetEnumeratingVisitor.java   
@Override
public void visitSelect(Select ins) {
    isBranch = true;

    // Add non-default switch edges.
    InstructionHandle[] targets = ins.getTargets();
    for (InstructionHandle target : targets) {
        targetList.add(new Target(target, SWITCH_EDGE));
    }

    // Add default switch edge.
    InstructionHandle defaultTarget = ins.getTarget();
    if (defaultTarget == null) {
        throw new IllegalStateException();
    }
    targetList.add(new Target(defaultTarget, SWITCH_DEFAULT_EDGE));
}
项目:FindBug-for-Domino-Designer    文件:TargetEnumeratingVisitor.java   
@Override
public void visitSelect(Select ins) {
    isBranch = true;

    // Add non-default switch edges.
    InstructionHandle[] targets = ins.getTargets();
    for (InstructionHandle target : targets) {
        targetList.add(new Target(target, SWITCH_EDGE));
    }

    // Add default switch edge.
    InstructionHandle defaultTarget = ins.getTarget();
    if (defaultTarget == null) {
        throw new IllegalStateException();
    }
    targetList.add(new Target(defaultTarget, SWITCH_DEFAULT_EDGE));
}
项目:VestaClient    文件:BCELFactory.java   
private void updateBranchTargets() {
    for (Iterator i = branches.iterator(); i.hasNext();) {
        BranchInstruction bi = (BranchInstruction) i.next();
        BranchHandle bh = (BranchHandle) branch_map.get(bi);
        int pos = bh.getPosition();
        String name = bi.getName() + "_" + pos;
        int t_pos = bh.getTarget().getPosition();
        _out.println("    " + name + ".setTarget(ih_" + t_pos + ");");
        if (bi instanceof Select) {
            InstructionHandle[] ihs = ((Select) bi).getTargets();
            for (int j = 0; j < ihs.length; j++) {
                t_pos = ihs[j].getPosition();
                _out.println("    " + name + ".setTarget(" + j + ", ih_" + t_pos + ");");
            }
        }
    }
}
项目:VestaClient    文件:Subroutines.java   
/**
 * A utility method that calculates the successors of a given InstructionHandle
 * <B>in the same subroutine</B>. That means, a RET does not have any successors
 * as defined here. A JsrInstruction has its physical successor as its successor
 * (opposed to its target) as defined here.
 */
private static InstructionHandle[] getSuccessors(InstructionHandle instruction){
    final InstructionHandle[] empty = new InstructionHandle[0];
    final InstructionHandle[] single = new InstructionHandle[1];
    final InstructionHandle[] pair = new InstructionHandle[2];

    Instruction inst = instruction.getInstruction();

    if (inst instanceof RET){
        return empty;
    }

    // Terminates method normally.
    if (inst instanceof ReturnInstruction){
        return empty;
    }

    // Terminates method abnormally, because JustIce mandates
    // subroutines not to be protected by exception handlers.
    if (inst instanceof ATHROW){
        return empty;
    }

    // See method comment.
    if (inst instanceof JsrInstruction){
        single[0] = instruction.getNext();
        return single;
    }

    if (inst instanceof GotoInstruction){
        single[0] = ((GotoInstruction) inst).getTarget();
        return single;
    }

    if (inst instanceof BranchInstruction){
        if (inst instanceof Select){
            // BCEL's getTargets() returns only the non-default targets,
            // thanks to Eli Tilevich for reporting.
            InstructionHandle[] matchTargets = ((Select) inst).getTargets();
            InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
            ret[0] = ((Select) inst).getTarget();
            System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
            return ret;
        }
        else{
            pair[0] = instruction.getNext();
            pair[1] = ((BranchInstruction) inst).getTarget();
            return pair;
        }
    }

    // default case: Fall through.      
    single[0] = instruction.getNext();
    return single;
}
项目:VestaClient    文件:BCELFactory.java   
public void visitBranchInstruction( BranchInstruction bi ) {
    BranchHandle bh = (BranchHandle) branch_map.get(bi);
    int pos = bh.getPosition();
    String name = bi.getName() + "_" + pos;
    if (bi instanceof Select) {
        Select s = (Select) bi;
        branches.add(bi);
        StringBuffer args = new StringBuffer("new int[] { ");
        int[] matchs = s.getMatchs();
        for (int i = 0; i < matchs.length; i++) {
            args.append(matchs[i]);
            if (i < matchs.length - 1) {
                args.append(", ");
            }
        }
        args.append(" }");
        _out.print("Select " + name + " = new " + bi.getName().toUpperCase(Locale.ENGLISH)
                + "(" + args + ", new InstructionHandle[] { ");
        for (int i = 0; i < matchs.length; i++) {
            _out.print("null");
            if (i < matchs.length - 1) {
                _out.print(", ");
            }
        }
        _out.println(" }, null);");
    } else {
        int t_pos = bh.getTarget().getPosition();
        String target;
        if (pos > t_pos) {
            target = "ih_" + t_pos;
        } else {
            branches.add(bi);
            target = "null";
        }
        _out.println("    BranchInstruction " + name + " = _factory.createBranchInstruction("
                + "Constants." + bi.getName().toUpperCase(Locale.ENGLISH) + ", " + target
                + ");");
    }
    if (bh.hasTargeters()) {
        _out.println("    ih_" + pos + " = il.append(" + name + ");");
    } else {
        _out.println("    il.append(" + name + ");");
    }
}
项目:eclectic    文件:DecompilingVisitor.java   
public void visitCode(Code code) {
    MethodGen mg = new MethodGen(_method, clazzname, cp);
    InstructionList il = mg.getInstructionList();
    InstructionHandle[] ihs = il.getInstructionHandles();

    LocalVariableGen[] lvs = mg.getLocalVariables();

    CodeExceptionGen[] ehs = mg.getExceptionHandlers();

    for (int i = 0; i < lvs.length; i++) {
        LocalVariableGen l = lvs[i];
        out.println("    // local variable " + l.getIndex() + " is \"" + l.getName()
                + "\" " + l.getType() + " from "
                + l.getStart().getPosition() + " to "
                + l.getEnd().getPosition());
    }

    out.print("\n");

    for (int i = 0; i < ihs.length; i++) {
        InstructionHandle ih = ihs[i];
        Instruction inst = ih.getInstruction();

        out.print("    " + ih.getPosition());

        if (inst instanceof BranchInstruction) {
            if (inst instanceof Select) { // Special cases LOOKUPSWITCH and
                                          // TABLESWITCH
                Select s = (Select) inst;
                int[] matchs = s.getMatchs();
                InstructionHandle[] targets = s.getTargets();

                if (s instanceof TABLESWITCH) {
                    out.println("  tableswitch " + matchs[0] + " "
                            + matchs[matchs.length - 1]);

                    for (int j = 0; j < targets.length; j++)
                        out.println("        " + targets[j].getPosition());

                } else { // LOOKUPSWITCH
                    out.println("  lookupswitch ");

                    for (int j = 0; j < targets.length; j++)
                        out.println("        " + matchs[j] + " : "
                                + targets[j].getPosition());
                }

                out.println("        default: " + s.getTarget()); // Applies
                                                                  // for
                                                                  // both
            } else {
                BranchInstruction bi = (BranchInstruction) inst;
                ih = bi.getTarget();
                //str = get(ih);
                out.println("  " + Constants.OPCODE_NAMES[bi.getOpcode()]
                        + " " + ih);
            }
        } else
            out.println("  " + inst.toString(cp.getConstantPool()));
    }

    out.print("\n");

    for (int i = 0; i < ehs.length; i++) {
        CodeExceptionGen c = ehs[i];
        ObjectType caught = c.getCatchType();
        String class_name = (caught == null) ? // catch any exception, used
                                               // when compiling finally
                "all" : caught.getClassName().replace('.', '/');

        out.println("    catch " + class_name + " from "
                + c.getStartPC().getPosition() + " to "
                + c.getEndPC().getPosition() + " using "
                + c.getHandlerPC().getPosition());
    }
}
项目:eclectic    文件:Subroutines.java   
/**
 * A utility method that calculates the successors of a given InstructionHandle
 * <B>in the same subroutine</B>. That means, a RET does not have any successors
 * as defined here. A JsrInstruction has its physical successor as its successor
 * (opposed to its target) as defined here.
 */
private static InstructionHandle[] getSuccessors(InstructionHandle instruction){
    Instruction inst = instruction.getInstruction();

       if (inst instanceof RET){
        return empty;
    }

    // Terminates method normally.
    if (inst instanceof ReturnInstruction){
        return empty;
    }

    // Terminates method abnormally, because JustIce mandates
    // subroutines not to be protected by exception handlers.
    if (inst instanceof ATHROW){
        return empty;
    }

       final InstructionHandle[] single = new InstructionHandle[1];

       // See method comment.
    if (inst instanceof JsrInstruction){
        single[0] = instruction.getNext();
        return single;
    }

    if (inst instanceof GotoInstruction){
        single[0] = ((GotoInstruction) inst).getTarget();
        return single;
    }

    if (inst instanceof BranchInstruction){
        if (inst instanceof Select){
            // BCEL's getTargets() returns only the non-default targets,
            // thanks to Eli Tilevich for reporting.
            InstructionHandle[] matchTargets = ((Select) inst).getTargets();
            InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
            ret[0] = ((Select) inst).getTarget();
            System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
            return ret;
        }
        else{
               final InstructionHandle[] pair = new InstructionHandle[2];
            pair[0] = instruction.getNext();
            pair[1] = ((BranchInstruction) inst).getTarget();
            return pair;
        }
    }

    // default case: Fall through.
    single[0] = instruction.getNext();
    return single;
}
项目:eclectic    文件:ControlFlowGraph.java   
/**
         * A utility method that calculates the successors of a given InstructionHandle
         * That means, a RET does have successors as defined here.
         * A JsrInstruction has its target as its successor
         * (opposed to its physical successor) as defined here.
         */
// TODO: implement caching!
        private InstructionHandle[] _getSuccessors(){
            final InstructionHandle[] empty = new InstructionHandle[0];
            final InstructionHandle[] single = new InstructionHandle[1];
            final InstructionHandle[] pair = new InstructionHandle[2];

            Instruction inst = getInstruction().getInstruction();

            if (inst instanceof RET){
                Subroutine s = subroutines.subroutineOf(getInstruction());
                if (s==null){ //return empty; // RET in dead code. "empty" would be the correct answer, but we know something about the surrounding project...
                    throw new AssertionViolatedException("Asking for successors of a RET in dead code?!");
                }
//TODO: remove
throw new AssertionViolatedException("DID YOU REALLY WANT TO ASK FOR RET'S SUCCS?");
/*
                InstructionHandle[] jsrs = s.getEnteringJsrInstructions();
                InstructionHandle[] ret = new InstructionHandle[jsrs.length];
                for (int i=0; i<jsrs.length; i++){
                    ret[i] = jsrs[i].getNext();
                }
                return ret;
*/
            }

            // Terminates method normally.
            if (inst instanceof ReturnInstruction){
                return empty;
            }

            // Terminates method abnormally, because JustIce mandates
            // subroutines not to be protected by exception handlers.
            if (inst instanceof ATHROW){
                return empty;
            }

            // See method comment.
            if (inst instanceof JsrInstruction){
                single[0] = ((JsrInstruction) inst).getTarget();
                return single;
            }

            if (inst instanceof GotoInstruction){
                single[0] = ((GotoInstruction) inst).getTarget();
                return single;
            }

            if (inst instanceof BranchInstruction){
                if (inst instanceof Select){
                    // BCEL's getTargets() returns only the non-default targets,
                    // thanks to Eli Tilevich for reporting.
                    InstructionHandle[] matchTargets = ((Select) inst).getTargets();
                    InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
                    ret[0] = ((Select) inst).getTarget();
                    System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
                    return ret;
                }
                else{
                    pair[0] = getInstruction().getNext();
                    pair[1] = ((BranchInstruction) inst).getTarget();
                    return pair;
                }
            }

            // default case: Fall through.      
            single[0] = getInstruction().getNext();
            return single;
        }
项目:eclectic    文件:DecompilingVisitor.java   
public void visitCode(Code code) {
    MethodGen mg = new MethodGen(_method, clazzname, cp);
    InstructionList il = mg.getInstructionList();
    InstructionHandle[] ihs = il.getInstructionHandles();

    LocalVariableGen[] lvs = mg.getLocalVariables();

    CodeExceptionGen[] ehs = mg.getExceptionHandlers();

    for (int i = 0; i < lvs.length; i++) {
        LocalVariableGen l = lvs[i];
        out.println("    // local variable " + l.getIndex() + " is \"" + l.getName()
                + "\" " + l.getType() + " from "
                + l.getStart().getPosition() + " to "
                + l.getEnd().getPosition());
    }

    out.print("\n");

    for (int i = 0; i < ihs.length; i++) {
        InstructionHandle ih = ihs[i];
        Instruction inst = ih.getInstruction();

        out.print("    " + ih.getPosition());

        if (inst instanceof BranchInstruction) {
            if (inst instanceof Select) { // Special cases LOOKUPSWITCH and
                                          // TABLESWITCH
                Select s = (Select) inst;
                int[] matchs = s.getMatchs();
                InstructionHandle[] targets = s.getTargets();

                if (s instanceof TABLESWITCH) {
                    out.println("  tableswitch " + matchs[0] + " "
                            + matchs[matchs.length - 1]);

                    for (int j = 0; j < targets.length; j++)
                        out.println("        " + targets[j].getPosition());

                } else { // LOOKUPSWITCH
                    out.println("  lookupswitch ");

                    for (int j = 0; j < targets.length; j++)
                        out.println("        " + matchs[j] + " : "
                                + targets[j].getPosition());
                }

                out.println("        default: " + s.getTarget()); // Applies
                                                                  // for
                                                                  // both
            } else {
                BranchInstruction bi = (BranchInstruction) inst;
                ih = bi.getTarget();
                //str = get(ih);
                out.println("  " + Constants.OPCODE_NAMES[bi.getOpcode()]
                        + " " + ih);
            }
        } else
            out.println("  " + inst.toString(cp.getConstantPool()));
    }

    out.print("\n");

    for (int i = 0; i < ehs.length; i++) {
        CodeExceptionGen c = ehs[i];
        ObjectType caught = c.getCatchType();
        String class_name = (caught == null) ? // catch any exception, used
                                               // when compiling finally
                "all" : caught.getClassName().replace('.', '/');

        out.println("    catch " + class_name + " from "
                + c.getStartPC().getPosition() + " to "
                + c.getEndPC().getPosition() + " using "
                + c.getHandlerPC().getPosition());
    }
}
项目:eclectic    文件:Subroutines.java   
/**
 * A utility method that calculates the successors of a given InstructionHandle
 * <B>in the same subroutine</B>. That means, a RET does not have any successors
 * as defined here. A JsrInstruction has its physical successor as its successor
 * (opposed to its target) as defined here.
 */
private static InstructionHandle[] getSuccessors(InstructionHandle instruction){
    Instruction inst = instruction.getInstruction();

       if (inst instanceof RET){
        return empty;
    }

    // Terminates method normally.
    if (inst instanceof ReturnInstruction){
        return empty;
    }

    // Terminates method abnormally, because JustIce mandates
    // subroutines not to be protected by exception handlers.
    if (inst instanceof ATHROW){
        return empty;
    }

       final InstructionHandle[] single = new InstructionHandle[1];

       // See method comment.
    if (inst instanceof JsrInstruction){
        single[0] = instruction.getNext();
        return single;
    }

    if (inst instanceof GotoInstruction){
        single[0] = ((GotoInstruction) inst).getTarget();
        return single;
    }

    if (inst instanceof BranchInstruction){
        if (inst instanceof Select){
            // BCEL's getTargets() returns only the non-default targets,
            // thanks to Eli Tilevich for reporting.
            InstructionHandle[] matchTargets = ((Select) inst).getTargets();
            InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
            ret[0] = ((Select) inst).getTarget();
            System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
            return ret;
        }
        else{
               final InstructionHandle[] pair = new InstructionHandle[2];
            pair[0] = instruction.getNext();
            pair[1] = ((BranchInstruction) inst).getTarget();
            return pair;
        }
    }

    // default case: Fall through.
    single[0] = instruction.getNext();
    return single;
}
项目:eclectic    文件:ControlFlowGraph.java   
/**
         * A utility method that calculates the successors of a given InstructionHandle
         * That means, a RET does have successors as defined here.
         * A JsrInstruction has its target as its successor
         * (opposed to its physical successor) as defined here.
         */
// TODO: implement caching!
        private InstructionHandle[] _getSuccessors(){
            final InstructionHandle[] empty = new InstructionHandle[0];
            final InstructionHandle[] single = new InstructionHandle[1];
            final InstructionHandle[] pair = new InstructionHandle[2];

            Instruction inst = getInstruction().getInstruction();

            if (inst instanceof RET){
                Subroutine s = subroutines.subroutineOf(getInstruction());
                if (s==null){ //return empty; // RET in dead code. "empty" would be the correct answer, but we know something about the surrounding project...
                    throw new AssertionViolatedException("Asking for successors of a RET in dead code?!");
                }
//TODO: remove
throw new AssertionViolatedException("DID YOU REALLY WANT TO ASK FOR RET'S SUCCS?");
/*
                InstructionHandle[] jsrs = s.getEnteringJsrInstructions();
                InstructionHandle[] ret = new InstructionHandle[jsrs.length];
                for (int i=0; i<jsrs.length; i++){
                    ret[i] = jsrs[i].getNext();
                }
                return ret;
*/
            }

            // Terminates method normally.
            if (inst instanceof ReturnInstruction){
                return empty;
            }

            // Terminates method abnormally, because JustIce mandates
            // subroutines not to be protected by exception handlers.
            if (inst instanceof ATHROW){
                return empty;
            }

            // See method comment.
            if (inst instanceof JsrInstruction){
                single[0] = ((JsrInstruction) inst).getTarget();
                return single;
            }

            if (inst instanceof GotoInstruction){
                single[0] = ((GotoInstruction) inst).getTarget();
                return single;
            }

            if (inst instanceof BranchInstruction){
                if (inst instanceof Select){
                    // BCEL's getTargets() returns only the non-default targets,
                    // thanks to Eli Tilevich for reporting.
                    InstructionHandle[] matchTargets = ((Select) inst).getTargets();
                    InstructionHandle[] ret = new InstructionHandle[matchTargets.length+1];
                    ret[0] = ((Select) inst).getTarget();
                    System.arraycopy(matchTargets, 0, ret, 1, matchTargets.length);
                    return ret;
                }
                else{
                    pair[0] = getInstruction().getNext();
                    pair[1] = ((BranchInstruction) inst).getTarget();
                    return pair;
                }
            }

            // default case: Fall through.      
            single[0] = getInstruction().getNext();
            return single;
        }