Search in sources :

Example 66 with Type

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

the class Desugar method cfGetter.

private static void cfGetter(Expression.Position pos, FieldDec f, Doc doc, List<Member> result) {
    if (!(f.getT() instanceof Type)) {
        return;
    }
    MethodWithType mwt = generateGetter(pos, f, doc);
    result.add(mwt);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodWithType(ast.Expression.ClassB.MethodWithType)

Example 67 with Type

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

the class Desugar method visit.

public MethodWithType visit(MethodWithType mt) {
    this.usedVars = new HashSet<String>();
    this.varEnv = new HashMap<String, Type>();
    String mName = desugarName(mt.getMs().nameToS());
    mt = mt.withMs(mt.getMs().withName(mName));
    if (!mt.getInner().isPresent()) {
        return super.visit(mt);
    }
    {
        int i = -1;
        for (String name : mt.getMs().getNames()) {
            i += 1;
            this.usedVars.add(name);
            this.varEnv.put(name, mt.getMt().getTs().get(i));
        }
    }
    usedVars.add("this");
    varEnv.put("this", new Type(mt.getMt().getMdf(), Path.outer(0), mt.getDoc()));
    usedVars.addAll(CollectDeclaredVars.of(mt.getInner().get()));
    //final restrictions
    final MethodWithType mt2 = mt;
    return withExpectedType(liftT(mt.getMt().getReturnType()), () -> super.visit(mt2));
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodWithType(ast.Expression.ClassB.MethodWithType)

Example 68 with Type

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

the class PlgWrapperGenerator method addMwt.

private static void addMwt(Program p, PlgInfo plgInfo, Method[] jms, Constructor<?>[] jcs, List<Member> msResult, Path pTop, MethodWithType mwt) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
    //checks
    try {
        isOkAsReturn(p, pTop, mwt.getMt().getReturnType());
        for (Type ti : mwt.getMt().getExceptions()) {
            isOkAsException(p, pTop, ti.getPath());
        }
        for (Type ti : mwt.getMt().getTs()) {
            isOkAsParameter(p, pTop, ti);
        }
    //TODO: we may want to cache those tests if performance is needed
    } catch (ClassUnfit | MethodUnfit e) {
        e.setMessage("While examining Class " + pTop + " method " + mwt.getMs() + ":\n" + e.getMessage());
        throw e;
    }
    //add to msResult
    //TODO: add behaviour if mwt have special comment to define specific ms for use
    String name = mwt.getMs().nameToS();
    if (name.startsWith("#")) {
        name = name.substring(1);
    }
    UsingInfo ui;
    if (!name.equals("new") && !name.equals("apply"))
        ui = usingMethod(plgInfo, jms, mwt, name);
    else
        ui = usingConstructor(plgInfo, jcs, mwt, name);
    MethodWithType tu = updateTemplateUsing(ui, mwt);
    msResult.add(tu);
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) UsingInfo(platformSpecific.fakeInternet.PluginWithPart.UsingInfo) ClassUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.ClassUnfit) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodUnfit(is.L42.connected.withSafeOperators.pluginWrapper.RefactorErrors.MethodUnfit)

Example 69 with Type

use of ast.Ast.Type 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 70 with Type

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

the class Compose method alradyRefreshedCompose.

public static ClassB alradyRefreshedCompose(PData p, ClassB a, ClassB b) {
    if (a.isInterface() || b.isInterface()) {
        assert false;
    }
    List<Type> impls = new ArrayList<>(a.getSupertypes());
    for (Type ti : b.getSupertypes()) {
        impls.remove(ti);
    }
    impls.addAll(b.getSupertypes());
    List<MethodWithType> mwts = new ArrayList<>(a.mwts());
    for (MethodWithType mwti : b.mwts()) {
        Functions._findAndRemove(mwts, mwti.getMs());
    }
    for (MethodWithType mwti : b.mwts()) {
        mwts.add(sumMwt(_extractMwt(mwti, a.mwts()), mwti));
    }
    List<NestedClass> ncs = new ArrayList<>(a.ns());
    for (NestedClass nci : b.ns()) {
        Functions._findAndRemove(ncs, nci.getName());
    }
    for (NestedClass nci : b.ns()) {
        NestedClass ncj = _extractNc(nci, a.ns());
        if (ncj == null) {
            ncs.add(nci);
        } else {
            ClassB l = alradyRefreshedCompose(p, (ClassB) nci.getE(), (ClassB) ncj.getE());
            ncs.add(nci.withE(l));
        }
    }
    return new ClassB(a.getDoc1().sum(b.getDoc1()), false, impls, mwts, ncs, a.getP().sum(b.getP()), Phase.Norm, p.p.getFreshId());
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Aggregations

Type (ast.Ast.Type)81 MethodType (ast.Ast.MethodType)50 MethodWithType (ast.ExpCore.ClassB.MethodWithType)28 MethodWithType (ast.Expression.ClassB.MethodWithType)24 ArrayList (java.util.ArrayList)24 Mdf (ast.Ast.Mdf)16 Expression (ast.Expression)15 Path (ast.Ast.Path)13 Doc (ast.Ast.Doc)11 Ast (ast.Ast)10 MethodSelector (ast.Ast.MethodSelector)10 HashMap (java.util.HashMap)10 MethodSelectorX (ast.Ast.MethodSelectorX)8 VarDecXE (ast.Ast.VarDecXE)8 ExpCore (ast.ExpCore)8 Catch (ast.Expression.Catch)8 X (ast.Expression.X)8 VarDec (ast.Ast.VarDec)7 Block (ast.ExpCore.Block)7 List (java.util.List)7