Skip to content

Commit 1857839

Browse files
committed
PR: Refactor codepositions
1 parent 78cf6eb commit 1857839

41 files changed

Lines changed: 1129 additions & 481 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/global-hybrid/GlobalHybridExamp2.ec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ rcondf{1} 1; first auto.
416416
rcondf{2} 1; first auto; smt().
417417
rcondt{2} 1; first auto.
418418
wp; inline*.
419-
swap{2} 2 -1; swap{2} 6 -4; swap{2} 10 -7.
419+
swap{2} 2 -1; swap{2} 6 -4.
420420
seq 2 3 :
421421
(#pre /\ x{1} = r0{2} /\ y{1} = r1{2} /\
422422
x0{2} = A); first auto.

src/ecCorePrinting.ml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,17 @@ module type PrinterAPI = sig
6868
val pp_shorten_path : PPEnv.t -> (path -> qsymbol -> bool) -> path pp
6969

7070
(* ------------------------------------------------------------------ *)
71-
val pp_codepos1 : PPEnv.t -> EcMatching.Position.codepos1 pp
72-
val pp_codeoffset1 : PPEnv.t -> EcMatching.Position.codeoffset1 pp
73-
74-
val pp_codepos : PPEnv.t -> EcMatching.Position.codepos pp
71+
val pp_codepos1 : PPEnv.t -> EcMatching.Position.codepos1 pp
72+
val pp_codepos_brsel : EcMatching.Position.codepos_brsel pp
73+
val pp_codepos_step : PPEnv.t -> EcMatching.Position.codepos_step pp
74+
val pp_codepos_path : PPEnv.t -> EcMatching.Position.codepos_path pp
75+
val pp_codeoffset1 : PPEnv.t -> EcMatching.Position.codeoffset1 pp
76+
77+
val pp_codepos : PPEnv.t -> EcMatching.Position.codepos pp
78+
val pp_codegap1 : PPEnv.t -> EcMatching.Position.codegap1 pp
79+
val pp_codegap : PPEnv.t -> EcMatching.Position.codegap pp
80+
val pp_codegap1_range : PPEnv.t -> EcMatching.Position.codegap1_range pp
81+
val pp_codegap_range : PPEnv.t -> EcMatching.Position.codegap_range pp
7582

7683
(* ------------------------------------------------------------------ *)
7784
type vsubst = [

src/ecHiTacticals.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,15 @@ and process1_phl (_ : ttenv) (t : phltactic located) (tc : tcenv1) =
238238

239239
try tx tc
240240
with (* PHL Specific low errors *)
241-
| EcLowPhlGoal.InvalidSplit cpos1 ->
241+
| EcLowPhlGoal.InvalidSplit is ->
242242
tc_error_lazy !!tc (fun fmt ->
243243
let ppe = EcPrinting.PPEnv.ofenv (FApi.tc1_env tc) in
244244
Format.fprintf fmt "invalid split index: %a"
245-
(EcPrinting.pp_codepos1 ppe) cpos1)
245+
(fun fmt is -> match is with
246+
| `Gap gap -> Format.fprintf fmt "%a" EcPrinting.(pp_codegap1 ppe) gap
247+
| `Instr i -> Format.fprintf fmt "%a" EcPrinting.(pp_codepos1 ppe) i
248+
) is)
249+
246250

247251
(* -------------------------------------------------------------------- *)
248252
and process_sub (ttenv : ttenv) tts tc =

src/ecLowPhlGoal.ml

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,18 @@ let tc1_get_stmt side tc =
207207
tc_error_noXhl ~kinds:(hlkinds_Xhl_r `Stmt) !!tc
208208

209209
(* ------------------------------------------------------------------ *)
210-
let tc1_process_codepos_range tc (side, cpr) =
210+
let tc1_process_codepos_or_range tc (side, cpor) =
211211
let me, _ = tc1_get_stmt side tc in
212212
let env = FApi.tc1_env tc in
213213
let env = EcEnv.Memory.push_active_ss me env in
214-
EcTyping.trans_codepos_range env cpr
214+
EcTyping.trans_codepos_or_range env cpor
215+
216+
(* ------------------------------------------------------------------ *)
217+
let tc1_process_codegap_range tc (side, cgr) =
218+
let me, _ = tc1_get_stmt side tc in
219+
let env = FApi.tc1_env tc in
220+
let env = EcEnv.Memory.push_active_ss me env in
221+
EcTyping.trans_codegap_range env cgr
215222

216223
(* ------------------------------------------------------------------ *)
217224
let tc1_process_codepos tc (side, cpos) =
@@ -379,22 +386,37 @@ let logicS_post_read (env : env) (f : logicS) =
379386
add EcPV.PMVS.empty (es_po es).inv
380387

381388
(* -------------------------------------------------------------------- *)
382-
exception InvalidSplit of codepos1
389+
exception InvalidSplit of [ `Instr of codepos1 | `Gap of codegap1 ]
390+
383391

384392
let s_split env i s =
385-
let module Zpr = EcMatching.Zipper in
386-
try Zpr.split_at_cpos1 env i s
387-
with Zpr.InvalidCPos -> raise (InvalidSplit i)
393+
let module Pos = EcMatching.Position in
394+
try Pos.split_at_cgap1 env i s
395+
with Pos.InvalidCPos -> raise (InvalidSplit (`Gap i))
388396

389397
let s_split_i env i s =
390-
let module Zpr = EcMatching.Zipper in
391-
try Zpr.find_by_cpos1 ~rev:false env i s
392-
with Zpr.InvalidCPos -> raise (InvalidSplit i)
398+
let module Pos = EcMatching.Position in
399+
try Pos.find_by_cpos1 ~rev:false env i s
400+
with Pos.InvalidCPos -> raise (InvalidSplit (`Instr i))
393401

394402
let o_split ?rev env i s =
395-
let module Zpr = EcMatching.Zipper in
396-
try Zpr.may_split_at_cpos1 ?rev env i s
397-
with Zpr.InvalidCPos -> raise (InvalidSplit (oget i))
403+
let module Pos = EcMatching.Position in
404+
try Pos.may_split_at_cgap1 ?rev env i s
405+
with Pos.InvalidCPos -> raise (InvalidSplit (`Gap(oget i)))
406+
407+
(* -------------------------------------------------------------------- *)
408+
(* Gap processing functions *)
409+
let tc1_process_codegap1 tc (side, g) =
410+
let me, _ = tc1_get_stmt side tc in
411+
let env = FApi.tc1_env tc in
412+
let env = EcEnv.Memory.push_active_ss me env in
413+
EcTyping.trans_codegap1 env g
414+
415+
let tc1_process_codegap tc (side, g) =
416+
let me, _ = tc1_get_stmt side tc in
417+
let env = FApi.tc1_env tc in
418+
let env = EcEnv.Memory.push_active_ss me env in
419+
EcTyping.trans_codegap env g
398420

399421
(* -------------------------------------------------------------------- *)
400422
let t_hS_or_bhS_or_eS ?th ?teh ?tbh ?te tc =
@@ -740,14 +762,14 @@ let t_fold f (cenv : code_txenv) (cpos : codepos) (_ : form * form) (state, s) =
740762
let env = EcEnv.LDecl.toenv (snd cenv) in
741763
let (me, f) = Zpr.fold env cenv cpos (fun _ -> f) state s in
742764
((me, f, []) : memenv * _ * form list)
743-
with Zpr.InvalidCPos -> tc_error (fst cenv) "invalid code position"
765+
with InvalidCPos -> tc_error (fst cenv) "invalid code position"
744766

745767
let t_zip f (cenv : code_txenv) (cpos : codepos) (prpo : form * form) (state, s) =
746768
try
747769
let env = EcEnv.LDecl.toenv (snd cenv) in
748770
let (me, zpr, gs) = f cenv prpo state (Zpr.zipper_of_cpos env cpos s) in
749771
((me, Zpr.zip zpr, gs) : memenv * _ * form list)
750-
with Zpr.InvalidCPos -> tc_error (fst cenv) "invalid code position"
772+
with InvalidCPos -> tc_error (fst cenv) "invalid code position"
751773

752774
let t_code_transform (side : oside) ?(bdhoare = false) cpos tr tx tc =
753775
let pf = FApi.tc1_penv tc in

0 commit comments

Comments
 (0)