use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class TsLibrary method coherent.
static boolean coherent(Program p, boolean force) {
ClassB top = p.top();
if (top.isInterface()) {
return true;
}
List<MethodWithType> stateC = top.mwts().stream().map(m -> (MethodWithType) m).filter(m -> !m.get_inner().isPresent()).sorted((m1, m2) -> m1.getMt().getMdf() == Mdf.Class ? -1 : 1).collect(Collectors.toList());
if (stateC.isEmpty()) {
return true;
}
MethodWithType ck = stateC.get(0);
if (!coherentK(p, ck)) {
if (force) {
throw new ErrorMessage.NotOkToStar(top, ck, "invalid candidate factory", ck.getP());
}
return false;
}
for (MethodWithType mwt : stateC.subList(1, stateC.size())) {
if (!coherentF(p, ck, mwt)) {
if (force) {
throw new ErrorMessage.NotOkToStar(top, ck, "abstract method\n" + sugarVisitors.ToFormattedText.of(mwt) + "\ndo not fit candidate factory", mwt.getP());
}
return false;
}
}
return true;
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class GuessTypeCore method visit.
@Override
public Type visit(MCall s) {
Type former = s.getInner().accept(this);
if (former == null) {
return null;
}
Path path = former.getPath();
assert path != null;
List<MethodSelectorX> msl = new ArrayList<>();
MethodSelectorX msx = new MethodSelectorX(s.getS(), "");
msl.add(msx);
MethodWithType meth = (MethodWithType) p.extractClassB(path)._getMember(s.getS());
if (meth == null) {
return null;
}
return (Type) From.fromT(meth.getMt().getReturnType(), path);
}
use of ast.ExpCore.ClassB.MethodWithType 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.ExpCore.ClassB.MethodWithType 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;
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class AlternativeMethodTypes method mBase.
static MethodType mBase(Program p, Path P, MethodSelector ms) {
//p(P)(ms).mh[from P]=refine? mdf0 method T m(T1 x1,..Tn xn) exception Ps
//T'=fwd% T if fwd_or_fwd%_in(Ts)
//otherwise T'=T
//(mBase)-------------------------------------------------------------------
//mdf0 P T1..Tn-> T';Ps in methTypes(p,P,ms) MethodWithType mwt = (MethodWithType) p.extractClassB(P)._getMember(ms);
MethodWithType mwt = (MethodWithType) p.extractClassB(P)._getMember(ms);
assert mwt != null;
MethodType mt = From.from(mwt.getMt(), P);
return mBase(mt);
}
Aggregations