Search in sources :

Example 1 with PathPath

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

the class Redirect method applyMapPath.

public static ClassB applyMapPath(Program p, ClassB cb, List<PathPath> mapPath) {
    cb = Rename.renameUsage(mapPath, cb);
    CollectedLocatorsMap coll = new CollectedLocatorsMap();
    for (PathPath pp : mapPath) {
        cb = Redirect.remove(pp.getPath1(), cb);
    }
    return cb;
}
Also used : PathPath(ast.Util.PathPath)

Example 2 with PathPath

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

the class Redirect method redirectOk.

public static List<PathPath> redirectOk(Program p, ClassB cbTop, Path internal, Path external) {
    List<PathPath> verified = new ArrayList<>();
    verifiedForErrorMsg = verified;
    List<PathSPath> ambiguities = new ArrayList<>();
    List<SPathSPath> exceptions = new ArrayList<>();
    ambiguities.add(new PathSPath(internal, new HashSet<>(Arrays.asList(external))));
    for (PathSPath current = choseUnabigus(ambiguities); current != null; current = choseUnabigus(ambiguities)) {
        //closure final limitations
        PathSPath _current = current;
        assert ambiguitiesOk(ambiguities);
        assert verified.stream().allMatch(pp -> !pp.getPath1().equals(_current.getPath())) : verified + " " + _current.getPath();
        redirectOkAux(p, current, cbTop, ambiguities, exceptions);
        assert current.getPathsSet().size() == 1;
        assert verified.stream().allMatch(pp -> !pp.getPath1().equals(_current.getPath())) : verified + " " + _current.getPath();
        verified.add(new PathPath(current.getPath(), current.getPathsSet().iterator().next()));
        accumulateVerified(ambiguities, verified);
    }
    assert choseUnabigus(ambiguities) == null;
    if (!ambiguities.isEmpty()) {
        throw Errors42.errorIncoherentRedirectMapping(verified, ambiguities, null, Collections.emptyList());
    }
    checkExceptionOk(exceptions, verified);
    return verified;
}
Also used : PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) PathPath(ast.Util.PathPath) SPathSPath(ast.Util.SPathSPath) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 3 with PathPath

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

the class Rename method renameUsage.

//TODO: replace with same mechanism of private normalization when is completed
static ClassB renameUsage(List<PathPath> mapPath, ClassB cb) {
    return (ClassB) cb.accept(new coreVisitors.CloneWithPath() {

        @Override
        protected Path liftP(Path s) {
            if (s.isPrimitive()) {
                return s;
            }
            assert s.isCore();
            List<Ast.C> path = this.getLocator().getClassNamesPath();
            if (s.outerNumber() > path.size()) {
                return s;
            }
            //in usedPath similar thing.
            List<Ast.C> unexploredPath = path.subList(0, path.size() - s.outerNumber());
            //we are in a class literal in a method and we look inside
            if (unexploredPath.contains(null)) {
                return s;
            }
            if (s.outerNumber() > path.size()) {
                return s;
            }
            List<Ast.C> topView = ClassOperations.toTop(path, s);
            for (PathPath pp : mapPath) {
                List<Ast.C> src = pp.getPath1().getCBar();
                if (topView.size() < src.size()) {
                    continue;
                }
                if (topView.equals(src)) {
                    if (pp.getPath2().isPrimitive()) {
                        return pp.getPath2();
                    }
                    if (pp.getPath2().outerNumber() == 0) {
                        return ClassOperations.normalizePath(path, path.size(), pp.getPath2().getCBar());
                    }
                    return pp.getPath2().setNewOuter(pp.getPath2().outerNumber() + path.size());
                }
                List<Ast.C> trimmedTop = topView.subList(0, src.size());
                if (trimmedTop.equals(src)) {
                    List<Ast.C> elongatedDest = new ArrayList<>(pp.getPath2().getCBar());
                    elongatedDest.addAll(topView.subList(src.size(), topView.size()));
                    if (pp.getPath2().outerNumber() == 0) {
                        return ClassOperations.normalizePath(path, path.size(), elongatedDest);
                    } else {
                        return Path.outer(pp.getPath2().outerNumber() + path.size(), elongatedDest);
                    }
                }
            }
            return s;
        }
    });
}
Also used : PathPath(ast.Util.PathPath) Path(ast.Ast.Path) C(ast.Ast.C) PathPath(ast.Util.PathPath) ArrayList(java.util.ArrayList)

Example 4 with PathPath

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

the class Redirect method accumulateVerified.

/*private static void lessEqual(List<PathSPath> ambiguities, List<PathPath> verified) {
    Iterator<PathSPath> it = ambiguities.iterator();
    while(it.hasNext()){
      Path pi=it.next().getPath();
      for(PathPath pp:verified){if(pp.getPath1().equals(pi)){it.remove();}}
    }
  }*/
private static void accumulateVerified(List<PathSPath> ambiguities, List<PathPath> verified) {
    assert ambiguitiesOk(ambiguities);
    for (PathPath pp : verified) {
        PathSPath psp = selectPSP(ambiguities, pp.getPath1());
        if (psp == null) {
            continue;
        }
        //ambiguities.add(new PathSPath(pp.getPath1(),Arrays.asList(pp.getPath2())));
        if (psp.getPathsSet().contains(pp.getPath2())) {
            ambiguities.remove(psp);
        } else {
            List<Path> ps = new ArrayList<>(psp.getPathsSet());
            ps.add(pp.getPath2());
            throw Errors42.errorIncoherentRedirectMapping(verified, ambiguities, psp.getPath(), ps);
        }
    }
}
Also used : PathPath(ast.Util.PathPath) PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) CloneWithPath(coreVisitors.CloneWithPath) Path(ast.Ast.Path) PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) PathPath(ast.Util.PathPath) ArrayList(java.util.ArrayList)

Example 5 with PathPath

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

the class Redirect method checkExceptionOk.

private static void checkExceptionOk(List<SPathSPath> exceptions, List<PathPath> verified) {
    for (SPathSPath exc : exceptions) {
        List<Path> src = Map.of(t -> traspose(verified, t.getPath()), exc.getMwt1().getMt().getExceptions());
        //was: src=Map.of(pi->traspose(verified,pi),src); and now is merged on top
        List<Path> other = Map.of(t -> t.getPath(), exc.getMwt2().getMt().getExceptions());
        if (!src.containsAll(other)) {
            throw Errors42.errorMethodClash(exc.getSrc().getCBar(), exc.getMwt1(), exc.getMwt2(), true, Collections.emptyList(), false, false, false);
        }
    }
}
Also used : PathPath(ast.Util.PathPath) PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) CloneWithPath(coreVisitors.CloneWithPath) Path(ast.Ast.Path) SPathSPath(ast.Util.SPathSPath)

Aggregations

PathPath (ast.Util.PathPath)7 Path (ast.Ast.Path)4 PathSPath (ast.Util.PathSPath)4 SPathSPath (ast.Util.SPathSPath)3 ArrayList (java.util.ArrayList)3 CloneWithPath (coreVisitors.CloneWithPath)2 C (ast.Ast.C)1 Doc (ast.Ast.Doc)1 HashSet (java.util.HashSet)1