88public class Context {
99 private Stack <List <RefinedVariable >> ctxVars ;
1010 private List <RefinedFunction > ctxFunctions ;
11- private List <RefinedVariable > ctxSpecificVars ;
12-
11+ private List <RefinedVariable > ctxInstanceVars ;
1312 private final List <RefinedVariable > ctxGlobalVars ;
1413
1514 private List <GhostFunction > ghosts ;
16- private Map <String , List <GhostState >> classStates ;
17- private List <AliasWrapper > alias ;
15+ private Map <String , List <GhostState >> states ;
16+ private List <AliasWrapper > aliases ;
1817
19- public int counter ;
18+ private int counter ;
2019 private static Context instance ;
2120
2221 private Context () {
2322 ctxVars = new Stack <>();
2423 ctxVars .add (new ArrayList <>());
2524 ctxFunctions = new ArrayList <>();
26- ctxSpecificVars = new ArrayList <>();
25+ ctxInstanceVars = new ArrayList <>();
2726 ctxGlobalVars = new ArrayList <>();
2827
29- alias = new ArrayList <>();
28+ aliases = new ArrayList <>();
3029 ghosts = new ArrayList <>();
31- classStates = new HashMap <>();
30+ states = new HashMap <>();
3231 counter = 0 ;
3332 }
3433
@@ -41,15 +40,15 @@ public static Context getInstance() {
4140 public void reinitializeContext () {
4241 ctxVars = new Stack <>();
4342 ctxVars .add (new ArrayList <>()); // global vars
44- ctxSpecificVars = new ArrayList <>();
43+ ctxInstanceVars = new ArrayList <>();
4544 }
4645
4746 public void reinitializeAllContext () {
4847 reinitializeContext ();
4948 ctxFunctions = new ArrayList <>();
50- alias = new ArrayList <>();
49+ aliases = new ArrayList <>();
5150 ghosts = new ArrayList <>();
52- classStates = new HashMap <>();
51+ states = new HashMap <>();
5352 counter = 0 ;
5453 }
5554
@@ -80,7 +79,7 @@ public Map<String, CtTypeReference<?>> getContext() {
8079 ret .put (var .getName (), var .getType ());
8180 }
8281 }
83- for (RefinedVariable var : ctxSpecificVars )
82+ for (RefinedVariable var : ctxInstanceVars )
8483 ret .put (var .getName (), var .getType ());
8584 for (RefinedVariable var : ctxGlobalVars )
8685 ret .put (var .getName (), var .getType ());
@@ -94,6 +93,10 @@ public void addGlobalVariableToContext(String simpleName, String location, CtTyp
9493 ctxGlobalVars .add (vi );
9594 }
9695
96+ public List <RefinedVariable > getCtxGlobalVars () {
97+ return ctxGlobalVars ;
98+ }
99+
97100 // ---------------------- Add variables and instances ----------------------
98101 public void addVarToContext (RefinedVariable var ) {
99102 ctxVars .peek ().add (var );
@@ -114,8 +117,8 @@ public RefinedVariable addInstanceToContext(String simpleName, CtTypeReference<?
114117 CtElement placementInCode ) {
115118 RefinedVariable vi = new VariableInstance (simpleName , type , c );
116119 vi .addPlacementInCode (PlacementInCode .createPlacement (placementInCode ));
117- if (!ctxSpecificVars .contains (vi ))
118- addSpecificVariable (vi );
120+ if (!ctxInstanceVars .contains (vi ))
121+ addInstanceVariable (vi );
119122 return vi ;
120123 }
121124
@@ -154,7 +157,7 @@ public RefinedVariable getVariableByName(String name) {
154157 return var ;
155158 }
156159 }
157- for (RefinedVariable var : ctxSpecificVars ) {
160+ for (RefinedVariable var : ctxInstanceVars ) {
158161 if (var .getName ().equals (name ))
159162 return var ;
160163 }
@@ -188,7 +191,7 @@ public List<RefinedVariable> getAllVariablesWithSupertypes() {
188191 if (!rv .getSuperTypes ().isEmpty ())
189192 lvi .add (rv );
190193 }
191- for (RefinedVariable rv : ctxSpecificVars ) {
194+ for (RefinedVariable rv : ctxInstanceVars ) {
192195 if (!rv .getSuperTypes ().isEmpty ())
193196 lvi .add (rv );
194197 }
@@ -204,7 +207,7 @@ public void addRefinementInstanceToVariable(String name, String instanceName) {
204207
205208 ((Variable ) vi1 ).addInstance ((VariableInstance ) vi2 );
206209 ((VariableInstance ) vi2 ).setParent ((Variable ) vi1 );
207- addSpecificVariable (vi2 );
210+ addInstanceVariable (vi2 );
208211 }
209212
210213 public Optional <VariableInstance > getLastVariableInstance (String name ) {
@@ -214,14 +217,30 @@ public Optional<VariableInstance> getLastVariableInstance(String name) {
214217 return ((Variable ) rv ).getLastInstance ();
215218 }
216219
217- public void addSpecificVariable (RefinedVariable vi ) {
218- if (!ctxSpecificVars .contains (vi )) {
219- ctxSpecificVars .add (vi );
220+ public void addInstanceVariable (RefinedVariable vi ) {
221+ if (!ctxInstanceVars .contains (vi )) {
222+ ctxInstanceVars .add (vi );
220223 CtTypeReference <?> type = vi .getType ();
221224 vi .addSuperTypes (type .getSuperclass (), type .getSuperInterfaces ());
222225 }
223226 }
224227
228+ public Variable getVariableFromInstance (VariableInstance vi ) {
229+ return vi .getParent ().orElse (null );
230+ }
231+
232+ public List <RefinedVariable > getCtxVars () {
233+ List <RefinedVariable > lvi = new ArrayList <>();
234+ for (List <RefinedVariable > l : ctxVars ) {
235+ lvi .addAll (l );
236+ }
237+ return lvi ;
238+ }
239+
240+ public List <RefinedVariable > getCtxInstanceVars () {
241+ return ctxInstanceVars ;
242+ }
243+
225244 // ---------------------- Variables - if information storing ----------------------
226245 public void variablesSetBeforeIf () {
227246 for (RefinedVariable vi : getAllVariables ())
@@ -290,6 +309,10 @@ public List<RefinedFunction> getAllMethodsWithNameSize(String name, int size) {
290309 return l ;
291310 }
292311
312+ public List <RefinedFunction > getCtxFunctions () {
313+ return ctxFunctions ;
314+ }
315+
293316 // ---------------------- Ghost Predicates ----------------------
294317 public void addGhostFunction (GhostFunction gh ) {
295318 ghosts .add (gh );
@@ -300,35 +323,35 @@ public List<GhostFunction> getGhosts() {
300323 }
301324
302325 public void addGhostClass (String klass ) {
303- if (!classStates .containsKey (klass ))
304- classStates .put (klass , new ArrayList <>());
326+ if (!states .containsKey (klass ))
327+ states .put (klass , new ArrayList <>());
305328 }
306329
307330 public void addToGhostClass (String klass , GhostState gs ) {
308- List <GhostState > l = classStates .get (klass );
331+ List <GhostState > l = states .get (klass );
309332 if (!l .contains (gs ))
310333 l .add (gs );
311334 }
312335
313336 public List <GhostState > getGhostState (String s ) {
314- return classStates .get (s );
337+ return states .get (s );
315338 }
316339
317- public List <GhostState > getGhostState () {
340+ public List <GhostState > getGhostStates () {
318341 List <GhostState > lgs = new ArrayList <>();
319- for (List <GhostState > l : classStates .values ())
342+ for (List <GhostState > l : states .values ())
320343 lgs .addAll (l );
321344 return lgs ;
322345 }
323346
324347 // ---------------------- Alias ----------------------
325348 public void addAlias (AliasWrapper aw ) {
326- if (!alias .contains (aw ))
327- alias .add (aw );
349+ if (!aliases .contains (aw ))
350+ aliases .add (aw );
328351 }
329352
330- public List <AliasWrapper > getAlias () {
331- return alias ;
353+ public List <AliasWrapper > getAliases () {
354+ return aliases ;
332355 }
333356
334357 @ Override
@@ -354,8 +377,4 @@ public String toString() {
354377 sb .append (f .toString ());
355378 return sb .toString ();
356379 }
357-
358- public Variable getVariableFromInstance (VariableInstance vi ) {
359- return vi .getParent ().orElse (null );
360- }
361380}
0 commit comments