Skip to content
Snippets Groups Projects
Commit a0d331fd authored by Valentin Perrelle's avatar Valentin Perrelle Committed by David Bühler
Browse files

[Eva] api: Add a result conversion helper

parent fa1206aa
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ end
module Results: sig
(* Usage sketch :
Eva.Results.(before stmt |> in_callstack cs |> eval_var vi |> as_int)
Eva.Results.(before stmt |> in_callstack cs |> eval_var vi |> as_int |> value ~default:0)
or, if you prefer
......@@ -124,6 +124,12 @@ module Results: sig
Raises [Stdlib.Invalid_argument] if the statement is not a [Call]
instruction or a [Local_init] with [ConsInit] initializer. *)
val callee : Cil_types.stmt -> Kernel_function.t list
(* Result conversion *)
(** [default d r] extract the value of r if r is Ok or use the default value d
otherwise.
Equivalent to [Result.value ~default:d r] *)
val default : 'a -> 'a result -> 'a
end
module Value_results: sig
......
......@@ -756,3 +756,9 @@ let callsites kf =
at_start_of kf |> callstacks |>
List.fold_left f Map.empty |> Map.to_seq |> List.of_seq |>
List.map (fun (kf,sites) -> kf, uniq_sites sites)
(* Result conversion *)
let default default_value result =
Result.value ~default:default_value result
......@@ -23,7 +23,7 @@
[@@@ api_start]
(* Usage sketch :
Eva.Results.(before stmt |> in_callstack cs |> eval_var vi |> as_int)
Eva.Results.(before stmt |> in_callstack cs |> eval_var vi |> as_int |> value ~default:0)
or, if you prefer
......@@ -127,4 +127,10 @@ val callsites : Cil_types.kernel_function ->
Raises [Stdlib.Invalid_argument] if the statement is not a [Call]
instruction or a [Local_init] with [ConsInit] initializer. *)
val callee : Cil_types.stmt -> Kernel_function.t list
(* Result conversion *)
(** [default d r] extract the value of r if r is Ok or use the default value d
otherwise.
Equivalent to [Result.value ~default:d r] *)
val default : 'a -> 'a result -> 'a
[@@@ api_end]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment