use of ast.Ast.MethodType 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.Ast.MethodType 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.MethodType 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.MethodType in project L42 by ElvisResearchGroup.
the class SumMethods method sumMethods.
public static ClassB sumMethods(ClassB lib, List<Ast.C> path, MethodSelector m1, MethodSelector m2, MethodSelector mRes, String name) {
ClassB pathCb = pathCb(lib, path);
Member mem1 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m1));
Member mem2 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m2));
MethodType mt1 = ((MethodWithType) pathCb._getMember(m1)).getMt();
MethodType mt2 = ((MethodWithType) pathCb._getMember(m2)).getMt();
int index = m2.getNames().indexOf(name);
if (index == -1) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, false, false, false);
}
checkParSize(index, path, m1, m2, mRes, mem1, mem2, mt1, mt2);
MethodType mtU = mtU(index, mt1, mt2);
if (mtU == null) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, isReplacedParOk(index, mt1, mt2), false, true);
}
ExpCore eU = eU(index, mem2.getP(), mt1, mt2, m1, m2, mRes);
MethodWithType mwtU = new MethodWithType(Doc.empty(), mRes, mtU, Optional.of(eU), mem2.getP());
checkConflict(path, mRes, pathCb, mwtU);
boolean replOk = isReplacedParOk(index, mt1, mt2);
if (!replOk) {
throw Errors42.errorParameterMismatch(path, mem1, mem2, false, true, true);
}
return finalResult(lib, path, mwtU);
}
use of ast.Ast.MethodType in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method hasPluginUnresponsive.
public static boolean hasPluginUnresponsive(ClassB l) {
//class method T #pluginUnresponsive(Library binaryRepr)
MethodSelector ms = MethodSelector.of("#pluginUnresponsive", 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().getMdf().equals(Mdf.Immutable)) {
return false;
}
//no need to check return type, since is just thrown as error
return true;
}
Aggregations