Source file sva_quadrivalent.ml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
module Boolean_Lattice = Lattices.Quadrivalent
include Boolean_Lattice
let name = "Single_value_abstraction.Quadrivalent"
module Boolean_Forward = struct
let true_ = True
let false_ = False
let not = function
| Bottom -> Bottom
| True -> False
| False -> True
| Top -> Top
;;
let (&&) a b = match (a,b) with
| Bottom, _ | _, Bottom -> Bottom
| False, _ | _, False -> False
| True, x | x, True -> x
| Top, Top -> Top
let (||) a b = match (a,b) with
| Bottom, _ | _, Bottom -> Bottom
| True, _ | _, True -> True
| False, x | x, False -> x
| Top, Top -> Top
end
let refine older newer = match older,newer with
| _, Top -> None
| Bottom, _ -> None
| _, Bottom -> Some Bottom
| True, True -> None
| True, False -> Some Bottom
| False, False -> None
| False, True -> Some Bottom
| Top, True -> Some True
| Top, False -> Some False
module Boolean_Backward = struct
let (&&) a1 a2 res = match res with
| Top -> None,None
| Bottom -> None, None
| True -> (refine a1 True), (refine a2 True)
| False -> (match a1,a2 with
| True, x -> None, (refine x False)
| x, True -> (refine x False), None
| False, _ | _, False -> None,None
| Bottom, _ | _, Bottom -> None, None
| Top, Top -> None,None
)
;;
let (||) a1 a2 res = match res with
| Top -> None,None
| Bottom -> None, None
| False -> (refine a1 False), (refine a2 False)
| True -> (match a1,a2 with
| False, x -> None, (refine x True)
| x, False -> (refine x True), None
| True, _ | _, True -> None,None
| Bottom, _ | _, Bottom -> None, None
| Top, Top -> None,None
)
;;
let not x res =
let notres = Boolean_Forward.not res in
let red = Boolean_Lattice.inter x notres in
if Boolean_Lattice.equal red res then None else Some red
end
let refine ~older ~newer = refine older newer