use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class ReplState method add.
public ReplState add(String code) {
Expression.ClassB cbEmpty = new ClassB(Doc.empty(), new ast.Ast.InterfaceHeader(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Position.noInfo);
try {
//parse
Expression.ClassB codeTmp = (ClassB) Parser.parse("Repl", "{" + code + "}");
//new original
ClassReuse newOriginal = this.originalL;
List<ast.Expression.ClassB.Member> newOriginalMs = newOriginal.getInner().getMs();
newOriginalMs.addAll(codeTmp.getMs());
newOriginal.withInner(newOriginal.getInner().withMs(newOriginalMs));
//new src to desugar
List<ClassB.Member> newMs = new ArrayList<>();
int nestedAdded = 0;
for (Member m : this.desugaredL.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
newMs.add(new ClassB.NestedClass(Doc.empty(), nc.getName(), cbEmpty, nc.getP()));
nestedAdded += 1;
}
newMs.addAll(codeTmp.getMs());
codeTmp = codeTmp.withMs(newMs);
Expression code2 = Desugar.of(codeTmp);
ExpCore.ClassB code3 = (ExpCore.ClassB) code2.accept(new InjectionOnCore());
// TODO: will die after new reduction Refresh of position identities, it is used to generate correct Java code.
code3 = (ExpCore.ClassB) code3.accept(new CloneVisitor() {
@Override
public ExpCore visit(ExpCore.ClassB cb) {
Position p = cb.getP();
cb = cb.withP(new Position(p.getFile(), p.getLine1(), p.getPos1(), p.getLine2(), p.getPos2(), p.get_next()));
return super.visit(cb);
}
});
//integrate new desugared src with old desugared code
List<Member> resultMs = new ArrayList<>(this.desugaredL.getMs());
for (int i = nestedAdded; i < code3.getMs().size(); i++) {
resultMs.add(code3.getMs().get(i));
}
code3 = code3.withMs(resultMs);
//call the repl and return
ExpCore.ClassB result = ProgramReduction.allSteps(code3);
return new ReplState(this.originalS + "\n" + code, newOriginal, result);
} catch (ParseCancellationException parser) {
System.out.println(parser.getMessage());
return null;
} catch (ErrorMessage msg) {
ErrorFormatter.topFormatErrorMessage(msg);
return null;
}
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class CtxL method _split.
public static CtxL _split(ExpCore.ClassB l) {
int pos = firstNotCompiled(l.getMs());
if (pos == l.getMs().size()) {
return null;
}
Member m = l.getMs().get(pos);
ExpCore inner = m.getInner();
boolean metaReady = m instanceof NestedClass && IsCompiled.of(m.getInner());
CtxC innerSplit;
if (metaReady) {
innerSplit = CtxC.hole(inner);
} else {
innerSplit = CtxC.split(inner);
}
return new CtxL(l, pos, innerSplit);
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class RemoveCode method collectPaths.
private static void collectPaths(Set<List<Ast.C>> accumulator, List<Ast.C> path, ClassB cb) {
accumulator.add(path);
for (Member m : cb.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
List<Ast.C> pathi = new ArrayList<>(path);
pathi.add(nc.getName());
collectPaths(accumulator, pathi, (ClassB) nc.getInner());
}
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class RemoveCode method collectDepNested.
private static ClassB collectDepNested(Set<List<Ast.C>> justAdded, ClassB originalCb, ClassB accumulator, ClassB depSource, List<Ast.C> origin) {
List<List<Ast.C>> dep = collectDep(depSource, origin);
for (List<Ast.C> pi : dep) {
if (justAdded.contains(pi)) {
continue;
}
justAdded.add(pi);
accumulator = addDep(accumulator, pi, originalCb);
}
assert dep != null : "to break";
for (Member m : depSource.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
ClassB cbi = (ClassB) nc.getInner();
List<Ast.C> newOrigin = new ArrayList<>(origin);
newOrigin.add(nc.getName());
accumulator = collectDepNested(justAdded, originalCb, accumulator, cbi, newOrigin);
}
return accumulator;
}
use of ast.ExpCore.ClassB.NestedClass in project L42 by ElvisResearchGroup.
the class RemoveCode method removeAllButPath.
private static ClassB removeAllButPath(List<Ast.C> path, ClassB originalCb) {
if (path.isEmpty()) {
List<Member> ms = new ArrayList<>();
for (Member m : originalCb.getMs()) {
if (m instanceof NestedClass) {
continue;
}
ms.add(m);
}
return originalCb.withMs(ms);
}
Ast.C firstName = path.get(0);
List<Member> ms = new ArrayList<>();
for (Member m : originalCb.getMs()) {
if (!(m instanceof NestedClass)) {
continue;
}
NestedClass nc = (NestedClass) m;
if (!nc.getName().equals(firstName)) {
continue;
}
ClassB newInner = removeAllButPath(path.subList(1, path.size()), (ClassB) nc.getInner());
ms.add(nc.withInner(newInner));
}
return ClassB.membersClass(ms, Position.noInfo, originalCb.getPhase());
}
Aggregations