use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class Lib method newFromClass.
public static Lib newFromClass(PData pData, Path path) {
//TODO: need from??
ClassB cb = pData.p.extractClassB(path);
Lib lib = new Lib(true, cb, Collections.emptyList(), cb);
return lib;
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method isOkAsParameter.
private static void isOkAsParameter(Program p, Path csTop, Type ti) throws ClassUnfit, MethodUnfit {
Path pi = ti.getPath();
//class parameters are ok, and we just omit the .#binaryRepr() call
if (ti.getMdf() == Mdf.Class) {
return;
}
//Libraries are ok and we just omit the .#binaryRepr() call
if (pi.equals(Path.Library())) {
return;
}
Path op = _pathForOutside(csTop.getCBar().size(), pi);
if (op == null) {
checkForInside(p.top(), csTop, pi);
return;
}
//TODO: since p.top is topL, is it ok this extraction?
ClassB l = p.extractClassB(op);
boolean hasIt = hasBinaryRepr(l);
boolean phOk = Functions.isComplete(ti);
if (!hasIt) {
throw new RefactorErrors.ClassUnfit().msg("Class " + op + " has no #binaryRepr() method");
}
if (!phOk) {
throw new RefactorErrors.MethodUnfit().msg("Fwd types not allowed.");
}
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class TestSumMethod method test.
@Test
public void test() {
TestHelper.configureForTest();
ClassB cb = getClassB(_cb);
Path path = Path.parse(_path);
MethodSelector ms1 = MethodSelector.parse(_ms1);
MethodSelector ms2 = MethodSelector.parse(_ms2);
MethodSelector ms3 = MethodSelector.parse(_ms3);
ClassB expected = getClassB(_expected);
if (!isError) {
ClassB res = SumMethods.sumMethods(cb, path.getCBar(), ms1, ms2, ms3, name);
TestHelper.assertEqualExp(expected, res);
} else {
try {
ClassB res = SumMethods.sumMethods(cb, path.getCBar(), ms1, ms2, ms3, name);
fail("error expected");
} catch (Resources.Error err) {
ClassB res = (ClassB) err.unbox;
TestHelper.assertEqualExp(expected, res);
}
}
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class TestLibrary method test.
@Test()
public void test() {
Program p = TestProgram.p(sProg);
ClassB cb1Pre = (ClassB) Desugar.of(Parser.parse(null, s1)).accept(new InjectionOnCore());
cb1Pre = new programReduction.Norm().norm(p.evilPush(cb1Pre));
TOut out;
try {
out = TypeSystem.instance().type(TIn.top(Phase.Coherent, p, cb1Pre));
} catch (NotOkToStar coh) {
assert s2 == ErrorKind.LibraryNotCoherent;
return;
}
if (s2 instanceof ErrorKind) {
assert !out.isOk();
ErrorKind kind = out.toError().kind;
assert kind == s2;
} else {
assert out.isOk() : "";
ClassB cb1 = (ClassB) out.toOk().annotated;
ClassB cbExpected = s2 == sameAsFormer ? cb1Pre : (ClassB) Desugar.of(Parser.parse(null, (String) s2)).accept(new InjectionOnCore());
TestHelper.assertEqualExp(cb1, cbExpected);
}
}
use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.
the class InjectionOnSugar method visit.
@Override
public Expression visit(ClassB s) {
Doc doc1 = s.getDoc1();
Header h = (s.isInterface()) ? new Ast.InterfaceHeader() : new Ast.TraitHeader();
List<Type> supertypes = s.getSupertypes();
List<Member> members = new ArrayList<>();
for (ast.ExpCore.ClassB.Member mi : s.getMs()) {
members.add(mi.match(nc -> new Expression.ClassB.NestedClass(nc.getDoc(), nc.getName(), lift(nc.getInner()), nc.getP()), mimpl -> new Expression.ClassB.MethodImplemented(mimpl.getDoc(), mimpl.getS(), lift(mimpl.getInner()), mimpl.getP()), mwt -> {
Doc idoc = mwt.getDoc();
MethodSelector is = mwt.getMs();
MethodType mt = mwt.getMt();
return new Expression.ClassB.MethodWithType(idoc, is, mt, lift(mwt.get_inner()), mwt.getP());
}));
}
return new Expression.ClassB(doc1, h, Collections.emptyList(), supertypes, members, s.getP());
}
Aggregations