Search in sources :

Example 1 with MethodWithType

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

the class Desugar method cfLentK.

public static MethodWithType cfLentK(MethodWithType mutK) {
    mutK = mutK.withMs(mutK.getMs().withName("#lentK"));
    Type resT = new ast.Ast.Type(Mdf.Lent, ast.Ast.Path.outer(0), Doc.empty());
    MethodType mt = mutK.getMt();
    mt = mt.withReturnType(resT).withTs(mt.getTs().stream().map(t -> (Type) t).map(nt -> nt.withMdf(nt.getMdf() == Mdf.Mutable ? Mdf.Lent : nt.getMdf())).collect(Collectors.toList()));
    mutK = mutK.withMt(mt);
    return mutK;
}
Also used : Stage(ast.Ast.Stage) VarDecXE(ast.Ast.VarDecXE) X(ast.Expression.X) Ast(ast.Ast) FieldDec(ast.Ast.FieldDec) Parameters(ast.Ast.Parameters) Catch1(ast.Expression.Catch1) Catch(ast.Expression.Catch) SquareWithCall(ast.Expression.SquareWithCall) ErrorMessage(ast.ErrorMessage) Type(ast.Ast.Type) Configuration(facade.Configuration) FCall(ast.Expression.FCall) SquareCall(ast.Expression.SquareCall) ConcreteHeader(ast.Ast.ConcreteHeader) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) Visitor(coreVisitors.Visitor) BinOp(ast.Expression.BinOp) InjectionOnSugar(coreVisitors.InjectionOnSugar) Op(ast.Ast.Op) SignalKind(ast.Ast.SignalKind) Loop(ast.Expression.Loop) OnLineCode(platformSpecific.fakeInternet.OnLineCode) RoundBlock(ast.Expression.RoundBlock) TypeManipulation(newTypeSystem.TypeManipulation) Set(java.util.Set) MethodSelectorX(ast.Ast.MethodSelectorX) With(ast.Expression.With) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) UseSquare(ast.Expression.UseSquare) While(ast.Expression.While) ClassReuse(ast.Expression.ClassReuse) VarDecCE(ast.Ast.VarDecCE) EncodingHelper(auxiliaryGrammar.EncodingHelper) Optional(java.util.Optional) Timer(profiling.Timer) L42(facade.L42) Expression._void(ast.Expression._void) Program(programReduction.Program) Header(ast.Ast.Header) Using(ast.Expression.Using) Member(ast.Expression.ClassB.Member) HashMap(java.util.HashMap) Assertions(tools.Assertions) MethodType(ast.Ast.MethodType) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PathMxMx(ast.Util.PathMxMx) RefreshUniqueNames(privateMangling.RefreshUniqueNames) MCall(ast.Expression.MCall) If(ast.Expression.If) Literal(ast.Expression.Literal) UnOp(ast.Expression.UnOp) IsCompiled(coreVisitors.IsCompiled) Mdf(ast.Ast.Mdf) VarDec(ast.Ast.VarDec) Path(ast.Ast.Path) DocE(ast.Expression.DocE) Doc(ast.Ast.Doc) VarDecE(ast.Ast.VarDecE) ExpCore(ast.ExpCore) Expression(ast.Expression) ClassB(ast.Expression.ClassB) Functions(auxiliaryGrammar.Functions) CatchMany(ast.Expression.CatchMany) CurlyBlock(ast.Expression.CurlyBlock) Position(ast.Ast.Position) MethodImplemented(ast.Expression.ClassB.MethodImplemented) PathAux(ast.PathAux) Collections(java.util.Collections) NestedClass(ast.Expression.ClassB.NestedClass) MethodType(ast.Ast.MethodType) Type(ast.Ast.Type) MethodWithType(ast.Expression.ClassB.MethodWithType) MethodType(ast.Ast.MethodType)

Example 2 with MethodWithType

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

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

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

the class Desugar method generateExposer.

//left cfExposer generating exposer since is different from generateExposer code for # and capsule
/*static private void cfExposer(Expression.Position pos,FieldDec f,Doc doc, List<Member> result) {
    NormType tt=f.getT().match(nt->Functions.toComplete(nt), hType->hType);
    MethodType mti=new MethodType(false,Mdf.Mutable,Collections.emptyList(),tt,Collections.emptyList());
    MethodSelector msi=MethodSelector.of("#"+f.getName(),Collections.emptyList());
    result.add(new MethodWithType(doc, msi, mti, Optional.empty(),pos));
  }*/
private static MethodWithType generateExposer(Expression.Position pos, FieldDec f, Doc doc) {
    Type tt = TypeManipulation.noFwd(f.getT());
    if (tt.getMdf() == Mdf.Capsule) {
        tt = tt.withMdf(Mdf.Lent);
    }
    MethodType mti = new MethodType(false, Mdf.Mutable, Collections.emptyList(), tt, Collections.emptyList());
    MethodSelector msi = MethodSelector.of("#" + f.getName(), 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)

Example 5 with MethodWithType

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

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