Search in sources :

Example 1 with BytecodeCFGMethodVisitor

use of org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor in project sonar-java by SonarSource.

the class SETestUtils method bytecodeCFG.

public static BytecodeCFG bytecodeCFG(String signature, SquidClassLoader classLoader) {
    BytecodeCFGMethodVisitor cfgMethodVisitor = new BytecodeCFGMethodVisitor() {

        @Override
        public boolean shouldVisitMethod(int methodFlags, String methodSignature) {
            return true;
        }
    };
    MethodLookup.lookup(signature, classLoader, cfgMethodVisitor);
    return cfgMethodVisitor.getCfg();
}
Also used : BytecodeCFGMethodVisitor(org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor)

Example 2 with BytecodeCFGMethodVisitor

use of org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor in project sonar-java by SonarSource.

the class BytecodeEGWalker method execute.

private void execute(String signature, SquidClassLoader classLoader) {
    BytecodeCFGMethodVisitor cfgVisitor = new BytecodeCFGMethodVisitor();
    MethodLookup lookup = MethodLookup.lookup(signature, classLoader, cfgVisitor);
    if (lookup == null) {
        LOG.debug("Method body not found: %s", signature);
        return;
    }
    methodBehavior.setDeclaredExceptions(lookup.declaredExceptions);
    methodBehavior.setVarArgs(lookup.isVarArgs);
    BytecodeCFG bytecodeCFG = cfgVisitor.getCfg();
    if (bytecodeCFG == null) {
        return;
    }
    exitBlock = bytecodeCFG.exitBlock();
    steps = 0;
    for (ProgramState startingState : startingStates(signature, ProgramState.EMPTY_STATE, lookup.isStatic)) {
        enqueue(new ProgramPoint(bytecodeCFG.entry()), startingState);
    }
    while (!workList.isEmpty()) {
        steps++;
        if (steps > maxSteps()) {
            throw new ExplodedGraphWalker.MaximumStepsReachedException("Too many steps resolving " + methodBehavior.signature());
        }
        // LIFO:
        setNode(workList.removeFirst());
        if (programPosition.block.successors().isEmpty()) {
            endOfExecutionPath.add(node);
            continue;
        }
        if (programPosition.i < programPosition.block.elements().size()) {
            // process block element
            executeInstruction((Instruction) programPosition.block.elements().get(programPosition.i));
        } else {
            // process block exit, which is unconditional jump such as goto-statement or return-statement
            handleBlockExit(programPosition);
        }
    }
    handleEndOfExecutionPath();
    executeCheckEndOfExecution();
    methodBehavior.completed();
    // Cleanup:
    workList = null;
    node = null;
    programState = null;
    constraintManager = null;
}
Also used : ProgramPoint(org.sonar.java.se.ProgramPoint) BytecodeCFG(org.sonar.java.bytecode.cfg.BytecodeCFG) ProgramState(org.sonar.java.se.ProgramState) BytecodeCFGMethodVisitor(org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor)

Aggregations

BytecodeCFGMethodVisitor (org.sonar.java.bytecode.cfg.BytecodeCFGMethodVisitor)2 BytecodeCFG (org.sonar.java.bytecode.cfg.BytecodeCFG)1 ProgramPoint (org.sonar.java.se.ProgramPoint)1 ProgramState (org.sonar.java.se.ProgramState)1