Search in sources :

Example 16 with AbstractIntermediate

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

the class SwitchRangeVisitor method visitSwitchIntermediate.

@Override
public void visitSwitchIntermediate(SwitchIntermediate line) {
    boolean foundUpper = false;
    AbstractIntermediate lastNode = igc.findNextNode(findMaxCase(line).getTarget());
    TreeSet<AbstractIntermediate> elements = (TreeSet<AbstractIntermediate>) igc.getOrderedIntermediate().subSet(line, true, lastNode, false);
    int position = lastNode.getInstruction().getPosition();
    // look for goto statements...
    for (AbstractIntermediate element : elements) {
        if (element instanceof GoToIntermediate) {
            GoToIntermediate gti = (GoToIntermediate) element;
            if (igc.getTarget(gti).getInstruction().getPosition() > position) {
                line.getBlockRange().setEnd(igc.getTarget(gti).getInstruction().getPrev());
                foundUpper = true;
                break;
            }
        }
    }
    if (!foundUpper) {
        // find the last node... and then get the next.
        line.getBlockRange().setEnd(lastNode.getInstruction());
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) TreeSet(java.util.TreeSet) GoToIntermediate(org.candle.decompiler.intermediate.code.GoToIntermediate)

Example 17 with AbstractIntermediate

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

the class BlockVisitor method visitIfIntermediate.

@Override
public void visitIfIntermediate(IfIntermediate line) {
    if (seen.contains(line)) {
        // do nothing.
        return;
    } else {
        seen.add(line);
    }
    IfBlock ifBlock = new IfBlock(line);
    current.addChild(ifBlock);
    this.current = ifBlock;
    List<AbstractIntermediate> successors = getUnseenSuccessors(line);
    // assign true... and go through true.
    AbstractIntermediate trueOutcome = igc.getTrueTarget(line);
    AbstractIntermediate falseOutcome = igc.getFalseTarget(line);
    /*
		for(AbstractIntermediate successor : successors) {
			if(successor instanceof BooleanBranchOutcome) {
				if(((BooleanBranchOutcome) successor).getExpressionOutcome() == Boolean.TRUE) {
					trueOutcome = (BooleanBranchOutcome)successor;
				}
				else {
					falseOutcome = (BooleanBranchOutcome)successor;
				}
			}
			else {
				throw new IllegalStateException("Outcome of If expected to be boolean.");
			}
		}*/
    trueOutcome.accept(this);
    // now, go back to if...
    this.current = ifBlock;
    falseOutcome.accept(this);
    if (this.current == ifBlock) {
        moveUp();
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) IfBlock(org.candle.decompiler.ast.conditional.IfBlock) ElseIfBlock(org.candle.decompiler.ast.conditional.ElseIfBlock)

Example 18 with AbstractIntermediate

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

the class BlockVisitor method visitElseIntermediate.

@Override
public void visitElseIntermediate(ElseIntermediate line) {
    if (seen.contains(line)) {
        // do nothing.
        return;
    } else {
        seen.add(line);
    }
    ElseBlock elseBlock = new ElseBlock(line);
    current.addChild(elseBlock);
    current = elseBlock;
    // now, visit the successor, if any.
    List<AbstractIntermediate> candidates = getUnseenSuccessors(line);
    if (candidates.size() > 0) {
        for (AbstractIntermediate candidate : candidates) {
            // move to the next.
            candidate.accept(this);
        }
    }
    moveUp();
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) ElseBlock(org.candle.decompiler.ast.conditional.ElseBlock)

Example 19 with AbstractIntermediate

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

the class GraphIntermediateVisitor method process.

public void process() {
    GraphUpdatedListener gul = new GraphUpdatedListener();
    if (listenForUpdates) {
        igc.getGraph().addGraphListener(gul);
    }
    while (true) {
        Set<AbstractIntermediate> snapshot = new HashSet<AbstractIntermediate>();
        snapshot.addAll(igc.getGraph().vertexSet());
        for (AbstractIntermediate vertex : snapshot) {
            if (igc.getGraph().containsVertex(vertex)) {
                vertex.accept(this);
            }
        }
        // reset the update listener.
        if (!gul.isUpdated()) {
            break;
        } else {
            gul.reset();
        }
    }
    igc.getGraph().removeGraphListener(gul);
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) GraphUpdatedListener(org.candle.decompiler.intermediate.graph.context.GraphUpdatedListener) HashSet(java.util.HashSet)

Example 20 with AbstractIntermediate

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

the class IntermediateGraphContext method getCatchClauses.

public List<CatchIntermediate> getCatchClauses(TryIntermediate tryIntermediate) {
    // of all the successors, get the catch...
    List<AbstractIntermediate> candidates = Graphs.successorListOf(graph, tryIntermediate);
    List<CatchIntermediate> catchClauses = new ArrayList<CatchIntermediate>();
    for (AbstractIntermediate candidate : candidates) {
        if (candidate instanceof CatchIntermediate) {
            catchClauses.add((CatchIntermediate) candidate);
        }
    }
    return catchClauses;
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) CatchIntermediate(org.candle.decompiler.intermediate.code.CatchIntermediate) ArrayList(java.util.ArrayList)

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