Search in sources :

Example 56 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class Desugar method blockInferVar.

private RoundBlock blockInferVar(RoundBlock s) {
    if (s.getContents().isEmpty()) {
        return s;
    }
    HashMap<String, Type> localVarEnv = new HashMap<String, Type>(this.varEnv);
    List<VarDec> newDecs = new ArrayList<VarDec>();
    for (VarDec _dec : s.getContents().get(0).getDecs()) {
        if (!(_dec instanceof VarDecXE)) {
            newDecs.add(_dec);
            continue;
        }
        VarDecXE dec = (VarDecXE) _dec;
        if (dec.getT().isPresent()) {
            Type ti = dec.getT().get();
            localVarEnv.put(dec.getX(), ti);
            newDecs.add(dec);
            continue;
        }
        localVarEnv.put(dec.getX(), null);
        newDecs.add(dec.withT(Optional.ofNullable(t)));
    }
    return blockWithDec(s, newDecs);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) HashMap(java.util.HashMap) VarDec(ast.Ast.VarDec) ArrayList(java.util.ArrayList) VarDecXE(ast.Ast.VarDecXE)

Example 57 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class Desugar method generateSetter.

private static MethodWithType generateSetter(Expression.Position pos, ast.Ast.FieldDec f, Doc doc) {
    Type tt = TypeManipulation.noFwd(f.getT());
    MethodType mti = new MethodType(false, Mdf.Mutable, Collections.singletonList(tt), Type.immVoid, Collections.emptyList());
    MethodSelector msi = MethodSelector.of(f.getName(), Collections.singletonList("that"));
    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)

Example 58 with Type

use of ast.Ast.Type 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());
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Parameters(ast.Ast.Parameters) ArrayList(java.util.ArrayList) MethodWithType(ast.Expression.ClassB.MethodWithType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) FieldDec(ast.Ast.FieldDec) Expression(ast.Expression) MCall(ast.Expression.MCall) X(ast.Expression.X) MethodSelectorX(ast.Ast.MethodSelectorX)

Example 59 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class DesugarVars method getDecForVar.

private VarDecXE getDecForVar(Ast.C cName, VarDecXE varDec) {
    Type nt = new Type(Mdf.Mutable, Path.outer(0).pushC(cName), Doc.empty());
    Position pos = Desugar.getPosition(varDec.getInner());
    MCall right = new MCall(new Expression.EPath(pos, nt.getPath()), "#apply", Doc.empty(), Desugar.getPs("inner", new X(pos, varDec.getX())), pos);
    String nameZ = Functions.freshName(nt.getPath(), usedVars);
    //usedVars.add(nameZ);
    return new VarDecXE(false, Optional.of(nt), nameZ, right);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) Position(ast.Ast.Position) Expression(ast.Expression) MCall(ast.Expression.MCall) X(ast.Expression.X) VarDecXE(ast.Ast.VarDecXE)

Example 60 with Type

use of ast.Ast.Type in project L42 by ElvisResearchGroup.

the class TsOperations method tsX.

default default TOut tsX(TIn in, X s) {
    //D |-x ~> x :D.G(x) <= T | emptyTr
    //  D.p|- D.G(x) <= T
    Type nt = in.g(s.getInner());
    ErrorKind subErr = TypeSystem.subtype(in.p, nt, in.expected);
    if (subErr == null) {
        return new TOk(in, s, nt);
    }
    return new TErr(in, "", nt, subErr);
}
Also used : Type(ast.Ast.Type)

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