use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class Rename method redirectDefinition.
private static ClassB redirectDefinition(List<Ast.C> src, List<Ast.C> dest, ClassB lprime) {
assert !src.isEmpty();
assert !dest.isEmpty();
NestedClass nsCb = lprime.getNested(src);
Path toFrom = Path.outer(dest.size() - 1, src.subList(0, src.size() - 1));
ClassB cb = (ClassB) FromInClass.of((ClassB) nsCb.getInner(), toFrom);
List<Member> ms = new ArrayList<>();
ms.add(Functions.encapsulateIn(dest, cb, nsCb.getDoc()));
return ClassB.membersClass(ms, Position.noInfo, lprime.getPhase());
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class Redirect method redirectOkMember.
private static void redirectOkMember(List<PathSPath> ambiguities, List<SPathSPath> exceptions, Member mi, Member miGet, PathSPath current) {
if (mi instanceof NestedClass) {
assert miGet instanceof NestedClass;
assert ((NestedClass) mi).getName().equals(((NestedClass) miGet).getName());
Path src = current.getPath().pushC(((NestedClass) mi).getName());
Path dest = current.getPathsSet().iterator().next().pushC(((NestedClass) mi).getName());
plusEqual(ambiguities, src, Arrays.asList(dest));
return;
}
assert mi.getClass().equals(miGet.getClass());
assert mi instanceof MethodWithType : mi;
MethodWithType mwtSrc = (MethodWithType) mi;
MethodWithType mwtDest = (MethodWithType) miGet;
//this is what happens in p.method
mwtSrc = From.from(mwtSrc, current.getPath());
mwtDest = From.from(mwtDest, current.getPathsSet().iterator().next());
assert mwtSrc.getMs().equals(mwtDest.getMs());
boolean thisMdfOk = mwtSrc.getMt().getMdf().equals(mwtDest.getMt().getMdf());
boolean retOk = redirectOkT(ambiguities, mwtSrc.getMt().getReturnType(), mwtDest.getMt().getReturnType());
List<Integer> parWrong = new ArrayList<Integer>();
{
int i = -1;
for (Type tSrc : mwtSrc.getMt().getTs()) {
i += 1;
Type tDest = mwtDest.getMt().getTs().get(i);
if (!redirectOkT(ambiguities, tSrc, tDest)) {
parWrong.add(i);
}
;
}
}
boolean excOk = plusEqualAndExc(ambiguities, exceptions, current.getPath(), mwtSrc, mwtDest);
if (thisMdfOk && retOk && excOk && parWrong.isEmpty()) {
return;
}
throw Errors42.errorMethodClash(current.getPath().getCBar(), mwtSrc, mwtDest, excOk, parWrong, retOk, thisMdfOk, false);
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class RemoveCode method addDep.
private static ClassB addDep(ClassB accumulator, List<Ast.C> path, ClassB originalCb) {
if (path.isEmpty()) {
return mergeNestedHolderWithDep(accumulator, originalCb);
}
Ast.C firstName = path.get(0);
//either fistName does not exist in accumulator, and we call removeAllButPath
//or we have to continue recursivelly.
Optional<Member> optM = Functions.getIfInDom(accumulator.getMs(), firstName);
NestedClass originalNc = (NestedClass) Functions.getIfInDom(originalCb.getMs(), firstName).get();
ClassB newInner;
if (!optM.isPresent()) {
newInner = removeAllButPath(path.subList(1, path.size()), (ClassB) originalNc.getInner());
} else {
NestedClass accumulatorNc = (NestedClass) optM.get();
newInner = addDep((ClassB) accumulatorNc.getInner(), path.subList(1, path.size()), (ClassB) originalNc.getInner());
}
NestedClass nc = originalNc.withInner(newInner);
List<Member> ms = new ArrayList<>(accumulator.getMs());
Functions.replaceIfInDom(ms, nc);
return accumulator.withMs(ms);
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class Rename method userForMethod.
public static UserForMethodResult userForMethod(Program p, ClassB cb, List<Ast.C> path, MethodSelector src, boolean checkMethExists) {
if (checkMethExists) {
Member mem = Errors42.checkExistsPathMethod(cb, path, Optional.of(src));
assert mem instanceof MethodWithType;
}
Member mem = new ExpCore.ClassB.MethodImplemented(Doc.empty(), src, new ExpCore._void(), Position.noInfo);
CollectedLocatorsMap maps = CollectedLocatorsMap.from(Path.outer(0, path), mem, src);
HashSet<PathMx> result1 = new HashSet<>();
HashSet<MethodSelector> result2 = new HashSet<>();
MethodPathCloneVisitor ren = new RenameUsage(cb, maps, p) {
public Ast.Type liftT(Ast.Type t) {
return t;
}
@Override
protected MethodSelector liftMs(MethodSelector ms) {
return ms;
}
@Override
protected MethodSelector liftMsInMetDec(MethodSelector ms) {
return ms;
}
public ExpCore visit(MCall s) {
List<Ast.C> localPath = this.getLocator().getClassNamesPath();
if (!localPath.equals(path)) {
return super.visit(s);
}
if (s.getInner().equals(Path.outer(0)) || s.getInner().equals(new ExpCore.X(Position.noInfo, "this"))) {
result2.add(s.getS());
return s.withInner(s.getInner().accept(this)).withEs(Map.of(e -> e.accept(this), s.getEs()));
}
return super.visit(s);
}
@Override
public MethodSelector visitMS(MethodSelector original, Path src) {
MethodSelector toCollect = this.mSToReplaceOrNull(original, src);
if (toCollect == null) {
return original;
}
Member m = this.getLocator().getLastMember();
assert !(m instanceof NestedClass) : "";
MethodSelector msUser = m.match(nc -> {
throw Assertions.codeNotReachable();
}, mi -> mi.getS(), mt -> mt.getMs());
Path pathUser = Path.outer(0, this.getLocator().getClassNamesPath());
result1.add(new PathMx(pathUser, msUser));
return original;
}
};
ren.visit(cb);
return new UserForMethodResult() {
{
asClient = new ArrayList<>(result1);
asThis = new ArrayList<>(result2);
}
};
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class _Aux method onClassNavigateToPathAndDo.
static ClassB onClassNavigateToPathAndDo(ClassB cb, List<Ast.C> cs, Function<ClassB, ClassB> op) {
if (cs.isEmpty()) {
return op.apply(cb);
}
List<Member> newMs = new ArrayList<>(cb.getMs());
Ast.C nName = cs.get(0);
int index = getIndex(newMs, nName);
checkIndex(index);
NestedClass nc = (NestedClass) newMs.get(index);
if (cs.size() > 1) {
nc = nc.withInner(onClassNavigateToPathAndDo(wrapCast(nc.getInner()), cs.subList(1, cs.size()), op));
newMs.set(index, nc);
return cb.withMs(newMs);
}
assert cs.size() == 1;
ClassB newCb = op.apply(wrapCast(nc.getInner()));
newMs.set(index, nc.withInner(newCb));
return cb.withMs(newMs);
}
Aggregations