use of ast.Expression.BlockContent 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;
}
use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.
the class DesugarCatchDefault method liftBC.
protected BlockContent liftBC(BlockContent c) {
if (c.get_catch().isEmpty()) {
return super.liftBC(c);
}
List<Catch> ks = Map.of(this::liftK, c.get_catch());
Type oldR = this.lastReturn;
this.lastReturn = newR(ks);
try {
List<VarDec> liftVarDecs = liftVarDecs(c.getDecs());
return new BlockContent(liftVarDecs, ks);
} finally {
this.lastReturn = oldR;
}
}
use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.
the class DesugarVars method visit.
public Expression visit(CurlyBlock s) {
Expression inner;
if (s.getContents().size() == 1 && s.getContents().get(0).get_catch().isEmpty() && s.getContents().get(0).getDecs().size() == 1 && s.getContents().get(0).getDecs().get(0) instanceof VarDecE) {
inner = ((VarDecE) s.getContents().get(0).getDecs().get(0)).getInner();
} else {
inner = new RoundBlock(s.getP(), s.getDoc(), Expression._void.instance, s.getContents());
}
inner = inner.accept(this);
List<VarDec> vd = Collections.singletonList((VarDec) new VarDecE(inner));
BlockContent o = new BlockContent(vd, Collections.emptyList());
return new CurlyBlock(s.getP(), Doc.empty(), Collections.singletonList(o));
}
use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.
the class DesugarW method with_C_A.
private Expression with_C_A(Position pos, List<String> xs, With.On on0, Expression continuation) {
List<String> ys = new ArrayList<String>();
for (String x : xs) {
ys.add(Functions.freshName(x, usedVars));
}
//(
List<VarDec> decs = new ArrayList<>();
//TODO:?? now is very strange and requires the mdf to propagate it to the locally introduced var?
//casts: every cast is a block content e+catch
{
int i = -1;
for (Type ti : on0.getTs()) {
i += 1;
String xi = xs.get(i);
String yi = ys.get(i);
decs.add(castT(pos, ti, yi, xi));
}
}
//catch exception Void recursive call
Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, continuation);
//main expression with 'T' renaming
Expression e0 = on0.getInner();
{
int i = -1;
for (Type ti : on0.getTs()) {
i += 1;
String xi = xs.get(i);
String yi = ys.get(i);
e0 = renameT(e0, new Expression.X(pos, xi), ti, new Expression.X(pos, yi));
}
}
BlockContent content = new BlockContent(decs, Collections.singletonList(k));
List<BlockContent> contents = new ArrayList<BlockContent>();
contents.add(content);
contents.add(Desugar.getBlockContent(e0));
//void)
return new RoundBlock(pos, Doc.empty(), Expression._void.instance, contents);
}
use of ast.Expression.BlockContent in project L42 by ElvisResearchGroup.
the class ToAst method visitCurlyBlock.
@Override
public Expression visitCurlyBlock(CurlyBlockContext ctx) {
Doc doc = parseDoc(ctx.docsOpt());
List<BlockContent> contents = new ArrayList<BlockContent>();
for (BbContext b : ctx.bb()) {
List<VarDec> decs = new ArrayList<VarDec>();
for (DContext d : b.d()) {
decs.add(parseVDec(d));
}
assert b.ks() != null;
List<Catch> _catch = parseKs(b.ks());
contents.add(new BlockContent(decs, _catch));
}
return new Expression.CurlyBlock(position(ctx), doc, contents);
}
Aggregations