Search in sources :

Example 41 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class RenameAlsoDefinition method liftMembers.

public List<Member> liftMembers(List<Member> s) {
    List<Member> result1 = super.liftMembers(s);
    List<Member> result2 = new ArrayList<>();
    for (Member m : result1) {
        Optional<Member> optM = Functions.getIfInDom(result2, m);
        if (!optM.isPresent()) {
            result2.add(m);
            continue;
        }
        Member m2 = optM.get();
        result2.remove(m2);
        assert m.getClass() == m2.getClass();
        _Sum.doubleSimmetricalMatch(null, /*boh, null program, does it breaks?*/
        visitStart, visitStart, result2, this.getLocator().getClassNamesPath(), m, m2);
    //remove clashes here
    }
    return result2;
}
Also used : ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member)

Example 42 with Member

use of ast.ExpCore.ClassB.Member 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 43 with Member

use of ast.ExpCore.ClassB.Member 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 44 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class TranslateClass method getPhNestedNotIntantiable.

private static void getPhNestedNotIntantiable(String s, ClassB cb, StringBuilder res, boolean isInterface) {
    if (isInterface) {
        res.append("public static final class Ph implements ");
        res.append(s + ", platformSpecific.javaTranslation.Resources.PhI<" + s + ">{\n");
    } else {
        res.append("public static final class Ph extends ");
        res.append(s + " implements platformSpecific.javaTranslation.Resources.PhI<" + s + ">{\n");
    }
    res.append("  private final java.util.ArrayList<java.util.function.Consumer<" + s + ">> actions=new java.util.ArrayList<>();\n");
    res.append("  public void commit(" + s + " val){ for(java.util.function.Consumer<" + s + "> r:actions){r.accept(val);} }");
    res.append("  public void addAction(java.util.function.Consumer<" + s + "> r){actions.add(r);}");
    res.append(" public ast.ExpCore revert()");
    res.append("{throw new Error(\"PhInvocation\");}\n");
    for (Member m : cb.getMs()) {
        MethodWithType mt = (MethodWithType) m;
        getMethodHeader(mt, res);
        res.append("{throw new Error(\"PhInvocation\");}\n");
    }
    res.append("  public Ph(){ }\n  }\n");
}
Also used : MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 45 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class TranslateClass method getIType.

private static void getIType(String s, ClassB cb, StringBuilder res) {
    res.append("public static final " + s + " type=new " + s + "(){\n");
    getITReverter(s, res);
    for (Member m : cb.getMs()) {
        MethodWithType mt = (MethodWithType) m;
        getMethodHeader(mt, res);
        res.append("{throw new Error(\"" + "Calling an interface method" + ":" + mt.getMs() + "\");}\n");
    }
    res.append("};\n");
}
Also used : MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Aggregations

Member (ast.ExpCore.ClassB.Member)54 ArrayList (java.util.ArrayList)32 ClassB (ast.ExpCore.ClassB)21 MethodWithType (ast.ExpCore.ClassB.MethodWithType)21 NestedClass (ast.ExpCore.ClassB.NestedClass)20 Ast (ast.Ast)14 ExpCore (ast.ExpCore)11 Path (ast.Ast.Path)10 List (java.util.List)7 Doc (ast.Ast.Doc)5 MethodSelector (ast.Ast.MethodSelector)5 MethodType (ast.Ast.MethodType)5 Collections (java.util.Collections)5 C (ast.Ast.C)4 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Assertions (tools.Assertions)4 Position (ast.Ast.Position)3