use of org.candle.decompiler.intermediate.code.CatchIntermediate 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.CatchIntermediate 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;
}
use of org.candle.decompiler.intermediate.code.CatchIntermediate 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);
}
use of org.candle.decompiler.intermediate.code.CatchIntermediate in project candle-decompiler by bradsdavis.
the class IntermediateEdgeAttributeProvider method getComponentAttributes.
@Override
public Map<String, String> getComponentAttributes(IntermediateEdge edge) {
Map<String, String> attributes = new HashMap<String, String>();
AbstractIntermediate source = (AbstractIntermediate) edge.getSource();
AbstractIntermediate target = (AbstractIntermediate) edge.getTarget();
if (source instanceof TryIntermediate && (target instanceof CatchIntermediate || target instanceof FinallyIntermediate)) {
attributes.put("style", "dashed");
}
return attributes;
}
use of org.candle.decompiler.intermediate.code.CatchIntermediate 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());
}
}
}
Aggregations