]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/ng_kernel/oCic2NCic.ml
Grave bug fixed: Ce that point to definitions were handled as those that point
[helm.git] / helm / software / components / ng_kernel / oCic2NCic.ml
index b1b08ee3c7821db86fd7186e588c04467f7cf62f..c3a6558c235e0c41ade35ee0840d706ebe22f433 100644 (file)
@@ -25,38 +25,46 @@ let context_tassonomy ctx =
     let rec split inner acc acc1 = function 
       | Ce _ :: tl when inner -> split inner (acc+1) (acc1+1) tl
       | Fix _ ::tl -> split false acc (acc1+1) tl
-      | _ as l -> acc, List.length l, acc1
+      | _ as l ->
+        let only_decl =
+         List.filter (function Ce (_, NCic.Decl _) | Fix _ -> true | _ -> false)
+          l
+        in
+         acc, List.length l, List.length only_decl, acc1
     in
       split true 0 1 ctx
 ;;
 
 let splat_args_for_rel ctx t = 
-  let bound, free, primo_ce_dopo_fix = context_tassonomy ctx in
+  let bound, free, _, primo_ce_dopo_fix = context_tassonomy ctx in
   if free = 0 then t 
   else
     let rec aux = function
       | 0 -> []
       | n -> 
-         (match List.nth ctx (n+bound) with
-         | Fix (refe, _, _) when (n+bound) < primo_ce_dopo_fix -> NCic.Const refe
-         | Fix _ | Ce _ -> NCic.Rel (n+bound)) :: aux (n-1)
+         match List.nth ctx (n+bound) with
+         | Fix (refe, _, _) when (n+bound) < primo_ce_dopo_fix ->
+            NCic.Const refe :: aux (n-1)
+         | Fix _ | Ce (_, NCic.Decl _) -> NCic.Rel (n+bound)::aux (n-1)
+         | Ce (_, NCic.Def _) -> aux (n-1)
     in
     NCic.Appl (t:: aux free)
 ;;
 
 let splat_args ctx t n_fix = 
-  let bound, free, primo_ce_dopo_fix = context_tassonomy ctx in
+  let bound, free, _, primo_ce_dopo_fix = context_tassonomy ctx in
   if ctx = [] then t
   else
    let rec aux = function
      | 0 -> []
      | n -> 
         (match List.nth ctx (n-1) with
-         | Ce _ when n <= bound -> NCic.Rel n
+         | Ce (_, NCic.Decl _) when n <= bound -> NCic.Rel n:: aux (n-1)
          | Fix (refe, _, _) when n < primo_ce_dopo_fix ->
-            splat_args_for_rel ctx (NCic.Const refe)
-         | Fix _ | Ce _ -> NCic.Rel (n - n_fix)
-        ) :: aux (n-1)
+            splat_args_for_rel ctx (NCic.Const refe):: aux (n-1)
+         | Fix _ | Ce (_, NCic.Decl _) -> NCic.Rel (n - n_fix):: aux (n-1)
+         | Ce (_, NCic.Def _) -> aux (n - 1)
+        ) 
    in
    NCic.Appl (t:: aux (List.length ctx))
 ;;
@@ -215,10 +223,10 @@ let convert_term uri t =
         in
         let bctx, fixpoints_tys, tys, _ = 
           List.fold_right 
-            (fun (name,ty,_) (ctx, fixpoints, tys, idx) -> 
+            (fun (name,ty,_) (bctx, fixpoints, tys, idx) -> 
               let ty, fixpoints_ty = aux octx ctx n_fix uri ty in
               let r = Ref.reference_of_ouri buri(Ref.CoFix idx) in
-              Fix (r,name,ty) :: ctx, fixpoints_ty @ fixpoints,ty::tys,idx+1)
+              Fix (r,name,ty) :: bctx, fixpoints_ty @ fixpoints,ty::tys,idx+1)
             fl ([], [], [], 0)
         in
         let bctx = bctx @ ctx in
@@ -261,11 +269,12 @@ let convert_term uri t =
               Fix (r,name,ty) :: bctx, fixpoints_ty@fixpoints,ty::tys,idx+1)
             fl ([], [], [], 0)
         in
-        let _, free, _ = context_tassonomy (bad_bctx @ ctx) in
+        let _, _, free_decls, _ = context_tassonomy (bad_bctx @ ctx) in
         let bctx = 
           List.map (function 
             | Fix (Ref.Ref (_,_,Ref.Fix (idx, recno)),name, ty) ->
-              Fix (Ref.reference_of_ouri buri(Ref.Fix (idx,recno+free)),name,ty)
+              Fix (Ref.reference_of_ouri buri
+                    (Ref.Fix (idx,recno+free_decls)),name,ty)
             | _ -> assert false) bad_bctx @ ctx
         in
         let n_fl = List.length fl in
@@ -280,7 +289,7 @@ let convert_term uri t =
           List.fold_right2 
             (fun (name,rno,_,bo) ty (l,fixpoints,idx) -> 
                let bo, fixpoints_bo = aux boctx bctx n_fl buri bo in
-               let rno = rno + free in
+               let rno = rno + free_decls in
                if idx = k then rno_k := rno;
                (([],name,rno,splat true ctx ty, splat false ctx bo)::l),
                fixpoints_bo @ fixpoints,idx+1)
@@ -296,7 +305,7 @@ let convert_term uri t =
           n_fix,
         fixpoints @ [obj]
     | Cic.Rel n ->
-        let bound, _, primo_ce_dopo_fix = context_tassonomy ctx in
+        let bound, _, _, primo_ce_dopo_fix = context_tassonomy ctx in
         (match List.nth ctx (n-1) with
         | Fix (r,_,_) when n < primo_ce_dopo_fix -> 
             splat_args_for_rel ctx (NCic.Const r), []
@@ -357,6 +366,11 @@ let convert_term uri t =
     | Cic.MutConstruct (curi, tyno, consno, ens) -> 
        aux_ens curi octx ctx n_fix uri ens
         (NCic.Const (Ref.reference_of_ouri curi (Ref.Con (tyno,consno))))
+    | Cic.Var (curi, ens) ->
+       (match fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph curi) with
+           Cic.Variable (_,Some bo,_,_,_) ->
+            aux octx ctx n_fix uri (CicSubstitution.subst_vars ens bo)
+         | _ -> assert false)
     | Cic.MutCase (curi, tyno, outty, t, branches) ->
         let r = Ref.reference_of_ouri curi (Ref.Ind tyno) in
         let outty, fixpoints_outty = aux octx ctx n_fix uri outty in
@@ -369,7 +383,7 @@ let convert_term uri t =
              branches ([],[])
         in
         NCic.Match (r,outty,t,branches), fixpoints_outty@fixpoints_t@fixpoints
-    | Cic.Implicit _ | Cic.Meta _ | Cic.Var _ -> assert false
+    | Cic.Implicit _ | Cic.Meta _ -> assert false
   and aux_ens curi octx ctx n_fix uri ens he =
    match ens with
       [] -> he,[]
@@ -384,9 +398,13 @@ let convert_term uri t =
       let ens,objs =
        List.fold_right
         (fun luri (l,objs) ->
-          let t = List.assoc luri ens in
-          let t,o = aux octx ctx n_fix uri t in
-           t::l, o@objs
+          match fst (CicEnvironment.get_obj CicUniv.oblivion_ugraph luri) with
+             Cic.Variable (_,Some _,_,_,_) -> l, objs
+           | Cic.Variable (_,None,_,_,_) ->
+              let t = List.assoc luri ens in
+              let t,o = aux octx ctx n_fix uri t in
+               t::l, o@objs
+           | _ -> assert false
         ) params ([],[])
       in
        NCic.Appl (he::ens),objs