use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class UsedPaths method usedPathsL.
//- usedPathsL(L, Cs1..Csn)=usedInnerL(L(Cs1),Cs1) U ... U usedInnerL(L(Csn),Csn)
private static Paths usedPathsL(Program pForError, ClassB l, List<List<Ast.C>> css, Phase phase0) {
Paths result = Paths.empty();
for (List<Ast.C> csi : css) {
assert !csi.isEmpty();
ClassB li;
try {
li = l.getClassB(csi);
} catch (ErrorMessage.PathMetaOrNonExistant pne) {
//.withWherePathWasWritten(p);
throw pne.withListOfNodeNames(csi).withCb(l);
}
ClassB liTop = li;
if (csi.size() != 0) {
liTop = l.getClassB(Collections.singletonList(csi.get(0)));
}
assert IsCompiled.of(liTop);
//checked after for newPaths: when the offending value is produced, so we have more context for error message
// throw new ErrorMessage.PathMetaOrNonExistant(true, Collections.singletonList(csi.get(0)), l, null,null);
Paths newPaths = usedInnerL(li, csi, phase0);
try {
newPaths.checkAllDefined(pForError);
} catch (ErrorMessage.PathMetaOrNonExistant pne) {
Position p = FindPathUsage._locate(pForError, li, Path.outer(csi.size() + 1, /*TODO we need to fix this crap for real*/
pne.getListOfNodeNames()));
throw pne.withWherePathWasWritten(p);
}
result = result.union(newPaths);
}
return result;
}
use of ast.ExpCore.ClassB 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.ExpCore.ClassB 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.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class Resources method getRes.
public static Object getRes(String key, int... ks) {
Object o = usedRes.get(key);
if (o == null) {
throw new Error("Invalid resource " + key + " Valid resources are: " + usedRes.keySet());
}
if (!(o instanceof ClassB)) {
return o;
}
int[] newK = pKeys();
int common = 0;
while (common < newK.length && common < ks.length) {
if (newK[common] == ks[common]) {
common++;
} else {
break;
}
}
int shift = newK.length - common;
int padding = ks.length - common;
if (shift == 0 && padding == 0) {
return o;
}
List<Ast.C> csPadding = new ArrayList<>();
for (int i = 0; i < padding; i++) {
csPadding.add(C.of("Padding" + i));
}
ClassB cb = (ClassB) FromInClass.of((ClassB) o, Path.outer(shift, csPadding));
//Configuration.typeSystem.computeStage(p, cb);
return cb;
}
use of ast.ExpCore.ClassB 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);
}
});
}
Aggregations