use of ast.Ast.VarDec in project L42 by ElvisResearchGroup.
the class DesugarVars method findD2.
private int findD2(X x, int pos, List<VarDec> decs) {
for (VarDec _dec : decs.subList(pos + 1, decs.size())) {
pos += 1;
Expression[] inner = { null };
_dec.match(xe -> inner[0] = xe.getInner(), e -> inner[0] = e.getInner(), ce -> null);
if (inner[0] == null) {
continue;
}
boolean isAssigned = Exists.of(inner[0], e -> {
if (!(e instanceof BinOp)) {
return false;
}
BinOp bo = (BinOp) e;
if (bo.getOp().kind != Ast.OpKind.EqOp) {
return false;
}
return bo.getLeft().equals(x);
});
if (isAssigned) {
return pos;
}
}
return -1;
}
use of ast.Ast.VarDec 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.VarDec in project L42 by ElvisResearchGroup.
the class CheckTerminatingBlock method visit.
public Void visit(CurlyBlock s) {
checkBlockContent(s.getContents());
Expression.BlockContent bc = s.getContents().get(s.getContents().size() - 1);
VarDec dec = bc.getDecs().get(bc.getDecs().size() - 1);
if (!(dec instanceof Ast.VarDecE)) {
return fail(s);
}
Ast.VarDecE decE = (Ast.VarDecE) dec;
return decE.getInner().accept(this);
}
use of ast.Ast.VarDec in project L42 by ElvisResearchGroup.
the class CheckVarUsedAreInScope method liftBC.
protected Expression.BlockContent liftBC(Expression.BlockContent c) {
Set<String> aux = this.xs;
Set<String> aux2 = new HashSet<String>(aux);
for (VarDec vd : c.getDecs()) {
vd.match(xe -> {
aux2.add(xe.getX());
return null;
}, e -> {
return null;
}, ce -> {
return null;
});
}
this.xs = aux2;
List<VarDec> liftVarDecs = liftVarDecs(c.getDecs());
this.xs = aux;
List<Catch> liftK;
try {
liftK = Map.of(this::liftK, c.get_catch());
} catch (ErrorMessage.VariableUsedNotInScope nis) {
Expression.X x = nis.getE();
assert !aux.contains(x.getInner());
if (aux2.contains(x.getInner())) {
throw nis.withReason(nis.getReason() + "\nThe variable is in lexical scope, but is used in a catch of the declaring block. It may not be initialized at this stage");
}
throw nis;
}
//add again for later contents
this.xs = aux2;
return new Expression.BlockContent(liftVarDecs, liftK);
}
use of ast.Ast.VarDec in project L42 by ElvisResearchGroup.
the class DesugarW method with_C_A.
private Expression with_C_A(Position pos, List<String> xs, With.On on0, Expression continuation) {
List<String> ys = new ArrayList<String>();
for (String x : xs) {
ys.add(Functions.freshName(x, usedVars));
}
//(
List<VarDec> decs = new ArrayList<>();
//TODO:?? now is very strange and requires the mdf to propagate it to the locally introduced var?
//casts: every cast is a block content e+catch
{
int i = -1;
for (Type ti : on0.getTs()) {
i += 1;
String xi = xs.get(i);
String yi = ys.get(i);
decs.add(castT(pos, ti, yi, xi));
}
}
//catch exception Void recursive call
Catch k = Desugar.getK(pos, SignalKind.Exception, "", Type.immVoid, continuation);
//main expression with 'T' renaming
Expression e0 = on0.getInner();
{
int i = -1;
for (Type ti : on0.getTs()) {
i += 1;
String xi = xs.get(i);
String yi = ys.get(i);
e0 = renameT(e0, new Expression.X(pos, xi), ti, new Expression.X(pos, yi));
}
}
BlockContent content = new BlockContent(decs, Collections.singletonList(k));
List<BlockContent> contents = new ArrayList<BlockContent>();
contents.add(content);
contents.add(Desugar.getBlockContent(e0));
//void)
return new RoundBlock(pos, Doc.empty(), Expression._void.instance, contents);
}
Aggregations