Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Painless Type from e-nodes in favor of Java Class #28364

Merged
merged 3 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -606,10 +606,10 @@ public Type ClassToType(Class<?> clazz) {
++dimensions;
}

if (clazz == def.class) {
if (component == def.class) {
return getType(structsMap.get("def"), 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);
Expand All @@ -618,8 +618,8 @@ public Type ClassToType(Class<?> clazz) {
return getType(structsMap.get(ClassToName(clazz)), 0);
}

public static Class<?> TypeToClass (Type type) {
if (type.dynamic) {
public static Class<?> TypeToClass(Type type) {
if ("def".equals(type.struct.name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use def.class.getShortName()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated for all of Definition.

return ObjectClassTodefClass(type.clazz);
}

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