@@ -96,30 +96,36 @@ private Optional<FunctionInvocation> stateOf(Expression set, Expression name) th
9696 /**
9797 * {@code expression} with each state of a named set, {@code open(e)}, written as a value of its set,
9898 * {@code phase(e) == open}, and {@code !open(e)} as {@code phase(e) != open}, for display. A state keeps the
99- * shorthand when its set has a generated name, such as {@code state1}, or when sets with different names have a
100- * state of that name
99+ * shorthand when its set has a generated name, such as {@code state1}, when sets with different names have a state
100+ * of that name, or when a ghost that is not a state has that name: the name alone does not tell which it is
101+ *
102+ * @param ghosts
103+ * the ghosts that are not states, and the state set functions
101104 */
102- public static Expression toSetForm (Expression expression , List <GhostState > states ) {
103- return rewriteToSetForm (expression .clone (), states );
105+ public static Expression toSetForm (Expression expression , List <GhostState > states , List < GhostFunction > ghosts ) {
106+ return rewriteToSetForm (expression .clone (), states , ghosts );
104107 }
105108
106- private static Expression rewriteToSetForm (Expression e , List <GhostState > states ) {
109+ private static Expression rewriteToSetForm (Expression e , List <GhostState > states , List < GhostFunction > ghosts ) {
107110 if (e instanceof UnaryExpression u && u .getOp ().equals ("!" )) {
108- Optional <BinaryExpression > value = setValue (u .getExpression (), "!=" , states );
111+ Optional <BinaryExpression > value = setValue (u .getExpression (), "!=" , states , ghosts );
109112 if (value .isPresent ())
110113 return value .get ();
111114 }
112- Optional <BinaryExpression > value = setValue (e , "==" , states );
115+ Optional <BinaryExpression > value = setValue (e , "==" , states , ghosts );
113116 if (value .isPresent ())
114117 return value .get ();
115118 for (int i = 0 ; i < e .getChildren ().size (); i ++)
116- e .setChild (i , rewriteToSetForm (e .getChildren ().get (i ), states ));
119+ e .setChild (i , rewriteToSetForm (e .getChildren ().get (i ), states , ghosts ));
117120 return e ;
118121 }
119122
120123 /** {@code set(e) op state} when {@code e} is the state {@code state(e)} of a set with one, given name */
121- private static Optional <BinaryExpression > setValue (Expression e , String op , List <GhostState > states ) {
122- if (!(e instanceof FunctionInvocation invocation && invocation .getArgs ().size () == 1 ))
124+ private static Optional <BinaryExpression > setValue (Expression e , String op , List <GhostState > states ,
125+ List <GhostFunction > ghosts ) {
126+ if (!(e instanceof FunctionInvocation invocation && invocation .getArgs ().size () == 1 )
127+ || ghosts .stream ().anyMatch (g -> g .matches (invocation .getName ()))
128+ || states .stream ().anyMatch (s -> s .getParent () == null && s .matches (invocation .getName ())))
123129 return Optional .empty ();
124130 List <String > setNames = states .stream ().filter (s -> s .getParent () != null && s .matches (invocation .getName ()))
125131 .map (s -> s .getParent ().getName ()).distinct ().toList ();
0 commit comments