Search in sources :

Example 26 with MethodWithType

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

the class TestCoherentClass method testCoherence.

@Test
public void testCoherence() {
    ClassB cb1 = (ClassB) (Parser.parse(null, e).accept(new InjectionOnCore()));
    Program p = Program.emptyLibraryProgram();
    MethodWithType mwt = (MethodWithType) cb1.getMs().get(0);
//boolean res=Functions.coherent(p, mdf, path, mwt);
//Assert.assertEquals(res,ok);
//TODO: disabled for now
}
Also used : Program(programReduction.Program) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore) Test(org.junit.Test)

Example 27 with MethodWithType

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

the class Methods method methods.

//  -methods(p,P0)=M1'..Mk'
//          p(P0)={interface? implements Ps Ms} 
public List<MethodWithType> methods(Ast.Path p0) {
    if (p0.isPrimitive()) {
        return Collections.emptyList();
    }
    Program p = this;
    ClassB cb0 = p.extractClassB(p0);
    List<Ast.Path> ps = cb0.getSuperPaths();
    //          P1..Pn=collect(p,Ps[from P0]), error unless forall i, p(Pi) is an interface
    List<Ast.Path> p1n = collect(p, Map.of(pi -> From.fromP(pi, p0), ps));
    List<ClassB> cb1n = Map.of(pi -> p.extractClassB(pi), p1n);
    {
        int i = -1;
        for (ClassB cbi : cb1n) {
            i++;
            if (!cbi.isInterface()) {
                throw new ast.ErrorMessage.NonInterfaceImplements(p0, p1n.get(i));
            }
        }
    }
    //          ms1..msk={ms|p(Pi)(ms) is defined}
    HashMap<Ast.MethodSelector, List<ClassB.Member>> ms1k = new LinkedHashMap<>();
    for (ClassB.Member mij : cb0.getMs()) {
        mij.match(nc -> null, mi -> add(true, ms1k, mi.getS(), From.from(mij, p0)), mt -> add(true, ms1k, mt.getMs(), From.from(mij, p0)));
    }
    for (Ast.Path pi : p1n) {
        //call the memoized methods
        for (ClassB.Member mij : p.methods(pi)) {
            mij.match(nc -> null, mi -> add(false, ms1k, mi.getS(), mij), mt -> add(false, ms1k, mt.getMs(), mij));
        }
    }
    //            such that p(Pj)(ms)=mh e? //no refine
    for (Entry<MethodSelector, List<Member>> ei : ms1k.entrySet()) {
        if (!exactly1NoRefine(ei.getValue())) {
            throw new ast.ErrorMessage.NotExaclyOneMethodOrigin(p0, ei.getKey(), ei.getValue());
        }
    }
    List<ClassB.MethodWithType> ms = new ArrayList<>();
    //            for the smallest j in 1..k such that methods(p,Pj)(msi) of form refine? mh
    for (Entry<MethodSelector, List<Member>> ei : ms1k.entrySet()) {
        List<Member> memsi = ei.getValue();
        if (memsi.get(0) != null && memsi.get(0) instanceof MethodWithType) {
            ms.add((MethodWithType) memsi.get(0));
            continue;
        }
        ClassB.MethodImplemented mem0 = (ClassB.MethodImplemented) memsi.get(0);
        for (Member mj : memsi) {
            // 0 will fail instanceof
            if (mj == null || !(mj instanceof MethodWithType)) {
                continue;
            }
            //    Mi'=Mi
            if (mem0 != null) {
                mj = mj.withInner(mem0.getE());
            }
            ms.add(addRefine((MethodWithType) mj));
            break;
        }
    }
    return ms;
}
Also used : From(coreVisitors.From) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Set(java.util.Set) HashMap(java.util.HashMap) Member(ast.ExpCore.ClassB.Member) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Collectors(java.util.stream.Collectors) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ClassB(ast.ExpCore.ClassB) Entry(java.util.Map.Entry) Collections(java.util.Collections) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) Path(ast.Ast.Path) Ast(ast.Ast) Path(ast.Ast.Path) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 28 with MethodWithType

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

the class UsedPaths method deepImplements.

private static Paths deepImplements(ClassB l) {
    Paths res = Paths.reorganize(l.getSuperPaths());
    Paths acc = Paths.empty();
    for (Member mi : l.getMs()) {
        if (mi instanceof MethodWithType && !((MethodWithType) mi).get_inner().isPresent()) {
            continue;
        }
        ExpCore e = mi.getInner();
        for (ClassB cbij : CollectClassBs0.of(e)) {
            acc = acc.union(deepImplements(cbij));
        }
    }
    return res.union(acc.pop());
}
Also used : ExpCore(ast.ExpCore) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 29 with MethodWithType

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

the class SumMethods method checkConflict.

private static void checkConflict(List<Ast.C> path, MethodSelector mRes, ClassB pathCb, MethodWithType mwtU) {
    /*for(PathMwt e:pathCb.getStage().getInherited()){
      if(e.getMwt().getMs().equals(mRes)){//method declared in an interface and not implemented
        MethodWithType mtConflict=e.getMwt();
        mtConflict=From.from(mtConflict, From.fromP(e.getOriginal(),Path.outer(0,path)));
        Errors42.checkMethodClash(path, mwtU,mtConflict,false);
        }
    }*/
    //unneded for normalized classb
    Optional<Member> optConflict = Functions.getIfInDom(pathCb.getMs(), mRes);
    if (optConflict.isPresent()) {
        if (optConflict.get() instanceof MethodImplemented) {
            throw Errors42.errorMethodClash(path, mwtU, optConflict.get(), true, Collections.emptyList(), true, true, false);
        }
        MethodWithType mwtC = (MethodWithType) optConflict.get();
        Errors42.checkMethodClash(path, mwtU, mwtC, false);
    }
}
Also used : MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 30 with MethodWithType

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

the class _Sum method sumMethod.

static MethodWithType sumMethod(MethodWithType ma, MethodWithType mb) {
    Set<Path> pa = new HashSet<Path>(Map.of(t -> t.getPath(), ma.getMt().getExceptions()));
    Set<Path> pb = new HashSet<Path>(Map.of(t -> t.getPath(), mb.getMt().getExceptions()));
    Set<Path> pc = new HashSet<>(pa);
    pc.retainAll(pb);
    Doc doc = ma.getDoc().sum(mb.getDoc());
    MethodType mt = ma.getMt();
    List<Ast.Type> opc = pc.stream().map(pi -> (Ast.Type) pi.toImmNT()).collect(Collectors.toList());
    Collections.sort(opc, (p1, p2) -> p1.toString().compareTo(p2.toString()));
    mt = mt.withExceptions(opc);
    MethodWithType mwt = ma.withMt(mt).withDoc(doc);
    //now mwt has min exceptions and summed docs
    assert !ma.get_inner().isPresent() || !mb.get_inner().isPresent();
    if (mb.get_inner().isPresent()) {
        mwt = mwt.withInner(mb.getInner());
    }
    return mwt;
}
Also used : Resources(platformSpecific.javaTranslation.Resources) From(coreVisitors.From) Stage(ast.Ast.Stage) Program(programReduction.Program) Ast(ast.Ast) Map(tools.Map) Configuration(facade.Configuration) ErrorMessage(ast.ErrorMessage) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RefreshUniqueNames(privateMangling.RefreshUniqueNames) ClassB(ast.ExpCore.ClassB) PathMwt(ast.Util.PathMwt) ClassKind(is.L42.connected.withSafeOperators.ExtractInfo.ClassKind) CloneVisitor(sugarVisitors.CloneVisitor) NestedClass(ast.ExpCore.ClassB.NestedClass) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) Set(java.util.Set) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) CollapsePositions(sugarVisitors.CollapsePositions) List(java.util.List) Optional(java.util.Optional) Collections(java.util.Collections) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) Path(ast.Ast.Path) MethodType(ast.Ast.MethodType) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Doc(ast.Ast.Doc) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashSet(java.util.HashSet)

Aggregations

MethodWithType (ast.ExpCore.ClassB.MethodWithType)46 Member (ast.ExpCore.ClassB.Member)21 MethodType (ast.Ast.MethodType)18 ArrayList (java.util.ArrayList)16 Type (ast.Ast.Type)13 Path (ast.Ast.Path)10 ClassB (ast.ExpCore.ClassB)10 NestedClass (ast.ExpCore.ClassB.NestedClass)9 ExpCore (ast.ExpCore)8 MethodSelector (ast.Ast.MethodSelector)7 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)7 Ast (ast.Ast)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Program (programReduction.Program)4 Mdf (ast.Ast.Mdf)3 Functions (auxiliaryGrammar.Functions)3 From (coreVisitors.From)3 Collections (java.util.Collections)3