use of coreVisitors.PropagatorVisitor 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);
}
Aggregations