Example usage for org.objectweb.asm Opcodes GOTO

List of usage examples for org.objectweb.asm Opcodes GOTO

Introduction

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

Prototype

int GOTO

To view the source code for org.objectweb.asm Opcodes GOTO.

Click Source Link

Usage

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java

@Override
public BytecodeExpression coalesce(Location loc, final List<BytecodeExpression> inputs) {
    List<TypeWidget> widgets = Lists.newArrayList();
    for (BytecodeExpression expr : inputs) {
        widgets.add(expr.getType());/*from w  w  w .j  av  a2  s. c o  m*/
    }
    TypeWidget output = unify(widgets);
    return new BaseTypeExpression(output) {
        @Override
        public void generate(CodeEmitter code) {
            Label done = new Label();
            MethodVisitor mv = code.getMethodVisitor();
            boolean lastNullable = true;
            for (BytecodeExpression expr : inputs) {
                Label isNull = new Label();
                code.exec(expr);
                if (code.cast(getType(), expr.getType(), isNull)) {
                    mv.visitJumpInsn(Opcodes.GOTO, done);
                    mv.visitLabel(isNull);
                } else {
                    lastNullable = false;
                    break;
                }
            }
            if (lastNullable) {
                mv.visitInsn(Opcodes.ACONST_NULL);
            }
            mv.visitLabel(done);
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java

@Override
public BytecodeExpression matches(Location loc, final BytecodeExpression left, final BytecodeExpression right) {
    return new BaseTypeExpression(BaseTypeAdapter.BOOLEAN) {
        @Override/*  w w  w.java  2 s.co m*/
        public void generate(CodeEmitter code) {
            Label done = new Label();
            Label anyIsNull = new Label();
            CodeEmitter.BinaryCoercion coerce = code.binaryCoercion(right, Pattern.class, left,
                    CharSequence.class, anyIsNull, anyIsNull, anyIsNull);
            MethodVisitor mv = code.getMethodVisitor();
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Pattern.class), "matcher",
                    Type.getMethodDescriptor(Type.getType(Matcher.class), Type.getType(CharSequence.class)),
                    false);
            mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Matcher.class), "matches",
                    Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false);
            if (coerce.leftNullable || coerce.rightNullable) {
                mv.visitJumpInsn(Opcodes.GOTO, done);
                mv.visitLabel(anyIsNull);
                mv.visitInsn(Opcodes.ICONST_0);
                mv.visitLabel(done);
            }
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java

@Override
public BytecodeExpression in(Location loc, final BytecodeExpression left, final BytecodeExpression right) {
    return new BaseTypeExpression(BaseTypeAdapter.BOOLEAN) {
        @Override//from ww  w  .jav a2  s.com
        public void generate(CodeEmitter code) {
            Label done = new Label();
            Label anyIsNull = new Label();
            CodeEmitter.BinaryCoercion coerce = code.binaryCoercion(right, Collection.class, left, Object.class,
                    anyIsNull, anyIsNull, anyIsNull);
            MethodVisitor mv = code.getMethodVisitor();
            mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Collection.class), "contains",
                    Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)), true);
            if (coerce.leftNullable || coerce.rightNullable) {
                mv.visitJumpInsn(Opcodes.GOTO, done);
                mv.visitLabel(anyIsNull);
                mv.visitInsn(Opcodes.ICONST_0);
                mv.visitLabel(done);
            }
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java

@Override
public BytecodeExpression guarded(final BytecodeExpression target, final BytecodeExpression ifTargetIsNotNull,
        final BytecodeExpression ifTargetIsNull) {
    if (!target.getType().isNullable()) {
        return ifTargetIsNotNull;
    }//from   w  w  w  .  j a va2  s . co m
    return new BaseTypeExpression(unify(ifTargetIsNotNull.getType(), ifTargetIsNull.getType())) {
        @Override
        public void generate(CodeEmitter code) {
            final MethodVisitor mv = code.getMethodVisitor();
            Label isNull = new Label();
            Label done = new Label();
            code.exec(target);
            code.nullTest(target.getType(), isNull);
            code.pop(target.getType());
            code.exec(ifTargetIsNotNull);
            code.cast(getType(), ifTargetIsNotNull.getType(), isNull);
            mv.visitJumpInsn(Opcodes.GOTO, done);
            mv.visitLabel(isNull);
            code.exec(ifTargetIsNull);
            code.cast(getType(), ifTargetIsNull.getType());
            mv.visitLabel(done);
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.ExpressionHandler.java

@Override
public BytecodeExpression fallback(Location loc, final BytecodeExpression primary,
        final BytecodeExpression caught) {
    TypeWidget unified = unify(primary.getType(), caught.getType());
    return new BaseTypeExpression(unified) {
        @Override//from ww w.  ja v a 2  s  .c om
        public void generate(CodeEmitter code) {
            MethodVisitor mv = code.getMethodVisitor();
            final Label start = new Label();
            final Label endCatch = new Label();
            final Label handler = new Label();
            Label done = new Label();
            // this probably should not be catching throwable and instead should be catching Exception
            // or permit certain Errors through only
            mv.visitTryCatchBlock(start, endCatch, handler, "java/lang/Throwable");
            mv.visitLabel(start);
            code.exec(primary);
            Label isNull = new Label();
            boolean maybeNull = code.cast(getType(), primary.getType(), isNull);
            mv.visitJumpInsn(Opcodes.GOTO, done);
            mv.visitLabel(endCatch);
            mv.visitLabel(handler);
            mv.visitInsn(Opcodes.POP);
            if (maybeNull) {
                mv.visitLabel(isNull);
            }
            code.exec(caught);
            code.cast(getType(), caught.getType());
            mv.visitLabel(done);
        }
    };
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.IfAdapter.java

@Override
public ScopedBuilder when(final BytecodeExpression test) {
    final TypeWidget type = test.getType();
    final Label isFalse = new Label();
    body.add(new BytecodeSequence() {
        @Override//  www .  j  av  a 2 s  . c  om
        public void generate(CodeEmitter code) {
            code.exec(test);
            Label isTrue = new Label();
            type.getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse);
            MethodVisitor mv = code.getMethodVisitor();
            mv.visitLabel(isTrue);
        }
    });
    Clause block = new Clause(source, body.block());
    body.add(new BytecodeSequence() {
        @Override
        public void generate(CodeEmitter code) {
            MethodVisitor mv = code.getMethodVisitor();
            mv.visitJumpInsn(Opcodes.GOTO, end);
            mv.visitLabel(isFalse);
        }
    });
    return block;
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.LoopAdapter.java

public LoopAdapter(ASMClassSource source, LocalCodeChunk parent, final BytecodeExpression test,
        BytecodeExpression result) {//from  w w w  . ja  va 2  s  .c  om
    super(source);
    this.body = parent.child();
    this.result = result;
    next = body.getStart();
    body.add(new BytecodeSequence() {
        @Override
        public void generate(CodeEmitter code) {
            abort(test);
        }
    });
    LocalCodeChunk child = body.block();
    body.add(new BytecodeSequence() {
        @Override
        public void generate(CodeEmitter code) {
            code.getMethodVisitor().visitJumpInsn(Opcodes.GOTO, body.getStart());
        }
    });
    body = child;
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.LoopAdapter.java

@Override
public void abort(final BytecodeExpression test) {
    final TypeWidget type = test.getType();
    body.add(new BytecodeSequence() {
        @Override//w ww .  j a v  a  2  s . c o  m
        public void generate(CodeEmitter code) {
            code.exec(test);
            Label isTrue = new Label();
            Label isFalse = new Label();
            type.getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse);
            MethodVisitor mv = code.getMethodVisitor();
            mv.visitLabel(isTrue);
            code.exec(result);
            mv.visitJumpInsn(Opcodes.GOTO, body.getEnd());
            mv.visitLabel(isFalse);
        }
    });
}

From source file:com.yahoo.yqlplus.engine.internal.bytecode.types.gambit.LoopAdapter.java

@Override
public void next(final BytecodeExpression test) {
    final TypeWidget type = test.getType();
    body.add(new BytecodeSequence() {
        @Override//from w ww.j  ava2  s.  c om
        public void generate(CodeEmitter code) {
            code.exec(test);
            Label isTrue = new Label();
            Label isFalse = new Label();
            type.getComparisionAdapter().coerceBoolean(code, isTrue, isFalse, isFalse);
            MethodVisitor mv = code.getMethodVisitor();
            mv.visitLabel(isTrue);
            code.exec(result);
            mv.visitJumpInsn(Opcodes.GOTO, next);
            mv.visitLabel(isFalse);
        }
    });

}

From source file:com.yahoo.yqlplus.engine.internal.compiler.BooleanCompareExpression.java

@Override
public void generate(CodeEmitter code) {
    code.exec(new CompareExpression(loc, leftExpr, rightExpr));
    MethodVisitor mv = code.getMethodVisitor();
    Label isTrue = new Label();
    Label done = new Label();
    switch (booleanComparison) {
    case LT://w w w .  j a  v a2 s .co m
        mv.visitJumpInsn(Opcodes.IFLT, isTrue);
        break;
    case LTEQ:
        mv.visitJumpInsn(Opcodes.IFLE, isTrue);
        break;
    case GT:
        mv.visitJumpInsn(Opcodes.IFGT, isTrue);
        break;
    case GTEQ:
        mv.visitJumpInsn(Opcodes.IFGE, isTrue);
        break;
    }
    code.emitBooleanConstant(false);
    mv.visitJumpInsn(Opcodes.GOTO, done);
    mv.visitLabel(isTrue);
    code.emitBooleanConstant(true);
    mv.visitLabel(done);
}