Search in sources :

Example 11 with MethodWithType

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

the class TranslateClass method extractConstructors.

private static List<MethodWithType> extractConstructors(ClassB ct) {
    List<MethodWithType> result = new ArrayList<>();
    for (Member m : ct.getMs()) {
        assert m instanceof MethodWithType;
        MethodWithType mt = (MethodWithType) m;
        if (mt.get_inner().isPresent()) {
            continue;
        }
        if (mt.getMt().getMdf() != Ast.Mdf.Class) {
            continue;
        }
        result.add(mt);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 12 with MethodWithType

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

the class TranslateClass method generateClassFacade.

private static void generateClassFacade(String s, ClassB ct, StringBuilder res) {
    List<MethodWithType> ctors = extractConstructors(ct);
    if (ctors.isEmpty()) {
        getReverterForNotInstantiableClass(s, res);
        getPhNestedNotIntantiable(s, ct, res, false);
        getTypeForNotInstantiableClass(s, res);
        return;
    }
    MethodWithType ctor = ctors.get(0);
    getFields(ctor, res);
    getConstructor(s, ctor, res);
    getReverter(s, ctor, res);
    getGettesSettersAndExposers(ct, res);
    getPhNested(s, ctor, res);
    getType(s, ctors, res);
}
Also used : MethodWithType(ast.ExpCore.ClassB.MethodWithType)

Example 13 with MethodWithType

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

the class TranslateClass method getMethods.

private static void getMethods(Program p, ClassB ct, StringBuilder res, boolean isInterface) {
    for (Member m : ct.getMs()) {
        assert m instanceof MethodWithType;
        MethodWithType mt = (MethodWithType) m;
        if (!isInterface && !mt.get_inner().isPresent()) {
            continue;
        }
        //if(mt.getMt().getMdf()!=Ast.Mdf.NormType){continue;}
        getMethod(p, mt, res);
    }
}
Also used : MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 14 with MethodWithType

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

the class TsLibrary method libraryWellTyped.

default default TOut libraryWellTyped(TIn in) {
    //   (library well typed)
    //   Phase |- p ~> L' //In implementation, if p.top().Phase>=Phase, L'=p.Top()
    ClassB top = in.p.top();
    assert //   Phase in {Typed,Coherent}
    in.phase.subtypeEq(Phase.Typed) : "";
    if (top.getPhase().subtypeEq(in.phase)) {
        return new TOk(in, top, Path.Library().toImmNT());
    }
    //   L0={interface? implements Ps M1..Mn Phase'}=norm(p)
    //   L'={interface? implements Ps M1'..Mn' max(Phase',Phase)}
    ClassB L0 = normTopL(in);
    List<MethodWithType> mwts = L0.mwts();
    List<NestedClass> ns = L0.ns();
    List<NestedClass> newNs = new ArrayList<>();
    //   forall i in 1..n
    //     Phase| p| Ps |- Mi ~> Mi'
    TIn inNested = in.withP(in.p.updateTop(L0));
    List<MethodWithType> newMwts;
    if (in.phase == Phase.Coherent && top.getPhase() == Phase.Typed) {
        newMwts = new ArrayList<>(mwts);
    } else {
        newMwts = new ArrayList<>();
        for (MethodWithType mwt : mwts) {
            TOutM out = memberMethod(inNested, L0.getSupertypes(), mwt);
            if (!out.isOk()) {
                return out.toError();
            }
            newMwts.add((MethodWithType) out.toOkM().inner);
        }
    }
    for (NestedClass nt : ns) {
        TOutM out = memberNested(inNested, nt);
        if (!out.isOk()) {
            return out.toError();
        }
        newNs.add((NestedClass) out.toOkM().inner);
    }
    Phase maxPhase = L0.getPhase();
    if (in.phase.subtypeEq(maxPhase)) {
        maxPhase = in.phase;
    }
    ClassB L1 = new ClassB(L0.getDoc1(), L0.isInterface(), L0.getSupertypes(), newMwts, newNs, L0.getP(), maxPhase, L0.getUniqueId());
    if (in.phase == Phase.Coherent) {
        boolean isCoh = coherent(in.p.updateTop(L1), true);
        if (!isCoh) {
            return new TErr(in, "", Path.Library().toImmNT(), ErrorKind.LibraryNotCoherent);
        }
    }
    //   //or error not coherent set of abstr. methods:list
    return new TOk(in, L1, Path.Library().toImmNT());
}
Also used : Phase(ast.ExpCore.ClassB.Phase) ArrayList(java.util.ArrayList) NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) ClassB(ast.ExpCore.ClassB)

Example 15 with MethodWithType

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

the class ErrorFormatter method whyIsNotExecutable.

private static String whyIsNotExecutable(ClassB cb) {
    /*if(cb.getH() instanceof Ast.TraitHeader){
      return "\n  The requested path is a trait";
    }*/
    for (Member m : cb.getMs()) {
        if (!(m instanceof MethodWithType)) {
            continue;
        }
    /*MethodWithType mt=(MethodWithType)m;
      if (!mt.getInner().isPresent() && !mt.isFieldGenerated()){
        return "\n  The method "+mt.getMs()+" of the requested path is abstract";
      }*/
    }
    for (Member m : cb.getMs()) {
        if (!(m instanceof NestedClass)) {
            continue;
        }
        NestedClass nc = (NestedClass) m;
        if (!(nc.getInner() instanceof ClassB)) {
            return "\n  The nested class " + nc.getName() + " of the requested path is not compiled yet";
        }
        String nestedRes = whyIsNotExecutable((ClassB) nc.getInner());
        if (nestedRes != null) {
            return "." + nc.getName() + nestedRes;
        }
    }
    return null;
}
Also used : NestedClass(ast.ExpCore.ClassB.NestedClass) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Aggregations

MethodWithType (ast.ExpCore.ClassB.MethodWithType)46 Member (ast.ExpCore.ClassB.Member)21 MethodType (ast.Ast.MethodType)18 ArrayList (java.util.ArrayList)16 Type (ast.Ast.Type)13 Path (ast.Ast.Path)10 ClassB (ast.ExpCore.ClassB)10 NestedClass (ast.ExpCore.ClassB.NestedClass)9 ExpCore (ast.ExpCore)8 MethodSelector (ast.Ast.MethodSelector)7 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)7 Ast (ast.Ast)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Program (programReduction.Program)4 Mdf (ast.Ast.Mdf)3 Functions (auxiliaryGrammar.Functions)3 From (coreVisitors.From)3 Collections (java.util.Collections)3