Search in sources :

Example 1 with ENewArray

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

the class Walker method visitConstructorfuncref.

@Override
public ANode visitConstructorfuncref(ConstructorfuncrefContext ctx) {
    if (!ctx.decltype().LBRACE().isEmpty()) {
        // array constructors are special: we need to make a synthetic method
        // taking integer as argument and returning a new instance, and return a ref to that.
        Location location = location(ctx);
        String arrayType = ctx.decltype().getText();
        SReturn code = new SReturn(location, new ENewArray(location, arrayType, Arrays.asList(new EVariable(location, "size")), false));
        String name = nextLambda();
        globals.addSyntheticMethod(new SFunction(new FunctionReserved(), location, arrayType, name, Arrays.asList("int"), Arrays.asList("size"), Arrays.asList(code), true));
        return new EFunctionRef(location(ctx), "this", name);
    }
    return new EFunctionRef(location(ctx), ctx.decltype().getText(), ctx.NEW().getText());
}
Also used : EVariable(org.elasticsearch.painless.node.EVariable) EFunctionRef(org.elasticsearch.painless.node.EFunctionRef) SFunction(org.elasticsearch.painless.node.SFunction) ENewArray(org.elasticsearch.painless.node.ENewArray) FunctionReserved(org.elasticsearch.painless.node.SFunction.FunctionReserved) EString(org.elasticsearch.painless.node.EString) SReturn(org.elasticsearch.painless.node.SReturn) Location(org.elasticsearch.painless.Location)

Example 2 with ENewArray

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

Example 3 with ENewArray

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

the class Walker method visitNewinitializedarray.

@Override
public ANode visitNewinitializedarray(NewinitializedarrayContext 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, true), null, 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

ENewArray (org.elasticsearch.painless.node.ENewArray)3 EString (org.elasticsearch.painless.node.EString)3 ArrayList (java.util.ArrayList)2 ExpressionContext (org.elasticsearch.painless.antlr.PainlessParser.ExpressionContext)2 AExpression (org.elasticsearch.painless.node.AExpression)2 Location (org.elasticsearch.painless.Location)1 EFunctionRef (org.elasticsearch.painless.node.EFunctionRef)1 EVariable (org.elasticsearch.painless.node.EVariable)1 SFunction (org.elasticsearch.painless.node.SFunction)1 FunctionReserved (org.elasticsearch.painless.node.SFunction.FunctionReserved)1 SReturn (org.elasticsearch.painless.node.SReturn)1