Search in sources :

Example 6 with RoundBlock

use of ast.Expression.RoundBlock in project L42 by ElvisResearchGroup.

the class Desugar method getBlock.

static RoundBlock getBlock(Position p, String x, Expression xe, Expression inner) {
    List<Expression.BlockContent> bc = new ArrayList<>();
    List<VarDec> decs = new ArrayList<VarDec>();
    decs.add(new VarDecXE(false, Optional.empty(), x, xe));
    bc.add(new Expression.BlockContent(decs, Collections.emptyList()));
    return new RoundBlock(p, Doc.empty(), inner, bc);
}
Also used : Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecXE(ast.Ast.VarDecXE)

Example 7 with RoundBlock

use of ast.Expression.RoundBlock in project L42 by ElvisResearchGroup.

the class Desugar method getBlock.

static RoundBlock getBlock(Position p, Expression xe, List<Expression.Catch> ks, Expression inner) {
    List<Expression.BlockContent> bc = new ArrayList<>();
    List<VarDec> decs = new ArrayList<VarDec>();
    decs.add(new VarDecE(xe));
    bc.add(new Expression.BlockContent(decs, ks));
    return new RoundBlock(p, Doc.empty(), inner, bc);
}
Also used : Expression(ast.Expression) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE)

Example 8 with RoundBlock

use of ast.Expression.RoundBlock in project L42 by ElvisResearchGroup.

the class Desugar method visit.

public Expression visit(CurlyBlock s) {
    assert s.getContents().size() == 1;
    assert s.getContents().get(0).get_catch().isEmpty();
    assert s.getContents().get(0).getDecs().size() == 1;
    assert s.getContents().get(0).getDecs().get(0) instanceof VarDecE;
    Expression inner = ((VarDecE) s.getContents().get(0).getDecs().get(0)).getInner();
    String y = Functions.freshName("result", this.usedVars);
    Expression.Catch k = getK(s.getP(), SignalKind.Return, y, this.t, new X(s.getP(), y));
    Expression termination = Desugar.errorMsg("CurlyBlock-Should be unreachable code");
    RoundBlock outer = getBlock(s.getP(), inner, Collections.singletonList(k), termination);
    return visit(outer);
}
Also used : Expression(ast.Expression) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX) RoundBlock(ast.Expression.RoundBlock) VarDecE(ast.Ast.VarDecE) Catch(ast.Expression.Catch)

Example 9 with RoundBlock

use of ast.Expression.RoundBlock in project L42 by ElvisResearchGroup.

the class DesugarVars method blockContentSepare.

private RoundBlock blockContentSepare(RoundBlock s) {
    if (s.getContents().size() <= 1) {
        return s;
    }
    List<Expression.BlockContent> ctxTop = new ArrayList<>(s.getContents().subList(0, 1));
    List<Expression.BlockContent> ctxPop = new ArrayList<>(s.getContents().subList(1, s.getContents().size()));
    RoundBlock next = blockContentSepare(s.withContents(ctxPop));
    return s.withContents(ctxTop).withInner(next);
}
Also used : ArrayList(java.util.ArrayList) BlockContent(ast.Expression.BlockContent) RoundBlock(ast.Expression.RoundBlock)

Example 10 with RoundBlock

use of ast.Expression.RoundBlock 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)

Aggregations

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