Search in sources :

Example 6 with On

use of ast.ExpCore.Block.On in project L42 by ElvisResearchGroup.

the class PropagatorVisitor method visit.

public Void visit(Block s) {
    liftDoc(s.getDoc());
    liftDecs(s.getDecs());
    lift(s.getInner());
    for (On o : s.getOns()) {
        liftO(o);
    }
    return null;
}
Also used : On(ast.ExpCore.Block.On)

Example 7 with On

use of ast.ExpCore.Block.On in project L42 by ElvisResearchGroup.

the class FreeVariables method visitK.

private void visitK(List<On> k) {
    for (On on : k) {
        inScope.add(on.getX());
        on.getInner().accept(this);
        inScope.remove(on.getX());
    }
}
Also used : On(ast.ExpCore.Block.On)

Example 8 with On

use of ast.ExpCore.Block.On in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method updateTemplateUsing.

private static MethodWithType updateTemplateUsing(UsingInfo ui, MethodWithType mwt) {
    MCall e = templateUsingExc;
    MethodType mt = mwt.getMt();
    ExpCore.Block b = (Block) e.getEs().get(0);
    if (mwt.getMt().getExceptions().isEmpty()) {
        b = b.withOns(Collections.emptyList());
    }
    ExpCore.Using u = (Using) b.getDecs().get(0).getInner();
    //parameter expressions
    ExpCore.MCall p0 = (MCall) u.getEs().get(0);
    //e#mcall.inner<-mwt.retType.path
    e = e.withInner(ExpCore.EPath.wrap(mt.getReturnType().getPath()));
    //u=u.withS(ui.usingMs);
    List<ExpCore> ues = new ArrayList<>();
    if (mt.getMdf() != Mdf.Class) {
        ues.add(p0.withInner(new ExpCore.X(mwt.getP(), "this")));
    }
    {
        int i = -1;
        for (String x : mwt.getMs().getNames()) {
            i++;
            ExpCore pi = new ExpCore.X(mwt.getP(), x);
            boolean needAddBinaryRepr = true;
            Type ti = mwt.getMt().getTs().get(i);
            if (ti.equals(Type.immLibrary)) {
                needAddBinaryRepr = false;
            }
            if (ti.getMdf() == Mdf.Class) {
                needAddBinaryRepr = false;
            }
            if (needAddBinaryRepr) {
                pi = p0.withInner(pi);
            }
            ues.add(pi);
        }
    }
    u = new Using(u.getPath(), ui.usingMs, u.getDoc(), ues, u.getInner());
    String errorS = "plugin string: " + ui.plgInfo.plgString + "\n" + "plugin part: " + ui.plgInfo.plgName + "\n" + "method name: " + mwt.getMs() + "\n" + "java method: " + ui.plgInfo.plgClass.getName() + "." + ui.usingMs + "\n";
    //u.inner#mcall.es(0)<-EncodingHelper.wrapStringU()
    List<ExpCore> errorEs = Collections.singletonList(EncodingHelper.wrapStringU(errorS));
    Signal tmpS = (Signal) u.getInner();
    MCall tmpMc = ((MCall) tmpS.getInner()).withEs(errorEs);
    u = u.withInner(tmpS.withInner(tmpMc));
    b = b.withDecs(Collections.singletonList(b.getDecs().get(0).withInner(u)));
    //--
    if (!mwt.getMt().getExceptions().isEmpty()) {
        On on = b.getOns().get(0);
        Dec k0 = ((Block) on.getInner()).getDecs().get(0);
        List<Dec> ks = new ArrayList<>();
        {
            int i = -1;
            for (Type ti : mt.getExceptions()) {
                i++;
                MCall mci = ((MCall) k0.getInner()).withInner(ExpCore.EPath.wrap(ti.getPath()));
                ks.add(k0.withInner(mci).withX(k0.getX() + i));
            }
        }
        on = on.withInner(((Block) on.getInner()).withDecs(ks));
        b = b.withOns(Collections.singletonList(on));
    //k0=b.k(0).inner#block.decs(0)
    //k0 add more on need
    //ki.inner#mcall.inner<-Pi
    }
    if (ui.isVoid) {
        b = b.withDecs(Collections.singletonList(b.getDecs().get(0).withT(Optional.of(Type.immVoid))));
    }
    if (!ui.isVoid && !mwt.getMt().getReturnType().equals(Type.immLibrary)) {
        e = e.withEs(Collections.singletonList(b));
        mwt = mwt.withInner(e);
    } else {
        mwt = mwt.withInner(b);
    }
    return mwt;
}
Also used : MethodType(ast.Ast.MethodType) ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) Dec(ast.ExpCore.Block.Dec) Using(ast.ExpCore.Using) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Signal(ast.ExpCore.Signal) Using(ast.ExpCore.Using) MCall(ast.ExpCore.MCall) Block(ast.ExpCore.Block) MCall(ast.ExpCore.MCall) On(ast.ExpCore.Block.On)

Example 9 with On

use of ast.ExpCore.Block.On in project L42 by ElvisResearchGroup.

the class MethodPathCloneVisitor method visit.

public ExpCore visit(Block s) {
    HashMap<String, Ast.Type> aux = new HashMap<>(this.varEnv);
    try {
        for (Dec d : s.getDecs()) {
            if (d.getT().isPresent()) {
                this.varEnv.put(d.getX(), d.getT().get());
            }
        //TODO:??? GuessTypeCore._of(this.varEnv,d.getInner());
        }
        List<Dec> newDecs = liftDecs(s.getDecs());
        List<On> newOns = new ArrayList<>();
        for (On on : s.getOns()) {
            this.varEnv.put(on.getX(), on.getT());
            newOns.add(liftO(on));
            this.varEnv.remove(on.getX());
        }
        return new Block(s.getDoc(), newDecs, lift(s.getInner()), newOns, s.getP());
    } finally {
        this.varEnv = aux;
    }
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Dec(ast.ExpCore.Block.Dec) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Block(ast.ExpCore.Block) On(ast.ExpCore.Block.On)

Aggregations

On (ast.ExpCore.Block.On)9 Block (ast.ExpCore.Block)5 Type (ast.Ast.Type)4 ArrayList (java.util.ArrayList)4 Dec (ast.ExpCore.Block.Dec)3 ExpCore (ast.ExpCore)2 MethodWithType (ast.ExpCore.ClassB.MethodWithType)2 Mdf (ast.Ast.Mdf)1 MethodType (ast.Ast.MethodType)1 SignalKind (ast.Ast.SignalKind)1 MCall (ast.ExpCore.MCall)1 Signal (ast.ExpCore.Signal)1 Using (ast.ExpCore.Using)1 WalkBy (ast.ExpCore.WalkBy)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1