@Override
 public boolean visit(WhileStatement node) {
   node.getBody().accept(this);
   newExpression(node.getExpression());
   node.getExpression().accept(this);
   List<VariableAccess> toExtract = getUnsequencedAccesses();
   if (!toExtract.isEmpty()) {
     // Convert "while (cond)" into "while (true) { if (!(cond)) break; ... }".
     List<Statement> stmtList = TreeUtil.asStatementList(node.getBody()).subList(0, 0);
     extractOrderedAccesses(stmtList, currentTopNode, toExtract);
     stmtList.add(createLoopTermination(node.getExpression()));
     node.setExpression(new BooleanLiteral(true, typeEnv));
   }
   return false;
 }
Ejemplo n.º 2
0
 @Override
 public void endVisit(WhileStatement node) {
   Expression expr = node.getExpression();
   if (getKnownValue(expr) == FALSE) {
     Statement sideEffects = getSideEffects(expr);
     if (sideEffects != null) {
       node.replaceWith(sideEffects);
     } else {
       node.remove();
     }
   }
 }