Search in sources :

Example 1 with VarDec

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

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

the class DesugarW method withDeclareIts.

private RoundBlock withDeclareIts(List<VarDecXE> is, RoundBlock inner) {
    if (is.isEmpty()) {
        return inner;
    }
    VarDecXE i0 = is.get(0);
    List<VarDecXE> is2 = is.subList(1, is.size());
    List<VarDec> decs = new ArrayList<VarDec>();
    decs.add(i0.withVar(false));
    RoundBlock conclusive = withDeclareItsNestedBlock(inner, i0, is2);
    return Desugar.getBlock(inner.getP(), decs, conclusive);
}
Also used : VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE)

Example 3 with VarDec

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

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

the class DesugarW method withNext.

private static Expression.BlockContent withNext(Position pos, int index, List<String> xs) {
    Expression eStart = Desugar.getMCall(pos, new X(pos, xs.get(index)), "#next", Desugar.getPs());
    List<VarDec> decs = new ArrayList<>();
    for (String x : xs.subList(index + 1, xs.size())) {
        Expression ei = Desugar.getMCall(pos, new X(pos, x), "#next", Desugar.getPs());
        ei = withE1CatchExceptionOnVoidE2elseE3(pos, ei, Expression._void.instance, Expression._void.instance);
        decs.add(new VarDecE(ei));
    }
    for (String x : xs) {
        Expression ei = Desugar.getMCall(pos, new X(pos, x), "#checkEnd", Desugar.getPs());
        ei = withE1CatchExceptionOnVoidE2elseE3(pos, ei, Expression._void.instance, Expression._void.instance);
        decs.add(new VarDecE(ei));
    }
    Expression eCatch = Desugar.getBlock(pos, decs, new Signal(SignalKind.Exception, Expression._void.instance));
    Expression.Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, eCatch);
    return Desugar.getBlockContent(eStart, k);
}
Also used : Signal(ast.Expression.Signal) Expression(ast.Expression) VarDec(ast.Ast.VarDec) X(ast.Expression.X) ArrayList(java.util.ArrayList) VarDecE(ast.Ast.VarDecE) Catch(ast.Expression.Catch)

Example 5 with VarDec

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

the class FlatFirstLevelLocalNestedClasses method liftVarDecs.

protected List<ast.Ast.VarDec> liftVarDecs(List<ast.Ast.VarDec> ds) {
    List<ast.Ast.VarDec> result = new ArrayList<>();
    for (VarDec d : ds) {
        if (!(d instanceof ast.Ast.VarDecCE)) {
            result.add(d);
            continue;
        }
        NestedClass nc = ((ast.Ast.VarDecCE) d).getInner();
        collected.add(nc);
    }
    return super.liftVarDecs(result);
}
Also used : VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList)

Aggregations

VarDec (ast.Ast.VarDec)25 ArrayList (java.util.ArrayList)17 Expression (ast.Expression)16 VarDecE (ast.Ast.VarDecE)10 VarDecXE (ast.Ast.VarDecXE)9 RoundBlock (ast.Expression.RoundBlock)9 BlockContent (ast.Expression.BlockContent)7 X (ast.Expression.X)6 Catch (ast.Expression.Catch)5 Type (ast.Ast.Type)4 Doc (ast.Ast.Doc)3 Parameters (ast.Ast.Parameters)3 MethodSelectorX (ast.Ast.MethodSelectorX)2 MethodType (ast.Ast.MethodType)2 MethodWithType (ast.Expression.ClassB.MethodWithType)2 Ast (ast.Ast)1 Position (ast.Ast.Position)1 VarDecCE (ast.Ast.VarDecCE)1 ErrorMessage (ast.ErrorMessage)1 BinOp (ast.Expression.BinOp)1