Search in sources :

Example 1 with Signal

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

the class ExtractThrow method visit.

public ExpCore visit(Block s) {
    if (!s.getOns().isEmpty()) {
        return new ExpCore.WalkBy();
    }
    for (int i = 0; i < s.getDecs().size(); i++) {
        if (new IsValue(p).validDv(s.getDecs().get(i))) {
            continue;
        }
        //otherwise, i is the first non dv
        ExpCore res = s.getDecs().get(i).getInner().accept(this);
        if (res instanceof ExpCore.WalkBy) {
            return res;
        }
        Signal res_ = (Signal) res;
        List<Block.Dec> decs = s.getDecs().subList(0, i);
        Block newInner = new Block(s.getDoc(), decs, res_.getInner(), Collections.emptyList(), s.getP());
        newInner = Functions.garbage(newInner, i);
        return res_.withInner(newInner);
    }
    ExpCore res = s.getInner().accept(this);
    if (res instanceof ExpCore.WalkBy) {
        return res;
    }
    Signal res_ = (Signal) res;
    Block newInner = s.withInner(res_.getInner());
    return res_.withInner(newInner);
}
Also used : ExpCore(ast.ExpCore) Signal(ast.ExpCore.Signal) Block(ast.ExpCore.Block) WalkBy(ast.ExpCore.WalkBy)

Example 2 with Signal

use of ast.ExpCore.Signal 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)

Aggregations

ExpCore (ast.ExpCore)2 Block (ast.ExpCore.Block)2 Signal (ast.ExpCore.Signal)2 MethodType (ast.Ast.MethodType)1 Type (ast.Ast.Type)1 Dec (ast.ExpCore.Block.Dec)1 On (ast.ExpCore.Block.On)1 MethodWithType (ast.ExpCore.ClassB.MethodWithType)1 MCall (ast.ExpCore.MCall)1 Using (ast.ExpCore.Using)1 WalkBy (ast.ExpCore.WalkBy)1 ArrayList (java.util.ArrayList)1