Search in sources :

Example 21 with Member

use of ast.ExpCore.ClassB.Member 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 22 with Member

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

the class RetainOnlyAndRenameAs method liftMembers.

public List<Member> liftMembers(List<Member> s) {
    if (!path.isEmpty()) {
        Ast.C name = path.get(0);
        List<Member> result = new ArrayList<>();
        Optional<Member> mOpt = Functions.getIfInDom(s, name);
        if (!mOpt.isPresent()) {
            throw new Resources.Error(EncodingHelper.wrapStringU("RenamedNestedClassNotExistant:" + name));
        }
        //retain only
        result.add(mOpt.get());
        return Map.of(this::liftM, result);
    }
    //rename as
    List<Member> result = new ArrayList<>();
    Optional<Member> mOpt = Functions.getIfInDom(s, ms1);
    if (mOpt.isPresent()) {
        Member m = mOpt.get();
        m = m.match(nc -> {
            throw Assertions.codeNotReachable();
        }, mi -> {
            throw Assertions.codeNotReachable();
        }, //mi->mi.withS(ms2).withInner(renameParameterAsVars(mi.getInner(),ms1,ms2)),
        mt -> mt.withMs(ms2).with_inner(Map.of(eMt -> renameParameterAsVars(eMt, ms1, ms2), mt.get_inner())));
        result.add(m);
    }
    return result;
}
Also used : Resources(platformSpecific.javaTranslation.Resources) Stage(ast.Ast.Stage) NestedClass(ast.ExpCore.ClassB.NestedClass) Program(programReduction.Program) Ast(ast.Ast) Path(ast.Ast.Path) Map(tools.Map) Doc(ast.Ast.Doc) HashMap(java.util.HashMap) Assertions(tools.Assertions) ExpCore(ast.ExpCore) Member(ast.ExpCore.ClassB.Member) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodSelector(ast.Ast.MethodSelector) Functions(auxiliaryGrammar.Functions) ArrayList(java.util.ArrayList) List(java.util.List) ClassB(ast.ExpCore.ClassB) WalkBy(ast.ExpCore.WalkBy) EncodingHelper(auxiliaryGrammar.EncodingHelper) Optional(java.util.Optional) Collections(java.util.Collections) TraitHeader(ast.Ast.TraitHeader) Ast(ast.Ast) ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member)

Example 23 with Member

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

the class Locator method getClassNamesPath.

public List<Ast.C> getClassNamesPath() {
    int size = this.size();
    //assert path.get(path.size()-1)==null;
    List<Ast.C> sPath = new ArrayList<>();
    for (Member m : this.ms) {
        m.match(nc -> sPath.add(nc.getName()), mi -> sPath.add(null), mt -> sPath.add(null));
    }
    if (size > 0 && cbs.get(size - 1) == null) {
        sPath.remove(sPath.size() - 1);
    }
    return sPath;
}
Also used : ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member)

Example 24 with Member

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

the class Locator method prefixOf.

public boolean prefixOf(Locator nl) {
    int size = nl.size();
    if (this.size() < size) {
        return false;
    }
    for (int i = 0; i < size; i++) {
        int indexC = this.indexes.get(i);
        int indexPos = nl.indexes.get(i);
        assert i != size - 1 || indexPos == 0 : "" + i + " " + size + " " + indexPos;
        if (i != size - 1 && indexC != indexPos) {
            return false;
        }
        Member ci = this.ms.get(i);
        Member nli = nl.ms.get(i);
        if (ci == nli) {
            continue;
        }
        if (ci.getClass() != nli.getClass()) {
            return false;
        }
        if (!(ci instanceof ClassB.NestedClass)) {
            return false;
        }
        Ast.C nci = ((ClassB.NestedClass) ci).getName();
        Ast.C nnli = ((ClassB.NestedClass) nli).getName();
        if (!nci.equals(nnli)) {
            return false;
        }
    //is ok to not check classBs?
    }
    return true;
}
Also used : Ast(ast.Ast) Member(ast.ExpCore.ClassB.Member)

Example 25 with Member

use of ast.ExpCore.ClassB.Member 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

Member (ast.ExpCore.ClassB.Member)54 ArrayList (java.util.ArrayList)32 ClassB (ast.ExpCore.ClassB)21 MethodWithType (ast.ExpCore.ClassB.MethodWithType)21 NestedClass (ast.ExpCore.ClassB.NestedClass)20 Ast (ast.Ast)14 ExpCore (ast.ExpCore)11 Path (ast.Ast.Path)10 List (java.util.List)7 Doc (ast.Ast.Doc)5 MethodSelector (ast.Ast.MethodSelector)5 MethodType (ast.Ast.MethodType)5 Collections (java.util.Collections)5 C (ast.Ast.C)4 MethodImplemented (ast.ExpCore.ClassB.MethodImplemented)4 Phase (ast.ExpCore.ClassB.Phase)4 HashSet (java.util.HashSet)4 Optional (java.util.Optional)4 Assertions (tools.Assertions)4 Position (ast.Ast.Position)3