Search in sources :

Example 36 with MethodType

use of ast.Ast.MethodType in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method hasBinaryRepr.

public static boolean hasBinaryRepr(ClassB l) {
    //read method Library #binaryRepr()
    MethodSelector ms = MethodSelector.of("#binaryRepr", Collections.emptyList());
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Readable)) {
        return false;
    }
    if (!mt.getTs().isEmpty()) {
        return false;
    }
    if (!mt.getExceptions().isEmpty()) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.immLibrary)) {
        return false;
    }
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 37 with MethodType

use of ast.Ast.MethodType in project L42 by ElvisResearchGroup.

the class PlgWrapperGenerator method hasExceptionIf.

public static boolean hasExceptionIf(ClassB l) {
    //class method Void #exceptionIf(Library binaryRepr) exception This
    MethodSelector ms = MethodSelector.of("#exceptionIf", Collections.singletonList("binaryRepr"));
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Class)) {
        return false;
    }
    if (!mt.getTs().get(0).equals(Type.immLibrary)) {
        return false;
    }
    if (mt.getExceptions().size() != 1) {
        return false;
    }
    if (!mt.getExceptions().get(0).equals(Path.outer(0))) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.immVoid)) {
        return false;
    }
    //no need to check return type, since is just thrown as error
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 38 with MethodType

use of ast.Ast.MethodType 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 39 with MethodType

use of ast.Ast.MethodType in project L42 by ElvisResearchGroup.

the class Test212_or_170_MethodTypes method couldSum.

@Test
public void couldSum() {
    List<Map<MethodType, String>> maps = new ArrayList<>();
    for (MethodType mt : dataSet) {
        maps.add(fixMap(mt));
    }
    int ok = 0;
    int fail = 0;
    int okExt = 0;
    int okFwd = 0;
    for (int i = 0; i < dataSet.size(); i++) {
        for (int j = 0; j < dataSet.size(); j++) {
            if (i == j) {
                continue;
            }
            int r = couldSum(i, j, maps);
            if (r == -1) {
                fail += 1;
            } else if (r == i || r == j) {
                ok += 1;
            } else {
                okExt += 1;
                String rs = mapToS(maps.get(r));
                if (rs.contains("Fwd,") || rs.contains("Fwd->")) {
                    okFwd += 1;
                } else {
                    System.out.println("RES");
                    System.out.println(mapToS(maps.get(r)));
                    System.out.println("m1");
                    System.out.println(mapToS(maps.get(i)));
                    System.out.println("m2");
                    System.out.println(mapToS(maps.get(j)));
                }
            }
        }
    }
    System.out.println("ok " + ok);
    System.out.println("okExt " + okExt);
    System.out.println("okFwd " + okFwd);
    System.out.println("fail " + fail);
}
Also used : MethodType(ast.Ast.MethodType) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 40 with MethodType

use of ast.Ast.MethodType in project L42 by ElvisResearchGroup.

the class Test212_or_170_MethodTypes method fixMap.

Map<MethodType, String> fixMap(MethodType mt__) {
    MethodType base = mBase(mt__);
    Map<MethodType, String> map = new HashMap<>();
    map.put(base, "mBase");
    while (true) {
        int count = 0;
        for (MethodType t : map.keySet()) {
            if (tryEverything(t, map.get(t), map)) {
                count += 1;
                break;
            }
        }
        if (count == 0) {
            break;
        }
    }
    return map;
}
Also used : MethodType(ast.Ast.MethodType) HashMap(java.util.HashMap)

Aggregations

MethodType (ast.Ast.MethodType)48 Type (ast.Ast.Type)32 MethodWithType (ast.ExpCore.ClassB.MethodWithType)25 Mdf (ast.Ast.Mdf)14 MethodSelector (ast.Ast.MethodSelector)14 ArrayList (java.util.ArrayList)14 Path (ast.Ast.Path)10 ExpCore (ast.ExpCore)9 List (java.util.List)9 Collections (java.util.Collections)8 Functions (auxiliaryGrammar.Functions)7 Test (org.junit.Test)7 Doc (ast.Ast.Doc)6 MethodWithType (ast.Expression.ClassB.MethodWithType)6 HashMap (java.util.HashMap)6 Program (programReduction.Program)6 Ast (ast.Ast)5 ClassB (ast.ExpCore.ClassB)5 Member (ast.ExpCore.ClassB.Member)5 Optional (java.util.Optional)5