Search in sources :

Example 41 with ClassB

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;
}
Also used : ClassB(ast.ExpCore.ClassB)

Example 42 with ClassB

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.");
    }
}
Also used : Path(ast.Ast.Path) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit) ClassB(ast.ExpCore.ClassB)

Example 43 with ClassB

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);
        }
    }
}
Also used : Path(ast.Ast.Path) MethodSelector(ast.Ast.MethodSelector) Resources(platformSpecific.javaTranslation.Resources) TestHelper.getClassB(helpers.TestHelper.getClassB) ClassB(ast.ExpCore.ClassB) Test(org.junit.Test)

Example 44 with ClassB

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);
    }
}
Also used : TestProgram(programReduction.TestProgram) Program(programReduction.Program) NotOkToStar(ast.ErrorMessage.NotOkToStar) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore) Test(org.junit.Test)

Example 45 with ClassB

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());
}
Also used : VarDecXE(ast.Ast.VarDecXE) UpdateVar(ast.ExpCore.UpdateVar) Ast(ast.Ast) Header(ast.Ast.Header) MCall(ast.ExpCore.MCall) Type(ast.Ast.Type) Member(ast.Expression.ClassB.Member) WellFormedness(auxiliaryGrammar.WellFormedness) MethodType(ast.Ast.MethodType) Loop(ast.ExpCore.Loop) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Visitor(coreVisitors.Visitor) ClassB(ast.ExpCore.ClassB) WalkBy(ast.ExpCore.WalkBy) Mdf(ast.Ast.Mdf) X(ast.ExpCore.X) VarDec(ast.Ast.VarDec) Path(ast.Ast.Path) Signal(ast.ExpCore.Signal) Match(tools.Match) Doc(ast.Ast.Doc) ExpCore._void(ast.ExpCore._void) ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) Expression(ast.Expression) List(java.util.List) Position(ast.Ast.Position) Using(ast.ExpCore.Using) Optional(java.util.Optional) Collections(java.util.Collections) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Header(ast.Ast.Header) Expression(ast.Expression) Doc(ast.Ast.Doc) Member(ast.Expression.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Aggregations

ClassB (ast.ExpCore.ClassB)107 ArrayList (java.util.ArrayList)33 Path (ast.Ast.Path)30 ExpCore (ast.ExpCore)25 Member (ast.ExpCore.ClassB.Member)25 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)20 Program (programReduction.Program)20 Ast (ast.Ast)19 MethodWithType (ast.ExpCore.ClassB.MethodWithType)19 MethodSelector (ast.Ast.MethodSelector)18 NestedClass (ast.ExpCore.ClassB.NestedClass)18 List (java.util.List)17 ActionType (platformSpecific.fakeInternet.ActionType)16 Doc (ast.Ast.Doc)12 Type (ast.Ast.Type)12 ErrorMessage (ast.ErrorMessage)12 Optional (java.util.Optional)10 C (ast.Ast.C)9 MethodType (ast.Ast.MethodType)8 Phase (ast.ExpCore.ClassB.Phase)8