Search in sources :

Example 11 with AbstractIntermediate

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

the class LoopGotoToBreak method processLoop.

public void processLoop(WhileIntermediate loop) {
    // get the target... then look for GOTO statements going into the target that are within the range
    // of the loop.
    TreeSet<AbstractIntermediate> loopElements = (TreeSet<AbstractIntermediate>) igc.getOrderedIntermediate().subSet(igc.getTrueTarget(loop), true, igc.getFalseTarget(loop), false);
    List<AbstractIntermediate> predecessors = Graphs.predecessorListOf(igc.getGraph(), igc.getFalseTarget(loop));
    Set<GoToIntermediate> gotoToBreak = new HashSet<GoToIntermediate>();
    for (AbstractIntermediate predecessor : predecessors) {
        if (predecessor instanceof GoToIntermediate) {
            if (loopElements.contains(predecessor)) {
                gotoToBreak.add((GoToIntermediate) predecessor);
            }
        }
    }
    // now, we create new statements.
    for (GoToIntermediate gotoToBreakStatement : gotoToBreak) {
        transformGotoToBreak(gotoToBreakStatement);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) TreeSet(java.util.TreeSet) GoToIntermediate(org.candle.decompiler.intermediate.code.GoToIntermediate) HashSet(java.util.HashSet)

Example 12 with AbstractIntermediate

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

the class IntermediateEdgeAttributeProvider method getComponentAttributes.

@Override
public Map<String, String> getComponentAttributes(IntermediateEdge edge) {
    Map<String, String> attributes = new HashMap<String, String>();
    AbstractIntermediate source = (AbstractIntermediate) edge.getSource();
    AbstractIntermediate target = (AbstractIntermediate) edge.getTarget();
    if (source instanceof TryIntermediate && (target instanceof CatchIntermediate || target instanceof FinallyIntermediate)) {
        attributes.put("style", "dashed");
    }
    return attributes;
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) HashMap(java.util.HashMap) CatchIntermediate(org.candle.decompiler.intermediate.code.CatchIntermediate) FinallyIntermediate(org.candle.decompiler.intermediate.code.FinallyIntermediate) TryIntermediate(org.candle.decompiler.intermediate.code.TryIntermediate)

Example 13 with AbstractIntermediate

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

the class ArrayForToEnhancedFor method getForExteriorPredecessor.

private AbstractIntermediate getForExteriorPredecessor(ForIntermediate line) {
    List<AbstractIntermediate> predecessors = Graphs.predecessorListOf(igc.getGraph(), line);
    // loop max min
    int min = line.getInstruction().getPosition();
    int max = igc.getFalseTarget(line).getInstruction().getPosition();
    Set<AbstractIntermediate> nested = new HashSet<AbstractIntermediate>();
    // eliminate nested predecessors.
    for (AbstractIntermediate pred : predecessors) {
        int curPred = pred.getInstruction().getPosition();
        if (curPred > min && curPred < max) {
            nested.add(pred);
        }
    }
    predecessors.removeAll(nested);
    if (predecessors.size() == 1) {
        return predecessors.get(0);
    }
    return null;
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) HashSet(java.util.HashSet)

Example 14 with AbstractIntermediate

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

the class ConditionToWhileLoop method updateEdges.

protected void updateEdges(WhileIntermediate wi) {
    List<AbstractIntermediate> predecessors = igc.getPredecessors(wi);
    for (AbstractIntermediate predecessor : predecessors) {
        IntermediateEdge ie = igc.getGraph().getEdge(predecessor, wi);
        igc.validateBackEdge(ie);
    }
    List<AbstractIntermediate> successors = igc.getSuccessors(wi);
    for (AbstractIntermediate successor : successors) {
        IntermediateEdge ie = igc.getGraph().getEdge(wi, successor);
        igc.validateBackEdge(ie);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) IntermediateEdge(org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)

Example 15 with AbstractIntermediate

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

the class CatchUpperRangeVisitor method processLastCatch.

public void processLastCatch(CatchIntermediate line) {
    TryIntermediate tryBlock = (TryIntermediate) igc.getSinglePredecessor(line);
    if (igc.getFinallyClause(tryBlock) != null) {
        return;
    }
    // now, we are going to look for the block jump.
    InstructionHandle ih = tryBlock.getBlockRange().getEnd();
    // see about a goto.
    GoToIntermediate gotoHandle = (GoToIntermediate) igc.findNextNode(ih.getNext());
    TreeSet<AbstractIntermediate> ordered = new TreeSet<AbstractIntermediate>(new IntermediateComparator());
    // no finally clause...
    ordered.addAll(igc.getCatchClauses(tryBlock));
    AbstractIntermediate target = igc.getTarget(gotoHandle);
    // now, look backwards and find the non-GOTO statement.
    List<AbstractIntermediate> candidates = Graphs.predecessorListOf(igc.getGraph(), target);
    Set<AbstractIntermediate> elements = new HashSet<AbstractIntermediate>();
    for (AbstractIntermediate candidate : candidates) {
        if (!(candidate instanceof GoToIntermediate)) {
            elements.add(candidate);
        }
    }
    for (AbstractIntermediate element : elements) {
        LOG.debug("Element: " + element + " Position: " + element.getInstruction().getPosition());
    }
    if (elements.size() == 1) {
        if (ordered.last() instanceof CatchIntermediate) {
            CatchIntermediate ci = (CatchIntermediate) ordered.last();
            ci.getBlockRange().setEnd(elements.iterator().next().getInstruction());
        }
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) GoToIntermediate(org.candle.decompiler.intermediate.code.GoToIntermediate) TreeSet(java.util.TreeSet) CatchIntermediate(org.candle.decompiler.intermediate.code.CatchIntermediate) TryIntermediate(org.candle.decompiler.intermediate.code.TryIntermediate) IntermediateComparator(org.candle.decompiler.intermediate.code.IntermediateComparator) InstructionHandle(org.apache.bcel.generic.InstructionHandle) 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