use of ast.ExpCore.WalkBy in project L42 by ElvisResearchGroup.
the class ExtractCtxVal method visit.
public Ctx<Redex> visit(Block s) {
Ctx<Redex> res = checkRedex(s);
if (res != null) {
return res;
}
for (int i = 0; i < s.getDecs().size(); i++) {
//final restrictions
int ii = i;
Dec di = s.getDecs().get(i);
boolean isDv = new IsValue(p).validDv(di);
Redex isGarbage = null;
if (isDv && di.getInner() instanceof Block) {
Block diB = (Block) di.getInner();
isGarbage = IsValue.nestedGarbage(diB);
}
if (isGarbage != null) {
List<Block.Dec> ds = new ArrayList<Block.Dec>(s.getDecs());
ds.set(ii, di.withInner(new WalkBy()));
return new Ctx<Redex>(s.withDecs(ds), isGarbage);
}
if (isDv) {
continue;
}
//otherwise, i is the first non dv
return lift(di.getInner().accept(this), ctx -> {
List<Block.Dec> es = new ArrayList<Block.Dec>(s.getDecs());
es.set(ii, es.get(ii).withInner(ctx));
return s.withDecs(es);
});
}
if (!s.getOns().isEmpty()) {
return null;
}
return lift(s.getInner().accept(this), ctx -> s.withInner(ctx));
}
use of ast.ExpCore.WalkBy in project L42 by ElvisResearchGroup.
the class HB method visit.
@Override
public ExpCore visit(Block s) {
ExpCore result = null;
for (Block.Dec di : s.getDecs()) {
result = acc(result, di.getInner().accept(this));
}
result = acc(result, s.getInner().accept(this));
if (result == null && onlyAroundHole) {
return null;
}
assert !onlyAroundHole || result instanceof WalkBy : onlyAroundHole + " " + result;
for (Block.Dec dec : s.getDecs()) {
if (xs.contains(dec.getX())) {
throw new ErrorMessage.VariableDeclaredMultipleTimes(dec.getX(), s.getP());
}
this.xs.add(dec.getX());
this.xsRes.add(dec.getX());
}
try {
if (!onlyAroundHole && !s.getOns().isEmpty()) {
for (On on : s.getOns()) {
if (xs.contains(on.getX())) {
throw new ErrorMessage.VariableDeclaredMultipleTimes(on.getX(), s.getP());
}
xs.add(on.getX());
xsRes.add(on.getX());
on.getInner().accept(this);
xs.remove(on.getX());
}
}
return result;
} finally {
for (Block.Dec dec : s.getDecs()) {
this.xs.remove(dec.getX());
}
}
}
use of ast.ExpCore.WalkBy in project L42 by ElvisResearchGroup.
the class ExtractCtxUpToX method visit.
public Ctx<Block> visit(Block s) {
int xPos = s.domDecs().indexOf(x);
if (xPos != -1 && IsCtx.of(s)) {
return new Ctx<Block>(new WalkBy(), s);
}
List<Block.Dec> newDecs = new ArrayList<Block.Dec>();
Ctx<Block> res = null;
for (Block.Dec dec : s.getDecs()) {
if (!IsCtx.of(dec.getInner())) {
newDecs.add(dec);
continue;
}
res = dec.getInner().accept(this);
newDecs.add(dec.withInner(res.ctx));
}
if (res != null) {
res.ctx = s.withDecs(newDecs);
return res;
}
assert IsCtx.of(s.getInner());
assert s.getOns().isEmpty();
res = s.getInner().accept(this);
res.ctx = s.withInner(res.ctx);
return res;
}