21
21
22
22
23
23
import org .elasticsearch .painless .AnalyzerCaster ;
24
+ import org .elasticsearch .painless .ClassWriter ;
24
25
import org .elasticsearch .painless .CompilerSettings ;
25
26
import org .elasticsearch .painless .DefBootstrap ;
26
27
import org .elasticsearch .painless .Globals ;
@@ -250,8 +251,8 @@ private void analyzeSimple(Locals locals) {
250
251
* also read from.
251
252
*/
252
253
@ Override
253
- void write (MethodWriter writer , Globals globals ) {
254
- writer .writeDebugInfo (location );
254
+ void write (ClassWriter classWriter , MethodWriter methodWriter , Globals globals ) {
255
+ methodWriter .writeDebugInfo (location );
255
256
256
257
// For the case where the assignment represents a String concatenation
257
258
// we must, depending on the Java version, write a StringBuilder or
@@ -261,84 +262,87 @@ void write(MethodWriter writer, Globals globals) {
261
262
int catElementStackSize = 0 ;
262
263
263
264
if (cat ) {
264
- catElementStackSize = writer .writeNewStrings ();
265
+ catElementStackSize = methodWriter .writeNewStrings ();
265
266
}
266
267
267
268
// Cast the lhs to a storeable to perform the necessary operations to store the rhs.
268
269
AStoreable lhs = (AStoreable )this .lhs ;
269
- lhs .setup (writer , globals ); // call the setup method on the lhs to prepare for a load/store operation
270
+ lhs .setup (classWriter , methodWriter , globals ); // call the setup method on the lhs to prepare for a load/store operation
270
271
271
272
if (cat ) {
272
273
// Handle the case where we are doing a compound assignment
273
274
// representing a String concatenation.
274
275
275
- writer .writeDup (lhs .accessElementCount (), catElementStackSize ); // dup the top element and insert it
276
+ methodWriter .writeDup (lhs .accessElementCount (), catElementStackSize ); // dup the top element and insert it
276
277
// before concat helper on stack
277
- lhs .load (writer , globals ); // read the current lhs's value
278
- writer .writeAppendStrings (lhs .actual ); // append the lhs's value using the StringBuilder
278
+ lhs .load (classWriter , methodWriter , globals ); // read the current lhs's value
279
+ methodWriter .writeAppendStrings (lhs .actual ); // append the lhs's value using the StringBuilder
279
280
280
- rhs .write (writer , globals ); // write the bytecode for the rhs
281
+ rhs .write (classWriter , methodWriter , globals ); // write the bytecode for the rhs
281
282
282
283
if (!(rhs instanceof EBinary ) || !((EBinary )rhs ).cat ) { // check to see if the rhs has already done a concatenation
283
- writer .writeAppendStrings (rhs .actual ); // append the rhs's value since it's hasn't already
284
+ methodWriter .writeAppendStrings (rhs .actual ); // append the rhs's value since it's hasn't already
284
285
}
285
286
286
- writer .writeToStrings (); // put the value for string concat onto the stack
287
- writer .writeCast (back ); // if necessary, cast the String to the lhs actual type
287
+ methodWriter .writeToStrings (); // put the value for string concat onto the stack
288
+ methodWriter .writeCast (back ); // if necessary, cast the String to the lhs actual type
288
289
289
290
if (lhs .read ) {
290
- writer .writeDup (MethodWriter .getType (lhs .actual ).getSize (), lhs .accessElementCount ()); // if this lhs is also read
291
+ methodWriter .writeDup (MethodWriter .getType (lhs .actual ).getSize (), lhs .accessElementCount ()); // if this lhs is also read
291
292
// from dup the value onto the stack
292
293
}
293
294
294
- lhs .store (writer , globals ); // store the lhs's value from the stack in its respective variable/field/array
295
+ lhs .store (classWriter , methodWriter , globals ); // store the lhs's value from the stack in its respective variable/field/array
295
296
} else if (operation != null ) {
296
297
// Handle the case where we are doing a compound assignment that
297
298
// does not represent a String concatenation.
298
299
299
- writer .writeDup (lhs .accessElementCount (), 0 ); // if necessary, dup the previous lhs's value
300
- // to be both loaded from and stored to
301
- lhs .load (writer , globals ); // load the current lhs's value
300
+ methodWriter .writeDup (lhs .accessElementCount (), 0 ); // if necessary, dup the previous lhs's value
301
+ // to be both loaded from and stored to
302
+ lhs .load (classWriter , methodWriter , globals ); // load the current lhs's value
302
303
303
304
if (lhs .read && post ) {
304
- writer .writeDup (MethodWriter .getType (lhs .actual ).getSize (), lhs .accessElementCount ()); // dup the value if the lhs is also
305
- // read from and is a post increment
305
+ methodWriter .writeDup (MethodWriter .getType (lhs .actual ).getSize (), lhs .accessElementCount ()); // dup the value if the
306
+ // lhs is also
307
+ // read from and is a post
308
+ // increment
306
309
}
307
310
308
- writer .writeCast (there ); // if necessary cast the current lhs's value
309
- // to the promotion type between the lhs and rhs types
310
- rhs .write (writer , globals ); // write the bytecode for the rhs
311
+ methodWriter .writeCast (there ); // if necessary cast the current lhs's value
312
+ // to the promotion type between the lhs and rhs types
313
+ rhs .write (classWriter , methodWriter , globals ); // write the bytecode for the rhs
311
314
312
315
// XXX: fix these types, but first we need def compound assignment tests.
313
316
// its tricky here as there are possibly explicit casts, too.
314
317
// write the operation instruction for compound assignment
315
318
if (promote == def .class ) {
316
- writer .writeDynamicBinaryInstruction (
319
+ methodWriter .writeDynamicBinaryInstruction (
317
320
location , promote , def .class , def .class , operation , DefBootstrap .OPERATOR_COMPOUND_ASSIGNMENT );
318
321
} else {
319
- writer .writeBinaryInstruction (location , promote , operation );
322
+ methodWriter .writeBinaryInstruction (location , promote , operation );
320
323
}
321
324
322
- writer .writeCast (back ); // if necessary cast the promotion type value back to the lhs's type
325
+ methodWriter .writeCast (back ); // if necessary cast the promotion type value back to the lhs's type
323
326
324
327
if (lhs .read && !post ) {
325
- writer .writeDup (MethodWriter .getType (lhs .actual ).getSize (), lhs .accessElementCount ()); // dup the value if the lhs is also
326
- // read from and is not a post
327
- // increment
328
+ methodWriter .writeDup (MethodWriter .getType (lhs .actual ).getSize (), lhs .accessElementCount ()); // dup the value if the lhs
329
+ // is also
330
+ // read from and is not a post
331
+ // increment
328
332
}
329
333
330
- lhs .store (writer , globals ); // store the lhs's value from the stack in its respective variable/field/array
334
+ lhs .store (classWriter , methodWriter , globals ); // store the lhs's value from the stack in its respective variable/field/array
331
335
} else {
332
336
// Handle the case for a simple write.
333
337
334
- rhs .write (writer , globals ); // write the bytecode for the rhs rhs
338
+ rhs .write (classWriter , methodWriter , globals ); // write the bytecode for the rhs rhs
335
339
336
340
if (lhs .read ) {
337
- writer .writeDup (MethodWriter .getType (lhs .actual ).getSize (), lhs .accessElementCount ()); // dup the value if the lhs
341
+ methodWriter .writeDup (MethodWriter .getType (lhs .actual ).getSize (), lhs .accessElementCount ()); // dup the value if the lhs
338
342
// is also read from
339
343
}
340
344
341
- lhs .store (writer , globals ); // store the lhs's value from the stack in its respective variable/field/array
345
+ lhs .store (classWriter , methodWriter , globals ); // store the lhs's value from the stack in its respective variable/field/array
342
346
}
343
347
}
344
348
0 commit comments