Remove Sort enum from Painless Definition (#26179)

This is step toward making Definition instanceable which is necessary for custom whitelists in different contexts.
This commit is contained in:
Jack Conradson 2017-08-17 12:02:11 -07:00 committed by GitHub
parent 7e76b2a8c3
commit 23858789f0
31 changed files with 893 additions and 1244 deletions

View File

@ -21,7 +21,6 @@ package org.elasticsearch.painless;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.SetOnce;
import org.elasticsearch.painless.api.Augmentation;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -99,72 +98,22 @@ public final class Definition {
public static final Type ARRAY_LIST_TYPE = BUILTINS.getType("ArrayList");
public static final Type HASH_MAP_TYPE = BUILTINS.getType("HashMap");
public enum Sort {
VOID( void.class , Void.class , null , 0 , true , false , false , false ),
BOOL( boolean.class , Boolean.class , null , 1 , true , true , false , true ),
BYTE( byte.class , Byte.class , null , 1 , true , false , true , true ),
SHORT( short.class , Short.class , null , 1 , true , false , true , true ),
CHAR( char.class , Character.class , null , 1 , true , false , true , true ),
INT( int.class , Integer.class , null , 1 , true , false , true , true ),
LONG( long.class , Long.class , null , 2 , true , false , true , true ),
FLOAT( float.class , Float.class , null , 1 , true , false , true , true ),
DOUBLE( double.class , Double.class , null , 2 , true , false , true , true ),
VOID_OBJ( Void.class , null , void.class , 1 , true , false , false , false ),
BOOL_OBJ( Boolean.class , null , boolean.class , 1 , false , true , false , false ),
BYTE_OBJ( Byte.class , null , byte.class , 1 , false , false , true , false ),
SHORT_OBJ( Short.class , null , short.class , 1 , false , false , true , false ),
CHAR_OBJ( Character.class , null , char.class , 1 , false , false , true , false ),
INT_OBJ( Integer.class , null , int.class , 1 , false , false , true , false ),
LONG_OBJ( Long.class , null , long.class , 1 , false , false , true , false ),
FLOAT_OBJ( Float.class , null , float.class , 1 , false , false , true , false ),
DOUBLE_OBJ( Double.class , null , double.class , 1 , false , false , true , false ),
NUMBER( Number.class , null , null , 1 , false , false , false , false ),
STRING( String.class , null , null , 1 , false , false , false , true ),
OBJECT( null , null , null , 1 , false , false , false , false ),
DEF( null , null , null , 1 , false , false , false , false ),
ARRAY( null , null , null , 1 , false , false , false , false );
public final Class<?> clazz;
public final Class<?> boxed;
public final Class<?> unboxed;
public final int size;
public final boolean primitive;
public final boolean bool;
public final boolean numeric;
public final boolean constant;
Sort(final Class<?> clazz, final Class<?> boxed, final Class<?> unboxed, final int size,
final boolean primitive, final boolean bool, final boolean numeric, final boolean constant) {
this.clazz = clazz;
this.boxed = boxed;
this.unboxed = unboxed;
this.size = size;
this.bool = bool;
this.primitive = primitive;
this.numeric = numeric;
this.constant = constant;
}
}
public static final class Type {
public final String name;
public final int dimensions;
public final boolean dynamic;
public final Struct struct;
public final Class<?> clazz;
public final org.objectweb.asm.Type type;
public final Sort sort;
private Type(final String name, final int dimensions, final Struct struct,
final Class<?> clazz, final org.objectweb.asm.Type type, final Sort sort) {
private Type(final String name, final int dimensions, final boolean dynamic,
final Struct struct, final Class<?> clazz, final org.objectweb.asm.Type type) {
this.name = name;
this.dimensions = dimensions;
this.struct = struct;
this.clazz = clazz;
this.type = type;
this.sort = sort;
this.dynamic = dynamic;
}
@Override
@ -503,6 +452,62 @@ public final class Definition {
return BUILTINS.getTypeInternal(struct, dimensions);
}
public static Type getBoxedType(Type unboxed) {
if (unboxed.clazz == boolean.class) {
return BOOLEAN_OBJ_TYPE;
} else if (unboxed.clazz == byte.class) {
return BYTE_OBJ_TYPE;
} else if (unboxed.clazz == short.class) {
return SHORT_OBJ_TYPE;
} else if (unboxed.clazz == char.class) {
return CHAR_OBJ_TYPE;
} else if (unboxed.clazz == int.class) {
return INT_OBJ_TYPE;
} else if (unboxed.clazz == long.class) {
return LONG_OBJ_TYPE;
} else if (unboxed.clazz == float.class) {
return FLOAT_OBJ_TYPE;
} else if (unboxed.clazz == double.class) {
return DOUBLE_OBJ_TYPE;
}
return unboxed;
}
public static Type getUnboxedType(Type boxed) {
if (boxed.clazz == Boolean.class) {
return BOOLEAN_TYPE;
} else if (boxed.clazz == Byte.class) {
return BYTE_TYPE;
} else if (boxed.clazz == Short.class) {
return SHORT_TYPE;
} else if (boxed.clazz == Character.class) {
return CHAR_TYPE;
} else if (boxed.clazz == Integer.class) {
return INT_TYPE;
} else if (boxed.clazz == Long.class) {
return LONG_TYPE;
} else if (boxed.clazz == Float.class) {
return FLOAT_TYPE;
} else if (boxed.clazz == Double.class) {
return DOUBLE_TYPE;
}
return boxed;
}
public static boolean isConstantType(Type constant) {
return constant.clazz == boolean.class ||
constant.clazz == byte.class ||
constant.clazz == short.class ||
constant.clazz == char.class ||
constant.clazz == int.class ||
constant.clazz == long.class ||
constant.clazz == float.class ||
constant.clazz == double.class ||
constant.clazz == String.class;
}
public RuntimeClass getRuntimeClass(Class<?> clazz) {
return BUILTINS.runtimeMap.get(clazz);
}
@ -1136,7 +1141,6 @@ public final class Definition {
String name = struct.name;
org.objectweb.asm.Type type = struct.type;
Class<?> clazz = struct.clazz;
Sort sort;
if (dimensions > 0) {
StringBuilder builder = new StringBuilder(name);
@ -1158,27 +1162,9 @@ public final class Definition {
throw new IllegalArgumentException("The class [" + type.getInternalName() + "]" +
" could not be found to create type [" + name + "].");
}
sort = Sort.ARRAY;
} else if ("def".equals(struct.name)) {
sort = Sort.DEF;
} else {
sort = Sort.OBJECT;
for (Sort value : Sort.values()) {
if (value.clazz == null) {
continue;
}
if (value.clazz.equals(struct.clazz)) {
sort = value;
break;
}
}
}
return new Type(name, dimensions, struct, clazz, type, sort);
return new Type(name, dimensions, "def".equals(name), struct, clazz, type);
}
private int getDimensions(String name) {

View File

@ -20,7 +20,6 @@
package org.elasticsearch.painless;
import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
@ -131,35 +130,39 @@ public final class MethodWriter extends GeneratorAdapter {
public void writeCast(final Cast cast) {
if (cast != null) {
if (cast.from.sort == Sort.CHAR && cast.to.sort == Sort.STRING) {
if (cast.from.clazz == char.class && cast.to.clazz == String.class) {
invokeStatic(UTILITY_TYPE, CHAR_TO_STRING);
} else if (cast.from.sort == Sort.STRING && cast.to.sort == Sort.CHAR) {
} else if (cast.from.clazz == String.class && cast.to.clazz == char.class) {
invokeStatic(UTILITY_TYPE, STRING_TO_CHAR);
} else if (cast.unboxFrom != null) {
unbox(cast.unboxFrom.type);
writeCast(cast.from, cast.to);
} else if (cast.unboxTo != null) {
if (cast.from.sort == Sort.DEF) {
if (cast.from.dynamic) {
if (cast.explicit) {
if (cast.to.sort == Sort.BOOL_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BOOLEAN);
else if (cast.to.sort == Sort.BYTE_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BYTE_EXPLICIT);
else if (cast.to.sort == Sort.SHORT_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_SHORT_EXPLICIT);
else if (cast.to.sort == Sort.CHAR_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_CHAR_EXPLICIT);
else if (cast.to.sort == Sort.INT_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_INT_EXPLICIT);
else if (cast.to.sort == Sort.LONG_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_LONG_EXPLICIT);
else if (cast.to.sort == Sort.FLOAT_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_FLOAT_EXPLICIT);
else if (cast.to.sort == Sort.DOUBLE_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_DOUBLE_EXPLICIT);
else throw new IllegalStateException("Illegal tree structure.");
if (cast.to.clazz == Boolean.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BOOLEAN);
else if (cast.to.clazz == Byte.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BYTE_EXPLICIT);
else if (cast.to.clazz == Short.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_SHORT_EXPLICIT);
else if (cast.to.clazz == Character.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_CHAR_EXPLICIT);
else if (cast.to.clazz == Integer.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_INT_EXPLICIT);
else if (cast.to.clazz == Long.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_LONG_EXPLICIT);
else if (cast.to.clazz == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_FLOAT_EXPLICIT);
else if (cast.to.clazz == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_DOUBLE_EXPLICIT);
else {
throw new IllegalStateException("Illegal tree structure.");
}
} else {
if (cast.to.sort == Sort.BOOL_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BOOLEAN);
else if (cast.to.sort == Sort.BYTE_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BYTE_IMPLICIT);
else if (cast.to.sort == Sort.SHORT_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_SHORT_IMPLICIT);
else if (cast.to.sort == Sort.CHAR_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_CHAR_IMPLICIT);
else if (cast.to.sort == Sort.INT_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_INT_IMPLICIT);
else if (cast.to.sort == Sort.LONG_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_LONG_IMPLICIT);
else if (cast.to.sort == Sort.FLOAT_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_FLOAT_IMPLICIT);
else if (cast.to.sort == Sort.DOUBLE_OBJ) invokeStatic(DEF_UTIL_TYPE, DEF_TO_DOUBLE_IMPLICIT);
else throw new IllegalStateException("Illegal tree structure.");
if (cast.to.clazz == Boolean.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BOOLEAN);
else if (cast.to.clazz == Byte.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_BYTE_IMPLICIT);
else if (cast.to.clazz == Short.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_SHORT_IMPLICIT);
else if (cast.to.clazz == Character.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_CHAR_IMPLICIT);
else if (cast.to.clazz == Integer.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_INT_IMPLICIT);
else if (cast.to.clazz == Long.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_LONG_IMPLICIT);
else if (cast.to.clazz == Float.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_FLOAT_IMPLICIT);
else if (cast.to.clazz == Double.class) invokeStatic(DEF_UTIL_TYPE, DEF_TO_DOUBLE_IMPLICIT);
else {
throw new IllegalStateException("Illegal tree structure.");
}
}
} else {
writeCast(cast.from, cast.to);
@ -182,7 +185,7 @@ public final class MethodWriter extends GeneratorAdapter {
return;
}
if (from.sort.numeric && from.sort.primitive && to.sort.numeric && to.sort.primitive) {
if (from.clazz != boolean.class && from.clazz.isPrimitive() && to.clazz != boolean.class && to.clazz.isPrimitive()) {
cast(from.type, to.type);
} else {
if (!to.clazz.isAssignableFrom(from.clazz)) {
@ -238,18 +241,16 @@ public final class MethodWriter extends GeneratorAdapter {
}
} else {
// Java 8: push a StringBuilder append
switch (type.sort) {
case BOOL: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_BOOLEAN); break;
case CHAR: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_CHAR); break;
case BYTE:
case SHORT:
case INT: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_INT); break;
case LONG: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_LONG); break;
case FLOAT: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_FLOAT); break;
case DOUBLE: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_DOUBLE); break;
case STRING: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_STRING); break;
default: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_OBJECT);
}
if (type.clazz == boolean.class) invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_BOOLEAN);
else if (type.clazz == char.class) invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_CHAR);
else if (type.clazz == byte.class ||
type.clazz == short.class ||
type.clazz == int.class) invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_INT);
else if (type.clazz == long.class) invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_LONG);
else if (type.clazz == float.class) invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_FLOAT);
else if (type.clazz == double.class) invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_DOUBLE);
else if (type.clazz == String.class) invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_STRING);
else invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_OBJECT);
}
}
@ -318,9 +319,7 @@ public final class MethodWriter extends GeneratorAdapter {
/** Writes a static binary instruction */
public void writeBinaryInstruction(Location location, Type type, Operation operation) {
final Sort sort = type.sort;
if ((sort == Sort.FLOAT || sort == Sort.DOUBLE) &&
if ((type.clazz == float.class || type.clazz == double.class) &&
(operation == Operation.LSH || operation == Operation.USH ||
operation == Operation.RSH || operation == Operation.BWAND ||
operation == Operation.XOR || operation == Operation.BWOR)) {

View File

@ -20,6 +20,7 @@
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Locals;
@ -157,7 +158,7 @@ public abstract class AExpression extends ANode {
return ecast;
} else {
if (expected.sort.constant) {
if (Definition.isConstantType(expected)) {
// For the case where a cast is required, a constant is set,
// and the constant can be immediately cast to the expected type.
// An EConstant replaces this node with the constant cast appropriately

View File

@ -23,7 +23,6 @@ import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.DefBootstrap;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
@ -103,14 +102,12 @@ public final class EAssignment extends AExpression {
throw createError(new IllegalStateException("Illegal tree structure."));
}
Sort sort = lhs.actual.sort;
if (operation == Operation.INCR) {
if (sort == Sort.DOUBLE) {
if (lhs.actual.clazz == double.class) {
rhs = new EConstant(location, 1D);
} else if (sort == Sort.FLOAT) {
} else if (lhs.actual.clazz == float.class) {
rhs = new EConstant(location, 1F);
} else if (sort == Sort.LONG) {
} else if (lhs.actual.clazz == long.class) {
rhs = new EConstant(location, 1L);
} else {
rhs = new EConstant(location, 1);
@ -118,11 +115,11 @@ public final class EAssignment extends AExpression {
operation = Operation.ADD;
} else if (operation == Operation.DECR) {
if (sort == Sort.DOUBLE) {
if (lhs.actual.clazz == double.class) {
rhs = new EConstant(location, 1D);
} else if (sort == Sort.FLOAT) {
} else if (lhs.actual.clazz == float.class) {
rhs = new EConstant(location, 1F);
} else if (sort == Sort.LONG) {
} else if (lhs.actual.clazz == long.class) {
rhs = new EConstant(location, 1L);
} else {
rhs = new EConstant(location, 1);
@ -177,19 +174,19 @@ public final class EAssignment extends AExpression {
"[" + operation.symbol + "=] to types [" + lhs.actual + "] and [" + rhs.actual + "]."));
}
cat = operation == Operation.ADD && promote.sort == Sort.STRING;
cat = operation == Operation.ADD && promote.clazz == String.class;
if (cat) {
if (rhs instanceof EBinary && ((EBinary)rhs).operation == Operation.ADD && rhs.actual.sort == Sort.STRING) {
if (rhs instanceof EBinary && ((EBinary)rhs).operation == Operation.ADD && rhs.actual.clazz == String.class) {
((EBinary)rhs).cat = true;
}
rhs.expected = rhs.actual;
} else if (shift) {
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
// shifts are promoted independently, but for the def type, we need object.
rhs.expected = promote;
} else if (shiftDistance.sort == Sort.LONG) {
} else if (shiftDistance.clazz == long.class) {
rhs.expected = Definition.INT_TYPE;
rhs.explicit = true;
} else {
@ -272,7 +269,7 @@ public final class EAssignment extends AExpression {
writer.writeCast(back); // if necessary, cast the String to the lhs actual type
if (lhs.read) {
writer.writeDup(lhs.actual.sort.size, lhs.accessElementCount()); // if this lhs is also read
writer.writeDup(lhs.actual.type.getSize(), lhs.accessElementCount()); // if this lhs is also read
// from dup the value onto the stack
}
@ -286,7 +283,7 @@ public final class EAssignment extends AExpression {
lhs.load(writer, globals); // load the current lhs's value
if (lhs.read && post) {
writer.writeDup(lhs.actual.sort.size, lhs.accessElementCount()); // dup the value if the lhs is also
writer.writeDup(lhs.actual.type.getSize(), lhs.accessElementCount()); // dup the value if the lhs is also
// read from and is a post increment
}
@ -297,7 +294,7 @@ public final class EAssignment extends AExpression {
// XXX: fix these types, but first we need def compound assignment tests.
// its tricky here as there are possibly explicit casts, too.
// write the operation instruction for compound assignment
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
writer.writeDynamicBinaryInstruction(location, promote,
Definition.DEF_TYPE, Definition.DEF_TYPE, operation, DefBootstrap.OPERATOR_COMPOUND_ASSIGNMENT);
} else {
@ -307,7 +304,7 @@ public final class EAssignment extends AExpression {
writer.writeCast(back); // if necessary cast the promotion type value back to the lhs's type
if (lhs.read && !post) {
writer.writeDup(lhs.actual.sort.size, lhs.accessElementCount()); // dup the value if the lhs is also
writer.writeDup(lhs.actual.type.getSize(), lhs.accessElementCount()); // dup the value if the lhs is also
// read from and is not a post increment
}
@ -318,7 +315,7 @@ public final class EAssignment extends AExpression {
rhs.write(writer, globals); // write the bytecode for the rhs rhs
if (lhs.read) {
writer.writeDup(lhs.actual.sort.size, lhs.accessElementCount()); // dup the value if the lhs is also read from
writer.writeDup(lhs.actual.type.getSize(), lhs.accessElementCount()); // dup the value if the lhs is also read from
}
lhs.store(writer, globals); // store the lhs's value from the stack in its respective variable/field/array

View File

@ -22,7 +22,6 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.DefBootstrap;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
@ -110,7 +109,7 @@ public final class EBinary extends AExpression {
actual = promote;
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
if (expected != null) {
@ -125,15 +124,15 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant * (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant * (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant * (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant * (double)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -154,7 +153,7 @@ public final class EBinary extends AExpression {
actual = promote;
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
@ -170,16 +169,16 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
try {
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant / (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant / (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant / (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant / (double)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -203,7 +202,7 @@ public final class EBinary extends AExpression {
actual = promote;
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
@ -219,16 +218,16 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
try {
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant % (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant % (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant % (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant % (double)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -250,23 +249,23 @@ public final class EBinary extends AExpression {
"[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
actual = promote;
if (sort == Sort.STRING) {
if (sort == String.class) {
left.expected = left.actual;
if (left instanceof EBinary && ((EBinary)left).operation == Operation.ADD && left.actual.sort == Sort.STRING) {
if (left instanceof EBinary && ((EBinary)left).operation == Operation.ADD && left.actual.clazz == String.class) {
((EBinary)left).cat = true;
}
right.expected = right.actual;
if (right instanceof EBinary && ((EBinary)right).operation == Operation.ADD && right.actual.sort == Sort.STRING) {
if (right instanceof EBinary && ((EBinary)right).operation == Operation.ADD && right.actual.clazz == String.class) {
((EBinary)right).cat = true;
}
} else if (sort == Sort.DEF) {
} else if (promote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
@ -282,15 +281,15 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant + (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant + (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant + (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant + (double)right.constant;
} else if (sort == Sort.STRING) {
} else if (sort == String.class) {
constant = left.constant.toString() + right.constant.toString();
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -312,7 +311,7 @@ public final class EBinary extends AExpression {
actual = promote;
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
@ -328,15 +327,15 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant - (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant - (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant - (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant - (double)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -373,7 +372,7 @@ public final class EBinary extends AExpression {
actual = promote = lhspromote;
shiftDistance = rhspromote;
if (lhspromote.sort == Sort.DEF || rhspromote.sort == Sort.DEF) {
if (lhspromote.dynamic || rhspromote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
@ -383,7 +382,7 @@ public final class EBinary extends AExpression {
} else {
left.expected = lhspromote;
if (rhspromote.sort == Sort.LONG) {
if (rhspromote.clazz == long.class) {
right.expected = Definition.INT_TYPE;
right.explicit = true;
} else {
@ -395,11 +394,11 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = lhspromote.sort;
Class<?> sort = lhspromote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant << (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant << (int)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -422,7 +421,7 @@ public final class EBinary extends AExpression {
actual = promote = lhspromote;
shiftDistance = rhspromote;
if (lhspromote.sort == Sort.DEF || rhspromote.sort == Sort.DEF) {
if (lhspromote.dynamic || rhspromote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
@ -432,7 +431,7 @@ public final class EBinary extends AExpression {
} else {
left.expected = lhspromote;
if (rhspromote.sort == Sort.LONG) {
if (rhspromote.clazz == long.class) {
right.expected = Definition.INT_TYPE;
right.explicit = true;
} else {
@ -444,11 +443,11 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = lhspromote.sort;
Class<?> sort = lhspromote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant >> (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant >> (int)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -471,7 +470,7 @@ public final class EBinary extends AExpression {
"[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
if (lhspromote.sort == Sort.DEF || rhspromote.sort == Sort.DEF) {
if (lhspromote.dynamic || rhspromote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
@ -481,7 +480,7 @@ public final class EBinary extends AExpression {
} else {
left.expected = lhspromote;
if (rhspromote.sort == Sort.LONG) {
if (rhspromote.clazz == long.class) {
right.expected = Definition.INT_TYPE;
right.explicit = true;
} else {
@ -493,11 +492,11 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = lhspromote.sort;
Class<?> sort = lhspromote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant >>> (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant >>> (int)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -518,7 +517,7 @@ public final class EBinary extends AExpression {
actual = promote;
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
@ -534,11 +533,11 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant & (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant & (long)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -559,7 +558,7 @@ public final class EBinary extends AExpression {
actual = promote;
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
if (expected != null) {
@ -574,13 +573,13 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
if (sort == Sort.BOOL) {
if (sort == boolean.class) {
constant = (boolean)left.constant ^ (boolean)right.constant;
} else if (sort == Sort.INT) {
} else if (sort == int.class) {
constant = (int)left.constant ^ (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant ^ (long)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -601,7 +600,7 @@ public final class EBinary extends AExpression {
actual = promote;
if (promote.sort == Sort.DEF) {
if (promote.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
if (expected != null) {
@ -616,11 +615,11 @@ public final class EBinary extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant | (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant | (long)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -632,7 +631,7 @@ public final class EBinary extends AExpression {
void write(MethodWriter writer, Globals globals) {
writer.writeDebugInfo(location);
if (promote.sort == Sort.STRING && operation == Operation.ADD) {
if (promote.clazz == String.class && operation == Operation.ADD) {
if (!cat) {
writer.writeNewStrings();
}
@ -668,7 +667,7 @@ public final class EBinary extends AExpression {
left.write(writer, globals);
right.write(writer, globals);
if (promote.sort == Sort.DEF || (shiftDistance != null && shiftDistance.sort == Sort.DEF)) {
if (promote.dynamic || (shiftDistance != null && shiftDistance.dynamic)) {
// def calls adopt the wanted return value. if there was a narrowing cast,
// we need to flag that so that its done at runtime.
int flags = 0;

View File

@ -64,7 +64,7 @@ public final class ECapturingFunctionRef extends AExpression implements ILambda
void analyze(Locals locals) {
captured = locals.getVariable(location, variable);
if (expected == null) {
if (captured.type.sort == Definition.Sort.DEF) {
if (captured.type.dynamic) {
// dynamic implementation
defPointer = "D" + variable + "." + call + ",1";
} else {
@ -75,7 +75,7 @@ public final class ECapturingFunctionRef extends AExpression implements ILambda
} else {
defPointer = null;
// static case
if (captured.type.sort != Definition.Sort.DEF) {
if (captured.type.dynamic == false) {
try {
ref = new FunctionRef(locals.getDefinition(), expected, captured.type.name, call, 1);

View File

@ -21,7 +21,6 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.AnalyzerCaster;
@ -97,7 +96,7 @@ public final class EComp extends AExpression {
"[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
if (promotedType.sort == Sort.DEF) {
if (promotedType.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
} else {
@ -113,17 +112,17 @@ public final class EComp extends AExpression {
}
if ((left.constant != null || left.isNull) && (right.constant != null || right.isNull)) {
Sort sort = promotedType.sort;
Class<?> sort = promotedType.clazz;
if (sort == Sort.BOOL) {
if (sort == boolean.class) {
constant = (boolean)left.constant == (boolean)right.constant;
} else if (sort == Sort.INT) {
} else if (sort == int.class) {
constant = (int)left.constant == (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant == (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant == (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant == (double)right.constant;
} else if (!left.isNull) {
constant = left.constant.equals(right.constant);
@ -159,17 +158,17 @@ public final class EComp extends AExpression {
}
if ((left.constant != null || left.isNull) && (right.constant != null || right.isNull)) {
Sort sort = promotedType.sort;
Class<?> sort = promotedType.clazz;
if (sort == Sort.BOOL) {
if (sort == boolean.class) {
constant = (boolean)left.constant == (boolean)right.constant;
} else if (sort == Sort.INT) {
} else if (sort == int.class) {
constant = (int)left.constant == (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant == (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant == (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant == (double)right.constant;
} else {
constant = left.constant == right.constant;
@ -190,7 +189,7 @@ public final class EComp extends AExpression {
"[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
if (promotedType.sort == Sort.DEF) {
if (promotedType.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
} else {
@ -206,17 +205,17 @@ public final class EComp extends AExpression {
}
if ((left.constant != null || left.isNull) && (right.constant != null || right.isNull)) {
Sort sort = promotedType.sort;
Class<?> sort = promotedType.clazz;
if (sort == Sort.BOOL) {
if (sort == boolean.class) {
constant = (boolean)left.constant != (boolean)right.constant;
} else if (sort == Sort.INT) {
} else if (sort == int.class) {
constant = (int)left.constant != (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant != (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant != (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant != (double)right.constant;
} else if (!left.isNull) {
constant = !left.constant.equals(right.constant);
@ -252,17 +251,17 @@ public final class EComp extends AExpression {
}
if ((left.constant != null || left.isNull) && (right.constant != null || right.isNull)) {
Sort sort = promotedType.sort;
Class<?> sort = promotedType.clazz;
if (sort == Sort.BOOL) {
if (sort == boolean.class) {
constant = (boolean)left.constant != (boolean)right.constant;
} else if (sort == Sort.INT) {
} else if (sort == int.class) {
constant = (int)left.constant != (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant != (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant != (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant != (double)right.constant;
} else {
constant = left.constant != right.constant;
@ -283,7 +282,7 @@ public final class EComp extends AExpression {
"[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
if (promotedType.sort == Sort.DEF) {
if (promotedType.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
} else {
@ -295,15 +294,15 @@ public final class EComp extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promotedType.sort;
Class<?> sort = promotedType.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant >= (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant >= (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant >= (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant >= (double)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -324,7 +323,7 @@ public final class EComp extends AExpression {
"[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
if (promotedType.sort == Sort.DEF) {
if (promotedType.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
} else {
@ -336,15 +335,15 @@ public final class EComp extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promotedType.sort;
Class<?> sort = promotedType.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant > (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant > (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant > (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant > (double)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -365,7 +364,7 @@ public final class EComp extends AExpression {
"[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
if (promotedType.sort == Sort.DEF) {
if (promotedType.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
} else {
@ -377,15 +376,15 @@ public final class EComp extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promotedType.sort;
Class<?> sort = promotedType.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant <= (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant <= (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant <= (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant <= (double)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -406,7 +405,7 @@ public final class EComp extends AExpression {
"[" + left.actual.name + "] and [" + right.actual.name + "]."));
}
if (promotedType.sort == Sort.DEF) {
if (promotedType.dynamic) {
left.expected = left.actual;
right.expected = right.actual;
} else {
@ -418,15 +417,15 @@ public final class EComp extends AExpression {
right = right.cast(variables);
if (left.constant != null && right.constant != null) {
Sort sort = promotedType.sort;
Class<?> sort = promotedType.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = (int)left.constant < (int)right.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = (long)left.constant < (long)right.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = (float)left.constant < (float)right.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = (double)left.constant < (double)right.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -458,96 +457,86 @@ public final class EComp extends AExpression {
boolean writejump = true;
switch (promotedType.sort) {
case VOID:
case BYTE:
case SHORT:
case CHAR:
Class<?> sort = promotedType.clazz;
if (sort == void.class || sort == byte.class || sort == short.class || sort == char.class) {
throw createError(new IllegalStateException("Illegal tree structure."));
} else if (sort == boolean.class) {
if (eq) writer.ifCmp(promotedType.type, MethodWriter.EQ, jump);
else if (ne) writer.ifCmp(promotedType.type, MethodWriter.NE, jump);
else {
throw createError(new IllegalStateException("Illegal tree structure."));
case BOOL:
if (eq) writer.ifCmp(promotedType.type, MethodWriter.EQ, jump);
else if (ne) writer.ifCmp(promotedType.type, MethodWriter.NE, jump);
else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
}
} else if (sort == int.class || sort == long.class || sort == float.class || sort == double.class) {
if (eq) writer.ifCmp(promotedType.type, MethodWriter.EQ, jump);
else if (ne) writer.ifCmp(promotedType.type, MethodWriter.NE, jump);
else if (lt) writer.ifCmp(promotedType.type, MethodWriter.LT, jump);
else if (lte) writer.ifCmp(promotedType.type, MethodWriter.LE, jump);
else if (gt) writer.ifCmp(promotedType.type, MethodWriter.GT, jump);
else if (gte) writer.ifCmp(promotedType.type, MethodWriter.GE, jump);
else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
break;
case INT:
case LONG:
case FLOAT:
case DOUBLE:
if (eq) writer.ifCmp(promotedType.type, MethodWriter.EQ, jump);
else if (ne) writer.ifCmp(promotedType.type, MethodWriter.NE, jump);
else if (lt) writer.ifCmp(promotedType.type, MethodWriter.LT, jump);
else if (lte) writer.ifCmp(promotedType.type, MethodWriter.LE, jump);
else if (gt) writer.ifCmp(promotedType.type, MethodWriter.GT, jump);
else if (gte) writer.ifCmp(promotedType.type, MethodWriter.GE, jump);
else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
} else if (promotedType.dynamic) {
org.objectweb.asm.Type booleanType = org.objectweb.asm.Type.getType(boolean.class);
org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(booleanType, left.actual.type, right.actual.type);
break;
case DEF:
org.objectweb.asm.Type booleanType = org.objectweb.asm.Type.getType(boolean.class);
org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(booleanType, left.actual.type, right.actual.type);
if (eq) {
if (right.isNull) {
writer.ifNull(jump);
} else if (!left.isNull && operation == Operation.EQ) {
writer.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL);
writejump = false;
} else {
writer.ifCmp(promotedType.type, MethodWriter.EQ, jump);
}
} else if (ne) {
if (right.isNull) {
writer.ifNonNull(jump);
} else if (!left.isNull && operation == Operation.NE) {
writer.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL);
writer.ifZCmp(MethodWriter.EQ, jump);
} else {
writer.ifCmp(promotedType.type, MethodWriter.NE, jump);
}
} else if (lt) {
writer.invokeDefCall("lt", descriptor, DefBootstrap.BINARY_OPERATOR, 0);
writejump = false;
} else if (lte) {
writer.invokeDefCall("lte", descriptor, DefBootstrap.BINARY_OPERATOR, 0);
writejump = false;
} else if (gt) {
writer.invokeDefCall("gt", descriptor, DefBootstrap.BINARY_OPERATOR, 0);
writejump = false;
} else if (gte) {
writer.invokeDefCall("gte", descriptor, DefBootstrap.BINARY_OPERATOR, 0);
if (eq) {
if (right.isNull) {
writer.ifNull(jump);
} else if (!left.isNull && operation == Operation.EQ) {
writer.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL);
writejump = false;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
writer.ifCmp(promotedType.type, MethodWriter.EQ, jump);
}
break;
default:
if (eq) {
if (right.isNull) {
writer.ifNull(jump);
} else if (operation == Operation.EQ) {
writer.invokeStatic(OBJECTS_TYPE, EQUALS);
writejump = false;
} else {
writer.ifCmp(promotedType.type, MethodWriter.EQ, jump);
}
} else if (ne) {
if (right.isNull) {
writer.ifNonNull(jump);
} else if (operation == Operation.NE) {
writer.invokeStatic(OBJECTS_TYPE, EQUALS);
writer.ifZCmp(MethodWriter.EQ, jump);
} else {
writer.ifCmp(promotedType.type, MethodWriter.NE, jump);
}
} else if (ne) {
if (right.isNull) {
writer.ifNonNull(jump);
} else if (!left.isNull && operation == Operation.NE) {
writer.invokeDefCall("eq", descriptor, DefBootstrap.BINARY_OPERATOR, DefBootstrap.OPERATOR_ALLOWS_NULL);
writer.ifZCmp(MethodWriter.EQ, jump);
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
writer.ifCmp(promotedType.type, MethodWriter.NE, jump);
}
} else if (lt) {
writer.invokeDefCall("lt", descriptor, DefBootstrap.BINARY_OPERATOR, 0);
writejump = false;
} else if (lte) {
writer.invokeDefCall("lte", descriptor, DefBootstrap.BINARY_OPERATOR, 0);
writejump = false;
} else if (gt) {
writer.invokeDefCall("gt", descriptor, DefBootstrap.BINARY_OPERATOR, 0);
writejump = false;
} else if (gte) {
writer.invokeDefCall("gte", descriptor, DefBootstrap.BINARY_OPERATOR, 0);
writejump = false;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
} else {
if (eq) {
if (right.isNull) {
writer.ifNull(jump);
} else if (operation == Operation.EQ) {
writer.invokeStatic(OBJECTS_TYPE, EQUALS);
writejump = false;
} else {
writer.ifCmp(promotedType.type, MethodWriter.EQ, jump);
}
} else if (ne) {
if (right.isNull) {
writer.ifNonNull(jump);
} else if (operation == Operation.NE) {
writer.invokeStatic(OBJECTS_TYPE, EQUALS);
writer.ifZCmp(MethodWriter.EQ, jump);
} else {
writer.ifCmp(promotedType.type, MethodWriter.NE, jump);
}
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
}
if (writejump) {

View File

@ -21,7 +21,6 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Definition.Sort;
import java.util.Set;
@ -73,20 +72,17 @@ final class EConstant extends AExpression {
@Override
void write(MethodWriter writer, Globals globals) {
Sort sort = actual.sort;
switch (sort) {
case STRING: writer.push((String)constant); break;
case DOUBLE: writer.push((double)constant); break;
case FLOAT: writer.push((float)constant); break;
case LONG: writer.push((long)constant); break;
case INT: writer.push((int)constant); break;
case CHAR: writer.push((char)constant); break;
case SHORT: writer.push((short)constant); break;
case BYTE: writer.push((byte)constant); break;
case BOOL: writer.push((boolean)constant); break;
default:
throw createError(new IllegalStateException("Illegal tree structure."));
if (actual.clazz == String.class) writer.push((String)constant);
else if (actual.clazz == double.class) writer.push((double)constant);
else if (actual.clazz == float.class) writer.push((float)constant);
else if (actual.clazz == long.class) writer.push((long)constant);
else if (actual.clazz == int.class) writer.push((int)constant);
else if (actual.clazz == char.class) writer.push((char)constant);
else if (actual.clazz == short.class) writer.push((short)constant);
else if (actual.clazz == byte.class) writer.push((byte)constant);
else if (actual.clazz == boolean.class) writer.push((boolean)constant);
else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
}

View File

@ -54,8 +54,8 @@ public class EElvis extends AExpression {
@Override
void analyze(Locals locals) {
if (expected != null && expected.sort.primitive) {
throw createError(new IllegalArgumentException("Evlis operator cannot return primitives"));
if (expected != null && expected.clazz.isPrimitive()) {
throw createError(new IllegalArgumentException("Elvis operator cannot return primitives"));
}
lhs.expected = expected;
lhs.explicit = explicit;
@ -73,7 +73,7 @@ public class EElvis extends AExpression {
if (lhs.constant != null) {
throw createError(new IllegalArgumentException("Extraneous elvis operator. LHS is a constant."));
}
if (lhs.actual.sort.primitive) {
if (lhs.actual.clazz.isPrimitive()) {
throw createError(new IllegalArgumentException("Extraneous elvis operator. LHS is a primitive."));
}
if (rhs.isNull) {

View File

@ -65,7 +65,7 @@ public final class EInstanceof extends AExpression {
}
// map to wrapped type for primitive types
resolvedType = type.sort.primitive ? type.sort.boxed : type.clazz;
resolvedType = type.clazz.isPrimitive() ? Definition.getBoxedType(type).clazz : type.clazz;
// analyze and cast the expression
expression.analyze(locals);
@ -73,9 +73,9 @@ public final class EInstanceof extends AExpression {
expression = expression.cast(locals);
// record if the expression returns a primitive
primitiveExpression = expression.actual.sort.primitive;
primitiveExpression = expression.actual.clazz.isPrimitive();
// map to wrapped type for primitive types
expressionType = expression.actual.sort.primitive ? expression.actual.sort.boxed : type.clazz;
expressionType = expression.actual.clazz.isPrimitive() ? Definition.getBoxedType(expression.actual).clazz : type.clazz;
actual = Definition.BOOLEAN_TYPE;
}

View File

@ -52,7 +52,7 @@ public final class ENull extends AExpression {
isNull = true;
if (expected != null) {
if (expected.sort.primitive) {
if (expected.clazz.isPrimitive()) {
throw createError(new IllegalArgumentException("Cannot cast null to a primitive type [" + expected.name + "]."));
}

View File

@ -22,7 +22,6 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.Definition.Sort;
import java.util.Objects;
import java.util.Set;
@ -87,16 +86,16 @@ public final class ENumeric extends AExpression {
}
} else {
try {
Sort sort = expected == null ? Sort.INT : expected.sort;
Class<?> sort = expected == null ? int.class : expected.clazz;
int integer = Integer.parseInt(value, radix);
if (sort == Sort.BYTE && integer >= Byte.MIN_VALUE && integer <= Byte.MAX_VALUE) {
if (sort == byte.class && integer >= Byte.MIN_VALUE && integer <= Byte.MAX_VALUE) {
constant = (byte)integer;
actual = Definition.BYTE_TYPE;
} else if (sort == Sort.CHAR && integer >= Character.MIN_VALUE && integer <= Character.MAX_VALUE) {
} else if (sort == char.class && integer >= Character.MIN_VALUE && integer <= Character.MAX_VALUE) {
constant = (char)integer;
actual = Definition.CHAR_TYPE;
} else if (sort == Sort.SHORT && integer >= Short.MIN_VALUE && integer <= Short.MAX_VALUE) {
} else if (sort == short.class && integer >= Short.MIN_VALUE && integer <= Short.MAX_VALUE) {
constant = (short)integer;
actual = Definition.SHORT_TYPE;
} else {

View File

@ -22,7 +22,6 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.DefBootstrap;
@ -101,18 +100,18 @@ public final class EUnary extends AExpression {
child = child.cast(variables);
if (child.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = ~(int)child.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = ~(long)child.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
}
if (promote.sort == Sort.DEF && expected != null) {
if (promote.dynamic && expected != null) {
actual = expected;
} else {
actual = promote;
@ -132,22 +131,22 @@ public final class EUnary extends AExpression {
child = child.cast(variables);
if (child.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = +(int)child.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = +(long)child.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = +(float)child.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = +(double)child.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
}
if (promote.sort == Sort.DEF && expected != null) {
if (promote.dynamic && expected != null) {
actual = expected;
} else {
actual = promote;
@ -167,22 +166,22 @@ public final class EUnary extends AExpression {
child = child.cast(variables);
if (child.constant != null) {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
if (sort == Sort.INT) {
if (sort == int.class) {
constant = -(int)child.constant;
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
constant = -(long)child.constant;
} else if (sort == Sort.FLOAT) {
} else if (sort == float.class) {
constant = -(float)child.constant;
} else if (sort == Sort.DOUBLE) {
} else if (sort == double.class) {
constant = -(double)child.constant;
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
}
}
if (promote.sort == Sort.DEF && expected != null) {
if (promote.dynamic && expected != null) {
actual = expected;
} else {
actual = promote;
@ -206,7 +205,7 @@ public final class EUnary extends AExpression {
writer.push(true);
writer.mark(end);
} else {
Sort sort = promote.sort;
Class<?> sort = promote.clazz;
child.write(writer, globals);
// Def calls adopt the wanted return value. If there was a narrowing cast,
@ -218,13 +217,13 @@ public final class EUnary extends AExpression {
}
if (operation == Operation.BWNOT) {
if (sort == Sort.DEF) {
if (promote.dynamic) {
org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type);
writer.invokeDefCall("not", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags);
} else {
if (sort == Sort.INT) {
if (sort == int.class) {
writer.push(-1);
} else if (sort == Sort.LONG) {
} else if (sort == long.class) {
writer.push(-1L);
} else {
throw createError(new IllegalStateException("Illegal tree structure."));
@ -233,14 +232,14 @@ public final class EUnary extends AExpression {
writer.math(MethodWriter.XOR, actual.type);
}
} else if (operation == Operation.SUB) {
if (sort == Sort.DEF) {
if (promote.dynamic) {
org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type);
writer.invokeDefCall("neg", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags);
} else {
writer.math(MethodWriter.NEG, actual.type);
}
} else if (operation == Operation.ADD) {
if (sort == Sort.DEF) {
if (promote.dynamic) {
org.objectweb.asm.Type descriptor = org.objectweb.asm.Type.getMethodType(actual.type, child.actual.type);
writer.invokeDefCall("plus", descriptor, DefBootstrap.UNARY_OPERATOR, defFlags);
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
@ -58,11 +57,9 @@ public final class PBrace extends AStoreable {
prefix.expected = prefix.actual;
prefix = prefix.cast(locals);
Sort sort = prefix.actual.sort;
if (sort == Sort.ARRAY) {
if (prefix.actual.dimensions > 0) {
sub = new PSubBrace(location, prefix.actual, index);
} else if (sort == Sort.DEF) {
} else if (prefix.actual.dynamic) {
sub = new PSubDefArray(location, index);
} else if (Map.class.isAssignableFrom(prefix.actual.clazz)) {
sub = new PSubMapShortcut(location, prefix.actual.struct, index);

View File

@ -19,9 +19,9 @@
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.MethodKey;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Struct;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
@ -66,14 +66,14 @@ public final class PCallInvoke extends AExpression {
prefix.expected = prefix.actual;
prefix = prefix.cast(locals);
if (prefix.actual.sort == Sort.ARRAY) {
if (prefix.actual.dimensions > 0) {
throw createError(new IllegalArgumentException("Illegal call [" + name + "] on array type."));
}
Struct struct = prefix.actual.struct;
if (prefix.actual.sort.primitive) {
struct = locals.getDefinition().getType(prefix.actual.sort.boxed.getSimpleName()).struct;
if (prefix.actual.clazz.isPrimitive()) {
struct = Definition.getBoxedType(prefix.actual).struct;
}
MethodKey methodKey = new MethodKey(name, arguments.size());
@ -81,7 +81,7 @@ public final class PCallInvoke extends AExpression {
if (method != null) {
sub = new PSubCallInvoke(location, method, prefix.actual, arguments);
} else if (prefix.actual.sort == Sort.DEF) {
} else if (prefix.actual.dynamic) {
sub = new PSubDefCall(location, name, arguments);
} else {
throw createError(new IllegalArgumentException(

View File

@ -22,7 +22,6 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Field;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Struct;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
@ -63,11 +62,9 @@ public final class PField extends AStoreable {
prefix.expected = prefix.actual;
prefix = prefix.cast(locals);
Sort sort = prefix.actual.sort;
if (sort == Sort.ARRAY) {
if (prefix.actual.dimensions > 0) {
sub = new PSubArrayLength(location, prefix.actual.name, value);
} else if (sort == Sort.DEF) {
} else if (prefix.actual.dynamic) {
sub = new PSubDefField(location, value);
} else {
Struct struct = prefix.actual.struct;

View File

@ -71,7 +71,7 @@ final class PSubCallInvoke extends AExpression {
void write(MethodWriter writer, Globals globals) {
writer.writeDebugInfo(location);
if (box.sort.primitive) {
if (box.clazz.isPrimitive()) {
writer.box(box.type);
}

View File

@ -21,7 +21,6 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Struct;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
@ -61,12 +60,12 @@ final class PSubListShortcut extends AStoreable {
getter = struct.methods.get(new Definition.MethodKey("get", 1));
setter = struct.methods.get(new Definition.MethodKey("set", 2));
if (getter != null && (getter.rtn.sort == Sort.VOID || getter.arguments.size() != 1 ||
getter.arguments.get(0).sort != Sort.INT)) {
if (getter != null && (getter.rtn.clazz == void.class || getter.arguments.size() != 1 ||
getter.arguments.get(0).clazz != int.class)) {
throw createError(new IllegalArgumentException("Illegal list get shortcut for type [" + struct.name + "]."));
}
if (setter != null && (setter.arguments.size() != 2 || setter.arguments.get(0).sort != Sort.INT)) {
if (setter != null && (setter.arguments.size() != 2 || setter.arguments.get(0).clazz != int.class)) {
throw createError(new IllegalArgumentException("Illegal list set shortcut for type [" + struct.name + "]."));
}
@ -132,7 +131,7 @@ final class PSubListShortcut extends AStoreable {
setter.write(writer);
writer.writePop(setter.rtn.sort.size);
writer.writePop(setter.rtn.type.getSize());
}
@Override

View File

@ -25,7 +25,6 @@ import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Sort;
import java.util.Objects;
import java.util.Set;
@ -61,7 +60,7 @@ final class PSubMapShortcut extends AStoreable {
getter = struct.methods.get(new Definition.MethodKey("get", 1));
setter = struct.methods.get(new Definition.MethodKey("put", 2));
if (getter != null && (getter.rtn.sort == Sort.VOID || getter.arguments.size() != 1)) {
if (getter != null && (getter.rtn.clazz == void.class || getter.arguments.size() != 1)) {
throw createError(new IllegalArgumentException("Illegal map get shortcut for type [" + struct.name + "]."));
}
@ -135,7 +134,7 @@ final class PSubMapShortcut extends AStoreable {
setter.write(writer);
writer.writePop(setter.rtn.sort.size);
writer.writePop(setter.rtn.type.getSize());
}
@Override

View File

@ -52,7 +52,7 @@ public class PSubNullSafeCallInvoke extends AExpression {
void analyze(Locals locals) {
guarded.analyze(locals);
actual = guarded.actual;
if (actual.sort.primitive) {
if (actual.clazz.isPrimitive()) {
throw new IllegalArgumentException("Result of null safe operator must be nullable");
}
}

View File

@ -52,7 +52,7 @@ public class PSubNullSafeField extends AStoreable {
guarded.read = read;
guarded.analyze(locals);
actual = guarded.actual;
if (actual.sort.primitive) {
if (actual.clazz.isPrimitive()) {
throw new IllegalArgumentException("Result of null safe operator must be nullable");
}
}

View File

@ -20,7 +20,6 @@
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
@ -55,12 +54,12 @@ final class PSubShortcut extends AStoreable {
@Override
void analyze(Locals locals) {
if (getter != null && (getter.rtn.sort == Sort.VOID || !getter.arguments.isEmpty())) {
if (getter != null && (getter.rtn.clazz == void.class || !getter.arguments.isEmpty())) {
throw createError(new IllegalArgumentException(
"Illegal get shortcut on field [" + value + "] for type [" + type + "]."));
}
if (setter != null && (setter.rtn.sort != Sort.VOID || setter.arguments.size() != 1)) {
if (setter != null && (setter.rtn.clazz != void.class || setter.arguments.size() != 1)) {
throw createError(new IllegalArgumentException(
"Illegal set shortcut on field [" + value + "] for type [" + type + "]."));
}
@ -124,7 +123,7 @@ final class PSubShortcut extends AStoreable {
setter.write(writer);
writer.writePop(setter.rtn.sort.size);
writer.writePop(setter.rtn.type.getSize());
}
@Override

View File

@ -82,17 +82,19 @@ public final class SDeclaration extends AStatement {
writer.writeStatementOffset(location);
if (expression == null) {
switch (variable.type.sort) {
case VOID: throw createError(new IllegalStateException("Illegal tree structure."));
case BOOL:
case BYTE:
case SHORT:
case CHAR:
case INT: writer.push(0); break;
case LONG: writer.push(0L); break;
case FLOAT: writer.push(0.0F); break;
case DOUBLE: writer.push(0.0); break;
default: writer.visitInsn(Opcodes.ACONST_NULL);
Class<?> sort = variable.type.clazz;
if (sort == void.class || sort == boolean.class || sort == byte.class ||
sort == short.class || sort == char.class || sort == int.class) {
writer.push(0);
} else if (sort == long.class) {
writer.push(0L);
} else if (sort == float.class) {
writer.push(0F);
} else if (sort == double.class) {
writer.push(0D);
} else {
writer.visitInsn(Opcodes.ACONST_NULL);
}
} else {
expression.write(writer, globals);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
@ -79,9 +78,9 @@ public class SEach extends AStatement {
locals = Locals.newLocalScope(locals);
Variable variable = locals.addVariable(location, type, name, true);
if (expression.actual.sort == Sort.ARRAY) {
if (expression.actual.dimensions > 0) {
sub = new SSubEachArray(location, variable, expression, block);
} else if (expression.actual.sort == Sort.DEF || Iterable.class.isAssignableFrom(expression.actual.clazz)) {
} else if (expression.actual.dynamic || Iterable.class.isAssignableFrom(expression.actual.clazz)) {
sub = new SSubEachIterable(location, variable, expression, block);
} else {
throw createError(new IllegalArgumentException("Illegal for each type [" + expression.actual.name + "]."));

View File

@ -19,7 +19,6 @@
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
@ -50,7 +49,7 @@ public final class SExpression extends AStatement {
@Override
void analyze(Locals locals) {
Type rtnType = locals.getReturnType();
boolean isVoid = rtnType.sort == Sort.VOID;
boolean isVoid = rtnType.clazz == void.class;
expression.read = lastSource && !isVoid;
expression.analyze(locals);
@ -59,7 +58,7 @@ public final class SExpression extends AStatement {
throw createError(new IllegalArgumentException("Not a statement."));
}
boolean rtn = lastSource && !isVoid && expression.actual.sort != Sort.VOID;
boolean rtn = lastSource && !isVoid && expression.actual.clazz != void.class;
expression.expected = rtn ? rtnType : expression.actual;
expression.internal = rtn;
@ -79,7 +78,7 @@ public final class SExpression extends AStatement {
if (methodEscape) {
writer.returnValue();
} else {
writer.writePop(expression.expected.sort.size);
writer.writePop(expression.expected.type.getSize());
}
}

View File

@ -161,7 +161,7 @@ public final class SFor extends AStatement {
AExpression initializer = (AExpression)this.initializer;
initializer.write(writer, globals);
writer.writePop(initializer.expected.sort.size);
writer.writePop(initializer.expected.type.getSize());
}
writer.mark(start);

View File

@ -24,7 +24,6 @@ import org.elasticsearch.painless.Constant;
import org.elasticsearch.painless.Def;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
@ -163,7 +162,7 @@ public final class SFunction extends AStatement {
allEscape = statement.allEscape;
}
if (!methodEscape && rtnType.sort != Sort.VOID) {
if (!methodEscape && rtnType.clazz != void.class) {
throw createError(new IllegalArgumentException("Not all paths provide a return value for method [" + name + "]."));
}
@ -198,7 +197,7 @@ public final class SFunction extends AStatement {
}
if (!methodEscape) {
if (rtnType.sort == Sort.VOID) {
if (rtnType.clazz == void.class) {
function.returnValue();
} else {
throw createError(new IllegalStateException("Illegal tree structure."));

View File

@ -25,7 +25,6 @@ import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.MethodKey;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Locals;
import org.elasticsearch.painless.Locals.Variable;
@ -74,7 +73,7 @@ final class SSubEachIterable extends AStatement {
iterator = locals.addVariable(location, locals.getDefinition().getType("Iterator"),
"#itr" + location.getOffset(), true);
if (expression.actual.sort == Sort.DEF) {
if (expression.actual.dynamic) {
method = null;
} else {
method = expression.actual.struct.methods.get(new MethodKey("iterator", 0));

View File

@ -142,6 +142,6 @@ public class ElvisTests extends ScriptTestCase {
private void assertCannotReturnPrimitive(String script) {
Exception e = expectScriptThrows(IllegalArgumentException.class, () -> exec(script));
assertEquals("Evlis operator cannot return primitives", e.getMessage());
assertEquals("Elvis operator cannot return primitives", e.getMessage());
}
}

View File

@ -69,7 +69,7 @@ public class PainlessDocGenerator {
emitGeneratedWarning(indexStream);
List<Type> types = Definition.allSimpleTypes().stream().sorted(comparing(t -> t.name)).collect(toList());
for (Type type : types) {
if (type.sort.primitive) {
if (type.clazz.isPrimitive()) {
// Primitives don't have methods to reference
continue;
}