use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class Errors42 method checkCompatibleMs.
public static void checkCompatibleMs(List<Ast.C> pathForError, MethodWithType mem, MethodSelector dest) {
int sizeA = mem.getMs().getNames().size();
int sizeB = dest.getNames().size();
if (sizeA == sizeB) {
return;
}
List<Integer> parsWrong = new ArrayList<>();
int min = Math.min(sizeA, sizeB);
int max = Math.max(sizeA, sizeB);
for (int i = min; i < max; i++) {
parsWrong.add(i);
}
List<Type> ts = new ArrayList<>(mem.getMt().getTs());
for (int i = sizeA; i < sizeB; i++) {
ts.add(ast.Ast.Type.immVoid);
}
if (sizeA > sizeB) {
ts = ts.subList(0, sizeB);
}
MethodWithType memb = mem.withMs(dest).withMt(mem.getMt().withTs(ts));
throw errorMethodClash(pathForError, mem, memb, true, parsWrong, true, true, false);
}
use of ast.ExpCore.ClassB.MethodWithType 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.MethodWithType 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.MethodWithType 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);
}
use of ast.ExpCore.ClassB.MethodWithType in project L42 by ElvisResearchGroup.
the class UsedPaths method usedInnerM.
private static Paths usedInnerM(Member m, Phase phase0) {
if (m instanceof NestedClass) {
NestedClass nc = (NestedClass) m;
return usedInnerL((ClassB) nc.getInner(), Collections.emptyList(), phase0).pop();
}
List<Path> result1;
List<ClassB> l1n = Collections.emptyList();
if (m instanceof MethodWithType) {
MethodWithType mwt = (MethodWithType) m;
result1 = CollectPaths0.of(mwt);
if (phase0 == Phase.Typed && mwt.get_inner().isPresent()) {
l1n = CollectClassBs0.of(m.getInner());
}
} else {
assert m instanceof MethodImplemented;
result1 = CollectPaths0.of(m.getInner());
}
Paths result2 = Paths.reorganize(result1);
Paths acc = Paths.empty();
for (ClassB li : l1n) {
acc = acc.union(usedInnerL(li, Collections.emptyList(), phase0));
}
return result2.union(acc.pop());
}
Aggregations