@@ -219,6 +219,53 @@ and rk_categories = {
219219 rkc_theory : bool ;
220220}
221221
222+ (* -------------------------------------------------------------------- *)
223+ type octxt = {
224+ oc_env : EcEnv .env ;
225+ oc_oth : ctheory ;
226+ }
227+
228+ (* -------------------------------------------------------------------- *)
229+ module Renaming : sig
230+ val rename1 : octxt -> theory_renaming -> renaming
231+ end = struct
232+ let rename1 oc (k , (r1 , r2 )) : renaming =
233+ let e1 =
234+ try EcRegexp. regexp (unloc r1)
235+ with EcRegexp. Error _ -> clone_error oc.oc_env (CE_InvalidRE (unloc r1)) in
236+ let e2 =
237+ try EcRegexp. subst (unloc r2)
238+ with EcRegexp. Error _ -> clone_error oc.oc_env (CE_InvalidRE (unloc r2)) in
239+
240+ Array. iter
241+ (fun m ->
242+ if EcRegexp. match_ (`S " ^0+$" ) (oget m.(1 )) then
243+ clone_error oc.oc_env (CE_InvalidRE (unloc r2)))
244+ (try EcRegexp. extract (`S " \\ $([0-9]+)" ) (unloc r2)
245+ with Not_found -> [||]);
246+
247+ let k =
248+ if List. is_empty k then `All else
249+
250+ let update rk = function
251+ | `Lemma -> { rk with rkc_lemmas = true ; }
252+ | `Type -> { rk with rkc_types = true ; }
253+ | `Op -> { rk with rkc_ops = true ; }
254+ | `Pred -> { rk with rkc_preds = true ; }
255+ | `Module -> { rk with rkc_module = true ; }
256+ | `ModType -> { rk with rkc_modtype = true ; }
257+ | `Theory -> { rk with rkc_theory = true ; } in
258+
259+ let init = {
260+ rkc_lemmas = false ; rkc_types = false ; rkc_ops = false ;
261+ rkc_preds = false ; rkc_module = false ; rkc_modtype = false ;
262+ rkc_theory = false ; } in
263+
264+ `Selected (List. fold_left update init k)
265+
266+ in (k, (e1, e2))
267+ end
268+
222269(* -------------------------------------------------------------------- *)
223270let rename ((rk , (rex , itempl )) : renaming ) (k , x ) =
224271 let selected =
@@ -239,12 +286,6 @@ let rename ((rk, (rex, itempl)) : renaming) (k, x) =
239286
240287 if x = newx then None else Some newx
241288
242- (* -------------------------------------------------------------------- *)
243- type octxt = {
244- oc_env : EcEnv .env ;
245- oc_oth : ctheory ;
246- }
247-
248289(* -------------------------------------------------------------------- *)
249290module OVRD : sig
250291 type state = theory_cloning_proof list * evclone
@@ -373,7 +414,9 @@ end = struct
373414 in (proofs, evc)
374415
375416 (* ------------------------------------------------------------------ *)
376- let th_ovrd oc ((proofs , evc ) : state ) name ((thd , mode ) : th_override ) =
417+ let th_ovrd oc ((proofs , evc ) : state ) name ((thd , mode , prerenames ) : th_override ) =
418+ let prerenames = List. map (Renaming. rename1 oc) prerenames in
419+
377420 let { pl_loc = lc; pl_desc = ((nm, x) as name) } = name in
378421
379422 let loced x = mk_loc lc x in
@@ -406,42 +449,53 @@ end = struct
406449 let thd = let thd = EcPath. toqsymbol sp in (fst thd @ [snd thd]) in
407450 let xdth = nm @ [x] in
408451
452+ let rename (kind , name ) =
453+ try
454+ List. find_map (fun rnm -> rename rnm (kind, name)) prerenames
455+ with Not_found -> name in
456+
409457 assert (not (Msym. mem x evc.evc_ths));
410458
411459 let evc = { evc with
412460 evc_ths = Msym. change (fun sub ->
413461 let sub, clear = odfl (evc_empty, false ) sub in
414462 Some (sub, clear || (mode <> `Alias ))) x evc.evc_ths } in
415463
416- let rec doit_r prefix (proofs , evc ) dth =
464+ let rec doit_r (prefix , tgprefix ) (proofs , evc ) dth =
465+ let dtpath (x : symbol ) =
466+ loced (xdth @ prefix, x) in
467+
468+ let tgpath ?kind (x : symbol ) =
469+ let x = Option. fold ~none: x ~some: (fun k -> rename (k, x)) kind in
470+ EcPath. fromqsymbol (thd @ tgprefix, x) in
471+
417472 match dth with
418473 | Th_type (x , _ ) ->
419- let ovrd = `ByPath (EcPath. fromqsymbol (thd @ prefix, x)) in
420- let ovrd = (ovrd, mode) in
421- ty_ovrd oc (proofs, evc) (loced (xdth @ prefix, x)) ovrd
474+ let ovrd = `ByPath (tgpath ~kind: `Type x), mode in
475+ ty_ovrd oc (proofs, evc) (dtpath x) ovrd
422476
423477 | Th_operator (x , ({ op_kind = OB_oper _ } )) ->
424- let ovrd = `ByPath (EcPath. fromqsymbol (thd @ prefix, x)) in
425- let ovrd = (ovrd, mode) in
426- op_ovrd oc (proofs, evc) (loced (xdth @ prefix, x)) ovrd
478+ let ovrd = (`ByPath (tgpath ~kind: `Op x), mode) in
479+ op_ovrd oc (proofs, evc) (dtpath x) ovrd
427480
428481 | Th_operator (x , ({ op_kind = OB_pred _ } )) ->
429- let ovrd = `ByPath (EcPath. fromqsymbol (thd @ prefix, x)) in
430- let ovrd = (ovrd, mode) in
431- pr_ovrd oc (proofs, evc) (loced (xdth @ prefix, x)) ovrd
482+ let ovrd = (`ByPath (tgpath ~kind: `Pred x), mode) in
483+ pr_ovrd oc (proofs, evc) (dtpath x) ovrd
432484
433485 | Th_operator (x , {op_kind =OB_nott _ ; _ } ) ->
434- let ovrd = EcPath. fromqsymbol (thd @ prefix, x) in
435- let ovrd = (ovrd, mode) in
436- nt_ovrd oc (proofs, evc) (loced (xdth @ prefix, x)) ovrd
486+ let ovrd = (tgpath x, mode) in
487+ nt_ovrd oc (proofs, evc) (dtpath x) ovrd
437488
438489 | Th_axiom (x , _ ) ->
439- let axd = loced (thd @ prefix, x) in
440- let name = (loced (xdth @ prefix, x)) in
441- ax_ovrd oc (proofs, evc) name (axd, mode)
490+ let axd = loced (EcPath. toqsymbol (tgpath ~kind: `Axiom x)) in
491+ ax_ovrd oc (proofs, evc) (dtpath x) (axd, mode)
442492
443493 | Th_theory (x , dth ) when dth.cth_mode = `Concrete ->
444- List. fold_left (doit (prefix @ [x])) (proofs, evc) dth.cth_items
494+ let tgx = rename (`Theory , x) in
495+ List. fold_left
496+ (doit (prefix @ [x], tgprefix @ [tgx]))
497+ (proofs, evc)
498+ dth.cth_items
445499
446500 | Th_theory (_ , _ ) ->
447501 (proofs, evc)
@@ -453,9 +507,9 @@ end = struct
453507 (proofs, evc)
454508
455509 | Th_modtype (x , _ ) ->
456- modtype_ovrd
457- oc (proofs, evc) (loced (xdth @ prefix, x))
458- (loced (thd @ prefix, x) , mode)
510+ let ovrd = loced ( EcPath. toqsymbol (tgpath ~kind: `ModType x)) in
511+ modtype_ovrd
512+ oc (proofs, evc) (dtpath x) (ovrd , mode)
459513
460514 | Th_instance _ -> (proofs, evc)
461515
@@ -468,7 +522,7 @@ end = struct
468522 and doit prefix (proofs , evc ) dth =
469523 doit_r prefix (proofs, evc) dth.ti_item
470524
471- in List. fold_left (doit [] ) (proofs, evc) dth.cth_items
525+ in List. fold_left (doit ( [] , [] ) ) (proofs, evc) dth.cth_items
472526
473527 (* ------------------------------------------------------------------ *)
474528 let ovrd oc state name (ovrd : theory_override ) =
@@ -492,47 +546,6 @@ end = struct
492546 th_ovrd oc state name thd
493547end
494548
495- (* -------------------------------------------------------------------- *)
496- module Renaming : sig
497- val rename1 : octxt -> theory_renaming -> renaming
498- end = struct
499- let rename1 oc (k , (r1 , r2 )) : renaming =
500- let e1 =
501- try EcRegexp. regexp (unloc r1)
502- with EcRegexp. Error _ -> clone_error oc.oc_env (CE_InvalidRE (unloc r1)) in
503- let e2 =
504- try EcRegexp. subst (unloc r2)
505- with EcRegexp. Error _ -> clone_error oc.oc_env (CE_InvalidRE (unloc r2)) in
506-
507- Array. iter
508- (fun m ->
509- if EcRegexp. match_ (`S " ^0+$" ) (oget m.(1 )) then
510- clone_error oc.oc_env (CE_InvalidRE (unloc r2)))
511- (try EcRegexp. extract (`S " \\ $([0-9]+)" ) (unloc r2)
512- with Not_found -> [||]);
513-
514- let k =
515- if List. is_empty k then `All else
516-
517- let update rk = function
518- | `Lemma -> { rk with rkc_lemmas = true ; }
519- | `Type -> { rk with rkc_types = true ; }
520- | `Op -> { rk with rkc_ops = true ; }
521- | `Pred -> { rk with rkc_preds = true ; }
522- | `Module -> { rk with rkc_module = true ; }
523- | `ModType -> { rk with rkc_modtype = true ; }
524- | `Theory -> { rk with rkc_theory = true ; } in
525-
526- let init = {
527- rkc_lemmas = false ; rkc_types = false ; rkc_ops = false ;
528- rkc_preds = false ; rkc_module = false ; rkc_modtype = false ;
529- rkc_theory = false ; } in
530-
531- `Selected (List. fold_left update init k)
532-
533- in (k, (e1, e2))
534- end
535-
536549(* -------------------------------------------------------------------- *)
537550module Proofs : sig
538551 val proof : intheory :bool -> octxt -> evclone -> theory_cloning_proof -> evclone
0 commit comments