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