From c250450f71470f01c913fdae950013341ecc9148 Mon Sep 17 00:00:00 2001
From: Allan Blanchard <allan.blanchard@cea.fr>
Date: Wed, 21 Sep 2022 15:48:20 +0200
Subject: [PATCH] [Extlib] removed filter_map' (List.filter_map)

---
 src/libraries/stdlib/extlib.ml               |  6 ------
 src/libraries/stdlib/extlib.mli              |  2 --
 src/plugins/eva/domains/multidim/multidim.ml |  8 ++++----
 src/plugins/gui/filetree.ml                  |  5 +++--
 tests/libc/check_compliance.ml               | 11 +++++------
 5 files changed, 12 insertions(+), 20 deletions(-)

diff --git a/src/libraries/stdlib/extlib.ml b/src/libraries/stdlib/extlib.ml
index cc38506a68f..eb390757a97 100644
--- a/src/libraries/stdlib/extlib.ml
+++ b/src/libraries/stdlib/extlib.ml
@@ -102,12 +102,6 @@ let replace cmp x l =
     | y::l -> if cmp x y then x::l else y :: aux l
   in aux l
 
-let filter_map' f filter l=
-  let rec aux = function
-    | [] -> []
-    | x::tl -> let x' = f x in if filter x' then x' :: aux tl else aux tl
-  in aux l
-
 let rec fold_map f acc = function
   | [] -> acc, []
   | x::tl ->
diff --git a/src/libraries/stdlib/extlib.mli b/src/libraries/stdlib/extlib.mli
index 8cf8182f59d..0229ce3436f 100644
--- a/src/libraries/stdlib/extlib.mli
+++ b/src/libraries/stdlib/extlib.mli
@@ -102,8 +102,6 @@ val replace: ('a -> 'a -> bool) -> 'a -> 'a list -> 'a list
     @since Neon-20140301
 *)
 
-val filter_map': ('a -> 'b) -> ('b -> bool) -> 'a list -> 'b list
-
 val fold_map: ('a -> 'b -> 'a * 'c) -> 'a -> 'b list -> 'a * 'c list
 (** Combines [fold_left] and [map] *)
 
diff --git a/src/plugins/eva/domains/multidim/multidim.ml b/src/plugins/eva/domains/multidim/multidim.ml
index 9e08333cbc1..951ea36b248 100644
--- a/src/plugins/eva/domains/multidim/multidim.ml
+++ b/src/plugins/eva/domains/multidim/multidim.ml
@@ -174,11 +174,11 @@ let mul_int x i =
 let mod_integer (o,sum) i =
   (* mod everything *)
   let o = Integer.e_rem o i in
-  let sum = Extlib.filter_map'
-      (fun (d,b) -> Integer.e_rem d i, b)
-      (fun (d,_b) -> not (Integer.is_zero d))
-      sum
+  let non_zero_rem (d, b) =
+    let rem = Integer.e_rem d i in
+    if Integer.is_zero rem then None else Some (rem, b)
   in
+  let sum = List.filter_map non_zero_rem sum in
   let sum = Terms.(normalize (reorder sum)) in (* order was not preserverd *)
   (* We must then ensure that the set of represented offset is < i,
      i.e. that the highest possible value is < i.
diff --git a/src/plugins/gui/filetree.ml b/src/plugins/gui/filetree.ml
index f1b9ad23581..351d8528aec 100644
--- a/src/plugins/gui/filetree.ml
+++ b/src/plugins/gui/filetree.ml
@@ -455,9 +455,10 @@ module State = struct
           Cil_builtins.is_unused_builtin vi
         | _ -> false
       in
-      f, Extlib.filter_out is_unused all
+      let gls = Extlib.filter_out is_unused all in
+      if gls = [] then None else Some (f, gls)
     in
-    Extlib.filter_map' globals_of_file (fun (_, gl) -> gl <> []) files
+    List.filter_map globals_of_file files
 
 
   (** Make and fill the custom model with default values. *)
diff --git a/tests/libc/check_compliance.ml b/tests/libc/check_compliance.ml
index 542109885e3..63485ebba93 100644
--- a/tests/libc/check_compliance.ml
+++ b/tests/libc/check_compliance.ml
@@ -18,12 +18,11 @@ class stdlib_visitor = object
       in_stdlib := false;
       Cil.SkipChildren
     | attrparams ->
-      let headers =
-        Extlib.filter_map' (fun ap ->
-            match ap with
-            | AStr s -> s
-            | _ -> assert false
-          ) (Extlib.string_suffix ".h") attrparams
+      let when_header = function
+        | AStr s when Extlib.string_suffix ".h" s -> Some s
+        | _ -> None
+      in
+      let headers = List.filter_map when_header attrparams
       in
       in_stdlib := true;
       begin
-- 
GitLab