use of org.apache.bcel.generic.CodeExceptionGen in project jop by jop-devel.
the class InstructionInterpreter method interpret.
private void interpret(InstructionList il, Map<InstructionHandle, T> start, boolean initialize) {
if (initialize) {
InstructionHandle ih = il.getStart();
// set initial value for all instructions
while (ih != null) {
results.put(ih, analysis.bottom());
ih = ih.getNext();
}
results.putAll(start);
} else {
// Set initial values for new instructions
for (InstructionHandle ih = il.getStart(); ih != null; ih = ih.getNext()) {
if (results.containsKey(ih))
continue;
if (ih.getPrev() == null) {
// entry instruction, must always be merged with the initial state once, even
// if this has an ingoing edge
results.put(ih, analysis.initial(ih));
} else {
results.put(ih, analysis.bottom());
// check for exception handler entry
if (ih.hasTargeters()) {
for (InstructionTargeter targeter : ih.getTargeters()) {
if (targeter instanceof CodeExceptionGen && ((CodeExceptionGen) targeter).getHandlerPC().equals(ih)) {
results.put(ih, analysis.initial((CodeExceptionGen) targeter));
break;
}
}
}
}
}
}
LinkedList<Edge> worklist = new LinkedList<Edge>();
// setup the worklist
for (InstructionHandle ih : start.keySet()) {
if (initialize) {
// when initializing, we start from the initial values, not from ingoing edges
worklist.addAll(getOutEdges(ih));
} else {
// we continue from existing results
List<Edge> inEdges = getInEdges(il, ih);
if (inEdges.isEmpty()) {
// entry instruction without ingoing edges, nothing to continue from
worklist.addAll(getOutEdges(ih));
} else {
worklist.addAll(inEdges);
}
}
}
while (!worklist.isEmpty()) {
Edge edge = worklist.removeFirst();
InstructionHandle tail = edge.getTail();
InstructionHandle head = edge.getHead();
T tailValue = results.get(tail);
T headValue = results.get(head);
T transferred = analysis.transfer(tailValue, edge);
if (!analysis.compare(transferred, headValue)) {
T newValue = analysis.join(transferred, headValue);
results.put(head, newValue);
if (edge.getType() == EdgeType.EXIT_EDGE) {
continue;
}
List<Edge> outEdges = getOutEdges(head);
for (Edge outEdge : outEdges) {
if (worklist.contains(outEdge)) {
continue;
}
if (outEdges.size() > 1) {
worklist.addLast(outEdge);
} else {
worklist.addFirst(outEdge);
}
}
}
}
}
use of org.apache.bcel.generic.CodeExceptionGen in project jop by jop-devel.
the class MethodCode method getEndingExceptionRanges.
public List<CodeExceptionGen> getEndingExceptionRanges(InstructionHandle ih) {
List<CodeExceptionGen> list = new ArrayList<CodeExceptionGen>();
InstructionTargeter[] targeters = ih.getTargeters();
if (targeters == null)
return list;
for (InstructionTargeter t : targeters) {
if (t instanceof CodeExceptionGen) {
CodeExceptionGen ceg = (CodeExceptionGen) t;
if (ceg.getEndPC().equals(ih)) {
list.add(ceg);
}
}
}
return list;
}
use of org.apache.bcel.generic.CodeExceptionGen 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.apache.bcel.generic.CodeExceptionGen in project candle-decompiler by bradsdavis.
the class FinallyIntermediate method toString.
@Override
public String toString() {
StringWriter sw = new StringWriter();
sw.append("Finally");
for (CodeExceptionGen ceg : codeExceptions) {
sw.append(" | Handler[" + ceg.getStartPC().getPosition() + ", " + ceg.getEndPC().getPosition() + "]");
}
return sw.toString() + ";";
}
use of org.apache.bcel.generic.CodeExceptionGen in project candle-decompiler by bradsdavis.
the class InstructionTryCatch method process.
public void process() {
Map<InstructionRange, List<CodeExceptionGen>> tryRangeGen = new HashMap<InstructionRange, List<CodeExceptionGen>>();
//create try statements...
for (CodeExceptionGen ceg : exceptions) {
InstructionHandle min = (ceg.getStartPC());
InstructionHandle max = (ceg.getEndPC());
InstructionRange tryRange = new InstructionRange();
tryRange.setStart(min);
tryRange.setEnd(max);
//SKIP THE FINALLY
if (ceg.getCatchType() == null) {
continue;
}
if (!tryRangeGen.containsKey(tryRange)) {
tryRangeGen.put(tryRange, new LinkedList<CodeExceptionGen>());
}
tryRangeGen.get(tryRange).add(ceg);
}
}
Aggregations