Search in sources :

Example 16 with ExpCore

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

Example 17 with ExpCore

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

Example 18 with ExpCore

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

Example 19 with ExpCore

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

Example 20 with ExpCore

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

Aggregations

ExpCore (ast.ExpCore)62 ArrayList (java.util.ArrayList)25 ClassB (ast.ExpCore.ClassB)18 Member (ast.ExpCore.ClassB.Member)11 MethodWithType (ast.ExpCore.ClassB.MethodWithType)10 Expression (ast.Expression)10 Block (ast.ExpCore.Block)9 MethodType (ast.Ast.MethodType)8 Doc (ast.Ast.Doc)7 Path (ast.Ast.Path)7 Assertions (tools.Assertions)7 MethodSelector (ast.Ast.MethodSelector)6 Position (ast.Ast.Position)6 Program (programReduction.Program)6 InjectionOnCore (sugarVisitors.InjectionOnCore)6 Ast (ast.Ast)5 Type (ast.Ast.Type)5 ErrorMessage (ast.ErrorMessage)5 CloneVisitor (coreVisitors.CloneVisitor)5 List (java.util.List)5