use of programReduction.Program 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 programReduction.Program in project L42 by ElvisResearchGroup.
the class CloneVisitorWithProgram method visit.
public ExpCore visit(ClassB s) {
Program aux = p;
if (lastCMs != null && lastCMs instanceof Ast.C) {
p = p.push((Ast.C) lastCMs);
} else {
p = p.evilPush(s);
}
Object auxO = lastCMs;
lastCMs = null;
try {
return super.visit(s);
} finally {
p = aux;
lastCMs = auxO;
}
}
use of programReduction.Program in project L42 by ElvisResearchGroup.
the class TsLibrary method memberNested.
default default TOutM memberNested(newTypeSystem.TIn in, NestedClass nc) {
//(member nested)
//Phase| p| Ps |-C:L ~> C:L'
// where
// Phase |-p.push(C) ~> L' return null;
Program p1 = in.p.push(nc.getName());
TOut res = typeLib(in.withP(p1));
if (!res.isOk()) {
return res.toError();
}
return new TOkM(nc.withInner(res.toOk().annotated));
}
use of programReduction.Program 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 programReduction.Program in project L42 by ElvisResearchGroup.
the class TestTypeSystemOk method runTypeSystem.
static ClassB runTypeSystem(String scb1) {
TestHelper.configureForTest();
ClassB cb1 = (ClassB) Desugar.of(Parser.parse(null, scb1)).accept(new InjectionOnCore());
Program p = Program.emptyLibraryProgram();
return TypeSystem.instance().topTypeLib(Phase.Coherent, p.evilPush(cb1));
}
Aggregations