use of ast.Ast.FieldDec in project L42 by ElvisResearchGroup.
the class WellFormedness method checkHeader.
static void checkHeader(ClassB cb, ConcreteHeader h) {
//All fields names in a given header must be unique.
HashSet<String> fnames = new HashSet<String>();
for (FieldDec f : h.getFs()) {
fnames.add(f.getName());
if (f.getName().equals("this")) {
throw new ErrorMessage.NotWellFormedMsk(cb, null, "\"this\" is not a valid field name");
}
}
if (fnames.size() != h.getFs().size()) {
throw new ErrorMessage.NotWellFormedMsk(cb, null, "Some field name is repeated.");
}
if (h.getMdf() == Mdf.Class) {
throw new ErrorMessage.NotWellFormedMsk(cb, null, "Constructors can not return types");
}
boolean haveVar = false;
for (FieldDec f : h.getFs()) {
if (f.isVar()) {
haveVar = true;
break;
}
}
if (haveVar && h.getMdf() == Mdf.Readable) {
//was Immutable, but now the idea is that the mdf can be inferred
throw new ErrorMessage.NotWellFormedMsk(cb, null, "Readable classes can not have a variable fields");
}
}
use of ast.Ast.FieldDec in project L42 by ElvisResearchGroup.
the class CloneVisitor method visit.
public Expression visit(ClassB s) {
Header h = liftH(s.getH());
List<FieldDec> fs = Map.of(this::liftF, s.getFields());
List<Type> superT = Map.of(this::liftT, s.getSupertypes());
List<Member> ms = Map.of(this::liftM, s.getMs());
return new ClassB(liftDoc(s.getDoc1()), h, fs, superT, ms, s.getP());
}
use of ast.Ast.FieldDec 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.FieldDec 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.FieldDec in project L42 by ElvisResearchGroup.
the class DesugarVars method getClassBForVar.
private VarDecCE getClassBForVar(VarDecXE varDec) {
List<FieldDec> fs = new ArrayList<FieldDec>();
fs.add(new FieldDec(true, _computeTypeForClassBForVar(varDec), "inner", Doc.empty()));
ClassB cb = new ClassB(Doc.empty(), new Ast.ConcreteHeader(Mdf.Mutable, "", fs, Position.noInfo), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Position.noInfo);
String nameC = Functions.freshName("Var" + varDec.getX(), L42.usedNames);
//usedCnames.add(nameC);
return new VarDecCE(new NestedClass(Doc.empty(), C.of(nameC).withUniqueNum(L42.freshPrivate()), cb, null));
}
Aggregations