LocalName localName = (LocalName)lhs;
String varName = localName.getName();
if (context.getLocalVarIndex(varName) != -1) {
lhs = new LocalVariable(varName, localName.getTypeName());
} else if (context.getMethodVarIndex(varName) != -1) {
lhs = new MethodVariable(varName);
} else {
lhs = new JavaField.Instance(null, varName, localName.getTypeName());
}
}
// assign the value
if (lhs instanceof JavaField.Instance) {
JavaField.Instance javaInstanceField = (JavaField.Instance)lhs;
//push the reference to the Java field itself. We can't just call encodeJavaField because we need the type of the instance object.
JavaExpression instance = javaInstanceField.getInstance();
JavaTypeName instanceType;
if (instance == null) {
//use 'this' as the instance expression, so if the field is 'foo', then it is 'this.foo'.
instanceType = encodeThis(context);
} else {
instanceType = encodeExpr(instance, context);
}
//push the rhs expression
// the type of the assignment takes on the type of the value (not the assigned variable).
JavaTypeName returnType = encodeExpr(assignment.getValue(), context);
if (retainValue) {
//duplicate the value so that a copy will be left over after assignment
//field, value --->
//value, field, value
mv.visitInsn(getDupX1OpCode(returnType));
}
//do the assignment
mv.visitFieldInsn(Opcodes.PUTFIELD, instanceType.getJVMInternalName(), javaInstanceField.getFieldName(), javaInstanceField.getFieldType().getJVMDescriptor());
return returnType;
} else if (lhs instanceof JavaField.Static) {
JavaField.Static javaStaticField = (JavaField.Static)lhs;
//push the rhs expression
// the type of the assignment takes on the type of the value (not the assigned variable).
JavaTypeName returnType = encodeExpr(assignment.getValue(), context);
if (retainValue) {
//duplicate the value so that a copy will be left over after assignment
//value --->
//value, value
mv.visitInsn(getDupOpCode(returnType));
}
//do the assignment
mv.visitFieldInsn(Opcodes.PUTSTATIC, javaStaticField.getInvocationClass().getJVMInternalName(), javaStaticField.getFieldName(), javaStaticField.getFieldType().getJVMDescriptor());
return returnType;
} else if (lhs instanceof LocalVariable) {
LocalVariable localVariable = (LocalVariable)lhs;
int localVarIndex = context.getLocalVarIndex(localVariable.getName());
//push the rhs expression
JavaTypeName returnType = encodeExpr(assignment.getValue(), context);
if (retainValue) {
//duplicate the value so that a copy will be left over after assignment
//value --->
//value, value
mv.visitInsn(getDupOpCode(returnType));
}
//encode the store instruction
mv.visitVarInsn(getStoreOpCode(localVariable.getTypeName()), localVarIndex);
return returnType;
} else if (lhs instanceof MethodVariable) {
MethodVariable methodVariable = (MethodVariable)lhs;
String varName = methodVariable.getName();
int methodVarIndex = context.getMethodVarIndex(varName);
JavaTypeName methodVarType = context.getMethodVarType(varName);
//push the rhs expression