private void genLoop(JCStatement loop,
                             JCStatement body,
                             JCExpression cond,
                             List<JCExpressionStatement> step,
                             boolean testFirst) {
            Env<GenContext> loopEnv = env.dup(loop, new GenContext());
            int startpc = code.entryPoint();
            if (testFirst) { //while or for loop
                CondItem c;
                if (cond != null) {
                    code.statBegin(cond.pos);
                    Assert.check(code.state.stacksize == 0);
                    c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER);
                } else {
                    c = items.makeCondItem(goto_);
                }
                Chain loopDone = c.jumpFalse();
                code.resolve(c.trueJumps);
                Assert.check(code.state.stacksize == 0);
                genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET);
                code.resolve(loopEnv.info.cont);
                genStats(step, loopEnv);
                code.resolve(code.branch(goto_), startpc);
                code.resolve(loopDone);
            } else {
                genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET);
                code.resolve(loopEnv.info.cont);
                genStats(step, loopEnv);
                if (code.isAlive()) {
                    CondItem c;
                    if (cond != null) {
                        code.statBegin(cond.pos);
                        Assert.check(code.state.stacksize == 0);
                        c = genCond(TreeInfo.skipParens(cond), CRT_FLOW_CONTROLLER);
                    } else {
                        c = items.makeCondItem(goto_);
                    }
                    code.resolve(c.jumpTrue(), startpc);
                    Assert.check(code.state.stacksize == 0);
                    code.resolve(c.falseJumps);
                }
            }
            Chain exit = loopEnv.info.exit;
            if (exit != null) {
                code.resolve(exit);
                exit.state.defined.excludeFrom(code.nextreg);
            }
        }
private void genLoop ( JCStatement loop , JCStatement body , JCExpression cond , List < JCExpressionStatement > step , boolean testFirst ) { Env < GenContext > loopEnv = env . dup ( loop , new GenContext ( ) ) ; int startpc = code . entryPoint ( ) ; if ( testFirst ) { CondItem c ; if ( cond != null ) { code . statBegin ( cond . pos ) ; Assert . check ( code . state . stacksize == 0 ) ; c = genCond ( TreeInfo . skipParens ( cond ) , CRT_FLOW_CONTROLLER ) ; } else { c = items . makeCondItem ( goto_ ) ; } Chain loopDone = c . jumpFalse ( ) ; code . resolve ( c . trueJumps ) ; Assert . check ( code . state . stacksize == 0 ) ; genStat ( body , loopEnv , CRT_STATEMENT | CRT_FLOW_TARGET ) ; code . resolve ( loopEnv . info . cont ) ; genStats ( step , loopEnv ) ; code . resolve ( code . branch ( goto_ ) , startpc ) ; code . resolve ( loopDone ) ; } else { genStat ( body , loopEnv , CRT_STATEMENT | CRT_FLOW_TARGET ) ; code . resolve ( loopEnv . info . cont ) ; genStats ( step , loopEnv ) ; if ( code . isAlive ( ) ) { CondItem c ; if ( cond != null ) { code . statBegin ( cond . pos ) ; Assert . check ( code . state . stacksize == 0 ) ; c = genCond ( TreeInfo . skipParens ( cond ) , CRT_FLOW_CONTROLLER ) ; } else { c = items . makeCondItem ( goto_ ) ; } code . resolve ( c . jumpTrue ( ) , startpc ) ; Assert . check ( code . state . stacksize == 0 ) ; code . resolve ( c . falseJumps ) ; } } Chain exit = loopEnv . info . exit ; if ( exit != null ) { code . resolve ( exit ) ; exit . state . defined . excludeFrom ( code . nextreg ) ; } }
Generate code for a loop.
@param loop       The tree representing the loop.
@param body       The loop's body.
@param cond       The loop's controling condition.
@param step       "Step" statements to be inserted at end of
each iteration.
@param testFirst  True if the loop test belongs before the body.