use of ast.Ast.Type 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.Ast.Type in project L42 by ElvisResearchGroup.
the class SumMethods method isReplacedParOk.
static boolean isReplacedParOk(int index, MethodType mt1, MethodType mt2) {
if (mt2.getTs().isEmpty()) {
return false;
}
Type p1 = mt2.getTs().get(index);
Type r = mt1.getReturnType();
return p1.equals(r);
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class TranslateExpression method getCatch.
private void getCatch(String kVar, On on, String asReturn, String kLab) {
Path p = ((Type) on.getT()).getPath();
String tn = Resources.nameOf(p);
if (p.equals(Path.Library())) {
res.append(getCatchHeaderForLibrary(kVar));
} else if (!p.isPrimitive() && tn.equals("Object")) {
res.append(getCatchHeaderForPathNotStar(kVar, p));
} else {
res.append("if(" + kVar + ".unbox instanceof " + tn + "){\n");
}
res.append(" " + tn + "[] P" + on.getX() + "={(" + tn + ")" + kVar + ".unbox};\n");
res.append(asReturn);
on.getInner().accept(this);
res.append(";");
if (asReturn.contains("=")) {
res.append("break " + kLab + ";");
}
res.append("\n }\nelse ");
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class InjectionOnSugar method visit.
@Override
public Expression visit(ClassB s) {
Doc doc1 = s.getDoc1();
Header h = (s.isInterface()) ? new Ast.InterfaceHeader() : new Ast.TraitHeader();
List<Type> supertypes = s.getSupertypes();
List<Member> members = new ArrayList<>();
for (ast.ExpCore.ClassB.Member mi : s.getMs()) {
members.add(mi.match(nc -> new Expression.ClassB.NestedClass(nc.getDoc(), nc.getName(), lift(nc.getInner()), nc.getP()), mimpl -> new Expression.ClassB.MethodImplemented(mimpl.getDoc(), mimpl.getS(), lift(mimpl.getInner()), mimpl.getP()), mwt -> {
Doc idoc = mwt.getDoc();
MethodSelector is = mwt.getMs();
MethodType mt = mwt.getMt();
return new Expression.ClassB.MethodWithType(idoc, is, mt, lift(mwt.get_inner()), mwt.getP());
}));
}
return new Expression.ClassB(doc1, h, Collections.emptyList(), supertypes, members, s.getP());
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class AlternativeMethodTypes method _mC.
static MethodType _mC(MethodType mt) {
//Ts->mut P0;Ps in methTypes(p,P,ms)
//(mC)-------------------------------------------------------------------
//mutToCapsule(Ts)->capsule P0;Ps in methTypes(p,P,ms)
Type retT = mt.getReturnType();
if (retT.getMdf() != Mdf.Mutable) {
return null;
}
retT = retT.withMdf(Mdf.Capsule);
List<Type> ts = Map.of(t -> mutToCapsule(t), mt.getTs());
return mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsule(mt.getMdf()));
}
Aggregations