Skip to content

Commit dd127c6

Browse files
committed
Save Ghosts By File
1 parent 07a4c63 commit dd127c6

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/ExternalRefinementTypeChecker.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import liquidjava.diagnostics.warnings.ExternalClassNotFoundWarning;
99
import liquidjava.diagnostics.warnings.ExternalMethodNotFoundWarning;
1010
import liquidjava.processor.context.Context;
11+
import liquidjava.processor.context.ContextHistory;
1112
import liquidjava.processor.context.GhostFunction;
1213
import liquidjava.processor.facade.GhostDTO;
1314
import liquidjava.processor.refinement_checker.general_checkers.MethodsFunctionsChecker;
@@ -27,8 +28,9 @@
2728
import spoon.reflect.reference.CtTypeReference;
2829

2930
public class ExternalRefinementTypeChecker extends TypeChecker {
30-
String prefix;
31-
Diagnostics diagnostics = Diagnostics.getInstance();
31+
private String prefix;
32+
private final Diagnostics diagnostics = Diagnostics.getInstance();
33+
private final ContextHistory contextHistory = ContextHistory.getInstance();
3234

3335
public ExternalRefinementTypeChecker(Context context, Factory factory) {
3436
super(context, factory);

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/TypeChecker.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import liquidjava.diagnostics.errors.*;
1010
import liquidjava.processor.context.AliasWrapper;
1111
import liquidjava.processor.context.Context;
12+
import liquidjava.processor.context.ContextHistory;
1213
import liquidjava.processor.context.GhostFunction;
1314
import liquidjava.processor.context.GhostState;
1415
import liquidjava.processor.context.RefinedVariable;
@@ -40,6 +41,7 @@ public abstract class TypeChecker extends CtScanner {
4041
protected final Context context;
4142
protected final Factory factory;
4243
protected final VCChecker vcChecker;
44+
private final ContextHistory contextHistory = ContextHistory.getInstance();
4345

4446
public TypeChecker(Context context, Factory factory) {
4547
this.context = context;
@@ -158,6 +160,7 @@ private void createStateSet(CtNewArray<String> e, int set, CtElement element) th
158160
gs.setRefinement(Predicate.createEquals(ip, Predicate.createLit(Integer.toString(order), Types.INT)));
159161
// open(THIS) -> state1(THIS) == 1
160162
context.addToGhostClass(g.getParentClassName(), gs);
163+
contextHistory.saveGhost(element, gs);
161164
}
162165
order++;
163166
}
@@ -183,6 +186,7 @@ private void createStateGhost(String string, CtAnnotation<? extends Annotation>
183186
CtTypeReference<?> r = factory.Type().createReference(gd.returnType());
184187
GhostState gs = new GhostState(gd.name(), param, r, qn);
185188
context.addToGhostClass(sn, gs);
189+
contextHistory.saveGhost(element, gs);
186190
}
187191

188192
protected String getQualifiedClassName(CtElement element) {

0 commit comments

Comments
 (0)