use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class Abstract method auxToAbstract.
private static ClassB auxToAbstract(Program p, ClassB cb, List<Ast.C> pathForError, MethodSelector sel, MethodSelector newSel) {
List<Member> newMs = new ArrayList<>(cb.getMs());
Member m = Functions.getIfInDom(newMs, sel).get();
//make m abstract
if (m instanceof MethodWithType) {
MethodWithType mwt = (MethodWithType) m;
mwt = mwt.with_inner(Optional.empty());
Functions.replaceIfInDom(newMs, mwt);
} else {
//it is method implemented
Functions.removeIfInDom(newMs, sel);
}
//create new class
if (newSel == null) {
return cb.withMs(newMs);
}
MethodWithType mwt1 = (MethodWithType) cb._getMember(sel);
assert mwt1 != null;
if (newSel != null) {
Errors42.checkCompatibleMs(pathForError, mwt1, newSel);
}
Optional<MethodWithType> mwt2 = Optional.ofNullable((MethodWithType) cb._getMember(newSel));
//never refine, see under
mwt1 = mwt1.withMs(newSel).withDoc(Doc.empty()).withMt(mwt1.getMt().withRefine(false));
if (mwt2.isPresent()) {
//Never there, so will never implement interfaces (on normalized classb)
throw Errors42.errorMethodClash(pathForError, mwt1, mwt2.get(), false, Collections.emptyList(), false, false, false);
}
newMs.add(mwt1);
return cb.withMs(newMs);
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class AddDocumentation method auxAddDocOnMethod.
private static ClassB auxAddDocOnMethod(Program p, ClassB cb, MethodSelector sel, Doc doc) {
List<Member> newMs = new ArrayList<>(cb.getMs());
Member m = Functions.getIfInDom(newMs, sel).get();
//add comment
m.match(nc -> {
throw Assertions.codeNotReachable();
}, mi -> {
throw Assertions.codeNotReachable();
}, mt -> {
mt = mt.withDoc(mt.getDoc().sum(doc));
Functions.replaceIfInDom(newMs, mt);
return null;
});
//create new class
return cb.withMs(newMs);
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class _Aux method onClassNavigateToPathAndDo.
static ClassB onClassNavigateToPathAndDo(ClassB cb, List<Ast.C> cs, Function<ClassB, ClassB> op) {
if (cs.isEmpty()) {
return op.apply(cb);
}
List<Member> newMs = new ArrayList<>(cb.getMs());
Ast.C nName = cs.get(0);
int index = getIndex(newMs, nName);
checkIndex(index);
NestedClass nc = (NestedClass) newMs.get(index);
if (cs.size() > 1) {
nc = nc.withInner(onClassNavigateToPathAndDo(wrapCast(nc.getInner()), cs.subList(1, cs.size()), op));
newMs.set(index, nc);
return cb.withMs(newMs);
}
assert cs.size() == 1;
ClassB newCb = op.apply(wrapCast(nc.getInner()));
newMs.set(index, nc.withInner(newCb));
return cb.withMs(newMs);
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class _Aux method onNestedNavigateToPathAndDo.
static ClassB onNestedNavigateToPathAndDo(ClassB cb, List<Ast.C> cs, Function<NestedClass, Optional<NestedClass>> op) {
assert !cs.isEmpty();
assert cb != null;
List<Member> newMs = new ArrayList<>(cb.getMs());
Ast.C nName = cs.get(0);
int index = getIndex(newMs, nName);
checkIndex(index);
NestedClass nc = (NestedClass) newMs.get(index);
if (cs.size() > 1) {
nc = nc.withInner(onNestedNavigateToPathAndDo(wrapCast(nc.getInner()), cs.subList(1, cs.size()), op));
newMs.set(index, nc);
return cb.withMs(newMs);
}
assert cs.size() == 1;
Optional<NestedClass> optNc = op.apply(nc);
if (optNc.isPresent()) {
newMs.set(index, optNc.get());
} else {
newMs.remove(index);
}
return cb.withMs(newMs);
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class _Aux method isConsistent.
static boolean isConsistent(ClassB cb) {
int countWalkBy = 0;
HashSet<String> keys = new HashSet<String>();
for (Member m : cb.getMs()) {
if (m instanceof MethodWithType) {
MethodWithType mwt = (MethodWithType) m;
String key = mwt.getMs().toString();
assert !keys.contains(key);
keys.add(key);
//assert mwt.getMt().getTDocs().size() == mwt.getMt().getTs().size();
}
if (m instanceof NestedClass) {
NestedClass nc = (NestedClass) m;
String key = nc.getName().toString();
assert !keys.contains(key);
keys.add(key);
if (nc.getInner() instanceof ExpCore.WalkBy) {
countWalkBy += 1;
}
}
if (m instanceof MethodImplemented) {
MethodImplemented mi = (MethodImplemented) m;
String key = mi.getS().toString();
assert !keys.contains(key);
keys.add(key);
}
}
// || ((cb.getPhase()!=ast.ExpCore.ClassB.Phase.None && !cb.getUniqueId().isEmpty()) );
assert countWalkBy <= 1 : cb;
return true;
}
Aggregations