Search in sources :

Example 21 with Type

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

the class Desugar method mdfForNamedK.

/*static public MethodWithType cfMutK(Doc doc,ast.Ast.ConcreteHeader h) {
    return cfMutK(doc,h.getFs(),h.getP());
    }*/
/*static public MethodWithType cfMutK(Doc doc,List<FieldDec>fields,Position pos) {
    List<String> names= new ArrayList<String>();
    List<NormType> ts=new ArrayList<NormType>();
    for(FieldDec fi:fields){
      NormType ti=fi.getT().match(nt->{
        if(nt.getMdf()==Mdf.Capsule){nt=nt.withMdf(Mdf.Mutable);}
        return nt;
        },ht->ht);
      ti=ti.withDoc(ti.getDoc().sum(fi.getDoc()));
      ts.add(ti);
      names.add(fi.getName());
      }
    MethodSelector ms=MethodSelector.of("#mutK",names);
    NormType resT=new ast.Ast.NormType(Mdf.Mutable,ast.Ast.Path.outer(0),Doc.empty());
    MethodType mt=new MethodType(false,ast.Ast.Mdf.Class,ts,resT,Collections.emptyList());
    return new MethodWithType(doc, ms,mt, Optional.empty(),pos);
    }*/
private static Mdf mdfForNamedK(ast.Ast.ConcreteHeader h) {
    boolean canImm = true;
    for (FieldDec f : h.getFs()) {
        //TODO: will disappear?
        if (!(f.getT() instanceof Type)) {
            return Mdf.Mutable;
        }
        Type nt = (Type) f.getT();
        Mdf m = nt.getMdf();
        if (m == Mdf.Lent || m == Mdf.Readable) {
            return Mdf.Lent;
        }
        if (m != Mdf.Immutable && m != Mdf.Class && m != Mdf.ImmutableFwd) {
            canImm = false;
        }
        if (f.isVar()) {
            canImm = false;
        }
    }
    if (canImm) {
        return Mdf.Immutable;
    }
    return Mdf.Mutable;
}
Also used : FieldDec(ast.Ast.FieldDec) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType) Mdf(ast.Ast.Mdf)

Example 22 with Type

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

the class SumMethods method isReplacedParOk.

static boolean isReplacedParOk(int index, MethodType mt1, MethodType mt2) {
    if (mt2.getTs().isEmpty()) {
        return false;
    }
    Type p1 = mt2.getTs().get(index);
    Type r = mt1.getReturnType();
    return p1.equals(r);
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 23 with Type

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

the class TranslateExpression method getCatch.

private void getCatch(String kVar, On on, String asReturn, String kLab) {
    Path p = ((Type) on.getT()).getPath();
    String tn = Resources.nameOf(p);
    if (p.equals(Path.Library())) {
        res.append(getCatchHeaderForLibrary(kVar));
    } else if (!p.isPrimitive() && tn.equals("Object")) {
        res.append(getCatchHeaderForPathNotStar(kVar, p));
    } else {
        res.append("if(" + kVar + ".unbox instanceof " + tn + "){\n");
    }
    res.append("  " + tn + "[] P" + on.getX() + "={(" + tn + ")" + kVar + ".unbox};\n");
    res.append(asReturn);
    on.getInner().accept(this);
    res.append(";");
    if (asReturn.contains("=")) {
        res.append("break " + kLab + ";");
    }
    res.append("\n  }\nelse ");
}
Also used : Path(ast.Ast.Path) Type(ast.Ast.Type) PluginType(platformSpecific.fakeInternet.PluginType)

Example 24 with Type

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

the class InjectionOnSugar method visit.

@Override
public Expression visit(ClassB s) {
    Doc doc1 = s.getDoc1();
    Header h = (s.isInterface()) ? new Ast.InterfaceHeader() : new Ast.TraitHeader();
    List<Type> supertypes = s.getSupertypes();
    List<Member> members = new ArrayList<>();
    for (ast.ExpCore.ClassB.Member mi : s.getMs()) {
        members.add(mi.match(nc -> new Expression.ClassB.NestedClass(nc.getDoc(), nc.getName(), lift(nc.getInner()), nc.getP()), mimpl -> new Expression.ClassB.MethodImplemented(mimpl.getDoc(), mimpl.getS(), lift(mimpl.getInner()), mimpl.getP()), mwt -> {
            Doc idoc = mwt.getDoc();
            MethodSelector is = mwt.getMs();
            MethodType mt = mwt.getMt();
            return new Expression.ClassB.MethodWithType(idoc, is, mt, lift(mwt.get_inner()), mwt.getP());
        }));
    }
    return new Expression.ClassB(doc1, h, Collections.emptyList(), supertypes, members, s.getP());
}
Also used : VarDecXE(ast.Ast.VarDecXE) UpdateVar(ast.ExpCore.UpdateVar) Ast(ast.Ast) Header(ast.Ast.Header) MCall(ast.ExpCore.MCall) Type(ast.Ast.Type) Member(ast.Expression.ClassB.Member) WellFormedness(auxiliaryGrammar.WellFormedness) MethodType(ast.Ast.MethodType) Loop(ast.ExpCore.Loop) MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) Visitor(coreVisitors.Visitor) ClassB(ast.ExpCore.ClassB) WalkBy(ast.ExpCore.WalkBy) Mdf(ast.Ast.Mdf) X(ast.ExpCore.X) VarDec(ast.Ast.VarDec) Path(ast.Ast.Path) Signal(ast.ExpCore.Signal) Match(tools.Match) Doc(ast.Ast.Doc) ExpCore._void(ast.ExpCore._void) ExpCore(ast.ExpCore) Block(ast.ExpCore.Block) Expression(ast.Expression) List(java.util.List) Position(ast.Ast.Position) Using(ast.ExpCore.Using) Optional(java.util.Optional) Collections(java.util.Collections) MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) Ast(ast.Ast) ArrayList(java.util.ArrayList) Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) Header(ast.Ast.Header) Expression(ast.Expression) Doc(ast.Ast.Doc) Member(ast.Expression.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 25 with Type

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

the class AlternativeMethodTypes method _mC.

static MethodType _mC(MethodType mt) {
    //Ts->mut P0;Ps in methTypes(p,P,ms)
    //(mC)-------------------------------------------------------------------
    //mutToCapsule(Ts)->capsule P0;Ps in methTypes(p,P,ms)
    Type retT = mt.getReturnType();
    if (retT.getMdf() != Mdf.Mutable) {
        return null;
    }
    retT = retT.withMdf(Mdf.Capsule);
    List<Type> ts = Map.of(t -> mutToCapsule(t), mt.getTs());
    return mt.withReturnType(retT).withTs(ts).withMdf(mutToCapsule(mt.getMdf()));
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

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