use of ast.Ast.VarDecXE in project L42 by ElvisResearchGroup.
the class CheckVarUsedAreInScope method visit.
public Expression visit(With s) {
Set<String> aux = this.xs;
this.xs = new HashSet<String>(aux);
List<VarDecXE> is = Map.of(this::liftVarDecXE, s.getIs());
for (VarDecXE vd : is) {
this.xs.add(vd.getX());
}
List<VarDecXE> es = Map.of(this::liftVarDecXE, s.getDecs());
for (VarDecXE vd : es) {
this.xs.add(vd.getX());
}
try {
return new With(s.getP(), s.getXs(), is, es, Map.of(this::liftO, s.getOns()), Map.of(this::lift, s.getDefaultE()));
} finally {
this.xs = aux;
}
}
use of ast.Ast.VarDecXE in project L42 by ElvisResearchGroup.
the class Desugar method getBlock.
static RoundBlock getBlock(Position p, String x, Expression xe, Expression inner) {
List<Expression.BlockContent> bc = new ArrayList<>();
List<VarDec> decs = new ArrayList<VarDec>();
decs.add(new VarDecXE(false, Optional.empty(), x, xe));
bc.add(new Expression.BlockContent(decs, Collections.emptyList()));
return new RoundBlock(p, Doc.empty(), inner, bc);
}
use of ast.Ast.VarDecXE 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.VarDecXE 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.VarDecXE 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);
}
Aggregations