From 90084ad4ed74c64a3322b3b0b2150228d3bd0df0 Mon Sep 17 00:00:00 2001
From: Valentin Perrelle <valentin.perrelle@cea.fr>
Date: Tue, 28 Jan 2025 15:55:49 +0100
Subject: [PATCH] [kernel] datatype: add Make_with_set_and_map and
 Make_with_hashtbl

---
 src/libraries/datatype/datatype.ml  | 35 ++++++++++++++++++++++-
 src/libraries/datatype/datatype.mli | 44 +++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/src/libraries/datatype/datatype.ml b/src/libraries/datatype/datatype.ml
index e130e39dd4..8dae3ee884 100644
--- a/src/libraries/datatype/datatype.ml
+++ b/src/libraries/datatype/datatype.ml
@@ -265,6 +265,17 @@ module type Hashtbl = sig
   module Make(Data: S) : S with type t = Data.t t
 end
 
+module type S_with_set_and_map = sig
+  include S
+  module Set: Set with type elt = t
+  module Map: Map with type key = t
+end
+
+module type S_with_hashtbl = sig
+  include S
+  module Hashtbl: Hashtbl with type key = t
+end
+
 module type S_with_collections = sig
   include S
   module Set: Set with type elt = t
@@ -1459,7 +1470,7 @@ end
 (** {2 Simple type values} *)
 (* ****************************************************************************)
 
-module With_collections(X: S)(Info: Functor_info) = struct
+module With_set_and_map(X: S)(Info: Functor_info) = struct
 
   module D = X
   include D
@@ -1476,6 +1487,18 @@ module With_collections(X: S)(Info: Functor_info) = struct
       (D)
       (struct let module_name = Info.module_name ^ ".Map" end)
 
+end
+
+module Make_with_set_and_map(X: Make_input) =
+  With_set_and_map
+    (Make(X))
+    (struct let module_name = String.capitalize_ascii X.name end)
+
+module With_hashtbl(X: S)(Info: Functor_info) = struct
+
+  module D = X
+  include D
+
   module Hashtbl =
     Hashtbl
       (struct
@@ -1503,6 +1526,16 @@ module With_collections(X: S)(Info: Functor_info) = struct
 
 end
 
+module Make_with_hashtbl(X: Make_input) =
+  With_hashtbl
+    (Make(X))
+    (struct let module_name = String.capitalize_ascii X.name end)
+
+module With_collections(X: S)(Info: Functor_info) = struct
+  include (With_set_and_map(X)(Info) : S_with_set_and_map with type t = X.t)
+  include (With_hashtbl(X)(Info) : S_with_hashtbl with type t := X.t)
+end
+
 module Make_with_collections(X: Make_input) =
   With_collections
     (Make(X))
diff --git a/src/libraries/datatype/datatype.mli b/src/libraries/datatype/datatype.mli
index c063b0fa6d..dfca5c26f8 100644
--- a/src/libraries/datatype/datatype.mli
+++ b/src/libraries/datatype/datatype.mli
@@ -267,6 +267,28 @@ module type Hashtbl = sig
 
 end
 
+(** A datatype for a type [t] extended with predefined hashtbl over [t].
+
+    @see <https://frama-c.com/download/frama-c-plugin-development-guide.pdf>
+*)
+module type S_with_hashtbl = sig
+  include S
+  module Hashtbl: Hashtbl with type key = t
+  (** @see <https://frama-c.com/download/frama-c-plugin-development-guide.pdf> *)
+end
+
+(** A datatype for a type [t] extended with predefined set and map over [t].
+
+    @see <https://frama-c.com/download/frama-c-plugin-development-guide.pdf>
+*)
+module type S_with_set_and_map = sig
+  include S
+  module Set: Set with type elt = t
+  (** @see <https://frama-c.com/download/frama-c-plugin-development-guide.pdf> *)
+
+  module Map: Map with type key = t
+end
+
 (** A datatype for a type [t] extended with predefined set, map and hashtbl
     over [t].
 
@@ -282,6 +304,28 @@ module type S_with_collections = sig
   (** @see <https://frama-c.com/download/frama-c-plugin-development-guide.pdf> *)
 end
 
+(** Generic comparable datatype builder: functions [equal] and [compare] must
+    not be {!undefined}. *)
+module Make_with_set_and_map(X: Make_input):
+  S_with_set_and_map with type t = X.t
+
+(** Add sets and maps to an existing datatype, provided the [equal] and
+    [compare] are not {!undefined}.
+    @since Oxygen-20120901 *)
+module With_set_and_map(X: S)(_: Functor_info):
+  S_with_set_and_map with type t = X.t
+
+(** Generic comparable datatype builder: functions [equal] and [hash] must not
+    be {!undefined}. *)
+module Make_with_hashtbl(X: Make_input):
+  S_with_hashtbl with type t = X.t
+
+(** Add hashtables modules to an existing datatype, provided the [equal] and
+    [hash] functions are not {!undefined}.
+    @since Oxygen-20120901 *)
+module With_hashtbl(X: S)(_: Functor_info):
+  S_with_hashtbl with type t = X.t
+
 (** Generic comparable datatype builder: functions [equal], [compare] and
     [hash] must not be {!undefined}. *)
 module Make_with_collections(X: Make_input):
-- 
GitLab