Example usage for org.objectweb.asm MethodVisitor visitJumpInsn

List of usage examples for org.objectweb.asm MethodVisitor visitJumpInsn

Introduction

In this page you can find the example usage for org.objectweb.asm MethodVisitor visitJumpInsn.

Prototype

public void visitJumpInsn(final int opcode, final Label label) 

Source Link

Document

Visits a jump instruction.

Usage

From source file:com.nginious.http.xsp.expr.LengthFunction.java

License:Apache License

/**
 * Creates bytecode for evaluating this function. The specified method
 * visitor is used to generate bytecode. The generated bytecode produces
 * a result of the specified type./*from   ww w  . j  ava  2 s .co m*/
 * 
 * @param visitor the method visitor
 * @param type the type
 */
void compile(MethodVisitor visitor, Type type) {
    value.compile(visitor, Type.STRING);
    visitor.visitVarInsn(Opcodes.ASTORE, 1);

    Label nullLabel = new Label();
    Label notNullLabel = new Label();

    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel);

    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "length", "()I");
    visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel);

    visitor.visitLabel(nullLabel);
    visitor.visitLdcInsn(0);

    visitor.visitLabel(notNullLabel);
}

From source file:com.nginious.http.xsp.expr.LessEqualsOperator.java

License:Apache License

/**
 * Creates bytecode for evaluating the argument values as integers. The bytecode
 * is generated using the specified method visitor.
 * /*from   w  ww. j  a  va2  s .  c  o  m*/
 * @param visitor the method visitor
 */
private void compileInt(MethodVisitor visitor) {
    Label labelFalse = new Label();
    Label labelEnd = new Label();

    value2.compile(visitor, Type.INT);
    value1.compile(visitor, Type.INT);

    visitor.visitJumpInsn(Opcodes.IF_ICMPLT, labelFalse);

    // True
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, labelEnd);

    // False
    visitor.visitLabel(labelFalse);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(labelEnd);
}

From source file:com.nginious.http.xsp.expr.LessEqualsOperator.java

License:Apache License

/**
 * Creates bytecode for evaluating the argument values as doubles. The bytecode
 * is generated using the specified method visitor.
 * /* w  w  w . jav a 2  s  .  c om*/
 * @param visitor the method visitor
 */
private void compileDouble(MethodVisitor visitor) {
    Label labelFalse = new Label();
    Label labelEnd = new Label();

    value2.compile(visitor, Type.DOUBLE);
    value1.compile(visitor, Type.DOUBLE);

    visitor.visitInsn(Opcodes.DCMPL);
    visitor.visitJumpInsn(Opcodes.IFLT, labelFalse);

    // True
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, labelEnd);

    // False
    visitor.visitLabel(labelFalse);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(labelEnd);
}

From source file:com.nginious.http.xsp.expr.LessOperator.java

License:Apache License

/**
 * Creates bytecode for evaluating the argument values as integers. The bytecode
 * is generated using the specified method visitor.
 * //from ww  w . j  ava2s . com
 * @param visitor the method visitor
 */
private void compileInt(MethodVisitor visitor) {
    Label labelFalse = new Label();
    Label labelEnd = new Label();

    value2.compile(visitor, Type.INT);
    value1.compile(visitor, Type.INT);

    visitor.visitJumpInsn(Opcodes.IF_ICMPLE, labelFalse);

    // True
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, labelEnd);

    // False
    visitor.visitLabel(labelFalse);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(labelEnd);
}

From source file:com.nginious.http.xsp.expr.LessOperator.java

License:Apache License

/**
 * Creates bytecode for evaluating the argument values as doubles. The bytecode
 * is generated using the specified method visitor.
 * /*from w  ww. jav  a2 s.c  o m*/
 * @param visitor the method visitor
 */
private void compileDouble(MethodVisitor visitor) {
    Label labelFalse = new Label();
    Label labelEnd = new Label();

    value2.compile(visitor, Type.DOUBLE);
    value1.compile(visitor, Type.DOUBLE);

    visitor.visitInsn(Opcodes.DCMPL);
    visitor.visitJumpInsn(Opcodes.IFLE, labelFalse);

    // True
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, labelEnd);

    // False
    visitor.visitLabel(labelFalse);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(labelEnd);
}

From source file:com.nginious.http.xsp.expr.MoreEqualsOperator.java

License:Apache License

/**
 * Creates bytecode for evaluating the argument values as integers. The bytecode
 * is generated using the specified method visitor.
 * /*from w  w w.  j  a  va  2  s . co m*/
 * @param visitor the method visitor
 */
private void compileInt(MethodVisitor visitor) {
    Label labelFalse = new Label();
    Label labelEnd = new Label();

    value1.compile(visitor, Type.INT);
    value2.compile(visitor, Type.INT);

    visitor.visitJumpInsn(Opcodes.IF_ICMPLT, labelFalse);

    // True
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, labelEnd);

    // False
    visitor.visitLabel(labelFalse);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(labelEnd);
}

From source file:com.nginious.http.xsp.expr.MoreEqualsOperator.java

License:Apache License

/**
 * Creates bytecode for evaluating the argument values as doubles. The bytecode
 * is generated using the specified method visitor.
 * //w  w w  .j  av a 2s . c om
 * @param visitor the method visitor
 */
private void compileDouble(MethodVisitor visitor) {
    Label labelFalse = new Label();
    Label labelEnd = new Label();

    value1.compile(visitor, Type.DOUBLE);
    value2.compile(visitor, Type.DOUBLE);

    visitor.visitInsn(Opcodes.DCMPL);
    visitor.visitJumpInsn(Opcodes.IFLT, labelFalse);

    // True
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, labelEnd);

    // False
    visitor.visitLabel(labelFalse);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(labelEnd);
}

From source file:com.nginious.http.xsp.expr.MoreOperator.java

License:Apache License

/**
 * Creates bytecode for evaluating the argument values as integers. The bytecode
 * is generated using the specified method visitor.
 * /*ww  w . j a v a 2  s.c om*/
 * @param visitor the method visitor
 */
private void compileInt(MethodVisitor visitor) {
    Label labelFalse = new Label();
    Label labelEnd = new Label();

    value1.compile(visitor, Type.INT);
    value2.compile(visitor, Type.INT);

    visitor.visitJumpInsn(Opcodes.IF_ICMPLE, labelFalse);

    // True
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, labelEnd);

    // False
    visitor.visitLabel(labelFalse);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(labelEnd);
}

From source file:com.nginious.http.xsp.expr.MoreOperator.java

License:Apache License

/**
 * Creates bytecode for evaluating the argument values as doubles. The bytecode
 * is generated using the specified method visitor.
 * // w w w  .j  av a2s  . co  m
 * @param visitor the method visitor
 */
private void compileDouble(MethodVisitor visitor) {
    Label labelFalse = new Label();
    Label labelEnd = new Label();

    value1.compile(visitor, Type.DOUBLE);
    value2.compile(visitor, Type.DOUBLE);

    visitor.visitInsn(Opcodes.DCMPL);
    visitor.visitJumpInsn(Opcodes.IFLE, labelFalse);

    // True
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, labelEnd);

    // False
    visitor.visitLabel(labelFalse);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(labelEnd);
}

From source file:com.nginious.http.xsp.expr.NotEqualsOperator.java

License:Apache License

/**
 * Compiles bytecode for evaluating this not equals operator producing
 * a string as result. The specified method visitor is used for generating
 * bytecode./*from   w  ww.ja va  2  s .com*/
 * 
 * @param visitor the method visitor
 */
private void compileString(MethodVisitor visitor) {
    Label trueLabel = new Label();
    Label falseLabel = new Label();
    Label nullLabel = new Label();

    value1.compile(visitor, Type.STRING);
    visitor.visitVarInsn(Opcodes.ASTORE, 1);
    value2.compile(visitor, Type.STRING);
    visitor.visitVarInsn(Opcodes.ASTORE, 2);

    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel);
    visitor.visitVarInsn(Opcodes.ALOAD, 2);
    visitor.visitJumpInsn(Opcodes.IFNULL, nullLabel);

    visitor.visitVarInsn(Opcodes.ALOAD, 1);
    visitor.visitVarInsn(Opcodes.ALOAD, 2);
    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z");
    visitor.visitJumpInsn(Opcodes.IFNE, falseLabel);

    visitor.visitLabel(nullLabel);
    visitor.visitLdcInsn(true);
    visitor.visitJumpInsn(Opcodes.GOTO, trueLabel);

    visitor.visitLabel(falseLabel);
    visitor.visitLdcInsn(false);

    visitor.visitLabel(trueLabel);
}