use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class AlternativeMethodTypes method _mRead.
static MethodType _mRead(MethodType mt) {
//mutToCapsuleAndFwdToRead(Ts)->read P0;Ps in methTypes(p,P,ms)
if (!TypeManipulation.fwd_or_fwdP_in(mt.getTs())) {
return null;
}
Type retT = mt.getReturnType();
if (retT.getMdf() != Mdf.MutablePFwd) {
return null;
}
retT = retT.withMdf(Mdf.Readable);
List<Type> ts = Map.of(t -> mutToCapsuleAndFwdToRead(t), mt.getTs());
MethodType res = mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsuleAndFwdToRead(mt.getMdf()));
if (WellFormednessCore.methodTypeWellFormed(res)) {
return res;
}
return null;
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class InjectionOnSugar method visit.
@Override
public Expression visit(Block s) {
Doc docs = s.getDoc();
Expression inner = lift(s.getInner());
List<VarDec> decs = new ArrayList<VarDec>();
for (int i = 0; i < s.getDecs().size(); i++) {
Optional<Type> t = s.getDecs().get(i).getT();
String x = s.getDecs().get(i).getX();
Expression e = lift(s.getDecs().get(i).getInner());
decs.add(new VarDecXE(s.getDecs().get(i).isVar(), t, x, e));
}
List<Expression.Catch> _catch = injectionCatch(s.getOns());
List<Expression.BlockContent> contents = new ArrayList<>();
if (!decs.isEmpty() || !_catch.isEmpty()) {
contents.add(new Expression.BlockContent(decs, _catch));
}
Expression.Position pos = s.getP();
Expression.RoundBlock result = new Expression.RoundBlock(pos, docs, inner, contents);
//assert WellFormedness.blockCheck(result);, no it can actually get wrong?
return result;
}
use of ast.Ast.Type 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.Type in project L42 by ElvisResearchGroup.
the class Desugar method liftKs.
protected List<Catch> liftKs(List<Catch> ks) {
List<Catch> result = new ArrayList<>();
String x = Functions.freshName("catched", usedVars);
for (Catch k : ks) {
if (k instanceof DesugarCatchDefault.CatchToComplete) {
Catch k2 = this.liftK(((DesugarCatchDefault.CatchToComplete) k).catch1);
result.add(new DesugarCatchDefault.CatchToComplete((Catch1) k2));
continue;
}
k.match(k1 -> result.add(liftK(k1)), kM -> {
for (Type t : kM.getTs()) {
result.add(liftK(new Expression.Catch1(kM.getP(), kM.getKind(), t, x, kM.getInner())));
}
return false;
}, kP -> {
for (Type t : kP.getTs()) {
Expression inner = kP.getInner();
inner = new Expression.FCall(kP.getP(), inner, Doc.empty(), new ast.Ast.Parameters(Optional.of(new X(kP.getP(), x)), Collections.emptyList(), Collections.emptyList()));
inner = new Expression.Signal(kP.getKind(), inner);
result.add(liftK(new Expression.Catch1(kP.getP(), SignalKind.Exception, t, x, inner)));
}
return false;
});
}
return result;
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public Expression visit(Using s) {
Type aux = this.t;
this.t = Type.immVoid;
Parameters ps = liftPs(s.getPs());
this.t = aux;
return new Using(liftP(s.getPath()), s.getName(), s.getDocs(), ps, lift(s.getInner()));
}
Aggregations