use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class TsLibrary method libraryWellTyped.
default default TOut libraryWellTyped(TIn in) {
// (library well typed)
// Phase |- p ~> L' //In implementation, if p.top().Phase>=Phase, L'=p.Top()
ClassB top = in.p.top();
assert // Phase in {Typed,Coherent}
in.phase.subtypeEq(Phase.Typed) : "";
if (top.getPhase().subtypeEq(in.phase)) {
return new TOk(in, top, Path.Library().toImmNT());
}
// L0={interface? implements Ps M1..Mn Phase'}=norm(p)
// L'={interface? implements Ps M1'..Mn' max(Phase',Phase)}
ClassB L0 = normTopL(in);
List<MethodWithType> mwts = L0.mwts();
List<NestedClass> ns = L0.ns();
List<NestedClass> newNs = new ArrayList<>();
// forall i in 1..n
// Phase| p| Ps |- Mi ~> Mi'
TIn inNested = in.withP(in.p.updateTop(L0));
List<MethodWithType> newMwts;
if (in.phase == Phase.Coherent && top.getPhase() == Phase.Typed) {
newMwts = new ArrayList<>(mwts);
} else {
newMwts = new ArrayList<>();
for (MethodWithType mwt : mwts) {
TOutM out = memberMethod(inNested, L0.getSupertypes(), mwt);
if (!out.isOk()) {
return out.toError();
}
newMwts.add((MethodWithType) out.toOkM().inner);
}
}
for (NestedClass nt : ns) {
TOutM out = memberNested(inNested, nt);
if (!out.isOk()) {
return out.toError();
}
newNs.add((NestedClass) out.toOkM().inner);
}
Phase maxPhase = L0.getPhase();
if (in.phase.subtypeEq(maxPhase)) {
maxPhase = in.phase;
}
ClassB L1 = new ClassB(L0.getDoc1(), L0.isInterface(), L0.getSupertypes(), newMwts, newNs, L0.getP(), maxPhase, L0.getUniqueId());
if (in.phase == Phase.Coherent) {
boolean isCoh = coherent(in.p.updateTop(L1), true);
if (!isCoh) {
return new TErr(in, "", Path.Library().toImmNT(), ErrorKind.LibraryNotCoherent);
}
}
// //or error not coherent set of abstr. methods:list
return new TOk(in, L1, Path.Library().toImmNT());
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class ErrorFormatter method whyIsNotExecutable.
private static String whyIsNotExecutable(ClassB cb) {
/*if(cb.getH() instanceof Ast.TraitHeader){
return "\n The requested path is a trait";
}*/
for (Member m : cb.getMs()) {
if (!(m instanceof MethodWithType)) {
continue;
}
/*MethodWithType mt=(MethodWithType)m;
if (!mt.getInner().isPresent() && !mt.isFieldGenerated()){
return "\n The method "+mt.getMs()+" of the requested path is abstract";
}*/
}
for (Member m : cb.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
if (!(nc.getInner() instanceof ClassB)) {
return "\n The nested class " + nc.getName() + " of the requested path is not compiled yet";
}
String nestedRes = whyIsNotExecutable((ClassB) nc.getInner());
if (nestedRes != null) {
return "." + nc.getName() + nestedRes;
}
}
return null;
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class TestHelper method _dbgCompact.
/*
static class LoggedPrintStream extends PrintStream {
final StringBuilder buf;
final PrintStream underlying;
LoggedPrintStream(StringBuilder sb, OutputStream os, PrintStream ul) {
super(os);
this.buf = sb;
this.underlying = ul;
}
public static LoggedPrintStream create(PrintStream toLog) {//from http://stackoverflow.com/questions/4334808/how-could-i-read-java-console-output-into-a-string-buffer
try {
final StringBuilder sb = new StringBuilder();
Field f = FilterOutputStream.class.getDeclaredField("out");
f.setAccessible(true);
OutputStream psout = (OutputStream) f.get(toLog);
return new LoggedPrintStream(sb, new FilterOutputStream(psout) {
public void write(int b) throws IOException {
super.write(b);
sb.append((char) b);
}
}, toLog);
}
catch (NoSuchFieldException|IllegalArgumentException |IllegalAccessException e) {
throw Assertions.codeNotReachable();
}}}*/
public static void _dbgCompact(ExpCore e) {
assert e instanceof ClassB;
ClassB cb = (ClassB) e;
ArrayList<Member> ms = new ArrayList<>();
for (Member m : cb.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
if ((nc.getInner() instanceof ClassB)) {
continue;
}
ms.add(nc);
break;
}
cb = cb.withMs(ms);
System.out.println(ToFormattedText.of(cb));
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class ProgramReduction method step.
static Program step(Program p) {
//precondition: at top level we have a L not of form LC
assert !IsCompiled.of(p.top());
CtxL top = CtxL._split(p.top());
assert top != null;
Member m = top.originalCtxM();
assert !IsCompiled.of(m);
ExpCore hole = top.originalHole();
if (hole instanceof ClassB) {
assert !IsCompiled.of(hole);
return enter(p, top, m);
}
ClassB.NestedClass nc = (NestedClass) m;
return top(p, nc);
}
use of ast.ExpCore.ClassB.NestedClass 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