Search in sources :

Example 66 with ClassB

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

the class TestShortPrograms method tp.

public static void tp(String... code) {
    TestHelper.configureForTest();
    FinalResult res0;
    try {
        res0 = facade.L42.runSlow(null, TestHelper.multiLine(code));
    } catch (ErrorMessage msg) {
        ErrorFormatter.topFormatErrorMessage(msg);
        throw msg;
    }
    ClassB res = res0.getTopLevelProgram();
    ClassB.NestedClass nc = (ClassB.NestedClass) res.getMs().get(res.getMs().size() - 1);
    ExpCore ee2 = Desugar.of(Parser.parse(null, "{//@exitStatus\n//0\n\n}")).accept(new InjectionOnCore());
    TestHelper.assertEqualExp(nc.getInner(), ee2);
}
Also used : ExpCore(ast.ExpCore) FinalResult(ast.ErrorMessage.FinalResult) ErrorMessage(ast.ErrorMessage) ClassB(ast.ExpCore.ClassB) InjectionOnCore(sugarVisitors.InjectionOnCore)

Example 67 with ClassB

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

the class Methods method methods.

//  -methods(p,P0)=M1'..Mk'
//          p(P0)={interface? implements Ps Ms} 
public List<MethodWithType> methods(Ast.Path p0) {
    if (p0.isPrimitive()) {
        return Collections.emptyList();
    }
    Program p = this;
    ClassB cb0 = p.extractClassB(p0);
    List<Ast.Path> ps = cb0.getSuperPaths();
    //          P1..Pn=collect(p,Ps[from P0]), error unless forall i, p(Pi) is an interface
    List<Ast.Path> p1n = collect(p, Map.of(pi -> From.fromP(pi, p0), ps));
    List<ClassB> cb1n = Map.of(pi -> p.extractClassB(pi), p1n);
    {
        int i = -1;
        for (ClassB cbi : cb1n) {
            i++;
            if (!cbi.isInterface()) {
                throw new ast.ErrorMessage.NonInterfaceImplements(p0, p1n.get(i));
            }
        }
    }
    //          ms1..msk={ms|p(Pi)(ms) is defined}
    HashMap<Ast.MethodSelector, List<ClassB.Member>> ms1k = new LinkedHashMap<>();
    for (ClassB.Member mij : cb0.getMs()) {
        mij.match(nc -> null, mi -> add(true, ms1k, mi.getS(), From.from(mij, p0)), mt -> add(true, ms1k, mt.getMs(), From.from(mij, p0)));
    }
    for (Ast.Path pi : p1n) {
        //call the memoized methods
        for (ClassB.Member mij : p.methods(pi)) {
            mij.match(nc -> null, mi -> add(false, ms1k, mi.getS(), mij), mt -> add(false, ms1k, mt.getMs(), mij));
        }
    }
    //            such that p(Pj)(ms)=mh e? //no refine
    for (Entry<MethodSelector, List<Member>> ei : ms1k.entrySet()) {
        if (!exactly1NoRefine(ei.getValue())) {
            throw new ast.ErrorMessage.NotExaclyOneMethodOrigin(p0, ei.getKey(), ei.getValue());
        }
    }
    List<ClassB.MethodWithType> ms = new ArrayList<>();
    //            for the smallest j in 1..k such that methods(p,Pj)(msi) of form refine? mh
    for (Entry<MethodSelector, List<Member>> ei : ms1k.entrySet()) {
        List<Member> memsi = ei.getValue();
        if (memsi.get(0) != null && memsi.get(0) instanceof MethodWithType) {
            ms.add((MethodWithType) memsi.get(0));
            continue;
        }
        ClassB.MethodImplemented mem0 = (ClassB.MethodImplemented) memsi.get(0);
        for (Member mj : memsi) {
            // 0 will fail instanceof
            if (mj == null || !(mj instanceof MethodWithType)) {
                continue;
            }
            //    Mi'=Mi
            if (mem0 != null) {
                mj = mj.withInner(mem0.getE());
            }
            ms.add(addRefine((MethodWithType) mj));
            break;
        }
    }
    return ms;
}
Also used : From(coreVisitors.From) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Set(java.util.Set) HashMap(java.util.HashMap) Member(ast.ExpCore.ClassB.Member) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Collectors(java.util.stream.Collectors) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ClassB(ast.ExpCore.ClassB) Entry(java.util.Map.Entry) Collections(java.util.Collections) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) Path(ast.Ast.Path) Ast(ast.Ast) Path(ast.Ast.Path) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 68 with ClassB

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

the class Norm method auxMultiNorm.

static Program auxMultiNorm(Program p, List<List<Ast.C>> topPaths) {
    ClassB lTop = p.top();
    for (List<Ast.C> csi : topPaths) {
        //  pi = p.navigate(Csi)
        //  Li = norm(pi)//norming the top
        //  L = p.top()[Cs1=L1..Csn=Ln] //replace the nested classes in paths Csi with libraries Li.
        Program pi = p.navigate(csi);
        ClassB li = new Norm().norm(pi);
        lTop = lTop.onClassNavigateToPathAndDo(csi, _l -> li);
    }
    return p.updateTop(lTop);
}
Also used : NestedClass(ast.ExpCore.ClassB.NestedClass) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Type(ast.Ast.Type) Phase(ast.ExpCore.ClassB.Phase) Assertions(tools.Assertions) ExpCore(ast.ExpCore) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CloneVisitor(coreVisitors.CloneVisitor) List(java.util.List) Stream(java.util.stream.Stream) ClassB(ast.ExpCore.ClassB) Optional(java.util.Optional) ClassB(ast.ExpCore.ClassB)

Example 69 with ClassB

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

the class Norm method norm.

public ExpCore.ClassB norm(Program p) {
    //-norm(p)={interface? implements Ps' norm(p,Ms') }
    //p.top()={interface? implements Ps Ms} //Ms is free var and is ok
    ClassB l = p.top();
    //Ps'=collect(p,Ps)
    List<Path> ps1 = Methods.collect(p, l.getSuperPaths());
    //Ms'=methods(p,This0), {C:e in Ms} //norm now put all the nested classes in the back.
    List<ClassB.Member> ms1 = Stream.concat(p.methods(Path.outer(0)).stream(), l.getMs().stream().filter(m -> m instanceof ClassB.NestedClass)).map(m -> norm(p, m)).collect(Collectors.toList());
    //return l.withSupertypes(ps1).withMs(ms1).withUniqueId(p.getFreshId()).withPhase(Phase.Norm);
    return new ClassB(l.getDoc1(), l.isInterface(), Map.of(pi -> pi.toImmNT(), ps1), ms1, l.getP(), Phase.Norm, p.getFreshId());
}
Also used : Path(ast.Ast.Path) NestedClass(ast.ExpCore.ClassB.NestedClass) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Type(ast.Ast.Type) Phase(ast.ExpCore.ClassB.Phase) Assertions(tools.Assertions) ExpCore(ast.ExpCore) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CloneVisitor(coreVisitors.CloneVisitor) List(java.util.List) Stream(java.util.stream.Stream) ClassB(ast.ExpCore.ClassB) Optional(java.util.Optional) NestedClass(ast.ExpCore.ClassB.NestedClass) ClassB(ast.ExpCore.ClassB)

Example 70 with ClassB

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

the class EvilPushed method push.

default default Program push(Ast.C c) {
    CtxL splitted = CtxL.split(this.top(), c);
    ExpCore holeP = splitted.originalHole();
    assert holeP instanceof ClassB;
    return new PushedProgram((ClassB) holeP, splitted, this);
}
Also used : ExpCore(ast.ExpCore) 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