@@ -13,16 +13,18 @@ public class ContextHistory {
1313 private static ContextHistory instance ;
1414
1515 private Map <String , Map <String , Set <RefinedVariable >>> vars ; // file -> (scope -> variables in scope)
16+ private Map <String , Set <GhostState >> ghosts ; // file -> ghosts
17+
18+ // globals
19+ private Set <AliasWrapper > aliases ;
1620 private Set <RefinedVariable > instanceVars ;
1721 private Set <RefinedVariable > globalVars ;
18- private Set <GhostState > ghosts ;
19- private Set <AliasWrapper > aliases ;
2022
2123 private ContextHistory () {
2224 vars = new HashMap <>();
2325 instanceVars = new HashSet <>();
2426 globalVars = new HashSet <>();
25- ghosts = new HashSet <>();
27+ ghosts = new HashMap <>();
2628 aliases = new HashSet <>();
2729 }
2830
@@ -41,23 +43,37 @@ public void clearHistory() {
4143 }
4244
4345 public void saveContext (CtElement element , Context context ) {
44- SourcePosition pos = element . getPosition ( );
45- if (pos == null || pos . getFile () == null )
46+ String file = getFile ( element );
47+ if (file == null )
4648 return ;
4749
48- // add variables in scope for this position
49- String file = pos .getFile ().getAbsolutePath ();
50+ // add variables in scope
5051 String scope = getScopePosition (element );
5152 vars .putIfAbsent (file , new HashMap <>());
5253 vars .get (file ).put (scope , new HashSet <>(context .getCtxVars ()));
5354
54- // add other elements in context
55+ // add other elements in context (except ghosts)
5556 instanceVars .addAll (context .getCtxInstanceVars ());
5657 globalVars .addAll (context .getCtxGlobalVars ());
57- ghosts .addAll (context .getGhostStates ());
5858 aliases .addAll (context .getAliases ());
5959 }
6060
61+ public void saveGhost (CtElement element , GhostState ghost ) {
62+ String file = getFile (element );
63+ if (file == null )
64+ return ;
65+ ghosts .putIfAbsent (file , new HashSet <>());
66+ ghosts .get (file ).add (ghost );
67+ }
68+
69+ private String getFile (CtElement element ) {
70+ SourcePosition pos = element .getPosition ();
71+ if (pos == null || pos .getFile () == null )
72+ return null ;
73+
74+ return pos .getFile ().getAbsolutePath ();
75+ }
76+
6177 public String getScopePosition (CtElement element ) {
6278 SourcePosition pos = element .getPosition ();
6379 SourcePosition innerPosition = pos ;
@@ -81,7 +97,7 @@ public Set<RefinedVariable> getGlobalVars() {
8197 return globalVars ;
8298 }
8399
84- public Set <GhostState > getGhosts () {
100+ public Map < String , Set <GhostState > > getGhosts () {
85101 return ghosts ;
86102 }
87103
0 commit comments