]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_tactics/nTacStatus.ml
matitacLib: bugfix in .moo generation
[helm.git] / helm / software / components / ng_tactics / nTacStatus.ml
index 545e5603bd3cb895b1cd05c2ecaa4ab2b0ebdeba..eeca351c228f01462ce591e70569109d7c2642c4 100644 (file)
@@ -45,24 +45,41 @@ let ctx_of (_,c,_) = c ;;
 
 let relocate status destination (name,source,t as orig) =
  if source == destination then status, orig else
-  let rec lcp j i = function
-    | (n1, t1)::cl1, (n2, t2)::cl2 ->
-        if n1 = n2 && t1 = t2 then
-          NCic.Rel i :: lcp (j-1) (i-1) (cl1,cl2)
+  let u, d, metasenv, subst, o = status.pstatus in 
+  let rec lcp ctx j i = function
+    | (n1, NCic.Decl t1 as e)::cl1, (n2, NCic.Decl t2)::cl2 ->
+        if n1 = n2 && 
+           NCicReduction.are_convertible ctx ~subst ~metasenv t1 t2 then
+          NCic.Rel i :: lcp (e::ctx)(j-1) (i-1) (cl1,cl2)
+        else
+          HExtlib.mk_list (NCic.Appl 
+            [NCic.Sort NCic.Prop; NCic.Sort NCic.Prop]) j
+    | (n1, NCic.Def (b1,t1) as e)::cl1, (n2, NCic.Def (b2,t2))::cl2 ->
+        if n1 = n2 && 
+           NCicReduction.are_convertible ctx ~subst ~metasenv t1 t2 &&
+           NCicReduction.are_convertible ctx ~subst ~metasenv b1 b2 then
+          NCic.Rel i :: lcp (e::ctx)(j-1) (i-1) (cl1,cl2)
         else
           HExtlib.mk_list (NCic.Appl 
             [NCic.Sort NCic.Prop; NCic.Sort NCic.Prop]) j
+    | (n1, NCic.Def (b1,t1) as e)::cl1, (n2, NCic.Decl t2)::cl2 ->
+        if n1 = n2 && 
+           NCicReduction.are_convertible ctx ~subst ~metasenv t1 t2 then
+          NCic.Rel i :: lcp (e::ctx)(j-1) (i-1) (cl1,cl2)
+        else
+          HExtlib.mk_list (NCic.Appl 
+            [NCic.Sort NCic.Prop; NCic.Sort NCic.Prop]) j
+    | (n1, NCic.Decl _)::cl1, (n2, NCic.Def _)::cl2 -> assert false
     | _::_, [] -> 
           HExtlib.mk_list (NCic.Appl 
             [NCic.Sort NCic.Prop; NCic.Sort NCic.Prop]) j
     | _ -> []
   in
   let lc = 
-    lcp (List.length destination) (List.length source) 
+    lcp [] (List.length destination) (List.length source) 
       (List.rev destination, List.rev source)
   in
   let lc = (0,NCic.Ctx (List.rev lc)) in
-  let u, d, metasenv, subst, o = status.pstatus in 
   let db = NCicUnifHint.db () in (* XXX fixme *)
   let (metasenv, subst), t =
     NCicMetaSubst.delift 
@@ -82,10 +99,13 @@ let term_of_cic_term s t c =
   s, t
 ;;
 
-type ast_term = string * int * CicNotationPt.term
+let ppterm status t =
+ let uri,height,metasenv,subst,obj = status.pstatus in
+ let _,context,t = t in
+  NCicPp.ppterm ~metasenv ~subst ~context t
+;;
 
-let disambiguate (status : lowtac_status) (t : ast_term)  
-                 (ty : cic_term option) context =
+let disambiguate status t ty context =
  let status, expty = 
    match ty with 
    | None -> status, None 
@@ -305,3 +325,46 @@ let analyse_indty status ty =
 ;;
 
 let mk_cic_term c t = None,c,t ;;
+
+(* CSC: next two functions to be moved elsewhere *)
+let rec apply_subst subst ctx =
+ function
+    NCic.Meta (i,lc) ->
+     (try
+       let _,_,t,_ = NCicUtils.lookup_subst i subst in
+       let t = NCicSubstitution.subst_meta lc t in
+        apply_subst subst ctx t
+      with
+       Not_found ->
+        match lc with
+           _,NCic.Irl _ -> NCic.Meta (i,lc)
+         | n,NCic.Ctx l ->
+            NCic.Meta
+             (i,(0,NCic.Ctx
+                 (List.map (fun t ->
+                   apply_subst subst ctx (NCicSubstitution.lift n t)) l))))
+  | t -> NCicUtils.map (fun item ctx -> item::ctx) ctx (apply_subst subst) t
+;;
+
+let apply_subst_obj subst =
+ function
+    NCic.Constant (relev,name,bo,ty,attrs) ->
+     NCic.Constant
+      (relev,name,HExtlib.map_option (apply_subst subst []) bo,
+        apply_subst subst [] ty,attrs)
+  | NCic.Fixpoint (ind,fl,attrs) ->
+     let fl =
+      List.map
+       (function (relevance,name,recno,ty,bo) ->
+         relevance,name,recno,apply_subst subst [] ty,apply_subst subst [] bo
+       ) fl
+     in
+      NCic.Fixpoint (ind,fl,attrs)
+  | _ -> assert false (* not implemented yet *)
+;;
+
+let apply_subst status ctx t =
+ let status, (name,_,t) = relocate status ctx t in
+ let _,_,_,subst,_ = status.pstatus in
+  status, (name, ctx, apply_subst subst ctx t)
+;;