Search in sources :

Example 1 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 2 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 3 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)

Example 4 with MethodType

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

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

the class SumMethods method isReplacedParOk.

static boolean isReplacedParOk(int index, MethodType mt1, MethodType mt2) {
    if (mt2.getTs().isEmpty()) {
        return false;
    }
    Type p1 = mt2.getTs().get(index);
    Type r = mt1.getReturnType();
    return p1.equals(r);
}
Also used : 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