use of is.L42.connected.withSafeOperators.ExtractInfo.ClassKind 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 is.L42.connected.withSafeOperators.ExtractInfo.ClassKind in project L42 by ElvisResearchGroup.
the class Redirect method redirectOkImpl.
private static void redirectOkImpl(ClassKind kindSrc, ClassKind kindDest, List<PathSPath> ambiguities, PathSPath current, ClassB currentIntCb, ClassB currentExtCb) {
// List<Path>unexpectedInterfaces=new ArrayList<>(unexpectedI);
// Collections.sort(unexpectedInterfaces,(pa,pb)->pa.toString().compareTo(pb.toString()));
List<Path> extPs = currentExtCb.getSuperPaths();
Path destP = current.getPathsSet().iterator().next();
extPs = Map.of(pi -> From.fromP(pi, destP), extPs);
List<Path> unexpectedInterfaces = new ArrayList<>();
for (Path pi : currentIntCb.getSuperPaths()) {
Path pif = From.fromP(pi, current.getPath());
if (extPs.isEmpty()) {
unexpectedInterfaces.add(pif);
} else if (pif.isPrimitive() || pif.outerNumber() > 0) {
if (!extPs.contains(pif)) {
unexpectedInterfaces.add(pif);
}
} else {
plusEqual(ambiguities, pif, extPs);
}
}
if (unexpectedInterfaces.isEmpty()) {
return;
}
throw Errors42.errorSourceUnfit(current.getPath().getCBar(), current.getPathsSet().iterator().next(), kindSrc, kindDest, Collections.emptyList(), true, unexpectedInterfaces);
}
Aggregations