} prevPop = null; simplifiedStatements.add(o); if (o instanceof JVariableDeclarationStatement) { numDecls++;
} else { LoopIterInfo forLoopInfo = null; SIRPopExpression popExpr = null;    if (o instanceof JForStatement) { JForStatement forStmt = (JForStatement)o; JStatement body = forStmt.getBody(); if ((body instanceof JExpressionStatement) && ((JExpressionStatement)body).getExpression() instanceof SIRPopExpression) { popExpr = (SIRPopExpression) ((JExpressionStatement)body).getExpression(); forLoopInfo = LoopIterInfo.getLoopInfo(forStmt.getInit(), forStmt.getCondition(), forStmt.getIncrement(), forStmt.getBody(), new HashMap(),new HashMap()); }    if (forLoopInfo == null && ! (body instanceof JBlock)) { JBlock block = new JBlock(); block.addStatement(body); forStmt.setBody(block); } } if (forLoopInfo != null) { int popCount = popExpr.getNumPop() * LoopIterInfo.getNumIterations(forLoopInfo); if (popCount > 0) { if (prevPop != null && prevPop.getType().equals(popExpr.getType())) { prevPop.setNumPop(prevPop.getNumPop()+popCount); } else { popExpr.setNumPop(popCount); prevPop = popExpr; simplifiedStatements.add(new JExpressionStatement(popExpr)); } } } else { prevPop = null; simplifiedStatements.add(o); }
    public Object visitBlockStatement(JBlock self,            JavaStyleComment[] comments) {        SIRPopExpression oldPrevPop = prevPop;        prevPop = null;                JBlock newBlock = (JBlock)super.visitBlockStatement(self,comments);                List /*<JStatement>*/ oldStatements = newBlock.getStatements();        List /*<JStatement>*/ simplifiedStatements = new LinkedList();        int numDecls = 0;        for (Iterator i = oldStatements.iterator(); i.hasNext();) {            Object o = i.next();            if (o != null && !(o instanceof JEmptyStatement)) {                if ((o instanceof JExpressionStatement) &&                    ((JExpressionStatement)(o)).getExpression() instanceof                     SIRPopExpression) {                    // found a pop.                      SIRPopExpression popExpr = (SIRPopExpression)((JExpressionStatement)o).getExpression();                    if (prevPop != null) {                        //combine with immediately previous pop if any                         prevPop.setNumPop(popExpr.getNumPop() + prevPop.getNumPop());                        continue;                    } else {                        // no immediately previous pop in block, but this                        // could be previous for the next statement.                        prevPop = popExpr;                        simplifiedStatements.add(o);                        continue;                    } // assert false : "execution does not get here";                }                 prevPop = null;                simplifiedStatements.add(o);                if (o instanceof JVariableDeclarationStatement) {                numDecls++;                }            }        }        // restore previous pop outside of block        prevPop = oldPrevPop;        // empty block becomes empty statement for surrounding block to elide        int newLen = simplifiedStatements.size();        if (newLen - numDecls == 0) {            // nothing except declarations which should have no effect outside block            return new JEmptyStatement();        }        if (newLen == 1) {            // single statment (not declation)            return simplifiedStatements.get(0);        } else if (newLen == oldStatements.size()) {            // same length: this loop only deletes never changes            return newBlock;        }        return new JBlock(newBlock.getTokenReference(),                simplifiedStatements,newBlock.getComments());    }