-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathVCBinderSimplification.java
More file actions
86 lines (71 loc) · 2.85 KB
/
Copy pathVCBinderSimplification.java
File metadata and controls
86 lines (71 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package liquidjava.rj_language.opt;
import static liquidjava.rj_language.opt.VCSimplificationUtils.containsVar;
import static liquidjava.rj_language.opt.VCSimplificationUtils.copyWithRefinement;
import static liquidjava.rj_language.opt.VCSimplificationUtils.isFalse;
import static liquidjava.rj_language.opt.VCSimplificationUtils.isTrue;
import liquidjava.processor.VCImplication;
import liquidjava.rj_language.Predicate;
import liquidjava.rj_language.ast.LiteralBoolean;
/**
* Simplifies VCImplication chains by removing vacuous binder implications
*/
public class VCBinderSimplification implements VCSimplificationPass {
/**
* Applies one binder simplification in a VC chain
*/
@Override
public VCImplication apply(VCImplication implication) {
VCImplication cloned = implication.clone();
VCImplication simplified = simplify(cloned);
return simplified == null ? cloned : simplified;
}
/**
* Simplifies the first applicable binder in a VC chain
*/
private VCImplication simplify(VCImplication implication) {
if (implication == null)
return null;
if (isFalseBinder(implication))
return collapseFalseBinder(implication);
if (isTrueBinder(implication) && !containsVar(implication.getNext(), implication.getName()))
return removeTrueBinder(implication);
VCImplication next = simplify(implication.getNext());
if (next == null)
return null;
VCImplication result = copyWithRefinement(implication, implication.getRefinement().clone());
result.setNext(next);
return result;
}
/**
* Removes a true binder whose name is not used in the suffix
*/
private VCImplication removeTrueBinder(VCImplication implication) {
VCImplication next = implication.getNext();
// ∀x. true => P -> P
if (next != null)
return next.clone();
// ∀x. true -> true
Predicate truePredicate = new Predicate(new LiteralBoolean(true));
return new VCImplication(truePredicate);
}
/**
* Replaces a false binder implication with true
*/
private VCImplication collapseFalseBinder(VCImplication implication) {
// ∀x. false => P -> true
Predicate truePredicate = new Predicate(new LiteralBoolean(true));
return new VCImplication(truePredicate);
}
/**
* Checks whether a VC node is a binder refined with true
*/
private boolean isTrueBinder(VCImplication implication) {
return implication.hasBinder() && isTrue(implication.getRefinement().getExpression());
}
/**
* Checks whether a VC node is a binder refined with false
*/
private boolean isFalseBinder(VCImplication implication) {
return implication.hasBinder() && isFalse(implication.getRefinement().getExpression());
}
}