use of ast.Ast.VarDecXE 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);
}
use of ast.Ast.VarDecXE in project L42 by ElvisResearchGroup.
the class DesugarVars method getDecForVar.
private VarDecXE getDecForVar(Ast.C cName, VarDecXE varDec) {
Type nt = new Type(Mdf.Mutable, Path.outer(0).pushC(cName), Doc.empty());
Position pos = Desugar.getPosition(varDec.getInner());
MCall right = new MCall(new Expression.EPath(pos, nt.getPath()), "#apply", Doc.empty(), Desugar.getPs("inner", new X(pos, varDec.getX())), pos);
String nameZ = Functions.freshName(nt.getPath(), usedVars);
//usedVars.add(nameZ);
return new VarDecXE(false, Optional.of(nt), nameZ, right);
}
use of ast.Ast.VarDecXE in project L42 by ElvisResearchGroup.
the class DesugarW method innerWithXs.
private static Expression innerWithXs(With e) {
//right side of case b and part of right side of case d
Expression inner = e.getDefaultE().get();
List<String> xs = new ArrayList<String>(e.getXs());
for (VarDecXE d : e.getDecs()) {
xs.add(d.getX());
}
for (VarDecXE d : e.getIs()) {
xs.add(d.getX());
}
inner = new With(e.getP(), xs, Collections.emptyList(), Collections.emptyList(), e.getOns(), e.getDefaultE());
return inner;
}
use of ast.Ast.VarDecXE in project L42 by ElvisResearchGroup.
the class Desugar method blockEtoXE.
private RoundBlock blockEtoXE(RoundBlock s) {
if (s.getContents().isEmpty()) {
return s;
}
List<VarDec> decs = s.getContents().get(0).getDecs();
List<VarDec> newDecs = new ArrayList<VarDec>();
for (VarDec _dec : decs) {
if (!(_dec instanceof VarDecE)) {
newDecs.add(_dec);
continue;
}
VarDecE dec = (VarDecE) _dec;
String x = Functions.freshName("unused", usedVars);
//usedVars.add(x);
VarDecXE newXE = new VarDecXE(false, Optional.of(Type.immVoid), x, dec.getInner());
newDecs.add(newXE);
}
RoundBlock result = blockWithDec(s, newDecs);
//assert L42.checkWellFormedness(result);
return result;
}
use of ast.Ast.VarDecXE in project L42 by ElvisResearchGroup.
the class ToAst method parseRealVDec.
private VarDecXE parseRealVDec(VarDecContext vd) {
TContext tt = vd.t();
Optional<Type> t = (tt == null) ? Optional.<Type>empty() : Optional.of(parseType(tt));
Expression inner = vd.eTop().accept(this);
return new Ast.VarDecXE(vd.Var() != null, t, nameL(vd.x()), inner);
}
Aggregations