Search in sources :

Example 1 with VarDecCE

use of ast.Ast.VarDecCE 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 2 with VarDecCE

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

the class DesugarVars method getClassBForVar.

private VarDecCE getClassBForVar(VarDecXE varDec) {
    List<FieldDec> fs = new ArrayList<FieldDec>();
    fs.add(new FieldDec(true, _computeTypeForClassBForVar(varDec), "inner", Doc.empty()));
    ClassB cb = new ClassB(Doc.empty(), new Ast.ConcreteHeader(Mdf.Mutable, "", fs, Position.noInfo), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Position.noInfo);
    String nameC = Functions.freshName("Var" + varDec.getX(), L42.usedNames);
    //usedCnames.add(nameC);
    return new VarDecCE(new NestedClass(Doc.empty(), C.of(nameC).withUniqueNum(L42.freshPrivate()), cb, null));
}
Also used : FieldDec(ast.Ast.FieldDec) Ast(ast.Ast) ArrayList(java.util.ArrayList) VarDecCE(ast.Ast.VarDecCE) NestedClass(ast.Expression.ClassB.NestedClass) ClassB(ast.Expression.ClassB)

Aggregations

VarDecCE (ast.Ast.VarDecCE)2 ArrayList (java.util.ArrayList)2 Ast (ast.Ast)1 FieldDec (ast.Ast.FieldDec)1 VarDec (ast.Ast.VarDec)1 VarDecXE (ast.Ast.VarDecXE)1 Expression (ast.Expression)1 BlockContent (ast.Expression.BlockContent)1 ClassB (ast.Expression.ClassB)1 NestedClass (ast.Expression.ClassB.NestedClass)1 RoundBlock (ast.Expression.RoundBlock)1 X (ast.Expression.X)1