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");
}
}
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;
}
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);
}
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);
}
}
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);
}
Aggregations