Search in sources :

Example 1 with AExpression

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

the class Walker method visitMapinitializer.

@Override
public ANode visitMapinitializer(MapinitializerContext ctx) {
    List<AExpression> keys = new ArrayList<>();
    List<AExpression> values = new ArrayList<>();
    for (MaptokenContext maptoken : ctx.maptoken()) {
        keys.add((AExpression) visit(maptoken.expression(0)));
        values.add((AExpression) visit(maptoken.expression(1)));
    }
    return new EMapInit(location(ctx), keys, values);
}
Also used : EMapInit(org.elasticsearch.painless.node.EMapInit) MaptokenContext(org.elasticsearch.painless.antlr.PainlessParser.MaptokenContext) AExpression(org.elasticsearch.painless.node.AExpression) ArrayList(java.util.ArrayList)

Example 2 with AExpression

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

the class Walker method visitCalllocal.

@Override
public ANode visitCalllocal(CalllocalContext ctx) {
    String name = ctx.ID().getText();
    List<AExpression> arguments = collectArguments(ctx.arguments());
    return new ECallLocal(location(ctx), name, arguments);
}
Also used : AExpression(org.elasticsearch.painless.node.AExpression) EString(org.elasticsearch.painless.node.EString) ECallLocal(org.elasticsearch.painless.node.ECallLocal)

Example 3 with AExpression

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

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

the class Walker method visitConditional.

@Override
public ANode visitConditional(ConditionalContext ctx) {
    AExpression condition = (AExpression) visit(ctx.expression(0));
    AExpression left = (AExpression) visit(ctx.expression(1));
    AExpression right = (AExpression) visit(ctx.expression(2));
    return new EConditional(location(ctx), condition, left, right);
}
Also used : AExpression(org.elasticsearch.painless.node.AExpression) EConditional(org.elasticsearch.painless.node.EConditional)

Example 5 with AExpression

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

the class Walker method visitFor.

@Override
public ANode visitFor(ForContext ctx) {
    reserved.peek().setMaxLoopCounter(settings.getMaxLoopCounter());
    ANode initializer = ctx.initializer() == null ? null : visit(ctx.initializer());
    AExpression expression = ctx.expression() == null ? null : (AExpression) visit(ctx.expression());
    AExpression afterthought = ctx.afterthought() == null ? null : (AExpression) visit(ctx.afterthought());
    if (ctx.trailer() != null) {
        SBlock block = (SBlock) visit(ctx.trailer());
        return new SFor(location(ctx), initializer, expression, afterthought, block);
    } else if (ctx.empty() != null) {
        return new SFor(location(ctx), initializer, expression, afterthought, null);
    } else {
        throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
    }
}
Also used : SFor(org.elasticsearch.painless.node.SFor) AExpression(org.elasticsearch.painless.node.AExpression) ANode(org.elasticsearch.painless.node.ANode) SBlock(org.elasticsearch.painless.node.SBlock)

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