use of org.elasticsearch.painless.node.SFunction 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);
}
use of org.elasticsearch.painless.node.SFunction 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());
}
use of org.elasticsearch.painless.node.SFunction 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);
}
Aggregations