use of org.objectweb.asm.tree.TryCatchBlockNode in project jacoco by jacoco.
the class MethodAnalyzer method accept.
@Override
public void accept(final MethodNode methodNode, final MethodVisitor methodVisitor) {
methodVisitor.visitCode();
for (final TryCatchBlockNode n : methodNode.tryCatchBlocks) {
n.accept(methodVisitor);
}
for (final AbstractInsnNode i : methodNode.instructions) {
currentNode = i;
i.accept(methodVisitor);
}
methodVisitor.visitEnd();
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project jacoco by jacoco.
the class TryWithResourcesJavac11Filter method filter.
public void filter(final MethodNode methodNode, final IFilterContext context, final IFilterOutput output) {
if (methodNode.tryCatchBlocks.isEmpty()) {
return;
}
final Matcher matcher = new Matcher();
for (TryCatchBlockNode t : methodNode.tryCatchBlocks) {
if ("java/lang/Throwable".equals(t.type)) {
matcher.match(t.handler, output, true);
matcher.match(t.handler, output, false);
}
}
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project jacoco by jacoco.
the class TryWithResourcesEcjFilter method filter.
public void filter(final String className, final String superClassName, final MethodNode methodNode, final IFilterOutput output) {
if (methodNode.tryCatchBlocks.isEmpty()) {
return;
}
final Matcher matcher = new Matcher(output);
for (TryCatchBlockNode t : methodNode.tryCatchBlocks) {
if (t.type == null) {
matcher.start(t.handler);
if (!matcher.matchEcj()) {
matcher.start(t.handler);
matcher.matchEcjNoFlowOut();
}
}
}
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project soot by Sable.
the class AsmMethodSource method emitTraps.
private void emitTraps() {
Chain<Trap> traps = body.getTraps();
SootClass throwable = Scene.v().getSootClass("java.lang.Throwable");
Map<LabelNode, Iterator<UnitBox>> handlers = new HashMap<LabelNode, Iterator<UnitBox>>(tryCatchBlocks.size());
for (TryCatchBlockNode tc : tryCatchBlocks) {
UnitBox start = Jimple.v().newStmtBox(null);
UnitBox end = Jimple.v().newStmtBox(null);
Iterator<UnitBox> hitr = handlers.get(tc.handler);
if (hitr == null) {
hitr = trapHandlers.get(tc.handler).iterator();
handlers.put(tc.handler, hitr);
}
UnitBox handler = hitr.next();
SootClass cls = tc.type == null ? throwable : Scene.v().getSootClass(AsmUtil.toQualifiedName(tc.type));
Trap trap = Jimple.v().newTrap(cls, start, end, handler);
traps.add(trap);
labels.put(tc.start, start);
labels.put(tc.end, end);
}
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project jphp by jphp-compiler.
the class TryCatchCompiler method write.
@Override
public void write(TryStmtToken token) {
if (token.getBody() == null || token.getBody().getInstructions().isEmpty()) {
if (token.getFinally() != null)
expr.write(BodyStmtToken.class, token.getFinally());
return;
}
expr.writeDefineVariables(token.getLocal());
LabelNode tryStart = expr.writeLabel(node, token.getMeta().getStartLine());
LabelNode tryEnd = new LabelNode();
LabelNode catchStart = new LabelNode();
LabelNode catchEnd = new LabelNode();
LabelNode returnLabel = new LabelNode();
method.node.tryCatchBlocks.add(0, new TryCatchBlockNode(tryStart, tryEnd, catchStart, Type.getInternalName(BaseBaseException.class)));
if (token.getFinally() != null) {
method.getTryStack().push(new MethodStmtCompiler.TryCatchItem(token, returnLabel));
}
expr.write(BodyStmtToken.class, token.getBody());
if (token.getFinally() != null) {
method.getTryStack().pop();
}
add(tryEnd);
add(new JumpInsnNode(GOTO, catchEnd));
add(catchStart);
LocalVariable exception = method.addLocalVariable("~catch~" + method.nextStatementIndex(BaseException.class), catchStart, BaseBaseException.class);
exception.setEndLabel(catchEnd);
expr.makeVarStore(exception);
LabelNode nextCatch = null;
int i = 0, size = token.getCatches().size();
LocalVariable local = null;
LabelNode catchFail = new LabelNode();
for (CatchStmtToken _catch : token.getCatches()) {
if (nextCatch != null) {
add(nextCatch);
}
if (i == size - 1) {
nextCatch = catchFail;
} else {
nextCatch = new LabelNode();
}
local = method.getLocalVariable(_catch.getVariable().getName());
List<FulledNameToken> catchExceptions = _catch.getExceptions();
LabelNode bodyLabel = new LabelNode();
LabelNode nextCatchLocal = new LabelNode();
int j = 0;
for (FulledNameToken catchException : catchExceptions) {
if (j > 0) {
add(nextCatchLocal);
nextCatchLocal = new LabelNode();
}
expr.writePushEnv();
expr.writeVarLoad(exception);
expr.writePushConstString(catchException.toName());
expr.writePushConstString(catchException.toName().toLowerCase());
expr.writeSysDynamicCall(Environment.class, "__throwCatch", Memory.class, BaseBaseException.class, String.class, String.class);
expr.writeVarAssign(local, _catch.getVariable(), true, false);
expr.writePopBoolean();
add(new JumpInsnNode(IFEQ, j == catchExceptions.size() - 1 ? nextCatch : nextCatchLocal));
expr.stackPop();
if (catchExceptions.size() > 1) {
add(new JumpInsnNode(GOTO, bodyLabel));
}
j++;
}
if (catchExceptions.size() > 1) {
add(bodyLabel);
}
expr.write(BodyStmtToken.class, _catch.getBody());
add(new JumpInsnNode(GOTO, catchEnd));
i++;
}
add(catchFail);
if (token.getFinally() != null) {
expr.write(BodyStmtToken.class, token.getFinally());
}
/*if (method.getTryStack().empty()) {
expr.writePushEnv();
expr.writeVarLoad(exception);
expr.writeSysDynamicCall(Environment.class, "__throwFailedCatch", void.class, BaseException.class);
} else {*/
expr.makeVarLoad(exception);
add(new InsnNode(ATHROW));
// }
add(catchEnd);
if (token.getFinally() != null) {
LabelNode skip = new LabelNode();
add(new JumpInsnNode(GOTO, skip));
// finally for return
add(returnLabel);
expr.write(BodyStmtToken.class, token.getFinally());
if (method.getTryStack().empty()) {
// all finally blocks are done
LocalVariable retVar = method.getOrAddLocalVariable("~result~", null, Memory.class);
expr.writeVarLoad(retVar);
add(new InsnNode(ARETURN));
expr.stackPop();
} else {
// goto next finally block
add(new JumpInsnNode(GOTO, method.getTryStack().peek().getReturnLabel()));
}
add(skip);
// other finally
expr.write(BodyStmtToken.class, token.getFinally());
}
expr.writeUndefineVariables(token.getLocal());
method.prevStatementIndex(BaseBaseException.class);
}
Aggregations