Skip to content

Commit 5903e1f

Browse files
committed
Internal: minor additions to EcLowPhlGoal & EcMatching modules
- EcMatching.Zipper.map - EcLowPhlGoal.{is_program_logic,hl_set_stmt}
1 parent ff7b195 commit 5903e1f

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/ecLowPhlGoal.ml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,26 @@ let tc1_as_equivF tc = pf_as_equivF !!tc (FApi.tc1_goal tc)
176176
let tc1_as_equivS tc = pf_as_equivS !!tc (FApi.tc1_goal tc)
177177
let tc1_as_eagerF tc = pf_as_eagerF !!tc (FApi.tc1_goal tc)
178178

179+
(* -------------------------------------------------------------------- *)
180+
let is_program_logic (f : form) (ks : hlkind list) =
181+
let do1 (k : hlkind) =
182+
match f.f_node, k with
183+
| FhoareF _, `Hoare (`Any | `Pred) -> true
184+
| FeHoareF _, `EHoare (`Any | `Pred) -> true
185+
| FcHoareF _, `CHoare (`Any | `Pred) -> true
186+
| FbdHoareF _, `PHoare (`Any | `Pred) -> true
187+
| FequivF _, `Equiv (`Any | `Pred) -> true
188+
| FhoareS _, `Hoare (`Any | `Stmt) -> true
189+
| FeHoareS _, `EHoare (`Any | `Stmt) -> true
190+
| FcHoareS _, `CHoare (`Any | `Stmt) -> true
191+
| FbdHoareS _, `PHoare (`Any | `Stmt) -> true
192+
| FequivS _, `Equiv (`Any | `Stmt) -> true
193+
| FeagerF _, `Eager -> true
194+
| _ , _ -> false
195+
in
196+
197+
List.exists do1 ks
198+
179199
(* -------------------------------------------------------------------- *)
180200
let tc1_get_stmt side tc =
181201
let concl = FApi.tc1_goal tc in
@@ -193,6 +213,17 @@ let tc1_get_stmt side tc =
193213
| _ ->
194214
tc_error_noXhl ~kinds:(hlkinds_Xhl_r `Stmt) !!tc
195215

216+
(* -------------------------------------------------------------------- *)
217+
let hl_set_stmt (side : side option) (f : form) (s : stmt) =
218+
match side, f.f_node with
219+
| None , FhoareS hs -> f_hoareS_r { hs with hs_s = s }
220+
| None , FeHoareS hs -> f_eHoareS_r { hs with ehs_s = s }
221+
| None , FcHoareS hs -> f_cHoareS_r { hs with chs_s = s }
222+
| None , FbdHoareS hs -> f_bdHoareS_r { hs with bhs_s = s }
223+
| Some `Left , FequivS es -> f_equivS_r { es with es_sl = s }
224+
| Some `Right, FequivS es -> f_equivS_r { es with es_sr = s }
225+
| _ , _ -> assert false
226+
196227
(* -------------------------------------------------------------------- *)
197228
let get_pre f =
198229
match f.f_node with

src/ecMatching.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ module Zipper = struct
188188
| (state', [i']) when i == i' && state == state' -> (state, s)
189189
| (state', si ) -> (state', zip { zpr with z_tail = si @ tl })
190190
end
191+
192+
let map cpos f s =
193+
fst_map
194+
Option.get
195+
(fold () cpos (fun () _ i -> fst_map some (f i)) None s)
191196
end
192197

193198
(* -------------------------------------------------------------------- *)

src/ecMatching.mli

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,20 @@ module Zipper : sig
5858

5959
type ('a, 'state) folder = 'a -> 'state -> instr -> 'state * instr list
6060

61-
(* [fold cl cpos f state s] create the zipper for [s] at [cpos], and apply
61+
(* [fold v cpos f state s] create the zipper for [s] at [cpos], and apply
6262
* [f] to it, along with [v] and the state [state]. [f] must return the
6363
* new [state] and a new [zipper]. These last are directly returned.
6464
*
6565
* Raise [InvalidCPos] if [cpos] is not valid for [s], or any exception
6666
* raised by [f].
6767
*)
6868
val fold : 'a -> codepos -> ('a, 'state) folder -> 'state -> stmt -> 'state * stmt
69+
70+
(* [map cpos f s] is a special case of [fold] where the state and the
71+
* out-of-band data are absent
72+
*)
73+
val map : codepos -> (instr -> 'a * instr list) -> stmt -> 'a * stmt
74+
6975
end
7076

7177
(* -------------------------------------------------------------------- *)

0 commit comments

Comments
 (0)