Skip to content

Commit fcaa941

Browse files
committed
Save Context History
1 parent 2a8f9b7 commit fcaa941

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

liquidjava-verifier/src/main/java/liquidjava/processor/context/ContextHistory.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77

88
import spoon.reflect.cu.SourcePosition;
99
import spoon.reflect.declaration.CtElement;
10-
import spoon.reflect.declaration.CtExecutable;
1110

1211
public class ContextHistory {
1312
private static ContextHistory instance;
14-
15-
private Map<String, Map<String, Set<RefinedVariable>>> fileScopeVars; // file -> (scope -> variables in scope)
13+
14+
private Map<String, Set<RefinedVariable>> vars; // scope -> variables in scope
1615
private Set<RefinedVariable> instanceVars;
1716
private Set<RefinedVariable> globalVars;
1817
private Set<GhostState> ghosts;
1918
private Set<AliasWrapper> aliases;
2019

2120
private ContextHistory() {
22-
fileScopeVars = new HashMap<>();
21+
vars = new HashMap<>();
2322
instanceVars = new HashSet<>();
2423
globalVars = new HashSet<>();
2524
ghosts = new HashSet<>();
@@ -33,7 +32,7 @@ public static ContextHistory getInstance() {
3332
}
3433

3534
public void clearHistory() {
36-
fileScopeVars.clear();
35+
vars.clear();
3736
instanceVars.clear();
3837
globalVars.clear();
3938
ghosts.clear();
@@ -44,33 +43,17 @@ public void saveContext(CtElement element, Context context) {
4443
SourcePosition pos = element.getPosition();
4544
if (pos == null || pos.getFile() == null)
4645
return;
47-
48-
// add variables in scope for this position
49-
String file = pos.getFile().getAbsolutePath();
50-
String scope = getScopePosition(element);
51-
fileScopeVars.putIfAbsent(file, new HashMap<>());
52-
fileScopeVars.get(file).put(scope, new HashSet<>(context.getCtxVars()));
53-
54-
// add other elements in context
46+
47+
String scope = String.format("%s:%d:%d", pos.getFile().getName(), pos.getLine(), pos.getColumn());
48+
vars.put(scope, new HashSet<>(context.getCtxVars()));
5549
instanceVars.addAll(context.getCtxInstanceVars());
5650
globalVars.addAll(context.getCtxGlobalVars());
5751
ghosts.addAll(context.getGhostStates());
5852
aliases.addAll(context.getAliases());
5953
}
6054

61-
public String getScopePosition(CtElement element) {
62-
SourcePosition pos = element.getPosition();
63-
SourcePosition innerPosition = pos;
64-
if (element instanceof CtExecutable<?> executable) {
65-
if (executable.getBody() != null)
66-
innerPosition = executable.getBody().getPosition();
67-
}
68-
return String.format("%d:%d-%d:%d", innerPosition.getLine(), innerPosition.getColumn() + 1, pos.getEndLine(),
69-
pos.getEndColumn());
70-
}
71-
72-
public Map<String, Map<String, Set<RefinedVariable>>> getFileScopeVars() {
73-
return fileScopeVars;
55+
public Map<String, Set<RefinedVariable>> getVars() {
56+
return vars;
7457
}
7558

7659
public Set<RefinedVariable> getInstanceVars() {

0 commit comments

Comments
 (0)