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;
}
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;
}
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());
}
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;
}
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);
}
Aggregations