Search in sources :

Example 16 with NestedClass

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());
}
Also used : PathPath(ast.Util.PathPath) Path(ast.Ast.Path) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member)

Example 17 with NestedClass

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);
}
Also used : PathPath(ast.Util.PathPath) PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) CloneWithPath(coreVisitors.CloneWithPath) Path(ast.Ast.Path) Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 18 with NestedClass

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);
}
Also used : Ast(ast.Ast) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) EncodingHelper.ensureExtractClassB(auxiliaryGrammar.EncodingHelper.ensureExtractClassB)

Example 19 with NestedClass

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);
        }
    };
}
Also used : PathMx(ast.Util.PathMx) Stage(ast.Ast.Stage) PathPath(ast.Util.PathPath) Program(programReduction.Program) Ast(ast.Ast) Map(tools.Map) Configuration(facade.Configuration) CloneVisitorWithProgram(coreVisitors.CloneVisitorWithProgram) Assertions(tools.Assertions) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CloneVisitor(coreVisitors.CloneVisitor) PathMxMx(ast.Util.PathMxMx) NestedClass(ast.ExpCore.ClassB.NestedClass) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Functions(auxiliaryGrammar.Functions) List(java.util.List) Position(ast.Ast.Position) PathMx(ast.Util.PathMx) Optional(java.util.Optional) FromInClass(coreVisitors.FromInClass) C(ast.Ast.C) Collections(java.util.Collections) L42(facade.L42) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) PathPath(ast.Util.PathPath) Path(ast.Ast.Path) ExpCore(ast.ExpCore) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) C(ast.Ast.C) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) HashSet(java.util.HashSet)

Example 20 with NestedClass

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);
}
Also used : Ast(ast.Ast) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Aggregations

NestedClass (ast.ExpCore.ClassB.NestedClass)24 Member (ast.ExpCore.ClassB.Member)18 ArrayList (java.util.ArrayList)16 ClassB (ast.ExpCore.ClassB)12 Ast (ast.Ast)10 MethodWithType (ast.ExpCore.ClassB.MethodWithType)7 Path (ast.Ast.Path)5 ExpCore (ast.ExpCore)4 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)3 PathPath (ast.Util.PathPath)3 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)3 List (java.util.List)3 C (ast.Ast.C)2 Position (ast.Ast.Position)2 Type (ast.Ast.Type)2 Phase (ast.ExpCore.ClassB.Phase)2 CloneVisitor (coreVisitors.CloneVisitor)2 HashSet (java.util.HashSet)2 Doc (ast.Ast.Doc)1 MethodSelector (ast.Ast.MethodSelector)1