Search in sources :

Example 1 with SquareCall

use of ast.Expression.SquareCall in project L42 by ElvisResearchGroup.

the class DesugarW method visit.

public Expression visit(SquareWithCall s) {
    //we can assumethe receivers are normalized after DesugarContext
    assert s.getReceiver() instanceof Ast.Atom : s;
    //(b=r.builder() b.a() b.b() b.c() .... b)
    List<VarDec> vd = new ArrayList<>();
    Expression k = Desugar.getMCall(s.getP(), s.getReceiver(), "#seqBuilder", Desugar.getPs());
    String x = Functions.freshName("b", usedVars);
    X b = new X(s.getP(), x);
    vd.add(new VarDecXE(false, Optional.empty(), x, k));
    Expression ew = s.getWith().accept(this);
    ew = ew.accept(new CloneVisitor() {

        @Override
        public Expression visit(Expression.UseSquare u) {
            SquareCall sq = (SquareCall) u.getInner();
            //inner, hide external one to prevent use (was a bug before)
            List<VarDec> vd = new ArrayList<>();
            for (Parameters ps : sq.getPss()) {
                vd.add(new VarDecE(Desugar.getMCall(s.getP(), b, "#add", ps)));
            }
            return Desugar.getBlock(s.getP(), vd, Expression._void.instance);
        }
    });
    vd.add(new VarDecE(ew));
    Expression inner = Desugar.getBlock(s.getP(), vd, b);
    Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("seqBuilder"), Collections.singletonList(inner));
    return Desugar.getMCall(s.getP(), s.getReceiver(), "#from", ps);
}
Also used : Parameters(ast.Ast.Parameters) ArrayList(java.util.ArrayList) VarDecE(ast.Ast.VarDecE) Expression(ast.Expression) VarDec(ast.Ast.VarDec) X(ast.Expression.X) SquareCall(ast.Expression.SquareCall) VarDecXE(ast.Ast.VarDecXE)

Aggregations

Parameters (ast.Ast.Parameters)1 VarDec (ast.Ast.VarDec)1 VarDecE (ast.Ast.VarDecE)1 VarDecXE (ast.Ast.VarDecXE)1 Expression (ast.Expression)1 SquareCall (ast.Expression.SquareCall)1 X (ast.Expression.X)1 ArrayList (java.util.ArrayList)1