Search in sources :

Example 6 with AExpression

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

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

the class Walker method visitCallinvoke.

public AExpression visitCallinvoke(CallinvokeContext ctx, AExpression prefix) {
    String name = ctx.DOTID().getText();
    List<AExpression> arguments = collectArguments(ctx.arguments());
    return new PCallInvoke(location(ctx), prefix, name, ctx.NSDOT() != null, arguments);
}
Also used : PCallInvoke(org.elasticsearch.painless.node.PCallInvoke) AExpression(org.elasticsearch.painless.node.AExpression) EString(org.elasticsearch.painless.node.EString)

Example 8 with AExpression

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

the class Walker method visitEach.

@Override
public ANode visitEach(EachContext ctx) {
    reserved.peek().setMaxLoopCounter(settings.getMaxLoopCounter());
    String type = ctx.decltype().getText();
    String name = ctx.ID().getText();
    AExpression expression = (AExpression) visit(ctx.expression());
    SBlock block = (SBlock) visit(ctx.trailer());
    return new SEach(location(ctx), type, 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 9 with AExpression

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

the class Walker method visitLambda.

@Override
public ANode visitLambda(LambdaContext ctx) {
    reserved.push(new FunctionReserved());
    List<String> paramTypes = new ArrayList<>();
    List<String> paramNames = new ArrayList<>();
    List<AStatement> statements = new ArrayList<>();
    for (LamtypeContext lamtype : ctx.lamtype()) {
        if (lamtype.decltype() == null) {
            paramTypes.add("def");
        } else {
            paramTypes.add(lamtype.decltype().getText());
        }
        paramNames.add(lamtype.ID().getText());
    }
    if (ctx.expression() != null) {
        // single expression
        AExpression expression = (AExpression) visit(ctx.expression());
        statements.add(new SReturn(location(ctx), expression));
    } else {
        for (StatementContext statement : ctx.block().statement()) {
            statements.add((AStatement) visit(statement));
        }
    }
    String name = nextLambda();
    return new ELambda(name, (FunctionReserved) reserved.pop(), location(ctx), paramTypes, paramNames, statements);
}
Also used : AStatement(org.elasticsearch.painless.node.AStatement) LamtypeContext(org.elasticsearch.painless.antlr.PainlessParser.LamtypeContext) ELambda(org.elasticsearch.painless.node.ELambda) FunctionReserved(org.elasticsearch.painless.node.SFunction.FunctionReserved) AExpression(org.elasticsearch.painless.node.AExpression) ArrayList(java.util.ArrayList) EString(org.elasticsearch.painless.node.EString) SReturn(org.elasticsearch.painless.node.SReturn) StatementContext(org.elasticsearch.painless.antlr.PainlessParser.StatementContext)

Example 10 with AExpression

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

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