painless: Refactor WriterUtils to extends ASM GeneratorAdapter as "MethodWriter" for easy usage (and more coming later)

This commit is contained in:
Uwe Schindler 2016-05-17 02:25:05 +02:00
parent ed74e53cf5
commit 75f27df376
49 changed files with 346 additions and 340 deletions

View File

@ -23,9 +23,11 @@ import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Transform;
import org.elasticsearch.painless.Definition.Type;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.objectweb.asm.commons.Method;
import static org.elasticsearch.painless.WriterConstants.ADDEXACT_INT;
import static org.elasticsearch.painless.WriterConstants.ADDEXACT_LONG;
@ -88,43 +90,61 @@ import static org.elasticsearch.painless.WriterConstants.TOSHORTWOOVERFLOW_DOUBL
import static org.elasticsearch.painless.WriterConstants.TOSHORTWOOVERFLOW_FLOAT;
/**
* Extension of {@link GeneratorAdapter} with some utility methods.
* <p>
* Set of methods used during the writing phase of compilation
* shared by the nodes of the Painless tree.
*/
public final class WriterUtility {
public final class MethodWriter extends GeneratorAdapter {
public static void writeLoopCounter(final GeneratorAdapter adapter, final int slot, final int count) {
MethodWriter(int access, Method method, org.objectweb.asm.Type[] exceptions, ClassVisitor cv) {
super(Opcodes.ASM5, cv.visitMethod(access, method.getName(), method.getDescriptor(), null, getInternalNames(exceptions)),
access, method.getName(), method.getDescriptor());
}
private static String[] getInternalNames(final org.objectweb.asm.Type[] types) {
if (types == null) {
return null;
}
String[] names = new String[types.length];
for (int i = 0; i < names.length; ++i) {
names[i] = types[i].getInternalName();
}
return names;
}
public void writeLoopCounter(final int slot, final int count) {
if (slot > -1) {
final Label end = new Label();
adapter.iinc(slot, -count);
adapter.visitVarInsn(Opcodes.ILOAD, slot);
adapter.push(0);
adapter.ifICmp(GeneratorAdapter.GT, end);
adapter.throwException(PAINLESS_ERROR_TYPE,
iinc(slot, -count);
visitVarInsn(Opcodes.ILOAD, slot);
push(0);
ifICmp(GeneratorAdapter.GT, end);
throwException(PAINLESS_ERROR_TYPE,
"The maximum number of statements that can be executed in a loop has been reached.");
adapter.mark(end);
mark(end);
}
}
public static void writeCast(final GeneratorAdapter adapter, final Cast cast) {
public void writeCast(final Cast cast) {
if (cast instanceof Transform) {
final Transform transform = (Transform)cast;
if (transform.upcast != null) {
adapter.checkCast(transform.upcast.type);
checkCast(transform.upcast.type);
}
if (java.lang.reflect.Modifier.isStatic(transform.method.reflect.getModifiers())) {
adapter.invokeStatic(transform.method.owner.type, transform.method.method);
invokeStatic(transform.method.owner.type, transform.method.method);
} else if (java.lang.reflect.Modifier.isInterface(transform.method.owner.clazz.getModifiers())) {
adapter.invokeInterface(transform.method.owner.type, transform.method.method);
invokeInterface(transform.method.owner.type, transform.method.method);
} else {
adapter.invokeVirtual(transform.method.owner.type, transform.method.method);
invokeVirtual(transform.method.owner.type, transform.method.method);
}
if (transform.downcast != null) {
adapter.checkCast(transform.downcast.type);
checkCast(transform.downcast.type);
}
} else if (cast != null) {
final Type from = cast.from;
@ -135,50 +155,50 @@ public final class WriterUtility {
}
if (from.sort.numeric && from.sort.primitive && to.sort.numeric && to.sort.primitive) {
adapter.cast(from.type, to.type);
cast(from.type, to.type);
} else {
if (!to.clazz.isAssignableFrom(from.clazz)) {
adapter.checkCast(to.type);
checkCast(to.type);
}
}
}
}
public static void writeBranch(final GeneratorAdapter adapter, final Label tru, final Label fals) {
public void writeBranch(final Label tru, final Label fals) {
if (tru != null) {
adapter.visitJumpInsn(Opcodes.IFNE, tru);
visitJumpInsn(Opcodes.IFNE, tru);
} else if (fals != null) {
adapter.visitJumpInsn(Opcodes.IFEQ, fals);
visitJumpInsn(Opcodes.IFEQ, fals);
}
}
public static void writeNewStrings(final GeneratorAdapter adapter) {
adapter.newInstance(STRINGBUILDER_TYPE);
adapter.dup();
adapter.invokeConstructor(STRINGBUILDER_TYPE, STRINGBUILDER_CONSTRUCTOR);
public void writeNewStrings() {
newInstance(STRINGBUILDER_TYPE);
dup();
invokeConstructor(STRINGBUILDER_TYPE, STRINGBUILDER_CONSTRUCTOR);
}
public static void writeAppendStrings(final GeneratorAdapter adapter, final Sort sort) {
public void writeAppendStrings(final Sort sort) {
switch (sort) {
case BOOL: adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_BOOLEAN); break;
case CHAR: adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_CHAR); break;
case BOOL: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_BOOLEAN); break;
case CHAR: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_CHAR); break;
case BYTE:
case SHORT:
case INT: adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_INT); break;
case LONG: adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_LONG); break;
case FLOAT: adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_FLOAT); break;
case DOUBLE: adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_DOUBLE); break;
case STRING: adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_STRING); break;
default: adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_OBJECT);
case INT: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_INT); break;
case LONG: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_LONG); break;
case FLOAT: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_FLOAT); break;
case DOUBLE: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_DOUBLE); break;
case STRING: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_STRING); break;
default: invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_APPEND_OBJECT);
}
}
public static void writeToStrings(final GeneratorAdapter adapter) {
adapter.invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_TOSTRING);
public void writeToStrings() {
invokeVirtual(STRINGBUILDER_TYPE, STRINGBUILDER_TOSTRING);
}
public static void writeBinaryInstruction(final CompilerSettings settings, final Definition definition,
final GeneratorAdapter adapter, final String location,
public void writeBinaryInstruction(final CompilerSettings settings, final Definition definition,
final String location,
final Type type, final Operation operation) {
final Sort sort = type.sort;
boolean exact = !settings.getNumericOverflow() &&
@ -193,29 +213,29 @@ public final class WriterUtility {
switch (sort) {
case INT:
switch (operation) {
case MUL: adapter.invokeStatic(definition.mathType.type, MULEXACT_INT); break;
case DIV: adapter.invokeStatic(definition.utilityType.type, DIVWOOVERLOW_INT); break;
case ADD: adapter.invokeStatic(definition.mathType.type, ADDEXACT_INT); break;
case SUB: adapter.invokeStatic(definition.mathType.type, SUBEXACT_INT); break;
case MUL: invokeStatic(definition.mathType.type, MULEXACT_INT); break;
case DIV: invokeStatic(definition.utilityType.type, DIVWOOVERLOW_INT); break;
case ADD: invokeStatic(definition.mathType.type, ADDEXACT_INT); break;
case SUB: invokeStatic(definition.mathType.type, SUBEXACT_INT); break;
}
break;
case LONG:
switch (operation) {
case MUL: adapter.invokeStatic(definition.mathType.type, MULEXACT_LONG); break;
case DIV: adapter.invokeStatic(definition.utilityType.type, DIVWOOVERLOW_LONG); break;
case ADD: adapter.invokeStatic(definition.mathType.type, ADDEXACT_LONG); break;
case SUB: adapter.invokeStatic(definition.mathType.type, SUBEXACT_LONG); break;
case MUL: invokeStatic(definition.mathType.type, MULEXACT_LONG); break;
case DIV: invokeStatic(definition.utilityType.type, DIVWOOVERLOW_LONG); break;
case ADD: invokeStatic(definition.mathType.type, ADDEXACT_LONG); break;
case SUB: invokeStatic(definition.mathType.type, SUBEXACT_LONG); break;
}
break;
case FLOAT:
switch (operation) {
case MUL: adapter.invokeStatic(definition.utilityType.type, MULWOOVERLOW_FLOAT); break;
case DIV: adapter.invokeStatic(definition.utilityType.type, DIVWOOVERLOW_FLOAT); break;
case REM: adapter.invokeStatic(definition.utilityType.type, REMWOOVERLOW_FLOAT); break;
case ADD: adapter.invokeStatic(definition.utilityType.type, ADDWOOVERLOW_FLOAT); break;
case SUB: adapter.invokeStatic(definition.utilityType.type, SUBWOOVERLOW_FLOAT); break;
case MUL: invokeStatic(definition.utilityType.type, MULWOOVERLOW_FLOAT); break;
case DIV: invokeStatic(definition.utilityType.type, DIVWOOVERLOW_FLOAT); break;
case REM: invokeStatic(definition.utilityType.type, REMWOOVERLOW_FLOAT); break;
case ADD: invokeStatic(definition.utilityType.type, ADDWOOVERLOW_FLOAT); break;
case SUB: invokeStatic(definition.utilityType.type, SUBWOOVERLOW_FLOAT); break;
default:
throw new IllegalStateException("Error " + location + ": Illegal tree structure.");
}
@ -223,11 +243,11 @@ public final class WriterUtility {
break;
case DOUBLE:
switch (operation) {
case MUL: adapter.invokeStatic(definition.utilityType.type, MULWOOVERLOW_DOUBLE); break;
case DIV: adapter.invokeStatic(definition.utilityType.type, DIVWOOVERLOW_DOUBLE); break;
case REM: adapter.invokeStatic(definition.utilityType.type, REMWOOVERLOW_DOUBLE); break;
case ADD: adapter.invokeStatic(definition.utilityType.type, ADDWOOVERLOW_DOUBLE); break;
case SUB: adapter.invokeStatic(definition.utilityType.type, SUBWOOVERLOW_DOUBLE); break;
case MUL: invokeStatic(definition.utilityType.type, MULWOOVERLOW_DOUBLE); break;
case DIV: invokeStatic(definition.utilityType.type, DIVWOOVERLOW_DOUBLE); break;
case REM: invokeStatic(definition.utilityType.type, REMWOOVERLOW_DOUBLE); break;
case ADD: invokeStatic(definition.utilityType.type, ADDWOOVERLOW_DOUBLE); break;
case SUB: invokeStatic(definition.utilityType.type, SUBWOOVERLOW_DOUBLE); break;
default:
throw new IllegalStateException("Error " + location + ": Illegal tree structure.");
}
@ -246,33 +266,33 @@ public final class WriterUtility {
if (sort == Sort.DEF) {
switch (operation) {
case MUL: adapter.invokeStatic(definition.defobjType.type, DEF_MUL_CALL); break;
case DIV: adapter.invokeStatic(definition.defobjType.type, DEF_DIV_CALL); break;
case REM: adapter.invokeStatic(definition.defobjType.type, DEF_REM_CALL); break;
case ADD: adapter.invokeStatic(definition.defobjType.type, DEF_ADD_CALL); break;
case SUB: adapter.invokeStatic(definition.defobjType.type, DEF_SUB_CALL); break;
case LSH: adapter.invokeStatic(definition.defobjType.type, DEF_LSH_CALL); break;
case USH: adapter.invokeStatic(definition.defobjType.type, DEF_RSH_CALL); break;
case RSH: adapter.invokeStatic(definition.defobjType.type, DEF_USH_CALL); break;
case BWAND: adapter.invokeStatic(definition.defobjType.type, DEF_AND_CALL); break;
case XOR: adapter.invokeStatic(definition.defobjType.type, DEF_XOR_CALL); break;
case BWOR: adapter.invokeStatic(definition.defobjType.type, DEF_OR_CALL); break;
case MUL: invokeStatic(definition.defobjType.type, DEF_MUL_CALL); break;
case DIV: invokeStatic(definition.defobjType.type, DEF_DIV_CALL); break;
case REM: invokeStatic(definition.defobjType.type, DEF_REM_CALL); break;
case ADD: invokeStatic(definition.defobjType.type, DEF_ADD_CALL); break;
case SUB: invokeStatic(definition.defobjType.type, DEF_SUB_CALL); break;
case LSH: invokeStatic(definition.defobjType.type, DEF_LSH_CALL); break;
case USH: invokeStatic(definition.defobjType.type, DEF_RSH_CALL); break;
case RSH: invokeStatic(definition.defobjType.type, DEF_USH_CALL); break;
case BWAND: invokeStatic(definition.defobjType.type, DEF_AND_CALL); break;
case XOR: invokeStatic(definition.defobjType.type, DEF_XOR_CALL); break;
case BWOR: invokeStatic(definition.defobjType.type, DEF_OR_CALL); break;
default:
throw new IllegalStateException("Error " + location + ": Illegal tree structure.");
}
} else {
switch (operation) {
case MUL: adapter.math(GeneratorAdapter.MUL, type.type); break;
case DIV: adapter.math(GeneratorAdapter.DIV, type.type); break;
case REM: adapter.math(GeneratorAdapter.REM, type.type); break;
case ADD: adapter.math(GeneratorAdapter.ADD, type.type); break;
case SUB: adapter.math(GeneratorAdapter.SUB, type.type); break;
case LSH: adapter.math(GeneratorAdapter.SHL, type.type); break;
case USH: adapter.math(GeneratorAdapter.USHR, type.type); break;
case RSH: adapter.math(GeneratorAdapter.SHR, type.type); break;
case BWAND: adapter.math(GeneratorAdapter.AND, type.type); break;
case XOR: adapter.math(GeneratorAdapter.XOR, type.type); break;
case BWOR: adapter.math(GeneratorAdapter.OR, type.type); break;
case MUL: math(GeneratorAdapter.MUL, type.type); break;
case DIV: math(GeneratorAdapter.DIV, type.type); break;
case REM: math(GeneratorAdapter.REM, type.type); break;
case ADD: math(GeneratorAdapter.ADD, type.type); break;
case SUB: math(GeneratorAdapter.SUB, type.type); break;
case LSH: math(GeneratorAdapter.SHL, type.type); break;
case USH: math(GeneratorAdapter.USHR, type.type); break;
case RSH: math(GeneratorAdapter.SHR, type.type); break;
case BWAND: math(GeneratorAdapter.AND, type.type); break;
case XOR: math(GeneratorAdapter.XOR, type.type); break;
case BWOR: math(GeneratorAdapter.OR, type.type); break;
default:
throw new IllegalStateException("Error " + location + ": Illegal tree structure.");
}
@ -287,111 +307,111 @@ public final class WriterUtility {
*
* @return This will be true if an instruction is written, false otherwise.
*/
public static boolean writeExactInstruction(
final Definition definition, final GeneratorAdapter adapter, final Sort fsort, final Sort tsort) {
public boolean writeExactInstruction(
final Definition definition, final Sort fsort, final Sort tsort) {
if (fsort == Sort.DOUBLE) {
if (tsort == Sort.FLOAT) {
adapter.invokeStatic(definition.utilityType.type, TOFLOATWOOVERFLOW_DOUBLE);
invokeStatic(definition.utilityType.type, TOFLOATWOOVERFLOW_DOUBLE);
} else if (tsort == Sort.FLOAT_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOFLOATWOOVERFLOW_DOUBLE);
adapter.checkCast(definition.floatobjType.type);
invokeStatic(definition.utilityType.type, TOFLOATWOOVERFLOW_DOUBLE);
checkCast(definition.floatobjType.type);
} else if (tsort == Sort.LONG) {
adapter.invokeStatic(definition.utilityType.type, TOLONGWOOVERFLOW_DOUBLE);
invokeStatic(definition.utilityType.type, TOLONGWOOVERFLOW_DOUBLE);
} else if (tsort == Sort.LONG_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOLONGWOOVERFLOW_DOUBLE);
adapter.checkCast(definition.longobjType.type);
invokeStatic(definition.utilityType.type, TOLONGWOOVERFLOW_DOUBLE);
checkCast(definition.longobjType.type);
} else if (tsort == Sort.INT) {
adapter.invokeStatic(definition.utilityType.type, TOINTWOOVERFLOW_DOUBLE);
invokeStatic(definition.utilityType.type, TOINTWOOVERFLOW_DOUBLE);
} else if (tsort == Sort.INT_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOINTWOOVERFLOW_DOUBLE);
adapter.checkCast(definition.intobjType.type);
invokeStatic(definition.utilityType.type, TOINTWOOVERFLOW_DOUBLE);
checkCast(definition.intobjType.type);
} else if (tsort == Sort.CHAR) {
adapter.invokeStatic(definition.utilityType.type, TOCHARWOOVERFLOW_DOUBLE);
invokeStatic(definition.utilityType.type, TOCHARWOOVERFLOW_DOUBLE);
} else if (tsort == Sort.CHAR_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOCHARWOOVERFLOW_DOUBLE);
adapter.checkCast(definition.charobjType.type);
invokeStatic(definition.utilityType.type, TOCHARWOOVERFLOW_DOUBLE);
checkCast(definition.charobjType.type);
} else if (tsort == Sort.SHORT) {
adapter.invokeStatic(definition.utilityType.type, TOSHORTWOOVERFLOW_DOUBLE);
invokeStatic(definition.utilityType.type, TOSHORTWOOVERFLOW_DOUBLE);
} else if (tsort == Sort.SHORT_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOSHORTWOOVERFLOW_DOUBLE);
adapter.checkCast(definition.shortobjType.type);
invokeStatic(definition.utilityType.type, TOSHORTWOOVERFLOW_DOUBLE);
checkCast(definition.shortobjType.type);
} else if (tsort == Sort.BYTE) {
adapter.invokeStatic(definition.utilityType.type, TOBYTEWOOVERFLOW_DOUBLE);
invokeStatic(definition.utilityType.type, TOBYTEWOOVERFLOW_DOUBLE);
} else if (tsort == Sort.BYTE_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOBYTEWOOVERFLOW_DOUBLE);
adapter.checkCast(definition.byteobjType.type);
invokeStatic(definition.utilityType.type, TOBYTEWOOVERFLOW_DOUBLE);
checkCast(definition.byteobjType.type);
} else {
return false;
}
} else if (fsort == Sort.FLOAT) {
if (tsort == Sort.LONG) {
adapter.invokeStatic(definition.utilityType.type, TOLONGWOOVERFLOW_FLOAT);
invokeStatic(definition.utilityType.type, TOLONGWOOVERFLOW_FLOAT);
} else if (tsort == Sort.LONG_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOLONGWOOVERFLOW_FLOAT);
adapter.checkCast(definition.longobjType.type);
invokeStatic(definition.utilityType.type, TOLONGWOOVERFLOW_FLOAT);
checkCast(definition.longobjType.type);
} else if (tsort == Sort.INT) {
adapter.invokeStatic(definition.utilityType.type, TOINTWOOVERFLOW_FLOAT);
invokeStatic(definition.utilityType.type, TOINTWOOVERFLOW_FLOAT);
} else if (tsort == Sort.INT_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOINTWOOVERFLOW_FLOAT);
adapter.checkCast(definition.intobjType.type);
invokeStatic(definition.utilityType.type, TOINTWOOVERFLOW_FLOAT);
checkCast(definition.intobjType.type);
} else if (tsort == Sort.CHAR) {
adapter.invokeStatic(definition.utilityType.type, TOCHARWOOVERFLOW_FLOAT);
invokeStatic(definition.utilityType.type, TOCHARWOOVERFLOW_FLOAT);
} else if (tsort == Sort.CHAR_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOCHARWOOVERFLOW_FLOAT);
adapter.checkCast(definition.charobjType.type);
invokeStatic(definition.utilityType.type, TOCHARWOOVERFLOW_FLOAT);
checkCast(definition.charobjType.type);
} else if (tsort == Sort.SHORT) {
adapter.invokeStatic(definition.utilityType.type, TOSHORTWOOVERFLOW_FLOAT);
invokeStatic(definition.utilityType.type, TOSHORTWOOVERFLOW_FLOAT);
} else if (tsort == Sort.SHORT_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOSHORTWOOVERFLOW_FLOAT);
adapter.checkCast(definition.shortobjType.type);
invokeStatic(definition.utilityType.type, TOSHORTWOOVERFLOW_FLOAT);
checkCast(definition.shortobjType.type);
} else if (tsort == Sort.BYTE) {
adapter.invokeStatic(definition.utilityType.type, TOBYTEWOOVERFLOW_FLOAT);
invokeStatic(definition.utilityType.type, TOBYTEWOOVERFLOW_FLOAT);
} else if (tsort == Sort.BYTE_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOBYTEWOOVERFLOW_FLOAT);
adapter.checkCast(definition.byteobjType.type);
invokeStatic(definition.utilityType.type, TOBYTEWOOVERFLOW_FLOAT);
checkCast(definition.byteobjType.type);
} else {
return false;
}
} else if (fsort == Sort.LONG) {
if (tsort == Sort.INT) {
adapter.invokeStatic(definition.mathType.type, TOINTEXACT_LONG);
invokeStatic(definition.mathType.type, TOINTEXACT_LONG);
} else if (tsort == Sort.INT_OBJ) {
adapter.invokeStatic(definition.mathType.type, TOINTEXACT_LONG);
adapter.checkCast(definition.intobjType.type);
invokeStatic(definition.mathType.type, TOINTEXACT_LONG);
checkCast(definition.intobjType.type);
} else if (tsort == Sort.CHAR) {
adapter.invokeStatic(definition.utilityType.type, TOCHAREXACT_LONG);
invokeStatic(definition.utilityType.type, TOCHAREXACT_LONG);
} else if (tsort == Sort.CHAR_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOCHAREXACT_LONG);
adapter.checkCast(definition.charobjType.type);
invokeStatic(definition.utilityType.type, TOCHAREXACT_LONG);
checkCast(definition.charobjType.type);
} else if (tsort == Sort.SHORT) {
adapter.invokeStatic(definition.utilityType.type, TOSHORTEXACT_LONG);
invokeStatic(definition.utilityType.type, TOSHORTEXACT_LONG);
} else if (tsort == Sort.SHORT_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOSHORTEXACT_LONG);
adapter.checkCast(definition.shortobjType.type);
invokeStatic(definition.utilityType.type, TOSHORTEXACT_LONG);
checkCast(definition.shortobjType.type);
} else if (tsort == Sort.BYTE) {
adapter.invokeStatic(definition.utilityType.type, TOBYTEEXACT_LONG);
invokeStatic(definition.utilityType.type, TOBYTEEXACT_LONG);
} else if (tsort == Sort.BYTE_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOBYTEEXACT_LONG);
adapter.checkCast(definition.byteobjType.type);
invokeStatic(definition.utilityType.type, TOBYTEEXACT_LONG);
checkCast(definition.byteobjType.type);
} else {
return false;
}
} else if (fsort == Sort.INT) {
if (tsort == Sort.CHAR) {
adapter.invokeStatic(definition.utilityType.type, TOCHAREXACT_INT);
invokeStatic(definition.utilityType.type, TOCHAREXACT_INT);
} else if (tsort == Sort.CHAR_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOCHAREXACT_INT);
adapter.checkCast(definition.charobjType.type);
invokeStatic(definition.utilityType.type, TOCHAREXACT_INT);
checkCast(definition.charobjType.type);
} else if (tsort == Sort.SHORT) {
adapter.invokeStatic(definition.utilityType.type, TOSHORTEXACT_INT);
invokeStatic(definition.utilityType.type, TOSHORTEXACT_INT);
} else if (tsort == Sort.SHORT_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOSHORTEXACT_INT);
adapter.checkCast(definition.shortobjType.type);
invokeStatic(definition.utilityType.type, TOSHORTEXACT_INT);
checkCast(definition.shortobjType.type);
} else if (tsort == Sort.BYTE) {
adapter.invokeStatic(definition.utilityType.type, TOBYTEEXACT_INT);
invokeStatic(definition.utilityType.type, TOBYTEEXACT_INT);
} else if (tsort == Sort.BYTE_OBJ) {
adapter.invokeStatic(definition.utilityType.type, TOBYTEEXACT_INT);
adapter.checkCast(definition.byteobjType.type);
invokeStatic(definition.utilityType.type, TOBYTEEXACT_INT);
checkCast(definition.byteobjType.type);
} else {
return false;
}
@ -402,33 +422,32 @@ public final class WriterUtility {
return true;
}
public static void writeDup(final GeneratorAdapter adapter, final int size, final int xsize) {
public void writeDup(final int size, final int xsize) {
if (size == 1) {
if (xsize == 2) {
adapter.dupX2();
dupX2();
} else if (xsize == 1) {
adapter.dupX1();
dupX1();
} else {
adapter.dup();
dup();
}
} else if (size == 2) {
if (xsize == 2) {
adapter.dup2X2();
dup2X2();
} else if (xsize == 1) {
adapter.dup2X1();
dup2X1();
} else {
adapter.dup2();
dup2();
}
}
}
public static void writePop(final GeneratorAdapter adapter, final int size) {
public void writePop(final int size) {
if (size == 1) {
adapter.pop();
pop();
} else if (size == 2) {
adapter.pop2();
pop2();
}
}
private WriterUtility() {}
}

View File

@ -53,7 +53,7 @@ final class Writer {
private final SSource root;
private final ClassWriter writer;
private final GeneratorAdapter adapter;
private final MethodWriter adapter;
private Writer(final CompilerSettings settings, final Definition definition,
String name, final String source, final Variables variables, final SSource root) {
@ -69,7 +69,7 @@ final class Writer {
writeBegin();
writeConstructor();
adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, EXECUTE, null, null, writer);
adapter = new MethodWriter(Opcodes.ACC_PUBLIC, EXECUTE, null, writer);
writeExecute();
writeEnd();

View File

@ -26,7 +26,7 @@ import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* The superclass for all E* (expression) nodes.
@ -106,7 +106,7 @@ public abstract class AExpression extends ANode {
/**
* Writes ASM based on the data collected during the analysis phase.
*/
abstract void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter);
abstract void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter);
/**
* Inserts {@link ECast} nodes into the tree for implicit casts. Also replaces

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* The superclass for all L* (link) nodes.
@ -92,17 +92,17 @@ public abstract class ALink extends ANode {
/**
* Write values before a load/store occurs such as an array index.
*/
abstract void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter);
abstract void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter);
/**
* Write a load for the specific link type.
*/
abstract void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter);
abstract void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter);
/**
* Write a store for the specific link type.
*/
abstract void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter);
abstract void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter);
/**
* Used to copy link data from one to another during analysis in the case of replacement.

View File

@ -19,8 +19,8 @@
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.MethodWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
/**
* The superclass for all other nodes.
@ -51,7 +51,7 @@ public abstract class ANode {
* <p>
* Currently we emit line number data for for leaf S-nodes
*/
void writeDebugInfo(GeneratorAdapter adapter) {
void writeDebugInfo(MethodWriter adapter) {
Label label = new Label();
adapter.visitLabel(label);
adapter.visitLineNumber(line, label);

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* The superclass for all S* (statement) nodes.
@ -121,5 +121,5 @@ public abstract class AStatement extends ANode {
/**
* Writes ASM based on the data collected during the analysis phase.
*/
abstract void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter);
abstract void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter);
}

View File

@ -19,15 +19,14 @@
package org.elasticsearch.painless.node;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.MethodWriter;
import org.elasticsearch.painless.Operation;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
/**
* Represents a binary math expression.
@ -495,34 +494,34 @@ public final class EBinary extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (actual.sort == Sort.STRING && operation == Operation.ADD) {
if (!cat) {
WriterUtility.writeNewStrings(adapter);
adapter.writeNewStrings();
}
left.write(settings, definition, adapter);
if (!(left instanceof EBinary) || ((EBinary)left).operation != Operation.ADD || left.actual.sort != Sort.STRING) {
WriterUtility.writeAppendStrings(adapter, left.actual.sort);
adapter.writeAppendStrings(left.actual.sort);
}
right.write(settings, definition, adapter);
if (!(right instanceof EBinary) || ((EBinary)right).operation != Operation.ADD || right.actual.sort != Sort.STRING) {
WriterUtility.writeAppendStrings(adapter, right.actual.sort);
adapter.writeAppendStrings(right.actual.sort);
}
if (!cat) {
WriterUtility.writeToStrings(adapter);
adapter.writeToStrings();
}
} else {
left.write(settings, definition, adapter);
right.write(settings, definition, adapter);
WriterUtility.writeBinaryInstruction(settings, definition, adapter, location, actual, operation);
adapter.writeBinaryInstruction(settings, definition, location, actual, operation);
}
WriterUtility.writeBranch(adapter, tru, fals);
adapter.writeBranch(tru, fals);
}
}

View File

@ -24,7 +24,7 @@ import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Operation;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a boolean expression.
@ -67,7 +67,7 @@ public final class EBool extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (tru != null || fals != null) {
if (operation == Operation.AND) {
final Label localfals = fals == null ? new Label() : fals;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a boolean constant.
@ -41,7 +41,7 @@ public final class EBoolean extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalArgumentException(error("Illegal tree structure."));
}
}

View File

@ -23,8 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents an implicit cast in most cases, though it will replace
@ -52,9 +51,9 @@ final class ECast extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
child.write(settings, definition, adapter);
WriterUtility.writeCast(adapter, cast);
WriterUtility.writeBranch(adapter, tru, fals);
adapter.writeCast(cast);
adapter.writeBranch(tru, fals);
}
}

View File

@ -27,8 +27,7 @@ import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.Operation;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.List;
@ -253,9 +252,9 @@ public final class EChain extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (cat) {
WriterUtility.writeNewStrings(adapter);
adapter.writeNewStrings();
}
final ALink last = links.get(links.size() - 1);
@ -265,43 +264,43 @@ public final class EChain extends AExpression {
if (link == last && link.store) {
if (cat) {
WriterUtility.writeDup(adapter, link.size, 1);
adapter.writeDup(link.size, 1);
link.load(settings, definition, adapter);
WriterUtility.writeAppendStrings(adapter, link.after.sort);
adapter.writeAppendStrings(link.after.sort);
expression.write(settings, definition, adapter);
if (!(expression instanceof EBinary) ||
((EBinary)expression).operation != Operation.ADD || expression.actual.sort != Sort.STRING) {
WriterUtility.writeAppendStrings(adapter, expression.actual.sort);
adapter.writeAppendStrings(expression.actual.sort);
}
WriterUtility.writeToStrings(adapter);
WriterUtility.writeCast(adapter, back);
adapter.writeToStrings();
adapter.writeCast(back);
if (link.load) {
WriterUtility.writeDup(adapter, link.after.sort.size, link.size);
adapter.writeDup(link.after.sort.size, link.size);
}
link.store(settings, definition, adapter);
} else if (operation != null) {
WriterUtility.writeDup(adapter, link.size, 0);
adapter.writeDup(link.size, 0);
link.load(settings, definition, adapter);
if (link.load && post) {
WriterUtility.writeDup(adapter, link.after.sort.size, link.size);
adapter.writeDup(link.after.sort.size, link.size);
}
WriterUtility.writeCast(adapter, there);
adapter.writeCast(there);
expression.write(settings, definition, adapter);
WriterUtility.writeBinaryInstruction(settings, definition, adapter, location, promote, operation);
adapter.writeBinaryInstruction(settings, definition, location, promote, operation);
if (!exact || !WriterUtility.writeExactInstruction(definition, adapter, promote.sort, link.after.sort)) {
WriterUtility.writeCast(adapter, back);
if (!exact || !adapter.writeExactInstruction(definition, promote.sort, link.after.sort)) {
adapter.writeCast(back);
}
if (link.load && !post) {
WriterUtility.writeDup(adapter, link.after.sort.size, link.size);
adapter.writeDup(link.after.sort.size, link.size);
}
link.store(settings, definition, adapter);
@ -309,7 +308,7 @@ public final class EChain extends AExpression {
expression.write(settings, definition, adapter);
if (link.load) {
WriterUtility.writeDup(adapter, link.after.sort.size, link.size);
adapter.writeDup(link.after.sort.size, link.size);
}
link.store(settings, definition, adapter);
@ -319,6 +318,6 @@ public final class EChain extends AExpression {
}
}
WriterUtility.writeBranch(adapter, tru, fals);
adapter.writeBranch(tru, fals);
}
}

View File

@ -27,7 +27,7 @@ import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.Operation;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import static org.elasticsearch.painless.WriterConstants.CHECKEQUALS;
import static org.elasticsearch.painless.WriterConstants.DEF_EQ_CALL;
@ -397,7 +397,7 @@ public final class EComp extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
final boolean branch = tru != null || fals != null;
final org.objectweb.asm.Type rtype = right.actual.type;
final Sort rsort = right.actual.sort;
@ -429,8 +429,8 @@ public final class EComp extends AExpression {
case CHAR:
throw new IllegalStateException(error("Illegal tree structure."));
case BOOL:
if (eq) adapter.ifZCmp(GeneratorAdapter.EQ, jump);
else if (ne) adapter.ifZCmp(GeneratorAdapter.NE, jump);
if (eq) adapter.ifZCmp(MethodWriter.EQ, jump);
else if (ne) adapter.ifZCmp(MethodWriter.NE, jump);
else {
throw new IllegalStateException(error("Illegal tree structure."));
}
@ -440,12 +440,12 @@ public final class EComp extends AExpression {
case LONG:
case FLOAT:
case DOUBLE:
if (eq) adapter.ifCmp(rtype, GeneratorAdapter.EQ, jump);
else if (ne) adapter.ifCmp(rtype, GeneratorAdapter.NE, jump);
else if (lt) adapter.ifCmp(rtype, GeneratorAdapter.LT, jump);
else if (lte) adapter.ifCmp(rtype, GeneratorAdapter.LE, jump);
else if (gt) adapter.ifCmp(rtype, GeneratorAdapter.GT, jump);
else if (gte) adapter.ifCmp(rtype, GeneratorAdapter.GE, jump);
if (eq) adapter.ifCmp(rtype, MethodWriter.EQ, jump);
else if (ne) adapter.ifCmp(rtype, MethodWriter.NE, jump);
else if (lt) adapter.ifCmp(rtype, MethodWriter.LT, jump);
else if (lte) adapter.ifCmp(rtype, MethodWriter.LE, jump);
else if (gt) adapter.ifCmp(rtype, MethodWriter.GT, jump);
else if (gte) adapter.ifCmp(rtype, MethodWriter.GE, jump);
else {
throw new IllegalStateException(error("Illegal tree structure."));
}
@ -458,16 +458,16 @@ public final class EComp extends AExpression {
} else if (!left.isNull && operation == Operation.EQ) {
adapter.invokeStatic(definition.defobjType.type, DEF_EQ_CALL);
} else {
adapter.ifCmp(rtype, GeneratorAdapter.EQ, jump);
adapter.ifCmp(rtype, MethodWriter.EQ, jump);
}
} else if (ne) {
if (right.isNull) {
adapter.ifNonNull(jump);
} else if (!left.isNull && operation == Operation.NE) {
adapter.invokeStatic(definition.defobjType.type, DEF_EQ_CALL);
adapter.ifZCmp(GeneratorAdapter.EQ, jump);
adapter.ifZCmp(MethodWriter.EQ, jump);
} else {
adapter.ifCmp(rtype, GeneratorAdapter.NE, jump);
adapter.ifCmp(rtype, MethodWriter.NE, jump);
}
} else if (lt) {
adapter.invokeStatic(definition.defobjType.type, DEF_LT_CALL);
@ -484,7 +484,7 @@ public final class EComp extends AExpression {
writejump = left.isNull || ne || operation == Operation.EQR;
if (branch && !writejump) {
adapter.ifZCmp(GeneratorAdapter.NE, jump);
adapter.ifZCmp(MethodWriter.NE, jump);
}
break;
@ -496,21 +496,21 @@ public final class EComp extends AExpression {
adapter.invokeStatic(definition.utilityType.type, CHECKEQUALS);
if (branch) {
adapter.ifZCmp(GeneratorAdapter.NE, jump);
adapter.ifZCmp(MethodWriter.NE, jump);
}
writejump = false;
} else {
adapter.ifCmp(rtype, GeneratorAdapter.EQ, jump);
adapter.ifCmp(rtype, MethodWriter.EQ, jump);
}
} else if (ne) {
if (right.isNull) {
adapter.ifNonNull(jump);
} else if (operation == Operation.NE) {
adapter.invokeStatic(definition.utilityType.type, CHECKEQUALS);
adapter.ifZCmp(GeneratorAdapter.EQ, jump);
adapter.ifZCmp(MethodWriter.EQ, jump);
} else {
adapter.ifCmp(rtype, GeneratorAdapter.NE, jump);
adapter.ifCmp(rtype, MethodWriter.NE, jump);
}
} else {
throw new IllegalStateException(error("Illegal tree structure."));

View File

@ -25,7 +25,7 @@ import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Respresents a conditional expression.
@ -77,7 +77,7 @@ public final class EConditional extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
final Label localfals = new Label();
final Label end = new Label();

View File

@ -23,8 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Respresents a constant. Note this replaces any other expression
@ -64,7 +63,7 @@ final class EConstant extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
final Sort sort = actual.sort;
switch (sort) {
@ -91,7 +90,7 @@ final class EConstant extends AExpression {
}
if (sort != Sort.BOOL) {
WriterUtility.writeBranch(adapter, tru, fals);
adapter.writeBranch(tru, fals);
}
}
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Respresents a decimal constant.
@ -57,7 +57,7 @@ public final class EDecimal extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalArgumentException(error("Illegal tree structure."));
}
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents an explicit cast.
@ -57,7 +57,7 @@ public final class EExplicit extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalArgumentException(error("Illegal tree structure."));
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a null constant.
@ -50,7 +50,7 @@ public final class ENull extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.visitInsn(Opcodes.ACONST_NULL);
}
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Respresents a non-decimal numeric constant.
@ -96,7 +96,7 @@ public final class ENumeric extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalArgumentException(error("Illegal tree structure."));
}
}

View File

@ -26,9 +26,8 @@ import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.Operation;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import static org.elasticsearch.painless.WriterConstants.DEF_NEG_CALL;
import static org.elasticsearch.painless.WriterConstants.DEF_NOT_CALL;
@ -169,7 +168,7 @@ public final class EUnary extends AExpression {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (operation == Operation.NOT) {
if (tru == null && fals == null) {
final Label localfals = new Label();
@ -206,14 +205,14 @@ public final class EUnary extends AExpression {
throw new IllegalStateException(error("Illegal tree structure."));
}
adapter.math(GeneratorAdapter.XOR, type);
adapter.math(MethodWriter.XOR, type);
}
} else if (operation == Operation.SUB) {
if (sort == Sort.DEF) {
adapter.invokeStatic(definition.defobjType.type, DEF_NEG_CALL);
} else {
if (settings.getNumericOverflow()) {
adapter.math(GeneratorAdapter.NEG, type);
adapter.math(MethodWriter.NEG, type);
} else {
if (sort == Sort.INT) {
adapter.invokeStatic(definition.mathType.type, NEGATEEXACT_INT);
@ -228,7 +227,7 @@ public final class EUnary extends AExpression {
throw new IllegalStateException(error("Illegal tree structure."));
}
WriterUtility.writeBranch(adapter, tru, fals);
adapter.writeBranch(tru, fals);
}
}
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents an array length field load.
@ -55,17 +55,17 @@ public final class LArrayLength extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.arrayLength();
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalStateException(error("Illegal tree structure."));
}
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.List;
import java.util.Map;
@ -69,17 +69,17 @@ public final class LBrace extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
index.write(settings, definition, adapter);
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.arrayLoad(after.type);
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.arrayStore(after.type);
}

View File

@ -24,7 +24,7 @@ import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Struct;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.List;
@ -87,12 +87,12 @@ public final class LCall extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
for (final AExpression argument : arguments) {
argument.write(settings, definition, adapter);
}
@ -111,7 +111,7 @@ public final class LCall extends ALink {
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalStateException(error("Illegal tree structure."));
}
}

View File

@ -24,8 +24,7 @@ import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.AnalyzerCaster;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a cast made in a variable/method chain.
@ -62,17 +61,17 @@ public final class LCast extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
WriterUtility.writeCast(adapter, cast);
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.writeCast(cast);
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalStateException(error("Illegal tree structure."));
}
}

View File

@ -24,7 +24,7 @@ import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.DefBootstrap;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE;
@ -53,18 +53,18 @@ final class LDefArray extends ALink implements IDefLink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
index.write(settings, definition, adapter);
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
final String desc = Type.getMethodDescriptor(after.type, definition.defType.type, index.actual.type);
adapter.invokeDynamic("arrayLoad", desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.ARRAY_LOAD);
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
final String desc = Type.getMethodDescriptor(definition.voidType.type, definition.defType.type,
index.actual.type, after.type);
adapter.invokeDynamic("arrayStore", desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.ARRAY_STORE);

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.DefBootstrap;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.List;
@ -61,12 +61,12 @@ final class LDefCall extends ALink implements IDefLink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
final StringBuilder signature = new StringBuilder();
signature.append('(');
@ -88,7 +88,7 @@ final class LDefCall extends ALink implements IDefLink {
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalStateException(error("Illegal tree structure."));
}
}

View File

@ -24,7 +24,7 @@ import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.DefBootstrap;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import static org.elasticsearch.painless.WriterConstants.DEF_BOOTSTRAP_HANDLE;
@ -50,18 +50,18 @@ final class LDefField extends ALink implements IDefLink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
final String desc = Type.getMethodDescriptor(after.type, definition.defType.type);
adapter.invokeDynamic(value, desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.LOAD);
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
final String desc = Type.getMethodDescriptor(definition.voidType.type, definition.defType.type, after.type);
adapter.invokeDynamic(value, desc, DEF_BOOTSTRAP_HANDLE, DefBootstrap.STORE);
}

View File

@ -25,7 +25,7 @@ import org.elasticsearch.painless.Definition.Field;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Struct;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.List;
import java.util.Map;
@ -96,12 +96,12 @@ public final class LField extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (java.lang.reflect.Modifier.isStatic(field.reflect.getModifiers())) {
adapter.getStatic(field.owner.type, field.reflect.getName(), field.type.type);
@ -118,7 +118,7 @@ public final class LField extends ALink {
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (java.lang.reflect.Modifier.isStatic(field.reflect.getModifiers())) {
adapter.putStatic(field.owner.type, field.reflect.getName(), field.type.type);
} else {

View File

@ -24,8 +24,7 @@ import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a list load/store shortcut. (Internal only.)
@ -75,12 +74,12 @@ final class LListShortcut extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
index.write(settings, definition, adapter);
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (java.lang.reflect.Modifier.isInterface(getter.owner.clazz.getModifiers())) {
adapter.invokeInterface(getter.owner.type, getter.method);
} else {
@ -93,13 +92,13 @@ final class LListShortcut extends ALink {
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (java.lang.reflect.Modifier.isInterface(setter.owner.clazz.getModifiers())) {
adapter.invokeInterface(setter.owner.type, setter.method);
} else {
adapter.invokeVirtual(setter.owner.type, setter.method);
}
WriterUtility.writePop(adapter, setter.rtn.sort.size);
adapter.writePop(setter.rtn.sort.size);
}
}

View File

@ -24,8 +24,7 @@ import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a map load/store shortcut. (Internal only.)
@ -74,12 +73,12 @@ final class LMapShortcut extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
index.write(settings, definition, adapter);
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (java.lang.reflect.Modifier.isInterface(getter.owner.clazz.getModifiers())) {
adapter.invokeInterface(getter.owner.type, getter.method);
} else {
@ -92,13 +91,13 @@ final class LMapShortcut extends ALink {
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (java.lang.reflect.Modifier.isInterface(setter.owner.clazz.getModifiers())) {
adapter.invokeInterface(setter.owner.type, setter.method);
} else {
adapter.invokeVirtual(setter.owner.type, setter.method);
}
WriterUtility.writePop(adapter, setter.rtn.sort.size);
adapter.writePop(setter.rtn.sort.size);
}
}

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.List;
@ -74,12 +74,12 @@ public final class LNewArray extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
for (final AExpression argument : arguments) {
argument.write(settings, definition, adapter);
}
@ -92,7 +92,7 @@ public final class LNewArray extends ALink {
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalStateException(error("Illegal tree structure."));
}
}

View File

@ -25,7 +25,7 @@ import org.elasticsearch.painless.Definition.Constructor;
import org.elasticsearch.painless.Definition.Struct;
import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.List;
@ -92,12 +92,12 @@ public final class LNewObj extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.newInstance(after.type);
if (load) {
@ -112,7 +112,7 @@ public final class LNewObj extends ALink {
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalStateException(error("Illegal tree structure."));
}
}

View File

@ -25,8 +25,7 @@ import org.elasticsearch.painless.Definition.Method;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Definition.Struct;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a field load/store shortcut. (Internal only.)
@ -75,12 +74,12 @@ final class LShortcut extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (java.lang.reflect.Modifier.isInterface(getter.owner.clazz.getModifiers())) {
adapter.invokeInterface(getter.owner.type, getter.method);
} else {
@ -93,13 +92,13 @@ final class LShortcut extends ALink {
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
if (java.lang.reflect.Modifier.isInterface(setter.owner.clazz.getModifiers())) {
adapter.invokeInterface(setter.owner.type, setter.method);
} else {
adapter.invokeVirtual(setter.owner.type, setter.method);
}
WriterUtility.writePop(adapter, setter.rtn.sort.size);
adapter.writePop(setter.rtn.sort.size);
}
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a string constant.
@ -51,17 +51,17 @@ public final class LString extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.push(string);
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
throw new IllegalStateException(error("Illegal tree structure."));
}
}

View File

@ -25,7 +25,7 @@ import org.elasticsearch.painless.Definition.Type;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.Variables.Variable;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a variable load/store.
@ -74,17 +74,17 @@ public final class LVariable extends ALink {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
// Do nothing.
}
@Override
void load(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void load(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.visitVarInsn(after.type.getOpcode(Opcodes.ILOAD), slot);
}
@Override
void store(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void store(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
adapter.visitVarInsn(after.type.getOpcode(Opcodes.ISTORE), slot);
}
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.Collections;
import java.util.List;
@ -65,7 +65,7 @@ public final class SBlock extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
for (final AStatement statement : statements) {
statement.continu = continu;
statement.brake = brake;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a break statement.
@ -46,7 +46,7 @@ public final class SBreak extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
adapter.goTo(brake);
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a continue statement.
@ -49,7 +49,7 @@ public final class SContinue extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
adapter.goTo(continu);
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.Collections;
import java.util.List;
@ -50,7 +50,7 @@ public final class SDeclBlock extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
for (final SDeclaration declaration : declarations) {
declaration.write(settings, definition, adapter);
}

View File

@ -25,7 +25,7 @@ import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.Variables.Variable;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a single variable declaration.
@ -58,7 +58,7 @@ public final class SDeclaration extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
final org.objectweb.asm.Type type = variable.type.type;
final Sort sort = variable.type.sort;

View File

@ -22,9 +22,8 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a do-while loop.
@ -81,7 +80,7 @@ public final class SDo extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
final Label start = new Label();
final Label begin = new Label();
@ -98,7 +97,7 @@ public final class SDo extends AStatement {
condition.fals = end;
condition.write(settings, definition, adapter);
WriterUtility.writeLoopCounter(adapter, loopCounterSlot, Math.max(1, block.statementCount));
adapter.writeLoopCounter(loopCounterSlot, Math.max(1, block.statementCount));
adapter.goTo(start);
adapter.mark(end);

View File

@ -23,8 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Definition.Sort;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents the top-level node for an expression as a statement.
@ -60,14 +59,14 @@ public final class SExpression extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
expression.write(settings, definition, adapter);
if (methodEscape) {
adapter.returnValue();
} else {
WriterUtility.writePop(adapter, expression.expected.sort.size);
adapter.writePop(expression.expected.sort.size);
}
}
}

View File

@ -22,9 +22,8 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a for loop.
@ -129,7 +128,7 @@ public final class SFor extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
final Label start = new Label();
final Label begin = afterthought == null ? start : new Label();
@ -141,7 +140,7 @@ public final class SFor extends AStatement {
AExpression initializer = (AExpression)this.initializer;
initializer.write(settings, definition, adapter);
WriterUtility.writePop(adapter, initializer.expected.sort.size);
adapter.writePop(initializer.expected.sort.size);
}
adapter.mark(start);
@ -162,10 +161,10 @@ public final class SFor extends AStatement {
++statementCount;
}
WriterUtility.writeLoopCounter(adapter, loopCounterSlot, statementCount);
adapter.writeLoopCounter(loopCounterSlot, statementCount);
block.write(settings, definition, adapter);
} else {
WriterUtility.writeLoopCounter(adapter, loopCounterSlot, 1);
adapter.writeLoopCounter(loopCounterSlot, 1);
}
if (afterthought != null) {

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents an if/else block.
@ -84,7 +84,7 @@ public final class SIfElse extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
final Label end = new Label();
final Label fals = elseblock != null ? new Label() : end;

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a return statement.
@ -51,7 +51,7 @@ public final class SReturn extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
expression.write(settings, definition, adapter);
adapter.returnValue();

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.Collections;
import java.util.List;
@ -63,7 +63,7 @@ public final class SSource extends AStatement {
}
@Override
public void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
public void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
for (final AStatement statement : statements) {
statement.write(settings, definition, adapter);
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a throw statement.
@ -50,7 +50,7 @@ public final class SThrow extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
expression.write(settings, definition, adapter);
adapter.throwException();

View File

@ -25,7 +25,7 @@ import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.Variables.Variable;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a catch block as part of a try-catch block.
@ -75,7 +75,7 @@ public final class STrap extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
final Label jump = new Label();

View File

@ -23,7 +23,7 @@ import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
import java.util.Collections;
import java.util.List;
@ -83,7 +83,7 @@ public final class STry extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
final Label begin = new Label();
final Label end = new Label();

View File

@ -22,9 +22,8 @@ package org.elasticsearch.painless.node;
import org.elasticsearch.painless.CompilerSettings;
import org.elasticsearch.painless.Definition;
import org.elasticsearch.painless.Variables;
import org.elasticsearch.painless.WriterUtility;
import org.objectweb.asm.Label;
import org.objectweb.asm.commons.GeneratorAdapter;
import org.elasticsearch.painless.MethodWriter;
/**
* Represents a while loop.
@ -93,7 +92,7 @@ public final class SWhile extends AStatement {
}
@Override
void write(final CompilerSettings settings, final Definition definition, final GeneratorAdapter adapter) {
void write(final CompilerSettings settings, final Definition definition, final MethodWriter adapter) {
writeDebugInfo(adapter);
final Label begin = new Label();
final Label end = new Label();
@ -104,13 +103,13 @@ public final class SWhile extends AStatement {
condition.write(settings, definition, adapter);
if (block != null) {
WriterUtility.writeLoopCounter(adapter, loopCounterSlot, Math.max(1, block.statementCount));
adapter.writeLoopCounter(loopCounterSlot, Math.max(1, block.statementCount));
block.continu = begin;
block.brake = end;
block.write(settings, definition, adapter);
} else {
WriterUtility.writeLoopCounter(adapter, loopCounterSlot, 1);
adapter.writeLoopCounter(loopCounterSlot, 1);
}
if (block == null || !block.allEscape) {