Search in sources :

Example 1 with Parameters

use of ast.Ast.Parameters in project L42 by ElvisResearchGroup.

the class Desugar method visit1Step.

public MCall visit1Step(SquareCall s) {
    //we can assumethe receivers are normalized after DesugarContext
    //assert s.getReceiver() instanceof Ast.Atom:      s.getReceiver();
    //but nor really, since vars accesses are replaced by meth calls. In that case is fine to not have an atom.
    //(b=r.builder() b.a() b.b() b.c() .... b)
    List<VarDec> vd = new ArrayList<>();
    Expression k = getMCall(s.getP(), s.getReceiver(), "#seqBuilder", getPs());
    String x = Functions.freshName("b", usedVars);
    X b = new X(s.getP(), x);
    vd.add(new VarDecXE(false, Optional.empty(), x, k));
    for (Parameters ps : s.getPss()) {
        vd.add(new VarDecE(getMCall(s.getP(), b, "#add", ps)));
    }
    Expression inner = getBlock(s.getP(), vd, b);
    Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("seqBuilder"), Collections.singletonList(inner));
    return getMCall(s.getP(), s.getReceiver(), "#from", ps);
}
Also used : Parameters(ast.Ast.Parameters) Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX) VarDecE(ast.Ast.VarDecE) VarDecXE(ast.Ast.VarDecXE)

Example 2 with Parameters

use of ast.Ast.Parameters in project L42 by ElvisResearchGroup.

the class Desugar method liftPs.

protected Parameters liftPs(Parameters ps) {
    if (!ps.getE().isPresent()) {
        return liftPsPropagate(ps);
    }
    List<String> xs = new ArrayList<String>(ps.getXs());
    List<Expression> es = new ArrayList<Expression>(ps.getEs());
    xs.add(0, "that");
    es.add(0, ps.getE().get());
    return liftPsPropagate(new Parameters(Optional.empty(), xs, es));
}
Also used : Parameters(ast.Ast.Parameters) Expression(ast.Expression) ArrayList(java.util.ArrayList)

Example 3 with Parameters

use of ast.Ast.Parameters 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)

Example 4 with Parameters

use of ast.Ast.Parameters in project L42 by ElvisResearchGroup.

the class DesugarContext method visit.

public Expression visit(SquareCall s) {
    List<Parameters> pss = new ArrayList<>();
    for (Parameters ps : s.getPss()) {
        pss.add(ContextReplace.of(s.getP(), s.getReceiver(), "#square", ps));
    }
    s = s.withPss(pss);
    return super.visit(s);
}
Also used : Parameters(ast.Ast.Parameters) ArrayList(java.util.ArrayList)

Example 5 with Parameters

use of ast.Ast.Parameters in project L42 by ElvisResearchGroup.

the class ToAst method visitUsing.

@Override
public Expression visitUsing(UsingContext ctx) {
    Path path = Ast.Path.sugarParse(nameU(ctx.Path()));
    Expression inner = ctx.eTop().accept(this);
    String name = nameL(ctx.mCall().m());
    Parameters parameters = this.parseMParameters(ctx.mCall().round().ps());
    Doc docs = parseDoc(ctx.mCall().round().docsOpt());
    return new Expression.Using(path, name, docs, parameters, inner);
}
Also used : Path(ast.Ast.Path) Parameters(ast.Ast.Parameters) Expression(ast.Expression) Doc(ast.Ast.Doc)

Aggregations

Parameters (ast.Ast.Parameters)8 Expression (ast.Expression)6 ArrayList (java.util.ArrayList)6 X (ast.Expression.X)4 MethodSelectorX (ast.Ast.MethodSelectorX)3 VarDec (ast.Ast.VarDec)3 VarDecE (ast.Ast.VarDecE)3 VarDecXE (ast.Ast.VarDecXE)3 MethodType (ast.Ast.MethodType)2 Type (ast.Ast.Type)2 MethodWithType (ast.Expression.ClassB.MethodWithType)2 Doc (ast.Ast.Doc)1 FieldDec (ast.Ast.FieldDec)1 MethodSelector (ast.Ast.MethodSelector)1 Path (ast.Ast.Path)1 MCall (ast.Expression.MCall)1 SquareCall (ast.Expression.SquareCall)1 Using (ast.Expression.Using)1