Search in sources :

Example 1 with EVariable

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

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

the class Walker method visitVariable.

@Override
public ANode visitVariable(VariableContext ctx) {
    String name = ctx.ID().getText();
    reserved.peek().markUsedVariable(name);
    return new EVariable(location(ctx), name);
}
Also used : EVariable(org.elasticsearch.painless.node.EVariable) EString(org.elasticsearch.painless.node.EString)

Aggregations

EString (org.elasticsearch.painless.node.EString)2 EVariable (org.elasticsearch.painless.node.EVariable)2 Location (org.elasticsearch.painless.Location)1 EFunctionRef (org.elasticsearch.painless.node.EFunctionRef)1 ENewArray (org.elasticsearch.painless.node.ENewArray)1 SFunction (org.elasticsearch.painless.node.SFunction)1 FunctionReserved (org.elasticsearch.painless.node.SFunction.FunctionReserved)1 SReturn (org.elasticsearch.painless.node.SReturn)1