use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class Desugar method withExpectedType.
private <T0, T> T withExpectedType(Type t, Supplier<T> f) {
if (t == null) {
t = Path.Any().toImmNT();
}
Type aux = this.t;
this.t = t;
T result = f.get();
this.t = aux;
return result;
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class DesugarCatchDefault method liftBC.
protected BlockContent liftBC(BlockContent c) {
if (c.get_catch().isEmpty()) {
return super.liftBC(c);
}
List<Catch> ks = Map.of(this::liftK, c.get_catch());
Type oldR = this.lastReturn;
this.lastReturn = newR(ks);
try {
List<VarDec> liftVarDecs = liftVarDecs(c.getDecs());
return new BlockContent(liftVarDecs, ks);
} finally {
this.lastReturn = oldR;
}
}
use of ast.Ast.Type 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.Type in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public Expression visit(RoundBlock s) {
s = blockEtoXE(s);
//s=blockInferVar(s);
HashMap<String, Type> oldVarEnv = new HashMap<String, Type>(varEnv);
try {
if (!s.getContents().isEmpty()) {
addAllDec(s.getContents().get(0).getDecs());
}
Expression result = super.visit(s);
return result;
} finally {
varEnv = oldVarEnv;
}
}
use of ast.Ast.Type in project L42 by ElvisResearchGroup.
the class Desugar method visit.
public NestedClass visit(NestedClass nc) {
while (nc.getInner() instanceof Expression.DocE) {
nc = nc.withInner(((Expression.DocE) nc.getInner()).getInner());
}
//TODO: document stripping of comments and decide scope
NestedClass nc1 = nc;
this.usedVars = new HashSet<String>();
this.varEnv = new HashMap<String, Type>();
usedVars.addAll(CollectDeclaredVars.of(nc.getInner()));
return withExpectedType(Type.immLibrary, () -> super.visit(nc1));
}
Aggregations