use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class InvocationWriter method writeNormalConstructorCall.
protected void writeNormalConstructorCall(final ConstructorCallExpression call) {
Expression arguments = call.getArguments();
if (arguments instanceof TupleExpression) {
TupleExpression tupleExpression = (TupleExpression) arguments;
int size = tupleExpression.getExpressions().size();
if (size == 0) {
arguments = MethodCallExpression.NO_ARGUMENTS;
}
}
Expression receiver = new ClassExpression(call.getType());
controller.getCallSiteWriter().makeCallSite(receiver, CallSiteWriter.CONSTRUCTOR, arguments, false, false, false, false);
}
use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class InvocationWriter method makeUncachedCall.
protected void makeUncachedCall(Expression origin, ClassExpression sender, Expression receiver, Expression message, Expression arguments, MethodCallerMultiAdapter adapter, boolean safe, boolean spreadSafe, boolean implicitThis, boolean containsSpreadExpression) {
CompileStack compileStack = controller.getCompileStack();
OperandStack operandStack = controller.getOperandStack();
AsmClassGenerator acg = controller.getAcg();
// ensure VariableArguments are read, not stored
compileStack.pushLHS(false);
// sender only for call sites
if (adapter == AsmClassGenerator.setProperty) {
ConstantExpression.NULL.visit(acg);
} else {
sender.visit(acg);
}
String methodName = getMethodName(message);
if (adapter == invokeMethodOnSuper && methodName != null) {
// for MOP method
controller.getSuperMethodNames().add(methodName);
}
// receiver
compileStack.pushImplicitThis(implicitThis);
receiver.visit(acg);
operandStack.box();
compileStack.popImplicitThis();
int operandsToRemove = 2;
// message
if (message != null) {
message.visit(acg);
operandStack.box();
operandsToRemove += 1;
}
// arguments
int numberOfArguments = containsSpreadExpression ? -1 : AsmClassGenerator.argumentSize(arguments);
if (numberOfArguments > MethodCallerMultiAdapter.MAX_ARGS || containsSpreadExpression) {
ArgumentListExpression ae = makeArgumentList(arguments);
if (containsSpreadExpression) {
acg.despreadList(ae.getExpressions(), true);
} else {
ae.visit(acg);
}
} else if (numberOfArguments > 0) {
operandsToRemove += numberOfArguments;
TupleExpression te = (TupleExpression) arguments;
for (int i = 0; i < numberOfArguments; i += 1) {
Expression argument = te.getExpression(i);
argument.visit(acg);
operandStack.box();
if (argument instanceof CastExpression)
acg.loadWrapper(argument);
}
}
if (adapter == null)
adapter = invokeMethod;
adapter.call(controller.getMethodVisitor(), numberOfArguments, safe, spreadSafe);
compileStack.popLHS();
operandStack.replace(ClassHelper.OBJECT_TYPE, operandsToRemove);
}
use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class ClosureWriter method createBlockStatementForConstructor.
protected BlockStatement createBlockStatementForConstructor(final ClosureExpression expression, final ClassNode outerClass, final ClassNode thisClassNode) {
BlockStatement block = new BlockStatement();
// this block does not get a source position, because we don't
// want this synthetic constructor to show up in corbertura reports
VariableExpression outer = varX(OUTER_INSTANCE, outerClass);
outer.setSourcePosition(expression);
block.getVariableScope().putReferencedLocalVariable(outer);
VariableExpression thisObject = varX(THIS_OBJECT, thisClassNode);
thisObject.setSourcePosition(expression);
block.getVariableScope().putReferencedLocalVariable(thisObject);
TupleExpression conArgs = new TupleExpression(outer, thisObject);
block.addStatement(stmt(ctorSuperX(conArgs)));
return block;
}
use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class AsmClassGenerator method containsSpreadExpression.
public static boolean containsSpreadExpression(final Expression arguments) {
List<Expression> args;
if (arguments instanceof TupleExpression) {
TupleExpression tupleExpression = (TupleExpression) arguments;
args = tupleExpression.getExpressions();
} else if (arguments instanceof ListExpression) {
ListExpression le = (ListExpression) arguments;
args = le.getExpressions();
} else {
return arguments instanceof SpreadExpression;
}
for (Expression arg : args) {
if (arg instanceof SpreadExpression)
return true;
}
return false;
}
use of org.codehaus.groovy.ast.expr.TupleExpression in project groovy by apache.
the class AsmClassGenerator method visitTupleExpression.
void visitTupleExpression(final TupleExpression expression, final boolean useWrapper) {
MethodVisitor mv = controller.getMethodVisitor();
int size = expression.getExpressions().size();
BytecodeHelper.pushConstant(mv, size);
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
OperandStack operandStack = controller.getOperandStack();
for (int i = 0; i < size; i += 1) {
mv.visitInsn(DUP);
BytecodeHelper.pushConstant(mv, i);
Expression argument = expression.getExpression(i);
argument.visit(this);
operandStack.box();
if (useWrapper && argument instanceof CastExpression)
loadWrapper(argument);
mv.visitInsn(AASTORE);
operandStack.remove(1);
}
}
Aggregations