use of org.codehaus.groovy.classgen.BytecodeExpression in project groovy by apache.
the class BinaryExpressionHelper method writePostOrPrefixMethod.
protected void writePostOrPrefixMethod(int op, String method, Expression expression, Expression orig) {
final OperandStack operandStack = controller.getOperandStack();
// at this point the receiver will be already on the stack.
// in a[1]++ the method will be "++" aka "next" and the receiver a[1]
ClassNode BEType = controller.getTypeChooser().resolveType(expression, controller.getClassNode());
Expression callSiteReceiverSwap = new BytecodeExpression(BEType) {
@Override
public void visit(MethodVisitor mv) {
// CallSite is normally not showing up on the
// operandStack, so we place a dummy here with same
// slot length.
operandStack.push(ClassHelper.OBJECT_TYPE);
// change (receiver,callsite) to (callsite,receiver)
operandStack.swap();
setType(operandStack.getTopOperand());
// no need to keep any of those on the operand stack
// after this expression is processed, the operand stack
// will contain callSiteReceiverSwap.getType()
operandStack.remove(2);
}
};
// execute method
// this will load the callsite and the receiver normally in the wrong
// order since the receiver is already present, but before the callsite
// Therefore we use callSiteReceiverSwap to correct the order.
// After this call the JVM operand stack will contain the the result of
// the method call... usually simply Object in operandStack
controller.getCallSiteWriter().makeCallSite(callSiteReceiverSwap, method, MethodCallExpression.NO_ARGUMENTS, false, false, false, false);
// now rhs is completely done and we need only to store. In a[1]++ this
// would be a.getAt(1).next() for the rhs, "lhs" code is a.putAt(1, rhs)
}
Aggregations