Search in sources :

Example 1 with StatementContext

use of org.elasticsearch.painless.antlr.PainlessParser.StatementContext in project elasticsearch by elastic.

the class Walker method visitSource.

@Override
public ANode visitSource(SourceContext ctx) {
    reserved.push(new MainMethodReserved());
    List<SFunction> functions = new ArrayList<>();
    for (FunctionContext function : ctx.function()) {
        functions.add((SFunction) visit(function));
    }
    List<AStatement> statements = new ArrayList<>();
    for (StatementContext statement : ctx.statement()) {
        statements.add((AStatement) visit(statement));
    }
    return new SSource(scriptInterface, settings, sourceName, sourceText, debugStream, (MainMethodReserved) reserved.pop(), location(ctx), functions, globals, statements);
}
Also used : MainMethodReserved(org.elasticsearch.painless.node.SSource.MainMethodReserved) AStatement(org.elasticsearch.painless.node.AStatement) SFunction(org.elasticsearch.painless.node.SFunction) SSource(org.elasticsearch.painless.node.SSource) ArrayList(java.util.ArrayList) FunctionContext(org.elasticsearch.painless.antlr.PainlessParser.FunctionContext) StatementContext(org.elasticsearch.painless.antlr.PainlessParser.StatementContext)

Example 2 with StatementContext

use of org.elasticsearch.painless.antlr.PainlessParser.StatementContext in project elasticsearch by elastic.

the class Walker method visitFunction.

@Override
public ANode visitFunction(FunctionContext ctx) {
    reserved.push(new FunctionReserved());
    String rtnType = ctx.decltype().getText();
    String name = ctx.ID().getText();
    List<String> paramTypes = new ArrayList<>();
    List<String> paramNames = new ArrayList<>();
    List<AStatement> statements = new ArrayList<>();
    for (DecltypeContext decltype : ctx.parameters().decltype()) {
        paramTypes.add(decltype.getText());
    }
    for (TerminalNode id : ctx.parameters().ID()) {
        paramNames.add(id.getText());
    }
    for (StatementContext statement : ctx.block().statement()) {
        statements.add((AStatement) visit(statement));
    }
    return new SFunction((FunctionReserved) reserved.pop(), location(ctx), rtnType, name, paramTypes, paramNames, statements, false);
}
Also used : AStatement(org.elasticsearch.painless.node.AStatement) SFunction(org.elasticsearch.painless.node.SFunction) FunctionReserved(org.elasticsearch.painless.node.SFunction.FunctionReserved) ArrayList(java.util.ArrayList) EString(org.elasticsearch.painless.node.EString) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode) DecltypeContext(org.elasticsearch.painless.antlr.PainlessParser.DecltypeContext) StatementContext(org.elasticsearch.painless.antlr.PainlessParser.StatementContext)

Example 3 with StatementContext

use of org.elasticsearch.painless.antlr.PainlessParser.StatementContext 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)

Aggregations

ArrayList (java.util.ArrayList)3 StatementContext (org.elasticsearch.painless.antlr.PainlessParser.StatementContext)3 AStatement (org.elasticsearch.painless.node.AStatement)3 EString (org.elasticsearch.painless.node.EString)2 SFunction (org.elasticsearch.painless.node.SFunction)2 FunctionReserved (org.elasticsearch.painless.node.SFunction.FunctionReserved)2 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)1 DecltypeContext (org.elasticsearch.painless.antlr.PainlessParser.DecltypeContext)1 FunctionContext (org.elasticsearch.painless.antlr.PainlessParser.FunctionContext)1 LamtypeContext (org.elasticsearch.painless.antlr.PainlessParser.LamtypeContext)1 AExpression (org.elasticsearch.painless.node.AExpression)1 ELambda (org.elasticsearch.painless.node.ELambda)1 SReturn (org.elasticsearch.painless.node.SReturn)1 SSource (org.elasticsearch.painless.node.SSource)1 MainMethodReserved (org.elasticsearch.painless.node.SSource.MainMethodReserved)1