Search in sources :

Example 21 with AbstractIntermediate

use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.

the class IntermediateGraphContext method getNodesWithinRange.

public Set<AbstractIntermediate> getNodesWithinRange(BlockRange blockRange) {
    AbstractIntermediate start = findNextNode(blockRange.getStart());
    AbstractIntermediate end = findPreviousNode(blockRange.getEnd());
    return orderedIntermediate.subSet(start, false, end, false);
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate)

Example 22 with AbstractIntermediate

use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.

the class IntermediateGraphContext method getCases.

public List<CaseIntermediate> getCases(SwitchIntermediate si) {
    List<AbstractIntermediate> intermediate = Graphs.successorListOf(graph, si);
    List<CaseIntermediate> switchCases = new LinkedList<CaseIntermediate>();
    for (AbstractIntermediate i : intermediate) {
        if (i instanceof CaseIntermediate) {
            switchCases.add((CaseIntermediate) i);
        }
    }
    Collections.sort(switchCases, new CaseIntermediateComparator());
    return switchCases;
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) CaseIntermediateComparator(org.candle.decompiler.intermediate.code.CaseIntermediateComparator) CaseIntermediate(org.candle.decompiler.intermediate.code.CaseIntermediate) LinkedList(java.util.LinkedList)

Example 23 with AbstractIntermediate

use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.

the class PositionalIntermediateListener method vertexRemoved.

@Override
public void vertexRemoved(GraphVertexChangeEvent<AbstractIntermediate> e) {
    this.igc.getOrderedIntermediate().remove(e.getVertex());
    // remove the queued object if it is there too.
    queuePosition.remove(e.getVertex());
    boolean placedQueued = false;
    for (AbstractIntermediate ai : queuePosition) {
        if (ai.getInstruction() == e.getVertex().getInstruction()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Removed vertex: " + e.getVertex() + " Instruction: " + ai.getInstruction().getPosition());
                LOG.debug("\tLocated queued vertex: " + ai);
            }
            this.igc.getOrderedIntermediate().add(ai);
            placedQueued = true;
            break;
        }
    }
    if (!placedQueued) {
        Integer position = e.getVertex().getInstruction().getPosition();
        igc.getInstructionHandles().remove(position);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate)

Example 24 with AbstractIntermediate

use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.

the class IntermediateGraphFactory method visitStatementIntermediate.

@Override
public void visitStatementIntermediate(StatementIntermediate line) {
    AbstractIntermediate next = ilc.getNext(line);
    // check to see if it is a return statement.
    if (line.getExpression() instanceof Return) {
        // don't add a line to next.
        return;
    }
    if (line.getExpression() instanceof Throw) {
        // don't add a line to next.
        return;
    }
    if (next != null) {
        // find how that actually maps to the abstract line..
        AbstractIntermediate intermediate = next;
        // now, we just add this into the graph.
        igc.getGraph().addVertex(intermediate);
        igc.getGraph().addEdge(line, intermediate);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) Return(org.candle.decompiler.intermediate.expression.Return) Throw(org.candle.decompiler.intermediate.expression.Throw)

Example 25 with AbstractIntermediate

use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.

the class IntermediateGraphFactory method visitMultiBranchIntermediate.

@Override
public void visitMultiBranchIntermediate(MultiBranchIntermediate line) {
    Select select = (Select) line.getInstruction().getInstruction();
    Set<Case> cases = new HashSet<Case>();
    InstructionHandle[] handles = select.getTargets();
    int[] matches = select.getMatchs();
    for (int i = 0, j = handles.length; i < j; i++) {
        InstructionHandle ih = handles[i];
        int match = matches[i];
        Resolved resolved = new Resolved(line.getInstruction(), BasicType.INT, "" + match);
        Case caseEntry = new Case(line.getInstruction(), ih, resolved);
        cases.add(caseEntry);
    }
    if (select.getTarget() != null) {
        DefaultCase defaultCase = new DefaultCase(line.getInstruction(), select.getTarget());
        line.setDefaultCase(defaultCase);
    }
    // now, create the graph.
    line.setCases(cases);
    // now, create the graph.
    igc.getGraph().addVertex(line);
    if (line.getDefaultCase() != null) {
        CaseIntermediate si = new CaseIntermediate(line.getInstruction(), line.getDefaultCase());
        igc.getGraph().addVertex(si);
        // add an edge.
        igc.getGraph().addEdge(line, si);
        // add edge from outcome to edge.
        LOG.debug(si);
        AbstractIntermediate target = ilc.getNext(line.getDefaultCase().getTarget().getPosition());
        LOG.debug("TargeT:" + target);
        igc.getGraph().addVertex(target);
        igc.getGraph().addEdge(si, target);
    }
    for (Case caseVal : line.getCases()) {
        CaseIntermediate si = new CaseIntermediate(line.getInstruction(), caseVal);
        igc.getGraph().addVertex(si);
        // add an edge.
        igc.getGraph().addEdge(line, si);
        // add edge from outcome to edge.
        AbstractIntermediate target = ilc.getNext(caseVal.getTarget().getPosition());
        igc.getGraph().addVertex(target);
        igc.getGraph().addEdge(si, target);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) DefaultCase(org.candle.decompiler.intermediate.expression.DefaultCase) Select(org.apache.bcel.generic.Select) CaseIntermediate(org.candle.decompiler.intermediate.code.CaseIntermediate) Resolved(org.candle.decompiler.intermediate.expression.Resolved) InstructionHandle(org.apache.bcel.generic.InstructionHandle) Case(org.candle.decompiler.intermediate.expression.Case) DefaultCase(org.candle.decompiler.intermediate.expression.DefaultCase) HashSet(java.util.HashSet)

Aggregations

AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)50 StatementIntermediate (org.candle.decompiler.intermediate.code.StatementIntermediate)11 InstructionHandle (org.apache.bcel.generic.InstructionHandle)9 TreeSet (java.util.TreeSet)8 GoToIntermediate (org.candle.decompiler.intermediate.code.GoToIntermediate)8 HashSet (java.util.HashSet)6 CatchIntermediate (org.candle.decompiler.intermediate.code.CatchIntermediate)6 Declaration (org.candle.decompiler.intermediate.expression.Declaration)6 IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)6 TryIntermediate (org.candle.decompiler.intermediate.code.TryIntermediate)5 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 IntermediateComparator (org.candle.decompiler.intermediate.code.IntermediateComparator)4 BooleanBranchIntermediate (org.candle.decompiler.intermediate.code.BooleanBranchIntermediate)3 FinallyIntermediate (org.candle.decompiler.intermediate.code.FinallyIntermediate)3 ArrayList (java.util.ArrayList)2 BranchHandle (org.apache.bcel.generic.BranchHandle)2 CodeExceptionGen (org.apache.bcel.generic.CodeExceptionGen)2 ElseIfBlock (org.candle.decompiler.ast.conditional.ElseIfBlock)2 CaseIntermediate (org.candle.decompiler.intermediate.code.CaseIntermediate)2