Search in sources :

Example 46 with Type

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

the class WellFormednessCore method methodTypeWellFormed.

public static boolean methodTypeWellFormed(MethodType mt) {
    boolean r1 = false;
    boolean r2 = false;
    //if exists fwdMut _ in Ts then (return type).mdf in {mut, fwdMut}
    for (Type t : mt.getTs()) {
        Mdf m = t.getMdf();
        if (m == Mdf.ImmutableFwd) {
            r1 = true;
        }
        if (m == Mdf.MutableFwd) {
            r2 = true;
        }
    }
    Mdf m = mt.getReturnType().getMdf();
    if (r2) {
        if (m != Mdf.Mutable && m != Mdf.MutableFwd && m != Mdf.MutablePFwd) {
            return false;
        }
    } else if (r1) {
        if (m != Mdf.Mutable && m != Mdf.Immutable && !TypeManipulation.fwd_or_fwdP_in(m)) {
            return false;
        }
    }
    //TODO: do we want this extra restriction?
    if (!r1 && !r2) {
        //no fwd at all
        if (TypeManipulation.fwd_or_fwdP_in(m)) {
            return false;
        }
    }
    return true;
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Mdf(ast.Ast.Mdf)

Example 47 with Type

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

the class AlternativeMethodTypes method _mImmFwd.

static MethodType _mImmFwd(MethodType mt) {
    //mutToCapsuleAndFwdMutToFwdImm(Ts)->fwd%Imm 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.ImmutablePFwd);
    List<Type> ts = Map.of(t -> mutToCapsuleAndFwdMutToFwdImm(t), mt.getTs());
    MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsuleAndFwdMutToFwdImm(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 48 with Type

use of ast.Ast.Type 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 49 with Type

use of ast.Ast.Type 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 50 with Type

use of ast.Ast.Type 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)

Aggregations

Type (ast.Ast.Type)81 MethodType (ast.Ast.MethodType)50 MethodWithType (ast.ExpCore.ClassB.MethodWithType)28 MethodWithType (ast.Expression.ClassB.MethodWithType)24 ArrayList (java.util.ArrayList)24 Mdf (ast.Ast.Mdf)16 Expression (ast.Expression)15 Path (ast.Ast.Path)13 Doc (ast.Ast.Doc)11 Ast (ast.Ast)10 MethodSelector (ast.Ast.MethodSelector)10 HashMap (java.util.HashMap)10 MethodSelectorX (ast.Ast.MethodSelectorX)8 VarDecXE (ast.Ast.VarDecXE)8 ExpCore (ast.ExpCore)8 Catch (ast.Expression.Catch)8 X (ast.Expression.X)8 VarDec (ast.Ast.VarDec)7 Block (ast.ExpCore.Block)7 List (java.util.List)7