Search in sources :

Example 6 with Member

use of ast.ExpCore.ClassB.Member 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 7 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class RemoveCode method collectPaths.

private static void collectPaths(Set<List<Ast.C>> accumulator, List<Ast.C> path, ClassB cb) {
    accumulator.add(path);
    for (Member m : cb.getMs()) {
        if (!(m instanceof NestedClass)) {
            continue;
        }
        NestedClass nc = (NestedClass) m;
        List<Ast.C> pathi = new ArrayList<>(path);
        pathi.add(nc.getName());
        collectPaths(accumulator, pathi, (ClassB) nc.getInner());
    }
}
Also used : ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member)

Example 8 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class RemoveCode method collectDepNested.

private static ClassB collectDepNested(Set<List<Ast.C>> justAdded, ClassB originalCb, ClassB accumulator, ClassB depSource, List<Ast.C> origin) {
    List<List<Ast.C>> dep = collectDep(depSource, origin);
    for (List<Ast.C> pi : dep) {
        if (justAdded.contains(pi)) {
            continue;
        }
        justAdded.add(pi);
        accumulator = addDep(accumulator, pi, originalCb);
    }
    assert dep != null : "to break";
    for (Member m : depSource.getMs()) {
        if (!(m instanceof NestedClass)) {
            continue;
        }
        NestedClass nc = (NestedClass) m;
        ClassB cbi = (ClassB) nc.getInner();
        List<Ast.C> newOrigin = new ArrayList<>(origin);
        newOrigin.add(nc.getName());
        accumulator = collectDepNested(justAdded, originalCb, accumulator, cbi, newOrigin);
    }
    return accumulator;
}
Also used : Ast(ast.Ast) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) EncodingHelper.ensureExtractClassB(auxiliaryGrammar.EncodingHelper.ensureExtractClassB)

Example 9 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class RemoveCode method removeAllButPath.

private static ClassB removeAllButPath(List<Ast.C> path, ClassB originalCb) {
    if (path.isEmpty()) {
        List<Member> ms = new ArrayList<>();
        for (Member m : originalCb.getMs()) {
            if (m instanceof NestedClass) {
                continue;
            }
            ms.add(m);
        }
        return originalCb.withMs(ms);
    }
    Ast.C firstName = path.get(0);
    List<Member> ms = new ArrayList<>();
    for (Member m : originalCb.getMs()) {
        if (!(m instanceof NestedClass)) {
            continue;
        }
        NestedClass nc = (NestedClass) m;
        if (!nc.getName().equals(firstName)) {
            continue;
        }
        ClassB newInner = removeAllButPath(path.subList(1, path.size()), (ClassB) nc.getInner());
        ms.add(nc.withInner(newInner));
    }
    return ClassB.membersClass(ms, Position.noInfo, originalCb.getPhase());
}
Also used : Ast(ast.Ast) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) EncodingHelper.ensureExtractClassB(auxiliaryGrammar.EncodingHelper.ensureExtractClassB)

Example 10 with Member

use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.

the class Push method pushOne.

//never wrong
//assumes s well formed class name
static ClassB pushOne(ClassB in, Ast.C s) {
    Path p = Path.outer(1);
    ClassB cb = (ClassB) FromInClass.of(in, p);
    List<Member> ms = Collections.singletonList(new ClassB.NestedClass(Doc.empty(), s, cb, null));
    return ClassB.membersClass(ms, cb.getP(), cb.getPhase());
}
Also used : Path(ast.Ast.Path) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Aggregations

Member (ast.ExpCore.ClassB.Member)54 ArrayList (java.util.ArrayList)32 ClassB (ast.ExpCore.ClassB)21 MethodWithType (ast.ExpCore.ClassB.MethodWithType)21 NestedClass (ast.ExpCore.ClassB.NestedClass)20 Ast (ast.Ast)14 ExpCore (ast.ExpCore)11 Path (ast.Ast.Path)10 List (java.util.List)7 Doc (ast.Ast.Doc)5 MethodSelector (ast.Ast.MethodSelector)5 MethodType (ast.Ast.MethodType)5 Collections (java.util.Collections)5 C (ast.Ast.C)4 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Assertions (tools.Assertions)4 Position (ast.Ast.Position)3