use of ast.Ast.VarDecXE 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.VarDecXE in project L42 by ElvisResearchGroup.
the class DesugarW method castT.
private VarDecXE castT(Position pos, Type t, String y, String x) {
assert t instanceof Type;
Type nt = t;
String z = Functions.freshName("casted", usedVars);
List<Catch> ks = new ArrayList<>();
Type t2 = new Type(nt.getMdf(), Path.Any(), Doc.empty());
ks.add(new //case return captured
Expression.Catch1(//case return captured
pos, //case return captured
SignalKind.Return, //case return captured
t, //case return captured
z, //return it
new X(pos, z)));
ks.add(new //else
Expression.Catch1(//else
pos, //else
SignalKind.Return, //else
t2, //else
z, // exception void
new Signal(SignalKind.Exception, Expression._void.instance)));
RoundBlock block = Desugar.getBlock(pos, new Signal(SignalKind.Return, new X(pos, x)), ks, Desugar.errorMsg("CastT-Should be unreachable code"));
return new VarDecXE(false, Optional.of(t), y, block);
}
use of ast.Ast.VarDecXE in project L42 by ElvisResearchGroup.
the class DesugarW method withDeclareIts.
private RoundBlock withDeclareIts(List<VarDecXE> is, RoundBlock inner) {
if (is.isEmpty()) {
return inner;
}
VarDecXE i0 = is.get(0);
List<VarDecXE> is2 = is.subList(1, is.size());
List<VarDec> decs = new ArrayList<VarDec>();
decs.add(i0.withVar(false));
RoundBlock conclusive = withDeclareItsNestedBlock(inner, i0, is2);
return Desugar.getBlock(inner.getP(), decs, conclusive);
}
use of ast.Ast.VarDecXE 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.VarDecXE 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