Search in sources :

Example 1 with Operation

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

the class Walker method visitBool.

@Override
public ANode visitBool(BoolContext ctx) {
    AExpression left = (AExpression) visit(ctx.expression(0));
    AExpression right = (AExpression) visit(ctx.expression(1));
    final Operation operation;
    if (ctx.BOOLAND() != null) {
        operation = Operation.AND;
    } else if (ctx.BOOLOR() != null) {
        operation = Operation.OR;
    } else {
        throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
    }
    return new EBool(location(ctx), operation, left, right);
}
Also used : EBool(org.elasticsearch.painless.node.EBool) AExpression(org.elasticsearch.painless.node.AExpression) Operation(org.elasticsearch.painless.Operation)

Example 2 with Operation

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

the class Walker method visitComp.

@Override
public ANode visitComp(CompContext ctx) {
    AExpression left = (AExpression) visit(ctx.expression(0));
    AExpression right = (AExpression) visit(ctx.expression(1));
    final Operation operation;
    if (ctx.LT() != null) {
        operation = Operation.LT;
    } else if (ctx.LTE() != null) {
        operation = Operation.LTE;
    } else if (ctx.GT() != null) {
        operation = Operation.GT;
    } else if (ctx.GTE() != null) {
        operation = Operation.GTE;
    } else if (ctx.EQ() != null) {
        operation = Operation.EQ;
    } else if (ctx.EQR() != null) {
        operation = Operation.EQR;
    } else if (ctx.NE() != null) {
        operation = Operation.NE;
    } else if (ctx.NER() != null) {
        operation = Operation.NER;
    } else {
        throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
    }
    return new EComp(location(ctx), operation, left, right);
}
Also used : AExpression(org.elasticsearch.painless.node.AExpression) EComp(org.elasticsearch.painless.node.EComp) Operation(org.elasticsearch.painless.Operation)

Example 3 with Operation

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

the class Walker method visitOperator.

@Override
public ANode visitOperator(OperatorContext ctx) {
    AExpression expression = (AExpression) visit(ctx.unary());
    final Operation operation;
    if (ctx.BOOLNOT() != null) {
        operation = Operation.NOT;
    } else if (ctx.BWNOT() != null) {
        operation = Operation.BWNOT;
    } else if (ctx.ADD() != null) {
        operation = Operation.ADD;
    } else if (ctx.SUB() != null) {
        if (ctx.unary() instanceof ReadContext && ((ReadContext) ctx.unary()).chain() instanceof DynamicContext && ((DynamicContext) ((ReadContext) ctx.unary()).chain()).primary() instanceof NumericContext && ((DynamicContext) ((ReadContext) ctx.unary()).chain()).postfix().isEmpty()) {
            return expression;
        }
        operation = Operation.SUB;
    } else {
        throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
    }
    return new EUnary(location(ctx), operation, expression);
}
Also used : EUnary(org.elasticsearch.painless.node.EUnary) AExpression(org.elasticsearch.painless.node.AExpression) ReadContext(org.elasticsearch.painless.antlr.PainlessParser.ReadContext) Operation(org.elasticsearch.painless.Operation) DynamicContext(org.elasticsearch.painless.antlr.PainlessParser.DynamicContext) NumericContext(org.elasticsearch.painless.antlr.PainlessParser.NumericContext)

Example 4 with Operation

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

the class Walker method visitPre.

@Override
public ANode visitPre(PreContext 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, true, false, operation);
}
Also used : EAssignment(org.elasticsearch.painless.node.EAssignment) AExpression(org.elasticsearch.painless.node.AExpression) Operation(org.elasticsearch.painless.Operation)

Example 5 with Operation

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

the class Walker method visitBinary.

@Override
public ANode visitBinary(BinaryContext ctx) {
    AExpression left = (AExpression) visit(ctx.expression(0));
    AExpression right = (AExpression) visit(ctx.expression(1));
    final Operation operation;
    if (ctx.MUL() != null) {
        operation = Operation.MUL;
    } else if (ctx.DIV() != null) {
        operation = Operation.DIV;
    } else if (ctx.REM() != null) {
        operation = Operation.REM;
    } else if (ctx.ADD() != null) {
        operation = Operation.ADD;
    } else if (ctx.SUB() != null) {
        operation = Operation.SUB;
    } else if (ctx.FIND() != null) {
        operation = Operation.FIND;
    } else if (ctx.MATCH() != null) {
        operation = Operation.MATCH;
    } else if (ctx.LSH() != null) {
        operation = Operation.LSH;
    } else if (ctx.RSH() != null) {
        operation = Operation.RSH;
    } else if (ctx.USH() != null) {
        operation = Operation.USH;
    } else if (ctx.BWAND() != null) {
        operation = Operation.BWAND;
    } else if (ctx.XOR() != null) {
        operation = Operation.XOR;
    } else if (ctx.BWOR() != null) {
        operation = Operation.BWOR;
    } else {
        throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
    }
    return new EBinary(location(ctx), operation, left, right);
}
Also used : AExpression(org.elasticsearch.painless.node.AExpression) Operation(org.elasticsearch.painless.Operation) EBinary(org.elasticsearch.painless.node.EBinary)

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