Search in sources :

Example 26 with AbstractIntermediate

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

the class IntermediateTryCatch method generateCatch.

private void generateCatch(TryIntermediate tryIntermediate, CodeExceptionGen ceg) {
    LOG.debug("CEG: " + ceg);
    // convert the node to catch blocks...
    AbstractIntermediate catchDeclaration = igc.getOrderedIntermediate().ceiling(new NullIntermediate(ceg.getHandlerPC()));
    LOG.debug("Catch Declaration:" + catchDeclaration);
    if (catchDeclaration instanceof StatementIntermediate) {
        StatementIntermediate declarationStatement = (StatementIntermediate) catchDeclaration;
        if (declarationStatement.getExpression() instanceof Declaration) {
            Declaration declaration = (Declaration) declarationStatement.getExpression();
            // now, we can convert this into a catch block.
            CatchIntermediate catchIntermediate = new CatchIntermediate(declarationStatement.getInstruction(), ceg, declaration.getVariable());
            igc.getGraph().addVertex(catchIntermediate);
            // redirect statement to catch.
            igc.redirectPredecessors(declarationStatement, catchIntermediate);
            igc.redirectSuccessors(declarationStatement, catchIntermediate);
            // now, we just need to remove the statement.
            igc.getGraph().removeVertex(declarationStatement);
            // populate the bounds..
            // add the link between try and catch.
            igc.getGraph().addEdge(tryIntermediate, catchIntermediate);
        }
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) StatementIntermediate(org.candle.decompiler.intermediate.code.StatementIntermediate) CatchIntermediate(org.candle.decompiler.intermediate.code.CatchIntermediate) Declaration(org.candle.decompiler.intermediate.expression.Declaration) NullIntermediate(org.candle.decompiler.intermediate.graph.context.NullIntermediate)

Example 27 with AbstractIntermediate

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

the class BlockVisitor method visitTryIntermediate.

@Override
public void visitTryIntermediate(TryIntermediate line) {
    if (seen.contains(line)) {
        // do nothing.
        return;
    } else {
        seen.add(line);
    }
    // set current block...
    TryBlock tryBlock = new TryBlock(line);
    // add it as a child of current..
    this.current.addChild(tryBlock);
    // set the current...
    this.current = tryBlock;
    // now, get the nested blocks...
    List<AbstractIntermediate> successors = getUnseenSuccessors(line);
    AbstractIntermediate inner = null;
    List<AbstractIntermediate> catchBlocks = new LinkedList<AbstractIntermediate>();
    AbstractIntermediate finallyIntermediate = null;
    // find the non-catch/finally...
    for (AbstractIntermediate successor : successors) {
        if (successor instanceof CatchIntermediate) {
            catchBlocks.add(successor);
        } else if (successor instanceof FinallyIntermediate) {
            finallyIntermediate = successor;
        } else {
            if (inner != null) {
                throw new IllegalStateException("Inner direction already set.");
            }
            inner = successor;
        }
    }
    Collections.sort(catchBlocks, new IntermediateComparator());
    if (inner == null) {
        throw new IllegalStateException("Inner is not set.");
    }
    inner.accept(this);
    // set the current up.
    moveUp();
    for (AbstractIntermediate catchBlock : catchBlocks) {
        current = tryBlock;
        catchBlock.accept(this);
    }
    if (finallyIntermediate != null) {
        current = tryBlock;
        finallyIntermediate.accept(this);
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) CatchIntermediate(org.candle.decompiler.intermediate.code.CatchIntermediate) FinallyIntermediate(org.candle.decompiler.intermediate.code.FinallyIntermediate) TryBlock(org.candle.decompiler.ast.tcf.TryBlock) IntermediateComparator(org.candle.decompiler.intermediate.code.IntermediateComparator) LinkedList(java.util.LinkedList)

Example 28 with AbstractIntermediate

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

the class BlockVisitor method processBoolean.

protected void processBoolean(Block block, BooleanBranchIntermediate bbi) {
    List<AbstractIntermediate> successors = getUnseenSuccessors(bbi);
    // assign true... and go through true.
    AbstractIntermediate trueOutcome = igc.getTrueTarget(bbi);
    AbstractIntermediate falseOutcome = igc.getFalseTarget(bbi);
    /*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 = block;
    falseOutcome.accept(this);
    if (this.current == block) {
        moveUp();
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate)

Example 29 with AbstractIntermediate

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

the class BlockVisitor method visitCaseIntermediate.

@Override
public void visitCaseIntermediate(CaseIntermediate line) {
    SwitchCaseBlock switchCaseBlock = new SwitchCaseBlock(line);
    current.addChild(switchCaseBlock);
    current = switchCaseBlock;
    // 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);
        }
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) SwitchCaseBlock(org.candle.decompiler.ast.swtch.SwitchCaseBlock)

Example 30 with AbstractIntermediate

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

the class BlockVisitor method visitElseIfIntermediate.

@Override
public void visitElseIfIntermediate(ElseIfIntermediate line) {
    if (seen.contains(line)) {
        // do nothing.
        return;
    } else {
        seen.add(line);
    }
    ElseIfBlock elseIfBlock = new ElseIfBlock(line);
    current.addChild(elseIfBlock);
    this.current = elseIfBlock;
    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 = elseIfBlock;
    falseOutcome.accept(this);
    if (this.current == elseIfBlock) {
        moveUp();
    }
}
Also used : AbstractIntermediate(org.candle.decompiler.intermediate.code.AbstractIntermediate) ElseIfBlock(org.candle.decompiler.ast.conditional.ElseIfBlock)

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