2121
2222import org .elasticsearch .painless .Definition .Method ;
2323import org .elasticsearch .painless .Definition .MethodKey ;
24- import org .elasticsearch .painless .Definition .Type ;
2524import org .elasticsearch .painless .ScriptClassInfo .MethodArgument ;
2625
2726import java .util .Arrays ;
@@ -58,7 +57,7 @@ public static Locals newLocalScope(Locals currentScope) {
5857 * <p>
5958 * This is just like {@link #newFunctionScope}, except the captured parameters are made read-only.
6059 */
61- public static Locals newLambdaScope (Locals programScope , Type returnType , List <Parameter > parameters ,
60+ public static Locals newLambdaScope (Locals programScope , Class <?> returnType , List <Parameter > parameters ,
6261 int captureCount , int maxLoopCounter ) {
6362 Locals locals = new Locals (programScope , programScope .definition , returnType , KEYWORDS );
6463 for (int i = 0 ; i < parameters .size (); i ++) {
@@ -68,43 +67,43 @@ public static Locals newLambdaScope(Locals programScope, Type returnType, List<P
6867 // currently, this cannot be allowed, as we swap in real types,
6968 // but that can prevent a store of a different type...
7069 boolean isCapture = true ;
71- locals .addVariable (parameter .location , parameter .type , parameter .name , isCapture );
70+ locals .addVariable (parameter .location , parameter .clazz , parameter .name , isCapture );
7271 }
7372 // Loop counter to catch infinite loops. Internal use only.
7473 if (maxLoopCounter > 0 ) {
75- locals .defineVariable (null , locals . getDefinition (). intType , LOOP , true );
74+ locals .defineVariable (null , int . class , LOOP , true );
7675 }
7776 return locals ;
7877 }
7978
8079 /** Creates a new function scope inside the current scope */
81- public static Locals newFunctionScope (Locals programScope , Type returnType , List <Parameter > parameters , int maxLoopCounter ) {
80+ public static Locals newFunctionScope (Locals programScope , Class <?> returnType , List <Parameter > parameters , int maxLoopCounter ) {
8281 Locals locals = new Locals (programScope , programScope .definition , returnType , KEYWORDS );
8382 for (Parameter parameter : parameters ) {
84- locals .addVariable (parameter .location , parameter .type , parameter .name , false );
83+ locals .addVariable (parameter .location , parameter .clazz , parameter .name , false );
8584 }
8685 // Loop counter to catch infinite loops. Internal use only.
8786 if (maxLoopCounter > 0 ) {
88- locals .defineVariable (null , locals . getDefinition (). intType , LOOP , true );
87+ locals .defineVariable (null , int . class , LOOP , true );
8988 }
9089 return locals ;
9190 }
9291
9392 /** Creates a new main method scope */
9493 public static Locals newMainMethodScope (ScriptClassInfo scriptClassInfo , Locals programScope , int maxLoopCounter ) {
95- Locals locals = new Locals (programScope , programScope . definition ,
96- scriptClassInfo .getExecuteMethodReturnType (), KEYWORDS );
94+ Locals locals = new Locals (
95+ programScope , programScope . definition , scriptClassInfo .getExecuteMethodReturnType (), KEYWORDS );
9796 // This reference. Internal use only.
98- locals .defineVariable (null , programScope . definition . getType ( " Object" ) , THIS , true );
97+ locals .defineVariable (null , Object . class , THIS , true );
9998
10099 // Method arguments
101100 for (MethodArgument arg : scriptClassInfo .getExecuteArguments ()) {
102- locals .defineVariable (null , arg .getType (), arg .getName (), true );
101+ locals .defineVariable (null , arg .getClazz (), arg .getName (), true );
103102 }
104103
105104 // Loop counter to catch infinite loops. Internal use only.
106105 if (maxLoopCounter > 0 ) {
107- locals .defineVariable (null , locals . getDefinition (). intType , LOOP , true );
106+ locals .defineVariable (null , int . class , LOOP , true );
108107 }
109108 return locals ;
110109 }
@@ -155,18 +154,18 @@ public Method getMethod(MethodKey key) {
155154 }
156155
157156 /** Creates a new variable. Throws IAE if the variable has already been defined (even in a parent) or reserved. */
158- public Variable addVariable (Location location , Type type , String name , boolean readonly ) {
157+ public Variable addVariable (Location location , Class <?> clazz , String name , boolean readonly ) {
159158 if (hasVariable (name )) {
160159 throw location .createError (new IllegalArgumentException ("Variable [" + name + "] is already defined." ));
161160 }
162161 if (keywords .contains (name )) {
163162 throw location .createError (new IllegalArgumentException ("Variable [" + name + "] is reserved." ));
164163 }
165- return defineVariable (location , type , name , readonly );
164+ return defineVariable (location , clazz , name , readonly );
166165 }
167166
168167 /** Return type of this scope (e.g. int, if inside a function that returns int) */
169- public Type getReturnType () {
168+ public Class <?> getReturnType () {
170169 return returnType ;
171170 }
172171
@@ -191,7 +190,7 @@ public Definition getDefinition() {
191190 // parent scope
192191 private final Locals parent ;
193192 // return type of this scope
194- private final Type returnType ;
193+ private final Class <?> returnType ;
195194 // keywords for this scope
196195 private final Set <String > keywords ;
197196 // next slot number to assign
@@ -211,7 +210,7 @@ private Locals(Locals parent) {
211210 /**
212211 * Create a new Locals with specified return type
213212 */
214- private Locals (Locals parent , Definition definition , Type returnType , Set <String > keywords ) {
213+ private Locals (Locals parent , Definition definition , Class <?> returnType , Set <String > keywords ) {
215214 this .parent = parent ;
216215 this .definition = definition ;
217216 this .returnType = returnType ;
@@ -246,13 +245,13 @@ private Method lookupMethod(MethodKey key) {
246245
247246
248247 /** Defines a variable at this scope internally. */
249- private Variable defineVariable (Location location , Type type , String name , boolean readonly ) {
248+ private Variable defineVariable (Location location , Class <?> type , String name , boolean readonly ) {
250249 if (variables == null ) {
251250 variables = new HashMap <>();
252251 }
253252 Variable variable = new Variable (location , name , type , getNextSlot (), readonly );
254253 variables .put (name , variable ); // TODO: check result
255- nextSlotNumber += type . type .getSize ();
254+ nextSlotNumber += MethodWriter . getType ( type ) .getSize ();
256255 return variable ;
257256 }
258257
@@ -272,15 +271,15 @@ private int getNextSlot() {
272271 public static final class Variable {
273272 public final Location location ;
274273 public final String name ;
275- public final Type type ;
274+ public final Class <?> clazz ;
276275 public final boolean readonly ;
277276 private final int slot ;
278277 private boolean used ;
279278
280- public Variable (Location location , String name , Type type , int slot , boolean readonly ) {
279+ public Variable (Location location , String name , Class <?> clazz , int slot , boolean readonly ) {
281280 this .location = location ;
282281 this .name = name ;
283- this .type = type ;
282+ this .clazz = clazz ;
284283 this .slot = slot ;
285284 this .readonly = readonly ;
286285 }
@@ -292,7 +291,7 @@ public int getSlot() {
292291 @ Override
293292 public String toString () {
294293 StringBuilder b = new StringBuilder ();
295- b .append ("Variable[type=" ).append (type );
294+ b .append ("Variable[type=" ).append (Definition . ClassToName ( clazz ) );
296295 b .append (",name=" ).append (name );
297296 b .append (",slot=" ).append (slot );
298297 if (readonly ) {
@@ -306,12 +305,12 @@ public String toString() {
306305 public static final class Parameter {
307306 public final Location location ;
308307 public final String name ;
309- public final Type type ;
308+ public final Class <?> clazz ;
310309
311- public Parameter (Location location , String name , Type type ) {
310+ public Parameter (Location location , String name , Class <?> clazz ) {
312311 this .location = location ;
313312 this .name = name ;
314- this .type = type ;
313+ this .clazz = clazz ;
315314 }
316315 }
317316}
0 commit comments