use of org.elasticsearch.painless.node.AExpression in project elasticsearch by elastic.
the class Walker method visitComp.
@Override
public ANode visitComp(CompContext ctx) {
AExpression left = (AExpression) visit(ctx.expression(0));
AExpression right = (AExpression) visit(ctx.expression(1));
final Operation operation;
if (ctx.LT() != null) {
operation = Operation.LT;
} else if (ctx.LTE() != null) {
operation = Operation.LTE;
} else if (ctx.GT() != null) {
operation = Operation.GT;
} else if (ctx.GTE() != null) {
operation = Operation.GTE;
} else if (ctx.EQ() != null) {
operation = Operation.EQ;
} else if (ctx.EQR() != null) {
operation = Operation.EQR;
} else if (ctx.NE() != null) {
operation = Operation.NE;
} else if (ctx.NER() != null) {
operation = Operation.NER;
} else {
throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
}
return new EComp(location(ctx), operation, left, right);
}
use of org.elasticsearch.painless.node.AExpression in project elasticsearch by elastic.
the class Walker method visitCallinvoke.
public AExpression visitCallinvoke(CallinvokeContext ctx, AExpression prefix) {
String name = ctx.DOTID().getText();
List<AExpression> arguments = collectArguments(ctx.arguments());
return new PCallInvoke(location(ctx), prefix, name, ctx.NSDOT() != null, arguments);
}
use of org.elasticsearch.painless.node.AExpression in project elasticsearch by elastic.
the class Walker method visitEach.
@Override
public ANode visitEach(EachContext ctx) {
reserved.peek().setMaxLoopCounter(settings.getMaxLoopCounter());
String type = ctx.decltype().getText();
String name = ctx.ID().getText();
AExpression expression = (AExpression) visit(ctx.expression());
SBlock block = (SBlock) visit(ctx.trailer());
return new SEach(location(ctx), type, name, expression, block);
}
use of org.elasticsearch.painless.node.AExpression 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);
}
use of org.elasticsearch.painless.node.AExpression in project elasticsearch by elastic.
the class Walker method visitOperator.
@Override
public ANode visitOperator(OperatorContext ctx) {
AExpression expression = (AExpression) visit(ctx.unary());
final Operation operation;
if (ctx.BOOLNOT() != null) {
operation = Operation.NOT;
} else if (ctx.BWNOT() != null) {
operation = Operation.BWNOT;
} else if (ctx.ADD() != null) {
operation = Operation.ADD;
} else if (ctx.SUB() != null) {
if (ctx.unary() instanceof ReadContext && ((ReadContext) ctx.unary()).chain() instanceof DynamicContext && ((DynamicContext) ((ReadContext) ctx.unary()).chain()).primary() instanceof NumericContext && ((DynamicContext) ((ReadContext) ctx.unary()).chain()).postfix().isEmpty()) {
return expression;
}
operation = Operation.SUB;
} else {
throw location(ctx).createError(new IllegalStateException("Illegal tree structure."));
}
return new EUnary(location(ctx), operation, expression);
}
Aggregations