Skip to content

Commit a532c05

Browse files
committed
Save Context Vars by File and Scope
1 parent fcaa941 commit a532c05

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
import spoon.reflect.cu.SourcePosition;
99
import spoon.reflect.declaration.CtElement;
10+
import spoon.reflect.declaration.CtExecutable;
11+
import spoon.reflect.declaration.CtMethod;
1012

1113
public class ContextHistory {
1214
private static ContextHistory instance;
1315

14-
private Map<String, Set<RefinedVariable>> vars; // scope -> variables in scope
16+
private Map<String, Map<String, Set<RefinedVariable>>> vars; // file -> (scope -> variables in scope)
1517
private Set<RefinedVariable> instanceVars;
1618
private Set<RefinedVariable> globalVars;
1719
private Set<GhostState> ghosts;
@@ -43,16 +45,28 @@ public void saveContext(CtElement element, Context context) {
4345
SourcePosition pos = element.getPosition();
4446
if (pos == null || pos.getFile() == null)
4547
return;
48+
49+
// add variables in scope for this position
50+
String file = pos.getFile().getAbsolutePath();
51+
String scope = getScopePosition(element);
52+
System.out.println("Saving context for " + file + " in scope " + scope);
53+
vars.putIfAbsent(file, new HashMap<>());
54+
vars.get(file).put(scope, new HashSet<>(context.getCtxVars()));
4655

47-
String scope = String.format("%s:%d:%d", pos.getFile().getName(), pos.getLine(), pos.getColumn());
48-
vars.put(scope, new HashSet<>(context.getCtxVars()));
56+
// add other elements in context
4957
instanceVars.addAll(context.getCtxInstanceVars());
5058
globalVars.addAll(context.getCtxGlobalVars());
5159
ghosts.addAll(context.getGhostStates());
5260
aliases.addAll(context.getAliases());
5361
}
5462

55-
public Map<String, Set<RefinedVariable>> getVars() {
63+
public String getScopePosition(CtElement element) {
64+
SourcePosition pos = element.getPosition();
65+
SourcePosition innerPosition = element instanceof CtExecutable ? ((CtExecutable<?>) element).getBody().getPosition() : pos;
66+
return String.format("%d:%d-%d:%d", innerPosition.getLine(), innerPosition.getColumn() + 1, pos.getEndLine(), pos.getEndColumn());
67+
}
68+
69+
public Map<String, Map<String, Set<RefinedVariable>>> getVars() {
5670
return vars;
5771
}
5872

0 commit comments

Comments
 (0)