Search in sources :

Example 26 with MethodType

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

the class AlternativeMethodTypes method mNoFwd.

static MethodType mNoFwd(MethodType mt) {
    //  Ts->T;Ps in methTypes(p,P,ms) 
    //(mNoFwd)-------------------------------------------------------------------
    //  noFwd Ts-> noFwd T;Ps in methTypes(p,P,ms)
    List<Type> ts = Map.of(t -> noFwd(t), mt.getTs());
    Type retT = noFwd(mt.getReturnType());
    return mt.withReturnType(retT).withTs(ts);
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 27 with MethodType

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

the class AlternativeMethodTypes method types.

static List<MethodType> types(MethodType mt) {
    List<MethodType> res = new ArrayList<>();
    MethodType base = mBase(mt);
    add(res, base);
    MethodType mNoFwd = mNoFwd(base);
    add(res, mNoFwd);
    MethodType mImmFwd = _mImmFwd(base);
    add(res, mImmFwd);
    MethodType mRead = _mRead(base);
    add(res, mRead);
    add(res, _mC(base));
    add(res, _mC(mNoFwd));
    add(res, _mI(base));
    if (mRead != null) {
        add(res, _mI(mRead));
    }
    if (mImmFwd != null) {
        add(res, mNoFwd(mImmFwd));
    }
    if (mt.getMdf() == Mdf.Mutable) {
        add(res, _mVp(base, 0));
    }
    //later, 0 for mvp is the receiver so is ok to start from 1
    {
        int i = 0;
        for (Type ti : base.getTs()) {
            i += 1;
            if (ti.getMdf() != Mdf.Mutable) {
                continue;
            }
            //1 mType for each mut parameter
            add(res, _mVp(base, i));
        }
    }
    if (mt.getMdf() == Mdf.Mutable) {
        add(res, _mVp(mNoFwd, 0));
    }
    {
        int i = 0;
        for (Type ti : mNoFwd.getTs()) {
            i += 1;
            if (ti.getMdf() != Mdf.Mutable) {
                continue;
            }
            //1 mType for each mut parameter
            add(res, _mVp(mNoFwd, i));
        }
    }
    return res;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList)

Example 28 with MethodType

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

the class AlternativeMethodTypes method _mVp.

static MethodType _mVp(MethodType mt, int parNum) {
    if (parNum > 0) {
        return _mVpNoRec(mt, parNum - 1);
    }
    assert parNum == 0;
    if (mt.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());
    MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(Mdf.Lent);
    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)

Example 29 with MethodType

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

the class AlternativeMethodTypes method _mRead.

static MethodType _mRead(MethodType mt) {
    //mutToCapsuleAndFwdToRead(Ts)->read P0;Ps in methTypes(p,P,ms)
    if (!TypeManipulation.fwd_or_fwdP_in(mt.getTs())) {
        return null;
    }
    Type retT = mt.getReturnType();
    if (retT.getMdf() != Mdf.MutablePFwd) {
        return null;
    }
    retT = retT.withMdf(Mdf.Readable);
    List<Type> ts = Map.of(t -> mutToCapsuleAndFwdToRead(t), mt.getTs());
    MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsuleAndFwdToRead(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)

Example 30 with MethodType

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

the class AlternativeMethodTypes method mBase.

static MethodType mBase(Program p, Path P, MethodSelector ms) {
    //p(P)(ms).mh[from P]=refine? mdf0 method T m(T1 x1,..Tn xn) exception Ps
    //T'=fwd% T if fwd_or_fwd%_in(Ts)
    //otherwise T'=T       
    //(mBase)-------------------------------------------------------------------
    //mdf0 P T1..Tn-> T';Ps in methTypes(p,P,ms)    MethodWithType mwt = (MethodWithType) p.extractClassB(P)._getMember(ms);
    MethodWithType mwt = (MethodWithType) p.extractClassB(P)._getMember(ms);
    assert mwt != null;
    MethodType mt = From.from(mwt.getMt(), P);
    return mBase(mt);
}
Also used : 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