Search in sources :

Example 6 with MethodType

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

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

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

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

the class SumMethods method sumMethods.

public static ClassB sumMethods(ClassB lib, List<Ast.C> path, MethodSelector m1, MethodSelector m2, MethodSelector mRes, String name) {
    ClassB pathCb = pathCb(lib, path);
    Member mem1 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m1));
    Member mem2 = Errors42.checkExistsPathMethod(lib, path, Optional.of(m2));
    MethodType mt1 = ((MethodWithType) pathCb._getMember(m1)).getMt();
    MethodType mt2 = ((MethodWithType) pathCb._getMember(m2)).getMt();
    int index = m2.getNames().indexOf(name);
    if (index == -1) {
        throw Errors42.errorParameterMismatch(path, mem1, mem2, false, false, false);
    }
    checkParSize(index, path, m1, m2, mRes, mem1, mem2, mt1, mt2);
    MethodType mtU = mtU(index, mt1, mt2);
    if (mtU == null) {
        throw Errors42.errorParameterMismatch(path, mem1, mem2, isReplacedParOk(index, mt1, mt2), false, true);
    }
    ExpCore eU = eU(index, mem2.getP(), mt1, mt2, m1, m2, mRes);
    MethodWithType mwtU = new MethodWithType(Doc.empty(), mRes, mtU, Optional.of(eU), mem2.getP());
    checkConflict(path, mRes, pathCb, mwtU);
    boolean replOk = isReplacedParOk(index, mt1, mt2);
    if (!replOk) {
        throw Errors42.errorParameterMismatch(path, mem1, mem2, false, true, true);
    }
    return finalResult(lib, path, mwtU);
}
Also used : MethodType(ast.Ast.MethodType) ExpCore(ast.ExpCore) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 10 with MethodType

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

the class PlgWrapperGenerator method hasPluginUnresponsive.

public static boolean hasPluginUnresponsive(ClassB l) {
    //class method T #pluginUnresponsive(Library binaryRepr)
    MethodSelector ms = MethodSelector.of("#pluginUnresponsive", 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().getMdf().equals(Mdf.Immutable)) {
        return false;
    }
    //no need to check return type, since is just thrown as error
    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