You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/02/14 20:36:04 UTC

[groovy] 02/06: minor edits

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 272eb893d2149c5045349b080cbe7f6d76c9004f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Thu Feb 13 16:40:27 2020 -0600

    minor edits
    
    (cherry picked from commit 345e47fd6f9d3adb84db3385657c8758a423512d)
---
 .../codehaus/groovy/ast/tools/GeneralUtils.java    |   2 +-
 .../classgen/asm/BinaryExpressionHelper.java       | 254 +++++++++------------
 2 files changed, 113 insertions(+), 143 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
index 793769d..1685b1b 100644
--- a/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
+++ b/src/main/java/org/codehaus/groovy/ast/tools/GeneralUtils.java
@@ -90,7 +90,7 @@ public class GeneralUtils {
     public static final Token AND = Token.newSymbol(Types.LOGICAL_AND, -1, -1);
     public static final Token OR = Token.newSymbol(Types.LOGICAL_OR, -1, -1);
     public static final Token CMP = Token.newSymbol(Types.COMPARE_TO, -1, -1);
-    private static final Token INSTANCEOF = Token.newSymbol(Types.KEYWORD_INSTANCEOF, -1, -1);
+    public static final Token INSTANCEOF = Token.newSymbol(Types.KEYWORD_INSTANCEOF, -1, -1);
     private static final Token PLUS = Token.newSymbol(Types.PLUS, -1, -1);
     private static final Token INDEX = Token.newSymbol("[", -1, -1);
 
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java b/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java
index 78944d4..22d6583 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/BinaryExpressionHelper.java
@@ -39,15 +39,20 @@ import org.codehaus.groovy.ast.expr.PropertyExpression;
 import org.codehaus.groovy.ast.expr.TernaryExpression;
 import org.codehaus.groovy.ast.expr.TupleExpression;
 import org.codehaus.groovy.ast.expr.VariableExpression;
+import org.codehaus.groovy.ast.tools.GeneralUtils;
 import org.codehaus.groovy.ast.tools.WideningCategories;
 import org.codehaus.groovy.classgen.AsmClassGenerator;
 import org.codehaus.groovy.classgen.BytecodeExpression;
 import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
 import org.codehaus.groovy.syntax.Token;
-import org.codehaus.groovy.syntax.Types;
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 
+import static org.codehaus.groovy.ast.tools.GeneralUtils.args;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.binX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.callX;
+import static org.codehaus.groovy.ast.tools.GeneralUtils.constX;
+import static org.codehaus.groovy.syntax.Types.ASSIGN;
 import static org.codehaus.groovy.syntax.Types.BITWISE_AND;
 import static org.codehaus.groovy.syntax.Types.BITWISE_AND_EQUAL;
 import static org.codehaus.groovy.syntax.Types.BITWISE_OR;
@@ -82,12 +87,14 @@ import static org.codehaus.groovy.syntax.Types.LOGICAL_OR;
 import static org.codehaus.groovy.syntax.Types.MATCH_REGEX;
 import static org.codehaus.groovy.syntax.Types.MINUS;
 import static org.codehaus.groovy.syntax.Types.MINUS_EQUAL;
+import static org.codehaus.groovy.syntax.Types.MINUS_MINUS;
 import static org.codehaus.groovy.syntax.Types.MOD;
 import static org.codehaus.groovy.syntax.Types.MOD_EQUAL;
 import static org.codehaus.groovy.syntax.Types.MULTIPLY;
 import static org.codehaus.groovy.syntax.Types.MULTIPLY_EQUAL;
 import static org.codehaus.groovy.syntax.Types.PLUS;
 import static org.codehaus.groovy.syntax.Types.PLUS_EQUAL;
+import static org.codehaus.groovy.syntax.Types.PLUS_PLUS;
 import static org.codehaus.groovy.syntax.Types.POWER;
 import static org.codehaus.groovy.syntax.Types.POWER_EQUAL;
 import static org.codehaus.groovy.syntax.Types.RIGHT_SHIFT;
@@ -338,9 +345,7 @@ public class BinaryExpressionHelper {
         // -> (x, [], 5), =, 10
         // -> methodCall(x, "putAt", [5, 10])
         ArgumentListExpression ae = new ArgumentListExpression(index,rhsValueLoader);
-        controller.getInvocationWriter().makeCall(
-                parent, receiver, new ConstantExpression("putAt"),
-                ae, InvocationWriter.invokeMethod, safe, false, false);
+        controller.getInvocationWriter().makeCall(parent, receiver, constX("putAt"), ae, InvocationWriter.invokeMethod, safe, false, false);
         controller.getOperandStack().pop();
         // return value of assignment
         rhsValueLoader.visit(controller.getAcg());
@@ -348,13 +353,11 @@ public class BinaryExpressionHelper {
 
     public void evaluateElvisEqual(final BinaryExpression expression) {
         Token operation = expression.getOperation();
-        BinaryExpression elvisAssignmentExpression =
-                new BinaryExpression(
-                        expression.getLeftExpression(),
-                        Token.newSymbol(Types.EQUAL, operation.getStartLine(), operation.getStartColumn()),
-                        new ElvisOperatorExpression(expression.getLeftExpression(), expression.getRightExpression())
-                );
-
+        BinaryExpression elvisAssignmentExpression = binX(
+                expression.getLeftExpression(),
+                Token.newSymbol(ASSIGN, operation.getStartLine(), operation.getStartColumn()),
+                new ElvisOperatorExpression(expression.getLeftExpression(), expression.getRightExpression())
+        );
         this.evaluateEqual(elvisAssignmentExpression, false);
     }
 
@@ -362,14 +365,11 @@ public class BinaryExpressionHelper {
         AsmClassGenerator acg = controller.getAcg();
         CompileStack compileStack = controller.getCompileStack();
         OperandStack operandStack = controller.getOperandStack();
-        Expression rightExpression = expression.getRightExpression();
         Expression leftExpression = expression.getLeftExpression();
-        ClassNode lhsType = controller.getTypeChooser().resolveType(leftExpression, controller.getClassNode());
+        Expression rightExpression = expression.getRightExpression();
+        boolean directAssignment = defineVariable && !(leftExpression instanceof TupleExpression);
 
-        if (    defineVariable &&
-                rightExpression instanceof EmptyExpression &&
-                !(leftExpression instanceof TupleExpression) )
-        {
+        if (directAssignment && rightExpression instanceof EmptyExpression) {
             VariableExpression ve = (VariableExpression) leftExpression;
             BytecodeVariable var = compileStack.defineVariable(ve, controller.getTypeChooser().resolveType(ve, controller.getClassNode()), false);
             operandStack.loadOrStoreVariable(var, false);
@@ -377,22 +377,21 @@ public class BinaryExpressionHelper {
         }
 
         // let's evaluate the RHS and store the result
-        ClassNode rhsType;
+        ClassNode lhsType = controller.getTypeChooser().resolveType(leftExpression, controller.getClassNode());
         if (rightExpression instanceof ListExpression && lhsType.isArray()) {
             ListExpression list = (ListExpression) rightExpression;
             ArrayExpression array = new ArrayExpression(lhsType.getComponentType(), list.getExpressions());
             array.setSourcePosition(list);
             array.visit(acg);
         } else if (rightExpression instanceof EmptyExpression) {
-            rhsType = leftExpression.getType();
-            loadInitValue(rhsType);
+            loadInitValue(leftExpression.getType()); // TODO: lhsType?
         } else {
             rightExpression.visit(acg);
         }
-        rhsType = operandStack.getTopOperand();
 
-        boolean directAssignment = defineVariable && !(leftExpression instanceof TupleExpression);
+        ClassNode rhsType = operandStack.getTopOperand();
         int rhsValueId;
+
         if (directAssignment) {
             VariableExpression var = (VariableExpression) leftExpression;
             if (var.isClosureSharedVariable() && ClassHelper.isPrimitiveType(rhsType)) {
@@ -422,13 +421,13 @@ public class BinaryExpressionHelper {
         } else {
             rhsValueId = compileStack.defineTemporaryVariable("$rhs", rhsType, true);
         }
-        //TODO: if rhs is VariableSlotLoader already, then skip crating a new one
+        // TODO: if rhs is VariableSlotLoader already, then skip crating a new one
         BytecodeExpression rhsValueLoader = new VariableSlotLoader(rhsType,rhsValueId,operandStack);
 
         // assignment for subscript
         if (leftExpression instanceof BinaryExpression) {
             BinaryExpression leftBinExpr = (BinaryExpression) leftExpression;
-            if (leftBinExpr.getOperation().getType() == Types.LEFT_SQUARE_BRACKET) {
+            if (leftBinExpr.getOperation().getType() == LEFT_SQUARE_BRACKET) {
                 assignToArray(expression, leftBinExpr.getLeftExpression(), leftBinExpr.getRightExpression(), rhsValueLoader, leftBinExpr.isSafe());
             }
             compileStack.removeVar(rhsValueId);
@@ -437,8 +436,8 @@ public class BinaryExpressionHelper {
 
         compileStack.pushLHS(true);
 
-        // multiple declaration
         if (leftExpression instanceof TupleExpression) {
+            // multiple declaration
             TupleExpression tuple = (TupleExpression) leftExpression;
             int i = 0;
             for (Expression e : tuple.getExpressions()) {
@@ -447,7 +446,7 @@ public class BinaryExpressionHelper {
                         rhsValueLoader, "getAt",
                         new ArgumentListExpression(new ConstantExpression(i)));
                 call.visit(acg);
-                i++;
+                i += 1;
                 if (defineVariable) {
                     operandStack.doGroovyCast(var);
                     compileStack.defineVariable(var, true);
@@ -456,16 +455,14 @@ public class BinaryExpressionHelper {
                     acg.visitVariableExpression(var);
                 }
             }
-        }
-        // single declaration
-        else if (defineVariable) {
+        } else if (defineVariable) {
+            // single declaration
             rhsValueLoader.visit(acg);
             operandStack.remove(1);
             compileStack.popLHS();
             return;
-        }
-        // normal assignment
-        else {
+        } else {
+            // normal assignment
             int mark = operandStack.getStackLength();
             // to leave a copy of the rightExpression value on the stack after the assignment.
             rhsValueLoader.visit(acg);
@@ -473,7 +470,7 @@ public class BinaryExpressionHelper {
             ClassNode targetType = typeChooser.resolveType(leftExpression, controller.getClassNode());
             operandStack.doGroovyCast(targetType);
             leftExpression.visit(acg);
-            operandStack.remove(operandStack.getStackLength()-mark);
+            operandStack.remove(operandStack.getStackLength() - mark);
         }
         compileStack.popLHS();
 
@@ -493,21 +490,17 @@ public class BinaryExpressionHelper {
     }
 
     protected void evaluateCompareExpression(final MethodCaller compareMethod, final BinaryExpression expression) {
+        ClassNode classNode = controller.getClassNode();
         Expression leftExp = expression.getLeftExpression();
-        TypeChooser typeChooser = controller.getTypeChooser();
-        ClassNode cn = controller.getClassNode();
-        ClassNode leftType = typeChooser.resolveType(leftExp,cn);
         Expression rightExp = expression.getRightExpression();
-        ClassNode rightType = typeChooser.resolveType(rightExp,cn);
+        ClassNode leftType = controller.getTypeChooser().resolveType(leftExp, classNode);
+        ClassNode rightType = controller.getTypeChooser().resolveType(rightExp, classNode);
 
         boolean done = false;
-        if (    ClassHelper.isPrimitiveType(leftType) &&
-                ClassHelper.isPrimitiveType(rightType))
-        {
-            BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(getController());
+        if (ClassHelper.isPrimitiveType(leftType) && ClassHelper.isPrimitiveType(rightType)) {
+            BinaryExpressionMultiTypeDispatcher helper = new BinaryExpressionMultiTypeDispatcher(controller);
             done = helper.doPrimitiveCompare(leftType, rightType, expression);
         }
-
         if (!done) {
             AsmClassGenerator acg = controller.getAcg();
             OperandStack operandStack = controller.getOperandStack();
@@ -519,33 +512,32 @@ public class BinaryExpressionHelper {
 
             compareMethod.call(controller.getMethodVisitor());
             ClassNode resType = ClassHelper.boolean_TYPE;
-            if (compareMethod==findRegexMethod) {
+            if (compareMethod == findRegexMethod) {
                 resType = ClassHelper.OBJECT_TYPE;
             }
-            operandStack.replace(resType,2);
+            operandStack.replace(resType, 2);
         }
     }
 
     private void evaluateCompareTo(final BinaryExpression expression) {
-        Expression leftExpression = expression.getLeftExpression();
         AsmClassGenerator acg = controller.getAcg();
+        MethodVisitor mv = controller.getMethodVisitor();
         OperandStack operandStack = controller.getOperandStack();
 
-        leftExpression.visit(acg);
+        expression.getLeftExpression().visit(acg);
         operandStack.box();
 
         // if the right hand side is a boolean expression, we need to autobox
-        Expression rightExpression = expression.getRightExpression();
-        rightExpression.visit(acg);
+        expression.getRightExpression().visit(acg);
         operandStack.box();
 
-        compareToMethod.call(controller.getMethodVisitor());
-        operandStack.replace(ClassHelper.Integer_TYPE,2);
+        compareToMethod.call(mv);
+        operandStack.replace(ClassHelper.Integer_TYPE, 2);
     }
 
     private void evaluateLogicalAndExpression(final BinaryExpression expression) {
-        MethodVisitor mv = controller.getMethodVisitor();
         AsmClassGenerator acg = controller.getAcg();
+        MethodVisitor mv = controller.getMethodVisitor();
         OperandStack operandStack = controller.getOperandStack();
 
         expression.getLeftExpression().visit(acg);
@@ -554,7 +546,7 @@ public class BinaryExpressionHelper {
 
         expression.getRightExpression().visit(acg);
         operandStack.doGroovyCast(ClassHelper.boolean_TYPE);
-        operandStack.jump(IFEQ,falseCase);
+        operandStack.jump(IFEQ, falseCase);
 
         ConstantExpression.PRIM_TRUE.visit(acg);
         Label trueCase = new Label();
@@ -568,12 +560,10 @@ public class BinaryExpressionHelper {
     }
 
     private void evaluateLogicalOrExpression(final BinaryExpression expression) {
-        MethodVisitor mv = controller.getMethodVisitor();
         AsmClassGenerator acg = controller.getAcg();
+        MethodVisitor mv = controller.getMethodVisitor();
         OperandStack operandStack = controller.getOperandStack();
 
-        Label end = new Label();
-
         expression.getLeftExpression().visit(acg);
         operandStack.doGroovyCast(ClassHelper.boolean_TYPE);
         Label trueCase = operandStack.jump(IFNE);
@@ -584,6 +574,7 @@ public class BinaryExpressionHelper {
 
         mv.visitLabel(trueCase);
         ConstantExpression.PRIM_TRUE.visit(acg);
+        Label end = new Label();
         operandStack.jump(GOTO, end);
 
         mv.visitLabel(falseCase);
@@ -592,23 +583,20 @@ public class BinaryExpressionHelper {
         mv.visitLabel(end);
     }
 
-    protected void evaluateBinaryExpression(final String message, final BinaryExpression binExp) {
+    protected void evaluateBinaryExpression(final String message, final BinaryExpression expression) {
         CompileStack compileStack = controller.getCompileStack();
-
-        Expression receiver = binExp.getLeftExpression();
-        Expression arguments = binExp.getRightExpression();
-
         // ensure VariableArguments are read, not stored
         compileStack.pushLHS(false);
-        controller.getInvocationWriter().makeSingleArgumentCall(receiver, message, arguments, binExp.isSafe());
+        controller.getInvocationWriter().makeSingleArgumentCall(
+                expression.getLeftExpression(),
+                message,
+                expression.getRightExpression(),
+                expression.isSafe()
+        );
         compileStack.popLHS();
     }
 
     protected void evaluateArrayAssignmentWithOperator(final String method, final BinaryExpression expression, final BinaryExpression leftBinExpr) {
-        CompileStack compileStack    = getController().getCompileStack();
-        AsmClassGenerator acg             = getController().getAcg();
-        OperandStack os              = getController().getOperandStack();
-
         // e.g. x[a] += b
         // to avoid loading x and a twice we transform the expression to use
         // ExpressionAsVariableSlot
@@ -619,15 +607,18 @@ public class BinaryExpressionHelper {
         // -> subscript=a, receiver=x, receiver#putAt(subscript, ret=receiver#getAt(subscript)#plus(b)), ret
         ExpressionAsVariableSlot subscript = new ExpressionAsVariableSlot(controller, leftBinExpr.getRightExpression(), "subscript");
         ExpressionAsVariableSlot receiver  = new ExpressionAsVariableSlot(controller, leftBinExpr.getLeftExpression(), "receiver");
-        MethodCallExpression getAt = new MethodCallExpression(receiver, "getAt", new ArgumentListExpression(subscript));
-        MethodCallExpression operation = new MethodCallExpression(getAt, method, expression.getRightExpression());
+        MethodCallExpression getAt = callX(receiver, "getAt", args(subscript));
+        MethodCallExpression operation = callX(getAt, method, expression.getRightExpression());
         ExpressionAsVariableSlot ret = new ExpressionAsVariableSlot(controller, operation, "ret");
-        MethodCallExpression putAt = new MethodCallExpression(receiver, "putAt", new ArgumentListExpression(subscript, ret));
+        MethodCallExpression putAt = callX(receiver, "putAt", args(subscript, ret));
 
+        AsmClassGenerator acg = controller.getAcg();
         putAt.visit(acg);
+        OperandStack os = controller.getOperandStack();
         os.pop();
         os.load(ret.getType(), ret.getIndex());
 
+        CompileStack compileStack = controller.getCompileStack();
         compileStack.removeVar(ret.getIndex());
         compileStack.removeVar(subscript.getIndex());
         compileStack.removeVar(receiver.getIndex());
@@ -635,44 +626,33 @@ public class BinaryExpressionHelper {
 
     protected void evaluateBinaryExpressionWithAssignment(final String method, final BinaryExpression expression) {
         Expression leftExpression = expression.getLeftExpression();
-        AsmClassGenerator acg = controller.getAcg();
-        OperandStack operandStack = controller.getOperandStack();
-
         if (leftExpression instanceof BinaryExpression) {
-            BinaryExpression leftBinExpr = (BinaryExpression) leftExpression;
-            if (leftBinExpr.getOperation().getType() == Types.LEFT_SQUARE_BRACKET) {
-                evaluateArrayAssignmentWithOperator(method, expression, leftBinExpr);
+            BinaryExpression bexp = (BinaryExpression) leftExpression;
+            if (bexp.getOperation().getType() == LEFT_SQUARE_BRACKET) {
+                evaluateArrayAssignmentWithOperator(method, expression, bexp);
                 return;
             }
         }
 
         evaluateBinaryExpression(method, expression);
 
-        // br to leave a copy of rvalue on the stack. see also isPopRequired()
-        operandStack.dup();
-
+        // br to leave a copy of rvalue on the stack; see also isPopRequired()
+        controller.getOperandStack().dup();
         controller.getCompileStack().pushLHS(true);
-        leftExpression.visit(acg);
+        leftExpression.visit(controller.getAcg());
         controller.getCompileStack().popLHS();
     }
 
     private void evaluateInstanceof(final BinaryExpression expression) {
-        OperandStack operandStack = controller.getOperandStack();
-
         expression.getLeftExpression().visit(controller.getAcg());
-        operandStack.box();
+        controller.getOperandStack().box();
         Expression rightExp = expression.getRightExpression();
-        ClassNode classType;
-        if (rightExp instanceof ClassExpression) {
-            ClassExpression classExp = (ClassExpression) rightExp;
-            classType = classExp.getType();
-        } else {
-            throw new RuntimeException(
-                    "Right hand side of the instanceof keyword must be a class name, not: " + rightExp);
+        if (!(rightExp instanceof ClassExpression)) {
+            throw new RuntimeException("RHS of the instanceof keyword must be a class name, not: " + rightExp);
         }
-        String classInternalName = BytecodeHelper.getClassInternalName(classType);
+        String classInternalName = BytecodeHelper.getClassInternalName(rightExp.getType());
         controller.getMethodVisitor().visitTypeInsn(INSTANCEOF, classInternalName);
-        operandStack.replace(ClassHelper.boolean_TYPE);
+        controller.getOperandStack().replace(ClassHelper.boolean_TYPE);
     }
 
     private void evaluateNotInstanceof(final BinaryExpression expression) {
@@ -680,7 +660,7 @@ public class BinaryExpressionHelper {
                 new NotExpression(
                         new BinaryExpression(
                                 expression.getLeftExpression(),
-                                Token.newSymbol(KEYWORD_INSTANCEOF, -1, -1),
+                                GeneralUtils.INSTANCEOF,
                                 expression.getRightExpression()
                         )
                 )
@@ -689,7 +669,7 @@ public class BinaryExpressionHelper {
 
     private void evaluatePostfixMethod(final int op, final String method, final Expression expression, final Expression orig) {
         CompileStack compileStack = controller.getCompileStack();
-        final OperandStack operandStack = controller.getOperandStack();
+        OperandStack operandStack = controller.getOperandStack();
 
         // load Expressions
         VariableSlotLoader usesSubscript = loadWithSubscript(expression);
@@ -699,13 +679,13 @@ public class BinaryExpressionHelper {
         ClassNode expressionType = operandStack.getTopOperand();
         int tempIdx = compileStack.defineTemporaryVariable("postfix_" + method, expressionType, true);
 
-        // execute Method
+        // execute method
         execMethodAndStoreForSubscriptOperator(op, method, expression, usesSubscript, orig);
 
         // remove the result of the method call
         operandStack.pop();
 
-        //reload saved value
+        // reload saved value
         operandStack.load(expressionType, tempIdx);
         compileStack.removeVar(tempIdx);
         if (usesSubscript != null) compileStack.removeVar(usesSubscript.getIndex());
@@ -714,10 +694,10 @@ public class BinaryExpressionHelper {
     public void evaluatePostfixMethod(final PostfixExpression expression) {
         int op = expression.getOperation().getType();
         switch (op) {
-            case Types.PLUS_PLUS:
+            case PLUS_PLUS:
                 evaluatePostfixMethod(op, "next", expression.getExpression(), expression);
                 break;
-            case Types.MINUS_MINUS:
+            case MINUS_MINUS:
                 evaluatePostfixMethod(op, "previous", expression.getExpression(), expression);
                 break;
         }
@@ -726,79 +706,73 @@ public class BinaryExpressionHelper {
     public void evaluatePrefixMethod(final PrefixExpression expression) {
         int type = expression.getOperation().getType();
         switch (type) {
-            case Types.PLUS_PLUS:
+            case PLUS_PLUS:
                 evaluatePrefixMethod(type, "next", expression.getExpression(), expression);
                 break;
-            case Types.MINUS_MINUS:
+            case MINUS_MINUS:
                 evaluatePrefixMethod(type, "previous", expression.getExpression(), expression);
                 break;
         }
     }
 
     private void evaluatePrefixMethod(final int op, final String method, final Expression expression, final Expression orig) {
-        // load Expressions
+        // load expressions
         VariableSlotLoader usesSubscript = loadWithSubscript(expression);
 
-        // execute Method
+        // execute method
         execMethodAndStoreForSubscriptOperator(op,method,expression,usesSubscript,orig);
 
         // new value is already on stack, so nothing to do here
-        if (usesSubscript!=null) controller.getCompileStack().removeVar(usesSubscript.getIndex());
+        if (usesSubscript != null) controller.getCompileStack().removeVar(usesSubscript.getIndex());
     }
 
     private VariableSlotLoader loadWithSubscript(final Expression expression) {
-        final OperandStack operandStack = controller.getOperandStack();
-        // if we have a BinaryExpression, let us check if it is with
-        // subscription
+        AsmClassGenerator acg = controller.getAcg();
+        // if we have a BinaryExpression, check if it is with subscription
         if (expression instanceof BinaryExpression) {
-            BinaryExpression be = (BinaryExpression) expression;
-            if (be.getOperation().getType()== Types.LEFT_SQUARE_BRACKET) {
+            BinaryExpression bexp = (BinaryExpression) expression;
+            if (bexp.getOperation().getType() == LEFT_SQUARE_BRACKET) {
                 // right expression is the subscript expression
                 // we store the result of the subscription on the stack
-                Expression subscript = be.getRightExpression();
-                subscript.visit(controller.getAcg());
+                Expression subscript = bexp.getRightExpression();
+                subscript.visit(acg);
+                OperandStack operandStack = controller.getOperandStack();
                 ClassNode subscriptType = operandStack.getTopOperand();
                 int id = controller.getCompileStack().defineTemporaryVariable("$subscript", subscriptType, true);
                 VariableSlotLoader subscriptExpression = new VariableSlotLoader(subscriptType, id, operandStack);
-                // do modified visit
-                BinaryExpression newBe = new BinaryExpression(be.getLeftExpression(), be.getOperation(), subscriptExpression);
-                newBe.copyNodeMetaData(be);
-                newBe.setSourcePosition(be);
-                newBe.visit(controller.getAcg());
+                BinaryExpression rewrite = binX(bexp.getLeftExpression(), bexp.getOperation(), subscriptExpression);
+                rewrite.copyNodeMetaData(bexp);
+                rewrite.setSourcePosition(bexp);
+                rewrite.visit(acg);
                 return subscriptExpression;
             }
         }
 
         // normal loading of expression
-        expression.visit(controller.getAcg());
+        expression.visit(acg);
         return null;
     }
 
     private void execMethodAndStoreForSubscriptOperator(final int op, String method, final Expression expression, final VariableSlotLoader usesSubscript, final Expression orig) {
-        final OperandStack operandStack = controller.getOperandStack();
-        writePostOrPrefixMethod(op,method,expression,orig);
+        writePostOrPrefixMethod(op, method, expression, orig);
 
         // we need special code for arrays to store the result (like for a[1]++)
-        if (usesSubscript!=null) {
-            CompileStack compileStack = controller.getCompileStack();
+        if (usesSubscript != null) {
             BinaryExpression be = (BinaryExpression) expression;
-
+            CompileStack compileStack = controller.getCompileStack();
+            OperandStack operandStack = controller.getOperandStack();
             ClassNode methodResultType = operandStack.getTopOperand();
-            final int resultIdx = compileStack.defineTemporaryVariable("postfix_" + method, methodResultType, true);
+            int resultIdx = compileStack.defineTemporaryVariable("postfix_" + method, methodResultType, true);
             BytecodeExpression methodResultLoader = new VariableSlotLoader(methodResultType, resultIdx, operandStack);
 
-            // execute the assignment, this will leave the right side
-            // (here the method call result) on the stack
+            // execute the assignment, this will leave the right side (here the method call result) on the stack
             assignToArray(be, be.getLeftExpression(), usesSubscript, methodResultLoader, be.isSafe());
 
             compileStack.removeVar(resultIdx);
-        }
-        // here we handle a.b++ and a++
-        else if (expression instanceof VariableExpression ||
-            expression instanceof FieldExpression ||
-            expression instanceof PropertyExpression)
-        {
-            operandStack.dup();
+
+        } else if (expression instanceof VariableExpression || expression instanceof PropertyExpression || expression instanceof FieldExpression) {
+            // here we handle a.b++ and a++
+            controller.getOperandStack().dup();
             controller.getCompileStack().pushLHS(true);
             expression.visit(controller.getAcg());
             controller.getCompileStack().popLHS();
@@ -807,14 +781,13 @@ public class BinaryExpressionHelper {
     }
 
     protected void writePostOrPrefixMethod(final int op, final String method, final Expression expression, final Expression orig) {
-        final OperandStack operandStack = controller.getOperandStack();
-        // at this point the receiver will be already on the stack.
+        // 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) {
+        ClassNode exprType = controller.getTypeChooser().resolveType(expression, controller.getClassNode());
+        Expression callSiteReceiverSwap = new BytecodeExpression(exprType) {
             @Override
             public void visit(MethodVisitor mv) {
+                OperandStack operandStack = controller.getOperandStack();
                 // CallSite is normally not showing up on the
                 // operandStack, so we place a dummy here with same
                 // slot length.
@@ -842,7 +815,6 @@ public class BinaryExpressionHelper {
                 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)
-
     }
 
     private void evaluateElvisOperatorExpression(final ElvisOperatorExpression expression) {
@@ -880,7 +852,7 @@ public class BinaryExpressionHelper {
             truePartType = ClassHelper.getWrapper(truePartType);
         }
         int retValueId = compileStack.defineTemporaryVariable("$t", truePartType, true);
-        operandStack.castToBool(mark,true);
+        operandStack.castToBool(mark, true);
 
         Label l0 = operandStack.jump(IFEQ);
         // true part: load $t and cast to S
@@ -897,14 +869,13 @@ public class BinaryExpressionHelper {
         // finish and cleanup
         mv.visitLabel(l1);
         compileStack.removeVar(retValueId);
-        controller.getOperandStack().replace(common, 2);
-
+        operandStack.replace(common, 2);
     }
 
     private void evaluateNormalTernary(final TernaryExpression expression) {
         MethodVisitor mv = controller.getMethodVisitor();
-        OperandStack operandStack = controller.getOperandStack();
         TypeChooser typeChooser = controller.getTypeChooser();
+        OperandStack operandStack = controller.getOperandStack();
 
         Expression boolPart = expression.getBooleanExpression();
         Expression truePart = expression.getTrueExpression();
@@ -923,7 +894,7 @@ public class BinaryExpressionHelper {
         // load b and convert to boolean
         int mark = operandStack.getStackLength();
         boolPart.visit(controller.getAcg());
-        operandStack.castToBool(mark,true);
+        operandStack.castToBool(mark, true);
 
         Label l0 = operandStack.jump(IFEQ);
         // true part: load x and cast to S
@@ -939,8 +910,7 @@ public class BinaryExpressionHelper {
 
         // finish and cleanup
         mv.visitLabel(l1);
-        controller.getOperandStack().replace(common, 2);
-
+        operandStack.replace(common, 2);
     }
 
     public void evaluateTernary(final TernaryExpression expression) {