Skip to content

Commit f502834

Browse files
Name the comparisons of Known Enum Values for what they are
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 09fafd4 commit f502834

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎liquidjava-verifier/src/main/java/liquidjava/rj_language/opt/VCKnownEnumValues.java‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
public class VCKnownEnumValues implements VCSimplificationPass {
2727

2828
/**
29-
* A fact {@code variable == constant}, or {@code variable != constant} when not {@code equal}
29+
* A comparison {@code variable == constant}, or {@code variable != constant} when not {@code equal}
3030
*/
31-
private record KnownValue(Expression fact, String variable, String constant, boolean equal) {
31+
private record EnumComparison(Expression expression, String variable, String constant, boolean equal) {
3232
}
3333

3434
/** The enum type of each enum constant, by the name the solver translates the constant from */
@@ -43,40 +43,40 @@ public VCKnownEnumValues(VCImplication implication) {
4343
}
4444

4545
/**
46-
* Decides the comparisons that the first fact deciding any decides
46+
* Uses the first fact that decides some comparison to replace those comparisons by their value
4747
*/
4848
@Override
4949
public VCImplication apply(VCImplication implication) {
5050
for (VCImplication row = implication; row != null; row = row.getNext())
5151
for (Expression fact : factsOf(row.getRefinement().getExpression())) {
52-
KnownValue known = knownValue(fact);
52+
EnumComparison known = enumComparison(fact);
5353
if (known == null)
5454
continue;
5555
// the last row may be the conclusion, which the other rows cannot assume
5656
boolean onlyLastRow = row.getNext() == null && row != implication;
57-
VCImplication decided = decide(implication, known, onlyLastRow);
57+
VCImplication decided = decideRows(implication, known, onlyLastRow);
5858
if (!decided.equals(implication))
5959
return decided;
6060
}
6161
return implication;
6262
}
6363

64-
private VCImplication decide(VCImplication implication, KnownValue known, boolean onlyLastRow) {
64+
private VCImplication decideRows(VCImplication implication, EnumComparison known, boolean onlyLastRow) {
6565
if (implication == null)
6666
return null;
6767
Expression expression = implication.getRefinement().getExpression();
6868
boolean decides = !onlyLastRow || implication.getNext() == null;
6969
VCImplication result = copyWithRefinement(implication,
7070
new Predicate(decides ? decide(expression, known) : expression.clone()));
71-
result.setNext(decide(implication.getNext(), known, onlyLastRow));
71+
result.setNext(decideRows(implication.getNext(), known, onlyLastRow));
7272
return result;
7373
}
7474

7575
// The expression with the comparisons known decides replaced by their value, except for its own fact
76-
private Expression decide(Expression expression, KnownValue known) {
77-
if (expression == known.fact())
76+
private Expression decide(Expression expression, EnumComparison known) {
77+
if (expression == known.expression())
7878
return expression.clone();
79-
KnownValue compared = knownValue(expression);
79+
EnumComparison compared = enumComparison(expression);
8080
if (compared != null && compared.variable().equals(known.variable())
8181
&& enumTypes.get(compared.constant()).equals(enumTypes.get(known.constant()))) {
8282
boolean sameConstant = compared.constant().equals(known.constant());
@@ -92,7 +92,7 @@ private Expression decide(Expression expression, KnownValue known) {
9292
}
9393

9494
// A comparison of a variable with an enum constant, either way round, or null
95-
private KnownValue knownValue(Expression expression) {
95+
private EnumComparison enumComparison(Expression expression) {
9696
if (!(expression instanceof BinaryExpression binary))
9797
return null;
9898
boolean equal = "==".equals(binary.getOperator());
@@ -101,9 +101,9 @@ private KnownValue knownValue(Expression expression) {
101101
Expression left = binary.getFirstOperand(), right = binary.getSecondOperand();
102102
String leftConstant = enumConstant(left), rightConstant = enumConstant(right);
103103
if (left instanceof Var variable && leftConstant == null && rightConstant != null)
104-
return new KnownValue(expression, variable.getName(), rightConstant, equal);
104+
return new EnumComparison(expression, variable.getName(), rightConstant, equal);
105105
if (right instanceof Var variable && rightConstant == null && leftConstant != null)
106-
return new KnownValue(expression, variable.getName(), leftConstant, equal);
106+
return new EnumComparison(expression, variable.getName(), leftConstant, equal);
107107
return null;
108108
}
109109

0 commit comments

Comments
 (0)