/** * Add an if clause to a (potentially) pre-existing else clause. The else clase can be null, or * can be an if expression. */ private Expr addIfClause(IfClause c, Expr elsePart) { GeneratorClause g = c.getTestClause(); if (g.getBind().size() > 0) { // if binds <- expr then body else elsePart end desugars to // __cond(expr, fn (binds) => body, elsePart) ArrayList<Expr> args = new ArrayList<Expr>(3); args.add(g.getInit()); args.add(bindsAndBody(g, c.getBody())); if (elsePart != null) args.add(thunk(elsePart)); return (Expr) recur( ExprFactory.make_RewriteFnApp( NodeUtil.getSpan(c), COND_NAME, ExprFactory.makeTupleExpr(NodeUtil.getSpan(c), args))); } // if expr then body else elsePart end is preserved // (but we replace elif chains by nesting). if (elsePart == null) { return (Expr) super.forIf(ExprFactory.makeIf(NodeUtil.getSpan(c), c)); } else { return (Expr) super.forIf(ExprFactory.makeIf(NodeUtil.getSpan(c), c, ExprFactory.makeBlock(elsePart))); } }