use of org.codehaus.groovy.ast.expr.ClosureListExpression in project groovy-core by groovy.
the class StatementWriter method writeForLoopWithClosureList.
protected void writeForLoopWithClosureList(ForStatement loop) {
controller.getAcg().onLineNumber(loop, "visitForLoop");
writeStatementLabel(loop);
MethodVisitor mv = controller.getMethodVisitor();
controller.getCompileStack().pushLoop(loop.getVariableScope(), loop.getStatementLabels());
ClosureListExpression clExpr = (ClosureListExpression) loop.getCollectionExpression();
controller.getCompileStack().pushVariableScope(clExpr.getVariableScope());
List expressions = clExpr.getExpressions();
int size = expressions.size();
// middle element is condition, lower half is init, higher half is increment
int condIndex = (size - 1) / 2;
// visit init
for (int i = 0; i < condIndex; i++) {
visitExpressionOrStatement(expressions.get(i));
}
Label continueLabel = controller.getCompileStack().getContinueLabel();
Label breakLabel = controller.getCompileStack().getBreakLabel();
Label cond = new Label();
mv.visitLabel(cond);
// visit condition leave boolean on stack
{
Expression condExpr = (Expression) expressions.get(condIndex);
int mark = controller.getOperandStack().getStackLength();
condExpr.visit(controller.getAcg());
controller.getOperandStack().castToBool(mark, true);
}
// jump if we don't want to continue
// note: ifeq tests for ==0, a boolean is 0 if it is false
controller.getOperandStack().jump(IFEQ, breakLabel);
// Generate the loop body
loop.getLoopBlock().visit(controller.getAcg());
// visit increment
mv.visitLabel(continueLabel);
for (int i = condIndex + 1; i < size; i++) {
visitExpressionOrStatement(expressions.get(i));
}
// jump to test the condition again
mv.visitJumpInsn(GOTO, cond);
// loop end
mv.visitLabel(breakLabel);
controller.getCompileStack().pop();
controller.getCompileStack().pop();
}
use of org.codehaus.groovy.ast.expr.ClosureListExpression in project groovy by apache.
the class StatementWriter method writeForLoopWithClosureList.
protected void writeForLoopWithClosureList(ForStatement loop) {
controller.getAcg().onLineNumber(loop, "visitForLoop");
writeStatementLabel(loop);
MethodVisitor mv = controller.getMethodVisitor();
controller.getCompileStack().pushLoop(loop.getVariableScope(), loop.getStatementLabels());
ClosureListExpression clExpr = (ClosureListExpression) loop.getCollectionExpression();
controller.getCompileStack().pushVariableScope(clExpr.getVariableScope());
List expressions = clExpr.getExpressions();
int size = expressions.size();
// middle element is condition, lower half is init, higher half is increment
int condIndex = (size - 1) / 2;
// visit init
for (int i = 0; i < condIndex; i++) {
visitExpressionOrStatement(expressions.get(i));
}
Label continueLabel = controller.getCompileStack().getContinueLabel();
Label breakLabel = controller.getCompileStack().getBreakLabel();
Label cond = new Label();
mv.visitLabel(cond);
// visit condition leave boolean on stack
{
Expression condExpr = (Expression) expressions.get(condIndex);
int mark = controller.getOperandStack().getStackLength();
condExpr.visit(controller.getAcg());
controller.getOperandStack().castToBool(mark, true);
}
// jump if we don't want to continue
// note: ifeq tests for ==0, a boolean is 0 if it is false
controller.getOperandStack().jump(IFEQ, breakLabel);
// Generate the loop body
loop.getLoopBlock().visit(controller.getAcg());
// visit increment
mv.visitLabel(continueLabel);
for (int i = condIndex + 1; i < size; i++) {
visitExpressionOrStatement(expressions.get(i));
}
// jump to test the condition again
mv.visitJumpInsn(GOTO, cond);
// loop end
mv.visitLabel(breakLabel);
controller.getCompileStack().pop();
controller.getCompileStack().pop();
}
Aggregations