Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CFAbstractStore#methodValues to CFAbstractStore#methodCallExpressions #6562

Merged
merged 14 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public void insertLockPossiblyHeld(JavaExpression je) {
}
} else if (je instanceof MethodCall) {
MethodCall method = (MethodCall) je;
CFValue current = methodValues.get(method);
CFValue current = methodCallExpressions.get(method);
CFValue value = changeLockAnnoToTop(je, current);
if (value != null) {
methodValues.put(method, value);
methodCallExpressions.put(method, value);
}
} else if (je instanceof ArrayAccess) {
ArrayAccess arrayAccess = (ArrayAccess) je;
Expand Down Expand Up @@ -233,10 +233,10 @@ public void insertValue(
}
} else if (je instanceof MethodCall) {
MethodCall method = (MethodCall) je;
CFValue oldValue = methodValues.get(method);
CFValue oldValue = methodCallExpressions.get(method);
CFValue newValue = value.mostSpecific(oldValue, null);
if (newValue != null) {
methodValues.put(method, newValue);
methodCallExpressions.put(method, newValue);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ Version 3.43.1 (June 3, 2024)

**Implementation details:**

Renamed `CFAbstractStore#methodValues` to
`CFAbstractStore#methodCallExpressions`.

Deprecated `isUnassignableByOtherCode()` in favor of `isAssignableByOtherCode()`.
Deprecated `isUnmodifiableByOtherCode()` in favor of `isModifiableByOtherCode()`.

**Closed issues:**


Version 3.43.0 (May 1, 2024)
----------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ public Map<FieldAccess, V> getFieldValues() {
protected final Map<ArrayAccess, V> arrayValues;

/**
* Information collected about method calls, using the internal representation {@link MethodCall}.
* Information collected about the expressions to which method calls evaluate, using the internal
* representation {@link MethodCall}.
*/
protected final Map<MethodCall, V> methodValues;
protected final Map<MethodCall, V> methodCallExpressions;

/**
* Information collected about <i>classname</i>.class values, using the internal representation
Expand Down Expand Up @@ -142,7 +143,7 @@ protected CFAbstractStore(CFAbstractAnalysis<V, S, ?> analysis, boolean sequenti
localVariableValues = new HashMap<>();
thisValue = null;
fieldValues = new HashMap<>();
methodValues = new HashMap<>();
methodCallExpressions = new HashMap<>();
arrayValues = new HashMap<>();
classValues = new HashMap<>();
this.sequentialSemantics = sequentialSemantics;
Expand All @@ -162,7 +163,7 @@ protected CFAbstractStore(CFAbstractStore<V, S> other) {
localVariableValues = new HashMap<>(other.localVariableValues);
thisValue = other.thisValue;
fieldValues = new HashMap<>(other.fieldValues);
methodValues = new HashMap<>(other.methodValues);
methodCallExpressions = new HashMap<>(other.methodCallExpressions);
arrayValues = new HashMap<>(other.arrayValues);
classValues = new HashMap<>(other.classValues);
sequentialSemantics = other.sequentialSemantics;
Expand Down Expand Up @@ -275,7 +276,7 @@ public void updateForMethodCall(
arrayValues.clear();

// update method values
methodValues.keySet().removeIf(e -> e.isModifiableByOtherCode());
methodCallExpressions.keySet().removeIf(MethodCall::isModifiableByOtherCode);
}

// store information about method call if possible
Expand Down Expand Up @@ -644,10 +645,10 @@ protected void computeNewValueAndInsert(
MethodCall method = (MethodCall) expr;
// Don't store any information if concurrent semantics are enabled.
if (sequentialSemantics) {
V oldValue = methodValues.get(method);
V oldValue = methodCallExpressions.get(method);
V newValue = merger.apply(oldValue, value);
if (newValue != null) {
methodValues.put(method, newValue);
methodCallExpressions.put(method, newValue);
}
}
} else if (expr instanceof ArrayAccess) {
Expand Down Expand Up @@ -764,7 +765,7 @@ public void clearValue(JavaExpression expr) {
fieldValues.remove(fieldAcc);
} else if (expr instanceof MethodCall) {
MethodCall method = (MethodCall) expr;
methodValues.remove(method);
methodCallExpressions.remove(method);
} else if (expr instanceof ArrayAccess) {
ArrayAccess a = (ArrayAccess) expr;
arrayValues.remove(a);
Expand Down Expand Up @@ -794,7 +795,7 @@ public void clearValue(JavaExpression expr) {
return fieldValues.get(fieldAcc);
} else if (expr instanceof MethodCall) {
MethodCall method = (MethodCall) expr;
return methodValues.get(method);
return methodCallExpressions.get(method);
} else if (expr instanceof ArrayAccess) {
ArrayAccess a = (ArrayAccess) expr;
return arrayValues.get(a);
Expand Down Expand Up @@ -856,7 +857,7 @@ public void clearValue(JavaExpression expr) {
if (method == null) {
return null;
}
return methodValues.get(method);
return methodCallExpressions.get(method);
}

/**
Expand Down Expand Up @@ -1002,7 +1003,7 @@ else if (fieldAccess.getField().equals(otherFieldAccess.getField())) {
}

// case 3:
methodValues.clear();
methodCallExpressions.clear();
}

/**
Expand Down Expand Up @@ -1053,7 +1054,7 @@ protected void removeConflicting(ArrayAccess arrayAccess, @Nullable V val) {
}

// case 3:
methodValues.clear();
methodCallExpressions.clear();
}

/**
Expand Down Expand Up @@ -1090,13 +1091,14 @@ protected void removeConflicting(LocalVariable var) {
}
}

Iterator<Map.Entry<MethodCall, V>> methodValuesIterator = methodValues.entrySet().iterator();
while (methodValuesIterator.hasNext()) {
Map.Entry<MethodCall, V> entry = methodValuesIterator.next();
Iterator<Map.Entry<MethodCall, V>> methodCallValuesIterator =
methodCallExpressions.entrySet().iterator();
while (methodCallValuesIterator.hasNext()) {
Map.Entry<MethodCall, V> entry = methodCallValuesIterator.next();
MethodCall otherMethodAccess = entry.getKey();
// case 3:
if (otherMethodAccess.containsSyntacticEqualJavaExpression(var)) {
methodValuesIterator.remove();
methodCallValuesIterator.remove();
}
}
}
Expand Down Expand Up @@ -1220,16 +1222,16 @@ private S upperBound(S other, boolean shouldWiden) {
}
}
}
for (Map.Entry<MethodCall, V> e : other.methodValues.entrySet()) {
for (Map.Entry<MethodCall, V> e : other.methodCallExpressions.entrySet()) {
// information about methods that are only part of one store, but not the other are
// discarded, as one store implicitly contains 'top' for that field.
MethodCall el = e.getKey();
V thisVal = methodValues.get(el);
V thisVal = methodCallExpressions.get(el);
if (thisVal != null) {
V otherVal = e.getValue();
V mergedVal = upperBoundOfValues(otherVal, thisVal, shouldWiden);
if (mergedVal != null) {
newStore.methodValues.put(el, mergedVal);
newStore.methodCallExpressions.put(el, mergedVal);
}
}
}
Expand Down Expand Up @@ -1282,9 +1284,9 @@ protected boolean supersetOf(CFAbstractStore<V, S> other) {
return false;
}
}
for (Map.Entry<MethodCall, V> e : other.methodValues.entrySet()) {
for (Map.Entry<MethodCall, V> e : other.methodCallExpressions.entrySet()) {
MethodCall key = e.getKey();
V value = methodValues.get(key);
V value = methodCallExpressions.get(key);
if (value == null || !value.equals(e.getValue())) {
return false;
}
Expand Down Expand Up @@ -1357,8 +1359,8 @@ protected String internalVisualize(CFGVisualizer<V, S, ?> viz) {
for (ArrayAccess fa : ToStringComparator.sorted(arrayValues.keySet())) {
res.add(viz.visualizeStoreArrayVal(fa, arrayValues.get(fa)));
}
for (MethodCall fa : ToStringComparator.sorted(methodValues.keySet())) {
res.add(viz.visualizeStoreMethodVals(fa, methodValues.get(fa)));
for (MethodCall fa : ToStringComparator.sorted(methodCallExpressions.keySet())) {
res.add(viz.visualizeStoreMethodVals(fa, methodCallExpressions.get(fa)));
}
for (ClassName fa : ToStringComparator.sorted(classValues.keySet())) {
res.add(viz.visualizeStoreClassVals(fa, classValues.get(fa)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public S initialStore(UnderlyingAST underlyingAST, List<LocalVariableNode> param
// store.localVariableValues.clear();
store.classValues.clear();
store.arrayValues.clear();
store.methodValues.clear();
store.methodCallExpressions.clear();
} else {
store = analysis.createEmptyStore(sequentialSemantics);
}
Expand Down