use of ast.Ast.VarDecE in project L42 by ElvisResearchGroup.
the class Desugar method visit1Step.
public MCall visit1Step(Literal s) {
//(b=r.builder() b.a() b.b() b.c() .... b)
List<VarDec> vd = new ArrayList<>();
Expression k = getMCall(s.getP(), s.getReceiver(), "#builder", getPs());
String x = Functions.freshName("b", usedVars);
X b = new X(s.getP(), x);
vd.add(new VarDecXE(false, Optional.empty(), x, k));
for (char ch : s.getInner().toCharArray()) {
String name = Character.toString(ch);
if (!Character.isAlphabetic(ch) && !Character.isDigit(ch)) {
name = desugarSymbol(name);
}
vd.add(new VarDecE(getMCall(s.getP(), b, "#" + name, getPs())));
}
Expression inner = getBlock(s.getP(), vd, b);
Parameters ps = new Parameters(Optional.empty(), Collections.singletonList("builder"), Collections.singletonList(inner));
return getMCall(s.getP(), s.getReceiver(), "#from", ps);
}
use of ast.Ast.VarDecE in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public Expression visit(CurlyBlock s) {
assert s.getContents().size() == 1;
assert s.getContents().get(0).get_catch().isEmpty();
assert s.getContents().get(0).getDecs().size() == 1;
assert s.getContents().get(0).getDecs().get(0) instanceof VarDecE;
Expression inner = ((VarDecE) s.getContents().get(0).getDecs().get(0)).getInner();
String y = Functions.freshName("result", this.usedVars);
Expression.Catch k = getK(s.getP(), SignalKind.Return, y, this.t, new X(s.getP(), y));
Expression termination = Desugar.errorMsg("CurlyBlock-Should be unreachable code");
RoundBlock outer = getBlock(s.getP(), inner, Collections.singletonList(k), termination);
return visit(outer);
}
use of ast.Ast.VarDecE 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.Ast.VarDecE in project L42 by ElvisResearchGroup.
the class DesugarW method oldWith_noUseKw.
private void oldWith_noUseKw(SquareWithCall s, X xX, List<VarDec> decs) {
List<With.On> ons = s.getWith().getOns();
List<With.On> onsPrime = new ArrayList<>();
for (With.On on : ons) {
onsPrime.add(on.withInner(withSquareAdd(s.getP(), xX, on.getInner())));
}
Optional<Expression> def = s.getWith().getDefaultE();
Optional<Expression> defPrime = Map.of(e -> withSquareAdd(s.getP(), xX, e), def);
With w = s.getWith().withOns(onsPrime).withDefaultE(defPrime);
decs.add(new VarDecE(w));
}
use of ast.Ast.VarDecE 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;
}
Aggregations