use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class LoopGotoToBreak method processLoop.
public void processLoop(WhileIntermediate loop) {
// get the target... then look for GOTO statements going into the target that are within the range
// of the loop.
TreeSet<AbstractIntermediate> loopElements = (TreeSet<AbstractIntermediate>) igc.getOrderedIntermediate().subSet(igc.getTrueTarget(loop), true, igc.getFalseTarget(loop), false);
List<AbstractIntermediate> predecessors = Graphs.predecessorListOf(igc.getGraph(), igc.getFalseTarget(loop));
Set<GoToIntermediate> gotoToBreak = new HashSet<GoToIntermediate>();
for (AbstractIntermediate predecessor : predecessors) {
if (predecessor instanceof GoToIntermediate) {
if (loopElements.contains(predecessor)) {
gotoToBreak.add((GoToIntermediate) predecessor);
}
}
}
// now, we create new statements.
for (GoToIntermediate gotoToBreakStatement : gotoToBreak) {
transformGotoToBreak(gotoToBreakStatement);
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate 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.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class ArrayForToEnhancedFor method getForExteriorPredecessor.
private AbstractIntermediate getForExteriorPredecessor(ForIntermediate line) {
List<AbstractIntermediate> predecessors = Graphs.predecessorListOf(igc.getGraph(), line);
// loop max min
int min = line.getInstruction().getPosition();
int max = igc.getFalseTarget(line).getInstruction().getPosition();
Set<AbstractIntermediate> nested = new HashSet<AbstractIntermediate>();
// eliminate nested predecessors.
for (AbstractIntermediate pred : predecessors) {
int curPred = pred.getInstruction().getPosition();
if (curPred > min && curPred < max) {
nested.add(pred);
}
}
predecessors.removeAll(nested);
if (predecessors.size() == 1) {
return predecessors.get(0);
}
return null;
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class ConditionToWhileLoop method updateEdges.
protected void updateEdges(WhileIntermediate wi) {
List<AbstractIntermediate> predecessors = igc.getPredecessors(wi);
for (AbstractIntermediate predecessor : predecessors) {
IntermediateEdge ie = igc.getGraph().getEdge(predecessor, wi);
igc.validateBackEdge(ie);
}
List<AbstractIntermediate> successors = igc.getSuccessors(wi);
for (AbstractIntermediate successor : successors) {
IntermediateEdge ie = igc.getGraph().getEdge(wi, successor);
igc.validateBackEdge(ie);
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate 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