use of ast.Ast.VarDec in project L42 by ElvisResearchGroup.
the class InjectionOnSugar method visit.
@Override
public Expression visit(Block s) {
Doc docs = s.getDoc();
Expression inner = lift(s.getInner());
List<VarDec> decs = new ArrayList<VarDec>();
for (int i = 0; i < s.getDecs().size(); i++) {
Optional<Type> t = s.getDecs().get(i).getT();
String x = s.getDecs().get(i).getX();
Expression e = lift(s.getDecs().get(i).getInner());
decs.add(new VarDecXE(s.getDecs().get(i).isVar(), t, x, e));
}
List<Expression.Catch> _catch = injectionCatch(s.getOns());
List<Expression.BlockContent> contents = new ArrayList<>();
if (!decs.isEmpty() || !_catch.isEmpty()) {
contents.add(new Expression.BlockContent(decs, _catch));
}
Expression.Position pos = s.getP();
Expression.RoundBlock result = new Expression.RoundBlock(pos, docs, inner, contents);
//assert WellFormedness.blockCheck(result);, no it can actually get wrong?
return result;
}
use of ast.Ast.VarDec 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);
}
use of ast.Ast.VarDec 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.VarDec in project L42 by ElvisResearchGroup.
the class Desugar method blockInferVar.
private RoundBlock blockInferVar(RoundBlock s) {
if (s.getContents().isEmpty()) {
return s;
}
HashMap<String, Type> localVarEnv = new HashMap<String, Type>(this.varEnv);
List<VarDec> newDecs = new ArrayList<VarDec>();
for (VarDec _dec : s.getContents().get(0).getDecs()) {
if (!(_dec instanceof VarDecXE)) {
newDecs.add(_dec);
continue;
}
VarDecXE dec = (VarDecXE) _dec;
if (dec.getT().isPresent()) {
Type ti = dec.getT().get();
localVarEnv.put(dec.getX(), ti);
newDecs.add(dec);
continue;
}
localVarEnv.put(dec.getX(), null);
newDecs.add(dec.withT(Optional.ofNullable(t)));
}
return blockWithDec(s, newDecs);
}
use of ast.Ast.VarDec 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);
}
Aggregations