Rule out signatures used in opens

parent 87256879
......@@ -213,7 +213,7 @@ public final class SSR extends CatalystCommand implements Runnable {
}
private SSRResult detectRemovableSigs(CompModule world) {
SSRVisitor v = new SSRVisitor();
SSRVisitor v = new SSRVisitor(world);
world.visitExpressions(v);
SSRResult r = new SSRResult();
r.sig_count = v.candidates.size();
......
......@@ -43,6 +43,7 @@ import edu.mit.csail.sdg.ast.Sig.Field;
import edu.mit.csail.sdg.ast.Sig.PrimSig;
import edu.mit.csail.sdg.ast.Type.ProductType;
import edu.mit.csail.sdg.ast.VisitReturn;
import edu.mit.csail.sdg.parser.CompModule;
/**
......@@ -52,6 +53,11 @@ import edu.mit.csail.sdg.ast.VisitReturn;
public class SSRVisitor extends VisitReturn<Object> {
Map<PrimSig, Boolean> candidates = new LinkedHashMap<>();
private CompModule world;
public SSRVisitor(CompModule world) {
this.world = world;
}
PrimSig getFirstPrimSig(Expr e) {
return
......@@ -73,6 +79,14 @@ public class SSRVisitor extends VisitReturn<Object> {
&& getFirstPrimSig(l) == getFirstPrimSig(r));
}
boolean isUsedInOpen(Sig s) {
for (CompModule.Open o : world.getOpens())
for (String arg : o.args)
if (s == world.getAllSigsMap().get(arg))
return true;
return false;
}
/** Visits an ExprBinary node. */
@Override
public Object visit(ExprBinary x) {
......@@ -82,7 +96,7 @@ public class SSRVisitor extends VisitReturn<Object> {
if (x.left instanceof ExprUnary && x.right instanceof ExprUnary)
if (isFieldAccess(x)) {
PrimSig s = getFirstPrimSig(x.left);
if (!s.builtin)
if (!(s.builtin || isUsedInOpen(s)))
candidates.put(s, true);
}
}
......@@ -224,7 +238,6 @@ public class SSRVisitor extends VisitReturn<Object> {
/** Visits a Sig node. */
@Override
public Object visit(Sig x) {
// add the sig as a candidate if we haven't seen it before
if (x instanceof PrimSig) {
PrimSig px = (PrimSig)x;
/*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment