use of org.elasticsearch.painless.Location 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.Location in project elasticsearch by elastic.
the class NodeToStringTests method testECast.
public void testECast() {
Location l = new Location(getTestName(), 0);
AExpression child = new EConstant(l, "test");
Cast cast = new Cast(Definition.STRING_TYPE, Definition.INT_OBJ_TYPE, true);
assertEquals("(ECast Integer (EConstant String 'test'))", new ECast(l, child, cast).toString());
l = new Location(getTestName(), 1);
child = new EBinary(l, Operation.ADD, new EConstant(l, "test"), new EConstant(l, 12));
cast = new Cast(Definition.INT_OBJ_TYPE, Definition.BOOLEAN_OBJ_TYPE, true);
assertEquals("(ECast Boolean (EBinary (EConstant String 'test') + (EConstant Integer 12)))", new ECast(l, child, cast).toString());
}
use of org.elasticsearch.painless.Location in project elasticsearch by elastic.
the class NodeToStringTests method testPSubDefCall.
public void testPSubDefCall() {
Location l = new Location(getTestName(), 0);
PSubDefCall node = new PSubDefCall(l, "toString", emptyList());
node.prefix = new EVariable(l, "a");
assertEquals("(PSubDefCall (EVariable a) toString)", node.toString());
assertEquals("(PSubNullSafeCallInvoke (PSubDefCall (EVariable a) toString))", new PSubNullSafeCallInvoke(l, node).toString());
l = new Location(getTestName(), 0);
node = new PSubDefCall(l, "equals", singletonList(new EVariable(l, "b")));
node.prefix = new EVariable(l, "a");
assertEquals("(PSubDefCall (EVariable a) equals (Args (EVariable b)))", node.toString());
assertEquals("(PSubNullSafeCallInvoke (PSubDefCall (EVariable a) equals (Args (EVariable b))))", new PSubNullSafeCallInvoke(l, node).toString());
l = new Location(getTestName(), 0);
node = new PSubDefCall(l, "superWeird", Arrays.asList(new EVariable(l, "b"), new EVariable(l, "c"), new EVariable(l, "d")));
node.prefix = new EVariable(l, "a");
assertEquals("(PSubDefCall (EVariable a) superWeird (Args (EVariable b) (EVariable c) (EVariable d)))", node.toString());
assertEquals("(PSubNullSafeCallInvoke (PSubDefCall (EVariable a) superWeird (Args (EVariable b) (EVariable c) (EVariable d))))", new PSubNullSafeCallInvoke(l, node).toString());
}
use of org.elasticsearch.painless.Location in project elasticsearch by elastic.
the class NodeToStringTests method testSSubEachArray.
public void testSSubEachArray() {
Location l = new Location(getTestName(), 0);
Variable v = new Variable(l, "test", Definition.INT_TYPE, 5, false);
AExpression e = new ENewArray(l, "int", Arrays.asList(new EConstant(l, 1), new EConstant(l, 2), new EConstant(l, 3)), true);
SBlock b = new SBlock(l, singletonList(new SReturn(l, new EConstant(l, 5))));
SSubEachArray node = new SSubEachArray(l, v, e, b);
assertEquals("(SSubEachArray int test (ENewArray int init (Args (EConstant Integer 1) (EConstant Integer 2) (EConstant Integer 3))) " + "(SBlock (SReturn (EConstant Integer 5))))", node.toString());
}
use of org.elasticsearch.painless.Location in project elasticsearch by elastic.
the class NodeToStringTests method testPSubCallInvoke.
public void testPSubCallInvoke() {
Location l = new Location(getTestName(), 0);
RuntimeClass c = Definition.getRuntimeClass(Integer.class);
Method m = c.methods.get(new MethodKey("toString", 0));
PSubCallInvoke node = new PSubCallInvoke(l, m, null, emptyList());
node.prefix = new EVariable(l, "a");
assertEquals("(PSubCallInvoke (EVariable a) toString)", node.toString());
assertEquals("(PSubNullSafeCallInvoke (PSubCallInvoke (EVariable a) toString))", new PSubNullSafeCallInvoke(l, node).toString());
l = new Location(getTestName(), 1);
m = c.methods.get(new MethodKey("equals", 1));
node = new PSubCallInvoke(l, m, null, singletonList(new EVariable(l, "b")));
node.prefix = new EVariable(l, "a");
assertEquals("(PSubCallInvoke (EVariable a) equals (Args (EVariable b)))", node.toString());
assertEquals("(PSubNullSafeCallInvoke (PSubCallInvoke (EVariable a) equals (Args (EVariable b))))", new PSubNullSafeCallInvoke(l, node).toString());
}
Aggregations