Search in sources :

Example 41 with Path

use of ast.Ast.Path 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 42 with Path

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

the class RenameMembers method liftP.

@Override
protected Path liftP(Path s) {
    if (s.isPrimitive()) {
        return s;
    }
    //System.out.print("     "+s);
    assert s.isCore();
    List<Ast.C> cs = s.getCBar();
    //no need to rename outers
    if (cs.isEmpty()) {
        return s;
    }
    Locator current = this.getLocator().copy();
    current.toFormerNodeLocator();
    boolean canCut = current.cutUpTo(s.outerNumber());
    if (!canCut) {
        return s;
    }
    int whereImSize = current.size();
    current.addCs(s.getCBar());
    for (Locator nl : maps.nesteds) {
        if (whereImSize > nl.size()) {
            continue;
        }
        //situation: rename: s1 c1->path   current path locator is:  whereIm c cs
        //check whereImSize<=s1Size and  whereIm c cs =s1 _ 
        boolean compatible = current.prefixOf(nl);
        if (!compatible) {
            continue;
        }
        //the class name in nl.that
        int extraCs = (current.size() - nl.size());
        Path pi = getDestPath(this.getLocator().getClassNamesPath().size(), nl, s, extraCs);
        //TODO:can be made more efficient without creating the listPaths
        return pi;
    }
    return s;
}
Also used : PathPath(ast.Util.PathPath) Path(ast.Ast.Path) Locator(auxiliaryGrammar.Locator)

Example 43 with Path

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

the class RenameMembers method getDestPath.

private Path getDestPath(int myDept, Locator nl, Path s, int extraCs) {
    assert extraCs >= 0 : extraCs;
    Path result = null;
    if (nl.getAnnotation() instanceof Path) {
        result = (Path) nl.getAnnotation();
    }
    List<Ast.C> cs = s.getCBar();
    if (result == null) {
        assert nl.getAnnotation() != null;
        assert nl.getAnnotation() instanceof String : nl.getAnnotation();
        List<Ast.C> newCs = new ArrayList<>(cs);
        newCs.set(cs.size() - 1 - extraCs, Ast.C.of((String) nl.getAnnotation()));
        return Path.outer(s.outerNumber(), newCs);
    }
    List<Ast.C> path = cs.subList(cs.size() - extraCs, cs.size());
    for (Ast.C si : path) {
        result = result.pushC(si);
    }
    return result.setNewOuter(result.outerNumber() + myDept);
}
Also used : PathPath(ast.Util.PathPath) Path(ast.Ast.Path) Ast(ast.Ast) ArrayList(java.util.ArrayList)

Example 44 with Path

use of ast.Ast.Path 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 45 with Path

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

the class RemoveCode method collectDep.

private static List<List<Ast.C>> collectDep(ClassB depSource, List<Ast.C> origin) {
    List<Path> dep = new UsedPaths().of(depSource);
    List<List<Ast.C>> result = new ArrayList<>();
    for (Path pi : new HashSet<>(dep)) {
        if (pi.isPrimitive()) {
            continue;
        }
        Path piF = From.fromP(pi, Path.outer(0, origin));
        if (piF.outerNumber() == 0) {
            result.add(piF.getCBar());
        }
    }
    return result;
}
Also used : Path(ast.Ast.Path) Ast(ast.Ast) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) UsedPaths(auxiliaryGrammar.UsedPaths) HashSet(java.util.HashSet)

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