Search in sources :

Example 21 with MethodWithType

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

the class TsLibrary method coherent.

static boolean coherent(Program p, boolean force) {
    ClassB top = p.top();
    if (top.isInterface()) {
        return true;
    }
    List<MethodWithType> stateC = top.mwts().stream().map(m -> (MethodWithType) m).filter(m -> !m.get_inner().isPresent()).sorted((m1, m2) -> m1.getMt().getMdf() == Mdf.Class ? -1 : 1).collect(Collectors.toList());
    if (stateC.isEmpty()) {
        return true;
    }
    MethodWithType ck = stateC.get(0);
    if (!coherentK(p, ck)) {
        if (force) {
            throw new ErrorMessage.NotOkToStar(top, ck, "invalid candidate factory", ck.getP());
        }
        return false;
    }
    for (MethodWithType mwt : stateC.subList(1, stateC.size())) {
        if (!coherentF(p, ck, mwt)) {
            if (force) {
                throw new ErrorMessage.NotOkToStar(top, ck, "abstract method\n" + sugarVisitors.ToFormattedText.of(mwt) + "\ndo not fit candidate factory", mwt.getP());
            }
            return false;
        }
    }
    return true;
}
Also used : From(coreVisitors.From) NestedClass(ast.ExpCore.ClassB.NestedClass) Program(programReduction.Program) Path(ast.Ast.Path) Type(ast.Ast.Type) ErrorMessage(ast.ErrorMessage) Phase(ast.ExpCore.ClassB.Phase) Assertions(tools.Assertions) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) ArrayList(java.util.ArrayList) List(java.util.List) ClassB(ast.ExpCore.ClassB) Optional(java.util.Optional) Norm(programReduction.Norm) Mdf(ast.Ast.Mdf) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB)

Example 22 with MethodWithType

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

the class GuessTypeCore method visit.

@Override
public Type visit(MCall s) {
    Type former = s.getInner().accept(this);
    if (former == null) {
        return null;
    }
    Path path = former.getPath();
    assert path != null;
    List<MethodSelectorX> msl = new ArrayList<>();
    MethodSelectorX msx = new MethodSelectorX(s.getS(), "");
    msl.add(msx);
    MethodWithType meth = (MethodWithType) p.extractClassB(path)._getMember(s.getS());
    if (meth == null) {
        return null;
    }
    return (Type) From.fromT(meth.getMt().getReturnType(), path);
}
Also used : Path(ast.Ast.Path) Type(ast.Ast.Type) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodSelectorX(ast.Ast.MethodSelectorX) ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 23 with MethodWithType

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

the class TIn method freshGFromMt.

public TIn freshGFromMt(MethodWithType mwt) {
    MethodType mt = mwt.getMt();
    assert mwt.get_inner().isPresent();
    Map<String, Map.Entry<Boolean, Type>> newG = new HashMap<>(g);
    newG.put("this", p(false, new Type(mt.getMdf(), Path.outer(0), Doc.empty())));
    {
        int i = -1;
        for (String x : mwt.getMs().getNames()) {
            i += 1;
            Type ntx = mt.getTs().get(i);
            newG.put(x, p(false, ntx));
        }
    }
    return new TIn(Phase.Typed, this.p, mwt.getInner(), TypeManipulation.fwdP(mt.getReturnType()), newG);
}
Also used : MethodType(ast.Ast.MethodType) Entry(java.util.Map.Entry) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashMap(java.util.HashMap)

Example 24 with MethodWithType

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

the class AlternativeMethodTypes method _mtDeclared.

static MethodType _mtDeclared(Program p, Path P, MethodSelector ms) {
    MethodWithType mwt = (MethodWithType) p.extractClassB(P)._getMember(ms);
    if (mwt == null) {
        return null;
    }
    MethodType mt = From.from(mwt.getMt(), P);
    return mt;
}
Also used : MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 25 with MethodWithType

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

the class AlternativeMethodTypes method mBase.

static MethodType mBase(Program p, Path P, MethodSelector ms) {
    //p(P)(ms).mh[from P]=refine? mdf0 method T m(T1 x1,..Tn xn) exception Ps
    //T'=fwd% T if fwd_or_fwd%_in(Ts)
    //otherwise T'=T       
    //(mBase)-------------------------------------------------------------------
    //mdf0 P T1..Tn-> T';Ps in methTypes(p,P,ms)    MethodWithType mwt = (MethodWithType) p.extractClassB(P)._getMember(ms);
    MethodWithType mwt = (MethodWithType) p.extractClassB(P)._getMember(ms);
    assert mwt != null;
    MethodType mt = From.from(mwt.getMt(), P);
    return mBase(mt);
}
Also used : MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Aggregations

MethodWithType (ast.ExpCore.ClassB.MethodWithType)46 Member (ast.ExpCore.ClassB.Member)21 MethodType (ast.Ast.MethodType)18 ArrayList (java.util.ArrayList)16 Type (ast.Ast.Type)13 Path (ast.Ast.Path)10 ClassB (ast.ExpCore.ClassB)10 NestedClass (ast.ExpCore.ClassB.NestedClass)9 ExpCore (ast.ExpCore)8 MethodSelector (ast.Ast.MethodSelector)7 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)7 Ast (ast.Ast)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Program (programReduction.Program)4 Mdf (ast.Ast.Mdf)3 Functions (auxiliaryGrammar.Functions)3 From (coreVisitors.From)3 Collections (java.util.Collections)3