use of ast.Expression.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class Desugar method cfLentK.
public static MethodWithType cfLentK(MethodWithType mutK) {
mutK = mutK.withMs(mutK.getMs().withName("#lentK"));
Type resT = new ast.Ast.Type(Mdf.Lent, ast.Ast.Path.outer(0), Doc.empty());
MethodType mt = mutK.getMt();
mt = mt.withReturnType(resT).withTs(mt.getTs().stream().map(t -> (Type) t).map(nt -> nt.withMdf(nt.getMdf() == Mdf.Mutable ? Mdf.Lent : nt.getMdf())).collect(Collectors.toList()));
mutK = mutK.withMt(mt);
return mutK;
}
use of ast.Expression.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class Desugar method generateGetter.
private static MethodWithType generateGetter(Expression.Position pos, FieldDec f, Doc doc) {
Type fieldNt = (Type) f.getT();
fieldNt = TypeManipulation.noFwd(fieldNt);
Mdf mdf = fieldNt.getMdf();
if (mdf == Mdf.Capsule || mdf == Mdf.Mutable || mdf == Mdf.Lent) {
fieldNt = fieldNt.withMdf(Mdf.Readable);
}
MethodType mti = new MethodType(false, Mdf.Readable, Collections.emptyList(), fieldNt, Collections.emptyList());
String name = f.getName();
//if(name.startsWith("#")){name=name.substring(1);}
MethodSelector msi = MethodSelector.of(name, Collections.emptyList());
MethodWithType mwt = new MethodWithType(doc, msi, mti, Optional.empty(), pos);
return mwt;
}
use of ast.Expression.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class Desugar method mdfForNamedK.
/*static public MethodWithType cfMutK(Doc doc,ast.Ast.ConcreteHeader h) {
return cfMutK(doc,h.getFs(),h.getP());
}*/
/*static public MethodWithType cfMutK(Doc doc,List<FieldDec>fields,Position pos) {
List<String> names= new ArrayList<String>();
List<NormType> ts=new ArrayList<NormType>();
for(FieldDec fi:fields){
NormType ti=fi.getT().match(nt->{
if(nt.getMdf()==Mdf.Capsule){nt=nt.withMdf(Mdf.Mutable);}
return nt;
},ht->ht);
ti=ti.withDoc(ti.getDoc().sum(fi.getDoc()));
ts.add(ti);
names.add(fi.getName());
}
MethodSelector ms=MethodSelector.of("#mutK",names);
NormType resT=new ast.Ast.NormType(Mdf.Mutable,ast.Ast.Path.outer(0),Doc.empty());
MethodType mt=new MethodType(false,ast.Ast.Mdf.Class,ts,resT,Collections.emptyList());
return new MethodWithType(doc, ms,mt, Optional.empty(),pos);
}*/
private static Mdf mdfForNamedK(ast.Ast.ConcreteHeader h) {
boolean canImm = true;
for (FieldDec f : h.getFs()) {
//TODO: will disappear?
if (!(f.getT() instanceof Type)) {
return Mdf.Mutable;
}
Type nt = (Type) f.getT();
Mdf m = nt.getMdf();
if (m == Mdf.Lent || m == Mdf.Readable) {
return Mdf.Lent;
}
if (m != Mdf.Immutable && m != Mdf.Class && m != Mdf.ImmutableFwd) {
canImm = false;
}
if (f.isVar()) {
canImm = false;
}
}
if (canImm) {
return Mdf.Immutable;
}
return Mdf.Mutable;
}
use of ast.Expression.ClassB.MethodWithType 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.Expression.ClassB.MethodWithType 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;
}
Aggregations