use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class RetractDuplicateFinally method processTry.
protected void processTry(TryIntermediate tryIntermediate, FinallyIntermediate finallyIntermediate, Set<Integer> offsets) {
// ok, now let's handle the try...
InstructionHandle end = tryIntermediate.getBlockRange().getEnd();
// next should be GOTO.
AbstractIntermediate tryEndNode = igc.findNextNode(end);
AbstractIntermediate gotoIntermediate = null;
// check to see if this is loop...
if (tryEndNode instanceof StatementIntermediate) {
LOG.debug("Position: " + tryEndNode.getInstruction().getPosition() + " Value: " + tryEndNode);
gotoIntermediate = igc.getSingleSuccessor(tryEndNode);
} else if (tryEndNode instanceof BooleanBranchIntermediate) {
BooleanBranchIntermediate bbi = (BooleanBranchIntermediate) tryEndNode;
// find higher target...
AbstractIntermediate trueTarget = igc.getTrueTarget(bbi);
AbstractIntermediate falseTarget = igc.getFalseTarget(bbi);
int trueTargetPosition = trueTarget.getInstruction().getPosition();
int falseTargetPosition = falseTarget.getInstruction().getPosition();
gotoIntermediate = (trueTargetPosition > falseTargetPosition) ? trueTarget : falseTarget;
}
// validate it is a GOTO.
if (!(gotoIntermediate instanceof GoToIntermediate)) {
LOG.warn("Expected GOTO. But this isn't: " + gotoIntermediate);
} else {
AbstractIntermediate tryFinallyFirst = igc.getSingleSuccessor(gotoIntermediate);
eliminateNode(tryFinallyFirst, offsets);
// now, eliminate the GOTO.
igc.getGraph().removeVertex(gotoIntermediate);
igc.getGraph().addEdge(tryIntermediate, finallyIntermediate);
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class RetractDuplicateFinally method matchTryBlock.
protected TryIntermediate matchTryBlock(InstructionHandle min, InstructionHandle max) {
LinkedList<TryIntermediate> matches = new LinkedList<TryIntermediate>();
// find the try block...
for (AbstractIntermediate ai : igc.getGraph().vertexSet()) {
if (ai instanceof TryIntermediate) {
TryIntermediate tryIntermediate = ((TryIntermediate) ai);
LOG.debug("Finally: " + tryIntermediate + " , " + tryIntermediate.getInstruction().getPosition() + " , " + tryIntermediate.getBlockRange().getStart());
if (tryIntermediate.getBlockRange().getStart().getPosition() == min.getPosition()) {
// only add where max > try's max range...
if (tryIntermediate.getBlockRange().getEnd().getPosition() < max.getPosition()) {
matches.add(tryIntermediate);
}
}
}
}
// return the smaller range...
if (matches.size() > 0) {
Collections.sort(matches, new Comparator<TryIntermediate>() {
@Override
public int compare(TryIntermediate t1, TryIntermediate t2) {
if (t1.getBlockRange().getEnd().getPosition() > t2.getBlockRange().getEnd().getPosition()) {
return -1;
}
return 0;
}
});
LOG.debug("Match: " + matches.peekFirst() + " Range: " + matches.peekFirst().getBlockRange());
return matches.getFirst();
}
return null;
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class RetractDuplicateFinally method processCatch.
protected void processCatch(CatchIntermediate catchIntermediate, FinallyIntermediate finallyIntermediate, Set<Integer> offsets) {
for (CodeExceptionGen ceg : finallyIntermediate.getCodeExceptions()) {
int position = ceg.getEndPC().getPosition();
if (catchIntermediate.getBlockRange().containsNumber(position)) {
LOG.debug("Relevant: " + position);
// we found the relevant position, now we need to find the next...
AbstractIntermediate lastNode = igc.findNextNode(ceg.getEndPC());
AbstractIntermediate finallyStart = igc.getSingleSuccessor(lastNode);
LOG.debug("Finally start: " + finallyStart);
// start eliminating nodes from this point.
eliminateNode(finallyStart, offsets);
}
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class FinallyRangeVisitor method visitFinallyIntermediate.
@Override
public void visitFinallyIntermediate(FinallyIntermediate line) {
NonGotoIterator iter = new NonGotoIterator(igc.getGraph(), line);
// walk until we find a THROW.
AbstractIntermediate throwsStatement = null;
while (iter.hasNext()) {
AbstractIntermediate i = iter.next();
if (i instanceof StatementIntermediate) {
StatementIntermediate s = (StatementIntermediate) i;
if (s.getExpression() instanceof Throw) {
throwsStatement = s;
break;
}
}
}
if (throwsStatement != null) {
line.getBlockRange().setEnd(throwsStatement.getInstruction());
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class ConstantArrayCompressor method extractNextDeclaration.
public Declaration extractNextDeclaration(StatementIntermediate statement) {
List<AbstractIntermediate> successors = Graphs.successorListOf(igc.getGraph(), statement);
if (successors.size() != 1) {
return null;
}
if (!(successors.get(0) instanceof StatementIntermediate)) {
return null;
}
StatementIntermediate si = (StatementIntermediate) successors.get(0);
if (si.getExpression() instanceof Declaration) {
return (Declaration) si.getExpression();
}
return null;
}
Aggregations