use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class SwitchRangeVisitor method visitSwitchIntermediate.
@Override
public void visitSwitchIntermediate(SwitchIntermediate line) {
boolean foundUpper = false;
AbstractIntermediate lastNode = igc.findNextNode(findMaxCase(line).getTarget());
TreeSet<AbstractIntermediate> elements = (TreeSet<AbstractIntermediate>) igc.getOrderedIntermediate().subSet(line, true, lastNode, false);
int position = lastNode.getInstruction().getPosition();
// look for goto statements...
for (AbstractIntermediate element : elements) {
if (element instanceof GoToIntermediate) {
GoToIntermediate gti = (GoToIntermediate) element;
if (igc.getTarget(gti).getInstruction().getPosition() > position) {
line.getBlockRange().setEnd(igc.getTarget(gti).getInstruction().getPrev());
foundUpper = true;
break;
}
}
}
if (!foundUpper) {
// find the last node... and then get the next.
line.getBlockRange().setEnd(lastNode.getInstruction());
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class BlockVisitor method visitIfIntermediate.
@Override
public void visitIfIntermediate(IfIntermediate line) {
if (seen.contains(line)) {
// do nothing.
return;
} else {
seen.add(line);
}
IfBlock ifBlock = new IfBlock(line);
current.addChild(ifBlock);
this.current = ifBlock;
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 = ifBlock;
falseOutcome.accept(this);
if (this.current == ifBlock) {
moveUp();
}
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class BlockVisitor method visitElseIntermediate.
@Override
public void visitElseIntermediate(ElseIntermediate line) {
if (seen.contains(line)) {
// do nothing.
return;
} else {
seen.add(line);
}
ElseBlock elseBlock = new ElseBlock(line);
current.addChild(elseBlock);
current = elseBlock;
// 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);
}
}
moveUp();
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate in project candle-decompiler by bradsdavis.
the class GraphIntermediateVisitor method process.
public void process() {
GraphUpdatedListener gul = new GraphUpdatedListener();
if (listenForUpdates) {
igc.getGraph().addGraphListener(gul);
}
while (true) {
Set<AbstractIntermediate> snapshot = new HashSet<AbstractIntermediate>();
snapshot.addAll(igc.getGraph().vertexSet());
for (AbstractIntermediate vertex : snapshot) {
if (igc.getGraph().containsVertex(vertex)) {
vertex.accept(this);
}
}
// reset the update listener.
if (!gul.isUpdated()) {
break;
} else {
gul.reset();
}
}
igc.getGraph().removeGraphListener(gul);
}
use of org.candle.decompiler.intermediate.code.AbstractIntermediate 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;
}
Aggregations