use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class Functions method neededX.
private static HashSet<String> neededX(Block e, int n) {
HashSet<String> neededX = new HashSet<String>();
for (int i = n; i < e.getDecs().size(); i++) {
ExpCore ei = e.getDecs().get(i).getInner();
neededX.addAll(FreeVariables.of(ei));
}
for (int i = n; i < e.getDecs().size(); i++) {
neededX.remove(e.getDecs().get(i).getX());
}
neededX.addAll(FreeVariables.of(e.getInner()));
return neededX;
}
use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class Functions method iterateAddNeeded.
private static boolean iterateAddNeeded(Block e, int n, HashSet<String> needX, HashSet<Integer> needKeep) {
int size = needKeep.size();
for (int i : needKeep) {
ExpCore ei = e.getDecs().get(i).getInner();
needX.addAll(FreeVariables.of(ei));
}
for (int i = 0; i < n; i++) {
if (!needX.contains(e.getDecs().get(i).getX())) {
continue;
}
needKeep.add(i);
}
assert size <= needKeep.size();
return size != needKeep.size();
}
use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class Functions method replace.
public static List<Block.Dec> replace(List<Block.Dec> dvs, MCall mc) {
String x = ((ExpCore.X) mc.getInner()).getInner();
List<Block.Dec> result = new ArrayList<>();
for (Block.Dec dv : dvs) {
if (!dv.getX().equals(x)) {
result.add(dv);
continue;
}
MCall inner = (MCall) dv.getInner();
String fieldName = mc.getS().nameToS();
int mIndex = inner.getS().getNames().indexOf(fieldName);
assert mIndex != -1 : fieldName + " / " + ToFormattedText.of(inner);
List<ExpCore> es2 = new ArrayList<>(inner.getEs());
ExpCore parameterAtom = mc.getEs().get(0);
es2.set(mIndex, parameterAtom);
result.add(dv.withInner(inner.withEs(es2)));
}
return result;
}
use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class ExtractCtxCompiled method visit.
public Ctx<ClassB> visit(Using s) {
for (ExpCore ei : s.getEs()) {
if (IsCompiled.of(ei)) {
continue;
}
return lift(ei.accept(this), ctx -> {
List<ExpCore> es = new ArrayList<ExpCore>(s.getEs());
es.set(es.indexOf(ei), ctx);
return s.withEs(es);
});
}
assert !IsCompiled.of(s.getInner());
return lift(s.getInner().accept(this), s::withInner);
}
use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class Move method visit.
public Ctx<List<Block.Dec>> visit(MCall s) {
if (IsCtx.of(s.getInner())) {
return lift(s.getInner().accept(this), ctx -> s.withInner(ctx));
}
for (ExpCore ei : s.getEs()) {
if (!IsCtx.of(ei)) {
continue;
}
return lift(ei.accept(this), ctx -> {
List<ExpCore> es = new ArrayList<>(s.getEs());
es.set(es.indexOf(ei), ctx);
return s.withEs(es);
});
}
return null;
}
Aggregations