Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Amin Bandali
alloy-catalyst
Commits
12512076
Verified
Commit
12512076
authored
May 30, 2019
by
Amin Bandali
Browse files
Don’t add built-in signatures
parent
7fa1cc14
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
17 deletions
+26
-17
org.aminb.alloy.catalyst/src/main/java/org/aminb/alloy/catalyst/SSRVisitor.java
...st/src/main/java/org/aminb/alloy/catalyst/SSRVisitor.java
+26
-17
No files found.
org.aminb.alloy.catalyst/src/main/java/org/aminb/alloy/catalyst/SSRVisitor.java
View file @
12512076
...
...
@@ -2,6 +2,10 @@ package org.aminb.alloy.catalyst;
import
java.util.Map
;
import
java.util.HashMap
;
import
java.util.Set
;
import
java.util.HashSet
;
import
java.util.Arrays
;
import
java.util.Optional
;
import
edu.mit.csail.sdg.alloy4.Pos
;
import
edu.mit.csail.sdg.ast.Decl
;
...
...
@@ -29,22 +33,27 @@ import edu.mit.csail.sdg.ast.VisitReturn;
*/
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
<>();
Optional
<
Boolean
>
putCandidate
(
PrimSig
sig
,
Boolean
viable
)
{
if
(!
builtins
.
contains
(
sig
))
return
Optional
.
of
(
candidates
.
put
(
sig
,
viable
));
else
return
Optional
.
empty
();
}
Optional
<
Boolean
>
putCandidateIfAbsent
(
PrimSig
sig
,
Boolean
viable
)
{
if
(!
builtins
.
contains
(
sig
))
return
Optional
.
of
(
candidates
.
putIfAbsent
(
sig
,
viable
));
else
return
Optional
.
empty
();
}
PrimSig
getFirstPrimSig
(
Expr
e
)
{
return
e
.
type
()
// :: Type
...
...
@@ -73,7 +82,7 @@ public class SSRVisitor extends VisitReturn {
if
(
x
.
op
==
ExprBinary
.
Op
.
JOIN
)
if
(
x
.
left
instanceof
ExprUnary
&&
x
.
right
instanceof
ExprUnary
)
if
(!
isFieldAccess
(
x
))
c
andidate
s
.
put
(
getFirstPrimSig
(
x
.
left
),
false
);
putC
andidate
(
getFirstPrimSig
(
x
.
left
),
false
);
visitThis
(
x
.
left
);
visitThis
(
x
.
right
);
return
null
;
...
...
@@ -133,7 +142,7 @@ public class SSRVisitor extends VisitReturn {
Expr
subsub
=
getUnarySub
(
getUnarySub
(
s
));
if
(
subsub
instanceof
PrimSig
)
if
(((
PrimSig
)
subsub
).
getFieldDecls
().
size
()
>
1
)
c
andidate
s
.
put
((
PrimSig
)
subsub
,
false
);
putC
andidate
((
PrimSig
)
subsub
,
false
);
}
}
else
if
(
s
instanceof
PrimSig
)
...
...
@@ -190,7 +199,7 @@ public class SSRVisitor extends VisitReturn {
public
Object
visit
(
Sig
x
)
{
// add the sig as a candidate if we haven't seen it before
if
(
x
instanceof
PrimSig
)
c
andidate
s
.
put
IfAbsent
((
PrimSig
)
x
,
true
);
putC
andidateIfAbsent
((
PrimSig
)
x
,
true
);
return
null
;
}
...
...
@@ -204,7 +213,7 @@ public class SSRVisitor extends VisitReturn {
// after first column
for
(
ProductType
t
:
x
.
type
())
for
(
int
i
=
1
;
i
<
t
.
arity
();
i
++)
c
andidate
s
.
put
(
t
.
get
(
i
),
false
);
putC
andidate
(
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
...
...
Amin Bandali
@bandali
mentioned in commit
536bf76c
·
May 30, 2019
mentioned in commit
536bf76c
mentioned in commit 536bf76ce65ac9a84b53f87ab7c83e3e6aa83aa1
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment