use of ast.Ast.VarDecE in project L42 by ElvisResearchGroup.
the class Desugar method visit1Step.
public MCall visit1Step(SquareCall s) {
//we can assumethe receivers are normalized after DesugarContext
//assert s.getReceiver() instanceof Ast.Atom: s.getReceiver();
//but nor really, since vars accesses are replaced by meth calls. In that case is fine to not have an atom.
//(b=r.builder() b.a() b.b() b.c() .... b)
List<VarDec> vd = new ArrayList<>();
Expression k = getMCall(s.getP(), s.getReceiver(), "#seqBuilder", getPs());
String x = Functions.freshName("b", usedVars);
X b = new X(s.getP(), x);
vd.add(new VarDecXE(false, Optional.empty(), x, k));
for (Parameters ps : s.getPss()) {
vd.add(new VarDecE(getMCall(s.getP(), b, "#add", ps)));
}
Expression inner = getBlock(s.getP(), vd, b);
Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("seqBuilder"), Collections.singletonList(inner));
return getMCall(s.getP(), s.getReceiver(), "#from", ps);
}
use of ast.Ast.VarDecE 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.Ast.VarDecE 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.Ast.VarDecE in project L42 by ElvisResearchGroup.
the class Desugar method getBlockContent.
public static Expression.BlockContent getBlockContent(Expression e, Expression.Catch k) {
List<VarDec> single = new ArrayList<VarDec>();
single.add(new VarDecE(e));
return new Expression.BlockContent(single, Collections.singletonList(k));
}
use of ast.Ast.VarDecE 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);
}
Aggregations