Search in sources :

Example 6 with MethodWithType

use of ast.Expression.ClassB.MethodWithType 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 7 with MethodWithType

use of ast.Expression.ClassB.MethodWithType in project L42 by ElvisResearchGroup.

the class Desugar method cfGetter.

private static void cfGetter(Expression.Position pos, FieldDec f, Doc doc, List<Member> result) {
    if (!(f.getT() instanceof Type)) {
        return;
    }
    MethodWithType mwt = generateGetter(pos, f, doc);
    result.add(mwt);
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodWithType(ast.Expression.ClassB.MethodWithType)

Example 8 with MethodWithType

use of ast.Expression.ClassB.MethodWithType in project L42 by ElvisResearchGroup.

the class Desugar method visit.

public MethodWithType visit(MethodWithType mt) {
    this.usedVars = new HashSet<String>();
    this.varEnv = new HashMap<String, Type>();
    String mName = desugarName(mt.getMs().nameToS());
    mt = mt.withMs(mt.getMs().withName(mName));
    if (!mt.getInner().isPresent()) {
        return super.visit(mt);
    }
    {
        int i = -1;
        for (String name : mt.getMs().getNames()) {
            i += 1;
            this.usedVars.add(name);
            this.varEnv.put(name, mt.getMt().getTs().get(i));
        }
    }
    usedVars.add("this");
    varEnv.put("this", new Type(mt.getMt().getMdf(), Path.outer(0), mt.getDoc()));
    usedVars.addAll(CollectDeclaredVars.of(mt.getInner().get()));
    //final restrictions
    final MethodWithType mt2 = mt;
    return withExpectedType(liftT(mt.getMt().getReturnType()), () -> super.visit(mt2));
}
Also used : Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) MethodWithType(ast.Expression.ClassB.MethodWithType)

Aggregations

MethodType (ast.Ast.MethodType)8 Type (ast.Ast.Type)8 MethodWithType (ast.Expression.ClassB.MethodWithType)8 MethodSelector (ast.Ast.MethodSelector)5 FieldDec (ast.Ast.FieldDec)3 Mdf (ast.Ast.Mdf)3 MethodSelectorX (ast.Ast.MethodSelectorX)2 Parameters (ast.Ast.Parameters)2 Expression (ast.Expression)2 MCall (ast.Expression.MCall)2 Ast (ast.Ast)1 ConcreteHeader (ast.Ast.ConcreteHeader)1 Doc (ast.Ast.Doc)1 Header (ast.Ast.Header)1 Op (ast.Ast.Op)1 Path (ast.Ast.Path)1 Position (ast.Ast.Position)1 SignalKind (ast.Ast.SignalKind)1 Stage (ast.Ast.Stage)1 VarDec (ast.Ast.VarDec)1