use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class UsedPaths method usedPathsE.
static PathsPaths usedPathsE(Program p, ExpCore e) {
//- usedPathsE(p,eC)= <reorganize(Ps); usedPathsFix(p,paths, empty)>
//assert that the result includes paths in usedPathsFix(p,paths, empty)
//Ps,Ps'={P|P inside eC}//arbitrary split of the set; heuristic will apply in the implementation.
//collect all paths
List<Ast.Path> psBoth = CollectPaths0.of(e);
List<Ast.Path> ps1;
try {
ps1 = collectNotAnyPaths(p, e);
} catch (ErrorMessage.PathMetaOrNonExistant pne) {
throw Assertions.codeNotReachable();
}
//L1..Ln={L| L inside eC}//in path not prime// not repeat check stage
List<ClassB> l1n = CollectClassBs0.of(e);
//paths'=usedPathsFix(p,reorganize(Ps'), empty,Coherent)
Paths paths1 = Paths.reorganize(ps1);
paths1 = usedPathsFix(p, paths1, Collections.emptyList(), Phase.Coherent);
assert paths1.checkAllDefined(p);
//paths0=reorganize(Ps,Ps') U paths' U (deepImplements(L1)U..U deepImplements(Ln)).pop()
//paths=usedPathsFix(p,paths0, empty,Typed)
Paths paths0 = Paths.reorganize(psBoth).union(paths1);
Paths acc = Paths.empty();
for (ClassB li : l1n) {
acc = acc.union(deepImplements(li));
}
paths0 = paths0.union(acc.pop());
Paths paths = usedPathsFix(p, paths0, Collections.emptyList(), Phase.Typed);
assert paths.checkAllDefined(p);
PathsPaths result = new PathsPaths(paths.setMinus(paths1), paths1);
System.out.println("UsedPaths:\npaths:" + result.left + "\npaths':" + result.right + "\n-----------------\n");
return result;
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class UsedPaths method usedInnerM.
private static Paths usedInnerM(Member m, Phase phase0) {
if (m instanceof NestedClass) {
NestedClass nc = (NestedClass) m;
return usedInnerL((ClassB) nc.getInner(), Collections.emptyList(), phase0).pop();
}
List<Path> result1;
List<ClassB> l1n = Collections.emptyList();
if (m instanceof MethodWithType) {
MethodWithType mwt = (MethodWithType) m;
result1 = CollectPaths0.of(mwt);
if (phase0 == Phase.Typed && mwt.get_inner().isPresent()) {
l1n = CollectClassBs0.of(m.getInner());
}
} else {
assert m instanceof MethodImplemented;
result1 = CollectPaths0.of(m.getInner());
}
Paths result2 = Paths.reorganize(result1);
Paths acc = Paths.empty();
for (ClassB li : l1n) {
acc = acc.union(usedInnerL(li, Collections.emptyList(), phase0));
}
return result2.union(acc.pop());
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class RefreshUniqueNames method refreshTopLevel.
public static ClassB refreshTopLevel(ClassB e) {
HashMap<Long, Long> map = new HashMap<>();
return (ClassB) e.accept(new coreVisitors.CloneVisitor() {
protected MethodSelector liftMs(MethodSelector ms) {
return ms.withUniqueNum(newN(map, ms.getUniqueNum()));
}
public ClassB.NestedClass visit(ClassB.NestedClass nc) {
long newN = newN(map, nc.getName().getUniqueNum());
return super.visit(nc.withName(nc.getName().withUniqueNum(newN)));
//I need to collect the DECLARED C,ms and those are the only that I need to refresh.
//refresh all can work only at top level
}
@Override
protected Path liftP(Path s) {
if (s.isPrimitive()) {
return s;
}
List<C> cs = s.getCBar();
List<C> newCs = new ArrayList<>();
for (C c : cs) {
newCs.add(c.withUniqueNum(newN(map, c.getUniqueNum())));
}
return Path.outer(s.outerNumber(), newCs);
}
});
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class RefreshUniqueNames method refresh.
@SuppressWarnings("unchecked")
public static <T extends ExpCore> T refresh(T e) {
HashMap<Long, Long> map = new HashMap<>();
//load up maps
e.accept(new coreVisitors.PropagatorVisitor() {
public void visit(ClassB.MethodWithType mwt) {
MethodSelector ms = mwt.getMs();
newN(map, ms.getUniqueNum());
super.visit(mwt);
return;
}
public void visit(ClassB.NestedClass nc) {
newN(map, nc.getName().getUniqueNum());
super.visit(nc);
}
});
return (T) e.accept(new coreVisitors.CloneVisitor() {
protected MethodSelector liftMs(MethodSelector ms) {
return ms.withUniqueNum(mappedN(map, ms.getUniqueNum()));
}
public ClassB.NestedClass visit(ClassB.NestedClass nc) {
C name = nc.getName().withUniqueNum(mappedN(map, nc.getName().getUniqueNum()));
return super.visit(nc.withName(name));
}
@Override
protected Path liftP(Path s) {
if (s.isPrimitive()) {
return s;
}
List<C> cs = s.getCBar();
List<C> newCs = new ArrayList<>();
for (C c : cs) {
newCs.add(c.withUniqueNum(mappedN(map, c.getUniqueNum())));
}
return Path.outer(s.outerNumber(), newCs);
}
});
}
use of ast.Ast.Path in project L42 by ElvisResearchGroup.
the class Methods method collect.
static List<Ast.Path> collect(Program p, List<Ast.Path> p0ps, List<Ast.Path> visited) {
if (p0ps.isEmpty()) {
return p0ps;
}
Ast.Path p0 = p0ps.get(0);
List<Ast.Path> ps = p0ps.subList(1, p0ps.size());
if (visited.contains(p0)) {
throw new ast.ErrorMessage.CircularImplements(push(visited, p0));
}
if (p0.isPrimitive()) {
return collect(p, ps, visited);
}
ClassB l = p.extractClassB(p0);
List<Path> superPaths = l.getSuperPaths();
List<Ast.Path> recP0 = collect(p.navigate(p0), superPaths, push(visited, p0));
recP0 = Map.of(pi -> From.fromP(pi, p0), recP0);
List<Ast.Path> recPs = collect(p, ps, visited);
return mergeUnique(p0, recP0, recPs);
}
Aggregations