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);
}
}
}
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);
}
}
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();
}
}
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);
}
}
}
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();
}
}
Aggregations