use of ast.Ast.Type 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.Type 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.Type in project L42 by ElvisResearchGroup.
the class AlternativeMethodTypes method mNoFwd.
static MethodType mNoFwd(MethodType mt) {
// Ts->T;Ps in methTypes(p,P,ms)
//(mNoFwd)-------------------------------------------------------------------
// noFwd Ts-> noFwd T;Ps in methTypes(p,P,ms)
List<Type> ts = Map.of(t -> noFwd(t), mt.getTs());
Type retT = noFwd(mt.getReturnType());
return mt.withReturnType(retT).withTs(ts);
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class AlternativeMethodTypes method types.
static List<MethodType> types(MethodType mt) {
List<MethodType> res = new ArrayList<>();
MethodType base = mBase(mt);
add(res, base);
MethodType mNoFwd = mNoFwd(base);
add(res, mNoFwd);
MethodType mImmFwd = _mImmFwd(base);
add(res, mImmFwd);
MethodType mRead = _mRead(base);
add(res, mRead);
add(res, _mC(base));
add(res, _mC(mNoFwd));
add(res, _mI(base));
if (mRead != null) {
add(res, _mI(mRead));
}
if (mImmFwd != null) {
add(res, mNoFwd(mImmFwd));
}
if (mt.getMdf() == Mdf.Mutable) {
add(res, _mVp(base, 0));
}
//later, 0 for mvp is the receiver so is ok to start from 1
{
int i = 0;
for (Type ti : base.getTs()) {
i += 1;
if (ti.getMdf() != Mdf.Mutable) {
continue;
}
//1 mType for each mut parameter
add(res, _mVp(base, i));
}
}
if (mt.getMdf() == Mdf.Mutable) {
add(res, _mVp(mNoFwd, 0));
}
{
int i = 0;
for (Type ti : mNoFwd.getTs()) {
i += 1;
if (ti.getMdf() != Mdf.Mutable) {
continue;
}
//1 mType for each mut parameter
add(res, _mVp(mNoFwd, i));
}
}
return res;
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class AlternativeMethodTypes method _mVp.
static MethodType _mVp(MethodType mt, int parNum) {
if (parNum > 0) {
return _mVpNoRec(mt, parNum - 1);
}
assert parNum == 0;
if (mt.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());
MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(Mdf.Lent);
if (WellFormednessCore.methodTypeWellFormed(res)) {
return res;
}
return null;
}
Aggregations