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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations