use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class _Sum method normalizedSum.
/*
private static void interfaceClash(Program p, ClassB candidate) {
try{
Configuration.typeSystem.computeStage(p,candidate);
}catch(ErrorMessage.IncoherentMwts i){
List<Path>ps=new ArrayList<>();
List<Member>mems=new ArrayList<>();
Path ph=Path.outer(0,i.getExploredPath());
for(PathMwt e:i.getIncoherent()){
ps.add(From.fromP(e.getOriginal(),ph));
}
assert !ps.isEmpty();
Member notInterf=null;
Program p1=p.addAtTop(candidate);
for(Path pi:ps){
ClassB cb=p1.extractCb(pi);
System.out.println(pi);
System.out.println(i);
System.out.println(cb.getStage());
System.out.println(candidate.getStage());
Optional<Member> currentOpt=Program.getIfInDom(cb.getMs(),i.getGuilty());
Member current=currentOpt.get();
if(cb.isInterface()){
mems.add(current);
}
else notInterf=current;
}
if(notInterf==null){
throw Errors42.errorClassClash(i.getExploredPath(), ps);
}
Member mb=mems.get(0);
throw Errors42.errorMethodClash(i.getExploredPath(), notInterf,mb, true,Collections.emptyList(),true,true,true);
}
}
*/
static ClassB normalizedSum(Program p, ClassB topA, ClassB topB, ClassB a, ClassB b, List<Ast.C> current) {
List<Member> ms = doubleSimetricalMatch(p, topA, topB, a, b, current);
List<ast.Ast.Type> superT = new ArrayList<>(a.getSupertypes());
superT.addAll(b.getSupertypes());
superT = Collections.unmodifiableList(superT);
Doc doc1 = a.getDoc1().sum(b.getDoc1());
//Sum.checkClassClash(p, current, topA, topB, a, b);
boolean isInterface = a.isInterface() || b.isInterface();
Phase accPhase = a.getPhase().acc(b.getPhase());
ExpCore.ClassB res = new ClassB(doc1, isInterface, superT, ms, CollapsePositions.accumulatePos(a.getP(), b.getP()), accPhase, accPhase == Phase.None ? 0 : 1);
res = (ClassB) res.accept(new coreVisitors.CloneVisitor() {
public ExpCore visit(ClassB s) {
if (s.getPhase() == Phase.None) {
return super.visit(s);
}
return super.visit(s.withPhase(accPhase));
}
});
//TODO: remove after new reduction introduced
return res;
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class PlgWrapperGenerator method plgComplete.
public static ClassB plgComplete(List<Ast.C> cs, Program p, ClassB l) throws UnresolvedOverloading, ClassUnfit, MethodUnfit {
//p.top() is topL
List<Member> ms = new ArrayList<>();
for (Member m : l.getMs()) {
if (!(m instanceof NestedClass)) {
ms.add(m);
continue;
}
NestedClass nc = (NestedClass) m;
List<Ast.C> csc = new ArrayList<>(cs);
csc.add(nc.getName());
ms.add(nc.withInner(plgComplete(csc, p, (ClassB) nc.getInner())));
}
return plgComplete1(cs, p, l.withMs(ms));
//forall nested c in l
// l=l[with c=plgComplete(cs:c, p,l.c)
//return plgComplete1(cs,p,l)
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class Translator method useFrom.
//this should take a class, strip out nested and 'from' it so that it is as at top level
static ClassB useFrom(ClassB ct, Path p) {
ArrayList<Member> ms = new ArrayList<Member>();
for (Member m : ct.getMs()) {
m.match(nc -> null, mi -> {
throw Assertions.codeNotReachable();
}, mt -> ms.add(From.from(mt, p)));
}
//for(PathMwt pmwt:ct.getStage().getInherited()){
for (PathMwt pmwt : Collections.<PathMwt>emptyList()) {
if (Functions.getIfInDom(ms, pmwt.getMwt().getMs()).isPresent()) {
continue;
}
ms.add(From.from(pmwt.getMwt(), p));
}
List<Path> sup = tools.Map.of(ti -> (Path) From.fromP(ti.getPath(), p), ct.getSupertypes());
//tools.Map.of(pi->(Path)From.fromP(pi,p),ct.getStage().getInheritedPaths());
List<Path> supAll = sup;
ClassB res = ct.withMs(ms).withSupertypes(tools.Map.of(pi -> pi.toImmNT(), sup));
return res;
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class Translator method add.
public static void add(int level, List<Ast.C> cs, ClassB cb, Map<String, ClassB> map, Program original) {
Ast.Path p = Ast.Path.outer(level, cs);
if (cb.getPhase() == Phase.Coherent && IsCompiled.of(cb)) {
//otherwise is "meta"
//assert cb.getStage().getInheritedPaths()!=null;
ClassB cbUF = useFrom(cb, p);
if (!cs.isEmpty()) {
//ok to ignore empty ones, since not complete?
map.put(Resources.nameOf(level, cs), cbUF);
}
} else {
//generate only for metaprogramming //Can be ignored now with typemap
/*ExpCore.ClassB cbMP = new ExpCore.ClassB(
Doc.factory("##@DebugInfo: is interface since (cb.getStage()!=Stage.Star :"
+(cb.getStage().getStage()!=Stage.Star)+") or since !IsCompiled.of(cb) :"+!IsCompiled.of(cb)+")"
),Doc.empty(),true,Collections.emptyList(),Collections.emptyList(),new Util.CachedStage());
cbMP.getStage().setInheritedPaths(Collections.emptyList());
cbMP.getStage().setInherited(Collections.emptyList());
assert cbMP.getStage().getInheritedPaths()!=null;
map.put(Resources.nameOf(level,cs),cbMP);
*/
}
for (Member m : cb.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
if (!(nc.getInner() instanceof ClassB)) {
continue;
}
if (cs.isEmpty() && level > 0) {
if (nc.getInner() == original.get(level - 1)) {
continue;
}
//avoid generation of multiple versions of the same thing
}
ArrayList<Ast.C> newCs = new ArrayList<>(cs);
newCs.add(nc.getName());
add(level, newCs, (ClassB) nc.getInner(), map, original);
}
}
use of ast.ExpCore.ClassB.Member in project L42 by ElvisResearchGroup.
the class Rename method redirectDefinition.
private static ClassB redirectDefinition(List<Ast.C> src, List<Ast.C> dest, ClassB lprime) {
assert !src.isEmpty();
assert !dest.isEmpty();
NestedClass nsCb = lprime.getNested(src);
Path toFrom = Path.outer(dest.size() - 1, src.subList(0, src.size() - 1));
ClassB cb = (ClassB) FromInClass.of((ClassB) nsCb.getInner(), toFrom);
List<Member> ms = new ArrayList<>();
ms.add(Functions.encapsulateIn(dest, cb, nsCb.getDoc()));
return ClassB.membersClass(ms, Position.noInfo, lprime.getPhase());
}
Aggregations