}
// Attempt to evaluate the loop management code ahead of time.
EvaluationContext context = new EvaluationContext();
context.evaluateStatements(tree.init);
Value condition = context.evaluate(tree.cond);
if (condition == Value.UNKNOWN) {
log.debug("Abort: Condition unknown.");
return;
}
if (!((Boolean) condition.getValue())) {
log.debug("Instantly false for condition...");
// Special case - the loop condition is initially false.
// We can replace the loop with the init statements (Killing any that are variable initialisers or
// depend thereon.
AJCBlock block = tree.getEnclosingBlock();
block.insertBefore(tree, tree.init);
block.remove(tree);
return;
}
int iterations = 0;
while (iterations < UNROLL_LIMIT && condition != Value.UNKNOWN && (Boolean) condition.getValue()) {
context.evaluateExpressionStatements(tree.step);
log.debug("Status: \n{}", context);
condition = context.evaluate(tree.cond);
iterations++;
}