Search in sources :

Example 16 with Type

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;
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType)

Example 17 with Type

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;
    }
}
Also used : Type(ast.Ast.Type) Catch(ast.Expression.Catch) VarDec(ast.Ast.VarDec) BlockContent(ast.Expression.BlockContent)

Example 18 with Type

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;
}
Also used : MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.Expression.ClassB.MethodWithType) Mdf(ast.Ast.Mdf)

Example 19 with Type

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;
    }
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) HashMap(java.util.HashMap) Expression(ast.Expression)

Example 20 with Type

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));
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) NestedClass(ast.Expression.ClassB.NestedClass) DocE(ast.Expression.DocE)

Aggregations

Type (ast.Ast.Type)81 MethodType (ast.Ast.MethodType)50 MethodWithType (ast.ExpCore.ClassB.MethodWithType)28 MethodWithType (ast.Expression.ClassB.MethodWithType)24 ArrayList (java.util.ArrayList)24 Mdf (ast.Ast.Mdf)16 Expression (ast.Expression)15 Path (ast.Ast.Path)13 Doc (ast.Ast.Doc)11 Ast (ast.Ast)10 MethodSelector (ast.Ast.MethodSelector)10 HashMap (java.util.HashMap)10 MethodSelectorX (ast.Ast.MethodSelectorX)8 VarDecXE (ast.Ast.VarDecXE)8 ExpCore (ast.ExpCore)8 Catch (ast.Expression.Catch)8 X (ast.Expression.X)8 VarDec (ast.Ast.VarDec)7 Block (ast.ExpCore.Block)7 List (java.util.List)7