Search in sources :

Example 21 with AExpression

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

the class Walker method visitDo.

@Override
public ANode visitDo(DoContext ctx) {
    reserved.peek().setMaxLoopCounter(settings.getMaxLoopCounter());
    AExpression expression = (AExpression) visit(ctx.expression());
    SBlock block = (SBlock) visit(ctx.block());
    return new SDo(location(ctx), block, expression);
}
Also used : AExpression(org.elasticsearch.painless.node.AExpression) SBlock(org.elasticsearch.painless.node.SBlock) SDo(org.elasticsearch.painless.node.SDo)

Example 22 with AExpression

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

the class Walker method visitInstanceof.

@Override
public ANode visitInstanceof(InstanceofContext ctx) {
    AExpression expr = (AExpression) visit(ctx.expression());
    String type = ctx.decltype().getText();
    return new EInstanceof(location(ctx), expr, type);
}
Also used : AExpression(org.elasticsearch.painless.node.AExpression) EInstanceof(org.elasticsearch.painless.node.EInstanceof) EString(org.elasticsearch.painless.node.EString)

Example 23 with AExpression

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

Example 24 with AExpression

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

the class Walker method visitDeclaration.

@Override
public ANode visitDeclaration(DeclarationContext ctx) {
    String type = ctx.decltype().getText();
    List<SDeclaration> declarations = new ArrayList<>();
    for (DeclvarContext declvar : ctx.declvar()) {
        String name = declvar.ID().getText();
        AExpression expression = declvar.expression() == null ? null : (AExpression) visit(declvar.expression());
        declarations.add(new SDeclaration(location(declvar), type, name, expression));
    }
    return new SDeclBlock(location(ctx), declarations);
}
Also used : DeclvarContext(org.elasticsearch.painless.antlr.PainlessParser.DeclvarContext) AExpression(org.elasticsearch.painless.node.AExpression) ArrayList(java.util.ArrayList) EString(org.elasticsearch.painless.node.EString) SDeclBlock(org.elasticsearch.painless.node.SDeclBlock) SDeclaration(org.elasticsearch.painless.node.SDeclaration)

Example 25 with AExpression

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

the class Walker method visitNewobject.

@Override
public ANode visitNewobject(NewobjectContext ctx) {
    String type = ctx.TYPE().getText();
    List<AExpression> arguments = collectArguments(ctx.arguments());
    return new ENewObj(location(ctx), type, arguments);
}
Also used : ENewObj(org.elasticsearch.painless.node.ENewObj) AExpression(org.elasticsearch.painless.node.AExpression) 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