use of ast.Ast.MethodType 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.MethodType 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.MethodType 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.MethodType in project L42 by ElvisResearchGroup.
the class _Sum method sumMethod.
static MethodWithType sumMethod(MethodWithType ma, MethodWithType mb) {
Set<Path> pa = new HashSet<Path>(Map.of(t -> t.getPath(), ma.getMt().getExceptions()));
Set<Path> pb = new HashSet<Path>(Map.of(t -> t.getPath(), mb.getMt().getExceptions()));
Set<Path> pc = new HashSet<>(pa);
pc.retainAll(pb);
Doc doc = ma.getDoc().sum(mb.getDoc());
MethodType mt = ma.getMt();
List<Ast.Type> opc = pc.stream().map(pi -> (Ast.Type) pi.toImmNT()).collect(Collectors.toList());
Collections.sort(opc, (p1, p2) -> p1.toString().compareTo(p2.toString()));
mt = mt.withExceptions(opc);
MethodWithType mwt = ma.withMt(mt).withDoc(doc);
//now mwt has min exceptions and summed docs
assert !ma.get_inner().isPresent() || !mb.get_inner().isPresent();
if (mb.get_inner().isPresent()) {
mwt = mwt.withInner(mb.getInner());
}
return mwt;
}
use of ast.Ast.MethodType in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method hasFrom.
public static boolean hasFrom(ClassB l) {
// class method mut This0 #from(Library binaryRepr)
MethodSelector ms = MethodSelector.of("#from", 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().isEmpty()) {
return false;
}
if (!mt.getReturnType().equals(Type.mutThis0)) {
return false;
}
return true;
}
Aggregations