Search in sources :

Example 21 with MethodType

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

the class AlternativeMethodTypes method _mI.

static MethodType _mI(MethodType mt) {
    //Ts->read P0;Ps in methTypes(p,P,ms) //by well formedness if return type is read, not fwd_or_fwd%_in Ts
    //(mI)-------------------------------------------------------------------
    //toImmOrCapsule(Ts)->imm P0;Ps in methTypes(p,P,ms) 
    ////the behaviour of immorcapsule on fwd is not relevant since the method
    //// returns a read and will be not well formed if it had fwd parameters
    Type retT = mt.getReturnType();
    if (retT.getMdf() != Mdf.Readable && retT.getMdf() != Mdf.Lent) {
        return null;
    }
    retT = retT.withMdf(Mdf.Immutable);
    List<Type> ts = Map.of(t -> toImmOrCapsule(t), mt.getTs());
    return mt.withReturnType(retT).withTs(ts).withMdf(toImmOrCapsule(mt.getMdf()));
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 22 with MethodType

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

the class TIn method freshGFromMt.

public TIn freshGFromMt(MethodWithType mwt) {
    MethodType mt = mwt.getMt();
    assert mwt.get_inner().isPresent();
    Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
    newG.put("this", p(false, new Type(mt.getMdf(), Path.outer(0), Doc.empty())));
    {
        int i = -1;
        for (String x : mwt.getMs().getNames()) {
            i += 1;
            Type ntx = mt.getTs().get(i);
            newG.put(x, p(false, ntx));
        }
    }
    return new TIn(Phase.Typed, this.p, mwt.getInner(), TypeManipulation.fwdP(mt.getReturnType()), newG);
}
Also used : MethodType(ast.Ast.MethodType) Entry(java.util.Map.Entry) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashMap(java.util.HashMap)

Example 23 with MethodType

use of ast.Ast.MethodType 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 24 with MethodType

use of ast.Ast.MethodType 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 25 with MethodType

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

the class AlternativeMethodTypes method _mtDeclared.

static MethodType _mtDeclared(Program p, Path P, MethodSelector ms) {
    MethodWithType mwt = (MethodWithType) p.extractClassB(P)._getMember(ms);
    if (mwt == null) {
        return null;
    }
    MethodType mt = From.from(mwt.getMt(), P);
    return 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