Skip to content

Commit 6b0574c

Browse files
committed
Save Scopes by File
1 parent 816df6b commit 6b0574c

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
public class ContextHistory {
1414
private static ContextHistory instance;
1515

16-
private Map<String, Map<String, Set<RefinedVariable>>> fileScopeVars; // file -> (scope -> variables in scope)
16+
private Map<String, Set<String>> fileScopes;
17+
private Set<RefinedVariable> localVars;
1718
private Set<GhostState> ghosts;
1819
private Set<AliasWrapper> aliases;
19-
private Set<RefinedVariable> instanceVars;
2020
private Set<RefinedVariable> globalVars;
2121

2222
private ContextHistory() {
23-
fileScopeVars = new HashMap<>();
24-
instanceVars = new HashSet<>();
23+
fileScopes = new HashMap<>();
24+
localVars = new HashSet<>();
2525
globalVars = new HashSet<>();
2626
ghosts = new HashSet<>();
2727
aliases = new HashSet<>();
@@ -34,8 +34,8 @@ public static ContextHistory getInstance() {
3434
}
3535

3636
public void clearHistory() {
37-
fileScopeVars.clear();
38-
instanceVars.clear();
37+
fileScopes.clear();
38+
localVars.clear();
3939
globalVars.clear();
4040
ghosts.clear();
4141
aliases.clear();
@@ -46,13 +46,14 @@ public void saveContext(CtElement element, Context context) {
4646
if (file == null)
4747
return;
4848

49-
// add variables in scope
49+
// add scope
5050
String scope = getScopePosition(element);
51-
fileScopeVars.putIfAbsent(file, new HashMap<>());
52-
fileScopeVars.get(file).put(scope, new HashSet<>(context.getCtxVars()));
51+
fileScopes.putIfAbsent(file, new HashSet<>());
52+
fileScopes.get(file).add(scope);
5353

54-
// add other elements in context (except ghosts)
55-
instanceVars.addAll(context.getCtxInstanceVars());
54+
// add variables, ghosts and aliases
55+
localVars.addAll(context.getCtxVars());
56+
localVars.addAll(context.getCtxInstanceVars());
5657
globalVars.addAll(context.getCtxGlobalVars());
5758
ghosts.addAll(context.getGhostStates());
5859
aliases.addAll(context.getAliases());
@@ -62,16 +63,12 @@ private String getScopePosition(CtElement element) {
6263
CtElement startElement = element instanceof CtParameter<?> ? element.getParent() : element;
6364
SourcePosition annPosition = Utils.getFirstLJAnnotationPosition(startElement);
6465
SourcePosition pos = element.getPosition();
65-
return String.format("%d:%d-%d:%d", annPosition.getLine() - 1, annPosition.getColumn() - 1,
66-
pos.getEndLine() - 1, pos.getEndColumn() - 1);
66+
return String.format("%d:%d-%d:%d", annPosition.getLine(), annPosition.getColumn(), pos.getEndLine(),
67+
pos.getEndColumn());
6768
}
6869

69-
public Map<String, Map<String, Set<RefinedVariable>>> getFileScopeVars() {
70-
return fileScopeVars;
71-
}
72-
73-
public Set<RefinedVariable> getInstanceVars() {
74-
return instanceVars;
70+
public Set<RefinedVariable> getLocalVars() {
71+
return localVars;
7572
}
7673

7774
public Set<RefinedVariable> getGlobalVars() {
@@ -85,4 +82,8 @@ public Set<GhostState> getGhosts() {
8582
public Set<AliasWrapper> getAliases() {
8683
return aliases;
8784
}
85+
86+
public Map<String, Set<String>> getFileScopes() {
87+
return fileScopes;
88+
}
8889
}

0 commit comments

Comments
 (0)