Search in sources :

Example 1 with SPathSPath

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

the class Redirect method redirectOkAux.

private static void redirectOkAux(Program p, PathSPath current, ClassB cbTop, List<PathSPath> ambiguities, List<SPathSPath> exceptions) {
    assert current.getPathsSet().size() == 1;
    List<Ast.C> cs = current.getPath().getCBar();
    if (cs.isEmpty()) {
        throw Errors42.errorInvalidOnTopLevel();
    }
    Errors42.checkExistsPathMethod(cbTop, cs, Optional.empty());
    //Boolean[] csPrivate=new Boolean[]{false};
    ClassB currentIntCb = cbTop.getClassB(cs);
    //path exists by construction.
    Path path = current.getPathsSet().iterator().next();
    ClassB currentExtCb;
    if (path.isCore()) {
        assert path.outerNumber() > 0 : path;
        currentExtCb = p.extractClassB(path);
    } else {
        assert path.isPrimitive();
        currentExtCb = ClassB.membersClass(Collections.emptyList(), Position.noInfo, cbTop.getPhase()).withInterface(path.equals(Path.Any()));
    }
    assert cs.stream().allMatch(c -> !c.isUnique());
    boolean isPrivateState = ExtractInfo.hasPrivateState(currentIntCb);
    boolean isNoImplementation = ExtractInfo.isNoImplementation(currentIntCb);
    boolean headerOk = currentIntCb.isInterface() == currentExtCb.isInterface();
    ClassKind kindSrc = ExtractInfo.classKind(cbTop, cs, currentIntCb, null, isPrivateState, isNoImplementation);
    if (!headerOk && !currentIntCb.isInterface()) {
        if (kindSrc == ClassKind.FreeTemplate) {
            headerOk = true;
        }
    }
    ClassKind kindDest = ExtractInfo.classKind(null, null, currentExtCb, null, null, null);
    if (isPrivateState || !isNoImplementation) {
        //unexpectedMembers stay empty if there is implementation
        assert kindSrc != ClassKind.FreeTemplate || kindSrc != ClassKind.Template || kindSrc != ClassKind.Interface : kindSrc;
        throw Errors42.errorSourceUnfit(current.getPath().getCBar(), path, kindSrc, kindDest, Collections.emptyList(), headerOk, Collections.emptyList());
    }
    redirectOkImpl(kindSrc, kindDest, ambiguities, current, currentIntCb, currentExtCb);
    List<Member> unexpectedMembers = new ArrayList<>();
    for (Member mi : currentIntCb.getMs()) {
        Optional<Member> miPrime = Functions.getIfInDom(currentExtCb.getMs(), mi);
        if (miPrime.isPresent() && miPrime.get().getClass().equals(mi.getClass())) {
            Member miGet = miPrime.get();
            redirectOkMember(ambiguities, exceptions, mi, miGet, current);
        } else {
            unexpectedMembers.add(mi);
        }
    }
    if (unexpectedMembers.isEmpty() && headerOk) {
        return;
    }
    if (kindSrc == null) {
        kindSrc = ExtractInfo.classKind(cbTop, cs, currentIntCb, null, isPrivateState, isNoImplementation);
    }
    if (kindDest == null) {
        kindDest = ExtractInfo.classKind(null, null, currentExtCb, null, null, null);
    }
    throw Errors42.errorSourceUnfit(cs, path, kindSrc, kindDest, unexpectedMembers, headerOk, Collections.emptyList());
}
Also used : PathPath(ast.Util.PathPath) PathSPath(ast.Util.PathSPath) SPathSPath(ast.Util.SPathSPath) CloneWithPath(coreVisitors.CloneWithPath) Path(ast.Ast.Path) C(ast.Ast.C) ClassKind(is.L42.connected.withSafeOperators.ExtractInfo.ClassKind) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 2 with SPathSPath

use of ast.Util.SPathSPath 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 SPathSPath

use of ast.Util.SPathSPath 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 4 with SPathSPath

use of ast.Util.SPathSPath 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 5 with SPathSPath

use of ast.Util.SPathSPath 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)5 PathSPath (ast.Util.PathSPath)5 SPathSPath (ast.Util.SPathSPath)5 Path (ast.Ast.Path)4 CloneWithPath (coreVisitors.CloneWithPath)4 ArrayList (java.util.ArrayList)3 C (ast.Ast.C)1 Type (ast.Ast.Type)1 ClassB (ast.ExpCore.ClassB)1 Member (ast.ExpCore.ClassB.Member)1 MethodWithType (ast.ExpCore.ClassB.MethodWithType)1 NestedClass (ast.ExpCore.ClassB.NestedClass)1 ClassKind (is.L42.connected.withSafeOperators.ExtractInfo.ClassKind)1 HashSet (java.util.HashSet)1