Between Tuesday August 20th, 5:00pm and Thursday August 22nd, 8:00am git.uwaterloo.ca will be down for an upgrade to version 10.8.7.

d8cd05b7 by Amin Bandali

Don’t add built-in signatures, this time without using Optional

1 parent 536bf76c
......@@ -2,6 +2,9 @@
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Arrays;
import edu.mit.csail.sdg.alloy4.Pos;
import edu.mit.csail.sdg.ast.Decl;
......@@ -29,19 +32,10 @@
*/
public class SSRVisitor extends VisitReturn {
// if come to var that's not used in a join field access, toss out its sig?
/**
* new plan:
*
* - gather list of candidate sigs in visit(Sig)
* - all but those who a field of their own or another sig refers to them
* - if in visit(ExprBinary) we detect a "field access" dot join involving
* a sig, let it remain on the list if it is
* - how about ExprQt? when to disallow those that are quantified over?
* - any other cases where it should be allowed?
* - otherwise, remove sig from candidates
*/
Set<PrimSig> builtins =
new HashSet<>(Arrays.asList(Sig.UNIV, Sig.SIGINT, Sig.SEQIDX,
Sig.STRING, Sig.NONE, Sig.GHOST));
Map<PrimSig, Boolean> candidates = new HashMap<>();
......@@ -72,8 +66,11 @@ public Object visit(ExprBinary x) {
// `var in sig', discard candidate
if (x.op == ExprBinary.Op.JOIN)
if (x.left instanceof ExprUnary && x.right instanceof ExprUnary)
if (!isFieldAccess(x))
candidates.put(getFirstPrimSig(x.left), false);
if (!isFieldAccess(x)) {
PrimSig s = getFirstPrimSig(x.left);
if (!builtins.contains(s))
candidates.put(s, false);
}
visitThis(x.left);
visitThis(x.right);
return null;
......@@ -133,7 +130,8 @@ public Object visit(ExprQt x) {
Expr subsub = getUnarySub(getUnarySub(s));
if (subsub instanceof PrimSig)
if (((PrimSig)subsub).getFieldDecls().size() > 1)
candidates.put((PrimSig)subsub, false);
if (!builtins.contains((PrimSig)subsub))
candidates.put((PrimSig)subsub, false);
}
}
else if (s instanceof PrimSig)
......@@ -190,7 +188,8 @@ public Object visit(ExprUnary x) {
public Object visit(Sig x) {
// add the sig as a candidate if we haven't seen it before
if (x instanceof PrimSig)
candidates.putIfAbsent((PrimSig)x, true);
if (!builtins.contains((PrimSig)x) && !candidates.containsKey((PrimSig)x))
candidates.put((PrimSig)x, true);
return null;
}
......@@ -204,7 +203,8 @@ public Object visit(Field x) {
// after first column
for (ProductType t : x.type())
for (int i = 1; i < t.arity(); i++)
candidates.put(t.get(i), false);
if (!builtins.contains(t.get(i)))
candidates.put(t.get(i), false);
// TODO: if type of field refers to another field, in this sig
// or elsewhere, if there are no multiplicity constraints then
......