Search in sources :

Example 1 with Member

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

the class Errors42 method checkExistsPathMethod.

static Member checkExistsPathMethod(ClassB cb, List<Ast.C> path, Optional<MethodSelector> ms) {
    try {
        //used in closures
        Boolean[] isPrivateRef = new Boolean[] { false };
        for (C c : path) {
            if (c.isUnique()) {
                isPrivateRef[0] = true;
            }
        }
        ClassB cbi = cb.getClassB(path);
        Boolean[] isPrivateMeth = new Boolean[] { false };
        boolean absentMeth = false;
        if (ms.isPresent()) {
            Optional<Member> meth = Functions.getIfInDom(cbi.getMs(), ms.get());
            absentMeth = !meth.isPresent();
            if (meth.isPresent()) {
                meth.get().match(nc -> {
                    throw Assertions.codeNotReachable();
                }, mi -> {
                    return null;
                }, mt -> {
                    if (mt.getMs().isUnique()) {
                        isPrivateMeth[0] = true;
                    }
                    return null;
                });
                if (!isPrivateMeth[0]) {
                    return meth.get();
                }
            }
        }
        MemberUnavailable kind = null;
        if (absentMeth) {
            kind = MemberUnavailable.NonExistentMethod;
        }
        if (isPrivateMeth[0]) {
            kind = MemberUnavailable.PrivateMethod;
        }
        if (isPrivateRef[0]) {
            kind = MemberUnavailable.PrivatePath;
        }
        if (kind == null) {
            return null;
        }
        throw Resources.Error.multiPartStringError("MemberUnavailable", "Path", formatPathIn(path), "Selector", "" + ((ms.isPresent()) ? ms.get() : ""), "InvalidKind", "" + kind.name(), "IsPrivate", "" + kind.name().contains("Private"));
    } catch (ast.ErrorMessage.PathMetaOrNonExistant e) {
        throw Resources.Error.multiPartStringError("MemberUnavailable", "Path", formatPathIn(path), "Selector", "" + ((ms.isPresent()) ? ms.get() : ""), "InvalidKind", "" + MemberUnavailable.NonExistentPath, "IsPrivate", "false");
    }
}
Also used : C(ast.Ast.C) ErrorMessage(ast.ErrorMessage) Member(ast.ExpCore.ClassB.Member) ClassB(ast.ExpCore.ClassB)

Example 2 with Member

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

the class ExtractInfo method isModule.

public static boolean isModule(ClassB cb) {
    for (Member m : cb.getMs()) {
        if (!(m instanceof MethodWithType)) {
            continue;
        }
        MethodWithType mwt = (MethodWithType) m;
        if (mwt.getMt().getMdf() != Mdf.Class) {
            return false;
        }
        Type rt = mwt.getMt().getReturnType();
        if (!(rt instanceof Type)) {
            continue;
        }
        Type nt = (Type) rt;
        if (nt.getPath().equals(Path.outer(0))) {
            return false;
        }
    }
    return true;
}
Also used : Type(ast.Ast.Type) MethodType(ast.Ast.MethodType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 3 with Member

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

the class ExtractInfo method accumulateCb.

/*   private static Set<MethodSelector> intersection(Collection<MethodSelector>ams, Collection<MethodSelector>bms){
    if( ams==null || ams.isEmpty() || bms==null || bms.isEmpty()){return  Collections.emptySet();}
    Set<MethodSelector> result = new HashSet<>(ams);
    result.retainAll(bms);
    return result;
  }*/
static void accumulateCb(java.util.Map<Path, List<MethodSelector>> accumulator, Path path, ClassB cb) {
    assert cb.isInterface();
    if (accumulator.containsKey(path)) {
        return;
    }
    List<MethodSelector> defined = new ArrayList<>();
    for (Member m : cb.getMs()) {
        if (!(m instanceof MethodWithType)) {
            continue;
        }
        defined.add(((MethodWithType) m).getMs());
    }
    accumulator.put(path, defined);
}
Also used : MethodSelector(ast.Ast.MethodSelector) ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

Example 4 with Member

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

the class ExtractInfo method auxCollectPrivatePathsAndSubpaths.

private static void auxCollectPrivatePathsAndSubpaths(ClassB cb, List<Path> accumulator, List<Ast.C> prefix, boolean collectAll) {
    for (Member m : cb.getMs()) {
        m.match(nc -> {
            List<Ast.C> newPrefix = new ArrayList<>(prefix);
            newPrefix.add(nc.getName());
            boolean newCollectAll = collectAll || nc.getName().isUnique();
            auxCollectPrivatePathsAndSubpaths((ClassB) nc.getInner(), accumulator, newPrefix, newCollectAll);
            if (newCollectAll) {
                accumulator.add(Path.outer(0, newPrefix));
            }
            return null;
        }, mi -> null, mt -> null);
    }
}
Also used : ArrayList(java.util.ArrayList) Member(ast.ExpCore.ClassB.Member)

Example 5 with Member

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

the class LiftValue method liftValue.

static ExpCore.ClassB liftValue(ExpCore val, Ast.MethodSelector sel, ExpCore.ClassB context) {
    List<Member> ms = new ArrayList<>(context.getMs());
    MethodType mt = new MethodType(false, Mdf.Class, Collections.emptyList(), Ast.Type.immAny, Collections.emptyList());
    //need to insert a "cast", or to return Any, and then fwd to a cast
    //lib={ T:{} class method Any val()  class method T cast() {with val=this.val() (on T return val) error ....}
    //lib:=redirect T ->... <<lib
    //lib:=liftValue  val
    Optional<Member> optMt = Functions.getIfInDom(ms, sel);
    ExpCore.ClassB.MethodWithType mwt = new ExpCore.ClassB.MethodWithType(Doc.empty(), sel, mt, Optional.of(val), context.getP());
    if (!optMt.isPresent()) {
        ms.add(mwt);
        return context.withMs(ms);
    }
    if (!(optMt.get() instanceof MethodWithType)) {
        throw Errors42.errorMethodClash(Collections.emptyList(), optMt.get(), mwt, true, Collections.emptyList(), true, true, false);
    }
    Errors42.checkMethodClash(Collections.emptyList(), (MethodWithType) optMt.get(), mwt, false);
    Functions.replaceIfInDom(ms, mwt);
    return context.withMs(ms);
}
Also used : MethodType(ast.Ast.MethodType) ExpCore(ast.ExpCore) ArrayList(java.util.ArrayList) MethodWithType(ast.ExpCore.ClassB.MethodWithType) MethodWithType(ast.ExpCore.ClassB.MethodWithType) Member(ast.ExpCore.ClassB.Member)

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