Search in sources :

Example 11 with VarDecXE

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

the class DesugarVars method _blockVarClass.

private RoundBlock _blockVarClass(RoundBlock s) {
    if (s.getContents().isEmpty()) {
        return s;
    }
    List<VarDec> varDecs = new ArrayList<VarDec>(s.getContents().get(0).getDecs());
    int pos = firstVar(varDecs);
    if (pos == -1) {
        return s;
    }
    VarDecXE varDec = (VarDecXE) varDecs.get(pos);
    varDecs.set(pos, varDec.withVar(false));
    VarDecCE ce = getClassBForVar(varDec);
    VarDecXE d = getDecForVar(ce.getInner().getName(), varDec);
    X x = new X(s.getP(), varDec.getX());
    X z = new X(s.getP(), d.getX());
    int d3First = findD2(x, pos, varDecs);
    RoundBlock fake = getFakeBlock(x, z, s, varDecs, d3First);
    List<VarDec> trueDecs = new ArrayList<VarDec>();
    trueDecs.add(ce);
    if (d3First != -1) {
        trueDecs.addAll(varDecs.subList(0, d3First));
    } else {
        trueDecs.addAll(varDecs);
    }
    trueDecs.add(d);
    trueDecs.addAll(fake.getContents().get(0).getDecs());
    List<Expression.BlockContent> trueContent = new ArrayList<>();
    trueContent.add(new Expression.BlockContent(trueDecs, fake.getContents().get(0).get_catch()));
    return fake.withContents(trueContent);
}
Also used : Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) X(ast.Expression.X) BlockContent(ast.Expression.BlockContent) VarDecCE(ast.Ast.VarDecCE) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE) BlockContent(ast.Expression.BlockContent)

Example 12 with VarDecXE

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

the class DesugarVars method getDecForVar.

private VarDecXE getDecForVar(Ast.C cName, VarDecXE varDec) {
    Type nt = new Type(Mdf.Mutable, Path.outer(0).pushC(cName), Doc.empty());
    Position pos = Desugar.getPosition(varDec.getInner());
    MCall right = new MCall(new Expression.EPath(pos, nt.getPath()), "#apply", Doc.empty(), Desugar.getPs("inner", new X(pos, varDec.getX())), pos);
    String nameZ = Functions.freshName(nt.getPath(), usedVars);
    //usedVars.add(nameZ);
    return new VarDecXE(false, Optional.of(nt), nameZ, right);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Position(ast.Ast.Position) Expression(ast.Expression) MCall(ast.Expression.MCall) X(ast.Expression.X) VarDecXE(ast.Ast.VarDecXE)

Example 13 with VarDecXE

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

the class DesugarW method innerWithXs.

private static Expression innerWithXs(With e) {
    //right side of case b and part of right side of case d
    Expression inner = e.getDefaultE().get();
    List<String> xs = new ArrayList<String>(e.getXs());
    for (VarDecXE d : e.getDecs()) {
        xs.add(d.getX());
    }
    for (VarDecXE d : e.getIs()) {
        xs.add(d.getX());
    }
    inner = new With(e.getP(), xs, Collections.emptyList(), Collections.emptyList(), e.getOns(), e.getDefaultE());
    return inner;
}
Also used : Expression(ast.Expression) ArrayList(java.util.ArrayList) VarDecXE(ast.Ast.VarDecXE) With(ast.Expression.With)

Example 14 with VarDecXE

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

the class Desugar method blockEtoXE.

private RoundBlock blockEtoXE(RoundBlock s) {
    if (s.getContents().isEmpty()) {
        return s;
    }
    List<VarDec> decs = s.getContents().get(0).getDecs();
    List<VarDec> newDecs = new ArrayList<VarDec>();
    for (VarDec _dec : decs) {
        if (!(_dec instanceof VarDecE)) {
            newDecs.add(_dec);
            continue;
        }
        VarDecE dec = (VarDecE) _dec;
        String x = Functions.freshName("unused", usedVars);
        //usedVars.add(x);
        VarDecXE newXE = new VarDecXE(false, Optional.of(Type.immVoid), x, dec.getInner());
        newDecs.add(newXE);
    }
    RoundBlock result = blockWithDec(s, newDecs);
    //assert L42.checkWellFormedness(result);
    return result;
}
Also used : VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE) VarDecXE(ast.Ast.VarDecXE)

Example 15 with VarDecXE

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

the class ToAst method parseRealVDec.

private VarDecXE parseRealVDec(VarDecContext vd) {
    TContext tt = vd.t();
    Optional<Type> t = (tt == null) ? Optional.<Type>empty() : Optional.of(parseType(tt));
    Expression inner = vd.eTop().accept(this);
    return new Ast.VarDecXE(vd.Var() != null, t, nameL(vd.x()), inner);
}
Also used : Type(ast.Ast.Type) Expression(ast.Expression) VarDecXE(ast.Ast.VarDecXE)

Aggregations

VarDecXE (ast.Ast.VarDecXE)15 ArrayList (java.util.ArrayList)12 Expression (ast.Expression)11 VarDec (ast.Ast.VarDec)9 X (ast.Expression.X)7 RoundBlock (ast.Expression.RoundBlock)6 Type (ast.Ast.Type)5 VarDecE (ast.Ast.VarDecE)4 Parameters (ast.Ast.Parameters)3 MethodWithType (ast.Expression.ClassB.MethodWithType)3 MethodSelectorX (ast.Ast.MethodSelectorX)2 MethodType (ast.Ast.MethodType)2 BlockContent (ast.Expression.BlockContent)2 Catch (ast.Expression.Catch)2 Doc (ast.Ast.Doc)1 Position (ast.Ast.Position)1 VarDecCE (ast.Ast.VarDecCE)1 Loop (ast.Expression.Loop)1 MCall (ast.Expression.MCall)1 Signal (ast.Expression.Signal)1