Search in sources :

Example 41 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class RetractDuplicateFinally method visitFinallyIntermediate.

@Override
public void visitFinallyIntermediate(FinallyIntermediate line) {
    // TODO: Remove the highest finally statements first; won't fit this visitor
    // pattern.
    // get the bounds of the finally... associate the try.
    // finally is part of the try if the try + catch bounds has:
    // Try[0,13]
    // Catch[19,50]
    // Catch[56,65]
    // Finally | Handler[56, 65]| Handler[0, 42] |  | Range[66, 76]
    // in the case above, finally should match because lower bound == finally lower handler bound.
    // and upper bound of Catch matches upper bound of Finally Handler.
    // first, match the Try block that applies...
    // get lowest bound.
    InstructionHandle min = getLowestBound(line.getCodeExceptions());
    InstructionHandle max = getHighestBound(line.getCodeExceptions());
    LOG.debug("Finally Range: " + min.getPosition() + " -> " + max.getPosition());
    TryIntermediate matched = matchTryBlock(min, max);
    if (matched != null) {
        final Set<Integer> offsets = collectOffsets(line);
        // ok, now we need to eliminate finally blocks from this try and all of the catches.  thanks Java!
        List<CatchIntermediate> catchClauses = igc.getCatchClauses(matched);
        // for each catch clause...
        for (CatchIntermediate catchClause : catchClauses) {
            processCatch(catchClause, line, offsets);
        }
        processTry(matched, line, offsets);
    }
    // now, add the edge between end of FINALLY and the next statement.
    InstructionHandle finallyEnd = line.getBlockRange().getEnd();
    // get the next.. then search for next node in graph.
    AbstractIntermediate finallyLast = igc.findNextNode(finallyEnd);
    AbstractIntermediate afterFinally = igc.findNextNode(finallyEnd.getNext());
    igc.redirectPredecessors(finallyLast, afterFinally);
    igc.getGraph().removeVertex(finallyLast);
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) CatchIntermediate(org.candle.decompiler.intermediate.code.CatchIntermediate) TryIntermediate(org.candle.decompiler.intermediate.code.TryIntermediate) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 42 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle 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)

Example 43 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class NonIntermediateEliminator method process.

@Override
public void process(InstructionHandle ih) {
    if (igc.hasIntermediate(ih)) {
        // don't process if there is an intermediate.
        return;
    }
    List<InstructionHandle> successors = igc.getSuccessors(ih);
    if (successors.size() == 1) {
        // now check to see whether there is an intermediate on the objects...
        InstructionHandle target = successors.get(0);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Remove vertex:" + ih);
        }
        igc.redirectPredecessors(ih, target);
        igc.getGraph().removeVertex(ih);
    } else {
        List<InstructionHandle> predecessors = igc.getPredecessors(ih);
        if (predecessors.size() == 1) {
            // compress backwards...
            igc.redirectSuccessors(ih, predecessors.get(0));
            igc.getGraph().removeVertex(ih);
        }
    }
}
Also used : InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 44 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class SplitInstructionEnhancer method visitPopInstruction.

@Override
public void visitPopInstruction(PopInstruction obj) {
    // check instruction in map.
    List<InstructionHandle> ivs = this.igc.getPredecessors(this.current);
    if (ivs.size() > 1) {
        // check to see if the predecessors pushed.
        int count = 0;
        for (InstructionHandle iv : ivs) {
            InstructionHandle jvmiv = (InstructionHandle) iv;
            jvmiv = findSource(jvmiv);
            if (jvmiv.getInstruction() instanceof PushInstruction) {
                count++;
            }
        }
        if (count > 1) {
            LOG.debug("Split vertex.");
            splitVertex(this.current);
        }
    }
}
Also used : PushInstruction(org.apache.bcel.generic.PushInstruction) InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Example 45 with InstructionHandle

use of org.apache.bcel.generic.InstructionHandle in project candle-decompiler by bradsdavis.

the class InstructionTransversalListener method vertexTraversed.

@Override
public void vertexTraversed(VertexTraversalEvent<InstructionHandle> e) {
    cpl.setup(e.getVertex());
    // process instruction handle.
    InstructionHandle jvm = e.getVertex();
    intermediateContext.setCurrentInstruction(jvm);
    jvm.getInstruction().accept(miv);
    // finish.
    cpl.finish(e);
    super.vertexFinished(e);
}
Also used : InstructionHandle(org.apache.bcel.generic.InstructionHandle)

Aggregations

InstructionHandle (org.apache.bcel.generic.InstructionHandle)103 InstructionList (org.apache.bcel.generic.InstructionList)26 MethodInfo (com.jopdesign.common.MethodInfo)20 CallString (com.jopdesign.common.code.CallString)20 Instruction (org.apache.bcel.generic.Instruction)13 MethodCode (com.jopdesign.common.MethodCode)12 ContextMap (com.jopdesign.dfa.framework.ContextMap)11 IntermediateEdge (org.candle.decompiler.intermediate.graph.edge.IntermediateEdge)11 Context (com.jopdesign.dfa.framework.Context)10 InvokeInstruction (org.apache.bcel.generic.InvokeInstruction)10 Iterator (java.util.Iterator)9 BranchInstruction (org.apache.bcel.generic.BranchInstruction)9 FieldInstruction (org.apache.bcel.generic.FieldInstruction)9 AbstractIntermediate (org.candle.decompiler.intermediate.code.AbstractIntermediate)9 ReturnInstruction (org.apache.bcel.generic.ReturnInstruction)8 InstructionFinder (org.apache.bcel.util.InstructionFinder)8 ClassInfo (com.jopdesign.common.ClassInfo)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 LinkedList (java.util.LinkedList)7