use of ast.Ast.MethodType in project L42 by ElvisResearchGroup.
the class Test212_or_170_MethodTypes method testListGenerateAllOfMap.
@Test
public void testListGenerateAllOfMap() {
for (MethodType mt : dataSet) {
Map<MethodType, String> all = fixMap(mt);
List<MethodType> list = AlternativeMethodTypes.types(mt);
//mi(mVp would be promotable in imm, but is unuseful:
//the direct promotion to mc is more expressive
Set<MethodType> removeUnuseful = all.entrySet().stream().filter(e -> !e.getValue().contains("mI(mVp")).map(e -> e.getKey()).collect(Collectors.toSet());
boolean either = new HashSet<>(list).equals(removeUnuseful) || new HashSet<>(list).equals(all.keySet());
assert either : mapToS(all) + "\n" + mtsToS(list);
}
}
use of ast.Ast.MethodType in project L42 by ElvisResearchGroup.
the class Test212_or_170_MethodTypes method testReciverWorksAsParameter.
@Test
public void testReciverWorksAsParameter() {
for (MethodType mt : dataSet) {
MethodType left = recLeft(mt);
if (left == null) {
continue;
}
List<MethodType> list = AlternativeMethodTypes.types(mt);
List<MethodType> listLeftBefore = AlternativeMethodTypes.types(left);
List<MethodType> listLeftAfter = tools.Map.of(this::recLeft, list);
assert listLeftBefore.equals(listLeftAfter) : "\n" + mtsToS(list) + "\n" + mtsToS(listLeftBefore) + "\n" + mtsToS(listLeftAfter);
}
}
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;
}
Aggregations