Skip to content

Commit f13da9f

Browse files
authored
Remove Painless Type from e-nodes in favor of Java Class (#28364)
1 parent 43d1dcb commit f13da9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+592
-676
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/Definition.java

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -452,60 +452,60 @@ public Type getType(final Struct struct, final int dimensions) {
452452
return getTypeInternal(struct, dimensions);
453453
}
454454

455-
public Type getBoxedType(Type unboxed) {
456-
if (unboxed.clazz == boolean.class) {
457-
return BooleanType;
458-
} else if (unboxed.clazz == byte.class) {
459-
return ByteType;
460-
} else if (unboxed.clazz == short.class) {
461-
return ShortType;
462-
} else if (unboxed.clazz == char.class) {
463-
return CharacterType;
464-
} else if (unboxed.clazz == int.class) {
465-
return IntegerType;
466-
} else if (unboxed.clazz == long.class) {
467-
return LongType;
468-
} else if (unboxed.clazz == float.class) {
469-
return FloatType;
470-
} else if (unboxed.clazz == double.class) {
471-
return DoubleType;
472-
}
473-
474-
return unboxed;
455+
public static Class<?> getBoxedType(Class<?> clazz) {
456+
if (clazz == boolean.class) {
457+
return Boolean.class;
458+
} else if (clazz == byte.class) {
459+
return Byte.class;
460+
} else if (clazz == short.class) {
461+
return Short.class;
462+
} else if (clazz == char.class) {
463+
return Character.class;
464+
} else if (clazz == int.class) {
465+
return Integer.class;
466+
} else if (clazz == long.class) {
467+
return Long.class;
468+
} else if (clazz == float.class) {
469+
return Float.class;
470+
} else if (clazz == double.class) {
471+
return Double.class;
472+
}
473+
474+
return clazz;
475475
}
476476

477-
public Type getUnboxedType(Type boxed) {
478-
if (boxed.clazz == Boolean.class) {
479-
return booleanType;
480-
} else if (boxed.clazz == Byte.class) {
481-
return byteType;
482-
} else if (boxed.clazz == Short.class) {
483-
return shortType;
484-
} else if (boxed.clazz == Character.class) {
485-
return charType;
486-
} else if (boxed.clazz == Integer.class) {
487-
return intType;
488-
} else if (boxed.clazz == Long.class) {
489-
return longType;
490-
} else if (boxed.clazz == Float.class) {
491-
return floatType;
492-
} else if (boxed.clazz == Double.class) {
493-
return doubleType;
494-
}
495-
496-
return boxed;
477+
public static Class<?> getUnboxedype(Class<?> clazz) {
478+
if (clazz == Boolean.class) {
479+
return boolean.class;
480+
} else if (clazz == Byte.class) {
481+
return byte.class;
482+
} else if (clazz == Short.class) {
483+
return short.class;
484+
} else if (clazz == Character.class) {
485+
return char.class;
486+
} else if (clazz == Integer.class) {
487+
return int.class;
488+
} else if (clazz == Long.class) {
489+
return long.class;
490+
} else if (clazz == Float.class) {
491+
return float.class;
492+
} else if (clazz == Double.class) {
493+
return double.class;
494+
}
495+
496+
return clazz;
497497
}
498498

499-
public static boolean isConstantType(Type constant) {
500-
return constant.clazz == boolean.class ||
501-
constant.clazz == byte.class ||
502-
constant.clazz == short.class ||
503-
constant.clazz == char.class ||
504-
constant.clazz == int.class ||
505-
constant.clazz == long.class ||
506-
constant.clazz == float.class ||
507-
constant.clazz == double.class ||
508-
constant.clazz == String.class;
499+
public static boolean isConstantType(Class<?> clazz) {
500+
return clazz == boolean.class ||
501+
clazz == byte.class ||
502+
clazz == short.class ||
503+
clazz == char.class ||
504+
clazz == int.class ||
505+
clazz == long.class ||
506+
clazz == float.class ||
507+
clazz == double.class ||
508+
clazz == String.class;
509509
}
510510

511511
public static Class<?> ObjectClassTodefClass(Class<?> clazz) {
@@ -579,7 +579,7 @@ public static String ClassToName(Class<?> clazz) {
579579
}
580580

581581
if (component == def.class) {
582-
StringBuilder builder = new StringBuilder("def");
582+
StringBuilder builder = new StringBuilder(def.class.getSimpleName());
583583

584584
for (int dimension = 0; dimension < dimensions; dimensions++) {
585585
builder.append("[]");
@@ -588,7 +588,7 @@ public static String ClassToName(Class<?> clazz) {
588588
return builder.toString();
589589
}
590590
} else if (clazz == def.class) {
591-
return "def";
591+
return def.class.getSimpleName();
592592
}
593593

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

609-
if (clazz == def.class) {
610-
return getType(structsMap.get("def"), dimensions);
609+
if (component == def.class) {
610+
return getType(structsMap.get(def.class.getSimpleName()), dimensions);
611611
} else {
612-
return getType(runtimeMap.get(clazz).struct, dimensions);
612+
return getType(runtimeMap.get(component).struct, dimensions);
613613
}
614614
} else if (clazz == def.class) {
615-
return getType(structsMap.get("def"), 0);
615+
return getType(structsMap.get(def.class.getSimpleName()), 0);
616616
}
617617

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

621-
public static Class<?> TypeToClass (Type type) {
622-
if (type.dynamic) {
621+
public static Class<?> TypeToClass(Type type) {
622+
if (def.class.getSimpleName().equals(type.struct.name)) {
623623
return ObjectClassTodefClass(type.clazz);
624624
}
625625

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

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

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

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

783784
if (painlessObjectStruct != null) {
@@ -835,7 +836,7 @@ public Definition(List<Whitelist> whitelists) {
835836
charType = getType("char");
836837
CharacterType = getType("Character");
837838
ObjectType = getType("Object");
838-
DefType = getType("def");
839+
DefType = getType(def.class.getSimpleName());
839840
NumberType = getType("Number");
840841
StringType = getType("String");
841842
ExceptionType = getType("Exception");
@@ -1409,7 +1410,7 @@ private Type getTypeInternal(Struct struct, int dimensions) {
14091410
}
14101411
}
14111412

1412-
return new Type(name, dimensions, "def".equals(name), struct, clazz, type);
1413+
return new Type(name, dimensions, def.class.getSimpleName().equals(name), struct, clazz, type);
14131414
}
14141415

14151416
private int getDimensions(String name) {

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AExpression.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.elasticsearch.painless.AnalyzerCaster;
2323
import org.elasticsearch.painless.Definition;
2424
import org.elasticsearch.painless.Definition.Cast;
25-
import org.elasticsearch.painless.Definition.Type;
2625
import org.elasticsearch.painless.Locals;
2726
import org.elasticsearch.painless.Location;
2827

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

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

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

125123
if (cast == null) {
126124
if (constant == null || this instanceof EConstant) {

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/AStoreable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.painless.node;
2121

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

9190
/**
9291
* Called before a storeable node is loaded or stored. Used to load prefixes and

0 commit comments

Comments
 (0)