Example usage for org.objectweb.asm Label Label

List of usage examples for org.objectweb.asm Label Label

Introduction

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

Prototype

public Label() 

Source Link

Document

Constructs a new label.

Usage

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

License:Apache License

/**
 * Creates bytecode for evaluating this left function. The specified method visitor
 * and type are used for generating bytecode.
 * // w w  w. ja  v a2  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.visitLdcInsn(0);
    value2.compile(visitor, Type.INT);
    visitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "substring", "(II)Ljava/lang/String;");
    visitor.visitJumpInsn(Opcodes.GOTO, notNullLabel);

    visitor.visitLabel(nullLabel);
    visitor.visitInsn(Opcodes.ACONST_NULL);

    visitor.visitLabel(notNullLabel);
}

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 w w  w. jav  a2s.  c o  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  .  co 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.
 * //from   ww w .j  ava 2s  .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 ava  2s  . c om*/
 * @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  ww  w . j a v  a 2s. 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.
 * /*  w ww  .  j  av 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_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.
 * //from w  ww .j  a  v  a 2s . 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.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.
 * //w w  w.  java 2  s.c  o  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_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.
 * /*from  w ww .ja  v a2  s .c o  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);
}