Search in sources :

Example 11 with MethodType

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

the class Test212_or_170_MethodTypes method testListGenerateAllOfMap.

@Test
public void testListGenerateAllOfMap() {
    for (MethodType mt : dataSet) {
        Map<MethodType, String> all = fixMap(mt);
        List<MethodType> list = AlternativeMethodTypes.types(mt);
        //mi(mVp would be promotable in imm, but is unuseful:
        //the direct promotion to mc is more expressive
        Set<MethodType> removeUnuseful = all.entrySet().stream().filter(e -> !e.getValue().contains("mI(mVp")).map(e -> e.getKey()).collect(Collectors.toSet());
        boolean either = new HashSet<>(list).equals(removeUnuseful) || new HashSet<>(list).equals(all.keySet());
        assert either : mapToS(all) + "\n" + mtsToS(list);
    }
}
Also used : TestProgram(programReduction.TestProgram) WellFormednessCore(auxiliaryGrammar.WellFormednessCore) Arrays(java.util.Arrays) Program(programReduction.Program) Path(ast.Ast.Path) Collection(java.util.Collection) Type(ast.Ast.Type) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) MethodType(ast.Ast.MethodType) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) Assert(org.junit.Assert) Collections(java.util.Collections) AlternativeMethodTypes(newTypeSystem.AlternativeMethodTypes) Mdf(ast.Ast.Mdf) MethodType(ast.Ast.MethodType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with MethodType

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

the class Test212_or_170_MethodTypes method testReciverWorksAsParameter.

@Test
public void testReciverWorksAsParameter() {
    for (MethodType mt : dataSet) {
        MethodType left = recLeft(mt);
        if (left == null) {
            continue;
        }
        List<MethodType> list = AlternativeMethodTypes.types(mt);
        List<MethodType> listLeftBefore = AlternativeMethodTypes.types(left);
        List<MethodType> listLeftAfter = tools.Map.of(this::recLeft, list);
        assert listLeftBefore.equals(listLeftAfter) : "\n" + mtsToS(list) + "\n" + mtsToS(listLeftBefore) + "\n" + mtsToS(listLeftAfter);
    }
}
Also used : MethodType(ast.Ast.MethodType) Test(org.junit.Test)

Example 13 with MethodType

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

the class InjectionOnSugar method visit.

@Override
public Expression visit(ClassB s) {
    Doc doc1 = s.getDoc1();
    Header h = (s.isInterface()) ? new Ast.InterfaceHeader() : new Ast.TraitHeader();
    List<Type> supertypes = s.getSupertypes();
    List<Member> members = new ArrayList<>();
    for (ast.ExpCore.ClassB.Member mi : s.getMs()) {
        members.add(mi.match(nc -> new Expression.ClassB.NestedClass(nc.getDoc(), nc.getName(), lift(nc.getInner()), nc.getP()), mimpl -> new Expression.ClassB.MethodImplemented(mimpl.getDoc(), mimpl.getS(), lift(mimpl.getInner()), mimpl.getP()), mwt -> {
            Doc idoc = mwt.getDoc();
            MethodSelector is = mwt.getMs();
            MethodType mt = mwt.getMt();
            return new Expression.ClassB.MethodWithType(idoc, is, mt, lift(mwt.get_inner()), mwt.getP());
        }));
    }
    return new Expression.ClassB(doc1, h, Collections.emptyList(), supertypes, members, s.getP());
}
Also used : VarDecXE(ast.Ast.VarDecXE) UpdateVar(ast.ExpCore.UpdateVar) Ast(ast.Ast) Header(ast.Ast.Header) MCall(ast.ExpCore.MCall) Type(ast.Ast.Type) Member(ast.Expression.ClassB.Member) WellFormedness(auxiliaryGrammar.WellFormedness) MethodType(ast.Ast.MethodType) Loop(ast.ExpCore.Loop) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Visitor(coreVisitors.Visitor) ClassB(ast.ExpCore.ClassB) WalkBy(ast.ExpCore.WalkBy) Mdf(ast.Ast.Mdf) X(ast.ExpCore.X) VarDec(ast.Ast.VarDec) Path(ast.Ast.Path) Signal(ast.ExpCore.Signal) Match(tools.Match) Doc(ast.Ast.Doc) ExpCore._void(ast.ExpCore._void) ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) Expression(ast.Expression) List(java.util.List) Position(ast.Ast.Position) Using(ast.ExpCore.Using) Optional(java.util.Optional) Collections(java.util.Collections) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Header(ast.Ast.Header) Expression(ast.Expression) Doc(ast.Ast.Doc) Member(ast.Expression.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 14 with MethodType

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

the class AlternativeMethodTypes method _mC.

static MethodType _mC(MethodType mt) {
    //Ts->mut P0;Ps in methTypes(p,P,ms)
    //(mC)-------------------------------------------------------------------
    //mutToCapsule(Ts)->capsule P0;Ps in methTypes(p,P,ms)
    Type retT = mt.getReturnType();
    if (retT.getMdf() != Mdf.Mutable) {
        return null;
    }
    retT = retT.withMdf(Mdf.Capsule);
    List<Type> ts = Map.of(t -> mutToCapsule(t), mt.getTs());
    return mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsule(mt.getMdf()));
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 15 with MethodType

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

the class AlternativeMethodTypes method _mVpNoRec.

static MethodType _mVpNoRec(MethodType mt, int parNum) {
    //Ts0 mut P Ts2->T;Ps in methTypes(p,P,ms)
    //Ts'=mutToCapsule(Ts0) lent P mutToCapsule(Ts2) //this implies not fwd_or_fwd%_in Ts0,Ts2
    //(mVp)-------------------------------------------------------------------
    //Ts'->toLent(T);Ps in methTypes(p,P,ms)
    Type pN = mt.getTs().get(parNum);
    if (pN.getMdf() != Mdf.Mutable) {
        return null;
    }
    Type retT = mt.getReturnType();
    retT = _toLent(retT);
    if (retT == null) {
        return null;
    }
    List<Type> ts = Map.of(t -> mutToCapsule(t), mt.getTs());
    ts.set(parNum, pN.withMdf(Mdf.Lent));
    MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsule(mt.getMdf()));
    if (WellFormednessCore.methodTypeWellFormed(res)) {
        return res;
    }
    return null;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Aggregations

MethodType (ast.Ast.MethodType)48 Type (ast.Ast.Type)32 MethodWithType (ast.ExpCore.ClassB.MethodWithType)25 Mdf (ast.Ast.Mdf)14 MethodSelector (ast.Ast.MethodSelector)14 ArrayList (java.util.ArrayList)14 Path (ast.Ast.Path)10 ExpCore (ast.ExpCore)9 List (java.util.List)9 Collections (java.util.Collections)8 Functions (auxiliaryGrammar.Functions)7 Test (org.junit.Test)7 Doc (ast.Ast.Doc)6 MethodWithType (ast.Expression.ClassB.MethodWithType)6 HashMap (java.util.HashMap)6 Program (programReduction.Program)6 Ast (ast.Ast)5 ClassB (ast.ExpCore.ClassB)5 Member (ast.ExpCore.ClassB.Member)5 Optional (java.util.Optional)5