From 614c81712cba940a609e206af1a508d1477314ae Mon Sep 17 00:00:00 2001 From: Valentin Perrelle <valentin.perrelle@cea.fr> Date: Thu, 5 Jan 2023 17:29:39 +0100 Subject: [PATCH] [Kernel] Extend State_builder.Hashtbl with two standard functions --- src/libraries/project/state_builder.ml | 4 ++++ src/libraries/project/state_builder.mli | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/libraries/project/state_builder.ml b/src/libraries/project/state_builder.ml index cb369ad1045..c93f9c167b3 100644 --- a/src/libraries/project/state_builder.ml +++ b/src/libraries/project/state_builder.ml @@ -490,9 +490,11 @@ module type Hashtbl = sig ?cmp:(key -> key -> int) -> (key -> data -> 'a -> 'a) -> 'a -> 'a val memo: ?change:(data -> data) -> (key -> data) -> key -> data val find: key -> data + val find_opt: key -> data option val find_all: key -> data list val mem: key -> bool val remove: key -> unit + val to_seq: unit -> (key * data) Seq.t end module Hashtbl @@ -548,6 +550,7 @@ struct let replace key v = H.replace !state key v let add key v = H.add !state key v let find key = H.find !state key + let find_opt key = H.find_opt !state key let find_all key = H.find_all !state key let mem key = H.mem !state key let remove key = H.remove !state key @@ -555,6 +558,7 @@ struct let iter_sorted ?cmp f = H.iter_sorted ?cmp f !state let fold f acc = H.fold f !state acc let fold_sorted ?cmp f acc = H.fold_sorted ?cmp f !state acc + let to_seq () = H.to_seq !state let memo ?change f key = try diff --git a/src/libraries/project/state_builder.mli b/src/libraries/project/state_builder.mli index 22ca6683820..658e4b0ff84 100644 --- a/src/libraries/project/state_builder.mli +++ b/src/libraries/project/state_builder.mli @@ -351,11 +351,22 @@ module type Hashtbl = sig (** Return the current binding of the given key. @raise Not_found if the key is not in the table. *) + val find_opt: key -> data option + (** Return the current binding of the given key or None if no such binding + exists. + + @since Frama-C+dev *) + val find_all: key -> data list (** Return the list of all data associated with the given key. *) val mem: key -> bool val remove: key -> unit + + val to_seq: unit -> (key * data) Seq.t + (** Iterate on the whole table. + + @since Frama-C+dev *) end (** @see <https://frama-c.com/download/frama-c-plugin-development-guide.pdf> Plug-in Development Guide -- GitLab