package codex

  1. Overview
  2. Docs
The Codex library for building static analysers based on abstract interpretation

Install

dune-project
 Dependency

Authors

Maintainers

Sources

1.0-rc4.tar.gz
md5=bc7266a140c6886add673ede90e335d3
sha512=8da42c0ff2c1098c5f9cb2b5b43b306faf7ac93b8f5ae00c176918cee761f249ff45b29309f31a05bbcf6312304f86a0d5a000eb3f1094d3d3c2b9b4c7f5c386

doc/src/codex.single_value_abstraction/sva_quadrivalent.ml.html

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
(**************************************************************************)
(*  This file is part of the Codex semantics library.                     *)
(*                                                                        *)
(*  Copyright (C) 2013-2025                                               *)
(*    CEA (Commissariat à l'énergie atomique et aux énergies              *)
(*         alternatives)                                                  *)
(*                                                                        *)
(*  you can redistribute it and/or modify it under the terms of the GNU   *)
(*  Lesser General Public License as published by the Free Software       *)
(*  Foundation, version 2.1.                                              *)
(*                                                                        *)
(*  It is distributed in the hope that it will be useful,                 *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *)
(*  GNU Lesser General Public License for more details.                   *)
(*                                                                        *)
(*  See the GNU Lesser General Public License version 2.1                 *)
(*  for more details (enclosed in the file LICENSE).                      *)
(*                                                                        *)
(**************************************************************************)

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

  (* Note: if the result is bottom it means that one of the argument
     should be bottom, but as we do not know which, we cannot refine
     anything. *)
  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