Search in sources :

Example 86 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class Executor method metaMethod.

protected ClassB metaMethod(Program p, ClassB cb, Member m) {
    log("---meta2--");
    //get cb-->ct
    //get p'
    Program p1 = p.evilPush(cb);
    //extract e
    ExpCore e = m.getInner();
    //extract cb
    Ctx<ClassB> ctxC = ExtractCtxCompiled.of(e);
    //run cb1-->cb2
    ClassB cb2 = (ClassB) step(new PData(p1), ctxC.hole);
    ExpCore e2 = ReplaceCtx.of(ctxC.ctx, cb2);
    //compose cb with new member
    return cb.withMember(m.withInner(e2));
}
Also used : ExpCore(ast.ExpCore) Program(programReduction.Program) PData(facade.PData) ClassB(ast.ExpCore.ClassB)

Example 87 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class TestSum method test.

@Test
public void test() {
    TestHelper.configureForTest();
    ClassB cb1 = getClassB(_cb1);
    ClassB cb2 = getClassB(_cb2);
    ClassB expected = getClassB(_expected);
    if (!isError) {
        ClassB res = _Sum.sum(Program.emptyLibraryProgram(), cb1, cb2);
        TestHelper.assertEqualExp(expected, res);
    } else {
        try {
            _Sum.sum(Program.emptyLibraryProgram(), cb1, cb2);
            fail("error expected");
        } catch (Resources.Error err) {
            ClassB res = (ClassB) err.unbox;
            TestHelper.assertEqualExp(expected, res);
        }
    }
}
Also used : Resources(platformSpecific.javaTranslation.Resources) TestHelper.getClassB(helpers.TestHelper.getClassB) ClassB(ast.ExpCore.ClassB) Test(org.junit.Test)

Example 88 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class RemoveCode method addDep.

private static ClassB addDep(ClassB accumulator, List<Ast.C> path, ClassB originalCb) {
    if (path.isEmpty()) {
        return mergeNestedHolderWithDep(accumulator, originalCb);
    }
    Ast.C firstName = path.get(0);
    //either fistName does not exist in accumulator, and we call removeAllButPath
    //or we have to continue recursivelly.
    Optional<Member> optM = Functions.getIfInDom(accumulator.getMs(), firstName);
    NestedClass originalNc = (NestedClass) Functions.getIfInDom(originalCb.getMs(), firstName).get();
    ClassB newInner;
    if (!optM.isPresent()) {
        newInner = removeAllButPath(path.subList(1, path.size()), (ClassB) originalNc.getInner());
    } else {
        NestedClass accumulatorNc = (NestedClass) optM.get();
        newInner = addDep((ClassB) accumulatorNc.getInner(), path.subList(1, path.size()), (ClassB) originalNc.getInner());
    }
    NestedClass nc = originalNc.withInner(newInner);
    List<Member> ms = new ArrayList<>(accumulator.getMs());
    Functions.replaceIfInDom(ms, nc);
    return accumulator.withMs(ms);
}
Also used : Ast(ast.Ast) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) EncodingHelper.ensureExtractClassB(auxiliaryGrammar.EncodingHelper.ensureExtractClassB)

Example 89 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class TranslateExpression method visit.

//not a propagator visitor. 
@Override
public Void visit(ExpCore.EPath s) {
    Path ss = s.getInner();
    if (ss.isPrimitive()) {
        if (ss.equals(Path.Any())) {
            res.append("platformSpecific.javaTranslation.Resources.Any.type");
        }
        if (ss.equals(Path.Library())) {
            res.append("platformSpecific.javaTranslation.Resources.Library.type");
        }
        if (ss.equals(Path.Void())) {
            res.append("platformSpecific.javaTranslation.Resources.Void.type");
        }
        return null;
    }
    ClassB cbs = Resources.getP().extractClassB(ss);
    if (cbs.getPhase() == Phase.Coherent && IsCompiled.of(cbs)) {
        res.append(Resources.nameOf(ss) + ".type ");
    } else {
        Position pos = Resources.getP().get(ss.outerNumber()).getP();
        int hash = System.identityHashCode(pos);
        String cs = s.toString();
        int dotPos = cs.indexOf(".");
        assert dotPos >= 0;
        cs = cs.substring(dotPos);
        res.append("platformSpecific.javaTranslation.Resources.fromHash(" + hash + ",\"" + cs + "\")");
    }
    return null;
}
Also used : Path(ast.Ast.Path) Position(ast.Ast.Position) ClassB(ast.ExpCore.ClassB)

Example 90 with ClassB

use of ast.ExpCore.ClassB in project L42 by ElvisResearchGroup.

the class TestPop method test.

@Test
public void test() {
    ClassB cb1 = getClassB(_cb1);
    ClassB expected = getClassB(_expected);
    if (!isError) {
        ClassB res = Pop.pop(cb1);
        TestHelper.assertEqualExp(expected, res);
    } else {
        try {
            Pop.pop(cb1);
            fail("error expected");
        } catch (Resources.Error err) {
            ClassB res = (ClassB) err.unbox;
            TestHelper.assertEqualExp(expected, res);
        }
    }
}
Also used : Resources(platformSpecific.javaTranslation.Resources) ClassB(ast.ExpCore.ClassB) TestHelper.getClassB(helpers.TestHelper.getClassB) Test(org.junit.Test)

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