Search in sources :

Example 51 with Path

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

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

the class Redirect method plusEqualAndExc.

private static boolean plusEqualAndExc(List<PathSPath> ambiguities, List<SPathSPath> exceptions, Path src, MethodWithType mwtSrc, MethodWithType mwtDest) {
    int countExternal = 0;
    int countExternalSatisfied = 0;
    List<Path> srcExc = Map.of(t -> t.getPath(), mwtSrc.getMt().getExceptions());
    List<Path> destExc = Map.of(t -> t.getPath(), mwtDest.getMt().getExceptions());
    exceptions.add(new SPathSPath(src, mwtSrc, mwtDest));
    for (Path pi : srcExc) {
        if (pi.isPrimitive() || pi.outerNumber() > 0) {
            countExternal += 1;
            if (destExc.contains(pi)) {
                countExternalSatisfied += 1;
            }
            continue;
        }
        plusEqual(ambiguities, pi, destExc);
    }
    int countInternal = srcExc.size() - countExternal;
    return countInternal + countExternalSatisfied >= destExc.size();
}
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)

Example 53 with Path

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

Example 54 with Path

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

the class ToAst method parseType.

private Type parseType(TContext t) {
    if (t.concreteT() != null) {
        ConcreteTContext tt = t.concreteT();
        Doc d = parseDoc(tt.docsOpt());
        Ast.Type nt = new Ast.Type(Mdf.fromString((tt.Mdf() == null) ? "" : nameK(tt.Mdf())), Ast.Path.sugarParse(nameU(tt.Path())), d);
        if (tt.Ph() == null) {
            return nt;
        }
        return Functions.toPh(nt);
    }
    if (t.historicalT() != null) {
        HistoricalTContext tt = t.historicalT();
        Doc d = parseDoc(tt.docsOpt());
        Path p = ast.Ast.Path.sugarParse(nameU(tt.Path()));
        List<MethodSelectorX> mss = new ArrayList<MethodSelectorX>();
        for (HistoricalSeqContext ms : tt.historicalSeq()) {
            mss.add(parseMethSelectorX(ms));
        }
        //return new ast.Ast.HistoricType(p,mss,d);
        throw Assertions.codeNotReachable();
    }
    throw Assertions.codeNotReachable();
}
Also used : Path(ast.Ast.Path) Type(ast.Ast.Type) Ast(ast.Ast) MethodSelectorX(ast.Ast.MethodSelectorX) Doc(ast.Ast.Doc) Type(ast.Ast.Type)

Example 55 with Path

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

the class Errors42 method errorIncoherentRedirectMapping.

/* static void checkCoherentMapping(List<PathPath> setVisited) {
    // setVisited is a set of individual redirected classes,
    // created by walking the sub-tree under each cascade redirect.
    // getPath1() is the path in the library before redirecting.
    // getPath2() is the proposed path in the redirected library.
    // We will allow many paths to be redirected into a single new path,
    // but not vice-versa.
    for(PathPath p1:setVisited){
      for(PathPath p2:setVisited){
        if(p1.equals(p2)){continue;}
        if(p1.getPath1().equals(p2.getPath1())){
          throw errorIncoherentRedirectMapping(setVisited, p1.getPath1(),p1.getPath2(),p2.getPath2());
          }
      }
    }
    return;
  }*/
static Error errorIncoherentRedirectMapping(List<PathPath> verified, List<PathSPath> ambiguities, Path incoSrc, List<Path> _incoDest) {
    Doc src = Doc.empty();
    Doc dest = Doc.empty();
    //Doc ambig=Doc.empty();
    for (PathPath v : verified) {
        src = src.sum(formatPathIn(v.getPath1().getCBar()));
        dest = dest.sum(formatPathOut(v.getPath2()));
    }
    for (PathSPath a : ambiguities) {
        //if(a.getPaths().size()!=1){
        //  ambig=ambig.sum(formatPathIn(a.getPath().getCBar()));
        //  ambig=ambig.sum(Doc.factory("@"+a.getPaths().size()));
        //  }
        Doc srci = formatPathIn(a.getPath().getCBar());
        for (Path pij : a.getPathsSet()) {
            src = src.sum(srci);
            dest = dest.sum(formatPathOut(pij));
        }
    }
    Doc incoDest = Doc.empty();
    for (Path pi : _incoDest) {
        incoDest = incoDest.sum(formatPathOut(pi));
    }
    return Resources.Error.multiPartStringError("IncoherentRedirectMapping", "Src", src.formatNewLinesAsList(), "Dest", dest.formatNewLinesAsList(), //"Ambiguities",ambig.formatNewLinesAsList(),
    "IncoherentSrc", incoSrc == null ? Doc.empty() : formatPathIn(incoSrc.getCBar()), "IncoherentDest", incoDest.formatNewLinesAsList());
}
Also used : PathPath(ast.Util.PathPath) PathSPath(ast.Util.PathSPath) Path(ast.Ast.Path) PathSPath(ast.Util.PathSPath) PathPath(ast.Util.PathPath) Doc(ast.Ast.Doc)

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