Search in sources :

Example 11 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class UsedPaths method usedPathsE.

static PathsPaths usedPathsE(Program p, ExpCore e) {
    //- usedPathsE(p,eC)= <reorganize(Ps); usedPathsFix(p,paths, empty)>
    //assert that the result includes paths in usedPathsFix(p,paths, empty)  
    //Ps,Ps'={P|P inside eC}//arbitrary split of the set; heuristic will apply in the implementation.
    //collect all paths
    List<Ast.Path> psBoth = CollectPaths0.of(e);
    List<Ast.Path> ps1;
    try {
        ps1 = collectNotAnyPaths(p, e);
    } catch (ErrorMessage.PathMetaOrNonExistant pne) {
        throw Assertions.codeNotReachable();
    }
    //L1..Ln={L| L inside eC}//in path not prime// not repeat check stage
    List<ClassB> l1n = CollectClassBs0.of(e);
    //paths'=usedPathsFix(p,reorganize(Ps'), empty,Coherent)
    Paths paths1 = Paths.reorganize(ps1);
    paths1 = usedPathsFix(p, paths1, Collections.emptyList(), Phase.Coherent);
    assert paths1.checkAllDefined(p);
    //paths0=reorganize(Ps,Ps') U paths' U (deepImplements(L1)U..U deepImplements(Ln)).pop()
    //paths=usedPathsFix(p,paths0, empty,Typed)
    Paths paths0 = Paths.reorganize(psBoth).union(paths1);
    Paths acc = Paths.empty();
    for (ClassB li : l1n) {
        acc = acc.union(deepImplements(li));
    }
    paths0 = paths0.union(acc.pop());
    Paths paths = usedPathsFix(p, paths0, Collections.emptyList(), Phase.Typed);
    assert paths.checkAllDefined(p);
    PathsPaths result = new PathsPaths(paths.setMinus(paths1), paths1);
    System.out.println("UsedPaths:\npaths:" + result.left + "\npaths':" + result.right + "\n-----------------\n");
    return result;
}
Also used : Path(ast.Ast.Path) PathMetaOrNonExistant(ast.ErrorMessage.PathMetaOrNonExistant) ErrorMessage(ast.ErrorMessage) ClassB(ast.ExpCore.ClassB)

Example 12 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class UsedPaths method usedInnerM.

private static Paths usedInnerM(Member m, Phase phase0) {
    if (m instanceof NestedClass) {
        NestedClass nc = (NestedClass) m;
        return usedInnerL((ClassB) nc.getInner(), Collections.emptyList(), phase0).pop();
    }
    List<Path> result1;
    List<ClassB> l1n = Collections.emptyList();
    if (m instanceof MethodWithType) {
        MethodWithType mwt = (MethodWithType) m;
        result1 = CollectPaths0.of(mwt);
        if (phase0 == Phase.Typed && mwt.get_inner().isPresent()) {
            l1n = CollectClassBs0.of(m.getInner());
        }
    } else {
        assert m instanceof MethodImplemented;
        result1 = CollectPaths0.of(m.getInner());
    }
    Paths result2 = Paths.reorganize(result1);
    Paths acc = Paths.empty();
    for (ClassB li : l1n) {
        acc = acc.union(usedInnerL(li, Collections.emptyList(), phase0));
    }
    return result2.union(acc.pop());
}
Also used : Path(ast.Ast.Path) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB)

Example 13 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class RefreshUniqueNames method refreshTopLevel.

public static ClassB refreshTopLevel(ClassB e) {
    HashMap<Long, Long> map = new HashMap<>();
    return (ClassB) e.accept(new coreVisitors.CloneVisitor() {

        protected MethodSelector liftMs(MethodSelector ms) {
            return ms.withUniqueNum(newN(map, ms.getUniqueNum()));
        }

        public ClassB.NestedClass visit(ClassB.NestedClass nc) {
            long newN = newN(map, nc.getName().getUniqueNum());
            return super.visit(nc.withName(nc.getName().withUniqueNum(newN)));
        //I need to collect the DECLARED C,ms and those are the only that I need to refresh.
        //refresh all can work only at top level
        }

        @Override
        protected Path liftP(Path s) {
            if (s.isPrimitive()) {
                return s;
            }
            List<C> cs = s.getCBar();
            List<C> newCs = new ArrayList<>();
            for (C c : cs) {
                newCs.add(c.withUniqueNum(newN(map, c.getUniqueNum())));
            }
            return Path.outer(s.outerNumber(), newCs);
        }
    });
}
Also used : Path(ast.Ast.Path) MethodSelector(ast.Ast.MethodSelector) C(ast.Ast.C) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NestedClass(ast.Expression.ClassB.NestedClass) ClassB(ast.ExpCore.ClassB)

Example 14 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class RefreshUniqueNames method refresh.

@SuppressWarnings("unchecked")
public static <T extends ExpCore> T refresh(T e) {
    HashMap<Long, Long> map = new HashMap<>();
    //load up maps
    e.accept(new coreVisitors.PropagatorVisitor() {

        public void visit(ClassB.MethodWithType mwt) {
            MethodSelector ms = mwt.getMs();
            newN(map, ms.getUniqueNum());
            super.visit(mwt);
            return;
        }

        public void visit(ClassB.NestedClass nc) {
            newN(map, nc.getName().getUniqueNum());
            super.visit(nc);
        }
    });
    return (T) e.accept(new coreVisitors.CloneVisitor() {

        protected MethodSelector liftMs(MethodSelector ms) {
            return ms.withUniqueNum(mappedN(map, ms.getUniqueNum()));
        }

        public ClassB.NestedClass visit(ClassB.NestedClass nc) {
            C name = nc.getName().withUniqueNum(mappedN(map, nc.getName().getUniqueNum()));
            return super.visit(nc.withName(name));
        }

        @Override
        protected Path liftP(Path s) {
            if (s.isPrimitive()) {
                return s;
            }
            List<C> cs = s.getCBar();
            List<C> newCs = new ArrayList<>();
            for (C c : cs) {
                newCs.add(c.withUniqueNum(mappedN(map, c.getUniqueNum())));
            }
            return Path.outer(s.outerNumber(), newCs);
        }
    });
}
Also used : Path(ast.Ast.Path) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) C(ast.Ast.C) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NestedClass(ast.Expression.ClassB.NestedClass) NestedClass(ast.Expression.ClassB.NestedClass) ClassB(ast.ExpCore.ClassB)

Example 15 with Path

use of ast.Ast.Path in project L42 by ElvisResearchGroup.

the class Methods method collect.

static List<Ast.Path> collect(Program p, List<Ast.Path> p0ps, List<Ast.Path> visited) {
    if (p0ps.isEmpty()) {
        return p0ps;
    }
    Ast.Path p0 = p0ps.get(0);
    List<Ast.Path> ps = p0ps.subList(1, p0ps.size());
    if (visited.contains(p0)) {
        throw new ast.ErrorMessage.CircularImplements(push(visited, p0));
    }
    if (p0.isPrimitive()) {
        return collect(p, ps, visited);
    }
    ClassB l = p.extractClassB(p0);
    List<Path> superPaths = l.getSuperPaths();
    List<Ast.Path> recP0 = collect(p.navigate(p0), superPaths, push(visited, p0));
    recP0 = Map.of(pi -> From.fromP(pi, p0), recP0);
    List<Ast.Path> recPs = collect(p, ps, visited);
    return mergeUnique(p0, recP0, recPs);
}
Also used : Path(ast.Ast.Path) From(coreVisitors.From) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Set(java.util.Set) HashMap(java.util.HashMap) Member(ast.ExpCore.ClassB.Member) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Collectors(java.util.stream.Collectors) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ClassB(ast.ExpCore.ClassB) Entry(java.util.Map.Entry) Collections(java.util.Collections) Ast(ast.Ast) Path(ast.Ast.Path) ClassB(ast.ExpCore.ClassB)

Aggregations

Path (ast.Ast.Path)56 ClassB (ast.ExpCore.ClassB)28 ArrayList (java.util.ArrayList)23 Ast (ast.Ast)14 PathPath (ast.Util.PathPath)13 Type (ast.Ast.Type)12 MethodWithType (ast.ExpCore.ClassB.MethodWithType)12 Doc (ast.Ast.Doc)11 Member (ast.ExpCore.ClassB.Member)11 List (java.util.List)11 ExpCore (ast.ExpCore)10 NestedClass (ast.ExpCore.ClassB.NestedClass)8 PathSPath (ast.Util.PathSPath)8 CloneWithPath (coreVisitors.CloneWithPath)8 Collections (java.util.Collections)8 HashSet (java.util.HashSet)8 Program (programReduction.Program)8 Map (tools.Map)8 MethodSelector (ast.Ast.MethodSelector)7 SPathSPath (ast.Util.SPathSPath)7