Search in sources :

Example 16 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarW method withDesugarGetDefaultCatch.

private Catch withDesugarGetDefaultCatch(Position pos, SignalKind kind, Expression eClose) {
    String propagated1 = Functions.freshName("propagated", usedVars);
    Expression blockPropagate1 = Desugar.getBlock(pos, eClose, new Signal(kind, new X(pos, propagated1)));
    Type t = Type.immAny;
    Expression.Catch1 k1 = new Expression.Catch1(pos, kind, t, propagated1, blockPropagate1);
    return new DesugarCatchDefault.CatchToComplete(k1);
}
Also used : Signal(ast.Expression.Signal) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Expression(ast.Expression) Catch1(ast.Expression.Catch1) X(ast.Expression.X) Catch1(ast.Expression.Catch1)

Example 17 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarW method of.

public static Expression of(Set<String> usedVars, Expression e) {
    DesugarW d = new DesugarW();
    d.usedVars = usedVars;
    Expression result = e.accept(d);
    return result;
}
Also used : Expression(ast.Expression)

Example 18 with Expression

use of ast.Expression 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 19 with Expression

use of ast.Expression 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 20 with Expression

use of ast.Expression in project L42 by ElvisResearchGroup.

the class DesugarW method with_E_handleIs.

private Expression with_E_handleIs(Position pos, List<VarDecXE> is, Expression b) {
    //case e in 6 pages
    //xs is dom(Is)
    List<String> xs = new ArrayList<>();
    for (VarDecXE i : is) {
        xs.add(i.getX());
    }
    //di ki is block content =nexti(xs)
    List<BlockContent> bc = new ArrayList<>();
    for (int i = 0; i < xs.size(); i++) {
        bc.add(withNext(pos, i, xs));
    }
    //inner =di ki s b[xs:=xs.#inner()]
    for (String xi : xs) {
        b = XInE.of(new X(pos, xi), Desugar.getMCall(pos, new X(pos, xi), "#inner", Desugar.getPs()), b);
    }
    RoundBlock inner = new RoundBlock(pos, Doc.empty(), b, bc);
    Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, Expression._void.instance);
    inner = Desugar.getBlock(pos, new Loop(inner), Collections.singletonList(k), Expression._void.instance);
    Expression result = withDeclareIts(is, inner);
    //accept
    return result;
}
Also used : Loop(ast.Expression.Loop) Expression(ast.Expression) Catch(ast.Expression.Catch) ArrayList(java.util.ArrayList) BlockContent(ast.Expression.BlockContent) X(ast.Expression.X) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE)

Aggregations

Expression (ast.Expression)66 ArrayList (java.util.ArrayList)24 VarDec (ast.Ast.VarDec)14 X (ast.Expression.X)13 Type (ast.Ast.Type)11 VarDecXE (ast.Ast.VarDecXE)11 ExpCore (ast.ExpCore)11 Catch (ast.Expression.Catch)11 RoundBlock (ast.Expression.RoundBlock)11 VarDecE (ast.Ast.VarDecE)10 Doc (ast.Ast.Doc)8 Position (ast.Ast.Position)8 MethodSelectorX (ast.Ast.MethodSelectorX)7 Parameters (ast.Ast.Parameters)7 MethodWithType (ast.Expression.ClassB.MethodWithType)7 MethodType (ast.Ast.MethodType)6 ClassB (ast.ExpCore.ClassB)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 Path (ast.Ast.Path)4