use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class TestHelper method getExpCore.
public static ExpCore getExpCore(String source, String _e1) {
Expression code1 = Parser.parse("GeneratedByTestHelper_", _e1);
Expression code2 = Desugar.of(code1);
ExpCore e1 = code2.accept(new InjectionOnCore());
return e1;
}
use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class SumMethods method eU.
static ExpCore eU(int index, Position pos, MethodType mt1, MethodType mt2, MethodSelector m1, MethodSelector m2, MethodSelector mRes) {
ExpCore r1 = (mt1.getMdf() == Mdf.Class) ? ExpCore.EPath.wrap(Path.outer(0)) : new ExpCore.X(pos, "this");
ExpCore r2 = (mt2.getMdf() == Mdf.Class) ? ExpCore.EPath.wrap(Path.outer(0)) : new ExpCore.X(pos, "this");
//this/outer0 . m2(this/outer0 .m1(ps1),ps2)
List<ExpCore> ps1 = new ArrayList<>();
for (String x : mRes.getNames().subList(0, m1.getNames().size())) {
ps1.add(new ExpCore.X(pos, x));
}
ExpCore eInner = new ExpCore.MCall(r1, m1, Doc.empty(), ps1, pos);
ArrayList<ExpCore> ps2 = new ArrayList<>();
for (int i = 1; i < m2.getNames().size(); i++) {
String x = mRes.getNames().get(m1.getNames().size() + i - 1);
ps2.add(new ExpCore.X(pos, x));
}
ps2.add(index, eInner);
ExpCore eU = new ExpCore.MCall(r2, m2, Doc.empty(), ps2, pos);
return eU;
}
use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class SumMethods method sumMethods.
public static ClassB sumMethods(ClassB lib, List<Ast.C> path, MethodSelector m1, MethodSelector m2, MethodSelector mRes, String name) {
ClassB pathCb = pathCb(lib, path);
Member mem1 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m1));
Member mem2 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m2));
MethodType mt1 = ((MethodWithType) pathCb._getMember(m1)).getMt();
MethodType mt2 = ((MethodWithType) pathCb._getMember(m2)).getMt();
int index = m2.getNames().indexOf(name);
if (index == -1) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, false, false, false);
}
checkParSize(index, path, m1, m2, mRes, mem1, mem2, mt1, mt2);
MethodType mtU = mtU(index, mt1, mt2);
if (mtU == null) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, isReplacedParOk(index, mt1, mt2), false, true);
}
ExpCore eU = eU(index, mem2.getP(), mt1, mt2, m1, m2, mRes);
MethodWithType mwtU = new MethodWithType(Doc.empty(), mRes, mtU, Optional.of(eU), mem2.getP());
checkConflict(path, mRes, pathCb, mwtU);
boolean replOk = isReplacedParOk(index, mt1, mt2);
if (!replOk) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, false, true, true);
}
return finalResult(lib, path, mwtU);
}
use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class Compose method sumMwt.
public static MethodWithType sumMwt(MethodWithType mwt1, MethodWithType mwt2) {
if (mwt1 == null) {
return mwt2;
}
boolean refine = mwt1.getMt().isRefine() || mwt2.getMt().isRefine();
if (!mwt1.getMt().withRefine(false).equals(mwt2.getMt().withRefine(false))) {
assert false;
}
Optional<ExpCore> body = mwt1.get_inner();
if (body.isPresent() && mwt2.get_inner().isPresent()) {
assert false;
}
if (!body.isPresent()) {
body = mwt2.get_inner();
}
MethodWithType mwt = mwt1.withMt(mwt1.getMt().withRefine(refine)).with_inner(body);
return mwt;
}
use of ast.ExpCore in project L42 by ElvisResearchGroup.
the class TestProgram method p.
public static Program p(String s) {
ExpCore.ClassB l = (ExpCore.ClassB) TestHelper.getExpCore(TestProgram.class.getSimpleName(), s);
Program p = new FlatProgram(l);
ExpCore.ClassB currentTop = l;
while (true) {
CtxL first = CtxL._split(currentTop);
if (first == null) {
return p;
}
ExpCore hole = first.originalHole();
if (!(hole instanceof ExpCore.ClassB)) {
return p;
}
currentTop = (ExpCore.ClassB) hole;
p = new PushedProgram(currentTop, first, p);
}
}
Aggregations