Search in sources :

Example 1 with EFunctionRef

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

Aggregations

Location (org.elasticsearch.painless.Location)1 EFunctionRef (org.elasticsearch.painless.node.EFunctionRef)1 ENewArray (org.elasticsearch.painless.node.ENewArray)1 EString (org.elasticsearch.painless.node.EString)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