Skip to content

Commit

Permalink
Remove Painless Type from e-nodes in favor of Java Class (#28364)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdconrad authored Jan 29, 2018
1 parent 43d1dcb commit f13da9f
Show file tree
Hide file tree
Showing 58 changed files with 592 additions and 676 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,60 +452,60 @@ public Type getType(final Struct struct, final int dimensions) {
return getTypeInternal(struct, dimensions);
}

public Type getBoxedType(Type unboxed) {
if (unboxed.clazz == boolean.class) {
return BooleanType;
} else if (unboxed.clazz == byte.class) {
return ByteType;
} else if (unboxed.clazz == short.class) {
return ShortType;
} else if (unboxed.clazz == char.class) {
return CharacterType;
} else if (unboxed.clazz == int.class) {
return IntegerType;
} else if (unboxed.clazz == long.class) {
return LongType;
} else if (unboxed.clazz == float.class) {
return FloatType;
} else if (unboxed.clazz == double.class) {
return DoubleType;
}

return unboxed;
public static Class<?> getBoxedType(Class<?> clazz) {
if (clazz == boolean.class) {
return Boolean.class;
} else if (clazz == byte.class) {
return Byte.class;
} else if (clazz == short.class) {
return Short.class;
} else if (clazz == char.class) {
return Character.class;
} else if (clazz == int.class) {
return Integer.class;
} else if (clazz == long.class) {
return Long.class;
} else if (clazz == float.class) {
return Float.class;
} else if (clazz == double.class) {
return Double.class;
}

return clazz;
}

public Type getUnboxedType(Type boxed) {
if (boxed.clazz == Boolean.class) {
return booleanType;
} else if (boxed.clazz == Byte.class) {
return byteType;
} else if (boxed.clazz == Short.class) {
return shortType;
} else if (boxed.clazz == Character.class) {
return charType;
} else if (boxed.clazz == Integer.class) {
return intType;
} else if (boxed.clazz == Long.class) {
return longType;
} else if (boxed.clazz == Float.class) {
return floatType;
} else if (boxed.clazz == Double.class) {
return doubleType;
}

return boxed;
public static Class<?> getUnboxedype(Class<?> clazz) {
if (clazz == Boolean.class) {
return boolean.class;
} else if (clazz == Byte.class) {
return byte.class;
} else if (clazz == Short.class) {
return short.class;
} else if (clazz == Character.class) {
return char.class;
} else if (clazz == Integer.class) {
return int.class;
} else if (clazz == Long.class) {
return long.class;
} else if (clazz == Float.class) {
return float.class;
} else if (clazz == Double.class) {
return double.class;
}

return clazz;
}

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 static boolean isConstantType(Class<?> clazz) {
return clazz == boolean.class ||
clazz == byte.class ||
clazz == short.class ||
clazz == char.class ||
clazz == int.class ||
clazz == long.class ||
clazz == float.class ||
clazz == double.class ||
clazz == String.class;
}

public static Class<?> ObjectClassTodefClass(Class<?> clazz) {
Expand Down Expand Up @@ -579,7 +579,7 @@ public static String ClassToName(Class<?> clazz) {
}

if (component == def.class) {
StringBuilder builder = new StringBuilder("def");
StringBuilder builder = new StringBuilder(def.class.getSimpleName());

for (int dimension = 0; dimension < dimensions; dimensions++) {
builder.append("[]");
Expand All @@ -588,7 +588,7 @@ public static String ClassToName(Class<?> clazz) {
return builder.toString();
}
} else if (clazz == def.class) {
return "def";
return def.class.getSimpleName();
}

return clazz.getCanonicalName().replace('$', '.');
Expand All @@ -606,20 +606,20 @@ public Type ClassToType(Class<?> clazz) {
++dimensions;
}

if (clazz == def.class) {
return getType(structsMap.get("def"), dimensions);
if (component == def.class) {
return getType(structsMap.get(def.class.getSimpleName()), dimensions);
} else {
return getType(runtimeMap.get(clazz).struct, dimensions);
return getType(runtimeMap.get(component).struct, dimensions);
}
} else if (clazz == def.class) {
return getType(structsMap.get("def"), 0);
return getType(structsMap.get(def.class.getSimpleName()), 0);
}

return getType(structsMap.get(ClassToName(clazz)), 0);
}

public static Class<?> TypeToClass (Type type) {
if (type.dynamic) {
public static Class<?> TypeToClass(Type type) {
if (def.class.getSimpleName().equals(type.struct.name)) {
return ObjectClassTodefClass(type.clazz);
}

Expand Down Expand Up @@ -672,7 +672,8 @@ public Definition(List<Whitelist> whitelists) {
String origin = null;

// add the universal def type
structsMap.put("def", new Struct("def", Object.class, org.objectweb.asm.Type.getType(Object.class)));
structsMap.put(def.class.getSimpleName(),
new Struct(def.class.getSimpleName(), Object.class, org.objectweb.asm.Type.getType(Object.class)));

try {
// first iteration collects all the Painless type names that
Expand Down Expand Up @@ -777,7 +778,7 @@ public Definition(List<Whitelist> whitelists) {
copyStruct(painlessStruct.name, painlessSuperStructs);

// copies methods and fields from Object into interface types
if (painlessStruct.clazz.isInterface() || ("def").equals(painlessStruct.name)) {
if (painlessStruct.clazz.isInterface() || (def.class.getSimpleName()).equals(painlessStruct.name)) {
Struct painlessObjectStruct = javaClassesToPainlessStructs.get(Object.class);

if (painlessObjectStruct != null) {
Expand Down Expand Up @@ -835,7 +836,7 @@ public Definition(List<Whitelist> whitelists) {
charType = getType("char");
CharacterType = getType("Character");
ObjectType = getType("Object");
DefType = getType("def");
DefType = getType(def.class.getSimpleName());
NumberType = getType("Number");
StringType = getType("String");
ExceptionType = getType("Exception");
Expand Down Expand Up @@ -1409,7 +1410,7 @@ private Type getTypeInternal(Struct struct, int dimensions) {
}
}

return new Type(name, dimensions, "def".equals(name), struct, clazz, type);
return new Type(name, dimensions, def.class.getSimpleName().equals(name), struct, clazz, type);
}

private int getDimensions(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
import org.elasticsearch.painless.Location;

Expand Down Expand Up @@ -60,15 +59,15 @@ public abstract class AExpression extends ANode {
* Set to the expected type this node needs to be. Note this variable
* is always set by the parent as input and should never be read from.
*/
Type expected = null;
Class<?> expected = null;

/**
* Set to the actual type this node is. Note this variable is always
* set by the node as output and should only be read from outside of the
* node itself. <b>Also, actual can always be read after a cast is
* called on this node to get the type of the node after the cast.</b>
*/
Type actual = null;
Class<?> actual = null;

/**
* Set by {@link EExplicit} if a cast made on an expression node should be
Expand Down Expand Up @@ -119,8 +118,7 @@ public abstract class AExpression extends ANode {
* @return The new child node for the parent node calling this method.
*/
AExpression cast(Locals locals) {
Cast cast =
AnalyzerCaster.getLegalCast(location, Definition.TypeToClass(actual), Definition.TypeToClass(expected), explicit, internal);
Cast cast = AnalyzerCaster.getLegalCast(location, actual, expected, explicit, internal);

if (cast == null) {
if (constant == null || this instanceof EConstant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.painless.node;

import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Globals;
import org.elasticsearch.painless.Location;
import org.elasticsearch.painless.MethodWriter;
Expand Down Expand Up @@ -86,7 +85,7 @@ abstract class AStoreable extends AExpression {
* actual will be set to this value. This is used for an optimization
* during assignment to def type targets.
*/
abstract void updateActual(Type actual);
abstract void updateActual(Class<?> actual);

/**
* Called before a storeable node is loaded or stored. Used to load prefixes and
Expand Down
Loading

0 comments on commit f13da9f

Please sign in to comment.