Search in sources :

Example 11 with AExpression

use of org.elasticsearch.painless.node.AExpression 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 12 with AExpression

use of org.elasticsearch.painless.node.AExpression 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)

Example 13 with AExpression

use of org.elasticsearch.painless.node.AExpression in project elasticsearch by elastic.

the class Walker method visitIf.

@Override
public ANode visitIf(IfContext ctx) {
    AExpression expression = (AExpression) visit(ctx.expression());
    SBlock ifblock = (SBlock) visit(ctx.trailer(0));
    if (ctx.trailer().size() > 1) {
        SBlock elseblock = (SBlock) visit(ctx.trailer(1));
        return new SIfElse(location(ctx), expression, ifblock, elseblock);
    } else {
        return new SIf(location(ctx), expression, ifblock);
    }
}
Also used : SIf(org.elasticsearch.painless.node.SIf) AExpression(org.elasticsearch.painless.node.AExpression) SIfElse(org.elasticsearch.painless.node.SIfElse) SBlock(org.elasticsearch.painless.node.SBlock)

Example 14 with AExpression

use of org.elasticsearch.painless.node.AExpression in project elasticsearch by elastic.

the class Walker method visitIneach.

@Override
public ANode visitIneach(IneachContext ctx) {
    reserved.peek().setMaxLoopCounter(settings.getMaxLoopCounter());
    String name = ctx.ID().getText();
    AExpression expression = (AExpression) visit(ctx.expression());
    SBlock block = (SBlock) visit(ctx.trailer());
    return new SEach(location(ctx), "def", name, expression, block);
}
Also used : SEach(org.elasticsearch.painless.node.SEach) AExpression(org.elasticsearch.painless.node.AExpression) EString(org.elasticsearch.painless.node.EString) SBlock(org.elasticsearch.painless.node.SBlock)

Example 15 with AExpression

use of org.elasticsearch.painless.node.AExpression in project elasticsearch by elastic.

the class Walker method visitNewstandardarray.

@Override
public ANode visitNewstandardarray(NewstandardarrayContext ctx) {
    String type = ctx.TYPE().getText();
    List<AExpression> expressions = new ArrayList<>();
    for (ExpressionContext expression : ctx.expression()) {
        expressions.add((AExpression) visit(expression));
    }
    return buildPostfixChain(new ENewArray(location(ctx), type, expressions, false), ctx.postdot(), ctx.postfix());
}
Also used : ENewArray(org.elasticsearch.painless.node.ENewArray) ExpressionContext(org.elasticsearch.painless.antlr.PainlessParser.ExpressionContext) AExpression(org.elasticsearch.painless.node.AExpression) ArrayList(java.util.ArrayList) EString(org.elasticsearch.painless.node.EString)

Aggregations

AExpression (org.elasticsearch.painless.node.AExpression)25 EString (org.elasticsearch.painless.node.EString)11 Operation (org.elasticsearch.painless.Operation)7 SBlock (org.elasticsearch.painless.node.SBlock)6 ArrayList (java.util.ArrayList)5 EAssignment (org.elasticsearch.painless.node.EAssignment)3 ExpressionContext (org.elasticsearch.painless.antlr.PainlessParser.ExpressionContext)2 ENewArray (org.elasticsearch.painless.node.ENewArray)2 SEach (org.elasticsearch.painless.node.SEach)2 DeclvarContext (org.elasticsearch.painless.antlr.PainlessParser.DeclvarContext)1 DynamicContext (org.elasticsearch.painless.antlr.PainlessParser.DynamicContext)1 LamtypeContext (org.elasticsearch.painless.antlr.PainlessParser.LamtypeContext)1 MaptokenContext (org.elasticsearch.painless.antlr.PainlessParser.MaptokenContext)1 NumericContext (org.elasticsearch.painless.antlr.PainlessParser.NumericContext)1 ReadContext (org.elasticsearch.painless.antlr.PainlessParser.ReadContext)1 StatementContext (org.elasticsearch.painless.antlr.PainlessParser.StatementContext)1 ANode (org.elasticsearch.painless.node.ANode)1 AStatement (org.elasticsearch.painless.node.AStatement)1 EBinary (org.elasticsearch.painless.node.EBinary)1 EBool (org.elasticsearch.painless.node.EBool)1