diff --git a/src/libraries/datatype/datatype.ml b/src/libraries/datatype/datatype.ml index e130e39dd4b9c2988caa553d429038604ec6d54c..8dae3ee8845863d16cf056b3afe010dc63f141d0 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 c063b0fa6d5f16c814946597fd18e63331e108c5..dfca5c26f86351caef328842b461258d5c142d97 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):