Search in sources :

Example 31 with MethodType

use of ast.Ast.MethodType 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 32 with MethodType

use of ast.Ast.MethodType 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 33 with MethodType

use of ast.Ast.MethodType 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 34 with MethodType

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

the class _Sum method sumMethod.

static MethodWithType sumMethod(MethodWithType ma, MethodWithType mb) {
    Set<Path> pa = new HashSet<Path>(Map.of(t -> t.getPath(), ma.getMt().getExceptions()));
    Set<Path> pb = new HashSet<Path>(Map.of(t -> t.getPath(), mb.getMt().getExceptions()));
    Set<Path> pc = new HashSet<>(pa);
    pc.retainAll(pb);
    Doc doc = ma.getDoc().sum(mb.getDoc());
    MethodType mt = ma.getMt();
    List<Ast.Type> opc = pc.stream().map(pi -> (Ast.Type) pi.toImmNT()).collect(Collectors.toList());
    Collections.sort(opc, (p1, p2) -> p1.toString().compareTo(p2.toString()));
    mt = mt.withExceptions(opc);
    MethodWithType mwt = ma.withMt(mt).withDoc(doc);
    //now mwt has min exceptions and summed docs
    assert !ma.get_inner().isPresent() || !mb.get_inner().isPresent();
    if (mb.get_inner().isPresent()) {
        mwt = mwt.withInner(mb.getInner());
    }
    return mwt;
}
Also used : Resources(platformSpecific.javaTranslation.Resources) From(coreVisitors.From) Stage(ast.Ast.Stage) Program(programReduction.Program) Ast(ast.Ast) Map(tools.Map) Configuration(facade.Configuration) ErrorMessage(ast.ErrorMessage) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RefreshUniqueNames(privateMangling.RefreshUniqueNames) ClassB(ast.ExpCore.ClassB) PathMwt(ast.Util.PathMwt) ClassKind(is.L42.connected.withSafeOperators.ExtractInfo.ClassKind) CloneVisitor(sugarVisitors.CloneVisitor) NestedClass(ast.ExpCore.ClassB.NestedClass) Path(ast.Ast.Path) Doc(ast.Ast.Doc) Phase(ast.ExpCore.ClassB.Phase) Set(java.util.Set) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) CollapsePositions(sugarVisitors.CollapsePositions) List(java.util.List) Optional(java.util.Optional) Collections(java.util.Collections) MethodImplemented(ast.ExpCore.ClassB.MethodImplemented) Path(ast.Ast.Path) MethodType(ast.Ast.MethodType) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Doc(ast.Ast.Doc) MethodWithType(ast.ExpCore.ClassB.MethodWithType) HashSet(java.util.HashSet)

Example 35 with MethodType

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

the class PlgWrapperGenerator method hasFrom.

public static boolean hasFrom(ClassB l) {
    //   class method mut This0 #from(Library binaryRepr)
    MethodSelector ms = MethodSelector.of("#from", Collections.singletonList("binaryRepr"));
    MethodWithType mwt = (MethodWithType) l._getMember(ms);
    //must be an mwt since normalized
    if (mwt == null) {
        return false;
    }
    MethodType mt = mwt.getMt();
    if (!mt.getMdf().equals(Mdf.Class)) {
        return false;
    }
    if (!mt.getTs().get(0).equals(Type.immLibrary)) {
        return false;
    }
    if (!mt.getExceptions().isEmpty()) {
        return false;
    }
    if (!mt.getReturnType().equals(Type.mutThis0)) {
        return false;
    }
    return true;
}
Also used : MethodType(ast.Ast.MethodType) MethodSelector(ast.Ast.MethodSelector) MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Aggregations

MethodType (ast.Ast.MethodType)48 Type (ast.Ast.Type)32 MethodWithType (ast.ExpCore.ClassB.MethodWithType)25 Mdf (ast.Ast.Mdf)14 MethodSelector (ast.Ast.MethodSelector)14 ArrayList (java.util.ArrayList)14 Path (ast.Ast.Path)10 ExpCore (ast.ExpCore)9 List (java.util.List)9 Collections (java.util.Collections)8 Functions (auxiliaryGrammar.Functions)7 Test (org.junit.Test)7 Doc (ast.Ast.Doc)6 MethodWithType (ast.Expression.ClassB.MethodWithType)6 HashMap (java.util.HashMap)6 Program (programReduction.Program)6 Ast (ast.Ast)5 ClassB (ast.ExpCore.ClassB)5 Member (ast.ExpCore.ClassB.Member)5 Optional (java.util.Optional)5