use of org.objectweb.asm.tree.LabelNode in project jacoco by jacoco.
the class SynchronizedFilterTest method javac.
@Test
public void javac() {
final Label start = new Label();
final Label end = new Label();
final Label handler = new Label();
final Label handlerEnd = new Label();
m.visitTryCatchBlock(start, end, handler, null);
m.visitTryCatchBlock(handler, handlerEnd, handler, null);
m.visitVarInsn(Opcodes.ALOAD, 0);
m.visitFieldInsn(Opcodes.GETFIELD, "Fun", "lock", "Ljava/lang/Object;");
m.visitInsn(Opcodes.DUP);
m.visitVarInsn(Opcodes.ASTORE, 1);
m.visitInsn(Opcodes.MONITORENTER);
m.visitLabel(start);
m.visitInsn(Opcodes.NOP);
m.visitVarInsn(Opcodes.ALOAD, 1);
m.visitInsn(Opcodes.MONITOREXIT);
m.visitLabel(end);
final Label exit = new Label();
m.visitJumpInsn(Opcodes.GOTO, exit);
m.visitLabel(handler);
m.visitVarInsn(Opcodes.ASTORE, 2);
m.visitVarInsn(Opcodes.ALOAD, 1);
m.visitInsn(Opcodes.MONITOREXIT);
m.visitLabel(handlerEnd);
m.visitVarInsn(Opcodes.ALOAD, 2);
m.visitInsn(Opcodes.ATHROW);
m.visitLabel(exit);
m.visitInsn(Opcodes.RETURN);
filter.filter(m, context, output);
assertIgnored(new Range((LabelNode) handler.info, ((LabelNode) exit.info).getPrevious()));
}
use of org.objectweb.asm.tree.LabelNode in project jphp by jphp-compiler.
the class IfElseCompiler method writeBody.
private void writeBody(IfStmtToken token) {
LabelNode end = new LabelNode();
LabelNode elseL = new LabelNode();
expr.writePopBoolean();
add(new JumpInsnNode(IFEQ, token.getElseBody() != null ? elseL : end));
expr.stackPop();
if (token.getBody() != null) {
expr.write(token.getBody());
}
if (token.getElseBody() != null) {
add(new JumpInsnNode(GOTO, end));
add(elseL);
expr.write(token.getElseBody());
}
add(end);
add(new LineNumberNode(token.getMeta().getEndLine(), end));
}
use of org.objectweb.asm.tree.LabelNode in project jphp by jphp-compiler.
the class DoCompiler method write.
@Override
public void write(DoStmtToken token) {
expr.writeDefineVariables(token.getLocal());
LabelNode start = expr.writeLabel(node, token.getMeta().getStartLine());
LabelNode end = new LabelNode();
method.pushJump(end, start);
expr.write(token.getBody());
method.popJump();
expr.writeConditional(token.getCondition(), end);
add(new JumpInsnNode(GOTO, start));
add(end);
add(new LineNumberNode(token.getMeta().getEndLine(), end));
expr.writeUndefineVariables(token.getLocal());
}
use of org.objectweb.asm.tree.LabelNode in project jphp by jphp-compiler.
the class GotoLabelCompiler method write.
@Override
public void write(LabelStmtToken token) {
LabelNode labelNode = method.getOrCreateGotoLabel(token.getName());
add(labelNode);
}
use of org.objectweb.asm.tree.LabelNode in project jphp by jphp-compiler.
the class SwitchCompiler method write.
@Override
public void write(SwitchStmtToken token) {
expr.writeDefineVariables(token.getLocal());
LabelNode l = new LabelNode();
LabelNode end = new LabelNode();
add(l);
LocalVariable switchValue = method.addLocalVariable("~switch~" + method.nextStatementIndex(Memory.class), l, Memory.class);
switchValue.setEndLabel(end);
LabelNode[][] jumps = new LabelNode[token.getCases().size() + 1][2];
int i = 0;
for (CaseStmtToken one : token.getCases()) {
// checkLabel, bodyLabel
jumps[i] = new LabelNode[] { new LabelNode(), new LabelNode() };
if (i == jumps.length - 1)
jumps[i] = new LabelNode[] { end, end };
i++;
}
jumps[jumps.length - 1] = new LabelNode[] { end, end };
method.pushJump(end, end);
expr.writeExpression(token.getValue(), true, false);
expr.writePopBoxing();
expr.writeVarStore(switchValue, false, false);
i = 0;
for (CaseStmtToken one : token.getCases()) {
// conditional
add(jumps[i][0]);
if (one.getConditional() != null) {
expr.writeVarLoad(switchValue);
expr.writeExpression(one.getConditional(), true, false);
expr.writeSysDynamicCall(Memory.class, "equal", Boolean.TYPE, expr.stackPeek().type.toClass());
add(new JumpInsnNode(IFEQ, jumps[i + 1][0]));
expr.stackPop();
}
// if is done...
add(new JumpInsnNode(GOTO, jumps[i][1]));
i++;
}
i = 0;
for (CaseStmtToken one : token.getCases()) {
add(jumps[i][1]);
expr.writeDefineVariables(one.getLocals());
expr.write(BodyStmtToken.class, one.getBody());
i++;
expr.writeUndefineVariables(one.getLocals());
}
method.popJump();
add(end);
add(new LineNumberNode(token.getMeta().getEndLine(), end));
method.prevStatementIndex(Memory.class);
expr.writeUndefineVariables(token.getLocal());
}
Aggregations