Search in sources :

Example 6 with Operation

use of org.elasticsearch.painless.Operation in project elasticsearch by elastic.

the class Walker method visitPost.

@Override
public ANode visitPost(PostContext ctx) {
    AExpression expression = (AExpression) visit(ctx.chain());
    final Operation operation;
    if (ctx.INCR() != null) {
        operation = Operation.INCR;
    } else if (ctx.DECR() != null) {
        operation = Operation.DECR;
    } else {
        throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
    }
    return new EAssignment(location(ctx), expression, null, false, true, operation);
}
Also used : EAssignment(org.elasticsearch.painless.node.EAssignment) AExpression(org.elasticsearch.painless.node.AExpression) Operation(org.elasticsearch.painless.Operation)

Example 7 with Operation

use of org.elasticsearch.painless.Operation in project elasticsearch by elastic.

the class Walker method visitAssignment.

@Override
public ANode visitAssignment(AssignmentContext ctx) {
    AExpression lhs = (AExpression) visit(ctx.expression(0));
    AExpression rhs = (AExpression) visit(ctx.expression(1));
    final Operation operation;
    if (ctx.ASSIGN() != null) {
        operation = null;
    } else if (ctx.AMUL() != null) {
        operation = Operation.MUL;
    } else if (ctx.ADIV() != null) {
        operation = Operation.DIV;
    } else if (ctx.AREM() != null) {
        operation = Operation.REM;
    } else if (ctx.AADD() != null) {
        operation = Operation.ADD;
    } else if (ctx.ASUB() != null) {
        operation = Operation.SUB;
    } else if (ctx.ALSH() != null) {
        operation = Operation.LSH;
    } else if (ctx.ARSH() != null) {
        operation = Operation.RSH;
    } else if (ctx.AUSH() != null) {
        operation = Operation.USH;
    } else if (ctx.AAND() != null) {
        operation = Operation.BWAND;
    } else if (ctx.AXOR() != null) {
        operation = Operation.XOR;
    } else if (ctx.AOR() != null) {
        operation = Operation.BWOR;
    } else {
        throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
    }
    return new EAssignment(location(ctx), lhs, rhs, false, false, operation);
}
Also used : EAssignment(org.elasticsearch.painless.node.EAssignment) AExpression(org.elasticsearch.painless.node.AExpression) Operation(org.elasticsearch.painless.Operation)

Aggregations

Operation (org.elasticsearch.painless.Operation)7 AExpression (org.elasticsearch.painless.node.AExpression)7 EAssignment (org.elasticsearch.painless.node.EAssignment)3 DynamicContext (org.elasticsearch.painless.antlr.PainlessParser.DynamicContext)1 NumericContext (org.elasticsearch.painless.antlr.PainlessParser.NumericContext)1 ReadContext (org.elasticsearch.painless.antlr.PainlessParser.ReadContext)1 EBinary (org.elasticsearch.painless.node.EBinary)1 EBool (org.elasticsearch.painless.node.EBool)1 EComp (org.elasticsearch.painless.node.EComp)1 EUnary (org.elasticsearch.painless.node.EUnary)1