use of org.codehaus.groovy.transform.sc.StaticCompilationVisitor in project groovy by apache.
the class StaticTypesBinaryExpressionMultiTypeDispatcher method assignToArray.
protected void assignToArray(Expression parent, Expression receiver, Expression index, Expression rhsValueLoader) {
ClassNode current = getController().getClassNode();
ClassNode arrayType = getController().getTypeChooser().resolveType(receiver, current);
ClassNode arrayComponentType = arrayType.getComponentType();
int operationType = getOperandType(arrayComponentType);
BinaryExpressionWriter bew = binExpWriter[operationType];
if (bew.arraySet(true) && arrayType.isArray()) {
super.assignToArray(parent, receiver, index, rhsValueLoader);
} else {
/******
/ This code path is needed because ACG creates array access expressions
*******/
WriterController controller = getController();
StaticTypeCheckingVisitor visitor = new StaticCompilationVisitor(controller.getSourceUnit(), controller.getClassNode());
// let's replace this assignment to a subscript operator with a
// method call
// e.g. x[5] = 10
// -> (x, [], 5), =, 10
// -> methodCall(x, "putAt", [5, 10])
ArgumentListExpression ae = new ArgumentListExpression(index, rhsValueLoader);
if (rhsValueLoader instanceof VariableSlotLoader && parent instanceof BinaryExpression) {
// GROOVY-6061
rhsValueLoader.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, controller.getTypeChooser().resolveType(parent, controller.getClassNode()));
}
MethodCallExpression mce = new MethodCallExpression(receiver, "putAt", ae);
mce.setSourcePosition(parent);
visitor.visitMethodCallExpression(mce);
OperandStack operandStack = controller.getOperandStack();
int height = operandStack.getStackLength();
mce.visit(controller.getAcg());
operandStack.pop();
operandStack.remove(operandStack.getStackLength() - height);
// return value of assignment
rhsValueLoader.visit(controller.getAcg());
}
}
use of org.codehaus.groovy.transform.sc.StaticCompilationVisitor in project groovy-core by groovy.
the class StaticTypesBinaryExpressionMultiTypeDispatcher method assignToArray.
protected void assignToArray(Expression parent, Expression receiver, Expression index, Expression rhsValueLoader) {
ClassNode current = getController().getClassNode();
ClassNode arrayType = getController().getTypeChooser().resolveType(receiver, current);
ClassNode arrayComponentType = arrayType.getComponentType();
int operationType = getOperandType(arrayComponentType);
BinaryExpressionWriter bew = binExpWriter[operationType];
AsmClassGenerator acg = getController().getAcg();
if (bew.arraySet(true) && arrayType.isArray()) {
super.assignToArray(parent, receiver, index, rhsValueLoader);
} else {
/**
****
* / This code path is needed because ACG creates array access expressions
******
*/
WriterController controller = getController();
StaticTypeCheckingVisitor visitor = new StaticCompilationVisitor(controller.getSourceUnit(), controller.getClassNode());
// let's replace this assignment to a subscript operator with a
// method call
// e.g. x[5] = 10
// -> (x, [], 5), =, 10
// -> methodCall(x, "putAt", [5, 10])
ArgumentListExpression ae = new ArgumentListExpression(index, rhsValueLoader);
if (rhsValueLoader instanceof VariableSlotLoader && parent instanceof BinaryExpression) {
// GROOVY-6061
Expression right = ((BinaryExpression) parent).getRightExpression();
rhsValueLoader.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, controller.getTypeChooser().resolveType(parent, controller.getClassNode()));
}
MethodCallExpression mce = new MethodCallExpression(receiver, "putAt", ae);
mce.setSourcePosition(parent);
visitor.visitMethodCallExpression(mce);
OperandStack operandStack = controller.getOperandStack();
int height = operandStack.getStackLength();
mce.visit(controller.getAcg());
operandStack.pop();
operandStack.remove(operandStack.getStackLength() - height);
// return value of assignment
rhsValueLoader.visit(controller.getAcg());
}
}
use of org.codehaus.groovy.transform.sc.StaticCompilationVisitor in project groovy by apache.
the class StaticTypesBinaryExpressionMultiTypeDispatcher method assignToArray.
@Override
protected void assignToArray(final Expression enclosing, final Expression receiver, final Expression subscript, final Expression rhsValueLoader, final boolean safe) {
ClassNode receiverType = controller.getTypeChooser().resolveType(receiver, controller.getClassNode());
if (receiverType.isArray() && !safe && binExpWriter[getOperandType(receiverType.getComponentType())].arraySet(true)) {
super.assignToArray(enclosing, receiver, subscript, rhsValueLoader, safe);
} else {
// GROOVY-6061
if (rhsValueLoader instanceof VariableSlotLoader && enclosing instanceof BinaryExpression) {
rhsValueLoader.putNodeMetaData(INFERRED_TYPE, controller.getTypeChooser().resolveType(enclosing, controller.getClassNode()));
}
// GROOVY-9771
receiver.visit(new StaticCompilationVisitor(controller.getSourceUnit(), controller.getClassNode()));
// replace assignment to a subscript operator with a method call
// e.g. x[5] = 10 -> methodCall(x, "putAt", [5, 10])
MethodCallExpression call = callX(receiver, "putAt", args(subscript, rhsValueLoader));
call.setSafe(safe);
call.setSourcePosition(enclosing);
OperandStack operandStack = controller.getOperandStack();
int height = operandStack.getStackLength();
call.visit(controller.getAcg());
operandStack.pop();
operandStack.remove(operandStack.getStackLength() - height);
// return value of assignment
rhsValueLoader.visit(controller.getAcg());
}
}
Aggregations