use of ast.ExpCore._void in project L42 by ElvisResearchGroup.
the class UsedPaths method collectNotAnyPaths.
private static List<Ast.Path> collectNotAnyPaths(Program p, ExpCore e) {
class HeuristicForNotAnyPathsSplit extends PropagatorVisitor {
public Void visit(ClassB s) {
return null;
}
protected List<Path> paths = new ArrayList<Path>();
private void add(Path p) {
this.paths.add(p);
}
//non determinism heuristic:
//**if P.m(_) inside e, P not Any
public Void visit(MCall s) {
Path p = justPath(s.getInner());
if (p != null) {
add(p);
}
return super.visit(s);
}
//**if ( _ T x=P _ _) inside e and T!=class Any, P not Any.
//**if (mdf P x=_ _) inside e, P not Any
protected void liftDec(Block.Dec s) {
if (s.getT().isPresent()) {
Path pt = s.getT().get().getPath();
if (!pt.isPrimitive()) {
add(pt);
}
}
Path p = justPath(s.getInner());
if (p != null) {
add(p);
}
super.liftDec(s);
}
private Path justPath(ExpCore e) {
if (e instanceof ExpCore.EPath) {
if (!((ExpCore.EPath) e).getInner().isPrimitive()) {
return ((ExpCore.EPath) e).getInner();
}
}
if (e instanceof ExpCore.Block) {
return justPath(((ExpCore.Block) e).getInner());
}
return null;
}
//**if p(Pi).Cache=Typed, Pi is not Any
@Override
protected void liftP(Path s) {
if (s.isPrimitive()) {
return;
}
try {
if (p.extractClassB(s).getPhase() == Phase.Typed) {
super.liftP(s);
return;
}
} catch (ErrorMessage.PathMetaOrNonExistant pne) {
/*we do not rise this error while computing the heuristic*/
}
}
//**if using P _ _ inside e, P not Any
public Void visit(ExpCore.Using s) {
if (!s.getPath().isPrimitive()) {
add(s.getPath());
}
return super.visit(s);
}
//**if catch T inside e, T.P not Any
protected void liftO(ExpCore.Block.On on) {
Path pOn = on.getT().getPath();
if (!pOn.isPrimitive()) {
add(pOn);
}
super.liftO(on);
}
List<Path> result(ExpCore e) {
e.accept(this);
return this.paths;
}
}
return new HeuristicForNotAnyPathsSplit().result(e);
}
use of ast.ExpCore._void 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._void in project L42 by ElvisResearchGroup.
the class CtxSplitter method visit.
//method call: if receiver, otherwise a point in parameters
public CtxC visit(MCall s) {
ExpCore r = s.getInner();
if (!IsCompiled.of(r)) {
return new CtxCInner<MCall>(s, r.accept(this));
}
int pos = firstNotCompiled(s.getEs());
return new CtxCMCallPos(s, pos, s.getEs().get(pos).accept(this));
}
use of ast.ExpCore._void in project L42 by ElvisResearchGroup.
the class CtxSplitter method _equals.
default default boolean _equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CtxC other = (CtxC) obj;
ExpCore oE = other.fillHole(new ExpCore.WalkBy());
ExpCore thisE = this.fillHole(new ExpCore.WalkBy());
return thisE.equals(oE);
}
use of ast.ExpCore._void in project L42 by ElvisResearchGroup.
the class InjectionOnCore method visit.
public ExpCore visit(Expression.Using s) {
assert !s.getPs().getE().isPresent();
List<String> xs = s.getPs().getXs();
List<ExpCore> es = new ArrayList<>();
for (Expression e : s.getPs().getEs()) {
es.add(e.accept(this));
}
return new Using(s.getPath(), MethodSelector.of(s.getName(), xs), s.getDocs(), es, s.getInner().accept(this));
}
Aggregations