use of ast.Expression in project L42 by ElvisResearchGroup.
the class DesugarW method withDesugarGetDefaultCatch.
private Catch withDesugarGetDefaultCatch(Position pos, SignalKind kind, Expression eClose) {
String propagated1 = Functions.freshName("propagated", usedVars);
Expression blockPropagate1 = Desugar.getBlock(pos, eClose, new Signal(kind, new X(pos, propagated1)));
Type t = Type.immAny;
Expression.Catch1 k1 = new Expression.Catch1(pos, kind, t, propagated1, blockPropagate1);
return new DesugarCatchDefault.CatchToComplete(k1);
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class DesugarW method of.
public static Expression of(Set<String> usedVars, Expression e) {
DesugarW d = new DesugarW();
d.usedVars = usedVars;
Expression result = e.accept(d);
return result;
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class DesugarW method visit.
public Expression visit(SquareWithCall s) {
//we can assumethe receivers are normalized after DesugarContext
assert s.getReceiver() instanceof Ast.Atom : s;
//(b=r.builder() b.a() b.b() b.c() .... b)
List<VarDec> vd = new ArrayList<>();
Expression k = Desugar.getMCall(s.getP(), s.getReceiver(), "#seqBuilder", Desugar.getPs());
String x = Functions.freshName("b", usedVars);
X b = new X(s.getP(), x);
vd.add(new VarDecXE(false, Optional.empty(), x, k));
Expression ew = s.getWith().accept(this);
ew = ew.accept(new CloneVisitor() {
@Override
public Expression visit(Expression.UseSquare u) {
SquareCall sq = (SquareCall) u.getInner();
//inner, hide external one to prevent use (was a bug before)
List<VarDec> vd = new ArrayList<>();
for (Parameters ps : sq.getPss()) {
vd.add(new VarDecE(Desugar.getMCall(s.getP(), b, "#add", ps)));
}
return Desugar.getBlock(s.getP(), vd, Expression._void.instance);
}
});
vd.add(new VarDecE(ew));
Expression inner = Desugar.getBlock(s.getP(), vd, b);
Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("seqBuilder"), Collections.singletonList(inner));
return Desugar.getMCall(s.getP(), s.getReceiver(), "#from", ps);
}
use of ast.Expression in project L42 by ElvisResearchGroup.
the class DesugarW method withNext.
private static Expression.BlockContent withNext(Position pos, int index, List<String> xs) {
Expression eStart = Desugar.getMCall(pos, new X(pos, xs.get(index)), "#next", Desugar.getPs());
List<VarDec> decs = new ArrayList<>();
for (String x : xs.subList(index + 1, xs.size())) {
Expression ei = Desugar.getMCall(pos, new X(pos, x), "#next", Desugar.getPs());
ei = withE1CatchExceptionOnVoidE2elseE3(pos, ei, Expression._void.instance, Expression._void.instance);
decs.add(new VarDecE(ei));
}
for (String x : xs) {
Expression ei = Desugar.getMCall(pos, new X(pos, x), "#checkEnd", Desugar.getPs());
ei = withE1CatchExceptionOnVoidE2elseE3(pos, ei, Expression._void.instance, Expression._void.instance);
decs.add(new VarDecE(ei));
}
Expression eCatch = Desugar.getBlock(pos, decs, new Signal(SignalKind.Exception, Expression._void.instance));
Expression.Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, eCatch);
return Desugar.getBlockContent(eStart, k);
}
use of ast.Expression 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;
}
Aggregations