Search in sources :

Example 11 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class AlternativeMethodTypes method _bestMatchMtype.

public static MethodType _bestMatchMtype(Program p, MethodType superMt, List<MethodType> mts) {
    List<MethodType> res = new ArrayList<>();
    for (MethodType mt : mts) {
        if (TypeSystem._methMdfTSubtype(mt, superMt)) {
            if (!res.stream().anyMatch(mti -> TypeSystem._methMdfTSubtype(mti, mt))) {
                res = res.stream().filter(mti -> !TypeSystem._methMdfTSubtype(mt, mti)).collect(Collectors.toList());
                //if there is no method that is even better, add
                res.add(mt);
            }
        }
    }
    //assert res.size()==1: res.size(); sometime is false, for example capsule->capsule and mut->mut
    if (res.isEmpty()) {
        return null;
    }
    if (res.size() == 1) {
        return res.get(0);
    }
    //for final limitations
    List<MethodType> _res = res;
    Optional<MethodType> res1 = res.stream().filter(mt1 -> _res.stream().allMatch(mt2 -> Functions.isSubtype(mt1.getReturnType().getMdf(), mt2.getReturnType().getMdf()))).findAny();
    if (res1.isPresent()) {
        return res1.get();
    }
    assert false : "";
    return res.get(0);
}
Also used : From(coreVisitors.From) WellFormednessCore(auxiliaryGrammar.WellFormednessCore) Program(programReduction.Program) Path(ast.Ast.Path) TypeManipulation(newTypeSystem.TypeManipulation) Map(tools.Map) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Member(ast.ExpCore.ClassB.Member) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Functions(auxiliaryGrammar.Functions) Collectors(java.util.stream.Collectors) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) List(java.util.List) Optional(java.util.Optional) Mdf(ast.Ast.Mdf) MethodType(ast.Ast.MethodType) ArrayList(java.util.ArrayList)

Example 12 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class CloneVisitorWithProgram method visit.

public ExpCore visit(ClassB s) {
    Program aux = p;
    if (lastCMs != null && lastCMs instanceof Ast.C) {
        p = p.push((Ast.C) lastCMs);
    } else {
        p = p.evilPush(s);
    }
    Object auxO = lastCMs;
    lastCMs = null;
    try {
        return super.visit(s);
    } finally {
        p = aux;
        lastCMs = auxO;
    }
}
Also used : Program(programReduction.Program) Ast(ast.Ast)

Example 13 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class TsLibrary method memberNested.

default default TOutM memberNested(newTypeSystem.TIn in, NestedClass nc) {
    //(member nested)
    //Phase| p| Ps |-C:L ~>  C:L'
    //   where
    //   Phase |-p.push(C) ~> L'    return null;
    Program p1 = in.p.push(nc.getName());
    TOut res = typeLib(in.withP(p1));
    if (!res.isOk()) {
        return res.toError();
    }
    return new TOkM(nc.withInner(res.toOk().annotated));
}
Also used : Program(programReduction.Program)

Example 14 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class TsLibrary method coherent.

static boolean coherent(Program p, boolean force) {
    ClassB top = p.top();
    if (top.isInterface()) {
        return true;
    }
    List<MethodWithType> stateC = top.mwts().stream().map(m -> (MethodWithType) m).filter(m -> !m.get_inner().isPresent()).sorted((m1, m2) -> m1.getMt().getMdf() == Mdf.Class ? -1 : 1).collect(Collectors.toList());
    if (stateC.isEmpty()) {
        return true;
    }
    MethodWithType ck = stateC.get(0);
    if (!coherentK(p, ck)) {
        if (force) {
            throw new ErrorMessage.NotOkToStar(top, ck, "invalid candidate factory", ck.getP());
        }
        return false;
    }
    for (MethodWithType mwt : stateC.subList(1, stateC.size())) {
        if (!coherentF(p, ck, mwt)) {
            if (force) {
                throw new ErrorMessage.NotOkToStar(top, ck, "abstract method\n" + sugarVisitors.ToFormattedText.of(mwt) + "\ndo not fit candidate factory", mwt.getP());
            }
            return false;
        }
    }
    return true;
}
Also used : From(coreVisitors.From) NestedClass(ast.ExpCore.ClassB.NestedClass) Program(programReduction.Program) Path(ast.Ast.Path) Type(ast.Ast.Type) ErrorMessage(ast.ErrorMessage) Phase(ast.ExpCore.ClassB.Phase) Assertions(tools.Assertions) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) ArrayList(java.util.ArrayList) List(java.util.List) ClassB(ast.ExpCore.ClassB) Optional(java.util.Optional) Norm(programReduction.Norm) Mdf(ast.Ast.Mdf) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB)

Example 15 with Program

use of programReduction.Program in project L42 by ElvisResearchGroup.

the class TestTypeSystemOk method runTypeSystem.

static ClassB runTypeSystem(String scb1) {
    TestHelper.configureForTest();
    ClassB cb1 = (ClassB) Desugar.of(Parser.parse(null, scb1)).accept(new InjectionOnCore());
    Program p = Program.emptyLibraryProgram();
    return TypeSystem.instance().topTypeLib(Phase.Coherent, p.evilPush(cb1));
}
Also used : Program(programReduction.Program) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Aggregations

Program (programReduction.Program)25 ClassB (ast.ExpCore.ClassB)16 MethodWithType (ast.ExpCore.ClassB.MethodWithType)8 Path (ast.Ast.Path)6 ExpCore (ast.ExpCore)6 ArrayList (java.util.ArrayList)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 MethodSelector (ast.Ast.MethodSelector)5 Type (ast.Ast.Type)5 Functions (auxiliaryGrammar.Functions)5 PData (facade.PData)5 List (java.util.List)5 Optional (java.util.Optional)5 Member (ast.ExpCore.ClassB.Member)4 CloneVisitorWithProgram (coreVisitors.CloneVisitorWithProgram)4 Collectors (java.util.stream.Collectors)4 Doc (ast.Ast.Doc)3 Mdf (ast.Ast.Mdf)3 ErrorMessage (ast.ErrorMessage)3