Search in sources :

Example 16 with MethodSelector

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

the class Desugar method generateExposer.

//left cfExposer generating exposer since is different from generateExposer code for # and capsule
/*static private void cfExposer(Expression.Position pos,FieldDec f,Doc doc, List<Member> result) {
    NormType tt=f.getT().match(nt->Functions.toComplete(nt), hType->hType);
    MethodType mti=new MethodType(false,Mdf.Mutable,Collections.emptyList(),tt,Collections.emptyList());
    MethodSelector msi=MethodSelector.of("#"+f.getName(),Collections.emptyList());
    result.add(new MethodWithType(doc, msi, mti, Optional.empty(),pos));
  }*/
private static MethodWithType generateExposer(Expression.Position pos, FieldDec f, Doc doc) {
    Type tt = TypeManipulation.noFwd(f.getT());
    if (tt.getMdf() == Mdf.Capsule) {
        tt = tt.withMdf(Mdf.Lent);
    }
    MethodType mti = new MethodType(false, Mdf.Mutable, Collections.emptyList(), tt, Collections.emptyList());
    MethodSelector msi = MethodSelector.of("#" + f.getName(), Collections.emptyList());
    MethodWithType mwt = new MethodWithType(doc, msi, mti, Optional.empty(), pos);
    return mwt;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.Expression.ClassB.MethodWithType)

Example 17 with MethodSelector

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

the class Desugar method generateSetter.

private static MethodWithType generateSetter(Expression.Position pos, ast.Ast.FieldDec f, Doc doc) {
    Type tt = TypeManipulation.noFwd(f.getT());
    MethodType mti = new MethodType(false, Mdf.Mutable, Collections.singletonList(tt), Type.immVoid, Collections.emptyList());
    MethodSelector msi = MethodSelector.of(f.getName(), Collections.singletonList("that"));
    MethodWithType mwt = new MethodWithType(doc, msi, mti, Optional.empty(), pos);
    return mwt;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.Expression.ClassB.MethodWithType)

Example 18 with MethodSelector

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

the class Desugar method cfNameK.

//private static final Doc consistentDoc=Doc.factory("@consistent\n");
/* public static List<Member> cfType(ConcreteHeader h,Doc doc){
    //doc=Doc.factory("@private");
    List<Member> result=new  ArrayList<Member>();
    MethodWithType k = cfMutK(doc,h);
    Mdf nameMdf=mdfForNamedK(h);
    if(nameMdf==Mdf.Lent){k=cfLentK(k);}
    MethodWithType kOut =cfNameK(doc, nameMdf, h, k.getMs());
    result.add(k);
    result.add(kOut);
    //cfType1(h,doc, result);
    for(FieldDec f:h.getFs()){
      Doc fDoc=doc.sum(f.getDoc());
      cfSetter(h.getP(),f,fDoc,result);
      cfExposer(h.getP(),f,fDoc,result);
      cfGetter(h.getP(),f,fDoc,result);
    }
    return result;
  }
*/
private static MethodWithType cfNameK(Doc doc, Mdf mdf, ast.Ast.ConcreteHeader h, MethodSelector called) {
    List<Type> ts = new ArrayList<Type>();
    for (FieldDec fi : h.getFs()) {
        Type ti = fi.getT();
        ts.add(ti.withDoc(ti.getDoc().sum(fi.getDoc())));
    }
    MethodSelector ms = called.withName(h.getName());
    Type resT = new ast.Ast.Type(mdf, ast.Ast.Path.outer(0), Doc.empty());
    MethodType mt = new MethodType(false, ast.Ast.Mdf.Class, ts, resT, Collections.emptyList());
    Parameters ps = new Parameters(Optional.empty(), called.getNames(), called.getNames().stream().map(n -> new X(Position.noInfo, n)).collect(Collectors.toList()));
    MCall body = new MCall(new Expression.EPath(h.getP(), Path.outer(0)), called.nameToS(), Doc.empty(), ps, h.getP());
    return new MethodWithType(doc, ms, mt, Optional.of(body), h.getP());
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Parameters(ast.Ast.Parameters) ArrayList(java.util.ArrayList) MethodWithType(ast.Expression.ClassB.MethodWithType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) FieldDec(ast.Ast.FieldDec) Expression(ast.Expression) MCall(ast.Expression.MCall) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX)

Example 19 with MethodSelector

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

the class Methods method methods.

//  -methods(p,P0)=M1'..Mk'
//          p(P0)={interface? implements Ps Ms} 
public List<MethodWithType> methods(Ast.Path p0) {
    if (p0.isPrimitive()) {
        return Collections.emptyList();
    }
    Program p = this;
    ClassB cb0 = p.extractClassB(p0);
    List<Ast.Path> ps = cb0.getSuperPaths();
    //          P1..Pn=collect(p,Ps[from P0]), error unless forall i, p(Pi) is an interface
    List<Ast.Path> p1n = collect(p, Map.of(pi -> From.fromP(pi, p0), ps));
    List<ClassB> cb1n = Map.of(pi -> p.extractClassB(pi), p1n);
    {
        int i = -1;
        for (ClassB cbi : cb1n) {
            i++;
            if (!cbi.isInterface()) {
                throw new ast.ErrorMessage.NonInterfaceImplements(p0, p1n.get(i));
            }
        }
    }
    //          ms1..msk={ms|p(Pi)(ms) is defined}
    HashMap<Ast.MethodSelector, List<ClassB.Member>> ms1k = new LinkedHashMap<>();
    for (ClassB.Member mij : cb0.getMs()) {
        mij.match(nc -> null, mi -> add(true, ms1k, mi.getS(), From.from(mij, p0)), mt -> add(true, ms1k, mt.getMs(), From.from(mij, p0)));
    }
    for (Ast.Path pi : p1n) {
        //call the memoized methods
        for (ClassB.Member mij : p.methods(pi)) {
            mij.match(nc -> null, mi -> add(false, ms1k, mi.getS(), mij), mt -> add(false, ms1k, mt.getMs(), mij));
        }
    }
    //            such that p(Pj)(ms)=mh e? //no refine
    for (Entry<MethodSelector, List<Member>> ei : ms1k.entrySet()) {
        if (!exactly1NoRefine(ei.getValue())) {
            throw new ast.ErrorMessage.NotExaclyOneMethodOrigin(p0, ei.getKey(), ei.getValue());
        }
    }
    List<ClassB.MethodWithType> ms = new ArrayList<>();
    //            for the smallest j in 1..k such that methods(p,Pj)(msi) of form refine? mh
    for (Entry<MethodSelector, List<Member>> ei : ms1k.entrySet()) {
        List<Member> memsi = ei.getValue();
        if (memsi.get(0) != null && memsi.get(0) instanceof MethodWithType) {
            ms.add((MethodWithType) memsi.get(0));
            continue;
        }
        ClassB.MethodImplemented mem0 = (ClassB.MethodImplemented) memsi.get(0);
        for (Member mj : memsi) {
            // 0 will fail instanceof
            if (mj == null || !(mj instanceof MethodWithType)) {
                continue;
            }
            //    Mi'=Mi
            if (mem0 != null) {
                mj = mj.withInner(mem0.getE());
            }
            ms.add(addRefine((MethodWithType) mj));
            break;
        }
    }
    return ms;
}
Also used : From(coreVisitors.From) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Set(java.util.Set) HashMap(java.util.HashMap) Member(ast.ExpCore.ClassB.Member) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Collectors(java.util.stream.Collectors) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ClassB(ast.ExpCore.ClassB) Entry(java.util.Map.Entry) Collections(java.util.Collections) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB) Path(ast.Ast.Path) Ast(ast.Ast) Path(ast.Ast.Path) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 20 with MethodSelector

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

the class OnLineCodeHelper method pluginType.

//Unuseful variant, since program not availabe at desugaring time
public static List<Type> pluginType(Program p, Expression.Using u) {
    MethodSelector ms = MethodSelector.of(u.getName(), u.getPs().getXs());
    ExpCore.Using uCore = new ExpCore.Using(u.getPath(), ms, Doc.empty(), Collections.emptyList(), new ExpCore._void());
    return plugin(p, uCore).typeOf(p, uCore);
}
Also used : ExpCore(ast.ExpCore) MethodSelector(ast.Ast.MethodSelector) Using(ast.ExpCore.Using) Using(ast.ExpCore.Using)

Aggregations

MethodSelector (ast.Ast.MethodSelector)31 ClassB (ast.ExpCore.ClassB)17 MethodType (ast.Ast.MethodType)11 ArrayList (java.util.ArrayList)11 Path (ast.Ast.Path)9 MethodWithType (ast.ExpCore.ClassB.MethodWithType)9 Type (ast.Ast.Type)8 EncodingHelper.ensureExtractClassB (auxiliaryGrammar.EncodingHelper.ensureExtractClassB)8 ActionType (platformSpecific.fakeInternet.ActionType)8 Ast (ast.Ast)6 Doc (ast.Ast.Doc)6 ExpCore (ast.ExpCore)6 List (java.util.List)6 Member (ast.ExpCore.ClassB.Member)5 MethodWithType (ast.Expression.ClassB.MethodWithType)5 Collections (java.util.Collections)5 Optional (java.util.Optional)5 Program (programReduction.Program)5 C (ast.Ast.C)4 Mdf (ast.Ast.Mdf)4