private Expression transformBinaryExpression(final BinaryExpression exp) { final int op = exp.getOperation().getType(); int token = TokenUtil.removeAssignment(op); if (token == op) { // no transform needed return super.transform(exp); } BinaryExpression operation = new BinaryExpression( exp.getLeftExpression(), Token.newSymbol(token, -1, -1), exp.getRightExpression() ); operation.setSourcePosition(exp); BinaryExpression result = new BinaryExpression( exp.getLeftExpression(), Token.newSymbol(EQUAL, -1, -1), operation ); result.setSourcePosition(exp); return result; } }
declaration.getOperation(), declaration.getRightExpression()); assignment.setSourcePosition(declaration); assignment.copyNodeMetaData(declaration);
@Override public void visitField(final FieldNode node) { final boolean osc = typeCheckingContext.isInStaticContext; try { typeCheckingContext.isInStaticContext = node.isInStaticContext(); currentField = node; super.visitField(node); Expression init = node.getInitialExpression(); if (init != null) { FieldExpression left = new FieldExpression(node); BinaryExpression bexp = binX( left, Token.newSymbol("=", node.getLineNumber(), node.getColumnNumber()), init ); bexp.setSourcePosition(init); typeCheckAssignment(bexp, left, node.getOriginType(), init, getType(init)); if (init instanceof ConstructorCallExpression) { inferDiamondType((ConstructorCallExpression) init, node.getOriginType()); } } } finally { currentField = null; typeCheckingContext.isInStaticContext = osc; } }
Expression right = rightIt.next(); BinaryExpression bexp = new DeclarationExpression(left, bin.getOperation(), right); bexp.setSourcePosition(right); cle.addExpression(bexp); VariableExpression tmpVar = new VariableExpression("$tmpVar$" + tmpVarCounter++); BinaryExpression bexp = new DeclarationExpression(tmpVar, bin.getOperation(), right); bexp.setSourcePosition(right); tmpAssignments.add(bexp); bexp = new BinaryExpression(left, bin.getOperation(), new VariableExpression(tmpVar)); bexp.setSourcePosition(left); finalAssignments.add(bexp);
private VariableSlotLoader loadWithSubscript(Expression expression) { final OperandStack operandStack = controller.getOperandStack(); // if we have a BinaryExpression, let us check if it is with // subscription if (expression instanceof BinaryExpression) { BinaryExpression be = (BinaryExpression) expression; if (be.getOperation().getType()==Types.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()); 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()); return subscriptExpression; } } // normal loading of expression expression.visit(controller.getAcg()); return null; }
valueExpression ); bexp.setSourcePosition(entryExpression); bexp.visit(acg);
newExpr.setSourcePosition(expr); MethodNode method = findMethodOrFail(newExpr, left.getPlainNodeReference(), "getAt", right.getPlainNodeReference()); if (method != null && implementsInterfaceOrIsSubclassOf(right, RANGE_TYPE)) {
@Override public Expression transform(Expression exp) { if (exp instanceof DeclarationExpression) { // info: http://stackoverflow.com/questions/8158637/using-asttransformation-to-remove-def-to-change-scope-in-groovy-script // DeclarationExpression is used when something is declared like this: // def a = "hi"; // Long b = 1; // // When we change it to use BinaryExpression, we "remove" the def or Long, making it "behave" like this: // a = "hi"; // b = 1; // This changes the scope BinaryExpression e = new BinaryExpression(((DeclarationExpression) exp).getLeftExpression(), ((DeclarationExpression) exp).getOperation(), ((DeclarationExpression) exp).getRightExpression()); // setting source position e.setSourcePosition( exp); return e.transformExpression(this); } else { return super.transform(exp); } } }
declaration.getOperation(), declaration.getRightExpression()); assignment.setSourcePosition(declaration); assignment.copyNodeMetaData(declaration);
private VariableSlotLoader loadWithSubscript(Expression expression) { final OperandStack operandStack = controller.getOperandStack(); // if we have a BinaryExpression, let us check if it is with // subscription if (expression instanceof BinaryExpression) { BinaryExpression be = (BinaryExpression) expression; if (be.getOperation().getType()==Types.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()); 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()); return subscriptExpression; } } // normal loading of expression expression.visit(controller.getAcg()); return null; }
indexExpression ); leftExpr.setSourcePosition(leftExpression); MethodCallExpression methodCall = new MethodCallExpression(