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());
}
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()));
}
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;
}
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);
}
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);
}
Aggregations