int i = from;
for (; i < to; i++) {
ASTNode e = exprs[i];
if (introduceIfReturnRest && e instanceof If && !RETURN_SYMBOL.builtinIsOverridden()) {
If ifExpr = (If) e;
if (i < to - 1 && ifExpr.getFalseCase() == null) {
// if (cond) { .... } ; remaining - we don't know yet if there is a return
ASTNode trueBranch = ifExpr.getTrueCase();
RNode truePart = null;
RNode returnCallArg = returnCallArgument(trueBranch);
if (returnCallArg != null) {
truePart = null;
} else if (trueBranch instanceof Sequence) {
Sequence trueSequence = (Sequence) trueBranch;
ASTNode[] trueExprs = trueSequence.getExprs();
if (trueExprs.length > 1) {
// FIXME: in theory we could be looking recursively into the tree, but recovery would then become hard
ASTNode lastTrueExpr = trueExprs[trueExprs.length - 1];
returnCallArg = returnCallArgument(lastTrueExpr);
if (returnCallArg != null) {
truePart = buildSequence(trueSequence, trueExprs, 0, trueExprs.length - 1, false);
}
}
}
if (returnCallArg != null) {
// if (cond) { .... ; return(returnCallArg) } ; remaining (no we know there is a return in the true branch
RNode remainingSubsequence = buildSequence(origSequence, exprs, i + 1, to, true);
RNode newIf = new r.nodes.exec.If.IfReturnRest.ReturnBuiltin(e, createLazyTree(ifExpr.getCond()), truePart,
returnCallArg, remainingSubsequence);
rexprs[i - from] = newIf;
if (DEBUG_RETURN) System.err.println("Converted if with return, new if is " + PrettyPrinter.prettyPrint(newIf.getAST()));
i++;
break;