Search in sources :

Example 1 with PathMx

use of ast.Util.PathMx 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 2 with PathMx

use of ast.Util.PathMx in project L42 by ElvisResearchGroup.

the class Abstract method checkPrivacyCoupuled.

static void checkPrivacyCoupuled(ClassB cbFull, ClassB cbClear, List<Ast.C> path) {
    //start from a already cleared out of private states
    //check if all private nested classes are USED using IsUsed on cbClear
    //this also verify that no private nested classes are used as
    //type in public methods of public classes.
    //collect all PublicPath.privateMethod
    //use main->introspection.FindUsage
    List<Path> prPath = ExtractInfo.collectPrivatePathsAndSubpaths(cbFull, path);
    List<PathMx> prMeth = ExtractInfo.collectPrivateMethodsOfPublicPaths(cbFull, path);
    List<Path> coupuledPaths = new ArrayList<>();
    for (Path pi : prPath) {
        Set<Path> used = ExtractInfo.IsUsed.of(cbClear, pi);
        if (used.isEmpty()) {
            continue;
        }
        coupuledPaths.add(pi);
    }
    List<PathMx> ordered = new ArrayList<>();
    try {
        //FindUsage.of(Program.empty(),prMeth, cbClear);
        Set<PathMx> usedPrMeth = findUsage(prMeth, cbClear);
        if (coupuledPaths.isEmpty() && usedPrMeth.isEmpty()) {
            return;
        }
        ordered.addAll(usedPrMeth);
    } catch (PathMetaOrNonExistant pne) {
        assert !coupuledPaths.isEmpty();
    }
    Collections.sort(ordered, (px1, px2) -> px1.toString().compareTo(px2.toString()));
    throw Errors42.errorPrivacyCoupuled(coupuledPaths, ordered);
}
Also used : Path(ast.Ast.Path) PathMx(ast.Util.PathMx) ArrayList(java.util.ArrayList) PathMetaOrNonExistant(ast.ErrorMessage.PathMetaOrNonExistant)

Example 3 with PathMx

use of ast.Util.PathMx in project L42 by ElvisResearchGroup.

the class Abstract method findUsage.

private static Set<PathMx> findUsage(List<PathMx> prMeth, ClassB cbClear) {
    Set<PathMx> result = new HashSet<>();
    for (PathMx pmx : prMeth) {
        assert pmx.getPath().outerNumber() == 0;
        UserForMethodResult res = Rename.userForMethod(Resources.getP(), /*wasEmpty*/
        cbClear, pmx.getPath().getCBar(), pmx.getMs(), false);
        result.addAll(res.asClient);
        res.asThis.stream().map(e -> new PathMx(Path.outer(0), e)).forEach(result::add);
    }
    return result;
}
Also used : PathMx(ast.Util.PathMx) Resources(platformSpecific.javaTranslation.Resources) Program(programReduction.Program) Ast(ast.Ast) PathMetaOrNonExistant(ast.ErrorMessage.PathMetaOrNonExistant) ErrorMessage(ast.ErrorMessage) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) IsUsed(is.L42.connected.withSafeOperators.ExtractInfo.IsUsed) ClassB(ast.ExpCore.ClassB) PathMwt(ast.Util.PathMwt) UserForMethodResult(is.L42.connected.withSafeOperators.Rename.UserForMethodResult) NestedClass(ast.ExpCore.ClassB.NestedClass) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Set(java.util.Set) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Functions(auxiliaryGrammar.Functions) List(java.util.List) PathMx(ast.Util.PathMx) Optional(java.util.Optional) Collections(java.util.Collections) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) UserForMethodResult(is.L42.connected.withSafeOperators.Rename.UserForMethodResult) HashSet(java.util.HashSet)

Example 4 with PathMx

use of ast.Util.PathMx in project L42 by ElvisResearchGroup.

the class ExtractInfo method auxCollectPrivateMethodsOfPublicPaths.

private static void auxCollectPrivateMethodsOfPublicPaths(ClassB cb, List<PathMx> accumulator, List<Ast.C> prefix) {
    for (Member m : cb.getMs()) {
        m.match(nc -> {
            if (nc.getName().isUnique()) {
                return null;
            }
            List<Ast.C> newPrefix = new ArrayList<>(prefix);
            newPrefix.add(nc.getName());
            auxCollectPrivateMethodsOfPublicPaths((ClassB) nc.getInner(), accumulator, newPrefix);
            return null;
        }, mi -> null, mt -> {
            if (!mt.getMs().isUnique()) {
                return null;
            }
            accumulator.add(new PathMx(Path.outer(0, prefix), mt.getMs()));
            return null;
        });
    }
}
Also used : PathMx(ast.Util.PathMx) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member)

Aggregations

PathMx (ast.Util.PathMx)4 ArrayList (java.util.ArrayList)4 Path (ast.Ast.Path)3 Member (ast.ExpCore.ClassB.Member)3 Ast (ast.Ast)2 Doc (ast.Ast.Doc)2 MethodSelector (ast.Ast.MethodSelector)2 PathMetaOrNonExistant (ast.ErrorMessage.PathMetaOrNonExistant)2 ExpCore (ast.ExpCore)2 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)2 MethodWithType (ast.ExpCore.ClassB.MethodWithType)2 NestedClass (ast.ExpCore.ClassB.NestedClass)2 Functions (auxiliaryGrammar.Functions)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Optional (java.util.Optional)2 Program (programReduction.Program)2 C (ast.Ast.C)1 Position (ast.Ast.Position)1