use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class Redirect method redirectOkAux.
private static void redirectOkAux(Program p, PathSPath current, ClassB cbTop, List<PathSPath> ambiguities, List<SPathSPath> exceptions) {
assert current.getPathsSet().size() == 1;
List<Ast.C> cs = current.getPath().getCBar();
if (cs.isEmpty()) {
throw Errors42.errorInvalidOnTopLevel();
}
Errors42.checkExistsPathMethod(cbTop, cs, Optional.empty());
//Boolean[] csPrivate=new Boolean[]{false};
ClassB currentIntCb = cbTop.getClassB(cs);
//path exists by construction.
Path path = current.getPathsSet().iterator().next();
ClassB currentExtCb;
if (path.isCore()) {
assert path.outerNumber() > 0 : path;
currentExtCb = p.extractClassB(path);
} else {
assert path.isPrimitive();
currentExtCb = ClassB.membersClass(Collections.emptyList(), Position.noInfo, cbTop.getPhase()).withInterface(path.equals(Path.Any()));
}
assert cs.stream().allMatch(c -> !c.isUnique());
boolean isPrivateState = ExtractInfo.hasPrivateState(currentIntCb);
boolean isNoImplementation = ExtractInfo.isNoImplementation(currentIntCb);
boolean headerOk = currentIntCb.isInterface() == currentExtCb.isInterface();
ClassKind kindSrc = ExtractInfo.classKind(cbTop, cs, currentIntCb, null, isPrivateState, isNoImplementation);
if (!headerOk && !currentIntCb.isInterface()) {
if (kindSrc == ClassKind.FreeTemplate) {
headerOk = true;
}
}
ClassKind kindDest = ExtractInfo.classKind(null, null, currentExtCb, null, null, null);
if (isPrivateState || !isNoImplementation) {
//unexpectedMembers stay empty if there is implementation
assert kindSrc != ClassKind.FreeTemplate || kindSrc != ClassKind.Template || kindSrc != ClassKind.Interface : kindSrc;
throw Errors42.errorSourceUnfit(current.getPath().getCBar(), path, kindSrc, kindDest, Collections.emptyList(), headerOk, Collections.emptyList());
}
redirectOkImpl(kindSrc, kindDest, ambiguities, current, currentIntCb, currentExtCb);
List<Member> unexpectedMembers = new ArrayList<>();
for (Member mi : currentIntCb.getMs()) {
Optional<Member> miPrime = Functions.getIfInDom(currentExtCb.getMs(), mi);
if (miPrime.isPresent() && miPrime.get().getClass().equals(mi.getClass())) {
Member miGet = miPrime.get();
redirectOkMember(ambiguities, exceptions, mi, miGet, current);
} else {
unexpectedMembers.add(mi);
}
}
if (unexpectedMembers.isEmpty() && headerOk) {
return;
}
if (kindSrc == null) {
kindSrc = ExtractInfo.classKind(cbTop, cs, currentIntCb, null, isPrivateState, isNoImplementation);
}
if (kindDest == null) {
kindDest = ExtractInfo.classKind(null, null, currentExtCb, null, null, null);
}
throw Errors42.errorSourceUnfit(cs, path, kindSrc, kindDest, unexpectedMembers, headerOk, Collections.emptyList());
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class RemoveCode method collectPaths.
private static void collectPaths(Set<List<Ast.C>> accumulator, List<Ast.C> path, ClassB cb) {
accumulator.add(path);
for (Member m : cb.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
List<Ast.C> pathi = new ArrayList<>(path);
pathi.add(nc.getName());
collectPaths(accumulator, pathi, (ClassB) nc.getInner());
}
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class RemoveCode method collectDepNested.
private static ClassB collectDepNested(Set<List<Ast.C>> justAdded, ClassB originalCb, ClassB accumulator, ClassB depSource, List<Ast.C> origin) {
List<List<Ast.C>> dep = collectDep(depSource, origin);
for (List<Ast.C> pi : dep) {
if (justAdded.contains(pi)) {
continue;
}
justAdded.add(pi);
accumulator = addDep(accumulator, pi, originalCb);
}
assert dep != null : "to break";
for (Member m : depSource.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
ClassB cbi = (ClassB) nc.getInner();
List<Ast.C> newOrigin = new ArrayList<>(origin);
newOrigin.add(nc.getName());
accumulator = collectDepNested(justAdded, originalCb, accumulator, cbi, newOrigin);
}
return accumulator;
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class RemoveCode method removeAllButPath.
private static ClassB removeAllButPath(List<Ast.C> path, ClassB originalCb) {
if (path.isEmpty()) {
List<Member> ms = new ArrayList<>();
for (Member m : originalCb.getMs()) {
if (m instanceof NestedClass) {
continue;
}
ms.add(m);
}
return originalCb.withMs(ms);
}
Ast.C firstName = path.get(0);
List<Member> ms = new ArrayList<>();
for (Member m : originalCb.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
if (!nc.getName().equals(firstName)) {
continue;
}
ClassB newInner = removeAllButPath(path.subList(1, path.size()), (ClassB) nc.getInner());
ms.add(nc.withInner(newInner));
}
return ClassB.membersClass(ms, Position.noInfo, originalCb.getPhase());
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class Push method pushOne.
//never wrong
//assumes s well formed class name
static ClassB pushOne(ClassB in, Ast.C s) {
Path p = Path.outer(1);
ClassB cb = (ClassB) FromInClass.of(in, p);
List<Member> ms = Collections.singletonList(new ClassB.NestedClass(Doc.empty(), s, cb, null));
return ClassB.membersClass(ms, cb.getP(), cb.getPhase());
}
Aggregations