Example usage for org.objectweb.asm.commons GeneratorAdapter NEG

List of usage examples for org.objectweb.asm.commons GeneratorAdapter NEG

Introduction

In this page you can find the example usage for org.objectweb.asm.commons GeneratorAdapter NEG.

Prototype

int NEG

To view the source code for org.objectweb.asm.commons GeneratorAdapter NEG.

Click Source Link

Document

Constant for the #math method.

Usage

From source file:io.datakernel.codegen.ExpressionNeg.java

License:Apache License

@Override
public Type load(Context ctx) {
    GeneratorAdapter g = ctx.getGeneratorAdapter();
    int sort = arg.type(ctx).getSort();
    arg.load(ctx);//ww w  .j  a va 2s. c o  m

    if (sort == Type.DOUBLE || sort == Type.FLOAT || sort == Type.LONG || sort == Type.INT) {
        g.math(GeneratorAdapter.NEG, arg.type(ctx));
        return arg.type(ctx);
    }
    if (sort == Type.BYTE || sort == Type.SHORT || sort == Type.CHAR) {
        g.cast(arg.type(ctx), INT_TYPE);
        g.math(GeneratorAdapter.NEG, INT_TYPE);
        return arg.type(ctx);
    }

    if (sort == Type.BOOLEAN) {
        Label labelTrue = new Label();
        Label labelExit = new Label();
        g.push(true);
        g.ifCmp(BOOLEAN_TYPE, GeneratorAdapter.EQ, labelTrue);
        g.push(true);
        g.goTo(labelExit);

        g.mark(labelTrue);
        g.push(false);

        g.mark(labelExit);
        return INT_TYPE;
    }

    throw new RuntimeException(format("%s is not primitive. %s",
            getJavaType(ctx.getClassLoader(), arg.type(ctx)), exceptionInGeneratedClass(ctx)));
}

From source file:org.elasticsearch.painless.Writer.java

License:Apache License

@Override
public Void visitUnary(final UnaryContext ctx) {
    final Metadata.ExpressionMetadata unaryemd = metadata.getExpressionMetadata(ctx);
    final Object postConst = unaryemd.postConst;
    final Object preConst = unaryemd.preConst;
    final Branch branch = getBranch(ctx);

    if (postConst != null) {
        if (ctx.BOOLNOT() != null) {
            if (branch == null) {
                writeConstant(ctx, postConst);
            } else {
                if ((boolean) postConst && branch.tru != null) {
                    execute.goTo(branch.tru);
                } else if (!(boolean) postConst && branch.fals != null) {
                    execute.goTo(branch.fals);
                }/*from w  w  w.  ja  v a2 s  .co  m*/
            }
        } else {
            writeConstant(ctx, postConst);
            checkWriteBranch(ctx);
        }
    } else if (preConst != null) {
        if (branch == null) {
            writeConstant(ctx, preConst);
            checkWriteCast(unaryemd);
        } else {
            throw new IllegalStateException(Metadata.error(ctx) + "Unexpected writer state.");
        }
    } else {
        final ExpressionContext exprctx = ctx.expression();

        if (ctx.BOOLNOT() != null) {
            final Branch local = markBranch(ctx, exprctx);

            if (branch == null) {
                local.fals = new Label();
                final Label aend = new Label();

                visit(exprctx);

                execute.push(false);
                execute.goTo(aend);
                execute.mark(local.fals);
                execute.push(true);
                execute.mark(aend);

                checkWriteCast(unaryemd);
            } else {
                local.tru = branch.fals;
                local.fals = branch.tru;

                visit(exprctx);
            }
        } else {
            final org.objectweb.asm.Type type = unaryemd.from.type;
            final Sort sort = unaryemd.from.sort;

            visit(exprctx);

            if (ctx.BWNOT() != null) {
                if (sort == Sort.DEF) {
                    execute.invokeStatic(definition.defobjType.type, DEF_NOT_CALL);
                } else {
                    if (sort == Sort.INT) {
                        writeConstant(ctx, -1);
                    } else if (sort == Sort.LONG) {
                        writeConstant(ctx, -1L);
                    } else {
                        throw new IllegalStateException(Metadata.error(ctx) + "Unexpected writer state.");
                    }

                    execute.math(GeneratorAdapter.XOR, type);
                }
            } else if (ctx.SUB() != null) {
                if (sort == Sort.DEF) {
                    execute.invokeStatic(definition.defobjType.type, DEF_NEG_CALL);
                } else {
                    if (settings.getNumericOverflow()) {
                        execute.math(GeneratorAdapter.NEG, type);
                    } else {
                        if (sort == Sort.INT) {
                            execute.invokeStatic(definition.mathType.type, NEGATEEXACT_INT);
                        } else if (sort == Sort.LONG) {
                            execute.invokeStatic(definition.mathType.type, NEGATEEXACT_LONG);
                        } else {
                            throw new IllegalStateException(Metadata.error(ctx) + "Unexpected writer state.");
                        }
                    }
                }
            } else if (ctx.ADD() == null) {
                throw new IllegalStateException(Metadata.error(ctx) + "Unexpected writer state.");
            }

            checkWriteCast(unaryemd);
            checkWriteBranch(ctx);
        }
    }

    return null;
}

From source file:org.elasticsearch.painless.WriterExpression.java

License:Apache License

void processUnary(final UnaryContext ctx) {
    final ExpressionMetadata unaryemd = metadata.getExpressionMetadata(ctx);
    final Object postConst = unaryemd.postConst;
    final Object preConst = unaryemd.preConst;
    final Branch branch = utility.getBranch(ctx);

    if (postConst != null) {
        if (ctx.BOOLNOT() != null) {
            if (branch == null) {
                utility.writeConstant(ctx, postConst);
            } else {
                if ((boolean) postConst && branch.tru != null) {
                    execute.goTo(branch.tru);
                } else if (!(boolean) postConst && branch.fals != null) {
                    execute.goTo(branch.fals);
                }/*from   www. j a va  2 s.  co  m*/
            }
        } else {
            utility.writeConstant(ctx, postConst);
            utility.checkWriteBranch(ctx);
        }
    } else if (preConst != null) {
        if (branch == null) {
            utility.writeConstant(ctx, preConst);
            caster.checkWriteCast(unaryemd);
        } else {
            throw new IllegalStateException(WriterUtility.error(ctx) + "Unexpected state.");
        }
    } else {
        final ExpressionContext exprctx = ctx.expression();

        if (ctx.BOOLNOT() != null) {
            final Branch local = utility.markBranch(ctx, exprctx);

            if (branch == null) {
                local.fals = new Label();
                final Label aend = new Label();

                writer.visit(exprctx);

                execute.push(false);
                execute.goTo(aend);
                execute.mark(local.fals);
                execute.push(true);
                execute.mark(aend);

                caster.checkWriteCast(unaryemd);
            } else {
                local.tru = branch.fals;
                local.fals = branch.tru;

                writer.visit(exprctx);
            }
        } else {
            final org.objectweb.asm.Type type = unaryemd.from.type;
            final Sort sort = unaryemd.from.sort;

            writer.visit(exprctx);

            if (ctx.BWNOT() != null) {
                if (sort == Sort.DEF) {
                    execute.invokeStatic(definition.defobjType.type, DEF_NOT_CALL);
                } else {
                    if (sort == Sort.INT) {
                        utility.writeConstant(ctx, -1);
                    } else if (sort == Sort.LONG) {
                        utility.writeConstant(ctx, -1L);
                    } else {
                        throw new IllegalStateException(WriterUtility.error(ctx) + "Unexpected state.");
                    }

                    execute.math(GeneratorAdapter.XOR, type);
                }
            } else if (ctx.SUB() != null) {
                if (sort == Sort.DEF) {
                    execute.invokeStatic(definition.defobjType.type, DEF_NEG_CALL);
                } else {
                    if (settings.getNumericOverflow()) {
                        execute.math(GeneratorAdapter.NEG, type);
                    } else {
                        if (sort == Sort.INT) {
                            execute.invokeStatic(definition.mathType.type, NEGATEEXACT_INT);
                        } else if (sort == Sort.LONG) {
                            execute.invokeStatic(definition.mathType.type, NEGATEEXACT_LONG);
                        } else {
                            throw new IllegalStateException(WriterUtility.error(ctx) + "Unexpected state.");
                        }
                    }
                }
            } else if (ctx.ADD() == null) {
                throw new IllegalStateException(WriterUtility.error(ctx) + "Unexpected state.");
            }

            caster.checkWriteCast(unaryemd);
            utility.checkWriteBranch(ctx);
        }
    }
}

From source file:org.elasticsearch.plan.a.Writer.java

License:Apache License

@Override
public Void visitUnary(final UnaryContext ctx) {
    final ExpressionMetadata unaryemd = metadata.getExpressionMetadata(ctx);
    final Object postConst = unaryemd.postConst;
    final Object preConst = unaryemd.preConst;
    final Branch branch = getBranch(ctx);

    if (postConst != null) {
        if (ctx.BOOLNOT() != null) {
            if (branch == null) {
                writeConstant(ctx, postConst);
            } else {
                if ((boolean) postConst && branch.tru != null) {
                    execute.goTo(branch.tru);
                } else if (!(boolean) postConst && branch.fals != null) {
                    execute.goTo(branch.fals);
                }//from w  w  w .  j ava  2s . c o  m
            }
        } else {
            writeConstant(ctx, postConst);
            checkWriteBranch(ctx);
        }
    } else if (preConst != null) {
        if (branch == null) {
            writeConstant(ctx, preConst);
            checkWriteCast(unaryemd);
        } else {
            throw new IllegalStateException(error(ctx) + "Unexpected writer state.");
        }
    } else {
        final ExpressionContext exprctx = ctx.expression();

        if (ctx.BOOLNOT() != null) {
            final Branch local = markBranch(ctx, exprctx);

            if (branch == null) {
                local.fals = new Label();
                final Label aend = new Label();

                visit(exprctx);

                execute.push(false);
                execute.goTo(aend);
                execute.mark(local.fals);
                execute.push(true);
                execute.mark(aend);

                checkWriteCast(unaryemd);
            } else {
                local.tru = branch.fals;
                local.fals = branch.tru;

                visit(exprctx);
            }
        } else {
            final org.objectweb.asm.Type type = unaryemd.from.type;
            final Sort sort = unaryemd.from.sort;

            visit(exprctx);

            if (ctx.BWNOT() != null) {
                if (sort == Sort.DEF) {
                    execute.invokeStatic(definition.defobjType.type, DEF_NOT_CALL);
                } else {
                    if (sort == Sort.INT) {
                        writeConstant(ctx, -1);
                    } else if (sort == Sort.LONG) {
                        writeConstant(ctx, -1L);
                    } else {
                        throw new IllegalStateException(error(ctx) + "Unexpected writer state.");
                    }

                    execute.math(GeneratorAdapter.XOR, type);
                }
            } else if (ctx.SUB() != null) {
                if (sort == Sort.DEF) {
                    execute.invokeStatic(definition.defobjType.type, DEF_NEG_CALL);
                } else {
                    if (settings.getNumericOverflow()) {
                        execute.math(GeneratorAdapter.NEG, type);
                    } else {
                        if (sort == Sort.INT) {
                            execute.invokeStatic(definition.mathType.type, NEGATEEXACT_INT);
                        } else if (sort == Sort.LONG) {
                            execute.invokeStatic(definition.mathType.type, NEGATEEXACT_LONG);
                        } else {
                            throw new IllegalStateException(error(ctx) + "Unexpected writer state.");
                        }
                    }
                }
            } else if (ctx.ADD() == null) {
                throw new IllegalStateException(error(ctx) + "Unexpected writer state.");
            }

            checkWriteCast(unaryemd);
            checkWriteBranch(ctx);
        }
    }

    return null;
}